Jpp  18.5.0
the software that should make you happy
 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/JDateAndTime.hh"
#include "JLang/JUUID.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JFilenameSupportkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JPMTRouter.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JDB/JDBSupportkit.hh"
#include "JDB/JProductRouter.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.

An output JSON file listing all failed evaluations other than those in dead modules
can be created optionally by specifiying an output file and the meta-information required by the database (user login and location ID).

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 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  JDateAndTime timer;
87 
88  timer.sub(elapsedTime);
89 
90  JDetector detector;
91 
92  try {
93  load(detectorFile, detector);
94  }
95  catch (const exception& error) {
96  FATAL(error.what() << endl);
97  }
98 
99  const JPMTRouter PMTrouter(detector);
100 
101 
102  JDBAPIVersion DBAPIVersion;
103  string DBTestType;
104  string metaInfoStr = MAKE_STRING(JMeta(argc, argv));
105 
106  size_t Ntotal = 0;
107 
108  map<int, JHVCalibration> failureMap;
109 
110  if (isJSONFile(inputFile.c_str())) {
111 
112  json js;
113 
114  ifstream ifs(inputFile.c_str());
115 
116  ifs >> js;
117  ifs.close();
118 
119  // Extract data
120 
121  json::const_iterator i0 = js.find(APIVersion_t);
122 
123  if (i0 != js.cend()) {
124 
125  istringstream iss(i0->get<string>());
126 
127  iss >> DBAPIVersion;
128  }
129 
130  JHVCalibration HVcals;
131 
132  json::const_iterator i1 = js.find(Data_t);
133 
134  if ((DBAPIVersion.getMajorVersion() == 2) &&
135  (i1 != js.cend() && i1->size() > 0)) {
136 
137  DBTestType = (*i1)[0].at(Test_t + Type_t).get<string>();
138 
139  JHVCalibration_t::setVersion(getDBVersionTuneHV(DBTestType));
140 
141  HVcals = (*i1)[0].at(Tests_t).get<JHVCalibration>();
142  metaInfoStr += (*i1)[0].at(Provenance_t + Info_t).at(Configuration_t).get<string>();
143 
144  } else {
145 
146  DBTestType = js.at(Test_t + Type_t).get<string>();
147 
148  JHVCalibration_t::setVersion(getDBVersionTuneHV(DBTestType));
149 
150  HVcals = js.at(Tests_t).get<JHVCalibration>();
151  }
152 
153 
154  NOTICE(LEFT (30) << "UPI" << CENTER(35) << "(identifier / location)" <<
155  RIGHT(20) << "HV" << RIGHT (10) << "gain" << RIGHT(10) << "status" << endl);
156 
157  for (JHVCalibration::const_iterator it = HVcals.cbegin(); it != HVcals.cend(); ++it) {
158 
159  const JUPI_t& pmtUPI = it->getUPI();
160  const JModule& module = PMTrouter.getParentModule(pmtUPI.getNumber());
161  const JPMTIdentifier& pmtID = PMTrouter.getIdentifier (pmtUPI.getNumber());
162 
163  const JLocation_t location(module.getString(), module.getFloor(), pmtID.getTDC());
164 
165  if (it->result != OK_t) {
166  failureMap[pmtID.getModuleID()].push_back(*it);
167  }
168 
169  NOTICE(LEFT (30) << pmtUPI << "(a.k.a. " << pmtID << " / " << location << "):" <<
170  FIXED(20,1) << it->supplyVoltage << RIGHT(10) << it->result << endl);
171 
172  ++Ntotal;
173  }
174 
175  } else {
176 
177  ERROR(inputFile << " is not a JSON file." << endl);
178  }
179 
180 
181  size_t Nfailed = 0;
182  size_t Nmissing = 0;
183 
185 
186  NOTICE(endl << FILL(105, '-') << " List of failures" << setfill(' ') << endl);
187 
188  for (map<int, JHVCalibration>::const_iterator i = failureMap.cbegin(); i != failureMap.cend(); ++i) {
189 
190  Nfailed += i->second.size();
191 
192  if (i->second.size() == NUMBER_OF_PMTS) {
193 
194  Nmissing += NUMBER_OF_PMTS;
195  WARNING("No successful calibrations found for module " << i->first << " (dead module?)" << endl);
196 
197  } else {
198 
199  for (JHVCalibration::const_iterator j = i->second.cbegin(); j != i->second.cend(); ++j) {
200 
201  const JUPI_t& pmtUPI = j->getUPI();
202  const JModule& module = PMTrouter.getParentModule(pmtUPI.getNumber());
203  const JPMTIdentifier& pmtID = PMTrouter.getIdentifier (pmtUPI.getNumber());
204 
205  const JLocation_t location(module.getString(), module.getFloor(), pmtID.getTDC());
206 
207  NOTICE(LEFT(30) << pmtUPI << "(a.k.a. " << pmtID << " / " << location << "):" <<
208  right << FIXED(20,1) << j->supplyVoltage << RIGHT(10) << j->result << endl);
209 
210  failures.push_back(*j);
211  }
212  }
213  }
214 
215  NOTICE(endl << FILL(105, '-') << " SUMMARY" << setfill(' ') << endl);
216  NOTICE(LEFT(40) << "Number of evaluated PMTs:" << RIGHT(20) << Ntotal << endl);
217  NOTICE(LEFT(40) << "Number of successful evaluations:" << RIGHT(20) << Ntotal - Nfailed << endl);
218  NOTICE(LEFT(40) << "Number of failed evaluations:" << RIGHT(20) << Nfailed << endl);
219  NOTICE(RIGHT(20) << '-' << LEFT(20) << " in missing modules:" << RIGHT(20) << Nmissing << endl);
220  NOTICE(RIGHT(20) << '-' << LEFT(20) << " other:" << RIGHT(20) << Nfailed - Nmissing << endl << endl);
221 
222 
223  if (!outputFile.empty()) {
224 
225  json js;
226 
227  if (DBAPIVersion.getMajorVersion() == 2) {
228 
229  json error = { {Message_t, "" },
230  {Code_t, OK_t },
231  {Arguments_t, json::array() } };
232 
233  json metaData = { {Configuration_t, metaInfoStr },
234  {UUID_t, MAKE_STRING(UUID) } };
235 
236  json data = { {Provenance_t + Info_t, json(metaData) },
237  {User_t, login },
238  {Location_t, locationID },
239  {Start_t + Time_t, timer.toString() },
240  {End_t + Time_t, timer().toString() },
241  {Test_t + Type_t, DBTestType },
242  {Tests_t, json(failures) } };
243 
244  js[APIVersion_t] = MAKE_STRING(DBAPIVersion);
245  js[Data_t + Type_t] = MAKE_STRING("ProductTestSession");
246  js[Encoding_t] = MAKE_STRING("NativeJSON");
247  js[Error_t] = json(error);
248  js[Start_t] = timer.toString();
249  js[End_t] = timer().toString();
250  js[Data_t][0] = json(data);
251 
252  } else {
253 
254  js[User_t] = login;
255  js[Location_t] = locationID;
256  js[Test_t + Type_t] = DBTestType;
257  js[Start_t + Time_t] = timer.toString();
258  js[End_t + Time_t] = timer().toString();
259  js[Tests_t] = json(failures);
260  }
261 
262  ofstream ofs(outputFile.c_str());
263 
264  ofs << setw(2) << setprecision(8);
265  ofs << js;
266 
267  ofs.close();
268  }
269 
270  return 0;
271 }
static JDBTestTypesTuneHV & getDBVersionTuneHV
Function object for looking up the HV-tuning database version number corresponding to a specific test...
then usage $script< detector file > minrun maxrun report nIn case of failures
static const std::string Arguments_t
Utility class to parse command line options.
Definition: JParser.hh:1514
static const std::string Start_t
#define WARNING(A)
Definition: JMessage.hh:65
static const std::string Location_t
static const std::string Code_t
static const std::string Encoding_t
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
JEEP::JVersion JDBAPIVersion
static const std::string Error_t
Utility class to parse parameter values.
Definition: JProperties.hh:497
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
static const std::string Time_t
Auxiliary data structure for alignment of data.
Definition: JManip.hh:366
static const std::string APIVersion_t
static const std::string Configuration_t
static const std::string Test_t
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
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 End_t
static const std::string Info_t
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
static const std::string Message_t
#define FATAL(A)
Definition: JMessage.hh:67
static const std::string Data_t
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
nlohmann::json json
static const std::string Type_t
int j
Definition: JPolint.hh:792
static const std::string Provenance_t
do set_variable DETECTOR_TXT $WORKDIR detector
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
static const std::string UUID_t
static const std::string Tests_t
bool isJSONFile(const char *file_name)
Check file format.
int debug
debug level
static const std::string OK_t
static const std::string User_t