Jpp - the software that should make you happy
 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 "JROOT/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  JServer server;
42  string usr;
43  string pwd;
44  string cookie;
45  string outputFile;
46  string detid;
47  int run;
48  long long int numberOfRows;
49  double precision;
50  int debug;
51 
52  try {
53 
54  JParser<> zap("Auxiliary program to check HV.");
55 
56  zap['s'] = make_field(server) = getServernames();
57  zap['u'] = make_field(usr) = "";
58  zap['!'] = make_field(pwd) = "";
59  zap['C'] = make_field(cookie) = "";
60  zap['o'] = make_field(outputFile) = "hv.root";
61  zap['D'] = make_field(detid, "Detector identifier");
62  zap['R'] = make_field(run, "Run");
63  zap['n'] = make_field(numberOfRows, "Maximal number of rows") = numeric_limits<long long int>::max();
64  zap['e'] = make_field(precision) = 0.5;
65  zap['d'] = make_field(debug) = 2;
66 
67  zap(argc, argv);
68  }
69  catch(const exception &error) {
70  FATAL(error.what() << endl);
71  }
72 
73 
74  JManager<JLocation_t, TH1D> manager(new TH1D("HV[%]", NULL, 200, -1500.0, +1500.0));
75 
76  try {
77 
78  JDB::reset(usr, pwd, cookie);
79 
80  if (is_integer(detid)) {
81  detid = getDetector(to_value<int>(detid));
82  }
83 
84  JDetectorIntegration_t detector;
85 
86  {
87  DEBUG("Reading database table " << getTable<JDetectorIntegration_t>() << endl);
88 
89  ResultSet& rs = getResultSet(getTable<JDetectorIntegration_t>());
90 
91  if (! (rs >> detector)) {
92  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration_t>());
93  }
94  }
95 
96  DEBUG("Number of integrated products (before) " << right << detector.size() << endl);
97 
98  detector.configure(detid);
99 
100  DEBUG("Number of integrated products (after) " << right << detector.size() << endl);
101 
102  const JProductRouter router(detector, PBS::CLB_SEQUENCES);
103 
105 
106  {
107  ResultSet& rs = getResultSet(getTable<JPMTHVRunSettings>(), getSelector<JPMTHVRunSettings>(detid, run));
108 
109  for (JPMTHVRunSettings parameters; rs >> parameters; ) {
110 
111  const JLocation_t location(parameters.DUID, parameters.FLOORID, parameters.PMTINTID);
112 
113  HV[location] = parameters.HV_VALUE;
114  }
115 
116  rs.Close();
117  }
118 
119  if (debug >= debug_t) {
120 
121  cout << "HV settings:" << endl;
122 
123  for (map<JLocation_t, double>::const_iterator i = HV.begin(); i != HV.end(); ++i) {
124  cout << i->first << ' ' << FIXED(6,1) << i->second << endl;
125  }
126  }
127 
128  JSelector selection(&JDatalogNumbers::PARAMETER_NAME, "pmt_highvolt@");
129 
130  selection += getSelector<JDatalogNumbers>(detid, run, run);
131 
132  ResultSet& rs = getResultSet(getTable<JDatalogNumbers>(), selection);
133 
134  long long int counter = 0;
135 
136  for (JDatalogNumbers parameters; rs >> parameters && counter != numberOfRows; ++counter) {
137 
138  STATUS(setw(10) << counter << '\r'); DEBUG(endl);
139 
140  const JUPI_t upi = parameters.SOURCE_NAME;
141  const JLocation_t& location = router.getLocation(upi);
142 
143  DEBUG(location << ' ' << FIXED(6,1) << HV[location] << ' ' << FIXED(6,1) << parameters.DATA_VALUE << endl);
144 
145  if (location.is_valid()) {
146 
147  const double hv = HV[location] - parameters.DATA_VALUE ;
148 
149  manager[location]->Fill(hv);
150 
151  if (fabs(hv) > precision) {
152  WARNING("HV " << location << " set/read " << FIXED(6,1) << HV[location] << "/" << FIXED(6,1) << parameters.DATA_VALUE << endl);
153  }
154  }
155  STATUS(endl);
156  }
157  }
158  catch(const exception& error) {
159  FATAL(error.what() << endl);
160  }
161 
162 
163  TFile out(outputFile.c_str(), "recreate");
164 
165  out << manager;
166 
167  out.Write();
168  out.Close();
169 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define WARNING(A)
Definition: JMessage.hh:65
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
#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: JManip.hh:446
string outputFile
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
Definition: JDBToolkit.cc:5
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
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:63
static const JPBSSequences CLB_SEQUENCES
PBS sequences for central-logic board.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:432
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:98
do set_variable DETECTOR_TXT $WORKDIR detector