Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (e199b415)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiHandle< T > Class Template Reference

#include <GaudiKernel/GaudiHandle.h>

Inheritance diagram for GaudiHandle< T >:
Collaboration diagram for GaudiHandle< T >:

Public Member Functions

template<typename CT = T, typename NCT = std::remove_const_t<T>>
 GaudiHandle (const GaudiHandle< NCT > &other) requires(std
 Copy constructor needed for correct ref-counting. More...
 
 GaudiHandle (const GaudiHandle &other)
 Copy constructor needed for correct ref-counting. More...
 
template<typename CT = T, typename NCT = std::remove_const_t<T>>
 requires (std::is_const_v< CT > &&!std::is_same_v< CT, NCT >) GaudiHandle &operator
 Assignment operator for correct ref-counting. More...
 
virtual StatusCode release (T *comp) const
 Release the component. More...
 
- Public Member Functions inherited from GaudiHandleBase
const std::stringtypeAndName () 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 (std::string_view myName)
 Set the instance name (part after the '/') without changing the class type. More...
 
std::string pythonPropertyClassName () const override
 Name of the componentType with "Handle" appended. More...
 
std::string messageName () const
 name used for printing messages More...
 
std::string pythonRepr () const override
 Python representation of handle, i.e. More...
 
- Public Member Functions inherited from GaudiHandleInfo
virtual ~GaudiHandleInfo ()
 virtual destructor so that derived class destructor is called. More...
 
const std::stringcomponentType () const
 
const std::stringpropertyName () 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::stringparentName () const
 The name of the parent. More...
 

Protected Member Functions

 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...
 
- 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 (std::string componentType)
 The component type. More...
 
void setParentName (std::string parent)
 The name of the parent. More...
 

Private Member Functions

void assertObject () const
 Load the pointer to the component. More...
 

Private Attributes

std::atomic< T * > m_pObject = nullptr
 

Additional Inherited Members

- Public Types inherited from GaudiHandleBase
using PropertyType = GaudiHandleProperty
 

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

Definition at line 179 of file GaudiHandle.h.

Constructor & Destructor Documentation

◆ GaudiHandle() [1/3]

template<class T >
GaudiHandle< T >::GaudiHandle ( std::string  myTypeAndName,
std::string  myComponentType,
std::string  myParentName 
)
inlineprotected

Definition at line 184 of file GaudiHandle.h.

185  : GaudiHandleBase( std::move( myTypeAndName ), std::move( myComponentType ), std::move( myParentName ) ) {}

◆ GaudiHandle() [2/3]

template<class T >
template<typename CT = T, typename NCT = std::remove_const_t<T>>
GaudiHandle< T >::GaudiHandle ( const GaudiHandle< NCT > &  other)
inline

Copy constructor needed for correct ref-counting.

Definition at line 190 of file GaudiHandle.h.

192  : GaudiHandleBase( other ) {
193  m_pObject = other.get();
194  if ( m_pObject ) ::details::nonConst( m_pObject.load() )->addRef();
195  }

◆ GaudiHandle() [3/3]

template<class T >
GaudiHandle< T >::GaudiHandle ( const GaudiHandle< T > &  other)
inline

Copy constructor needed for correct ref-counting.

Definition at line 198 of file GaudiHandle.h.

198  : GaudiHandleBase( other ) {
199  m_pObject = other.m_pObject.load();
200  if ( m_pObject ) ::details::nonConst( m_pObject.load() )->addRef();
201  }

Member Function Documentation

◆ assertObject()

template<class T >
void GaudiHandle< T >::assertObject ( ) const
inlineprivate

Load the pointer to the component.

Do a retrieve if needed. Throw an exception if retrieval fails.

Definition at line 319 of file GaudiHandle.h.

319  { // not really const, because it may update m_pObject
320  if ( !isValid() ) {
321  throw GaudiException( "Failed to retrieve " + componentType() + ": " + typeAndName(),
322  componentType() + " retrieve", StatusCode::FAILURE );
323  }
324  }

◆ release()

template<class T >
virtual StatusCode GaudiHandle< T >::release ( T *  comp) const
inlinevirtual

Release the component.

Default implementation calls release() on the component. Can be overridden by the derived class if something else is needed.

Reimplemented in ToolHandle< T >, ToolHandle< IWrongTool >, ToolHandle< IThreadInitTool >, ToolHandle< IMyTool >, ToolHandle< IAlgTool >, ToolHandle< GaudiTesting::ITestTool >, ToolHandle< Gaudi::TestSuite::FloatTool >, ToolHandle< Gaudi::Tests::Histograms::Directories::HistoGroupsTool >, and ToolHandle< const IMyTool >.

Definition at line 310 of file GaudiHandle.h.

310  { // not really const, because it updates m_pObject
311  // const cast to support T being a const type
312  ::details::nonConst( comp )->release();
313  return StatusCode::SUCCESS;
314  }

◆ requires()

template<class T >
template<typename CT = T, typename NCT = std::remove_const_t<T>>
GaudiHandle< T >::requires ( std::is_const_v< CT > &&!std::is_same_v< CT, NCT >  ) &

Assignment operator for correct ref-counting.

Member Data Documentation

◆ m_pObject

template<class T >
std::atomic<T*> GaudiHandle< T >::m_pObject = nullptr
mutableprivate

Definition at line 330 of file GaudiHandle.h.


The documentation for this class was generated from the following file:
std::move
T move(T... args)
GaudiException
Definition: GaudiException.h:32
GaudiHandleInfo::componentType
const std::string & componentType() const
Definition: GaudiHandle.h:56
details::nonConst
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
Definition: GaudiHandle.h:29
std::atomic::load
T load(T... args)
GaudiHandle::m_pObject
std::atomic< T * > m_pObject
Definition: GaudiHandle.h:330
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
GaudiHandleBase::typeAndName
const std::string & typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:131
GaudiHandleBase::GaudiHandleBase
GaudiHandleBase(std::string myTypeAndName, std::string myComponentType, std::string myParentName)
Create a handle ('smart pointer') to a gaudi component.
Definition: GaudiHandle.h:121
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101