Jpp  15.0.5
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JStringCounter.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JSTRINGCOUNTER__
2 #define __JDETECTOR__JSTRINGCOUNTER__
3 
4 #include <vector>
5 #include <algorithm>
6 
7 #include "JDetector/JDetector.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JDETECTOR {}
16 namespace JPP { using namespace JDETECTOR; }
17 
18 namespace JDETECTOR {
19 
20  /**
21  * Auxiliary class for counting unique strings.
22  */
23  struct JStringCounter {
24  /**
25  * Default constructor.
26  */
28  {}
29 
30 
31  /**
32  * Count unique strings.
33  *
34  * \param detector detector
35  * \return number of unique strings
36  */
37  inline int operator()(const JDetector& detector) const
38  {
39  using namespace std;
40 
41  buffer.resize(detector.size());
42 
43  vector<int>::iterator out = buffer.begin();
44 
45  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module, ++out) {
46  *out = module->getString();
47  }
48 
49  sort(buffer.begin(), buffer.end());
50 
51  return distance(buffer.begin(), unique(buffer.begin(), buffer.end()));
52  }
53 
54 
55  /**
56  * Count unique strings.
57  *
58  * The template parameter should correspond to a data type which provides for the following method:
59  * <pre>
60  * int getModuleID();
61  * </pre>
62  * Note that the input data are not changed.
63  *
64  * \param router module router
65  * \param __begin begin of data
66  * \param __end end of data
67  * \return number of unique strings
68  */
69  template<class T>
70  int operator()(const JModuleRouter& router, T __begin, T __end) const
71  {
72  using namespace std;
73 
74  buffer.resize(distance(__begin, __end));
75 
76  vector<int>::iterator out = buffer.begin();
77 
78  for (T i = __begin; i != __end; ++i, ++out) {
79  *out = router.getModule(i->getModuleID()).getString();
80  }
81 
82  sort(buffer.begin(), buffer.end());
83 
84  return distance(buffer.begin(), unique(buffer.begin(), buffer.end()));
85  }
86 
87  private:
89  };
90 
91 
92  /**
93  * Function object to count unique strings.
94  */
96 }
97 
98 #endif
const JModule & getModule(const JObjectID &id) const
Get module parameters.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
int operator()(const JModuleRouter &router, T __begin, T __end) const
Count unique strings.
int operator()(const JDetector &detector) const
Count unique strings.
Data structure for detector geometry and calibration.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
static const JStringCounter getNumberOfStrings
Function object to count unique strings.
Direct access to module in detector data structure.
std::vector< int > buffer
Auxiliary class for counting unique strings.
do set_variable DETECTOR_TXT $WORKDIR detector
JStringCounter()
Default constructor.