GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gtestAlgorithms.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \program gtestAlgorithms
5 
6 \brief Program used for testing / debugging GENIE's Algorithms & AlgFactory
7 
8 \author Costas Andreopoulos <c.andreopoulos \at cern.ch>
9  University of Liverpool
10 
11 \created October 26, 2006
12 
13 \cpright Copyright (c) 2003-2024, The GENIE Collaboration
14  For the full text of the license visit http://copyright.genie-mc.org
15 
16 */
17 //____________________________________________________________________________
18 
26 
27 using namespace genie;
28 
29 void testReconfigInCommonPool (void);
30 void testReconfigInOwnedModules (void);
31 
32 int main(int /*argc*/, char ** /*argv*/)
33 {
36 
37  return 0;
38 }
39 //____________________________________________________________________________
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
80  algf->ForceReconfiguration();
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 }
86 //____________________________________________________________________________
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
107  AlgFactory * algf = AlgFactory::Instance();
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 }
145 //____________________________________________________________________________
Cross Section Calculation Interface.
void testReconfigInOwnedModules(void)
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
int main(int argc, char **argv)
Definition: gAtmoEvGen.cxx:327
virtual const Registry & GetConfig(void) const
Definition: Algorithm.cxx:246
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void ForceReconfiguration(bool ignore_alg_opt_out=false)
Definition: AlgFactory.cxx:131
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
const Algorithm * GetAlgorithm(const AlgId &algid)
Definition: AlgFactory.cxx:75
#define pINFO
Definition: Messenger.h:62
void AdoptSubstructure(void)
Definition: Algorithm.cxx:400
Algorithm * AdoptAlgorithm(const AlgId &algid) const
Definition: AlgFactory.cxx:116
void testReconfigInCommonPool(void)
void UnLock(void)
unlocks the registry (doesn&#39;t unlock items)
Definition: Registry.cxx:153
Algorithm ID (algorithm name + configuration set name)
Definition: AlgId.h:34
static AlgFactory * Instance()
Definition: AlgFactory.cxx:64
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
Registry * FindRegistry(string key) const
The GENIE Algorithm Factory.
Definition: AlgFactory.h:39
void Set(RgIMapPair entry)
Definition: Registry.cxx:267
static AlgConfigPool * Instance()