| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 19 of file ServiceLocatorHelper.h.

19 :
20 m_svcLoc(svcLoc),
21 m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requester.name()), //use requester msg level
22 m_requesterName(requester.name()) {
23 }
SmartIF< IMessageSvc >
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:80
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:81
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:79
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 24 of file ServiceLocatorHelper.h.

26 :
27 m_svcLoc(svcLoc),
28 m_msgLog(SmartIF<IMessageSvc>(&svcLoc), loggedName), //use requester msg level
29 m_requesterName(requesterName) {
30 }
SmartIF< IMessageSvc >
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:80
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:81
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:79

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

Definition at line 31 of file ServiceLocatorHelper.h.

31 :
32 m_svcLoc(svcLoc),
33 m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requesterName), //use requester msg level
34 m_requesterName(requesterName) {
35 }
SmartIF< IMessageSvc >
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:80
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:81
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:79

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

Definition at line 37 of file ServiceLocatorHelper.h.

39 :
40 m_svcLoc(svcLoc), m_msgLog(log), m_requesterName(requesterName) {}
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:80
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:81
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:79

## Member Function Documentation

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

Definition at line 40 of file ServiceLocatorHelper.cpp.

42 {
43 auto theSvc = service(name, false, true);
44 if (!theSvc) return StatusCode::FAILURE;
45 StatusCode sc = theSvc->queryInterface(iid, ppSvc);
46 if (!sc.isSuccess()) {
47 *ppSvc = nullptr;
48 log() << MSG::ERROR
49 << "ServiceLocatorHelper::createService: wrong interface id "
50 << iid << " for service " << name << endmsg;
51 }
52 return sc;
53 }
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:77
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
MSG::ERROR
Definition: IMessageSvc.h:21
ServiceLocatorHelper::service
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.cpp:63
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

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

Definition at line 56 of file ServiceLocatorHelper.cpp.

59 {
60 return createService(type + "/" + name, iid, ppSvc);
61 }
ServiceLocatorHelper::createService
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.cpp:40

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

Definition at line 43 of file ServiceLocatorHelper.h.

46 {
47 return createIf ? createService(name, iid, ppSvc)
48 : locateService(name, iid, ppSvc, true);
49 }
ServiceLocatorHelper::locateService
StatusCode locateService(const std::string &name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const
Definition: ServiceLocatorHelper.cpp:23
ServiceLocatorHelper::createService
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.cpp:40

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

Definition at line 18 of file ServiceLocatorHelper.cpp.

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

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

Definition at line 23 of file ServiceLocatorHelper.cpp.

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

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

Definition at line 77 of file ServiceLocatorHelper.h.

77 { return m_msgLog; }
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:80

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

Definition at line 78 of file ServiceLocatorHelper.h.

78 { return m_requesterName; }
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:81

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

Definition at line 63 of file ServiceLocatorHelper.cpp.

63 {
64 SmartIF<IService> theSvc;
65 if (isInThread()) {
66 //first we look for a thread-specific version of the service
67 theSvc = serviceLocator()->service(name + threadName(), createIf);
68 }
69 // if not, try to find the common, single-threaded version of the service
70 if (!theSvc) theSvc = serviceLocator()->service(name, createIf);
71
72 if (theSvc) {
73 if (!quiet) {
74 if (UNLIKELY(log().level() <= MSG::VERBOSE))
75 log() << MSG::VERBOSE
76 << "ServiceLocatorHelper::service: found service " << name <<endmsg;
77 }
78 } else {
79 // if not return an error
80 if (!quiet) {
81 log() << MSG::ERROR
82 << "ServiceLocatorHelper::service: can not locate service "
83 << name;
84 if (isInThread()) log() << MSG::ERROR << " or " << name + threadName();
85 log() << MSG::ERROR << endmsg;
86 }
87 }
88 return theSvc;
89 }
ServiceLocatorHelper::serviceLocator
ISvcLocator * serviceLocator() const
Definition: ServiceLocatorHelper.h:76
SmartIF< IService >
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
ServiceLocatorHelper::threadName
std::string threadName() const
Definition: ServiceLocatorHelper.cpp:8
MSG::VERBOSE
Definition: IMessageSvc.h:17
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:77
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:78
ServiceLocatorHelper::isInThread
bool isInThread() const
Definition: ServiceLocatorHelper.cpp:18
MSG::ERROR
Definition: IMessageSvc.h:21
gaudirun.level
level
Definition: gaudirun.py:261
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
template<typename T >

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

Definition at line 68 of file ServiceLocatorHelper.h.

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

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

Definition at line 76 of file ServiceLocatorHelper.h.

76 { return &m_svcLoc; }
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:79

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

Definition at line 13 of file ServiceLocatorHelper.cpp.

13 {
14 return ( isInThread() ? name + threadName() : name );
15 }
ServiceLocatorHelper::threadName
std::string threadName() const
Definition: ServiceLocatorHelper.cpp:8
ServiceLocatorHelper::isInThread
bool isInThread() const
Definition: ServiceLocatorHelper.cpp:18

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

Definition at line 8 of file ServiceLocatorHelper.cpp.

8 {
9 return getGaudiThreadIDfromName(requesterName());
10 }
ServiceLocatorHelper::requesterName
const std::string & requesterName() const
Definition: ServiceLocatorHelper.h:78
getGaudiThreadIDfromName
GAUDI_API std::string getGaudiThreadIDfromName(const std::string &name)
helper function to extract Gaudi Thread ID from thread copy name
Definition: ThreadGaudi.cpp:26

## Member Data Documentation

MsgStream ServiceLocatorHelper::m_msgLog
| mutable private

Definition at line 80 of file ServiceLocatorHelper.h.

std::string ServiceLocatorHelper::m_requesterName
| private

Definition at line 81 of file ServiceLocatorHelper.h.

ISvcLocator& ServiceLocatorHelper::m_svcLoc
| private

Definition at line 79 of file ServiceLocatorHelper.h.

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

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