Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JModuleRouter.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JMODULEROUTER__
2 #define __JDETECTOR__JMODULEROUTER__
3 
6 #include "JDetector/JDetector.hh"
8 #include "JTools/JRouter.hh"
9 #include "JLang/JReference.hh"
10 
11 
12 /**
13  * \file
14  * Direct access to module in detector data structure.
15  * \author mdejong
16  */
17 namespace JDETECTOR {}
18 namespace JPP { using namespace JDETECTOR; }
19 
20 namespace JDETECTOR {
21 
22 
23  using JLANG::JObjectID;
24  using JLANG::JReference;
26 
27 
28  /**
29  * Router for direct addressing of module data in detector data structure.
30  *
31  * This router can be used to directly map the module identifier to
32  * the logical address of the module (JModuleAddress) in the detector data structure.
33  *
34  * Note that the required memory is determined by the range covered by the module identifiers.
35  */
36  class JModuleRouter :
37  public JReference<const JDetector>
38  {
39 
41 
42  public:
43 
44  typedef JDetector::const_iterator const_iterator;
45 
46 
47  /**
48  * Constructor.
49  *
50  * \param detector detector
51  */
53  JReference_t(detector),
55  {
56  for (const_iterator module = detector.begin(); module != detector.end(); ++module) {
57  router.put(module->getID(), JModuleAddress(std::distance(detector.begin(), module)));
58  }
59  }
60 
61 
62  /**
63  * Get module router.
64  *
65  * \return module router
66  */
68  {
69  return static_cast<const JModuleRouter&>(*this);
70  }
71 
72 
73  /**
74  * Get address of module.
75  *
76  * \param id module identifier
77  * \return address
78  */
79  const JModuleAddress& getAddress(const JObjectID& id) const
80  {
81  return router.get(id.getID());
82  }
83 
84 
85  /**
86  * Get module parameters.
87  *
88  * \param id module identifier
89  * \return module parameters
90  */
91  const JModule& getModule(const JObjectID& id) const
92  {
93  return getReference().getModule(this->getAddress(id));
94  }
95 
96 
97  /**
98  * Has module.
99  *
100  * \param id module identifier
101  * \return true if module present; else false
102  */
103  bool hasModule(const JObjectID& id) const
104  {
105  return router.has(id.getID());
106  }
107 
108 
109  /**
110  * Get index of module.
111  *
112  * \param id module identifier
113  * \return index
114  */
115  const int getIndex(const JObjectID& id) const
116  {
117  return getAddress(id).first;
118  }
119 
120 
121  /**
122  * Has PMT.
123  *
124  * \param id PMT identifier
125  * \return true if PMT present; else false
126  */
127  bool hasPMT(const JPMTIdentifier& id) const
128  {
129  return hasModule(id.getID()) && id.getPMTAddress() >= 0 && id.getPMTAddress() < (int) getModule(id.getID()).size();
130  }
131 
132 
133  /**
134  * Get PMT parameters.
135  *
136  * \param id PMT identifier
137  * \return PMT parameters
138  */
139  const JPMT& getPMT(const JPMTIdentifier& id) const
140  {
141  return getModule(id.getID()).getPMT(id.getPMTAddress());
142  }
143 
144 
145  /**
146  * Get UTM position of given module identifier.
147  *
148  * \param id module identifier
149  * \return UTM position
150  */
152  {
154  }
155 
156  private:
158  };
159 }
160 
161 #endif
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:68
Direct addressing of elements with unique identifiers.
Definition: JRouter.hh:27
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
const int getIndex(const JObjectID &id) const
Get index of module.
bool hasPMT(const JPMTIdentifier &id) const
Has PMT.
Router for direct addressing of module data in detector data structure.
JTOOLS::JRouter< JModuleAddress > router
Data structure for detector geometry and calibration.
Data structure for UTM position.
Definition: JUTMPosition.hh:36
JModuleRouter(const JDetector &detector)
Constructor.
int first
index of module in detector data structure
JDetector::const_iterator const_iterator
The template JReference class can be used to reference an object.
Definition: JReference.hh:21
Data structure for PMT geometry, calibration and status.
Definition: JPMT.hh:43
JPosition3D getPosition(const Vec &pos)
Get position.
Address of module in detector data structure.
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:173
const JPMT & getPMT(const JPMTIdentifier &id) const
Get PMT parameters.
const JClass_t & getReference() const
Get reference to object.
Definition: JReference.hh:38
Auxiliary class for object identification.
Definition: JObjectID.hh:22
const JModuleAddress & getAddress(const JObjectID &id) const
Get address of module.
const JObjectID & getUndefinedObjectID()
Get undefined object identifier.
Definition: JObjectID.hh:149
bool hasModule(const JObjectID &id) const
Has module.
JReference< const JDetector > JReference_t
do set_variable DETECTOR_TXT $WORKDIR detector
JUTMPosition getUTMPosition(const JObjectID &id) const
Get UTM position of given module identifier.
const JModuleRouter & getModuleRouter() const
Get module router.