| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

Public Member Functions | Private Attributes

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

        : ToolHandleInfo(parent,createIf),
          GaudiHandle<T>( GaudiHandle<T>::getDefaultType(),
                          ToolHandleInfo::toolComponentType(parent),
                          ToolHandleInfo::toolParentName(parent) ),
          m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() )
      {}

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.

        : ToolHandleInfo(parent,createIf),
          GaudiHandle<T>( toolTypeAndName,
                          ToolHandleInfo::toolComponentType(parent),
                          ToolHandleInfo::toolParentName(parent) ),
          m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() )
      {}

## Member Function Documentation

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.

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

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.

                                                     {
        return m_pToolSvc->releaseTool( algTool );
      }

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.

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

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.

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

## 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_v22r4/GaudiKernel/GaudiKernel/ToolHandle.h

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines