Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCheckHV.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <limits>
5 #include <map>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH1D.h"
10 
11 #include "JDB/JDB.hh"
12 #include "JDB/JSelector.hh"
14 #include "JDB/JDBToolkit.hh"
16 #include "JDB/JProductRouter.hh"
17 #include "JDB/JAllParams.hh"
18 #include "JDB/JDatalogNumbers.hh"
19 #include "JDB/JPMTHVRunSettings.hh"
20 #include "JDB/JSupport.hh"
21 
22 #include "JGizmo/JManager.hh"
23 #include "JLang/JLangToolkit.hh"
24 
25 #include "Jeep/JPrint.hh"
26 #include "Jeep/JParser.hh"
27 #include "Jeep/JMessage.hh"
28 
29 
30 /**
31  * \file
32  *
33  * Auxiliary program to check HV.
34  * \author mdejong
35  */
36 int main(int argc, char **argv)
37 {
38  using namespace std;
39  using namespace JPP;
40 
41  string usr;
42  string pwd;
43  string cookie;
44  string outputFile;
45  string detid;
46  int run;
47  long long int numberOfRows;
48  double precision;
49  int debug;
50 
51  try {
52 
53  JParser<> zap("Auxiliary program to check HV.");
54 
55  zap['u'] = make_field(usr) = "";
56  zap['!'] = make_field(pwd) = "";
57  zap['C'] = make_field(cookie) = "";
58  zap['o'] = make_field(outputFile) = "hv.root";
59  zap['D'] = make_field(detid, "Detector identifier");
60  zap['R'] = make_field(run, "Run");
61  zap['n'] = make_field(numberOfRows, "Maximal number of rows") = numeric_limits<long long int>::max();
62  zap['p'] = make_field(precision) = 0.5;
63  zap['d'] = make_field(debug) = 2;
64 
65  zap(argc, argv);
66  }
67  catch(const exception &error) {
68  FATAL(error.what() << endl);
69  }
70 
71 
72  JManager<JLocation_t, TH1D> manager(new TH1D("HV[%]", NULL, 200, -1500.0, +1500.0));
73 
74  try {
75 
76  JDB::reset(usr, pwd, cookie);
77 
78  if (is_integer(detid)) {
79  detid = getDetector(to_value<int>(detid));
80  }
81 
82  JDetectorIntegration_t detector;
83 
84  {
85  DEBUG("Reading database table " << getTable<JDetectorIntegration_t>() << endl);
86 
87  ResultSet& rs = getResultSet(getTable<JDetectorIntegration_t>());
88 
89  if (! (rs >> detector)) {
90  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration_t>());
91  }
92  }
93 
94  DEBUG("Number of integrated products (before) " << right << detector.size() << endl);
95 
96  detector.configure(detid);
97 
98  DEBUG("Number of integrated products (after) " << right << detector.size() << endl);
99 
100  const JProductRouter router(detector);
101 
103 
104  {
105  ResultSet& rs = getResultSet(getTable<JPMTHVRunSettings>(), getSelector<JPMTHVRunSettings>(detid, run));
106 
107  for (JPMTHVRunSettings parameters; rs >> parameters; ) {
108 
109  const JLocation_t location(parameters.DUID, parameters.FLOORID, parameters.PMTINTID);
110 
111  HV[location] = parameters.HV_VALUE;
112  }
113 
114  rs.Close();
115  }
116 
117  if (debug >= debug_t) {
118 
119  cout << "HV settings:" << endl;
120 
121  for (map<JLocation_t, double>::const_iterator i = HV.begin(); i != HV.end(); ++i) {
122  cout << i->first << ' ' << FIXED(6,1) << i->second << endl;
123  }
124  }
125 
126  JSelector selection(&JDatalogNumbers::PARAMETER_NAME, "pmt_highvolt@");
127 
128  selection += getSelector<JDatalogNumbers>(detid, run, run);
129 
130  ResultSet& rs = getResultSet(getTable<JDatalogNumbers>(), selection);
131 
132  long long int counter = 0;
133 
134  for (JDatalogNumbers parameters; rs >> parameters && counter != numberOfRows; ++counter) {
135 
136  STATUS(setw(10) << counter << '\r'); DEBUG(endl);
137 
138  const JUPI upi = parameters.SOURCE_NAME;
139  const JLocation_t& location = router.getLocation(upi);
140 
141  DEBUG(location << ' ' << FIXED(6,1) << HV[location] << ' ' << FIXED(6,1) << parameters.DATA_VALUE << endl);
142 
143  if (location != JLocation_t()) {
144 
145  const double hv = HV[location] - parameters.DATA_VALUE ;
146 
147  manager[location]->Fill(hv);
148 
149  if (fabs(hv) > precision) {
150  WARNING("HV " << location << " set/read " << FIXED(6,1) << HV[location] << "/" << FIXED(6,1) << parameters.DATA_VALUE << endl);
151  }
152  }
153  STATUS(endl);
154  }
155  }
156  catch(const exception& error) {
157  FATAL(error.what() << endl);
158  }
159 
160 
161  TFile out(outputFile.c_str(), "recreate");
162 
163  out << manager;
164 
165  out.Write();
166  out.Close();
167 }
Utility class to parse command line options.
Definition: JParser.hh:1493
#define WARNING(A)
Definition: JMessage.hh:65
debug
Definition: JMessage.hh:29
#define STATUS(A)
Definition: JMessage.hh:63
#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
Dynamic ROOT object management.
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
string outputFile
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
ROOT TTree parameter settings.
int debug
debug level
Definition: JSirene.cc:61
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
static const JDetectorsHelper & getDetector
Function object for mapping serial number and object identifier of detectors.
Definition: JDBToolkit.hh:131
void reset(T &value)
Reset value.
Utility class to parse command line options.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
int main(int argc, char *argv[])
Definition: Main.cpp:15