ATLAS Offline Software
Public Types | Public Member Functions | List of all members
DataHandle< DATA > Class Template Reference

an iterator over instances of a given type in StoreGateSvc. It d-casts and caches locally the pointed-at object, to speed-up subsequent accesses. It can be reset by the store for asynchronous updates (IOVSvc) More...

#include <DataHandle.h>

Inheritance diagram for DataHandle< DATA >:
Collaboration diagram for DataHandle< DATA >:

Public Types

using iterator_category = std::forward_iterator_tag
 
using value_type = DATA
 
using difference_type = std::ptrdiff_t
 
using pointer = value_type *
 
using reference = value_type &
 
typedef pointer pointer_type
 
using const_pointer_type = const DATA *
 
using reference_type = reference
 
using const_reference_type = const DATA &
 
typedef DataHandleBase::ID_type ID_type
 

Public Member Functions

virtual void finalReset ()
 optional special action on final reset call (e.g. in caller destructor) More...
 
constructors and assignment
 DataHandle ()
 
 DataHandle (const DataHandle &h)
 
DataHandleoperator= (const DataHandle &h)
 
DataHandleoperator= (const DATA &d)
 
virtual ~DataHandle ()
 unbind from the proxy before we go More...
 
validity checks
bool isValid () const
 RETRIEVES the DO to check it is valid and unlocked. More...
 
bool operator! () const
 DEPRECATED for statements like: if (!DataHandle<XXX>) {...}. More...
 
 operator int () const
 DEPRECATED for statements like: if (DataHandle<XXX>) {...}. More...
 
iterator interface
const DataHandleoperator++ () const
 prefix More...
 
DataHandle operator++ (int) const
 postfix More...
 
const_pointer_type operator-> () const
 
const_reference_type operator* () const
 
access to the underlying ptr
 operator const_pointer_type () const
 often ambiguous More...
 
const_pointer_type cptr () const
 safer explicit ptr accessor More...
 
virtual void reset (bool) override
 reset pointer More...
 

validity checks

bool isConst () const
 
bool isInitialized () const
 weaker test but it does not touch the disk! More...
 
bool isSet () const
 
const std::string & key () const
 Get the key string with which the current object was stored. More...
 
StatusCode setState (SG::DataProxy *proxy) const
 
StatusCode setState (IProxyDict *store, const ID_type &name) const
 
StatusCode setState (SG::ConstProxyIterator &itr1, const SG::ConstProxyIterator &itr2) const
 
StatusCode setState (SG::DataProxy *proxy)
 
StatusCode setState (IProxyDict *store, const ID_type &name)
 
ID_type ID () const
 get the data object key (ID) More...
 
SG::ConstProxyIterator m_itr
 iterator pointing at the beginning of the range of proxies More...
 
SG::ConstProxyIterator m_itrEnd
 iterator pointing at the end of the range of proxies More...
 
SG::DataProxym_proxy
 the proxy holding the object we are bound to More...
 
bool m_useItr
 use the proxy-iterator or just the proxy ? More...
 

other constructors and methods for SG internal use

const_pointer_type m_ptr
 
 DataHandle (SG::DataProxy *proxy)
 
 DataHandle (const SG::ConstProxyIterator &itr1, const SG::ConstProxyIterator &itr2)
 
virtual CLID clid () const override
 the CLID of the object we are bound to More...
 
bool operator==ATLAS_NOT_THREAD_SAFE (const DataHandle< DATA > &h1, const DataHandle< DATA > &h2)
 
bool operator!=ATLAS_NOT_THREAD_SAFE (const DataHandle< DATA > &h1, const DataHandle< DATA > &h2)
 
const_pointer_type dataPointer () const
 

Detailed Description

template<typename DATA>
class DataHandle< DATA >

an iterator over instances of a given type in StoreGateSvc. It d-casts and caches locally the pointed-at object, to speed-up subsequent accesses. It can be reset by the store for asynchronous updates (IOVSvc)

Holds a reference count on the proxy to which it's currently pointing. Note: one may think that we should hold reference counts for the entire range which the DataHandle references (if it is a range). The problem with this is that the range may change underneath us. For example, if someone does a SG record, then a new element may appear within the range. So we only hold the refcount for the object to which we're currently pointing.

Parameters
DATAthe data object type
Author
ATLAS Collaboration

Definition at line 40 of file DataHandle.h.

Member Typedef Documentation

◆ const_pointer_type

template<typename DATA >
using DataHandle< DATA >::const_pointer_type = const DATA*

Definition at line 51 of file DataHandle.h.

◆ const_reference_type

template<typename DATA >
using DataHandle< DATA >::const_reference_type = const DATA&

Definition at line 53 of file DataHandle.h.

◆ difference_type

template<typename DATA >
using DataHandle< DATA >::difference_type = std::ptrdiff_t

Definition at line 46 of file DataHandle.h.

◆ ID_type

template<typename DATA >
typedef DataHandleBase::ID_type DataHandle< DATA >::ID_type

Definition at line 55 of file DataHandle.h.

◆ iterator_category

template<typename DATA >
using DataHandle< DATA >::iterator_category = std::forward_iterator_tag

Definition at line 44 of file DataHandle.h.

◆ pointer

template<typename DATA >
using DataHandle< DATA >::pointer = value_type*

Definition at line 47 of file DataHandle.h.

◆ pointer_type

template<typename DATA >
typedef pointer DataHandle< DATA >::pointer_type

Definition at line 50 of file DataHandle.h.

◆ reference

template<typename DATA >
using DataHandle< DATA >::reference = value_type&

Definition at line 48 of file DataHandle.h.

◆ reference_type

template<typename DATA >
using DataHandle< DATA >::reference_type = reference

Definition at line 52 of file DataHandle.h.

◆ value_type

template<typename DATA >
using DataHandle< DATA >::value_type = DATA

Definition at line 45 of file DataHandle.h.

Constructor & Destructor Documentation

◆ DataHandle() [1/4]

template<typename DATA >
DataHandle< DATA >::DataHandle ( )

◆ DataHandle() [2/4]

template<typename DATA >
DataHandle< DATA >::DataHandle ( const DataHandle< DATA > &  h)

◆ ~DataHandle()

template<typename DATA >
virtual DataHandle< DATA >::~DataHandle ( )
virtual

unbind from the proxy before we go

◆ DataHandle() [3/4]

template<typename DATA >
DataHandle< DATA >::DataHandle ( SG::DataProxy proxy)

◆ DataHandle() [4/4]

template<typename DATA >
DataHandle< DATA >::DataHandle ( const SG::ConstProxyIterator itr1,
const SG::ConstProxyIterator itr2 
)

Member Function Documentation

◆ clid()

template<typename DATA >
virtual CLID DataHandle< DATA >::clid ( ) const
inlineoverridevirtual

the CLID of the object we are bound to

Implements DataHandleBase.

Definition at line 119 of file DataHandle.h.

119 { return ClassID_traits<DATA>::ID(); }

◆ cptr()

template<typename DATA >
const_pointer_type DataHandle< DATA >::cptr ( ) const

safer explicit ptr accessor

◆ dataPointer()

template<typename DATA >
const_pointer_type DataHandle< DATA >::dataPointer ( ) const
private

◆ finalReset()

virtual void IResetable::finalReset ( )
inlinevirtualinherited

optional special action on final reset call (e.g. in caller destructor)

Reimplemented in SG::VarHandleBase.

Definition at line 33 of file IResetable.h.

33 {};

◆ ID()

ID_type DataHandleBase::ID ( ) const
inlineinherited

get the data object key (ID)

Definition at line 94 of file DataHandleBase.h.

94 { return isInitialized() ? m_proxy->name() : "NONE"; }

◆ isConst()

bool DataHandleBase::isConst ( ) const
inherited

Definition at line 196 of file DataHandleBase.cxx.

197 {
198  return 0 != m_proxy
199  ? m_proxy->isConst()
200  : false;
201 }

◆ isInitialized()

bool DataHandleBase::isInitialized ( ) const
inherited

weaker test but it does not touch the disk!

Definition at line 207 of file DataHandleBase.cxx.

208 {
209  return (0 != m_proxy);
210 }

◆ isSet()

bool DataHandleBase::isSet ( ) const
inlinevirtualinherited

Implements IResetable.

Definition at line 77 of file DataHandleBase.h.

77 { return isInitialized(); }

◆ isValid()

template<typename DATA >
bool DataHandle< DATA >::isValid ( ) const

RETRIEVES the DO to check it is valid and unlocked.

◆ key()

const std::string & DataHandleBase::key ( ) const
virtualinherited

Get the key string with which the current object was stored.

Implements IResetable.

Definition at line 186 of file DataHandleBase.cxx.

187 {
188  if (m_itr == m_itrEnd) {
189  return m_proxy->name();
190  } else {
191  return m_itr->first;
192  }
193 }

◆ operator const_pointer_type()

template<typename DATA >
DataHandle< DATA >::operator const_pointer_type ( ) const
inline

often ambiguous

Definition at line 103 of file DataHandle.h.

◆ operator int()

template<typename DATA >
DataHandle< DATA >::operator int ( ) const
inline

DEPRECATED for statements like: if (DataHandle<XXX>) {...}.

Definition at line 88 of file DataHandle.h.

88 { return isValid(); }

◆ operator!()

template<typename DATA >
bool DataHandle< DATA >::operator! ( ) const
inline

DEPRECATED for statements like: if (!DataHandle<XXX>) {...}.

Definition at line 84 of file DataHandle.h.

84 { return !isValid(); }

◆ operator*()

template<typename DATA >
const_reference_type DataHandle< DATA >::operator* ( ) const
inline

Definition at line 98 of file DataHandle.h.

98 { return *cptr(); }

◆ operator++() [1/2]

template<typename DATA >
const DataHandle& DataHandle< DATA >::operator++ ( ) const

prefix

◆ operator++() [2/2]

template<typename DATA >
DataHandle DataHandle< DATA >::operator++ ( int  ) const

postfix

◆ operator->()

template<typename DATA >
const_pointer_type DataHandle< DATA >::operator-> ( ) const
inline

Definition at line 96 of file DataHandle.h.

96 { return cptr(); }

◆ operator=() [1/2]

template<typename DATA >
DataHandle& DataHandle< DATA >::operator= ( const DATA &  d)
inline

Definition at line 62 of file DataHandle.h.

63  {
64  typename DataHandle<DATA>::pointer_type ptr = this->ptr();
65  if (ptr) {
66  *ptr = d;
67  } else {
68  std::cerr << "invalid proxy\n";
69  }
70  return *this;
71  }

◆ operator=() [2/2]

template<typename DATA >
DataHandle& DataHandle< DATA >::operator= ( const DataHandle< DATA > &  h)

◆ reset()

template<typename DATA >
virtual void DataHandle< DATA >::reset ( bool  )
inlineoverridevirtual

reset pointer

Implements IResetable.

Definition at line 107 of file DataHandle.h.

◆ setState() [1/5]

StatusCode DataHandleBase::setState ( IProxyDict store,
const ID_type name 
)
inherited

Definition at line 235 of file DataHandleBase.cxx.

236 {
237  if (0 == store) {
238  return StatusCode::FAILURE;
239  }
240  CLID cid = this->clid();
241  SG::DataProxy* proxy = store->proxy(cid, key);
242  return this->setState(proxy);
243 }

◆ setState() [2/5]

StatusCode DataHandleBase::setState ( IProxyDict store,
const ID_type name 
) const
inherited

Definition at line 175 of file DataHandleBase.cxx.

176 {
177  if (0 == store) {
178  return StatusCode::FAILURE;
179  }
180  CLID cid = this->clid();
181  SG::DataProxy* proxy = store->proxy(cid, key);
182  return this->setState(proxy);
183 }

◆ setState() [3/5]

StatusCode DataHandleBase::setState ( SG::ConstProxyIterator itr1,
const SG::ConstProxyIterator itr2 
) const
inherited

Definition at line 123 of file DataHandleBase.cxx.

125 {
126  if (m_proxy) m_proxy->release();
127 
128  m_itr = itr;
129  m_itrEnd = itrEnd;
130  m_useItr = true;
131 
132  // ouch! FIXME ?
133  // we could have a void* m_ptr data member and have a
134  // typeless_dataPointer method using the typeless machinery of
135  // DataProxy+DataBucketBase...
136  const_cast<DataHandleBase*>(this)->reset (false);
137 
138  // scan from itr to itrEnd and set m_itr to the first valid iterator:
139 
140  for (; itr != itrEnd; itr++) {
141  if (itr->second->isValid()) {
142  m_itr = itr;
143  m_proxy = m_itr->second;
144  if (m_proxy) m_proxy->addRef();
145  return StatusCode::SUCCESS;
146  }
147  }
148 
149  m_itr = itrEnd;
150  m_proxy = 0;
151 
152  return StatusCode::FAILURE;
153 }

◆ setState() [4/5]

StatusCode DataHandleBase::setState ( SG::DataProxy proxy)
inherited

Definition at line 217 of file DataHandleBase.cxx.

218 {
219  if (0 == proxy || !proxy->isValid() || proxy->isConst()) {
220  return StatusCode::FAILURE;
221  }
222 
223  if (m_proxy != proxy) {
224  if (m_proxy) m_proxy->release();
225  m_proxy = proxy;
226  m_proxy->addRef();
227  }
228 
229  m_useItr = false;
230  this->reset (false);
231  return StatusCode::SUCCESS;
232 }

◆ setState() [5/5]

StatusCode DataHandleBase::setState ( SG::DataProxy proxy) const
inherited

Definition at line 156 of file DataHandleBase.cxx.

157 {
158  if (0 == proxy || !proxy->isValid()) {
159  return StatusCode::FAILURE;
160  }
161 
162  if (m_proxy != proxy) {
163  if (m_proxy) m_proxy->release();
164  m_proxy = proxy;
165  m_proxy->addRef();
166  }
167 
168  m_useItr = false;
169  const_cast<DataHandleBase*>(this)->reset (false);
170 
171  return StatusCode::SUCCESS;
172 }

Friends And Related Function Documentation

◆ operator!=ATLAS_NOT_THREAD_SAFE

template<typename DATA >
bool operator!=ATLAS_NOT_THREAD_SAFE ( const DataHandle< DATA > &  h1,
const DataHandle< DATA > &  h2 
)
friend

Definition at line 129 of file DataHandle.h.

131  {
132  return h1.m_proxy != h2.m_proxy;
133  }

◆ operator==ATLAS_NOT_THREAD_SAFE

template<typename DATA >
bool operator==ATLAS_NOT_THREAD_SAFE ( const DataHandle< DATA > &  h1,
const DataHandle< DATA > &  h2 
)
friend

Definition at line 122 of file DataHandle.h.

124  {
125  return h1.m_proxy == h2.m_proxy;
126  }

Member Data Documentation

◆ m_itr

SG::ConstProxyIterator DataHandleBase::m_itr
mutableprotectedinherited

iterator pointing at the beginning of the range of proxies

Definition at line 109 of file DataHandleBase.h.

◆ m_itrEnd

SG::ConstProxyIterator DataHandleBase::m_itrEnd
mutableprotectedinherited

iterator pointing at the end of the range of proxies

Definition at line 112 of file DataHandleBase.h.

◆ m_proxy

SG::DataProxy* DataHandleBase::m_proxy
mutableprotectedinherited

the proxy holding the object we are bound to

Definition at line 115 of file DataHandleBase.h.

◆ m_ptr

template<typename DATA >
const_pointer_type DataHandle< DATA >::m_ptr
mutableprivate

Definition at line 139 of file DataHandle.h.

◆ m_useItr

bool DataHandleBase::m_useItr
mutableprotectedinherited

use the proxy-iterator or just the proxy ?

Definition at line 118 of file DataHandleBase.h.


The documentation for this class was generated from the following file:
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
DataHandleBase
an iterator over instances of a given type in an IProxyDict (such as StoreGateSvc)....
Definition: DataHandleBase.h:38
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
SG::DataProxy::isConst
bool isConst() const
Check if it is a const object.
DataHandleBase::clid
virtual CLID clid() const =0
the CLID of the object we are bound to
DataHandleBase::m_useItr
bool m_useItr
use the proxy-iterator or just the proxy ?
Definition: DataHandleBase.h:118
hist_file_dump.d
d
Definition: hist_file_dump.py:137
DataHandle::cptr
const_pointer_type cptr() const
safer explicit ptr accessor
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
DataHandleBase::m_itrEnd
SG::ConstProxyIterator m_itrEnd
iterator pointing at the end of the range of proxies
Definition: DataHandleBase.h:112
ClassID_traits::ID
static const CLID & ID()
the CLID of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:50
DataHandleBase::key
const std::string & key() const
Get the key string with which the current object was stored.
Definition: DataHandleBase.cxx:186
DataHandleBase::setState
StatusCode setState(SG::DataProxy *proxy) const
Definition: DataHandleBase.cxx:156
DataHandle::isValid
bool isValid() const
RETRIEVES the DO to check it is valid and unlocked.
DataHandleBase::m_itr
SG::ConstProxyIterator m_itr
iterator pointing at the beginning of the range of proxies
Definition: DataHandleBase.h:109
DataHandleBase::m_proxy
SG::DataProxy * m_proxy
the proxy holding the object we are bound to
Definition: DataHandleBase.h:115
DataHandle::pointer_type
pointer pointer_type
Definition: DataHandle.h:50
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
SG::DataProxy::release
virtual unsigned long release() override final
release reference to object
Definition: DataProxy.cxx:320
StoreGateSvc::proxy
virtual SG::DataProxy * proxy(const void *const pTransient) const override final
get proxy for a given data object address in memory
SG::DataProxy::addRef
virtual unsigned long addRef() override final
Add reference to object.
Definition: DataProxy.cxx:313
SG::DataProxy::name
virtual const name_type & name() const override final
Retrieve data object key == string.
DataHandleBase::isInitialized
bool isInitialized() const
weaker test but it does not touch the disk!
Definition: DataHandleBase.cxx:207
IResetable::reset
virtual void reset(bool hard)=0
Clear cached data from this object.
SG::DataProxy
Definition: DataProxy.h:44