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 >:
Collaboration diagram for ServiceHandle< T >:

Public Member Functions

 ServiceHandle (const std::string &serviceName, const std::string &theParentName)
 Create a handle ('smart pointer') to a service. More...
 
StatusCode retrieve () const
 Retrieve the Service. More...
 
 ServiceHandle (const std::string &serviceName, const std::string &theParentName)
 Create a handle ('smart pointer') to a service. More...
 
StatusCode retrieve () const
 Retrieve the Service. More...
 
- Public Member Functions inherited from GaudiHandle< T >
 GaudiHandle (const GaudiHandle &other)
 Copy constructor needed for correct ref-counting. More...
 
GaudiHandleoperator= (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 () 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-> ()
 
T & operator* () const
 
T * operator-> () const
 
std::string getDefaultType ()
 Helper function to get default type string from the class type. More...
 
std::string getDefaultName ()
 
 GaudiHandle (const GaudiHandle &other)
 Copy constructor needed for correct ref-counting. More...
 
GaudiHandleoperator= (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 () 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-> ()
 
T & operator* () const
 
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 (const 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...
 
const std::string pythonPropertyClassName () const
 Name of the componentType with "Handle" appended. More...
 
const std::string messageName () const
 name used for printing messages More...
 
virtual const std::string pythonRepr () const
 Python representation of handle, i.e. More...
 
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 (const 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...
 
const std::string pythonPropertyClassName () const
 Name of the componentType with "Handle" appended. More...
 
const std::string messageName () const
 name used for printing messages More...
 
virtual const std::string pythonRepr () const
 Python representation of handle, i.e. More...
 
- Public Member Functions inherited from GaudiHandleInfo
virtual ~GaudiHandleInfo ()
 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 (const std::string &propName)
 set name as used in declareProperty(name,gaudiHandle). More...
 
const std::string & parentName () const
 The name of the parent. More...
 
virtual ~GaudiHandleInfo ()
 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 (const 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
 Release the Service. More...
 
StatusCode retrieve (T *&service) const
 Release the Service. More...
 
- Protected Member Functions inherited from GaudiHandle< T >
 GaudiHandle (const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
 
virtual StatusCode release (T *comp) const
 Release the component. More...
 
 GaudiHandle (const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
 
virtual StatusCode release (T *comp) const
 Release the component. More...
 
- Protected Member Functions inherited from GaudiHandleBase
 GaudiHandleBase (const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
 Create a handle ('smart pointer') to a gaudi component. More...
 
 GaudiHandleBase (const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
 Create a handle ('smart pointer') to a gaudi component. More...
 
- Protected Member Functions inherited from GaudiHandleInfo
 GaudiHandleInfo (const std::string &myComponentType, const std::string &myParentName)
 Some basic information and helper functions shared between various handles/arrays. More...
 
 GaudiHandleInfo (const std::string &myComponentType, const std::string &myParentName)
 Some basic information and helper functions shared between various handles/arrays. More...
 

Private Member Functions

SmartIF< ISvcLocator > & serviceLocator () const
 Do the real release of the Service. More...
 
SmartIF< IMessageSvc > & messageSvc () const
 
SmartIF< ISvcLocator > & serviceLocator () const
 Do the real release of the Service. More...
 
SmartIF< IMessageSvc > & messageSvc () const
 

Private Attributes

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

Definition at line 21 of file PropertyMgr.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
serviceNamename of the service
parentNamename 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.

43  : GaudiHandle<T>(serviceName, "Service", theParentName)
44  {}
Handle to be used in lieu of naked pointers to gaudis.
Definition: GaudiHandle.h:158
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
serviceNamename of the service
parentNamename 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.

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

Member Function Documentation

template<class T>
SmartIF<IMessageSvc>& ServiceHandle< T >::messageSvc ( ) const
inlineprivate

Definition at line 84 of file ServiceHandle.h.

84  { // not really const, because it may change m_pMessageSvc
85  if ( !m_pMessageSvc.isValid() ) {
86  m_pMessageSvc = serviceLocator(); // default message service
87  if( !m_pMessageSvc.isValid() ) {
88  throw GaudiException("Service [MessageSvc] not found",
90  }
91  }
92  return m_pMessageSvc;
93  }
Define general base for Gaudi exception.
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:48
SmartIF< IMessageSvc > m_pMessageSvc
Definition: ServiceHandle.h:98
SmartIF< ISvcLocator > & serviceLocator() const
Do the real release of the Service.
Definition: ServiceHandle.h:74
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
template<class T>
SmartIF<IMessageSvc>& ServiceHandle< T >::messageSvc ( ) const
inlineprivate

Definition at line 84 of file ServiceHandle.h.

84  { // not really const, because it may change m_pMessageSvc
85  if ( !m_pMessageSvc.isValid() ) {
86  m_pMessageSvc = serviceLocator(); // default message service
87  if( !m_pMessageSvc.isValid() ) {
88  throw GaudiException("Service [MessageSvc] not found",
90  }
91  }
92  return m_pMessageSvc;
93  }
Define general base for Gaudi exception.
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:48
SmartIF< IMessageSvc > m_pMessageSvc
Definition: ServiceHandle.h:98
SmartIF< ISvcLocator > & serviceLocator() const
Do the real release of the Service.
Definition: ServiceHandle.h:74
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
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 48 of file ServiceHandle.h.

48  { // not really const, because it updates m_pObject
49  return GaudiHandle<T>::retrieve();
50  }
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:188
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 48 of file ServiceHandle.h.

48  { // not really const, because it updates m_pObject
49  return GaudiHandle<T>::retrieve();
50  }
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:188
template<class T>
StatusCode ServiceHandle< T >::retrieve ( T *&  service) const
inlineprotectedvirtual

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.

60  {
62  return helper.getService(GaudiHandleBase::typeAndName(), true, T::interfaceID(), (void**)&service);
63  }
an helper to share the implementation of service() among the various kernel base classes $Id: ...
const std::string messageName() const
name used for printing messages
Definition: GaudiHandle.cpp:48
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:48
SmartIF< ISvcLocator > & serviceLocator() const
Do the real release of the Service.
Definition: ServiceHandle.h:74
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:107
template<class T>
StatusCode ServiceHandle< T >::retrieve ( T *&  service) const
inlineprotectedvirtual

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.

60  {
62  return helper.getService(GaudiHandleBase::typeAndName(), true, T::interfaceID(), (void**)&service);
63  }
an helper to share the implementation of service() among the various kernel base classes $Id: ...
const std::string messageName() const
name used for printing messages
Definition: GaudiHandle.cpp:48
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:48
SmartIF< ISvcLocator > & serviceLocator() const
Do the real release of the Service.
Definition: ServiceHandle.h:74
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:107
template<class T>
SmartIF<ISvcLocator>& ServiceHandle< T >::serviceLocator ( ) const
inlineprivate

Do the real release of the Service.

Definition at line 74 of file ServiceHandle.h.

74  { // not really const, because it may change m_pSvcLocator
75  if ( !m_pSvcLocator.isValid() ) {
77  if ( !m_pSvcLocator.isValid() ) {
78  throw GaudiException("SvcLocator not found", "Core component not found", StatusCode::FAILURE);
79  }
80  }
81  return m_pSvcLocator;
82  }
Define general base for Gaudi exception.
SmartIF< ISvcLocator > m_pSvcLocator
Definition: ServiceHandle.h:97
GAUDI_API ISvcLocator * svcLocator()
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
template<class T>
SmartIF<ISvcLocator>& ServiceHandle< T >::serviceLocator ( ) const
inlineprivate

Do the real release of the Service.

Definition at line 74 of file ServiceHandle.h.

74  { // not really const, because it may change m_pSvcLocator
75  if ( !m_pSvcLocator.isValid() ) {
77  if ( !m_pSvcLocator.isValid() ) {
78  throw GaudiException("SvcLocator not found", "Core component not found", StatusCode::FAILURE);
79  }
80  }
81  return m_pSvcLocator;
82  }
Define general base for Gaudi exception.
SmartIF< ISvcLocator > m_pSvcLocator
Definition: ServiceHandle.h:97
GAUDI_API ISvcLocator * svcLocator()
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51

Member Data Documentation

template<class T>
SmartIF< IMessageSvc > ServiceHandle< T >::m_pMessageSvc
mutableprivate

Definition at line 98 of file ServiceHandle.h.

template<class T>
SmartIF< ISvcLocator > ServiceHandle< T >::m_pSvcLocator
mutableprivate

Definition at line 97 of file ServiceHandle.h.


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