#ifndef __JAANET__JEVTWEIGHTHELPER__ #define __JAANET__JEVTWEIGHTHELPER__ #include #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/offline/Evt.hh" #include "JAAnet/JHead.hh" #include "JAAnet/JEvtWeight.hh" /** * \author mdejong */ namespace JAANET {} namespace JPP { using namespace JAANET; } namespace JAANET { /** * Helper class for event weighing. */ struct JEvtWeightHelper : public JHead, public std::shared_ptr { /** * Default constructor. */ JEvtWeightHelper() : counter(0) {} /** * Constructor. * * \param weighter event weighter */ JEvtWeightHelper(const JEvtWeight& weighter) : counter(0) { this->configure(weighter); } /** * Get name. * * \return name */ const char* const getName() const { return getEvtWeighter().getName(); } /** * Configuration. * * \param weighter event weighter */ void configure(const JEvtWeight& weighter) { counter = 0; reset(weighter.clone()); } /** * Check if a given header is consistent with this event weighter. * * \param header header * \return true if header is consistent with this event weighter; else false. */ bool check(const JHead& header) const { const JEvtWeight& weighter = getEvtWeighter(); return weighter.check(header); } /** * Get reference to event-weighter. * * \return reference to event-weighter */ JEvtWeight& getEvtWeighter() const { using namespace JPP; if (static_cast(*this)) { return *(this->get()); } else { THROW(JNullPointerException, "JEvtWeightHelper::getEvtWeighter(): Event-weighter is not set."); } } /** * Add header. * * \param header header */ void add(const JHead& header) { using namespace JPP; JEvtWeight& weighter = getEvtWeighter(); if (check(header)) { if (counter == 0) { JHead::setHeader(header); } else { JHead::add(header); } ++counter; weighter.configure(getHeader()); } else { THROW(JValueOutOfRange, "JEvtWeightHelper::add(): headers do not match."); } } /** * Get weight of given event. * * \param evt event * \return weight [Hz] */ double getWeight(const Evt& evt) const { const JEvtWeight& weighter = getEvtWeighter(); return weighter.getWeight(evt); } /** * Get event-weight normalisation. * * \return event-weight normalisation */ double getNormalisation() const { const JEvtWeight& weighter = getEvtWeighter(); return weighter.getNormalisation(); } /** * Get event-weight normalisation. * * \param evt event * \return event-weight normalisation */ double getNormalisation(const Evt& evt) const { const JEvtWeight& weighter = getEvtWeighter(); return weighter.getNormalisation(evt); } private: int counter; //!< Counter to check how many headers have been added }; } #endif