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 "boost/algorithm/string.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 255 of file CoolFix.cxx.

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

◆ printhelp()

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

Definition at line 51 of file CoolFix.cxx.

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

◆ readKeyFromPrompt()

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

Definition at line 241 of file CoolFix.cxx.

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