| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Private Member Functions | Private Attributes | List of all members
DataObjectHandle< T > Class Template Reference

DataObjectHandle.h GaudiKernel/DataObjectHandle.h. More...

`#include <GaudiKernel/AlgTool.h>`

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

## Public Member Functions
T * | get () const
| Retrieve object from transient data store. More...
T * | getIfExists () const
| Bypass check of existence of object in transient store Only uses main location of the. More...
bool | exist () const
| Check the existence of the object in the transient store. More...
T * | getOrCreate () const
| Get object from store or create a new one if it doesn't exist. More...
T * | put (std::unique_ptr< T > object) const
| Register object in transient store. More...
T * | put (T *object) const
| DataObjectHandleBase (const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
| DataObjectHandleBase (const std::string &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
| DataObjectHandleBase (const DataObjectHandleBase &)=delete
| DataObjectHandleBase (DataObjectHandleBase &&)
template<class OWNER , class K , typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
| DataObjectHandleBase (OWNER *owner, Gaudi::DataHandle::Mode m, std::string name, const K &key={}, std::string doc="")
| Autodeclaring constructor with property name, mode, key and documentation. More...
Public Member Functions inherited from DataObjectHandleBase
| DataObjectHandleBase (const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
| DataObjectHandleBase (const std::string &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
virtual | ~DataObjectHandleBase ()
| DataObjectHandleBase (const DataObjectHandleBase &)=delete
| DataObjectHandleBase (DataObjectHandleBase &&)
DataObjectHandleBase & | operator= (const DataObjectHandleBase &)
template<class OWNER , class K , typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
| DataObjectHandleBase (OWNER *owner, Gaudi::DataHandle::Mode m, std::string name, const K &key={}, std::string doc="")
| Autodeclaring constructor with property name, mode, key and documentation. More...
std::string | toString () const
std::string | pythonRepr () const override
void | fromString (const std::string &s)
bool | isOptional () const
| Check if the data object declared is optional for the algorithm. More...
void | setOptional (bool optional=true)
bool | initialized () const
bool | wasRead () const
bool | wasWritten () const
bool | isValid () const
Public Member Functions inherited from Gaudi::DataHandle
| DataHandle (const DataObjID &k, Mode a=Reader, IDataHandleHolder *owner=nullptr)
| DataHandle (const DataObjID &k, const bool &isCond, Mode a=Reader, IDataHandleHolder *owner=nullptr)
virtual | ~DataHandle ()=default
virtual void | setOwner (IDataHandleHolder *o)
virtual IDataHandleHolder * | owner () const
virtual Mode | mode () const
virtual void | setKey (const DataObjID &key) const
virtual void | updateKey (const std::string &key) const
virtual const std::string & | objKey () const
virtual const DataObjID & | fullKey () const
virtual void | reset (bool)
virtual bool | isCondition () const

## Private Member Functions
T * | get (bool mustExist) const
| Try to retrieve from the transient store. More...

## Private Attributes
bool | m_goodType = false

## Additional Inherited Members
Public Types inherited from DataObjectHandleBase
using | PropertyType = DataObjectHandleProperty
Public Types inherited from Gaudi::DataHandle
enum | Mode { Reader = 1 << 2, Writer = 1 << 4, Updater = Reader | Writer }
Protected Member Functions inherited from DataObjectHandleBase
void | setRead (bool wasRead=true)
void | setWritten (bool wasWritten=true)
bool | init () override
DataObject * | fetch () const
Protected Attributes inherited from DataObjectHandleBase
SmartIF< IDataProviderSvc > | m_EDS
SmartIF< IMessageSvc > | m_MS
bool | m_init = false
bool | m_optional = false
bool | m_wasRead = false
bool | m_wasWritten = false
bool | m_searchDone = false
| Whether the search part of the fetch method (so dealing with alt names was already executed or not. More...
std::mutex | m_searchMutex
| A Mutex protecting the calls to the search part of the fetch method, so that we are sure that we only call it once. More...
Protected Attributes inherited from Gaudi::DataHandle
DataObjID | m_key = {"NONE"}
| The key of the object behind this DataHandle Although it may look strange to have it mutable, this can actually change in case the object had alternative names, and it should not be visible to the end user, for which the Handle is still the same. More...
IDataHandleHolder * | m_owner = nullptr

## Detailed Description

### template<typename T>
class DataObjectHandle< T >

DataObjectHandle.h GaudiKernel/DataObjectHandle.h.

Templated Handle class for objects in the event store

Inheritance: DataHandle->DataObjectHandleBase->DataObjectHandle<T>

Author
  Charles Leggett

Date
  2015-09-01

Definition at line 26 of file AlgTool.h.

## Member Function Documentation

## ◆ DataObjectHandleBase() [1/5]

template<typename T>

DataObjectHandleBase::DataObjectHandleBase

Definition at line 45 of file DataObjectHandleBase.cpp.

46 : Gaudi::DataHandle( k, a, owner ) {
47 m_owner->declare( *this );
48 }
IDataHandleHolder::declare
virtual void declare(Gaudi::DataHandle &)=0
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:40
Gaudi::DataHandle::m_owner
IDataHandleHolder * m_owner
Definition: DataHandle.h:66
Gaudi::DataHandle
Definition: DataHandle.h:27

## ◆ DataObjectHandleBase() [2/5]

template<typename T>

DataObjectHandleBase::DataObjectHandleBase

Definition at line 52 of file DataObjectHandleBase.cpp.

53 : DataObjectHandleBase( DataObjID( k ), a, owner ) {}
DataObjID
Definition: DataObjID.h:37
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:40
DataObjectHandleBase::DataObjectHandleBase
DataObjectHandleBase(const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
Definition: DataObjectHandleBase.cpp:45

## ◆ DataObjectHandleBase() [3/5]

template<typename T>

DataObjectHandleBase::DataObjectHandleBase
| delete

## ◆ DataObjectHandleBase() [4/5]

template<typename T>

DataObjectHandleBase::DataObjectHandleBase

Definition at line 16 of file DataObjectHandleBase.cpp.

17 : Gaudi::DataHandle( other )
18 , m_EDS( std::move( other.m_EDS ) )
19 , m_MS( std::move( other.m_MS ) )
20 , m_init( other.m_init )
21 , m_optional( other.m_optional )
22 , m_wasRead( other.m_wasRead )
23 , m_wasWritten( other.m_wasWritten )
24 , m_searchDone( other.m_searchDone ) {
25 m_owner->declare( *this );
26 }
IDataHandleHolder::declare
virtual void declare(Gaudi::DataHandle &)=0
DataObjectHandleBase::m_wasRead
bool m_wasRead
Definition: DataObjectHandleBase.h:79
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition: DataObjectHandleBase.h:74
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:77
DataObjectHandleBase::m_searchDone
bool m_searchDone
Whether the search part of the fetch method (so dealing with alt names was already executed or not.
Definition: DataObjectHandleBase.h:87
DataObjectHandleBase::m_optional
bool m_optional
Definition: DataObjectHandleBase.h:78
Gaudi::DataHandle::m_owner
IDataHandleHolder * m_owner
Definition: DataHandle.h:66
Gaudi::DataHandle
Definition: DataHandle.h:27
std::move
T move(T... args)
DataObjectHandleBase::m_MS
SmartIF< IMessageSvc > m_MS
Definition: DataObjectHandleBase.h:75
DataObjectHandleBase::m_wasWritten
bool m_wasWritten
Definition: DataObjectHandleBase.h:80

## ◆ DataObjectHandleBase() [5/5]

template<typename T>
template<class OWNER , class K , typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>

DataObjectHandleBase::DataObjectHandleBase | ( | class OWNER | ,
|  | class K | ,
|  | typename | = `std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>`
| ) |  |
| inline

Autodeclaring constructor with property name, mode, key and documentation.

Note
  the use std::enable_if is required to avoid ambiguities

Definition at line 40 of file DataObjectHandleBase.h.

40 {},
41 std::string doc = "" )
42 : DataObjectHandleBase( key, m, owner ) {
43 auto p = owner->declareProperty( std::move( name ), *this, std::move( doc ) );
44 p->template setOwnerType<OWNER>();
45 }
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:40
std::string
STL class.
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:92
std::move
T move(T... args)
DataObjectHandleBase::DataObjectHandleBase
DataObjectHandleBase(const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
Definition: DataObjectHandleBase.cpp:45

## ◆ exist()

template<typename T>

bool DataObjectHandle< T >::exist | ( |  | ) | const
| inline

Check the existence of the object in the transient store.

Definition at line 108 of file DataObjectHandle.h.

108 { return get( false ) != nullptr; }
DataObjectHandle::get
T * get() const
Retrieve object from transient data store.
Definition: DataObjectHandle.h:97

## ◆ get() [1/2]

template<typename ValueType >

auto DataObjectHandle< ValueType >::get | ( |  | ) | const
| inline

Retrieve object from transient data store.

Definition at line 97 of file DataObjectHandle.h.

97 { return get( true ); }
DataObjectHandle::get
T * get() const
Retrieve object from transient data store.
Definition: DataObjectHandle.h:97

## ◆ get() [2/2]

template<typename T >

T * DataObjectHandle< T >::get | ( | bool | mustExist | ) | const
| private

Try to retrieve from the transient store.

If the retrieval succeded and this is the first time we retrieve, perform a dynamic cast to the desired object. Then finally set the handle as Read. If this is not the first time we cast and the cast worked, just use the static cast: we do not need the checks of the dynamic cast for every access!

Definition at line 138 of file DataObjectHandle.h.

138 {
139 auto dataObj = fetch();
140 if ( UNLIKELY( !dataObj ) ) {
141 if ( mustExist ) { // Problems in getting from the store
142 throw GaudiException( "Cannot retrieve " + objKey() + " from transient store.",
143 m_owner ? owner()->name() : "no owner", StatusCode::FAILURE );
144 }
145 return nullptr;
146 }
147 if ( UNLIKELY( !m_goodType ) ) m_goodType = ::details::verifyType<T>( dataObj );
148 return static_cast<T*>( dataObj );
149 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:96
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:40
DataObjectHandle::m_goodType
bool m_goodType
Definition: DataObjectHandle.h:125
Gaudi::DataHandle::objKey
virtual const std::string & objKey() const
Definition: DataHandle.h:47
Gaudi::DataHandle::m_owner
IDataHandleHolder * m_owner
Definition: DataHandle.h:66
DataObjectHandleBase::fetch
DataObject * fetch() const
Definition: DataObjectHandleBase.cpp:59
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86

## ◆ getIfExists()

template<typename T>

T* DataObjectHandle< T >::getIfExists | ( |  | ) | const
| inline

Bypass check of existence of object in transient store Only uses main location of the.

Definition at line 103 of file DataObjectHandle.h.

103 { return get( false ); }
DataObjectHandle::get
T * get() const
Retrieve object from transient data store.
Definition: DataObjectHandle.h:97

## ◆ getOrCreate()

template<typename T >

T * DataObjectHandle< T >::getOrCreate | ( |  | ) | const

Get object from store or create a new one if it doesn't exist.

Definition at line 164 of file DataObjectHandle.h.

164 {
165 T* obj = get( false );
166 return obj ? obj : put( std::make_unique<T>() );
167 }
DataObjectHandle::get
T * get() const
Retrieve object from transient data store.
Definition: DataObjectHandle.h:97
DataObjectHandle::put
T * put(std::unique_ptr< T > object) const
Register object in transient store.
Definition: DataObjectHandle.h:153

## ◆ put() [1/2]

template<typename T>

T * DataObjectHandle< T >::put | ( | std::unique_ptr< T > | object | ) | const

Register object in transient store.

Definition at line 153 of file DataObjectHandle.h.

153 {
154 assert( m_init );
155 StatusCode rc = m_EDS->registerObject( objKey(), objectp.get() );
156 if ( !rc.isSuccess() ) {
157 throw GaudiException( "Error in put of " + objKey(), "DataObjectHandle<T>::put", StatusCode::FAILURE );
158 }
159 return objectp.release();
160 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
Gaudi::DataHandle::objKey
virtual const std::string & objKey() const
Definition: DataHandle.h:47
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition: DataObjectHandleBase.h:74
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:77
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IOTest.rc
rc
Definition: IOTest.py:101
IDataProviderSvc::registerObject
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
Definition: IDataProviderSvc.h:62
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86

## ◆ put() [2/2]

template<typename T>

T* DataObjectHandle< T >::put | ( | T * | object | ) | const
| inline

Definition at line 121 of file DataObjectHandle.h.

121 { return put( std::unique_ptr<T>( object ) ); }
DataObjectHandle::put
T * put(std::unique_ptr< T > object) const
Register object in transient store.
Definition: DataObjectHandle.h:153
std::unique_ptr
STL class.

## Member Data Documentation

## ◆ m_goodType

template<typename T>

bool DataObjectHandle< T >::m_goodType = false
| mutable private

Definition at line 125 of file DataObjectHandle.h.

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

- GaudiKernel/GaudiKernel/AlgTool.h
- GaudiKernel/GaudiKernel/DataObjectHandle.h