ATLAS Offline Software
Loading...
Searching...
No Matches
ReadWrite.cxx File Reference
#include "TrigConfBase/MsgStream.h"
#include "TrigConfStorage/StorageMgr.h"
#include "TrigConfStorage/DBLoader.h"
#include "TrigConfStorage/IStorageMgr.h"
#include "TrigConfStorage/IHLTFrameLoader.h"
#include "TrigConfStorage/MCKLoader.h"
#include "TrigConfL1Data/CaloInfo.h"
#include "TrigConfL1Data/CTPConfig.h"
#include "L1TopoConfig/L1TopoMenu.h"
#include "TrigConfL1Data/Muctpi.h"
#include "TrigConfHLTData/HLTFrame.h"
#include "TrigConfHLTData/HLTPrescaleSet.h"
#include "TrigConfJobOptData/JobOptionTable.h"
#include "TrigConfCoolWriter.h"
#include "Run2toRun3ConvertersL1.h"
#include "Run2toRun3ConvertersHLT.h"
#include "CoolKernel/DatabaseId.h"
#include "CoolKernel/Exception.h"
#include "CoolKernel/IDatabaseSvc.h"
#include "CoolKernel/IDatabase.h"
#include "CoolKernel/IFolder.h"
#include "CoolKernel/IObject.h"
#include "boost/algorithm/string.hpp"
#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))
int main (int argc, char *argv[])

Function Documentation

◆ main()

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

Definition at line 352 of file ReadWrite.cxx.

352 {
353
354 /***************************************
355 *
356 * Getting the program parameters
357 *
358 ***************************************/
359 JobConfig gConfig;
360 gConfig.parseProgramOptions(argc, argv);
361 if(gConfig.help) {
362 printhelp(cout, endl);
363 return 0;
364 }
365 if(gConfig.error.size()!=0) {
366 for(const string& e: gConfig.error)
367 cerr << e << endl;
368 printhelp(cout, endl);
369 return 1;
370 }
371
372 ofstream *outf(0), *errf(0);
373 if(gConfig.logFileName != "") {
374 string outfn = gConfig.logFileName+".out";
375 string errfn = gConfig.logFileName+".err";
376 outf = new ofstream(outfn.c_str());
377 errf = new ofstream(errfn.c_str());
378 }
379 ostream& log = (outf==0?cout:*outf);
380 ostream& logerr = (errf==0?cerr:*errf);
381 ostream& (*lineend) ( ostream& os ) = &endl;
382
383 string check = gConfig.CheckForCompleteSetup();
384 if( check != "" ) {
385 logerr << lineend << "===> Error in the option specification: " << check << lineend << lineend;
386 printhelp(log, lineend);
387 if(outf) outf->close();
388 if(errf) errf->close();
389 return 1;
390 }
391
392 gConfig.PrintSetup(log, lineend);
393
394
395 /***************************************
396 *
397 * Reading
398 *
399 ***************************************/
400 CTPConfig* ctpc(0);
401 BunchGroupSet* bgs(nullptr);
402 HLTFrame* hltFrame(0);
403 TXC::L1TopoMenu* l1tm = nullptr;
404 uint smk(0),l1psk(0),hltpsk(0),bgsk(0), mck{0};
405 string release;
406
407
408 /*------------------
409 * from DB
410 *-----------------*/
411 if (gConfig.input == JobConfig::DB) {
412 unique_ptr<StorageMgr> sm(new StorageMgr(gConfig.db, "", "", log));
413
414 // Loading L1 topo
415 //log << "Retrieving Lvl1 Topo configuration" << lineend;
416 l1tm = new TXC::L1TopoMenu();
417 l1tm->setSMK(gConfig.getKey(0));
418 sm->masterTableLoader().setLevel(gConfig.outputlevel);
419 sm->masterTableLoader().load(*l1tm);
420
421 //log << "Retrieving Lvl1 CTP configuration" << lineend;
422 ctpc = new TrigConf::CTPConfig();
423 ctpc->setSMK( gConfig.getKey(0) );
424 ctpc->setPrescaleSetId( gConfig.getKey(1) );
425 ctpc->setBunchGroupSetId( gConfig.getKey(3) );
426 sm->menuLoader().setEnv(IMenuLoader::CTPOnl);
427 ctpc->setLoadCtpFiles(gConfig.fw); // load CTP files ?
428 sm->masterTableLoader().setLevel( gConfig.outputlevel );
429 sm->masterTableLoader().load(*ctpc);
430 ctpc->muCTPi().setSMK( gConfig.getKey(0) );
431 sm->masterTableLoader().load( ctpc->muCTPi() );
432
433 //log << "Retrieving HLT menu configuration and prescale set from the TriggerDB" << lineend;
434 hltFrame = new HLTFrame();
435 hltFrame->setSMK( gConfig.getKey(0) );
436 if( gConfig.getKey(2)>0 )
437 hltFrame->thePrescaleSetCollection().set_prescale_key_to_load( gConfig.getKey(2) );
438 sm->hltFrameLoader().setLevel( gConfig.outputlevel );
439 sm->hltFrameLoader().load( *hltFrame );
440
441 smk = gConfig.getKey(0);
442 l1psk = gConfig.getKey(1);
443 hltpsk = gConfig.getKey(2);
444 bgsk = gConfig.getKey(3);
445
446 // loading attached MCK
447 auto mckloader = new MCKLoader(*sm);
448 mckloader->loadMCKlinkedToSMK(smk, mck);
449 if ( mck != 0 ) {
450 mckloader->loadReleaseLinkedToMCK(mck,release);
451 log << "Loaded MCK " << mck << " (active for SMK " << smk << " and release " << release << ")" << endl;
452 } else {
453 log << "Did not load MCK from DB as MCK is 0 or no MCK is linked";
454 }
455
456 }
457 /*------------------
458 * from COOL
459 *-----------------*/
460 else if (gConfig.input == JobConfig::COOL) {
461 string coolInputConnection = gConfig.coolInputConnection;
462 unsigned int runnumber = gConfig.inpar.size()>1 ? static_cast<unsigned int>(std::stoul(gConfig.inpar[1])) : 1;
463 unsigned int lb = gConfig.inpar.size()>2 ? static_cast<unsigned int>(std::stoul(gConfig.inpar[2])) : 0;
464 log << "TrigConfReadWrite Reading cool : " << coolInputConnection << lineend;
465 log << " run number : " << runnumber << lineend;
466 log << " lb : " << lb << lineend;
467 TrigConfCoolWriter * coolWriter = new TrigConfCoolWriter( coolInputConnection );
468 string configSource("");
469 ctpc = new CTPConfig();
470 coolWriter->readL1Payload( runnumber, *ctpc);
471
473 coolWriter->readL1PrescalePayload( runnumber, lb, l1psk, ps);
474 ctpc->setPrescaleSet( ps );
475
476 // log << "L1 PSK 0 " << ps.id() << lineend;
477 // log << "L1 PSK 1 " << l1psk << lineend;
478 // log << "L1 PSK 2 " << ctpc->prescaleSet().id() << lineend;
479 // log << "L1 PSK 3 " << ctpc->prescaleSetId() << lineend; <---- does not work
480
481 int bgKey(0);
482 coolWriter->readL1BunchGroupLBPayload( runnumber, lb, bgKey, ctpc->bunchGroupSet() );
483
484 hltFrame = new HLTFrame();
485 coolWriter->readHLTPayload(runnumber, *hltFrame);
486
487 if(lb!=0) {
488 HLTPrescaleSet * pss = new HLTPrescaleSet();
489 coolWriter->readHltPrescalePayload( runnumber, lb, *pss);
490 hltpsk = pss->id();
491 hltFrame->thePrescaleSetCollection().addPrescaleSet( lb, pss );
492 }
493
494 smk = hltFrame->smk();
495 bgsk = bgKey;
496
497 }
498
499 if(gConfig.printlevel>=0) {
500 log << "Loaded this configuration" << lineend;
501 log << " SMK " << smk << lineend;
502 log << " L1 PSK " << l1psk << lineend;
503 log << " HLT PSK " << hltpsk << lineend;
504 log << " BGSK " << bgsk << lineend;
505 if(ctpc) ctpc->print(" ", gConfig.printlevel);
506 if(bgs) bgs->print(" ", gConfig.printlevel);
507 if(hltFrame) hltFrame->print(" ", gConfig.printlevel);
508 }
509
510
511 if (gConfig.input2 != JobConfig::UNDEF) {
512 CTPConfig* ctpc2(0);
513 HLTFrame* hltFrame2(0);
514
515 /*------------------
516 * from DB
517 *-----------------*/
518 if (gConfig.input2 == JobConfig::DB) {
519 TrigConf::StorageMgr *sm = new TrigConf::StorageMgr(gConfig.db2, "", "", log);
520
521 log << "Retrieving Lvl1 CTP configuration for comparison" << lineend;
522 ctpc2 = new TrigConf::CTPConfig();
523 ctpc2->setSMK( gConfig.getKey2(0) );
524 ctpc2->setPrescaleSetId( gConfig.getKey2(1) );
525 ctpc2->setBunchGroupSetId( gConfig.getKey2(3) );
528 sm->masterTableLoader().load(*ctpc2);
529 ctpc2->muCTPi().setSMK( gConfig.getKey2(0) );
530 sm->masterTableLoader().load(ctpc2->muCTPi());
531
532 log << "Retrieving HLT menu configuration and prescale set from the TriggerDB for comparison" << lineend;
533 hltFrame2 = new HLTFrame();
534 hltFrame2->setSMK( gConfig.getKey2(0) );
535 if( gConfig.getKey2(2)>0)
536 hltFrame2->thePrescaleSetCollection().set_prescale_key_to_load( gConfig.getKey2(2) );
537 sm->hltFrameLoader().load( *hltFrame2 );
538 delete sm;
539 } else if (gConfig.input2 == JobConfig::COOL) {
540 /*------------------
541 * from COOL
542 *-----------------*/
543 }
544
545 if(ctpc && ctpc2) {
546 bool equalMenus = ctpc->equals(ctpc2, "LVL1config_Diff.xml");
547 if(equalMenus) {
548 log << "LVL1 menus are identical." << lineend;
549 } else {
550 log << "LVL1 menus differ. Writing LVL1 menu comparison file LVL1config_Diff.xml" << lineend;
551 }
552 }
553 if(hltFrame && hltFrame2) {
554 bool equalMenus = hltFrame->equals(hltFrame2, "HLTconfig_Diff.xml");
555 if(equalMenus) {
556 log << "HLT menus are identical." << lineend;
557 } else {
558 log << "HLT menus differ. Writing HLT menu comparison file HLTconfig_Diff.xml" << lineend;
559 }
560 }
561
562 }
563
564
565 // ========================================
566 // Writing
567 // ========================================
568 if ( (gConfig.output & JobConfig::JSON) != 0 ) {
569 /*------------------
570 * to JSON
571 *-----------------*/
572 if(ctpc && l1tm) {
573 convertRun2L1MenuToRun3(ctpc, l1tm, gConfig.l1JsonOutFile);
576 }
577 if(hltFrame) {
578 convertRun2HLTMenuToRun3(hltFrame, gConfig.hltJsonOutFile);
580 }
581 }
582
583 if ( (gConfig.output & JobConfig::COOL) != 0 ) {
584 /*------------------
585 * to COOL
586 *-----------------*/
587 log << "TrigConfReadWrite: Writing sqlite cool file : " << gConfig.coolOutputConnection << " with ";
588 if( gConfig.coolOutputRunNr==0 ) { log << "infinite IOV"; } else { log << " runNr " << gConfig.coolOutputRunNr; }
589 log << lineend;
590 TrigConfCoolWriter * coolWriter = new TrigConfCoolWriter( gConfig.coolOutputConnection );
591 string configSource("");
592 string info("");
593 unsigned int runNr = gConfig.coolOutputRunNr;
594 if(runNr == 0) { runNr = 0x80000000; } // infinite range
595
596 if(ctpc) {
597 coolWriter->writeL1Payload(runNr, *ctpc);
598 }
599 try{
600 if(hltFrame) {
601 coolWriter->writeHLTPayload(runNr, *hltFrame, configSource);
602 }
603 }
604 catch(const cool::StorageTypeStringTooLong& e){
605 log << "FATAL: Unable to write data to COOL";
606 return 1;
607 }
608 if(mck) {
609 coolWriter->writeMCKPayload(runNr, mck, release, info);
610 }
611 }
612
613 delete ctpc;
614 delete hltFrame;
615 if(l1tm!=nullptr)
616 delete l1tm;
617
618 if( gConfig.jo ) {
619
620 JobOptionTable jot;
621 unique_ptr<IStorageMgr> sm( new StorageMgr(gConfig.db,"","",log) );
622
623 log << "TrigConfReadWrite: Retrieving JO from the TriggerDB" << lineend;
624 jot.setSMK( gConfig.getKey(0) );
625 jot.setTriggerLevel(0); // L2
627 sm->jobOptionTableLoader().load( jot );
628 if(gConfig.printlevel>0) jot.print();
629 }
630
631}
unsigned int uint
void printhelp(std::ostream &o, std::ostream &(*lineend)(std::ostream &os))
Definition ReadWrite.cxx:63
void convertRun2HLTMenuToRun3(const TrigConf::HLTFrame *frame, const std::string &filename)
void convertRun2HLTPrescalesToRun3(const TrigConf::HLTFrame *frame, const std::string &filename)
void convertRun2L1MenuToRun3(const TrigConf::CTPConfig *ctpConfig, const TXC::L1TopoMenu *topoMenu, const std::string &filename, bool writeTmpFile)
Conversion of L1 menu.
void convertRun2L1PrescalesToRun3(const TrigConf::CTPConfig *ctpConfig, const std::string &filename, bool writeTmpFile)
Conversion of L1 prescales set.
void convertRun2BunchGroupsToRun3(const TrigConf::CTPConfig *ctpConfig, const std::string &filename, bool writeTmpFile)
Run 2 to Run 3 bunchgroup converter.
void setSMK(const unsigned int &smk)
Definition L1TopoMenu.h:63
The HLT trigger menu,.
Definition HLTFrame.h:33
HLT chain configuration information.
virtual bool load(HLTFrame &data)=0
virtual bool load(JobOptionTable &data)=0
virtual void setLevel(MSGTC::Level lvl)=0
Load the configuration data from the configuration source.
virtual bool load(ThresholdConfig &thrcfg)=0
Load the LVL1 trigger thresholds from the configuration source.
virtual void setEnv(ENV env)=0
table to hold the complete list of JobOption entries for a single configuration, from which the JobOp...
void print(const std::string &indent="", unsigned int detail=1) const override
print method
void setTriggerLevel(int level)
setter of the trigger level
Database Storage Manager, controls the database session and the different loader classes for DB acces...
Definition StorageMgr.h:23
virtual IMenuLoader & menuLoader() override
virtual IHLTFrameLoader & hltFrameLoader() override
virtual IJobOptionTableLoader & jobOptionTableLoader() override
virtual IMasterTableLoader & masterTableLoader() override
Reading/Writing of trigger configuration data from/to COOL.
void readL1BunchGroupLBPayload(unsigned int runNumber, unsigned int lumiblockNumber, int &bgKey, TrigConf::BunchGroupSet &bgs)
Reading lb-wise bunch group configuration information from COOL database.
void readL1Payload(unsigned int run, CTPConfig &ctpc)
void readHltPrescalePayload(unsigned int runNumber, unsigned int lumiblockNumber, TrigConf::HLTPrescaleSet &pss)
Reading luminosityblock-wise configuration information the COOL database.
void readL1PrescalePayload(unsigned int runNumber, unsigned int lumiblockNumber, unsigned int &lvl1PrescaleKey, TrigConf::PrescaleSet &prescale)
Reading luminosityblock-wise configuration information the COOL database.
void writeHLTPayload(ValidityRange vr, const HLTFrame &hltFrame, const std::string &configSource)
void writeMCKPayload(ValidityRange vr, unsigned int mck, std::string &release, std::string &info)
void writeL1Payload(ValidityRange vr, const CTPConfig &ctpConfig)
void readHLTPayload(unsigned int run, HLTFrame &hltFrame)
unsigned int id() const
static std::string release
Definition computils.h:50
int lb
Definition globals.cxx:23
static std::vector< uint32_t > runnumber
Definition iLumiCalc.h:37
logerr(out1, out2)
Definition logParser.py:475
string bgkJsonOutFile
unsigned int getKey2(unsigned int which)
Format input
Format input2
void PrintSetup()
Definition CoolFix.cxx:223
string hltPSJsonOutFile
string coolInputConnection
MSGTC::Level outputlevel
Definition CoolFix.cxx:101
string db2
string coolOutputConnection
string db
string logFileName
string hltJsonOutFile
vector< string > error
Definition CoolFix.cxx:103
string CheckForCompleteSetup()
int parseProgramOptions(int argc, char *argv[])
Definition CoolFix.cxx:114
std::vector< std::string > inpar
string l1PSJsonOutFile
bool help
Definition CoolFix.cxx:99
unsigned int coolOutputRunNr
string l1JsonOutFile
int printlevel
Definition CoolFix.cxx:100
unsigned int output
unsigned int getKey(unsigned int which)

◆ printhelp()

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

Definition at line 63 of file ReadWrite.cxx.

63 {
64 o << "================================================================================\n";
65 o << "The program needs to be run with the following specifications:\n" << lineend;
66 o << "TrigConfReadWrite <options>\n";
67 o << "\n";
68 o << "[Global options]\n";
69 o << " -i|--input input [input [input]] ... source of configuration, format see below (mandatory)\n";
70 o << " -2|--comp input [input [input]] ... source of a second configuration for comparison\n";
71 o << " -o|--output r3json|cool [output[;cooldb]] [run] ... output format, name (for cool optional run number)\n";
72 o << " ... absolute output file name must contain '/', cooldb can be appended COMP200|OFLP200\n";
73 o << " -v|--loglevel <string> ... log level [NIL, VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL, ALWAYS]\n";
74 o << " -l|--log <string> ... name of a log file\n";
75 o << " --jo ... read and write job options where possible\n";
76 o << " --fw ... read ctp firmware\n";
77 o << " -p|--print <int> ... print configuration with detail 0...5 (default 1)\n";
78 o << " -h|--help ... this output\n";
79 o << " --nomerge ... internally don't merge L2 and EF (by default merge is enabled)\n";
80 o << "\n\n";
81 o << "Input can be specified the following\n";
82 o << " -i <TRIGDB_ALIAS>|<TRIGDB_connection> smk[,l1psk,hltpsk,bgsk] ... to read the menu from a trigger db via alias or explicit connection specification (ORACLE or SQlite)\n";
83 o << " -i <COOLDB_ALIAS>|<COOLDB_connection>|cool.db run[,lb] ... to read the menu from COOL for a certain run and possibly LB [file names must end with '.db']\n";
84 o << "\n";
85 o << "The cool dbconnection can be specified as one of the following\n";
86 o << " - via alias : COOLONL_TRIGGER (use COOLONL_TRIGGER/COMP200 for Run 1 data)";
87 o << " - from sqlite : cool.db (use cool.db;COMP200 for Run 1 data)";
88 o << "\n";
89 o << "\n";
90 o << "Input for comparison can be specified the same way, using the '-2' or '--comp' option\n";
91 o << "\n";
92 o << "\n";
93 o << "Output formats can be json or cool. In case a second input is specified for comparison, the output will be on screen or an xml file with the differences\n";
94 o << " -o r3json [<test>] ... will produce Run 3 config files L1PrescalesSet[_<test>].json, BunchGroupSet[_<test>].json, L1Menu[_<test>].json, HLTPrescalesSet[_<test>].json, and HLTMenu[_<test>].json\n";
95 o << " -o cool ... will produce trig_cool.db with cool db instance CONDBR2 and infinite IOV\n";
96 o << " -o cool 200000 ... will produce trig_cool.db with cool db instance CONDBR2 and run number 200000\n";
97 o << " -o cool test [200000] ... will produce trig_cool_test.db with cool db instance CONDBR2 [and run number 200000]\n";
98 o << " -o cool ../test.db [200000] ... will produce ../test.db with cool db instance CONDBR2 [and run number 200000]\n";
99 o << " -o cool 'test;COMP200' [200000] ... will produce Menu_test.db with cool db instance COMP200 [and run number 200000]\n";
100 o << "\n";
101 o << "================================================================================\n";
102}