| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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...
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...
| ~extends () override=default
| Virtual destructor. 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 CommonMessagingBase
virtual | ~CommonMessagingBase ()=default
| Virtual destructor. More...
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...
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 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, std::unique_ptr< Mutex_t > > | m_lockMap

## 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< 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...

## 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

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

Definition at line 50 of file ServiceManager.h.

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

Definition at line 182 of file ServiceManager.h.

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

Definition at line 51 of file ServiceManager.h.

typedef boost::recursive_mutex ServiceManager::Mutex_t
| private

Mutex to synchronize shared service initialization between threads.

Definition at line 181 of file ServiceManager.h.

## Constructor & Destructor Documentation

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

default creator

Definition at line 42 of file ServiceManager.cpp.

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

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

virtual destructor

Definition at line 52 of file ServiceManager.cpp.

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

## Member Function Documentation

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 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
ServiceManager::LockGuard_t
boost::lock_guard< Mutex_t > LockGuard_t
Definition: ServiceManager.h:182
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:184
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:155
std::list::emplace_back
T emplace_back(T...args)

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 = createService(typeName); // WARNING: svc is now a reference to something that lives in m_listsvc
123 if (!svc) return StatusCode::FAILURE;
124 it = find(svc.get()); // now it is in the list because createService added it
125 it->priority = prio;
126 StatusCode sc = StatusCode(StatusCode::SUCCESS, true);
127 if (targetFSMState() >= Gaudi::StateMachine::INITIALIZED) { // WARNING: this can trigger a recursion!!!
128 sc = svc->sysInitialize();
129 if (sc.isSuccess() && targetFSMState() >= Gaudi::StateMachine::RUNNING) {
130 sc = svc->sysStart();
131 }
132 }
133 if(sc.isFailure()) { // if initialization failed, remove it from the list
134 error() << "Unable to initialize service \"" << typeName.name() << "\""
135 << endmsg;
136 LockGuard_t lck(m_gLock);
137 m_listsvc.erase(it);
138 // Note: removing it from the list + the SmartIF going out of scope should trigger the delete
139 // delete svc.get();
140 return sc;
141 }
142 // initialization successful, we can work with the service
143 // Move the just initialized service to the back of the list
144 // (we care more about order of initialization than of creation)
145 LockGuard_t lck(m_gLock);
146 m_listsvc.push_back(*it);
147 m_listsvc.erase(it);
148 it = std::prev(std::end(m_listsvc)); // last entry (the iterator was invalidated by erase)
149 } else {
150 // if the service is already known, it is equivalent to a setPriority
151 it->priority = prio;
152 }
153 // 'it' is defined because either we found the service or we created it
154 // Now we can activate the service
155 it->active = true; // and make it active
156 return StatusCode(StatusCode::SUCCESS, true);
157 }
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
StatusCode::SUCCESS
Definition: StatusCode.h:30
SmartIF< IService >
ServiceManager::LockGuard_t
boost::lock_guard< Mutex_t > LockGuard_t
Definition: ServiceManager.h:182
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:184
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
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
std::list::end
T end(T...args)
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
std::prev
T prev(T...args)
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
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:117
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::list::erase
T erase(T...args)
Gaudi::StateMachine::RUNNING
Definition: StateMachine.h:16
IService::sysStart
virtual StatusCode sysStart()=0
Start Service.
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:133
Gaudi::Utils::TypeNameString::name
const std::string & name() const
Definition: TypeNameString.h:40
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because...
Definition: ServiceManager.h:155
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:59
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

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 59 of file ServiceManager.cpp.

61 {
62 // Check if the service is already existing
63 if(existsService(typeName.name())) {
64 // return an error because a service with that name already exists
65 return no_service;
66 }
67
68 const std::string &name = typeName.name();
69 std::string type = typeName.type();
70 if (!typeName.haveType()) { // the type is not explicit
71 // see we have some specific type mapping for the name
72 auto it = m_maptype.find(typeName.name());
73 if( it != m_maptype.end() ) {
74 type = it->second; // use the declared type
75 }
76 }
77
79 auto ip = type.find("__");
80 if ( ip != std::string::npos) type.erase(ip,type.length());
81
82 IService* service = Service::Factory::create(type, name, this);
83 if ( !service ) {
84 fatal() << "No Service factory for " << type << " available." << endmsg;
85 return no_service;
86 }
87 // Check the compatibility of the version of the interface obtained
88 if( !isValidInterface(service) ) {
89 fatal() << "Incompatible interface IService version for " << type << endmsg;
90 return no_service;
91 }
92
93 m_listsvc.push_back(service);
94 service->setServiceManager(this);
95 return m_listsvc.back().service; // DANGER: returns a reference to a SmartIF in m_listsvc, and hence does no longer allow relocations of those...
96 }
isValidInterface
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
Definition: IInterface.h:323
ServiceManager::m_maptype
MapType m_maptype
Map of service name and service type.
Definition: ServiceManager.h:169
std::string
STL class.
std::list::push_back
T push_back(T...args)
ServiceManager::existsService
bool existsService(const std::string &name) const override
implementation of ISvcLocation::existsService
Definition: ServiceManager.cpp:228
GaudiUtils::Map::end
iterator end()
Definition: Map.h:132
IService
General service interface definition.
Definition: IService.h:18
gaudirun.type
type
Definition: gaudirun.py:125
std::string::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:111
GaudiUtils::Map::find
iterator find(const key_type &key)
Definition: Map.h:149
std::string::find
T find(T...args)
std::string::length
T length(T...args)
std::list::back
T back(T...args)
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:111
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:161
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:155
IService::setServiceManager
virtual void setServiceManager(ISvcManager *)=0
ServiceManager::ServiceItem::service
SmartIF< IService > service
Definition: ServiceManager.h:41
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

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

implementation of ISvcManager::declareSvcType

Definition at line 255 of file ServiceManager.cpp.

258 {
259 // once we get to C++17, replace with m_maptype.insert_or_assign...
260 auto p = m_maptype.emplace( svcname, svctype );
261 if ( !p.second ) p.first->second = svctype;
262 return StatusCode::SUCCESS;
263 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
GaudiUtils::Map::emplace
std::pair< iterator, bool > emplace(Args &&...args)
Definition: Map.h:166
ServiceManager::m_maptype
MapType m_maptype
Map of service name and service type.
Definition: ServiceManager.h:169

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

Definition at line 531 of file ServiceManager.cpp.

531 {
532
533
534 auto& log = info();
535 log << "\n"
536 << "===================== listing all services ===================\n"
537 << " prior ref name active\n";
538
539 for (const auto& svc : m_listsvc) {
540
541 log.width(6);
542 log.flags(std::ios_base::right);
543 log << svc.priority << " ";
544 log.width(5);
545 log << svc.service->refCount() << " ";
546 log.width(30);
547 log.flags(std::ios_base::left);
548 log << svc.service->name() << " ";
549 log.width(2);
550 log << svc.active << std::endl;
551
552 }
553
554 log << "=================================================================\n";
555 log << endmsg;
556
557 }
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:123
std::endl
T endl(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:155
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Gaudi.Configuration.log
log
Definition: Configuration.py:13

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

implementation of ISvcLocation::existsService

Definition at line 228 of file ServiceManager.cpp.

230 {
231 return find(name) != m_listsvc.end();
232 }
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:155

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

Finalize (from INITIALIZED to CONFIGURED).

Definition at line 413 of file ServiceManager.cpp.

415 {
416 // make sure that HistogramDataSvc and THistSvc get finalized after the
417 // ToolSvc, and the FileMgr and StatusCodeSvc after that
418 int pri_tool = getPriority("ToolSvc");
419 if (pri_tool != 0) {
420 setPriority("THistSvc",pri_tool-10).ignore();
421 setPriority("ChronoStatSvc",pri_tool-20).ignore();
422 setPriority("AuditorSvc",pri_tool-30).ignore();
423 setPriority("NTupleSvc",pri_tool-10).ignore();
424 setPriority("HistogramDataSvc",pri_tool-10).ignore();
425 // Preserve the relative ordering between HistogramDataSvc and HistogramPersistencySvc
426 setPriority("HistogramPersistencySvc",pri_tool-20).ignore();
427 setPriority("HistorySvc",pri_tool-30).ignore();
428 setPriority("FileMgr",pri_tool-40).ignore();
429 }
430
431
432 // get list of PostFinalize clients
433 std::vector<IIncidentListener*> postFinList;
434 auto p_inc = service<IIncidentSvc>("IncidentSvc",false);
435 if (p_inc) {
436 p_inc->getListeners(postFinList,IncidentType::SvcPostFinalize);
437 p_inc.reset();
438 }
439
440 // make sure the StatusCodeSvc gets finalized really late:
441 setPriority("StatusCodeSvc",-9999).ignore();
442
443 // ensure that the list is ordered by priority
444 m_listsvc.sort();
445 // dump();
446
447 StatusCode sc(StatusCode::SUCCESS, true);
448 {
449 // we work on a copy to avoid to operate twice on the services created on demand
450 // which are already in the correct state.
451 // only act on active services
452 // call finalize() for all services in reverse order
453 for (const auto& svc : reverse(activeSvc(m_listsvc)) ) {
454 const std::string& name = svc->name();
455 // ignore the current state for the moment
456 // if( Gaudi::StateMachine::INITIALIZED == svc->state() )
457 DEBMSG << "Finalizing service " << name << endmsg;
458 if ( !svc->sysFinalize().isSuccess() ) {
459 warning() << "Finalization of service " << name << " failed" << endmsg;
460 sc = StatusCode::FAILURE;
461 }
462 }
463 }
464
465 // call SvcPostFinalize on all clients
466 if (!postFinList.empty()) {
467 DEBMSG << "Will call SvcPostFinalize for " << postFinList.size() << " clients"
468 << endmsg;
469 Incident inc("ServiceManager", IncidentType::SvcPostFinalize);
470 for (auto& itr : postFinList) itr->handle(inc);
471 }
472
473 // loop over all Active Services, removing them one by one.
474 // They should be deleted because the reference counting goes to 0.
475 DEBMSG << "Looping over all active services..." << endmsg;
476 auto it = m_listsvc.begin();
477 while (it != m_listsvc.end()) {
478 DEBMSG << "---- " << it->service->name()
479 << " (refCount = " << it->service->refCount() << ")"
480 << endmsg;
481 if (it->service->refCount() < 1) {
482 warning() << "Too low reference count for " << it->service->name()
483 << " (should not go below 1 at this point)" << endmsg;
484 it->service->addRef();
485 }
486 if (it->active) {
487 it = m_listsvc.erase(it);
488 } else {
489 ++it;
490 }
491 }
492 return sc;
493 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
std::vector::empty
T empty(T...args)
StatusCode::FAILURE
Definition: StatusCode.h:29
std::list::end
T end(T...args)
std::string
STL class.
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:120
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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:111
ServiceManager::getPriority
int getPriority(const std::string &name) const override
manage priorities of services
Definition: ServiceManager.cpp:498
reverse
reverse_wrapper< T > reverse(T &&iterable)
Definition: reverse.h:33
std::vector::size
T size(T...args)
std::vector
STL class.
std::list::begin
T begin(T...args)
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
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:506
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:106
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because...
Definition: ServiceManager.h:155
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

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

Definition at line 133 of file ServiceManager.h.

134 {
135 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
136 return std::find( m_listsvc.begin(), m_listsvc.end(), name );
137 }
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:184
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:111
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:155

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

Definition at line 138 of file ServiceManager.h.

139 {
140 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
141 return std::find( m_listsvc.begin(), m_listsvc.end(), name );
142 }
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:184
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:111
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:155

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

Definition at line 143 of file ServiceManager.h.

144 {
145 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
146 return std::find( m_listsvc.begin(), m_listsvc.end(), ptr );
147 }
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:184
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:155

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

Definition at line 148 of file ServiceManager.h.

149 {
150 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
151 return std::find( m_listsvc.begin(), m_listsvc.end(), ptr );
152 }
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:184
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:155

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

manage priorities of services

Definition at line 498 of file ServiceManager.cpp.

498 {
499 //------------------------------------------------------------------------------
500 auto it = find(name);
501 return (it != m_listsvc.end()) ? it->priority: 0;
502 }
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:155

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

Return the list of Services.

Definition at line 215 of file ServiceManager.cpp.

217 {
218 m_listOfPtrs.clear();
219 std::transform( std::begin(m_listsvc), std::end(m_listsvc),
220 std::back_inserter(m_listOfPtrs),
221 [](ListSvc::const_reference i) {
222 return const_cast<IService*>(i.service.get());
223 });
224 return m_listOfPtrs;
225 }
ServiceManager::m_listOfPtrs
std::list< IService * > m_listOfPtrs
List of pointers to the know services used to implement getServices()
Definition: ServiceManager.h:176
std::end
T end(T...args)
IService
General service interface definition.
Definition: IService.h:18
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:155

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

Initialization (from CONFIGURED to INITIALIZED).

Definition at line 266 of file ServiceManager.cpp.

268 {
269 // ensure that the list is ordered by priority
270 m_listsvc.sort();
271 // we work on a copy to avoid to operate twice on the services created on demand
272 // which are already in the correct state.
273
274 StatusCode sc(StatusCode::SUCCESS, true);
275 // call initialize() for all services
276 for (auto& it : activeSvc(m_listsvc) ) {
277 const std::string& name = it->name();
278 switch (it->FSMState()) {
279 case Gaudi::StateMachine::INITIALIZED:
280 DEBMSG << "Service " << name << " already initialized" << endmsg;
281 break;
282 case Gaudi::StateMachine::OFFLINE:
283 DEBMSG << "Initializing service " << name << endmsg;
284 sc = it->sysInitialize();
285 if( !sc.isSuccess() ) {
286 error() << "Unable to initialize Service: " << name << endmsg;
287 return sc;
288 } break;
289 default:
290 error() << "Service " << name
291 << " not in the correct state to be initialized ("
292 << it->FSMState() << ")" << endmsg;
293 return StatusCode::FAILURE;
294 }
295 }
296 return StatusCode::SUCCESS;
297 }
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode::FAILURE
Definition: StatusCode.h:29
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:111
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:155
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:244

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

Get the value of the initialization loop check flag.

Definition at line 517 of file ServiceManager.cpp.

517 {
518 return m_loopCheck;
519 }
ServiceManager::m_loopCheck
bool m_loopCheck
Check for service initialization loops.
Definition: ServiceManager.h:170

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

Return the name of the manager (implementation of INamedInterface)

Definition at line 111 of file ServiceManager.h.

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

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

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

Definition at line 371 of file ServiceManager.cpp.

373 {
374 // ensure that the list is ordered by priority
375 m_listsvc.sort();
376 // we work on a copy to avoid to operate twice on the services created on demand
377 // which are already in the correct state.
378 // only act on active services
379 StatusCode sc(StatusCode::SUCCESS, true);
380 // Re-Initialize all services
381 for (auto& svc : activeSvc(m_listsvc)) {
382 sc = svc->sysReinitialize();
383 if( !sc.isSuccess() ) {
384 error() << "Unable to re-initialize Service: " << svc->name() << endmsg;
385 return StatusCode::FAILURE;
386 }
387 }
388 return StatusCode::SUCCESS;
389 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode::FAILURE
Definition: StatusCode.h:29
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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:155
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

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

implementation of ISvcManager::removeService

Definition at line 235 of file ServiceManager.cpp.

237 {
238 auto it = find(svc);
239 if (it == m_listsvc.end()) return StatusCode(StatusCode::FAILURE,true);
240 m_listsvc.erase(it);
241 return StatusCode(StatusCode::SUCCESS,true);
242 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode::FAILURE
Definition: StatusCode.h:29
std::list::end
T end(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::list::erase
T erase(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:155

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

implementation of ISvcManager::removeService

Definition at line 245 of file ServiceManager.cpp.

247 {
248 auto it = find(name);
249 if (it == m_listsvc.end()) return StatusCode::FAILURE;
250 m_listsvc.erase(it);
251 return StatusCode::SUCCESS;
252 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode::FAILURE
Definition: StatusCode.h:29
std::list::end
T end(T...args)
std::list::erase
T erase(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:155

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

Initialization (from RUNNING to RUNNING, via INITIALIZED).

Definition at line 392 of file ServiceManager.cpp.

394 {
395 // ensure that the list is ordered by priority
396 m_listsvc.sort();
397 // we work on a copy to avoid to operate twice on the services created on demand
398 // which are already in the correct state.
399 // only act on active services
400 StatusCode sc(StatusCode::SUCCESS, true);
401 // Re-Start all services
402 for (auto& svc : activeSvc(m_listsvc)) {
403 sc = svc->sysRestart();
404 if( !sc.isSuccess() ) {
405 error() << "Unable to re-start Service: " << svc->name() << endmsg;
406 return StatusCode::FAILURE;
407 }
408 }
409 return StatusCode::SUCCESS;
410 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode::FAILURE
Definition: StatusCode.h:29
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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:155
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

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

Returns a smart pointer to a service.

Definition at line 161 of file ServiceManager.cpp.

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

123 {
124 return SmartIF<T>{service( typeName, createIf )};
125 }
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
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:161

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

Function needed by CommonMessaging.

Definition at line 57 of file ServiceManager.h.

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

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

Set the value of the initialization loop check flag.

Definition at line 523 of file ServiceManager.cpp.

523 {
524 m_loopCheck = en;
525 }
ServiceManager::m_loopCheck
bool m_loopCheck
Check for service initialization loops.
Definition: ServiceManager.h:170

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

Definition at line 506 of file ServiceManager.cpp.

506 {
507 //------------------------------------------------------------------------------
508 auto it = find(name);
509 if (it == m_listsvc.end()) return StatusCode::FAILURE;
510 it->priority = prio;
511 return StatusCode::SUCCESS;
512 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode::FAILURE
Definition: StatusCode.h:29
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:155

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

Start (from INITIALIZED to RUNNING).

Definition at line 300 of file ServiceManager.cpp.

302 {
303 // ensure that the list is ordered by priority
304 m_listsvc.sort();
305 // we work on a copy to avoid to operate twice on the services created on demand
306 // (which are already in the correct state.
307 // only act on active services
308 StatusCode sc(StatusCode::SUCCESS, true);
309 // call initialize() for all services
310 for (auto& it : activeSvc(m_listsvc)) {
311 const std::string& name = it->name();
312 switch (it->FSMState()) {
313 case Gaudi::StateMachine::RUNNING:
314 DEBMSG << "Service " << name
315 << " already started" << endmsg;
316 break;
317 case Gaudi::StateMachine::INITIALIZED:
318 DEBMSG << "Starting service " << name << endmsg;
319 sc = it->sysStart();
320 if( !sc.isSuccess() ) {
321 error() << "Unable to start Service: " << name << endmsg;
322 return sc;
323 } break;
324 default:
325 error() << "Service " << name
326 << " not in the correct state to be started ("
327 << it->FSMState() << ")" << endmsg;
328 return StatusCode::FAILURE;
329 }
330 }
331 return StatusCode::SUCCESS;
332 }
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode::FAILURE
Definition: StatusCode.h:29
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:111
Gaudi::StateMachine::RUNNING
Definition: StateMachine.h:16
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:155
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

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

Stop (from RUNNING to INITIALIZED).

Definition at line 336 of file ServiceManager.cpp.

338 {
339 // ensure that the list is ordered by priority
340 m_listsvc.sort();
341 // we work on a copy to avoid to operate twice on the services created on demand
342 // which are already in the correct state.
343 // only act on active services
344
345 StatusCode sc(StatusCode::SUCCESS, true);
346 // call stop() for all services
347 for (const auto& svc : reverse(activeSvc(m_listsvc))) {
348 const std::string& name = svc->name();
349 switch (svc->FSMState()) {
350 case Gaudi::StateMachine::INITIALIZED:
351 DEBMSG << "Service " << name << " already stopped" << endmsg;
352 break;
353 case Gaudi::StateMachine::RUNNING:
354 DEBMSG << "Stopping service " << name << endmsg;
355 sc = svc->sysStop();
356 if( !sc.isSuccess() ) {
357 error() << "Unable to stop Service: " << name << endmsg;
358 return sc;
359 } break;
360 default:
361 DEBMSG << "Service " << name
362 << " not in the correct state to be stopped ("
363 << svc->FSMState() << ")" << endmsg;
364 return StatusCode::FAILURE;
365 }
366 }
367 return StatusCode::SUCCESS;
368 }
Gaudi::StateMachine::INITIALIZED
Definition: StateMachine.h:15
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode::FAILURE
Definition: StatusCode.h:29
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:111
reverse
reverse_wrapper< T > reverse(T &&iterable)
Definition: reverse.h:33
Gaudi::StateMachine::RUNNING
Definition: StateMachine.h:16
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:155
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

## Member Data Documentation

SmartIF<IService> ServiceManager::m_appSvc
| private

Pointer to the application IService interface.

Definition at line 173 of file ServiceManager.h.

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

Definition at line 178 of file ServiceManager.h.

Mutex_t ServiceManager::m_gLock
| mutable private

Definition at line 184 of file ServiceManager.h.

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

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

Definition at line 176 of file ServiceManager.h.

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 155 of file ServiceManager.h.

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

Definition at line 185 of file ServiceManager.h.

bool ServiceManager::m_loopCheck = true
| private

Check for service initialization loops.

Definition at line 170 of file ServiceManager.h.

MapType ServiceManager::m_maptype
| private

Map of service name and service type.

Definition at line 169 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