ATLAS Offline Software
Loading...
Searching...
No Matches
CoolFix.cxx File Reference
#include "TrigConfBase/MsgStream.h"
#include "TrigConfStorage/DBLoader.h"
#include "TrigConfStorage/IStorageMgr.h"
#include "TrigConfStorage/StorageMgr.h"
#include "TrigConfStorage/IHLTFrameLoader.h"
#include "TrigConfL1Data/CTPConfig.h"
#include "TrigConfL1Data/BunchGroupSet.h"
#include "TrigConfL1Data/PrescaleSet.h"
#include "TrigConfHLTData/HLTFrame.h"
#include "TrigConfHLTData/HLTPrescaleSet.h"
#include "boost/lexical_cast.hpp"
#include "TrigConfCoolWriter.h"
#include <iostream>
#include <fstream>
#include <string>
#include <memory>
#include <ctime>
#include <map>
#include <vector>
#include <sys/stat.h>

Go to the source code of this file.

Classes

struct  JobConfig

Functions

void printhelp (std::ostream &o, std::ostream &(*lineend)(std::ostream &os))
template<typename T>
void readKeyFromPrompt (const std::string &prompt, T &key)
int main (int argc, char *argv[])

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

BGSK

L1PSK

HLT prescales

L1

HLT

Definition at line 254 of file CoolFix.cxx.

254 {
255
256 /***************************************
257 *
258 * Getting the program parameters
259 *
260 ***************************************/
261 JobConfig gConfig;
262 int retCode = gConfig.parseProgramOptions(argc, argv);
263 if(retCode>=0)
264 return retCode;
265
266 gConfig.PrintSetup();
267
268 /*----------------------------
269 *
270 * Read information from COOL
271 * and display it
272 *
273 *---------------------------*/
274
275 TrigConfCoolWriter * coolReader = new TrigConfCoolWriter( gConfig.coolConnection );
276
277 int displayMode = gConfig.fix ? ( gConfig.extendedSelection ? 2 : 1 ) : 0;
278
279 vector<string> fixableFolders = coolReader->checkPayloadSize( gConfig.run, gConfig.lb, displayMode, gConfig.openended, gConfig.lbend );
280
281 if( ! gConfig.fix ) {
282 delete coolReader;
283 return 0;
284 }
285
286 if(fixableFolders.size()==0) {
287 cout << endl << "All folders are properly filled. Exiting ..." << endl;
288 return 0; // exit the program
289 }
290
291 /*----------------------------
292 *
293 * Select which folders should
294 * be fixed
295 *
296 *---------------------------*/
297
298 set<unsigned int> selectForFixing;
299
300 string selection="";
301 while(selection != "f" && selection != "0") {
302 // print
303 cout << endl << " 0 ... exit" << endl;
304 int idx=0;
305 for(const string & f : fixableFolders) {
306 if(selectForFixing.count(idx)>0) {
307 cout << " * " << ++idx << " ... " << f << endl;
308 } else {
309 cout << " " << ++idx << " ... " << f << endl;
310 }
311 }
312 cout << endl << " a ... select/deselect all" << endl;
313 cout << endl << " e ... " << (gConfig.extendedSelection ? "disallow" : "allow") << " multiversion folder selection (clears selection)" << endl;
314 cout << endl << " f ... fix now" << endl;
315 cout << endl << endl << "Select/deselect folder to fix or other option : "; cin >> selection;
316
317 try {
318 if(selection=="a") {
319 // select all
320 bool allSelected = (fixableFolders.size() == selectForFixing.size());
321 if(allSelected) {
322 selectForFixing.clear();
323 } else {
324 for(unsigned int selInd = 0; selInd<fixableFolders.size();selInd++)
325 selectForFixing.insert(selInd);
326 }
327 } else if(selection=="e") {
328
329 gConfig.extendedSelection = !gConfig.extendedSelection;
330
331 fixableFolders = coolReader->checkPayloadSize( gConfig.run, gConfig.lb, gConfig.extendedSelection ? 2 : 1, gConfig.openended, gConfig.lbend );
332
333 selectForFixing.clear();
334
335 } else {
336 unsigned int selInd = static_cast<unsigned int>(std::stoul(selection)) - 1;
337 if(selectForFixing.count(selInd)) {
338 selectForFixing.erase(selInd);
339 } else {
340 selectForFixing.insert(selInd);
341 }
342 }
343 }
344 catch(...){}
345
346 }
347
348 delete coolReader;
349
350
351 if(selection=="0") {
352 cout << endl << "Exiting ..." << endl;
353 return 0; // exit the program
354 }
355
356 if(selectForFixing.empty()) {
357 cout << endl << "Nothing selected. Exiting ..." << endl;
358 return 0; // exit the program
359 }
360
361 vector<string> foldersToFix;
362 for(unsigned int idx=0; idx!=fixableFolders.size(); idx++) {
363 if(selectForFixing.count(idx)>0)
364 foldersToFix.push_back(fixableFolders[idx]);
365 }
366
367 // printout which folders were selected
368 cout << endl << "Folders for fixing:";
369 for(const string & f : foldersToFix)
370 cout << " " << f;
371 cout << endl;
372
373
374 // check which information we need from the database
375 bool loadL1(false), loadHLT(false), loadBGSK(false), loadL1PSK(false), loadHLTPSK(false), saveConfigSource(false);
376 for(const string & folderToFix : foldersToFix) {
377
378 loadL1 |=
379 ( folderToFix == "/TRIGGER/LVL1/Menu") ||
380 ( folderToFix == "/TRIGGER/LVL1/ItemDef") ||
381 ( folderToFix == "/TRIGGER/LVL1/Thresholds") ||
382 ( folderToFix == "/TRIGGER/LVL1/CTPCoreInputMapping") ||
383 ( folderToFix == "/TRIGGER/LVL1/BunchGroupDescription");
384
385 loadHLT |=
386 ( folderToFix == "/TRIGGER/HLT/HltConfigKeys") ||
387 ( folderToFix == "/TRIGGER/HLT/Menu") ||
388 ( folderToFix == "/TRIGGER/HLT/Groups");
389
390 loadBGSK |=
391 ( folderToFix == "/TRIGGER/LVL1/BunchGroupKey") ||
392 ( folderToFix == "/TRIGGER/LVL1/BunchGroupContent") ||
393 ( folderToFix == "/TRIGGER/LVL1/BunchGroupDescription");
394
395 loadL1PSK |=
396 ( folderToFix == "/TRIGGER/LVL1/Lvl1ConfigKey") ||
397 ( folderToFix == "/TRIGGER/LVL1/Prescales");
398
399 loadHLTPSK |=
400 ( folderToFix == "/TRIGGER/HLT/PrescaleKey") ||
401 ( folderToFix == "/TRIGGER/HLT/Prescales");
402
403 saveConfigSource |=
404 ( folderToFix == "/TRIGGER/HLT/HltConfigKeys");
405 }
406
407
408
409 if( (loadL1 || loadHLT) && gConfig.smk==0)
410 readKeyFromPrompt("Please specify Supermaster key : ", gConfig.smk);
411
412 if( loadBGSK && gConfig.bgsk==0)
413 readKeyFromPrompt("Please specify Bunchgroupset key : ", gConfig.bgsk );
414
415 if( loadL1PSK && gConfig.l1psk==0)
416 readKeyFromPrompt("Please specify L1 Prescaleset key : ", gConfig.l1psk );
417
418 if( loadHLTPSK && gConfig.hltpsk==0) {
419 string prompt = "Please specify HLT Prescaleset key";
420 if(gConfig.openended) {
421 prompt += " (starting at LB " + std::to_string(gConfig.lb) + "): ";
422 } else {
423 prompt += " (for LB " + std::to_string(gConfig.lb) + " - " + std::to_string(gConfig.lbend) + "): ";
424 }
425 readKeyFromPrompt( prompt, gConfig.hltpsk );
426 }
427
428 if( saveConfigSource && gConfig.release=="")
429 readKeyFromPrompt("Please specify the HLT release : ", gConfig.release );
430
431
432 CTPConfig * ctpConfig(0);
433 BunchGroupSet * bgs(0);
434 HLTFrame * hltFrame(0);
435 PrescaleSet * l1pss(0);
436 HLTPrescaleSet * hltpss(0);
437
438 {
439 unique_ptr<StorageMgr> sm(new StorageMgr(gConfig.triggerdb, "", "", cout));
440
441 ctpConfig = new TrigConf::CTPConfig();
442 if(loadL1) {
443 ctpConfig->setSMK( gConfig.smk );
444 sm->menuLoader().setEnv(IMenuLoader::CTPOnl);
445 cout << endl << endl << "Retrieving Lvl1 CTP configuration" << endl;
446 sm->masterTableLoader().setLevel(gConfig.outputlevel);
447 sm->masterTableLoader().load(*ctpConfig);
448 if( gConfig.printlevel>=0)
449 ctpConfig->print(" ",gConfig.printlevel);
450 }
451
452 if(loadHLT) {
453 cout << endl << endl << "Retrieving HLT menu configuration" << endl;
454 hltFrame = new HLTFrame();
455 hltFrame->setSMK( gConfig.smk );
456 sm->hltFrameLoader().load(*hltFrame);
457 if( gConfig.printlevel>=0)
458 hltFrame->print(" ",gConfig.printlevel);
459 }
460
461 if( loadBGSK ) {
462 cout << endl << endl << "Retrieving Lvl1 Bunchgroup set configuration" << endl;
463 bgs = new BunchGroupSet();
464 bgs->setId(gConfig.bgsk);
465 sm->bunchGroupSetLoader().load(*bgs);
466 if( gConfig.printlevel>=0)
467 bgs->print(" ",gConfig.printlevel);
468 }
469
470 if( loadL1PSK ) {
471 cout << endl << endl << "Retrieving L1 prescales" << endl;
472 l1pss = new PrescaleSet();
473 l1pss->setId(gConfig.l1psk);
474 sm->prescaleSetLoader().load(ctpConfig->ctpVersion(), *l1pss);
475 if( gConfig.printlevel>=0)
476 l1pss->print(" ",gConfig.printlevel);
477 }
478
479 if( loadHLTPSK ) {
480 cout << endl << endl << "Retrieving HLT prescales" << endl;
481 hltpss = new HLTPrescaleSet();
482 hltpss->setId(gConfig.hltpsk);
483 sm->hltPrescaleSetLoader().load(*hltpss);
484 if( gConfig.printlevel>=0)
485 hltpss->print(" ",gConfig.printlevel);
486 }
487 }
488
489
490 /********************************************************************************
491 *
492 * Writing to COOL
493 *
494 *******************************************************************************/
495
496 cout << "Writing cool to destination " << gConfig.coolConnection << endl;
497 TrigConfCoolWriter * coolWriter = new TrigConfCoolWriter( gConfig.coolConnection );
498
499 ValidityRange vr(gConfig.run);
500
501 if(gConfig.openended) {
502 vr = ValidityRange(gConfig.run, gConfig.lb);
503 } else {
504 cool::ValidityKey since(gConfig.run); since <<= 32; since += gConfig.lb;
505 cool::ValidityKey until(gConfig.run); until <<= 32; until += gConfig.lbend+1;
506 vr = ValidityRange(since, until);
507 }
508
509
513 {
514
515 bool doWrite(false);
516 for(const string & folderToFix : foldersToFix) {
517 if( folderToFix == "/TRIGGER/LVL1/BunchGroupKey" ||
518 folderToFix == "/TRIGGER/LVL1/BunchGroupContent") {
519 coolWriter->addWriteFolder( folderToFix );
520 doWrite = true;
521 }
522 }
523 if(loadBGSK && doWrite) {
524 coolWriter->writeL1BunchGroupLBPayload( vr, bgs->id(), *bgs);
525 }
526 coolWriter->clearWriteFolder();
527
528 for(const string & folderToFix : foldersToFix) {
529 if( folderToFix == "/TRIGGER/LVL1/BunchGroupDescription") {
530 if(ctpConfig && bgs) {
531 coolWriter->writeL1BunchGroupRunPayload( vr,
532 ctpConfig->menu(),
533 *bgs);
534 }
535 }
536 }
537
538 }
539
543 {
544
545 bool doWrite(false);
546 for(const string & folderToFix : foldersToFix) {
547 if( folderToFix == "/TRIGGER/LVL1/Lvl1ConfigKey" ||
548 folderToFix == "/TRIGGER/LVL1/Prescales") {
549 coolWriter->addWriteFolder( folderToFix );
550 doWrite = true;
551 }
552 }
553 if(loadL1PSK && doWrite) {
554 coolWriter->writeL1PrescalePayload( vr.since(), vr.until(), l1pss->id() , *l1pss);
555 }
556 coolWriter->clearWriteFolder();
557
558
559 }
560
561
562
566 {
567
568 bool doWrite(false);
569 for(const string & folderToFix : foldersToFix) {
570 if( folderToFix == "/TRIGGER/HLT/PrescaleKey" ||
571 folderToFix == "/TRIGGER/HLT/Prescales") {
572 coolWriter->addWriteFolder( folderToFix );
573 doWrite = true;
574 }
575 }
576 if(hltpss && doWrite) {
577 coolWriter->writeHltPrescalePayload( vr.since(), vr.until(), *hltpss);
578 }
579 coolWriter->clearWriteFolder();
580 }
581
582
586 {
587 bool doWrite(false);
588 for(const string & folderToFix : foldersToFix) {
589 if( folderToFix == "/TRIGGER/LVL1/Menu" ||
590 folderToFix == "/TRIGGER/LVL1/ItemDef" ||
591 folderToFix == "/TRIGGER/LVL1/Thresholds" ||
592 folderToFix == "/TRIGGER/LVL1/CTPCoreInputMapping") {
593 coolWriter->addWriteFolder( folderToFix );
594 doWrite = true;
595 }
596 }
597 if(ctpConfig && doWrite) {
598 coolWriter->writeL1MenuPayload( ValidityRange(gConfig.run), ctpConfig->menu());
599 }
600 coolWriter->clearWriteFolder();
601 }
602
603
604
608 {
609 bool doWrite(false);
610 for(const string & folderToFix : foldersToFix) {
611 if( folderToFix == "/TRIGGER/HLT/Menu" ||
612 folderToFix == "/TRIGGER/HLT/Groups" ||
613 folderToFix == "/TRIGGER/HLT/HltConfigKeys" ) {
614 coolWriter->addWriteFolder( folderToFix );
615 doWrite = true;
616 }
617 }
618
619 if(hltFrame && doWrite) {
620 string configSource = "TRIGGERDBR2," + gConfig.release + ",AtlasP1HLT";
621
622 coolWriter->writeHLTPayload( ValidityRange(gConfig.run), *hltFrame, configSource);
623 }
624 coolWriter->clearWriteFolder();
625 }
626
627
628 delete ctpConfig;
629 delete hltFrame;
630 delete bgs;
631 delete l1pss;
632 delete hltpss;
633
634}
void readKeyFromPrompt(const std::string &prompt, T &key)
Definition CoolFix.cxx:240
The HLT trigger menu,.
Definition HLTFrame.h:33
HLT chain configuration information.
Database Storage Manager, controls the database session and the different loader classes for DB acces...
Definition StorageMgr.h:23
Reading/Writing of trigger configuration data from/to COOL.
void writeL1BunchGroupRunPayload(ValidityRange vr, const Menu &lvl1Menu, const BunchGroupSet &bgs)
Writing run-wise L1 bunch group names and item to bunch group mapping to COOL.
void writeHltPrescalePayload(unsigned int runNumber, unsigned int lumiblockNumber, const TrigConf::HLTPrescaleSet &pss)
Writing luminosityblock-wise configuration information the COOL database.
void writeL1MenuPayload(ValidityRange vr, const TrigConf::Menu &lvl1Menu)
Writing L1 run-wise configuration information to the COOL database.
void writeL1PrescalePayload(unsigned int runNumber, unsigned int lumiblockNumber, unsigned int lvl1PrescaleKey, const TrigConf::PrescaleSet &prescale)
Writing luminosityblock-wise configuration information the COOL database.
void writeHLTPayload(ValidityRange vr, const HLTFrame &hltFrame, const std::string &configSource)
void addWriteFolder(const std::string &fname)
void writeL1BunchGroupLBPayload(const RunRangeVec &runRanges, unsigned int bgKey, const BunchGroupSet &bgs)
Writing LB-wise L1 bunch group definition to the COOL database.
std::vector< std::string > checkPayloadSize(unsigned int run, unsigned int lb, int displayMode, bool openend, unsigned int lbend)
const std::string selection
string release
Definition CoolFix.cxx:96
void PrintSetup()
Definition CoolFix.cxx:222
string triggerdb
Definition CoolFix.cxx:91
string coolConnection
Definition CoolFix.cxx:104
int l1psk
Definition CoolFix.cxx:94
bool openended
Definition CoolFix.cxx:86
int hltpsk
Definition CoolFix.cxx:95
unsigned int run
Definition CoolFix.cxx:83
MSGTC::Level outputlevel
Definition CoolFix.cxx:100
unsigned int lbend
Definition CoolFix.cxx:85
bool fix
Definition CoolFix.cxx:88
bool extendedSelection
Definition CoolFix.cxx:89
unsigned int lb
Definition CoolFix.cxx:84
int parseProgramOptions(int argc, char *argv[])
Definition CoolFix.cxx:113
int printlevel
Definition CoolFix.cxx:99

◆ printhelp()

void printhelp ( std::ostream & o,
std::ostream &(* lineend )(std::ostream &os) )

Definition at line 50 of file CoolFix.cxx.

50 {
51 o << "================================================================================\n";
52 o << "The program needs to be run with the following specifications:\n" << lineend;
53 o << "TrigConfReadWrite <options>\n";
54 o << "\n";
55 o << "[Global options]\n";
56 o << " -c|--cooldb <cooldb> ... cool database and run number (default is COOLONL_TRIGGER/CONDBR2)\n";
57 o << " e.g. COOLONL_TRIGGER/CONDBR2 or testcool.db \n";
58 o << " -r|--run <run> [<lb>] [<lbend>] ... run number (mandatory) and optionally lb (range)\n";
59 o << "\n";
60 o << " --triggerdb <triggerdb> ... trigger database as source of information (default is TRIGGERDBR2)\n";
61 o << " --smk <smk> ... SMK to load to cool (specify when needed)\n";
62 o << " --bgsk <bgsk> ... Bunchgroupset key to load to cool (specify when needed)\n";
63 o << " --l1psk <l1psk> ... L1PSK to load to cool (specify when needed)\n";
64 o << " --hltpsk <int> ... hltpsk to load to cool (specify when needed)\n";
65 o << " --release <string> ... release, e.g. 20.2.3.1 (specify when configkeys is to be uploaded)\n";
66 o << "\n";
67 o << " -f|--fix ... when specified it fixes the database. Only run after a test without it\n";
68 o << " -e|--extended ... allows fixing of any multiversion folder\n";
69 o << "\n";
70 o << " -v|--loglevel <level> ... log level [NIL, VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL, ALWAYS]\n";
71 o << " -p|--print <detail> ... print configuration with detail 0...5 (default 1)\n";
72 o << " -h|--help ... this output\n";
73 o << "\n";
74 o << "Input database can be specified the following ways: COOLONL_TRIGGER/CONDBR2 or trigconf.db/CONDBR2\n";
75 o << "\n";
76 o << "Instructions at https://twiki.cern.ch/twiki/bin/view/Atlas/TriggerConfigurationCOOLArchiver\n";
77 o << "================================================================================\n";
78}

◆ readKeyFromPrompt()

template<typename T>
void readKeyFromPrompt ( const std::string & prompt,
T & key )

Definition at line 240 of file CoolFix.cxx.

240 {
241 string input("");
242 cout << prompt; cin >> input;
243 try {
244 key = boost::lexical_cast<T, string>(input);
245 }
246 catch(...) {
247 cout << input << " is not a valid input" << endl;
248 }
249}