2 * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
6 * @file AsgDataHandles/ReadDecorHandle.icc
7 * @author Nils Krumnack <Nils.Erik.Krumnack@cern.h>
8 * @author scott snyder <snyder@bnl.gov> (for original)
9 * @brief Handle class for reading a decoration on an object.
16 * @brief Constructor from a ReadDecorHandleKey.
17 * @param key The key object holding the clid/key/store/attr.
19 * This will raise an exception if the StoreGate key is blank,
20 * or if the event store cannot be found.
22 template <class T, class D>
23 ReadDecorHandle<T, D>::ReadDecorHandle (const ReadDecorHandleKey<T>& key)
24 : Base (key.contHandleKey()),
25 m_decorKey (key.key()),
26 m_acc (SG::decorKeyFromKey (key.key()))
32 * @brief Constructor from a ReadDecorHandleKey and an explicit event context.
33 * @param key The key object holding the clid/key.
34 * @param ctx The event context.
36 * This will raise an exception if the StoreGate key is blank,
37 * or if the event store cannot be found.
39 * If the default event store has been requested, then the thread-specific
40 * store from the event context will be used.
42 template <class T, class D>
43 ReadDecorHandle<T, D>::ReadDecorHandle (const ReadDecorHandleKey<T>& key,
44 const EventContext& ctx)
45 : Base (key.contHandleKey(), ctx),
46 m_decorKey (key.key()),
47 m_acc (SG::decorKeyFromKey (key.key()))
53 // * @brief Copy constructor.
55 // template <class T, class D>
56 // ReadDecorHandle<T, D>::ReadDecorHandle (const ReadDecorHandle& rhs)
58 // m_decorKey (rhs.m_decorKey),
65 // * @brief Move constructor.
67 // template <class T, class D>
68 // ReadDecorHandle<T, D>::ReadDecorHandle (ReadDecorHandle&& rhs)
69 // : Base (std::move (rhs)),
70 // m_decorKey (std::move (rhs.m_decorKey)),
71 // m_acc (std::move (rhs.m_acc))
77 // * @brief Assignment operator.
79 // template <class T, class D>
80 // ReadDecorHandle<T, D>& ReadDecorHandle<T, D>::operator= (const ReadDecorHandle& rhs)
82 // if (this != &rhs) {
83 // *static_cast<Base*>(this) = rhs;
84 // m_decorKey = rhs.m_decorKey;
92 // * @brief Move operator.
94 // template <class T, class D>
95 // ReadDecorHandle<T, D>& ReadDecorHandle<T, D>::operator= (ReadDecorHandle&& rhs)
97 // if (this != &rhs) {
98 // *static_cast<Base*>(this) = std::move (rhs);
99 // m_decorKey = std::move (rhs.m_decorKey);
100 // m_acc = std::move (rhs.m_acc);
107 * @brief Is the referenced container present in SG?
109 * Note that this tests for the presence of the _container_,
110 * not for the decoration.
112 * Const method; the handle does not change as a result of this.
114 template <class T, class D>
116 bool ReadDecorHandle<T, D>::isPresent() const
118 return Base::isPresent();
123 * @brief Fetch the variable for one element, as a const reference.
124 * @param e The element for which to fetch the variable.
126 template <class T, class D>
128 typename ReadDecorHandle<T, D>::const_reference_type
129 ReadDecorHandle<T, D>::operator() (const AuxElement& e) const
136 * @brief Fetch the variable for one element, as a const reference.
137 * @param index The index of the desired element.
139 * This looks up the variable in the object referenced by this handle.
140 * For a standalone object, pass an index of 0.
142 template <class T, class D>
144 typename ReadDecorHandle<T, D>::const_reference_type
145 ReadDecorHandle<T, D>::operator() (size_t i)
147 return m_acc (*this->vectorData(), i);
152 // * @brief Get a pointer to the start of the auxiliary data array.
153 // * for the referenced object.
155 // template <class T, class D>
156 // typename ReadDecorHandle<T, D>::const_container_pointer_type
157 // ReadDecorHandle<T, D>::getDataArray()
159 // return reinterpret_cast<const_container_pointer_type>
160 // (this->vectorData()->getDataArray (m_acc.auxid()));
165 * @brief Test to see if this variable exists in the store,
166 * for the referenced object.
168 template <class T, class D>
170 bool ReadDecorHandle<T, D>::isAvailable()
172 const SG::AuxVectorData* vec = this->vectorData();
173 return vec && vec->isAvailable (m_acc.auxid());
178 // * @brief Return the aux id for this variable.
180 // template <class T, class D>
182 // SG::auxid_t ReadDecorHandle<T, D>::auxid() const
184 // return m_acc.auxid();
189 * @brief Return the name of the decoration alias (CONT.DECOR).
191 template <class T, class D>
193 std::string ReadDecorHandle<T, D>::decorKey() const
200 * @brief Return the referenced object as a @c SG::AuxVectorData.
201 * Specialization for the case of a standalone object
202 * (@c T derives from @c SG::AuxElement).
204 template <class T, class D>
206 const SG::AuxVectorData* ReadDecorHandle<T, D>::vectorData (std::true_type)
208 return (*this)->container();
213 * @brief Return the referenced object as a @c SG::AuxVectorData.
214 * Specialization for the case of a container
215 * (@c T does not derive from @c SG::AuxElement).
217 template <class T, class D>
219 const SG::AuxVectorData* ReadDecorHandle<T, D>::vectorData (std::false_type)
226 * @brief Return the referenced object as a @c SG::AuxVectorData.
228 * If @c T is a container object, then this should be the object itself.
229 * But if it is a standalone object, deriving from @c SG::AuxElement,
230 * then we need to call container() on the object.
232 template <class T, class D>
234 const SG::AuxVectorData* ReadDecorHandle<T, D>::vectorData()
236 // Dispatch to the appropriate specialization, depending on whether or not
237 // @c T derives from @c SG::AuxElement.
238 return vectorData (typename std::is_base_of<SG::AuxElement, T>::type());
243 // * @brief Return a @c ReadDecorHandle referencing @c key.
244 // * @param key The key object holding the clid/key/store.
246 // * This will raise an exception if the StoreGate key is blank,
247 // * or if the event store cannot be found.
249 // * The type of the decoration must be included as an explicit template parameter:
252 // * auto handle = SG::makeHandle<float> (key);
255 // * Note that @c D comes first in the argument list. It's given explicitly,
256 // * while @c T is inferred from @c key.
258 // template <class D, class T>
259 // ReadDecorHandle<T, D> makeHandle (const ReadDecorHandleKey<T>& key)
261 // return ReadDecorHandle<T, D> (key);
266 // * @brief Return a @c ReadDecorHandle referencing @c key for an explicit context.
267 // * @param key The key object holding the clid/key/store.
268 // * @param ctx The event context.
270 // * This will raise an exception if the StoreGate key is blank,
271 // * or if the event store cannot be found.
273 // * If the default event store has been requested, then the thread-specific
274 // * store from the event context will be used.
276 // * The type of the decoration must be included as an explicit template parameter:
279 // * auto handle = SG::makeHandle<float> (key, ctx);
282 // * Note that @c D comes first in the argument list. It's given explicitly,
283 // * while @c T is inferred from @c key.
285 // template <class D, class T>
286 // ReadDecorHandle<T, D> makeHandle (const ReadDecorHandleKey<T>& key,
287 // const EventContext& ctx)
289 // return ReadDecorHandle<T, D> (key, ctx);
294 // * @brief These two signatures are to catch cases where the explicit
295 // * template argument is omitted from the @c makeHandle call
296 // * and give an error tailored to that. Otherwise, the @c makeHandle
297 // * call for @c ReadHandle would match, potentially giving a much
298 // * more confusing error.
300 // template <class T>
301 // void makeHandle (const ReadDecorHandleKey<T>& /*key*/)
303 // // If you see an error from here, you've forgotten the explicit template
304 // // argument to @c makeHandle giving the decoration type.
305 // // See the examples of @c makeHandle above.
306 // return T::makeHandleForDecorationsRequiresExplicitTemplateArgument();
308 // template <class T>
309 // void makeHandle (const ReadDecorHandleKey<T>& /*key*/,
310 // const EventContext& /*ctx*/)
312 // // If you see an error from here, you've forgotten the explicit template
313 // // argument to @c makeHandle giving the decoration type.
314 // // See the examples of @c makeHandle above.
315 // return T::makeHandleForDecorationsRequiresExplicitTemplateArgument();