25 using namespace genie;
52 fID.SetId(name,config);
59 this->DeleteSubstructure();
70 LOG(
"Algorithm",
pNOTICE)
"Registry " << config.
Name() <<
" is empty. Not added to " << fID.Name();
74 Registry* rp = ExtractLocalConfig( config ) ;
77 MergeTopRegistry( *rp ) ;
78 LOG(
"Algorithm",
pNOTICE) << fID.Name() <<
" merged with external configuration: " << *rp;
84 if(!fOwnsSubstruc)
return;
85 if(fOwnedSubAlgMp->size()==0)
return;
87 LOG(
"Algorithm",
pNOTICE) <<
"Configuring algorithms stored at local pool";
91 for(
AlgMapIter alg_iter = fOwnedSubAlgMp->begin();
92 alg_iter != fOwnedSubAlgMp->end(); ++alg_iter) {
94 string alg_key = alg_iter->first;
99 <<
"Key: " << alg_key <<
" points to a null algorithm at local pool";
103 LOG(
"Algorithm",
pNOTICE) <<
"Configuring sub-alg: " << alg->
Id().
Key();
105 rp = ExtractLowerConfig( config, alg_key ) ;
123 fID.SetConfig(config);
142 if ( fID.Config() !=
"Default" ) {
143 config = pool -> FindRegistry( fID.Name(),
"Default" );
145 if ( config -> NEntries() > 0 ) {
146 AddTopRegistry( config,
false ) ;
158 <<
"No Configuration available for " 159 << this->Id().Key() <<
" at the ConfigPool";
161 if ( config -> NEntries() > 0 ) {
162 AddTopRegistry( config,
false ) ;
167 const string common_key_root =
"Common" ;
168 std::map<string, string> common_lists;
171 for (
unsigned int i = 0 ; i < fConfVect.size() ; ++i ) {
176 if ( it -> first.find( common_key_root ) == 0 ) {
182 string temp_list = temp.
GetString( it -> first ) ;
183 if ( temp_list.length() > 0 ) {
184 common_lists[
type] = temp_list ;
195 it != common_lists.end() ; ++it ) {
199 for (
unsigned int i = 0; i < list.size(); ++i ) {
201 config = pool -> CommonList( it -> first, list[i] ) ;
205 <<
"No Common parameters available for " << it -> first <<
" list " 206 << list[i] <<
" at the ConfigPool";
211 AddLowRegistry( config,
false ) ;
213 << it -> first <<
" registry " 214 << list[i] <<
" \n" <<
config;
224 config = pool -> CommonList(
"Param",
"Tunable" ) ;
226 if ( config -> NEntries() > 0 ) {
227 AddTopRegistry( config,
false ) ;
234 <<
"No Tunable parameter set available at the ConfigPool";
248 if ( fConfig )
return * fConfig ;
250 const_cast<Algorithm*
>( this ) -> fConfig =
new Registry( fID.Key() +
"_summary", false ) ;
254 for (
unsigned int i = 0 ; i < fConfVect.size(); ++i ) {
255 fConfig -> Append( * fConfVect[i] ) ;
258 if ( fOwnsSubstruc ) {
261 iter != fOwnedSubAlgMp ->
end() ; ++iter ) {
265 LOG(
"Algorithm",
pDEBUG) <<
"Appending config from " << iter -> first <<
" -> " << subalg -> Id() ;
268 fConfig -> Append(r,prefix);
290 string alg1 = this->Id().Name();
291 string config1 = this->Id().Config();
292 string alg2 = algo->
Id().
Name();
293 string config2 = algo->
Id().
Config();
312 fID.SetId(name, config);
318 stream <<
"\nAlgorithm Key: " << this->fID.Key();
319 stream <<
" - Owns Substruc: " << ((fOwnsSubstruc) ?
"[true]" :
"[false]");
327 for(; iter!=fOwnedSubAlgMp->end(); ++iter) {
329 stream <<
"<Next algorithm is owned by : " << this->fID.Key() <<
">";
339 fAllowReconfig =
true;
340 fOwnsSubstruc =
false;
355 <<
"Fetching sub-alg within alg: " << this->Id().Key()
356 <<
" pointed to by key: " << registry_key;
363 if(iter!=fOwnedSubAlgMp->end())
return iter->second;
365 <<
"Owned sub-alg pointed to by key: " << registry_key
366 <<
" was not found within alg: " << this->Id().Key();
373 GetParam( registry_key, alg ) ;
376 <<
"Registry key: " << registry_key <<
" points to algorithm: " << alg;
389 << this->Id().Key() <<
" is taking ownership of its configuration";
413 <<
"Algorithm: " << this->Id().Key() <<
" is adopting its substructure";
422 if(fOwnsSubstruc) this->DeleteSubstructure();
424 fOwnedSubAlgMp =
new AlgMap;
425 fOwnsSubstruc =
true;
429 const RgIMap & rgmap = GetConfig().GetItemMap();
432 for( ; iter != rgmap.end(); ++iter) {
434 RgKey reg_key = iter->first;
439 <<
"Found sub-algorithm pointed to by " << reg_key;
440 RgAlg reg_alg = fConfig->GetAlg(reg_key);
443 LOG(
"Algorithm",
pDEBUG) <<
"Adopting sub-algorithm = " <<
id.Key();
447 LOG(
"Algorithm",
pDEBUG) <<
"Adding sub-algorithm to local pool";
449 fOwnedSubAlgMp->insert(key_alg_pair);
469 for (
unsigned int i = 0 ; i < fConfVect.size() ; ++i ) {
470 if ( fOwnerships[i] ) {
471 delete fConfVect[i] ;
476 fOwnerships.clear() ;
493 if(!fOwnsSubstruc)
return;
498 for( ; iter != fOwnedSubAlgMp->end(); ++iter) {
505 delete fOwnedSubAlgMp;
512 std::stringstream
name;
513 name << comm_name <<
'-' << i ;
522 return 'N' + comm_name +
's' ;
529 bool is_top_call )
const {
536 bool found = GetParam( n_name, n, is_top_call ) ;
542 for (
int i = 0; i <
n; ++i ) {
550 k.push_back( temp_key ) ;
564 reg_iter != rgmap.end(); ++reg_iter ) {
566 RgKey reg_key = reg_iter->first;
567 if( reg_key.find(
'/' ) != string::npos)
continue;
575 out ->
Set(key_item_pair);
579 if ( out -> NEntries() <= 0 ) {
595 reg_iter != rgmap.end(); ++reg_iter ) {
597 RgKey reg_key = reg_iter->first;
598 if( reg_key.find(alg_key+
"/") == string::npos)
continue;
604 int new_key_start = reg_key.find_first_of(
'/')+1;
605 RgKey new_reg_key = reg_key.substr( new_key_start, reg_key.length() );
609 out ->
Set(key_item_pair);
613 if ( out -> NEntries() <= 0 ) {
627 fConfVect.insert( fConfVect.begin(), rp ) ;
628 fOwnerships.insert( fOwnerships.begin(), own ) ;
635 return fConfVect.size() ;
643 fConfVect.push_back( rp ) ;
644 fOwnerships.push_back( own ) ;
651 return fConfVect.size() ;
660 if ( fOwnerships.empty() ) {
664 AddTopRegistry( p ) ;
669 if ( fOwnerships[0] ) {
671 fConfVect[0] -> Merge( r ) ;
678 AddTopRegistry( p ) ;
687 return fConfVect.size() ;
695 fConfVect.insert( fConfVect.begin(), rs.begin(), rs.end() ) ;
697 fOwnerships.insert( fOwnerships.begin(), rs.size(), own ) ;
704 return fConfVect.size() ;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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...
ChannelGroupService::Name Name
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
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
typename config_impl< T >::type Config
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?
constexpr BitMask< Storage > Set(Flag_t< Storage > flag)
Returns a bit mask which sets the specified flag.
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
virtual const AlgId & Id(void) const
Get algorithm ID.
RgStr GetString(RgKey key) const
vector< string > Split(string input, string delim)
static AlgFactory * Instance()
static string BuildParamVectSizeKey(const std::string &comm_name)
A registry. Provides the container for algorithm configuration parameters.
virtual RegistryItemI * Clone(void) const =0
void Configure(string mesg)
int GetParamVectKeys(const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
virtual AlgCmp_t Compare(const Algorithm *alg) const
Compare with input algorithm.
virtual void Print(ostream &stream) const
Print algorithm info.
Registry * FindRegistry(string key) const
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
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
second_as<> second
Type of time stored in seconds, in double precision.
static string BuildParamVectKey(const std::string &comm_name, unsigned int i)
Root of GENIE utility namespaces.
QTextStream & endl(QTextStream &s)
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