#ifndef __JDAQEVALUATOR__ #define __JDAQEVALUATOR__ #include #include "km3net-dataformat/online/JDAQUTCExtended.hh" #include "km3net-dataformat/online/JDAQHeader.hh" #include "km3net-dataformat/online/JDAQEventHeader.hh" #include "JLang/JComparable.hh" /** * \author mdejong */ namespace KM3NETDAQ { using JLANG::JComparable; /** * Auxiliary class to determine time of DAQ objects. * * The time is relative to the fixed time defined in JDAQUTCExtended.\n * For DAQ events, the time is offset by the product of the event counter and a constant weight.\n * To correlate DAQ events with summary data, the weight should be set to a value such that * this product is strictly less than half of the frame duration. */ struct JDAQEvaluator { /** * Type definition of time value. */ struct value_type : public JComparable { static inline JTriggerCounter_t min() { return std::numeric_limits::min(); } //!< minimal counter value static inline JTriggerCounter_t max() { return std::numeric_limits::max(); } //!< maximal counter value /** * Default constructor. */ value_type() {} /** * Constructor. */ value_type(const JDAQUTCExtended& utc, const JTriggerCounter_t counter) : utc (utc), counter(counter) {} /** * Less-than method. * * \param value value * \return true if this value less than given value; else false */ bool less(const value_type& value) const { if (this->utc == value.utc && this->counter != max() && value.counter != max()) return this->counter < value.counter; else return this->utc < value.utc; } /** * Subtraction operator. * * \param first first value * \param second second value * \return difference */ friend inline double operator-(const value_type& first, const value_type& second) { if (first.utc == second.utc && first.counter != max() && second.counter != max()) return ((double) first.counter - (double) second.counter) / ((double) JDAQEvaluator::value_type::max()); else return getTimeDifference(second.utc, first.utc); } JDAQUTCExtended utc; JTriggerCounter_t counter; }; /** * Default constructor. */ JDAQEvaluator() {} /** * Get time of object. * * \param object UTC time * \return time */ inline value_type operator()(const JDAQUTCExtended& object) const { return value_type(object, JDAQEvaluator::value_type::max()); } /** * Get time of object. * * \param object DAQ header * \return time */ inline value_type operator()(const JDAQHeader& object) const { return (*this)(object.getTimesliceStart()); } /** * Get time of event. * * \param object event header * \return time */ inline value_type operator()(const JDAQEventHeader& object) const { return value_type(object.getTimesliceStart(), object.getCounter()); } }; /** * Function object for evaluation of DAQ objects. */ static const JDAQEvaluator getDAQValue; } #endif