Jpp  15.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JCheckHV.cc File Reference

Auxiliary program to check HV. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TGraph.h"
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JDBToolkit.hh"
#include "JDB/JDetectorIntegration.hh"
#include "JDB/JDatalogNumbers.hh"
#include "JDB/JPMTHVRunSettings.hh"
#include "JDB/JLocation_t.hh"
#include "JDB/JSupport.hh"
#include "JROOT/JGraph.hh"
#include "JROOT/JRootToolkit.hh"
#include "JROOT/JManager.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to check HV.

Author
mdejong

Definition in file JCheckHV.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 38 of file JCheckHV.cc.

39 {
40  using namespace std;
41  using namespace JPP;
42 
43  JServer server;
44  string usr;
45  string pwd;
46  string cookie;
47  string outputFile;
48  string detid;
49  vector<int> runs;
50  long long int numberOfRows;
51  double precision;
52  int debug;
53 
54  try {
55 
56  JParser<> zap("Auxiliary program to check HV.");
57 
58  zap['s'] = make_field(server) = getServernames();
59  zap['u'] = make_field(usr) = "";
60  zap['!'] = make_field(pwd) = "";
61  zap['C'] = make_field(cookie) = "";
62  zap['o'] = make_field(outputFile) = "hv.root";
63  zap['D'] = make_field(detid, "Detector identifier");
64  zap['R'] = make_field(runs, "Run(s)");
65  zap['n'] = make_field(numberOfRows, "Maximal number of rows") = numeric_limits<long long int>::max();
66  zap['e'] = make_field(precision) = 0.5;
67  zap['d'] = make_field(debug) = 2;
68 
69  zap(argc, argv);
70  }
71  catch(const exception &error) {
72  FATAL(error.what() << endl);
73  }
74 
75 
77  JManager<JLocation_t, TH1D> H1(new TH1D("HV[%]", NULL, 201, -1500.0, +1500.0));
78 
79  map<JUPI_t, int> errors;
80 
81  try {
82 
83  JDB::reset(usr, pwd, cookie);
84 
85  int ID = -1;
86 
87  if (is_integer(detid)) {
88  ID = to_value<int>(detid);
89  detid = getDetector(ID);
90  } else {
91  ID = getDetector(detid);
92  }
93 
94  typedef map<JUPI_t, JLocation_t> detector_type;
95 
96  detector_type detector;
97 
98  {
99  ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(ID));
100 
101  for (JDetectorIntegration parameters; rs >> parameters; ) {
102 
103  if (parameters.PMTUPI.getPBS() == PBS::PMT) {
104  detector[parameters.PMTUPI] = JLocation_t(parameters.DUID, parameters.FLOORID, parameters.CABLEPOS);
105  }
106  }
107 
108  rs.Close();
109  }
110 
111  for (const int run : runs) {
112 
114 
115  {
116  ResultSet& rs = getResultSet(getTable<JPMTHVRunSettings>(), getSelector<JPMTHVRunSettings>(detid, run));
117 
118  for (JPMTHVRunSettings parameters; rs >> parameters; ) {
119 
120  const JLocation_t location(parameters.DUID, parameters.FLOORID, parameters.CABLEPOS);
121 
122  if (parameters.CABLEPOS != parameters.PMTINTID) {
123  WARNING("PMT " << location << " position " << parameters.PMTINTID << endl);
124  }
125 
126  HV[location] = parameters.HV_VALUE;
127  }
128 
129  rs.Close();
130  }
131 
132  if (debug >= debug_t) {
133 
134  cout << "HV settings " << setw(8) << run << endl;
135 
136  for (map<JLocation_t, double>::const_iterator i = HV.begin(); i != HV.end(); ++i) {
137  cout << i->first << ' ' << FIXED(6,1) << i->second << endl;
138  }
139  }
140 
141  JSelector selection(&JDatalogNumbers::PARAMETER_NAME, "pmt_highvolt@");
142 
143  selection += getSelector<JDatalogNumbers>(detid, run, run);
144 
145  ResultSet& rs = getResultSet(getTable<JDatalogNumbers>(), selection);
146 
147  long long int counter = 0;
148 
149  for (JDatalogNumbers parameters; rs >> parameters && counter != numberOfRows; ++counter) {
150 
151  STATUS(setw(10) << counter << '\r'); DEBUG(endl);
152 
153  const JUPI_t upi = parameters.SOURCE_NAME;
154  const JLocation_t location = detector[upi];
155 
156  DEBUG(location << ' ' << FIXED(7,1) << HV[location] << ' ' << FIXED(7,1) << parameters.DATA_VALUE << endl);
157 
158  if (location.is_valid()) {
159 
160  G1[location].put(parameters.getTime(), parameters.DATA_VALUE);
161 
162  H1[location]->Fill(HV[location] - parameters.DATA_VALUE);
163 
164  if (fabs(HV[location] - parameters.DATA_VALUE) > precision) {
165  ERROR("HV " << location << " set/read " << FIXED(7,1) << HV[location] << "/" << FIXED(7,1) << parameters.DATA_VALUE << endl);
166  }
167 
168  } else {
169 
170  errors[upi] += 1;
171  }
172 
173  STATUS(endl);
174  }
175 
176  rs.Close();
177  }
178  }
179  catch(const exception& error) {
180  FATAL(error.what() << endl);
181  }
182 
183 
184  for (map<JUPI_t, int>::const_iterator i = errors.begin(); i != errors.end(); ++i) {
185  ERROR("Alien UPI " << setw(24) << i->first << ' ' << i->second << endl);
186  }
187 
188  TFile out(outputFile.c_str(), "recreate");
189 
190  for (map<JLocation_t, JGraph_t>::const_iterator i = G1.begin(); i != G1.end(); ++i) {
191  out << JGraph(i->second, MAKE_CSTRING("G[" << i->first << "].hv"));
192  }
193 
194  out << H1;
195 
196  out.Write();
197  out.Close();
198 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define WARNING(A)
Definition: JMessage.hh:65
debug
Definition: JMessage.hh:29
do rm f tmp H1
static const JPBS_t PMT(3, 4, 2, 3)
PBS of photo-multiplier tube (PMT)
#define STATUS(A)
Definition: JMessage.hh:63
*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
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
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
Double_t G1(const Double_t x)
Integral of method g1.
Definition: JQuantiles.cc:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define ERROR(A)
Definition: JMessage.hh:66
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
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