Jpp  15.0.1-rc.1-highqe
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintTuneHV.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <map>
4 
6 
7 #include "JSystem/JDate.hh"
8 
9 #include "JLang/JUUID.hh"
10 
11 #include "Jeep/JPrint.hh"
12 #include "Jeep/JParser.hh"
13 #include "Jeep/JMessage.hh"
14 
15 #include "JSupport/JMeta.hh"
17 
18 #include "JDetector/JDetector.hh"
19 #include "JDetector/JPMTRouter.hh"
22 
23 #include "JDB/JDBSupportkit.hh"
24 #include "JDB/JProductRouter.hh"
25 
26 #include "JSon/JSon.hh"
27 
28 
29 /**
30  * \file
31  *
32  * Auxiliary program to print HV-tuning output.
33  *
34  * An output JSON file listing all failed evaluations other than those in dead modules\n
35  * can be created optionally by specifiying an output file and the meta-information
36  * required by the database (user login and location ID).
37  * \author bjung
38  */
39 int main(int argc, char **argv)
40 {
41  using namespace std;
42  using namespace JPP;
43  using namespace KM3NETDAQ;
44 
45  string inputFile;
46  string detectorFile;
47  string outputFile;
48 
49  string login;
50  string locationID;
51  int elapsedTime = 0;
52 
53  int debug;
54 
55  try {
56 
57  JProperties properties;
58 
59  properties.insert(gmake_property(login));
60  properties.insert(gmake_property(locationID));
61  properties.insert(gmake_property(elapsedTime));
62 
63  JParser<> zap("Auxiliary program to print high-voltage tuning results.");
64 
65  zap['f'] = make_field(inputFile, "input file (JSON output of JTuneHV)");
66  zap['a'] = make_field(detectorFile, "detector file");
67  zap['o'] = make_field(outputFile, "output file (for writing failed evaluations to separate JSON output)") = "";
68  zap['#'] = make_field(properties, "database information") = JPARSER::initialised();
69  zap['d'] = make_field(debug, "debug") = 2;
70 
71  zap(argc, argv);
72 
73  } catch(const exception &error) {
74 
75  FATAL(error.what() << endl);
76  }
77 
78  if (!outputFile.empty() && (login.empty() || locationID.empty())) {
79 
80  FATAL("Missing user information (please specify via -#login and -#locationID).");
81  }
82 
83 
84  const JUUID& UUID = JUUID::rndm();
85 
86  JDateAndTimeFormat format = ISO8601;
87  JDateAndTime timer;
88 
89  timer->tm_sec -= elapsedTime;
90 
92 
93  try {
94  load(detectorFile, detector);
95  }
96  catch (const exception& error) {
97  FATAL(error.what() << endl);
98  }
99 
100  const JPMTRouter PMTrouter(detector);
101 
102 
103  JDBAPIVersion DBAPIVersion;
104  string DBTestType;
105  string metaInfoStr = MAKE_STRING(JMeta(argc, argv));
106 
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  // Extract data
121 
122  json::const_iterator i0 = js.find(APIVersion_t);
123 
124  if (i0 != js.cend()) {
125 
126  istringstream iss(i0->get<string>());
127 
128  iss >> DBAPIVersion;
129  }
130 
131  JHVCalibration HVcals;
132 
133  json::const_iterator i1 = js.find(Data_t);
134 
135  if ((DBAPIVersion.getMajorVersion() == 2) &&
136  (i1 != js.cend() && i1->size() > 0)) {
137 
138  DBTestType = (*i1)[0].at(Test_t + Type_t).get<string>();
139 
140  JHVCalibration_t::setVersion(getDBVersionTuneHV(DBTestType));
141 
142  HVcals = (*i1)[0].at(Tests_t).get<JHVCalibration>();
143  metaInfoStr += (*i1)[0].at(Provenance_t + Info_t).at(Configuration_t).get<string>();
144 
145  } else {
146 
147  DBTestType = js.at(Test_t + Type_t).get<string>();
148 
149  JHVCalibration_t::setVersion(getDBVersionTuneHV(DBTestType));
150 
151  HVcals = js.at(Tests_t).get<JHVCalibration>();
152  }
153 
154 
155  NOTICE(LEFT (30) << "UPI" << CENTER(35) << "(identifier / location)" <<
156  RIGHT(20) << "HV" << RIGHT (10) << "gain" << RIGHT(10) << "status" << endl);
157 
158  for (JHVCalibration::const_iterator it = HVcals.cbegin(); it != HVcals.cend(); ++it) {
159 
160  const JUPI_t& pmtUPI = it->getUPI();
161  const JModule& module = PMTrouter.getParentModule(pmtUPI.getNumber());
162  const JPMTIdentifier& pmtID = PMTrouter.getIdentifier (pmtUPI.getNumber());
163 
164  const JLocation_t location(module.getString(), module.getFloor(), pmtID.getTDC());
165 
166  if (it->result != OK_t) {
167  failureMap[pmtID.getModuleID()].push_back(*it);
168  }
169 
170  NOTICE(LEFT (30) << pmtUPI << "(a.k.a. " << pmtID << " / " << location << "):" <<
171  FIXED(20,1) << it->supplyVoltage << RIGHT(10) << it->result << endl);
172 
173  ++Ntotal;
174  }
175 
176  } else {
177 
178  ERROR(inputFile << " is not a JSON file." << endl);
179  }
180 
181 
182  size_t Nfailed = 0;
183  size_t Nmissing = 0;
184 
185  JHVCalibration failures;
186 
187  NOTICE(endl << FILL(105, '-') << " List of failures" << setfill(' ') << endl);
188 
189  for (map<int, JHVCalibration>::const_iterator i = failureMap.cbegin(); i != failureMap.cend(); ++i) {
190 
191  Nfailed += i->second.size();
192 
193  if (i->second.size() == NUMBER_OF_PMTS) {
194 
195  Nmissing += NUMBER_OF_PMTS;
196  WARNING("No successful calibrations found for module " << i->first << " (dead module?)" << endl);
197 
198  } else {
199 
200  for (JHVCalibration::const_iterator j = i->second.cbegin(); j != i->second.cend(); ++j) {
201 
202  const JUPI_t& pmtUPI = j->getUPI();
203  const JModule& module = PMTrouter.getParentModule(pmtUPI.getNumber());
204  const JPMTIdentifier& pmtID = PMTrouter.getIdentifier (pmtUPI.getNumber());
205 
206  const JLocation_t location(module.getString(), module.getFloor(), pmtID.getTDC());
207 
208  NOTICE(LEFT(30) << pmtUPI << "(a.k.a. " << pmtID << " / " << location << "):" <<
209  right << FIXED(20,1) << j->supplyVoltage << 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 
224  if (!outputFile.empty()) {
225 
226  json js;
227 
228  if (DBAPIVersion.getMajorVersion() == 2) {
229 
230  json error = { {Message_t, "" },
231  {Code_t, OK_t },
232  {Arguments_t, json::array() } };
233 
234  json metaData = { {Configuration_t, metaInfoStr },
235  {UUID_t, MAKE_STRING(UUID) } };
236 
237  json data = { {Provenance_t + Info_t, json(metaData) },
238  {User_t, login },
239  {Location_t, locationID },
240  {Start_t + Time_t, timer.toString (format)},
241  {End_t + Time_t, timer().toString(format)},
242  {Test_t + Type_t, DBTestType },
243  {Tests_t, json(failures) } };
244 
245  js[APIVersion_t] = MAKE_STRING(DBAPIVersion);
246  js[Data_t + Type_t] = MAKE_STRING("ProductTestSession");
247  js[Encoding_t] = MAKE_STRING("NativeJSON");
248  js[Error_t] = json(error);
249  js[Start_t] = timer.toString(format);
250  js[End_t] = timer().toString(format);
251  js[Data_t][0] = json(data);
252 
253  } else {
254 
255  js[User_t] = login;
256  js[Location_t] = locationID;
257  js[Test_t + Type_t] = DBTestType;
258  js[Start_t + Time_t] = timer.toString(format);
259  js[End_t + Time_t] = timer().toString(format);
260  js[Tests_t] = json(failures);
261  }
262 
263  ofstream ofs(outputFile.c_str());
264 
265  ofs << setw(2) << setprecision(8);
266  ofs << js;
267 
268  ofs.close();
269  }
270 
271  return 0;
272 }
static JDBTestTypesTuneHV & getDBVersionTuneHV
Function object for looking up the HV-tuning database version number corresponding to a specific test...
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1500
static const std::string UUID_t
#define WARNING(A)
Definition: JMessage.hh:65
int main(int argc, char *argv[])
Definition: Main.cc:15
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
Data structure for a composite optical module.
Definition: JModule.hh:68
int getNumber() const
Get serial number.
Definition: JUPI_t.hh:130
static const std::string Time_t
#define gmake_property(A)
macro to convert (template) parameter to JPropertiesElement object
JPMTIdentifier getIdentifier(const JPMTAddress &address) const
Get identifier of PMT.
Definition: JPMTRouter.hh:126
static const std::string Tests_t
static const std::string OK_t
Detector data structure.
Definition: JDetector.hh:89
int getModuleID() const
Get module identifier.
Utility class to parse parameter values.
Definition: JProperties.hh:496
static const std::string Location_t
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
JDateAndTimeFormat
Date and time formats.
Universal product identifier (UPI).
Definition: JUPI_t.hh:29
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
static const std::string Encoding_t
Data structure for detector geometry and calibration.
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
const JUPI_t & getUPI() const
Get UPI.
Definition: JUPI_t.hh:97
static const std::string Provenance_t
Date and time functions.
Auxiliary data structure for alignment of data.
Definition: JManip.hh:366
static const std::string Arguments_t
static const std::string Configuration_t
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:196
Auxiliary data structure for location of product in detector.
Definition: JLocation_t.hh:24
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Auxiliary data structure for I/O of database API versions.
const JModule & getParentModule(const JObjectID &id) const
Get parent module.
Definition: JPMTRouter.hh:162
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
static const std::string Code_t
static const std::string Test_t
ISO-8601 standard.
static const std::string Info_t
static const std::string Message_t
Direct access to PMT in detector data structure.
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
int getString() const
Get string number.
Definition: JLocation.hh:134
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Auxililary class to get date and time.
Utility class to parse command line options.
Simple wrapper for UUID.
Definition: JUUID.hh:22
nlohmann::json json
static const std::string Type_t
static const std::string APIVersion_t
static const std::string User_t
Detector calibration key words for JSON I/O.
int j
Definition: JPolint.hh:666
static const std::string Error_t
do set_variable DETECTOR_TXT $WORKDIR detector
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
static const std::string Data_t
static const std::string End_t
static const std::string Start_t
Specifications of file name extensions.
bool isJSONFile(const char *file_name)
Check file format.