34 fFirstSequenceName =
"";
35 fLastSequenceName =
"";
36 SetParameter(
"General.MainConfigFile",std::string(
""));
37 SetParameter(
"General.LogFile",std::string(
""));
39 SetParameter(
"General.PrintVerbosity",
QVdt(1));
40 SetParameter(
"General.LogVerbosity",
QVdt(1));
41 SetParameter(
"General.EventsToBeSkipped",0);
42 SetParameter(
"General.EventsToBeProcessed",0);
43 SetParameter(
"General.Driver",
QVdt(
""));
44 SetParameter(
"General.OverWrite",
QVdt(
false));
45 SetParameter(
"General.TimeProfilingOn",
QVdt(
false));
46 SetParameter(
"General.SkipRequiredNotValid",
QVdt(
false));
58 SetParameter(
"General.DIANA_EXTSWREVISION",versions);
71 std::map< std::string, ParamInfo >::const_iterator iter = fParams.begin();
72 std::vector<std::string> floatingOptions;
73 while(iter != fParams.end()) {
74 std::string name = iter->first;
75 std::string myseq = name.substr(0,name.find_first_of(
"."));
76 std::string rest = name.substr(0,name.find_last_of(
"."));
79 enabled = GetParameter(rest +
".enable").GetBool();
82 if(myseq == seq && enabled && iter->second.get == 0) {
83 floatingOptions.push_back(iter->first);
87 if(!floatingOptions.empty()) {
88 o <<
"The following configuration file parameters were not read by modules (useless directives?): "<<std::endl;
89 for(
size_t i = 0; i < floatingOptions.size(); i++ ) {
90 o <<
"Parameter: "<<floatingOptions[i]<<std::endl;
97 std::map< std::string, ParamInfo >::const_iterator iter = fParams.begin();
98 std::vector<std::string> floatingOptions;
99 while(iter != fParams.end()) {
100 std::string name = iter->first;
101 std::string myseq = name.substr(0,name.find_first_of(
"."));
102 std::string rest = name.substr(0,name.find_last_of(
"."));
103 bool enabled =
false;
105 enabled = GetParameter(rest +
".enable").GetBool();
108 if(myseq == seq && enabled && iter->second.get == 2) {
109 floatingOptions.push_back(iter->first);
113 if(!floatingOptions.empty()) {
114 o <<
"The following configuration parameters were set at default values: "<<std::endl;
115 for(
size_t i = 0; i < floatingOptions.size(); i++ ) {
116 o <<
"Parameter: "<<floatingOptions[i]<<
" = "<<fParams[floatingOptions[i]].param<<std::endl;
123 o <<
"(CC) Dump of configuration parameters\n";
124 std::map< std::string, ParamInfo>::iterator it;
125 for(it=fParams.begin(); it!=fParams.end(); it++) {
126 o <<
"(CC) "<< it->first<<
"\t=\t";
130 for(
size_t i = 0; i <
vec.size(); i++) {
131 o<<
vec[i].GetName()<<
"="<<
vec[i].GetString()<<
",";
135 o <<it->second.param.GetString()<<std::endl;
138 o <<
"(CC) End of dump of configuration parameters\n";
143 std::cout <<
"Usage: "<<exe<<
" -C file [options]" << std::endl;
144 std::cout <<
"Options:" << std::endl;
145 std::cout <<
" -c file file overriding config file parameters\n";
146 std::cout <<
" -C file config file name (mandatory)\n";
147 std::cout <<
" -e n number of events to be processed\n";
148 std::cout <<
" -D driver automatically load a driver module\n";
149 std::cout <<
" -f file input filename or filelist (must have .list extension) \n";
150 std::cout <<
" -g abort instead of throwing an exception (useful to trace back errors)\n";
151 std::cout <<
" -h this command \n";
152 std::cout <<
" -i version version of input gloabl data quantities (e.g. 2.10) \n";
153 std::cout <<
" -l logfile logfile name\n";
154 std::cout <<
" -o filep output file prefix \n";
155 std::cout <<
" -O overwrite objects already present in input files \n";
156 std::cout <<
" -p param val override config file parameter sequence.module.occurrence.parameter with value val\n";
157 std::cout <<
" -q decrease screen verbosity by 1 level\n";
158 std::cout <<
" -s n number of events to be skipped\n";
159 std::cout <<
" -S switch to true the SkipRequiredNotValid option when present\n";
160 std::cout <<
" -T enable time profiling of Do() methods in modules\n";
161 std::cout <<
" -v increase screen verbosity by 1 level\n";
162 std::cout <<
" -V var val define config file variable var with value val\n";
170 int GeneralVerbosity = 2;
171 std::string UserConfigFile =
"";
172 std::string MainConfigFile =
"";
173 std::string LogFileName;
174 std::string Driver =
"";
176 char time_string[31];
177 ::strftime(time_string, 31,
"diana_%Y_%m_%d_%H%M%S.log", ::localtime(&t));
178 const char *p = ::getenv(
"DIANA_INSTALL");
179 if(p) SetParameter(
"CFGVar.DIANA_INSTALL",
QVdt(p));
180 const char *pext = ::getenv(
"DIANA_EXT_INSTALL");
181 if(pext) SetParameter(
"CFGVar.DIANA_EXT_INSTALL",
QVdt(pext));
187 LogFileName +=
"/log/";
188 LogFileName += time_string;
190 LogFileName =
"log/";
191 LogFileName += time_string;
195 dbv = ::getenv(
"DIANA_DB_NAME");
196 if(dbv) SetParameter(
"General.DIANA_DB_NAME",
QVdt(dbv));
197 dbv = ::getenv(
"DIANA_DB_HOST");
198 if(dbv) SetParameter(
"General.DIANA_DB_HOST",
QVdt(dbv));
199 dbv = ::getenv(
"DIANA_DB_PORT");
200 if(dbv) SetParameter(
"General.DIANA_DB_PORT",
QVdt(dbv));
201 dbv = ::getenv(
"DIANA_DB_USER");
202 if(dbv) SetParameter(
"General.DIANA_DB_USER",
QVdt(dbv));
203 dbv = ::getenv(
"DIANA_DB_PWD");
204 if(dbv) SetParameter(
"General.DIANA_DB_PWD",
QVdt(dbv));
207 int EventsToBeSkipped = 0;
210 std::string InputFileName=
"";
211 std::string InputFilesList=
"";
212 std::string OutputFilePrefix=
"";
216 SetParameter(
"General.GSLErrorHandler",std::string(
"diana"));
218 const char valid_options[] =
":vqhgc:i:C:G:f:F:Ss:e:n:OTp:lo:D:V:";
220 int c = ::getopt (argc, argv, valid_options);
228 SetParameter(
"General.UserConfigFile",
QVdt(UserConfigFile));
241 std::string inputVersion =
optarg;
242 SetParameter(
"General.GlobalDataInputVersion",
QVdt(inputVersion));
247 SetParameter(
"General.InputFile",
QVdt(InputFileName));
248 SetParameter(
"General.ReadFilesList",
QVdt(
false));
253 SetParameter(
"General.InputFilesList",
QVdt(InputFilesList));
254 SetParameter(
"General.ReadFilesList",
QVdt(
true));
257 SetParameter(
"General.GSLErrorHandler",std::string(
"default"));
261 EventsToBeSkipped = atoi(
optarg );
262 if (EventsToBeSkipped < 0)
267 SetParameter(
"General.SkipRequiredNotValid",
QVdt(
true));
270 SetParameter(
"General.TimeProfilingOn",
QVdt(
true));
274 EventsToBeProcessed = atoi(
optarg );
275 if (EventsToBeProcessed < 0)
276 EventsToBeProcessed=999999999;
279 SetParameter(
"General.OverWrite",
QVdt(
true));
285 throw std::runtime_error (
"option -p requires 2 parameters with the \"sequence.module.occurrence.parameter value\" syntax");
287 for (
size_t k = 0; k < ::strlen (valid_options); k++) {
288 if (valid_options[k] !=
':' && valid_options[k] == argv[
optind][1])
289 throw std::runtime_error (
"option -p requires 2 parameters with the \"sequence.module.occurrence.parameter value\" syntax");
300 throw std::runtime_error (
"option -V requires 2 parameters with the \"variable_name variable_value\" syntax");
302 for (
size_t k = 0; k < ::strlen (valid_options); k++) {
303 if (valid_options[k] !=
':' && valid_options[k] == argv[
optind][1])
304 throw std::runtime_error (
"option -V requires 2 parameters with the \"variable_name variable_value\" syntax");
307 std::string cfgvar =
"CFGVar.";
308 cfgvar += std::string(
optarg);
316 LogFileName = argv[
optind++];
323 if(GeneralVerbosity<0) GeneralVerbosity = 0;
331 OutputFilePrefix =
optarg;
332 SetParameter(
"General.OutputFilePrefix",
QVdt(OutputFilePrefix));
339 throw std::runtime_error (std::string(
"Missing value on command line option -") +
char (
optopt));
343 throw std::runtime_error (std::string(
"Unknown command line option: -") +
char (
optopt));
349 if(MainConfigFile.empty()) {
354 SetParameter(
"General.MainConfigFile",
QVdt(MainConfigFile));
355 SetParameter(
"General.LogFile",
QVdt(LogFileName));
356 SetParameter(
"General.PrintVerbosity",
QVdt(GeneralVerbosity));
357 SetParameter(
"General.LogVerbosity",
QVdt(1));
358 SetParameter(
"General.EventsToBeSkipped",
QVdt(EventsToBeSkipped));
359 SetParameter(
"General.EventsToBeProcessed",
QVdt(EventsToBeProcessed));
360 SetParameter(
"General.Driver",
QVdt(Driver));
362 (
MsgLevel)GetInt(
"General.LogVerbosity"),
363 GetString(
"General.LogFile")
370 std::map<std::string,QVdt>::const_iterator itb;
371 for(itb=fUserParams.begin(); itb!=fUserParams.end(); itb++) {
372 const std::string& n = itb->first;
373 SetParameter(n,itb->second);
376 std::map<std::string,ParamInfo>::const_iterator itp = fParams.begin();
377 while(itp != fParams.end()) {
378 std::string key = itp->first;
380 if ((key.substr(key.find_last_of(
".0"),std::string::npos) ==
".InputFilesList") &&
381 (key.substr(0,key.find_first_of(
".")) == fFirstSequenceName)) {
383 QVdt s = GetParameter(
"General.InputFilesList");
385 SetParameter(itp->first,s);
395 if ((key.substr(key.find_last_of(
".0"),std::string::npos) ==
".OutputFilePrefix") &&
396 (key.substr(0,key.find_first_of(
".")) == fLastSequenceName)) {
398 QVdt s = GetParameter(
"General.OutputFilePrefix");
400 SetParameter(itp->first,s);
410 if ((key.substr(key.find_last_of(
".0"),std::string::npos) ==
".InputFile") &&
411 (key.substr(0,key.find_first_of(
".")) == fFirstSequenceName)) {
414 QVdt s = GetParameter(
"General.InputFile");
416 SetParameter(itp->first,s);
426 if ((key.substr(key.find_last_of(
".0"),std::string::npos) ==
".ReadFilesList") &&
427 (key.substr(0,key.find_first_of(
".")) == fFirstSequenceName)) {
429 QVdt b = GetParameter(
"General.ReadFilesList");
430 SetParameter(itp->first,
b);
440 if ((key.substr(key.find_last_of(
"."),std::string::npos) ==
".SkipRequiredNotValid") ) {
443 QVdt s = GetParameter(
"General.SkipRequiredNotValid");
445 SetParameter(itp->first,s);
449 QMessageHandler::Panic(GetName(),
"Command line option error for parameter SkipRequiredNotValid: " +
err.GetDescription());
464 if ( fParams.find(n) ==fParams.end() ){
465 throw std::runtime_error(
"Parameter: \""+n+
"\" does not exist");
467 if(fParams[n].get != 2)
469 return fParams[n].param;
475 snprintf(o,128,
"%u",(
unsigned int)occ);
476 std::string n = seq+
"."+mod+
"."+o+
"."+par;
477 return GetParameter(n);
480 void QOptions::SetParameter(
const std::string& seq,
const std::string& mod,
size_t occ,
const std::string& par,
const QVdt& p,
const bool isDefault)
483 snprintf(o,128,
"%u",(
unsigned int)occ);
484 std::string n = seq+
"."+mod+
"."+o+
"."+par;
485 SetParameter(n,p, isDefault);
489 double QOptions::GetDouble(
const std::string& seq,
const std::string& mod,
size_t occ,
const std::string& par)
491 return GetParameter(seq,mod,occ,par).GetDouble();
496 return GetParameter(n).GetDouble();
500 return GetParameter(seq,mod,occ,par).GetVectorDouble();
504 return GetParameter(n).GetVectorDouble();
508 int QOptions::GetInt(
const std::string& seq,
const std::string& mod,
size_t occ,
const std::string& par)
510 return GetParameter(seq,mod,occ,par).GetInt();
514 return GetParameter(n).GetInt();
516 std::vector<int>
QOptions::GetVectorInt(
const std::string& seq,
const std::string& mod,
size_t occ,
const std::string& par)
518 return GetParameter(seq,mod,occ,par).GetVectorInt();
522 return GetParameter(n).GetVectorInt();
526 bool QOptions::GetBool(
const std::string& seq,
const std::string& mod,
size_t occ,
const std::string& par)
528 return GetParameter(seq,mod,occ,par).GetBool();
532 return GetParameter(n).GetBool();
536 return GetParameter(seq,mod,occ,par).GetVectorBool();
540 return GetParameter(n).GetVectorBool();
546 return GetParameter(seq,mod,occ,par).GetVectorString();
550 return GetParameter(n).GetVectorString();
556 const std::string&
QOptions::GetString(
const std::string& seq,
const std::string& mod,
size_t occ,
const std::string& par)
558 return GetParameter(seq,mod,occ,par).GetString();
563 return GetParameter(n).GetString();
569 if(fParams.find(n) != fParams.end()) {
570 fParams[n].param.SetName(n);
572 fParams[n].param = val;
582 std::map<std::string,QVdt*> theMap;
584 std::map<std::string, ParamInfo>::iterator p = fParams.begin();
586 while(p != fParams.end()) {
588 snprintf(o,128,
"%u",(
unsigned int)occ);
590 std::string::size_type loc = p->first.find(seq +
"." + mod+
"." + os, 0 );
591 if( loc != std::string::npos ) {
592 size_t len = seq.size() + 1 + mod.size() + 1 + os.size();
593 std::string paramName = p->first.substr(len+1,std::string::npos);
594 theMap[paramName] = &(p->second.param);
#define Q_BEGIN_NAMESPACE
error class with error type and description
static QMessageHandler * Get()
static void Panic(const std::string &sender, const std::string &msg)
const std::string & GetString(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
double GetDouble(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
std::vector< double > GetVectorDouble(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
void SetParameter(const std::string &n, const QVdt &value, const bool isDefault=false)
void Init(int argc, char *const argv[])
std::vector< bool > GetVectorBool(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
void CheckNotGet(const std::string &seq, std::ostream &o)
void Help(const char *exe)
const QVdt & GetParameter(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
void Dump(std::ostream &)
std::map< std::string, QVdt * > GetModuleParameters(const std::string &seq, const std::string &mod, size_t occ)
void ReplaceUserParams()
replace parameters that where super-seeded with inline command
std::vector< std::string > GetVectorString(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
int GetInt(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
static QOptions & GetInstance()
std::vector< int > GetVectorInt(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
bool GetBool(const std::string &seq, const std::string &mod, size_t occ, const std::string &par)
void CheckAtDefault(const std::string &seq, std::ostream &o)
static const char * GetFFTLibrary()
std::vector< QVdt > QVdt_vector
const std::string & GetString() const
const char * GetFFTWVersion()
Return the FFTW version.
const char * GetBoostVersion()
Return the Boost version.
const char * GetDianaVersionTag()
Return the DIANA version tag.
const char * GetQtVersion()
Return the Qt version.
const char * GetGSLVersion()
Return the GSL version.
const char * GetROOTVersion()
Return the ROOT version.
const char * GetDianaSWRevision()
Return the DIANA SW version string.
const char * GetPSQLVersion()
Return the PSQL version.
general purpose string manipulation functions