All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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::stringAlgTypeAliasesMap
 typedefs and classes More...
 
- Public Types inherited from extends< ComponentManager, IAlgManager >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
- Public Types inherited from CommonMessaging< implements< IComponentManager > >
using base_class = CommonMessaging
 
- 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...
 

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, bool checkIfExists=true) 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::stringname () 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< ComponentManager, IAlgManager >
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::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from ComponentManager
 ComponentManager (IInterface *application, const InterfaceID &baseIID)
 Constructor. More...
 
const InterfaceIDcomponentBaseInterface () const override
 Basic interface id of the managed components. More...
 
StatusCode queryInterface (const InterfaceID &iid, void **pinterface) override
 Specialized queryInterface implementation. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 
StatusCode configure () override
 Configuration (from OFFLINE to CONFIGURED). 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 terminate () override
 Initialization (from CONFIGURED to OFFLINE). 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...
 
Gaudi::StateMachine::State FSMState () const override
 Get the current state. More...
 
Gaudi::StateMachine::State targetFSMState () const override
 When we are in the middle of a transition, get the state where the transition is leading us. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces... >
 ~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
 

Additional Inherited Members

- Protected Member Functions inherited from CommonMessaging< implements< IComponentManager > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from ComponentManager
SmartIF< IInterfacem_application
 Pointer to the owner of the manager. More...
 
SmartIF< IStatefulm_stateful
 Pointer to the IStateful interface of the owner. More...
 
InterfaceID m_basicInterfaceId
 Basic interface id of the managed components. More...
 
SmartIF< ISvcLocatorm_svcLocator
 Service locator (needed to access the MessageSvc) More...
 

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

typedefs and classes

Definition at line 49 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 103 of file AlgorithmManager.cpp.

103  {
104  auto it = std::find(m_algs.begin(), m_algs.end(), typeName.name());
105  if (it != m_algs.end()) { // found
106  return it->algorithm;
107  }
108  if (createIf) {
109  IAlgorithm* alg;
110  if (createAlgorithm(typeName.type(), typeName.name(), alg, true).isSuccess()) {
111  return algorithm(typeName, false);
112  }
113  }
114  return no_algorithm;
115 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:27
T find(T...args)
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, bool checkIfExists=true) override
implementation of IAlgManager::createAlgorithm
StatusCode AlgorithmManager::createAlgorithm ( const std::string algtype,
const std::string algname,
IAlgorithm *&  algorithm,
bool  managed = false,
bool  checkIfExists = true 
)
override

implementation of IAlgManager::createAlgorithm

Definition at line 41 of file AlgorithmManager.cpp.

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

implementation of IAlgManager::existsAlgorithm

Definition at line 118 of file AlgorithmManager.cpp.

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

Finalize (from INITIALIZED to CONFIGURED).

Definition at line 165 of file AlgorithmManager.cpp.

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

implementation of IAlgManager::getAlgorithms

Definition at line 123 of file AlgorithmManager.cpp.

124 {
126  m_listOfPtrs.reserve(m_algs.size());
129  [](const AlgorithmItem& alg) {
130  return const_cast<IAlgorithm*>(alg.algorithm.get());
131  } );
132  return m_listOfPtrs;
133 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
std::vector< IAlgorithm * > m_listOfPtrs
List of pointers to the know services used to implement getAlgorithms()
T end(T...args)
T clear(T...args)
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:27
T begin(T...args)
T back_inserter(T...args)
T transform(T...args)
T reserve(T...args)
StatusCode AlgorithmManager::initialize ( )
override

Initialization (from CONFIGURED to INITIALIZED).

Definition at line 135 of file AlgorithmManager.cpp.

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

Return the name of the manager (implementation of INamedInterface)

Definition at line 84 of file AlgorithmManager.h.

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

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

Definition at line 180 of file AlgorithmManager.cpp.

180  {
181  StatusCode rc;
182  for (auto& it : m_algs ) {
183  if (!it.managed) continue;
184  rc = it.algorithm->sysReinitialize();
185  if( rc.isFailure() ){
186  this->error() << "Unable to re-initialize algorithm: " << it.algorithm->name() << endmsg;
187  return rc;
188  }
189  }
190  return rc;
191 }
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
rc
Definition: IOTest.py:92
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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
T find(T...args)
StatusCode AlgorithmManager::restart ( )
override

Initialization (from RUNNING to RUNNING, via INITIALIZED).

Definition at line 193 of file AlgorithmManager.cpp.

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

Start (from INITIALIZED to RUNNING).

Definition at line 145 of file AlgorithmManager.cpp.

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

Stop (from RUNNING to INITIALIZED).

Definition at line 155 of file AlgorithmManager.cpp.

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

Definition at line 91 of file AlgorithmManager.h.

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

Definition at line 92 of file AlgorithmManager.h.

92 { return m_algTypeAliases; }
AlgTypeAliasesMap m_algTypeAliases

Member Data Documentation

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

algorithms maintained by AlgorithmManager

Definition at line 95 of file AlgorithmManager.h.

AlgTypeAliasesMap AlgorithmManager::m_algTypeAliases
private

Definition at line 100 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 98 of file AlgorithmManager.h.


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