Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPMT.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JPMT__
2 #define __JDETECTOR__JPMT__
3 
4 #include <istream>
5 #include <ostream>
6 #include <string>
7 #include <vector>
8 #include <map>
9 
10 #include "JLang/JType.hh"
11 #include "JLang/JObjectID.hh"
12 #include "JLang/JMultiEquals.hh"
13 #include "JLang/JException.hh"
14 #include "JGeometry3D/JAxis3D.hh"
17 #include "Jeep/JStatus.hh"
18 #include "Jeep/JVersion.hh"
19 #include "Jeep/JeepToolkit.hh"
20 #include "JIO/JSerialisable.hh"
21 
22 
23 /**
24  * \file
25  *
26  * Data structure for PMT geometry and calibration.
27  * \author mdejong
28  */
29 namespace JDETECTOR {}
30 namespace JPP { using namespace JDETECTOR; }
31 
32 namespace JDETECTOR {
33 
34  using JLANG::JType;
35  using JLANG::JObjectID;
36  using JLANG::JMultiEquals;
37  using JLANG::JTYPELIST;
40  using JEEP::JStatus;
41  using JEEP::JVersion;
42  using JIO::JReader;
43  using JIO::JWriter;
44 
45 
46  /**
47  * Data structure for PMT geometry and calibration.
48  *
49  * N.B.
50  * The axis of the PMT points in the direction of the field of view of the photo-cathode.
51  */
52  class JPMT :
53  public JObjectID,
54  public JAxis3D,
55  public JCalibration,
56  public JStatus,
57  public JMultiEquals<JPMT, JTYPELIST<JObjectID>::typelist>
58  {
59  public:
60  /**
61  * Enumeration of status bits.\n
62  * Additional status bits should be included in JGetPMTStatusBit::JGetPMTStatusBit.
63  */
65  PMT_STATUS = 0 //!< General status.
66  };
67 
68 
69  /**
70  * Default constructor.
71  */
72  JPMT() :
73  JObjectID(),
74  JAxis3D(),
75  JCalibration(),
76  JStatus()
77  {}
78 
79 
80  /**
81  * Constructor.
82  *
83  * \param id identifier
84  * \param axis axis
85  * \param status status
86  */
87  JPMT(const int& id,
88  const JAxis3D& axis,
89  const JStatus& status = JStatus()) :
90  JObjectID(id),
91  JAxis3D(axis),
92  JCalibration(),
93  JStatus(status)
94  {}
95 
96 
97  /**
98  * Constructor.
99  *
100  * \param id identifier
101  * \param axis axis
102  * \param cal calibration
103  * \param status status
104  */
105  JPMT(const int& id,
106  const JAxis3D& axis,
107  const JCalibration& cal,
108  const JStatus& status = JStatus()) :
109  JObjectID(id),
110  JAxis3D(axis),
111  JCalibration(cal),
112  JStatus(status)
113  {}
114 
115 
116  /**
117  * Get detector version.
118  */
120  {
121  static JDetectorVersion version;
122 
123  return version;
124  }
125 
126 
127  /**
128  * Set detector version.
129  *
130  * \param version version
131  */
132  static void setVersion(const JVersion& version)
133  {
134  getVersion() = JDetectorVersion(version);
135  }
136 
137 
138  /**
139  * Test PMT status.
140  *
141  * \param bit bit
142  */
143  bool has(const JPMTStatusBits_t bit) const
144  {
145  return (this->getStatus() & (1<<bit)) != 0;
146  }
147 
148 
149  /**
150  * Set PMT status.
151  *
152  * \param bit bit
153  */
154  void set(const JPMTStatusBits_t bit)
155  {
156  this->getStatus() |= (1<<bit);
157  }
158 
159 
160  /**
161  * Reset PMT status.
162  *
163  * \param bit bit
164  */
165  void reset(const JPMTStatusBits_t bit)
166  {
167  this->getStatus() &= ~(1<<bit);
168  }
169 
170 
171  /**
172  * Dot product.
173  *
174  * The dot product is evaluated for the PMT orientation.
175  *
176  * \param pmt PMT
177  * \return dot product
178  */
179  inline double getDot(const JPMT& pmt) const
180  {
181  return this->getDirection().getDot(pmt.getDirection());
182  }
183 
184 
185  /**
186  * Read PMT from input.
187  *
188  * \param in input stream
189  * \param pmt PMT
190  * \return input stream
191  */
192  friend inline std::istream& operator>>(std::istream& in, JPMT& pmt)
193  {
194  in >> static_cast<JObjectID&> (pmt);
195  in >> static_cast<JAxis3D&> (pmt);
196  in >> static_cast<JCalibration&>(pmt);
197 
199  in >> static_cast<JStatus&>(pmt);
200  }
201 
202  return in;
203  }
204 
205 
206  /**
207  * Write PMT to output.
208  *
209  * \param out output stream
210  * \param pmt PMT
211  * \return output stream
212  */
213  friend inline std::ostream& operator<<(std::ostream& out, const JPMT& pmt)
214  {
215  out << static_cast<const JObjectID&> (pmt);
216  out << ' ';
217  out << static_cast<const JAxis3D&> (pmt);
218  out << ' ';
219  out << static_cast<const JCalibration&>(pmt);
220 
222  out << ' ';
223  out << static_cast<const JStatus&>(pmt);
224  }
225 
226  return out;
227  }
228 
229 
230  /**
231  * Read PMT from input.
232  *
233  * \param in reader
234  * \param pmt PMT
235  * \return reader
236  */
237  friend inline JReader& operator>>(JReader& in, JPMT& pmt)
238  {
239  in >> static_cast<JObjectID&> (pmt);
240  in >> static_cast<JAxis3D&> (pmt);
241  in >> static_cast<JCalibration&>(pmt);
242 
244  in >> static_cast<JStatus&>(pmt);
245  }
246 
247  return in;
248  }
249 
250 
251  /**
252  * Write PMT to output.
253  *
254  * \param out writer
255  * \param pmt PMT
256  * \return writer
257  */
258  friend inline JWriter& operator<<(JWriter& out, const JPMT& pmt)
259  {
260  out << static_cast<const JObjectID&> (pmt);
261  out << static_cast<const JAxis3D&> (pmt);
262  out << static_cast<const JCalibration&>(pmt);
263 
265  out << static_cast<const JStatus&>(pmt);
266  }
267 
268  return out;
269  }
270  };
271 
272 
273 
274  /**
275  * Auxiliary class to map key to PMT status bit.
276  */
278  public std::map<std::string, JPMT::JPMTStatusBits_t>
279  {
280  /**
281  * Default constructor.
282  */
284  {
285  using namespace JPP;
286 
287 #define MAKE_ENTRY(A) std::make_pair(getClassname(#A), A)
288 
289  this->insert(MAKE_ENTRY(JPMT::PMT_STATUS));
290 
291 #undef MAKE_ENTRY
292  }
293 
294 
295  /**
296  * Get PMT status bit.
297  *
298  * \param key key
299  * \return bit
300  */
301  JPMT::JPMTStatusBits_t operator()(const std::string& key) const
302  {
303  const_iterator i = this->find(key);
304 
305  if (i != this->end()) {
306 
307  return i->second;
308 
309  } else {
310 
311  THROW(JTypeInformationException, "Invalid key <" << key << ">");
312  }
313  }
314  };
315 
316 
317  /**
318  * Auxiliary class to map PMT status bit to key.
319  */
321  public std::map<JPMT::JPMTStatusBits_t, std::string>
322  {
323  /**
324  * Constructor.
325  *
326  * \param input PMT status bits
327  */
329  {
330  using namespace std;
331 
332  for (JGetPMTStatusBit::const_iterator i = input.begin(); i != input.end(); ++i) {
333  this->insert(make_pair(i->second, i->first));
334  }
335  }
336 
337 
338  /**
339  * Put PMT status bit.
340  *
341  * \param bit bit
342  * \return bit
343  */
344  const std::string& operator()(const JPMT::JPMTStatusBits_t bit) const
345  {
346  using namespace JPP;
347 
348  const_iterator i = this->find(bit);
349 
350  if (i != this->end()) {
351 
352  return i->second;
353 
354  } else {
355 
356  THROW(JTypeInformationException, "Invalid status bit <" << bit << ">");
357  }
358  }
359  };
360 
361 
362  /**
363  * Function object to map key to PMT status bit.
364  */
366 
367 
368  /**
369  * Function object to map PMT status bit to key.
370  */
371  static const JPutPMTStatusBit putPMTStatusBit(getPMTStatusBit);
372 
373 
374  /**
375  * Get PMT status bits.
376  *
377  * \param type type
378  * \return status bits
379  */
381  {
383 
384  for (JPutPMTStatusBit::const_iterator i = putPMTStatusBit.begin(); i != putPMTStatusBit.end(); ++i) {
385  buffer.push_back(i->second);
386  }
387 
388  return buffer;
389  }
390 
391 
392  /**
393  * Get PMT status bits.
394  *
395  * \param type type
396  * \return status bits
397  */
399  {
401 
402  for (JPutPMTStatusBit::const_iterator i = putPMTStatusBit.begin(); i != putPMTStatusBit.end(); ++i) {
403  buffer.push_back(i->first);
404  }
405 
406  return buffer;
407  }
408 
409 
410  /**
411  * Get PMT status bits.
412  *
413  * \return status bits
414  */
415  template<class T>
417  {
418  return getPMTStatusBits(JType<T>());
419  }
420 }
421 
422 #endif
void set(const JPMTStatusBits_t bit)
Set PMT status.
Definition: JPMT.hh:154
static const JGetPMTStatusBit getPMTStatusBit
Function object to map key to PMT status bit.
Definition: JPMT.hh:365
Exception for absence of type information.
Definition: JException.hh:594
Exceptions.
Interface for binary output.
std::vector< std::string > getPMTStatusBits(const JType< std::string > &type)
Get PMT status bits.
Definition: JPMT.hh:380
PMT calibration (including definition of sign of time offset).
const JDirection3D & getDirection() const
Get direction.
friend JReader & operator>>(JReader &in, JPMT &pmt)
Read PMT from input.
Definition: JPMT.hh:237
Auxiliary class to map PMT status bit to key.
Definition: JPMT.hh:320
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
JPMT(const int &id, const JAxis3D &axis, const JCalibration &cal, const JStatus &status=JStatus())
Constructor.
Definition: JPMT.hh:105
friend std::ostream & operator<<(std::ostream &out, const JPMT &pmt)
Write PMT to output.
Definition: JPMT.hh:213
Auxiliary class to map key to PMT status bit.
Definition: JPMT.hh:277
Data structure for PMT calibration.
Auxiliary class for a type holder.
Definition: JType.hh:19
JPMT()
Default constructor.
Definition: JPMT.hh:72
friend std::istream & operator>>(std::istream &in, JPMT &pmt)
Read PMT from input.
Definition: JPMT.hh:192
double getDot(const JAngle3D &angle) const
Get dot product.
Template definition of auxiliary base class for composite data structures composed of base classes wi...
Definition: JMultiEquals.hh:31
Axis object.
Definition: JAxis3D.hh:37
General status.
Definition: JPMT.hh:65
JPutPMTStatusBit(const JGetPMTStatusBit &input)
Constructor.
Definition: JPMT.hh:328
JPMT(const int &id, const JAxis3D &axis, const JStatus &status=JStatus())
Constructor.
Definition: JPMT.hh:87
static const JPutPMTStatusBit putPMTStatusBit(getPMTStatusBit)
Function object to map PMT status bit to key.
Version with PMT status field and comments.
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:377
Auxiliary methods for handling file names, type names and environment.
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:52
Data structure for detector version.
Interface for binary input.
void reset(const JPMTStatusBits_t bit)
Reset PMT status.
Definition: JPMT.hh:165
static const JGetDetectorVersion getDetectorVersion
Function object to map detector variant to detector version.
bool has(const JPMTStatusBits_t bit) const
Test PMT status.
Definition: JPMT.hh:143
Auxiliary class for version identifier.
Definition: JVersion.hh:30
static void setVersion(const JVersion &version)
Set detector version.
Definition: JPMT.hh:132
friend JWriter & operator<<(JWriter &out, const JPMT &pmt)
Write PMT to output.
Definition: JPMT.hh:258
JStatus()
Default constructor.
Definition: JStatus.hh:36
Auxiliary class for object identification.
Definition: JObjectID.hh:27
JGetPMTStatusBit()
Default constructor.
Definition: JPMT.hh:283
#define MAKE_ENTRY(A)
static JDetectorVersion & getVersion()
Get detector version.
Definition: JPMT.hh:119
int getStatus() const
Get status.
Definition: JStatus.hh:56
const std::string & operator()(const JPMT::JPMTStatusBits_t bit) const
Put PMT status bit.
Definition: JPMT.hh:344
Auxiliary class for status identifier.
Definition: JStatus.hh:29
JPMT::JPMTStatusBits_t operator()(const std::string &key) const
Get PMT status bit.
Definition: JPMT.hh:301
double getDot(const JPMT &pmt) const
Dot product.
Definition: JPMT.hh:179
JPMTStatusBits_t
Enumeration of status bits.
Definition: JPMT.hh:64