#ifndef __JAANET__JEVTWEIGHTFACTOR__ #define __JAANET__JEVTWEIGHTFACTOR__ #include "km3net-dataformat/offline/Evt.hh" #include "JLang/JStringStream.hh" #include "JSystem/JStat.hh" #include "Jeep/JProperties.hh" #include "JLang/JClonable.hh" /** * \author bjung */ namespace JAANET {} namespace JPP { using namespace JAANET; } namespace JAANET { using JLANG::JClonable; /** * Abstract base class for specifiable event-weight factors. */ struct JEvtWeightFactor : public JClonable { /** * Virtual destructor. */ virtual ~JEvtWeightFactor() {} /** * Get type keyword. * * \return type keyword */ static const char* const getTypeKey() { return "type"; } /** * Get event-weight factor of given event. * * \param evt event * \return event-weight factor */ virtual double getFactor(const Evt& evt) const = 0; /** * Get event-weight factor of given event. * * \param evt event * \return event-weight factor */ double operator()(const Evt& evt) const { return getFactor(evt); } /** * Check whether this event-weight factor is valid. * * \return true if valid; else false */ virtual bool is_valid() const { return true; } /** * Check validity of this event-weight factor. */ void check_validity() const { using namespace JPP; if (!is_valid()) { THROW(JValueOutOfRange, "JEvtWeightFactor():check_validity(): Invalid event-weight factor " << *this); } } /** * Get equation parameters. * * \return equation parameters */ static inline JEquationParameters& getEquationParameters() { static JEquationParameters equation("=", ",", "./", "#"); return equation; } /** * Set equation parameters. * * \param eqpars equation parameters */ static inline void setEquationParameters(const JEquationParameters& eqpars) { getEquationParameters() = eqpars; } /** * Get properties of this class. * * \param eqpars equation parameters */ virtual JProperties getProperties(const JEquationParameters& eqpars = JEvtWeightFactor::getEquationParameters()) { return JProperties(eqpars,1); } /** * Get properties of this class. * * \param eqpars equation parameters */ virtual JProperties getProperties(const JEquationParameters& eqpars = JEvtWeightFactor::getEquationParameters()) const { return JProperties(eqpars,1); } /** * Read event-weight factor from input. * * \param in input stream * \return input stream */ virtual std::istream& read(std::istream& in) { using namespace std; using namespace JPP; JStringStream is(in); if (getFileStatus(is.str().c_str())) { is.load(); } JProperties properties = getProperties(); is >> properties; check_validity(); return in; } /** * Write event-weight factor to output * * \param out output stream * \return output stream */ virtual std::ostream& write(std::ostream& out) const { return out << getProperties(); } /** * Read event category from input. * * \param in input stream * \param object event category * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JEvtWeightFactor& object) { return object.read(in); } /** * Write event category to output. * * \param out output stream * \param object event category * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JEvtWeightFactor& object) { return object.write(out); } }; } #endif