| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
GaudiHandle< T > Class Template Referenceabstract

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

`#include <GaudiKernel/GaudiHandle.h>`

Inheritance diagram for GaudiHandle< T >:
[legend]
Collaboration diagram for GaudiHandle< T >:
[legend]

## Public Member Functions
template<typename CT = T, typename NCT = std::remove_const_t<T>>
| GaudiHandle (const GaudiHandle< NCT > &other, std::enable_if_t< std::is_const_v< CT > &&!std::is_same_v< CT, NCT >> *=nullptr)
| 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>>
std::enable_if_t< std::is_const_v< CT > &&!std::is_same_v< CT, NCT >, GaudiHandle & > | operator= (const GaudiHandle< NCT > &other)
| Assignment operator for correct ref-counting. More...
GaudiHandle & | operator= (const GaudiHandle &other)
| Assignment operator for correct ref-counting. More...
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 ()
| Return the wrapped pointer, not calling retrieve() if null. More...
std::add_const_t< 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-> ()
std::add_const_t< T > & | operator * () const
std::add_const_t< 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 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 ()=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
| GaudiHandle (std::string myTypeAndName, std::string myComponentType, std::string myParentName)
virtual StatusCode | retrieve (T *&) const =0
| Retrieve the component. More...
virtual StatusCode | release (T *comp) const
| Release the component. More...
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 (const std::string &componentType)
| The component type. More...
void | setParentName (const std::string &parent)
| The name of the parent. More...

## Private Member Functions
void | setDefaultTypeAndName ()
| Helper function to set default name and type. More...
void | setDefaultType ()
| Helper function to set default type from the class type T. More...
void | assertObject () const
| Load the pointer to the component. More...

## Private Attributes
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 163 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
| ) |  |
| inline protected

Definition at line 168 of file GaudiHandle.h.

169 : GaudiHandleBase( std::move( myTypeAndName ), std::move( myComponentType ), std::move( myParentName ) ) {}
std::move
T move(T... args)
GaudiHandleBase::GaudiHandleBase
GaudiHandleBase(std::string myTypeAndName, std::string myComponentType, std::string myParentName)
Create a handle ('smart pointer') to a gaudi component.
Definition: GaudiHandle.h:105

## ◆ GaudiHandle() [2/3]

template<class T>
template<typename CT = T, typename NCT = std::remove_const_t<T>>

GaudiHandle< T >::GaudiHandle | ( | const GaudiHandle< NCT > & | other,
|  | std::enable_if_t< std::is_const_v< CT > &&!std::is_same_v< CT, NCT >> * | = `nullptr`
| ) |  |
| inline

Copy constructor needed for correct ref-counting.

Definition at line 174 of file GaudiHandle.h.

176 : GaudiHandleBase( other ) {
177 m_pObject = other.get();
178 if ( m_pObject ) ::details::nonConst( m_pObject )->addRef();
179 }
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
details::nonConst
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
Definition: GaudiHandle.h:20
GaudiHandle::get
T * get()
Return the wrapped pointer, not calling retrieve() if null.
Definition: GaudiHandle.h:248
GaudiHandleBase::GaudiHandleBase
GaudiHandleBase(std::string myTypeAndName, std::string myComponentType, std::string myParentName)
Create a handle ('smart pointer') to a gaudi component.
Definition: GaudiHandle.h:105

## ◆ GaudiHandle() [3/3]

template<class T>

GaudiHandle< T >::GaudiHandle | ( | const GaudiHandle< T > & | other | ) |
| inline

Copy constructor needed for correct ref-counting.

Definition at line 182 of file GaudiHandle.h.

182 : GaudiHandleBase( other ) {
183 m_pObject = other.m_pObject;
184 if ( m_pObject ) ::details::nonConst( m_pObject )->addRef();
185 }
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
details::nonConst
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
Definition: GaudiHandle.h:20
GaudiHandleBase::GaudiHandleBase
GaudiHandleBase(std::string myTypeAndName, std::string myComponentType, std::string myParentName)
Create a handle ('smart pointer') to a gaudi component.
Definition: GaudiHandle.h:105

## Member Function Documentation

## ◆ assertObject()

template<class T>

void GaudiHandle< T >::assertObject | ( |  | ) | const
| inline private

Load the pointer to the component.

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

Definition at line 310 of file GaudiHandle.h.

310 { // not really const, because it may update m_pObject
311 if ( UNLIKELY( !isValid() ) ) {
312 throw GaudiException( "Failed to retrieve " + componentType() + ": " + typeAndName(),
313 componentType() + " retrieve", StatusCode::FAILURE );
314 }
315 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:96
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
GaudiHandleBase::typeAndName
std::string typeAndName() const
The full type and name: "type/name".
Definition: GaudiHandle.h:115
GaudiHandleInfo::componentType
const std::string & componentType() const
Definition: GaudiHandle.h:44
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
GaudiHandle::isValid
bool isValid() const
Check if the handle is valid (try to retrive the object is not done yet).
Definition: GaudiHandle.h:235

## ◆ get() [1/2]

template<class T>

T* GaudiHandle< T >::get | ( |  | ) |
| inline

Return the wrapped pointer, not calling retrieve() if null.

Definition at line 248 of file GaudiHandle.h.

248 { return m_pObject; }
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321

## ◆ get() [2/2]

template<class T>

std::add_const_t<T>* GaudiHandle< T >::get | ( |  | ) | const
| inline

Return the wrapped pointer, not calling retrieve() if null.

Definition at line 251 of file GaudiHandle.h.

251 { return m_pObject; }
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321

## ◆ getDefaultName()

template<class T>

std::string GaudiHandle< T >::getDefaultName | ( |  | ) |
| inline

Definition at line 281 of file GaudiHandle.h.

281 {
282 const auto defName = GaudiHandleBase::type();
283 return ( defName.empty() ? getDefaultType() : defName );
284 }
GaudiHandle::getDefaultType
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:279
GaudiHandleBase::type
std::string type() const
The concrete component class name: the part before the '/'.
Definition: GaudiHandle.cpp:11

## ◆ getDefaultType()

template<class T>

std::string GaudiHandle< T >::getDefaultType | ( |  | ) |
| inline

Helper function to get default type string from the class type.

Definition at line 279 of file GaudiHandle.h.

279 { return System::typeinfoName( typeid( T ) ); }
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:298

## ◆ isSet()

template<class T>

bool GaudiHandle< T >::isSet | ( |  | ) | const
| inline

True if the wrapped pointer is not null.

Definition at line 254 of file GaudiHandle.h.

254 { return get(); }
GaudiHandle::get
T * get()
Return the wrapped pointer, not calling retrieve() if null.
Definition: GaudiHandle.h:248

## ◆ isValid()

template<class T>

bool GaudiHandle< T >::isValid | ( |  | ) | const
| inline

Check if the handle is valid (try to retrive the object is not done yet).

Definition at line 235 of file GaudiHandle.h.

235 {
236 // not really const, because it may update m_pObject
237 return m_pObject || retrieve().isSuccess();
238 }
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
GaudiHandle::retrieve
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:212
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267

## ◆ operator *() [1/2]

template<class T>

T& GaudiHandle< T >::operator * | ( |  | ) |
| inline

Definition at line 256 of file GaudiHandle.h.

256 {
257 assertObject();
258 return *m_pObject;
259 }
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
GaudiHandle::assertObject
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:310

## ◆ operator *() [2/2]

template<class T>

std::add_const_t<T>& GaudiHandle< T >::operator * | ( |  | ) | const
| inline

Definition at line 266 of file GaudiHandle.h.

266 {
267 // not really const, because it may update m_pObject
268 assertObject();
269 return *m_pObject;
270 }
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
GaudiHandle::assertObject
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:310

## ◆ operator bool()

template<class T>

GaudiHandle< T >::operator bool | ( |  | ) | const
| inline

For testing if handle has component.

Does retrieve() if needed. If this returns false, the component could not be retrieved.

Definition at line 242 of file GaudiHandle.h.

242 {
243 // not really const, because it may update m_pObject
244 return isValid();
245 }
GaudiHandle::isValid
bool isValid() const
Check if the handle is valid (try to retrive the object is not done yet).
Definition: GaudiHandle.h:235

## ◆ operator->() [1/2]

template<class T>

T* GaudiHandle< T >::operator-> | ( |  | ) |
| inline

Definition at line 261 of file GaudiHandle.h.

261 {
262 assertObject();
263 return m_pObject;
264 }
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
GaudiHandle::assertObject
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:310

## ◆ operator->() [2/2]

template<class T>

std::add_const_t<T>* GaudiHandle< T >::operator-> | ( |  | ) | const
| inline

Definition at line 272 of file GaudiHandle.h.

272 {
273 // not really const, because it may update m_pObject
274 assertObject();
275 return m_pObject;
276 }
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
GaudiHandle::assertObject
void assertObject() const
Load the pointer to the component.
Definition: GaudiHandle.h:310

## ◆ operator=() [1/2]

template<class T>
template<typename CT = T, typename NCT = std::remove_const_t<T>>

std::enable_if_t<std::is_const_v<CT> && !std::is_same_v<CT, NCT>, GaudiHandle&> GaudiHandle< T >::operator= | ( | const GaudiHandle< NCT > & | other | ) |
| inline

Assignment operator for correct ref-counting.

Definition at line 190 of file GaudiHandle.h.

190 {
191 GaudiHandleBase::operator=( other );
192 // release any current tool
193 release().ignore();
194 m_pObject = other.get();
195 // update ref-counting
196 if ( m_pObject ) ::details::nonConst( m_pObject )->addRef();
197 return *this;
198 }
GaudiHandle::release
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:224
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
details::nonConst
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
Definition: GaudiHandle.h:20
GaudiHandle::get
T * get()
Return the wrapped pointer, not calling retrieve() if null.
Definition: GaudiHandle.h:248
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153

## ◆ operator=() [2/2]

template<class T>

GaudiHandle& GaudiHandle< T >::operator= | ( | const GaudiHandle< T > & | other | ) |
| inline

Assignment operator for correct ref-counting.

Definition at line 201 of file GaudiHandle.h.

201 {
202 GaudiHandleBase::operator=( other );
203 // release any current tool
204 release().ignore();
205 m_pObject = other.m_pObject;
206 // update ref-counting
207 if ( m_pObject ) ::details::nonConst( m_pObject )->addRef();
208 return *this;
209 }
GaudiHandle::release
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:224
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
details::nonConst
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
Definition: GaudiHandle.h:20
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153

## ◆ release() [1/2]

template<class T>

StatusCode GaudiHandle< T >::release | ( |  | ) | const
| inline

Release the component.

Definition at line 224 of file GaudiHandle.h.

224 {
225 // not really const, because it updates m_pObject
226 StatusCode sc = StatusCode::SUCCESS;
227 if ( m_pObject ) {
228 sc = release( m_pObject );
229 m_pObject = nullptr;
230 }
231 return sc;
232 }
GaudiHandle::release
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:224
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50

## ◆ release() [2/2]

template<class T>

virtual StatusCode GaudiHandle< T >::release | ( | T * | comp | ) | const
| inline protected virtual

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 >, and ToolHandle< IThreadInitTool >.

Definition at line 292 of file GaudiHandle.h.

292 { // not really const, because it updates m_pObject
293 // const cast to support T being a const type
294 ::details::nonConst( comp )->release();
295 return StatusCode::SUCCESS;
296 }
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
details::nonConst
std::remove_const_t< T > * nonConst(T *p)
Cast a pointer to a non const type.
Definition: GaudiHandle.h:20

## ◆ retrieve() [1/2]

template<class T>

StatusCode GaudiHandle< T >::retrieve | ( |  | ) | const
| inline

Retrieve the component.

Release existing component if needed.

Definition at line 212 of file GaudiHandle.h.

212 {
213 // not really const, because it updates m_pObject
214 StatusCode sc = StatusCode::SUCCESS;
215 if ( m_pObject && release().isFailure() ) { sc = StatusCode::FAILURE; }
216 if ( sc && retrieve( m_pObject ).isFailure() ) {
217 m_pObject = nullptr;
218 sc = StatusCode::FAILURE;
219 }
220 return sc;
221 }
GaudiHandle::release
StatusCode release() const
Release the component.
Definition: GaudiHandle.h:224
GaudiHandle::m_pObject
T * m_pObject
Definition: GaudiHandle.h:321
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
GaudiHandle::retrieve
StatusCode retrieve() const
Retrieve the component.
Definition: GaudiHandle.h:212
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86

## ◆ retrieve() [2/2]

template<class T>

virtual StatusCode GaudiHandle< T >::retrieve | ( | T *& |  | ) | const
| protected pure virtual

Retrieve the component.

To be implemented by the derived class. It will pass the pointer

Implemented in ToolHandle< T >, ToolHandle< IThreadInitTool >, ServiceHandle< T >, ServiceHandle< IToolSvc >, and ServiceHandle< IInterface >.

## ◆ setDefaultType()

template<class T>

void GaudiHandle< T >::setDefaultType | ( |  | ) |
| inline private

Helper function to set default type from the class type T.

Definition at line 306 of file GaudiHandle.h.

306 { GaudiHandleBase::setTypeAndName( getDefaultType() ); }
GaudiHandle::getDefaultType
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:279
GaudiHandleBase::setTypeAndName
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9

## ◆ setDefaultTypeAndName()

template<class T>

void GaudiHandle< T >::setDefaultTypeAndName | ( |  | ) |
| inline private

Helper function to set default name and type.

Definition at line 300 of file GaudiHandle.h.

300 {
301 const std::string& myType = getDefaultType();
302 GaudiHandleBase::setTypeAndName( myType + '/' + myType );
303 }
GaudiHandle::getDefaultType
std::string getDefaultType()
Helper function to get default type string from the class type.
Definition: GaudiHandle.h:279
GaudiHandleBase::setTypeAndName
void setTypeAndName(std::string myTypeAndName)
The component "type/name" string.
Definition: GaudiHandle.cpp:9
std::string
STL class.

## Member Data Documentation

## ◆ m_pObject

template<class T>

T* GaudiHandle< T >::m_pObject = nullptr
| mutable private

Definition at line 321 of file GaudiHandle.h.

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

- GaudiKernel/GaudiKernel/GaudiHandle.h