#ifndef __JAANET__JEVTWEIGHTHELPER__ #define __JAANET__JEVTWEIGHTHELPER__ #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/offline/Evt.hh" #include "JLang/JSharedPointer.hh" #include "JAAnet/JHead.hh" #include "JAAnet/JEvtWeight.hh" /** * \author mdejong */ namespace JAANET {} namespace JPP { using namespace JAANET; } namespace JAANET { using JLANG::JSharedPointer; /** * Helper class for event weighing. */ struct JEvtWeightHelper : public JSharedPointer, public JHead { using JSharedPointer::is_valid; /** * Default constructor. */ JEvtWeightHelper() : counter(0) {} /** * Constructor. * * \param weighter event weighter */ JEvtWeightHelper(const JEvtWeight& weighter) : counter(0) { this->configure(weighter); } /** * 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 { return (is_valid() ? get()->check(header) : false); } /** * Add header. * * \param header header */ void add(const JHead& header) { using namespace JPP; if (check(header)) { if (counter == 0) { JHead::setHeader(header); } else { JHead::add(header); } ++counter; get()->configure(getHeader()); } else { THROW(JNullPointerException, "JEvtWeightHelper::add(): headers do not match."); } } /** * Get weight of given event. * * \param evt event * \return weight [Hz] */ double getWeight(const Evt& evt) const { using namespace JPP; if (is_valid()) { return get()->getWeight(evt); } else { THROW(JNullPointerException, "JEvtWeightHelper::getWeight(): Event weighter is null."); } } /** * Get event-weight normalisation. * * \return event-weight normalisation */ double getNormalisation() const { using namespace JPP; if (is_valid()) { return get()->getNormalisation(); } else { THROW(JNullPointerException, "JEvtWeightHelper::getWeightNormalisation(): Event weighter is null."); } } /** * Get event-weight normalisation. * * \param evt event * \return event-weight normalisation */ double getNormalisation(const Evt& evt) const { using namespace JPP; if (is_valid()) { return get()->getNormalisation(evt); } else { THROW(JNullPointerException, "JEvtWeightHelper::getWeightNormalisation(): Event weighter is null."); } } private: int counter; }; } #endif