All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ServiceLocatorHelper Class Reference

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

#include <GaudiKernel/ServiceLocatorHelper.h>

Collaboration diagram for ServiceLocatorHelper:

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< IServiceservice (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
 
ISvcLocatorserviceLocator () const
 
MsgStreamlog () const
 
const std::string & requesterName () 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 $Id:

Definition at line 18 of file ServiceLocatorHelper.h.

Constructor & Destructor Documentation

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

Definition at line 20 of file ServiceLocatorHelper.h.

20  :
21  m_svcLoc(svcLoc),
22  m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requester.name()), //use requester msg level
23  m_requesterName(requester.name()) {
24  }
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 25 of file ServiceLocatorHelper.h.

27  :
28  m_svcLoc(svcLoc),
29  m_msgLog(SmartIF<IMessageSvc>(&svcLoc), loggedName), //use requester msg level
31  }
const std::string & requesterName() const
ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const std::string &  requesterName 
)
inline

Definition at line 32 of file ServiceLocatorHelper.h.

32  :
33  m_svcLoc(svcLoc),
34  m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requesterName), //use requester msg level
36  }
const std::string & requesterName() const
ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const MsgStream log,
const std::string &  requesterName 
)
inline

Definition at line 38 of file ServiceLocatorHelper.h.

40  :
const std::string & requesterName() const

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  SmartIF<IService> theSvc = service(name, false, true);
44  if (!theSvc.isValid()) return StatusCode::FAILURE;
45  StatusCode sc = theSvc->queryInterface(iid, ppSvc);
46  if (!sc.isSuccess()) {
47  *ppSvc = 0;
48  log() << MSG::ERROR
49  << "ServiceLocatorHelper::createService: wrong interface id "
50  << iid << " for service " << name << endmsg;
51  }
52  return sc;
53 }
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
MsgStream & log() const
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
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 }
string type
Definition: gaudirun.py:126
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const
StatusCode ServiceLocatorHelper::getService ( const std::string &  name,
bool  createIf,
const InterfaceID iid,
void **  ppSvc 
) const
inline

Definition at line 44 of file ServiceLocatorHelper.h.

47  {
48  return (createIf ?
49  createService(name, iid, ppSvc) :
50  locateService(name, iid, ppSvc, true));
51  }
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
bool ServiceLocatorHelper::isInThread ( ) const
private

Definition at line 18 of file ServiceLocatorHelper.cpp.

18  {
20 }
GAUDI_API bool isGaudiThreaded(const std::string &name)
test if current Gaudi object is running /will run in a thread
Definition: ThreadGaudi.cpp:75
const std::string & requesterName() const
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  SmartIF<IService> theSvc = service(name, quiet, false);
28  if (!theSvc.isValid()) return StatusCode::FAILURE;
29  StatusCode sc = theSvc->queryInterface(iid, ppSvc);
30  if (!sc.isSuccess()) {
31  *ppSvc = 0;
32  if (!quiet) log() << MSG::ERROR
33  << "ServiceLocatorHelper::locateService: wrong interface id "
34  << iid << " for service " << name << endmsg;
35  }
36  return sc;
37 }
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
MsgStream & log() const
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream& ServiceLocatorHelper::log ( ) const
inlineprivate

Definition at line 74 of file ServiceLocatorHelper.h.

74 { return m_msgLog; }
const std::string& ServiceLocatorHelper::requesterName ( ) const
inlineprivate

Definition at line 75 of file ServiceLocatorHelper.h.

75 { return m_requesterName; }
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.isValid()){
71  theSvc = serviceLocator()->service(name, createIf);
72  }
73 
74  if (theSvc.isValid()) {
75  if (!quiet) {
76  if (UNLIKELY(log().level() <= MSG::VERBOSE))
77  log() << MSG::VERBOSE
78  << "ServiceLocatorHelper::service: found service " << name <<endmsg;
79  }
80  } else {
81  // if not return an error
82  if (!quiet) {
83  log() << MSG::ERROR
84  << "ServiceLocatorHelper::service: can not locate service "
85  << name;
86  if (isInThread()) log() << MSG::ERROR << " or " << name + threadName();
87  log() << MSG::ERROR << endmsg;
88  }
89  }
90  return theSvc;
91 }
ISvcLocator * serviceLocator() const
#define UNLIKELY(x)
Definition: Kernel.h:127
std::string threadName() const
MsgStream & log() const
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:82
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
ISvcLocator* ServiceLocatorHelper::serviceLocator ( ) const
inlineprivate

Definition at line 73 of file ServiceLocatorHelper.h.

73 { return &m_svcLoc; }
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 }
std::string threadName() const
std::string ServiceLocatorHelper::threadName ( ) const
private

Definition at line 8 of file ServiceLocatorHelper.cpp.

8  {
10 }
const std::string & requesterName() const
GAUDI_API std::string getGaudiThreadIDfromName(const std::string &name)
helper function to extract Gaudi Thread ID from thread copy name
Definition: ThreadGaudi.cpp:28

Member Data Documentation

MsgStream ServiceLocatorHelper::m_msgLog
mutableprivate

Definition at line 77 of file ServiceLocatorHelper.h.

std::string ServiceLocatorHelper::m_requesterName
private

Definition at line 78 of file ServiceLocatorHelper.h.

ISvcLocator& ServiceLocatorHelper::m_svcLoc
private

Definition at line 76 of file ServiceLocatorHelper.h.


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