Jpp  17.3.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  * Read version from input.
77  *
78  * \param in input stream
79  * \param version version
80  * \return input stream
81  */
82  friend inline std::istream& operator>>(std::istream& in, JDetectorVersion& version)
83  {
84  return in >> version.version;
85  }
86 
87 
88  /**
89  * Write version to output.
90  *
91  * \param out output stream
92  * \param version version
93  * \return output stream
94  */
95  friend inline std::ostream& operator<<(std::ostream& out, const JDetectorVersion& version)
96  {
97  return out << version.version;
98  }
99 
100 
101  /**
102  * Read version from input.
103  *
104  * \param in reader
105  * \param version version
106  * \return reader
107  */
109  {
110  return in >> version.version;
111  }
112 
113 
114  /**
115  * Write version to output.
116  *
117  * \param out writer
118  * \param version version
119  * \return writer
120  */
121  friend inline JWriter& operator<<(JWriter& out, const JDetectorVersion& version)
122  {
123  return out << version.version;
124  }
125  };
126 
127 
128  /**
129  * Auxiliary class to map detector version to numerical value.
130  */
132  public std::map<std::string, JDetectorVersion::JVersion_t>
133  {
134  /**
135  * Default constructor.
136  */
138  {
139  using namespace JPP;
140 
141 #define MAKE_ENTRY(A) std::make_pair(to_upper(getClassname(#A)), A)
142 
143  this->insert(MAKE_ENTRY(JDetectorVersion::V1));
144  this->insert(MAKE_ENTRY(JDetectorVersion::V2));
145  this->insert(MAKE_ENTRY(JDetectorVersion::V3));
146  this->insert(MAKE_ENTRY(JDetectorVersion::V4));
147  this->insert(MAKE_ENTRY(JDetectorVersion::V5));
148 
149 #undef MAKE_ENTRY
150  }
151 
152 
153  /**
154  * Get numerical value.
155  *
156  * \param version version
157  * \return numerical value
158  */
160  {
161  using namespace JPP;
162 
163  const_iterator i = this->find(to_upper(version));
164 
165  if (i != this->end()) {
166  return i->second;
167  } else {
168  THROW(JTypeInformationException, "Invalid version <" << version << ">");
169  }
170  }
171 
172 
173  /**
174  * Get numerical value.
175  *
176  * \param version version
177  * \return numerical value
178  */
180  {
181  return (*this)(version.getVersion());
182  }
183 
184 
185  /**
186  * Get index of detector version.
187  *
188  * \param version version
189  * \return index
190  */
191  int operator[](const std::string& version) const
192  {
193  using namespace std;
194  using namespace JPP;
195 
196  const_iterator i = this->find(to_upper(version));
197 
198  if (i != this->end())
199  return distance(this->begin(), i);
200  else
201  return -1;
202  }
203 
204 
205  /**
206  * Get index of detector version.
207  *
208  * \param version version
209  * \return index
210  */
212  {
213  return (*this)[version.getVersion()];
214  }
215 
216 
217  /**
218  * Get index of detector version.
219  *
220  * \param value numerical value
221  * \return index
222  */
223  int operator[](const JDetectorVersion::JVersion_t& value) const
224  {
225  using namespace std;
226 
227  for (const_iterator i = this->begin(); i != this->end(); ++i) {
228  if (i->second == value) {
229  return distance(this->begin(), i);
230  }
231  }
232 
233  return -1;
234  }
235  };
236 
237 
238  /**
239  * Auxiliary class to map numerical value to detector version.
240  */
242  public std::map<JDetectorVersion::JVersion_t, std::string>
243  {
244  /**
245  * Constructor.
246  *
247  * \param input detector versions
248  */
250  {
251  using namespace std;
252 
253  for (JGetDetectorVersion::const_iterator i = input.begin(); i != input.end(); ++i) {
254  this->insert(make_pair(i->second, i->first));
255  }
256  }
257 
258 
259  /**
260  * Put detector version.
261  *
262  * \param value numerical value
263  * \return version
264  */
266  {
267  const_iterator i = this->find(value);
268 
269  if (i != this->end()) {
270  return i->second;
271  } else {
272  THROW(JTypeInformationException, "Invalid value <" << value << ">");
273  }
274  }
275 
276 
277  /**
278  * Get index of version
279  *
280  * \param value numerical value
281  * \return index
282  */
283  int operator[](const JDetectorVersion::JVersion_t& value) const
284  {
285  using namespace std;
286 
287  const_iterator i = this->find(value);
288 
289  if (i != this->end())
290  return distance(this->begin(), i);
291  else
292  return -1;
293  }
294  };
295 
296 
297  /**
298  * Function object to map detector version to numerical value.
299  */
301 
302 
303  /**
304  * Function object to map numerical value to detector version.
305  */
306  static const JPutDetectorVersion putDetectorVersion(getDetectorVersion);
307 
308 
309  /**
310  * Get detector versions.
311  *
312  * Note that the order of the versions is descending.
313  *
314  * \param type type
315  * \return versions
316  */
318  {
319  return JLANG::make_array(putDetectorVersion.rbegin(), putDetectorVersion.rend(), &JPutDetectorVersion::value_type::second);
320  }
321 
322 
323  /**
324  * Get detector versions.
325  *
326  * Note that the order of the versions is descending.
327  *
328  * \param type type
329  * \return numerical values
330  */
332  {
334  }
335 
336 
337  /**
338  * Get detector versions.
339  *
340  * \return versions
341  */
342  template<class T>
344  {
345  return getDetectorVersions(JType<T>());
346  }
347 
348 
349  /**
350  * Get latest detector version.
351  *
352  * \param type type
353  * \return version
354  */
356  {
357  return putDetectorVersion.rbegin()->second;
358  }
359 
360 
361  /**
362  * Get latest detector version.
363  *
364  * \param type type
365  * \return version
366  */
368  {
369  return putDetectorVersion.rbegin()->second;
370  }
371 
372 
373  /**
374  * Get latest detector version.
375  *
376  * \param type type
377  * \return version
378  */
380  {
381  return putDetectorVersion.rbegin()->first;
382  }
383 
384 
385  /**
386  * Get latest detector version.
387  *
388  * \return version
389  */
390  template<class T>
392  {
394  }
395 }
396 
397 #endif
JGetDetectorVersion()
Default constructor.
Exception for absence of type information.
Definition: JException.hh:630
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:696
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.
then awk string
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.
Version with module status field.
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 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:46
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:324