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