| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# ToolHandle< T > Class Template Reference

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

`#include <GaudiKernel/ToolHandle.h>`

Inheritance diagram for ToolHandle< T >:

[legend]
Collaboration diagram for ToolHandle< T >:

[legend]

List of all members.

## Public Member Functions
| ToolHandle (const IInterface *parent=0, bool createIf=true)
| Constructor for a tool with default tool type and name.
| ToolHandle (const std::string &toolTypeAndName, const IInterface *parent=0, bool createIf=true)
| Create a handle ('smart pointer') to a tool.
StatusCode | retrieve () const
| Retrieve the AlgTool.
StatusCode | release () const
| Release the AlgTool.
virtual StatusCode | retrieve (T *&algTool) const
| Do the real retrieval of the AlgTool.
virtual StatusCode | release (T *algTool) const
| Do the real release of the AlgTool.
## Private Attributes
ServiceHandle< IToolSvc > | m_pToolSvc

## Detailed Description

### template<class T>
class ToolHandle< T >

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

This allows better control through the framework of tool loading and usage. T is the AlgTool interface class (or concrete class) of the tool to use, and must derive from IAlgTool.

Author:
  Wim Lavrijsen <WLavrijsen@lbl.gov>

  Martin.Woudstra@cern.ch

Definition at line 80 of file ToolHandle.h.

## Constructor & Destructor Documentation

template<class T>

ToolHandle< T >::ToolHandle | ( | const IInterface * | parent = `0`,
|  | bool | createIf = `true` |
| ) |  |  | `[inline]`

Constructor for a tool with default tool type and name.

Can be called only if the type T is a concrete tool type (not an interface), and you want to use the default name.

Definition at line 88 of file ToolHandle.h.

    00089     : ToolHandleInfo(parent,createIf),
    00090       GaudiHandle<T>( GaudiHandle<T>::getDefaultType(),
    00091                       ToolHandleInfo::toolComponentType(parent),
    00092                       ToolHandleInfo::toolParentName(parent) ),
    00093       m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() )
    00094   {}

template<class T>

ToolHandle< T >::ToolHandle | ( | const std::string & | toolTypeAndName,
|  | const IInterface * | parent = `0`,
|  | bool | createIf = `true` |
| ) |  |  | `[inline]`

Create a handle ('smart pointer') to a tool.

The arguments are passed on to ToolSvc, and have the same meaning:

          StatusCode ToolSvc::retrieveTool ( const std::string& type            ,
                                             T*&                tool            ,
                                             const IInterface*  parent   = 0    ,
                                             bool               createIf = true )

Parameters:

  | toolType,: | "MyToolType/MyToolName" "MyToolType" is short for "MyToolType/MyToolType" 'MyToolType' is the name of the class of the concrete tool 'MyToolName' is to distinguish several tool instances of the same class
  | parent,: | the parent Algorithm,Tool or Service of which this tool is a member. If non-zero, the the tool is a private tool of the parent, otherwise it is a public (shared) tool.
  | createIf,: | if true, create tool if not yet existing.

Definition at line 113 of file ToolHandle.h.

    00114     : ToolHandleInfo(parent,createIf),
    00115       GaudiHandle<T>( toolTypeAndName,
    00116                       ToolHandleInfo::toolComponentType(parent),
    00117                       ToolHandleInfo::toolParentName(parent) ),
    00118       m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() )
    00119   {}

## Member Function Documentation

template<class T>

StatusCode ToolHandle< T >::retrieve | ( |  | ) | const`[inline]`

Retrieve the AlgTool.

Release existing tool if needed. Function must be repeated here to avoid hiding the function retrieve( T*& )

Reimplemented from GaudiHandle< T >.

Definition at line 123 of file ToolHandle.h.

    00123                               { // not really const, because it updates m_pObject
    00124     return GaudiHandle<T>::retrieve();
    00125   }

template<class T>

StatusCode ToolHandle< T >::release | ( |  | ) | const`[inline]`

Release the AlgTool.

Function must be repeated here to avoid hiding the function release( T*& )

Reimplemented from GaudiHandle< T >.

Definition at line 129 of file ToolHandle.h.

    00129                              { // not really const, because it updates m_pObject
    00130     return GaudiHandle<T>::release();
    00131   }

template<class T>

virtual StatusCode ToolHandle< T >::retrieve | ( | T *& | algTool | ) | const`[inline, virtual]`

Do the real retrieval of the AlgTool.

Implements GaudiHandle< T >.

Definition at line 134 of file ToolHandle.h.

    00134                                                    {
    00135     return m_pToolSvc->retrieve( GaudiHandleBase::typeAndName(), T::interfaceID(),
    00136                                  (IAlgTool*&)(algTool),
    00137                                  ToolHandleInfo::parent(), ToolHandleInfo::createIf() );
    00138   }

template<class T>

virtual StatusCode ToolHandle< T >::release | ( | T * | algTool | ) | const`[inline, virtual]`

Do the real release of the AlgTool.

Reimplemented from GaudiHandle< T >.

Definition at line 141 of file ToolHandle.h.

    00141                                                  {
    00142     return m_pToolSvc->releaseTool( algTool );
    00143   }

## Member Data Documentation

template<class T>

ServiceHandle<IToolSvc> ToolHandle< T >::m_pToolSvc`[mutable, private]`

Definition at line 149 of file ToolHandle.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r7/GaudiKernel/GaudiKernel/ToolHandle.h