| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

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

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# ToolHandle< T > Class Template Reference

`#include <GaudiKernel/ToolHandle.h>`

Inheritance diagram for ToolHandle< T >:

[legend]
Collaboration diagram for ToolHandle< T >:

[legend]
List of all members.

## 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 77 of file ToolHandle.h.

## 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

## 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 85 of file ToolHandle.h.

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

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 110 of file ToolHandle.h.

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

## 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 120 of file ToolHandle.h.

References GaudiHandle< T >::retrieve().

    00120                               { // not really const, because it updates m_pObject
    00121     return GaudiHandle<T>::retrieve();
    00122   }

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 126 of file ToolHandle.h.

References GaudiHandle< T >::release().

    00126                              { // not really const, because it updates m_pObject
    00127     return GaudiHandle<T>::release();
    00128   }

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 131 of file ToolHandle.h.

References ToolHandleInfo::createIf(), ToolHandle< T >::m_pToolSvc, ToolHandleInfo::parent(), ServiceHandle< T >::retrieve(), and GaudiHandleBase::typeAndName().

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

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 138 of file ToolHandle.h.

References ToolHandle< T >::m_pToolSvc.

    00138                                                  {
    00139     return m_pToolSvc->releaseTool( algTool );
    00140   }

## Member Data Documentation

template<class T>

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

Definition at line 146 of file ToolHandle.h.

Referenced by ToolHandle< T >::release(), and ToolHandle< T >::retrieve().

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

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