ATLAS Offline Software
DataHandleBase.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2017 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
13 #include "SGTools/DataHandleBase.h"
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),
43  m_useItr(rhs.m_useItr)
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 
75  IResetable(),
76  m_itr(),
77  m_itrEnd(),
78  m_proxy(proxy),
79  //m_ptr(0),
80  m_useItr(false)
81 {
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 
122 StatusCode
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 
155 StatusCode
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 
174 StatusCode
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 
185 const std::string&
187 {
188  if (m_itr == m_itrEnd) {
189  return m_proxy->name();
190  } else {
191  return m_itr->first;
192  }
193 }
194 
195 bool
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
206 bool
208 {
209  return (0 != m_proxy);
210 }
211 
213 // Non-const methods:
215 
216 StatusCode
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 
234 StatusCode
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 
DataHandleBase::operator=
DataHandleBase & operator=(const DataHandleBase &rhs)
Assignment operator:
Definition: DataHandleBase.cxx:53
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
DataHandleBase.h
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
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
SG::DataProxy::unbindHandle
void unbindHandle(IResetable *ir)
Definition: DataProxy.cxx:293
DataHandleBase::m_itrEnd
SG::ConstProxyIterator m_itrEnd
iterator pointing at the end of the range of proxies
Definition: DataHandleBase.h:112
DataHandleBase::isConst
bool isConst() const
Definition: DataHandleBase.cxx:196
IResetable
a resetable object (e.g. a SG DataHandle)
Definition: IResetable.h:15
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
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DataHandleBase::DataHandleBase
DataHandleBase()
Default constructor:
Definition: DataHandleBase.cxx:27
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
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::~DataHandleBase
virtual ~DataHandleBase()
Destructor:
Definition: DataHandleBase.cxx:107
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
DataHandleBase::ID_type
std::string ID_type
Definition: DataHandleBase.h:44
SG::ConstProxyIterator
ProxyMap::const_iterator ConstProxyIterator
Definition: ProxyMap.h:28
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37