DataObjectHandle< T > Class Template Reference

#include </tmp/marcocle/lhcb-release/1122/GAUDI/GAUDI_v27r0/InstallArea/x86_64-slc6-gcc49-opt/include/GaudiKernel/Algorithm.h>

Inheritance diagram for DataObjectHandle< T >:
Collaboration diagram for DataObjectHandle< T >:

Public Member Functions

 DataObjectHandle ()
 
 DataObjectHandle (DataObjectDescriptor &descriptor, IAlgorithm *fatherAlg)
 Initialises mother class. More...
 
 DataObjectHandle (DataObjectDescriptor &descriptor, IAlgTool *fatherAlg)
 Initialises mother class. More...
 
StatusCode initialize ()
 Initialize. More...
 
StatusCode reinitialize ()
 Reinitialize. More...
 
StatusCode finalize ()
 Finalize. More...
 
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...
 
 DataObjectHandle ()
 
 DataObjectHandle (DataObjectDescriptor &descriptor, IAlgorithm *fatherAlg)
 Initialises mother class. More...
 
 DataObjectHandle (DataObjectDescriptor &descriptor, IAlgTool *fatherAlg)
 Initialises mother class. More...
 
StatusCode initialize ()
 Initialize. More...
 
StatusCode reinitialize ()
 Reinitialize. More...
 
StatusCode finalize ()
 Finalize. More...
 
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 MinimalDataObjectHandle
 MinimalDataObjectHandle ()
 
 MinimalDataObjectHandle (DataObjectDescriptor &descriptor)
 Constructor initialises the members and registers products in SchedSvc the MinimalDataObjectHandle takes over the ownership of the descriptor. More...
 
virtual ~MinimalDataObjectHandle ()
 
bool isOptional () const
 Check if the data object declared is optional for the algorithm. More...
 
void setOptional (bool optional=true)
 
size_t dataProductIndex () const
 Return the product index. More...
 
const std::string & dataProductName () const
 Return the product name. More...
 
const std::vector< std::string > & alternativeDataProductNames () const
 
StatusCode setDataProductName (const std::string &address)
 Update address of data product if possible -> not if was written. More...
 
StatusCode setAlternativeDataProductNames (const std::vector< std::string > &alternativeAddresses)
 
StatusCode setDataProductNames (const std::vector< std::string > &addresses)
 
AccessType accessType () const
 Access type. More...
 
bool wasRead () const
 Check if operation was performed. More...
 
bool wasWritten () const
 Check if operation was performed. More...
 
bool isValid () const
 
bool initialized () const
 
void lock ()
 
void unlock ()
 
 MinimalDataObjectHandle ()
 
 MinimalDataObjectHandle (DataObjectDescriptor &descriptor)
 Constructor initialises the members and registers products in SchedSvc the MinimalDataObjectHandle takes over the ownership of the descriptor. More...
 
virtual ~MinimalDataObjectHandle ()
 
bool isOptional () const
 Check if the data object declared is optional for the algorithm. More...
 
void setOptional (bool optional=true)
 
size_t dataProductIndex () const
 Return the product index. More...
 
const std::string & dataProductName () const
 Return the product name. More...
 
const std::vector< std::string > & alternativeDataProductNames () const
 
StatusCode setDataProductName (const std::string &address)
 Update address of data product if possible -> not if was written. More...
 
StatusCode setAlternativeDataProductNames (const std::vector< std::string > &alternativeAddresses)
 
StatusCode setDataProductNames (const std::vector< std::string > &addresses)
 
AccessType accessType () const
 Access type. More...
 
bool wasRead () const
 Check if operation was performed. More...
 
bool wasWritten () const
 Check if operation was performed. More...
 
bool isValid () const
 
bool initialized () const
 
void lock ()
 
void unlock ()
 

Private Member Functions

void setOwner (IAlgorithm *fatherAlg)
 
void setOwner (IAlgTool *fatherTool)
 
T * get (bool mustExist)
 Try to retrieve from the transient store. More...
 
 DataObjectHandle (const DataObjectHandle &)
 
DataObjectHandleoperator= (const DataObjectHandle &)
 
void setOwner (IAlgorithm *fatherAlg)
 
void setOwner (IAlgTool *fatherTool)
 
T * get (bool mustExist)
 
 DataObjectHandle (const DataObjectHandle &)
 
DataObjectHandleoperator= (const DataObjectHandle &)
 

Private Attributes

SmartIF< IDataProviderSvcm_EDS
 
SmartIF< IMessageSvcm_MS
 
IAlgorithmm_fatherAlg
 
IAlgToolm_fatherTool
 
bool m_goodType
 

Friends

class Algorithm
 
class AlgTool
 

Additional Inherited Members

- Public Types inherited from MinimalDataObjectHandle
enum  AccessType {
  READ, WRITE, UPDATE, READ,
  WRITE, UPDATE
}
 The type of the access. More...
 
enum  AccessType {
  READ, WRITE, UPDATE, READ,
  WRITE, UPDATE
}
 The type of the access. More...
 
- Protected Member Functions inherited from MinimalDataObjectHandle
void setRead (bool wasRead=true)
 
void setWritten (bool wasWritten=true)
 
DataObjectDescriptordescriptor ()
 
void setRead (bool wasRead=true)
 
void setWritten (bool wasWritten=true)
 
DataObjectDescriptordescriptor ()
 
- Protected Attributes inherited from MinimalDataObjectHandle
DataObjectDescriptorm_descriptor
 

Detailed Description

template<typename T>
class DataObjectHandle< T >

Definition at line 43 of file Algorithm.h.

Constructor & Destructor Documentation

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

Definition at line 153 of file DataObjectHandle.h.

153  :
154  m_fatherAlg(0),
155  m_fatherTool(0),
156  m_goodType(false){}
IAlgorithm * m_fatherAlg
IAlgTool * m_fatherTool
template<typename T >
DataObjectHandle< T >::DataObjectHandle ( DataObjectDescriptor descriptor,
IAlgorithm fatherAlg 
)

Initialises mother class.

Definition at line 160 of file DataObjectHandle.h.

161  :
162  MinimalDataObjectHandle(descriptor),
163  m_fatherAlg(fatherAlg),
164  m_fatherTool(0),
165  m_goodType(false){}
IAlgorithm * m_fatherAlg
IAlgTool * m_fatherTool
template<typename T >
DataObjectHandle< T >::DataObjectHandle ( DataObjectDescriptor descriptor,
IAlgTool fatherAlg 
)

Initialises mother class.

Definition at line 169 of file DataObjectHandle.h.

170  :
171  MinimalDataObjectHandle(descriptor),
172  m_fatherAlg(0),
173  m_fatherTool(fatherTool),
174  m_goodType(false){}
IAlgorithm * m_fatherAlg
IAlgTool * m_fatherTool
template<typename T>
DataObjectHandle< T >::DataObjectHandle ( const DataObjectHandle< T > &  )
private
template<typename T>
DataObjectHandle< T >::DataObjectHandle ( )
template<typename T>
DataObjectHandle< T >::DataObjectHandle ( DataObjectDescriptor descriptor,
IAlgorithm fatherAlg 
)

Initialises mother class.

template<typename T>
DataObjectHandle< T >::DataObjectHandle ( DataObjectDescriptor descriptor,
IAlgTool fatherAlg 
)

Initialises mother class.

template<typename T>
DataObjectHandle< T >::DataObjectHandle ( const DataObjectHandle< T > &  )
private

Member Function Documentation

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

Check the existence of the object in the transient store.

Definition at line 52 of file DataObjectHandle.h.

52 { return get(false) != NULL; }
template<typename T>
bool DataObjectHandle< T >::exist ( )
inline

Check the existence of the object in the transient store.

Definition at line 52 of file DataObjectHandle.h.

52 { return get(false) != NULL; }
template<typename T >
StatusCode DataObjectHandle< T >::finalize ( )
virtual

Finalize.

Reimplemented from MinimalDataObjectHandle.

Definition at line 146 of file DataObjectHandle.h.

146  {
148 }
virtual StatusCode finalize()
Finalize.
template<typename T>
StatusCode DataObjectHandle< T >::finalize ( )
virtual

Finalize.

Reimplemented from MinimalDataObjectHandle.

template<typename T>
T* DataObjectHandle< T >::get ( )
inline

Retrieve object from transient data store.

Definition at line 41 of file DataObjectHandle.h.

41 { return get(true); }
template<typename T>
T* DataObjectHandle< T >::get ( )
inline

Retrieve object from transient data store.

Definition at line 41 of file DataObjectHandle.h.

41 { 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 186 of file DataObjectHandle.h.

186  {
187 
188  //MsgStream log(m_MS,"DataObjectHandle");
189 
190  DataObject* dataObjectp = NULL;
191 
192  StatusCode sc = m_EDS->retrieveObject(dataProductName(), dataObjectp);
193 
194  //if(sc.isSuccess())
195  // log << MSG::DEBUG << "Using main location " << dataProductName() << " for " << *dataObjectp << endmsg;
196 
197  if(sc.isFailure() && ! m_descriptor->alternativeAddresses().empty()){
198  for(uint i = 0; i < m_descriptor->alternativeAddresses().size() && sc.isFailure(); ++i){
199  sc = m_EDS->retrieveObject(m_descriptor->alternativeAddresses()[i], dataObjectp);
200 
201  //if(sc.isSuccess())
202  // log << MSG::DEBUG << "Using alternative location " << m_descriptor->alternativeAddresses()[i] << " for " << *dataObjectp << endmsg;
203  }
204  }
205 
206  T* returnObject = NULL;
207  if ( LIKELY( sc.isSuccess() ) ){
208 
209  if (UNLIKELY(!m_goodType)){ // Check type compatibility once
210 
211  // DP: can use a gaudi feature?
212  m_goodType = (NULL != dynamic_cast<T*> (dataObjectp));
213  //( typeid(tmp) == typeid(*dataObjectp) ) ;
214 
215  T tmp;
216 
217  const std::string dataType(typeid(tmp).name());
218 
219  if (!m_goodType){
220  std::string errorMsg("The type provided for "+ dataProductName()
221  + " is " + dataType
222  + " and is different form the one of the object in the store.");
223  //log << MSG::ERROR << errorMsg << endmsg;
224  throw GaudiException (errorMsg,"Wrong DataObjectType",StatusCode::FAILURE);
225  }
226  else{
227  //log << MSG::DEBUG << "The data type (" << dataType
228  // << ") specified for the handle of " << dataProductName()
229  // << " is the same of the object in the store. "
230  // << "From now on the result of a static_cast will be returned." << endmsg;
231  }
232  }
233 
234  if (LIKELY(m_goodType)) { // From the second read on, this is safe
235  returnObject = static_cast<T*> (dataObjectp);
236  }
237 
238  }
239  else if(mustExist){ // Problems in getting from the store
240  throw GaudiException("Cannot retrieve " + dataProductName() + " from transient store.",
241  m_fatherAlg != 0 ? m_fatherAlg->name() : m_fatherTool->name(), StatusCode::FAILURE);
242  }
243 
244  setRead();
245  return returnObject;
246 }
Define general base for Gaudi exception.
SmartIF< IDataProviderSvc > m_EDS
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
IAlgorithm * m_fatherAlg
const std::string & dataProductName() const
Return the product name.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
void setRead(bool wasRead=true)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
DataObjectDescriptor * m_descriptor
#define UNLIKELY(x)
Definition: Kernel.h:126
#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
list i
Definition: ana.py:128
const std::vector< std::string > & alternativeAddresses() const
IAlgTool * m_fatherTool
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 >::get ( bool  mustExist)
private
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 47 of file DataObjectHandle.h.

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

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

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

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

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

Definition at line 259 of file DataObjectHandle.h.

259  {
260 
261  //this process needs to be locking for multi-threaded applications
262  //lock(); --> done in caller
263 
264  T* obj = get(false);
265 
266  //object exists, we are done
267  if(obj != NULL){
268 
269  //unlock();
270  return obj;
271  }
272 
273  //MsgStream log(m_MS,"DataObjectHandle");
274  //log << MSG::DEBUG << "Object " << dataProductName() << " does not exist, creating it" << endmsg;
275 
276  //create it
277  obj = new T();
278  put(obj);
279 
280  //unlock();
281  return obj;
282 }
void put(T *object)
Register object in transient store.
template<typename T >
StatusCode DataObjectHandle< T >::initialize ( )
virtual

Initialize.

Reimplemented from MinimalDataObjectHandle.

Definition at line 91 of file DataObjectHandle.h.

91  {
92 
93  // GCCXML cannot understand c++11 yet, NULL used.
94 
96 
97  if(m_fatherAlg == 0 && m_fatherTool == 0){
98  return StatusCode::FAILURE;
99  }
100 
101  if (m_fatherAlg != 0) {
102  // Fetch the event Data Service from the algorithm
103  Algorithm* algorithm = dynamic_cast<Algorithm*>(m_fatherAlg);
104  if (LIKELY(algorithm != NULL)) {
105  m_EDS = algorithm->evtSvc();
106  m_MS = algorithm->msgSvc();
107  } else
108  throw GaudiException(
109  "Cannot cast " + m_fatherAlg->name() + " to Algorithm.",
110  "Invalid Cast", StatusCode::FAILURE);
111  }
112 
113  if (m_fatherTool != 0) {
114  // Fetch the event Data Service from the algorithm
115  AlgTool* tool = dynamic_cast<AlgTool*>(m_fatherTool);
116  if (LIKELY(tool != NULL)) {
117  m_EDS = tool->evtSvc();
118  m_MS = tool->msgSvc();
119  } else
120  throw GaudiException(
121  "Cannot cast " + m_fatherTool->name() + " to AlgTool.",
122  "Invalid Cast", StatusCode::FAILURE);
123  }
124 
125  m_goodType = false;
126 
127  return StatusCode::SUCCESS;
128 }
Define general base for Gaudi exception.
SmartIF< IDataProviderSvc > m_EDS
IAlgorithm * m_fatherAlg
virtual StatusCode initialize()
Initialize.
IMessageSvc * msgSvc() const
Retrieve pointer to message service.
Definition: AlgTool.cpp:92
IDataProviderSvc * evtSvc() const
accessor to event service service
Definition: AlgTool.cpp:101
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:77
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition: Algorithm.h:286
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:44
void ignore() const
Definition: StatusCode.h:108
#define LIKELY(x)
Definition: Kernel.h:125
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Algorithm.cpp:1001
SmartIF< IMessageSvc > m_MS
IAlgTool * m_fatherTool
template<typename T>
StatusCode DataObjectHandle< T >::initialize ( )
virtual

Initialize.

Reimplemented from MinimalDataObjectHandle.

template<typename T>
DataObjectHandle& DataObjectHandle< T >::operator= ( const DataObjectHandle< T > &  )
private
template<typename T>
DataObjectHandle& DataObjectHandle< T >::operator= ( const DataObjectHandle< T > &  )
private
template<typename T>
void DataObjectHandle< T >::put ( T *  object)

Register object in transient store.

Definition at line 250 of file DataObjectHandle.h.

250  {
251 
253  if ( LIKELY( sc.isSuccess() ) )
254  setWritten();
255 }
SmartIF< IDataProviderSvc > m_EDS
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
const std::string & dataProductName() const
Return the product name.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void setWritten(bool wasWritten=true)
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)=0
Register object with the data store.
#define LIKELY(x)
Definition: Kernel.h:125
template<typename T>
void DataObjectHandle< T >::put ( T *  object)

Register object in transient store.

template<typename T >
StatusCode DataObjectHandle< T >::reinitialize ( )
virtual

Reinitialize.

Reimplemented from MinimalDataObjectHandle.

Definition at line 132 of file DataObjectHandle.h.

132  {
133 
135 
136  if(sc.isFailure())
137  return sc;
138 
139  m_goodType = false;
140 
141  return StatusCode::SUCCESS;
142 }
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual StatusCode reinitialize()
Reinitialize -> may be overwritten in derived class.
template<typename T>
StatusCode DataObjectHandle< T >::reinitialize ( )
virtual

Reinitialize.

Reimplemented from MinimalDataObjectHandle.

template<typename T>
void DataObjectHandle< T >::setOwner ( IAlgorithm fatherAlg)
inlineprivate

Definition at line 65 of file DataObjectHandle.h.

65  {
66  m_fatherAlg = fatherAlg;
67  m_fatherTool = 0;
68  }
IAlgorithm * m_fatherAlg
IAlgTool * m_fatherTool
template<typename T>
void DataObjectHandle< T >::setOwner ( IAlgorithm fatherAlg)
inlineprivate

Definition at line 65 of file DataObjectHandle.h.

65  {
66  m_fatherAlg = fatherAlg;
67  m_fatherTool = 0;
68  }
IAlgorithm * m_fatherAlg
IAlgTool * m_fatherTool
template<typename T>
void DataObjectHandle< T >::setOwner ( IAlgTool fatherTool)
inlineprivate

Definition at line 70 of file DataObjectHandle.h.

70  {
71  m_fatherAlg = 0;
72  m_fatherTool = fatherTool;
73  }
IAlgorithm * m_fatherAlg
IAlgTool * m_fatherTool
template<typename T>
void DataObjectHandle< T >::setOwner ( IAlgTool fatherTool)
inlineprivate

Definition at line 70 of file DataObjectHandle.h.

70  {
71  m_fatherAlg = 0;
72  m_fatherTool = fatherTool;
73  }
IAlgorithm * m_fatherAlg
IAlgTool * m_fatherTool

Friends And Related Function Documentation

template<typename T>
Algorithm
friend

Definition at line 15 of file DataObjectHandle.h.

template<typename T>
AlgTool
friend

Definition at line 16 of file DataObjectHandle.h.

Member Data Documentation

template<typename T>
SmartIF< IDataProviderSvc > DataObjectHandle< T >::m_EDS
private

Definition at line 79 of file DataObjectHandle.h.

template<typename T>
IAlgorithm * DataObjectHandle< T >::m_fatherAlg
private

Definition at line 81 of file DataObjectHandle.h.

template<typename T>
IAlgTool * DataObjectHandle< T >::m_fatherTool
private

Definition at line 82 of file DataObjectHandle.h.

template<typename T>
bool DataObjectHandle< T >::m_goodType
private

Definition at line 83 of file DataObjectHandle.h.

template<typename T>
SmartIF< IMessageSvc > DataObjectHandle< T >::m_MS
private

Definition at line 80 of file DataObjectHandle.h.


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