189{
192
193 typedef JHVTable::JHVTableTypes JHVTableType_t;
195
196 string inputFile;
198 JHVTable_t HVtable;
199
201
202 string login;
203 string locationID;
204 int elapsedTime = 0;
205
206 double minHV = -1500;
207 double maxHV = - 800;
208
210
211 try {
212
214
218
220
223
224 JParser<> zap(
"Auxiliary program to treat failed high-voltage tuning results.");
225
226 zap[
'f'] =
make_field(inputFile,
"input file");
233
234 zap(argc, argv);
235
236 } catch(const exception &error) {
237
238 FATAL(error.what() << endl);
239 }
240
241 if (login.empty() || locationID.empty()) {
242 FATAL(
"Missing user information (please specify via -#login and -#locationID).");
243 }
244
245
246 const JUUID& UUID = JUUID::rndm();
247
249
250 timer.
sub(elapsedTime);
251
252
253
254
256 string DBTestType;
258
260
262
264
265 ifstream ifs(inputFile.c_str());
266
267 ifs >> js;
268 ifs.close();
269
270
271
272 json::const_iterator i0 = js.find(APIVersion_t);
273
274 if (i0 != js.cend()) {
275
276 istringstream iss(i0->get<string>());
277
278 iss >> DBAPIVersion;
279 }
280
282
283 json::const_iterator i1 = js.find(Data_t);
284
286 (i1 != js.cend() && i1->size() > 0)) {
287
288 DBTestType = (*i1)[0].at(Test_t + Type_t).get<string>();
289
290 JHVCalibration_t::setVersion(getDBVersionTuneHV(DBTestType));
291
293 metaInfoStr += (*i1)[0].at(Provenance_t + Info_t).at(Configuration_t).get<string>();
294
295 } else {
296
297 DBTestType = js.at(Test_t + Type_t).get<string>();
298
299 JHVCalibration_t::setVersion(getDBVersionTuneHV(DBTestType));
300
302 }
303
304
305
306 if (pmtSet.empty()) {
307
308 for (JHVCalibration::iterator it = HVcals.begin(); it != HVcals.end(); ++it) {
309
310 if (it->result != OK_t) {
311 toEdit.push_back(*it);
312 }
313 }
314
315 } else {
316
318
319 JHVCalibration::iterator pmt = find_if(HVcals.begin(), HVcals.end(),
320 make_predicate(&JHVCalibration_t::getNumber, it->getNumber()));
321 if (pmt != HVcals.end()) {
322
323 if (pmt->result == OK_t) {
324 WARNING(
"Editing " << OK_t <<
" result for " << pmt->getUPI() << endl);
325 }
326
327 toEdit.push_back(*pmt);
328 }
329 }
330 }
331
332 } else {
333
334 ERROR(inputFile <<
" is not a JSON file." << endl);
335 }
336
337
338 if (!HVtable.second.empty()) {
339
340 NOTICE(
"Setting " << (HVtable.first == JHVTableType_t::VENDOR_HV ?
"vendor " :
"run-specific ") <<
341 "PMT high-voltages from file " << HVtable.second << "..." << endl);
342
343 JHVTable getHV(HVtable.second.c_str(), HVtable.first);
344
345 for (JHVCalibration::iterator i = toEdit.begin(); i != toEdit.end(); ++i) {
346
348 const double HV = getHV(upi.
getNumber());
349
350 if (HV > minHV && HV < maxHV) {
351
352 i->supplyVoltage = getHV(upi.
getNumber());
353 i->result = OK_t;
354
355 } else {
356
357 WARNING(
"Invalid high-voltage for PMT " << upi <<
" (" <<
FIXED(7,1) << HV <<
358 " not within [ " <<
FIXED(7,1) << minHV <<
", " <<
FIXED(7,1) << maxHV <<
"]); skip." << endl);
359 }
360 }
361
362 } else {
363
364 NOTICE(
"Setting high-voltages manually..." << endl);
365
366 for (JHVCalibration::iterator i = toEdit.begin(); i != toEdit.end(); ++i) {
367
368 NOTICE(
"Please specify high-voltage for " <<
RIGHT(30) << i->getUPI() <<
":" << endl);
369
370 double manualHV;
371 cin >> manualHV;
372
373 while (manualHV < minHV || manualHV > maxHV) {
374
375 WARNING(
"Specified high-voltage is not within range [" <<
376 FIXED(7,1) << minHV <<
", " <<
FIXED(7,1) << maxHV <<
377 "]; Please specify again." << endl);
378
379 cin >> manualHV;
380 }
381
382 i->supplyVoltage = manualHV;
383 i->result = OK_t;
384 }
385 }
386
387
389
391
392 json error = { {Message_t,
"" },
393 {Code_t, OK_t },
394 {Arguments_t, json::array() } };
395
396 json metaData = { {Configuration_t, metaInfoStr },
398
400 {User_t, login },
401 {Location_t, locationID },
402 {Start_t + Time_t, timer.
toString() },
403 {End_t + Time_t, timer().
toString() },
404 {Test_t + Type_t, DBTestType },
405 {Tests_t,
json(toEdit) } };
406
408 js[Data_t + Type_t] =
MAKE_STRING(
"ProductTestSession");
410 js[Error_t] =
json(error);
413 js[Data_t][0] =
json(data);
414
415 } else {
416
417 js[User_t] = login;
418 js[Location_t] = locationID;
419 js[Test_t + Type_t] = DBTestType;
420 js[Start_t + Time_t] = timer.
toString();
421 js[End_t + Time_t] = timer().
toString();
422 js[Tests_t] =
json(toEdit);
423 }
424
425
427
428 ofs << setw(2) << setprecision(8);
429 ofs << js;
430
431 ofs.close();
432
433 return 0;
434}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
#define MAKE_STRING(A)
Make string.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
Utility class to parse command line options.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool isJSONFile(const char *file_name)
Check file format.
Auxiliary data structure for floating point format specification.
Universal product identifier (UPI).
const JUPI_t & getUPI() const
Get UPI.
int getNumber() const
Get serial number.
Auxiliary data structure for general purpose version number.
version_type getMajorVersion() const
Get major version.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Auxiliary class for date and time.
std::string toString() const
Get ASCII formatted date and time.
void sub(const time_t t1)
Subtract given time.
Auxiliary data structure for alignment of data.