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 "/cvmfs/nova.opensciencegrid.org/externals/genie/v3_00_06_p01/Linux64bit+2.6-2.12-e17-debug/GENIE-Generator/src/Framework/Algorithm/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 <costas.andreopoulos stfc.ac.uk> University of Liverpool & STFC Rutherford Appleton Lab

May 12, 2004

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

Definition at line 40 of file AlgFactory.h.

Constructor & Destructor Documentation

AlgFactory::AlgFactory ( )
private

Definition at line 48 of file AlgFactory.cxx.

References fInstance.

Referenced by Instance().

49 {
50  fInstance = 0;
51 }
static AlgFactory * fInstance
sinleton&#39;s self
Definition: AlgFactory.h:75
genie::AlgFactory::AlgFactory ( const AlgFactory alg_factory)
private
AlgFactory::~AlgFactory ( )
privatevirtual

Definition at line 53 of file AlgFactory.cxx.

References fAlgPool, and fInstance.

54 {
55 // Clean up and report on the concrete algorithms used in this instance.
56 // Don't clutter output if exiting in err.
57 
58  map<string, Algorithm *>::iterator alg_iter;
59  for(alg_iter = fAlgPool.begin(); alg_iter != fAlgPool.end(); ++alg_iter) {
60  Algorithm * alg = alg_iter->second;
61  if(alg) {
62 /*
63  if(!gAbortingInErr) {
64  cout << "- Deleting algorithm: " << alg->Id() << endl;
65  }
66 */
67  delete alg;
68  alg = 0;
69  }
70  }
71  fAlgPool.clear();
72  fInstance = 0;
73 }
Algorithm abstract base class.
Definition: Algorithm.h:54
static AlgFactory * fInstance
sinleton&#39;s self
Definition: AlgFactory.h:75
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -> &#39;algorithmic object&#39; map
Definition: AlgFactory.h:78

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 127 of file AlgFactory.cxx.

References genie::AlgId::Config(), and genie::AlgId::Name().

Referenced by genie::Algorithm::AdoptSubstructure(), genie::GEVGDriver::BuildInteractionSelector(), GetCrossSection(), main(), and testReconfigInOwnedModules().

128 {
129 //! Hands over an algorithm instance that is owned by the client.
130 //! The client can alter this object (eg. reconfigure) but the AlgFactory does
131 //! not keep track of it and the client is responsible for deleting it.
132 
133  return this->AdoptAlgorithm(algid.Name(), algid.Config());
134 }
string Name(void) const
Definition: AlgId.h:45
Algorithm * AdoptAlgorithm(const AlgId &algid) const
Definition: AlgFactory.cxx:127
string Config(void) const
Definition: AlgId.h:46
Algorithm * AlgFactory::AdoptAlgorithm ( string  name,
string  conf = "Default" 
) const

Definition at line 136 of file AlgFactory.cxx.

References InstantiateAlgorithm().

137 {
138  Algorithm * alg_base = InstantiateAlgorithm(name, config);
139  return alg_base;
140 }
const XML_Char * name
Definition: expat.h:151
Algorithm abstract base class.
Definition: Algorithm.h:54
Definition: config.py:1
Algorithm * InstantiateAlgorithm(string name, string config) const
Definition: AlgFactory.cxx:162
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 142 of file AlgFactory.cxx.

References genie::Algorithm::AllowReconfig(), genie::AlgId::Config(), genie::Algorithm::Configure(), fAlgPool, genie::Algorithm::Id(), LOG, and pNOTICE.

Referenced by IncrementCoefficients(), main(), and testReconfigInCommonPool().

143 {
144  LOG("AlgFactory", pNOTICE)
145  << " ** Forcing algorithm re-configuration";
146 
147  map<string, Algorithm *>::iterator alg_iter = fAlgPool.begin();
148  for( ; alg_iter != fAlgPool.end(); ++alg_iter) {
149  Algorithm * alg = alg_iter->second;
150  bool reconfig = (ignore_alg_opt_out) ? true : alg->AllowReconfig();
151  if(reconfig) {
152  string config = alg->Id().Config();
153  bool skip_conf = (config=="NoConfig" || config=="");
154  if(!skip_conf) {
155 // LOG("AlgFactory", pINFO) << "Reconfiguring: " << alg->Id().Key();
156  alg->Configure(config);
157  }
158  }//allow?
159  }
160 }
Algorithm abstract base class.
Definition: Algorithm.h:54
Definition: config.py:1
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:70
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:98
virtual bool AllowReconfig(void) const
Definition: Algorithm.h:106
#define pNOTICE
Definition: Messenger.h:62
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -> &#39;algorithmic object&#39; map
Definition: AlgFactory.h:78
string Config(void) const
Definition: AlgId.h:46
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 86 of file AlgFactory.cxx.

References genie::AlgId::Config(), and genie::AlgId::Name().

Referenced by BuildStdNtuple(), CalculateFormFactor(), genie::utils::gsl::d2Xsec_dQ2dv::d2Xsec_dQ2dv(), GetAlgorithms(), GetIntranuke(), evgen::GENIENeutronOscGen::initializeNeutronOscGenerator(), genie::NewQELXSec::Integrate(), genie::ReinSehgalRESPXSec::LoadConfig(), genie::BSKLNBaseRESPXSec2014::LoadConfig(), genie::PauliBlocker::LoadModelType(), main(), NeutronOscGenerator(), NucleonDecayGenerator(), genie::utils::nuclear::NuclQELXSecSuppression(), genie::Algorithm::SubAlg(), TestPythiaTauDecays(), testReconfigInCommonPool(), and VerticalSlice().

87 {
88 //! Manages the instantiation and "storage/retrieval" of algorithms.
89 //! These algorithms are owned by the factory and it hands over (to the client)
90 //! a "const Algorithm *" that can be dynamically casted to the requested
91 //! Algorithm Interface (eg. XSecAlgorithmI, Decayer, PdfModelI, etc...)
92 
93  return this->GetAlgorithm(algid.Name(), algid.Config());
94 }
string Name(void) const
Definition: AlgId.h:45
const Algorithm * GetAlgorithm(const AlgId &algid)
Definition: AlgFactory.cxx:86
string Config(void) const
Definition: AlgId.h:46
const Algorithm * AlgFactory::GetAlgorithm ( string  name,
string  conf = "Default" 
)

Definition at line 96 of file AlgFactory.cxx.

References gen_flatrecord::config, exit(), fAlgPool, modifyFHiCL::found, InstantiateAlgorithm(), findDuplicateFiles::key, LOG, pDEBUG, pFATAL, and SLOG.

97 {
98  string key = name + "/" + config;
99 
100  SLOG("AlgFactory", pDEBUG)
101  << "Algorithm: " << key << " requested from AlgFactory";
102 
103  map<string, Algorithm *>::const_iterator alg_iter = fAlgPool.find(key);
104  bool found = (alg_iter != fAlgPool.end());
105 
106  if(found) {
107  LOG("AlgFactory", pDEBUG) << key << " algorithm found in memory";
108  return alg_iter->second;
109  } else {
110  //-- instantiate the factory
111  Algorithm * alg_base = this->InstantiateAlgorithm(name,config);
112 
113  //-- cache the algorithm for future use
114  if(alg_base) {
115  pair<string, Algorithm *> key_alg_pair(key, alg_base);
116  fAlgPool.insert(key_alg_pair);
117  } else {
118  LOG("AlgFactory", pFATAL)
119  << "Algorithm: " << key << " could not be instantiated";
120  exit(1);
121  }
122  return alg_base;
123  }
124  return 0;
125 }
const XML_Char * name
Definition: expat.h:151
#define pFATAL
Definition: Messenger.h:57
Algorithm abstract base class.
Definition: Algorithm.h:54
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
Algorithm * InstantiateAlgorithm(string name, string config) const
Definition: AlgFactory.cxx:162
exit(0)
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -> &#39;algorithmic object&#39; map
Definition: AlgFactory.h:78
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:85
#define pDEBUG
Definition: Messenger.h:64
AlgFactory * AlgFactory::Instance ( )
static
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 162 of file AlgFactory.cxx.

References gen_flatrecord::config, genie::Algorithm::Configure(), LOG, pDEBUG, and pERROR.

Referenced by AdoptAlgorithm(), and GetAlgorithm().

163 {
164 //! Instantiate the requested object based on the registration of its TClass
165 //! through the generated ROOT dictionaries
166 //! The class of any object instantiated here must have a LinkDef entry.
167 
168  // Get object through ROOT's TROOT::GetClass() mechanism
169  LOG("AlgFactory", pDEBUG) << "Instantiating algorithm = " << name;
170 
171  TClass * tclass = gROOT->GetClass(name.c_str());
172  if(!tclass) {
173  LOG("AlgFactory", pERROR)
174  << "Failed instantiating algorithm = " << name;
175  return 0;
176  }
177  void * vd_base = tclass->New();
178  Algorithm * alg_base = (Algorithm *) (vd_base);
179 
180  // Configure the instantiated algorithm
181 
182  LOG("AlgFactory", pDEBUG) << "Setting Configuration Set = " << config;
183 
184  bool skip_conf = (config=="NoConfig" || config=="");
185  if ( skip_conf ) {
186  LOG("AlgFactory", pDEBUG) << "Skipping algorithm configuration step!";
187  } else {
188  alg_base->Configure(config);
189  }
190 
191  return alg_base;
192 }
const XML_Char * name
Definition: expat.h:151
#define pERROR
Definition: Messenger.h:60
Algorithm abstract base class.
Definition: Algorithm.h:54
Definition: config.py:1
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:70
#define pDEBUG
Definition: Messenger.h:64
void AlgFactory::Print ( ostream &  stream) const

print algorithm factory

Definition at line 194 of file AlgFactory.cxx.

References allTimeWatchdog::endl, fAlgPool, genie::Algorithm::GetConfig(), genie::AlgConfigPool::GlobalParameterList(), genie::Algorithm::Id(), and genie::AlgConfigPool::Instance().

Referenced by genie::operator<<().

195 {
196  string frame(100,'.');
197 
198  stream << endl;
199  map<string, Algorithm *>::const_iterator alg_iter;
200  for(alg_iter = fAlgPool.begin(); alg_iter != fAlgPool.end(); ++alg_iter) {
201  const Algorithm * alg = alg_iter->second;
202  stream << frame << endl;
203  stream << "Used algorithm: " << alg->Id() << endl;
204  stream << "Printing config:";
205  stream << alg->GetConfig();
206  }
207 
209  const Registry & gc = *(confp->GlobalParameterList());
210 
211  stream << frame << endl;
212  stream << "Printing global parameters list:";
213  stream << gc;
214 }
A singleton class holding all configuration registries built while parsing all loaded XML configurati...
Definition: AlgConfigPool.h:41
Algorithm abstract base class.
Definition: Algorithm.h:54
virtual const Registry & GetConfig(void) const
Definition: Algorithm.cxx:254
Registry * GlobalParameterList(void) const
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:98
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:66
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -> &#39;algorithmic object&#39; map
Definition: AlgFactory.h:78
static AlgConfigPool * Instance()

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 90 of file AlgFactory.h.

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

Definition at line 39 of file AlgFactory.cxx.

40  {
41  algf.Print(stream);
42  return stream;
43  }
void Print(ostream &stream) const
print algorithm factory
Definition: AlgFactory.cxx:194

Member Data Documentation

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

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

Definition at line 78 of file AlgFactory.h.

Referenced by ForceReconfiguration(), GetAlgorithm(), Print(), and ~AlgFactory().

AlgFactory * AlgFactory::fInstance = 0
staticprivate

sinleton's self

Definition at line 75 of file AlgFactory.h.

Referenced by AlgFactory(), Instance(), genie::operator<<(), ~AlgFactory(), and genie::AlgFactory::Cleaner::~Cleaner().


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