GENIEGenerator
Loading...
Searching...
No Matches
genie::AlgFactory Class Reference

The GENIE Algorithm Factory. More...

#include <AlgFactory.h>

Collaboration diagram for genie::AlgFactory:
[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

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

Static Private Attributes

static AlgFactoryfInstance = 0
 sinleton's self

Friends

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

Detailed Description

The GENIE Algorithm Factory.

Author
Costas Andreopoulos <c.andreopoulos \at cern.ch> University of Liverpool
Created:\n May 12, 2004
License:\n Copyright (c) 2003-2025, 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() [1/2]

AlgFactory::AlgFactory ( )
private

Definition at line 37 of file AlgFactory.cxx.

38{
39 fInstance = 0;
40}
static AlgFactory * fInstance
sinleton's self
Definition AlgFactory.h:74

References fInstance.

Referenced by AlgFactory(), Instance(), and operator<<.

◆ AlgFactory() [2/2]

genie::AlgFactory::AlgFactory ( const AlgFactory & alg_factory)
private

References AlgFactory().

◆ ~AlgFactory()

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
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}
map< string, Algorithm * > fAlgPool
'algorithm key' (namespace::name/config) -> 'algorithmic object' map
Definition AlgFactory.h:77

References fAlgPool, and fInstance.

Member Function Documentation

◆ AdoptAlgorithm() [1/2]

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}
Algorithm * AdoptAlgorithm(const AlgId &algid) const
string Config(void) const
Definition AlgId.h:45
string Name(void) const
Definition AlgId.h:44

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

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

◆ AdoptAlgorithm() [2/2]

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}
Algorithm * InstantiateAlgorithm(string name, string config) const

References InstantiateAlgorithm().

◆ ForceReconfiguration()

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}
#define pNOTICE
Definition Messenger.h:61
#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

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

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

◆ GetAlgorithm() [1/2]

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}
const Algorithm * GetAlgorithm(const AlgId &algid)

References genie::AlgId::Config(), GetAlgorithm(), 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(), GeneratePosition(), GetAlgorithm(), GetAlgorithms(), GetCommandLineArgs(), GetIntranuke(), genie::hnl::FluxCreator::GetProductionProbs(), HNLGenerator(), genie::NewQELXSec::Integrate(), genie::BSKLNBaseRESPXSec2014::LoadConfig(), genie::ReinSehgalRESPXSec::LoadConfig(), genie::PauliBlocker::LoadModelType(), main(), main(), NeutronOscGenerator(), NucleonDecayGenerator(), genie::utils::nuclear::NuclQELXSecSuppression(), genie::utils::mec::OldTensorContraction(), ReadInConfig(), genie::Algorithm::SubAlg(), TestDecay(), TestPythiaTauDecays(), testReconfigInCommonPool(), and VerticalSlice().

◆ GetAlgorithm() [2/2]

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
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
#define pDEBUG
Definition Messenger.h:63
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition Messenger.h:84

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

◆ Instance()

AlgFactory * AlgFactory::Instance ( )
static

Definition at line 64 of file AlgFactory.cxx.

65{
66 if(fInstance == 0) {
67 static AlgFactory::Cleaner cleaner;
69
71 }
72 return fInstance;
73}
friend struct Cleaner
Definition AlgFactory.h:89

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(), GeneratePosition(), GetAlgorithms(), GetCommandLineArgs(), GetCrossSection(), GetIntranuke(), genie::hnl::FluxCreator::GetProductionProbs(), genie::hnl::selector::GetValidChannelWidths(), HNLGenerator(), genie::NewQELXSec::Integrate(), genie::BSKLNBaseRESPXSec2014::LoadConfig(), genie::EmpiricalMECPXSec2015::LoadConfig(), genie::ReinSehgalRESPXSec::LoadConfig(), genie::PauliBlocker::LoadModelType(), main(), main(), NeutronOscGenerator(), NucleonDecayGenerator(), genie::utils::nuclear::NuclQELXSecSuppression(), genie::utils::mec::OldTensorContraction(), ReadInConfig(), genie::Algorithm::SubAlg(), TestDecay(), TestPythiaTauDecays(), testReconfigInCommonPool(), testReconfigInOwnedModules(), and VerticalSlice().

◆ InstantiateAlgorithm()

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}
#define pERROR
Definition Messenger.h:59

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

Referenced by AdoptAlgorithm(), and GetAlgorithm().

◆ Print()

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;
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
197 AlgConfigPool * confp = AlgConfigPool::Instance();
198 const Registry & gc = *(confp->GlobalParameterList());
199
200 stream << frame << endl;
201 stream << "Printing global parameters list:";
202 stream << gc;
203}
static AlgConfigPool * Instance()
Registry * GlobalParameterList(void) const
virtual const Registry & GetConfig(void) const

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

Referenced by operator<<.

◆ Cleaner

friend struct Cleaner
friend

Definition at line 89 of file AlgFactory.h.

◆ operator<<

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

References AlgFactory(), and Print().

Member Data Documentation

◆ fAlgPool

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().

◆ fInstance

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: