ATLAS Offline Software
Loading...
Searching...
No Matches
DataHandleBase.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7// DataHandleBase.cxx
8// Implementation file for class DataHandleBase
9// Author: S.Binet<binet@cern.ch>
11
12// SGTools includes
14
15// STL includes
16
17
18
20// Public methods:
22
23// Constructors
25
28 IResetable(),
29 m_itr(),
30 m_itrEnd(),
31 m_proxy(0),
32 //m_ptr(0),
33 m_useItr(false)
34{}
35
38 IResetable(),
39 m_itr(rhs.m_itr),
40 m_itrEnd(rhs.m_itrEnd),
41 m_proxy(rhs.m_proxy),
42 //m_ptr(rhs.m_ptr),
44{
45 if (m_proxy) {
46 m_proxy->addRef();
47 }
48}
49
50
54{
55 if (this != &rhs) {
56 if (m_proxy) {
57 m_proxy->release();
58 }
59
60 m_itr = rhs.m_itr;
61 m_itrEnd = rhs.m_itrEnd;
62 m_useItr = rhs.m_useItr;
63 m_proxy = rhs.m_proxy;
64 //m_ptr = rhs.m_ptr;
65 if (m_proxy) {
66 m_proxy->addRef();
67 }
68 }
69
70 return *this;
71}
72
77 m_itrEnd(),
78 m_proxy(proxy),
79 //m_ptr(0),
80 m_useItr(false)
82 if (m_proxy) {
83 m_proxy->addRef();
84 }
85}
86
88 const SG::ConstProxyIterator& itrEnd) :
89 IResetable(),
90 m_itr(itr),
91 m_itrEnd(itrEnd),
92 m_proxy(0),
93 //m_ptr(0),
94 m_useItr(true)
95{
96 if (m_itr != m_itrEnd) {
97 m_proxy = m_itr->second;
98 }
99
100 if (m_proxy) {
101 m_proxy->addRef();
102 }
103}
104
105
108{
109 if (m_proxy != 0) {
110 m_proxy->unbindHandle(this);
111 m_proxy->release();
112 }
113}
114
115// Destructor
117
119// Const methods:
121
122StatusCode
124 const SG::ConstProxyIterator &itrEnd) const
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}
154
155StatusCode
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}
173
174StatusCode
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}
184
185const std::string&
187{
188 if (m_itr == m_itrEnd) {
189 return m_proxy->name();
190 } else {
191 return m_itr->first;
192 }
193}
194
195bool
197{
198 return 0 != m_proxy
199 ? m_proxy->isConst()
200 : false;
201}
202
203
204// A weaker test that
205// *does not* retrieve the GaudiObject to check validity if not already done
206bool
208{
209 return (0 != m_proxy);
210}
211
213// Non-const methods:
215
216StatusCode
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}
233
234StatusCode
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}
244
246// Protected methods:
248
249
uint32_t CLID
The Class ID type.
an iterator over instances of a given type in an IProxyDict (such as StoreGateSvc).
std::string ID_type
SG::DataProxy * m_proxy
the proxy holding the object we are bound to
StatusCode setState(SG::DataProxy *proxy) const
DataHandleBase()
Default constructor:
bool m_useItr
use the proxy-iterator or just the proxy ?
bool isConst() const
SG::ConstProxyIterator m_itrEnd
iterator pointing at the end of the range of proxies
bool isInitialized() const
weaker test but it does not touch the disk!
virtual ~DataHandleBase()
Destructor:
virtual const std::string & key() const override
Get the key string with which the current object was stored.
DataHandleBase & operator=(const DataHandleBase &rhs)
Assignment operator:
SG::ConstProxyIterator m_itr
iterator pointing at the beginning of the range of proxies
virtual CLID clid() const =0
the CLID of the object we are bound to
a resetable object (e.g.
Definition IResetable.h:15
virtual void reset(bool hard)=0
Clear cached data from this object.
virtual SG::DataProxy * proxy(const void *const pTransient) const override
ProxyMap::const_iterator ConstProxyIterator
Definition ProxyMap.h:24