| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

GaudiHandle< T > Class Template Reference

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]
List of all members.

Public Member Functions

 GaudiHandle (const GaudiHandle &other)
 Copy constructor needed for correct ref-counting.
GaudiHandleoperator= (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 ()
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.
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.

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:
Martin.Woudstra@cern.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.

00165     : GaudiHandleBase(myTypeAndName, myComponentType, myParentName), m_pObject(0) 
00166   {}

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.

00171     : GaudiHandleBase( other ) {
00172     m_pObject = other.m_pObject;
00173     if ( m_pObject ) m_pObject->addRef();
00174   }


Member Function Documentation

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.

00177                                                      {
00178     GaudiHandleBase::operator=( other );
00179     // release any current tool
00180     release().ignore();
00181     m_pObject = other.m_pObject;
00182     // update ref-counting
00183     if ( m_pObject ) m_pObject->addRef();
00184     return *this;
00185   }

template<class T>
StatusCode GaudiHandle< T >::retrieve (  )  const [inline]

Retrieve the component.

Release existing component if needed.

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

Definition at line 188 of file GaudiHandle.h.

00188                               { // not really const, because it updates m_pObject
00189     if ( m_pObject && release().isFailure() ) return StatusCode::FAILURE;
00190     if ( retrieve( m_pObject ).isFailure() ) {
00191       m_pObject = 0;
00192       return StatusCode::FAILURE;
00193     }
00194     return StatusCode::SUCCESS;
00195   }

template<class T>
StatusCode GaudiHandle< T >::release (  )  const [inline]

Release the component.

Reimplemented in ToolHandle< T >.

Definition at line 198 of file GaudiHandle.h.

00198                              { // not really const, because it updates m_pObject
00199     if ( m_pObject ) {
00200       StatusCode sc = release( m_pObject );
00201       m_pObject = 0;
00202       return sc;
00203     }
00204     return StatusCode::SUCCESS;
00205   }

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.

00209                         { // not really const, because it may update m_pObject 
00210     return getObject();
00211   }

template<class T>
T& GaudiHandle< T >::operator * (  )  [inline]

Definition at line 213 of file GaudiHandle.h.

00213                  { 
00214     assertObject();
00215     return *m_pObject;
00216   }

template<class T>
T* GaudiHandle< T >::operator-> (  )  [inline]

Definition at line 218 of file GaudiHandle.h.

00218                   { 
00219     assertObject();
00220     return m_pObject; 
00221   }

template<class T>
T& GaudiHandle< T >::operator * (  )  const [inline]

Definition at line 223 of file GaudiHandle.h.

00223                        { // not really const, because it may update m_pObject 
00224     assertObject();
00225     return *m_pObject; 
00226   }

template<class T>
T* GaudiHandle< T >::operator-> (  )  const [inline]

Definition at line 228 of file GaudiHandle.h.

00228                         { // not really const, because it may update m_pObject 
00229     assertObject();
00230     return m_pObject;
00231   }

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.

00234                              {  
00235     return System::typeinfoName( typeid(T) );
00236   }

template<class T>
std::string GaudiHandle< T >::getDefaultName (  )  [inline]

Definition at line 238 of file GaudiHandle.h.

00238                              {
00239     std::string defName = GaudiHandleBase::type();
00240     if ( defName.empty() ) defName = getDefaultType();
00241     return defName;
00242   }

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 ServiceHandle< T >, ToolHandle< T >, and ServiceHandle< IToolSvc >.

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.

00250                                               { // not really const, because it updates m_pObject
00251     comp->release();
00252     return StatusCode::SUCCESS;
00253   }

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.

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

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.

00263                         {  
00264     GaudiHandleBase::setTypeAndName( getDefaultType() ); 
00265   }

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.

00268                          { // not really const, because it may update m_pObject 
00269     return m_pObject || retrieve().isSuccess();
00270   }

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.

00274                             { // not really const, because it may update m_pObject 
00275     if ( !getObject() ) {
00276       throw GaudiException("Failed to retrieve " + componentType() + ": " + typeAndName(),
00277                            componentType() + " retrieve", StatusCode::FAILURE);
00278     }
00279   }

std::string GaudiHandleBase::typeAndName (  )  const [inline, inherited]

The full type and name: "type/name".

Definition at line 107 of file GaudiHandle.h.

00107                                 { 
00108      return m_typeAndName;
00109   }

std::string GaudiHandleBase::type (  )  const [inherited]

The concrete component class name: the part before the '/'.

std::string GaudiHandleBase::name (  )  const [inherited]

The instance name: the part after the '/'.

bool GaudiHandleBase::empty (  )  const [inline, inherited]

Check if the handle has been set to empty string (i.e.

typeAndName string is empty).

Definition at line 118 of file GaudiHandle.h.

00118                      {
00119     return m_typeAndName.empty();
00120   }

void GaudiHandleBase::setTypeAndName ( const std::string &  myTypeAndName  )  [inherited]

The component "type/name" string.

void GaudiHandleBase::setName ( const std::string &  myName  )  [inherited]

Set the instance name (part after the '/') without changing the class type.

const std::string GaudiHandleBase::pythonPropertyClassName (  )  const [virtual, inherited]

Name of the componentType with "Handle" appended.

Used as the python class name for the property in the genconf-generated configurables. The python class is defined in GaudiPython/python/GaudiHandles.py.

Implements GaudiHandleInfo.

const std::string GaudiHandleBase::messageName (  )  const [inherited]

name used for printing messages

virtual const std::string GaudiHandleBase::pythonRepr (  )  const [virtual, inherited]

Python representation of handle, i.e.

python class name and argument. Can be used in the genconf-generated configurables. The corresponding python classes are defined in GaudiPython/GaudiHandles.py

Implements GaudiHandleInfo.

const std::string& GaudiHandleInfo::componentType (  )  const [inline, inherited]

Definition at line 33 of file GaudiHandle.h.

00033                                          {
00034      return m_componentType;
00035   }

const std::string& GaudiHandleInfo::propertyName (  )  const [inline, inherited]

name as used in declareProperty(name,gaudiHandle)

Definition at line 38 of file GaudiHandle.h.

00038                                         {
00039      return m_propertyName;
00040   }

void GaudiHandleInfo::setPropertyName ( const std::string &  propName  )  [inline, inherited]

set name as used in declareProperty(name,gaudiHandle).

Used in printout.

Definition at line 43 of file GaudiHandle.h.

00043                                                     {
00044     m_propertyName = propName;
00045   }

const std::string& GaudiHandleInfo::parentName (  )  const [inline, inherited]

The name of the parent.

Definition at line 48 of file GaudiHandle.h.

00048                                       {
00049     return m_parentName;
00050   }


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:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:57:07 2011 for GaudiKernel by doxygen 1.4.7