#ifndef __JDETECTOR__JSTRINGCOUNTER__ #define __JDETECTOR__JSTRINGCOUNTER__ #include #include #include "JDetector/JDetector.hh" #include "JDetector/JModuleRouter.hh" /** * \author mdejong */ namespace JDETECTOR {} namespace JPP { using namespace JDETECTOR; } namespace JDETECTOR { /** * Auxiliary class for counting unique strings. */ struct JStringCounter { /** * Default constructor. */ JStringCounter() {} /** * Count unique strings. * * \param detector detector * \return number of unique strings */ inline int operator()(const JDetector& detector) const { using namespace std; buffer.resize(detector.size()); vector::iterator out = buffer.begin(); for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module, ++out) { *out = module->getString(); } sort(buffer.begin(), buffer.end()); return distance(buffer.begin(), unique(buffer.begin(), buffer.end())); } /** * Count unique strings. * * 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 router module router * \param __begin begin of data * \param __end end of data * \return number of unique strings */ template int operator()(const JModuleRouter& router, 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 = router.getModule(i->getModuleID()).getString(); } sort(buffer.begin(), buffer.end()); return distance(buffer.begin(), unique(buffer.begin(), buffer.end())); } private: mutable std::vector buffer; }; /** * Function object to count unique strings. */ static const JStringCounter getNumberOfStrings; } #endif