#ifndef __JTRIGGER__JSUMMARYSLICEROUTER__ #define __JTRIGGER__JSUMMARYSLICEROUTER__ #include "km3net-dataformat/online/JDAQSummaryslice.hh" #include "km3net-dataformat/online/JDAQModuleIdentifier.hh" #include "JSummaryslice/JSummaryslice.hh" #include "JTools/JRouter.hh" /** * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { using KM3NETDAQ::JDAQSummaryslice; using KM3NETDAQ::JDAQSummaryFrame; using KM3NETDAQ::JDAQModuleIdentifier; using KM3NETDAQ::JSummaryslice; /** * Router for fast addressing of summary data in JDAQSummaryslice data structure * as a function of the optical module identifier. * * Note that this class derives from KM3NETDAQ::JSummaryslice * which in turn derives from KM3NETDAQ::JDAQSummaryslice so that: * - standard summary data can efficiently be updated via method JSummaryRouter::update; and * - a posteriori corrected for use in simulations via method JSummaryslice::correct. */ class JSummaryRouter : public JSummaryslice { public: /** * Default constructor. */ JSummaryRouter() : router(-1) // default address {} /** * Update router. * * \param ps pointer to new summary slice (will be overwritten) */ void update(JDAQSummaryslice* ps) { if (ps != NULL) { // reset internal router for (iterator i = this->begin(); i != this->end(); ++i) { router.put(i->getModuleID(), router.getDefaultAddress()); } this->setDAQChronometer(ps->getDAQChronometer()); this->swap(*ps); // set internal router for (iterator i = this->begin(); i != this->end(); ++i) { router.put(i->getModuleID(), std::distance(this->begin(), i)); } } } /** * Get address of module. * * \param module module * \return address */ const int getAddress(const JDAQModuleIdentifier& module) const { return router.get(module.getModuleID()); } /** * Get summary frame. * * \param module module * \return summary frame */ const JDAQSummaryFrame& getSummaryFrame(const JDAQModuleIdentifier& module) const { return (*this)[getAddress(module)]; } /** * Has summary frame. * * \param module module * \return true if module present; else false */ bool hasSummaryFrame(const JDAQModuleIdentifier& module) const { return router.has(module.getModuleID()); } private: JTOOLS::JRouter router; }; } #endif