The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
AlgorithmManager Class Reference

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

#include </builds/gaudi/Gaudi/GaudiCoreSvc/src/ApplicationMgr/AlgorithmManager.h>

Inheritance diagram for AlgorithmManager:
Collaboration diagram for AlgorithmManager:

Classes

struct  AlgorithmItem
 

Public Types

typedef std::map< std::string, std::string, std::less<> > AlgTypeAliasesMap
 typedefs and classes
 
- Public Types inherited from extends< ComponentManager, IAlgManager >
using base_class
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
- Public Types inherited from CommonMessaging< implements< IComponentManager > >
using base_class
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 

Public Member Functions

 AlgorithmManager (IInterface *iface)
 default creator
 
StatusCode addAlgorithm (IAlgorithm *alg) override
 implementation of IAlgManager::addAlgorithm
 
StatusCode removeAlgorithm (IAlgorithm *alg) override
 implementation of IAlgManager::removeAlgorithm
 
StatusCode createAlgorithm (const std::string &algtype, const std::string &algname, IAlgorithm *&algorithm, bool managed=false, bool checkIfExists=true) override
 implementation of IAlgManager::createAlgorithm
 
bool existsAlgorithm (std::string_view name) const override
 implementation of IAlgManager::existsAlgorithm
 
std::vector< IAlgorithm * > getAlgorithms () const override
 implementation of IAlgManager::getAlgorithms
 
StatusCode initialize () override
 Initialization (from CONFIGURED to INITIALIZED).
 
StatusCode start () override
 Start (from INITIALIZED to RUNNING).
 
StatusCode stop () override
 Stop (from RUNNING to INITIALIZED).
 
StatusCode finalize () override
 Finalize (from INITIALIZED to CONFIGURED).
 
StatusCode reinitialize () override
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
 
StatusCode restart () override
 Initialization (from RUNNING to RUNNING, via INITIALIZED).
 
const std::string & name () const override
 Return the name of the manager (implementation of INamedInterface)
 
SmartIF< IAlgorithm > & algorithm (const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
 
AlgTypeAliasesMaptypeAliases ()
 
const AlgTypeAliasesMaptypeAliases () const
 
void outputLevelUpdate () override
 Function to call to update the outputLevel of the components (after a change in MessageSvc).
 
- Public Member Functions inherited from extends< ComponentManager, IAlgManager >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
- Public Member Functions inherited from ComponentManager
 ComponentManager (IInterface *application, const InterfaceID &baseIID)
 Constructor.
 
const InterfaceIDcomponentBaseInterface () const override
 Basic interface id of the managed components.
 
void const * i_cast (const InterfaceID &iid) const override
 Specialized i_cast implementation.
 
SmartIF< ISvcLocator > & serviceLocator () const override
 
StatusCode configure () override
 Configuration (from OFFLINE to CONFIGURED).
 
StatusCode initialize () override
 Initialization (from CONFIGURED to INITIALIZED).
 
StatusCode start () override
 Start (from INITIALIZED to RUNNING).
 
StatusCode stop () override
 Stop (from RUNNING to INITIALIZED).
 
StatusCode finalize () override
 Finalize (from INITIALIZED to CONFIGURED).
 
StatusCode terminate () override
 Initialization (from CONFIGURED to OFFLINE).
 
StatusCode reinitialize () override
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
 
StatusCode restart () override
 Initialization (from RUNNING to RUNNING, via INITIALIZED).
 
Gaudi::StateMachine::State FSMState () const override
 Get the current state.
 
Gaudi::StateMachine::State targetFSMState () const override
 When we are in the middle of a transition, get the state where the transition is leading us.
 
- Public Member Functions inherited from CommonMessaging< implements< IComponentManager > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 

Private Attributes

std::vector< AlgorithmItemm_algs
 algorithms maintained by AlgorithmManager
 
std::unordered_multimap< std::string, SmartIF< IAlgorithm > > m_algsMap
 algorithms maintained by AlgorithmManager
 
AlgTypeAliasesMap m_algTypeAliases
 

Additional Inherited Members

- Protected Member Functions inherited from CommonMessaging< implements< IComponentManager > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 
- Protected Attributes inherited from ComponentManager
SmartIF< IInterfacem_application
 Pointer to the owner of the manager.
 
SmartIF< IStatefulm_stateful
 Pointer to the IStateful interface of the owner.
 
InterfaceID m_basicInterfaceId
 Basic interface id of the managed components.
 
SmartIF< ISvcLocatorm_svcLocator
 Service locator (needed to access the MessageSvc)
 
friend ApplicationMgr
 

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 39 of file AlgorithmManager.h.

Member Typedef Documentation

◆ AlgTypeAliasesMap

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

typedefs and classes

Definition at line 49 of file AlgorithmManager.h.

Constructor & Destructor Documentation

◆ AlgorithmManager()

AlgorithmManager::AlgorithmManager ( IInterface * iface)

default creator

Definition at line 25 of file AlgorithmManager.cpp.

25 : base_class( application, IAlgorithm::interfaceID() ) {
26 addRef(); // Initial count set to 1
27}

Member Function Documentation

◆ addAlgorithm()

StatusCode AlgorithmManager::addAlgorithm ( IAlgorithm * alg)
override

implementation of IAlgManager::addAlgorithm

Definition at line 29 of file AlgorithmManager.cpp.

29 {
30 m_algs.push_back( alg );
31 m_algsMap.emplace( alg->name(), alg );
33}
std::vector< AlgorithmItem > m_algs
algorithms maintained by AlgorithmManager
std::unordered_multimap< std::string, SmartIF< IAlgorithm > > m_algsMap
algorithms maintained by AlgorithmManager
constexpr static const auto SUCCESS
Definition StatusCode.h:99

◆ algorithm()

SmartIF< IAlgorithm > & AlgorithmManager::algorithm ( const Gaudi::Utils::TypeNameString & typeName,
const bool createIf = true )
override

Definition at line 92 of file AlgorithmManager.cpp.

92 {
93 auto it = m_algsMap.find( typeName.name() );
94 if ( it != m_algsMap.end() ) { // found
95 return it->second;
96 }
97 if ( createIf ) {
98 IAlgorithm* alg;
99 if ( createAlgorithm( typeName.type(), typeName.name(), alg, true ).isSuccess() ) {
100 return algorithm( typeName, false );
101 }
102 }
103 return no_algorithm;
104}
SmartIF< IAlgorithm > & algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
StatusCode createAlgorithm(const std::string &algtype, const std::string &algname, IAlgorithm *&algorithm, bool managed=false, bool checkIfExists=true) override
implementation of IAlgManager::createAlgorithm
bool isSuccess() const
Definition StatusCode.h:314
std::string typeName(const std::type_info &typ)

◆ 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 48 of file AlgorithmManager.cpp.

49 {
50 // Check if the algorithm is already existing
51 if ( checkIfExists ) {
52 if ( existsAlgorithm( algname ) ) {
53 // return an error because an algorithm with that name already exists
55 }
56 }
57 std::string actualalgtype( algtype );
58 // a '\' in front of the type name prevents alias replacement
59 if ( ( actualalgtype.size() > 8 ) && ( actualalgtype.compare( 0, 8, "unalias:" ) == 0 ) ) {
60 actualalgtype = actualalgtype.substr( 8 );
61 } else {
62 auto typeAlias = m_algTypeAliases.find( algtype );
63 if ( typeAlias != m_algTypeAliases.end() ) { actualalgtype = typeAlias->second; }
64 }
65 algorithm = Gaudi::Algorithm::Factory::create( actualalgtype, algname, serviceLocator().get() ).release();
66 if ( !algorithm ) {
67 this->error() << "Algorithm of type " << actualalgtype << " is unknown (No factory available)." << endmsg;
68 errno =
69 0xAFFEDEAD; // code used by Gaudi for library load errors: forces getLastErrorString do use dlerror (on Linux)
70 std::string err = System::getLastErrorString();
71 if ( !err.empty() ) this->error() << err << endmsg;
72 this->error() << "More information may be available by setting the global jobOpt \"PluginDebugLevel\" to 1"
73 << endmsg;
75 }
76 m_algs.emplace_back( algorithm, managed );
77 m_algsMap.emplace( algorithm->name(), algorithm );
78 // let the algorithm know its type
79 algorithm->setType( std::move( actualalgtype ) );
80 StatusCode rc;
81 if ( managed ) {
82 // Bring the created algorithm to the target state of the ApplicationMgr
84 rc = algorithm->sysInitialize();
85 if ( rc.isSuccess() && targetFSMState() >= Gaudi::StateMachine::RUNNING ) { rc = algorithm->sysStart(); }
86 }
87 if ( !rc.isSuccess() ) { this->error() << "Failed to initialize algorithm: [" << algname << "]" << endmsg; }
88 }
89 return rc;
90}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
AlgTypeAliasesMap m_algTypeAliases
bool existsAlgorithm(std::string_view name) const override
implementation of IAlgManager::existsAlgorithm
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
Gaudi::StateMachine::State targetFSMState() const override
When we are in the middle of a transition, get the state where the transition is leading us.
SmartIF< ISvcLocator > & serviceLocator() const override
constexpr static const auto FAILURE
Definition StatusCode.h:100
get
decorate the vector of properties
Definition decorators.py:94
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition System.cpp:234

◆ existsAlgorithm()

bool AlgorithmManager::existsAlgorithm ( std::string_view name) const
override

implementation of IAlgManager::existsAlgorithm

Definition at line 106 of file AlgorithmManager.cpp.

106 {
107 return m_algsMap.find( std::string( name ) ) != m_algsMap.end();
108}
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)

◆ finalize()

StatusCode AlgorithmManager::finalize ( )
override

Finalize (from INITIALIZED to CONFIGURED).

Definition at line 148 of file AlgorithmManager.cpp.

148 {
149 StatusCode rc;
150 auto it = m_algs.begin();
151 while ( it != m_algs.end() ) { // finalize and remove from the list the managed algorithms
152 if ( it->managed ) {
153 auto range = m_algsMap.equal_range( it->algorithm->name() );
154 auto itm = std::find_if( range.first, range.second, [&]( auto const& p ) { return p.second == it->algorithm; } );
155 if ( itm == range.second ) { return StatusCode::FAILURE; }
156
157 rc = it->algorithm->sysFinalize();
158 if ( rc.isFailure() ) return rc;
159
160 it = m_algs.erase( it );
161 m_algsMap.erase( itm );
162 } else {
163 ++it;
164 }
165 }
166 return rc;
167}
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition details.h:81

◆ getAlgorithms()

std::vector< IAlgorithm * > AlgorithmManager::getAlgorithms ( ) const
override

implementation of IAlgManager::getAlgorithms

Definition at line 110 of file AlgorithmManager.cpp.

110 {
111 std::vector<IAlgorithm*> listOfPtrs;
112 listOfPtrs.reserve( m_algs.size() );
113 std::transform( std::begin( m_algs ), std::end( m_algs ), std::back_inserter( listOfPtrs ),
114 []( const AlgorithmItem& alg ) { return alg.algorithm; } );
115 return listOfPtrs;
116}

◆ initialize()

StatusCode AlgorithmManager::initialize ( )
override

Initialization (from CONFIGURED to INITIALIZED).

Definition at line 118 of file AlgorithmManager.cpp.

118 {
119 StatusCode rc;
120 for ( auto& it : m_algs ) {
121 if ( !it.managed || it.algorithm->FSMState() >= Gaudi::StateMachine::INITIALIZED ) continue;
122 rc = it.algorithm->sysInitialize();
123 if ( rc.isFailure() ) return rc;
124 }
125 return rc;
126}

◆ name()

const std::string & AlgorithmManager::name ( ) const
inlineoverride

Return the name of the manager (implementation of INamedInterface)

Definition at line 82 of file AlgorithmManager.h.

82 {
83 static const std::string _name = "AlgorithmManager";
84 return _name;
85 }

◆ outputLevelUpdate()

void AlgorithmManager::outputLevelUpdate ( )
override

Function to call to update the outputLevel of the components (after a change in MessageSvc).

Definition at line 204 of file AlgorithmManager.cpp.

204 {
206 for ( auto& algItem : m_algs ) {
207 const auto alg = dynamic_cast<Gaudi::Algorithm*>( algItem.algorithm );
208 if ( alg ) alg->resetMessaging();
209 }
210}

◆ reinitialize()

StatusCode AlgorithmManager::reinitialize ( )
override

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

Definition at line 169 of file AlgorithmManager.cpp.

169 {
170 StatusCode rc;
171 for ( auto& it : m_algs ) {
172 if ( !it.managed ) continue;
173 rc = it.algorithm->sysReinitialize();
174 if ( rc.isFailure() ) {
175 this->error() << "Unable to re-initialize algorithm: " << it.algorithm->name() << endmsg;
176 return rc;
177 }
178 }
179 return rc;
180}

◆ removeAlgorithm()

StatusCode AlgorithmManager::removeAlgorithm ( IAlgorithm * alg)
override

implementation of IAlgManager::removeAlgorithm

Definition at line 35 of file AlgorithmManager.cpp.

35 {
36 auto it = std::find( m_algs.begin(), m_algs.end(), alg );
37 if ( it == m_algs.end() ) { return StatusCode::FAILURE; }
38
39 auto range = m_algsMap.equal_range( alg->name() );
40 auto itm = std::find_if( range.first, range.second, [&]( auto const& p ) { return p.second == alg; } );
41 if ( itm == range.second ) { return StatusCode::FAILURE; }
42
43 m_algs.erase( it );
44 m_algsMap.erase( itm );
46}

◆ restart()

StatusCode AlgorithmManager::restart ( )
override

Initialization (from RUNNING to RUNNING, via INITIALIZED).

Definition at line 182 of file AlgorithmManager.cpp.

182 {
183 SmartIF<IAlgExecStateSvc> m_aess;
184 m_aess = serviceLocator()->service( "AlgExecStateSvc" );
185 if ( !m_aess.isValid() ) {
186 fatal() << "Error retrieving AlgExecStateSvc" << endmsg;
187 return StatusCode::FAILURE;
188 }
189
190 StatusCode rc;
191
192 for ( auto& it : m_algs ) {
193 if ( !it.managed ) continue;
194 rc = it.algorithm->sysRestart();
195 m_aess->resetErrorCount( it.algorithm );
196 if ( rc.isFailure() ) {
197 this->error() << "Unable to re-initialize algorithm: " << it.algorithm->name() << endmsg;
198 return rc;
199 }
200 }
201 return rc;
202}
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
bool isValid() const
Allow for check if smart pointer is valid.
Definition SmartIF.h:69

◆ start()

StatusCode AlgorithmManager::start ( )
override

Start (from INITIALIZED to RUNNING).

Definition at line 128 of file AlgorithmManager.cpp.

128 {
129 StatusCode rc;
130 for ( auto& it : m_algs ) {
131 if ( !it.managed || it.algorithm->FSMState() >= Gaudi::StateMachine::RUNNING ) continue;
132 rc = it.algorithm->sysStart();
133 if ( rc.isFailure() ) return rc;
134 }
135 return rc;
136}

◆ stop()

StatusCode AlgorithmManager::stop ( )
override

Stop (from RUNNING to INITIALIZED).

Definition at line 138 of file AlgorithmManager.cpp.

138 {
139 StatusCode rc;
140 for ( auto& it : m_algs ) {
141 if ( !it.managed ) continue;
142 rc = it.algorithm->sysStop();
143 if ( rc.isFailure() ) return rc;
144 }
145 return rc;
146}

◆ typeAliases() [1/2]

AlgTypeAliasesMap & AlgorithmManager::typeAliases ( )
inline

Definition at line 89 of file AlgorithmManager.h.

89{ return m_algTypeAliases; }

◆ typeAliases() [2/2]

const AlgTypeAliasesMap & AlgorithmManager::typeAliases ( ) const
inline

Definition at line 90 of file AlgorithmManager.h.

90{ return m_algTypeAliases; }

Member Data Documentation

◆ m_algs

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

algorithms maintained by AlgorithmManager

Definition at line 96 of file AlgorithmManager.h.

◆ m_algsMap

std::unordered_multimap<std::string, SmartIF<IAlgorithm> > AlgorithmManager::m_algsMap
private

algorithms maintained by AlgorithmManager

Definition at line 97 of file AlgorithmManager.h.

◆ m_algTypeAliases

AlgTypeAliasesMap AlgorithmManager::m_algTypeAliases
private

Definition at line 100 of file AlgorithmManager.h.


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