| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
GaudiHandle< T > Class Template Referenceabstract

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

`#include <GaudiKernel/GaudiHandle.h>`

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

## Public Member Functions
| GaudiHandle (const GaudiHandle &other)
| Copy constructor needed for correct ref-counting.
GaudiHandle & | operator= (const GaudiHandle &other)
| Assignment operator for correct ref-counting.
StatusCode | retrieve () const
| Retrieve the component.
StatusCode | release () const
| Release the component.
| operator bool () const
| For testing if handle has component.
T & | operator* ()
T * | operator-> ()
T & | operator* () const
T * | operator-> () const
std::string | getDefaultType ()
| Helper function to get default type string from the class type.
std::string | getDefaultName ()
Public Member Functions inherited from GaudiHandleBase
std::string | typeAndName () const
| The full type and name: "type/name".
std::string | type () const
| The concrete component class name: the part before the '/'.
std::string | name () const
| The instance name: the part after the '/'.
bool | empty () const
| Check if the handle has been set to empty string (i.e.
void | setTypeAndName (const std::string &myTypeAndName)
| The component "type/name" string.
void | setName (const std::string &myName)
| Set the instance name (part after the '/') without changing the class type.
const std::string | pythonPropertyClassName () const
| Name of the componentType with "Handle" appended.
const std::string | messageName () const
| name used for printing messages
virtual const std::string | pythonRepr () const
| Python representation of handle, i.e.
Public Member Functions inherited from GaudiHandleInfo
virtual | ~GaudiHandleInfo ()
| virtual destructor so that derived class destructor is called.
const std::string & | componentType () const
const std::string & | propertyName () const
| name as used in declareProperty(name,gaudiHandle)
void | setPropertyName (const std::string &propName)
| set name as used in declareProperty(name,gaudiHandle).
const std::string & | parentName () const
| The name of the parent.

## Protected Member Functions
| GaudiHandle (const std::string &myTypeAndName, const std::string &myComponentType, const std::string &myParentName)
virtual StatusCode | retrieve (T *&) const =0
| Retrieve the component.
virtual StatusCode | release (T *comp) const
| Release the component.
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.
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.

## Private Member Functions
void | setDefaultTypeAndName ()
| Helper function to set default name and type.
void | setDefaultType ()
| Helper function to set default type from the class type T.
bool | getObject () const
| Load the pointer to the component.
void | assertObject () const
| Load the pointer to the component.

## Private Attributes
T * | m_pObject

## Detailed Description

### template<class T>
class GaudiHandle< T >

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

This allows better control through the framework of gaudi loading and usage. T is the type of the component interface (or concrete class).

Author
  Marti.nosp@m.n.Wo.nosp@m.udstr.nosp@m.a@ce.nosp@m.rn.ch

Definition at line 158 of file GaudiHandle.h.

## Constructor & Destructor Documentation

template<class T>

GaudiHandle< T >::GaudiHandle | ( | const std::string & | myTypeAndName,
|  | const std::string & | myComponentType,
|  | const std::string & | myParentName
| ) |  |
| inline protected

Definition at line 163 of file GaudiHandle.h.

: GaudiHandleBase(myTypeAndName, myComponentType, myParentName), m_pObject(0)
{}
template<class T>

GaudiHandle< T >::GaudiHandle | ( | const GaudiHandle< T > & | other | ) |
| inline

Copy constructor needed for correct ref-counting.

Definition at line 170 of file GaudiHandle.h.

: GaudiHandleBase( other ) {
m_pObject = other.m_pObject;
if ( m_pObject ) m_pObject->addRef();
}

## Member Function Documentation

template<class T>

void GaudiHandle< T >::assertObject | ( |  | ) | const
| inline private

Load the pointer to the component.

Do a retrieve if needed. Throw an exception if retrieval fails.

Definition at line 274 of file GaudiHandle.h.

{ // not really const, because it may update m_pObject
if ( !getObject() ) {
throw GaudiException("Failed to retrieve " + componentType() + ": " + typeAndName(),
componentType() + " retrieve", StatusCode::FAILURE);
}
}
template<class T>

std::string GaudiHandle< T >::getDefaultName | ( |  | ) |
| inline

Definition at line 238 of file GaudiHandle.h.

{
std::string defName = GaudiHandleBase::type();
if ( defName.empty() ) defName = getDefaultType();
return defName;
}
template<class T>

std::string GaudiHandle< T >::getDefaultType | ( |  | ) |
| inline

Helper function to get default type string from the class type.

Definition at line 234 of file GaudiHandle.h.

{
return System::typeinfoName( typeid(T) );
}
template<class T>

bool GaudiHandle< T >::getObject | ( |  | ) | const
| inline private

Load the pointer to the component.

Do a retrieve if needed

Definition at line 268 of file GaudiHandle.h.

{ // not really const, because it may update m_pObject
return m_pObject || retrieve().isSuccess();
}
template<class T>

GaudiHandle< T >::operator bool | ( |  | ) | const
| inline

For testing if handle has component.

Does retrieve() if needed. If this returns false, the component could not be retrieved.

Definition at line 209 of file GaudiHandle.h.

{ // not really const, because it may update m_pObject
return getObject();
}
template<class T>

T& GaudiHandle< T >::operator* | ( |  | ) |
| inline

Definition at line 213 of file GaudiHandle.h.

{
assertObject();
return *m_pObject;
}
template<class T>

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

Definition at line 223 of file GaudiHandle.h.

{ // not really const, because it may update m_pObject
assertObject();
return *m_pObject;
}
template<class T>

T* GaudiHandle< T >::operator-> | ( |  | ) |
| inline

Definition at line 218 of file GaudiHandle.h.

{
assertObject();
return m_pObject;
}
template<class T>

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

Definition at line 228 of file GaudiHandle.h.

{ // not really const, because it may update m_pObject
assertObject();
return m_pObject;
}
template<class T>

GaudiHandle& GaudiHandle< T >::operator= | ( | const GaudiHandle< T > & | other | ) |
| inline

Assignment operator for correct ref-counting.

Definition at line 177 of file GaudiHandle.h.

{
GaudiHandleBase::operator=( other );
// release any current tool
release().ignore();
m_pObject = other.m_pObject;
// update ref-counting
if ( m_pObject ) m_pObject->addRef();
return *this;
}
template<class T>

StatusCode GaudiHandle< T >::release | ( |  | ) | const
| inline

Release the component.

Definition at line 198 of file GaudiHandle.h.

{ // not really const, because it updates m_pObject
if ( m_pObject ) {
StatusCode sc = release( m_pObject );
m_pObject = 0;
return sc;
}
return StatusCode::SUCCESS;
}
template<class T>

virtual StatusCode GaudiHandle< T >::release | ( | T * | comp | ) | const
| inline protected virtual

Release the component.

Default implementation calls release() on the component. Can be overridden by the derived class if something else if needed.

Reimplemented in ToolHandle< T >.

Definition at line 250 of file GaudiHandle.h.

{ // not really const, because it updates m_pObject
comp->release();
return StatusCode::SUCCESS;
}
template<class T>

StatusCode GaudiHandle< T >::retrieve | ( |  | ) | const
| inline

Retrieve the component.

Release existing component if needed.

Definition at line 188 of file GaudiHandle.h.

{ // not really const, because it updates m_pObject
if ( m_pObject && release().isFailure() ) return StatusCode::FAILURE;
if ( retrieve( m_pObject ).isFailure() ) {
m_pObject = 0;
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
template<class T>

virtual StatusCode GaudiHandle< T >::retrieve | ( | T *& |  | ) | const
| protected pure virtual

Retrieve the component.

To be implemented by the derived class. It will pass the pointer

Implemented in ToolHandle< T >, ServiceHandle< T >, and ServiceHandle< IToolSvc >.

template<class T>

void GaudiHandle< T >::setDefaultType | ( |  | ) |
| inline private

Helper function to set default type from the class type T.

Definition at line 263 of file GaudiHandle.h.

{
GaudiHandleBase::setTypeAndName( getDefaultType() );
}
template<class T>

void GaudiHandle< T >::setDefaultTypeAndName | ( |  | ) |
| inline private

Helper function to set default name and type.

Definition at line 257 of file GaudiHandle.h.

{
const std::string& myType = getDefaultType();
GaudiHandleBase::setTypeAndName(myType+'/'+myType);
}

## Member Data Documentation

template<class T>

T* GaudiHandle< T >::m_pObject
| mutable private

Definition at line 283 of file GaudiHandle.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiKernel/GaudiKernel/GaudiHandle.h