Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDetectorVersion.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JDETECTORVERSION__
2 #define __JDETECTOR__JDETECTORVERSION__
3 
4 #include <istream>
5 #include <ostream>
6 #include <string>
7 #include <vector>
8 #include <map>
9 
10 #include "JIO/JSerialisable.hh"
11 #include "JIO/JSTDIO.hh"
12 #include "JLang/JType.hh"
13 #include "JLang/JLangToolkit.hh"
14 #include "JLang/JException.hh"
15 #include "JLang/JVectorize.hh"
16 #include "JDetector/JVersion.hh"
17 #include "Jeep/JeepToolkit.hh"
18 
19 
20 /**
21  * \file
22  *
23  * Data structure for detector version.
24  * \author mdejong
25  */
26 namespace JDETECTOR {}
27 namespace JPP { using namespace JDETECTOR; }
28 
29 namespace JDETECTOR {
30 
31  using JLANG::JType;
33  using JLANG::JIOException;
34  using JIO::JReader;
35  using JIO::JWriter;
36 
37 
38  /**
39  * Detector version.
40  */
41  struct JDetectorVersion :
42  public JVersion
43  {
44  /**
45  * Enumeration of version types.\n
46  * Note that additional version types should be included in JGetDetectorVersion::JGetDetectorVersion.
47  */
48  enum JVersion_t {
49  V1 = 1, //!< First version
50  V2 = 2, //!< Version with UTC time and UTM position data
51  V3 = 3, //!< Version with PMT status field and comments
52  V4 = 4 //!< Version with quaternion and time offset per module
53  };
54 
55 
56  /**
57  * Default constructor.
58  */
60  JVersion()
61  {}
62 
63 
64  /**
65  * Constructor.
66  *
67  * \param version version
68  */
70  JVersion(version)
71  {}
72 
73 
74  /**
75  * Read version from input.
76  *
77  * \param in input stream
78  * \param version version
79  * \return input stream
80  */
81  friend inline std::istream& operator>>(std::istream& in, JDetectorVersion& version)
82  {
83  return in >> version.version;
84  }
85 
86 
87  /**
88  * Write version to output.
89  *
90  * \param out output stream
91  * \param version version
92  * \return output stream
93  */
94  friend inline std::ostream& operator<<(std::ostream& out, const JDetectorVersion& version)
95  {
96  return out << version.version;
97  }
98 
99 
100  /**
101  * Read version from input.
102  *
103  * \param in reader
104  * \param version version
105  * \return reader
106  */
108  {
109  return in >> version.version;
110  }
111 
112 
113  /**
114  * Write version to output.
115  *
116  * \param out writer
117  * \param version version
118  * \return writer
119  */
120  friend inline JWriter& operator<<(JWriter& out, const JDetectorVersion& version)
121  {
122  return out << version.version;
123  }
124  };
125 
126 
127  /**
128  * Auxiliary class to map detector version to numerical value.
129  */
131  public std::map<std::string, JDetectorVersion::JVersion_t>
132  {
133  /**
134  * Default constructor.
135  */
137  {
138  using namespace JPP;
139 
140 #define MAKE_ENTRY(A) std::make_pair(to_upper(getClassname(#A)), A)
141 
142  this->insert(MAKE_ENTRY(JDetectorVersion::V1));
143  this->insert(MAKE_ENTRY(JDetectorVersion::V2));
144  this->insert(MAKE_ENTRY(JDetectorVersion::V3));
145  this->insert(MAKE_ENTRY(JDetectorVersion::V4));
146 
147 #undef MAKE_ENTRY
148  }
149 
150 
151  /**
152  * Get numerical value.
153  *
154  * \param version version
155  * \return numerical value
156  */
158  {
159  using namespace JPP;
160 
161  const_iterator i = this->find(to_upper(version));
162 
163  if (i != this->end()) {
164  return i->second;
165  } else {
166  THROW(JTypeInformationException, "Invalid version <" << version << ">");
167  }
168  }
169 
170 
171  /**
172  * Get numerical value.
173  *
174  * \param version version
175  * \return numerical value
176  */
178  {
179  return (*this)(version.getVersion());
180  }
181 
182 
183  /**
184  * Get index of detector version.
185  *
186  * \param version version
187  * \return index
188  */
189  int operator[](const std::string& version) const
190  {
191  using namespace std;
192  using namespace JPP;
193 
194  const_iterator i = this->find(to_upper(version));
195 
196  if (i != this->end())
197  return distance(this->begin(), i);
198  else
199  return -1;
200  }
201 
202 
203  /**
204  * Get index of detector version.
205  *
206  * \param version version
207  * \return index
208  */
210  {
211  return (*this)[version.getVersion()];
212  }
213 
214 
215  /**
216  * Get index of detector version.
217  *
218  * \param value numerical value
219  * \return index
220  */
221  int operator[](const JDetectorVersion::JVersion_t& value) const
222  {
223  using namespace std;
224 
225  for (const_iterator i = this->begin(); i != this->end(); ++i) {
226  if (i->second == value) {
227  return distance(this->begin(), i);
228  }
229  }
230 
231  return -1;
232  }
233  };
234 
235 
236  /**
237  * Auxiliary class to map numerical value to detector version.
238  */
240  public std::map<JDetectorVersion::JVersion_t, std::string>
241  {
242  /**
243  * Constructor.
244  *
245  * \param input detector versions
246  */
248  {
249  using namespace std;
250 
251  for (JGetDetectorVersion::const_iterator i = input.begin(); i != input.end(); ++i) {
252  this->insert(make_pair(i->second, i->first));
253  }
254  }
255 
256 
257  /**
258  * Put detector version.
259  *
260  * \param value numerical value
261  * \return version
262  */
263  const std::string& operator()(const JDetectorVersion::JVersion_t& value) const
264  {
265  const_iterator i = this->find(value);
266 
267  if (i != this->end()) {
268  return i->second;
269  } else {
270  THROW(JTypeInformationException, "Invalid value <" << value << ">");
271  }
272  }
273 
274 
275  /**
276  * Get index of version
277  *
278  * \param value numerical value
279  * \return index
280  */
281  int operator[](const JDetectorVersion::JVersion_t& value) const
282  {
283  using namespace std;
284 
285  const_iterator i = this->find(value);
286 
287  if (i != this->end())
288  return distance(this->begin(), i);
289  else
290  return -1;
291  }
292  };
293 
294 
295  /**
296  * Function object to map detector version to numerical value.
297  */
299 
300 
301  /**
302  * Function object to map numerical value to detector version.
303  */
304  static const JPutDetectorVersion putDetectorVersion(getDetectorVersion);
305 
306 
307  /**
308  * Get detector versions.
309  *
310  * Note that the order of the versions is descending.
311  *
312  * \param type type
313  * \return versions
314  */
316  {
317  return JLANG::make_array(putDetectorVersion.rbegin(), putDetectorVersion.rend(), &JPutDetectorVersion::value_type::second);
318  }
319 
320 
321  /**
322  * Get detector versions.
323  *
324  * Note that the order of the versions is descending.
325  *
326  * \param type type
327  * \return numerical values
328  */
330  {
332  }
333 
334 
335  /**
336  * Get detector versions.
337  *
338  * \return versions
339  */
340  template<class T>
342  {
343  return getDetectorVersions(JType<T>());
344  }
345 
346 
347  /**
348  * Get latest detector version.
349  *
350  * \param type type
351  * \return version
352  */
353  inline std::string getLatestDetectorVersion(const JType<std::string>& type)
354  {
355  return putDetectorVersion.rbegin()->second;
356  }
357 
358 
359  /**
360  * Get latest detector version.
361  *
362  * \param type type
363  * \return version
364  */
366  {
367  return putDetectorVersion.rbegin()->first;
368  }
369 
370 
371  /**
372  * Get latest detector version.
373  *
374  * \return version
375  */
376  template<class T>
378  {
380  }
381 }
382 
383 #endif
JGetDetectorVersion()
Default constructor.
Exception for absence of type information.
Definition: JException.hh:612
Exceptions.
Interface for binary output.
Auxiliary class to map detector version to numerical value.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
JDetectorVersion()
Default constructor.
JVersion_t
Enumeration of version types.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JPutDetectorVersion(const JGetDetectorVersion &input)
Constructor.
const std::string & getVersion() const
Get version.
JDetectorVersion::JVersion_t operator()(const std::string &version) const
Get numerical value.
std::string getLatestDetectorVersion(const JType< std::string > &type)
Get latest detector version.
Auxiliary class for a type holder.
Definition: JType.hh:19
friend std::istream & operator>>(std::istream &in, JDetectorVersion &version)
Read version from input.
friend std::ostream & operator<<(std::ostream &out, const JDetectorVersion &version)
Write version to output.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
JDetectorVersion::JVersion_t operator()(const JDetectorVersion &version) const
Get numerical value.
int operator[](const JDetectorVersion &version) const
Get index of detector version.
Auxiliary class to map numerical value to detector version.
Version with UTC time and UTM position data.
Version with PMT status field and comments.
Version with quaternion and time offset per module.
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
Auxiliary methods for handling file names, type names and environment.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
std::vector< std::string > getDetectorVersions(const JType< std::string > &type)
Get detector versions.
std::string to_upper(const std::string &value)
Convert all character to upper case.
Interface for binary input.
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
static const JGetDetectorVersion getDetectorVersion
Function object to map detector version to numerical value.
#define MAKE_ENTRY(A)
static const JPutDetectorVersion putDetectorVersion(getDetectorVersion)
Function object to map numerical value to detector version.
friend JReader & operator>>(JReader &in, JDetectorVersion &version)
Read version from input.
const std::string & operator()(const JDetectorVersion::JVersion_t &value) const
Put detector version.
JDetectorVersion(const JVersion &version)
Constructor.
friend JWriter & operator<<(JWriter &out, const JDetectorVersion &version)
Write version to output.
Auxiliary class for version identifier.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:40
int operator[](const JDetectorVersion::JVersion_t &value) const
Get index of detector version.
int operator[](const JDetectorVersion::JVersion_t &value) const
Get index of version.
version
Definition: JCalibratePMT.sh:7
STD extensions for binary I/O.
int operator[](const std::string &version) const
Get index of detector version.
Exception for I/O.
Definition: JException.hh:324