All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
Collaboration diagram for ServiceManager:

Classes

struct  ServiceItem
 

Public Types

typedef std::list< ServiceItemListSvc
 
typedef GaudiUtils::Map
< std::string, std::string > 
MapType
 
- Public Types inherited from extends2< ComponentManager, ISvcManager, ISvcLocator >
typedef extends2 base_class
 Typedef to this class. More...
 
typedef extend_interfaces2
< ISvcManager, ISvcLocator
extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from CommonMessaging< implements1< IComponentManager > >
typedef CommonMessaging base_class
 
- Public Types inherited from implements1< IComponentManager >
typedef implements1 base_class
 Typedef to this class. More...
 
typedef extend_interfaces1
< IComponentManager
extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from extend_interfaces1< IComponentManager >
typedef
IComponentManager::iid::iids::type 
ext_iids
 MPL set of interfaces extended by this one. More...
 
- Public Types inherited from IInterface
enum  Status { SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR }
 Return status. More...
 
typedef Gaudi::InterfaceId
< IInterface, 0, 0 > 
iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
- Public Types inherited from extend_interfaces2< ISvcManager, ISvcLocator >
typedef mpl::fold< typename
ISvcManager::iid::iids::type,
typename
ISvcLocator::iid::iids::type,
mpl::insert< mpl::_1, mpl::_2 >
>::type 
ext_iids
 MPL set of interfaces extended by this one. More...
 

Public Member Functions

 ServiceManager (IInterface *application)
 default creator More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 Function needed by CommonMessaging. More...
 
virtual ~ServiceManager ()
 virtual destructor More...
 
virtual const std::list
< IService * > & 
getServices () const
 Return the list of Services. More...
 
virtual bool existsService (const std::string &name) const
 implementation of ISvcLocation::existsService More...
 
virtual StatusCode addService (IService *svc, int prio=DEFAULT_SVC_PRIORITY)
 implementation of ISvcManager::addService More...
 
virtual StatusCode addService (const Gaudi::Utils::TypeNameString &typeName, int prio=DEFAULT_SVC_PRIORITY)
 implementation of ISvcManager::addService More...
 
virtual StatusCode removeService (IService *svc)
 implementation of ISvcManager::removeService More...
 
virtual StatusCode removeService (const std::string &name)
 implementation of ISvcManager::removeService More...
 
virtual StatusCode declareSvcType (const std::string &svcname, const std::string &svctype)
 implementation of ISvcManager::declareSvcType More...
 
virtual SmartIF< IService > & createService (const Gaudi::Utils::TypeNameString &nametype)
 implementation of ISvcManager::createService More...
 
virtual StatusCode initialize ()
 Initialization (from CONFIGURED to INITIALIZED). More...
 
virtual StatusCode start ()
 Start (from INITIALIZED to RUNNING). More...
 
virtual StatusCode stop ()
 Stop (from RUNNING to INITIALIZED). More...
 
virtual StatusCode finalize ()
 Finalize (from INITIALIZED to CONFIGURED). More...
 
virtual StatusCode reinitialize ()
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED). More...
 
virtual StatusCode restart ()
 Initialization (from RUNNING to RUNNING, via INITIALIZED). More...
 
virtual int getPriority (const std::string &name) const
 manage priorities of services More...
 
virtual StatusCode setPriority (const std::string &name, int pri)
 
virtual bool loopCheckEnabled () const
 Get the value of the initialization loop check flag. More...
 
virtual void setLoopCheckEnabled (bool en)
 Set the value of the initialization loop check flag. More...
 
const std::string & name () const
 Return the name of the manager (implementation of INamedInterface) More...
 
virtual SmartIF< IService > & service (const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
 Returns a smart pointer to a service. More...
 
- Public Member Functions inherited from extends2< ComponentManager, ISvcManager, ISvcLocator >
 extends2 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments. More...
 
 extends2 (A1 a1, A2 a2)
 Templated constructor with 2 arguments. More...
 
 extends2 (A1 a1)
 Templated constructor with 1 argument. More...
 
 extends2 ()
 Default constructor. More...
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface. More...
 
virtual std::vector< std::string > getInterfaceNames () const
 Implementation of IInterface::getInterfaceNames. More...
 
virtual ~extends2 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from ComponentManager
 ComponentManager (IInterface *application, const InterfaceID &baseIID)
 Constructor. More...
 
virtual const InterfaceIDcomponentBaseInterface () const
 Basic interface id of the managed components. More...
 
virtual ~ComponentManager ()
 Virtual destructor. More...
 
virtual StatusCode configure ()
 Configuration (from OFFLINE to CONFIGURED). More...
 
virtual StatusCode terminate ()
 Initialization (from CONFIGURED to OFFLINE). More...
 
virtual Gaudi::StateMachine::State FSMState () const
 Get the current state. More...
 
virtual Gaudi::StateMachine::State targetFSMState () const
 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< implements1< IComponentManager > >
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments. More...
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments. More...
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument. More...
 
 CommonMessaging ()
 Default constructor. More...
 
virtual ~CommonMessaging ()
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces1< IComponentManager >
virtual ~extend_interfaces1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IComponentManager
 DeclareInterfaceID (IComponentManager, 1, 0)
 InterfaceID. More...
 
virtual ~IComponentManager ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IStateful
 DeclareInterfaceID (IStateful, 1, 0)
 InterfaceID. More...
 
virtual ~IStateful ()
 
- Public Member Functions inherited from IInterface
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long release ()=0
 Release Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces2< ISvcManager, ISvcLocator >
virtual ~extend_interfaces2 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from ISvcManager
 DeclareInterfaceID (ISvcManager, 4, 0)
 InterfaceID. 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 declareSvcFactory (const ISvcFactory &, const std::string &)
 Declare an abstract factory for a given service type. 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...
 
virtual StatusCode getFactory (const std::string &, const ISvcFactory *&) const
 Access to service factory by name to create unmanaged services. More...
 
virtual StatusCode initializeServices ()
 Initializes the list of "active" services. More...
 
virtual StatusCode startServices ()
 Starts the list of "active" services. More...
 
virtual StatusCode stopServices ()
 Stops the list of "active" services. More...
 
virtual StatusCode finalizeServices ()
 Finalizes the list of "active" services. More...
 
virtual StatusCode reinitializeServices ()
 Reinitializes the list of "active" services. More...
 
virtual StatusCode restartServices ()
 Restarts the list of "active" services. More...
 
- Public Member Functions inherited from ISvcLocator
 DeclareInterfaceID (ISvcLocator, 3, 0)
 InterfaceID. More...
 
virtual StatusCode getService (const Gaudi::Utils::TypeNameString &typeName, IService *&svc, const bool createIf=true)
 Get a reference to the service given a service name. More...
 
virtual StatusCode getService (const Gaudi::Utils::TypeNameString &typeName, const InterfaceID &iid, IInterface *&pinterface)
 Get a specific interface pointer given a service name and interface id. More...
 
template<class T >
StatusCode service (const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
 Templated method to access a service by name. More...
 
template<class T >
StatusCode service (const std::string &type, const std::string &name, T *&svc, bool createIf=true)
 Templated method to access a service by type and name. 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...
 

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. More...
 
MapType m_maptype
 Map of service name and service type. More...
 
bool m_loopCheck
 Check for service initialization loops. More...
 
SmartIF< IServicem_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
 
boost::recursive_mutex m_svcinitmutex
 Mutex to synchronize shared service initialization between threads. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 
- Static Public Attributes inherited from ISvcManager
static const int DEFAULT_SVC_PRIORITY = 100
 
- Protected Member Functions inherited from CommonMessaging< implements1< IComponentManager > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from ComponentManager
SmartIF< IInterfacem_application
 Pointer to the owner of the manager. More...
 
SmartIF< IStatefulm_stateful
 Pointer to the IStateful interface of the owner. More...
 
InterfaceID m_basicInterfaceId
 Basic interface id of the managed components. More...
 
SmartIF< ISvcLocatorm_svcLocator
 Service locator (needed to access the MessageSvc) More...
 
- Protected Attributes inherited from CommonMessaging< implements1< IComponentManager > >
SmartIF< IMessageSvcm_msgsvc
 Pointer to the message service;. More...
 
std::auto_ptr< MsgStreamm_msgStream
 The predefined message stream. More...
 
bool m_streamWithService
 Flag to create a new MsgStream if it was created without the message service. 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

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.

27  :
28  base_class(application, IService::interfaceID()),
29  m_loopCheck(true),
30  m_appSvc(application)
31 {
32  // Set the service locator to myself
33  m_svcLocator = static_cast<ISvcLocator*>(this);
34 
35  addRef(); // Initial count set to 1
36 }
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
extends2 base_class
Typedef to this class.
Definition: extends.h:77
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
bool m_loopCheck
Check for service initialization loops.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Definition: IInterface.h:171
ServiceManager::~ServiceManager ( )
virtual

virtual destructor

Definition at line 39 of file ServiceManager.cpp.

39  {
40  //-- inform the orphan services that I am gone....
41  for (ListSvc::iterator it = m_listsvc.begin(); it != m_listsvc.end(); it++ ) {
42  it->service->setServiceManager(0);
43  }
44 }
ListSvc m_listsvc
List of service maintained by ServiceManager.

Member Function Documentation

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

implementation of ISvcManager::addService

Implements ISvcManager.

Definition at line 95 of file ServiceManager.cpp.

97 {
98  ListSvc::iterator it = find(svc);
99  if (it != m_listsvc.end()) {
100  it->priority = prio; // if the service is already known, it is equivalent to a setPriority
101  it->active = true; // and make it active
102  } else {
103  m_listsvc.push_back(ServiceItem(svc,prio,true));
104  }
105  return StatusCode::SUCCESS;
106 }
ListSvc::iterator find(const std::string &name)
ListSvc m_listsvc
List of service maintained by ServiceManager.
StatusCode ServiceManager::addService ( const Gaudi::Utils::TypeNameString typeName,
int  prio = DEFAULT_SVC_PRIORITY 
)
virtual

implementation of ISvcManager::addService

Implements ISvcManager.

Definition at line 110 of file ServiceManager.cpp.

112 {
113  ListSvc::iterator it = find(typeName.name()); // try to find the service by name
114  if (it == m_listsvc.end()) { // not found
115  // If the service does not exist, we create it
116  SmartIF<IService> &svc = createService(typeName);
117  if (svc.isValid()) {
118  it = find(svc.get()); // now it is in the list because createService added it
119  it->priority = prio;
122  sc = svc->sysInitialize();
124  sc = svc->sysStart();
125  }
126  }
127  if(sc.isFailure()) { // if initialization failed, remove it from the list
128  error() << "Unable to initialize service \"" << typeName.name() << "\""
129  << endmsg;
130  m_listsvc.erase(it);
131  // Note: removing it from the list + the SmartIF going out of scope should trigger the delete
132  // delete svc.get();
133  return sc;
134  } else { // initialization successful, we can work with the service
135  // Move the just initialized service to the back of the list
136  // (we care more about order of initialization than of creation)
137  m_listsvc.push_back(*it);
138  m_listsvc.erase(it);
139  it = --m_listsvc.end(); // last entry (the iterator was invalidated by erase)
140  }
141  } else {
142  return StatusCode::FAILURE;
143  }
144  } else {
145  // if the service is already known, it is equivalent to a setPriority
146  it->priority = prio;
147  }
148  // 'it' is defined because either we found the service or we created it
149  // Now we can activate the service
150  it->active = true; // and make it active
151  return StatusCode(StatusCode::SUCCESS, true);
152 }
virtual Gaudi::StateMachine::State targetFSMState() const
When we are in the middle of a transition, get the state where the transition is leading us...
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:72
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
virtual SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype)
implementation of ISvcManager::createService
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
ListSvc::iterator find(const std::string &name)
const std::string & name() const
ListSvc m_listsvc
List of service maintained by ServiceManager.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
SmartIF< IService > & ServiceManager::createService ( const Gaudi::Utils::TypeNameString nametype)
virtual

implementation of ISvcManager::createService

Fix-Me:
: check how this hack works
Fix-Me:
: what does this mean?

Implements ISvcManager.

Definition at line 48 of file ServiceManager.cpp.

50 {
51  // Check if the service is already existing
52  if(existsService(typeName.name())) {
53  // return an error because a service with that name already exists
54  return no_service;
55  }
56 
59  rc.setChecked(); //hack to avoid going into infinite recursion on ~StatusCode
60 
61  const std::string &name = typeName.name();
62  std::string type = typeName.type();
63  if (!typeName.haveType()) { // the type is not explicit
64  // see we have some specific type mapping for the name
66  if( it != m_maptype.end() ) {
67  type = (*it).second; // use the declared type
68  }
69  }
70 
72  std::string::size_type ip;
73  if ( (ip = type.find("__")) != std::string::npos) {
74  type.erase(ip,type.length());
75  }
76 
77  IService* service = Service::Factory::create(type, name, static_cast<ISvcLocator*>(this)); // serviceLocator().get());
78 
79  if ( service ) {
80  m_listsvc.push_back(service);
81  // Check the compatibility of the version of the interface obtained
82  if( !isValidInterface(service) ) {
83  fatal() << "Incompatible interface IService version for " << type << endmsg;
84  return no_service;
85  }
86  service->setServiceManager(this);
87  return m_listsvc.back().service;
88  }
89  fatal() << "No Service factory for " << type << " available." << endmsg;
90  return no_service;
91 }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
Definition: IInterface.h:257
MapType m_maptype
Map of service name and service type.
iterator end()
Definition: Map.h:131
string type
Definition: gaudirun.py:126
General service interface definition.
Definition: IService.h:19
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
iterator find(const key_type &key)
Definition: Map.h:148
tuple rc
Definition: IOTest.py:92
virtual bool existsService(const std::string &name) const
implementation of ISvcLocation::existsService
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
Returns a smart pointer to a service.
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:22
ListSvc m_listsvc
List of service maintained by ServiceManager.
virtual void setServiceManager(ISvcManager *)=0
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
void setChecked() const
Ignore the checking code;.
Definition: StatusCode.h:91
StatusCode ServiceManager::declareSvcType ( const std::string &  svcname,
const std::string &  svctype 
)
virtual

implementation of ISvcManager::declareSvcType

Implements ISvcManager.

Definition at line 234 of file ServiceManager.cpp.

237 {
238  std::pair<MapType::iterator, bool> p = m_maptype.insert(std::make_pair(svcname, svctype));
239  if( p.second == false) {
240  m_maptype.erase ( p.first );
241  p = m_maptype.insert(std::make_pair(svcname, svctype) );
242  if( p.second == false) return StatusCode::FAILURE;
243  }
244  return StatusCode::SUCCESS;
245 }
MapType m_maptype
Map of service name and service type.
void erase(iterator pos)
Definition: Map.h:173
std::pair< iterator, bool > insert(const value_type &val)
Definition: Map.h:165
void ServiceManager::dump ( ) const
private

Definition at line 529 of file ServiceManager.cpp.

529  {
530 
531  MsgStream log(msgSvc(),name());
532 
533  log << MSG::INFO << "\n"
534  << "===================== listing all services ===================\n"
535  << " prior ref name active\n";
536 
537  ListSvc::const_iterator it;
538  for (it=m_listsvc.begin(); it != m_listsvc.end(); ++it) {
539 
540  log.width(6);
541  log.flags(std::ios_base::right);
542  log << it->priority << " ";
543  log.width(5);
544  log << it->service->refCount() << " ";
545  log.width(30);
546  log.flags(std::ios_base::left);
547  log << it->service->name() << " ";
548  log.width(2);
549  log << it->active << std::endl;
550 
551  }
552 
553  log << "=================================================================\n";
554  log << endmsg;
555 
556 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
ListSvc m_listsvc
List of service maintained by ServiceManager.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
bool ServiceManager::existsService ( const std::string &  name) const
virtual

implementation of ISvcLocation::existsService

Implements ISvcLocator.

Definition at line 203 of file ServiceManager.cpp.

205 {
206  return find(name) != m_listsvc.end();
207 }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
ListSvc::iterator find(const std::string &name)
ListSvc m_listsvc
List of service maintained by ServiceManager.
StatusCode ServiceManager::finalize ( )
virtual

Finalize (from INITIALIZED to CONFIGURED).

Reimplemented from ComponentManager.

Definition at line 402 of file ServiceManager.cpp.

404 {
405  // make sure that HistogramDataSvc and THistSvc get finalized after the
406  // ToolSvc, and the FileMgr and StatusCodeSvc after that
407  int pri_tool = getPriority("ToolSvc");
408  if (pri_tool != 0) {
409  setPriority("THistSvc",pri_tool-10).ignore();
410  setPriority("ChronoStatSvc",pri_tool-20).ignore();
411  setPriority("AuditorSvc",pri_tool-30).ignore();
412  setPriority("NTupleSvc",pri_tool-10).ignore();
413  setPriority("HistogramDataSvc",pri_tool-10).ignore();
414  // Preserve the relative ordering between HistogramDataSvc and HistogramPersistencySvc
415  setPriority("HistogramPersistencySvc",pri_tool-20).ignore();
416  setPriority("HistorySvc",pri_tool-30).ignore();
417  setPriority("FileMgr",pri_tool-40).ignore();
418  }
419 
420 
421  // get list of PostFinalize clients
422  std::vector<IIncidentListener*> postFinList;
423  {
424  SmartIF<IIncidentSvc> p_inc(service("IncidentSvc",false));
425  if (p_inc.isValid()) {
426  p_inc->getListeners(postFinList,IncidentType::SvcPostFinalize);
427  }
428  }
429 
430  // make sure the StatusCodeSvc gets finalized really late:
431  setPriority("StatusCodeSvc",-9999).ignore();
432 
433  m_listsvc.sort(); // ensure that the list is ordered by priority
434  // dump();
435 
437  {
438  // we work on a copy to avoid to operate twice on the services created on demand
439  // (which are already in the correct state).
440  ListSvc tmpList(m_listsvc);
441 
442  // call finalize() for all services in reverse order
443  ListSvc::reverse_iterator rit;
444  for (rit = tmpList.rbegin(); rit != tmpList.rend(); ++rit ) {
445  if (!rit->active) continue; // only act on active services
446  const std::string& name = rit->service->name();
447  // ignore the current state for the moment
448  // if( Gaudi::StateMachine::INITIALIZED == rit->service->state() ) {
449  DEBMSG << "Finalizing service " << name << endmsg;
450  if ( !(rit->service->sysFinalize()).isSuccess() ) {
451  warning() << "Finalization of service " << name << " failed" << endmsg;
453  }
454  }
455  }
456 
457  // call SvcPostFinalize on all clients
458  if (!postFinList.empty()) {
459  DEBMSG << "Will call SvcPostFinalize for " << postFinList.size() << " clients"
460  << endmsg;
461  Incident inc("ServiceManager", IncidentType::SvcPostFinalize);
462  std::vector<IIncidentListener*>::iterator itr;
463  for (itr = postFinList.begin(); itr != postFinList.end(); ++itr) {
464  (*itr)->handle(inc);
465  }
466  }
467 
468  // loop over all Active Services, removing them one by one.
469  // They should be deleted because the reference counting goes to 0.
470  DEBMSG << "Looping over all active services..." << endmsg;
471  ListSvc::iterator it = m_listsvc.begin();
472  while (it != m_listsvc.end()) {
473  DEBMSG << "---- " << it->service->name()
474  << " (refCount = " << it->service->refCount() << ")"
475  << endmsg;
476  if (it->service->refCount() < 1) {
477  warning() << "Too low reference count for " << it->service->name()
478  << " (should not go below 1 at this point)" << endmsg;
479  it->service->addRef();
480  }
481  if (it->active) {
482  it = m_listsvc.erase(it);
483  } else {
484  ++it;
485  }
486  }
487 
488  return sc;
489 }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
virtual int getPriority(const std::string &name) const
manage priorities of services
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
const std::string SvcPostFinalize
ONLY For Services that need something after they've been finalized.
Definition: Incident.h:91
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode setPriority(const std::string &name, int pri)
Base class for all Incidents (computing events).
Definition: Incident.h:16
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
Returns a smart pointer to a service.
#define DEBMSG
void ignore() const
Definition: StatusCode.h:94
std::list< ServiceItem > ListSvc
ListSvc m_listsvc
List of service maintained by ServiceManager.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
ListSvc::iterator ServiceManager::find ( const std::string &  name)
inlineprivate

Definition at line 131 of file ServiceManager.h.

131  {
132  return std::find(m_listsvc.begin(), m_listsvc.end(), name);
133  }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
ListSvc m_listsvc
List of service maintained by ServiceManager.
ListSvc::const_iterator ServiceManager::find ( const std::string &  name) const
inlineprivate

Definition at line 134 of file ServiceManager.h.

134  {
135  return std::find(m_listsvc.begin(), m_listsvc.end(), name);
136  }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
ListSvc m_listsvc
List of service maintained by ServiceManager.
ListSvc::iterator ServiceManager::find ( const IService ptr)
inlineprivate

Definition at line 137 of file ServiceManager.h.

137  {
138  return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
139  }
ListSvc m_listsvc
List of service maintained by ServiceManager.
ListSvc::const_iterator ServiceManager::find ( const IService ptr) const
inlineprivate

Definition at line 140 of file ServiceManager.h.

140  {
141  return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
142  }
ListSvc m_listsvc
List of service maintained by ServiceManager.
int ServiceManager::getPriority ( const std::string &  name) const
virtual

manage priorities of services

Implements ISvcManager.

Definition at line 494 of file ServiceManager.cpp.

494  {
495 //------------------------------------------------------------------------------
496  ListSvc::const_iterator it = find(name);
497  return (it != m_listsvc.end()) ? it->priority: 0;
498 }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
ListSvc::iterator find(const std::string &name)
ListSvc m_listsvc
List of service maintained by ServiceManager.
const std::list< IService * > & ServiceManager::getServices ( ) const
virtual

Return the list of Services.

Implements ISvcLocator.

Definition at line 192 of file ServiceManager.cpp.

194 {
195  m_listOfPtrs.clear();
196  for (ListSvc::const_iterator it = m_listsvc.begin(); it != m_listsvc.end(); ++it) {
197  m_listOfPtrs.push_back(const_cast<IService*>(it->service.get()));
198  }
199  return m_listOfPtrs;
200 }
std::list< IService * > m_listOfPtrs
List of pointers to the know services used to implement getServices()
ListSvc m_listsvc
List of service maintained by ServiceManager.
StatusCode ServiceManager::initialize ( )
virtual

Initialization (from CONFIGURED to INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 248 of file ServiceManager.cpp.

250 {
251  m_listsvc.sort(); // ensure that the list is ordered by priority
252  // we work on a copy to avoid to operate twice on the services created on demand
253  // (which are already in the correct state.
254  ListSvc tmpList(m_listsvc);
255 
257  // call initialize() for all services
258  for (ListSvc::iterator it = tmpList.begin(); it != tmpList.end(); ++it ) {
259  if (!it->active) continue; // only act on active services
260  const std::string& name = it->service->name();
261  switch (it->service->FSMState()) {
263  DEBMSG << "Service " << name << " already initialized" << endmsg;
264  break;
266  DEBMSG << "Initializing service " << name << endmsg;
267  sc = it->service->sysInitialize();
268  if( !sc.isSuccess() ) {
269  error() << "Unable to initialize Service: " << name << endmsg;
270  return sc;
271  } break;
272  default:
273  error() << "Service " << name
274  << " not in the correct state to be initialized ("
275  << it->service->FSMState() << ")" << endmsg;
276  return StatusCode::FAILURE;
277  }
278  }
279  return StatusCode::SUCCESS;
280 }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
#define DEBMSG
std::list< ServiceItem > ListSvc
ListSvc m_listsvc
List of service maintained by ServiceManager.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
bool ServiceManager::loopCheckEnabled ( ) const
virtual

Get the value of the initialization loop check flag.

Implements ISvcManager.

Definition at line 515 of file ServiceManager.cpp.

515  {
516  return m_loopCheck;
517 }
bool m_loopCheck
Check for service initialization loops.
const std::string& ServiceManager::name ( ) const
inlinevirtual

Return the name of the manager (implementation of INamedInterface)

Implements CommonMessaging< implements1< IComponentManager > >.

Definition at line 116 of file ServiceManager.h.

116  {
117  static std::string _name = "ServiceManager";
118  return _name;
119  }
StatusCode ServiceManager::reinitialize ( )
virtual

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

Reimplemented from ComponentManager.

Definition at line 356 of file ServiceManager.cpp.

358 {
359  m_listsvc.sort(); // ensure that the list is ordered by priority
360  // we work on a copy to avoid to operate twice on the services created on demand
361  // (which are already in the correct state.
362  ListSvc tmpList(m_listsvc);
363 
365  ListSvc::iterator it;
366  // Re-Initialize all services
367  for ( it = tmpList.begin(); it != tmpList.end(); ++it ) {
368  if (!it->active) continue; // only act on active services
369  sc = it->service->sysReinitialize();
370  if( !sc.isSuccess() ) {
371  error() << "Unable to re-initialize Service: " << it->service->name() << endmsg;
372  return StatusCode::FAILURE;
373  }
374  }
375  return StatusCode::SUCCESS;
376 }
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::list< ServiceItem > ListSvc
ListSvc m_listsvc
List of service maintained by ServiceManager.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
StatusCode ServiceManager::removeService ( IService svc)
virtual

implementation of ISvcManager::removeService

Implements ISvcManager.

Definition at line 210 of file ServiceManager.cpp.

212 {
213  ListSvc::iterator it = find(svc);
214  if (it != m_listsvc.end()) {
215  m_listsvc.erase(it);
216  return StatusCode(StatusCode::SUCCESS,true);
217  }
218  return StatusCode(StatusCode::FAILURE,true);
219 }
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
ListSvc::iterator find(const std::string &name)
ListSvc m_listsvc
List of service maintained by ServiceManager.
StatusCode ServiceManager::removeService ( const std::string &  name)
virtual

implementation of ISvcManager::removeService

Implements ISvcManager.

Definition at line 222 of file ServiceManager.cpp.

224 {
225  ListSvc::iterator it = find(name);
226  if (it != m_listsvc.end()) {
227  m_listsvc.erase(it);
228  return StatusCode::SUCCESS;
229  }
230  return StatusCode::FAILURE;
231 }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
ListSvc::iterator find(const std::string &name)
ListSvc m_listsvc
List of service maintained by ServiceManager.
StatusCode ServiceManager::restart ( )
virtual

Initialization (from RUNNING to RUNNING, via INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 379 of file ServiceManager.cpp.

381 {
382  m_listsvc.sort(); // ensure that the list is ordered by priority
383  // we work on a copy to avoid to operate twice on the services created on demand
384  // (which are already in the correct state.
385  ListSvc tmpList(m_listsvc);
386 
388  ListSvc::iterator it;
389  // Re-Start all services
390  for ( it = tmpList.begin(); it != tmpList.end(); ++it ) {
391  if (!it->active) continue; // only act on active services
392  sc = it->service->sysRestart();
393  if( !sc.isSuccess() ) {
394  error() << "Unable to re-start Service: " << it->service->name() << endmsg;
395  return StatusCode::FAILURE;
396  }
397  }
398  return StatusCode::SUCCESS;
399 }
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::list< ServiceItem > ListSvc
ListSvc m_listsvc
List of service maintained by ServiceManager.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
SmartIF< IService > & ServiceManager::service ( const Gaudi::Utils::TypeNameString typeName,
const bool  createIf = true 
)
virtual

Returns a smart pointer to a service.

Implements ISvcLocator.

Definition at line 156 of file ServiceManager.cpp.

156  {
157  const std::string &name = typeName.name();
158 
159  // Acquire the RAII lock to avoid simultaneous attempts from different threads to initialize a service
160  boost::lock_guard<boost::recursive_mutex> lck(m_svcinitmutex);
161 
162  ListSvc::iterator it = find(name);
163 
164  if (it != m_listsvc.end()) {
165  if (m_loopCheck &&
166  (createIf && it->service->FSMState() == Gaudi::StateMachine::CONFIGURED)) {
167  error()
168  << "Initialization loop detected when creating service \"" << name
169  << "\""
170  << endmsg;
171  return no_service;
172  }
173  return it->service;
174  } else {
175  // Service not found. The user may be interested in one of the interfaces
176  // of the application manager itself
177  if( name == "ApplicationMgr" ||
178  name == "APPMGR" ||
179  name == "" ) {
180  return m_appSvc;
181  } else if ( createIf ){
182  //last resort: we try to create the service
183  if (addService(typeName).isSuccess()){
184  return find(name)->service;
185  }
186  }
187  }
188  return no_service;
189 }
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
bool m_loopCheck
Check for service initialization loops.
virtual StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY)
implementation of ISvcManager::addService
ListSvc::iterator find(const std::string &name)
const std::string & name() const
boost::recursive_mutex m_svcinitmutex
Mutex to synchronize shared service initialization between threads.
ListSvc m_listsvc
List of service maintained by ServiceManager.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
SmartIF<ISvcLocator>& ServiceManager::serviceLocator ( ) const
inlinevirtual

Function needed by CommonMessaging.

Reimplemented from ComponentManager.

Definition at line 64 of file ServiceManager.h.

64  {
65  return m_svcLocator;
66  }
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
void ServiceManager::setLoopCheckEnabled ( bool  en)
virtual

Set the value of the initialization loop check flag.

Implements ISvcManager.

Definition at line 521 of file ServiceManager.cpp.

521  {
522  m_loopCheck = en;
523 }
bool m_loopCheck
Check for service initialization loops.
StatusCode ServiceManager::setPriority ( const std::string &  name,
int  pri 
)
virtual

Implements ISvcManager.

Definition at line 502 of file ServiceManager.cpp.

502  {
503 //------------------------------------------------------------------------------
504  ListSvc::iterator it = find(name);
505  if (it != m_listsvc.end()) {
506  it->priority = prio;
507  return StatusCode::SUCCESS;
508  }
509  return StatusCode::FAILURE;
510 }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
ListSvc::iterator find(const std::string &name)
ListSvc m_listsvc
List of service maintained by ServiceManager.
StatusCode ServiceManager::start ( )
virtual

Start (from INITIALIZED to RUNNING).

Reimplemented from ComponentManager.

Definition at line 283 of file ServiceManager.cpp.

285 {
286  m_listsvc.sort(); // ensure that the list is ordered by priority
287  // we work on a copy to avoid to operate twice on the services created on demand
288  // (which are already in the correct state.
289  ListSvc tmpList(m_listsvc);
290 
292  // call initialize() for all services
293  for (ListSvc::iterator it = tmpList.begin(); it != tmpList.end(); ++it ) {
294  if (!it->active) continue; // only act on active services
295  const std::string& name = it->service->name();
296  switch (it->service->FSMState()) {
298  DEBMSG << "Service " << name
299  << " already started" << endmsg;
300  break;
302  DEBMSG << "Starting service " << name << endmsg;
303  sc = it->service->sysStart();
304  if( !sc.isSuccess() ) {
305  error() << "Unable to start Service: " << name << endmsg;
306  return sc;
307  } break;
308  default:
309  error() << "Service " << name
310  << " not in the correct state to be started ("
311  << it->service->FSMState() << ")" << endmsg;
312  return StatusCode::FAILURE;
313  }
314  }
315  return StatusCode::SUCCESS;
316 }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
#define DEBMSG
std::list< ServiceItem > ListSvc
ListSvc m_listsvc
List of service maintained by ServiceManager.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
StatusCode ServiceManager::stop ( )
virtual

Stop (from RUNNING to INITIALIZED).

Reimplemented from ComponentManager.

Definition at line 320 of file ServiceManager.cpp.

322 {
323  m_listsvc.sort(); // ensure that the list is ordered by priority
324  // we work on a copy to avoid to operate twice on the services created on demand
325  // (which are already in the correct state.
326  ListSvc tmpList(m_listsvc);
327 
329  ListSvc::reverse_iterator it;
330  // call stop() for all services
331  for (it = tmpList.rbegin(); it != tmpList.rend(); ++it ) {
332  if (!it->active) continue; // only act on active services
333  const std::string& name = it->service->name();
334  switch (it->service->FSMState()) {
336  DEBMSG << "Service " << name << " already stopped" << endmsg;
337  break;
339  DEBMSG << "Stopping service " << name << endmsg;
340  sc = it->service->sysStop();
341  if( !sc.isSuccess() ) {
342  error() << "Unable to stop Service: " << name << endmsg;
343  return sc;
344  } break;
345  default:
346  DEBMSG << "Service " << name
347  << " not in the correct state to be stopped ("
348  << it->service->FSMState() << ")" << endmsg;
349  return StatusCode::FAILURE;
350  }
351  }
352  return StatusCode::SUCCESS;
353 }
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
#define DEBMSG
std::list< ServiceItem > ListSvc
ListSvc m_listsvc
List of service maintained by ServiceManager.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243

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
mutableprivate

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: