GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>

Collaboration diagram for genie::AlgFactory:
Collaboration graph
[legend]

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 <c.andreopoulos cern.ch> University of Liverpool
Created:
May 12, 2004
License:
Copyright (c) 2003-2024, 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.

References fInstance.

Referenced by Instance().

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.

References fAlgPool, and fInstance.

43 {
44 // Clean up and report on the concrete algorithms used in this instance.
45 // Don't clutter output if exiting in err.
46 
47  map<string, Algorithm *>::iterator alg_iter;
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 }
Algorithm abstract base class.
Definition: Algorithm.h:54
static AlgFactory * fInstance
sinleton&#39;s self
Definition: AlgFactory.h:74
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -&gt; &#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.

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

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

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.

References InstantiateAlgorithm().

126 {
127  Algorithm * alg_base = InstantiateAlgorithm(name, config);
128  return alg_base;
129 }
Algorithm abstract base class.
Definition: Algorithm.h:54
Algorithm * InstantiateAlgorithm(string name, string config) const
Definition: AlgFactory.cxx:151
const char * name
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.

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

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

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 }
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:96
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
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:61
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -&gt; &#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.

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

Referenced by BuildStdNtuple(), CalculateFormFactor(), genie::utils::gsl::d2Xsec_dQ2dv::d2Xsec_dQ2dv(), genie::utils::gsl::dv_dQ2_E::dv_dQ2_E(), GenerateOriginMomentum(), GenerateOriginPosition(), GetAlgorithms(), GetIntranuke(), genie::hnl::FluxCreator::GetProductionProbs(), genie::hnl::selector::GetValidChannelWidths(), HNLGenerator(), genie::NewQELXSec::Integrate(), genie::ReinSehgalRESPXSec::LoadConfig(), genie::BSKLNBaseRESPXSec2014::LoadConfig(), genie::PauliBlocker::LoadModelType(), main(), NeutronOscGenerator(), NucleonDecayGenerator(), genie::utils::nuclear::NuclQELXSecSuppression(), genie::utils::mec::OldTensorContraction(), ReadInConfig(), genie::Algorithm::SubAlg(), TestDecay(), TestPythiaTauDecays(), testReconfigInCommonPool(), and VerticalSlice().

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.

References fAlgPool, InstantiateAlgorithm(), LOG, pDEBUG, pFATAL, and SLOG.

86 {
87  string key = name + "/" + config;
88 
89  SLOG("AlgFactory", pDEBUG)
90  << "Algorithm: " << key << " requested from AlgFactory";
91 
92  map<string, Algorithm *>::const_iterator alg_iter = fAlgPool.find(key);
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 }
#define pFATAL
Definition: Messenger.h:56
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:96
Algorithm * InstantiateAlgorithm(string name, string config) const
Definition: AlgFactory.cxx:151
const char * name
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -&gt; &#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.

References AlgFactory(), genie::AlgFactory::Cleaner::DummyMethodAndSilentCompiler(), and fInstance.

Referenced by genie::Algorithm::AdoptSubstructure(), genie::GEVGDriver::BuildInteractionSelector(), BuildStdNtuple(), genie::utils::gsl::d2Xsec_dQ2dv::d2Xsec_dQ2dv(), genie::utils::gsl::dv_dQ2_E::dv_dQ2_E(), GenerateOriginMomentum(), GenerateOriginPosition(), GetCrossSection(), GetIntranuke(), genie::hnl::FluxCreator::GetProductionProbs(), genie::hnl::selector::GetValidChannelWidths(), HNLGenerator(), genie::NewQELXSec::Integrate(), genie::EmpiricalMECPXSec2015::LoadConfig(), genie::ReinSehgalRESPXSec::LoadConfig(), genie::BSKLNBaseRESPXSec2014::LoadConfig(), genie::PauliBlocker::LoadModelType(), main(), NeutronOscGenerator(), NucleonDecayGenerator(), genie::utils::nuclear::NuclQELXSecSuppression(), genie::utils::mec::OldTensorContraction(), ReadInConfig(), genie::Algorithm::SubAlg(), TestDecay(), TestPythiaTauDecays(), testReconfigInCommonPool(), testReconfigInOwnedModules(), and VerticalSlice().

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.

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

Referenced by AdoptAlgorithm(), and GetAlgorithm().

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 }
#define pERROR
Definition: Messenger.h:59
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:96
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
const char * name
#define pDEBUG
Definition: Messenger.h:63
void AlgFactory::Print ( ostream &  stream) const

print algorithm factory

Definition at line 183 of file AlgFactory.cxx.

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

Referenced by genie::operator<<().

184 {
185  string frame(100,'.');
186 
187  stream << endl;
188  map<string, Algorithm *>::const_iterator alg_iter;
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:54
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:98
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -&gt; &#39;algorithmic object&#39; map
Definition: AlgFactory.h:77
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.

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

AlgFactory * AlgFactory::fInstance = 0
staticprivate

sinleton's self

Definition at line 74 of file AlgFactory.h.

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


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