The Gaudi Framework  master (37c0b60a)
ServiceLocatorHelper Class Reference

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

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/ServiceLocatorHelper.h>

Collaboration diagram for ServiceLocatorHelper:

Public Member Functions

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

Private Member Functions

ISvcLocatorserviceLocator () const
 
MsgStreamlog () const
 
const std::stringrequesterName () const
 

Private Attributes

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

Constructor & Destructor Documentation

◆ ServiceLocatorHelper() [1/4]

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

Definition at line 29 of file ServiceLocatorHelper.h.

30  : m_svcLoc( svcLoc )
31  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
32  , // use requester msg level
33  m_requesterName( requester.name() ) {}

◆ ServiceLocatorHelper() [2/4]

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

Definition at line 34 of file ServiceLocatorHelper.h.

35  : m_svcLoc( svcLoc )
36  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), std::move( loggedName ) )
37  , // use requester msg level

◆ ServiceLocatorHelper() [3/4]

ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
std::string  requesterName 
)
inline

Definition at line 39 of file ServiceLocatorHelper.h.

40  : m_svcLoc( svcLoc )
42  , // use requester msg level

◆ ServiceLocatorHelper() [4/4]

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

Definition at line 45 of file ServiceLocatorHelper.h.

Member Function Documentation

◆ createService() [1/2]

StatusCode ServiceLocatorHelper::createService ( std::string_view  name,
const InterfaceID iid,
void **  ppSvc 
) const

Definition at line 33 of file ServiceLocatorHelper.cpp.

33  {
34  auto theSvc = service( name, false, true );
35  if ( !theSvc ) return StatusCode::FAILURE;
36  StatusCode sc = theSvc->queryInterface( iid, ppSvc );
37  if ( !sc.isSuccess() ) {
38  *ppSvc = nullptr;
39  log() << MSG::ERROR << "ServiceLocatorHelper::createService: wrong interface id " << iid << " for service " << name
40  << endmsg;
41  }
42  return sc;
43 }

◆ createService() [2/2]

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

Definition at line 45 of file ServiceLocatorHelper.cpp.

46  {
47  return createService( fmt::format( "{}/{}", type, name ), iid, ppSvc );
48 }

◆ getService()

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

Definition at line 52 of file ServiceLocatorHelper.h.

52  {
53  return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
54  }

◆ locateService()

StatusCode ServiceLocatorHelper::locateService ( std::string_view  name,
const InterfaceID iid,
void **  ppSvc,
bool  quiet = false 
) const

Definition at line 19 of file ServiceLocatorHelper.cpp.

20  {
21  auto theSvc = service( name, quiet, false );
22  if ( !theSvc ) return StatusCode::FAILURE;
23  StatusCode sc = theSvc->queryInterface( iid, ppSvc );
24  if ( !sc.isSuccess() ) {
25  *ppSvc = nullptr;
26  if ( !quiet )
27  log() << MSG::ERROR << "ServiceLocatorHelper::locateService: wrong interface id " << iid << " for service "
28  << name << endmsg;
29  }
30  return sc;
31 }

◆ log()

MsgStream& ServiceLocatorHelper::log ( ) const
inlineprivate

Definition at line 71 of file ServiceLocatorHelper.h.

71 { return m_msgLog; }

◆ requesterName()

const std::string& ServiceLocatorHelper::requesterName ( ) const
inlineprivate

Definition at line 72 of file ServiceLocatorHelper.h.

72 { return m_requesterName; }

◆ service() [1/2]

SmartIF< IService > ServiceLocatorHelper::service ( std::string_view  name,
const bool  quiet = false,
const bool  createIf = true 
) const

Definition at line 50 of file ServiceLocatorHelper.cpp.

50  {
51  SmartIF<IService> theSvc = serviceLocator()->service( name, createIf );
52 
53  if ( theSvc ) {
54  if ( !quiet ) {
55  if ( log().level() <= MSG::VERBOSE )
56  log() << MSG::VERBOSE << "ServiceLocatorHelper::service: found service " << name << endmsg;
57  }
58  } else {
59  // if not return an error
60  if ( !quiet ) { log() << MSG::ERROR << "ServiceLocatorHelper::service: can not locate service " << name << endmsg; }
61  }
62  return theSvc;
63 }

◆ service() [2/2]

template<typename T >
SmartIF<T> ServiceLocatorHelper::service ( std::string_view  name,
const bool  quiet = false,
const bool  createIf = true 
) const
inline

Definition at line 65 of file ServiceLocatorHelper.h.

65  {
66  return service( name, quiet, createIf ).as<T>();
67  }

◆ serviceLocator()

ISvcLocator* ServiceLocatorHelper::serviceLocator ( ) const
inlineprivate

Definition at line 70 of file ServiceLocatorHelper.h.

70 { return &m_svcLoc; }

Member Data Documentation

◆ m_msgLog

MsgStream ServiceLocatorHelper::m_msgLog
mutableprivate

Definition at line 74 of file ServiceLocatorHelper.h.

◆ m_requesterName

std::string ServiceLocatorHelper::m_requesterName
private

Definition at line 75 of file ServiceLocatorHelper.h.

◆ m_svcLoc

ISvcLocator& ServiceLocatorHelper::m_svcLoc
private

Definition at line 73 of file ServiceLocatorHelper.h.


The documentation for this class was generated from the following files:
ServiceLocatorHelper::service
SmartIF< IService > service(std::string_view name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.cpp:50
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:73
std::move
T move(T... args)
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
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:75
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:74
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:71
ServiceLocatorHelper::requesterName
const std::string & requesterName() const
Definition: ServiceLocatorHelper.h:72
ServiceLocatorHelper::locateService
StatusCode locateService(std::string_view name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const
Definition: ServiceLocatorHelper.cpp:19
StatusCode
Definition: StatusCode.h:65
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:98
SmartIF< IMessageSvc >
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
gaudirun.level
level
Definition: gaudirun.py:364
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:117
gaudirun.type
type
Definition: gaudirun.py:160
MSG::VERBOSE
@ VERBOSE
Definition: IMessageSvc.h:25
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
ServiceLocatorHelper::serviceLocator
ISvcLocator * serviceLocator() const
Definition: ServiceLocatorHelper.h:70
ServiceLocatorHelper::createService
StatusCode createService(std::string_view name, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.cpp:33