2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5 // $Id: UpdateHandle.icc 797637 2017-02-17 02:32:11Z ssnyder $
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.
13 #ifndef STOREGATE_SG_UPDATEHANDLE_ICC
14 #define STOREGATE_SG_UPDATEHANDLE_ICC 1
17 #include "StoreGate/exceptions.h"
18 #include "AthenaKernel/ClassID_traits.h"
26 * @brief Default constructor.
28 * The handle will not be usable until a non-blank key is assigned.
32 UpdateHandle<T>::UpdateHandle()
33 : VarHandleBase(ClassID_traits<T>::ID(), Gaudi::DataHandle::Reader)
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.
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 )
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.
60 UpdateHandle<T>::UpdateHandle(const std::string& sgkey,
61 const EventContext& ctx)
62 : UpdateHandle(sgkey, StoreID::storeName(StoreID::EVENT_STORE), ctx)
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.
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 )
85 * @brief Constructor from an UpdateHandleKey.
86 * @param key The key object holding the clid/key/store.
88 * This will raise an exception if the StoreGate key is blank,
89 * or if the event store cannot be found.
93 UpdateHandle<T>::UpdateHandle (const UpdateHandleKey<T>& key)
94 : VarHandleBase (key, nullptr)
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.
104 * This will raise an exception if the StoreGate key is blank,
105 * or if the event store cannot be found.
107 * If the default event store has been requested, then the thread-specific
108 * store from the event context will be used.
111 UpdateHandle<T>::UpdateHandle (const UpdateHandleKey<T>& key,
112 const EventContext& ctx)
113 : VarHandleBase (key, &ctx)
119 * @brief Copy constructor.
123 UpdateHandle<T>::UpdateHandle(const UpdateHandle& h)
129 * @brief Move constructor.
133 UpdateHandle<T>::UpdateHandle(UpdateHandle&& h)
134 : VarHandleBase(std::move(h))
140 * @brief Assignment operator.
145 UpdateHandle<T>::UpdateHandle::operator= (const UpdateHandle& h)
148 this->VarHandleBase::operator=(h);
155 * @brief Move operator.
160 UpdateHandle<T>::UpdateHandle::operator= (UpdateHandle&& h)
163 this->VarHandleBase::operator=(std::move(h));
169 //************************************************************************
175 * @brief Dereference the pointer.
176 * Throws ExcNullReadHandle on failure.
178 * This will inform Hive that the object has been modified.
182 typename UpdateHandle<T>::pointer_type
183 UpdateHandle<T>::operator->()
190 * @brief Dereference the pointer.
191 * Throws ExcNullReadHandle on failure.
193 * This will inform Hive that the object has been modified.
197 typename UpdateHandle<T>::reference_type UpdateHandle<T>::operator*()
199 return *checkedPtr();
204 * @brief Dereference the pointer.
205 * Returns nullptr on failure.
207 * This will _not_ inform Hive that the object has been modified.
211 typename UpdateHandle<T>::const_pointer_type UpdateHandle<T>::cptr()
213 return reinterpret_cast<const_pointer_type>(this->typeless_cptr());
218 * @brief Dereference the pointer.
219 * Returns nullptr on failure.
221 * This will inform Hive that the object has been modified.
224 typename UpdateHandle<T>::pointer_type
225 UpdateHandle<T>::ptr()
227 pointer_type ptr = reinterpret_cast<pointer_type>(this->typeless_ptr());
233 * @brief Return the cached pointer directly; no lookup.
237 typename UpdateHandle<T>::pointer_type
238 UpdateHandle<T>::cachedPtr()
240 return reinterpret_cast<pointer_type>(this->m_ptr);
245 * @brief Can the handle be successfully dereferenced?
249 bool UpdateHandle<T>::isValid()
251 const bool QUIET=true;
252 if (0 != this->typeless_dataPointer(QUIET))
259 * @brief Reset this handle.
260 * @param hard If true, anything depending on the event store is cleared.
262 * Call reset() from the base class.
265 void UpdateHandle<T>::reset (bool hard)
267 VarHandleBase::reset (hard);
272 * @brief Helper: dereference the pointer.
273 * Throws ExcNullUpdateHandle on failure.
277 typename UpdateHandle<T>::pointer_type
278 UpdateHandle<T>::checkedPtr()
280 pointer_type p = this->ptr();
282 throwExcNullUpdateHandle (clid(), key(), store());
288 * @brief Return an @c UpdateHandle referencing @c key.
289 * @param key The key object holding the clid/key/store.
291 * This will raise an exception if the StoreGate key is blank,
292 * or if the event store cannot be found.
295 UpdateHandle<T> makeHandle (const UpdateHandleKey<T>& key)
297 return UpdateHandle<T> (key);
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.
306 * This will raise an exception if the StoreGate key is blank,
307 * or if the event store cannot be found.
309 * If the default event store has been requested, then the thread-specific
310 * store from the event context will be used.
313 UpdateHandle<T> makeHandle (const UpdateHandleKey<T>& key,
314 const EventContext& ctx)
316 return UpdateHandle<T> (key, ctx);
323 #endif //> !STOREGATE_SG_UPDATEHANDLE_ICC