Jpp
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 #endif
JTRIGGER::JModuleCounter::JModuleCounter
JModuleCounter()
Default constructor.
Definition: JModuleCounter.hh:24
std::vector
Definition: JSTDTypes.hh:12
JTRIGGER::JModuleCounter::buffer
std::vector< int > buffer
Definition: JModuleCounter.hh:60
distance
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: PhysicsEvent.hh:434
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTRIGGER::JModuleCounter
Auxiliary class for counting unique modules.
Definition: JModuleCounter.hh:20
std
Definition: jaanetDictionary.h:36
JTRIGGER::JModuleCounter::operator()
int operator()(T __begin, T __end) const
Count unique modules.
Definition: JModuleCounter.hh:42
JTRIGGER
Checksum.
Definition: JSupport/JSupport.hh:35