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