#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 consecutive hits when matched according given criterion. * * \param match match criterion */ void filter(const match_type& match) { iterator out = this->begin(); for (const_iterator p = this->begin(); p != this->end(); ) { *out = *p; for (const_iterator i = p++; p != this->end() && match(*i,*p); ++i, ++p) {} ++out; } if (out != this->end()) { this->erase(out, this->end()); this->putEndMarker(); } } /** * Remove consecutive hits when matched according given criterion. * * \param match match criterion */ void remove(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 = q++; q != this->end() && match(*i,*q); ++i, ++q) {} if (std::distance(p,q) == 1) { *out = *p; ++out; } p = q; } if (out != this->end()) { this->erase(out, this->end()); this->putEndMarker(); } } }; } #endif