41#include "CoolKernel/DatabaseId.h"
42#include "CoolKernel/Exception.h"
43#include "CoolKernel/IDatabaseSvc.h"
44#include "CoolKernel/IDatabase.h"
45#include "CoolKernel/IFolder.h"
46#include "CoolKernel/IObject.h"
48#include "boost/algorithm/string.hpp"
63void printhelp(std::ostream & o, std::ostream& (*lineend) ( std::ostream& os )) {
64 o <<
"================================================================================\n";
65 o <<
"The program needs to be run with the following specifications:\n" << lineend;
66 o <<
"TrigConfReadWrite <options>\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";
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";
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)";
90 o <<
"Input for comparison can be specified the same way, using the '-2' or '--comp' option\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";
101 o <<
"================================================================================\n";
135 vector<string>
error;
140 void PrintSetup(std::ostream & log, std::ostream& (*lineend) ( std::ostream& os ));
144 unsigned int getKey(
unsigned int which) {
return keys.size()>which?
keys[which]:0; }
152 bool startswith(
const std::string&
str,
const std::string& sub) {
153 if(
str.size()<sub.size())
155 return (
str.compare(0,sub.size(),sub) == 0);
158 bool isUnsignedInteger(
const std::string&
str) {
159 for(
const char c :
str)
160 if(c<
'0' || c>
'9')
return false;
168 std::string currentPar(
"");
169 std::string listofUnknownParameters =
"";
170 for(
int i=1;
i<
argc;
i++) {
171 string currInput(argv[i]);
172 int fchar = currInput.find_first_not_of(
'-');
173 string stripped = currInput.substr(fchar);
174 bool isParam = (fchar!=0);
177 if( ! (stripped ==
"i" || stripped ==
"input" ||
178 stripped ==
"2" || stripped ==
"comp" ||
179 stripped ==
"o" || stripped ==
"output" ||
180 stripped ==
"l" || stripped ==
"log" ||
181 stripped ==
"p" || stripped ==
"print" ||
184 stripped ==
"nomerge" ||
185 stripped ==
"v" || stripped ==
"loglevel") ) {
186 listofUnknownParameters +=
" " + currInput;
192 if(stripped ==
"h" || stripped ==
"help" ) {
help =
true;
continue; }
193 if(stripped ==
"jo") {
jo =
true;
continue; }
194 if(stripped ==
"fw") {
fw =
true;
continue; }
195 if(stripped ==
"nomerge") {
merge =
false;
continue; }
196 currentPar = std::move(stripped);
198 if(currentPar ==
"i" || currentPar ==
"input") {
inpar.push_back(std::move(stripped));
continue; }
199 if(currentPar ==
"2" || currentPar ==
"comp") {
inpar2.push_back(std::move(stripped));
continue; }
200 if(currentPar ==
"o" || currentPar ==
"output") {
201 if(
outpar.size()==0 && stripped !=
"r3json" && stripped !=
"cool") {
202 error.push_back(
"Unknown output type: " + stripped +
". Must be either json or cool, optionally followed by a base string for the output file name");
204 outpar.push_back(std::move(stripped));
207 if(currentPar ==
"l" || currentPar ==
"log") {
logFileName = std::move(stripped);
continue; }
208 if(currentPar ==
"p" || currentPar ==
"print") {
printlevel = std::stoi(stripped); currentPar=
"";
continue; }
209 if(currentPar ==
"v" || currentPar ==
"loglevel") {
219 error.push_back(
"Unknown output level: " + stripped +
". Must be one of NIL, VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL, ALWAYS");
225 if(listofUnknownParameters!=
"")
226 error.push_back(
"Unknown parameter(s): " + listofUnknownParameters);
229 error.push_back(
"No input specified, use '-i' option");
233 if(
inpar.size()>=1 &&
inpar[0].find(
".db") != string::npos ) {
237 boost::split(ksv,
inpar[0],boost::is_any_of(
";"));
243 }
else if(
inpar.size()>=1 && startswith(
inpar[0],
"COOLONL_TRIGGER") ) {
246 boost::split(ksv,
inpar[0],boost::is_any_of(
"/"));
253 }
else if(
inpar.size()==2 ) {
257 boost::split(ksv,
inpar[1],boost::is_any_of(
","));
258 for(
const string& ks: ksv) {
259 keys.push_back(
static_cast<unsigned int>(std::stoul(ks)) );
264 for(
const string& o:
outpar) {
267 }
else if ( o==
"cool" ) {
269 }
else if ( isUnsignedInteger(o) ) {
278 string dbname =
"CONDBR2";
281 boost::split(ksv,
outBase,boost::is_any_of(
";"));
286 if (
outfile.find(
"/")==string::npos &&
outfile.find(
'.')==string::npos) {
304 return "Use argument '-i' to specify input source and check that the input is specified correctly";
307 return "No TriggerDB connection string specified";
309 return "No configuration key(s) specified";
313 return "No TriggerDB connection string specified for comparison, use option '--db2'";
314 if(
keys2.size()==0 )
315 return "No smk specified for comparison, use option '--dbsmk2'";
323 log <<
"========================================" << lineend;
324 log <<
"JOB SETUP: " << (
input==
DB?
"DB":
"COOL");
326 log <<
" --> " << (
output==
COOL?
"COOL":
"JSON");
328 log <<
"----------" << lineend;
330 for(
const string& s:
inpar) log << s <<
", ";
333 log <<
" Input for comparison: ";
334 for(
const string& s:
inpar2) log << s <<
", ";
346 log <<
" Print menu detail : " <<
printlevel << lineend;
347 log <<
"========================================" << lineend;
352int main(
int argc,
char* argv[] ) {
365 if(gConfig.
error.size()!=0) {
366 for(
const string& e: gConfig.
error)
372 ofstream *outf(0), *errf(0);
376 outf =
new ofstream(outfn.c_str());
377 errf =
new ofstream(errfn.c_str());
379 ostream& log = (outf==0?cout:*outf);
380 ostream& logerr = (errf==0?cerr:*errf);
381 ostream& (*lineend) ( ostream& os ) = &endl;
385 logerr << lineend <<
"===> Error in the option specification: " << check << lineend << lineend;
387 if(outf) outf->close();
388 if(errf) errf->close();
404 uint smk(0),l1psk(0),hltpsk(0),bgsk(0), mck{0};
412 unique_ptr<StorageMgr> sm(
new StorageMgr(gConfig.
db,
"",
"", log));
418 sm->masterTableLoader().setLevel(gConfig.
outputlevel);
419 sm->masterTableLoader().load(*l1tm);
428 sm->masterTableLoader().setLevel( gConfig.
outputlevel );
429 sm->masterTableLoader().load(*ctpc);
431 sm->masterTableLoader().load( ctpc->
muCTPi() );
438 sm->hltFrameLoader().setLevel( gConfig.
outputlevel );
439 sm->hltFrameLoader().load( *hltFrame );
442 l1psk = gConfig.
getKey(1);
443 hltpsk = gConfig.
getKey(2);
448 mckloader->loadMCKlinkedToSMK(smk, mck);
450 mckloader->loadReleaseLinkedToMCK(mck,
release);
451 log <<
"Loaded MCK " << mck <<
" (active for SMK " << smk <<
" and release " <<
release <<
")" << endl;
453 log <<
"Did not load MCK from DB as MCK is 0 or no MCK is linked";
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;
468 string configSource(
"");
494 smk = hltFrame->
smk();
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;
521 log <<
"Retrieving Lvl1 CTP configuration for comparison" << lineend;
532 log <<
"Retrieving HLT menu configuration and prescale set from the TriggerDB for comparison" << lineend;
546 bool equalMenus = ctpc->
equals(ctpc2,
"LVL1config_Diff.xml");
548 log <<
"LVL1 menus are identical." << lineend;
550 log <<
"LVL1 menus differ. Writing LVL1 menu comparison file LVL1config_Diff.xml" << lineend;
553 if(hltFrame && hltFrame2) {
554 bool equalMenus = hltFrame->
equals(hltFrame2,
"HLTconfig_Diff.xml");
556 log <<
"HLT menus are identical." << lineend;
558 log <<
"HLT menus differ. Writing HLT menu comparison file HLTconfig_Diff.xml" << lineend;
587 log <<
"TrigConfReadWrite: Writing sqlite cool file : " << gConfig.
coolOutputConnection <<
" with ";
591 string configSource(
"");
594 if(runNr == 0) { runNr = 0x80000000; }
604 catch(
const cool::StorageTypeStringTooLong& e){
605 log <<
"FATAL: Unable to write data to COOL";
621 unique_ptr<IStorageMgr> sm(
new StorageMgr(gConfig.
db,
"",
"",log) );
623 log <<
"TrigConfReadWrite: Retrieving JO from the TriggerDB" << lineend;
626 sm->jobOptionTableLoader().setLevel(gConfig.
outputlevel);
627 sm->jobOptionTableLoader().load( jot );
void printhelp(std::ostream &o, std::ostream &(*lineend)(std::ostream &os))
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.
MsgStream for TrigConf classes.
virtual void print(const std::string &indent="", unsigned int detail=1) const override
void setPrescaleSetId(int id)
void setPrescaleSet(const PrescaleSet &pss)
const BunchGroupSet & bunchGroupSet() const
virtual void print(const std::string &indent="", unsigned int detail=1) const override
const Muctpi & muCTPi() const
void setLoadCtpFiles(bool flag=true)
void setBunchGroupSetId(int id)
bool equals(const CTPConfig *other, const std::string &filename) const
HLTPrescaleSetCollection & thePrescaleSetCollection()
void print(const std::string &indent="", unsigned int detail=1) const override
print method
bool equals(const HLTFrame *other, const std::string &filename) const
void addPrescaleSet(unsigned int lumiblock, HLTPrescaleSet *pss)
Add prescale set for this lumiblock number.
void set_prescale_key_to_load(unsigned int)
HLT chain configuration information.
virtual bool load(HLTFrame &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.
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...
virtual IMenuLoader & menuLoader() override
virtual IHLTFrameLoader & hltFrameLoader() 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)
static std::string release
static std::vector< uint32_t > runnumber
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Forward iterator to traverse the main components of the trigger configuration.
unsigned int getKey2(unsigned int which)
vector< unsigned int > keys2
string coolInputConnection
std::vector< std::string > outpar
vector< unsigned int > keys
std::vector< std::string > inpar2
string coolOutputConnection
string CheckForCompleteSetup()
void parseProgramOptions(int argc, char *argv[])
std::vector< std::string > inpar
unsigned int coolOutputRunNr
unsigned int getKey(unsigned int which)