GENIEGenerator
Loading...
Searching...
No Matches
genie::AlgConfigPool Class Reference

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

#include <AlgConfigPool.h>

Collaboration diagram for genie::AlgConfigPool:
[legend]

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 (std::string configname)
bool LoadMasterConfigs (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=";")
int AddParameterMatrix (Registry *r, string pt, string pn, string pv, const string &rowdelim, const string &coldelim)
int AddParameterMatrix (Registry *r, string pt, string pn, string pv)
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
map< string, string > fConfigFiles
 algorithm -> XML config file
vector< string > fConfigKeyList
 list of all available configuration keys
string fMasterConfig
 lists config files for all algorithms

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 <c.andreopoulos \at cern.ch> University of Liverpool
Created:\n May 06, 2004
License:\n Copyright (c) 2003-2025, 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() [1/2]

AlgConfigPool::AlgConfigPool ( )
private

Definition at line 52 of file AlgConfigPool.cxx.

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

References fInstance, LoadAlgConfig(), LOG, and pERROR.

Referenced by AlgConfigPool(), CommonList(), Instance(), and operator<<.

◆ AlgConfigPool() [2/2]

genie::AlgConfigPool::AlgConfigPool ( const AlgConfigPool & config_pool)
private

References AlgConfigPool().

◆ ~AlgConfigPool()

AlgConfigPool::~AlgConfigPool ( )
privatevirtual

Definition at line 59 of file AlgConfigPool.cxx.

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}
map< string, string > fConfigFiles
algorithm -> XML config file
vector< string > fConfigKeyList
list of all available configuration keys
map< string, Registry * > fRegistryPool
algorithm/param_set -> Registry
bool gAbortingInErr
Definition Messenger.cxx:34

References fConfigFiles, fConfigKeyList, fInstance, fRegistryPool, and genie::gAbortingInErr.

Member Function Documentation

◆ AddBasicParameter()

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

Definition at line 591 of file AlgConfigPool.cxx.

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}
#define pFATAL
Definition Messenger.h:56
string RgStr
int RgInt
double RgDbl
string RgKey
void Set(RgIMapPair entry)
Definition Registry.cxx:267
vector< string > Split(string input, string delim)

References LOG, pERROR, pFATAL, genie::Registry::Set(), and genie::utils::str::Split().

Referenced by AddConfigParameter().

◆ AddConfigParameter()

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

Definition at line 561 of file AlgConfigPool.cxx.

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}
#define pDEBUG
Definition Messenger.h:63
#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 AddRootObjParameter(Registry *r, string pt, string pn, string pv)
void AddBasicParameter(Registry *r, string pt, string pn, string pv)

References AddBasicParameter(), AddRootObjParameter(), pDEBUG, pERROR, and SLOG.

Referenced by AddParameterMatrix(), AddParameterMatrix(), AddParameterVector(), and LoadRegistries().

◆ AddParameterMatrix() [1/2]

int AlgConfigPool::AddParameterMatrix ( Registry * r,
string pt,
string pn,
string pv )
private

Definition at line 501 of file AlgConfigPool.cxx.

501 {
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}
void AddConfigParameter(Registry *r, string pt, string pn, string pv)
static string BuildParamMatKey(const std::string &comm_name, unsigned int i, unsigned int j)
static string BuildParamMatColSizeKey(const std::string &comm_name)
static string BuildParamMatRowSizeKey(const std::string &comm_name)
string TrimSpaces(string input)

References AddConfigParameter(), genie::Algorithm::BuildParamMatColSizeKey(), genie::Algorithm::BuildParamMatKey(), genie::Algorithm::BuildParamMatRowSizeKey(), LOG, pFATAL, and genie::utils::str::TrimSpaces().

◆ AddParameterMatrix() [2/2]

int AlgConfigPool::AddParameterMatrix ( Registry * r,
string pt,
string pn,
string pv,
const string & rowdelim,
const string & coldelim )
private

Definition at line 441 of file AlgConfigPool.cxx.

442 {
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}

References AddConfigParameter(), genie::Algorithm::BuildParamMatColSizeKey(), genie::Algorithm::BuildParamMatKey(), genie::Algorithm::BuildParamMatRowSizeKey(), LOG, pDEBUG, pFATAL, SLOG, genie::utils::str::Split(), and genie::utils::str::TrimSpaces().

Referenced by LoadRegistries().

◆ AddParameterVector()

int AlgConfigPool::AddParameterVector ( Registry * r,
string pt,
string pn,
string pv,
const string & delim = ";" )
private

Definition at line 406 of file AlgConfigPool.cxx.

407 {
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}
static string BuildParamVectSizeKey(const std::string &comm_name)
static string BuildParamVectKey(const std::string &comm_name, unsigned int i)

References AddConfigParameter(), genie::Algorithm::BuildParamVectKey(), genie::Algorithm::BuildParamVectSizeKey(), pDEBUG, SLOG, genie::utils::str::Split(), and genie::utils::str::TrimSpaces().

Referenced by LoadRegistries().

◆ AddRootObjParameter()

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

Definition at line 645 of file AlgConfigPool.cxx.

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}
#define pWARN
Definition Messenger.h:60

References pERROR, pWARN, genie::Registry::Set(), SLOG, and genie::utils::str::Split().

Referenced by AddConfigParameter().

◆ BuildConfigKey() [1/2]

string genie::AlgConfigPool::BuildConfigKey ( const Algorithm * algorithm) const
private

◆ BuildConfigKey() [2/2]

string genie::AlgConfigPool::BuildConfigKey ( string alg_name,
string param_set ) const
private

◆ CommonList()

Registry * AlgConfigPool::CommonList ( const string & file_id,
const string & set_name ) const

Definition at line 744 of file AlgConfigPool.cxx.

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}
Registry * FindRegistry(string key) const
bool LoadCommonLists(const string &file_id)

References AlgConfigPool(), FindRegistry(), and LoadCommonLists().

Referenced by genie::PDGLibrary::AddDarkSector(), genie::PDGLibrary::AddHNL(), CheckUnitarityLimit(), genie::GVldContext::Decode(), genie::TabulatedLabFrameHadronTensor::dSigma_dT_dCosTheta_rosenbluth(), genie::KPhaseSpace::GetTMaxDFR(), genie::PDGLibrary::LoadDBase(), and main().

◆ ConfigKeyList()

const vector< string > & AlgConfigPool::ConfigKeyList ( void ) const

Definition at line 766 of file AlgConfigPool.cxx.

767{
768 return fConfigKeyList;
769}

References fConfigKeyList.

Referenced by genie::NtpMCJobConfig::Load(), and main().

◆ FindRegistry() [1/4]

Registry * AlgConfigPool::FindRegistry ( const AlgId & algid) const

Definition at line 706 of file AlgConfigPool.cxx.

707{
708 string key = algid.Key();
709 return this->FindRegistry(key);
710}
string Key(void) const
Definition AlgId.h:46

References FindRegistry(), and genie::AlgId::Key().

◆ FindRegistry() [2/4]

Registry * AlgConfigPool::FindRegistry ( const Algorithm * algorithm) const

Definition at line 700 of file AlgConfigPool.cxx.

701{
702 string key = algorithm->Id().Key();
703 return this->FindRegistry(key);
704}
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition Algorithm.h:98

References FindRegistry(), genie::Algorithm::Id(), and genie::AlgId::Key().

◆ FindRegistry() [3/4]

Registry * AlgConfigPool::FindRegistry ( string alg_name,
string param_set ) const

Definition at line 712 of file AlgConfigPool.cxx.

713{
714 AlgId id(alg_name,param_set);
715 string key = id.Key();
716 return this->FindRegistry(key);
717}

References FindRegistry().

◆ FindRegistry() [4/4]

Registry * AlgConfigPool::FindRegistry ( string key) const

Definition at line 719 of file AlgConfigPool.cxx.

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}

References fRegistryPool, LOG, and pDEBUG.

Referenced by CommonList(), genie::Algorithm::FindConfig(), FindRegistry(), FindRegistry(), FindRegistry(), GlobalParameterList(), genie::NtpMCJobConfig::Load(), main(), main(), testReconfigInCommonPool(), and TuneGeneratorList().

◆ GlobalParameterList()

Registry * AlgConfigPool::GlobalParameterList ( void ) const

Definition at line 734 of file AlgConfigPool.cxx.

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}

References FindRegistry().

Referenced by genie::PauliBlocker::LoadModelType(), main(), genie::utils::nuclear::NuclQELXSecSuppression(), and genie::AlgFactory::Print().

◆ Instance()

◆ LoadAlgConfig()

bool AlgConfigPool::LoadAlgConfig ( void )
private

Definition at line 95 of file AlgConfigPool.cxx.

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};
#define pNOTICE
Definition Messenger.h:61
#define pINFO
Definition Messenger.h:62
bool LoadSingleAlgConfig(string alg_name, string file_name)
bool LoadTuneGeneratorList(void)
bool LoadGlobalParamLists(void)
string GetXMLFilePath(string basename)

References fConfigFiles, genie::utils::xml::GetXMLFilePath(), LoadGlobalParamLists(), LoadMasterConfigs(), LoadSingleAlgConfig(), LoadTuneGeneratorList(), pERROR, pINFO, pNOTICE, pWARN, and SLOG.

Referenced by AlgConfigPool().

◆ LoadCommonLists()

bool AlgConfigPool::LoadCommonLists ( const string & file_id)
private

Definition at line 235 of file AlgConfigPool.cxx.

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}
bool LoadRegistries(string key_base, string file_name, string root)

References genie::utils::xml::GetXMLFilePath(), LoadRegistries(), pERROR, pINFO, and SLOG.

Referenced by CommonList().

◆ LoadGlobalParamLists()

bool AlgConfigPool::LoadGlobalParamLists ( void )
private

Definition at line 218 of file AlgConfigPool.cxx.

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}

References genie::utils::xml::GetXMLFilePath(), LoadRegistries(), pINFO, and SLOG.

Referenced by LoadAlgConfig().

◆ LoadMasterConfig()

bool AlgConfigPool::LoadMasterConfig ( std::string configname)
private

Definition at line 149 of file AlgConfigPool.cxx.

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::TrimSpacesClean(
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}
string fMasterConfig
lists config files for all algorithms
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
string TrimSpacesClean(xmlChar *xmls)

References fConfigFiles, fMasterConfig, genie::utils::xml::GetAttribute(), genie::utils::xml::GetXMLFilePath(), pERROR, SLOG, genie::utils::str::TrimSpaces(), and genie::utils::xml::TrimSpacesClean().

Referenced by LoadMasterConfigs().

◆ LoadMasterConfigs()

bool AlgConfigPool::LoadMasterConfigs ( void )
private

Definition at line 209 of file AlgConfigPool.cxx.

209 {
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}
int main()
bool LoadMasterConfig(std::string configname)

References LoadMasterConfig(), and main().

Referenced by LoadAlgConfig().

◆ LoadRegistries()

bool AlgConfigPool::LoadRegistries ( string key_base,
string file_name,
string root )
private

Definition at line 287 of file AlgConfigPool.cxx.

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}
int AddParameterMatrix(Registry *r, string pt, string pn, string pv, const string &rowdelim, const string &coldelim)
int AddParameterVector(Registry *r, string pt, string pn, string pv, const string &delim=";")
void Lock(void)
locks the registry
Definition Registry.cxx:148
void SetName(string name)
set the registry name
Definition Registry.cxx:588

References AddConfigParameter(), AddParameterMatrix(), AddParameterVector(), fConfigKeyList, fRegistryPool, genie::utils::xml::GetAttribute(), genie::Registry::Lock(), LOG, pDEBUG, pERROR, pNOTICE, genie::Registry::SetName(), SLOG, genie::utils::str::TrimSpaces(), and genie::utils::xml::TrimSpacesClean().

Referenced by LoadCommonLists(), LoadGlobalParamLists(), LoadSingleAlgConfig(), and LoadTuneGeneratorList().

◆ LoadSingleAlgConfig()

bool AlgConfigPool::LoadSingleAlgConfig ( string alg_name,
string file_name )
private

Definition at line 275 of file AlgConfigPool.cxx.

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}

References LoadRegistries().

Referenced by LoadAlgConfig().

◆ LoadTuneGeneratorList()

bool AlgConfigPool::LoadTuneGeneratorList ( void )
private

Definition at line 258 of file AlgConfigPool.cxx.

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}

References genie::utils::xml::GetXMLFilePath(), LoadRegistries(), pINFO, and SLOG.

Referenced by LoadAlgConfig().

◆ Print()

void AlgConfigPool::Print ( ostream & stream) const

Definition at line 771 of file AlgConfigPool.cxx.

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}

References fRegistryPool.

Referenced by operator<<.

◆ TuneGeneratorList()

Registry * AlgConfigPool::TuneGeneratorList ( void ) const

Definition at line 757 of file AlgConfigPool.cxx.

758{
759
760 ostringstream key;
761 key << "TuneGeneratorList/Default";
762
763 return this->FindRegistry(key.str());
764}

References FindRegistry().

◆ Cleaner

friend struct Cleaner
friend

Definition at line 100 of file AlgConfigPool.h.

◆ operator<<

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

Definition at line 43 of file AlgConfigPool.cxx.

44 {
45 config_pool.Print(stream);
46 return stream;
47 }

References AlgConfigPool(), and Print().

Member Data Documentation

◆ fConfigFiles

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

algorithm -> XML config file

Definition at line 87 of file AlgConfigPool.h.

Referenced by LoadAlgConfig(), LoadMasterConfig(), and ~AlgConfigPool().

◆ fConfigKeyList

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

list of all available configuration keys

Definition at line 88 of file AlgConfigPool.h.

Referenced by ConfigKeyList(), LoadRegistries(), and ~AlgConfigPool().

◆ fInstance

AlgConfigPool * AlgConfigPool::fInstance = 0
staticprivate

◆ fMasterConfig

string genie::AlgConfigPool::fMasterConfig
private

lists config files for all algorithms

Definition at line 89 of file AlgConfigPool.h.

Referenced by LoadMasterConfig().

◆ fRegistryPool

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

algorithm/param_set -> Registry

Definition at line 86 of file AlgConfigPool.h.

Referenced by FindRegistry(), LoadRegistries(), Print(), and ~AlgConfigPool().


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