Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPrintTuneHV.cc File Reference

Auxiliary program to print HV-tuning output. More...

#include <iostream>
#include <iomanip>
#include <map>
#include "km3net-dataformat/online/JDAQ.hh"
#include "JSystem/JDate.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JLang/JPredicate.hh"
#include "JSupport/JFilenameSupportkit.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JCalibrate/JFitToT.hh"
#include "JDB/JDB.hh"
#include "JDB/JDBToolkit.hh"
#include "JDB/JDBincludes.hh"
#include "JDB/JProductRouter.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JDetectorIntegration.hh"
#include "JDB/JDetectorIntegration_t.hh"
#include "JSon/JSon.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to print HV-tuning output.

Author
bjung

Definition in file JPrintTuneHV.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 39 of file JPrintTuneHV.cc.

40 {
41  using namespace std;
42  using namespace JPP;
43  using namespace KM3NETDAQ;
44 
45  string usr;
46  string pwd;
47  string cookie;
48 
49  string inputFile;
50  string outputFile;
51 
52  int detid;
53  int debug;
54 
55  try {
56 
57  JParser<> zap("Auxiliary program to print high-voltage tuning results.");
58 
59  zap['u'] = make_field(usr) = "";
60  zap['!'] = make_field(pwd) = "";
61  zap['C'] = make_field(cookie) = "";
62  zap['f'] = make_field(inputFile, "input file (ROOT or JSON output of JTuneHV)");
63  zap['o'] = make_field(outputFile, "output file (for writing failed evaluations") = "";
64  zap['D'] = make_field(detid, "detector identifier");
65  zap['d'] = make_field(debug, "debug") = 2;
66 
67  zap(argc, argv);
68 
69  } catch(const exception &error) {
70 
71  FATAL(error.what() << endl);
72  }
73 
74  JDateAndTime timer;
75  JPersons person;
76  JDetectorIntegration_t detector;
77 
78  try {
79 
80  JDB::reset(usr, pwd, cookie);
81 
82  {
83  JSelector selector = getSelector<JPersons>(JDB::get()->User());
84  ResultSet& rs = getResultSet(getTable<JPersons>(), selector);
85  rs >> person;
86  rs.Close();
87  }
88 
89  {
90  ResultSet& rs = getResultSet(getTable<JDetectorIntegration_t>());
91 
92  if (! (rs >> detector)) {
93  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration_t>());
94  }
95  }
96 
97  } catch (const exception& error) {
98 
99  FATAL(error.what() << endl);
100  }
101 
102  detector.configure(getDetector(detid));
103 
104  const JProductRouter router(detector, PBS::PMT_SEQUENCES);
105 
106  string testType;
107  size_t Ntotal = 0;
108 
109  map<int, JHVCalibration> failureMap;
110 
111  if (isJSONFile(inputFile.c_str())) {
112 
113  json js;
114 
115  ifstream ifs(inputFile.c_str());
116 
117  ifs >> js;
118  ifs.close();
119 
120  JHVCalibration HVcals;
121 
122  json::const_iterator data = js.find(Tests_t);
123 
124  if (data != js.end()) {
125 
126  HVcals = data->get<JHVCalibration>();
127 
128  } else {
129 
130  ERROR("HV calibration data could not be found!");
131  }
132 
133  json::const_iterator DBtype = js.find(Test_t + Type_t);
134 
135  if (DBtype != js.end()) {
136 
137  testType = DBtype->get<string>();
138 
139  } else {
140 
141  WARNING("No database test type specified.");
142  }
143 
144  NOTICE(LEFT (30) << "UPI" << CENTER(35) << "(identifier / location)" <<
145  RIGHT(20) << "HV" << RIGHT (10) << "gain" << RIGHT(10) << "status" << endl);
146 
147  for (JHVCalibration::const_iterator it = HVcals.cbegin(); it != HVcals.cend(); ++it) {
148 
149  const JUPI_t& pmtUPI = it->getUPI();
150  const JUPI_t& domUPI = detector.trace(pmtUPI, PBS::DOM).container.getUPI();
151  const JLocation_t& location = router.getLocation(pmtUPI);
152 
153  int domID = -1;
154 
155  const JDetectorIntegration_t::range_type range = detector.get(domUPI);
156 
157  for (JDetectorIntegration_t::range_const_iterator i = range.first; i != range.second; ++i) {
158 
159  const JUPI_t& upi = detector[i->second].content.getUPI();
160 
161  if (upi.getPBS() == PBS::CLB) {
162 
163  domID = getCLBID(upi);
164 
165  if (it->result != OK_t) {
166  failureMap[domID].push_back(*it);
167  }
168 
169  break;
170  }
171  }
172 
173  NOTICE(LEFT(30) << pmtUPI << "(a.k.a. " << domID << '.' << FILL(2,'0') << location.position << " / " << location << "):" <<
174  right << FIXED(20,1) << it->supplyVoltage << FIXED(10,1) << it->PMTgain << RIGHT(10) << it->result << endl);
175 
176  ++Ntotal;
177  }
178 
179  } else {
180 
181  ERROR(inputFile << " is not a JSON file." << endl);
182  }
183 
184 
185  size_t Nfailed = 0;
186  size_t Nmissing = 0;
187 
188  JHVCalibration failures;
189 
190  NOTICE(endl << FILL(105, '-') << " List of failures" << setfill(' ') << endl);
191 
192  for (map<int, JHVCalibration>::const_iterator i = failureMap.cbegin(); i != failureMap.cend(); ++i) {
193 
194  Nfailed += i->second.size();
195 
196  if (i->second.size() == NUMBER_OF_PMTS) {
197 
198  Nmissing += NUMBER_OF_PMTS;
199  WARNING("No successful calibrations found for module " << i->first << " (dead module?)" << endl);
200 
201  } else {
202 
203  for (JHVCalibration::const_iterator j = i->second.cbegin(); j != i->second.cend(); ++j) {
204 
205  const JUPI_t& pmtUPI = j->getUPI();
206  const JLocation_t& location = router.getLocation(pmtUPI);
207 
208  NOTICE(LEFT(30) << pmtUPI << "(a.k.a. " << i->first << '.' << FILL(2,'0') << location.position << " / " << location << "):" <<
209  right << FIXED(20,1) << j->supplyVoltage << FIXED(10,1) << j->PMTgain << RIGHT(10) << j->result << endl);
210 
211  failures.push_back(*j);
212  }
213  }
214  }
215 
216  NOTICE(endl << FILL(105, '-') << " SUMMARY" << setfill(' ') << endl);
217  NOTICE(LEFT(40) << "Number of evaluated PMTs:" << RIGHT(20) << Ntotal << endl);
218  NOTICE(LEFT(40) << "Number of successful evaluations:" << RIGHT(20) << Ntotal - Nfailed << endl);
219  NOTICE(LEFT(40) << "Number of failed evaluations:" << RIGHT(20) << Nfailed << endl);
220  NOTICE(RIGHT(20) << '-' << LEFT(20) << " in missing modules:" << RIGHT(20) << Nmissing << endl);
221  NOTICE(RIGHT(20) << '-' << LEFT(20) << " other:" << RIGHT(20) << Nfailed - Nmissing << endl << endl);
222 
223  if (!outputFile.empty()) {
224 
225  json js;
226 
227  js[User_t] = person.LOGIN;
228  js[Location_t] = person.LOCATIONID;
229  js[StartTime_t] = timer.toString();
230  js[EndTime_t] = timer().toString();
231  js[Test_t + Type_t] = testType;
232  js[Tests_t] = json(failures);
233 
234  ofstream ofs(outputFile.c_str());
235 
236  ofs << setw(2) << setprecision(8);
237  ofs << js;
238 
239  ofs.close();
240  }
241 
242  return 0;
243 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define WARNING(A)
Definition: JMessage.hh:65
static const std::string Tests_t
static const JPBS_t DOM(3, 4)
PBS of optical module
static const std::string OK_t
static const JPBSSequences PMT_SEQUENCES
PBS sequences for PMT.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
T get(const JHead &header)
Get object from header.
static const std::string Location_t
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:445
string outputFile
static const JPBS_t CLB(3, 4, 3, 2)
PBS of central-logic board
Auxiliary data structure for alignment of data.
Definition: JManip.hh:365
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
Definition: JDBToolkit.cc:5
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
std::vector< JHVCalibration_t > JHVCalibration
PMT high voltage calibration.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
static const std::string Test_t
int debug
debug level
Definition: JSirene.cc:63
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:327
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi mv $WORKDIR/fit.root $MODULE_ROOT typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
Definition: module-Z:fit.sh:84
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
static const std::string EndTime_t
nlohmann::json json
static const std::string Type_t
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
static const std::string StartTime_t
static const std::string User_t
Detector calibration key words for JSON I/O.
int j
Definition: JPolint.hh:666
JCLBIDHelper getCLBID
Function object for mapping UPI of central-logic board to module identifier.
Definition: JDBToolkit.cc:6
do set_variable DETECTOR_TXT $WORKDIR detector
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
bool isJSONFile(const char *file_name)
Check file format.