| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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 ()
| Get object from store or create a new one if it doesn't exist. More...
T * | put (T *object)
| Register object in transient store. 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 = typename std::enable_if<std::is_base_of<IProperty, OWNER>::value>::type>
| 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 StatusCode | commit ()
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 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 27 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 47 of file DataObjectHandle.h.

47 { return get( false ) != nullptr; }
template<typename T>

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

Retrieve object from transient data store.

Definition at line 36 of file DataObjectHandle.h.

36 { 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 115 of file DataObjectHandle.h.

116 {
117
118 auto dataObj = fetch();
119
120 if ( UNLIKELY( !dataObj ) ) {
121 if ( mustExist ) { // Problems in getting from the store
122 throw GaudiException( "Cannot retrieve " + objKey() + " from transient store.",
123 m_owner ? owner()->name() : "no owner", StatusCode::FAILURE );
124 }
125 return nullptr;
126 }
127
128 if ( UNLIKELY( !m_goodType ) ) { // Check type compatibility once
129
130 T* obj = dynamic_cast<T*>( dataObj );
131 m_goodType = ( obj != nullptr );
132
133 if ( UNLIKELY( !m_goodType ) ) {
134
135 std::string errorMsg( "The type provided for " + objKey() + " is " + System::typeinfoName( typeid( T ) ) +
136 " and is different from the one of the object in the store." );
137 // log << MSG::ERROR << errorMsg << endmsg;
138 throw GaudiException( errorMsg, "Wrong DataObjectType", StatusCode::FAILURE );
139 }
140 // log << MSG::DEBUG << "The data type (" << typeid(T).name()
141 // << ") specified for the handle of " << dataProductName()
142 // << " is the same of the object in the store. "
143 // << "From now on the result of a static_cast will be returned." << endmsg;
144 return obj;
145 }
146
147 // setRead();
148 // From the second read on, this is safe
149 return static_cast<T*>( dataObj );
150 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:128
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
StatusCode::FAILURE
Definition: StatusCode.h:31
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:329
Gaudi::DataHandle::objKey
virtual const std::string & objKey() const
Definition: DataHandle.h:49
DataObjectHandle::m_goodType
bool m_goodType
Definition: DataObjectHandle.h:61
std::string
STL class.
Gaudi::DataHandle::m_owner
IDataHandleHolder * m_owner
Definition: DataHandle.h:69
DataObjectHandleBase::fetch
DataObject * fetch() const
Definition: DataObjectHandleBase.cpp:64
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:42
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 42 of file DataObjectHandle.h.

42 { 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 166 of file DataObjectHandle.h.

167 {
168
169 // this process needs to be locking for multi-threaded applications
170 // lock(); --> done in caller
171
172 T* obj = get( false );
173
174 // object exists, we are done
175 if ( obj ) {
176 // unlock();
177 return obj;
178 }
179
180 // create it
181 return put( new T{} );
182
183 // unlock();
184 }
DataObjectHandle::put
T * put(T *object)
Register object in transient store.
Definition: DataObjectHandle.h:154
template<typename T>

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

Register object in transient store.

Definition at line 154 of file DataObjectHandle.h.

155 {
156 assert( m_init );
157 StatusCode rc = m_EDS->registerObject( objKey(), objectp );
158 if ( !rc.isSuccess() ) {
159 throw GaudiException( "Error in put of " + objKey(), "DataObjectHandle<T>::put", StatusCode::FAILURE );
160 }
161 return objectp;
162 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
StatusCode::FAILURE
Definition: StatusCode.h:31
Gaudi::DataHandle::objKey
virtual const std::string & objKey() const
Definition: DataHandle.h:49
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition: DataObjectHandleBase.h:73
DataObjectHandleBase::m_init
bool m_init
Definition: DataObjectHandleBase.h:76
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
IOTest.rc
rc
Definition: IOTest.py:103
IDataProviderSvc::registerObject
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)=0
Register object with the data store.

## Member Data Documentation

template<typename T>

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

Definition at line 61 of file DataObjectHandle.h.

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

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