Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
UpdateHandle.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: UpdateHandle.icc 797637 2017-02-17 02:32:11Z ssnyder $
6 /**
7  * @file StoreGate/UpdateHandle.icc
8  * @author S. Binet, P. Calafiura, scott snyder <snyder@bnl.gov>
9  * @date Updated: Feb, 2016
10  * @brief Handle class for modifying an existing object in StoreGate.
11  */
12 
13 #ifndef STOREGATE_SG_UPDATEHANDLE_ICC
14 #define STOREGATE_SG_UPDATEHANDLE_ICC 1
15 
16 
17 #include "StoreGate/exceptions.h"
18 #include "AthenaKernel/ClassID_traits.h"
19 #include <stdexcept>
20 
21 
22 namespace SG {
23 
24 
25 /**
26  * @brief Default constructor.
27  *
28  * The handle will not be usable until a non-blank key is assigned.
29  */
30 template <class T>
31 inline
32 UpdateHandle<T>::UpdateHandle()
33  : VarHandleBase(ClassID_traits<T>::ID(), Gaudi::DataHandle::Reader)
34 {
35 }
36 
37 
38 /**
39  * @brief Constructor specifying the key as a string.
40  * @param sgkey StoreGate key of the referenced object.
41  * @param storename Name of the referenced event store.
42  */
43 template <class T>
44 inline
45 UpdateHandle<T>::UpdateHandle(const std::string& sgkey,
46  const std::string& storename /*= "StoreGateSvc"*/)
47  : VarHandleBase( ClassID_traits<T>::ID(),
48  sgkey, Gaudi::DataHandle::Reader, storename, nullptr )
49 {
50 }
51 
52 
53 /**
54  * @brief Constructor specifying the key as a string, with context.
55  * @param sgkey StoreGate key of the referenced object.
56  * @param ctx The event context.
57  */
58 template <class T>
59 inline
60 UpdateHandle<T>::UpdateHandle(const std::string& sgkey,
61  const EventContext& ctx)
62  : UpdateHandle(sgkey, StoreID::storeName(StoreID::EVENT_STORE), ctx)
63 {
64 }
65 
66 
67 /**
68  * @brief Constructor specifying the key as a string, with context.
69  * @param sgkey StoreGate key of the referenced object.
70  * @param storename Name of the referenced event store.
71  * @param ctx The event context.
72  */
73 template <class T>
74 inline
75 UpdateHandle<T>::UpdateHandle(const std::string& sgkey,
76  const std::string& storename,
77  const EventContext& ctx)
78  : VarHandleBase( ClassID_traits<T>::ID(),
79  sgkey, Gaudi::DataHandle::Reader, storename, &ctx )
80 {
81 }
82 
83 
84 /**
85  * @brief Constructor from an UpdateHandleKey.
86  * @param key The key object holding the clid/key/store.
87  *
88  * This will raise an exception if the StoreGate key is blank,
89  * or if the event store cannot be found.
90  */
91 template <class T>
92 inline
93 UpdateHandle<T>::UpdateHandle (const UpdateHandleKey<T>& key)
94  : VarHandleBase (key, nullptr)
95 {
96 }
97 
98 
99 /**
100  * @brief Constructor from an UpdateHandleKey and an explicit event context.
101  * @param key The key object holding the clid/key.
102  * @param ctx The event context.
103  *
104  * This will raise an exception if the StoreGate key is blank,
105  * or if the event store cannot be found.
106  *
107  * If the default event store has been requested, then the thread-specific
108  * store from the event context will be used.
109  */
110 template <class T>
111 UpdateHandle<T>::UpdateHandle (const UpdateHandleKey<T>& key,
112  const EventContext& ctx)
113  : VarHandleBase (key, &ctx)
114 {
115 }
116 
117 
118 /**
119  * @brief Copy constructor.
120  */
121 template <class T>
122 inline
123 UpdateHandle<T>::UpdateHandle(const UpdateHandle& h)
124  : VarHandleBase(h)
125 {
126 }
127 
128 /**
129  * @brief Move constructor.
130  */
131 template <class T>
132 inline
133 UpdateHandle<T>::UpdateHandle(UpdateHandle&& h)
134  : VarHandleBase(std::move(h))
135 {
136 }
137 
138 
139 /**
140  * @brief Assignment operator.
141  */
142 template <class T>
143 inline
144 UpdateHandle<T>&
145 UpdateHandle<T>::UpdateHandle::operator= (const UpdateHandle& h)
146 {
147  if (this != &h) {
148  this->VarHandleBase::operator=(h);
149  }
150  return *this;
151 }
152 
153 
154 /**
155  * @brief Move operator.
156  */
157 template <class T>
158 inline
159 UpdateHandle<T>&
160 UpdateHandle<T>::UpdateHandle::operator= (UpdateHandle&& h)
161 {
162  if (this != &h) {
163  this->VarHandleBase::operator=(std::move(h));
164  }
165  return *this;
166 }
167 
168 
169 //************************************************************************
170 // Dereference.
171 //
172 
173 
174 /**
175  * @brief Dereference the pointer.
176  * Throws ExcNullReadHandle on failure.
177  *
178  * This will inform Hive that the object has been modified.
179  */
180 template <class T>
181 inline
182 typename UpdateHandle<T>::pointer_type
183 UpdateHandle<T>::operator->()
184 {
185  return checkedPtr();
186 }
187 
188 
189 /**
190  * @brief Dereference the pointer.
191  * Throws ExcNullReadHandle on failure.
192  *
193  * This will inform Hive that the object has been modified.
194  */
195 template <class T>
196 inline
197 typename UpdateHandle<T>::reference_type UpdateHandle<T>::operator*()
198 {
199  return *checkedPtr();
200 }
201 
202 
203 /**
204  * @brief Dereference the pointer.
205  * Returns nullptr on failure.
206  *
207  * This will _not_ inform Hive that the object has been modified.
208  */
209 template <class T>
210 inline
211 typename UpdateHandle<T>::const_pointer_type UpdateHandle<T>::cptr()
212 {
213  return reinterpret_cast<const_pointer_type>(this->typeless_cptr());
214 }
215 
216 
217 /**
218  * @brief Dereference the pointer.
219  * Returns nullptr on failure.
220  *
221  * This will inform Hive that the object has been modified.
222  */
223 template <class T>
224 typename UpdateHandle<T>::pointer_type
225 UpdateHandle<T>::ptr()
226 {
227  pointer_type ptr = reinterpret_cast<pointer_type>(this->typeless_ptr());
228  return ptr;
229 }
230 
231 
232 /**
233  * @brief Return the cached pointer directly; no lookup.
234  */
235 template <class T>
236 inline
237 typename UpdateHandle<T>::pointer_type
238 UpdateHandle<T>::cachedPtr()
239 {
240  return reinterpret_cast<pointer_type>(this->m_ptr);
241 }
242 
243 
244 /**
245  * @brief Can the handle be successfully dereferenced?
246  */
247 template <class T>
248 inline
249 bool UpdateHandle<T>::isValid()
250 {
251  const bool QUIET=true;
252  if (0 != this->typeless_dataPointer(QUIET))
253  return !isConst();
254  return false;
255 }
256 
257 
258 /**
259  * @brief Reset this handle.
260  * @param hard If true, anything depending on the event store is cleared.
261  *
262  * Call reset() from the base class.
263  */
264 template <class T>
265 void UpdateHandle<T>::reset (bool hard)
266 {
267  VarHandleBase::reset (hard);
268 }
269 
270 
271 /**
272  * @brief Helper: dereference the pointer.
273  * Throws ExcNullUpdateHandle on failure.
274  */
275 template <class T>
276 inline
277 typename UpdateHandle<T>::pointer_type
278 UpdateHandle<T>::checkedPtr()
279 {
280  pointer_type p = this->ptr();
281  if (!p)
282  throwExcNullUpdateHandle (clid(), key(), store());
283  return p;
284 }
285 
286 
287 /**
288  * @brief Return an @c UpdateHandle referencing @c key.
289  * @param key The key object holding the clid/key/store.
290  *
291  * This will raise an exception if the StoreGate key is blank,
292  * or if the event store cannot be found.
293  */
294 template <class T>
295 UpdateHandle<T> makeHandle (const UpdateHandleKey<T>& key)
296 {
297  return UpdateHandle<T> (key);
298 }
299 
300 
301 /**
302  * @brief Return an @c UpdateHandle referencing @c key for an explicit context.
303  * @param key The key object holding the clid/key/store.
304  * @param ctx The event context.
305  *
306  * This will raise an exception if the StoreGate key is blank,
307  * or if the event store cannot be found.
308  *
309  * If the default event store has been requested, then the thread-specific
310  * store from the event context will be used.
311  */
312 template <class T>
313 UpdateHandle<T> makeHandle (const UpdateHandleKey<T>& key,
314  const EventContext& ctx)
315 {
316  return UpdateHandle<T> (key, ctx);
317 }
318 
319 
320 } /* namespace SG */
321 
322 
323 #endif //> !STOREGATE_SG_UPDATEHANDLE_ICC