| # Gaudi Framework, version v23r1 |

Home |  | Generated: Wed Feb 29 2012

Public Member Functions | Private Member Functions | Private Attributes

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

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

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

Definition at line 25 of file ServiceLocatorHelper.h.

                                         :
        m_svcLoc(svcLoc),
        m_msgLog(SmartIF<IMessageSvc>(&svcLoc), loggedName), //use requester msg level
        m_requesterName(requesterName) {
      }

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

Definition at line 32 of file ServiceLocatorHelper.h.

                                                                               :
        m_svcLoc(svcLoc),
        m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requesterName), //use requester msg level
        m_requesterName(requesterName) {
      }

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

Definition at line 38 of file ServiceLocatorHelper.h.

                                                    :
        m_svcLoc(svcLoc), m_msgLog(log), m_requesterName(requesterName) {}

## Member Function Documentation

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

Definition at line 40 of file ServiceLocatorHelper.cpp.

                                                            {
      SmartIF<IService> theSvc = service(name, false, true);
      if (!theSvc.isValid()) return StatusCode::FAILURE;
      StatusCode sc = theSvc->queryInterface(iid, ppSvc);
      if (!sc.isSuccess()) {
        *ppSvc = 0;
        log() << MSG::ERROR
          << "ServiceLocatorHelper::createService: wrong interface id "
          << iid << " for service " << name << endmsg;
      }
      return sc;
    }

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.

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

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

Definition at line 44 of file ServiceLocatorHelper.h.

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

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

Definition at line 18 of file ServiceLocatorHelper.cpp.

                                           {
      return isGaudiThreaded(requesterName());
    }

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

Definition at line 23 of file ServiceLocatorHelper.cpp.

                                                          {
      SmartIF<IService> theSvc = service(name, quiet, false);
      if (!theSvc.isValid()) return StatusCode::FAILURE;
      StatusCode sc = theSvc->queryInterface(iid, ppSvc);
      if (!sc.isSuccess()) {
        *ppSvc = 0;
        if (!quiet) log() << MSG::ERROR
          << "ServiceLocatorHelper::locateService: wrong interface id "
          << iid << " for service " << name << endmsg;
      }
      return sc;
    }

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

Definition at line 74 of file ServiceLocatorHelper.h.

    { return m_msgLog; }

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

Definition at line 75 of file ServiceLocatorHelper.h.

    { 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.

                                                                                                                      {
      SmartIF<IService> theSvc;
      if (isInThread()) {
        //first we look for  a thread-specific version of the service
        theSvc = serviceLocator()->service(name + threadName(), createIf);
      }
      // if not, try to find the common, single-threaded version of the service
      if (!theSvc.isValid()){
        theSvc = serviceLocator()->service(name, createIf);
      }

      if (theSvc.isValid()) {
        if (!quiet) {
          if (UNLIKELY(log().level() <= MSG::VERBOSE))
            log() << MSG::VERBOSE
                  << "ServiceLocatorHelper::service: found service " << name <<endmsg;
        }
      } else {
        // if not return an error
        if (!quiet) {
          log() << MSG::ERROR
                << "ServiceLocatorHelper::service: can not locate service "
                << name;
          if (isInThread()) log() << MSG::ERROR << " or " << name + threadName();
          log() << MSG::ERROR << endmsg;
        }
      }
      return theSvc;
    }

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

Definition at line 73 of file ServiceLocatorHelper.h.

    { return &m_svcLoc; }

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

Definition at line 13 of file ServiceLocatorHelper.cpp.

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

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

Definition at line 8 of file ServiceLocatorHelper.cpp.

                                           {
      return getGaudiThreadIDfromName(requesterName());
    }

## Member Data Documentation

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.

ISvcLocator& ServiceLocatorHelper::m_svcLoc`[private]`

Definition at line 76 of file ServiceLocatorHelper.h.

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines