Jpp  18.6.0-rc.1
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  V5 = 5 //!< Version with module status field
54  };
55 
56 
57  /**
58  * Default constructor.
59  */
61  JVersion()
62  {}
63 
64 
65  /**
66  * Constructor.
67  *
68  * \param version version
69  */
71  JVersion(version)
72  {}
73 
74 
75  /**
76  * Check validity of version.
77  *
78  * \return true if valid; else false
79  */
80  bool hasVersion() const
81  {
82  return (!this->version.empty() && (this->version[0] == 'v' || this->version[0] == 'V'));
83  }
84 
85 
86  /**
87  * Read version from input.
88  *
89  * \param in input stream
90  * \param version version
91  * \return input stream
92  */
93  friend inline std::istream& operator>>(std::istream& in, JDetectorVersion& version)
94  {
95  return in >> version.version;
96  }
97 
98 
99  /**
100  * Write version to output.
101  *
102  * \param out output stream
103  * \param version version
104  * \return output stream
105  */
106  friend inline std::ostream& operator<<(std::ostream& out, const JDetectorVersion& version)
107  {
108  return out << version.version;
109  }
110 
111 
112  /**
113  * Read version from input.
114  *
115  * \param in reader
116  * \param version version
117  * \return reader
118  */
120  {
121  return in >> version.version;
122  }
123 
124 
125  /**
126  * Write version to output.
127  *
128  * \param out writer
129  * \param version version
130  * \return writer
131  */
132  friend inline JWriter& operator<<(JWriter& out, const JDetectorVersion& version)
133  {
134  return out << version.version;
135  }
136  };
137 
138 
139  /**
140  * Auxiliary class to map detector version to numerical value.
141  */
143  public std::map<std::string, JDetectorVersion::JVersion_t>
144  {
145  /**
146  * Default constructor.
147  */
149  {
150  using namespace JPP;
151 
152 #define MAKE_ENTRY(A) std::make_pair(to_upper(getClassname(#A)), A)
153 
154  this->insert(MAKE_ENTRY(JDetectorVersion::V1));
155  this->insert(MAKE_ENTRY(JDetectorVersion::V2));
156  this->insert(MAKE_ENTRY(JDetectorVersion::V3));
157  this->insert(MAKE_ENTRY(JDetectorVersion::V4));
158  this->insert(MAKE_ENTRY(JDetectorVersion::V5));
159 
160 #undef MAKE_ENTRY
161  }
162 
163 
164  /**
165  * Get numerical value.
166  *
167  * \param version version
168  * \return numerical value
169  */
171  {
172  using namespace JPP;
173 
174  const_iterator i = this->find(to_upper(version));
175 
176  if (i != this->end()) {
177  return i->second;
178  } else {
179  THROW(JTypeInformationException, "Invalid version <" << version << ">");
180  }
181  }
182 
183 
184  /**
185  * Get numerical value.
186  *
187  * \param version version
188  * \return numerical value
189  */
191  {
192  return (*this)(version.getVersion());
193  }
194 
195 
196  /**
197  * Get index of detector version.
198  *
199  * \param version version
200  * \return index
201  */
202  int operator[](const std::string& version) const
203  {
204  using namespace std;
205  using namespace JPP;
206 
207  const_iterator i = this->find(to_upper(version));
208 
209  if (i != this->end())
210  return distance(this->begin(), i);
211  else
212  return -1;
213  }
214 
215 
216  /**
217  * Get index of detector version.
218  *
219  * \param version version
220  * \return index
221  */
223  {
224  return (*this)[version.getVersion()];
225  }
226 
227 
228  /**
229  * Get index of detector version.
230  *
231  * \param value numerical value
232  * \return index
233  */
234  int operator[](const JDetectorVersion::JVersion_t& value) const
235  {
236  using namespace std;
237 
238  for (const_iterator i = this->begin(); i != this->end(); ++i) {
239  if (i->second == value) {
240  return distance(this->begin(), i);
241  }
242  }
243 
244  return -1;
245  }
246  };
247 
248 
249  /**
250  * Auxiliary class to map numerical value to detector version.
251  */
253  public std::map<JDetectorVersion::JVersion_t, std::string>
254  {
255  /**
256  * Constructor.
257  *
258  * \param input detector versions
259  */
261  {
262  using namespace std;
263 
264  for (JGetDetectorVersion::const_iterator i = input.begin(); i != input.end(); ++i) {
265  this->insert(make_pair(i->second, i->first));
266  }
267  }
268 
269 
270  /**
271  * Put detector version.
272  *
273  * \param value numerical value
274  * \return version
275  */
276  const std::string& operator()(const JDetectorVersion::JVersion_t& value) const
277  {
278  const_iterator i = this->find(value);
279 
280  if (i != this->end()) {
281  return i->second;
282  } else {
283  THROW(JTypeInformationException, "Invalid value <" << value << ">");
284  }
285  }
286 
287 
288  /**
289  * Get index of version
290  *
291  * \param value numerical value
292  * \return index
293  */
294  int operator[](const JDetectorVersion::JVersion_t& value) const
295  {
296  using namespace std;
297 
298  const_iterator i = this->find(value);
299 
300  if (i != this->end())
301  return distance(this->begin(), i);
302  else
303  return -1;
304  }
305  };
306 
307 
308  /**
309  * Function object to map detector version to numerical value.
310  */
312 
313 
314  /**
315  * Function object to map numerical value to detector version.
316  */
317  static const JPutDetectorVersion putDetectorVersion(getDetectorVersion);
318 
319 
320  /**
321  * Get detector versions.
322  *
323  * Note that the order of the versions is descending.
324  *
325  * \param type type
326  * \return versions
327  */
329  {
330  return JLANG::make_array(putDetectorVersion.rbegin(), putDetectorVersion.rend(), &JPutDetectorVersion::value_type::second);
331  }
332 
333 
334  /**
335  * Get detector versions.
336  *
337  * Note that the order of the versions is descending.
338  *
339  * \param type type
340  * \return numerical values
341  */
343  {
345  }
346 
347 
348  /**
349  * Get detector versions.
350  *
351  * \return versions
352  */
353  template<class T>
355  {
356  return getDetectorVersions(JType<T>());
357  }
358 
359 
360  /**
361  * Get latest detector version.
362  *
363  * \param type type
364  * \return version
365  */
367  {
368  return putDetectorVersion.rbegin()->second;
369  }
370 
371 
372  /**
373  * Get latest detector version.
374  *
375  * \param type type
376  * \return version
377  */
379  {
380  return putDetectorVersion.rbegin()->second;
381  }
382 
383 
384  /**
385  * Get latest detector version.
386  *
387  * \param type type
388  * \return version
389  */
391  {
392  return putDetectorVersion.rbegin()->first;
393  }
394 
395 
396  /**
397  * Get latest detector version.
398  *
399  * \return version
400  */
401  template<class T>
403  {
405  }
406 }
407 
408 #endif
JGetDetectorVersion()
Default constructor.
Exception for absence of type information.
Definition: JException.hh:646
Exceptions.
Interface for binary output.
Auxiliary class to map detector version to numerical value.
version
Definition: JEditTuneHV.sh:5
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:712
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.
then set_variable PMT_FILE set_variable DAQ_FILE set_variable OUTPUT_FILE set_variable DETECTOR else fatal Wrong number of arguments fi JPrintTree f $DAQ_FILE type
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.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
const std::string & operator()(const JDetectorVersion::JVersion_t &value) const
Put detector version.
JDetectorVersion(const JVersion &version)
Constructor.
Version with module status field.
friend JWriter & operator<<(JWriter &out, const JDetectorVersion &version)
Write version to output.
Auxiliary class for version identifier.
bool hasVersion() const
Check validity of version.
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.
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:340