Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
genie::AlgFactory Class Reference

The GENIE Algorithm Factory. More...

#include <AlgFactory.h>

Classes

struct  Cleaner
 singleton cleaner More...
 

Public Member Functions

const AlgorithmGetAlgorithm (const AlgId &algid)
 
const AlgorithmGetAlgorithm (string name, string conf="Default")
 
AlgorithmAdoptAlgorithm (const AlgId &algid) const
 
AlgorithmAdoptAlgorithm (string name, string conf="Default") const
 
void ForceReconfiguration (bool ignore_alg_opt_out=false)
 
void Print (ostream &stream) const
 print algorithm factory More...
 

Static Public Member Functions

static AlgFactoryInstance ()
 

Private Member Functions

 AlgFactory ()
 
 AlgFactory (const AlgFactory &alg_factory)
 
virtual ~AlgFactory ()
 
AlgorithmInstantiateAlgorithm (string name, string config) const
 

Private Attributes

map< string, Algorithm * > fAlgPool
 'algorithm key' (namespace::name/config) -> 'algorithmic object' map More...
 

Static Private Attributes

static AlgFactoryfInstance = 0
 sinleton's self More...
 

Friends

struct Cleaner
 
ostream & operator<< (ostream &stream, const AlgFactory &algf)
 

Detailed Description

The GENIE Algorithm Factory.

Author
Costas Andreopoulos <constantinos.andreopoulos cern.ch> University of Liverpool & STFC Rutherford Appleton Laboratory

May 12, 2004

Copyright (c) 2003-2020, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 39 of file AlgFactory.h.

Constructor & Destructor Documentation

AlgFactory::AlgFactory ( )
private

Definition at line 37 of file AlgFactory.cxx.

38 {
39  fInstance = 0;
40 }
static AlgFactory * fInstance
sinleton&#39;s self
Definition: AlgFactory.h:74
genie::AlgFactory::AlgFactory ( const AlgFactory alg_factory)
private
AlgFactory::~AlgFactory ( )
privatevirtual

Definition at line 42 of file AlgFactory.cxx.

43 {
44 // Clean up and report on the concrete algorithms used in this instance.
45 // Don't clutter output if exiting in err.
46 
48  for(alg_iter = fAlgPool.begin(); alg_iter != fAlgPool.end(); ++alg_iter) {
49  Algorithm * alg = alg_iter->second;
50  if(alg) {
51 /*
52  if(!gAbortingInErr) {
53  cout << "- Deleting algorithm: " << alg->Id() << endl;
54  }
55 */
56  delete alg;
57  alg = 0;
58  }
59  }
60  fAlgPool.clear();
61  fInstance = 0;
62 }
intermediate_table::iterator iterator
Algorithm abstract base class.
Definition: Algorithm.h:53
static AlgFactory * fInstance
sinleton&#39;s self
Definition: AlgFactory.h:74
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -> &#39;algorithmic object&#39; map
Definition: AlgFactory.h:77

Member Function Documentation

Algorithm * AlgFactory::AdoptAlgorithm ( const AlgId algid) const

Like GetAlgorithm() but the algorithm is not placed at the AlgFactory pool and its ownership is transfered to the caller

Hands over an algorithm instance that is owned by the client. The client can alter this object (eg. reconfigure) but the AlgFactory does not keep track of it and the client is responsible for deleting it.

Definition at line 116 of file AlgFactory.cxx.

117 {
118 //! Hands over an algorithm instance that is owned by the client.
119 //! The client can alter this object (eg. reconfigure) but the AlgFactory does
120 //! not keep track of it and the client is responsible for deleting it.
121 
122  return this->AdoptAlgorithm(algid.Name(), algid.Config());
123 }
string Name(void) const
Definition: AlgId.h:44
Algorithm * AdoptAlgorithm(const AlgId &algid) const
Definition: AlgFactory.cxx:116
string Config(void) const
Definition: AlgId.h:45
Algorithm * AlgFactory::AdoptAlgorithm ( string  name,
string  conf = "Default" 
) const

Definition at line 125 of file AlgFactory.cxx.

126 {
127  Algorithm * alg_base = InstantiateAlgorithm(name, config);
128  return alg_base;
129 }
static QCString name
Definition: declinfo.cpp:673
Algorithm abstract base class.
Definition: Algorithm.h:53
static Config * config
Definition: config.cpp:1054
Algorithm * InstantiateAlgorithm(string name, string config) const
Definition: AlgFactory.cxx:151
void AlgFactory::ForceReconfiguration ( bool  ignore_alg_opt_out = false)

Forces a reconfiguration of all algorithms kept at the factory pool. The algorithms look up their nominal configuration from the config pool. Use that to propagate modifications made directly at the config pool.

Definition at line 131 of file AlgFactory.cxx.

132 {
133  LOG("AlgFactory", pNOTICE)
134  << " ** Forcing algorithm re-configuration";
135 
136  map<string, Algorithm *>::iterator alg_iter = fAlgPool.begin();
137  for( ; alg_iter != fAlgPool.end(); ++alg_iter) {
138  Algorithm * alg = alg_iter->second;
139  bool reconfig = (ignore_alg_opt_out) ? true : alg->AllowReconfig();
140  if(reconfig) {
141  string config = alg->Id().Config();
142  bool skip_conf = (config=="NoConfig" || config=="");
143  if(!skip_conf) {
144 // LOG("AlgFactory", pINFO) << "Reconfiguring: " << alg->Id().Key();
145  alg->Configure(config);
146  }
147  }//allow?
148  }
149 }
intermediate_table::iterator iterator
Algorithm abstract base class.
Definition: Algorithm.h:53
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static Config * config
Definition: config.cpp:1054
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:97
virtual bool AllowReconfig(void) const
Definition: Algorithm.h:105
#define pNOTICE
Definition: Messenger.h:61
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -> &#39;algorithmic object&#39; map
Definition: AlgFactory.h:77
string Config(void) const
Definition: AlgId.h:45
const Algorithm * AlgFactory::GetAlgorithm ( const AlgId algid)

Instantiates, configures and returns a pointer to the specified algorithm. The algorithm is placed at the AlgFactory pool (is owned by the factory) from where it will be looked up at subsequent calls.

Manages the instantiation and "storage/retrieval" of algorithms. These algorithms are owned by the factory and it hands over (to the client) a "const Algorithm *" that can be dynamically casted to the requested Algorithm Interface (eg. XSecAlgorithmI, Decayer, PdfModelI, etc...)

Definition at line 75 of file AlgFactory.cxx.

76 {
77 //! Manages the instantiation and "storage/retrieval" of algorithms.
78 //! These algorithms are owned by the factory and it hands over (to the client)
79 //! a "const Algorithm *" that can be dynamically casted to the requested
80 //! Algorithm Interface (eg. XSecAlgorithmI, Decayer, PdfModelI, etc...)
81 
82  return this->GetAlgorithm(algid.Name(), algid.Config());
83 }
string Name(void) const
Definition: AlgId.h:44
const Algorithm * GetAlgorithm(const AlgId &algid)
Definition: AlgFactory.cxx:75
string Config(void) const
Definition: AlgId.h:45
const Algorithm * AlgFactory::GetAlgorithm ( string  name,
string  conf = "Default" 
)

Definition at line 85 of file AlgFactory.cxx.

86 {
87  string key = name + "/" + config;
88 
89  SLOG("AlgFactory", pDEBUG)
90  << "Algorithm: " << key << " requested from AlgFactory";
91 
93  bool found = (alg_iter != fAlgPool.end());
94 
95  if(found) {
96  LOG("AlgFactory", pDEBUG) << key << " algorithm found in memory";
97  return alg_iter->second;
98  } else {
99  //-- instantiate the factory
100  Algorithm * alg_base = this->InstantiateAlgorithm(name,config);
101 
102  //-- cache the algorithm for future use
103  if(alg_base) {
104  pair<string, Algorithm *> key_alg_pair(key, alg_base);
105  fAlgPool.insert(key_alg_pair);
106  } else {
107  LOG("AlgFactory", pFATAL)
108  << "Algorithm: " << key << " could not be instantiated";
109  exit(1);
110  }
111  return alg_base;
112  }
113  return 0;
114 }
static QCString name
Definition: declinfo.cpp:673
#define pFATAL
Definition: Messenger.h:56
Algorithm abstract base class.
Definition: Algorithm.h:53
intermediate_table::const_iterator const_iterator
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
def key(type, name=None)
Definition: graph.py:13
static Config * config
Definition: config.cpp:1054
Algorithm * InstantiateAlgorithm(string name, string config) const
Definition: AlgFactory.cxx:151
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -> &#39;algorithmic object&#39; map
Definition: AlgFactory.h:77
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
#define pDEBUG
Definition: Messenger.h:63
AlgFactory * AlgFactory::Instance ( )
static

Definition at line 64 of file AlgFactory.cxx.

65 {
66  if(fInstance == 0) {
67  static AlgFactory::Cleaner cleaner;
69 
70  fInstance = new AlgFactory;
71  }
72  return fInstance;
73 }
singleton cleaner
Definition: AlgFactory.h:80
static AlgFactory * fInstance
sinleton&#39;s self
Definition: AlgFactory.h:74
Algorithm * AlgFactory::InstantiateAlgorithm ( string  name,
string  config 
) const
private

method instantiating (based on TClass * TROOT::GetClass(name)) & configuring algorithmic objects

Instantiate the requested object based on the registration of its TClass through the generated ROOT dictionaries The class of any object instantiated here must have a LinkDef entry.

Definition at line 151 of file AlgFactory.cxx.

152 {
153 //! Instantiate the requested object based on the registration of its TClass
154 //! through the generated ROOT dictionaries
155 //! The class of any object instantiated here must have a LinkDef entry.
156 
157  // Get object through ROOT's TROOT::GetClass() mechanism
158  LOG("AlgFactory", pDEBUG) << "Instantiating algorithm = " << name;
159 
160  TClass * tclass = gROOT->GetClass(name.c_str());
161  if(!tclass) {
162  LOG("AlgFactory", pERROR)
163  << "Failed instantiating algorithm = " << name;
164  return 0;
165  }
166  void * vd_base = tclass->New();
167  Algorithm * alg_base = (Algorithm *) (vd_base);
168 
169  // Configure the instantiated algorithm
170 
171  LOG("AlgFactory", pDEBUG) << "Setting Configuration Set = " << config;
172 
173  bool skip_conf = (config=="NoConfig" || config=="");
174  if ( skip_conf ) {
175  LOG("AlgFactory", pDEBUG) << "Skipping algorithm configuration step!";
176  } else {
177  alg_base->Configure(config);
178  }
179 
180  return alg_base;
181 }
static QCString name
Definition: declinfo.cpp:673
#define pERROR
Definition: Messenger.h:59
Algorithm abstract base class.
Definition: Algorithm.h:53
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static Config * config
Definition: config.cpp:1054
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
#define pDEBUG
Definition: Messenger.h:63
void AlgFactory::Print ( ostream &  stream) const

print algorithm factory

Definition at line 183 of file AlgFactory.cxx.

184 {
185  string frame(100,'.');
186 
187  stream << endl;
189  for(alg_iter = fAlgPool.begin(); alg_iter != fAlgPool.end(); ++alg_iter) {
190  const Algorithm * alg = alg_iter->second;
191  stream << frame << endl;
192  stream << "Used algorithm: " << alg->Id() << endl;
193  stream << "Printing config:";
194  stream << alg->GetConfig();
195  }
196 
198  const Registry & gc = *(confp->GlobalParameterList());
199 
200  stream << frame << endl;
201  stream << "Printing global parameters list:";
202  stream << gc;
203 }
A singleton class holding all configuration registries built while parsing all loaded XML configurati...
Definition: AlgConfigPool.h:40
Algorithm abstract base class.
Definition: Algorithm.h:53
intermediate_table::const_iterator const_iterator
virtual const Registry & GetConfig(void) const
Definition: Algorithm.cxx:246
Registry * GlobalParameterList(void) const
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:97
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -> &#39;algorithmic object&#39; map
Definition: AlgFactory.h:77
QTextStream & endl(QTextStream &s)
static AlgConfigPool * Instance()

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 89 of file AlgFactory.h.

ostream& operator<< ( ostream &  stream,
const AlgFactory algf 
)
friend

Definition at line 28 of file AlgFactory.cxx.

29  {
30  algf.Print(stream);
31  return stream;
32  }
void Print(ostream &stream) const
print algorithm factory
Definition: AlgFactory.cxx:183

Member Data Documentation

map<string, Algorithm *> genie::AlgFactory::fAlgPool
private

'algorithm key' (namespace::name/config) -> 'algorithmic object' map

Definition at line 77 of file AlgFactory.h.

AlgFactory * AlgFactory::fInstance = 0
staticprivate

sinleton's self

Definition at line 74 of file AlgFactory.h.


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