33 "file",
"f",
"smk",
"l1psk",
"hltpsk",
"bgsk",
"db",
"crest-db",
"crest-server",
"crest-api",
"write",
"w",
34 "Write",
"W",
"help",
"h",
"detail",
"d",
"ctp",
"c"
40 unsigned int smk { 0 };
74 cout <<
"The program needs to be run with the following specifications:\n\n";
75 cout <<
"TriggerMenuRW <options>\n";
77 cout <<
"[Input options]\n";
78 cout <<
" -f|--file file1 [file2 [file3 ...]] ... one or multiple json files\n";
79 cout <<
" --smk smk ... smk \n";
80 cout <<
" --l1psk l1psk ... the L1 prescale key \n";
81 cout <<
" --hltpsk hltpsk ... the HLT prescale key \n";
82 cout <<
" --bgsk bgsk ... the bunchgroup key \n";
83 cout <<
" --db dbalias ... dbalias for oracle/frontier access (default " <<
dbalias <<
") \n";
84 cout <<
" --crest-db crestdb ... crest_db for Crest access, if specified Crest will be used (default '') \n";
85 cout <<
" possible values: CONF_DATA_RUN3, CONF_MC_RUN3, CONF_REPR_RUN3\n";
86 cout <<
" --crest-server server ... crest server (default " <<
crestServerDefault <<
")\n";
87 cout <<
" --crest-api version ... crest api version (default taken from CrestApi)";
88 cout <<
" -c|--ctp ... if provided together with the SMK and DB then will read only CTP files from the DB and not the rest of the menu\n";
89 cout <<
"[Output options]\n";
90 cout <<
" -w|--write [base] ... to write out json files, e.g. L1menu[_<base>].json. base is optional.\n";
91 cout <<
" -W|--Write [base] ... to write out json files from the internal structure (only for L1Menu), e.g. L1menu[_<base>].json. base is optional.\n";
92 cout <<
"[Other options]\n";
93 cout <<
" -h|--help ... this help\n";
94 cout <<
" -d|--detail ... prints detailed job options\n";
97 cout <<
" --file L1menu.json HLTMenu.json ... read L1Menu.json and HLTMenu.json and show some basic statistics\n";
98 cout <<
" --db TRIGGERDB_RUN3 --smk 3205 ... read the L1 menu, HLT menu, HLT job options, and HLT monitoring groups for SMK 3205\n";
99 cout <<
" --db TRIGGERDB_RUN3 --smk 3205 -w ... read the information and write DB content directly as json files\n";
105 std::string currentParameter(
"");
106 std::string listofUnknownParameters =
"";
108 for(
int i=1; i<argc; i++) {
110 std::string currentWord(argv[i]);
111 bool isParam = currentWord[0]==
'-';
114 int firstChar = currentWord.find_first_not_of(
'-');
115 string paramName = currentWord.substr(firstChar);
119 listofUnknownParameters +=
" " + currentWord;
124 currentParameter =
"";
126 if(paramName ==
"h" || paramName ==
"help" ) {
help =
true;
continue; }
127 if(paramName ==
"d" || paramName ==
"detail" ) {
detail =
true;
continue; }
128 if(paramName ==
"w" || paramName ==
"write" ) {
write =
true; }
130 if(paramName ==
"c" || paramName ==
"ctp" ) {
doCtp =
true; }
131 currentParameter = std::move(paramName);
138 if(currentParameter ==
"file" || currentParameter ==
"f") {
142 if(currentParameter ==
"smk") {
143 smk = stoul(currentWord);
146 if(currentParameter ==
"l1psk") {
147 l1psk = stoul(currentWord);
150 if(currentParameter ==
"hltpsk") {
151 hltpsk = stoul(currentWord);
154 if(currentParameter ==
"bgsk") {
155 bgsk = stoul(currentWord);
158 if(currentParameter ==
"db") {
159 dbalias = std::move(currentWord);
162 if(currentParameter ==
"crest-db") {
163 crestDb = std::move(currentWord);
166 if(currentParameter ==
"crest-server") {
170 if(currentParameter ==
"crest-api") {
175 if(currentParameter ==
"write" || currentParameter ==
"w" || currentParameter ==
"Write" || currentParameter ==
"W") {
176 base = std::move(currentWord);
184 error.push_back(
"No input specified! Please provide either one of the following: input file(s), smk, l1psk, hltpsk, or bgsk");
187 if ( listofUnknownParameters.size() > 0 ) {
188 error.push_back(
string(
"Unknown parameter(s):") + listofUnknownParameters);
197 std::string filename = kind;
198 if ( cfg.base !=
"" ) {
199 filename +=
"_" + cfg.base;
203 return fileLoader.
saveFile(filename, ds);
204 }
else if (
cfg.writeFromDataStructure ) {
206 if (
cfg.base !=
"" ) {
210 if ( kind==
"L1Menu" ) {
214 }
else if ( kind ==
"HLTMenu") {
228 if (
cfg.base !=
"" ) {
237int main(
int argc,
char** argv) {
240 cfg.parseProgramOptions(argc, argv);
246 if(cfg.error.size()!=0) {
247 for(
const string & e: cfg.error)
253 if( cfg.inputFiles.size()>0 ) {
256 for (
const std::string & fn : cfg.inputFiles) {
258 std::string filetype = fileLoader.
getFileType( fn );
259 if(filetype ==
"l1menu") {
262 cout <<
"Loaded L1 menu " << l1menu.name() <<
" with " << l1menu.size() <<
" items from " << fn << endl;
263 l1menu.printMenu(cfg.detail);
264 writeJsonFile(l1menu,
"L1Menu", cfg);
265 }
else if(filetype ==
"hltmenu" ) {
268 cout <<
"Loaded HLT menu " << hltmenu.
name() <<
" with " << hltmenu.
size() <<
" chains from " << fn << endl;
270 writeJsonFile(hltmenu,
"HLTMenu", cfg);
271 }
else if(filetype ==
"l1prescale" ) {
274 cout <<
"Loaded L1 prescales set file " << fn <<
" with " << l1pss.
size() <<
" prescales from " << fn << endl;
275 writeJsonFile(l1pss,
"L1PrescalesSet", cfg);
276 }
else if(filetype ==
"hltprescale" ) {
279 cout <<
"Loaded HLT prescales set file " << fn <<
" with " << hltpss.
size() <<
" prescales from " << fn << endl;
281 writeJsonFile(hltpss,
"HLTPrescalesSet", cfg);
282 }
else if(filetype ==
"bunchgroupset" ) {
285 cout <<
"Loaded L1 BunchGroup set file " << fn <<
" with " << bgs.
sizeNonEmpty() <<
" non-empty bunchgroups from " << fn << endl;
287 writeJsonFile(bgs,
"BunchGroupSet", cfg);
288 }
else if(filetype ==
"joboptions" ) {
291 cout <<
"Loaded job options with " << jo.
getObject(
"properties").
getKeys().size() <<
" properties from " << fn << endl;
294 for(
const auto& alg : ds.data()) {
295 std::cout << alg.first << std::endl;
296 for(
const auto& prop : alg.second ) {
297 std::cout <<
" " << prop.first <<
" -> " << prop.second.data() << std::endl;
301 writeJsonFile(jo,
"HLTJobOptions", cfg);
302 }
else if(filetype ==
"hltmonitoringsummary" ) {
305 cout <<
"Loaded HLT monnitoring with " << mon.size() <<
" signatures from " << fn << endl;
306 mon.printMonConfig(cfg.detail);
307 writeJsonFile(mon,
"HLTMonitoring", cfg);
309 cerr <<
"File " << fn <<
" not recognized as being an L1 or HLT menu or prescale set or bunchgroup set" << endl;
314 if( cfg.smk != 0 && !cfg.doCtp ) {
319 if(!cfg.crestDb.empty()) {
331 cout <<
"Could not load L1 menu. An exception occurred: " << ex.
what() << endl;
334 cout <<
"Loaded L1 menu " << l1menu.name() <<
" with " << l1menu.size() <<
" items from " << cfg.dbalias <<
" with SMK " << cfg.smk << endl;
336 l1menu.printMenu(
true);
349 cout <<
"Could not load HLT menu. An exception occurred: " << ex.
what() << endl;
352 cout <<
"Loaded HLT menu " << hltmenu.
name() <<
" with " << hltmenu.
size() <<
" chains from " << cfg.dbalias <<
" with SMK " << cfg.smk << endl;
364 if(!cfg.crestDb.empty()) {
373 cout <<
"Could not load HLT job options. An exception occurred: " << ex.
what() << endl;
376 cout <<
"Loaded job options with " << jo.
getObject(
"properties").
getKeys().size() <<
" entries from " << cfg.dbalias <<
" with SMK " << cfg.smk << endl;
379 for(
const auto& alg : ds.data()) {
380 std::cout << alg.first << std::endl;
381 for(
const auto& prop : alg.second ) {
382 std::cout <<
" " << prop.first <<
" -> " << prop.second.data() << std::endl;
393 if(!cfg.crestDb.empty()) {
402 cout <<
"Could not load HLT monitoring. An exception occurred: " << ex.
what() << endl;
405 cout <<
"Loaded HLT monitoring with " << hltmon.
size() <<
" signatures rom " << cfg.dbalias <<
" with SMK " << cfg.smk << endl;
415 if( cfg.smk != 0 && cfg.doCtp ) {
420 }
catch (std::format_error & e){
421 cout <<
" format_error "<<e.what()<<
" thrown in TriggerMenuRW.\n";
427 if( cfg.l1psk != 0 ) {
430 if(!cfg.crestDb.empty()) {
439 cout <<
"Could not load L1 prescales. An exception occurred: " << ex.
what() << endl;
442 cout <<
"Loaded L1 prescales set " << l1pss.
name() <<
" with " << l1pss.
size() <<
" prescales from " << cfg.dbalias <<
" with L1 PSK " << cfg.l1psk << endl;
446 if( cfg.hltpsk != 0 ) {
449 if(!cfg.crestDb.empty()) {
458 cout <<
"Could not load HLT prescales. An exception occurred: " << ex.
what() << endl;
461 cout <<
"Loaded HLT prescales set " << hltpss.
name() <<
" with " << hltpss.
size() <<
" prescales from " << cfg.dbalias <<
" with HLT PSK " << cfg.hltpsk << endl;
465 if( cfg.bgsk != 0 ) {
468 if(!cfg.crestDb.empty()) {
477 cout <<
"Could not load bunchgroup set. An exception occurred: " << ex.
what() << endl;
480 cout <<
"Loaded L1 bunchgroup set " << bgs.
name() <<
" with " << bgs.
size() <<
" bunchgroups from " << cfg.dbalias <<
" with BGSK " << cfg.bgsk << endl;
Loader class for Trigger configuration from Json.
static const std::string outputFileName
Loader class for Trigger configuration (L1 hardware files) from the Trigger DB.
Loader class for Trigger configuration (HLT prescales set) from the Trigger DB.
Loader class for Trigger configuration from the Trigger DB.
Loader class for Trigger configuration (L1 prescales set) from the Trigger DB.
Loader class for Trigger configuration (L1 prescales set) from the Trigger DB.
Base class for Trigger configuration data and wrapper around underlying representation.
virtual const std::string & name() const final
std::vector< std::string > getKeys() const
Access to the keys of an DataStructure which presents a dictionary.
DataStructure getObject(const std::string &pathToChild, bool ignoreIfMissing=false) const
Access to configuration object.
HLT monitoring configuration.
std::size_t size() const
Accessor to the number of HLT monitoring chains.
void printMonConfig(bool full=false) const
print overview of L1 Menu
std::size_t size() const
number of HLT prescales
void printPrescaleSet(bool full) const
virtual const char * what() const noexcept
Loader of trigger configurations from Json files.
bool saveFile(const std::string &filename, const DataStructure &data) const
Save content of DataStructure (underlying ptree) to a file.
std::string getFileType(const std::string &filename) const
Checks the trigger level of a given json file.
bool loadFile(const std::string &filename, boost::property_tree::ptree &data, const std::string &pathToChild="") const
Load content of json file into a ptree.
Loader of trigger configurations from Json files.
bool writeJsonFile(const std::string &filename, const HLTMenu &menu) const
Loader of trigger configurations from Json files.
bool writeJsonFile(const std::string &filename, const L1Menu &l1menu) const
std::size_t size() const
Accessor to the number of defined bunchgroups.
std::size_t sizeNonEmpty() const
Accessor to the number of non-empty bunchgroups.
void printSummary(bool detailed=false) const
print a more or less detailed summary
std::size_t size() const
number of L1 prescales
Loader of trigger configurations from Json files.
bool loadHardwareFiles(unsigned int smk, L1CTPFiles &ctpfiles, uint8_t loadMask=0x0F, const std::string &outFileName="") const
Load content from the Trigger DB into an L1CTPFiles object for a given super master key (SMK)
Loader of trigger configurations from Json files.
bool loadHLTPrescales(unsigned int hltpsk, HLTPrescalesSet &hltpss, const std::string &outFileName="") const
Load content from the Trigger DB into an HLTPrescalesSet for a given HLTPrescaleKey (HLTPSK)
Loader of trigger configurations from Json files.
bool loadJobOptions(unsigned int smk, boost::property_tree::ptree &jobOptions, const std::string &outFileName="") const
Load job options from the Trigger DB into a ptree for a given SuperMasterKey (SMK)
Loader of trigger configurations from Json files.
bool loadBunchGroupSet(unsigned int bgsk, L1BunchGroupSet &bgs, const std::string &outFileName="") const
Load content from the Trigger DB into an L1PrescalesSet for a given L1PrescaleKey (L1PSK)
Loader of trigger configurations from Json files.
bool loadL1Prescales(unsigned int l1psk, L1PrescalesSet &l1pss, const std::string &outFileName="") const
Load content from the Trigger DB into an L1PrescalesSet for a given L1PrescaleKey (L1PSK)
void setCrestTrigDB(const std::string &crestTrigDB)
set trigger db for the crest connection
void setCrestConnection(const std::string &server, const std::string &version="")
declare CREST as the source of the configuration An empty crest server makes it use Oracle
Loader of trigger menu configurations from the database.
bool loadHLTMonitoring(unsigned int smk, boost::property_tree::ptree &hltmonitoring, const std::string &outFileName="") const
Load HLT menu content from the Trigger DB into two ptrees for a given SuperMasterKey (SMK)
std::vector< std::string > knownParameters
bool writeFromDataStructure
const std::string crestServerDefault
void parseProgramOptions(int argc, char *argv[])
std::vector< std::string > inputFiles