2 Copyright (C) 2002-2018 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 with full arguments.
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 )
54 * @brief Constructor from an UpdateHandleKey.
55 * @param key The key object holding the clid/key/store.
57 * This will raise an exception if the StoreGate key is blank,
58 * or if the event store cannot be found.
62 UpdateHandle<T>::UpdateHandle (const UpdateHandleKey<T>& key)
63 : VarHandleBase (key, nullptr)
69 * @brief Constructor from an UpdateHandleKey and an explicit event context.
70 * @param key The key object holding the clid/key.
71 * @param ctx The event context.
73 * This will raise an exception if the StoreGate key is blank,
74 * or if the event store cannot be found.
76 * If the default event store has been requested, then the thread-specific
77 * store from the event context will be used.
80 UpdateHandle<T>::UpdateHandle (const UpdateHandleKey<T>& key,
81 const EventContext& ctx)
82 : VarHandleBase (key, &ctx)
88 * @brief Copy constructor.
92 UpdateHandle<T>::UpdateHandle(const UpdateHandle& h)
98 * @brief Move constructor.
102 UpdateHandle<T>::UpdateHandle(UpdateHandle&& h)
103 : VarHandleBase(std::move(h))
109 * @brief Assignment operator.
114 UpdateHandle<T>::UpdateHandle::operator= (const UpdateHandle& h)
117 this->VarHandleBase::operator=(h);
124 * @brief Move operator.
129 UpdateHandle<T>::UpdateHandle::operator= (UpdateHandle&& h)
132 this->VarHandleBase::operator=(std::move(h));
138 //************************************************************************
144 * @brief Dereference the pointer.
145 * Throws ExcNullReadHandle on failure.
147 * This will inform Hive that the object has been modified.
151 typename UpdateHandle<T>::pointer_type
152 UpdateHandle<T>::operator->()
159 * @brief Dereference the pointer.
160 * Throws ExcNullReadHandle on failure.
162 * This will inform Hive that the object has been modified.
166 typename UpdateHandle<T>::reference_type UpdateHandle<T>::operator*()
168 return *checkedPtr();
173 * @brief Dereference the pointer.
174 * Returns nullptr on failure.
176 * This will _not_ inform Hive that the object has been modified.
180 typename UpdateHandle<T>::const_pointer_type UpdateHandle<T>::cptr()
182 return reinterpret_cast<const_pointer_type>(this->typeless_cptr());
187 * @brief Dereference the pointer.
188 * Returns nullptr on failure.
190 * This will inform Hive that the object has been modified.
193 typename UpdateHandle<T>::pointer_type
194 UpdateHandle<T>::ptr()
196 pointer_type ptr = reinterpret_cast<pointer_type>(this->typeless_ptr());
202 * @brief Return the cached pointer directly; no lookup.
206 typename UpdateHandle<T>::pointer_type
207 UpdateHandle<T>::cachedPtr()
209 return reinterpret_cast<pointer_type>(this->m_ptr);
214 * @brief Can the handle be successfully dereferenced?
218 bool UpdateHandle<T>::isValid()
220 const bool QUIET=true;
221 if (0 != this->typeless_dataPointer(QUIET))
228 * @brief Reset this handle.
229 * @param hard If true, anything depending on the event store is cleared.
231 * Call reset() from the base class.
234 void UpdateHandle<T>::reset (bool hard)
236 VarHandleBase::reset (hard);
241 * @brief Helper: dereference the pointer.
242 * Throws ExcNullUpdateHandle on failure.
246 typename UpdateHandle<T>::pointer_type
247 UpdateHandle<T>::checkedPtr()
249 pointer_type p = this->ptr();
251 throwExcNullUpdateHandle (clid(), key(), store());
257 * @brief Return an @c UpdateHandle referencing @c key.
258 * @param key The key object holding the clid/key/store.
260 * This will raise an exception if the StoreGate key is blank,
261 * or if the event store cannot be found.
264 UpdateHandle<T> makeHandle (const UpdateHandleKey<T>& key)
266 return UpdateHandle<T> (key);
271 * @brief Return an @c UpdateHandle referencing @c key for an explicit context.
272 * @param key The key object holding the clid/key/store.
273 * @param ctx The event context.
275 * This will raise an exception if the StoreGate key is blank,
276 * or if the event store cannot be found.
278 * If the default event store has been requested, then the thread-specific
279 * store from the event context will be used.
282 UpdateHandle<T> makeHandle (const UpdateHandleKey<T>& key,
283 const EventContext& ctx)
285 return UpdateHandle<T> (key, ctx);
292 #endif //> !STOREGATE_SG_UPDATEHANDLE_ICC