The Gaudi Framework  v36r1 (3e2fb5a8)
DataObjectHandle< T > Class Template Reference

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

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/AlgTool.h>

Inheritance diagram for DataObjectHandle< T >:

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
 
std::string pythonRepr () const override
 
 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...
 

Private Member Functions

T * get (bool mustExist) const
 Try to retrieve from the transient store. More...
 

Private Attributes

bool m_goodType = false
 

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 36 of file AlgTool.h.

Member Function Documentation

◆ DataObjectHandleBase() [1/5]

template<typename T >
DataObjectHandleBase::DataObjectHandleBase
delete

◆ DataObjectHandleBase() [2/5]

template<typename T >
DataObjectHandleBase::DataObjectHandleBase

Definition at line 38 of file DataObjectHandleBase.cpp.

56  : Gaudi::DataHandle( k, a, owner ) {
57  m_owner->declare( *this );
58 }

◆ DataObjectHandleBase() [3/5]

template<typename T >
DataObjectHandleBase::DataObjectHandleBase

Definition at line 39 of file DataObjectHandleBase.cpp.

63  : DataObjectHandleBase( DataObjID( k ), a, owner ) {}

◆ DataObjectHandleBase() [4/5]

template<typename T >
DataObjectHandleBase::DataObjectHandleBase

Definition at line 43 of file DataObjectHandleBase.cpp.

27  : Gaudi::DataHandle( other )
28  , m_EDS( std::move( other.m_EDS ) )
29  , m_MS( std::move( other.m_MS ) )
30  , m_init( other.m_init )
31  , m_optional( other.m_optional )
32  , m_wasRead( other.m_wasRead )
33  , m_wasWritten( other.m_wasWritten )
34  , m_searchDone( other.m_searchDone ) {
35  m_owner->declare( *this );
36 }

◆ 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 ,
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 49 of file DataObjectHandleBase.h.

49  {},
50  std::string doc = "" )
51  : DataObjectHandleBase( key, m, owner ) {
52  auto p = owner->declareProperty( std::move( name ), *this, std::move( doc ) );
53  p->template setOwnerType<OWNER>();
54  }

◆ exist()

template<typename T >
bool DataObjectHandle< T >::exist ( ) const
inline

Check the existence of the object in the transient store.

Definition at line 123 of file DataObjectHandle.h.

123 { return get( false ) != nullptr; }

◆ get() [1/2]

template<typename ValueType >
auto DataObjectHandle< ValueType >::get
inline

Retrieve object from transient data store.

Definition at line 112 of file DataObjectHandle.h.

112 { return get( true ); }

◆ 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 160 of file DataObjectHandle.h.

160  {
161  auto dataObj = fetch();
162  if ( UNLIKELY( !dataObj ) ) {
163  if ( mustExist ) { // Problems in getting from the store
164  throw GaudiException( "Cannot retrieve " + objKey() + " from transient store.",
165  m_owner ? owner()->name() : "no owner", StatusCode::FAILURE );
166  }
167  return nullptr;
168  }
169  if ( UNLIKELY( !m_goodType ) ) m_goodType = ::details::verifyType<T>( dataObj );
170  return static_cast<T*>( dataObj );
171 }

◆ 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 118 of file DataObjectHandle.h.

118 { return get( false ); }

◆ getOrCreate()

template<typename T >
T * DataObjectHandle< T >::getOrCreate

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

Definition at line 184 of file DataObjectHandle.h.

184  {
185  T* obj = get( false );
186  return obj ? obj : put( std::make_unique<T>() );
187 }

◆ put() [1/2]

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

Register object in transient store.

Definition at line 175 of file DataObjectHandle.h.

175  {
176  assert( m_init );
177  StatusCode sc = m_EDS->registerObject( objKey(), objectp.get() );
178  if ( !sc.isSuccess() ) { throw GaudiException( "Error in put of " + objKey(), "DataObjectHandle<T>::put", sc ); }
179  return objectp.release();
180 }

◆ put() [2/2]

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

Definition at line 135 of file DataObjectHandle.h.

135  {
136  return put( std::unique_ptr<T>( object ) );
137  }

◆ pythonRepr()

template<typename T >
std::string DataObjectHandle< T >::pythonRepr ( ) const
inlineoverride

Definition at line 139 of file DataObjectHandle.h.

139  {
140  auto repr = DataObjectHandleBase::pythonRepr();
141  boost::replace_all( repr, default_type, System::typeinfoName( typeid( T ) ) );
142  return repr;
143  }

Member Data Documentation

◆ m_goodType

template<typename T >
bool DataObjectHandle< T >::m_goodType = false
mutableprivate

Definition at line 147 of file DataObjectHandle.h.


The documentation for this class was generated from the following files:
std::string
STL class.
DataObjectHandle::m_goodType
bool m_goodType
Definition: DataObjectHandle.h:147
std::move
T move(T... args)
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:355
GaudiException
Definition: GaudiException.h:31
NewInputWrite.fetch
fetch
Definition: NewInputWrite.py:44
Gaudi::DataHandle
Definition: DataHandle.h:38
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:308
DataObjectHandle::get
T * get() const
Retrieve object from transient data store.
Definition: DataObjectHandle.h:112
TimingHistograms.name
name
Definition: TimingHistograms.py:23
StatusCode
Definition: StatusCode.h:65
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
DataObjectHandleBase
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
Definition: DataObjectHandleBase.h:35
DataObjID
Definition: DataObjID.h:47
DataObjectHandle::put
T * put(std::unique_ptr< T > object) const
Register object in transient store.
Definition: DataObjectHandle.h:175
Gaudi::DataHandle::pythonRepr
virtual std::string pythonRepr() const
Definition: DataHandle.cpp:19
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:106
std::unique_ptr
STL class.
ProduceConsume.key
key
Definition: ProduceConsume.py:52