Jpp 21.0.0-rc.1-88-g0130508c4
the software that should make you happy
Loading...
Searching...
No Matches
JEditTuneHV.cc File Reference

Auxiliary program to treat failed HV-tuning calibrations. More...

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <set>
#include "km3net-dataformat/online/JDAQ.hh"
#include "JSystem/JDateAndTime.hh"
#include "JLang/JUUID.hh"
#include "JLang/JPredicate.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JFilenameSupportkit.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JDB/JUPI_t.hh"
#include "JDB/JVendorHV.hh"
#include "JDB/JDBSupportkit.hh"
#include "JDB/JPMTHVRunSettings.hh"
#include "JSon/JSon.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "Jeep/JProperties.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to treat failed HV-tuning calibrations.

Author
bjung

Definition in file JEditTuneHV.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 188 of file JEditTuneHV.cc.

189{
190 using namespace std;
191 using namespace JPP;
192
193 typedef JHVTable::JHVTableTypes JHVTableType_t;
194 typedef pair<JHVTableType_t, string> JHVTable_t;
195
196 string inputFile;
197 string outputFile;
198 JHVTable_t HVtable;
199
200 set<JUPI_t> pmtSet;
201
202 string login;
203 string locationID;
204 int elapsedTime = 0;
205
206 double minHV = -1500;
207 double maxHV = - 800;
208
209 int debug;
210
211 try {
212
213 JProperties properties;
214
215 properties.insert(gmake_property(login));
216 properties.insert(gmake_property(locationID));
217 properties.insert(gmake_property(elapsedTime));
218
219 JProperties settings;
220
221 settings.insert(gmake_property(minHV));
222 settings.insert(gmake_property(maxHV));
223
224 JParser<> zap("Auxiliary program to treat failed high-voltage tuning results.");
225
226 zap['f'] = make_field(inputFile, "input file");
227 zap['o'] = make_field(outputFile, "output file");
228 zap['b'] = make_field(HVtable, "ASCII HV table") = JPARSER::initialised();
229 zap['P'] = make_field(pmtSet, "Set of PMT UPIs") = JPARSER::initialised();
230 zap['#'] = make_field(properties, "database information") = JPARSER::initialised();
231 zap['@'] = make_field(settings, "HV limits") = JPARSER::initialised();
232 zap['d'] = make_field(debug, "debug") = 2;
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
248 JDateAndTime timer;
249
250 timer.sub(elapsedTime);
251
252
253 // Edit high-voltage calibrations
254
255 JDBAPIVersion DBAPIVersion;
256 string DBTestType;
257 string metaInfoStr = MAKE_STRING(JMeta(argc, argv));
258
259 JHVCalibration toEdit;
260
261 if (isJSONFile(inputFile.c_str())) {
262
263 json js;
264
265 ifstream ifs(inputFile.c_str());
266
267 ifs >> js;
268 ifs.close();
269
270 // Extract data
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
281 JHVCalibration HVcals;
282
283 json::const_iterator i1 = js.find(Data_t);
284
285 if ((DBAPIVersion.getMajorVersion() == 2) &&
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
292 HVcals = (*i1)[0].at(Tests_t).get<JHVCalibration>();
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
301 HVcals = js.at(Tests_t).get<JHVCalibration>();
302 }
303
304 // Collect PMTs which need to be edited
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
317 for (set<JUPI_t>::const_iterator it = pmtSet.cbegin(); it != pmtSet.cend(); ++it) {
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
347 const JUPI_t& upi = i->getUPI();
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
388 json js;
389
390 if (DBAPIVersion.getMajorVersion() == 2) {
391
392 json error = { {Message_t, "" },
393 {Code_t, OK_t },
394 {Arguments_t, json::array() } };
395
396 json metaData = { {Configuration_t, metaInfoStr },
397 {UUID_t, MAKE_STRING(UUID) } };
398
399 json data = { {Provenance_t + Info_t, json(metaData) },
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
407 js[APIVersion_t] = MAKE_STRING(DBAPIVersion);
408 js[Data_t + Type_t] = MAKE_STRING("ProductTestSession");
409 js[Encoding_t] = MAKE_STRING("NativeJSON");
410 js[Error_t] = json(error);
411 js[Start_t] = timer.toString();
412 js[End_t] = timer().toString();
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
426 ofstream ofs(outputFile.c_str());
427
428 ofs << setw(2) << setprecision(8);
429 ofs << js;
430
431 ofs.close();
432
433 return 0;
434}
string outputFile
#define ERROR(A)
Definition JMessage.hh:66
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#define WARNING(A)
Definition JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2140
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:48
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
nlohmann::json json
Utility class to parse parameter values.
Utility class to parse command line options.
Definition JParser.hh:1697
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.
Definition JManip.hh:448
Universal product identifier (UPI).
Definition JUPI_t.hh:33
const JUPI_t & getUPI() const
Get UPI.
Definition JUPI_t.hh:101
int getNumber() const
Get serial number.
Definition JUPI_t.hh:134
Auxiliary data structure for general purpose version number.
version_type getMajorVersion() const
Get major version.
Simple wrapper for UUID.
Definition JUUID.hh:24
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:67
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72
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.
Definition JManip.hh:298