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 >:
Collaboration diagram for ToolHandle< T >:

Public Member Functions

 ToolHandle (const IInterface *parent=nullptr, bool createIf=true)
 Constructor for a tool with default tool type and name. More...
 
 ToolHandle (const std::string &toolTypeAndName, const IInterface *parent=nullptr, bool createIf=true)
 Create a handle ('smart pointer') to a tool. More...
 
StatusCode initialize (const std::string &toolTypeAndName, const IInterface *parent=nullptr, bool createIf=true)
 
StatusCode retrieve () const
 Retrieve the AlgTool. More...
 
StatusCode release () const
 Release the AlgTool. More...
 
StatusCode retrieve (T *&algTool) const override
 Do the real retrieval of the AlgTool. More...
 
StatusCode release (T *algTool) const override
 Do the real release of the AlgTool. More...
 
 ToolHandle (const IInterface *parent=nullptr, bool createIf=true)
 Constructor for a tool with default tool type and name. More...
 
 ToolHandle (const std::string &toolTypeAndName, const IInterface *parent=nullptr, bool createIf=true)
 Create a handle ('smart pointer') to a tool. More...
 
StatusCode initialize (const std::string &toolTypeAndName, const IInterface *parent=nullptr, bool createIf=true)
 
StatusCode retrieve () const
 Retrieve the AlgTool. More...
 
StatusCode release () const
 Release the AlgTool. More...
 
StatusCode retrieve (T *&algTool) const override
 Do the real retrieval of the AlgTool. More...
 
StatusCode release (T *algTool) const override
 Do the real release of the AlgTool. More...
 
- Public Member Functions inherited from BaseToolHandle
virtual ~BaseToolHandle ()
 
StatusCode retrieve (IAlgTool *&tool) const
 
virtual ~BaseToolHandle ()
 
StatusCode retrieve (IAlgTool *&tool) const
 
- Public Member Functions inherited from ToolHandleInfo
virtual ~ToolHandleInfo ()=default
 
bool isPublic () const
 
bool createIf () const
 
const IInterfaceparent () const
 
virtual ~ToolHandleInfo ()=default
 
bool isPublic () const
 
bool createIf () const
 
const IInterfaceparent () const
 
- Public Member Functions inherited from GaudiHandle< T >
 GaudiHandle (const GaudiHandle &other)
 Copy constructor needed for correct ref-counting. More...
 
GaudiHandleoperator= (const GaudiHandle &other)
 Assignment operator for correct ref-counting. More...
 
 ~GaudiHandle ()
 
StatusCode retrieve () const
 Retrieve the component. More...
 
StatusCode release () const
 Release the component. More...
 
bool isValid () const
 Check if the handle is valid (try to retrive the object is not done yet). More...
 
 operator bool () const
 For testing if handle has component. More...
 
T * get () const
 Return the wrapped pointer, not calling retrieve() if null. More...
 
bool isSet () const
 True if the wrapped pointer is not null. More...
 
T & operator* ()
 
T * operator-> ()
 
T & operator* () const
 
T * operator-> () const
 
std::string getDefaultType ()
 Helper function to get default type string from the class type. More...
 
std::string getDefaultName ()
 
 GaudiHandle (const GaudiHandle &other)
 Copy constructor needed for correct ref-counting. More...
 
GaudiHandleoperator= (const GaudiHandle &other)
 Assignment operator for correct ref-counting. More...
 
 ~GaudiHandle ()
 
StatusCode retrieve () const
 Retrieve the component. More...
 
StatusCode release () const
 Release the component. More...
 
bool isValid () const
 Check if the handle is valid (try to retrive the object is not done yet). More...
 
 operator bool () const
 For testing if handle has component. More...
 
T * get () const
 Return the wrapped pointer, not calling retrieve() if null. More...
 
bool isSet () const
 True if the wrapped pointer is not null. More...
 
T & operator* ()
 
T * operator-> ()
 
T & operator* () const
 
T * operator-> () const
 
std::string getDefaultType ()
 Helper function to get default type string from the class type. More...
 
std::string getDefaultName ()
 
- Public Member Functions inherited from GaudiHandleBase
std::string typeAndName () const
 The full type and name: "type/name". More...
 
std::string type () const
 The concrete component class name: the part before the '/'. More...
 
std::string name () const
 The instance name: the part after the '/'. More...
 
bool empty () const
 Check if the handle has been set to empty string (i.e. More...
 
void setTypeAndName (std::string myTypeAndName)
 The component "type/name" string. More...
 
void setName (const std::string &myName)
 Set the instance name (part after the '/') without changing the class type. More...
 
std::string pythonPropertyClassName () const
 Name of the componentType with "Handle" appended. More...
 
std::string messageName () const
 name used for printing messages More...
 
virtual std::string pythonRepr () const
 Python representation of handle, i.e. More...
 
std::string typeAndName () const
 The full type and name: "type/name". More...
 
std::string type () const
 The concrete component class name: the part before the '/'. More...
 
std::string name () const
 The instance name: the part after the '/'. More...
 
bool empty () const
 Check if the handle has been set to empty string (i.e. More...
 
void setTypeAndName (std::string myTypeAndName)
 The component "type/name" string. More...
 
void setName (const std::string &myName)
 Set the instance name (part after the '/') without changing the class type. More...
 
std::string pythonPropertyClassName () const
 Name of the componentType with "Handle" appended. More...
 
std::string messageName () const
 name used for printing messages More...
 
virtual std::string pythonRepr () const
 Python representation of handle, i.e. More...
 
- Public Member Functions inherited from GaudiHandleInfo
virtual ~GaudiHandleInfo ()=default
 virtual destructor so that derived class destructor is called. More...
 
const std::string & componentType () const
 
const std::string & propertyName () const
 name as used in declareProperty(name,gaudiHandle) More...
 
void setPropertyName (std::string propName)
 set name as used in declareProperty(name,gaudiHandle). More...
 
const std::string & parentName () const
 The name of the parent. More...
 
virtual ~GaudiHandleInfo ()=default
 virtual destructor so that derived class destructor is called. More...
 
const std::string & componentType () const
 
const std::string & propertyName () const
 name as used in declareProperty(name,gaudiHandle) More...
 
void setPropertyName (std::string propName)
 set name as used in declareProperty(name,gaudiHandle). More...
 
const std::string & parentName () const
 The name of the parent. More...
 

Protected Member Functions

StatusCode i_retrieve (IAlgTool *&algTool) const override
 
StatusCode i_retrieve (IAlgTool *&algTool) const override
 
- Protected Member Functions inherited from BaseToolHandle
 BaseToolHandle (const IInterface *parent=nullptr, bool createIf=true)
 
 BaseToolHandle (const IInterface *parent=nullptr, bool createIf=true)
 
- Protected Member Functions inherited from ToolHandleInfo
 ToolHandleInfo (const IInterface *parent=nullptr, bool createIf=true)
 
 ToolHandleInfo (const IInterface *parent=nullptr, bool createIf=true)
 
- Protected Member Functions inherited from GaudiHandle< T >
 GaudiHandle (std::string myTypeAndName, std::string myComponentType, std::string myParentName)
 
 GaudiHandle (std::string myTypeAndName, std::string myComponentType, std::string myParentName)
 
- Protected Member Functions inherited from GaudiHandleBase
 GaudiHandleBase (std::string myTypeAndName, std::string myComponentType, std::string myParentName)
 Create a handle ('smart pointer') to a gaudi component. More...
 
 GaudiHandleBase (std::string myTypeAndName, std::string myComponentType, std::string myParentName)
 Create a handle ('smart pointer') to a gaudi component. More...
 
- Protected Member Functions inherited from GaudiHandleInfo
 GaudiHandleInfo (std::string myComponentType, std::string myParentName)
 Some basic information and helper functions shared between various handles/arrays. More...
 
void setComponentType (const std::string &componentType)
 The component type. More...
 
void setParentName (const std::string &parent)
 The name of the parent. More...
 
 GaudiHandleInfo (std::string myComponentType, std::string myParentName)
 Some basic information and helper functions shared between various handles/arrays. More...
 
void setComponentType (const std::string &componentType)
 The component type. More...
 
void setParentName (const std::string &parent)
 The name of the parent. More...
 

Private Attributes

ServiceHandle< IToolSvcm_pToolSvc
 

Friends

class Algorithm
 
class AlgTool
 
class Service
 

Additional Inherited Members

- Static Public Member Functions inherited from ToolHandleInfo
static std::string toolComponentType (const IInterface *parent)
 
static std::string toolParentName (const IInterface *parent)
 
static std::string toolComponentType (const IInterface *parent)
 
static std::string toolParentName (const IInterface *parent)
 
- Protected Attributes inherited from ToolHandleInfo
const IInterfacem_parent
 
bool m_createIf
 

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 WLavr.nosp@m.ijse.nosp@m.n@lbl.nosp@m..gov
Marti.nosp@m.n.Wo.nosp@m.udstr.nosp@m.a@ce.nosp@m.rn.ch

Definition at line 21 of file PropertyMgr.h.

Constructor & Destructor Documentation

template<class T>
ToolHandle< T >::ToolHandle ( const IInterface parent = nullptr,
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 106 of file ToolHandle.h.

107  : BaseToolHandle(parent,createIf),
109  toolComponentType(parent),
110  toolParentName(parent) ),
112  { }
Handle to be used in lieu of naked pointers to gaudis.
Definition: GaudiHandle.h:171
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:266
static std::string toolParentName(const IInterface *parent)
Definition: ToolHandle.h:47
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:49
BaseToolHandle(const IInterface *parent=nullptr, bool createIf=true)
Definition: ToolHandle.h:69
static std::string toolComponentType(const IInterface *parent)
Definition: ToolHandle.h:43
ServiceHandle< IToolSvc > m_pToolSvc
Definition: ToolHandle.h:206
bool createIf() const
Definition: ToolHandle.h:36
template<class T>
ToolHandle< T >::ToolHandle ( const std::string &  toolTypeAndName,
const IInterface parent = nullptr,
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
ownerclass owning the ToolHandle
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
parentthe 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.
createIfif true, create tool if not yet existing.

Definition at line 145 of file ToolHandle.h.

147  : BaseToolHandle(parent,createIf),
148  GaudiHandle<T>( toolTypeAndName,
149  toolComponentType(parent),
150  toolParentName(parent) ),
152  { }
Handle to be used in lieu of naked pointers to gaudis.
Definition: GaudiHandle.h:171
static std::string toolParentName(const IInterface *parent)
Definition: ToolHandle.h:47
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:49
BaseToolHandle(const IInterface *parent=nullptr, bool createIf=true)
Definition: ToolHandle.h:69
static std::string toolComponentType(const IInterface *parent)
Definition: ToolHandle.h:43
ServiceHandle< IToolSvc > m_pToolSvc
Definition: ToolHandle.h:206
bool createIf() const
Definition: ToolHandle.h:36
template<class T>
ToolHandle< T >::ToolHandle ( const IInterface parent = nullptr,
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 106 of file ToolHandle.h.

107  : BaseToolHandle(parent,createIf),
109  toolComponentType(parent),
110  toolParentName(parent) ),
112  { }
Handle to be used in lieu of naked pointers to gaudis.
Definition: GaudiHandle.h:171
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:266
static std::string toolParentName(const IInterface *parent)
Definition: ToolHandle.h:47
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:49
BaseToolHandle(const IInterface *parent=nullptr, bool createIf=true)
Definition: ToolHandle.h:69
static std::string toolComponentType(const IInterface *parent)
Definition: ToolHandle.h:43
ServiceHandle< IToolSvc > m_pToolSvc
Definition: ToolHandle.h:206
bool createIf() const
Definition: ToolHandle.h:36
template<class T>
ToolHandle< T >::ToolHandle ( const std::string &  toolTypeAndName,
const IInterface parent = nullptr,
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
ownerclass owning the ToolHandle
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
parentthe 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.
createIfif true, create tool if not yet existing.

Definition at line 145 of file ToolHandle.h.

147  : BaseToolHandle(parent,createIf),
148  GaudiHandle<T>( toolTypeAndName,
149  toolComponentType(parent),
150  toolParentName(parent) ),
152  { }
Handle to be used in lieu of naked pointers to gaudis.
Definition: GaudiHandle.h:171
static std::string toolParentName(const IInterface *parent)
Definition: ToolHandle.h:47
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:49
BaseToolHandle(const IInterface *parent=nullptr, bool createIf=true)
Definition: ToolHandle.h:69
static std::string toolComponentType(const IInterface *parent)
Definition: ToolHandle.h:43
ServiceHandle< IToolSvc > m_pToolSvc
Definition: ToolHandle.h:206
bool createIf() const
Definition: ToolHandle.h:36

Member Function Documentation

template<class T>
StatusCode ToolHandle< T >::i_retrieve ( IAlgTool *&  algTool) const
inlineoverrideprotectedvirtual

Implements BaseToolHandle.

Definition at line 196 of file ToolHandle.h.

196  {
197  return m_pToolSvc->retrieve( GaudiHandleBase::typeAndName(), IAlgTool::interfaceID(),
198  algTool,
200  }
ServiceHandle< IToolSvc > m_pToolSvc
Definition: ToolHandle.h:206
const IInterface * parent() const
Definition: ToolHandle.h:38
StatusCode retrieve() const
Retrieve the Service.
Definition: ServiceHandle.h:56
bool createIf() const
Definition: ToolHandle.h:36
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:120
template<class T>
StatusCode ToolHandle< T >::i_retrieve ( IAlgTool *&  algTool) const
inlineoverrideprotectedvirtual

Implements BaseToolHandle.

Definition at line 196 of file ToolHandle.h.

196  {
197  return m_pToolSvc->retrieve( GaudiHandleBase::typeAndName(), IAlgTool::interfaceID(),
198  algTool,
200  }
ServiceHandle< IToolSvc > m_pToolSvc
Definition: ToolHandle.h:206
const IInterface * parent() const
Definition: ToolHandle.h:38
StatusCode retrieve() const
Retrieve the Service.
Definition: ServiceHandle.h:56
bool createIf() const
Definition: ToolHandle.h:36
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:120
template<class T>
StatusCode ToolHandle< T >::initialize ( const std::string &  toolTypeAndName,
const IInterface parent = nullptr,
bool  createIf = true 
)
inline

Definition at line 156 of file ToolHandle.h.

157  {
158 
159  GaudiHandleBase::setTypeAndName(toolTypeAndName);
162 
163  m_parent = parent;
165 
167 
168  return sc;
169  }
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9
void setComponentType(const std::string &componentType)
The component type.
Definition: GaudiHandle.h:67
static std::string toolParentName(const IInterface *parent)
Definition: ToolHandle.h:47
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:49
void setParentName(const std::string &parent)
The name of the parent.
Definition: GaudiHandle.h:72
static std::string toolComponentType(const IInterface *parent)
Definition: ToolHandle.h:43
StatusCode initialize(const std::string &serviceName, const std::string &theParentName)
Definition: ServiceHandle.h:46
ServiceHandle< IToolSvc > m_pToolSvc
Definition: ToolHandle.h:206
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
const IInterface * parent() const
Definition: ToolHandle.h:38
const IInterface * m_parent
Definition: ToolHandle.h:54
bool createIf() const
Definition: ToolHandle.h:36
template<class T>
StatusCode ToolHandle< T >::initialize ( const std::string &  toolTypeAndName,
const IInterface parent = nullptr,
bool  createIf = true 
)
inline

Definition at line 156 of file ToolHandle.h.

157  {
158 
159  GaudiHandleBase::setTypeAndName(toolTypeAndName);
162 
163  m_parent = parent;
165 
167 
168  return sc;
169  }
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9
void setComponentType(const std::string &componentType)
The component type.
Definition: GaudiHandle.h:67
static std::string toolParentName(const IInterface *parent)
Definition: ToolHandle.h:47
const std::string & parentName() const
The name of the parent.
Definition: GaudiHandle.h:49
void setParentName(const std::string &parent)
The name of the parent.
Definition: GaudiHandle.h:72
static std::string toolComponentType(const IInterface *parent)
Definition: ToolHandle.h:43
StatusCode initialize(const std::string &serviceName, const std::string &theParentName)
Definition: ServiceHandle.h:46
ServiceHandle< IToolSvc > m_pToolSvc
Definition: ToolHandle.h:206
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
const IInterface * parent() const
Definition: ToolHandle.h:38
const IInterface * m_parent
Definition: ToolHandle.h:54
bool createIf() const
Definition: ToolHandle.h:36
template<class T>
StatusCode ToolHandle< T >::release ( ) const
inline

Release the AlgTool.

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

Definition at line 179 of file ToolHandle.h.

179  { // not really const, because it updates m_pObject
180  return GaudiHandle<T>::release();
181  }
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:215
template<class T>
StatusCode ToolHandle< T >::release ( ) const
inline

Release the AlgTool.

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

Definition at line 179 of file ToolHandle.h.

179  { // not really const, because it updates m_pObject
180  return GaudiHandle<T>::release();
181  }
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:215
template<class T>
StatusCode ToolHandle< T >::release ( T *  algTool) const
inlineoverridevirtual

Do the real release of the AlgTool.

Reimplemented from GaudiHandle< T >.

Definition at line 191 of file ToolHandle.h.

191  {
192  return m_pToolSvc->releaseTool( algTool );
193  }
ServiceHandle< IToolSvc > m_pToolSvc
Definition: ToolHandle.h:206
template<class T>
StatusCode ToolHandle< T >::release ( T *  algTool) const
inlineoverridevirtual

Do the real release of the AlgTool.

Reimplemented from GaudiHandle< T >.

Definition at line 191 of file ToolHandle.h.

191  {
192  return m_pToolSvc->releaseTool( algTool );
193  }
ServiceHandle< IToolSvc > m_pToolSvc
Definition: ToolHandle.h:206
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*& )

Definition at line 173 of file ToolHandle.h.

173  { // not really const, because it updates m_pObject
174  return GaudiHandle<T>::retrieve();
175  }
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:205
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*& )

Definition at line 173 of file ToolHandle.h.

173  { // not really const, because it updates m_pObject
174  return GaudiHandle<T>::retrieve();
175  }
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:205
template<class T>
StatusCode ToolHandle< T >::retrieve ( T *&  algTool) const
inlineoverridevirtual

Do the real retrieval of the AlgTool.

Implements GaudiHandle< T >.

Definition at line 184 of file ToolHandle.h.

184  {
185  IAlgTool* iface = nullptr;
186  algTool = i_retrieve(iface) ? dynamic_cast<T*>(iface) : nullptr;
187  return algTool ? StatusCode::SUCCESS : StatusCode::FAILURE;
188  }
StatusCode i_retrieve(IAlgTool *&algTool) const override
Definition: ToolHandle.h:196
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
template<class T>
StatusCode ToolHandle< T >::retrieve ( T *&  algTool) const
inlineoverridevirtual

Do the real retrieval of the AlgTool.

Implements GaudiHandle< T >.

Definition at line 184 of file ToolHandle.h.

184  {
185  IAlgTool* iface = nullptr;
186  algTool = i_retrieve(iface) ? dynamic_cast<T*>(iface) : nullptr;
187  return algTool ? StatusCode::SUCCESS : StatusCode::FAILURE;
188  }
StatusCode i_retrieve(IAlgTool *&algTool) const override
Definition: ToolHandle.h:196
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23

Friends And Related Function Documentation

template<class T>
Algorithm
friend

Definition at line 96 of file ToolHandle.h.

template<class T>
AlgTool
friend

Definition at line 99 of file ToolHandle.h.

template<class T>
Service
friend

Definition at line 100 of file ToolHandle.h.

Member Data Documentation

template<class T>
ServiceHandle< IToolSvc > ToolHandle< T >::m_pToolSvc
mutableprivate

Definition at line 206 of file ToolHandle.h.


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