Jpp  18.0.0-rc.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JModuleMapper.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JMODULEMAPPER__
2 #define __JDETECTOR__JMODULEMAPPER__
3 
4 #include <vector>
5 #include <limits>
6 
7 #include "JLang/JNullType.hh"
8 #include "JMath/JMathToolkit.hh"
11 #include "JDetector/JDetector.hh"
12 
13 
14 /**
15  * \file
16  * Map of associated modules in detector.
17  * \author mdejong
18  */
19 namespace JDETECTOR {}
20 namespace JPP { using namespace JDETECTOR; }
21 
22 namespace JDETECTOR {
23 
24  using JLANG::JNullType;
25 
26 
27  /**
28  * Template method to set module attributes.
29  * This method should be overloaded for each type of module attributes.
30  *
31  * \param first first module
32  * \param second second module
33  * \param attributes module attributes
34  */
35  template<class JAttributes_t>
36  void setAttributes(const JModule& first,
37  const JModule& second,
38  JAttributes_t& attributes);
39 
40 
41  /**
42  * Template specialisation to set no attributes for the default empty object.
43  *
44  * \param first first module
45  * \param second second module
46  * \param attributes module attributes
47  */
48  template<>
50  const JModule& second,
51  JNullType& attributes)
52  {}
53 
54 
55  /**
56  * Data structure for module address and module attributes.
57  *
58  * The template argument refers to the module attributes
59  * for which the following method should be overloaded:
60  * <pre>
61  * void setAttributes(const JModule& first,
62  * const JModule& second,
63  * JAttributes_t& attributes);
64  * </pre>
65  */
66  template<class JAttributes_t>
68  public JModuleAddress,
69  public JAttributes_t
70  {
71  /**
72  * Get module attributes.
73  *
74  * \param first first module
75  * \param second second module
76  * \return module attributes
77  */
78  static const JAttributes_t& getAttributes(const JModule& first,
79  const JModule& second)
80  {
81  static JAttributes_t attributes;
82 
83  setAttributes(first, second, attributes);
84 
85  return attributes;
86  }
87 
88 
89  /**
90  * Default constructor.
91  */
94  JAttributes_t()
95  {}
96 
97 
98  /**
99  * Constructor.
100  *
101  * \param index index of module in detector data structure
102  * \param first first module
103  * \param second second module
104  */
105  JModuleAttributes(const int index,
106  const JModule& first,
107  const JModule& second) :
108  JModuleAddress(index),
109  JAttributes_t(getAttributes(first, second))
110  {}
111  };
112 
113 
114  /**
115  * Auxiliary class to match modules according maximal distance.
116  */
118  /**
119  * Constructor.
120  *
121  * \param Dmax_m maximal distance [m]
122  */
123  JMaximalDistance(const double Dmax_m) :
124  dmax(Dmax_m)
125  {}
126 
127 
128  /**
129  * Get maximal distance.
130  *
131  * \return maximal distance [m]
132  */
133  double getDmax() const
134  {
135  return dmax;
136  }
137 
138 
139  /**
140  * Test whether two module match.
141  *
142  * \param first first module
143  * \param second second module
144  * \return true if distance between modules less than limit; else false
145  */
146  bool operator()(const JModule& first, const JModule& second) const
147  {
148  return getDistance(first.getPosition(), second.getPosition()) <= dmax;
149  }
150 
151  protected:
152  double dmax;
153  };
154 
155 
156  /**
157  * Mapper for directly addressing of associated modules in the detector data structure.
158  * The template argument refers to the module attributes.
159  * Note that, by construction, a module will not be assiciated to itself.
160  */
161  template<class JAttributes_t = JNullType>
163  public JModuleRouter
164  {
165  public:
166  /**
167  * Type definition of module data.
168  */
170 
171  /**
172  * Type definition of a list with module data.
173  */
175 
176 
177  /**
178  * Constructor.
179  *
180  * \param detector detector
181  */
183  JModuleRouter(detector)
184  {
185  configure(JMaximalDistance(std::numeric_limits<double>::max()));
186  }
187 
188 
189  /**
190  * Constructor.
191  *
192  * \param router module router
193  */
195  JModuleRouter(router)
196  {
197  configure(JMaximalDistance(std::numeric_limits<double>::max()));
198  }
199 
200 
201  /**
202  * Constructor.
203  *
204  * The argument <tt>match</tt>refers to a template which should implement the following operator:
205  * <pre>
206  * bool operator()(const JModule& first, const JModule& second);
207  * </pre>
208  *
209  * \param detector detector
210  * \param match module matcher
211  */
212  template<class JMatch_t>
213  JModuleMapper(const JDetector& detector, JMatch_t match) :
214  JModuleRouter(detector)
215  {
216  configure(match);
217  }
218 
219 
220  /**
221  * Constructor.
222  *
223  * The argument <tt>match</tt>refers to a template which should implement the following operator:
224  * <pre>
225  * bool operator()(const JModule& first, const JModule& second);
226  * </pre>
227  *
228  * \param router module router
229  * \param match module matcher
230  */
231  template<class JMatch_t>
232  JModuleMapper(const JModuleRouter& router, JMatch_t match) :
233  JModuleRouter(router)
234  {
235  configure(match);
236  }
237 
238 
239  /**
240  * Get list with module data matching given module.
241  *
242  * \param id module identifier
243  * \return module data
244  */
245  const container_type& getList(const JObjectID& id) const
246  {
247  return zmap[this->getAddress(id).first];
248  }
249 
250 
251  /**
252  * Configure this module mapper.
253  *
254  * The argument <tt>match</tt>refers to a template which should implement the following operator:
255  * <pre>
256  * bool operator()(const JModule& first, const JModule& second);
257  * </pre>
258  *
259  * \param match module matcher
260  */
261  template<class JMatch_t>
262  void configure(JMatch_t match)
263  {
264  const JDetector& detector = this->getReference();
265 
266  zmap.resize(detector.size());
267 
268  for (typename std::vector<container_type>::iterator i = zmap.begin(); i != zmap.end(); ++i) {
269  i->clear();
270  }
271 
272  for (int i = 0; i != (int) detector.size(); ++i) {
273  for (int j = i; ++j != (int) detector.size(); ) {
274  if (match(detector[i], detector[j])) {
275  zmap[i].push_back(moduleattributes_type(j, detector[i], detector[j]));
276  zmap[j].push_back(moduleattributes_type(i, detector[j], detector[i]));
277  }
278  }
279  }
280  }
281 
282 
283  protected:
285  };
286 }
287 
288 #endif
JModuleAttributes< JAttributes_t > moduleattributes_type
Type definition of module data.
Auxiliary methods for geometrical methods.
void configure(JMatch_t match)
Configure this module mapper.
Data structure for a composite optical module.
Definition: JModule.hh:68
JModuleMapper(const JModuleRouter &router, JMatch_t match)
Constructor.
Detector data structure.
Definition: JDetector.hh:89
JMaximalDistance(const double Dmax_m)
Constructor.
Router for direct addressing of module data in detector data structure.
JModuleAttributes(const int index, const JModule &first, const JModule &second)
Constructor.
JModuleMapper(const JDetector &detector, JMatch_t match)
Constructor.
JModuleAttributes()
Default constructor.
double getDmax() const
Get maximal distance.
JTOOLS::JRouter< JModuleAddress > router
void setAttributes< JNullType >(const JModule &first, const JModule &second, JNullType &attributes)
Template specialisation to set no attributes for the default empty object.
Data structure for detector geometry and calibration.
std::vector< moduleattributes_type > container_type
Type definition of a list with module data.
Data structure for module address and module attributes.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
JModuleMapper(const JDetector &detector)
Constructor.
int first
index of module in detector data structure
Auxiliary class to match modules according maximal distance.
Auxiliary class for no type definition.
Definition: JNullType.hh:19
static const JAttributes_t & getAttributes(const JModule &first, const JModule &second)
Get module attributes.
Address of module in detector data structure.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
const container_type & getList(const JObjectID &id) const
Get list with module data matching given module.
void setAttributes(const JModule &first, const JModule &second, JAttributes_t &attributes)
Template method to set module attributes.
Direct access to module in detector data structure.
const JClass_t & getReference() const
Get reference to object.
Definition: JReference.hh:38
JModuleMapper(const JModuleRouter &router)
Constructor.
Mapper for directly addressing of associated modules in the detector data structure.
Auxiliary class for object identification.
Definition: JObjectID.hh:22
const JModuleAddress & getAddress(const JObjectID &id) const
Get address of module.
int j
Definition: JPolint.hh:703
bool operator()(const JModule &first, const JModule &second) const
Test whether two module match.
do set_variable DETECTOR_TXT $WORKDIR detector
std::vector< container_type > zmap