Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
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
22namespace JDATABASE {};
23namespace JPP { using namespace JDATABASE; }
24
25/**
26 * Auxiliary classes and methods for database I/O.
27 */
28namespace JDATABASE {
29
32
34
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) :
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
128 int run;
129 };
130
131
132 /**
133 * Table listing HV-tuning database test types.
134 */
136 {
137 /**
138 * Constructor.
139 */
141 {
142 DBTestTypesTuneHV.insert("HV-TUNING-GAIN-v1");
143 DBTestTypesTuneHV.insert("HV-TUNING-GAIN-v2");
144 DBTestTypesTuneHV.insert("HV-TUNING-GAIN-v3");
145 }
146
147
148 /**
149 * Get HV-tuning DB test type corresponding to given version number.
150 *
151 * \param version version number
152 * \return HV-tuning database test type
153 */
154 const std::string& operator()(const int version) const
155 {
156 using namespace std;
157
158 for (set<string>::const_iterator i = DBTestTypesTuneHV.cbegin(); i != DBTestTypesTuneHV.cend(); ++i) {
159
160 if (i->find(to_string(version)) != string::npos) {
161 return *i;
162 }
163 }
164
165 THROW(JValueOutOfRange, "JDBTestTypesTuneHV::operator(): No HV-tuning database test type corresponding to given version number \'" << version << "\'.");
166 }
167
168
169 /**
170 * Get version number corresponding to given HV-tuning DB test type.
171 *
172 * \param testType HV-tuning database test type
173 * \return version number
174 */
175 const int operator()(const std::string& testType) const
176 {
177 using namespace std;
178
179 for (set<string>::const_iterator i = DBTestTypesTuneHV.cbegin(); i != DBTestTypesTuneHV.cend(); ++i) {
180
181 if (i->compare(testType) == 0) {
182
183 const int pos = i->find('v') + 1;
184
185 return stoi(i->substr(pos));
186 }
187 }
188
189 THROW(JValueOutOfRange, "JDBTestTypesTuneHV::operator(): Given HV-tuning database test type \'" << testType << "\' is invalid.");
190 }
191
192 protected:
194 };
195
196
197 extern JDBTestTypesTuneHV getDBTestTypeTuneHV; //!< Function object for looking up the HV-tuning database test type corresponding to a specific version number.
198 static JDBTestTypesTuneHV& getDBVersionTuneHV = getDBTestTypeTuneHV; //!< Function object for looking up the HV-tuning database version number corresponding to a specific test type.
199}
200
201#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for accessing a value in a collection that is outside of its range.
Auxiliary classes and methods for database I/O.
Definition JAHRS.hh:14
JEEP::JVersion JDBAPIVersion
static JDBTestTypesTuneHV & getDBVersionTuneHV
Function object for looking up the HV-tuning database version number corresponding to a specific test...
JDBTestTypesTuneHV getDBTestTypeTuneHV
Function object for looking up the HV-tuning database test type corresponding to a specific version n...
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Table listing HV-tuning database test types.
std::set< std::string > DBTestTypesTuneHV
const int operator()(const std::string &testType) const
Get version number corresponding to given HV-tuning DB test type.
const std::string & operator()(const int version) const
Get HV-tuning DB test type corresponding to given version number.
Auxiliary data structure for data quality.
Auxiliary class for detector/run comparisons.
bool more(const JRuns &object) const
More-than method.
bool less(const JRunQuality &object) const
Less-than method.
bool more(const JRunQuality &object) const
More-than method.
JRun_t(const int detector, const int run)
Constructor.
bool less(const JRun_t &object) const
Less-than method.
bool less(const JRuns &object) const
Less-than method.
Auxiliary data structure for general purpose version number.
Template definition of auxiliary base class for comparison of data structures.