Jpp  19.1.0
the software that should make you happy
Public Member Functions | Private Attributes | List of all members
JDETECTOR::JStringCounter Struct Reference

Auxiliary class for counting unique strings. More...

#include <JStringCounter.hh>

Public Member Functions

 JStringCounter ()
 Default constructor. More...
 
int operator() (const JDetector &detector) const
 Count unique strings. More...
 
template<class T >
int operator() (const JModuleRouter &router, T __begin, T __end) const
 Count unique strings. More...
 

Private Attributes

std::vector< int > buffer
 

Detailed Description

Auxiliary class for counting unique strings.

Definition at line 23 of file JStringCounter.hh.

Constructor & Destructor Documentation

◆ JStringCounter()

JDETECTOR::JStringCounter::JStringCounter ( )
inline

Default constructor.

Definition at line 27 of file JStringCounter.hh.

28  {}

Member Function Documentation

◆ operator()() [1/2]

int JDETECTOR::JStringCounter::operator() ( const JDetector detector) const
inline

Count unique strings.

Parameters
detectordetector
Returns
number of unique strings

Definition at line 37 of file JStringCounter.hh.

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  }
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: JSTDTypes.hh:14
std::vector< int > buffer

◆ operator()() [2/2]

template<class T >
int JDETECTOR::JStringCounter::operator() ( const JModuleRouter router,
__begin,
__end 
) const
inline

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.

Parameters
routermodule router
__beginbegin of data
__endend of data
Returns
number of unique strings

Definition at line 70 of file JStringCounter.hh.

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  }
int getString() const
Get string number.
Definition: JLocation.hh:135
const JModule & getModule(const JObjectID &id) const
Get module parameters.

Member Data Documentation

◆ buffer

std::vector<int> JDETECTOR::JStringCounter::buffer
mutableprivate

Definition at line 88 of file JStringCounter.hh.


The documentation for this struct was generated from the following file: