2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
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.
11#ifndef STOREGATE_SG_UPDATEHANDLE_ICC
12#define STOREGATE_SG_UPDATEHANDLE_ICC 1
15#include "StoreGate/exceptions.h"
16#include "AthenaKernel/ClassID_traits.h"
24 * @brief Default constructor.
26 * The handle will not be usable until a non-blank key is assigned.
30UpdateHandle<T>::UpdateHandle()
31 : VarHandleBase(ClassID_traits<T>::ID(), Gaudi::DataHandle::Reader)
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.
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 )
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.
58UpdateHandle<T>::UpdateHandle(const std::string& sgkey, const EventContext& ctx)
59 : UpdateHandle(sgkey, StoreID::storeName(StoreID::EVENT_STORE), ctx)
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.
71UpdateHandle<T>::UpdateHandle(const std::string& sgkey, IProxyDict* sg)
72 : VarHandleBase(ClassID_traits<T>::ID(), sgkey, Gaudi::DataHandle::Reader, sg)
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.
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 )
95 * @brief Constructor from an UpdateHandleKey.
96 * @param key The key object holding the clid/key/store.
98 * This will raise an exception if the StoreGate key is blank,
99 * or if the event store cannot be found.
103UpdateHandle<T>::UpdateHandle (const UpdateHandleKey<T>& key)
104 : VarHandleBase (key, nullptr)
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.
114 * This will raise an exception if the StoreGate key is blank,
115 * or if the event store cannot be found.
117 * If the default event store has been requested, then the thread-specific
118 * store from the event context will be used.
121UpdateHandle<T>::UpdateHandle (const UpdateHandleKey<T>& key,
122 const EventContext& ctx)
123 : VarHandleBase (key, &ctx)
129 * @brief Copy constructor.
133UpdateHandle<T>::UpdateHandle(const UpdateHandle& h)
139 * @brief Move constructor.
143UpdateHandle<T>::UpdateHandle(UpdateHandle&& h)
144 : VarHandleBase(std::move(h))
150 * @brief Assignment operator.
155UpdateHandle<T>::UpdateHandle::operator= (const UpdateHandle& h)
158 this->VarHandleBase::operator=(h);
165 * @brief Move operator.
170UpdateHandle<T>::UpdateHandle::operator= (UpdateHandle&& h)
173 this->VarHandleBase::operator=(std::move(h));
179//************************************************************************
185 * @brief Dereference the pointer.
186 * Throws ExcNullReadHandle on failure.
188 * This will inform Hive that the object has been modified.
192typename UpdateHandle<T>::pointer_type
193UpdateHandle<T>::operator->()
200 * @brief Dereference the pointer.
201 * Throws ExcNullReadHandle on failure.
203 * This will inform Hive that the object has been modified.
207typename UpdateHandle<T>::reference_type UpdateHandle<T>::operator*()
209 return *checkedPtr();
214 * @brief Dereference the pointer.
215 * Returns nullptr on failure.
217 * This will _not_ inform Hive that the object has been modified.
221typename UpdateHandle<T>::const_pointer_type UpdateHandle<T>::cptr()
223 return reinterpret_cast<const_pointer_type>(this->typeless_cptr());
228 * @brief Dereference the pointer.
229 * Returns nullptr on failure.
231 * This will inform Hive that the object has been modified.
234typename UpdateHandle<T>::pointer_type
235UpdateHandle<T>::ptr()
237 pointer_type ptr = reinterpret_cast<pointer_type>(this->typeless_ptr());
243 * @brief Return the cached pointer directly; no lookup.
247typename UpdateHandle<T>::pointer_type
248UpdateHandle<T>::cachedPtr()
250 return reinterpret_cast<pointer_type>(this->m_ptr);
255 * @brief Can the handle be successfully dereferenced?
259bool UpdateHandle<T>::isValid()
261 const bool QUIET=true;
262 if (0 != this->typeless_dataPointer(QUIET))
269 * @brief Reset this handle.
270 * @param hard If true, anything depending on the event store is cleared.
272 * Call reset() from the base class.
275void UpdateHandle<T>::reset (bool hard)
277 VarHandleBase::reset (hard);
282 * @brief Helper: dereference the pointer.
283 * Throws ExcNullUpdateHandle on failure.
287typename UpdateHandle<T>::pointer_type
288UpdateHandle<T>::checkedPtr()
290 pointer_type p = this->ptr();
292 throwExcNullUpdateHandle (clid(), key(), store());
298 * @brief Return an @c UpdateHandle referencing @c key.
299 * @param key The key object holding the clid/key/store.
301 * This will raise an exception if the StoreGate key is blank,
302 * or if the event store cannot be found.
305UpdateHandle<T> makeHandle (const UpdateHandleKey<T>& key)
307 return UpdateHandle<T> (key);
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.
316 * This will raise an exception if the StoreGate key is blank,
317 * or if the event store cannot be found.
319 * If the default event store has been requested, then the thread-specific
320 * store from the event context will be used.
323UpdateHandle<T> makeHandle (const UpdateHandleKey<T>& key,
324 const EventContext& ctx)
326 return UpdateHandle<T> (key, ctx);
333#endif //> !STOREGATE_SG_UPDATEHANDLE_ICC