34 #include "boost/lexical_cast.hpp"
35 #include "boost/algorithm/string.hpp"
50 using boost::lexical_cast;
53 void printhelp(std::ostream & o, std::ostream& (*lineend) ( std::ostream&
os )) {
54 o <<
"================================================================================\n";
55 o <<
"The program needs to be run with the following specifications:\n" << lineend;
56 o <<
"TrigConfReadWrite <options>\n";
58 o <<
"[Global options]\n";
59 o <<
" -c|--cooldb <cooldb> ... cool database and run number (default is COOLONL_TRIGGER/CONDBR2)\n";
60 o <<
" e.g. COOLONL_TRIGGER/CONDBR2 or testcool.db \n";
61 o <<
" -r|--run <run> [<lb>] [<lbend>] ... run number (mandatory) and optionally lb (range)\n";
63 o <<
" --triggerdb <triggerdb> ... trigger database as source of information (default is TRIGGERDBR2)\n";
64 o <<
" --smk <smk> ... SMK to load to cool (specify when needed)\n";
65 o <<
" --bgsk <bgsk> ... Bunchgroupset key to load to cool (specify when needed)\n";
66 o <<
" --l1psk <l1psk> ... L1PSK to load to cool (specify when needed)\n";
67 o <<
" --hltpsk <int> ... hltpsk to load to cool (specify when needed)\n";
68 o <<
" --release <string> ... release, e.g. 20.2.3.1 (specify when configkeys is to be uploaded)\n";
70 o <<
" -f|--fix ... when specified it fixes the database. Only run after a test without it\n";
71 o <<
" -e|--extended ... allows fixing of any multiversion folder\n";
73 o <<
" -v|--loglevel <level> ... log level [NIL, VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL, ALWAYS]\n";
74 o <<
" -p|--print <detail> ... print configuration with detail 0...5 (default 1)\n";
75 o <<
" -h|--help ... this output\n";
77 o <<
"Input database can be specified the following ways: COOLONL_TRIGGER/CONDBR2 or trigconf.db/CONDBR2\n";
79 o <<
"Instructions at https://twiki.cern.ch/twiki/bin/view/Atlas/TriggerConfigurationCOOLArchiver\n";
80 o <<
"================================================================================\n";
85 string cooldb{
"COOLONL_TRIGGER/CONDBR2"};
88 unsigned int lbend {0};
89 bool openended {
true};
92 bool extendedSelection {
false};
94 string triggerdb {
"TRIGGERDBR2"};
107 string coolConnection {
""};
108 int parseProgramOptions(
int argc,
char*
argv[]);
117 std::string currentPar(
"");
118 std::string listofUnknownParameters =
"";
121 string currInput(
argv[
i]);
122 int fchar = currInput.find_first_not_of(
'-');
123 string stripped = currInput.substr(fchar);
124 bool isParam = (fchar!=0);
127 if( ! (stripped ==
"c" || stripped ==
"cooldb" ||
128 stripped ==
"r" || stripped ==
"run" ||
129 stripped ==
"l" || stripped ==
"log" ||
130 stripped ==
"p" || stripped ==
"print" ||
131 stripped ==
"f" || stripped ==
"fix" ||
132 stripped ==
"e" || stripped ==
"extended" ||
133 stripped ==
"triggerdb" ||
134 stripped ==
"release" ||
135 stripped ==
"h" || stripped ==
"help" ||
136 stripped ==
"v" || stripped ==
"loglevel") ) {
137 listofUnknownParameters +=
" " + currInput;
143 if(stripped ==
"h" || stripped ==
"help" ) {
help =
true;
continue; }
144 if(stripped ==
"f" || stripped ==
"fix") { fix =
true;
continue; }
145 if(stripped ==
"e" || stripped ==
"extended") { extendedSelection =
true;
continue; }
146 currentPar = stripped;
148 if(currentPar ==
"c" || currentPar ==
"cooldb") { cooldb = stripped; currentPar=
"";
continue; }
149 if(currentPar ==
"r" || currentPar ==
"run") {
150 unsigned int val = boost::lexical_cast<unsigned int,string>(stripped);
166 if(currentPar ==
"triggerdb") { triggerdb = stripped;
continue; }
167 if(currentPar ==
"release") {
release = stripped;
continue; }
168 if(currentPar ==
"p" || currentPar ==
"print") { printlevel = boost::lexical_cast<int,string>(stripped); currentPar=
"";
continue; }
169 if(currentPar ==
"v" || currentPar ==
"loglevel") {
170 if(
"NIL" == stripped ) { outputlevel =
MSGTC::NIL; }
172 else if(
"DEBUG" == stripped ) { outputlevel =
MSGTC::DEBUG; }
173 else if(
"INFO" == stripped ) { outputlevel =
MSGTC::INFO; }
175 else if(
"ERROR" == stripped ) { outputlevel =
MSGTC::ERROR; }
176 else if(
"FATAL" == stripped ) { outputlevel =
MSGTC::FATAL; }
177 else if(
"ALWAYS" == stripped ) { outputlevel =
MSGTC::ALWAYS; }
179 error.push_back(
"Unknown output level: " + stripped +
". Must be one of NIL, VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL, ALWAYS");
186 if(listofUnknownParameters!=
"")
187 error.push_back(
"Unknown parameter(s): " + listofUnknownParameters);
190 error.push_back(
"No run specified, use '--run <run>' option");
195 string dbname =
"CONDBR2";
196 size_t slashpos = cooldb.find(
'/');
197 if(slashpos != string::npos) {
198 db = cooldb.substr(0,slashpos);
199 dbname = cooldb.substr(slashpos+1);
201 if(
db.find(
'.') != string::npos) {
202 coolConnection =
"sqlite://;schema="+
db+
";dbname=" +
dbname;
212 if(
error.size()!=0) {
213 for(
const string&
e:
error)
226 cout <<
"========================================" << endl;
227 cout <<
"JOB SETUP: " << endl;
228 cout <<
"----------" << endl;
229 cout <<
" Run : " <<
run << endl;
230 cout <<
" LB : " <<
lb <<
" - " << lbend << endl;
231 cout <<
" Cool DB : " << coolConnection << endl;
232 cout <<
" Trigger database : " << triggerdb << endl;
233 cout <<
" Fix flag : " << (fix ?
"yes" :
"no") << endl;
236 cout <<
" Print menu detail : " << printlevel << endl;
237 cout <<
"========================================" << endl;
245 cout << prompt; cin >>
input;
247 key = boost::lexical_cast<T, string>(
input);
250 cout <<
input <<
" is not a valid input" << endl;
284 if( ! gConfig.
fix ) {
289 if(fixableFolders.size()==0) {
290 cout << endl <<
"All folders are properly filled. Exiting ..." << endl;
301 set<unsigned int> selectForFixing;
306 cout << endl <<
" 0 ... exit" << endl;
308 for(
const string &
f : fixableFolders) {
309 if(selectForFixing.count(
idx)>0) {
310 cout <<
" * " << ++
idx <<
" ... " <<
f << endl;
312 cout <<
" " << ++
idx <<
" ... " <<
f << endl;
315 cout << endl <<
" a ... select/deselect all" << endl;
316 cout << endl <<
" e ... " << (gConfig.
extendedSelection ?
"disallow" :
"allow") <<
" multiversion folder selection (clears selection)" << endl;
317 cout << endl <<
" f ... fix now" << endl;
318 cout << endl << endl <<
"Select/deselect folder to fix or other option : "; cin >>
selection;
323 bool allSelected = (fixableFolders.size() == selectForFixing.size());
325 selectForFixing.clear();
327 for(
unsigned int selInd = 0; selInd<fixableFolders.size();selInd++)
328 selectForFixing.insert(selInd);
336 selectForFixing.clear();
339 unsigned int selInd = boost::lexical_cast<unsigned int,string>(
selection) - 1;
340 if(selectForFixing.count(selInd)) {
341 selectForFixing.erase(selInd);
343 selectForFixing.insert(selInd);
355 cout << endl <<
"Exiting ..." << endl;
359 if(selectForFixing.empty()) {
360 cout << endl <<
"Nothing selected. Exiting ..." << endl;
364 vector<string> foldersToFix;
365 for(
unsigned int idx=0;
idx!=fixableFolders.size();
idx++) {
366 if(selectForFixing.count(
idx)>0)
367 foldersToFix.push_back(fixableFolders[
idx]);
371 cout << endl <<
"Folders for fixing:";
372 for(
const string &
f : foldersToFix)
378 bool loadL1(
false), loadHLT(
false), loadBGSK(
false), loadL1PSK(
false), loadHLTPSK(
false), saveConfigSource(
false);
379 for(
const string & folderToFix : foldersToFix) {
382 ( folderToFix ==
"/TRIGGER/LVL1/Menu") ||
383 ( folderToFix ==
"/TRIGGER/LVL1/ItemDef") ||
384 ( folderToFix ==
"/TRIGGER/LVL1/Thresholds") ||
385 ( folderToFix ==
"/TRIGGER/LVL1/CTPCoreInputMapping") ||
386 ( folderToFix ==
"/TRIGGER/LVL1/BunchGroupDescription");
389 ( folderToFix ==
"/TRIGGER/HLT/HltConfigKeys") ||
390 ( folderToFix ==
"/TRIGGER/HLT/Menu") ||
391 ( folderToFix ==
"/TRIGGER/HLT/Groups");
394 ( folderToFix ==
"/TRIGGER/LVL1/BunchGroupKey") ||
395 ( folderToFix ==
"/TRIGGER/LVL1/BunchGroupContent") ||
396 ( folderToFix ==
"/TRIGGER/LVL1/BunchGroupDescription");
399 ( folderToFix ==
"/TRIGGER/LVL1/Lvl1ConfigKey") ||
400 ( folderToFix ==
"/TRIGGER/LVL1/Prescales");
403 ( folderToFix ==
"/TRIGGER/HLT/PrescaleKey") ||
404 ( folderToFix ==
"/TRIGGER/HLT/Prescales");
407 ( folderToFix ==
"/TRIGGER/HLT/HltConfigKeys");
412 if( (loadL1 || loadHLT) && gConfig.
smk==0)
415 if( loadBGSK && gConfig.
bgsk==0)
418 if( loadL1PSK && gConfig.
l1psk==0)
421 if( loadHLTPSK && gConfig.
hltpsk==0) {
422 string prompt =
"Please specify HLT Prescaleset key";
424 prompt +=
" (starting at LB " + lexical_cast<string,int>(gConfig.
lb) +
"): ";
431 if( saveConfigSource && gConfig.
release==
"")
448 cout << endl << endl <<
"Retrieving Lvl1 CTP configuration" << endl;
456 cout << endl << endl <<
"Retrieving HLT menu configuration" << endl;
465 cout << endl << endl <<
"Retrieving Lvl1 Bunchgroup set configuration" << endl;
474 cout << endl << endl <<
"Retrieving L1 prescales" << endl;
483 cout << endl << endl <<
"Retrieving HLT prescales" << endl;
499 cout <<
"Writing cool to destination " << gConfig.
coolConnection << endl;
519 for(
const string & folderToFix : foldersToFix) {
520 if( folderToFix ==
"/TRIGGER/LVL1/BunchGroupKey" ||
521 folderToFix ==
"/TRIGGER/LVL1/BunchGroupContent") {
526 if(loadBGSK && doWrite) {
531 for(
const string & folderToFix : foldersToFix) {
532 if( folderToFix ==
"/TRIGGER/LVL1/BunchGroupDescription") {
533 if(ctpConfig && bgs) {
549 for(
const string & folderToFix : foldersToFix) {
550 if( folderToFix ==
"/TRIGGER/LVL1/Lvl1ConfigKey" ||
551 folderToFix ==
"/TRIGGER/LVL1/Prescales") {
556 if(loadL1PSK && doWrite) {
572 for(
const string & folderToFix : foldersToFix) {
573 if( folderToFix ==
"/TRIGGER/HLT/PrescaleKey" ||
574 folderToFix ==
"/TRIGGER/HLT/Prescales") {
579 if(hltpss && doWrite) {
591 for(
const string & folderToFix : foldersToFix) {
592 if( folderToFix ==
"/TRIGGER/LVL1/Menu" ||
593 folderToFix ==
"/TRIGGER/LVL1/ItemDef" ||
594 folderToFix ==
"/TRIGGER/LVL1/Thresholds" ||
595 folderToFix ==
"/TRIGGER/LVL1/CTPCoreInputMapping") {
600 if(ctpConfig && doWrite) {
613 for(
const string & folderToFix : foldersToFix) {
614 if( folderToFix ==
"/TRIGGER/HLT/Menu" ||
615 folderToFix ==
"/TRIGGER/HLT/Groups" ||
616 folderToFix ==
"/TRIGGER/HLT/HltConfigKeys" ) {
622 if(hltFrame && doWrite) {
623 string configSource =
"TRIGGERDBR2," + gConfig.
release +
",AtlasP1HLT";