The Gaudi Framework  v30r4 (9b837755)
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 ()
 Get object from store or create a new one if it doesn't exist. More...
 
T * put (std::unique_ptr< T > object)
 Register object in transient store. More...
 
T * put (T *object)
 
- Public Member Functions inherited from DataObjectHandleBase
 DataObjectHandleBase (const DataObjID &k, Gaudi::v1::DataHandle::Mode a, IDataHandleHolder *owner)
 
 DataObjectHandleBase (const std::string &k, Gaudi::v1::DataHandle::Mode a, IDataHandleHolder *owner)
 
virtual ~DataObjectHandleBase ()
 
 DataObjectHandleBase (const DataObjectHandleBase &)=delete
 
 DataObjectHandleBase (DataObjectHandleBase &&)
 
DataObjectHandleBaseoperator= (const DataObjectHandleBase &)
 
template<class OWNER , class K , typename = typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type>
 DataObjectHandleBase (OWNER *owner, Gaudi::v1::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::v1::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::v1::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::v1::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
 

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

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

Check the existence of the object in the transient store.

Definition at line 113 of file DataObjectHandle.h.

113 { return get( false ) != nullptr; }
template<typename ValueType >
auto DataObjectHandle< ValueType >::get ( ) const
inline

Retrieve object from transient data store.

Definition at line 102 of file DataObjectHandle.h.

102 { return get( true ); }
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 143 of file DataObjectHandle.h.

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

108 { return get( false ); }
template<typename T >
T * DataObjectHandle< T >::getOrCreate ( )

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

Definition at line 171 of file DataObjectHandle.h.

172 {
173  T* obj = get( false );
174  return obj ? obj : put( std::make_unique<T>() );
175 }
T * put(std::unique_ptr< T > object)
Register object in transient store.
template<typename T>
T * DataObjectHandle< T >::put ( std::unique_ptr< T >  object)

Register object in transient store.

Definition at line 159 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 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Define general base for Gaudi exception.
bool isSuccess() const
Definition: StatusCode.h:287
SmartIF< IDataProviderSvc > m_EDS
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
StatusCode registerObject(boost::string_ref fullPath, DataObject *pObject)
Register object with the data store.
virtual const std::string & objKey() const
Definition: DataHandle.h:55
template<typename T>
T* DataObjectHandle< T >::put ( T *  object)
inline

Definition at line 126 of file DataObjectHandle.h.

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

Member Data Documentation

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

Definition at line 130 of file DataObjectHandle.h.


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