#ifndef __JTRIGGER__JMODULECOUNTER__ #define __JTRIGGER__JMODULECOUNTER__ #include #include /** * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { /** * Auxiliary class for counting unique modules. */ struct JModuleCounter { /** * Default constructor. */ JModuleCounter() {} /** * Count unique modules. * * The template parameter should correspond to a data type which provides for the following method: *
     *        int getModuleID();
     * 
* Note that the input data are not changed. * * \param __begin begin of data * \param __end end of data * \return number of unique modules */ template int operator()(T __begin, T __end) const { using namespace std; buffer.resize(distance(__begin, __end)); vector::iterator out = buffer.begin(); for (T i = __begin; i != __end; ++i, ++out) { *out = i->getModuleID(); } sort(buffer.begin(), buffer.end()); return distance(buffer.begin(), unique(buffer.begin(), buffer.end())); } private: mutable std::vector buffer; }; /** * Function object to count unique modules. */ static const JModuleCounter getNumberOfModules; } #endif