Jpp 19.3.0
the software that should make you happy
Loading...
Searching...
No Matches
JPMTRunsetupParams.hh
Go to the documentation of this file.
1#ifndef __JDB_JPMTRUNSETUPPARAMS__
2#define __JDB_JPMTRUNSETUPPARAMS__
3
4#include <ostream>
5#include <iomanip>
6#include <sstream>
7#include <string>
8#include <map>
9
10#include "JDB/JDB.hh"
11#include "JDB/JSelector.hh"
13#include "JDB/JDBToolkit.hh"
14#include "JDB/JRuns.hh"
15#include "JDB/JAllParams.hh"
17#include "JDB/JUPI_t.hh"
18
19#include "Jeep/JPrint.hh"
20
21
22/**
23 * \author mdejong
24 */
25namespace JDATABASE {}
26namespace JPP { using namespace JDATABASE; }
27
28namespace JDATABASE {
29
30 const char* const OPTICS_t = "OPTICS"; //!< sub-system of PMT
31 const char* const PMT_THRESHOLD_t = "PMT_THRESHOLD"; //!< parameter name of PMT threshold
32 const char* const PMT_HV_t = "PMT_HIGHVOLT"; //!< parameter name of PMT high voltage
33
34
35 /**
36 * Auxiliary data structure for fallback order of PMT data.
37 */
38 template<class JValue_t>
39 struct JPMTValue :
40 std::pair<int, JValue_t>
41 {
42 /**
43 * Default constructor.
44 */
46 std::pair<int, JValue_t>(-1, JValue_t())
47 {}
48 };
49
50
51 /**
52 * Auxiliary class for PMT run setup parameters.
53 *
54 * This class provides for an implementation of the fallback method based on the %UPI of a PMT and the value of JRunsetupParams::ORDER.
55 */
56 template<class JValue_t>
58 public std::map<std::string, JPMTValue<JValue_t> >
59 {
60 public:
61 /**
62 * Type definition of PMT parameter value.
63 */
64 struct result_type {
65 bool is_default; //!< true if fallback; else false
66 JValue_t value; //!< value
67
68 /**
69 * Write result type to output stream.
70 *
71 * \param out output stream
72 * \param object result type
73 * \return output stream
74 */
75 friend inline std::ostream& operator<<(std::ostream& out, const result_type& object)
76 {
77 using namespace std;
78
79 return out << object.is_default << ' ' << dec << setw(3) << object.value;
80 }
81 };
82
83
84 /**
85 * Default constructor.
86 */
89
90
91 /**
92 * Configure PMT run setup parameters for given detector and run.
93 *
94 * \param id detector identifier
95 * \param run run number
96 * \param parameter parameter name
97 */
98 void configure(const int id, const int run, const std::string& parameter)
99 {
100 using namespace std;
101 using namespace JPP;
102
103 this->clear();
104
105 string rs_oid;
106 JAllParams upars;
107
108 {
109 ResultSet& rs = getResultSet(getTable<JRuns>(), getSelector<JRuns>(id, run));
110
111 JRuns parameters;
112
113 if (rs >> parameters) {
114 rs_oid = parameters.RUNSETUPID;
115 }
116
117 rs.Close();
118 }
119 {
121
122 for (JAllParams parameters; rs >> parameters; ) {
123 if (parameters.NAME == parameter) {
124 upars = parameters;
125 }
126 }
127
128 rs.Close();
129 }
130 {
132
133 for (JRunsetupParams parameters; rs >> parameters; ) {
134 if (parameters.PAR_OID == upars.OID && parameters.ISINPUT == 'Y') {
135 if (parameters.VALUE != "") {
136
137 JPMTValue<JValue_t>& value = (*this)[parameters.UPIFILTER];
138
139 if (parameters.ORDER > value.first) {
140
141 value.first = parameters.ORDER;
142
143 istringstream(parameters.VALUE) >> value.second;
144 }
145 }
146 }
147 }
148
149 rs.Close();
150 }
151 }
152
153
154 /**
155 * Get PMT parameter value for given %UPI of PMT.
156 *
157 * \param upi %UPI
158 * \return PMT parameter value
159 */
160 result_type operator()(const JUPI_t& upi) const
161 {
162 typename JPMTRunsetupParams::const_iterator p = this->find(upi.toString()), p0 = p, p1 = p;
163
164 // fallbacks
165
166 const JUPI_t buffer[] = {
171 };
172
173 for (const JUPI_t& i : buffer) {
174 if ((p = this->find(i.toString())) != this->end()) {
175 if (p1 == this->end() || p->first > p1->first) {
176 p1 = p;
177 }
178 }
179 }
180
181 if (p1 != this->end()) {
182 return { p0 != p1, p1->second.second };
183 }
184
185 THROW(JDatabaseException, "Invalid UPI " << upi);
186 }
187
188
189 /**
190 * Write PMT run setup parameters to output stream.
191 *
192 * \param out output stream
193 * \param object PMT run setup parameters
194 * \return output stream
195 */
196 friend inline std::ostream& operator<<(std::ostream& out, const JPMTRunsetupParams& object)
197 {
198 using namespace std;
199
200 for (typename JPMTRunsetupParams::const_iterator i = object.begin(); i != object.end(); ++i) {
201 out << left << setw(32) << i->first << ' ' << right << i->second.second << endl;
202 }
203
204 return out;
205 }
206 };
207}
208
209#endif
TPaveText * p1
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
I/O formatting auxiliaries.
Auxiliary class for PMT run setup parameters.
void configure(const int id, const int run, const std::string &parameter)
Configure PMT run setup parameters for given detector and run.
friend std::ostream & operator<<(std::ostream &out, const JPMTRunsetupParams &object)
Write PMT run setup parameters to output stream.
result_type operator()(const JUPI_t &upi) const
Get PMT parameter value for given UPI of PMT.
JPMTRunsetupParams()
Default constructor.
Database exception.
Auxiliary classes and methods for database I/O.
Definition JAHRS.hh:14
const char *const OPTICS_t
sub-system of PMT
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition JDB.hh:438
const char * getTable()
Get table name.
Definition JDB.hh:373
JDetectorsHelper & getDetector()
Auxiliary function for helper object initialisation.
const char *const PMT_THRESHOLD_t
parameter name of PMT threshold
const char *const PMT_HV_t
parameter name of PMT high voltage
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const JPBS_t & getPBS() const
Get PBS.
Definition JPBS_t.hh:101
Type definition of PMT parameter value.
friend std::ostream & operator<<(std::ostream &out, const result_type &object)
Write result type to output stream.
bool is_default
true if fallback; else false
Auxiliary data structure for fallback order of PMT data.
JPMTValue()
Default constructor.
std::string RUNSETUPID
Definition JRuns.hh:26
Universal product identifier (UPI).
Definition JUPI_t.hh:33
static const int DEFAULT_VERSION
Default version.
Definition JUPI_t.hh:39
std::string toString() const
Convert UPI.
Definition JUPI_t.hh:145
static const int DEFAULT_NUMBER
Default number.
Definition JUPI_t.hh:40
const std::string & getVariant() const
Get variant.
Definition JUPI_t.hh:112
Template definition for getting table specific selector.