GENIEGenerator
Loading...
Searching...
No Matches
gtestAlgorithms.cxx File Reference
Include dependency graph for gtestAlgorithms.cxx:

Go to the source code of this file.

Functions

void testReconfigInCommonPool (void)
void testReconfigInOwnedModules (void)
int main (int, char **)

Function Documentation

◆ main()

int main ( int ,
char **  )

Definition at line 32 of file gtestAlgorithms.cxx.

33{
36
37 return 0;
38}
void testReconfigInOwnedModules(void)
void testReconfigInCommonPool(void)

References testReconfigInCommonPool(), and testReconfigInOwnedModules().

◆ testReconfigInCommonPool()

void testReconfigInCommonPool ( void )

Definition at line 40 of file gtestAlgorithms.cxx.

41{
42// Test reconfiguration of algorithms in common pool
43// (AP: algorithm factory pool, CP: configuration pool)
44//
45// The test function access an algorithm stored in the AP & then access the
46// configuration registry that the algorithm is looking up at the CP.
47// Then it modifies the configuration stored at the CP, and forces all
48// algorithms stored at the AP to reconfigure themselves.
49//
50// Reconfiguring common pool objects makes it easier to guarantee consistency:
51// Eg say that you have a low-level algorithm stored at the AP that is
52// referenced by many higher-level objects, also stored at the AP.
53// Reconfiguring this instance of the low-level algorithms **automatically**
54// guarantees that all high-level algorithms use the reconfigured version.
55// This does *not* require you to know which high-level algorithms are
56// pointing to which low-level algorithms which is typically difficult to
57// keep track of
58
59 // get the algorithm factory & config pool
62
63 // instantiate some algorithms
64 LOG("test", pINFO) << "Instantiate a concrete algorithm";
65 AlgId id("genie::QELPXSec","CC-Default");
66 const Algorithm * alg = algf->GetAlgorithm(id);
67 LOG("test", pINFO) << *alg;
68
69 LOG("test", pINFO) << "Access its configuration at the config pool";
70 Registry * r = cnfp->FindRegistry(alg);
71 r->UnLock();
72 LOG("test", pINFO) << *r;
73
74 // modify configuration
75 LOG("test", pINFO) << "Modifying registry";
76 r->Set("CabbiboAngle",0.25);
77 LOG("test", pINFO) << *r;
78
79 // force reconfiguration
81
82 // print all algorithms stored at the algorithm factory pool (for now just 1)
83 // & their configurations to verify that the change was propagated correctly
84 LOG("test", pINFO) << *algf;
85}
#define pINFO
Definition Messenger.h:62
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
A singleton class holding all configuration registries built while parsing all loaded XML configurati...
Registry * FindRegistry(string key) const
static AlgConfigPool * Instance()
The GENIE Algorithm Factory.
Definition AlgFactory.h:39
const Algorithm * GetAlgorithm(const AlgId &algid)
static AlgFactory * Instance()
void ForceReconfiguration(bool ignore_alg_opt_out=false)
Algorithm ID (algorithm name + configuration set name)
Definition AlgId.h:34
Algorithm abstract base class.
Definition Algorithm.h:54
A registry. Provides the container for algorithm configuration parameters.
Definition Registry.h:65
void Set(RgIMapPair entry)
Definition Registry.cxx:267
void UnLock(void)
unlocks the registry (doesn't unlock items)
Definition Registry.cxx:153

References genie::AlgConfigPool::FindRegistry(), genie::AlgFactory::ForceReconfiguration(), genie::AlgFactory::GetAlgorithm(), genie::AlgConfigPool::Instance(), genie::AlgFactory::Instance(), LOG, pINFO, genie::Registry::Set(), and genie::Registry::UnLock().

Referenced by main().

◆ testReconfigInOwnedModules()

void testReconfigInOwnedModules ( void )

Definition at line 87 of file gtestAlgorithms.cxx.

88{
89// Test reconfiguration of owned "algorithm/configuration blocks"
90//
91// In GENIE it is possible to take ownership of an algorithms and its
92// subtructure (all the sub-algorithms it is referencing) by extracting (clones
93// of) them from the AlgFactory pool to a local pool. The owned algorithms are
94// also forced to take ownership of their configurations. All the configuration
95// variables are bundled together at the top level algorithms' configuration.
96//
97// Having a group of algorithms/configurations behaving as a monolithic block,
98// with a single point of configuration (the top level) is to be used when bits
99// & pieces of GENIE are used in isolation for data fitting or reweighting
100//
101// For more details and information on the naming convention used when all
102// sub-algorithms configurations are merged to the top level algorithm config
103// see the Algorithm package
104//
105
106 // get the algorithm factory & config pool
108
109 // instantiate some algorithms
110 LOG("test", pINFO) << "Instantiate a concrete algorithm";
111 AlgId id("genie::QELPXSec","CC-Default");
112 Algorithm * alg = algf->AdoptAlgorithm(id);
113 XSecAlgorithmI * xsecalg = dynamic_cast<XSecAlgorithmI*>(alg);
114
115 LOG("test", pINFO) << *xsecalg;
116
117 LOG("test", pINFO) << "Adopting substructure";
118 xsecalg->AdoptSubstructure();
119
120 LOG("test", pINFO) << *xsecalg;
121
122 // access the top level algorithm registry where all the config params
123 // (including config params of all the referenced sub-algs have been
124 // bundled) following a special naming convention
125 //
126 LOG("test", pINFO) << "Taking a clone of the deep config registry:";
127 Registry r(xsecalg->GetConfig());
128 LOG("test", pINFO) << r;
129
130 LOG("test", pINFO) << "Modifying parameters at the deep registry";
131 r.Set("CabbiboAngle", 0.23); // refers to top level alg
132 r.Set("FormFactorsAlg/MuN", -1.92); // refers to an alg 1-level deep
133 r.Set("FormFactorsAlg/ElFormFactorsAlg/MuN",-1.92); // refers to an alg 2-level deep
134
135 LOG("test", pINFO) << "Modified deep config registry:";
136 LOG("test", pINFO) << r;
137
138 // This would reconfigure the top level algorithm and then, in a recursive
139 // mode, all owned sub-algorithms will be reconfigured and then their owned
140 // sub-algorithms and so on, however complex the algorithm strucure
141 xsecalg->Configure(r);
142
143 LOG("test", pINFO) << *xsecalg;
144}
Algorithm * AdoptAlgorithm(const AlgId &algid) const
void AdoptSubstructure(void)
virtual const Registry & GetConfig(void) const
virtual void Configure(const Registry &config)
Definition Algorithm.cxx:62
Cross Section Calculation Interface.

References genie::AlgFactory::AdoptAlgorithm(), genie::Algorithm::AdoptSubstructure(), genie::Algorithm::Configure(), genie::Algorithm::GetConfig(), genie::AlgFactory::Instance(), LOG, pINFO, and genie::Registry::Set().

Referenced by main().