ATLAS Offline Software
AthToolSupport/AsgDataHandles/AsgDataHandles/ReadDecorHandle.icc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3  */
4 
5 /**
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.
10  */
11 
12 
13 namespace SG {
14 
15 /**
16  * @brief Constructor from a ReadDecorHandleKey.
17  * @param key The key object holding the clid/key/store/attr.
18  *
19  * This will raise an exception if the StoreGate key is blank,
20  * or if the event store cannot be found.
21  */
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()))
27 {
28 }
29 
30 
31 /**
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.
35  *
36  * This will raise an exception if the StoreGate key is blank,
37  * or if the event store cannot be found.
38  *
39  * If the default event store has been requested, then the thread-specific
40  * store from the event context will be used.
41  */
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()))
48 {
49 }
50 
51 
52 // /**
53 // * @brief Copy constructor.
54 // */
55 // template <class T, class D>
56 // ReadDecorHandle<T, D>::ReadDecorHandle (const ReadDecorHandle& rhs)
57 // : Base (rhs),
58 // m_decorKey (rhs.m_decorKey),
59 // m_acc (rhs.m_acc)
60 // {
61 // }
62 
63 
64 // /**
65 // * @brief Move constructor.
66 // */
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))
72 // {
73 // }
74 
75 
76 // /**
77 // * @brief Assignment operator.
78 // */
79 // template <class T, class D>
80 // ReadDecorHandle<T, D>& ReadDecorHandle<T, D>::operator= (const ReadDecorHandle& rhs)
81 // {
82 // if (this != &rhs) {
83 // *static_cast<Base*>(this) = rhs;
84 // m_decorKey = rhs.m_decorKey;
85 // m_acc = rhs.m_acc;
86 // }
87 // return *this;
88 // }
89 
90 
91 // /**
92 // * @brief Move operator.
93 // */
94 // template <class T, class D>
95 // ReadDecorHandle<T, D>& ReadDecorHandle<T, D>::operator= (ReadDecorHandle&& rhs)
96 // {
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);
101 // }
102 // return *this;
103 // }
104 
105 
106 /**
107  * @brief Is the referenced container present in SG?
108  *
109  * Note that this tests for the presence of the _container_,
110  * not for the decoration.
111  *
112  * Const method; the handle does not change as a result of this.
113  */
114 template <class T, class D>
115 inline
116 bool ReadDecorHandle<T, D>::isPresent() const
117 {
118  return Base::isPresent();
119 }
120 
121 
122 /**
123  * @brief Fetch the variable for one element, as a const reference.
124  * @param e The element for which to fetch the variable.
125  */
126 template <class T, class D>
127 inline
128 typename ReadDecorHandle<T, D>::const_reference_type
129 ReadDecorHandle<T, D>::operator() (const AuxElement& e) const
130 {
131  return m_acc (e);
132 }
133 
134 
135 /**
136  * @brief Fetch the variable for one element, as a const reference.
137  * @param index The index of the desired element.
138  *
139  * This looks up the variable in the object referenced by this handle.
140  * For a standalone object, pass an index of 0.
141  */
142 template <class T, class D>
143 inline
144 typename ReadDecorHandle<T, D>::const_reference_type
145 ReadDecorHandle<T, D>::operator() (size_t i)
146 {
147  return m_acc (*this->vectorData(), i);
148 }
149 
150 
151 // /**
152 // * @brief Get a pointer to the start of the auxiliary data array.
153 // * for the referenced object.
154 // */
155 // template <class T, class D>
156 // typename ReadDecorHandle<T, D>::const_container_pointer_type
157 // ReadDecorHandle<T, D>::getDataArray()
158 // {
159 // return reinterpret_cast<const_container_pointer_type>
160 // (this->vectorData()->getDataArray (m_acc.auxid()));
161 // }
162 
163 
164 /**
165  * @brief Test to see if this variable exists in the store,
166  * for the referenced object.
167  */
168 template <class T, class D>
169 inline
170 bool ReadDecorHandle<T, D>::isAvailable()
171 {
172  const SG::AuxVectorData* vec = this->vectorData();
173  return vec && vec->isAvailable (m_acc.auxid());
174 }
175 
176 
177 // /**
178 // * @brief Return the aux id for this variable.
179 // */
180 // template <class T, class D>
181 // inline
182 // SG::auxid_t ReadDecorHandle<T, D>::auxid() const
183 // {
184 // return m_acc.auxid();
185 // }
186 
187 
188 /**
189  * @brief Return the name of the decoration alias (CONT.DECOR).
190  */
191 template <class T, class D>
192 inline
193 std::string ReadDecorHandle<T, D>::decorKey() const
194 {
195  return m_decorKey;
196 }
197 
198 
199 /**
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).
203  */
204 template <class T, class D>
205 inline
206 const SG::AuxVectorData* ReadDecorHandle<T, D>::vectorData (std::true_type)
207 {
208  return (*this)->container();
209 }
210 
211 
212 /**
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).
216  */
217 template <class T, class D>
218 inline
219 const SG::AuxVectorData* ReadDecorHandle<T, D>::vectorData (std::false_type)
220 {
221  return this->cptr();
222 }
223 
224 
225 /**
226  * @brief Return the referenced object as a @c SG::AuxVectorData.
227  *
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.
231  */
232 template <class T, class D>
233 inline
234 const SG::AuxVectorData* ReadDecorHandle<T, D>::vectorData()
235 {
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());
239 }
240 
241 
242 // /**
243 // * @brief Return a @c ReadDecorHandle referencing @c key.
244 // * @param key The key object holding the clid/key/store.
245 // *
246 // * This will raise an exception if the StoreGate key is blank,
247 // * or if the event store cannot be found.
248 // *
249 // * The type of the decoration must be included as an explicit template parameter:
250 // *
251 // *@code
252 // * auto handle = SG::makeHandle<float> (key);
253 // @endcode
254 // *
255 // * Note that @c D comes first in the argument list. It's given explicitly,
256 // * while @c T is inferred from @c key.
257 // */
258 // template <class D, class T>
259 // ReadDecorHandle<T, D> makeHandle (const ReadDecorHandleKey<T>& key)
260 // {
261 // return ReadDecorHandle<T, D> (key);
262 // }
263 
264 
265 // /**
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.
269 // *
270 // * This will raise an exception if the StoreGate key is blank,
271 // * or if the event store cannot be found.
272 // *
273 // * If the default event store has been requested, then the thread-specific
274 // * store from the event context will be used.
275 // *
276 // * The type of the decoration must be included as an explicit template parameter:
277 // *
278 // *@code
279 // * auto handle = SG::makeHandle<float> (key, ctx);
280 // @endcode
281 // *
282 // * Note that @c D comes first in the argument list. It's given explicitly,
283 // * while @c T is inferred from @c key.
284 // */
285 // template <class D, class T>
286 // ReadDecorHandle<T, D> makeHandle (const ReadDecorHandleKey<T>& key,
287 // const EventContext& ctx)
288 // {
289 // return ReadDecorHandle<T, D> (key, ctx);
290 // }
291 
292 
293 // /**
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.
299 // */
300 // template <class T>
301 // void makeHandle (const ReadDecorHandleKey<T>& /*key*/)
302 // {
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();
307 // }
308 // template <class T>
309 // void makeHandle (const ReadDecorHandleKey<T>& /*key*/,
310 // const EventContext& /*ctx*/)
311 // {
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();
316 // }
317 
318 
319 } // namespace SG