AlgorithmManager Class Reference

The AlgorithmManager class is in charge of the creation of concrete instances of Algorithms. More...

#include <src/ApplicationMgr/AlgorithmManager.h>

Inheritance diagram for AlgorithmManager:
Collaboration diagram for AlgorithmManager:

Classes

struct  AlgorithmItem
 

Public Types

typedef std::map< std::string, std::string > AlgTypeAliasesMap
 typedefs and classes More...
 
- Public Types inherited from extends< BASE, Interfaces >
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Public Member Functions

 AlgorithmManager (IInterface *iface)
 default creator More...
 
 ~AlgorithmManager () override=default
 virtual destructor More...
 
StatusCode addAlgorithm (IAlgorithm *alg) override
 implementation of IAlgManager::addAlgorithm More...
 
StatusCode removeAlgorithm (IAlgorithm *alg) override
 implementation of IAlgManager::removeAlgorithm More...
 
StatusCode createAlgorithm (const std::string &algtype, const std::string &algname, IAlgorithm *&algorithm, bool managed=false) override
 implementation of IAlgManager::createAlgorithm More...
 
bool existsAlgorithm (const std::string &name) const override
 implementation of IAlgManager::existsAlgorithm More...
 
const std::vector< IAlgorithm * > & getAlgorithms () const override
 implementation of IAlgManager::getAlgorithms More...
 
StatusCode initialize () override
 Initialization (from CONFIGURED to INITIALIZED). More...
 
StatusCode start () override
 Start (from INITIALIZED to RUNNING). More...
 
StatusCode stop () override
 Stop (from RUNNING to INITIALIZED). More...
 
StatusCode finalize () override
 Finalize (from INITIALIZED to CONFIGURED). More...
 
StatusCode reinitialize () override
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED). More...
 
StatusCode restart () override
 Initialization (from RUNNING to RUNNING, via INITIALIZED). More...
 
const std::string & name () const override
 Return the name of the manager (implementation of INamedInterface) More...
 
SmartIF< IAlgorithm > & algorithm (const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
 
AlgTypeAliasesMaptypeAliases ()
 
const AlgTypeAliasesMaptypeAliases () const
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Attributes

std::vector< AlgorithmItemm_algs
 algorithms maintained by AlgorithmManager More...
 
std::vector< IAlgorithm * > m_listOfPtrs
 List of pointers to the know services used to implement getAlgorithms() More...
 
AlgTypeAliasesMap m_algTypeAliases
 

Detailed Description

The AlgorithmManager class is in charge of the creation of concrete instances of Algorithms.

The ApplicationMgr delegates the creation and bookkeeping of algorithms to the algorithm factory. In order to be able to create algorithms from which it does not know the concrete type it requires that the algorithm has been declared in one of 3 possible ways: an abstract static creator function, a dynamic link library or an abstract factory reference.

Author
Pere Mato

Definition at line 31 of file AlgorithmManager.h.

Member Typedef Documentation

typedef std::map<std::string, std::string> AlgorithmManager::AlgTypeAliasesMap

typedefs and classes

Definition at line 48 of file AlgorithmManager.h.

Constructor & Destructor Documentation

AlgorithmManager::AlgorithmManager ( IInterface iface)

default creator

Definition at line 18 of file AlgorithmManager.cpp.

18  :
19  base_class(application, IAlgorithm::interfaceID())
20 {
21  addRef(); // Initial count set to 1
22 }
extends base_class
Typedef to this class.
Definition: extends.h:14
AlgorithmManager::~AlgorithmManager ( )
overridedefault

virtual destructor

Member Function Documentation

StatusCode AlgorithmManager::addAlgorithm ( IAlgorithm alg)
override

implementation of IAlgManager::addAlgorithm

Definition at line 25 of file AlgorithmManager.cpp.

25  {
26  m_algs.push_back(alg);
27  return StatusCode::SUCCESS;
28 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
SmartIF< IAlgorithm > & AlgorithmManager::algorithm ( const Gaudi::Utils::TypeNameString typeName,
const bool  createIf = true 
)
override

Definition at line 98 of file AlgorithmManager.cpp.

98  {
99  auto it = std::find(m_algs.begin(), m_algs.end(), typeName.name());
100  if (it != m_algs.end()) { // found
101  return it->algorithm;
102  }
103  if (createIf) {
104  IAlgorithm* alg;
105  if (createAlgorithm(typeName.type(), typeName.name(), alg, true).isSuccess()) {
106  return algorithm(typeName, false);
107  }
108  }
109  return no_algorithm;
110 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:19
const std::string & type() const
SmartIF< IAlgorithm > & algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
const std::string & name() const
StatusCode createAlgorithm(const std::string &algtype, const std::string &algname, IAlgorithm *&algorithm, bool managed=false) override
implementation of IAlgManager::createAlgorithm
StatusCode AlgorithmManager::createAlgorithm ( const std::string &  algtype,
const std::string &  algname,
IAlgorithm *&  algorithm,
bool  managed = false 
)
override

implementation of IAlgManager::createAlgorithm

Definition at line 41 of file AlgorithmManager.cpp.

45 {
46  // Check is the algorithm is already existing
47  if( existsAlgorithm( algname ) ) {
48  // return an error because an algorithm with that name already exists
49  return StatusCode::FAILURE;
50  }
51  std::string actualalgtype(algtype);
52  // a '\' in front of the type name prevents alias replacement
53  if ((actualalgtype.size() > 8) && (actualalgtype.compare(0, 8,"unalias:") == 0)) {
54  actualalgtype = actualalgtype.substr(8);
55  } else {
56  auto typeAlias = m_algTypeAliases.find(algtype);
57  if (typeAlias != m_algTypeAliases.end()) {
58  actualalgtype = typeAlias->second;
59  }
60  }
61  algorithm = Algorithm::Factory::create(actualalgtype, algname, serviceLocator().get());
62  if ( !algorithm ) {
63  this->error() << "Algorithm of type " << actualalgtype
64  << " is unknown (No factory available)." << endmsg;
65 #ifndef _WIN32
66  errno = 0xAFFEDEAD; // code used by Gaudi for library load errors: forces getLastErrorString do use dlerror (on Linux)
67 #endif
68  std::string err = System::getLastErrorString();
69  if (! err.empty()) this->error() << err << endmsg;
70  this->error() << "More information may be available by setting the global jobOpt \"PluginDebugLevel\" to 1" << endmsg;
71  return StatusCode::FAILURE;
72  }
73  // Check the compatibility of the version of the interface obtained
74  if( !isValidInterface(algorithm) ) {
75  fatal() << "Incompatible interface IAlgorithm version for " << actualalgtype << endmsg;
76  return StatusCode::FAILURE;
77  }
78  m_algs.emplace_back(algorithm, managed);
79  // this is needed to keep the reference count correct, since isValidInterface(algorithm)
80  // implies an increment of the counter by 1
81  algorithm->release();
82  StatusCode rc;
83  if ( managed ) {
84  // Bring the created algorithm to the same state of the ApplicationMgr
85  if (FSMState() >= Gaudi::StateMachine::INITIALIZED) {
86  rc = algorithm->sysInitialize();
87  if (rc.isSuccess() && FSMState() >= Gaudi::StateMachine::RUNNING) {
88  rc = algorithm->sysStart();
89  }
90  }
91  if ( !rc.isSuccess() ) {
92  this->error() << "Failed to initialize algorithm: [" << algname << "]" << endmsg;
93  }
94  }
95  return rc;
96 }
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
Definition: IInterface.h:323
virtual StatusCode sysStart()=0
Startup method invoked by the framework.
AlgTypeAliasesMap m_algTypeAliases
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
bool existsAlgorithm(const std::string &name) const override
implementation of IAlgManager::existsAlgorithm
virtual StatusCode sysInitialize()=0
Initialization method invoked by the framework.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
tuple rc
Definition: IOTest.py:92
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:254
bool AlgorithmManager::existsAlgorithm ( const std::string &  name) const
override

implementation of IAlgManager::existsAlgorithm

Definition at line 113 of file AlgorithmManager.cpp.

113  {
114  return m_algs.end() != std::find(m_algs.begin(), m_algs.end(), name);
115 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
StatusCode AlgorithmManager::finalize ( )
override

Finalize (from INITIALIZED to CONFIGURED).

Definition at line 160 of file AlgorithmManager.cpp.

160  {
161  StatusCode rc;
162  auto it = m_algs.begin();
163  while (it != m_algs.end()){ // finalize and remove from the list the managed algorithms
164  if (it->managed) {
165  rc = it->algorithm->sysFinalize();
166  if( rc.isFailure() ) return rc;
167  it = m_algs.erase(it);
168  } else {
169  ++it;
170  }
171  }
172  return rc;
173 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
tuple rc
Definition: IOTest.py:92
const std::vector< IAlgorithm * > & AlgorithmManager::getAlgorithms ( ) const
override

implementation of IAlgManager::getAlgorithms

Definition at line 118 of file AlgorithmManager.cpp.

119 {
120  m_listOfPtrs.clear();
121  m_listOfPtrs.reserve(m_algs.size());
122  std::transform( std::begin(m_algs), std::end(m_algs),
123  std::back_inserter(m_listOfPtrs),
124  [](const AlgorithmItem& alg) {
125  return const_cast<IAlgorithm*>(alg.algorithm.get());
126  } );
127  return m_listOfPtrs;
128 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
std::vector< IAlgorithm * > m_listOfPtrs
List of pointers to the know services used to implement getAlgorithms()
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:19
StatusCode AlgorithmManager::initialize ( )
override

Initialization (from CONFIGURED to INITIALIZED).

Definition at line 130 of file AlgorithmManager.cpp.

130  {
131  StatusCode rc;
132  for (auto& it : m_algs ) {
133  if (!it.managed) continue;
134  rc = it.algorithm->sysInitialize();
135  if ( rc.isFailure() ) return rc;
136  }
137  return rc;
138 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
tuple rc
Definition: IOTest.py:92
const std::string& AlgorithmManager::name ( ) const
inlineoverride

Return the name of the manager (implementation of INamedInterface)

Definition at line 83 of file AlgorithmManager.h.

83  {
84  static const std::string _name = "AlgorithmManager";
85  return _name;
86  }
StatusCode AlgorithmManager::reinitialize ( )
override

Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).

Definition at line 175 of file AlgorithmManager.cpp.

175  {
176  StatusCode rc;
177  for (auto& it : m_algs ) {
178  if (!it.managed) continue;
179  rc = it.algorithm->sysReinitialize();
180  if( rc.isFailure() ){
181  this->error() << "Unable to re-initialize algorithm: " << it.algorithm->name() << endmsg;
182  return rc;
183  }
184  }
185  return rc;
186 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
tuple rc
Definition: IOTest.py:92
StatusCode AlgorithmManager::removeAlgorithm ( IAlgorithm alg)
override

implementation of IAlgManager::removeAlgorithm

Definition at line 31 of file AlgorithmManager.cpp.

31  {
32  auto it = std::find(m_algs.begin(), m_algs.end(), alg);
33  if (it != m_algs.end()) {
34  m_algs.erase(it);
35  return StatusCode::SUCCESS;
36  }
37  return StatusCode::FAILURE;
38 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
StatusCode AlgorithmManager::restart ( )
override

Initialization (from RUNNING to RUNNING, via INITIALIZED).

Definition at line 188 of file AlgorithmManager.cpp.

188  {
189  StatusCode rc;
190  for (auto& it : m_algs ) {
191  if (!it.managed) continue;
192  rc = it.algorithm->sysRestart();
193  if( rc.isFailure() ){
194  this->error() << "Unable to re-initialize algorithm: " << it.algorithm->name() << endmsg;
195  return rc;
196  }
197  }
198  return rc;
199 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
tuple rc
Definition: IOTest.py:92
StatusCode AlgorithmManager::start ( )
override

Start (from INITIALIZED to RUNNING).

Definition at line 140 of file AlgorithmManager.cpp.

140  {
141  StatusCode rc;
142  for (auto& it : m_algs ) {
143  if (!it.managed) continue;
144  rc = it.algorithm->sysStart();
145  if ( rc.isFailure() ) return rc;
146  }
147  return rc;
148 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
tuple rc
Definition: IOTest.py:92
StatusCode AlgorithmManager::stop ( )
override

Stop (from RUNNING to INITIALIZED).

Definition at line 150 of file AlgorithmManager.cpp.

150  {
151  StatusCode rc;
152  for (auto& it : m_algs) {
153  if (!it.managed) continue;
154  rc = it.algorithm->sysStop();
155  if ( rc.isFailure() ) return rc;
156  }
157  return rc;
158 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
tuple rc
Definition: IOTest.py:92
AlgTypeAliasesMap& AlgorithmManager::typeAliases ( )
inline

Definition at line 90 of file AlgorithmManager.h.

90 { return m_algTypeAliases; }
AlgTypeAliasesMap m_algTypeAliases
const AlgTypeAliasesMap& AlgorithmManager::typeAliases ( ) const
inline

Definition at line 91 of file AlgorithmManager.h.

91 { return m_algTypeAliases; }
AlgTypeAliasesMap m_algTypeAliases

Member Data Documentation

std::vector<AlgorithmItem> AlgorithmManager::m_algs
private

algorithms maintained by AlgorithmManager

Definition at line 94 of file AlgorithmManager.h.

AlgTypeAliasesMap AlgorithmManager::m_algTypeAliases
private

Definition at line 99 of file AlgorithmManager.h.

std::vector<IAlgorithm*> AlgorithmManager::m_listOfPtrs
mutableprivate

List of pointers to the know services used to implement getAlgorithms()

Definition at line 97 of file AlgorithmManager.h.


The documentation for this class was generated from the following files: