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"
7 #include "JTools/JRouter.hh"
8 #include "JLang/JReference.hh"
9 
10 
11 /**
12  * \file
13  * Direct access to module 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::JObjectID;
23  using JLANG::JReference;
25 
26 
27  /**
28  * Router for direct addressing of module data in detector data structure.
29  *
30  * This router can be used to directly map the module identifier (JModuleIdentifier) to
31  * the logical address of the module (JModuleAddress) in the detector data structure.
32  */
33  class JModuleRouter :
34  public JReference<const JDetector>
35  {
36 
38 
39  public:
40 
41  typedef JDetector::const_iterator const_iterator;
42 
43 
44  /**
45  * Constructor.
46  *
47  * \param detector detector
48  */
49  JModuleRouter(const JDetector& detector) :
50  JReference_t(detector),
52  {
53  for (const_iterator module = detector.begin(); module != detector.end(); ++module) {
54  router.put(module->getID(), JModuleAddress(std::distance(detector.begin(), module)));
55  }
56  }
57 
58 
59  /**
60  * Get module router.
61  *
62  * \return module router
63  */
65  {
66  return static_cast<const JModuleRouter&>(*this);
67  }
68 
69 
70  /**
71  * Get address of module.
72  *
73  * \param id module identifier
74  * \return address
75  */
76  const JModuleAddress& getAddress(const JObjectID& id) const
77  {
78  return router.get(id.getID());
79  }
80 
81 
82  /**
83  * Get module parameters.
84  *
85  * \param id module identifier
86  * \return module parameters
87  */
88  const JModule& getModule(const JObjectID& id) const
89  {
90  return getReference().getModule(this->getAddress(id));
91  }
92 
93 
94  /**
95  * Has module.
96  *
97  * \param id module identifier
98  * \return true if module present; else false
99  */
100  bool hasModule(const JObjectID& id) const
101  {
102  return router.has(id.getID());
103  }
104 
105 
106  /**
107  * Get index of module.
108  *
109  * \param id module identifier
110  * \return index
111  */
112  const int getIndex(const JObjectID& id) const
113  {
114  return getAddress(id).first;
115  }
116 
117 
118  /**
119  * Get UTM position of given module identifier.
120  *
121  * \param id module identifier
122  * \return UTM position
123  */
125  {
127  }
128 
129  private:
131  };
132 }
133 
134 #endif
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:47
Direct addressing of elements with unique identifiers.
Definition: JRouter.hh:26
Detector data structure.
Definition: JDetector.hh:77
const int getIndex(const JObjectID &id) const
Get index of module.
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:30
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
Address of module in detector data structure.
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:168
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.