16 #include "libxml/xmlmemory.h" 17 #include "libxml/parser.h" 35 using std::ostringstream;
37 using namespace genie;
43 config_pool.
Print(stream);
53 LOG(
"AlgConfigPool",
pERROR) <<
"Could not load XML config file";
70 string key = citer->first;
99 <<
"AlgConfigPool late initialization: Loading all XML config. files";
110 SLOG(
"AlgConfigPool",
pWARN ) <<
"Tune generator List not available" ;
118 conf_file_iter !=
fConfigFiles.end(); ++conf_file_iter) {
120 string alg_name = conf_file_iter->first;
121 string file_name = conf_file_iter->second;
128 <<
"*** GENIE XML config file " << full_path;
132 <<
"Error in loading config sets for algorithm = " << alg_name;
146 bool is_accessible = ! (gSystem->AccessPathName(
fMasterConfig.c_str() ));
147 if (!is_accessible) {
149 <<
"The XML doc doesn't exist! (filename : " <<
fMasterConfig <<
")";
156 <<
"The XML doc can't be parsed! (filename : " <<
fMasterConfig <<
")";
160 xmlNodePtr xml_root = xmlDocGetRootElement(xml_doc);
163 <<
"The XML doc is empty! (filename : " <<
fMasterConfig <<
")";
168 if( xmlStrcmp(xml_root->name, (
const xmlChar *)
"genie_config") ) {
170 <<
"The XML doc has invalid root element! " 178 xmlNodePtr xml_ac = xml_root->xmlChildrenNode;
179 while (xml_ac != NULL) {
180 if( (!xmlStrcmp(xml_ac->name, (
const xmlChar *)
"config")) ) {
185 xmlNodeListGetString(xml_doc, xml_ac->xmlChildrenNode, 1));
187 pair<string, string> alg_conf(alg_name, config_file);
190 xml_ac = xml_ac->next;
202 SLOG(
"AlgConfigPool",
pINFO) <<
"Loading global parameter lists";
208 string key_prefix =
"GlobalParameterList";
211 return this->
LoadRegistries(key_prefix, glob_params,
"global_param_list");
218 SLOG(
"AlgConfigPool",
pINFO) <<
"Loading Common " << file_id <<
" lists";
221 std::string xml_name =
"Common" + file_id +
".xml" ;
225 string key_prefix =
"Common" + file_id +
"List";
228 if ( ! this->
LoadRegistries(key_prefix, full_path,
"common_"+file_id+
"_list") ) {
230 SLOG(
"AlgConfigPool",
pERROR) <<
"Failed to load Common " << file_id ;
241 SLOG(
"AlgConfigPool",
pINFO) <<
"Loading Tune Gerator List";
247 string key_prefix =
"TuneGeneratorList";
250 return this->
LoadRegistries(key_prefix, generator_list_file,
"tune_generator_list");
260 string key_prefix = alg_name;
267 string key_prefix,
string file_name,
string root)
271 SLOG(
"AlgConfigPool",
pDEBUG) <<
"[-] Loading registries:";
273 bool is_accessible = ! (gSystem->AccessPathName(file_name.c_str()));
274 if (!is_accessible) {
276 <<
"The XML doc doesn't exist! (filename : " << file_name <<
")";
280 xmlDocPtr xml_doc = xmlParseFile( file_name.c_str() );
283 <<
"The XML document can't be parsed! (filename : " << file_name <<
")";
287 xmlNodePtr xml_cur = xmlDocGetRootElement( xml_doc );
290 <<
"The XML document is empty! (filename : " << file_name <<
")";
294 if( xmlStrcmp(xml_cur->name, (
const xmlChar *) root.c_str()) ) {
296 <<
"The XML document has invalid root element! " 297 <<
"(filename : " << file_name <<
")";
298 xmlFreeNode(xml_cur);
304 xml_cur = xml_cur->xmlChildrenNode;
305 while (xml_cur != NULL) {
307 if( (!xmlStrcmp(xml_cur->name, (
const xmlChar *)
"param_set")) ) {
314 key << key_prefix <<
"/" << param_set;
322 xmlNodePtr xml_param = xml_cur->xmlChildrenNode;
323 while (xml_param != NULL) {
324 if( (!xmlStrcmp(xml_param->name, (
const xmlChar *)
"param")) ) {
334 xmlNodeListGetString(
335 xml_doc, xml_param->xmlChildrenNode, 1));
338 if ( param_type.find(
"vec-" ) == 0 ) {
340 param_type = param_type.substr( 4 ) ;
347 param_type, param_name,
350 xml_param = xml_param->next;
353 xmlFreeNode(xml_param);
357 pair<string, Registry *> single_reg(key.str(),
config);
360 SLOG(
"AlgConfigPool",
pDEBUG) <<
" |---o " << key.str();
362 xml_cur = xml_cur->next;
365 xmlFreeNode(xml_cur);
373 const string &
delim ) {
382 <<
"Adding Parameter Vector [" << pt <<
"]: Key = " 383 << pn <<
" -> Value = " << pv;
389 std::stringstream n_value ;
390 n_value << bits.size() ;
394 for (
unsigned int i = 0 ; i < bits.size() ; ++i ) {
408 string ptype,
string pname,
string pvalue)
414 <<
"Adding Parameter [" << ptype <<
"]: Key = " 415 << pname <<
" -> Value = " << pvalue;
417 bool isRootObjParam = (
strcmp(ptype.c_str(),
"h1f") == 0) ||
418 (
strcmp(ptype.c_str(),
"Th2f") == 0) ||
419 (
strcmp(ptype.c_str(),
"tree") == 0);
420 bool isBasicParam = (
strcmp(ptype.c_str(),
"int") == 0) ||
421 (
strcmp(ptype.c_str(),
"bool") == 0) ||
422 (
strcmp(ptype.c_str(),
"double") == 0) ||
423 (
strcmp(ptype.c_str(),
"string") == 0) ||
424 (
strcmp(ptype.c_str(),
"alg") == 0);
431 <<
"Parameter [" << ptype <<
"]: Key = " << pname
432 <<
" -> Value = " << pvalue <<
" could not be added";
438 Registry *
r,
string ptype,
string pname,
string pvalue)
442 if (ptype==
"double") {
443 RgDbl item = (double) atof(pvalue.c_str());
446 else if (ptype==
"int") {
447 RgInt item = (
int) atoi(pvalue.c_str());
450 else if (ptype==
"bool") {
451 if (pvalue==
"true" ) r->
Set(key,
true );
452 else if (pvalue==
"TRUE" ) r->
Set(key,
true );
453 else if (pvalue==
"1" ) r->
Set(key,
true );
454 else if (pvalue==
"false") r->
Set(key,
false);
455 else if (pvalue==
"FALSE") r->
Set(key,
false);
456 else if (pvalue==
"0" ) r->
Set(key,
false);
459 <<
"Could not set bool param: " <<
key;
462 else if (ptype==
"string") {
466 else if (ptype==
"alg") {
469 if (algv.size()==2) {
473 else if (algv.size()==1) {
478 <<
"Unrecognized algorithm id: " << pvalue;
481 RgAlg item(name,config);
486 <<
"Config. parameter: " << key
487 <<
"has unrecognized type: " << ptype;
492 Registry *
r,
string ptype,
string pname,
string pvalue)
498 if(rootobjv.size() != 2) {
500 <<
"ROOT objects are added in XML config files as: " 501 <<
"object-name@file-name. Wrong syntax in: [" << pvalue <<
"]";
503 <<
"Parameter [" << ptype <<
"]: Key = " << pname
504 <<
" -> Value = " << pvalue <<
" could not be added";
507 string rootobj = rootobjv[0];
508 string rootfile = rootobjv[1];
510 TFile
f(rootfile.c_str(),
"read");
513 TH1F *
h = (TH1F*)
f.Get(rootobj.c_str());
515 TH1F * ch =
new TH1F(*h);
520 <<
"No TH1F named = " << rootobj <<
" in ROOT file = " << rootfile;
522 }
else if (ptype==
"h2f") {
523 TH2F *
h2 = (TH2F*)
f.Get(rootobj.c_str());
525 TH2F * ch2 =
new TH2F(*h2);
526 ch2->SetDirectory(0);
530 <<
"No TH2F named = " << rootobj <<
" in ROOT file = " << rootfile;
532 }
else if (ptype==
"tree") {
533 TTree *
t = (TTree*)
f.Get(rootobj.c_str());
536 TTree * ct = t->CopyTree(
"1");
540 <<
"No TTree named = " << rootobj <<
" in ROOT file = " << rootfile;
560 AlgId id(alg_name,param_set);
561 string key =
id.Key();
567 LOG(
"AlgConfigPool",
pDEBUG) <<
"Searching for registry with key " <<
key;
572 return config_entry->second;
574 LOG(
"AlgConfigPool",
pDEBUG) <<
"No config registry for key " <<
key;
582 string glob_param_set = (gSystem->Getenv(
"GUSERPHYSOPT")) ?
583 string(gSystem->Getenv(
"GUSERPHYSOPT")) :
"Default";
585 key <<
"GlobalParameterList/" << glob_param_set;
594 key <<
"Common" << file_id <<
"List/" << set_name;
607 key <<
"TuneGeneratorList/Default";
619 string frame(100,
'~');
622 typedef map<string, Registry *>::size_type sregSize;
627 <<
endl <<
"Algorithm Configuration Pool (" 628 << size <<
" configuration sets found)" 634 stream << iter->first;
636 stream << frame <<
endl;
vector< string > fConfigKeyList
list of all available configuration keys
void DummyMethodAndSilentCompiler()
THE MAIN GENIE PROJECT NAMESPACE
bool LoadGlobalParamLists(void)
void Print(ostream &stream) const
string TrimSpaces(xmlChar *xmls)
A singleton class holding all configuration registries built while parsing all loaded XML configurati...
Algorithm abstract base class.
void AddConfigParameter(Registry *r, string pt, string pn, string pv)
bool LoadSingleAlgConfig(string alg_name, string file_name)
Registry * CommonList(const string &file_id, const string &set_name) const
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
void AddRootObjParameter(Registry *r, string pt, string pn, string pv)
static AlgConfigPool * fInstance
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Registry * TuneGeneratorList(void) const
string GetXMLFilePath(string basename)
void AddBasicParameter(Registry *r, string pt, string pn, string pv)
bool LoadTuneGeneratorList(void)
void Lock(void)
locks the registry
void SetName(string name)
set the registry name
const vector< string > & ConfigKeyList(void) const
Registry * GlobalParameterList(void) const
Q_EXPORT QTSManip setw(int w)
string TrimSpaces(string input)
Algorithm ID (algorithm name + configuration set name)
int AddParameterVector(Registry *r, string pt, string pn, string pv, const string &delim=";")
bool LoadRegistries(string key_base, string file_name, string root)
virtual const AlgId & Id(void) const
Get algorithm ID.
map< string, string > fConfigFiles
algorithm -> XML config file
vector< string > Split(string input, string delim)
static string BuildParamVectSizeKey(const std::string &comm_name)
bool LoadMasterConfig(void)
int strcmp(const String &s1, const String &s2)
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
A registry. Provides the container for algorithm configuration parameters.
map< string, Registry * > fRegistryPool
algorithm/param_set -> Registry
Registry * FindRegistry(string key) const
cet::registry_via_id< success_t, val > reg
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
void Set(RgIMapPair entry)
static string BuildParamVectKey(const std::string &comm_name, unsigned int i)
Q_EXPORT QTSManip setfill(int f)
bool LoadCommonLists(const string &file_id)
QTextStream & endl(QTextStream &s)
static AlgConfigPool * Instance()
string fMasterConfig
lists config files for all algorithms