25 using namespace genie;
26 using namespace genie::utils;
52 fID.SetId(name,config);
59 this->DeleteSubstructure();
66 LOG(
"Algorithm",
pNOTICE) <<
"Input configuration: " << config;
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 ) ;
147 LOG(
"Algorithm",
pDEBUG) <<
"\n" << *config;
158 <<
"No Configuration available for "
159 << this->Id().Key() <<
" at the ConfigPool";
161 if ( config -> NEntries() > 0 ) {
162 AddTopRegistry( config,
false ) ;
163 LOG(
"Algorithm",
pDEBUG) <<
"\n" << config;
167 const string common_key_root =
"Common" ;
168 std::map<string, string> common_lists;
171 for (
unsigned int i = 0 ; i < fConfVect.size() ; ++i ) {
172 const Registry & temp = * fConfVect[i] ;
176 if ( it -> first.find( common_key_root ) == 0 ) {
178 std::string type = it -> first.substr(common_key_root.size() ) ;
182 string temp_list = temp.
GetString( it -> first ) ;
183 if ( temp_list.length() > 0 ) {
184 common_lists[type] = temp_list ;
194 for ( std::map<string, string>::const_iterator it = common_lists.begin() ;
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 ) ;
228 LOG(
"Algorithm",
pDEBUG) <<
"Loading Tunable registry \n" << config;
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() ;
267 RgKey prefix = iter -> first +
"/";
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]");
322 const Registry & r = this->GetConfig();
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 std::stringstream name;
530 name << comm_name <<
'-' << i <<
"-" << j ;
539 return "Nrow" + comm_name +
's' ;
547 return "Ncol" + comm_name +
's' ;
556 bool is_top_call )
const {
563 bool found = GetParam( n_name, n, is_top_call ) ;
569 for (
int i = 0; i < n; ++i ) {
577 k.push_back( temp_key ) ;
586 bool is_top_call )
const {
590 int n_row = 0, n_col = 0 ;
594 bool found = GetParam( row_name, n_row, is_top_call ) && GetParam( col_name, n_col, is_top_call ) ;
600 for (
int i = 0; i < n_row; ++i ) {
601 for (
int j = 0; j < n_col; ++j ) {
609 k.push_back( temp_key ) ;
625 reg_iter != rgmap.end(); ++reg_iter ) {
627 RgKey reg_key = reg_iter->first;
628 if( reg_key.find(
'/' ) != string::npos)
continue;
636 out -> Set(key_item_pair);
640 if ( out -> NEntries() <= 0 ) {
656 reg_iter != rgmap.end(); ++reg_iter ) {
658 RgKey reg_key = reg_iter->first;
659 if( reg_key.find(alg_key+
"/") == string::npos)
continue;
665 int new_key_start = reg_key.find_first_of(
'/')+1;
666 RgKey new_reg_key = reg_key.substr( new_key_start, reg_key.length() );
670 out -> Set(key_item_pair);
674 if ( out -> NEntries() <= 0 ) {
688 fConfVect.insert( fConfVect.begin(), rp ) ;
689 fOwnerships.insert( fOwnerships.begin(), own ) ;
696 return fConfVect.size() ;
704 fConfVect.push_back( rp ) ;
705 fOwnerships.push_back( own ) ;
712 return fConfVect.size() ;
721 if ( fOwnerships.empty() ) {
725 AddTopRegistry( p ) ;
730 if ( fOwnerships[0] ) {
732 fConfVect[0] -> Merge( r ) ;
739 AddTopRegistry( p ) ;
748 return fConfVect.size() ;
756 fConfVect.insert( fConfVect.begin(), rs.begin(), rs.end() ) ;
758 fOwnerships.insert( fOwnerships.begin(), rs.size(), own ) ;
765 return fConfVect.size() ;
static string BuildParamMatKey(const std::string &comm_name, unsigned int i, unsigned int j)
virtual RegistryItemI * Clone(void) const =0
Registry * GetOwnedConfig(void)
static string BuildParamMatColSizeKey(const std::string &comm_name)
void DeleteSubstructure(void)
int GetParamMatKeys(const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
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
virtual const Registry & GetConfig(void) const
enum genie::EAlgCmp AlgCmp_t
string Name(void) const
get the registry name
static constexpr double second
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)
static string BuildParamMatRowSizeKey(const std::string &comm_name)
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
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)
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
A registry. Provides the container for algorithm configuration parameters.
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
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
virtual RgType_t TypeInfo(void) const =0
The GENIE Algorithm Factory.
map< string, Algorithm * >::iterator AlgMapIter
static string BuildParamVectKey(const std::string &comm_name, unsigned int i)
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