#ifndef __JHITTOOLKIT__ #define __JHITTOOLKIT__ #include #include #include "JDAQ/JDAQHit.hh" #include "JTrigger/JHit.hh" #include "JTrigger/JCalibration.hh" namespace JTRIGGER { namespace { using KM3NETDAQ::JDAQHit; using std::numeric_limits; } /** * Get calibrated time of hit. * * \param hit DAQ hit * \param cal calibration * \return time [ns] */ inline double getTime(const JDAQHit& hit, const JCalibration& cal) { return hit.getT() + cal.getT0(); } /** * Template definition of hit tool kit. * * The specialised class should provide implementations for * the methods and operators that are used by the trigger. */ template struct JTemplateHitToolkit; /** * Template specialisation of hit tool kit for JHit class. */ template<> struct JTemplateHitToolkit : public std::binary_function { /** * Get time of hit. * * \param hit hit * \return time of hit [ns] */ static inline double getT(const JHit& hit) { return hit.getT(); } /** * Construct JHit. * * \param hit hit * \return hit */ static inline JHit getJHit(const JHit& hit) { return hit; } /** * Construct hit. * * \param hit DAQ hit * \param cal calibration * \return hit */ static inline JHit getHit(const JDAQHit& hit, const JCalibration& cal) { //return JHit(getTime(hit, cal), hit); return JHit(getTime(hit, cal)); } /** * Get end marker. * * \return latest possible hit */ static inline JHit getEndMarker() { //return JHit(numeric_limits::max(), JDAQHit()); return JHit(numeric_limits::max()); } /** * Get time difference between two hits. * * \param first first hit * \param second second hit * \return time second hit - time first hit [ns] */ static inline double getTimeDifference(const JHit& first, const JHit& second) { return getT(second) - getT(first); } /** * Compare time of two hits. * * \param first first value [ns] * \param second second value [ns] * \return true if second hit later; else false */ inline bool operator()(const JHit& first, const JHit& second) const { return getT(first) < getT(second); } }; /** * Template specialisation of hit tool kit for any primitive data type. */ template struct JTemplateHitToolkit : public std::binary_function { /** * Get time of hit. * * \param hit hit * \return time of hit [ns] */ static inline JHit_t getT(const JHit_t hit) { return hit; } /** * Construct JHit. * * \param hit hit * \return hit */ static inline JHit getJHit(const JHit_t hit) { return JHit(hit); } /** * Construct hit. * * \param hit DAQ hit * \param cal calibration * \return hit */ static inline JHit_t getHit(const JDAQHit& hit, const JCalibration& cal) { return getTime(hit, cal); } /** * Get end marker. * * \return latest possible hit */ static inline JHit_t getEndMarker() { return numeric_limits::max(); } /** * Get time difference between two hits. * * \param first first hit * \param second second hit * \return time second hit - time first hit [ns] */ static inline JHit_t getTimeDifference(const JHit_t first, const JHit_t second) { return second - first; } /** * Compare time of two hits. * * \param first first value [ns] * \param second second value [ns] * \return true if second hit later; else false */ inline bool operator()(const JHit_t first, const JHit_t second) const { return first < second; } }; /** * Hit tool kit. */ template class JHitToolkit : public JTemplateHitToolkit::is_specialized> { public: /** * Default constructor. */ JHitToolkit() : JTemplateHitToolkit::is_specialized>() {} /** * Get toolkit. * * \return this JHitToolkit */ const JHitToolkit& getToolkit() const { return *this; } }; } #endif