| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | 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 <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 extends2< ComponentManager, ISvcManager, ISvcLocator >
typedef extends2 | base_class
| Typedef to this class.
typedef extend_interfaces2 < ISvcManager, ISvcLocator > | extend_interfaces_base
| Typedef to the base of this class.
typedef extend_interfaces_base::ext_iids | interfaces
| MPL set of all the implemented interfaces.
Public Types inherited from extend_interfaces2< I1, I2 >
typedef mpl::fold< typename I1::iid::iids::type, typename I2::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type | ext_iids
| MPL set of interfaces extended by this one.

## Public Member Functions
| ServiceManager (IInterface *application)
| default creator
SmartIF< ISvcLocator > & | serviceLocator () const
| Function needed by CommonMessaging.
virtual | ~ServiceManager ()
| virtual destructor
virtual const std::list < IService * > & | getServices () const
| Return the list of Services.
virtual bool | existsService (const std::string &name) const
| implementation of ISvcLocation::existsService
virtual StatusCode | addService (IService *svc, int prio=DEFAULT_SVC_PRIORITY)
| implementation of ISvcManager::addService
virtual StatusCode | addService (const Gaudi::Utils::TypeNameString &typeName, int prio=DEFAULT_SVC_PRIORITY)
| implementation of ISvcManager::addService
virtual StatusCode | removeService (IService *svc)
| implementation of ISvcManager::removeService
virtual StatusCode | removeService (const std::string &name)
| implementation of ISvcManager::removeService
virtual StatusCode | declareSvcType (const std::string &svcname, const std::string &svctype)
| implementation of ISvcManager::declareSvcType
virtual SmartIF< IService > & | createService (const Gaudi::Utils::TypeNameString &nametype)
| implementation of ISvcManager::createService
virtual StatusCode | initialize ()
| Initialization (from CONFIGURED to INITIALIZED).
virtual StatusCode | start ()
| Start (from INITIALIZED to RUNNING).
virtual StatusCode | stop ()
| Stop (from RUNNING to INITIALIZED).
virtual StatusCode | finalize ()
| Finalize (from INITIALIZED to CONFIGURED).
virtual StatusCode | reinitialize ()
| Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
virtual StatusCode | restart ()
| Initialization (from RUNNING to RUNNING, via INITIALIZED).
virtual int | getPriority (const std::string &name) const
| manage priorities of services
virtual StatusCode | setPriority (const std::string &name, int pri)
virtual bool | loopCheckEnabled () const
| Get the value of the initialization loop check flag.
virtual void | setLoopCheckEnabled (bool en)
| Set the value of the initialization loop check flag.
const std::string & | name () const
| Return the name of the manager (implementation of INamedInterface)
virtual SmartIF< IService > & | service (const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
| Returns a smart pointer to a service.
Public Member Functions inherited from extends2< ComponentManager, ISvcManager, ISvcLocator >
| extends2 (A1 a1, A2 a2, A3 a3)
| Templated constructor with 3 arguments.
| extends2 (A1 a1, A2 a2)
| Templated constructor with 2 arguments.
| extends2 (A1 a1)
| Templated constructor with 1 argument.
| extends2 ()
| Default constructor.
virtual void * | i_cast (const InterfaceID &tid) const
| Implementation of IInterface::i_cast.
virtual StatusCode | queryInterface (const InterfaceID &ti, void **pp)
| Implementation of IInterface::queryInterface.
virtual std::vector< std::string > | getInterfaceNames () const
| Implementation of IInterface::getInterfaceNames.
virtual | ~extends2 ()
| Virtual destructor.
Public Member Functions inherited from ComponentManager
| ComponentManager (IInterface *application, const InterfaceID &baseIID)
| Constructor.
virtual const InterfaceID & | componentBaseInterface () const
| Basic interface id of the managed components.
virtual | ~ComponentManager ()
| Virtual destructor.
virtual StatusCode | configure ()
| Configuration (from OFFLINE to CONFIGURED).
virtual StatusCode | terminate ()
| Initialization (from CONFIGURED to OFFLINE).
virtual Gaudi::StateMachine::State | FSMState () const
| Get the current state.
virtual Gaudi::StateMachine::State | targetFSMState () const
| When we are in the middle of a transition, get the state where the transition is leading us.
Public Member Functions inherited from CommonMessaging< implements1< IComponentManager > >
| CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
| Templated constructor with 3 arguments.
| CommonMessaging (const A1 &a1, const A2 &a2)
| Templated constructor with 2 arguments.
| CommonMessaging (const A1 &a1)
| Templated constructor with 1 argument.
| CommonMessaging ()
| Default constructor.
virtual | ~CommonMessaging ()
| Virtual destructor.
SmartIF< IMessageSvc > & | msgSvc () const
| The standard message service.
MsgStream & | msgStream () const
| Return an uninitialized MsgStream.
MsgStream & | msgStream (const MSG::Level level) const
| Predefined configurable message stream for the efficient printouts.
MsgStream & | always () const
| shortcut for the method msgStream(MSG::ALWAYS)
MsgStream & | fatal () const
| shortcut for the method msgStream(MSG::FATAL)
MsgStream & | err () const
| shortcut for the method msgStream(MSG::ERROR)
MsgStream & | error () const
| shortcut for the method msgStream(MSG::ERROR)
MsgStream & | warning () const
| shortcut for the method msgStream(MSG::WARNING)
MsgStream & | info () const
| shortcut for the method msgStream(MSG::INFO)
MsgStream & | debug () const
| shortcut for the method msgStream(MSG::DEBUG)
MsgStream & | verbose () const
| shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & | msg () const
| shortcut for the method msgStream(MSG::INFO)
MSG::Level | msgLevel () const
| get the output level from the embedded MsgStream
bool | msgLevel (MSG::Level lvl) const
| get the output level from the embedded MsgStream
Public Member Functions inherited from extend_interfaces2< I1, I2 >
virtual | ~extend_interfaces2 ()
| Virtual destructor.

## 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.
MapType | m_maptype
| Map of service name and service type.
bool | m_loopCheck
| Check for service initialization loops.
SmartIF< IService > | m_appSvc
| Pointer to the application IService interface.
std::list< IService * > | m_listOfPtrs
| List of pointers to the know services used to implement getServices()
GaudiUtils::Map< InterfaceID, SmartIF< IInterface > > | m_defaultImplementations
boost::recursive_mutex | m_svcinitmutex
| Mutex to synchronize shared service initialization between threads.

## Additional Inherited Members
Static Public Member Functions inherited from IInterface
static const InterfaceID & | interfaceID ()
| Return an instance of InterfaceID identifying the interface.
Protected Member Functions inherited from CommonMessaging< implements1< IComponentManager > >
void | updateMsgStreamOutputLevel (int level)
| Update the output level of the cached MsgStream.
Protected Attributes inherited from ComponentManager
SmartIF< IInterface > | m_application
| Pointer to the owner of the manager.
SmartIF< IStateful > | m_stateful
| Pointer to the IStateful interface of the owner.
InterfaceID | m_basicInterfaceId
| Basic interface id of the managed components.
SmartIF< ISvcLocator > | m_svcLocator
| Service locator (needed to access the MessageSvc)

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

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

Definition at line 58 of file ServiceManager.h.

## Constructor & Destructor Documentation

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

default creator

Definition at line 27 of file ServiceManager.cpp.

:
base_class(application, IService::interfaceID()),
m_loopCheck(true),
m_appSvc(application)
{
// Set the service locator to myself
m_svcLocator = static_cast<ISvcLocator*>(this);
addRef(); // Initial count set to 1
}

ServiceManager::~ServiceManager | ( |  | ) |
| virtual

virtual destructor

Definition at line 39 of file ServiceManager.cpp.

{
//-- inform the orphan services that I am gone....
for (ListSvc::iterator it = m_listsvc.begin(); it != m_listsvc.end(); it++ ) {
it->service->setServiceManager(0);
}
}

## Member Function Documentation

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

implementation of ISvcManager::addService

Definition at line 95 of file ServiceManager.cpp.

{
ListSvc::iterator it = find(svc);
if (it != m_listsvc.end()) {
it->priority = prio; // if the service is already known, it is equivalent to a setPriority
it->active = true; // and make it active
} else {
m_listsvc.push_back(ServiceItem(svc,prio,true));
}
return StatusCode::SUCCESS;
}

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

implementation of ISvcManager::addService

Definition at line 110 of file ServiceManager.cpp.

{
ListSvc::iterator it = find(typeName.name()); // try to find the service by name
if (it == m_listsvc.end()) { // not found
// If the service does not exist, we create it
SmartIF<IService> &svc = createService(typeName);
if (svc.isValid()) {
it = find(svc.get()); // now it is in the list because createService added it
it->priority = prio;
StatusCode sc = StatusCode(StatusCode::SUCCESS, true);
if (targetFSMState() >= Gaudi::StateMachine::INITIALIZED) {
sc = svc->sysInitialize();
if (sc.isSuccess() && targetFSMState() >= Gaudi::StateMachine::RUNNING) {
sc = svc->sysStart();
}
}
if(sc.isFailure()) { // if initialization failed, remove it from the list
error() << "Unable to initialize service \"" << typeName.name() << "\""
<< endmsg;
m_listsvc.erase(it);
// Note: removing it from the list + the SmartIF going out of scope should trigger the delete
// delete svc.get();
return sc;
} else { // initialization successful, we can work with the service
// Move the just initialized service to the back of the list
// (we care more about order of initialization than of creation)
m_listsvc.push_back(*it);
m_listsvc.erase(it);
it = --m_listsvc.end(); // last entry (the iterator was invalidated by erase)
}
} else {
return StatusCode::FAILURE;
}
} else {
// if the service is already known, it is equivalent to a setPriority
it->priority = prio;
}
// 'it' is defined because either we found the service or we created it
// Now we can activate the service
it->active = true; // and make it active
return StatusCode(StatusCode::SUCCESS, true);
}

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

implementation of ISvcManager::createService

: check how this hack works

: what does this mean?

Definition at line 48 of file ServiceManager.cpp.

{
// Check if the service is already existing
if(existsService(typeName.name())) {
// return an error because a service with that name already exists
return no_service;
}
StatusCode rc = StatusCode::FAILURE;
rc.setChecked(); //hack to avoid going into infinite recursion on ~StatusCode
const std::string &name = typeName.name();
std::string type = typeName.type();
if (!typeName.haveType()) { // the type is not explicit
// see we have some specific type mapping for the name
MapType::iterator it = m_maptype.find(typeName.name());
if( it != m_maptype.end() ) {
type = (*it).second; // use the declared type
}
}
std::string::size_type ip;
if ( (ip = type.find("__")) != std::string::npos) {
type.erase(ip,type.length());
}
IService* service = Service::Factory::create(type, name, static_cast<ISvcLocator*>(this)); // serviceLocator().get());
if ( service ) {
m_listsvc.push_back(service);
// Check the compatibility of the version of the interface obtained
if( !isValidInterface(service) ) {
fatal() << "Incompatible interface IService version for " << type << endmsg;
return no_service;
}
service->setServiceManager(this);
return m_listsvc.back().service;
}
fatal() << "No Service factory for " << type << " available." << endmsg;
return no_service;
}

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

implementation of ISvcManager::declareSvcType

Definition at line 234 of file ServiceManager.cpp.

{
std::pair<MapType::iterator, bool> p = m_maptype.insert(std::make_pair(svcname, svctype));
if( p.second == false) {
m_maptype.erase ( p.first );
p = m_maptype.insert(std::make_pair(svcname, svctype) );
if( p.second == false) return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}

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

Definition at line 529 of file ServiceManager.cpp.

{
MsgStream log(msgSvc(),name());
log << MSG::INFO << "\n"
<< "===================== listing all services ===================\n"
<< " prior ref name active\n";
ListSvc::const_iterator it;
for (it=m_listsvc.begin(); it != m_listsvc.end(); ++it) {
log.width(6);
log.flags(std::ios_base::right);
log << it->priority << " ";
log.width(5);
log << it->service->refCount() << " ";
log.width(30);
log.flags(std::ios_base::left);
log << it->service->name() << " ";
log.width(2);
log << it->active << std::endl;
}
log << "=================================================================\n";
log << endmsg;
}

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

implementation of ISvcLocation::existsService

Definition at line 203 of file ServiceManager.cpp.

{
return find(name) != m_listsvc.end();
}

StatusCode ServiceManager::finalize | ( |  | ) |
| virtual

Finalize (from INITIALIZED to CONFIGURED).

Reimplemented from ComponentManager.

Definition at line 402 of file ServiceManager.cpp.

{
// make sure that HistogramDataSvc and THistSvc get finalized after the
// ToolSvc, and the FileMgr and StatusCodeSvc after that
int pri_tool = getPriority("ToolSvc");
if (pri_tool != 0) {
setPriority("THistSvc",pri_tool-10).ignore();
setPriority("ChronoStatSvc",pri_tool-20).ignore();
setPriority("AuditorSvc",pri_tool-30).ignore();
setPriority("NTupleSvc",pri_tool-10).ignore();
setPriority("HistogramDataSvc",pri_tool-10).ignore();
// Preserve the relative ordering between HistogramDataSvc and HistogramPersistencySvc
setPriority("HistogramPersistencySvc",pri_tool-20).ignore();
setPriority("HistorySvc",pri_tool-30).ignore();
setPriority("FileMgr",pri_tool-40).ignore();
}
// get list of PostFinalize clients
std::vector<IIncidentListener*> postFinList;
{
SmartIF<IIncidentSvc> p_inc(service("IncidentSvc",false));
if (p_inc.isValid()) {
p_inc->getListeners(postFinList,IncidentType::SvcPostFinalize);
}
}
// make sure the StatusCodeSvc gets finalized really late:
setPriority("StatusCodeSvc",-9999).ignore();
m_listsvc.sort(); // ensure that the list is ordered by priority
// dump();
StatusCode sc(StatusCode::SUCCESS, true);
{
// we work on a copy to avoid to operate twice on the services created on demand
// (which are already in the correct state).
ListSvc tmpList(m_listsvc);
// call finalize() for all services in reverse order
ListSvc::reverse_iterator rit;
for (rit = tmpList.rbegin(); rit != tmpList.rend(); ++rit ) {
if (!rit->active) continue; // only act on active services
const std::string& name = rit->service->name();
// ignore the current state for the moment
// if( Gaudi::StateMachine::INITIALIZED == rit->service->state() ) {
DEBMSG << "Finalizing service " << name << endmsg;
if ( !(rit->service->sysFinalize()).isSuccess() ) {
warning() << "Finalization of service " << name << " failed" << endmsg;
sc = StatusCode::FAILURE;
}
}
}
// call SvcPostFinalize on all clients
if (!postFinList.empty()) {
DEBMSG << "Will call SvcPostFinalize for " << postFinList.size() << " clients"
<< endmsg;
Incident inc("ServiceManager", IncidentType::SvcPostFinalize);
std::vector<IIncidentListener*>::iterator itr;
for (itr = postFinList.begin(); itr != postFinList.end(); ++itr) {
(*itr)->handle(inc);
}
}
// loop over all Active Services, removing them one by one.
// They should be deleted because the reference counting goes to 0.
DEBMSG << "Looping over all active services..." << endmsg;
ListSvc::iterator it = m_listsvc.begin();
while (it != m_listsvc.end()) {
DEBMSG << "---- " << it->service->name()
<< " (refCount = " << it->service->refCount() << ")"
<< endmsg;
if (it->service->refCount() < 1) {
warning() << "Too low reference count for " << it->service->name()
<< " (should not go below 1 at this point)" << endmsg;
it->service->addRef();
}
if (it->active) {
it = m_listsvc.erase(it);
} else {
++it;
}
}
return sc;
}

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

Definition at line 131 of file ServiceManager.h.

{
return std::find(m_listsvc.begin(), m_listsvc.end(), name);
}

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

Definition at line 134 of file ServiceManager.h.

{
return std::find(m_listsvc.begin(), m_listsvc.end(), name);
}

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

Definition at line 137 of file ServiceManager.h.

{
return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
}

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

Definition at line 140 of file ServiceManager.h.

{
return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
}

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

manage priorities of services

Definition at line 494 of file ServiceManager.cpp.

{
//------------------------------------------------------------------------------
ListSvc::const_iterator it = find(name);
return (it != m_listsvc.end()) ? it->priority: 0;
}

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

Return the list of Services.

Definition at line 192 of file ServiceManager.cpp.

{
m_listOfPtrs.clear();
for (ListSvc::const_iterator it = m_listsvc.begin(); it != m_listsvc.end(); ++it) {
m_listOfPtrs.push_back(const_cast<IService*>(it->service.get()));
}
return m_listOfPtrs;
}

StatusCode ServiceManager::initialize | ( |  | ) |
| virtual

Initialization (from CONFIGURED to INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 248 of file ServiceManager.cpp.

{
m_listsvc.sort(); // ensure that the list is ordered by priority
// we work on a copy to avoid to operate twice on the services created on demand
// (which are already in the correct state.
ListSvc tmpList(m_listsvc);
StatusCode sc(StatusCode::SUCCESS, true);
// call initialize() for all services
for (ListSvc::iterator it = tmpList.begin(); it != tmpList.end(); ++it ) {
if (!it->active) continue; // only act on active services
const std::string& name = it->service->name();
switch (it->service->FSMState()) {
case Gaudi::StateMachine::INITIALIZED:
DEBMSG << "Service " << name << " already initialized" << endmsg;
break;
case Gaudi::StateMachine::OFFLINE:
DEBMSG << "Initializing service " << name << endmsg;
sc = it->service->sysInitialize();
if( !sc.isSuccess() ) {
error() << "Unable to initialize Service: " << name << endmsg;
return sc;
} break;
default:
error() << "Service " << name
<< " not in the correct state to be initialized ("
<< it->service->FSMState() << ")" << endmsg;
return StatusCode::FAILURE;
}
}
return StatusCode::SUCCESS;
}

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

Get the value of the initialization loop check flag.

Definition at line 515 of file ServiceManager.cpp.

{
return m_loopCheck;
}

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

Return the name of the manager (implementation of INamedInterface)

Implements CommonMessaging< implements1< IComponentManager > >.

Definition at line 116 of file ServiceManager.h.

{
static std::string _name = "ServiceManager";
return _name;
}

StatusCode ServiceManager::reinitialize | ( |  | ) |
| virtual

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

Reimplemented from ComponentManager.

Definition at line 356 of file ServiceManager.cpp.

{
m_listsvc.sort(); // ensure that the list is ordered by priority
// we work on a copy to avoid to operate twice on the services created on demand
// (which are already in the correct state.
ListSvc tmpList(m_listsvc);
StatusCode sc(StatusCode::SUCCESS, true);
ListSvc::iterator it;
// Re-Initialize all services
for ( it = tmpList.begin(); it != tmpList.end(); ++it ) {
if (!it->active) continue; // only act on active services
sc = it->service->sysReinitialize();
if( !sc.isSuccess() ) {
error() << "Unable to re-initialize Service: " << it->service->name() << endmsg;
return StatusCode::FAILURE;
}
}
return StatusCode::SUCCESS;
}

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

implementation of ISvcManager::removeService

Definition at line 210 of file ServiceManager.cpp.

{
ListSvc::iterator it = find(svc);
if (it != m_listsvc.end()) {
m_listsvc.erase(it);
return StatusCode(StatusCode::SUCCESS,true);
}
return StatusCode(StatusCode::FAILURE,true);
}

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

implementation of ISvcManager::removeService

Definition at line 222 of file ServiceManager.cpp.

{
ListSvc::iterator it = find(name);
if (it != m_listsvc.end()) {
m_listsvc.erase(it);
return StatusCode::SUCCESS;
}
return StatusCode::FAILURE;
}

StatusCode ServiceManager::restart | ( |  | ) |
| virtual

Initialization (from RUNNING to RUNNING, via INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 379 of file ServiceManager.cpp.

{
m_listsvc.sort(); // ensure that the list is ordered by priority
// we work on a copy to avoid to operate twice on the services created on demand
// (which are already in the correct state.
ListSvc tmpList(m_listsvc);
StatusCode sc(StatusCode::SUCCESS, true);
ListSvc::iterator it;
// Re-Start all services
for ( it = tmpList.begin(); it != tmpList.end(); ++it ) {
if (!it->active) continue; // only act on active services
sc = it->service->sysRestart();
if( !sc.isSuccess() ) {
error() << "Unable to re-start Service: " << it->service->name() << endmsg;
return StatusCode::FAILURE;
}
}
return StatusCode::SUCCESS;
}

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

Returns a smart pointer to a service.

Definition at line 156 of file ServiceManager.cpp.

{
const std::string &name = typeName.name();
// Acquire the RAII lock to avoid simultaneous attempts from different threads to initialize a service
boost::lock_guard<boost::recursive_mutex> lck(m_svcinitmutex);
ListSvc::iterator it = find(name);
if (it != m_listsvc.end()) {
if (m_loopCheck &&
(createIf && it->service->FSMState() == Gaudi::StateMachine::CONFIGURED)) {
error()
<< "Initialization loop detected when creating service \"" << name
<< "\""
<< endmsg;
return no_service;
}
return it->service;
} else {
// Service not found. The user may be interested in one of the interfaces
// of the application manager itself
if( name == "ApplicationMgr" ||
name == "APPMGR" ||
name == "" ) {
return m_appSvc;
} else if ( createIf ){
//last resort: we try to create the service
if (addService(typeName).isSuccess()){
return find(name)->service;
}
}
}
return no_service;
}

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

Function needed by CommonMessaging.

Reimplemented from ComponentManager.

Definition at line 64 of file ServiceManager.h.

{
return m_svcLocator;
}

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

Set the value of the initialization loop check flag.

Definition at line 521 of file ServiceManager.cpp.

{
m_loopCheck = en;
}

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

Definition at line 502 of file ServiceManager.cpp.

{
//------------------------------------------------------------------------------
ListSvc::iterator it = find(name);
if (it != m_listsvc.end()) {
it->priority = prio;
return StatusCode::SUCCESS;
}
return StatusCode::FAILURE;
}

StatusCode ServiceManager::start | ( |  | ) |
| virtual

Start (from INITIALIZED to RUNNING).

Reimplemented from ComponentManager.

Definition at line 283 of file ServiceManager.cpp.

{
m_listsvc.sort(); // ensure that the list is ordered by priority
// we work on a copy to avoid to operate twice on the services created on demand
// (which are already in the correct state.
ListSvc tmpList(m_listsvc);
StatusCode sc(StatusCode::SUCCESS, true);
// call initialize() for all services
for (ListSvc::iterator it = tmpList.begin(); it != tmpList.end(); ++it ) {
if (!it->active) continue; // only act on active services
const std::string& name = it->service->name();
switch (it->service->FSMState()) {
case Gaudi::StateMachine::RUNNING:
DEBMSG << "Service " << name
<< " already started" << endmsg;
break;
case Gaudi::StateMachine::INITIALIZED:
DEBMSG << "Starting service " << name << endmsg;
sc = it->service->sysStart();
if( !sc.isSuccess() ) {
error() << "Unable to start Service: " << name << endmsg;
return sc;
} break;
default:
error() << "Service " << name
<< " not in the correct state to be started ("
<< it->service->FSMState() << ")" << endmsg;
return StatusCode::FAILURE;
}
}
return StatusCode::SUCCESS;
}

StatusCode ServiceManager::stop | ( |  | ) |
| virtual

Stop (from RUNNING to INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 320 of file ServiceManager.cpp.

{
m_listsvc.sort(); // ensure that the list is ordered by priority
// we work on a copy to avoid to operate twice on the services created on demand
// (which are already in the correct state.
ListSvc tmpList(m_listsvc);
StatusCode sc(StatusCode::SUCCESS, true);
ListSvc::reverse_iterator it;
// call stop() for all services
for (it = tmpList.rbegin(); it != tmpList.rend(); ++it ) {
if (!it->active) continue; // only act on active services
const std::string& name = it->service->name();
switch (it->service->FSMState()) {
case Gaudi::StateMachine::INITIALIZED:
DEBMSG << "Service " << name << " already stopped" << endmsg;
break;
case Gaudi::StateMachine::RUNNING:
DEBMSG << "Stopping service " << name << endmsg;
sc = it->service->sysStop();
if( !sc.isSuccess() ) {
error() << "Unable to stop Service: " << name << endmsg;
return sc;
} break;
default:
DEBMSG << "Service " << name
<< " not in the correct state to be stopped ("
<< it->service->FSMState() << ")" << endmsg;
return StatusCode::FAILURE;
}
}
return StatusCode::SUCCESS;
}

## Member Data Documentation

SmartIF<IService> ServiceManager::m_appSvc
| private

Pointer to the application IService interface.

Definition at line 150 of file ServiceManager.h.

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

Definition at line 155 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 153 of file ServiceManager.h.

ListSvc ServiceManager::m_listsvc
| private

List of service maintained by ServiceManager.

Definition at line 145 of file ServiceManager.h.

bool ServiceManager::m_loopCheck
| private

Check for service initialization loops.

Definition at line 147 of file ServiceManager.h.

MapType ServiceManager::m_maptype
| private

Map of service name and service type.

Definition at line 146 of file ServiceManager.h.

boost::recursive_mutex ServiceManager::m_svcinitmutex
| private

Mutex to synchronize shared service initialization between threads.

Definition at line 158 of file ServiceManager.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiCoreSvc/src/ApplicationMgr/ServiceManager.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiCoreSvc/src/ApplicationMgr/ServiceManager.cpp