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