|
ATLAS Offline Software
|
Go to the documentation of this file.
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/lexical_cast.hpp"
49 #include "boost/algorithm/string.hpp"
64 void printhelp(std::ostream & o, std::ostream& (*lineend) ( std::ostream&
os )) {
65 o <<
"================================================================================\n";
66 o <<
"The program needs to be run with the following specifications:\n" << lineend;
67 o <<
"TrigConfReadWrite <options>\n";
69 o <<
"[Global options]\n";
70 o <<
" -i|--input input [input [input]] ... source of configuration, format see below (mandatory)\n";
71 o <<
" -2|--comp input [input [input]] ... source of a second configuration for comparison\n";
72 o <<
" -o|--output r3json|cool [output[;cooldb]] [run] ... output format, name (for cool optional run number)\n";
73 o <<
" ... absolute output file name must contain '/', cooldb can be appended COMP200|OFLP200\n";
74 o <<
" -v|--loglevel <string> ... log level [NIL, VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL, ALWAYS]\n";
75 o <<
" -l|--log <string> ... name of a log file\n";
76 o <<
" --jo ... read and write job options where possible\n";
77 o <<
" --fw ... read ctp firmware\n";
78 o <<
" -p|--print <int> ... print configuration with detail 0...5 (default 1)\n";
79 o <<
" -h|--help ... this output\n";
80 o <<
" --nomerge ... internally don't merge L2 and EF (by default merge is enabled)\n";
82 o <<
"Input can be specified the following\n";
83 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";
84 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";
86 o <<
"The cool dbconnection can be specified as one of the following\n";
87 o <<
" - via alias : COOLONL_TRIGGER (use COOLONL_TRIGGER/COMP200 for Run 1 data)";
88 o <<
" - from sqlite : cool.db (use cool.db;COMP200 for Run 1 data)";
91 o <<
"Input for comparison can be specified the same way, using the '-2' or '--comp' option\n";
94 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";
95 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";
96 o <<
" -o cool ... will produce trig_cool.db with cool db instance CONDBR2 and infinite IOV\n";
97 o <<
" -o cool 200000 ... will produce trig_cool.db with cool db instance CONDBR2 and run number 200000\n";
98 o <<
" -o cool test [200000] ... will produce trig_cool_test.db with cool db instance CONDBR2 [and run number 200000]\n";
99 o <<
" -o cool ../test.db [200000] ... will produce ../test.db with cool db instance CONDBR2 [and run number 200000]\n";
100 o <<
" -o cool 'test;COMP200' [200000] ... will produce Menu_test.db with cool db instance COMP200 [and run number 200000]\n";
102 o <<
"================================================================================\n";
109 std::vector<std::string> inpar, inpar2,
outpar;
118 string l1JsonOutFile {
"L1Menu.json"};
119 string bgkJsonOutFile {
"BunchGroupSet.json"};
120 string l1PSJsonOutFile {
"L1PrescalesSet.json" };
121 string hltJsonOutFile {
"HLTMenu.json" };
122 string hltPSJsonOutFile {
"HLTPrescalesSet.json" };
124 string coolInputConnection {
"" };
125 string coolOutputConnection {
"" };
126 unsigned int coolOutputRunNr { 0 };
134 string logFileName {
""};
136 vector<string>
error;
139 string CheckForCompleteSetup();
141 void PrintSetup(std::ostream &
log, std::ostream& (*lineend) ( std::ostream&
os ));
153 bool startswith(
const std::string&
str,
const std::string& sub) {
154 if(
str.size()<sub.size())
156 return (
str.compare(0,sub.size(),sub) == 0);
159 bool isUnsignedInteger(
const std::string&
str) {
160 for(
const char c :
str)
161 if(c<'0' || c>
'9')
return false;
169 std::string currentPar(
"");
170 std::string listofUnknownParameters =
"";
172 string currInput(
argv[
i]);
173 int fchar = currInput.find_first_not_of(
'-');
174 string stripped = currInput.substr(fchar);
175 bool isParam = (fchar!=0);
178 if( ! (stripped ==
"i" || stripped ==
"input" ||
179 stripped ==
"2" || stripped ==
"comp" ||
180 stripped ==
"o" || stripped ==
"output" ||
181 stripped ==
"l" || stripped ==
"log" ||
182 stripped ==
"p" || stripped ==
"print" ||
185 stripped ==
"nomerge" ||
186 stripped ==
"v" || stripped ==
"loglevel") ) {
187 listofUnknownParameters +=
" " + currInput;
193 if(stripped ==
"h" || stripped ==
"help" ) {
help =
true;
continue; }
194 if(stripped ==
"jo") { jo =
true;
continue; }
195 if(stripped ==
"fw") { fw =
true;
continue; }
196 if(stripped ==
"nomerge") {
merge =
false;
continue; }
197 currentPar = stripped;
199 if(currentPar ==
"i" || currentPar ==
"input") { inpar.push_back(stripped);
continue; }
200 if(currentPar ==
"2" || currentPar ==
"comp") { inpar2.push_back(stripped);
continue; }
201 if(currentPar ==
"o" || currentPar ==
"output") {
202 if(outpar.size()==0 && stripped !=
"r3json" && stripped !=
"cool") {
203 error.push_back(
"Unknown output type: " + stripped +
". Must be either json or cool, optionally followed by a base string for the output file name");
205 outpar.push_back(stripped);
208 if(currentPar ==
"l" || currentPar ==
"log") { logFileName = stripped;
continue; }
209 if(currentPar ==
"p" || currentPar ==
"print") { printlevel = boost::lexical_cast<int,string>(stripped); currentPar=
"";
continue; }
210 if(currentPar ==
"v" || currentPar ==
"loglevel") {
211 if(
"NIL" == stripped ) { outputlevel =
MSGTC::NIL; }
213 else if(
"DEBUG" == stripped ) { outputlevel =
MSGTC::DEBUG; }
214 else if(
"INFO" == stripped ) { outputlevel =
MSGTC::INFO; }
216 else if(
"ERROR" == stripped ) { outputlevel =
MSGTC::ERROR; }
217 else if(
"FATAL" == stripped ) { outputlevel =
MSGTC::FATAL; }
218 else if(
"ALWAYS" == stripped ) { outputlevel =
MSGTC::ALWAYS; }
220 error.push_back(
"Unknown output level: " + stripped +
". Must be one of NIL, VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL, ALWAYS");
226 if(listofUnknownParameters!=
"")
227 error.push_back(
"Unknown parameter(s): " + listofUnknownParameters);
230 error.push_back(
"No input specified, use '-i' option");
234 if( inpar.size()>=1 && inpar[0].find(
".db") != string::npos ) {
240 coolInputConnection =
"sqlite://;schema="+ksv[0]+
";dbname=CONDBR2";
242 coolInputConnection =
"sqlite://;schema="+ksv[0]+
";dbname=" + ksv[1];
244 }
else if( inpar.size()>=1 && startswith(inpar[0],
"COOLONL_TRIGGER") ) {
249 coolInputConnection = ksv[0]+
"/CONDBR2";
251 coolInputConnection = ksv[0]+
"/" + ksv[1];
254 }
else if( inpar.size()==2 ) {
259 for(
const string& ks: ksv) {
260 keys.push_back( boost::lexical_cast<unsigned int,string>(ks) );
265 for(
const string& o: outpar) {
268 }
else if ( o==
"cool" ) {
270 }
else if ( isUnsignedInteger(o) ) {
271 coolOutputRunNr = boost::lexical_cast<unsigned int,string>(o);
279 string dbname =
"CONDBR2";
287 if (
outfile.find(
"/")==string::npos &&
outfile.find(
'.')==string::npos) {
290 coolOutputConnection =
"sqlite://;schema="+
outfile+
";dbname="+
dbname;
292 boost::replace_last(l1JsonOutFile,
".json",
"_"+outBase+
".json");
293 boost::replace_last(bgkJsonOutFile,
".json",
"_"+outBase+
".json");
294 boost::replace_last(l1PSJsonOutFile,
".json",
"_"+outBase+
".json");
295 boost::replace_last(hltJsonOutFile,
".json",
"_"+outBase+
".json");
296 boost::replace_last(hltPSJsonOutFile,
".json",
"_"+outBase+
".json");
305 return "Use argument '-i' to specify input source and check that the input is specified correctly";
308 return "No TriggerDB connection string specified";
310 return "No configuration key(s) specified";
314 return "No TriggerDB connection string specified for comparison, use option '--db2'";
315 if( keys2.size()==0 )
316 return "No smk specified for comparison, use option '--dbsmk2'";
324 log <<
"========================================" << lineend;
325 log <<
"JOB SETUP: " << (
input==DB?
"DB":
"COOL");
327 log <<
" --> " << (
output==COOL?
"COOL":
"JSON");
329 log <<
"----------" << lineend;
331 for(
const string&
s: inpar)
log <<
s <<
", ";
333 if( input2 !=
UNDEF ) {
334 log <<
" Input for comparison: ";
335 for(
const string&
s: inpar2)
log <<
s <<
", ";
341 log << coolOutputConnection;
342 if(coolOutputRunNr==0) {
log <<
", infinite IOV"; }
else {
log <<
", run nr " << coolOutputRunNr; }
347 log <<
" Print menu detail : " << printlevel << lineend;
348 log <<
"========================================" << lineend;
366 if(gConfig.
error.size()!=0) {
367 for(
const string&
e: gConfig.
error)
373 ofstream *outf(0), *errf(0);
377 outf =
new ofstream(outfn.c_str());
378 errf =
new ofstream(errfn.c_str());
380 ostream&
log = (outf==0?cout:*outf);
381 ostream&
logerr = (errf==0?cerr:*errf);
382 ostream& (*lineend) ( ostream&
os ) = &endl;
386 logerr << lineend <<
"===> Error in the option specification: " <<
check << lineend << lineend;
388 if(outf) outf->close();
389 if(errf) errf->close();
444 hltpsk = gConfig.
getKey(2);
449 mckloader->loadMCKlinkedToSMK(
smk, mck);
451 mckloader->loadReleaseLinkedToMCK(mck,
release);
452 log <<
"Loaded MCK " << mck <<
" (active for SMK " <<
smk <<
" and release " <<
release <<
")" << endl;
454 log <<
"Did not load MCK from DB as MCK is 0 or no MCK is linked";
463 unsigned int runnumber = gConfig.
inpar.size()>1 ? boost::lexical_cast<unsigned int,string>(gConfig.
inpar[1]) : 1;
464 unsigned int lb = gConfig.
inpar.size()>2 ? boost::lexical_cast<unsigned int,string>(gConfig.
inpar[2]) : 0;
465 log <<
"TrigConfReadWrite Reading cool : " << coolInputConnection << lineend;
467 log <<
" lb : " <<
lb << lineend;
469 string configSource(
"");
501 log <<
"Loaded this configuration" << lineend;
502 log <<
" SMK " <<
smk << lineend;
503 log <<
" L1 PSK " <<
l1psk << lineend;
504 log <<
" HLT PSK " << hltpsk << lineend;
505 log <<
" BGSK " << bgsk << lineend;
522 log <<
"Retrieving Lvl1 CTP configuration for comparison" << lineend;
533 log <<
"Retrieving HLT menu configuration and prescale set from the TriggerDB for comparison" << lineend;
547 bool equalMenus = ctpc->
equals(ctpc2,
"LVL1config_Diff.xml");
549 log <<
"LVL1 menus are identical." << lineend;
551 log <<
"LVL1 menus differ. Writing LVL1 menu comparison file LVL1config_Diff.xml" << lineend;
554 if(hltFrame && hltFrame2) {
555 bool equalMenus = hltFrame->
equals(hltFrame2,
"HLTconfig_Diff.xml");
557 log <<
"HLT menus are identical." << lineend;
559 log <<
"HLT menus differ. Writing HLT menu comparison file HLTconfig_Diff.xml" << lineend;
592 string configSource(
"");
605 catch(
const cool::StorageTypeStringTooLong&
e){
606 log <<
"FATAL: Unable to write data to COOL";
624 log <<
"TrigConfReadWrite: Retrieving JO from the TriggerDB" << lineend;
void convertRun2BunchGroupsToRun3(const TrigConf::CTPConfig *ctpConfig, const std::string &filename, bool writeTmpFile)
Run 2 to Run 3 bunchgroup converter.
void readHLTPayload(unsigned int run, HLTFrame &hltFrame)
virtual IHLTFrameLoader & hltFrameLoader() override
void convertRun2HLTPrescalesToRun3(const TrigConf::HLTFrame *frame, const std::string &filename)
void printhelp(std::ostream &o, std::ostream &(*lineend)(std::ostream &os))
virtual IMenuLoader & menuLoader() override
const BunchGroupSet & bunchGroupSet() const
virtual bool load(ThresholdConfig &thrcfg)=0
Load the LVL1 trigger thresholds from the configuration source.
HLTPrescaleSetCollection & thePrescaleSetCollection()
std::vector< std::string > inpar
void print(const std::string &indent="", unsigned int detail=1) const override
print method
MsgStream for TrigConf classes.
void readL1PrescalePayload(unsigned int runNumber, unsigned int lumiblockNumber, unsigned int &lvl1PrescaleKey, TrigConf::PrescaleSet &prescale)
Reading luminosityblock-wise configuration information the COOL database.
table to hold the complete list of JobOption entries for a single configuration, from which the JobOp...
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
void writeMCKPayload(ValidityRange vr, unsigned int mck, std::string &release, std::string &info)
void readHltPrescalePayload(unsigned int runNumber, unsigned int lumiblockNumber, TrigConf::HLTPrescaleSet &pss)
Reading luminosityblock-wise configuration information the COOL database.
Database Storage Manager, controls the database session and the different loader classes for DB acces...
string coolOutputConnection
Forward iterator to traverse the main components of the trigger configuration.
bool equals(const CTPConfig *other, const std::string &filename) const
int main(int argc, char *argv[])
unsigned int getKey2(unsigned int which)
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
virtual IJobOptionTableLoader & jobOptionTableLoader()=0
void convertRun2L1MenuToRun3(const TrigConf::CTPConfig *ctpConfig, const TXC::L1TopoMenu *topoMenu, const std::string &filename, bool writeTmpFile)
Conversion of L1 menu.
void print(const std::string &indent="", unsigned int detail=1) const override
print method
string coolInputConnection
unsigned int getKey(unsigned int which)
virtual void setLevel(MSGTC::Level lvl)=0
Load the configuration data from the configuration source.
unsigned int coolOutputRunNr
void readL1BunchGroupLBPayload(unsigned int runNumber, unsigned int lumiblockNumber, int &bgKey, TrigConf::BunchGroupSet &bgs)
Reading lb-wise bunch group configuration information from COOL database.
HLT chain configuration information.
void writeL1Payload(ValidityRange vr, const CTPConfig &ctpConfig)
void setLoadCtpFiles(bool flag=true)
void convertRun2L1PrescalesToRun3(const TrigConf::CTPConfig *ctpConfig, const std::string &filename, bool writeTmpFile)
Conversion of L1 prescales set.
void addPrescaleSet(unsigned int lumiblock, HLTPrescaleSet *pss)
Add prescale set for this lumiblock number.
virtual IMasterTableLoader & masterTableLoader() override
void setBunchGroupSetId(int id)
void setTriggerLevel(int level)
setter of the trigger level
void readL1Payload(unsigned int run, CTPConfig &ctpc)
vector< unsigned int > keys2
virtual void print(const std::string &indent="", unsigned int detail=1) const override
void convertRun2HLTMenuToRun3(const TrigConf::HLTFrame *frame, const std::string &filename)
bool equals(const HLTFrame *other, const std::string &filename) const
string CheckForCompleteSetup()
void setPrescaleSetId(int id)
Reading/Writing of trigger configuration data from/to COOL.
void writeHLTPayload(ValidityRange vr, const HLTFrame &hltFrame, const std::string &configSource)
void set_prescale_key_to_load(unsigned int)
virtual bool load(JobOptionTable &data)=0
virtual bool load(HLTFrame &data)=0
virtual void print(const std::string &indent="", unsigned int detail=1) const override
void parseProgramOptions(int argc, char *argv[])
const Muctpi & muCTPi() const
void setPrescaleSet(const PrescaleSet &pss)
std::vector< std::string > outpar