Jpp
 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 "Jeep/JVersion.hh"
12 #include "Jeep/JeepToolkit.hh"
13 
14 
15 /**
16  * \file
17  *
18  * Data structure for detector version.
19  * \author mdejong
20  */
21 namespace JDETECTOR {}
22 namespace JPP { using namespace JDETECTOR; }
23 
24 namespace JDETECTOR {
25 
26  using JEEP::JVersion;
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  };
46 
47  /**
48  * Default constructor.
49  */
51  JVersion()
52  {}
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param version version
59  */
60  JDetectorVersion(const JVersion& version) :
61  JVersion(version)
62  {}
63  };
64 
65 
66  /**
67  * Auxiliary class to map detector variant to detector version.
68  */
70  public std::map<std::string, JDetectorVersion::JVersion_t>
71  {
72  /**
73  * Default constructor.
74  */
76  {
77  using namespace JPP;
78 
79 #define MAKE_ENTRY(A) std::make_pair(to_upper(getClassname(#A)), A)
80 
81  this->insert(MAKE_ENTRY(JDetectorVersion::V1));
82  this->insert(MAKE_ENTRY(JDetectorVersion::V2));
83  this->insert(MAKE_ENTRY(JDetectorVersion::V3));
84 
85 #undef MAKE_ENTRY
86  }
87 
88 
89  /**
90  * Get detector version.
91  *
92  * \param variant variant
93  * \return version
94  */
95  JDetectorVersion::JVersion_t operator()(const std::string& variant) const
96  {
97  using namespace JPP;
98 
99  const_iterator i = this->find(to_upper(variant));
100 
101  if (i != this->end()) {
102 
103  return i->second;
104 
105  } else {
106 
107  THROW(JTypeInformationException, "Invalid variant <" << variant << ">");
108  }
109  }
110 
111 
112  /**
113  * Get detector version.
114  *
115  * \param version version
116  * \return version
117  */
119  {
120  return (*this)(version.getVariant());
121  }
122  };
123 
124 
125  /**
126  * Auxiliary class to map detector version to detector variant.
127  */
129  public std::map<JDetectorVersion::JVersion_t, std::string>
130  {
131  /**
132  * Constructor.
133  *
134  * \param input detector versions
135  */
137  {
138  using namespace std;
139 
140  for (JGetDetectorVersion::const_iterator i = input.begin(); i != input.end(); ++i) {
141  this->insert(make_pair(i->second, i->first));
142  }
143  }
144 
145 
146  /**
147  * Put detector version.
148  *
149  * \param version version
150  * \return version
151  */
152  const std::string& operator()(const JDetectorVersion::JVersion_t& version) const
153  {
154  using namespace JPP;
155 
156  const_iterator i = this->find(version);
157 
158  if (i != this->end()) {
159 
160  return i->second;
161 
162  } else {
163 
164  THROW(JTypeInformationException, "Invalid version <" << version << ">");
165  }
166  }
167  };
168 
169 
170  /**
171  * Function object to map detector variant to detector version.
172  */
174 
175 
176  /**
177  * Function object to map detector version to detector variant.
178  */
179  static const JPutDetectorVersion putDetectorVersion(getDetectorVersion);
180 
181 
182  /**
183  * Get detector versions.
184  *
185  * Note that the order of the versions is descending.
186  *
187  * \param type type
188  * \return versions
189  */
191  {
193 
194  for (JPutDetectorVersion::const_reverse_iterator i = putDetectorVersion.rbegin(); i != putDetectorVersion.rend(); ++i) {
195  buffer.push_back(i->second);
196  }
197 
198  return buffer;
199  }
200 
201 
202  /**
203  * Get detector versions.
204  *
205  * Note that the order of the versions is descending.
206  *
207  * \param type type
208  * \return versions
209  */
211  {
213 
214  for (JPutDetectorVersion::const_reverse_iterator i = putDetectorVersion.rbegin(); i != putDetectorVersion.rend(); ++i) {
215  buffer.push_back(i->first);
216  }
217 
218  return buffer;
219  }
220 
221 
222  /**
223  * Get detector versions.
224  *
225  * \return versions
226  */
227  template<class T>
229  {
230  return getDetectorVersions(JType<T>());
231  }
232 }
233 
234 #endif
JGetDetectorVersion()
Default constructor.
Exception for absence of type information.
Definition: JException.hh:594
Exceptions.
Auxiliary class to map detector variant to detector version.
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:633
JPutDetectorVersion(const JGetDetectorVersion &input)
Constructor.
Auxiliary class for a type holder.
Definition: JType.hh:19
const std::string & operator()(const JDetectorVersion::JVersion_t &version) const
Put detector version.
JDetectorVersion::JVersion_t operator()(const JDetectorVersion &version) const
Get detector version.
Auxiliary class to map detector version to detector variant.
Version with UTC time and UTM position data.
const std::string & getVariant() const
Get variant.
Definition: JVersion.hh:90
Version with PMT status field and comments.
Auxiliary methods for handling file names, type names and environment.
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.
static const JGetDetectorVersion getDetectorVersion
Function object to map detector variant to detector version.
Auxiliary class for version identifier.
Definition: JVersion.hh:30
#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.