#ifndef __JTRIGGER__JTRIGGERTOOLKIT__ #define __JTRIGGER__JTRIGGERTOOLKIT__ #include "km3net-dataformat/online/JDAQFrameStatus.hh" #include "km3net-dataformat/online/JDAQSummaryFrame.hh" #include "km3net-dataformat/definitions/pmt_status.hh" #include "JDetector/JTimeRange.hh" #include "JDetector/JModule.hh" #include "JPhysics/JConstants.hh" #include "JTrigger/JTriggerParameters.hh" #include "Jeep/JStatus.hh" /** * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } /** * Trigger algorithms, support classes and auxiliary methods. */ namespace JTRIGGER { using KM3NETDAQ::JDAQFrameStatus; using KM3NETDAQ::JDAQSummaryFrame; using JDETECTOR::JTimeRange; using JDETECTOR::JModule; using JEEP::JStatus; /** * Get time range of snapshot. * * \param parameters trigger parameters * \return time range [ns] */ inline JTimeRange getTimeRange(const JTriggerParameters& parameters) { return JTimeRange(-parameters.TMaxEvent_ns, +parameters.TMaxEvent_ns); } /** * Get time range of snapshot. * * \param parameters trigger parameters * \return time range [ns] */ inline JTimeRange getTimeRange(const JTriggerNB_t::JParameters& parameters) { using namespace JPP; return JTimeRange(0.0, parameters.DMax_m * getIndexOfRefraction() * getInverseSpeedOfLight()); } /** * Test status of DAQ. * * The DAQ test passes if the assembly of UDP packets is complete.\n * The test can be bypassed using the PMT control status. * * \param frame data frame status * \param status PMT control status * \return true if test passes; else false */ inline bool getDAQStatus(const JDAQFrameStatus& frame, const JStatus& status) { return ((status.has(UDP_COUNTER_DISABLE) || (frame.getUDPNumberOfReceivedPackets() == frame.getUDPMaximalSequenceNumber() + 1)) && (status.has(UDP_TRAILER_DISABLE) || (frame.hasUDPTrailer()))); } /** * Test status of DAQ. * * The DAQ test passes if the assembly of UDP packets is complete.\n * The test can be bypassed using the PMT control status. * * \param frame data frame status * \param module module * \param pmt PMT number * \return true if test passes; else false */ inline bool getDAQStatus(const JDAQFrameStatus& frame, const JModule& module, const int pmt) { return getDAQStatus(frame, module.getPMT(pmt)); } /** * Test status of PMT. * * The PMT test passes if it is not disabled. * * \param status PMT control status * \return true if test passes; else false */ inline bool getPMTStatus(const JStatus& status) { return !status.has(PMT_DISABLE); } /** * Test status of PMT. * * The PMT test passes if it is not disabled and no high-rate veto or FIFO (almost) full.\n * The test can be bypassed using the PMT control status. * * \param frame data frame * \param status PMT control status * \param pmt PMT number * \return true if test passes; else false */ inline bool getPMTStatus(const JDAQFrameStatus& frame, const JStatus& status, const int pmt) { return ((status.has(HIGH_RATE_VETO_DISABLE) || !frame.testHighRateVeto(pmt)) && (status.has(FIFO_FULL_DISABLE) || !frame.testFIFOStatus (pmt)) && (getPMTStatus(status))); } /** * Test status of PMT. * * The PMT test passes if it is not disabled and no high-rate veto or FIFO (almost) full.\n * The test can be bypassed using the PMT control status. * * \param frame data frame * \param module module * \param pmt PMT number * \return true if test passes; else false */ inline bool getPMTStatus(const JDAQFrameStatus& frame, const JModule& module, const int pmt) { return getPMTStatus(frame, module.getPMT(pmt), pmt); } /** * Get corrected rate of PMT. * * The measured rate is corrected for the possible loss of UDP packets. * * \param frame data frame * \param pmt PMT number * \param factor scaling factor * \return rate x scaling factor [Hz] */ inline double getRate(const JDAQSummaryFrame& frame, const int pmt, const double factor = 1.0) { double rate_Hz = frame.getRate(pmt, factor); // correct measured rate for UDP packet loss const int n1 = frame.getUDPNumberOfReceivedPackets(); const int n2 = frame.getUDPMaximalSequenceNumber (); if (n1 < n2 + 1) { rate_Hz *= (double) (n2 + 1) / (double) n1; } return rate_Hz; } } #endif