ATLAS Offline Software
DataHandle.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /*
4  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5 */
6 
10 #ifndef STOREGATE_DATAHANDLE_H
11 #define STOREGATE_DATAHANDLE_H
12 
16 #include "SGTools/ProxyMap.h"
17 #include "SGTools/DataProxy.h"
18 #include "SGTools/DataProxy_cast.h"
19 #include "SGTools/DataHandleBase.h"
21 #include <iterator>
22 #include <iostream>
23 
40 template <typename DATA>
42  public DataHandleBase
43 {
44 public:
45  using iterator_category = std::forward_iterator_tag;
46  using value_type = DATA;
47  using difference_type = std::ptrdiff_t;
48  using pointer = value_type*;
50 
51  typedef pointer pointer_type; // `using' here gives cppcheck false positives
52  using const_pointer_type = const DATA*;
54  using const_reference_type = const DATA&;
55 
57 
59 
63  DataHandle& operator= (const DATA& d)
64  {
65  typename DataHandle<DATA>::pointer_type ptr = m_ptr;
66  if (ptr) {
67  *ptr = d;
68  } else {
69  std::cerr << "invalid proxy\n";
70  }
71  return *this;
72  }
73 
74  virtual ~DataHandle();
75 
76 
78 
79  bool isValid() const;
80 
81  // FIXME op! is to keep backward compatibility with Gaudi
82  // FIXME similar to checking the SmartDataPtr
83  // FIXME dangerous stuff: remove!
85  bool operator !() const { return !isValid(); }
86 
87  //FIXME VERY dangerous stuff: remove!
89  operator int() const { return isValid(); }
91 
93 
94  const DataHandle& operator++ () const;
95  DataHandle operator++ (int) const;
96 
97  const_pointer_type operator->() const { return cptr(); }
98 
99  const_reference_type operator*() const { return *cptr(); }
101 
103 
104  operator const_pointer_type() const { return cptr(); }
105 
107 
108  virtual void reset (bool /*hard*/) override { m_ptr = 0; }
109 
110 
112 
115  const SG::ConstProxyIterator& itr2);
116 
118 
120  virtual CLID clid() const override { return ClassID_traits<DATA>::ID(); }
121 
122  friend
123  bool operator== ATLAS_NOT_THREAD_SAFE (const DataHandle<DATA>& h1,
124  const DataHandle<DATA>& h2)
125  {
126  return h1.m_proxy == h2.m_proxy;
127  }
128 
129  friend
130  bool operator!= ATLAS_NOT_THREAD_SAFE (const DataHandle<DATA>& h1,
131  const DataHandle<DATA>& h2)
132  {
133  return h1.m_proxy != h2.m_proxy;
134  }
135 
136 private:
137 
138  // OK since DataHandle should only be used locally, not shared between threads.
139  // Eventually we'd like to deprecate DataHandle anyway.
142 
143 
144 };
145 
146 #include "StoreGate/DataHandle.icc"
147 
148 /* FIXME LEGACY - No dependency on ActiveStoreSvc here, but a number of Muon AtlasEvent packages are
149  getting the include through this one!!!! */
150 
152 
153 #endif // STOREGATE_DATAHANDLE_H
154 
155 
156 
157 
158 
159 
160 
161 
162 
163 
164 
DataHandleBase::operator=
DataHandleBase & operator=(const DataHandleBase &rhs)
Assignment operator:
Definition: DataHandleBase.cxx:53
DataHandle::ID_type
DataHandleBase::ID_type ID_type
Definition: DataHandle.h:56
ActiveStoreSvc.h
DataHandle.icc
DataHandle::DataHandle
DataHandle(const DataHandle &h)
DataHandleBase
an iterator over instances of a given type in an IProxyDict (such as StoreGateSvc)....
Definition: DataHandleBase.h:38
DataHandleBase.h
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
DataHandle::reset
virtual void reset(bool) override
reset pointer
Definition: DataHandle.h:108
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition: checker_macros.h:212
DataHandle::m_ptr
const_pointer_type m_ptr
Definition: DataHandle.h:140
hist_file_dump.d
d
Definition: hist_file_dump.py:143
DataHandle::cptr
const_pointer_type cptr() const
safer explicit ptr accessor
DataHandle< StrawDxContainer >::const_reference_type
const StrawDxContainer & const_reference_type
Definition: DataHandle.h:54
DataHandle< StrawDxContainer >::const_pointer_type
const StrawDxContainer * const_pointer_type
Definition: DataHandle.h:52
DataHandle< StrawDxContainer >::difference_type
std::ptrdiff_t difference_type
Definition: DataHandle.h:47
reference
Definition: hcg.cxx:437
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:812
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
DataHandle< StrawDxContainer >::pointer
value_type * pointer
Definition: DataHandle.h:48
DataHandle::operator->
const_pointer_type operator->() const
Definition: DataHandle.h:97
DataHandle::DataHandle
DataHandle(SG::DataProxy *proxy)
ProxyMap.h
DataBucket.h
DataHandle< StrawDxContainer >::iterator_category
std::forward_iterator_tag iterator_category
Definition: DataHandle.h:45
IResetable.h
python.LArMinBiasAlgConfig.int
int
Definition: LArMinBiasAlgConfig.py:59
DataHandle::isValid
bool isValid() const
RETRIEVES the DO to check it is valid and unlocked.
DataHandleBase::m_proxy
SG::DataProxy * m_proxy
the proxy holding the object we are bound to
Definition: DataHandleBase.h:115
DataHandle::DataHandle
DataHandle(const SG::ConstProxyIterator &itr1, const SG::ConstProxyIterator &itr2)
DataHandle::pointer_type
pointer pointer_type
Definition: DataHandle.h:51
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
IProxyDict.h
LVL1TGCTrigger::operator++
TGCHBChip operator++(TGCHBChip &rs, int)
Definition: TGCHighPtBoard.h:28
operator!
const APEvtWeight operator!(const APEvtWeight &a_in)
Definition: APEvtWeight.cxx:212
DataProxy_cast.h
Helpers for retrieving the payload held by a DataProxy.
DataHandle
an iterator over instances of a given type in StoreGateSvc. It d-casts and caches locally the pointed...
Definition: DataHandle.h:43
DataHandle::~DataHandle
virtual ~DataHandle()
unbind from the proxy before we go
h
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:44
DataHandle::DataHandle
DataHandle()
ClassID_traits::ID
static CLID ID()
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:44
DataHandle< StrawDxContainer >::reference_type
reference reference_type
Definition: DataHandle.h:53
checker_macros.h
Define macros for attributes used to control the static checker.
value_type
Definition: EDM_MasterSearch.h:11
SG::DataProxy
Definition: DataProxy.h:45
DataHandleBase::ID_type
std::string ID_type
Definition: DataHandleBase.h:44
DataHandle::operator*
const_reference_type operator*() const
Definition: DataHandle.h:99
SG::ConstProxyIterator
ProxyMap::const_iterator ConstProxyIterator
Definition: ProxyMap.h:28
DataHandle::clid
virtual CLID clid() const override
the CLID of the object we are bound to
Definition: DataHandle.h:120
DataHandle::dataPointer
const_pointer_type dataPointer() const
DataProxy.h