ATLAS Offline Software
Loading...
Searching...
No Matches
ReadWrite.cxx File Reference
#include "TrigConfBase/MsgStream.h"
#include <CxxUtils/StringUtils.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 348 of file ReadWrite.cxx.

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