Jpp - 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 <string>
5 #include <vector>
6 #include <map>
7 
8 #include "JLang/JType.hh"
9 #include "JLang/JLangToolkit.hh"
10 #include "JLang/JException.hh"
11 #include "JLang/JVectorize.hh"
12 #include "JDetector/JVersion.hh"
13 #include "Jeep/JeepToolkit.hh"
14 
15 
16 /**
17  * \file
18  *
19  * Data structure for detector version.
20  * \author mdejong
21  */
22 namespace JDETECTOR {}
23 namespace JPP { using namespace JDETECTOR; }
24 
25 namespace JDETECTOR {
26 
27  using JLANG::JType;
29 
30 
31  /**
32  * Detector version.
33  */
34  struct JDetectorVersion :
35  public JVersion
36  {
37  /**
38  * Enumeration of version types.\n
39  * Additional version types should be included in JGetDetectorVersion::JGetDetectorVersion.
40  */
41  enum JVersion_t {
42  V1 = 1, //!< First version
43  V2 = 2, //!< Version with UTC time and UTM position data
44  V3 = 3, //!< Version with PMT status field and comments
45  V4 = 4 //!< Version with quaternion and time offset per module
46  };
47 
48  /**
49  * Default constructor.
50  */
52  JVersion()
53  {}
54 
55 
56  /**
57  * Constructor.
58  *
59  * \param version version
60  */
62  JVersion(version)
63  {}
64  };
65 
66 
67  /**
68  * Auxiliary class to map detector variant to detector version.
69  */
71  public std::map<std::string, JDetectorVersion::JVersion_t>
72  {
73  /**
74  * Default constructor.
75  */
77  {
78  using namespace JPP;
79 
80 #define MAKE_ENTRY(A) std::make_pair(to_upper(getClassname(#A)), A)
81 
82  this->insert(MAKE_ENTRY(JDetectorVersion::V1));
83  this->insert(MAKE_ENTRY(JDetectorVersion::V2));
84  this->insert(MAKE_ENTRY(JDetectorVersion::V3));
85  this->insert(MAKE_ENTRY(JDetectorVersion::V4));
86 
87 #undef MAKE_ENTRY
88  }
89 
90 
91  /**
92  * Get detector version.
93  *
94  * \param variant variant
95  * \return version
96  */
97  JDetectorVersion::JVersion_t operator()(const std::string& variant) const
98  {
99  using namespace JPP;
100 
101  const_iterator i = this->find(to_upper(variant));
102 
103  if (i != this->end()) {
104  return i->second;
105  } else {
106  THROW(JTypeInformationException, "Invalid variant <" << variant << ">");
107  }
108  }
109 
110 
111  /**
112  * Get detector version.
113  *
114  * \param version version
115  * \return version
116  */
118  {
119  return (*this)(version.getVariant());
120  }
121 
122 
123  /**
124  * Get index of detector version.
125  *
126  * \param variant variant
127  * \return index
128  */
129  int operator[](const std::string& variant) const
130  {
131  using namespace std;
132  using namespace JPP;
133 
134  const_iterator i = this->find(to_upper(variant));
135 
136  if (i != this->end())
137  return distance(this->begin(), i);
138  else
139  return -1;
140  }
141 
142 
143  /**
144  * Get index of detector version.
145  *
146  * \param version variant
147  * \return index
148  */
150  {
151  return (*this)[version.getVariant()];
152  }
153 
154 
155  /**
156  * Get index of detector version.
157  *
158  * \param version version
159  * \return index
160  */
162  {
163  using namespace std;
164 
165  for (const_iterator i = this->begin(); i != this->end(); ++i) {
166  if (i->second == version) {
167  return distance(this->begin(), i);
168  }
169  }
170 
171  return -1;
172  }
173  };
174 
175 
176  /**
177  * Auxiliary class to map detector version to detector variant.
178  */
180  public std::map<JDetectorVersion::JVersion_t, std::string>
181  {
182  /**
183  * Constructor.
184  *
185  * \param input detector versions
186  */
188  {
189  using namespace std;
190 
191  for (JGetDetectorVersion::const_iterator i = input.begin(); i != input.end(); ++i) {
192  this->insert(make_pair(i->second, i->first));
193  }
194  }
195 
196 
197  /**
198  * Put detector version.
199  *
200  * \param version version
201  * \return version
202  */
203  const std::string& operator()(const JDetectorVersion::JVersion_t& version) const
204  {
205  const_iterator i = this->find(version);
206 
207  if (i != this->end()) {
208  return i->second;
209  } else {
210  THROW(JTypeInformationException, "Invalid version <" << version << ">");
211  }
212  }
213 
214 
215  /**
216  * Get index of detector version.
217  *
218  * \param version version
219  * \return index
220  */
222  {
223  using namespace std;
224 
225  const_iterator i = this->find(version);
226 
227  if (i != this->end())
228  return distance(this->begin(), i);
229  else
230  return -1;
231  }
232  };
233 
234 
235  /**
236  * Function object to map detector variant to detector version.
237  */
239 
240 
241  /**
242  * Function object to map detector version to detector variant.
243  */
244  static const JPutDetectorVersion putDetectorVersion(getDetectorVersion);
245 
246 
247  /**
248  * Get detector versions.
249  *
250  * Note that the order of the versions is descending.
251  *
252  * \param type type
253  * \return versions
254  */
256  {
257  return JLANG::make_array(putDetectorVersion.rbegin(), putDetectorVersion.rend(), &JPutDetectorVersion::value_type::second);
258  }
259 
260 
261  /**
262  * Get detector versions.
263  *
264  * Note that the order of the versions is descending.
265  *
266  * \param type type
267  * \return versions
268  */
270  {
272  }
273 
274 
275  /**
276  * Get detector versions.
277  *
278  * \return versions
279  */
280  template<class T>
282  {
283  return getDetectorVersions(JType<T>());
284  }
285 
286 
287  /**
288  * Get latest detector version.
289  *
290  * \param type type
291  * \return version
292  */
293  inline std::string getLatestDetectorVersion(const JType<std::string>& type)
294  {
295  return putDetectorVersion.rbegin()->second;
296  }
297 
298 
299  /**
300  * Get latest detector version.
301  *
302  * \param type type
303  * \return version
304  */
306  {
307  return putDetectorVersion.rbegin()->first;
308  }
309 
310 
311  /**
312  * Get latest detector version.
313  *
314  * \return version
315  */
316  template<class T>
318  {
320  }
321 }
322 
323 #endif
JGetDetectorVersion()
Default constructor.
Exception for absence of type information.
Definition: JException.hh:612
Exceptions.
Auxiliary class to map detector variant to detector version.
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.
int operator[](const std::string &variant) const
Get index of detector version.
std::string getLatestDetectorVersion(const JType< std::string > &type)
Get latest detector version.
Auxiliary class for a type holder.
Definition: JType.hh:19
const std::string & operator()(const JDetectorVersion::JVersion_t &version) const
Put detector version.
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 detector version.
int operator[](const JDetectorVersion &version) const
Get index of detector version.
Auxiliary class to map detector version to detector variant.
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.
const std::string & getVariant() const
Get variant.
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 variant to detector version.
int operator[](const JDetectorVersion::JVersion_t &version) const
Get index of detector version.
#define MAKE_ENTRY(A)
static const JPutDetectorVersion putDetectorVersion(getDetectorVersion)
Function object to map detector version to detector variant.
JDetectorVersion(const JVersion &version)
Constructor.
JDetectorVersion::JVersion_t operator()(const std::string &variant) const
Get detector version.
Auxiliary class for version identifier.
version
Definition: JCalibratePMT.sh:7
int operator[](const JDetectorVersion::JVersion_t &version) const
Get index of detector version.