| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
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]

## Public Member Functions
| ServiceHandle (const std::string &serviceName, const std::string &theParentName)
| Create a handle ('smart pointer') to a service. More...
template<typename CT = T, typename NCT = std::remove_const_t<T>, typename = std::enable_if_t<std::is_const_v<CT> && !std::is_same_v<CT, NCT>>>
| ServiceHandle (const ServiceHandle< NCT > &other)
| Copy constructor from a non const T to const T service handle. More...
template<class OWNER , typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
| ServiceHandle (OWNER *owner, std::string PropName, std::string svcName, std::string doc="")
| Autodeclaring constructor with property name, service type/name and documentation. More...
StatusCode | initialize (const std::string &serviceName, const std::string &theParentName)
StatusCode | retrieve () const
| Retrieve the Service. More...
T * | get () const
| Release the Service. More...
T * | operator-> () const
| Allow non const access to the service, even from a const handle... More...
T & | operator * () const
Public Member Functions inherited from GaudiHandle< T >
template<typename CT = T, typename NCT = std::remove_const_t<T>>
| GaudiHandle (const GaudiHandle< NCT > &other, std::enable_if_t< std::is_const_v< CT > &&!std::is_same_v< CT, NCT >> *=nullptr)
| Copy constructor needed for correct ref-counting. More...
| GaudiHandle (const GaudiHandle &other)
| Copy constructor needed for correct ref-counting. More...
template<typename CT = T, typename NCT = std::remove_const_t<T>>
std::enable_if_t< std::is_const_v< CT > &&!std::is_same_v< CT, NCT >, GaudiHandle & > | operator= (const GaudiHandle< NCT > &other)
| Assignment operator for correct ref-counting. More...
GaudiHandle & | operator= (const GaudiHandle &other)
| Assignment operator for correct ref-counting. More...
StatusCode | retrieve () const
| Retrieve the component. More...
StatusCode | release () const
| Release the component. More...
bool | isValid () const
| Check if the handle is valid (try to retrive the object is not done yet). More...
| operator bool () const
| For testing if handle has component. More...
T * | get ()
| Return the wrapped pointer, not calling retrieve() if null. More...
std::add_const_t< T > * | get () const
| Return the wrapped pointer, not calling retrieve() if null. More...
bool | isSet () const
| True if the wrapped pointer is not null. More...
T & | operator * ()
T * | operator-> ()
std::add_const_t< T > & | operator * () const
std::add_const_t< T > * | operator-> () const
std::string | getDefaultType ()
| Helper function to get default type string from the class type. More...
std::string | getDefaultName ()
Public Member Functions inherited from GaudiHandleBase
std::string | typeAndName () const
| The full type and name: "type/name". More...
std::string | type () const
| The concrete component class name: the part before the '/'. More...
std::string | name () const
| The instance name: the part after the '/'. More...
bool | empty () const
| Check if the handle has been set to empty string (i.e. More...
void | setTypeAndName (std::string myTypeAndName)
| The component "type/name" string. More...
void | setName (const std::string &myName)
| Set the instance name (part after the '/') without changing the class type. More...
std::string | pythonPropertyClassName () const override
| Name of the componentType with "Handle" appended. More...
std::string | messageName () const
| name used for printing messages More...
std::string | pythonRepr () const override
| Python representation of handle, i.e. More...
Public Member Functions inherited from GaudiHandleInfo
virtual | ~GaudiHandleInfo ()=default
| virtual destructor so that derived class destructor is called. More...
const std::string & | componentType () const
const std::string & | propertyName () const
| name as used in declareProperty(name,gaudiHandle) More...
void | setPropertyName (std::string propName)
| set name as used in declareProperty(name,gaudiHandle). More...
const std::string & | parentName () const
| The name of the parent. More...

## Protected Member Functions
StatusCode | retrieve (T *&service) const override
| Do the real retrieval of the Service. More...
Protected Member Functions inherited from GaudiHandle< T >
| GaudiHandle (std::string myTypeAndName, std::string myComponentType, std::string myParentName)
virtual StatusCode | release (T *comp) const
| Release the component. More...
Protected Member Functions inherited from GaudiHandleBase
| GaudiHandleBase (std::string myTypeAndName, std::string myComponentType, std::string myParentName)
| Create a handle ('smart pointer') to a gaudi component. More...
Protected Member Functions inherited from GaudiHandleInfo
| GaudiHandleInfo (std::string myComponentType, std::string myParentName)
| Some basic information and helper functions shared between various handles/arrays. More...
void | setComponentType (const std::string &componentType)
| The component type. More...
void | setParentName (const std::string &parent)
| The name of the parent. More...

## Private Member Functions
SmartIF< ISvcLocator > & | serviceLocator () const
| Do the real release of the Service. More...
SmartIF< IMessageSvc > & | messageSvc () const

## Private Attributes
SmartIF< ISvcLocator > | m_pSvcLocator
SmartIF< IMessageSvc > | m_pMessageSvc

## Additional Inherited Members
Public Types inherited from GaudiHandleBase
using | PropertyType = GaudiHandleProperty

## 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
  Marti.nosp@m.n.Wo.nosp@m.udstr.nosp@m.a@ce.nosp@m.rn.ch

Definition at line 31 of file ServiceHandle.h.

## Constructor & Destructor Documentation

## ◆ ServiceHandle() [1/3]

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

44 : GaudiHandle<T>( serviceName, "Service", theParentName ) {}
GaudiHandle
Handle to be used in lieu of naked pointers to gaudis.
Definition: GaudiHandle.h:163

## ◆ ServiceHandle() [2/3]

template<class T>
template<typename CT = T, typename NCT = std::remove_const_t<T>, typename = std::enable_if_t<std::is_const_v<CT> && !std::is_same_v<CT, NCT>>>

ServiceHandle< T >::ServiceHandle | ( | const ServiceHandle< NCT > & | other | ) |
| inline

Copy constructor from a non const T to const T service handle.

Definition at line 49 of file ServiceHandle.h.

49 : GaudiHandle<CT>( other ) {}
GaudiHandle
Handle to be used in lieu of naked pointers to gaudis.
Definition: GaudiHandle.h:163

## ◆ ServiceHandle() [3/3]

template<class T>
template<class OWNER , typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>

ServiceHandle< T >::ServiceHandle | ( | OWNER * | owner,
|  | std::string | PropName,
|  | std::string | svcName,
|  | std::string | doc = `""`
| ) |  |
| inline

Autodeclaring constructor with property name, service type/name and documentation.

Note
  the use std::enable_if is required to avoid ambiguities

Definition at line 54 of file ServiceHandle.h.

55 : ServiceHandle( svcName, owner->name() ) {
56 auto p = owner->OWNER::PropertyHolderImpl::declareProperty( std::move( PropName ), *this, std::move( doc ) );
57 p->template setOwnerType<OWNER>();
58 }
std::move
T move(T... args)
ServiceHandle::ServiceHandle
ServiceHandle(const std::string &serviceName, const std::string &theParentName)
Create a handle ('smart pointer') to a service.
Definition: ServiceHandle.h:43

## Member Function Documentation

## ◆ get()

template<class T>

T* ServiceHandle< T >::get | ( |  | ) | const
| inline

Release the Service.

Function must be repeated here to avoid hiding the function release( T*& ) Allow non const access to the service, even from a const handle...

Definition at line 81 of file ServiceHandle.h.

81 { return ::details::nonConst( GaudiHandle<T>::get() ); }
GaudiHandle
Handle to be used in lieu of naked pointers to gaudis.
Definition: GaudiHandle.h:163
details::nonConst
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
Definition: GaudiHandle.h:20

## ◆ initialize()

template<class T>

StatusCode ServiceHandle< T >::initialize | ( | const std::string & | serviceName,
|  | const std::string & | theParentName
| ) |  |
| inline

Definition at line 60 of file ServiceHandle.h.

60 {
61
62 GaudiHandleBase::setTypeAndName( serviceName );
63 GaudiHandleBase::setParentName( theParentName );
64
65 return StatusCode::SUCCESS;
66 }
GaudiHandleBase::setTypeAndName
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
GaudiHandleInfo::setParentName
void setParentName(const std::string &parent)
The name of the parent.
Definition: GaudiHandle.h:71

## ◆ messageSvc()

template<class T>

SmartIF<IMessageSvc>& ServiceHandle< T >::messageSvc | ( |  | ) | const
| inline private

Definition at line 113 of file ServiceHandle.h.

113 { // not really const, because it may change m_pMessageSvc
114 if ( !m_pMessageSvc ) {
115 m_pMessageSvc = serviceLocator(); // default message service
116 if ( !m_pMessageSvc ) {
117 throw GaudiException( "Service [MessageSvc] not found", this->parentName(), StatusCode::FAILURE );
118 }
119 }
120 return m_pMessageSvc;
121 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
ServiceHandle::m_pMessageSvc
SmartIF< IMessageSvc > m_pMessageSvc
Definition: ServiceHandle.h:126
GaudiHandleInfo::parentName
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:53
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
ServiceHandle::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const
Do the real release of the Service.
Definition: ServiceHandle.h:103

## ◆ operator *()

template<class T>

T& ServiceHandle< T >::operator * | ( |  | ) | const
| inline

Definition at line 85 of file ServiceHandle.h.

85 { return *::details::nonConst( GaudiHandle<T>::operator->() ); }
GaudiHandle
Handle to be used in lieu of naked pointers to gaudis.
Definition: GaudiHandle.h:163
details::nonConst
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
Definition: GaudiHandle.h:20

## ◆ operator->()

template<class T>

T* ServiceHandle< T >::operator-> | ( |  | ) | const
| inline

Allow non const access to the service, even from a const handle...

Definition at line 84 of file ServiceHandle.h.

84 { return ::details::nonConst( GaudiHandle<T>::operator->() ); }
GaudiHandle
Handle to be used in lieu of naked pointers to gaudis.
Definition: GaudiHandle.h:163
details::nonConst
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
Definition: GaudiHandle.h:20

## ◆ retrieve() [1/2]

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*& )

Definition at line 70 of file ServiceHandle.h.

70 { // not really const, because it updates m_pObject
71 return GaudiHandle<T>::retrieve();
72 }
GaudiHandle::retrieve
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:212

## ◆ retrieve() [2/2]

template<class T>

StatusCode ServiceHandle< T >::retrieve | ( | T *& | service | ) | const
| inline override protected virtual

Do the real retrieval of the Service.

Implements GaudiHandle< T >.

Definition at line 89 of file ServiceHandle.h.

89 {
90 const ServiceLocatorHelper helper( *serviceLocator(), GaudiHandleBase::messageName(), this->parentName() );
91 return helper.getService( GaudiHandleBase::typeAndName(), true, T::interfaceID(), (void**)&service );
92 }
ServiceLocatorHelper
an helper to share the implementation of service() among the various kernel base classes
Definition: ServiceLocatorHelper.h:17
GaudiHandleBase::typeAndName
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:115
GaudiHandleInfo::parentName
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:53
GaudiHandleBase::messageName
std::string messageName() const
name used for printing messages
Definition: GaudiHandle.cpp:42
ServiceHandle::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const
Do the real release of the Service.
Definition: ServiceHandle.h:103

## ◆ serviceLocator()

template<class T>

SmartIF<ISvcLocator>& ServiceHandle< T >::serviceLocator | ( |  | ) | const
| inline private

Do the real release of the Service.

Definition at line 103 of file ServiceHandle.h.

103 { // not really const, because it may change m_pSvcLocator
104 if ( !m_pSvcLocator ) {
105 m_pSvcLocator = Gaudi::svcLocator();
106 if ( !m_pSvcLocator ) {
107 throw GaudiException( "SvcLocator not found", "Core component not found", StatusCode::FAILURE );
108 }
109 }
110 return m_pSvcLocator;
111 }
ServiceHandle::m_pSvcLocator
SmartIF< ISvcLocator > m_pSvcLocator
Definition: ServiceHandle.h:125
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86

## Member Data Documentation

## ◆ m_pMessageSvc

template<class T>

SmartIF<IMessageSvc> ServiceHandle< T >::m_pMessageSvc
| mutable private

Definition at line 126 of file ServiceHandle.h.

## ◆ m_pSvcLocator

template<class T>

SmartIF<ISvcLocator> ServiceHandle< T >::m_pSvcLocator
| mutable private

Definition at line 125 of file ServiceHandle.h.

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

- GaudiKernel/GaudiKernel/ServiceHandle.h