Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
genie::AlgConfigPool Class Reference

A singleton class holding all configuration registries built while parsing all loaded XML configuration files. More...

#include <AlgConfigPool.h>

Classes

struct  Cleaner
 

Public Member Functions

RegistryFindRegistry (string key) const
 
RegistryFindRegistry (string alg_name, string param_set) const
 
RegistryFindRegistry (const Algorithm *algorithm) const
 
RegistryFindRegistry (const AlgId &algid) const
 
RegistryGlobalParameterList (void) const
 
RegistryCommonList (const string &file_id, const string &set_name) const
 
RegistryTuneGeneratorList (void) const
 
const vector< string > & ConfigKeyList (void) const
 
void Print (ostream &stream) const
 

Static Public Member Functions

static AlgConfigPoolInstance ()
 

Private Member Functions

 AlgConfigPool ()
 
 AlgConfigPool (const AlgConfigPool &config_pool)
 
virtual ~AlgConfigPool ()
 
string BuildConfigKey (string alg_name, string param_set) const
 
string BuildConfigKey (const Algorithm *algorithm) const
 
bool LoadAlgConfig (void)
 
bool LoadMasterConfig (void)
 
bool LoadGlobalParamLists (void)
 
bool LoadCommonLists (const string &file_id)
 
bool LoadTuneGeneratorList (void)
 
bool LoadSingleAlgConfig (string alg_name, string file_name)
 
bool LoadRegistries (string key_base, string file_name, string root)
 
int AddParameterVector (Registry *r, string pt, string pn, string pv, const string &delim=";")
 
void AddConfigParameter (Registry *r, string pt, string pn, string pv)
 
void AddBasicParameter (Registry *r, string pt, string pn, string pv)
 
void AddRootObjParameter (Registry *r, string pt, string pn, string pv)
 

Private Attributes

map< string, Registry * > fRegistryPool
 algorithm/param_set -> Registry More...
 
map< string, stringfConfigFiles
 algorithm -> XML config file More...
 
vector< stringfConfigKeyList
 list of all available configuration keys More...
 
string fMasterConfig
 lists config files for all algorithms More...
 

Static Private Attributes

static AlgConfigPoolfInstance = 0
 

Friends

struct Cleaner
 
ostream & operator<< (ostream &stream, const AlgConfigPool &cp)
 

Detailed Description

A singleton class holding all configuration registries built while parsing all loaded XML configuration files.

Author
Costas Andreopoulos <constantinos.andreopoulos cern.ch> University of Liverpool & STFC Rutherford Appleton Laboratory

May 06, 2004

Copyright (c) 2003-2020, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 40 of file AlgConfigPool.h.

Constructor & Destructor Documentation

AlgConfigPool::AlgConfigPool ( )
private

Definition at line 50 of file AlgConfigPool.cxx.

51 {
52  if( ! this->LoadAlgConfig() )
53  LOG("AlgConfigPool", pERROR) << "Could not load XML config file";
54  fInstance = 0;
55 }
#define pERROR
Definition: Messenger.h:59
static AlgConfigPool * fInstance
Definition: AlgConfigPool.h:81
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
genie::AlgConfigPool::AlgConfigPool ( const AlgConfigPool config_pool)
private
AlgConfigPool::~AlgConfigPool ( )
privatevirtual

Definition at line 57 of file AlgConfigPool.cxx.

58 {
59 // Clean up and report the most important physics params used in this instance.
60 // Don't clutter output if exiting in err.
61 
62  if(!gAbortingInErr) {
63 /*
64  cout << "AlgConfigPool singleton dtor: "
65  << "Deleting all owned algorithm configurations" << endl;
66 */
67  }
69  for(citer = fRegistryPool.begin(); citer != fRegistryPool.end(); ++citer) {
70  string key = citer->first;
71  Registry * config = citer->second;
72  if(config) {
73  delete config;
74  config = 0;
75  }
76  }
77  fRegistryPool.clear();
78  fConfigFiles.clear();
79  fConfigKeyList.clear();
80  fInstance = 0;
81 }
intermediate_table::iterator iterator
vector< string > fConfigKeyList
list of all available configuration keys
Definition: AlgConfigPool.h:85
static AlgConfigPool * fInstance
Definition: AlgConfigPool.h:81
def key(type, name=None)
Definition: graph.py:13
static Config * config
Definition: config.cpp:1054
map< string, string > fConfigFiles
algorithm -> XML config file
Definition: AlgConfigPool.h:84
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
map< string, Registry * > fRegistryPool
algorithm/param_set -> Registry
Definition: AlgConfigPool.h:83
bool gAbortingInErr
Definition: Messenger.cxx:34

Member Function Documentation

void AlgConfigPool::AddBasicParameter ( Registry r,
string  pt,
string  pn,
string  pv 
)
private

Definition at line 437 of file AlgConfigPool.cxx.

439 {
440  RgKey key = pname;
441 
442  if (ptype=="double") {
443  RgDbl item = (double) atof(pvalue.c_str());
444  r->Set(key, item);
445  }
446  else if (ptype=="int") {
447  RgInt item = (int) atoi(pvalue.c_str());
448  r->Set(key, item);
449  }
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);
457  else {
458  LOG("AlgConfigPool", pERROR)
459  << "Could not set bool param: " << key;
460  }
461  }
462  else if (ptype=="string") {
463  RgStr item = pvalue;
464  r->Set(key, item);
465  }
466  else if (ptype=="alg") {
467  string name, config;
468  vector<string> algv = utils::str::Split(pvalue, "/");
469  if (algv.size()==2) {
470  name = algv[0];
471  config = algv[1];
472  }
473  else if (algv.size()==1) {
474  name = algv[0];
475  config = "Default";
476  } else {
477  LOG("AlgConfigPool", pFATAL)
478  << "Unrecognized algorithm id: " << pvalue;
479  exit(1);
480  }
481  RgAlg item(name,config);
482  r->Set(key, item);
483  }
484  else {
485  LOG("AlgConfigPool", pERROR)
486  << "Config. parameter: " << key
487  << "has unrecognized type: " << ptype;
488  }
489 }
static QCString name
Definition: declinfo.cpp:673
#define pERROR
Definition: Messenger.h:59
#define pFATAL
Definition: Messenger.h:56
int RgInt
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
def key(type, name=None)
Definition: graph.py:13
static Config * config
Definition: config.cpp:1054
string RgStr
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
string RgKey
double RgDbl
void Set(RgIMapPair entry)
Definition: Registry.cxx:267
void AlgConfigPool::AddConfigParameter ( Registry r,
string  pt,
string  pn,
string  pv 
)
private

Definition at line 407 of file AlgConfigPool.cxx.

409 {
410 // Adds a configuration parameter with type = ptype, key = pname and value =
411 // pvalue at the input configuration registry r
412 
413  SLOG("AlgConfigPool", pDEBUG)
414  << "Adding Parameter [" << ptype << "]: Key = "
415  << pname << " -> Value = " << pvalue;
416 
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);
425 
426 
427  if (isBasicParam) this->AddBasicParameter (r, ptype, pname, pvalue);
428  else if(isRootObjParam) this->AddRootObjParameter(r, ptype, pname, pvalue);
429  else {
430  SLOG("AlgConfigPool", pERROR)
431  << "Parameter [" << ptype << "]: Key = " << pname
432  << " -> Value = " << pvalue << " could not be added";
433  }
434 
435 }
#define pERROR
Definition: Messenger.h:59
void AddRootObjParameter(Registry *r, string pt, string pn, string pv)
void AddBasicParameter(Registry *r, string pt, string pn, string pv)
int strcmp(const String &s1, const String &s2)
Definition: relates.cpp:14
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
#define pDEBUG
Definition: Messenger.h:63
int AlgConfigPool::AddParameterVector ( Registry r,
string  pt,
string  pn,
string  pv,
const string delim = ";" 
)
private

Definition at line 372 of file AlgConfigPool.cxx.

373  {
374 
375  // Adds a configuration parameter vector
376  // It is simply add a number of entries in the Registy
377  // The name scheme starts from the name and it goes like
378  // 'N'+pn+'s' that will be an integer with the number of entries.
379  // Each entry will be named pn+"-i" where i is replaced by the number
380 
381  SLOG("AlgConfigPool", pDEBUG)
382  << "Adding Parameter Vector [" << pt << "]: Key = "
383  << pn << " -> Value = " << pv;
384 
385  vector<string> bits = utils::str::Split( pv, delim ) ;
386 
387  string n_name = Algorithm::BuildParamVectSizeKey( pn ) ;
388 
389  std::stringstream n_value ;
390  n_value << bits.size() ;
391 
392  this->AddConfigParameter(r, "int", n_name, n_value.str() );
393 
394  for ( unsigned int i = 0 ; i < bits.size() ; ++i ) {
395 
397 
398  this -> AddConfigParameter( r, pt, name, utils::str::TrimSpaces( bits[i] ) );
399 
400  }
401 
402  return bits.size() ;
403 
404 }
static QCString name
Definition: declinfo.cpp:673
string delim()
Definition: fcldump.cxx:40
std::string string
Definition: nybbler.cc:12
void AddConfigParameter(Registry *r, string pt, string pn, string pv)
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
static string BuildParamVectSizeKey(const std::string &comm_name)
Definition: Algorithm.cxx:520
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
static string BuildParamVectKey(const std::string &comm_name, unsigned int i)
Definition: Algorithm.cxx:510
#define pDEBUG
Definition: Messenger.h:63
void AlgConfigPool::AddRootObjParameter ( Registry r,
string  pt,
string  pn,
string  pv 
)
private

Definition at line 491 of file AlgConfigPool.cxx.

493 {
494  // the ROOT object is given in the XML config file as
495  // <param> object_name@root_file_name </param>
496  vector<string> rootobjv = utils::str::Split(pvalue, "@");
497 
498  if(rootobjv.size() != 2) {
499  SLOG("AlgConfigPool", pWARN)
500  << "ROOT objects are added in XML config files as: "
501  << "object-name@file-name. Wrong syntax in: [" << pvalue << "]";
502  SLOG("AlgConfigPool", pERROR)
503  << "Parameter [" << ptype << "]: Key = " << pname
504  << " -> Value = " << pvalue << " could not be added";
505  }
506 
507  string rootobj = rootobjv[0];
508  string rootfile = rootobjv[1];
509 
510  TFile f(rootfile.c_str(), "read");
511 
512  if (ptype=="h1f") {
513  TH1F * h = (TH1F*) f.Get(rootobj.c_str());
514  if(h) {
515  TH1F * ch = new TH1F(*h); // clone
516  ch->SetDirectory(0);
517  r->Set(pname,ch);
518  } else {
519  SLOG("AlgConfigPool", pERROR)
520  << "No TH1F named = " << rootobj << " in ROOT file = " << rootfile;
521  }
522  } else if (ptype=="h2f") {
523  TH2F * h2 = (TH2F*) f.Get(rootobj.c_str());
524  if(h2) {
525  TH2F * ch2 = new TH2F(*h2); // clone
526  ch2->SetDirectory(0);
527  r->Set(pname,ch2);
528  } else {
529  SLOG("AlgConfigPool", pERROR)
530  << "No TH2F named = " << rootobj << " in ROOT file = " << rootfile;
531  }
532  } else if (ptype=="tree") {
533  TTree * t = (TTree*) f.Get(rootobj.c_str());
534  if(t) {
535  //TTree * ct = new TTree(*t); // clone
536  TTree * ct = t->CopyTree("1");
537  r->Set(pname,ct);
538  } else {
539  SLOG("AlgConfigPool", pERROR)
540  << "No TTree named = " << rootobj << " in ROOT file = " << rootfile;
541  }
542  }
543  else {}
544 }
#define pERROR
Definition: Messenger.h:59
#define pWARN
Definition: Messenger.h:60
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
void Set(RgIMapPair entry)
Definition: Registry.cxx:267
string genie::AlgConfigPool::BuildConfigKey ( string  alg_name,
string  param_set 
) const
private
string genie::AlgConfigPool::BuildConfigKey ( const Algorithm algorithm) const
private
Registry * AlgConfigPool::CommonList ( const string file_id,
const string set_name 
) const

Definition at line 590 of file AlgConfigPool.cxx.

591 {
592 
593  ostringstream key;
594  key << "Common" << file_id << "List/" << set_name;
595 
596  if ( ! this->FindRegistry(key.str()) ) {
597  const_cast<AlgConfigPool*>( this ) -> LoadCommonLists( file_id ) ;
598  }
599 
600  return this->FindRegistry(key.str()) ;
601 }
A singleton class holding all configuration registries built while parsing all loaded XML configurati...
Definition: AlgConfigPool.h:40
def key(type, name=None)
Definition: graph.py:13
Registry * FindRegistry(string key) const
bool LoadCommonLists(const string &file_id)
const vector< string > & AlgConfigPool::ConfigKeyList ( void  ) const

Definition at line 612 of file AlgConfigPool.cxx.

613 {
614  return fConfigKeyList;
615 }
vector< string > fConfigKeyList
list of all available configuration keys
Definition: AlgConfigPool.h:85
Registry * AlgConfigPool::FindRegistry ( string  key) const

Definition at line 565 of file AlgConfigPool.cxx.

566 {
567  LOG("AlgConfigPool", pDEBUG) << "Searching for registry with key " << key;
568 
569  if( fRegistryPool.count(key) == 1 ) {
571  fRegistryPool.find(key);
572  return config_entry->second;
573  } else {
574  LOG("AlgConfigPool", pDEBUG) << "No config registry for key " << key;
575  return 0;
576  }
577  return 0;
578 }
intermediate_table::const_iterator const_iterator
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
def key(type, name=None)
Definition: graph.py:13
map< string, Registry * > fRegistryPool
algorithm/param_set -> Registry
Definition: AlgConfigPool.h:83
#define pDEBUG
Definition: Messenger.h:63
Registry * AlgConfigPool::FindRegistry ( string  alg_name,
string  param_set 
) const

Definition at line 558 of file AlgConfigPool.cxx.

559 {
560  AlgId id(alg_name,param_set);
561  string key = id.Key();
562  return this->FindRegistry(key);
563 }
def key(type, name=None)
Definition: graph.py:13
Algorithm ID (algorithm name + configuration set name)
Definition: AlgId.h:34
Registry * FindRegistry(string key) const
Registry * AlgConfigPool::FindRegistry ( const Algorithm algorithm) const

Definition at line 546 of file AlgConfigPool.cxx.

547 {
548  string key = algorithm->Id().Key();
549  return this->FindRegistry(key);
550 }
def key(type, name=None)
Definition: graph.py:13
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:97
Registry * FindRegistry(string key) const
string Key(void) const
Definition: AlgId.h:46
Registry * AlgConfigPool::FindRegistry ( const AlgId algid) const

Definition at line 552 of file AlgConfigPool.cxx.

553 {
554  string key = algid.Key();
555  return this->FindRegistry(key);
556 }
def key(type, name=None)
Definition: graph.py:13
Registry * FindRegistry(string key) const
string Key(void) const
Definition: AlgId.h:46
Registry * AlgConfigPool::GlobalParameterList ( void  ) const

Definition at line 580 of file AlgConfigPool.cxx.

581 {
582  string glob_param_set = (gSystem->Getenv("GUSERPHYSOPT")) ?
583  string(gSystem->Getenv("GUSERPHYSOPT")) : "Default";
584  ostringstream key;
585  key << "GlobalParameterList/" << glob_param_set;
586 
587  return this->FindRegistry(key.str());
588 }
def key(type, name=None)
Definition: graph.py:13
Registry * FindRegistry(string key) const
AlgConfigPool * AlgConfigPool::Instance ( )
static

Definition at line 83 of file AlgConfigPool.cxx.

84 {
85  if(fInstance == 0) {
86  static AlgConfigPool::Cleaner cleaner;
89  }
90  return fInstance;
91 }
static AlgConfigPool * fInstance
Definition: AlgConfigPool.h:81
bool AlgConfigPool::LoadAlgConfig ( void  )
private

Definition at line 93 of file AlgConfigPool.cxx.

94 {
95 // Loads all algorithm XML configurations and creates a map with all loaded
96 // configuration registries
97 
98  SLOG("AlgConfigPool", pINFO)
99  << "AlgConfigPool late initialization: Loading all XML config. files";
100 
101  //-- read the global parameter lists
102  if(!this->LoadGlobalParamLists()) return false;
103 
104  //-- read the MASTER_CONFIG XML file
105  if(!this->LoadMasterConfig()) return false;
106 
107  //-- read Tune Generator List for the tune, if available
108  if( ! LoadTuneGeneratorList() ) {
109 
110  SLOG( "AlgConfigPool", pWARN ) << "Tune generator List not available" ;
111  }
112 
113  //-- loop over all XML config files and read all named configuration
114  // sets for each algorithm
116 
117  for(conf_file_iter = fConfigFiles.begin();
118  conf_file_iter != fConfigFiles.end(); ++conf_file_iter) {
119 
120  string alg_name = conf_file_iter->first;
121  string file_name = conf_file_iter->second;
122 
123  SLOG("AlgConfigPool", pINFO)
124  << setfill('.') << setw(40) << alg_name << " -> " << file_name;
125 
126  string full_path = utils::xml::GetXMLFilePath(file_name);
127  SLOG("AlgConfigPool", pNOTICE)
128  << "*** GENIE XML config file " << full_path;
129  bool ok = this->LoadSingleAlgConfig(alg_name, full_path);
130  if(!ok) {
131  SLOG("AlgConfigPool", pERROR)
132  << "Error in loading config sets for algorithm = " << alg_name;
133  }
134  }
135  return true;
136 };
#define pERROR
Definition: Messenger.h:59
bool LoadGlobalParamLists(void)
intermediate_table::const_iterator const_iterator
bool LoadSingleAlgConfig(string alg_name, string file_name)
QCString file_name
string GetXMLFilePath(string basename)
bool LoadTuneGeneratorList(void)
#define pINFO
Definition: Messenger.h:62
#define pWARN
Definition: Messenger.h:60
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
map< string, string > fConfigFiles
algorithm -> XML config file
Definition: AlgConfigPool.h:84
#define pNOTICE
Definition: Messenger.h:61
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
bool AlgConfigPool::LoadCommonLists ( const string file_id)
private

Definition at line 214 of file AlgConfigPool.cxx.

215 {
216 // Load the common parameter list
217 //
218  SLOG("AlgConfigPool", pINFO) << "Loading Common " << file_id << " lists";
219 
220  // -- get the user config XML file using GXMLPATH + default locations
221  std::string xml_name = "Common" + file_id + ".xml" ;
222  string full_path = utils::xml::GetXMLFilePath( xml_name );
223 
224  // fixed key prefix
225  string key_prefix = "Common" + file_id + "List";
226 
227  // load and report status
228  if ( ! this->LoadRegistries(key_prefix, full_path, "common_"+file_id+"_list") ) {
229 
230  SLOG("AlgConfigPool", pERROR) << "Failed to load Common " << file_id ;
231  return false ;
232  }
233 
234  return true ;
235 }
#define pERROR
Definition: Messenger.h:59
std::string string
Definition: nybbler.cc:12
string GetXMLFilePath(string basename)
#define pINFO
Definition: Messenger.h:62
bool LoadRegistries(string key_base, string file_name, string root)
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
bool AlgConfigPool::LoadGlobalParamLists ( void  )
private

Definition at line 197 of file AlgConfigPool.cxx.

198 {
199 // Load the global parameter list (a list of physics constants at a given MC
200 // job, that is allowed to be modified to fine tune the generator output)
201 //
202  SLOG("AlgConfigPool", pINFO) << "Loading global parameter lists";
203 
204  // -- get the user config XML file using GXMLPATH + default locations
205  string glob_params = utils::xml::GetXMLFilePath("ModelConfiguration.xml");
206 
207  // fixed key prefix
208  string key_prefix = "GlobalParameterList";
209 
210  // load and report status
211  return this->LoadRegistries(key_prefix, glob_params, "global_param_list");
212 }
string GetXMLFilePath(string basename)
#define pINFO
Definition: Messenger.h:62
bool LoadRegistries(string key_base, string file_name, string root)
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
bool AlgConfigPool::LoadMasterConfig ( void  )
private

Definition at line 138 of file AlgConfigPool.cxx.

139 {
140 // Loads the master config XML file: the file that specifies which XML config
141 // file to load for each algorithm
142 
143  //-- get the master config XML file using GXMLPATH + default locations
144  fMasterConfig = utils::xml::GetXMLFilePath("master_config.xml");
145 
146  bool is_accessible = ! (gSystem->AccessPathName( fMasterConfig.c_str() ));
147  if (!is_accessible) {
148  SLOG("AlgConfigPool", pERROR)
149  << "The XML doc doesn't exist! (filename : " << fMasterConfig << ")";
150  return false;
151  }
152 
153  xmlDocPtr xml_doc = xmlParseFile(fMasterConfig.c_str());
154  if(xml_doc==NULL) {
155  SLOG("AlgConfigPool", pERROR)
156  << "The XML doc can't be parsed! (filename : " << fMasterConfig << ")";
157  return false;
158  }
159 
160  xmlNodePtr xml_root = xmlDocGetRootElement(xml_doc);
161  if(xml_root==NULL) {
162  SLOG("AlgConfigPool", pERROR)
163  << "The XML doc is empty! (filename : " << fMasterConfig << ")";
164  xmlFreeDoc(xml_doc);
165  return false;
166  }
167 
168  if( xmlStrcmp(xml_root->name, (const xmlChar *) "genie_config") ) {
169  SLOG("AlgConfigPool", pERROR)
170  << "The XML doc has invalid root element! "
171  << "(filename : " << fMasterConfig << ")";
172  xmlFreeDoc(xml_doc);
173  return false;
174  }
175 
176  // loop over all xml tree nodes (<alg_config>) that are children of the
177  // root node and read the config file name for each registered algorithm
178  xmlNodePtr xml_ac = xml_root->xmlChildrenNode;
179  while (xml_ac != NULL) {
180  if( (!xmlStrcmp(xml_ac->name, (const xmlChar *) "config")) ) {
181 
182  string alg_name = utils::str::TrimSpaces(
183  utils::xml::GetAttribute(xml_ac, "alg"));
184  string config_file = utils::xml::TrimSpaces(
185  xmlNodeListGetString(xml_doc, xml_ac->xmlChildrenNode, 1));
186 
187  pair<string, string> alg_conf(alg_name, config_file);
188  fConfigFiles.insert(alg_conf);
189  }
190  xml_ac = xml_ac->next;
191  }
192  xmlFreeNode(xml_ac);
193  xmlFreeDoc(xml_doc);
194  return true;
195 }
#define pERROR
Definition: Messenger.h:59
string TrimSpaces(xmlChar *xmls)
string GetXMLFilePath(string basename)
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
map< string, string > fConfigFiles
algorithm -> XML config file
Definition: AlgConfigPool.h:84
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
string fMasterConfig
lists config files for all algorithms
Definition: AlgConfigPool.h:86
bool AlgConfigPool::LoadRegistries ( string  key_base,
string  file_name,
string  root 
)
private

Definition at line 266 of file AlgConfigPool.cxx.

268 {
269 // Loads all the configuration registries from the input XML file
270 
271  SLOG("AlgConfigPool", pDEBUG) << "[-] Loading registries:";
272 
273  bool is_accessible = ! (gSystem->AccessPathName(file_name.c_str()));
274  if (!is_accessible) {
275  SLOG("AlgConfigPool", pERROR)
276  << "The XML doc doesn't exist! (filename : " << file_name << ")";
277  return false;
278  }
279 
280  xmlDocPtr xml_doc = xmlParseFile( file_name.c_str() );
281  if(xml_doc==NULL) {
282  SLOG("AlgConfigPool", pERROR)
283  << "The XML document can't be parsed! (filename : " << file_name << ")";
284  return false;
285  }
286 
287  xmlNodePtr xml_cur = xmlDocGetRootElement( xml_doc );
288  if(xml_cur==NULL) {
289  SLOG("AlgConfigPool", pERROR)
290  << "The XML document is empty! (filename : " << file_name << ")";
291  xmlFreeDoc(xml_doc);
292  return false;
293  }
294  if( xmlStrcmp(xml_cur->name, (const xmlChar *) root.c_str()) ) {
295  SLOG("AlgConfigPool", pERROR)
296  << "The XML document has invalid root element! "
297  << "(filename : " << file_name << ")";
298  xmlFreeNode(xml_cur);
299  xmlFreeDoc(xml_doc);
300  return false;
301  }
302 
303  // loop over all xml tree nodes that are children of the root node
304  xml_cur = xml_cur->xmlChildrenNode;
305  while (xml_cur != NULL) {
306  // enter everytime you find an 'param_set' tag
307  if( (!xmlStrcmp(xml_cur->name, (const xmlChar *) "param_set")) ) {
308 
309  string param_set = utils::str::TrimSpaces(
310  utils::xml::GetAttribute(xml_cur, "name"));
311 
312  // build the registry key
313  ostringstream key;
314  key << key_prefix << "/" << param_set;
315 
316  // store the key in the key list
317  fConfigKeyList.push_back(key.str());
318 
319  // create a new Registry and fill it with the configuration params
320  Registry * config = new Registry(param_set,false);
321 
322  xmlNodePtr xml_param = xml_cur->xmlChildrenNode;
323  while (xml_param != NULL) {
324  if( (!xmlStrcmp(xml_param->name, (const xmlChar *) "param")) ) {
325 
326  string param_type =
328  utils::xml::GetAttribute(xml_param, "type"));
329  string param_name =
331  utils::xml::GetAttribute(xml_param, "name"));
332  string param_value =
334  xmlNodeListGetString(
335  xml_doc, xml_param->xmlChildrenNode, 1));
336 
337 
338  if ( param_type.find( "vec-" ) == 0 ) {
339 
340  param_type = param_type.substr( 4 ) ;
341 
342  string delim = utils::str::TrimSpaces( utils::xml::GetAttribute(xml_param, "delim"));
343 
344  this -> AddParameterVector( config, param_type, param_name, param_value, delim ) ;
345  }
346  else this->AddConfigParameter( config,
347  param_type, param_name,
348  param_value);
349  }
350  xml_param = xml_param->next;
351  }
352  //xmlFree(xml_param);
353  xmlFreeNode(xml_param);
354  config->SetName(param_set);
355  config->Lock();
356 
357  pair<string, Registry *> single_reg(key.str(), config);
358  fRegistryPool.insert(single_reg);
359 
360  SLOG("AlgConfigPool", pDEBUG) << " |---o " << key.str();
361  }
362  xml_cur = xml_cur->next;
363  }
364  //xmlFree(xml_cur);
365  xmlFreeNode(xml_cur);
366  //xmlFree(xml_doc);
367  xmlFreeDoc(xml_doc);
368 
369  return true;
370 }
vector< string > fConfigKeyList
list of all available configuration keys
Definition: AlgConfigPool.h:85
string delim()
Definition: fcldump.cxx:40
#define pERROR
Definition: Messenger.h:59
string TrimSpaces(xmlChar *xmls)
void AddConfigParameter(Registry *r, string pt, string pn, string pv)
QCString file_name
def key(type, name=None)
Definition: graph.py:13
static Config * config
Definition: config.cpp:1054
void Lock(void)
locks the registry
Definition: Registry.cxx:148
void SetName(string name)
set the registry name
Definition: Registry.cxx:588
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
int AddParameterVector(Registry *r, string pt, string pn, string pv, const string &delim=";")
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
map< string, Registry * > fRegistryPool
algorithm/param_set -> Registry
Definition: AlgConfigPool.h:83
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
#define pDEBUG
Definition: Messenger.h:63
bool AlgConfigPool::LoadSingleAlgConfig ( string  alg_name,
string  file_name 
)
private

Definition at line 254 of file AlgConfigPool.cxx.

255 {
256 // Loads all configuration sets for the input algorithm that can be found in
257 // the input XML file
258 
259  // use the algorithm name as the key prefix
260  string key_prefix = alg_name;
261 
262  // load and report status
263  return this->LoadRegistries(key_prefix, file_name, "alg_conf");
264 }
QCString file_name
bool LoadRegistries(string key_base, string file_name, string root)
bool AlgConfigPool::LoadTuneGeneratorList ( void  )
private

Definition at line 237 of file AlgConfigPool.cxx.

238 {
239 // Load the common parameter list
240 //
241  SLOG("AlgConfigPool", pINFO) << "Loading Tune Gerator List";
242 
243  // -- get the user config XML file using GXMLPATH + default locations
244  string generator_list_file = utils::xml::GetXMLFilePath("TuneGeneratorList.xml");
245 
246  // fixed key prefix
247  string key_prefix = "TuneGeneratorList";
248 
249  // load and report status
250  return this->LoadRegistries(key_prefix, generator_list_file, "tune_generator_list");
251 }
string GetXMLFilePath(string basename)
#define pINFO
Definition: Messenger.h:62
bool LoadRegistries(string key_base, string file_name, string root)
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
void AlgConfigPool::Print ( ostream &  stream) const

Definition at line 617 of file AlgConfigPool.cxx.

618 {
619  string frame(100,'~');
620 
622  typedef map<string, Registry *>::size_type sregSize;
623 
624  sregSize size = fRegistryPool.size();
625 
626  stream << frame
627  << endl << "Algorithm Configuration Pool ("
628  << size << " configuration sets found)"
629  << endl << frame << endl;
630 
631  sregIter iter = fRegistryPool.begin();
632  for( ; iter != fRegistryPool.end(); iter++) {
633  const Registry & reg = *(iter->second);
634  stream << iter->first;
635  stream << reg;
636  stream << frame << endl;
637  }
638 }
intermediate_table::const_iterator const_iterator
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
map< string, Registry * > fRegistryPool
algorithm/param_set -> Registry
Definition: AlgConfigPool.h:83
cet::registry_via_id< success_t, val > reg
QTextStream & endl(QTextStream &s)
Registry * AlgConfigPool::TuneGeneratorList ( void  ) const

Definition at line 603 of file AlgConfigPool.cxx.

604 {
605 
606  ostringstream key;
607  key << "TuneGeneratorList/Default";
608 
609  return this->FindRegistry(key.str());
610 }
def key(type, name=None)
Definition: graph.py:13
Registry * FindRegistry(string key) const

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 97 of file AlgConfigPool.h.

ostream& operator<< ( ostream &  stream,
const AlgConfigPool cp 
)
friend

Definition at line 41 of file AlgConfigPool.cxx.

42  {
43  config_pool.Print(stream);
44  return stream;
45  }

Member Data Documentation

map<string, string> genie::AlgConfigPool::fConfigFiles
private

algorithm -> XML config file

Definition at line 84 of file AlgConfigPool.h.

vector<string> genie::AlgConfigPool::fConfigKeyList
private

list of all available configuration keys

Definition at line 85 of file AlgConfigPool.h.

AlgConfigPool * AlgConfigPool::fInstance = 0
staticprivate

Definition at line 81 of file AlgConfigPool.h.

string genie::AlgConfigPool::fMasterConfig
private

lists config files for all algorithms

Definition at line 86 of file AlgConfigPool.h.

map<string, Registry *> genie::AlgConfigPool::fRegistryPool
private

algorithm/param_set -> Registry

Definition at line 83 of file AlgConfigPool.h.


The documentation for this class was generated from the following files: