Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
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
9
10
11/**
12 * \author mdejong
13 */
14
15namespace JDETECTOR {}
16namespace JPP { using namespace JDETECTOR; }
17
18namespace JDETECTOR {
19
20 /**
21 * Auxiliary class for counting unique strings.
22 */
24 /**
25 * Default constructor.
26 */
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
Data structure for detector geometry and calibration.
Direct access to module in detector data structure.
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:96
int getString() const
Get string number.
Definition JLocation.hh:135
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
file Auxiliary data structures and methods for detector calibration.
Definition JAnchor.hh:12
static const JStringCounter getNumberOfStrings
Function object to count unique strings.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for counting unique strings.
JStringCounter()
Default constructor.
std::vector< int > buffer
int operator()(const JModuleRouter &router, T __begin, T __end) const
Count unique strings.
int operator()(const JDetector &detector) const
Count unique strings.