| The Gaudi Framework v32r1 (f65d50dc)

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
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() [1/4]

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

Definition at line 19 of file ServiceLocatorHelper.h.

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

## ◆ ServiceLocatorHelper() [2/4]

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

Definition at line 24 of file ServiceLocatorHelper.h.

25 : m_svcLoc( svcLoc )
26 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), loggedName )
27 , // use requester msg level
28 m_requesterName( requesterName ) {}
SmartIF< IMessageSvc >
ServiceLocatorHelper::requesterName
const std::string & requesterName() const
Definition: ServiceLocatorHelper.h:62
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:64
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:65
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:63

## ◆ ServiceLocatorHelper() [3/4]

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

Definition at line 29 of file ServiceLocatorHelper.h.

30 : m_svcLoc( svcLoc )
31 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
32 , // use requester msg level
33 m_requesterName( requesterName ) {}
SmartIF< IMessageSvc >
ServiceLocatorHelper::requesterName
const std::string & requesterName() const
Definition: ServiceLocatorHelper.h:62
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:64
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:65
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:63

## ◆ ServiceLocatorHelper() [4/4]

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

Definition at line 35 of file ServiceLocatorHelper.h.

38 : m_svcLoc( svcLoc ), m_msgLog( log ), m_requesterName( requesterName ) {}
ServiceLocatorHelper::requesterName
const std::string & requesterName() const
Definition: ServiceLocatorHelper.h:62
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:64
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:65
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:61
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:63

## Member Function Documentation

## ◆ createService() [1/2]

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

Definition at line 21 of file ServiceLocatorHelper.cpp.

21 {
22 auto theSvc = service( name, false, true );
23 if ( !theSvc ) return StatusCode::FAILURE;
24 StatusCode sc = theSvc->queryInterface( iid, ppSvc );
25 if ( !sc.isSuccess() ) {
26 *ppSvc = nullptr;
27 log() << MSG::ERROR << "ServiceLocatorHelper::createService: wrong interface id " << iid << " for service " << name
28 << endmsg;
29 }
30 return sc;
31 }
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:61
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
ServiceLocatorHelper::service
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.cpp:38
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
MSG::ERROR
Definition: IMessageSvc.h:15
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ createService() [2/2]

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

Definition at line 33 of file ServiceLocatorHelper.cpp.

34 {
35 return createService( type + "/" + name, iid, ppSvc );
36 }
ServiceLocatorHelper::createService
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.cpp:21
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
gaudirun.type
type
Definition: gaudirun.py:142

## ◆ getService()

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

Definition at line 41 of file ServiceLocatorHelper.h.

41 {
42 return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
43 }
ServiceLocatorHelper::createService
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.cpp:21
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
ServiceLocatorHelper::locateService
StatusCode locateService(const std::string &name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const
Definition: ServiceLocatorHelper.cpp:7

## ◆ locateService()

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

Definition at line 7 of file ServiceLocatorHelper.cpp.

8 {
9 auto theSvc = service( name, quiet, false );
10 if ( !theSvc ) return StatusCode::FAILURE;
11 StatusCode sc = theSvc->queryInterface( iid, ppSvc );
12 if ( !sc.isSuccess() ) {
13 *ppSvc = nullptr;
14 if ( !quiet )
15 log() << MSG::ERROR << "ServiceLocatorHelper::locateService: wrong interface id " << iid << " for service "
16 << name << endmsg;
17 }
18 return sc;
19 }
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:61
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
ServiceLocatorHelper::service
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.cpp:38
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
MSG::ERROR
Definition: IMessageSvc.h:15
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ log()

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

Definition at line 61 of file ServiceLocatorHelper.h.

61 { return m_msgLog; }
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:64

## ◆ requesterName()

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

Definition at line 62 of file ServiceLocatorHelper.h.

62 { return m_requesterName; }
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:65

## ◆ service() [1/2]

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

Definition at line 38 of file ServiceLocatorHelper.cpp.

39 {
40 SmartIF<IService> theSvc = serviceLocator()->service( name, createIf );
41
42 if ( theSvc ) {
43 if ( !quiet ) {
44 if ( UNLIKELY( log().level() <= MSG::VERBOSE ) )
45 log() << MSG::VERBOSE << "ServiceLocatorHelper::service: found service " << name << endmsg;
46 }
47 } else {
48 // if not return an error
49 if ( !quiet ) { log() << MSG::ERROR << "ServiceLocatorHelper::service: can not locate service " << name << endmsg; }
50 }
51 return theSvc;
52 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:96
SmartIF< IService >
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
MSG::VERBOSE
Definition: IMessageSvc.h:15
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:76
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:61
ServiceLocatorHelper::serviceLocator
ISvcLocator * serviceLocator() const
Definition: ServiceLocatorHelper.h:60
MSG::ERROR
Definition: IMessageSvc.h:15
gaudirun.level
level
Definition: gaudirun.py:334
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

## ◆ service() [2/2]

template<typename T >

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

Definition at line 55 of file ServiceLocatorHelper.h.

55 {
56 return service( name, quiet, createIf ).as<T>();
57 }
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:107
ServiceLocatorHelper::service
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.cpp:38

## ◆ serviceLocator()

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

Definition at line 60 of file ServiceLocatorHelper.h.

60 { return &m_svcLoc; }
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:63

## Member Data Documentation

## ◆ m_msgLog

MsgStream ServiceLocatorHelper::m_msgLog
| mutable private

Definition at line 64 of file ServiceLocatorHelper.h.

## ◆ m_requesterName

std::string ServiceLocatorHelper::m_requesterName
| private

Definition at line 65 of file ServiceLocatorHelper.h.

## ◆ m_svcLoc

ISvcLocator& ServiceLocatorHelper::m_svcLoc
| private

Definition at line 63 of file ServiceLocatorHelper.h.

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

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