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 "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  };
46 
47  /**
48  * Default constructor.
49  */
51  JVersion()
52  {}
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param version version
59  */
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  return i->second;
103  } else {
104  THROW(JTypeInformationException, "Invalid variant <" << variant << ">");
105  }
106  }
107 
108 
109  /**
110  * Get detector version.
111  *
112  * \param version version
113  * \return version
114  */
116  {
117  return (*this)(version.getVariant());
118  }
119 
120 
121  /**
122  * Get index of detector version.
123  *
124  * \param variant variant
125  * \return index
126  */
127  int operator[](const std::string& variant) const
128  {
129  using namespace std;
130  using namespace JPP;
131 
132  const_iterator i = this->find(to_upper(variant));
133 
134  if (i != this->end())
135  return distance(this->begin(), i);
136  else
137  return -1;
138  }
139 
140 
141  /**
142  * Get index of detector version.
143  *
144  * \param version variant
145  * \return index
146  */
148  {
149  return (*this)[version.getVariant()];
150  }
151 
152 
153  /**
154  * Get index of detector version.
155  *
156  * \param version version
157  * \return index
158  */
160  {
161  using namespace std;
162 
163  for (const_iterator i = this->begin(); i != this->end(); ++i) {
164  if (i->second == version) {
165  return distance(this->begin(), i);
166  }
167  }
168 
169  return -1;
170  }
171  };
172 
173 
174  /**
175  * Auxiliary class to map detector version to detector variant.
176  */
178  public std::map<JDetectorVersion::JVersion_t, std::string>
179  {
180  /**
181  * Constructor.
182  *
183  * \param input detector versions
184  */
186  {
187  using namespace std;
188 
189  for (JGetDetectorVersion::const_iterator i = input.begin(); i != input.end(); ++i) {
190  this->insert(make_pair(i->second, i->first));
191  }
192  }
193 
194 
195  /**
196  * Put detector version.
197  *
198  * \param version version
199  * \return version
200  */
201  const std::string& operator()(const JDetectorVersion::JVersion_t& version) const
202  {
203  const_iterator i = this->find(version);
204 
205  if (i != this->end()) {
206  return i->second;
207  } else {
208  THROW(JTypeInformationException, "Invalid version <" << version << ">");
209  }
210  }
211 
212 
213  /**
214  * Get index of detector version.
215  *
216  * \param version version
217  * \return index
218  */
220  {
221  using namespace std;
222 
223  const_iterator i = this->find(version);
224 
225  if (i != this->end())
226  return distance(this->begin(), i);
227  else
228  return -1;
229  }
230  };
231 
232 
233  /**
234  * Function object to map detector variant to detector version.
235  */
237 
238 
239  /**
240  * Function object to map detector version to detector variant.
241  */
242  static const JPutDetectorVersion putDetectorVersion(getDetectorVersion);
243 
244 
245  /**
246  * Get detector versions.
247  *
248  * Note that the order of the versions is descending.
249  *
250  * \param type type
251  * \return versions
252  */
254  {
255  return JLANG::make_array(putDetectorVersion.rbegin(), putDetectorVersion.rend(), &JPutDetectorVersion::value_type::second);
256  }
257 
258 
259  /**
260  * Get detector versions.
261  *
262  * Note that the order of the versions is descending.
263  *
264  * \param type type
265  * \return versions
266  */
268  {
270  }
271 
272 
273  /**
274  * Get detector versions.
275  *
276  * \return versions
277  */
278  template<class T>
280  {
281  return getDetectorVersions(JType<T>());
282  }
283 }
284 
285 #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.
const std::vector< JValue_t > make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:27
#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.
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.
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.
const std::string & getVariant() const
Get variant.
Definition: JVersion.hh:89
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.
Definition: JVersion.hh:30
version
Definition: JCalibratePMT.sh:7
int operator[](const JDetectorVersion::JVersion_t &version) const
Get index of detector version.