Jpp
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 "Jeep/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 JEEP::JVersion;
28  using JLANG::JType;
30 
31 
32  /**
33  * Detector version.
34  */
35  struct JDetectorVersion :
36  public JVersion
37  {
38  /**
39  * Enumeration of version types.\n
40  * Additional version types should be included in JGetDetectorVersion::JGetDetectorVersion.
41  */
42  enum JVersion_t {
43  V1 = 1, //!< First version
44  V2 = 2, //!< Version with UTC time and UTM position data
45  V3 = 3 //!< Version with PMT status field and comments
46  };
47 
48  /**
49  * Default constructor.
50  */
52  JVersion()
53  {}
54 
55 
56  /**
57  * Constructor.
58  *
59  * \param version version
60  */
61  JDetectorVersion(const JVersion& version) :
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 
86 #undef MAKE_ENTRY
87  }
88 
89 
90  /**
91  * Get detector version.
92  *
93  * \param variant variant
94  * \return version
95  */
96  JDetectorVersion::JVersion_t operator()(const std::string& variant) const
97  {
98  using namespace JPP;
99 
100  const_iterator i = this->find(to_upper(variant));
101 
102  if (i != this->end()) {
103  return i->second;
104  } else {
105  THROW(JTypeInformationException, "Invalid variant <" << variant << ">");
106  }
107  }
108 
109 
110  /**
111  * Get detector version.
112  *
113  * \param version version
114  * \return version
115  */
117  {
118  return (*this)(version.getVariant());
119  }
120  };
121 
122 
123  /**
124  * Auxiliary class to map detector version to detector variant.
125  */
127  public std::map<JDetectorVersion::JVersion_t, std::string>
128  {
129  /**
130  * Constructor.
131  *
132  * \param input detector versions
133  */
135  {
136  using namespace std;
137 
138  for (JGetDetectorVersion::const_iterator i = input.begin(); i != input.end(); ++i) {
139  this->insert(make_pair(i->second, i->first));
140  }
141  }
142 
143 
144  /**
145  * Put detector version.
146  *
147  * \param version version
148  * \return version
149  */
150  const std::string& operator()(const JDetectorVersion::JVersion_t& version) const
151  {
152  const_iterator i = this->find(version);
153 
154  if (i != this->end()) {
155  return i->second;
156  } else {
157  THROW(JTypeInformationException, "Invalid version <" << version << ">");
158  }
159  }
160  };
161 
162 
163  /**
164  * Function object to map detector variant to detector version.
165  */
167 
168 
169  /**
170  * Function object to map detector version to detector variant.
171  */
173 
174 
175  /**
176  * Get detector versions.
177  *
178  * Note that the order of the versions is descending.
179  *
180  * \param type type
181  * \return versions
182  */
184  {
185  return JLANG::make_array(putDetectorVersion.rbegin(), putDetectorVersion.rend(), &JPutDetectorVersion::value_type::second);
186  }
187 
188 
189  /**
190  * Get detector versions.
191  *
192  * Note that the order of the versions is descending.
193  *
194  * \param type type
195  * \return versions
196  */
198  {
199  return JLANG::make_array(putDetectorVersion.rbegin(), putDetectorVersion.rend(), &JPutDetectorVersion::value_type::first);
200  }
201 
202 
203  /**
204  * Get detector versions.
205  *
206  * \return versions
207  */
208  template<class T>
210  {
211  return getDetectorVersions(JType<T>());
212  }
213 }
214 
215 #endif
JException.hh
JDETECTOR::JDetectorVersion::V2
Version with UTC time and UTM position data.
Definition: JDetectorVersion.hh:44
JDETECTOR::JGetDetectorVersion
Auxiliary class to map detector variant to detector version.
Definition: JDetectorVersion.hh:70
JLANG::JType
Auxiliary class for a type holder.
Definition: JType.hh:19
JDETECTOR::putDetectorVersion
static const JPutDetectorVersion putDetectorVersion(getDetectorVersion)
Function object to map detector version to detector variant.
JDETECTOR::JDetectorVersion::V3
Version with PMT status field and comments.
Definition: JDetectorVersion.hh:45
JLANG::to_upper
std::string to_upper(const std::string &value)
Convert all character to upper case.
Definition: JLangToolkit.hh:229
JDETECTOR::JGetDetectorVersion::operator()
JDetectorVersion::JVersion_t operator()(const std::string &variant) const
Get detector version.
Definition: JDetectorVersion.hh:96
JDETECTOR::getDetectorVersion
static const JGetDetectorVersion getDetectorVersion
Function object to map detector variant to detector version.
Definition: JDetectorVersion.hh:166
JDETECTOR::JPutDetectorVersion::JPutDetectorVersion
JPutDetectorVersion(const JGetDetectorVersion &input)
Constructor.
Definition: JDetectorVersion.hh:134
std::vector< std::string >
JVersion.hh
JDETECTOR::JPutDetectorVersion
Auxiliary class to map detector version to detector variant.
Definition: JDetectorVersion.hh:126
JDETECTOR::JDetectorVersion::JVersion_t
JVersion_t
Enumeration of version types.
Definition: JDetectorVersion.hh:42
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JGetDetectorVersion::JGetDetectorVersion
JGetDetectorVersion()
Default constructor.
Definition: JDetectorVersion.hh:76
JDETECTOR::JDetectorVersion::JDetectorVersion
JDetectorVersion(const JVersion &version)
Constructor.
Definition: JDetectorVersion.hh:61
JDETECTOR::JDetectorVersion::V1
First version.
Definition: JDetectorVersion.hh:43
MAKE_ENTRY
#define MAKE_ENTRY(A)
THROW
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:669
JDETECTOR::getDetectorVersions
std::vector< T > getDetectorVersions()
Get detector versions.
Definition: JDetectorVersion.hh:209
std::map
Definition: JSTDTypes.hh:16
JDETECTOR::JPutDetectorVersion::operator()
const std::string & operator()(const JDetectorVersion::JVersion_t &version) const
Put detector version.
Definition: JDetectorVersion.hh:150
JVectorize.hh
JEEP::JVersion
Auxiliary class for version identifier.
Definition: JVersion.hh:30
std
Definition: jaanetDictionary.h:36
JDETECTOR::JDetectorVersion::JDetectorVersion
JDetectorVersion()
Default constructor.
Definition: JDetectorVersion.hh:51
JeepToolkit.hh
JDETECTOR::JDetectorVersion
Detector version.
Definition: JDetectorVersion.hh:35
JLANG::JTypeInformationException
Exception for absence of type information.
Definition: JException.hh:612
JEEP::JVersion::getVariant
const std::string & getVariant() const
Get variant.
Definition: JVersion.hh:90
JLANG::make_array
const std::vector< JValue_t > make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:27
JType.hh
JDETECTOR
Auxiliary classes and methods for detector calibration.
Definition: JAnchor.hh:12
JDETECTOR::JGetDetectorVersion::operator()
JDetectorVersion::JVersion_t operator()(const JDetectorVersion &version) const
Get detector version.
Definition: JDetectorVersion.hh:116
JLangToolkit.hh