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