The Gaudi Framework  v32r2 (46d42edc)
DataObjectHandle< T > Class Template Reference

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

#include <GaudiKernel/AlgTool.h>

Inheritance diagram for DataObjectHandle< T >:
Collaboration 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...
 
- 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 &&)
 
DataObjectHandleBaseoperator= (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 IDataHandleHolderowner () const
 
virtual Mode mode () const
 
virtual void setKey (const DataObjID &key) const
 
virtual void updateKey (const std::string &key) const
 
virtual const std::stringobjKey () const
 
virtual const DataObjIDfullKey () 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
 
DataObjectfetch () const
 
- Protected Attributes inherited from DataObjectHandleBase
SmartIF< IDataProviderSvcm_EDS
 
SmartIF< IMessageSvcm_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...
 
IDataHandleHolderm_owner = nullptr
 
- Static Protected Attributes inherited from DataObjectHandleBase
static const std::string default_type = "unknown_t"
 

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 47 of file DataObjectHandleBase.cpp.

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

◆ DataObjectHandleBase() [2/5]

template<typename T>
DataObjectHandleBase::DataObjectHandleBase

Definition at line 54 of file DataObjectHandleBase.cpp.

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

◆ DataObjectHandleBase() [3/5]

template<typename T>
DataObjectHandleBase::DataObjectHandleBase
delete

◆ DataObjectHandleBase() [4/5]

template<typename T>
DataObjectHandleBase::DataObjectHandleBase

Definition at line 18 of file DataObjectHandleBase.cpp.

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

◆ 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 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  }
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:40
STL class.
constexpr double m
Definition: SystemOfUnits.h:92
T move(T... args)
DataObjectHandleBase(const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)

◆ exist()

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

Check the existence of the object in the transient store.

Definition at line 109 of file DataObjectHandle.h.

109 { return get( false ) != nullptr; }
T * get() const
Retrieve object from transient data store.

◆ get() [1/2]

template<typename ValueType >
auto DataObjectHandle< ValueType >::get ( ) const
inline

Retrieve object from transient data store.

Definition at line 98 of file DataObjectHandle.h.

98 { return get( true ); }
T * get() const
Retrieve object from transient data store.

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

145  {
146  auto dataObj = fetch();
147  if ( UNLIKELY( !dataObj ) ) {
148  if ( mustExist ) { // Problems in getting from the store
149  throw GaudiException( "Cannot retrieve " + objKey() + " from transient store.",
150  m_owner ? owner()->name() : "no owner", StatusCode::FAILURE );
151  }
152  return nullptr;
153  }
154  if ( UNLIKELY( !m_goodType ) ) m_goodType = ::details::verifyType<T>( dataObj );
155  return static_cast<T*>( dataObj );
156 }
#define UNLIKELY(x)
Definition: Kernel.h:96
Define general base for Gaudi exception.
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:40
virtual const std::string & objKey() const
Definition: DataHandle.h:47
IDataHandleHolder * m_owner
Definition: DataHandle.h:66
DataObject * fetch() const
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 104 of file DataObjectHandle.h.

104 { return get( false ); }
T * get() const
Retrieve object from transient data store.

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

171  {
172  T* obj = get( false );
173  return obj ? obj : put( std::make_unique<T>() );
174 }
T * get() const
Retrieve object from transient data store.
T * put(std::unique_ptr< T > object) const
Register object in transient store.

◆ put() [1/2]

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

Register object in transient store.

Definition at line 160 of file DataObjectHandle.h.

160  {
161  assert( m_init );
162  StatusCode rc = m_EDS->registerObject( objKey(), objectp.get() );
163  if ( !rc.isSuccess() ) {
164  throw GaudiException( "Error in put of " + objKey(), "DataObjectHandle<T>::put", StatusCode::FAILURE );
165  }
166  return objectp.release();
167 }
Define general base for Gaudi exception.
virtual const std::string & objKey() const
Definition: DataHandle.h:47
SmartIF< IDataProviderSvc > m_EDS
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
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 122 of file DataObjectHandle.h.

122 { return put( std::unique_ptr<T>( object ) ); }
T * put(std::unique_ptr< T > object) const
Register object in transient store.
STL class.

◆ pythonRepr()

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

Reimplemented from Gaudi::DataHandle.

Definition at line 124 of file DataObjectHandle.h.

124  {
125  auto repr = DataObjectHandleBase::pythonRepr();
126  boost::replace_all( repr, default_type, System::typeinfoName( typeid( T ) ) );
127  return repr;
128  }
static const std::string default_type
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:298
std::string pythonRepr() const override

Member Data Documentation

◆ m_goodType

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

Definition at line 132 of file DataObjectHandle.h.


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