ATLAS Offline Software
Classes | Functions
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 257 of file CoolFix.cxx.

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

◆ printhelp()

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

Definition at line 53 of file CoolFix.cxx.

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

◆ readKeyFromPrompt()

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

Definition at line 243 of file CoolFix.cxx.

243  {
244  string input("");
245  cout << prompt; cin >> input;
246  try {
247  key = boost::lexical_cast<T, string>(input);
248  }
249  catch(...) {
250  cout << input << " is not a valid input" << endl;
251  }
252 }
TrigConf::BunchGroupSet
Definition: BunchGroupSet.h:19
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
TrigConf::PrescaleSet
Definition: PrescaleSet.h:22
JobConfig::PrintSetup
void PrintSetup()
Definition: CoolFix.cxx:225
TrigConf::TrigConfCoolWriter::checkPayloadSize
std::vector< std::string > checkPayloadSize(unsigned int run, unsigned int lb, int displayMode, bool openend, unsigned int lbend)
Definition: TrigConfCoolWriter.cxx:1704
JobConfig::bgsk
int bgsk
Definition: CoolFix.cxx:96
JobConfig::lbend
unsigned int lbend
Definition: CoolFix.cxx:88
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
JobConfig::outputlevel
MSGTC::Level outputlevel
Definition: CoolFix.cxx:103
TrigConf::TrigConfCoolWriter::writeL1MenuPayload
void writeL1MenuPayload(ValidityRange vr, const TrigConf::Menu &lvl1Menu)
Writing L1 run-wise configuration information to the COOL database.
Definition: TrigConfCoolWriter.cxx:746
JobConfig::release
string release
Definition: CoolFix.cxx:99
TrigConf::StorageMgr
Database Storage Manager, controls the database session and the different loader classes for DB acces...
Definition: StorageMgr.h:23
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
dq_defect_copy_defect_database.until
def until
Definition: dq_defect_copy_defect_database.py:55
JobConfig::run
unsigned int run
Definition: CoolFix.cxx:86
JobConfig
Definition: CoolFix.cxx:83
TrigConf::TrigConfCoolWriter::clearWriteFolder
void clearWriteFolder()
Definition: TrigConfCoolWriter.h:387
TrigConf::TrigConfCoolWriter::addWriteFolder
void addWriteFolder(const std::string &fname)
Definition: TrigConfCoolWriter.h:378
TrigConf::TrigConfCoolWriter::writeL1BunchGroupRunPayload
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.
Definition: TrigConfCoolWriter.cxx:945
JobConfig::hltpsk
int hltpsk
Definition: CoolFix.cxx:98
JobConfig::fix
bool fix
Definition: CoolFix.cxx:91
TrigConf::TrigConfCoolWriter::writeL1BunchGroupLBPayload
void writeL1BunchGroupLBPayload(const RunRangeVec &runRanges, unsigned int bgKey, const BunchGroupSet &bgs)
Writing LB-wise L1 bunch group definition to the COOL database.
Definition: TrigConfCoolWriter.cxx:979
JobConfig::extendedSelection
bool extendedSelection
Definition: CoolFix.cxx:92
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
JobConfig::printlevel
int printlevel
Definition: CoolFix.cxx:102
JobConfig::lb
unsigned int lb
Definition: CoolFix.cxx:87
TrigConf::ValidityRange
Definition: TrigConfCoolWriter.h:39
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
JobConfig::openended
bool openended
Definition: CoolFix.cxx:89
TrigConf::HLTPrescaleSet
HLT chain configuration information.
Definition: HLTPrescaleSet.h:31
selection
std::string selection
Definition: fbtTestBasics.cxx:73
TrigConf::TrigConfCoolWriter::writeHltPrescalePayload
void writeHltPrescalePayload(unsigned int runNumber, unsigned int lumiblockNumber, const TrigConf::HLTPrescaleSet &pss)
Writing luminosityblock-wise configuration information the COOL database.
Definition: TrigConfCoolWriter.cxx:1040
readKeyFromPrompt
void readKeyFromPrompt(const std::string &prompt, T &key)
Definition: CoolFix.cxx:243
JobConfig::smk
int smk
Definition: CoolFix.cxx:95
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
LArCellConditions.prompt
string prompt
Definition: LArCellConditions.py:71
TrigConf::HLTFrame
The HLT trigger menu,.
Definition: HLTFrame.h:33
TrigConf::TrigConfCoolWriter
Reading/Writing of trigger configuration data from/to COOL.
Definition: TrigConfCoolWriter.h:95
TrigConf::TrigConfCoolWriter::writeHLTPayload
void writeHLTPayload(ValidityRange vr, const HLTFrame &hltFrame, const std::string &configSource)
Definition: TrigConfCoolWriter.cxx:326
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
TrigConf::CTPConfig
Definition: CTPConfig.h:27
JobConfig::triggerdb
string triggerdb
Definition: CoolFix.cxx:94
JobConfig::coolConnection
string coolConnection
Definition: CoolFix.cxx:107
python.StandardJetMods.vr
vr
Definition: StandardJetMods.py:276
JobConfig::l1psk
int l1psk
Definition: CoolFix.cxx:97
JobConfig::parseProgramOptions
int parseProgramOptions(int argc, char *argv[])
Definition: CoolFix.cxx:116
TrigConf::TrigConfCoolWriter::writeL1PrescalePayload
void writeL1PrescalePayload(unsigned int runNumber, unsigned int lumiblockNumber, unsigned int lvl1PrescaleKey, const TrigConf::PrescaleSet &prescale)
Writing luminosityblock-wise configuration information the COOL database.
Definition: TrigConfCoolWriter.cxx:1187
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37