| The Gaudi Framework v29r0 (ff2e7097)

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

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

Public Member Functions | Private Member Functions | Private Attributes | List of all members
ServiceLocatorHelper Class Reference

an helper to share the implementation of service() among the various kernel base classes More...

`#include <GaudiKernel/ServiceLocatorHelper.h>`

Collaboration diagram for ServiceLocatorHelper:
[legend]

## Public Member Functions
| ServiceLocatorHelper (ISvcLocator &svcLoc, const INamedInterface &requester)
| ServiceLocatorHelper (ISvcLocator &svcLoc, const std::string &loggedName, const std::string &requesterName)
| ServiceLocatorHelper (ISvcLocator &svcLoc, const std::string &requesterName)
| ServiceLocatorHelper (ISvcLocator &svcLoc, const MsgStream &log, const std::string &requesterName)
StatusCode | getService (const std::string &name, bool createIf, const InterfaceID &iid, void **ppSvc) const
StatusCode | locateService (const std::string &name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const
StatusCode | createService (const std::string &name, const InterfaceID &iid, void **ppSvc) const
StatusCode | createService (const std::string &type, const std::string &name, const InterfaceID &iid, void **ppSvc) const
SmartIF< IService > | service (const std::string &name, const bool quiet=false, const bool createIf=true) const
template<typename T >
SmartIF< T > | service (const std::string &name, const bool quiet=false, const bool createIf=true) const

## Private Member Functions
std::string | threadName () const
std::string | threadedName (const std::string &name) const
bool | isInThread () const
ISvcLocator * | serviceLocator () const
MsgStream & | log () const
const std::string & | requesterName () const

## Private Attributes
ISvcLocator & | m_svcLoc
MsgStream | m_msgLog
std::string | m_requesterName

## Detailed Description

an helper to share the implementation of service() among the various kernel base classes

Definition at line 17 of file ServiceLocatorHelper.h.

## Constructor & Destructor Documentation

ServiceLocatorHelper::ServiceLocatorHelper | ( | ISvcLocator & | svcLoc,
|  | const INamedInterface & | requester
| ) |  |
| inline

Definition at line 20 of file ServiceLocatorHelper.h.

21 : m_svcLoc( svcLoc )
22 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
23 , // use requester msg level
24 m_requesterName( requester.name() )
25 {
26 }
SmartIF< IMessageSvc >
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:78
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:79
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:77
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.

ServiceLocatorHelper::ServiceLocatorHelper | ( | ISvcLocator & | svcLoc,
|  | const std::string & | loggedName,
|  | const std::string & | requesterName
| ) |  |
| inline

Definition at line 27 of file ServiceLocatorHelper.h.

28 : m_svcLoc( svcLoc )
29 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), loggedName )
30 , // use requester msg level
31 m_requesterName( requesterName )
32 {
33 }
SmartIF< IMessageSvc >
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:78
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:79
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:77

ServiceLocatorHelper::ServiceLocatorHelper | ( | ISvcLocator & | svcLoc,
|  | const std::string & | requesterName
| ) |  |
| inline

Definition at line 34 of file ServiceLocatorHelper.h.

35 : m_svcLoc( svcLoc )
36 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
37 , // use requester msg level
38 m_requesterName( requesterName )
39 {
40 }
SmartIF< IMessageSvc >
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:78
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:79
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:77

ServiceLocatorHelper::ServiceLocatorHelper | ( | ISvcLocator & | svcLoc,
|  | const MsgStream & | log,
|  | const std::string & | requesterName
| ) |  |
| inline

Definition at line 42 of file ServiceLocatorHelper.h.

45 : m_svcLoc( svcLoc ), m_msgLog( log ), m_requesterName( requesterName )
46 {
47 }
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:78
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:79
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:77

## Member Function Documentation

StatusCode ServiceLocatorHelper::createService | ( | const std::string & | name,
|  | const InterfaceID & | iid,
|  | void ** | ppSvc
| ) |  | const

Definition at line 31 of file ServiceLocatorHelper.cpp.

32 {
33 auto theSvc = service( name, false, true );
34 if ( !theSvc ) return StatusCode::FAILURE;
35 StatusCode sc = theSvc->queryInterface( iid, ppSvc );
36 if ( !sc.isSuccess() ) {
37 *ppSvc = nullptr;
38 log() << MSG::ERROR << "ServiceLocatorHelper::createService: wrong interface id " << iid << " for service " << name
39 << endmsg;
40 }
41 return sc;
42 }
StatusCode::FAILURE
Definition: StatusCode.h:31
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:75
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
MSG::ERROR
Definition: IMessageSvc.h:16
ServiceLocatorHelper::service
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.cpp:50
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209

StatusCode ServiceLocatorHelper::createService | ( | const std::string & | type,
|  | const std::string & | name,
|  | const InterfaceID & | iid,
|  | void ** | ppSvc
| ) |  | const

Definition at line 44 of file ServiceLocatorHelper.cpp.

46 {
47 return createService( type + "/" + name, iid, ppSvc );
48 }
ServiceLocatorHelper::createService
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.cpp:31

StatusCode ServiceLocatorHelper::getService | ( | const std::string & | name,
|  | bool | createIf,
|  | const InterfaceID & | iid,
|  | void ** | ppSvc
| ) |  | const
| inline

Definition at line 50 of file ServiceLocatorHelper.h.

51 {
52 return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
53 }
ServiceLocatorHelper::locateService
StatusCode locateService(const std::string &name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const
Definition: ServiceLocatorHelper.cpp:16
ServiceLocatorHelper::createService
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.cpp:31

bool ServiceLocatorHelper::isInThread | ( |  | ) | const
| private

Definition at line 14 of file ServiceLocatorHelper.cpp.

14 { return isGaudiThreaded( requesterName() ); }
isGaudiThreaded
GAUDI_API bool isGaudiThreaded(const std::string &name)
test if current Gaudi object is running /will run in a thread
Definition: ThreadGaudi.cpp:76
ServiceLocatorHelper::requesterName
const std::string & requesterName() const
Definition: ServiceLocatorHelper.h:76

StatusCode ServiceLocatorHelper::locateService | ( | const std::string & | name,
|  | const InterfaceID & | iid,
|  | void ** | ppSvc,
|  | bool | quiet = `false`
| ) |  | const

Definition at line 16 of file ServiceLocatorHelper.cpp.

18 {
19 auto theSvc = service( name, quiet, false );
20 if ( !theSvc ) return StatusCode::FAILURE;
21 StatusCode sc = theSvc->queryInterface( iid, ppSvc );
22 if ( !sc.isSuccess() ) {
23 *ppSvc = nullptr;
24 if ( !quiet )
25 log() << MSG::ERROR << "ServiceLocatorHelper::locateService: wrong interface id " << iid << " for service "
26 << name << endmsg;
27 }
28 return sc;
29 }
StatusCode::FAILURE
Definition: StatusCode.h:31
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:75
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
MSG::ERROR
Definition: IMessageSvc.h:16
ServiceLocatorHelper::service
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.cpp:50
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209

MsgStream& ServiceLocatorHelper::log | ( |  | ) | const
| inline private

Definition at line 75 of file ServiceLocatorHelper.h.

75 { return m_msgLog; }
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:78

const std::string& ServiceLocatorHelper::requesterName | ( |  | ) | const
| inline private

Definition at line 76 of file ServiceLocatorHelper.h.

76 { return m_requesterName; }
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:79

SmartIF< IService > ServiceLocatorHelper::service | ( | const std::string & | name,
|  | const bool | quiet = `false`,
|  | const bool | createIf = `true`
| ) |  | const

Definition at line 50 of file ServiceLocatorHelper.cpp.

51 {
52 SmartIF<IService> theSvc;
53 if ( isInThread() ) {
54 // first we look for a thread-specific version of the service
55 theSvc = serviceLocator()->service( name + threadName(), createIf );
56 }
57 // if not, try to find the common, single-threaded version of the service
58 if ( !theSvc ) theSvc = serviceLocator()->service( name, createIf );
59
60 if ( theSvc ) {
61 if ( !quiet ) {
62 if ( UNLIKELY( log().level() <= MSG::VERBOSE ) )
63 log() << MSG::VERBOSE << "ServiceLocatorHelper::service: found service " << name << endmsg;
64 }
65 } else {
66 // if not return an error
67 if ( !quiet ) {
68 log() << MSG::ERROR << "ServiceLocatorHelper::service: can not locate service " << name;
69 if ( isInThread() ) log() << MSG::ERROR << " or " << name + threadName();
70 log() << MSG::ERROR << endmsg;
71 }
72 }
73 return theSvc;
74 }
ServiceLocatorHelper::serviceLocator
ISvcLocator * serviceLocator() const
Definition: ServiceLocatorHelper.h:74
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:128
SmartIF< IService >
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
ServiceLocatorHelper::threadName
std::string threadName() const
Definition: ServiceLocatorHelper.cpp:7
MSG::VERBOSE
Definition: IMessageSvc.h:16
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:75
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
ServiceLocatorHelper::isInThread
bool isInThread() const
Definition: ServiceLocatorHelper.cpp:14
MSG::ERROR
Definition: IMessageSvc.h:16
gaudirun.level
level
Definition: gaudirun.py:271
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
template<typename T >

SmartIF<T> ServiceLocatorHelper::service | ( | const std::string & | name,
|  | const bool | quiet = `false`,
|  | const bool | createIf = `true`
| ) |  | const
| inline

Definition at line 65 of file ServiceLocatorHelper.h.

66 {
67 return service( name, quiet, createIf ).as<T>();
68 }
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:115
ServiceLocatorHelper::service
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.cpp:50

ISvcLocator* ServiceLocatorHelper::serviceLocator | ( |  | ) | const
| inline private

Definition at line 74 of file ServiceLocatorHelper.h.

74 { return &m_svcLoc; }
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:77

std::string ServiceLocatorHelper::threadedName | ( | const std::string & | name | ) | const
| private

Definition at line 9 of file ServiceLocatorHelper.cpp.

10 {
11 return ( isInThread() ? name + threadName() : name );
12 }
ServiceLocatorHelper::threadName
std::string threadName() const
Definition: ServiceLocatorHelper.cpp:7
ServiceLocatorHelper::isInThread
bool isInThread() const
Definition: ServiceLocatorHelper.cpp:14

std::string ServiceLocatorHelper::threadName | ( |  | ) | const
| private

Definition at line 7 of file ServiceLocatorHelper.cpp.

7 { return getGaudiThreadIDfromName( requesterName() ); }
ServiceLocatorHelper::requesterName
const std::string & requesterName() const
Definition: ServiceLocatorHelper.h:76
getGaudiThreadIDfromName
GAUDI_API std::string getGaudiThreadIDfromName(const std::string &name)
helper function to extract Gaudi Thread ID from thread copy name
Definition: ThreadGaudi.cpp:27

## Member Data Documentation

MsgStream ServiceLocatorHelper::m_msgLog
| mutable private

Definition at line 78 of file ServiceLocatorHelper.h.

std::string ServiceLocatorHelper::m_requesterName
| private

Definition at line 79 of file ServiceLocatorHelper.h.

ISvcLocator& ServiceLocatorHelper::m_svcLoc
| private

Definition at line 77 of file ServiceLocatorHelper.h.

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

- GaudiKernel/GaudiKernel/ServiceLocatorHelper.h
- GaudiKernel/src/Lib/ServiceLocatorHelper.cpp