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