#ifndef __JAANET__JEVTWEIGHTFACTORHELPER__ #define __JAANET__JEVTWEIGHTFACTORHELPER__ #include #include "km3net-dataformat/offline/Evt.hh" #include "Jeep/JProperties.hh" #include "JAAnet/JEvtWeightFactor.hh" /** * \author bjung */ namespace JAANET {} namespace JPP { using namespace JAANET; } namespace JAANET { using JEEP::JProperties; /** * Helper class for event-weight factor. */ struct JEvtWeightFactorHelper : public std::shared_ptr { typedef std::shared_ptr pointer_type; /** * Default constructor. */ JEvtWeightFactorHelper() : pointer_type() {} /** * Constructor. * * \param p shared pointer to event-weight factor */ JEvtWeightFactorHelper(const pointer_type& p) : pointer_type(p) {} /** * Constructor. * * \param factor event-weight factor */ JEvtWeightFactorHelper(const JEvtWeightFactor& factor) { configure(factor); } /** * Configure event-weight factor. * * \param p pointer to event-weight factor */ void configure(const pointer_type& p) { static_cast(*this) = p; } /** * Configure event-weight factor. * * \param factor event-weight factor */ void configure(const JEvtWeightFactor& factor) { using namespace JPP; JEvtWeightFactor* p = dynamic_cast(factor.clone()); if (p != NULL) { this->reset(p); } else { THROW(JNullPointerException, "JEvtWeightFactorHelper::configure(): Could not retrieve event-weight factor interface."); } } /** * Get reference to event-weight factor. * * \return reference to event-weight factor */ JEvtWeightFactor& getFactor() const { using namespace JPP; if (static_cast(*this)) { return *(this->get()); } else { THROW(JNullPointerException, "JEvtWeightFactorHelper::getFactor(): Event-weight factor is not set."); } } /** * Check whether this event-weight factor is valid. * * \return true if valid; else false */ bool is_valid() const { const JEvtWeightFactorHelper& helper = static_cast(*this); return (helper && helper->is_valid()); } /** * Get weight-factor of given event. * * \param evt event * \return event-weight factor */ double getFactor(const Evt& evt) const { const JEvtWeightFactor& weightFactor = getFactor(); return weightFactor.getFactor(evt); } /** * Get weight-factor of given event. * * \param evt event * \return event-weight factor */ double operator()(const Evt& evt) const { return getFactor(evt); } /** * Get properties of this class. * * \param eqpars equation parameters */ JProperties getProperties(const JEquationParameters& eqpars = JEvtWeightFactor::getEquationParameters()) { const JEvtWeightFactor& weightFactor = getFactor(); return weightFactor.getProperties(eqpars); } /** * Get properties of this class. * * \param eqpars equation parameters */ JProperties getProperties(const JEquationParameters& eqpars = JEvtWeightFactor::getEquationParameters()) const { const JEvtWeightFactor& weightFactor = getFactor(); return weightFactor.getProperties(eqpars); } }; } #endif