AlgFactory.h
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \class genie::AlgFactory
5 
6 \brief The GENIE Algorithm Factory.
7 
8 \author Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
9  University of Liverpool & STFC Rutherford Appleton Lab
10 
11 \created May 12, 2004
12 
13 \cpright Copyright (c) 2003-2019, The GENIE Collaboration
14  For the full text of the license visit http://copyright.genie-mc.org
15  or see $GENIE/LICENSE
16 */
17 //____________________________________________________________________________
18 
19 #ifndef _ALG_FACTORY_H_
20 #define _ALG_FACTORY_H_
21 
22 #include <map>
23 #include <string>
24 #include <iostream>
25 
27 
28 using std::map;
29 using std::pair;
30 using std::string;
31 using std::ostream;
32 
33 namespace genie {
34 
35 class Algorithm;
36 class AlgFactory;
37 
38 ostream & operator << (ostream & stream, const genie::AlgFactory & algf);
39 
40 class AlgFactory {
41 
42 public:
43  static AlgFactory * Instance();
44 
45  //! Instantiates, configures and returns a pointer to the specified algorithm.
46  //! The algorithm is placed at the AlgFactory pool (is owned by the factory)
47  //! from where it will be looked up at subsequent calls.
48  const Algorithm * GetAlgorithm (const AlgId & algid);
49  const Algorithm * GetAlgorithm (string name, string conf="Default");
50 
51  //! Like GetAlgorithm() but the algorithm is not placed at the AlgFactory pool
52  //! and its ownership is transfered to the caller
53  Algorithm * AdoptAlgorithm (const AlgId & algid) const;
54  Algorithm * AdoptAlgorithm (string name, string conf="Default") const;
55 
56  //! Forces a reconfiguration of all algorithms kept at the factory pool.
57  //! The algorithms look up their nominal configuration from the config pool.
58  //! Use that to propagate modifications made directly at the config pool.
59  void ForceReconfiguration(bool ignore_alg_opt_out=false);
60 
61  //! print algorithm factory
62  void Print(ostream & stream) const;
63  friend ostream & operator << (ostream & stream, const AlgFactory & algf);
64 
65 private:
66  AlgFactory();
67  AlgFactory(const AlgFactory & alg_factory);
68  virtual ~AlgFactory();
69 
70  //! method instantiating (based on TClass * TROOT::GetClass(name))
71  //! & configuring algorithmic objects
72  Algorithm * InstantiateAlgorithm(string name, string config) const;
73 
74  //! sinleton's self
76 
77  //! 'algorithm key' (namespace::name/config) -> 'algorithmic object' map
78  map<string, Algorithm *> fAlgPool;
79 
80  //! singleton cleaner
81  struct Cleaner {
84  if (AlgFactory::fInstance !=0) {
85  delete AlgFactory::fInstance;
87  }
88  }
89  };
90  friend struct Cleaner;
91 };
92 
93 } // genie namespace
94 
95 #endif // _ALG_FACTORY_H_
const XML_Char * name
Definition: expat.h:151
void Print(ostream &stream) const
print algorithm factory
Definition: AlgFactory.cxx:194
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
friend ostream & operator<<(ostream &stream, const AlgFactory &algf)
Definition: AlgFactory.cxx:39
Algorithm abstract base class.
Definition: Algorithm.h:54
Definition: config.py:1
virtual ~AlgFactory()
Definition: AlgFactory.cxx:53
singleton cleaner
Definition: AlgFactory.h:81
static AlgFactory * fInstance
sinleton&#39;s self
Definition: AlgFactory.h:75
void ForceReconfiguration(bool ignore_alg_opt_out=false)
Definition: AlgFactory.cxx:142
const Algorithm * GetAlgorithm(const AlgId &algid)
Definition: AlgFactory.cxx:86
Algorithm * AdoptAlgorithm(const AlgId &algid) const
Definition: AlgFactory.cxx:127
Algorithm * InstantiateAlgorithm(string name, string config) const
Definition: AlgFactory.cxx:162
Algorithm ID (algorithm name + configuration set name)
Definition: AlgId.h:35
static AlgFactory * Instance()
Definition: AlgFactory.cxx:75
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
The GENIE Algorithm Factory.
Definition: AlgFactory.h:40
map< string, Algorithm * > fAlgPool
&#39;algorithm key&#39; (namespace::name/config) -> &#39;algorithmic object&#39; map
Definition: AlgFactory.h:78
enum BeamMode string