Jpp
 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 (JModuleIdentifier) to
32  * the logical address of the module (JModuleAddress) in the detector data structure.
33  */
34  class JModuleRouter :
35  public JReference<const JDetector>
36  {
37 
39 
40  public:
41 
42  typedef JDetector::const_iterator const_iterator;
43 
44 
45  /**
46  * Constructor.
47  *
48  * \param detector detector
49  */
51  JReference_t(detector),
53  {
54  for (const_iterator module = detector.begin(); module != detector.end(); ++module) {
55  router.put(module->getID(), JModuleAddress(std::distance(detector.begin(), module)));
56  }
57  }
58 
59 
60  /**
61  * Get module router.
62  *
63  * \return module router
64  */
66  {
67  return static_cast<const JModuleRouter&>(*this);
68  }
69 
70 
71  /**
72  * Get address of module.
73  *
74  * \param id module identifier
75  * \return address
76  */
77  const JModuleAddress& getAddress(const JObjectID& id) const
78  {
79  return router.get(id.getID());
80  }
81 
82 
83  /**
84  * Get module parameters.
85  *
86  * \param id module identifier
87  * \return module parameters
88  */
89  const JModule& getModule(const JObjectID& id) const
90  {
91  return getReference().getModule(this->getAddress(id));
92  }
93 
94 
95  /**
96  * Has module.
97  *
98  * \param id module identifier
99  * \return true if module present; else false
100  */
101  bool hasModule(const JObjectID& id) const
102  {
103  return router.has(id.getID());
104  }
105 
106 
107  /**
108  * Get index of module.
109  *
110  * \param id module identifier
111  * \return index
112  */
113  const int getIndex(const JObjectID& id) const
114  {
115  return getAddress(id).first;
116  }
117 
118 
119  /**
120  * Has PMT.
121  *
122  * \param id PMT identifier
123  * \return true if PMT present; else false
124  */
125  bool hasPMT(const JPMTIdentifier& id) const
126  {
127  return hasModule(id.getID()) && id.getPMTAddress() >= 0 && id.getPMTAddress() < (int) getModule(id.getID()).size();
128  }
129 
130 
131  /**
132  * Get PMT parameters.
133  *
134  * \param id PMT identifier
135  * \return PMT parameters
136  */
137  const JPMT& getPMT(const JPMTIdentifier& id) const
138  {
139  return getModule(id.getID()).getPMT(id.getPMTAddress());
140  }
141 
142 
143  /**
144  * Get UTM position of given module identifier.
145  *
146  * \param id module identifier
147  * \return UTM position
148  */
150  {
152  }
153 
154  private:
156  };
157 }
158 
159 #endif
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:50
Direct addressing of elements with unique identifiers.
Definition: JRouter.hh:26
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:80
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:34
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 and calibration.
Definition: JPMT.hh:47
Address of module in detector data structure.
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:174
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:27
const JModuleAddress & getAddress(const JObjectID &id) const
Get address of module.
const JObjectID & getUndefinedObjectID()
Get undefined object identifier.
Definition: JObjectID.hh:169
bool hasModule(const JObjectID &id) const
Has module.
JReference< const JDetector > JReference_t
JUTMPosition getUTMPosition(const JObjectID &id) const
Get UTM position of given module identifier.
const JModuleRouter & getModuleRouter() const
Get module router.
JPosition3D getPosition(const Vec &v)
Get position.