Jpp  17.3.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
19 /**
20  * \author mdejong
21  */
22 namespace JDATABASE {}
23 namespace JPP { using namespace JDATABASE; }
24 
25 namespace JDATABASE {
26 
27  const char* const OPTICS_t = "OPTICS"; //!< sub-system of PMT
28  const char* const PMT_THRESHOLD_t = "PMT_THRESHOLD"; //!< parameter name of PMT threshold
29  const char* const PMT_HV_t = "PMT_HIGHVOLT"; //!< parameter name of PMT high voltage
30 
31 
32  /**
33  * Auxiliary class for PMT run setup parameters.
34  *
35  * This class provides for an implementation of the fallback method based on the %UPI of a PMT.
36  */
37  template<class JValue_t>
39  public std::map<std::string, JValue_t>
40  {
41  public:
42  /**
43  * Type definition of PMT parameter value.
44  */
45  struct result_type {
46  bool is_default; //!< true if fallback; else false
47  JValue_t value; //!< value
48  };
49 
50 
51  /**
52  * Get fallback %UPI.
53  *
54  * \param upi %UPI
55  * \return %UPI
56  */
57  static std::string getUPI(const JUPI_t& upi)
58  {
59  std::ostringstream os;
60 
61  os << upi.getPBS()
63  << upi.getVariant()
65  << JUPI_t::DOT;
66 
67  return os.str();
68  }
69 
70 
71  /**
72  * Default constructor.
73  */
75  {}
76 
77 
78  /**
79  * Configure PMT run setup parameters for given detector and run.
80  *
81  * \param id detector identifier
82  * \param run run number
83  * \param parameter parameter name
84  */
85  void configure(const int id, const int run, const std::string& parameter)
86  {
87  using namespace std;
88  using namespace JPP;
89 
90  this->clear();
91 
92  string rs_oid;
93  JAllParams upars;
94 
95  {
96  ResultSet& rs = getResultSet(getTable<JRuns>(), getSelector<JRuns>(id, run));
97 
99 
100  if (rs >> parameters) {
101  rs_oid = parameters.RUNSETUPID;
102  }
103 
104  rs.Close();
105  }
106  {
107  ResultSet& rs = getResultSet(getTable<JAllParams>(), getSelector<JAllParams>(OPTICS_t));
108 
109  for (JAllParams parameters; rs >> parameters; ) {
110  if (parameters.NAME == parameter) {
111  upars = parameters;
112  }
113  }
114 
115  rs.Close();
116  }
117  {
118  ResultSet& rs = getResultSet(getTable<JRunsetupParams>(), getSelector<JRunsetupParams>(getDetector(id), rs_oid));
119 
120  for (JRunsetupParams parameters; rs >> parameters; ) {
121  if (parameters.PAR_OID == upars.OID && parameters.ISINPUT == 'Y') {
122  if (parameters.VALUE != "") {
123  istringstream(parameters.VALUE) >> (*this)[parameters.UPIFILTER];
124  }
125  }
126  }
127 
128  rs.Close();
129  }
130  }
131 
132 
133  /**
134  * Get PMT parameter value for given %UPI of PMT.
135  *
136  * \param upi %UPI
137  * \return PMT parameter value
138  */
139  result_type operator()(const JUPI_t& upi) const
140  {
141  typename JPMTRunsetupParams::const_iterator p = this->find(upi.toString());
142 
143  const bool is_default = (p == this->end());
144 
145  if (is_default) {
146  p = this->find(getUPI(upi));
147  }
148 
149  if (p != this->end())
150  return { is_default, p->second };
151  else
152  THROW(JDatabaseException, "Invalid UPI " << upi);
153  }
154 
155 
156  /**
157  * Write PMT run setup parameters to output stream.
158  *
159  * \param out output stream
160  * \param object PMT run setup parameters
161  * \return output stream
162  */
163  friend inline std::ostream& operator<<(std::ostream& out, const JPMTRunsetupParams& object)
164  {
165  using namespace std;
166 
167  for (typename JPMTRunsetupParams::const_iterator i = object.begin(); i != object.end(); ++i) {
168  out << left << setw(32) << i->first << ' ' << right << setw(6) << i->second << endl;
169  }
170 
171  return out;
172  }
173  };
174 }
175 
176 #endif
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.
const std::string & getVariant() const
Get variant.
Definition: JUPI_t.hh:108
Database exception.
Definition: JException.hh:666
friend std::ostream & operator<<(std::ostream &out, const JPMTRunsetupParams &object)
Write PMT run setup parameters to output stream.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
Type definition of PMT parameter value.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Universal product identifier (UPI).
Definition: JUPI_t.hh:29
static const char SEPARATOR
Separator between PBS, variant and version.
Definition: JUPI_t.hh:35
const char *const PMT_THRESHOLD_t
parameter name of PMT threshold
JDetectorsHelper & getDetector()
Auxiliary function for helper object initialisation.
Definition: JDBToolkit.hh:378
const JPBS_t & getPBS() const
Get PBS.
Definition: JPBS_t.hh:101
result_type operator()(const JUPI_t &upi) const
Get PMT parameter value for given UPI of PMT.
const char *const PMT_HV_t
parameter name of PMT high voltage
const char *const OPTICS_t
sub-system of PMT
then awk string
JPMTRunsetupParams()
Default constructor.
static std::string getUPI(const JUPI_t &upi)
Get fallback UPI.
std::string toString() const
Convert UPI.
Definition: JUPI_t.hh:141
bool is_default
true if fallback; else false
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:431
static const char DOT
Separator between PBS values.
Definition: JPBS_t.hh:33
Template definition for getting table specific selector.
std::string RUNSETUPID
Definition: JRuns.hh:26