Jpp  15.0.1-rc.1-highqe
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDBSupportkit.hh
Go to the documentation of this file.
1 #ifndef __JDB_JDBSUPPORTKIT__
2 #define __JDB_JDBSUPPORTKIT__
3 
4 #include <set>
5 #include <string>
6 #include <istream>
7 #include <ostream>
8 
9 #include "JLang/JException.hh"
10 #include "JLang/JComparable.hh"
11 
12 #include "Jeep/JPrint.hh"
13 #include "Jeep/JVersion.hh"
14 
15 #include "JDB/JRuns.hh"
16 #include "JDB/JRunQuality.hh"
17 
18 
19 /**
20  * \author mdejong, bjung
21  */
22 
23 namespace JDATABASE {};
24 namespace JPP { using namespace JDATABASE; }
25 
26 /**
27  * Auxiliary classes and methods for database I/O.
28  */
29 namespace JDATABASE {
30 
31  using JEEP::JVersion;
32 
33  using JLANG::JComparable;
35 
36  /**
37  * Auxiliary class for detector/run comparisons.
38  */
39  struct JRun_t :
40  public JComparable<JRun_t>,
41  public JComparable<JRun_t, JRuns>,
42  public JComparable<JRun_t, JRunQuality>
43  {
44  /**
45  * Constructor.
46  *
47  * \param detector detector
48  * \param run run
49  */
50  JRun_t(const int detector,
51  const int run) :
52  detector(detector),
53  run (run)
54  {}
55 
56 
57  /**
58  * Less-than method.
59  *
60  * \param object run
61  */
62  bool less(const JRun_t& object) const
63  {
64  if (this->detector == object.detector)
65  return this->run < object.run;
66  else
67  return this->detector < object.detector;
68  }
69 
70 
71  /**
72  * Less-than method.
73  *
74  * \param object run
75  */
76  bool less(const JRuns& object) const
77  {
78  if (this->detector == object.DETID)
79  return this->run < object.RUN;
80  else
81  return this->detector < object.DETID;
82  }
83 
84 
85  /**
86  * More-than method.
87  *
88  * \param object run
89  */
90  bool more(const JRuns& object) const
91  {
92  if (this->detector == object.DETID)
93  return this->run > object.RUN;
94  else
95  return this->detector > object.DETID;
96  }
97 
98 
99  /**
100  * Less-than method.
101  *
102  * \param object run
103  */
104  bool less(const JRunQuality& object) const
105  {
106  if (this->detector == object.detector)
107  return this->run < object.run;
108  else
109  return this->detector < object.detector;
110  }
111 
112 
113  /**
114  * More-than method.
115  *
116  * \param object run
117  */
118  bool more(const JRunQuality& object) const
119  {
120  if (this->detector == object.detector)
121  return this->run > object.run;
122  else
123  return this->detector > object.detector;
124  }
125 
126 
127  int detector;
128  int run;
129  };
130 
131 
132  /**
133  * Auxiliary data structure for I/O of database API versions.
134  */
135  struct JDBAPIVersion :
136  public JVersion,
137  public JComparable<JDBAPIVersion>
138  {
139  /**
140  * Default constructor.
141  */
143  JVersion()
144  {}
145 
146 
147  /**
148  * Constructor.
149  *
150  * \param major major version
151  * \param minor minor version
152  * \param patch patch version
153  */
154  JDBAPIVersion(const int major,
155  const int minor,
156  const int patch) :
157  JVersion(major, minor, patch)
158  {}
159 
160 
161  /**
162  * Check validity.
163  *
164  * \return true if valid; else false
165  */
166  bool is_valid() const
167  {
168  using namespace std;
169 
170  static const set<JVersion> versions{ JVersion(1, 0, 0),
171  JVersion(2, 0, 0) };
172 
173  for (set<JVersion>::const_iterator i = versions.cbegin(); i != versions.cend(); ++i) {
174 
175  if (i->getMajorVersion() == this->getMajorVersion() &&
176  i->getMinorVersion() == this->getMinorVersion() &&
177  i->getPatchVersion() == this->getPatchVersion()) {
178 
179  return true;
180  }
181  }
182 
183  return false;
184  }
185  };
186 
187 
188  /**
189  * Table listing HV-tuning database test types.
190  */
192  {
193  /**
194  * Constructor.
195  */
197  {
198  DBTestTypesTuneHV.insert("HV-TUNING-GAIN-v1");
199  DBTestTypesTuneHV.insert("HV-TUNING-GAIN-v2");
200  DBTestTypesTuneHV.insert("HV-TUNING-GAIN-v3");
201  }
202 
203 
204  /**
205  * Get HV-tuning DB test type corresponding to given version number.
206  *
207  * \param version version number
208  * \return HV-tuning database test type
209  */
210  const std::string& operator()(const int version) const
211  {
212  using namespace std;
213 
214  for (set<string>::const_iterator i = DBTestTypesTuneHV.cbegin(); i != DBTestTypesTuneHV.cend(); ++i) {
215 
216  if (i->find(to_string(version)) != string::npos) {
217  return *i;
218  }
219  }
220 
221  THROW(JValueOutOfRange, "JDBTestTypesTuneHV::operator(): No HV-tuning database test type corresponding to given version number \'" << version << "\'.");
222  }
223 
224 
225  /**
226  * Get version number corresponding to given HV-tuning DB test type.
227  *
228  * \param testType HV-tuning database test type
229  * \return version number
230  */
231  const int operator()(const std::string& testType) const
232  {
233  using namespace std;
234 
235  for (set<string>::const_iterator i = DBTestTypesTuneHV.cbegin(); i != DBTestTypesTuneHV.cend(); ++i) {
236 
237  if (i->compare(testType) == 0) {
238 
239  const int pos = i->find('v') + 1;
240 
241  return stoi(i->substr(pos));
242  }
243  }
244 
245  THROW(JValueOutOfRange, "JDBTestTypesTuneHV::operator(): Given HV-tuning database test type \'" << testType << "\' is invalid.");
246  }
247 
248  protected:
250  };
251 
252 
253  extern JDBTestTypesTuneHV getDBTestTypeTuneHV; //!< Function object for looking up the HV-tuning database test type corresponding to a specific version number.
254  static JDBTestTypesTuneHV& getDBVersionTuneHV = getDBTestTypeTuneHV; //!< Function object for looking up the HV-tuning database version number corresponding to a specific test type.
255 }
256 
257 #endif
static JDBTestTypesTuneHV & getDBVersionTuneHV
Function object for looking up the HV-tuning database version number corresponding to a specific test...
JDBAPIVersion()
Default constructor.
Exceptions.
Auxiliary class for detector/run comparisons.
std::set< std::string > DBTestTypesTuneHV
bool less(const JRuns &object) const
Less-than method.
version_type getMajorVersion() const
Get major version.
JDBAPIVersion(const int major, const int minor, const int patch)
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
bool is_valid() const
Check validity.
JRun_t(const int detector, const int run)
Constructor.
then set_variable DETID
Definition: JEditTuneHV.sh:63
bool more(const JRuns &object) const
More-than method.
I/O formatting auxiliaries.
Auxiliary data structure for I/O of database API versions.
bool less(const JRunQuality &object) const
Less-than method.
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
JVersion()
Default constructor.
const std::string & operator()(const int version) const
Get HV-tuning DB test type corresponding to given version number.
std::string to_string(const T &value)
Convert value to string.
version_type getMinorVersion() const
Get minor version.
bool less(const JRun_t &object) const
Less-than method.
Table listing HV-tuning database test types.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
Auxiliary data structure for general purpose version number.
version_type getPatchVersion() const
Get patch version.
const int operator()(const std::string &testType) const
Get version number corresponding to given HV-tuning DB test type.
version
Definition: JCalibratePMT.sh:7
JDBTestTypesTuneHV getDBTestTypeTuneHV
Function object for looking up the HV-tuning database test type corresponding to a specific version n...
Definition: JDBSupportkit.cc:5
Auxiliary data structure for data quality.
Definition: JRunQuality.hh:34
bool more(const JRunQuality &object) const
More-than method.