#ifndef __JTRIGGER__JMATCH__ #define __JTRIGGER__JMATCH__ #include "JLang/JClonable.hh" /** * \file * * Base class for match operations for cluster and hit-preprocessing methods. * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { using JLANG::JClonable; /** * Function object interface for hit matching. */ template class JMatch : public JClonable< JMatch > { public: /** * Virtual destructor. */ virtual ~JMatch() {} /** * Match operator. * * \param first hit * \param second hit * \return match result */ virtual bool operator()(const JHit_t& first, const JHit_t& second) const = 0; /** * Get number of matches between given hit and data. * * \param hit hit * \param __begin begin of data * \param __end end of data * \return number of matches */ template int count(const JHit_t& hit, T __begin, T __end) const { int n = 0; for (T i = __begin; i != __end; ++i) { if ((*this)(hit,*i)) { ++n; } } return n; } }; /** * Auxiliary class to handle pointer to match function. */ template class JMatchHelper : public JClonable< JMatch , JMatchHelper > { public: typedef bool (*pFun)(const JHit_t&, const JHit_t&); //!< pointer to match function /** * Constructor * * \param match pointer to match function */ JMatchHelper(pFun match) : match(match) {} /** * Match operator. * * \param first hit * \param second hit * \return match result */ virtual bool operator()(const JHit_t& first, const JHit_t& second) const override { return match(first, second); } protected: pFun match; }; /** * Auxiliary method to make JMatch object based on pointer to match function. * * \param match pointer to match function * \return match object */ template JMatchHelper make_match(bool (*match)(const JHit_t&, const JHit_t&)) { return JMatchHelper(match); } } #endif