GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AlgConfigPool.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <c.andreopoulos \at cern.ch>
7  University of Liverpool
8 */
9 //____________________________________________________________________________
10 
11 #include <cstring>
12 #include <iomanip>
13 #include <iostream>
14 #include <sstream>
15 #include <cstdlib>
16 #include <fstream>
17 
18 #include "libxml/xmlmemory.h"
19 #include "libxml/parser.h"
20 
21 #include <TSystem.h>
22 #include <TFile.h>
23 #include <TTree.h>
24 #include <TH1F.h>
25 #include <TH2F.h>
26 
31 
33 
34 using std::setw;
35 using std::setfill;
36 using std::endl;
37 using std::ostringstream;
38 
39 using namespace genie;
40 
41 //____________________________________________________________________________
42 namespace genie {
43  ostream & operator<<(ostream & stream, const AlgConfigPool & config_pool)
44  {
45  config_pool.Print(stream);
46  return stream;
47  }
48 }
49 //____________________________________________________________________________
51 //____________________________________________________________________________
53 {
54  if( ! this->LoadAlgConfig() )
55  LOG("AlgConfigPool", pERROR) << "Could not load XML config file";
56  fInstance = 0;
57 }
58 //____________________________________________________________________________
60 {
61 // Clean up and report the most important physics params used in this instance.
62 // Don't clutter output if exiting in err.
63 
64  if(!gAbortingInErr) {
65 /*
66  cout << "AlgConfigPool singleton dtor: "
67  << "Deleting all owned algorithm configurations" << endl;
68 */
69  }
70  map<string, Registry *>::iterator citer;
71  for(citer = fRegistryPool.begin(); citer != fRegistryPool.end(); ++citer) {
72  string key = citer->first;
73  Registry * config = citer->second;
74  if(config) {
75  delete config;
76  config = 0;
77  }
78  }
79  fRegistryPool.clear();
80  fConfigFiles.clear();
81  fConfigKeyList.clear();
82  fInstance = 0;
83 }
84 //____________________________________________________________________________
86 {
87  if(fInstance == 0) {
88  static AlgConfigPool::Cleaner cleaner;
91  }
92  return fInstance;
93 }
94 //____________________________________________________________________________
96 {
97 // Loads all algorithm XML configurations and creates a map with all loaded
98 // configuration registries
99 
100  SLOG("AlgConfigPool", pINFO)
101  << "AlgConfigPool late initialization: Loading all XML config. files";
102 
103  //-- read the global parameter lists
104  if(!this->LoadGlobalParamLists())
105  {
106  SLOG("AlgConfigPool", pERROR)
107  << "Global parameter lists not available "
108  "This can be normal if you are running "
109  "Comparisons/Reweight in some cases";
110  }
111 
112  //-- read the MASTER_CONFIG XML file
113  if(!this->LoadMasterConfigs())
114  {
115  SLOG("AlgConfigPool", pERROR)
116  << "Master config file not available";
117  }
118 
119  //-- read Tune Generator List for the tune, if available
120  if( ! LoadTuneGeneratorList() ) {
121  SLOG( "AlgConfigPool", pWARN ) << "Tune generator List not available" ;
122  }
123 
124  //-- loop over all XML config files and read all named configuration
125  // sets for each algorithm
126  map<string, string>::const_iterator conf_file_iter;
127 
128  for(conf_file_iter = fConfigFiles.begin();
129  conf_file_iter != fConfigFiles.end(); ++conf_file_iter) {
130 
131  string alg_name = conf_file_iter->first;
132  string file_name = conf_file_iter->second;
133 
134  SLOG("AlgConfigPool", pINFO)
135  << setfill('.') << setw(40) << alg_name << " -> " << file_name;
136 
137  string full_path = utils::xml::GetXMLFilePath(file_name);
138  SLOG("AlgConfigPool", pNOTICE)
139  << "*** GENIE XML config file " << full_path;
140  bool ok = this->LoadSingleAlgConfig(alg_name, full_path);
141  if(!ok) {
142  SLOG("AlgConfigPool", pERROR)
143  << "Error in loading config sets for algorithm = " << alg_name;
144  }
145  }
146  return true;
147 };
148 //____________________________________________________________________________
149 bool AlgConfigPool::LoadMasterConfig(std::string configname)
150 {
151 // Loads the master config XML file: the file that specifies which XML config
152 // file to load for each algorithm
153 
154  //-- get the master config XML file using GXMLPATH + default locations
155  // fMasterConfig = utils::xml::GetXMLFilePath("master_config.xml");
157 
158  bool is_accessible = ! (gSystem->AccessPathName( fMasterConfig.c_str() ));
159  if (!is_accessible) {
160  SLOG("AlgConfigPool", pERROR)
161  << "The XML doc doesn't exist! (filename : " << fMasterConfig << ")";
162  return false;
163  }
164 
165  xmlDocPtr xml_doc = xmlParseFile(fMasterConfig.c_str());
166  if(xml_doc==NULL) {
167  SLOG("AlgConfigPool", pERROR)
168  << "The XML doc can't be parsed! (filename : " << fMasterConfig << ")";
169  return false;
170  }
171 
172  xmlNodePtr xml_root = xmlDocGetRootElement(xml_doc);
173  if(xml_root==NULL) {
174  SLOG("AlgConfigPool", pERROR)
175  << "The XML doc is empty! (filename : " << fMasterConfig << ")";
176  xmlFreeDoc(xml_doc);
177  return false;
178  }
179 
180  if( xmlStrcmp(xml_root->name, (const xmlChar *) "genie_config") ) {
181  SLOG("AlgConfigPool", pERROR)
182  << "The XML doc has invalid root element! "
183  << "(filename : " << fMasterConfig << ")";
184  xmlFreeDoc(xml_doc);
185  return false;
186  }
187 
188  // loop over all xml tree nodes (<alg_config>) that are children of the
189  // root node and read the config file name for each registered algorithm
190  xmlNodePtr xml_ac = xml_root->xmlChildrenNode;
191  while (xml_ac != NULL) {
192  if( (!xmlStrcmp(xml_ac->name, (const xmlChar *) "config")) ) {
193 
194  string alg_name = utils::str::TrimSpaces(
195  utils::xml::GetAttribute(xml_ac, "alg"));
196  string config_file = utils::xml::TrimSpaces(
197  xmlNodeListGetString(xml_doc, xml_ac->xmlChildrenNode, 1));
198 
199  pair<string, string> alg_conf(alg_name, config_file);
200  fConfigFiles.insert(alg_conf);
201  }
202  xml_ac = xml_ac->next;
203  }
204  xmlFreeNode(xml_ac);
205  xmlFreeDoc(xml_doc);
206  return true;
207 }
208 
210  auto main = LoadMasterConfig("master_config.xml");
211  if (std::getenv("GENIE_REWEIGHT")) {
212  auto rew_main = LoadMasterConfig("reweight_master_config.xml");
213  return main && rew_main;
214  } else
215  return main;
216 }
217 //____________________________________________________________________________
219 {
220 // Load the global parameter list (a list of physics constants at a given MC
221 // job, that is allowed to be modified to fine tune the generator output)
222 //
223  SLOG("AlgConfigPool", pINFO) << "Loading global parameter lists";
224 
225  // -- get the user config XML file using GXMLPATH + default locations
226  string glob_params = utils::xml::GetXMLFilePath("ModelConfiguration.xml");
227 
228  // fixed key prefix
229  string key_prefix = "GlobalParameterList";
230 
231  // load and report status
232  return this->LoadRegistries(key_prefix, glob_params, "global_param_list");
233 }
234 //____________________________________________________________________________
235 bool AlgConfigPool::LoadCommonLists( const string & file_id )
236 {
237 // Load the common parameter list
238 //
239  SLOG("AlgConfigPool", pINFO) << "Loading Common " << file_id << " lists";
240 
241  // -- get the user config XML file using GXMLPATH + default locations
242  std::string xml_name = "Common" + file_id + ".xml" ;
243  string full_path = utils::xml::GetXMLFilePath( xml_name );
244 
245  // fixed key prefix
246  string key_prefix = "Common" + file_id + "List";
247 
248  // load and report status
249  if ( ! this->LoadRegistries(key_prefix, full_path, "common_"+file_id+"_list") ) {
250 
251  SLOG("AlgConfigPool", pERROR) << "Failed to load Common " << file_id ;
252  return false ;
253  }
254 
255  return true ;
256 }
257 //____________________________________________________________________________
259 {
260 // Load the common parameter list
261 //
262  SLOG("AlgConfigPool", pINFO) << "Loading Tune Gerator List";
263 
264  // -- get the user config XML file using GXMLPATH + default locations
265  string generator_list_file = utils::xml::GetXMLFilePath("TuneGeneratorList.xml");
266 
267  // fixed key prefix
268  string key_prefix = "TuneGeneratorList";
269 
270  // load and report status
271  return this->LoadRegistries(key_prefix, generator_list_file, "tune_generator_list");
272 }
273 //____________________________________________________________________________
274 
275 bool AlgConfigPool::LoadSingleAlgConfig(string alg_name, string file_name)
276 {
277 // Loads all configuration sets for the input algorithm that can be found in
278 // the input XML file
279 
280  // use the algorithm name as the key prefix
281  string key_prefix = alg_name;
282 
283  // load and report status
284  return this->LoadRegistries(key_prefix, file_name, "alg_conf");
285 }
286 //____________________________________________________________________________
288  string key_prefix, string file_name, string root)
289 {
290 // Loads all the configuration registries from the input XML file
291 
292  SLOG("AlgConfigPool", pDEBUG) << "[-] Loading registries:";
293 
294  bool is_accessible = ! (gSystem->AccessPathName(file_name.c_str()));
295  if (!is_accessible) {
296  SLOG("AlgConfigPool", pERROR)
297  << "The XML doc doesn't exist! (filename : " << file_name << ")";
298  return false;
299  }
300 
301  xmlDocPtr xml_doc = xmlParseFile( file_name.c_str() );
302  if(xml_doc==NULL) {
303  SLOG("AlgConfigPool", pERROR)
304  << "The XML document can't be parsed! (filename : " << file_name << ")";
305  return false;
306  }
307 
308  xmlNodePtr xml_cur = xmlDocGetRootElement( xml_doc );
309  if(xml_cur==NULL) {
310  SLOG("AlgConfigPool", pERROR)
311  << "The XML document is empty! (filename : " << file_name << ")";
312  xmlFreeDoc(xml_doc);
313  return false;
314  }
315  if( xmlStrcmp(xml_cur->name, (const xmlChar *) root.c_str()) ) {
316  SLOG("AlgConfigPool", pERROR)
317  << "The XML document has invalid root element! "
318  << "(filename : " << file_name << ")";
319  xmlFreeNode(xml_cur);
320  xmlFreeDoc(xml_doc);
321  return false;
322  }
323 
324  // loop over all xml tree nodes that are children of the root node
325  xml_cur = xml_cur->xmlChildrenNode;
326  while (xml_cur != NULL) {
327  // enter everytime you find an 'param_set' tag
328  if( (!xmlStrcmp(xml_cur->name, (const xmlChar *) "param_set")) ) {
329 
330  string param_set = utils::str::TrimSpaces(
331  utils::xml::GetAttribute(xml_cur, "name"));
332 
333  // build the registry key
334  ostringstream key;
335  key << key_prefix << "/" << param_set;
336 
337  // store the key in the key list
338  fConfigKeyList.push_back(key.str());
339 
340  // create a new Registry and fill it with the configuration params
341  Registry * config = new Registry(param_set,false);
342 
343  xmlNodePtr xml_param = xml_cur->xmlChildrenNode;
344  while (xml_param != NULL) {
345  if( (!xmlStrcmp(xml_param->name, (const xmlChar *) "param")) ) {
346 
347  string param_type =
349  utils::xml::GetAttribute(xml_param, "type"));
350  string param_name =
352  utils::xml::GetAttribute(xml_param, "name"));
353  string param_value =
355  xmlNodeListGetString(
356  xml_doc, xml_param->xmlChildrenNode, 1));
357 
358 
359  if ( param_type.find( "vec-" ) == 0 ) {
360 
361  param_type = param_type.substr( 4 ) ;
362 
363  string delim = utils::str::TrimSpaces( utils::xml::GetAttribute(xml_param, "delim"));
364 
365  this -> AddParameterVector( config, param_type, param_name, param_value, delim ) ;
366  }
367  else if (param_type.find( "mat-" ) == 0) {
368  param_type = param_type.substr( 4 ) ;
369  LOG("AlgConfigPool", pNOTICE) << "Liang Liu" << param_type ;
370  string importfile = utils::str::TrimSpaces( utils::xml::GetAttribute(xml_param, "importfile"));
371  if(!importfile.compare("false")){
372  string rowdelim = utils::str::TrimSpaces( utils::xml::GetAttribute(xml_param, "rowdelim"));
373  string coldelim = utils::str::TrimSpaces( utils::xml::GetAttribute(xml_param, "coldelim"));
374  this -> AddParameterMatrix(config, param_type, param_name, param_value, rowdelim, coldelim);
375  }
376  else if(!importfile.compare("true")){
377  this -> AddParameterMatrix(config, param_type, param_name, param_value );
378  }
379  }
380  else this->AddConfigParameter( config,
381  param_type, param_name,
382  param_value);
383  }
384  xml_param = xml_param->next;
385  }
386  //xmlFree(xml_param);
387  xmlFreeNode(xml_param);
388  config->SetName(param_set);
389  config->Lock();
390 
391  pair<string, Registry *> single_reg(key.str(), config);
392  fRegistryPool.insert(single_reg);
393 
394  SLOG("AlgConfigPool", pDEBUG) << " |---o " << key.str();
395  }
396  xml_cur = xml_cur->next;
397  }
398  //xmlFree(xml_cur);
399  xmlFreeNode(xml_cur);
400  //xmlFree(xml_doc);
401  xmlFreeDoc(xml_doc);
402 
403  return true;
404 }
405 //____________________________________________________________________________
406 int AlgConfigPool::AddParameterVector (Registry * r, string pt, string pn, string pv,
407  const string & delim ) {
408 
409  // Adds a configuration parameter vector
410  // It is simply add a number of entries in the Registy
411  // The name scheme starts from the name and it goes like
412  // 'N'+pn+'s' that will be an integer with the number of entries.
413  // Each entry will be named pn+"-i" where i is replaced by the number
414 
415  SLOG("AlgConfigPool", pDEBUG)
416  << "Adding Parameter Vector [" << pt << "]: Key = "
417  << pn << " -> Value = " << pv;
418 
419  vector<string> bits = utils::str::Split( pv, delim ) ;
420 
421  string n_name = Algorithm::BuildParamVectSizeKey( pn ) ;
422 
423  std::stringstream n_value ;
424  n_value << bits.size() ;
425 
426  this->AddConfigParameter(r, "int", n_name, n_value.str() );
427 
428  for ( unsigned int i = 0 ; i < bits.size() ; ++i ) {
429 
430  std::string name = Algorithm::BuildParamVectKey( pn, i ) ;
431 
432  this -> AddConfigParameter( r, pt, name, utils::str::TrimSpaces( bits[i] ) );
433 
434  }
435 
436  return bits.size() ;
437 
438 }
439 
440 //____________________________________________________________________________
441 int AlgConfigPool::AddParameterMatrix (Registry * r, string pt, string pn, string pv,
442  const string & rowdelim, const string & coldelim ) {
443 
444  // Adds a configuration parameter matrix
445  // It is simply add a number of entries in the Registy
446  // The name scheme starts from the name and it goes like
447  // 'Nrow'+pn+'s' for the size of rows and
448  // 'Ncol'+pn+'s' for the size of columns
449  // that will be an integer with the number of entries.
450  // Each entry will be named pn+"-i"+"-j" where i and j are
451  // index of row and column and replaced by the number
452 
453  if(!rowdelim.compare(coldelim) || rowdelim.empty() || coldelim.empty()) {
454  LOG("AlgConfigPool", pFATAL) << "row and column have wrong delims: " << rowdelim << " " << coldelim ;
455  exit(1);
456  }
457  SLOG("AlgConfigPool", pDEBUG)
458  << "Adding Parameter Matrix [" << pt << "]: Key = "
459  << pn << " -> Value = " << pv;
460 
461  vector<string> mat_row = utils::str::Split( pv, rowdelim ) ;
462 
463  string r_name = Algorithm::BuildParamMatRowSizeKey( pn ) ;
464 
465 
466  unsigned int n_row = 0, n_col = 0;
467  std::stringstream r_value ;
468  r_value << mat_row.size() ;
469  n_row = mat_row.size() ;
470 
471  this->AddConfigParameter(r, "int", r_name, r_value.str() );
472 
473  for ( unsigned int i = 0 ; i < mat_row.size() ; ++i ) {
474  vector<string> bits = utils::str::Split( mat_row[i], coldelim ) ;
475  if(i == 0){
476  string c_name = Algorithm::BuildParamMatColSizeKey( pn ) ;
477  std::stringstream c_value ;
478  c_value << bits.size();
479  n_col = bits.size();
480  this->AddConfigParameter(r, "int", c_name, c_value.str() );
481  }
482  else{
483  if(n_col != bits.size()){
484  LOG("AlgConfigPool", pFATAL) << "wrong size of matrix in row: " << i;
485  exit(1);
486  }
487  }
488 
489  for ( unsigned int j = 0 ; j < bits.size() ; ++j ) {
490 
491  std::string name = Algorithm::BuildParamMatKey( pn, i, j ) ;
492 
493  this -> AddConfigParameter( r, pt, name, utils::str::TrimSpaces( bits[j] ) );
494 
495  }
496  }
497  return n_row * n_col;
498 
499 }
500 //____________________________________________________________________________
501 int AlgConfigPool::AddParameterMatrix (Registry * r, string pt, string pn, string pv ) {
502 
503  // Adds a configuration parameter matrix
504  // It is simply add a number of entries in the Registy
505  // The name scheme starts from the name and it goes like
506  // 'Nrow'+pn+'s' for the size of rows and
507  // 'Ncol'+pn+'s' for the size of columns
508  // that will be an integer with the number of entries.
509  // Each entry will be named pn+"-i"+"-j" where i and j are
510  // index of row and column and replaced by the number
511 
512  char * GENIE_PATH = std::getenv("GENIE");
513  string filepath = std::string(GENIE_PATH) + "/" + pv;
514  std::ifstream file(filepath);
515  if (!file.is_open()) {
516  throw std::runtime_error("Could not open file");
517  }
518 
519  std::string line;
520  int n_row = 0, n_col = 0;
521  int i_row = 0;
522  while (getline(file, line)) {
523  size_t start = line.find_first_not_of(" \t");
524  std::string trimmedLine = (start == std::string::npos) ? "" : line.substr(start);
525  if(trimmedLine.empty()) continue;
526  if(!trimmedLine.empty() && trimmedLine[0] == '%') continue;
527 
528  std::istringstream iss(line);
529  double value;
530  int i_col = 0;
531  while (iss >> value) {
532  std::string name = Algorithm::BuildParamMatKey( pn, i_row, i_col ) ;
533  this -> AddConfigParameter( r, pt, name, utils::str::TrimSpaces( std::to_string(value) ) );
534  i_col++;
535  }
536  if(i_row == 0)
537  n_col = i_col;
538  else{
539  if(n_col != i_col){
540  LOG("AlgConfigPool", pFATAL) << "wrong size of matrix in row: " << i_row;
541  exit(1);
542  }
543  }
544  i_row++;
545  }
546  n_row = i_row;
547  std::stringstream r_value ;
548  r_value << n_row ;
549  string r_name = Algorithm::BuildParamMatRowSizeKey( pn ) ;
550  this->AddConfigParameter(r, "int", r_name, r_value.str() );
551  std::stringstream c_value ;
552  c_value << n_col ;
553  string c_name = Algorithm::BuildParamMatColSizeKey( pn ) ;
554  this->AddConfigParameter(r, "int", c_name, c_value.str() );
555  return n_row*n_col;
556 }
557 
558 
559 
560 //____________________________________________________________________________
562  string ptype, string pname, string pvalue)
563 {
564 // Adds a configuration parameter with type = ptype, key = pname and value =
565 // pvalue at the input configuration registry r
566 
567  SLOG("AlgConfigPool", pDEBUG)
568  << "Adding Parameter [" << ptype << "]: Key = "
569  << pname << " -> Value = " << pvalue;
570 
571  bool isRootObjParam = (strcmp(ptype.c_str(), "h1f") == 0) ||
572  (strcmp(ptype.c_str(), "Th2f") == 0) ||
573  (strcmp(ptype.c_str(), "tree") == 0);
574  bool isBasicParam = (strcmp(ptype.c_str(), "int") == 0) ||
575  (strcmp(ptype.c_str(), "bool") == 0) ||
576  (strcmp(ptype.c_str(), "double") == 0) ||
577  (strcmp(ptype.c_str(), "string") == 0) ||
578  (strcmp(ptype.c_str(), "alg") == 0);
579 
580 
581  if (isBasicParam) this->AddBasicParameter (r, ptype, pname, pvalue);
582  else if(isRootObjParam) this->AddRootObjParameter(r, ptype, pname, pvalue);
583  else {
584  SLOG("AlgConfigPool", pERROR)
585  << "Parameter [" << ptype << "]: Key = " << pname
586  << " -> Value = " << pvalue << " could not be added";
587  }
588 
589 }
590 //____________________________________________________________________________
592  Registry * r, string ptype, string pname, string pvalue)
593 {
594  RgKey key = pname;
595 
596  if (ptype=="double") {
597  RgDbl item = (double) atof(pvalue.c_str());
598  r->Set(key, item);
599  }
600  else if (ptype=="int") {
601  RgInt item = (int) atoi(pvalue.c_str());
602  r->Set(key, item);
603  }
604  else if (ptype=="bool") {
605  if (pvalue=="true" ) r->Set(key, true );
606  else if (pvalue=="TRUE" ) r->Set(key, true );
607  else if (pvalue=="1" ) r->Set(key, true );
608  else if (pvalue=="false") r->Set(key, false);
609  else if (pvalue=="FALSE") r->Set(key, false);
610  else if (pvalue=="0" ) r->Set(key, false);
611  else {
612  LOG("AlgConfigPool", pERROR)
613  << "Could not set bool param: " << key;
614  }
615  }
616  else if (ptype=="string") {
617  RgStr item = pvalue;
618  r->Set(key, item);
619  }
620  else if (ptype=="alg") {
621  string name, config;
622  vector<string> algv = utils::str::Split(pvalue, "/");
623  if (algv.size()==2) {
624  name = algv[0];
625  config = algv[1];
626  }
627  else if (algv.size()==1) {
628  name = algv[0];
629  config = "Default";
630  } else {
631  LOG("AlgConfigPool", pFATAL)
632  << "Unrecognized algorithm id: " << pvalue;
633  exit(1);
634  }
635  RgAlg item(name,config);
636  r->Set(key, item);
637  }
638  else {
639  LOG("AlgConfigPool", pERROR)
640  << "Config. parameter: " << key
641  << "has unrecognized type: " << ptype;
642  }
643 }
644 //____________________________________________________________________________
646  Registry * r, string ptype, string pname, string pvalue)
647 {
648  // the ROOT object is given in the XML config file as
649  // <param> object_name@root_file_name </param>
650  vector<string> rootobjv = utils::str::Split(pvalue, "@");
651 
652  if(rootobjv.size() != 2) {
653  SLOG("AlgConfigPool", pWARN)
654  << "ROOT objects are added in XML config files as: "
655  << "object-name@file-name. Wrong syntax in: [" << pvalue << "]";
656  SLOG("AlgConfigPool", pERROR)
657  << "Parameter [" << ptype << "]: Key = " << pname
658  << " -> Value = " << pvalue << " could not be added";
659  }
660 
661  string rootobj = rootobjv[0];
662  string rootfile = rootobjv[1];
663 
664  TFile f(rootfile.c_str(), "read");
665 
666  if (ptype=="h1f") {
667  TH1F * h = (TH1F*) f.Get(rootobj.c_str());
668  if(h) {
669  TH1F * ch = new TH1F(*h); // clone
670  ch->SetDirectory(0);
671  r->Set(pname,ch);
672  } else {
673  SLOG("AlgConfigPool", pERROR)
674  << "No TH1F named = " << rootobj << " in ROOT file = " << rootfile;
675  }
676  } else if (ptype=="h2f") {
677  TH2F * h2 = (TH2F*) f.Get(rootobj.c_str());
678  if(h2) {
679  TH2F * ch2 = new TH2F(*h2); // clone
680  ch2->SetDirectory(0);
681  r->Set(pname,ch2);
682  } else {
683  SLOG("AlgConfigPool", pERROR)
684  << "No TH2F named = " << rootobj << " in ROOT file = " << rootfile;
685  }
686  } else if (ptype=="tree") {
687  TTree * t = (TTree*) f.Get(rootobj.c_str());
688  if(t) {
689  //TTree * ct = new TTree(*t); // clone
690  TTree * ct = t->CopyTree("1");
691  r->Set(pname,ct);
692  } else {
693  SLOG("AlgConfigPool", pERROR)
694  << "No TTree named = " << rootobj << " in ROOT file = " << rootfile;
695  }
696  }
697  else {}
698 }
699 //____________________________________________________________________________
701 {
702  string key = algorithm->Id().Key();
703  return this->FindRegistry(key);
704 }
705 //____________________________________________________________________________
707 {
708  string key = algid.Key();
709  return this->FindRegistry(key);
710 }
711 //____________________________________________________________________________
712 Registry* AlgConfigPool::FindRegistry(string alg_name, string param_set) const
713 {
714  AlgId id(alg_name,param_set);
715  string key = id.Key();
716  return this->FindRegistry(key);
717 }
718 //____________________________________________________________________________
720 {
721  LOG("AlgConfigPool", pDEBUG) << "Searching for registry with key " << key;
722 
723  if( fRegistryPool.count(key) == 1 ) {
724  map<string, Registry *>::const_iterator config_entry =
725  fRegistryPool.find(key);
726  return config_entry->second;
727  } else {
728  LOG("AlgConfigPool", pDEBUG) << "No config registry for key " << key;
729  return 0;
730  }
731  return 0;
732 }
733 //____________________________________________________________________________
735 {
736  string glob_param_set = (gSystem->Getenv("GUSERPHYSOPT")) ?
737  string(gSystem->Getenv("GUSERPHYSOPT")) : "Default";
738  ostringstream key;
739  key << "GlobalParameterList/" << glob_param_set;
740 
741  return this->FindRegistry(key.str());
742 }
743 //____________________________________________________________________________
744 Registry * AlgConfigPool::CommonList( const string & file_id, const string & set_name ) const
745 {
746 
747  ostringstream key;
748  key << "Common" << file_id << "List/" << set_name;
749 
750  if ( ! this->FindRegistry(key.str()) ) {
751  const_cast<AlgConfigPool*>( this ) -> LoadCommonLists( file_id ) ;
752  }
753 
754  return this->FindRegistry(key.str()) ;
755 }
756 //____________________________________________________________________________
758 {
759 
760  ostringstream key;
761  key << "TuneGeneratorList/Default";
762 
763  return this->FindRegistry(key.str());
764 }
765 //____________________________________________________________________________
766 const vector<string> & AlgConfigPool::ConfigKeyList(void) const
767 {
768  return fConfigKeyList;
769 }
770 //____________________________________________________________________________
771 void AlgConfigPool::Print(ostream & stream) const
772 {
773  string frame(100,'~');
774 
775  typedef map<string, Registry *>::const_iterator sregIter;
776  typedef map<string, Registry *>::size_type sregSize;
777 
778  sregSize size = fRegistryPool.size();
779 
780  stream << frame
781  << endl << "Algorithm Configuration Pool ("
782  << size << " configuration sets found)"
783  << endl << frame << endl;
784 
785  sregIter iter = fRegistryPool.begin();
786  for( ; iter != fRegistryPool.end(); iter++) {
787  const Registry & reg = *(iter->second);
788  stream << iter->first;
789  stream << reg;
790  stream << frame << endl;
791  }
792 }
793 //____________________________________________________________________________
static string BuildParamMatKey(const std::string &comm_name, unsigned int i, unsigned int j)
Definition: Algorithm.cxx:527
vector< string > fConfigKeyList
list of all available configuration keys
Definition: AlgConfigPool.h:88
#define pERROR
Definition: Messenger.h:59
bool LoadGlobalParamLists(void)
void Print(ostream &stream) const
static string BuildParamMatColSizeKey(const std::string &comm_name)
Definition: Algorithm.cxx:545
string TrimSpaces(xmlChar *xmls)
A singleton class holding all configuration registries built while parsing all loaded XML configurati...
Definition: AlgConfigPool.h:40
#define pFATAL
Definition: Messenger.h:56
int RgInt
Algorithm abstract base class.
Definition: Algorithm.h:54
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
int main(int argc, char **argv)
Definition: gAtmoEvGen.cxx:327
int AddParameterMatrix(Registry *r, string pt, string pn, string pv, const string &rowdelim, const string &coldelim)
void AddRootObjParameter(Registry *r, string pt, string pn, string pv)
static AlgConfigPool * fInstance
Definition: AlgConfigPool.h:84
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static string BuildParamMatRowSizeKey(const std::string &comm_name)
Definition: Algorithm.cxx:537
Registry * TuneGeneratorList(void) const
string GetXMLFilePath(string basename)
void AddBasicParameter(Registry *r, string pt, string pn, string pv)
bool LoadTuneGeneratorList(void)
string RgStr
#define pINFO
Definition: Messenger.h:62
void Lock(void)
locks the registry
Definition: Registry.cxx:148
void SetName(string name)
set the registry name
Definition: Registry.cxx:588
const vector< string > & ConfigKeyList(void) const
Registry * GlobalParameterList(void) const
#define pWARN
Definition: Messenger.h:60
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
Algorithm ID (algorithm name + configuration set name)
Definition: AlgId.h:34
int AddParameterVector(Registry *r, string pt, string pn, string pv, const string &delim=";")
bool LoadMasterConfigs(void)
bool LoadRegistries(string key_base, string file_name, string root)
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:98
map< string, string > fConfigFiles
algorithm -&gt; XML config file
Definition: AlgConfigPool.h:87
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
static string BuildParamVectSizeKey(const std::string &comm_name)
Definition: Algorithm.cxx:520
string RgKey
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
map< string, Registry * > fRegistryPool
algorithm/param_set -&gt; Registry
Definition: AlgConfigPool.h:86
bool LoadMasterConfig(std::string configname)
Registry * FindRegistry(string key) const
#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
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
double RgDbl
bool gAbortingInErr
Definition: Messenger.cxx:34
void Set(RgIMapPair entry)
Definition: Registry.cxx:267
static string BuildParamVectKey(const std::string &comm_name, unsigned int i)
Definition: Algorithm.cxx:510
bool LoadCommonLists(const string &file_id)
string Key(void) const
Definition: AlgId.h:46
static AlgConfigPool * Instance()
#define pDEBUG
Definition: Messenger.h:63
string fMasterConfig
lists config files for all algorithms
Definition: AlgConfigPool.h:89