| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# ServiceHandle< T > Class Template Reference

`#include <GaudiKernel/ServiceHandle.h>`

Inheritance diagram for ServiceHandle< T >:

[legend]
Collaboration diagram for ServiceHandle< T >:

[legend]
List of all members.

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

## 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
| Do the real retrieval of the Service.
## Private Member Functions
ISvcLocator * | serviceLocator () const
| Do the real release of the Service.
IMessageSvc * | messageSvc () const
## Private Attributes
ISvcLocator * | m_pSvcLocator
IMessageSvc * | m_pMessageSvc

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

    00043     : GaudiHandle<T>(serviceName, "Service", theParentName),
    00044       m_pSvcLocator(0), m_pMessageSvc(0)
    00045   {}

## Member Function Documentation

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 49 of file ServiceHandle.h.

Referenced by ToolHandle< T >::retrieve().

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

template<class T>

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

Do the real retrieval of the Service.

Implements GaudiHandle< T >.

Definition at line 61 of file ServiceHandle.h.

    00061                                            {
    00062     MsgStream log(messageSvc(), GaudiHandleBase::messageName());
    00063     ServiceLocatorHelper helper(*serviceLocator(), log, this->parentName());
    00064     return helper.getService(GaudiHandleBase::typeAndName(), true, T::interfaceID(), (void**)&service);
    00065   }

template<class T>

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

Do the real release of the Service.

Definition at line 76 of file ServiceHandle.h.

Referenced by ServiceHandle< IToolSvc >::messageSvc(), and ServiceHandle< IToolSvc >::retrieve().

    00076                                       { // not really const, because it may change m_pSvcLocator
    00077     if ( !m_pSvcLocator ) {
    00078       m_pSvcLocator = Gaudi::svcLocator();
    00079       if ( !m_pSvcLocator ) {
    00080         throw GaudiException("SvcLocator not found", "Core component not found", StatusCode::FAILURE);
    00081       }
    00082     }
    00083     return m_pSvcLocator;
    00084   }

template<class T>

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

Definition at line 86 of file ServiceHandle.h.

Referenced by ServiceHandle< IToolSvc >::retrieve().

    00086                                   { // not really const, because it may change m_pMessageSvc
    00087     if ( !m_pMessageSvc ) {
    00088       StatusCode sc = serviceLocator()->service( "MessageSvc", m_pMessageSvc, true );
    00089       if( sc.isFailure() ) {
    00090         throw GaudiException("Service [MessageSvc] not found",
    00091                              this->parentName(), sc);
    00092       }
    00093     }
    00094     return m_pMessageSvc;
    00095   }

## Member Data Documentation

template<class T>

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

Definition at line 99 of file ServiceHandle.h.

Referenced by ServiceHandle< IToolSvc >::serviceLocator().

template<class T>

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

Definition at line 100 of file ServiceHandle.h.

Referenced by ServiceHandle< IToolSvc >::messageSvc().

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

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