#ifndef __JTRIGGER__JFRAME__ #define __JTRIGGER__JFRAME__ #include #include "km3net-dataformat/online/JDAQHit.hh" #include "km3net-dataformat/online/JDAQClock.hh" #include "JTrigger/JMatch.hh" #include "JTrigger/JPMTHeader.hh" #include "JTrigger/JHitToolkit.hh" #include "JTrigger/JCalibration.hh" #include "JTrigger/JFrame_t.hh" /** * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { using KM3NETDAQ::JDAQHit; /** * Data frame for calibrated hits of one PMT. * * Note that the calibration is applied on the fly in the member method JFrame::push_back. */ template > class JFrame : public JPMTHeader, public JCalibration, public JFrame_t { public: typedef JFrame_t container_type; typedef JElement_t value_type; typedef JMatch match_type; typedef typename container_type::iterator iterator; typedef typename container_type::const_iterator const_iterator; typedef typename container_type::reverse_iterator reverse_iterator; typedef typename container_type::const_reverse_iterator const_reverse_iterator; using JHitToolkit::join; /** * Default constructor. */ JFrame() {} /** * Constructor. * * \param chronometer DAQ chronometer * \param id PMT identifier * \param axis PMT axis * \param calibration calibration */ JFrame(const JDAQChronometer& chronometer, const JDAQPMTIdentifier& id, const JAxis3D& axis, const JCalibration& calibration) : JPMTHeader (chronometer, id, axis), JCalibration(calibration), JFrame_t() {} /** * Append DAQ hit. * * The time calibration is applied before the hit is appended. * * \param hit DAQ hit */ void push_back(const JDAQHit& hit) { container_type::push_back(this->getHit(hit, this->getCalibration())); } /** * Apply high-rate veto. * * If vetoed, the container is cleared and an end marker is put. * * \param rate_Hz high-rate veto [Hz] */ void applyHighRateVeto(const double rate_Hz) { using KM3NETDAQ::getFrameTime; if (this->size() * 1.0e9 / getFrameTime() > rate_Hz) { this->reset(); } } /** * Join consecutive hits when matched according given criterion. * * \param match match criterion */ void join(const match_type& match) { iterator out = this->begin(); for (const_iterator p = this->begin(); p != this->end(); ) { *out = *p; while (++p != this->end() && match(*out,*p)) { *out = join(*out,*p); } ++out; } if (out != this->end()) { this->erase(out, this->end()); this->putEndMarker(); } } /** * Filter-out consecutive hits when matched according given criterion. * * Note that all hits which are matched are removed. * * \param match match criterion */ void filter(const match_type& match) { iterator out = this->begin(); for (const_iterator p = this->begin(); p != this->end(); ) { const_iterator q = p; for (const_iterator i = p; ++q != this->end() && match(*i,*q); ++i) {} if (std::distance(p,q) == 1) { *out = *p; ++out; } p = q; } if (out != this->end()) { this->erase(out, this->end()); this->putEndMarker(); } } }; } #endif