| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# ServiceLocatorHelper Class Reference

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

`#include <ServiceLocatorHelper.h>`

Collaboration diagram for ServiceLocatorHelper:

[legend]

List of all members.

## 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
## 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 $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.

    00020                                                                              :
    00021     m_svcLoc(svcLoc),
    00022     m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requester.name()), //use requester msg level
    00023     m_requesterName(requester.name()) {
    00024   }
      ServiceLocatorHelper(ISvcLocator& svcLoc,

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

Definition at line 25 of file ServiceLocatorHelper.h.

    00027                                      :
    00028     m_svcLoc(svcLoc),
    00029     m_msgLog(SmartIF<IMessageSvc>(&svcLoc), loggedName), //use requester msg level
    00030     m_requesterName(requesterName) {
    00031   }
      ServiceLocatorHelper(ISvcLocator& svcLoc, const std::string& requesterName):

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

Definition at line 32 of file ServiceLocatorHelper.h.

    00032                                                                            :
    00033     m_svcLoc(svcLoc),
    00034     m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requesterName), //use requester msg level
    00035     m_requesterName(requesterName) {
    00036   }
    #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)

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

Definition at line 38 of file ServiceLocatorHelper.h.

    00040                                                 :
    00041     m_svcLoc(svcLoc), m_msgLog(log), m_requesterName(requesterName) {}
    #endif

## Member Function Documentation

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

Definition at line 44 of file ServiceLocatorHelper.h.

    00047                                             {
    00048     return (createIf ?
    00049             createService(name, iid, ppSvc) :
    00050             locateService(name, iid, ppSvc, true));
    00051   }

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

Definition at line 23 of file ServiceLocatorHelper.cpp.

    00026                                                       {
    00027   SmartIF<IService> theSvc = service(name, quiet, false);
    00028   if (!theSvc.isValid()) return StatusCode::FAILURE;
    00029   StatusCode sc = theSvc->queryInterface(iid, ppSvc);
    00030   if (!sc.isSuccess()) {
    00031     *ppSvc = 0;
    00032     if (!quiet) log() << MSG::ERROR
    00033       << "ServiceLocatorHelper::locateService: wrong interface id "
    00034       << iid << " for service " << name << endmsg;
    00035   }
    00036   return sc;
    00037 }

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

Definition at line 40 of file ServiceLocatorHelper.cpp.

    00042                                                         {
    00043   SmartIF<IService> theSvc = service(name, false, true);
    00044   if (!theSvc.isValid()) return StatusCode::FAILURE;
    00045   StatusCode sc = theSvc->queryInterface(iid, ppSvc);
    00046   if (!sc.isSuccess()) {
    00047     *ppSvc = 0;
    00048     log() << MSG::ERROR
    00049       << "ServiceLocatorHelper::createService: wrong interface id "
    00050       << iid << " for service " << name << endmsg;
    00051   }
    00052   return sc;
    00053 }

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.

    00059                                                         {
    00060   return createService(type + "/" + name, iid, ppSvc);
    00061 }

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.

    00063                                                                                                                   {
    00064   SmartIF<IService> theSvc;
    00065   if (isInThread()) {
    00066     //first we look for  a thread-specific version of the service
    00067     theSvc = serviceLocator()->service(name + threadName(), createIf);
    00068   }
    00069   // if not, try to find the common, single-threaded version of the service
    00070   if (!theSvc.isValid()){
    00071     theSvc = serviceLocator()->service(name, createIf);
    00072   }
    00073
    00074   if (theSvc.isValid()) {
    00075     if (!quiet) {
    00076       log() << MSG::VERBOSE
    00077             << "ServiceLocatorHelper::service: found service " << name <<endmsg;
    00078     }
    00079   } else {
    00080     // if not return an error
    00081     if (!quiet) {
    00082       log() << MSG::ERROR
    00083             << "ServiceLocatorHelper::service: can not locate service "
    00084             << name;
    00085       if (isInThread()) log() << MSG::ERROR << " or " << name + threadName();
    00086       log() << MSG::ERROR << endmsg;
    00087     }
    00088   }
    00089   return theSvc;
    00090 }

std::string ServiceLocatorHelper::threadName | ( |  | ) | const`[private]`

Definition at line 8 of file ServiceLocatorHelper.cpp.

    00008                                        {
    00009   return getGaudiThreadIDfromName(requesterName());
    00010 }

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

Definition at line 13 of file ServiceLocatorHelper.cpp.

    00013                                                               {
    00014   return ( isInThread() ? name + threadName() : name );
    00015 }

bool ServiceLocatorHelper::isInThread | ( |  | ) | const`[private]`

Definition at line 18 of file ServiceLocatorHelper.cpp.

    00018                                        {
    00019   return isGaudiThreaded(requesterName());
    00020 }

ISvcLocator* ServiceLocatorHelper::serviceLocator | ( |  | ) | const`[inline, private]`

Definition at line 73 of file ServiceLocatorHelper.h.

    00073 { return &m_svcLoc; }

MsgStream& ServiceLocatorHelper::log | ( |  | ) | const`[inline, private]`

Definition at line 74 of file ServiceLocatorHelper.h.

    00074 { return m_msgLog; }

const std::string& ServiceLocatorHelper::requesterName | ( |  | ) | const`[inline, private]`

Definition at line 75 of file ServiceLocatorHelper.h.

    00075 { return m_requesterName; }

## Member Data Documentation

ISvcLocator& ServiceLocatorHelper::m_svcLoc`[private]`

Definition at line 76 of file ServiceLocatorHelper.h.

MsgStream ServiceLocatorHelper::m_msgLog`[mutable, private]`

Definition at line 77 of file ServiceLocatorHelper.h.

std::string ServiceLocatorHelper::m_requesterName`[private]`

Definition at line 78 of file ServiceLocatorHelper.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r7/GaudiKernel/GaudiKernel/ServiceLocatorHelper.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r7/GaudiKernel/src/Lib/ServiceLocatorHelper.cpp