Jpp  15.0.1-rc.2-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JModuleCounter.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JMODULECOUNTER__
2 #define __JTRIGGER__JMODULECOUNTER__
3 
4 #include <vector>
5 #include <algorithm>
6 
7 
8 /**
9  * \author mdejong
10  */
11 
12 namespace JTRIGGER {}
13 namespace JPP { using namespace JTRIGGER; }
14 
15 namespace JTRIGGER {
16 
17  /**
18  * Auxiliary class for counting unique modules.
19  */
20  struct JModuleCounter {
21  /**
22  * Default constructor.
23  */
25  {}
26 
27 
28  /**
29  * Count unique modules.
30  *
31  * The template parameter should correspond to a data type which provides for the following method:
32  * <pre>
33  * int getModuleID();
34  * </pre>
35  * Note that the input data are not changed.
36  *
37  * \param __begin begin of data
38  * \param __end end of data
39  * \return number of unique modules
40  */
41  template<class T>
42  int operator()(T __begin, T __end) const
43  {
44  using namespace std;
45 
46  buffer.resize(distance(__begin, __end));
47 
48  vector<int>::iterator out = buffer.begin();
49 
50  for (T i = __begin; i != __end; ++i, ++out) {
51  *out = i->getModuleID();
52  }
53 
54  sort(buffer.begin(), buffer.end());
55 
56  return distance(buffer.begin(), unique(buffer.begin(), buffer.end()));
57  }
58 
59  private:
61  };
62 
63 
64  /**
65  * Function object to count unique modules.
66  */
68 }
69 
70 #endif
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
int operator()(T __begin, T __end) const
Count unique modules.
static const JModuleCounter getNumberOfModules
Function object to count unique modules.
std::vector< int > buffer
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JModuleCounter()
Default constructor.
Auxiliary class for counting unique modules.