Jpp  18.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JLocationRouter.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JLOCATIONROUTER__
2 #define __JDETECTOR__JLOCATIONROUTER__
3 
4 #include "JDetector/JLocation.hh"
6 #include "JDetector/JDetector.hh"
7 #include "JTools/JHashMap.hh"
8 #include "JLang/JReference.hh"
9 
10 
11 /**
12  * \file
13  * Direct access to location in detector data structure.
14  * \author mdejong
15  */
16 namespace JDETECTOR {}
17 namespace JPP { using namespace JDETECTOR; }
18 
19 namespace JDETECTOR {
20 
21 
22  using JLANG::JReference;
23 
24 
25  /**
26  * Router for direct addressing of location data in detector data structure.
27  */
29  public JReference<const JDetector>
30  {
31 
33 
34  public:
35 
36  typedef JDetector::const_iterator const_iterator;
37 
38 
39  /**
40  * Constructor.
41  *
42  * \param detector detector
43  */
45  JReference_t(detector)
46  {
47  for (const_iterator module = detector.begin(); module != detector.end(); ++module) {
48  router[module->getString()][module->getFloor()] = JModuleAddress(std::distance(detector.begin(), module));
49  }
50  }
51 
52 
53  /**
54  * Get location router.
55  *
56  * \return location router
57  */
59  {
60  return static_cast<const JLocationRouter&>(*this);
61  }
62 
63 
64  /**
65  * Get address of location.
66  *
67  * \param location location
68  * \return address
69  */
70  const JModuleAddress& getAddress(const JLocation& location) const
71  {
72  return router[location.getString()][location.getFloor()];
73  }
74 
75 
76  /**
77  * Get module parameters.
78  *
79  * \param location location
80  * \return module parameters
81  */
82  const JModule& getModule(const JLocation& location) const
83  {
84  return getReference().getModule(this->getAddress(location));
85  }
86 
87 
88  /**
89  * Has module.
90  *
91  * \param location location
92  * \return true if location present; else false
93  */
94  bool hasLocation(const JLocation& location) const
95  {
96  return router.has(location.getString()) && router[location.getString()].has(location.getFloor());
97  }
98 
99 
100  /**
101  * Get index of location.
102  *
103  * \param location location
104  * \return index
105  */
106  const int getIndex(const JLocation& location) const
107  {
108  return getAddress(location).first;
109  }
110 
111  private:
113  };
114 }
115 
116 #endif
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
Data structure for a composite optical module.
Definition: JModule.hh:67
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:72
JDetector::const_iterator const_iterator
General purpose class for hash map of unique elements.
Detector data structure.
Definition: JDetector.hh:89
bool hasLocation(const JLocation &location) const
Has module.
const JModule & getModule(const JLocation &location) const
Get module parameters.
JLocationRouter(const JDetector &detector)
Constructor.
JTOOLS::JHashMap< int, JTOOLS::JHashMap< int, JModuleAddress > > router
Data structure for detector geometry and calibration.
int first
index of module in detector data structure
Router for direct addressing of location data in detector data structure.
Logical location of module.
Definition: JLocation.hh:37
The template JReference class can be used to reference an object.
Definition: JReference.hh:21
const JLocationRouter & getLocationRouter() const
Get location router.
Address of module in detector data structure.
const JModuleAddress & getAddress(const JLocation &location) const
Get address of location.
Logical location of module.
int getString() const
Get string number.
Definition: JLocation.hh:134
const JClass_t & getReference() const
Get reference to object.
Definition: JReference.hh:38
JReference< const JDetector > JReference_t
do set_variable DETECTOR_TXT $WORKDIR detector
const int getIndex(const JLocation &location) const
Get index of location.