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

 DataObjectHandle ()
 
 DataObjectHandle (const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *o)
 
 DataObjectHandle (const std::string &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *o)
 
virtual ~DataObjectHandle ()
 
T * get ()
 Retrieve object from transient data store. More...
 
T * getIfExists ()
 Bypass check of existence of object in transient store Only uses main location of the. More...
 
bool exist ()
 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...
 
void put (T *object)
 Register object in transient store. More...
 
- Public Member Functions inherited from DataObjectHandleBase
 DataObjectHandleBase ()
 
 DataObjectHandleBase (const DataObjID &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *o)
 
 DataObjectHandleBase (const std::string &k, Gaudi::DataHandle::Mode a, IDataHandleHolder *o)
 
virtual ~DataObjectHandleBase ()
 
const std::string toString () const
 
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)
 
const std::vector< std::string > & alternativeDataProductNames () const
 
void setAlternativeDataProductNames (const std::vector< std::string > &alternativeAddresses)
 
bool initialized () const
 
bool wasRead () const
 
bool wasWritten () const
 
bool isValid () const
 
- Public Member Functions inherited from Gaudi::DataHandle
 DataHandle ()
 
 DataHandle (const DataObjID &k, Mode a=Reader, IDataHandleHolder *owner=0)
 
virtual ~DataHandle ()
 
virtual void setOwner (IDataHandleHolder *o)
 
virtual IDataHandleHolderowner () const
 
virtual Mode mode () const
 
virtual void setKey (const DataObjID &key)
 
virtual void updateKey (const std::string &key)
 
virtual const std::stringobjKey () const
 
virtual const DataObjIDfullKey () const
 
virtual void reset (bool)
 
virtual StatusCode commit ()
 

Private Member Functions

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

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)
 
void init ()
 
- Protected Member Functions inherited from Gaudi::DataHandle
virtual void setMode (const Mode &mode)
 
- Protected Attributes inherited from DataObjectHandleBase
SmartIF< IDataProviderSvcm_EDS
 
SmartIF< IMessageSvcm_MS
 
bool m_init
 
bool m_goodType
 
bool m_optional
 
bool m_wasRead
 
bool m_wasWritten
 
std::vector< std::stringm_altNames
 
- Protected Attributes inherited from Gaudi::DataHandle
DataObjID m_key
 
IDataHandleHolderm_owner
 

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

Constructor & Destructor Documentation

template<typename T >
DataObjectHandle< T >::DataObjectHandle ( )

Definition at line 75 of file DataObjectHandle.h.

template<typename T >
DataObjectHandle< T >::DataObjectHandle ( const DataObjID k,
Gaudi::DataHandle::Mode  a,
IDataHandleHolder o 
)

Definition at line 80 of file DataObjectHandle.h.

82  :
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:45
template<typename T >
DataObjectHandle< T >::DataObjectHandle ( const std::string k,
Gaudi::DataHandle::Mode  a,
IDataHandleHolder o 
)

Definition at line 86 of file DataObjectHandle.h.

88  :
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:45
template<typename T>
virtual DataObjectHandle< T >::~DataObjectHandle ( )
inlinevirtual

Definition at line 38 of file DataObjectHandle.h.

38 {}

Member Function Documentation

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

Check the existence of the object in the transient store.

Definition at line 54 of file DataObjectHandle.h.

54 { return get(false) != NULL; }
template<typename T>
T* DataObjectHandle< T >::get ( )
inline

Retrieve object from transient data store.

Definition at line 43 of file DataObjectHandle.h.

43 { return get(true); }
template<typename T >
T * DataObjectHandle< T >::get ( bool  mustExist)
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 101 of file DataObjectHandle.h.

101  {
102 
103  if (!m_init) {
104  init();
105  }
106 
107  //MsgStream log(m_MS,"DataObjectHandle");
108 
109  DataObject* dataObjectp = NULL;
110 
111  StatusCode sc = m_EDS->retrieveObject(objKey(), dataObjectp);
112 
113  T* returnObject = NULL;
114  if ( LIKELY( sc.isSuccess() ) ){
115 
116  if (UNLIKELY(!m_goodType)){ // Check type compatibility once
117 
118  // DP: can use a gaudi feature?
119  m_goodType = (NULL != dynamic_cast<T*> (dataObjectp));
120  //( typeid(tmp) == typeid(*dataObjectp) ) ;
121 
122  T tmp;
123 
124  const std::string dataType(typeid(tmp).name());
125 
126  if (!m_goodType){
127  std::string errorMsg("The type provided for "+ objKey()
128  + " is " + dataType
129  + " and is different form the one of the object in the store.");
130  //log << MSG::ERROR << errorMsg << endmsg;
131  throw GaudiException (errorMsg,"Wrong DataObjectType",StatusCode::FAILURE);
132  }
133  else{
134  //log << MSG::DEBUG << "The data type (" << dataType
135  // << ") specified for the handle of " << dataProductName()
136  // << " is the same of the object in the store. "
137  // << "From now on the result of a static_cast will be returned." << endmsg;
138  }
139  }
140 
141  if (LIKELY(m_goodType)) { // From the second read on, this is safe
142  returnObject = static_cast<T*> (dataObjectp);
143  }
144 
145  }
146  else if(mustExist){ // Problems in getting from the store
147  throw GaudiException("Cannot retrieve " + objKey() +
148  " from transient store.",
149  m_owner != 0 ? owner()->name() : "no owner",
151  }
152 
153  // setRead();
154  return returnObject;
155 }
Define general base for Gaudi exception.
virtual const std::string & objKey() const
Definition: DataHandle.h:52
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
SmartIF< IDataProviderSvc > m_EDS
#define UNLIKELY(x)
Definition: Kernel.h:126
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IDataHandleHolder * m_owner
Definition: DataHandle.h:64
#define LIKELY(x)
Definition: Kernel.h:125
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:45
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
template<typename T>
T* DataObjectHandle< T >::getIfExists ( )
inline

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

Definition at line 49 of file DataObjectHandle.h.

49 { 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 173 of file DataObjectHandle.h.

173  {
174 
175  //this process needs to be locking for multi-threaded applications
176  //lock(); --> done in caller
177 
178  T* obj = get(false);
179 
180  //object exists, we are done
181  if(obj != NULL){
182 
183  //unlock();
184  return obj;
185  }
186 
187  //MsgStream log(m_MS,"DataObjectHandle");
188  //log << MSG::DEBUG << "Object " << objKey() << " does not exist, creating it" << endmsg;
189 
190  //create it
191  obj = new T();
192  put(obj);
193 
194  //unlock();
195  return obj;
196 }
void put(T *object)
Register object in transient store.
template<typename T>
void DataObjectHandle< T >::put ( T *  object)

Register object in transient store.

Definition at line 159 of file DataObjectHandle.h.

159  {
160 
161  if (!m_init) {
162  init();
163  }
164 
165  StatusCode sc = m_EDS->registerObject(objKey(), objectp);
166  sc.ignore();
167  // if ( LIKELY( sc.isSuccess() ) )
168  // setWritten();
169 }
virtual const std::string & objKey() const
Definition: DataHandle.h:52
SmartIF< IDataProviderSvc > m_EDS
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void ignore() const
Definition: StatusCode.h:106
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)=0
Register object with the data store.

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