| # Gaudi Framework, version v23r0 |

Home |  | Generated: Mon Jan 30 2012

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

# ServiceHandle< T > Class Template Reference

Handle to be used in lieu of naked pointers to services. More...

`#include <GaudiKernel/ServiceHandle.h>`

Inheritance diagram for ServiceHandle< T >:
[legend]
Collaboration diagram for ServiceHandle< T >:
[legend]

List of all members.

## Public Member Functions
| ServiceHandle (const std::string &serviceName, const std::string &theParentName)
| Create a handle ('smart pointer') to a service.
StatusCode | retrieve () const
| Retrieve the Service.
## Protected Member Functions
StatusCode | retrieve (T *&service) const
| Release the Service.
## Private Member Functions
SmartIF< ISvcLocator > & | serviceLocator () const
| Do the real release of the Service.
SmartIF< IMessageSvc > & | messageSvc () const
## Private Attributes
SmartIF< ISvcLocator > | m_pSvcLocator
SmartIF< IMessageSvc > | m_pMessageSvc

## Detailed Description

### template<class T>
class ServiceHandle< T >

Handle to be used in lieu of naked pointers to services.

This allows better control through the framework of service loading and usage.

Author:
  Martin.Woudstra@cern.ch

Definition at line 30 of file ServiceHandle.h.

## Constructor & Destructor Documentation

template<class T>

ServiceHandle< T >::ServiceHandle | ( | const std::string & | serviceName,
|  | const std::string & | theParentName
| ) |  | `[inline]`

Create a handle ('smart pointer') to a service.

The arguments are passed on to ServiceSvc, and have the same meaning:

Parameters:

  serviceName | name of the service
  parentName | name of the parent Algorithm, AlgTool or Service. It is used for log printout at retrieve(), and for retrieving a thread-dependent service (if applicable)

Definition at line 42 of file ServiceHandle.h.

        : GaudiHandle<T>(serviceName, "Service", theParentName)
      {}

## Member Function Documentation

template<class T>

SmartIF<IMessageSvc>& ServiceHandle< T >::messageSvc | ( | ) | const`[inline, private]`

Definition at line 84 of file ServiceHandle.h.

                                               { // not really const, because it may change m_pMessageSvc
        if ( !m_pMessageSvc.isValid() ) {
          m_pMessageSvc = serviceLocator(); // default message service
          if( !m_pMessageSvc.isValid() ) {
            throw GaudiException("Service [MessageSvc] not found",
                                 this->parentName(), StatusCode::FAILURE);
          }
        }
        return m_pMessageSvc;
      }

template<class T>

StatusCode ServiceHandle< T >::retrieve | ( | T *& | service ) | const`[inline, protected, virtual]`

Release the Service.

Function must be repeated here to avoid hiding the function release( T*& ) Do the real retrieval of the Service.

Implements GaudiHandle< T >.

Definition at line 60 of file ServiceHandle.h.

                                               {
        const ServiceLocatorHelper helper(*serviceLocator(), GaudiHandleBase::messageName(), this->parentName());
        return helper.getService(GaudiHandleBase::typeAndName(), true, T::interfaceID(), (void**)&service);
      }

template<class T>

StatusCode ServiceHandle< T >::retrieve | ( | ) | const`[inline]`

Retrieve the Service.

Release existing Service if needed. Function must be repeated here to avoid hiding the function retrieve( T*& )

Reimplemented from GaudiHandle< T >.

Definition at line 48 of file ServiceHandle.h.

                                  { // not really const, because it updates m_pObject
        return GaudiHandle<T>::retrieve();
      }

template<class T>

SmartIF<ISvcLocator>& ServiceHandle< T >::serviceLocator | ( | ) | const`[inline, private]`

Do the real release of the Service.

Definition at line 74 of file ServiceHandle.h.

                                                   { // not really const, because it may change m_pSvcLocator
        if ( !m_pSvcLocator.isValid() ) {
          m_pSvcLocator = Gaudi::svcLocator();
          if ( !m_pSvcLocator.isValid() ) {
            throw GaudiException("SvcLocator not found", "Core component not found", StatusCode::FAILURE);
          }
        }
        return m_pSvcLocator;
      }

## Member Data Documentation

template<class T>

SmartIF<IMessageSvc> ServiceHandle< T >::m_pMessageSvc`[mutable, private]`

Definition at line 98 of file ServiceHandle.h.

template<class T>

SmartIF<ISvcLocator> ServiceHandle< T >::m_pSvcLocator`[mutable, private]`

Definition at line 97 of file ServiceHandle.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v23r0/GaudiKernel/GaudiKernel/ServiceHandle.h

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