| The Gaudi Framework v32r1 (f65d50dc)

Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ServiceManager Class Reference

The ServiceManager class is in charge of the creation of concrete instances of Services. More...

`#include <src/ApplicationMgr/ServiceManager.h>`

Inheritance diagram for ServiceManager:
[legend]
Collaboration diagram for ServiceManager:
[legend]

## Classes
struct | ServiceItem

## Public Types
typedef std::list< ServiceItem > | ListSvc
typedef GaudiUtils::Map< std::string, std::string > | MapType
Public Types inherited from extends< ComponentManager, ISvcManager, ISvcLocator >
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
| ServiceManager (IInterface *application)
| default creator More...
SmartIF< ISvcLocator > & | serviceLocator () const override
| Function needed by CommonMessaging. More...
| ~ServiceManager () override
| virtual destructor More...
const std::list< IService * > & | getServices () const override
| Return the list of Services. More...
bool | existsService (const std::string &name) const override
| implementation of ISvcLocation::existsService More...
StatusCode | addService (IService *svc, int prio=DEFAULT_SVC_PRIORITY) override
| implementation of ISvcManager::addService More...
StatusCode | addService (const Gaudi::Utils::TypeNameString &typeName, int prio=DEFAULT_SVC_PRIORITY) override
| implementation of ISvcManager::addService More...
StatusCode | removeService (IService *svc) override
| implementation of ISvcManager::removeService More...
StatusCode | removeService (const std::string &name) override
| implementation of ISvcManager::removeService More...
StatusCode | declareSvcType (const std::string &svcname, const std::string &svctype) override
| implementation of ISvcManager::declareSvcType More...
SmartIF< IService > & | createService (const Gaudi::Utils::TypeNameString &nametype) override
| implementation of ISvcManager::createService NOTE: as this returns a &, we must guarantee that once created, these SmartIF remain pinned in their location, thus constraining the underlying implementation... 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...
int | getPriority (const std::string &name) const override
| manage priorities of services More...
StatusCode | setPriority (const std::string &name, int pri) override
bool | loopCheckEnabled () const override
| Get the value of the initialization loop check flag. More...
void | setLoopCheckEnabled (bool en) override
| Set the value of the initialization loop check flag. More...
const std::string & | name () const override
| Return the name of the manager (implementation of INamedInterface) More...
SmartIF< IService > & | service (const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
| Returns a smart pointer to a service. More...
template<typename T >
SmartIF< T > | service (const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
| Returns a smart pointer to the requested interface of a service. More...
void | outputLevelUpdate () override
| Function to call to update the outputLevel of the components (after a change in MessageSvc). More...
virtual StatusCode | addService (IService *svc, int prio=DEFAULT_SVC_PRIORITY)=0
| Add a service to the "active" list of services of the factory. More...
virtual StatusCode | addService (const std::string &typ, const std::string &nam, int prio)
| Add a service to the "active" list of services of the factory. More...
virtual StatusCode | addService (const Gaudi::Utils::TypeNameString &nametype, int prio=DEFAULT_SVC_PRIORITY)=0
| Add a service to the "active" list of services of the factory. More...
virtual SmartIF< IService > & | createService (const Gaudi::Utils::TypeNameString &nametype)=0
| Creates and instance of a service type that has been declared beforehand and assigns it a name. More...
virtual StatusCode | createService (const std::string &svctype, const std::string &svcname, IService *&svc)
| Creates and instance of a service type that has been declared beforehand and assigns it a name. More...
Public Member Functions inherited from extends< ComponentManager, ISvcManager, ISvcLocator >
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...
Public Member Functions inherited from ComponentManager
| ComponentManager (IInterface *application, const InterfaceID &baseIID)
| Constructor. More...
const InterfaceID & | componentBaseInterface () 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 CommonMessaging< implements< IComponentManager > >
MSG::Level | msgLevel () const
| get the cached level (originally extracted from the embedded MsgStream) More...
bool | msgLevel (MSG::Level lvl) const
| get the output level from the embedded MsgStream More...
MSG::Level | outputLevel () const
| Backward compatibility function for getting the output level. More...
Public Member Functions inherited from CommonMessagingBase
virtual | ~CommonMessagingBase ()=default
| Virtual destructor. More...
const SmartIF< IMessageSvc > & | msgSvc () const
| The standard message service. More...
MsgStream & | msgStream () const
| Return an uninitialized MsgStream. More...
MsgStream & | msgStream (const MSG::Level level) const
| Predefined configurable message stream for the efficient printouts. More...
MsgStream & | always () const
| shortcut for the method msgStream(MSG::ALWAYS) More...
MsgStream & | fatal () const
| shortcut for the method msgStream(MSG::FATAL) More...
MsgStream & | err () const
| shortcut for the method msgStream(MSG::ERROR) More...
MsgStream & | error () const
| shortcut for the method msgStream(MSG::ERROR) More...
MsgStream & | warning () const
| shortcut for the method msgStream(MSG::WARNING) More...
MsgStream & | info () const
| shortcut for the method msgStream(MSG::INFO) More...
MsgStream & | debug () const
| shortcut for the method msgStream(MSG::DEBUG) More...
MsgStream & | verbose () const
| shortcut for the method msgStream(MSG::VERBOSE) More...
MsgStream & | msg () const
| shortcut for the method msgStream(MSG::INFO) More...

## Private Types
typedef boost::recursive_mutex | Mutex_t
| Mutex to synchronize shared service initialization between threads. More...
typedef boost::lock_guard< Mutex_t > | LockGuard_t

## Private Member Functions
ListSvc::iterator | find (const std::string &name)
ListSvc::const_iterator | find (const std::string &name) const
ListSvc::iterator | find (const IService *ptr)
ListSvc::const_iterator | find (const IService *ptr) const
void | dump () const

## Private Attributes
ListSvc | m_listsvc
| List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because there can be SmartIF<T>& 'out there' that refer to these specific SmarIF<T>, we unfortunately must guarantee that they never move after creation. More...
MapType | m_maptype
| Map of service name and service type. More...
bool | m_loopCheck = true
| Check for service initialization loops. More...
SmartIF< IService > | m_appSvc
| Pointer to the application IService interface. More...
std::list< IService * > | m_listOfPtrs
| List of pointers to the know services used to implement getServices() More...
GaudiUtils::Map< InterfaceID, SmartIF< IInterface > > | m_defaultImplementations
Mutex_t | m_gLock
std::map< std::string, Mutex_t > | m_lockMap

## Additional Inherited Members
Protected Member Functions inherited from CommonMessaging< implements< IComponentManager > >
MSG::Level | setUpMessaging () const
| Set up local caches. More...
MSG::Level | resetMessaging ()
| Reinitialize internal states. More...
void | updateMsgStreamOutputLevel (int level)
| Update the output level of the cached MsgStream. More...
Protected Attributes inherited from ComponentManager
SmartIF< IInterface > | m_application
| Pointer to the owner of the manager. More...
SmartIF< IStateful > | m_stateful
| Pointer to the IStateful interface of the owner. More...
InterfaceID | m_basicInterfaceId
| Basic interface id of the managed components. More...
SmartIF< ISvcLocator > | m_svcLocator
| Service locator (needed to access the MessageSvc) More...
friend | ApplicationMgr

## Detailed Description

The ServiceManager class is in charge of the creation of concrete instances of Services.

The ApplicationMgr delegates the creation and bookkeeping of services to the ServiceManager. In order to be able to create services from which it is not know the concrete type it requires that the services 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 36 of file ServiceManager.h.

## Member Typedef Documentation

## ◆ ListSvc

typedef std::list<ServiceItem> ServiceManager::ListSvc

Definition at line 49 of file ServiceManager.h.

## ◆ LockGuard_t

typedef boost::lock_guard<Mutex_t> ServiceManager::LockGuard_t
| private

Definition at line 178 of file ServiceManager.h.

## ◆ MapType

typedef GaudiUtils::Map<std::string, std::string> ServiceManager::MapType

Definition at line 50 of file ServiceManager.h.

## ◆ Mutex_t

typedef boost::recursive_mutex ServiceManager::Mutex_t
| private

Mutex to synchronize shared service initialization between threads.

Definition at line 177 of file ServiceManager.h.

## Constructor & Destructor Documentation

## ◆ ServiceManager()

ServiceManager::ServiceManager | ( | IInterface * | application | ) |

default creator

Definition at line 43 of file ServiceManager.cpp.

44 : base_class( application, IService::interfaceID() ), m_appSvc( application ) {
45 // Set the service locator to myself
46 m_svcLocator = this;
47 addRef(); // increase ref count, so we live forever...
48 }
ServiceManager::m_appSvc
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
Definition: ServiceManager.h:169
ComponentManager::m_svcLocator
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
Definition: ComponentManager.h:76
extends< ComponentManager, ISvcManager, ISvcLocator >::base_class
extends base_class
Typedef to this class.
Definition: extends.h:14
gaudirun.application
application
Definition: gaudirun.py:295

## ◆ ~ServiceManager()

ServiceManager::~ServiceManager | ( |  | ) |
| override

virtual destructor

Definition at line 51 of file ServiceManager.cpp.

51 {
52 //-- inform the orphan services that I am gone....
53 for ( auto& svc : m_listsvc ) svc.service->setServiceManager( nullptr );
54 }
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## Member Function Documentation

## ◆ addService() [1/5]

StatusCode ServiceManager::addService | ( | IService * | svc,
|  | int | prio = `DEFAULT_SVC_PRIORITY`
| ) |  |
| override

implementation of ISvcManager::addService

Definition at line 100 of file ServiceManager.cpp.

102 {
103 ListSvc::iterator it = find( svc );
104 LockGuard_t lck( m_gLock );
105 if ( it != m_listsvc.end() ) {
106 it->priority = prio; // if the service is already known, it is equivalent to a setPriority
107 it->active = true; // and make it active
108 } else {
109 m_listsvc.emplace_back( svc, prio, true );
110 }
111 return StatusCode::SUCCESS;
112 }
ServiceManager::LockGuard_t
boost::lock_guard< Mutex_t > LockGuard_t
Definition: ServiceManager.h:178
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:180
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::list::end
T end(T... args)
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:133
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
std::list::emplace_back
T emplace_back(T... args)

## ◆ addService() [2/5]

StatusCode ServiceManager::addService | ( | const Gaudi::Utils::TypeNameString & | typeName,
|  | int | prio = `DEFAULT_SVC_PRIORITY`
| ) |  |
| override

implementation of ISvcManager::addService

Definition at line 116 of file ServiceManager.cpp.

118 {
119 auto it = find( typeName.name() ); // try to find the service by name
120 if ( it == m_listsvc.end() ) { // not found
121 // If the service does not exist, we create it
122 SmartIF<IService>& svc =
123 createService( typeName ); // WARNING: svc is now a reference to something that lives in m_listsvc
124 if ( !svc ) return StatusCode::FAILURE;
125 it = find( svc.get() ); // now it is in the list because createService added it
126 it->priority = prio;
127 StatusCode sc = StatusCode( StatusCode::SUCCESS, true );
128 if ( targetFSMState() >= Gaudi::StateMachine::INITIALIZED ) { // WARNING: this can trigger a recursion!!!
129 sc = svc->sysInitialize();
130 if ( sc.isSuccess() && targetFSMState() >= Gaudi::StateMachine::RUNNING ) { sc = svc->sysStart(); }
131 }
132 if ( sc.isFailure() ) { // if initialization failed, remove it from the list
133 error() << "Unable to initialize service \"" << typeName.name() << "\"" << endmsg;
134 LockGuard_t lck( m_gLock );
135 m_listsvc.erase( it );
136 // Note: removing it from the list + the SmartIF going out of scope should trigger the delete
137 // delete svc.get();
138 return sc;
139 }
140 // initialization successful, we can work with the service
141 // Move the just initialized service to the back of the list
142 // (we care more about order of initialization than of creation)
143 LockGuard_t lck( m_gLock );
144 m_listsvc.push_back( *it );
145 m_listsvc.erase( it );
146 it = std::prev( std::end( m_listsvc ) ); // last entry (the iterator was invalidated by erase)
147 } else {
148 // if the service is already known, it is equivalent to a setPriority
149 it->priority = prio;
150 }
151 // 'it' is defined because either we found the service or we created it
152 // Now we can activate the service
153 it->active = true; // and make it active
154 return StatusCode( StatusCode::SUCCESS, true );
155 }
ComponentManager::targetFSMState
Gaudi::StateMachine::State targetFSMState() const override
When we are in the middle of a transition, get the state where the transition is leading us.
Definition: ComponentManager.h:63
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
SmartIF< IService >
ServiceManager::LockGuard_t
boost::lock_guard< Mutex_t > LockGuard_t
Definition: ServiceManager.h:178
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:180
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::list::end
T end(T... args)
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
std::prev
T prev(T... args)
IService::sysInitialize
virtual StatusCode sysInitialize()=0
Initialize Service.
std::list::push_back
T push_back(T... args)
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
std::list::erase
T erase(T... args)
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
Gaudi::StateMachine::RUNNING
Definition: StateMachine.h:16
IService::sysStart
virtual StatusCode sysStart()=0
Start Service.
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:133
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
GaudiDict::typeName
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:21
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
ServiceManager::createService
SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype) override
implementation of ISvcManager::createService NOTE: as this returns a &, we must guarantee that once c...
Definition: ServiceManager.cpp:58
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ addService() [3/5]

virtual StatusCode ISvcManager::addService

Add a service to the "active" list of services of the factory.

Parameters

  svc | Pointer to the service

Returns
  StatusCode indicating success or failure.

## ◆ addService() [4/5]

virtual StatusCode ISvcManager::addService
| inline

Add a service to the "active" list of services of the factory.

Parameters

  svc | Pointer to the service

Returns
  StatusCode indicating success or failure.

Definition at line 48 of file ISvcManager.h.

48 {
49 return addService( Gaudi::Utils::TypeNameString( nam, typ ), prio );
50 }
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:10
ServiceManager::addService
StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY) override
implementation of ISvcManager::addService
Definition: ServiceManager.cpp:100

## ◆ addService() [5/5]

virtual StatusCode ISvcManager::addService

Add a service to the "active" list of services of the factory.

Parameters

  svc | Pointer to the service

Returns
  StatusCode indicating success or failure.

## ◆ createService() [1/3]

SmartIF< IService > & ServiceManager::createService | ( | const Gaudi::Utils::TypeNameString & | nametype | ) |
| override

implementation of ISvcManager::createService NOTE: as this returns a &, we must guarantee that once created, these SmartIF remain pinned in their location, thus constraining the underlying implementation...

Fix-Me:
  : what does this mean?

Definition at line 58 of file ServiceManager.cpp.

60 {
61 // Check if the service is already existing
62 if ( existsService( typeName.name() ) ) {
63 // return an error because a service with that name already exists
64 return no_service;
65 }
66
67 const std::string& name = typeName.name();
68 std::string type = typeName.type();
69 if ( !typeName.haveType() ) { // the type is not explicit
70 // see we have some specific type mapping for the name
71 auto it = m_maptype.find( typeName.name() );
72 if ( it != m_maptype.end() ) {
73 type = it->second; // use the declared type
74 }
75 }
76
78 auto ip = type.find( "__" );
79 if ( ip != std::string::npos ) type.erase( ip, type.length() );
80
81 IService* service = Service::Factory::create( type, name, this ).release();
82 if ( !service ) {
83 fatal() << "No Service factory for " << type << " available." << endmsg;
84 return no_service;
85 }
86 // Check the compatibility of the version of the interface obtained
87 if ( !isValidInterface( service ) ) {
88 fatal() << "Incompatible interface IService version for " << type << endmsg;
89 return no_service;
90 }
91
92 m_listsvc.push_back( service );
93 service->setServiceManager( this );
94 return m_listsvc.back().service; // DANGER: returns a reference to a SmartIF in m_listsvc, and hence does no longer
95 // allow relocations of those...
96 }
ServiceManager::existsService
bool existsService(const std::string &name) const override
implementation of ISvcLocation::existsService
Definition: ServiceManager.cpp:214
isValidInterface
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
Definition: IInterface.h:341
ServiceManager::m_maptype
MapType m_maptype
Map of service name and service type.
Definition: ServiceManager.h:165
std::string
STL class.
std::list::push_back
T push_back(T... args)
GaudiUtils::Map::end
iterator end()
Definition: Map.h:130
IService
General service interface definition.
Definition: IService.h:18
gaudirun.type
type
Definition: gaudirun.py:142
GaudiUtils::Map::find
iterator find(const key_type &key)
Definition: Map.h:147
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
std::list::back
T back(T... args)
ServiceManager::service
SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
Returns a smart pointer to a service.
Definition: ServiceManager.cpp:159
GaudiDict::typeName
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:21
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
IService::setServiceManager
virtual void setServiceManager(ISvcManager *)=0
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:92
ServiceManager::ServiceItem::service
SmartIF< IService > service
Definition: ServiceManager.h:40
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ createService() [2/3]

virtual SmartIF<IService>& ISvcManager::createService

Creates and instance of a service type that has been declared beforehand and assigns it a name.

It returns a pointer to an IService.

Parameters

  nametype | name/type of the service to create

Returns
  SmartIF& to the created service.

NOTE: as this returns a &, the underlying implementation must guarantee that once created, these SmartIF remain pinned in their location, thus constraining the underlying implementation (i.e. one cannot use something like std::vector<SmartIF<IService>>). If this interface had used value-semantics, and returned just plain SmartIF<IService> (i.e. WITHOUT the &) then the underlying implementation would have much more freedom)

## ◆ createService() [3/3]

virtual StatusCode ISvcManager::createService
| inline

Creates and instance of a service type that has been declared beforehand and assigns it a name.

It returns a pointer to an IService.

Parameters

  svctype | Service type name
  svcname | Service name to be set
  svc | Returned service pointer

Returns
  StatusCode indicating success or failure.

Definition at line 121 of file ISvcManager.h.

121 {
122 SmartIF<IService> s = createService( svctype + "/" + svcname );
123 svc = s.get();
124 if ( svc ) {
125 svc->addRef(); // Needed to maintain the correct reference counting.
126 return StatusCode::SUCCESS;
127 }
128 return StatusCode::FAILURE;
129 }
SmartIF< IService >
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
gaudirun.s
string s
Definition: gaudirun.py:316
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
ServiceManager::createService
SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype) override
implementation of ISvcManager::createService NOTE: as this returns a &, we must guarantee that once c...
Definition: ServiceManager.cpp:58

## ◆ declareSvcType()

StatusCode ServiceManager::declareSvcType | ( | const std::string & | svcname,
|  | const std::string & | svctype
| ) |  |
| override

implementation of ISvcManager::declareSvcType

Definition at line 241 of file ServiceManager.cpp.

243 {
244 // once we get to C++17, replace with m_maptype.insert_or_assign...
245 auto p = m_maptype.emplace( svcname, svctype );
246 if ( !p.second ) p.first->second = svctype;
247 return StatusCode::SUCCESS;
248 }
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
ServiceManager::m_maptype
MapType m_maptype
Map of service name and service type.
Definition: ServiceManager.h:165
GaudiUtils::Map::emplace
std::pair< iterator, bool > emplace(Args &&... args)
Definition: Map.h:164

## ◆ dump()

void ServiceManager::dump | ( |  | ) | const
| private

Definition at line 500 of file ServiceManager.cpp.

500 {
501
502 auto& log = info();
503 log << "\n"
504 << "===================== listing all services ===================\n"
505 << " prior ref name active\n";
506
507 for ( const auto& svc : m_listsvc ) {
508
509 log.width( 6 );
510 log.flags( std::ios_base::right );
511 log << svc.priority << " ";
512 log.width( 5 );
513 log << svc.service->refCount() << " ";
514 log.width( 30 );
515 log.flags( std::ios_base::left );
516 log << svc.service->name() << " ";
517 log.width( 2 );
518 log << svc.active << std::endl;
519 }
520
521 log << "=================================================================\n";
522 log << endmsg;
523 }
std::endl
T endl(T... args)
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:104
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Gaudi.Configuration.log
log
Definition: Configuration.py:13

## ◆ existsService()

bool ServiceManager::existsService | ( | const std::string & | name | ) | const
| override

implementation of ISvcLocation::existsService

Definition at line 214 of file ServiceManager.cpp.

216 {
217 return find( name ) != m_listsvc.end();
218 }
std::list::end
T end(T... args)
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:133
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ finalize()

StatusCode ServiceManager::finalize | ( |  | ) |
| override

Finalize (from INITIALIZED to CONFIGURED).

Definition at line 394 of file ServiceManager.cpp.

396 {
397 // make sure that HistogramDataSvc and THistSvc get finalized after the
398 // ToolSvc, and the FileMgr and StatusCodeSvc after that
399 int pri_tool = getPriority( "ToolSvc" );
400 if ( pri_tool != 0 ) {
401 setPriority( "THistSvc", pri_tool - 10 ).ignore();
402 setPriority( "ChronoStatSvc", pri_tool - 20 ).ignore();
403 setPriority( "AuditorSvc", pri_tool - 30 ).ignore();
404 setPriority( "NTupleSvc", pri_tool - 10 ).ignore();
405 setPriority( "HistogramDataSvc", pri_tool - 10 ).ignore();
406 // Preserve the relative ordering between HistogramDataSvc and HistogramPersistencySvc
407 setPriority( "HistogramPersistencySvc", pri_tool - 20 ).ignore();
408 setPriority( "HistorySvc", pri_tool - 30 ).ignore();
409 setPriority( "FileMgr", pri_tool - 40 ).ignore();
410 }
411
412 // get list of PostFinalize clients
413 std::vector<IIncidentListener*> postFinList;
414 auto p_inc = service<IIncidentSvc>( "IncidentSvc", false );
415 if ( p_inc ) {
416 p_inc->getListeners( postFinList, IncidentType::SvcPostFinalize );
417 p_inc.reset();
418 }
419
420 // make sure the StatusCodeSvc gets finalized really late:
421 setPriority( "StatusCodeSvc", -9999 ).ignore();
422
423 // ensure that the list is ordered by priority
424 m_listsvc.sort();
425 // dump();
426
427 StatusCode sc( StatusCode::SUCCESS, true );
428 {
429 // we work on a copy to avoid to operate twice on the services created on demand
430 // which are already in the correct state.
431 // only act on active services
432 // call finalize() for all services in reverse order
433 for ( const auto& svc : reverse( activeSvc( m_listsvc ) ) ) {
434 const std::string& name = svc->name();
435 // ignore the current state for the moment
436 // if( Gaudi::StateMachine::INITIALIZED == svc->state() )
437 DEBMSG << "Finalizing service " << name << endmsg;
438 if ( !svc->sysFinalize().isSuccess() ) {
439 warning() << "Finalization of service " << name << " failed" << endmsg;
440 sc = StatusCode::FAILURE;
441 }
442 }
443 }
444
445 // call SvcPostFinalize on all clients
446 if ( !postFinList.empty() ) {
447 DEBMSG << "Will call SvcPostFinalize for " << postFinList.size() << " clients" << endmsg;
448 Incident inc( "ServiceManager", IncidentType::SvcPostFinalize );
449 for ( auto& itr : postFinList ) itr->handle( inc );
450 }
451
452 // loop over all Active Services, removing them one by one.
453 // They should be deleted because the reference counting goes to 0.
454 DEBMSG << "Looping over all active services..." << endmsg;
455 auto it = m_listsvc.begin();
456 while ( it != m_listsvc.end() ) {
457 DEBMSG << "---- " << it->service->name() << " (refCount = " << it->service->refCount() << ")" << endmsg;
458 if ( it->service->refCount() < 1 ) {
459 warning() << "Too low reference count for " << it->service->name() << " (should not go below 1 at this point)"
460 << endmsg;
461 it->service->addRef();
462 }
463 if ( it->active ) {
464 it = m_listsvc.erase( it );
465 } else {
466 ++it;
467 }
468 }
469 return sc;
470 }
std::vector::empty
T empty(T... args)
ServiceManager::getPriority
int getPriority(const std::string &name) const override
manage priorities of services
Definition: ServiceManager.cpp:473
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:101
reverse
::details::reverse_wrapper< T > reverse(T &&iterable)
Definition: reverse.h:49
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::list::end
T end(T... args)
std::string
STL class.
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
std::list::erase
T erase(T... args)
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
std::vector::size
T size(T... args)
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
std::vector
STL class.
std::list::begin
T begin(T... args)
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
std::list::sort
T sort(T... args)
DEBMSG
#define DEBMSG
Definition: ServiceManager.cpp:23
ServiceManager::setPriority
StatusCode setPriority(const std::string &name, int pri) override
Definition: ServiceManager.cpp:480
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ find() [1/4]

ListSvc::iterator ServiceManager::find | ( | const std::string & | name | ) |
| inline private

Definition at line 133 of file ServiceManager.h.

133 {
134 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
135 return std::find( m_listsvc.begin(), m_listsvc.end(), name );
136 }
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:180
std::list::end
T end(T... args)
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
std::find
T find(T... args)
std::list::begin
T begin(T... args)
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ find() [2/4]

ListSvc::const_iterator ServiceManager::find | ( | const std::string & | name | ) | const
| inline private

Definition at line 137 of file ServiceManager.h.

137 {
138 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
139 return std::find( m_listsvc.begin(), m_listsvc.end(), name );
140 }
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:180
std::list::end
T end(T... args)
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
std::find
T find(T... args)
std::list::begin
T begin(T... args)
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ find() [3/4]

ListSvc::iterator ServiceManager::find | ( | const IService * | ptr | ) |
| inline private

Definition at line 141 of file ServiceManager.h.

141 {
142 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
143 return std::find( m_listsvc.begin(), m_listsvc.end(), ptr );
144 }
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:180
std::list::end
T end(T... args)
std::find
T find(T... args)
std::list::begin
T begin(T... args)
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ find() [4/4]

ListSvc::const_iterator ServiceManager::find | ( | const IService * | ptr | ) | const
| inline private

Definition at line 145 of file ServiceManager.h.

145 {
146 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
147 return std::find( m_listsvc.begin(), m_listsvc.end(), ptr );
148 }
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:180
std::list::end
T end(T... args)
std::find
T find(T... args)
std::list::begin
T begin(T... args)
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ getPriority()

int ServiceManager::getPriority | ( | const std::string & | name | ) | const
| override

manage priorities of services

Definition at line 473 of file ServiceManager.cpp.

473 {
474 //------------------------------------------------------------------------------
475 auto it = find( name );
476 return ( it != m_listsvc.end() ) ? it->priority : 0;
477 }
std::list::end
T end(T... args)
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:133
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ getServices()

const std::list< IService * > & ServiceManager::getServices | ( |  | ) | const
| override

Return the list of Services.

Definition at line 204 of file ServiceManager.cpp.

206 {
207 m_listOfPtrs.clear();
208 std::transform( std::begin( m_listsvc ), std::end( m_listsvc ), std::back_inserter( m_listOfPtrs ),
209 []( ListSvc::const_reference i ) { return i.service.get(); } );
210 return m_listOfPtrs;
211 }
ServiceManager::m_listOfPtrs
std::list< IService * > m_listOfPtrs
List of pointers to the know services used to implement getServices()
Definition: ServiceManager.h:172
std::end
T end(T... args)
std::list::clear
T clear(T... args)
std::begin
T begin(T... args)
std::back_inserter
T back_inserter(T... args)
std::transform
T transform(T... args)
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ initialize()

StatusCode ServiceManager::initialize | ( |  | ) |
| override

Initialization (from CONFIGURED to INITIALIZED).

Definition at line 251 of file ServiceManager.cpp.

253 {
254 // ensure that the list is ordered by priority
255 m_listsvc.sort();
256 // we work on a copy to avoid to operate twice on the services created on demand
257 // which are already in the correct state.
258
259 StatusCode sc( StatusCode::SUCCESS, true );
260 // call initialize() for all services
261 for ( auto& it : activeSvc( m_listsvc ) ) {
262 const std::string& name = it->name();
263 switch ( it->FSMState() ) {
264 case Gaudi::StateMachine::INITIALIZED:
265 DEBMSG << "Service " << name << " already initialized" << endmsg;
266 break;
267 case Gaudi::StateMachine::OFFLINE:
268 DEBMSG << "Initializing service " << name << endmsg;
269 sc = it->sysInitialize();
270 if ( !sc.isSuccess() ) {
271 error() << "Unable to initialize Service: " << name << endmsg;
272 return sc;
273 }
274 break;
275 default:
276 error() << "Service " << name << " not in the correct state to be initialized (" << it->FSMState() << ")"
277 << endmsg;
278 return StatusCode::FAILURE;
279 }
280 }
281 return StatusCode::SUCCESS;
282 }
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
std::list::sort
T sort(T... args)
DEBMSG
#define DEBMSG
Definition: ServiceManager.cpp:23
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
Gaudi::StateMachine::OFFLINE
Definition: StateMachine.h:13
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ loopCheckEnabled()

bool ServiceManager::loopCheckEnabled | ( |  | ) | const
| override

Get the value of the initialization loop check flag.

Definition at line 491 of file ServiceManager.cpp.

491 { return m_loopCheck; }
ServiceManager::m_loopCheck
bool m_loopCheck
Check for service initialization loops.
Definition: ServiceManager.h:166

## ◆ name()

const std::string& ServiceManager::name | ( |  | ) | const
| inline override

Return the name of the manager (implementation of INamedInterface)

Definition at line 110 of file ServiceManager.h.

110 {
111 static std::string _name = "ServiceManager";
112 return _name;
113 }
std::string
STL class.

## ◆ outputLevelUpdate()

void ServiceManager::outputLevelUpdate | ( |  | ) |
| override

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

Definition at line 525 of file ServiceManager.cpp.

525 {
526 resetMessaging();
527 for ( auto& svcItem : m_listsvc ) {
528 const auto svc = dynamic_cast<Service*>( svcItem.service.get() );
529 if ( svc ) svc->resetMessaging();
530 }
531 }
CommonMessaging< implements< IComponentManager > >::resetMessaging
MSG::Level resetMessaging()
Reinitialize internal states.
Definition: CommonMessaging.h:174
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ reinitialize()

StatusCode ServiceManager::reinitialize | ( |  | ) |
| override

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

Definition at line 352 of file ServiceManager.cpp.

354 {
355 // ensure that the list is ordered by priority
356 m_listsvc.sort();
357 // we work on a copy to avoid to operate twice on the services created on demand
358 // which are already in the correct state.
359 // only act on active services
360 StatusCode sc( StatusCode::SUCCESS, true );
361 // Re-Initialize all services
362 for ( auto& svc : activeSvc( m_listsvc ) ) {
363 sc = svc->sysReinitialize();
364 if ( !sc.isSuccess() ) {
365 error() << "Unable to re-initialize Service: " << svc->name() << endmsg;
366 return StatusCode::FAILURE;
367 }
368 }
369 return StatusCode::SUCCESS;
370 }
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
std::list::sort
T sort(T... args)
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ removeService() [1/2]

StatusCode ServiceManager::removeService | ( | IService * | svc | ) |
| override

implementation of ISvcManager::removeService

Definition at line 221 of file ServiceManager.cpp.

223 {
224 auto it = find( svc );
225 if ( it == m_listsvc.end() ) return StatusCode( StatusCode::FAILURE, true );
226 m_listsvc.erase( it );
227 return StatusCode( StatusCode::SUCCESS, true );
228 }
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::list::end
T end(T... args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
std::list::erase
T erase(T... args)
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:133
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ removeService() [2/2]

StatusCode ServiceManager::removeService | ( | const std::string & | name | ) |
| override

implementation of ISvcManager::removeService

Definition at line 231 of file ServiceManager.cpp.

233 {
234 auto it = find( name );
235 if ( it == m_listsvc.end() ) return StatusCode::FAILURE;
236 m_listsvc.erase( it );
237 return StatusCode::SUCCESS;
238 }
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::list::end
T end(T... args)
std::list::erase
T erase(T... args)
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:133
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ restart()

StatusCode ServiceManager::restart | ( |  | ) |
| override

Initialization (from RUNNING to RUNNING, via INITIALIZED).

Definition at line 373 of file ServiceManager.cpp.

375 {
376 // ensure that the list is ordered by priority
377 m_listsvc.sort();
378 // we work on a copy to avoid to operate twice on the services created on demand
379 // which are already in the correct state.
380 // only act on active services
381 StatusCode sc( StatusCode::SUCCESS, true );
382 // Re-Start all services
383 for ( auto& svc : activeSvc( m_listsvc ) ) {
384 sc = svc->sysRestart();
385 if ( !sc.isSuccess() ) {
386 error() << "Unable to re-start Service: " << svc->name() << endmsg;
387 return StatusCode::FAILURE;
388 }
389 }
390 return StatusCode::SUCCESS;
391 }
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
std::list::sort
T sort(T... args)
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ service() [1/2]

SmartIF< IService > & ServiceManager::service | ( | const Gaudi::Utils::TypeNameString & | typeName,
|  | const bool | createIf = `true`
| ) |  |
| override

Returns a smart pointer to a service.

Definition at line 159 of file ServiceManager.cpp.

159 {
160 const std::string& name = typeName.name();
161
162 // Acquire the RAII lock to avoid simultaneous attempts from different threads to initialize a service
163
164 Mutex_t* imut;
165 {
166 // get the global lock, then extract/create the service specific mutex
167 // then release global lock
168
169 LockGuard_t lk( m_gLock );
170 auto mit = m_lockMap.find( name );
171 if ( mit == m_lockMap.end() ) {
172 mit = m_lockMap.emplace( std::piecewise_construct_t{}, std::forward_as_tuple( name ), std::forward_as_tuple() )
173 .first;
174 }
175 imut = &mit->second;
176 }
177
178 {
179 // now we have the service specific lock on the above mutex
180 LockGuard_t lk2( *imut );
181
182 auto it = find( name );
183
184 if ( it != m_listsvc.end() ) {
185 if ( m_loopCheck && ( createIf && it->service->FSMState() == Gaudi::StateMachine::CONFIGURED ) ) {
186 error() << "Initialization loop detected when creating service \"" << name << "\"" << endmsg;
187 return no_service;
188 }
189 return it->service;
190 }
191
192 // Service not found. The user may be interested in one of the interfaces
193 // of the application manager itself
194 if ( name == "ApplicationMgr" || name == "APPMGR" || name == "" ) { return m_appSvc; }
195
196 // last resort: we try to create the service
197 if ( createIf && addService( typeName ).isSuccess() ) { return find( name )->service; }
198
199 return no_service;
200 }
201 }
ServiceManager::m_appSvc
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
Definition: ServiceManager.h:169
ServiceManager::LockGuard_t
boost::lock_guard< Mutex_t > LockGuard_t
Definition: ServiceManager.h:178
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:180
std::forward_as_tuple
T forward_as_tuple(T... args)
Gaudi::StateMachine::CONFIGURED
Definition: StateMachine.h:14
ServiceManager::m_loopCheck
bool m_loopCheck
Check for service initialization loops.
Definition: ServiceManager.h:166
ServiceManager::Mutex_t
boost::recursive_mutex Mutex_t
Mutex to synchronize shared service initialization between threads.
Definition: ServiceManager.h:177
std::map::end
T end(T... args)
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
std::piecewise_construct_t
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
std::map::find
T find(T... args)
std::map::emplace
T emplace(T... args)
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:133
GaudiDict::typeName
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:21
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
ServiceManager::m_lockMap
std::map< std::string, Mutex_t > m_lockMap
Definition: ServiceManager.h:181
ServiceManager::addService
StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY) override
implementation of ISvcManager::addService
Definition: ServiceManager.cpp:100

## ◆ service() [2/2]

template<typename T >

SmartIF<T> ServiceManager::service | ( | const Gaudi::Utils::TypeNameString & | typeName,
|  | const bool | createIf = `true`
| ) |  |
| inline

Returns a smart pointer to the requested interface of a service.

Definition at line 120 of file ServiceManager.h.

120 {
121 return SmartIF<T>{service( typeName, createIf )};
122 }
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
ServiceManager::service
SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
Returns a smart pointer to a service.
Definition: ServiceManager.cpp:159
GaudiDict::typeName
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:21

## ◆ serviceLocator()

SmartIF<ISvcLocator>& ServiceManager::serviceLocator | ( |  | ) | const
| inline override

Function needed by CommonMessaging.

Definition at line 56 of file ServiceManager.h.

56 { return m_svcLocator; }
ComponentManager::m_svcLocator
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
Definition: ComponentManager.h:76

## ◆ setLoopCheckEnabled()

void ServiceManager::setLoopCheckEnabled | ( | bool | en | ) |
| override

Set the value of the initialization loop check flag.

Definition at line 495 of file ServiceManager.cpp.

495 { m_loopCheck = en; }
ServiceManager::m_loopCheck
bool m_loopCheck
Check for service initialization loops.
Definition: ServiceManager.h:166

## ◆ setPriority()

StatusCode ServiceManager::setPriority | ( | const std::string & | name,
|  | int | pri
| ) |  |
| override

Definition at line 480 of file ServiceManager.cpp.

480 {
481 //------------------------------------------------------------------------------
482 auto it = find( name );
483 if ( it == m_listsvc.end() ) return StatusCode::FAILURE;
484 it->priority = prio;
485 return StatusCode::SUCCESS;
486 }
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::list::end
T end(T... args)
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:133
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151

## ◆ start()

StatusCode ServiceManager::start | ( |  | ) |
| override

Start (from INITIALIZED to RUNNING).

Definition at line 285 of file ServiceManager.cpp.

287 {
288 // ensure that the list is ordered by priority
289 m_listsvc.sort();
290 // we work on a copy to avoid to operate twice on the services created on demand
291 // (which are already in the correct state.
292 // only act on active services
293 StatusCode sc( StatusCode::SUCCESS, true );
294 // call initialize() for all services
295 for ( auto& it : activeSvc( m_listsvc ) ) {
296 const std::string& name = it->name();
297 switch ( it->FSMState() ) {
298 case Gaudi::StateMachine::RUNNING:
299 DEBMSG << "Service " << name << " already started" << endmsg;
300 break;
301 case Gaudi::StateMachine::INITIALIZED:
302 DEBMSG << "Starting service " << name << endmsg;
303 sc = it->sysStart();
304 if ( !sc.isSuccess() ) {
305 error() << "Unable to start Service: " << name << endmsg;
306 return sc;
307 }
308 break;
309 default:
310 error() << "Service " << name << " not in the correct state to be started (" << it->FSMState() << ")" << endmsg;
311 return StatusCode::FAILURE;
312 }
313 }
314 return StatusCode::SUCCESS;
315 }
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
Gaudi::StateMachine::RUNNING
Definition: StateMachine.h:16
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
std::list::sort
T sort(T... args)
DEBMSG
#define DEBMSG
Definition: ServiceManager.cpp:23
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ stop()

StatusCode ServiceManager::stop | ( |  | ) |
| override

Stop (from RUNNING to INITIALIZED).

Definition at line 318 of file ServiceManager.cpp.

320 {
321 // ensure that the list is ordered by priority
322 m_listsvc.sort();
323 // we work on a copy to avoid to operate twice on the services created on demand
324 // which are already in the correct state.
325 // only act on active services
326
327 StatusCode sc( StatusCode::SUCCESS, true );
328 // call stop() for all services
329 for ( const auto& svc : reverse( activeSvc( m_listsvc ) ) ) {
330 const std::string& name = svc->name();
331 switch ( svc->FSMState() ) {
332 case Gaudi::StateMachine::INITIALIZED:
333 DEBMSG << "Service " << name << " already stopped" << endmsg;
334 break;
335 case Gaudi::StateMachine::RUNNING:
336 DEBMSG << "Stopping service " << name << endmsg;
337 sc = svc->sysStop();
338 if ( !sc.isSuccess() ) {
339 error() << "Unable to stop Service: " << name << endmsg;
340 return sc;
341 }
342 break;
343 default:
344 DEBMSG << "Service " << name << " not in the correct state to be stopped (" << svc->FSMState() << ")" << endmsg;
345 return StatusCode::FAILURE;
346 }
347 }
348 return StatusCode::SUCCESS;
349 }
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
reverse
::details::reverse_wrapper< T > reverse(T &&iterable)
Definition: reverse.h:49
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
Gaudi::StateMachine::RUNNING
Definition: StateMachine.h:16
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
std::list::sort
T sort(T... args)
DEBMSG
#define DEBMSG
Definition: ServiceManager.cpp:23
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## Member Data Documentation

## ◆ m_appSvc

SmartIF<IService> ServiceManager::m_appSvc
| private

Pointer to the application IService interface.

Definition at line 169 of file ServiceManager.h.

## ◆ m_defaultImplementations

GaudiUtils::Map<InterfaceID, SmartIF<IInterface> > ServiceManager::m_defaultImplementations
| private

Definition at line 174 of file ServiceManager.h.

## ◆ m_gLock

Mutex_t ServiceManager::m_gLock
| mutable private

Definition at line 180 of file ServiceManager.h.

## ◆ m_listOfPtrs

std::list<IService*> ServiceManager::m_listOfPtrs
| mutable private

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

Definition at line 172 of file ServiceManager.h.

## ◆ m_listsvc

ListSvc ServiceManager::m_listsvc
| private

List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because there can be SmartIF<T>& 'out there' that refer to these specific SmarIF<T>, we unfortunately must guarantee that they never move after creation.

Hence, we cannot use a plain std::vector here, as that may cause relocation and/or swapping of SmartIF<T>'s, and then the already handed out references may refer to the wrong item.... Note that we could use an std::vector<std::unique_ptr<ServiceItem>> (sometimes known as 'stable vector') as then the individual ServiceItems would stay pinned in their original location, but that would put ServiceItem on the heap... And maybe I'm way too paranoid...

Definition at line 151 of file ServiceManager.h.

## ◆ m_lockMap

std::map<std::string, Mutex_t> ServiceManager::m_lockMap
| mutable private

Definition at line 181 of file ServiceManager.h.

## ◆ m_loopCheck

bool ServiceManager::m_loopCheck = true
| private

Check for service initialization loops.

Definition at line 166 of file ServiceManager.h.

## ◆ m_maptype

MapType ServiceManager::m_maptype
| private

Map of service name and service type.

Definition at line 165 of file ServiceManager.h.

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

- GaudiCoreSvc/src/ApplicationMgr/ServiceManager.h
- GaudiCoreSvc/src/ApplicationMgr/ServiceManager.cpp