33 using namespace genie;
60 fID.SetId(name,config);
67 this->DeleteSubstructure();
78 LOG(
"Algorithm",
pNOTICE)
"Registry " << config.
Name() <<
" is empty. Not added to " << fID.Name();
82 Registry* rp = ExtractLocalConfig( config ) ;
85 MergeTopRegistry( *rp ) ;
86 LOG(
"Algorithm",
pNOTICE) << fID.Name() <<
" merged with external configuration: " << *rp;
92 if(!fOwnsSubstruc)
return;
93 if(fOwnedSubAlgMp->size()==0)
return;
95 LOG(
"Algorithm",
pNOTICE) <<
"Configuring algorithms stored at local pool";
99 for(
AlgMapIter alg_iter = fOwnedSubAlgMp->begin();
100 alg_iter != fOwnedSubAlgMp->end(); ++alg_iter) {
102 string alg_key = alg_iter->first;
107 <<
"Key: " << alg_key <<
" points to a null algorithm at local pool";
111 LOG(
"Algorithm",
pNOTICE) <<
"Configuring sub-alg: " << alg->
Id().
Key();
113 rp = ExtractLowerConfig( config, alg_key ) ;
131 fID.SetConfig(config);
150 if ( fID.Config() !=
"Default" ) {
151 config = pool -> FindRegistry( fID.Name(),
"Default" );
153 if ( config -> NEntries() > 0 ) {
154 AddTopRegistry( config,
false ) ;
166 <<
"No Configuration available for " 167 << this->Id().Key() <<
" at the ConfigPool";
169 if ( config -> NEntries() > 0 ) {
170 AddTopRegistry( config,
false ) ;
175 const string common_key_root =
"Common" ;
176 std::map<string, string> common_lists;
179 for (
unsigned int i = 0 ;
i < fConfVect.size() ; ++
i ) {
184 if (
it -> first.find( common_key_root ) == 0 ) {
191 if ( temp_list.length() > 0 ) {
192 common_lists[
type] = temp_list ;
202 for ( std::map<string, string>::const_iterator
it = common_lists.begin() ;
203 it != common_lists.end() ; ++
it ) {
207 for (
unsigned int i = 0;
i < list.size(); ++
i ) {
209 config = pool -> CommonList(
it -> first, list[
i] ) ;
213 <<
"No Commom parameters available for " <<
it -> first <<
" list " 214 << list[
i] <<
" at the ConfigPool";
219 AddLowRegistry( config,
false ) ;
221 <<
it -> first <<
" registry " 232 config = pool -> CommonList(
"Param",
"Tunable" ) ;
234 if ( config -> NEntries() > 0 ) {
235 AddTopRegistry( config,
false ) ;
242 <<
"No Tunable parameter set available at the ConfigPool";
256 if ( fConfig )
return * fConfig ;
258 const_cast<Algorithm*
>( this ) -> fConfig =
new Registry( fID.Key() +
"_summary", false ) ;
262 for (
unsigned int i = 0 ;
i < fConfVect.size(); ++
i ) {
263 fConfig -> Append( * fConfVect[
i] ) ;
266 if ( fOwnsSubstruc ) {
269 iter != fOwnedSubAlgMp ->
end() ; ++iter ) {
273 LOG(
"Algorithm",
pDEBUG) <<
"Appending config from " << iter -> first <<
" -> " << subalg -> Id() ;
276 fConfig -> Append(r,prefix);
298 string alg1 = this->Id().Name();
299 string config1 = this->Id().Config();
300 string alg2 = algo->
Id().
Name();
301 string config2 = algo->
Id().
Config();
320 fID.SetId(name, config);
326 stream <<
"\nAlgorithm Key: " << this->fID.Key();
327 stream <<
" - Owns Substruc: " << ((fOwnsSubstruc) ?
"[true]" :
"[false]");
335 for(; iter!=fOwnedSubAlgMp->end(); ++iter) {
337 stream <<
"<Next algorithm is owned by : " << this->fID.Key() <<
">";
347 fAllowReconfig =
true;
348 fOwnsSubstruc =
false;
363 <<
"Fetching sub-alg within alg: " << this->Id().Key()
364 <<
" pointed to by key: " << registry_key;
371 if(iter!=fOwnedSubAlgMp->end())
return iter->second;
373 <<
"Owned sub-alg pointed to by key: " << registry_key
374 <<
" was not found within alg: " << this->Id().Key();
381 GetParam( registry_key, alg ) ;
384 <<
"Registry key: " << registry_key <<
" points to algorithm: " << alg;
397 << this->Id().Key() <<
" is taking ownership of its configuration";
421 <<
"Algorithm: " << this->Id().Key() <<
" is adopting its substructure";
430 if(fOwnsSubstruc) this->DeleteSubstructure();
432 fOwnedSubAlgMp =
new AlgMap;
433 fOwnsSubstruc =
true;
440 for( ; iter != rgmap.end(); ++iter) {
442 RgKey reg_key = iter->first;
447 <<
"Found sub-algorithm pointed to by " << reg_key;
448 RgAlg reg_alg = fConfig->GetAlg(reg_key);
451 LOG(
"Algorithm",
pDEBUG) <<
"Adopting sub-algorithm = " <<
id.Key();
455 LOG(
"Algorithm",
pDEBUG) <<
"Adding sub-algorithm to local pool";
457 fOwnedSubAlgMp->insert(key_alg_pair);
477 for (
unsigned int i = 0 ;
i < fConfVect.size() ; ++
i ) {
478 if ( fOwnerships[
i] ) {
479 delete fConfVect[
i] ;
484 fOwnerships.clear() ;
501 if(!fOwnsSubstruc)
return;
506 for( ; iter != fOwnedSubAlgMp->end(); ++iter) {
513 delete fOwnedSubAlgMp;
524 reg_iter != rgmap.end(); ++reg_iter ) {
526 RgKey reg_key = reg_iter->first;
527 if( reg_key.find(
'/' ) != string::npos)
continue;
535 out -> Set(key_item_pair);
539 if ( out -> NEntries() <= 0 ) {
555 reg_iter != rgmap.end(); ++reg_iter ) {
557 RgKey reg_key = reg_iter->first;
558 if( reg_key.find(alg_key+
"/") == string::npos)
continue;
564 int new_key_start = reg_key.find_first_of(
'/')+1;
565 RgKey new_reg_key = reg_key.substr( new_key_start, reg_key.length() );
569 out -> Set(key_item_pair);
573 if ( out -> NEntries() <= 0 ) {
587 fConfVect.insert( fConfVect.begin(), rp ) ;
588 fOwnerships.insert( fOwnerships.begin(), own ) ;
595 return fConfVect.size() ;
603 fConfVect.push_back( rp ) ;
604 fOwnerships.push_back( own ) ;
611 return fConfVect.size() ;
620 if ( fOwnerships.empty() ) {
624 AddTopRegistry( p ) ;
629 if ( fOwnerships[0] ) {
631 fConfVect[0] -> Merge( r ) ;
638 AddTopRegistry( p ) ;
647 return fConfVect.size() ;
655 fConfVect.insert( fConfVect.begin(), rs.begin(), rs.end() ) ;
657 fOwnerships.insert( fOwnerships.begin(), rs.size(), own ) ;
664 return fConfVect.size() ;
::xsd::cxx::tree::id< char, ncname > id
Registry * GetOwnedConfig(void)
THE MAIN GENIE PROJECT NAMESPACE
void DeleteSubstructure(void)
Registry * ExtractLowerConfig(const Registry &in, const string &alg_key) const
Split an incoming configuration Registry into a block valid for the sub-algo identified by alg_key...
A singleton class holding all configuration registries built while parsing all loaded XML configurati...
int MergeTopRegistry(const Registry &r)
Algorithm abstract base class.
int AddTopRegisties(const vector< Registry * > &rs, bool owns=false)
Add registries with top priority, also udated Ownerships.
map< string, Algorithm * > AlgMap
void Initialize(Bool_t useTMVAStyle=kTRUE)
ostream & operator<<(ostream &stream, const T2KEvGenMetaData &md)
virtual const Registry & GetConfig(void) const
enum genie::EAlgCmp AlgCmp_t
string Name(void) const
get the registry name
virtual RgType_t TypeInfo(void) const =0
map< RgKey, RegistryItemI * >::const_iterator RgIMapConstIter
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
const RgIMap & GetItemMap(void) const
virtual void FindConfig(void)
bool ItemIsLocal(RgKey key) const
local or global?
virtual void Configure(const Registry &config)
const Algorithm * GetAlgorithm(const AlgId &algid)
void AdoptSubstructure(void)
pair< string, Algorithm * > AlgMapPair
Algorithm * AdoptAlgorithm(const AlgId &algid) const
pair< RgKey, RegistryItemI * > RgIMapPair
int AddTopRegistry(Registry *rp, bool owns=true)
add registry with top priority, also update ownership
Algorithm ID (algorithm name + configuration set name)
map< string, Algorithm * >::const_iterator AlgMapConstIter
TString GetConfig(int dbcfg)
virtual const AlgId & Id(void) const
Get algorithm ID.
RgStr GetString(RgKey key) const
vector< string > Split(string input, string delim)
static AlgFactory * Instance()
A registry. Provides the container for algorithm configuration parameters.
virtual RegistryItemI * Clone(void) const =0
void Configure(string mesg)
virtual AlgCmp_t Compare(const Algorithm *alg) const
Compare with input algorithm.
virtual void Print(ostream &stream) const
Print algorithm info.
assert(nhit_max >=nhit_nbins)
Registry * FindRegistry(string key) const
virtual void SetId(const AlgId &id)
Set algorithm ID.
int AddLowRegistry(Registry *rp, bool owns=true)
add registry with lowest priority, also update ownership
Registry * ExtractLocalConfig(const Registry &in) const
The GENIE Algorithm Factory.
map< string, Algorithm * >::iterator AlgMapIter
Root of GENIE utility namespaces.
static AlgConfigPool * Instance()
map< RgKey, RegistryItemI * > RgIMap
string Config(void) const
int NEntries(void) const
get number of items
const Algorithm * SubAlg(const RgKey ®istry_key) const