33 #include "libxml/xmlmemory.h" 34 #include "libxml/parser.h" 52 using std::ostringstream;
54 using namespace genie;
60 config_pool.
Print(stream);
70 LOG(
"AlgConfigPool",
pERROR) <<
"Could not load XML config file";
85 map<string, Registry *>::iterator citer;
87 string key = citer->first;
116 <<
"AlgConfigPool late initialization: Loading all XML config. files";
127 SLOG(
"AlgConfigPool",
pWARN ) <<
"Tune generator List not available" ;
132 map<string, string>::const_iterator conf_file_iter;
135 conf_file_iter !=
fConfigFiles.end(); ++conf_file_iter) {
137 string alg_name = conf_file_iter->first;
138 string file_name = conf_file_iter->second;
141 << setfill(
'.') << setw(40) << alg_name <<
" -> " <<
file_name;
145 <<
"*** GENIE XML config file " << full_path;
149 <<
"Error in loading config sets for algorithm = " << alg_name;
163 bool is_accessible = ! (gSystem->AccessPathName(
fMasterConfig.c_str() ));
164 if (!is_accessible) {
166 <<
"The XML doc doesn't exist! (filename : " <<
fMasterConfig <<
")";
173 <<
"The XML doc can't be parsed! (filename : " <<
fMasterConfig <<
")";
177 xmlNodePtr xml_root = xmlDocGetRootElement(xml_doc);
180 <<
"The XML doc is empty! (filename : " <<
fMasterConfig <<
")";
185 if( xmlStrcmp(xml_root->name, (
const xmlChar *)
"genie_config") ) {
187 <<
"The XML doc has invalid root element! " 195 xmlNodePtr xml_ac = xml_root->xmlChildrenNode;
196 while (xml_ac != NULL) {
197 if( (!xmlStrcmp(xml_ac->name, (
const xmlChar *)
"config")) ) {
202 xmlNodeListGetString(xml_doc, xml_ac->xmlChildrenNode, 1));
204 pair<string, string> alg_conf(alg_name, config_file);
207 xml_ac = xml_ac->next;
219 SLOG(
"AlgConfigPool",
pINFO) <<
"Loading global parameter lists";
225 string key_prefix =
"GlobalParameterList";
228 return this->
LoadRegistries(key_prefix, glob_params,
"global_param_list");
235 SLOG(
"AlgConfigPool",
pINFO) <<
"Loading Common " << file_id <<
" lists";
238 std::string xml_name =
"Common" + file_id +
".xml" ;
242 string key_prefix =
"Common" + file_id +
"List";
245 if ( ! this->
LoadRegistries(key_prefix, full_path,
"common_"+file_id+
"_list") ) {
247 SLOG(
"AlgConfigPool",
pERROR) <<
"Failed to load Common " << file_id ;
258 SLOG(
"AlgConfigPool",
pINFO) <<
"Loading Tune Gerator List";
264 string key_prefix =
"TuneGeneratorList";
267 return this->
LoadRegistries(key_prefix, generator_list_file,
"tune_generator_list");
277 string key_prefix = alg_name;
288 SLOG(
"AlgConfigPool",
pDEBUG) <<
"[-] Loading registries:";
290 bool is_accessible = ! (gSystem->AccessPathName(file_name.c_str()));
291 if (!is_accessible) {
293 <<
"The XML doc doesn't exist! (filename : " << file_name <<
")";
297 xmlDocPtr xml_doc = xmlParseFile( file_name.c_str() );
300 <<
"The XML document can't be parsed! (filename : " << file_name <<
")";
304 xmlNodePtr xml_cur = xmlDocGetRootElement( xml_doc );
307 <<
"The XML document is empty! (filename : " << file_name <<
")";
311 if( xmlStrcmp(xml_cur->name, (
const xmlChar *) root.c_str()) ) {
313 <<
"The XML document has invalid root element! " 314 <<
"(filename : " << file_name <<
")";
315 xmlFreeNode(xml_cur);
321 xml_cur = xml_cur->xmlChildrenNode;
322 while (xml_cur != NULL) {
324 if( (!xmlStrcmp(xml_cur->name, (
const xmlChar *)
"param_set")) ) {
331 key << key_prefix <<
"/" << param_set;
339 xmlNodePtr xml_param = xml_cur->xmlChildrenNode;
340 while (xml_param != NULL) {
341 if( (!xmlStrcmp(xml_param->name, (
const xmlChar *)
"param")) ) {
351 xmlNodeListGetString(
352 xml_doc, xml_param->xmlChildrenNode, 1));
354 config, param_type, param_name, param_value);
356 xml_param = xml_param->next;
359 xmlFreeNode(xml_param);
363 pair<string, Registry *> single_reg(key.str(),
config);
366 SLOG(
"AlgConfigPool",
pDEBUG) <<
" |---o " << key.str();
368 xml_cur = xml_cur->next;
371 xmlFreeNode(xml_cur);
385 <<
"Adding Parameter [" << ptype <<
"]: Key = " 386 << pname <<
" -> Value = " << pvalue;
388 bool isRootObjParam = (strcmp(ptype.c_str(),
"h1f") == 0) ||
389 (strcmp(ptype.c_str(),
"Th2f") == 0) ||
390 (strcmp(ptype.c_str(),
"tree") == 0);
391 bool isBasicParam = (strcmp(ptype.c_str(),
"int") == 0) ||
392 (strcmp(ptype.c_str(),
"bool") == 0) ||
393 (strcmp(ptype.c_str(),
"double") == 0) ||
394 (strcmp(ptype.c_str(),
"string") == 0) ||
395 (strcmp(ptype.c_str(),
"alg") == 0);
401 <<
"Parameter [" << ptype <<
"]: Key = " << pname
402 <<
" -> Value = " << pvalue <<
" could not be added";
411 if (ptype==
"double") {
412 RgDbl item = (double) atof(pvalue.c_str());
415 else if (ptype==
"int") {
416 RgInt item = (
int) atoi(pvalue.c_str());
419 else if (ptype==
"bool") {
420 if (pvalue==
"true" ) r->
Set(key,
true );
421 else if (pvalue==
"TRUE" ) r->
Set(key,
true );
422 else if (pvalue==
"1" ) r->
Set(key,
true );
423 else if (pvalue==
"false") r->
Set(key,
false);
424 else if (pvalue==
"FALSE") r->
Set(key,
false);
425 else if (pvalue==
"0" ) r->
Set(key,
false);
428 <<
"Could not set bool param: " <<
key;
431 else if (ptype==
"string") {
435 else if (ptype==
"alg") {
438 if (algv.size()==2) {
442 else if (algv.size()==1) {
447 <<
"Unrecognized algorithm id: " << pvalue;
450 RgAlg item(name,config);
455 <<
"Config. parameter: " << key
456 <<
"has unrecognized type: " << ptype;
467 if(rootobjv.size() != 2) {
469 <<
"ROOT objects are added in XML config files as: " 470 <<
"object-name@file-name. Wrong syntax in: [" << pvalue <<
"]";
472 <<
"Parameter [" << ptype <<
"]: Key = " << pname
473 <<
" -> Value = " << pvalue <<
" could not be added";
476 string rootobj = rootobjv[0];
479 TFile
f(rootfile.c_str(),
"read");
482 TH1F *
h = (TH1F*)
f.Get(rootobj.c_str());
484 TH1F * ch =
new TH1F(*h);
489 <<
"No TH1F named = " << rootobj <<
" in ROOT file = " <<
rootfile;
491 }
else if (ptype==
"h2f") {
492 TH2F *
h2 = (TH2F*)
f.Get(rootobj.c_str());
494 TH2F * ch2 =
new TH2F(*h2);
495 ch2->SetDirectory(0);
499 <<
"No TH2F named = " << rootobj <<
" in ROOT file = " <<
rootfile;
501 }
else if (ptype==
"tree") {
502 TTree *
t = (TTree*)
f.Get(rootobj.c_str());
505 TTree * ct = t->CopyTree(
"1");
509 <<
"No TTree named = " << rootobj <<
" in ROOT file = " <<
rootfile;
530 string key =
id.Key();
536 LOG(
"AlgConfigPool",
pDEBUG) <<
"Searching for registry with key " <<
key;
539 map<string, Registry *>::const_iterator config_entry =
541 return config_entry->second;
543 LOG(
"AlgConfigPool",
pDEBUG) <<
"No config registry for key " <<
key;
551 string glob_param_set = (gSystem->Getenv(
"GUSERPHYSOPT")) ?
552 string(gSystem->Getenv(
"GUSERPHYSOPT")) :
"Default";
554 key <<
"GlobalParameterList/" << glob_param_set;
563 key <<
"Common" << file_id <<
"List/" << set_name;
576 key <<
"TuneGeneratorList/Default";
588 string frame(100,
'~');
590 typedef map<string, Registry *>::const_iterator sregIter;
596 <<
endl <<
"Algorithm Configuration Pool (" 597 << size <<
" configuration sets found)" 602 const Registry & reg = *(iter->second);
603 stream << iter->first;
605 stream << frame <<
endl;
::xsd::cxx::tree::id< char, ncname > id
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
void AddRootObjParameter(Registry *r, string pt, string pn, string pv)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
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
root
Link up the nodes tree #####.
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
string TrimSpaces(string input)
Algorithm ID (algorithm name + configuration set name)
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)
bool LoadMasterConfig(void)
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
#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)
bool LoadCommonLists(const string &file_id)
static AlgConfigPool * Instance()
string fMasterConfig
lists config files for all algorithms