Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPMTThreshold.hh
Go to the documentation of this file.
1 #ifndef __JDB_JPMTTHRESHOLD__
2 #define __JDB_JPMTTHRESHOLD__
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"; //!< name of PMT threshold
29 
30 
31  /**
32  * Auxiliary class for PMT thresholds.
33  */
34  class JPMTThreshold :
35  public std::map<std::string, int>
36  {
37  public:
38  /**
39  * Type definition of PMT threshold.
40  */
41  struct threshold_type {
42  bool is_default; //!< true by default; else false
43  int value; //!< value [DAC]
44  };
45 
46 
47  /**
48  * Default constructor.
49  */
51  {}
52 
53 
54  /**
55  * Constructor.
56  *
57  * \param id detector identifier
58  * \param run run number
59  */
60  JPMTThreshold(const int id, const int run)
61  {
62  configure(id, run);
63  }
64 
65 
66  /**
67  * Configure PMT thresholds for given detector and run.
68  *
69  * \param id detector identifier
70  * \param run run number
71  */
72  void configure(const int id, const int run)
73  {
74  using namespace std;
75  using namespace JPP;
76 
77  this->clear();
78 
79  string rs_oid;
80  JAllParams upars;
81 
82  {
83  ResultSet& rs = getResultSet(getTable<JRuns>(), getSelector<JRuns>(id, run));
84 
86 
87  if (rs >> parameters) {
88  rs_oid = parameters.RUNSETUPID;
89  }
90 
91  rs.Close();
92  }
93  {
94  ResultSet& rs = getResultSet(getTable<JAllParams>(), getSelector<JAllParams>(OPTICS_t));
95 
96  for (JAllParams parameters; rs >> parameters; ) {
97  if (parameters.NAME == PMT_THRESHOLD_t) {
98  upars = parameters;
99  }
100  }
101 
102  rs.Close();
103  }
104  {
105  ResultSet& rs = getResultSet(getTable<JRunsetupParams>(), getSelector<JRunsetupParams>(getDetector(id), rs_oid));
106 
107  for (JRunsetupParams parameters; rs >> parameters; ) {
108  if (parameters.PAR_OID == upars.OID && parameters.ISINPUT == 'Y') {
109  if (parameters.VALUE != "") {
110  istringstream(parameters.VALUE) >> (*this)[parameters.UPIFILTER];
111  }
112  }
113  }
114 
115  rs.Close();
116  }
117  }
118 
119 
120  /**
121  * Get PMT threshold for given %UPI of PMT.
122  *
123  * \param upi %UPI
124  * \return PMT threshold
125  */
126  threshold_type operator()(const JUPI_t& upi) const
127  {
128  const_iterator p = this->find(upi.toString());
129 
130  const bool is_default = (p == this->end());
131 
132  if (is_default) {
133 
134  std::ostringstream os;
135 
136  os << upi.getPBS()
138  << upi.getVariant()
140  << JUPI_t::DOT;
141 
142  p = this->find(os.str());
143  }
144 
145  if (p != this->end())
146  return { is_default, p->second };
147  else
148  THROW(JDatabaseException, "Invalid UPI " << upi);
149  }
150 
151 
152  /**
153  * Write PMT thresholds to output stream.
154  *
155  * \param out output stream
156  * \param object PMT thresholds
157  * \return output stream
158  */
159  friend inline std::ostream& operator<<(std::ostream& out, const JPMTThreshold& object)
160  {
161  using namespace std;
162 
163  for (JPMTThreshold::const_iterator i = object.begin(); i != object.end(); ++i) {
164  out << left << setw(32) << i->first << ' ' << right << setw(3) << i->second << endl;
165  }
166 
167  return out;
168  }
169  };
170 }
171 
172 #endif
Auxiliary class for PMT thresholds.
const std::string & getVariant() const
Get variant.
Definition: JUPI_t.hh:108
JPMTThreshold(const int id, const int run)
Constructor.
Database exception.
Definition: JException.hh:648
void configure(const int id, const int run)
Configure PMT thresholds for given detector and run.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
*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
friend std::ostream & operator<<(std::ostream &out, const JPMTThreshold &object)
Write PMT thresholds to output stream.
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
name of PMT threshold
const JPBS_t & getPBS() const
Get PBS.
Definition: JPBS_t.hh:99
threshold_type operator()(const JUPI_t &upi) const
Get PMT threshold for given UPI of PMT.
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
Definition: JDBToolkit.cc:5
const char *const OPTICS_t
sub-system of PMT
JPMTThreshold()
Default constructor.
std::string toString() const
Convert UPI.
Definition: JUPI_t.hh:141
Type definition of PMT threshold.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:432
bool is_default
true by default; else false
static const char DOT
Separator between PBS values.
Definition: JPBS_t.hh:31
Template definition for getting table specific selector.
std::string RUNSETUPID
Definition: JRuns.hh:26