ATLAS Offline Software
Loading...
Searching...
No Matches
JaggedVecAccessor.icc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3 */
4/**
5 * @file AthContainers/JaggedVecAccessor.h
6 * @author scott snyder <snyder@bnl.gov>
7 * @date Apr, 2024
8 * @brief Helper class to provide type-safe access to aux data. xxx
9 */
10
11
12#include "AthContainers/AuxElement.h"
13#include "AthContainers/AuxTypeRegistry.h"
14#include "AthContainers/tools/AuxVectorInterface.h"
15#include "AthContainers/exceptions.h"
16#include "CxxUtils/checker_macros.h"
17
18
19namespace SG {
20
21
22/**
23 * @brief Constructor.
24 * @param name Name of this aux variable.
25 *
26 * The name -> auxid lookup is done here.
27 */
28template <class PAYLOAD_T, class ALLOC>
29inline
30Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::Accessor (const std::string& name)
31 : Base (name)
32{
33}
34
35
36/**
37 * @brief Constructor.
38 * @param name Name of this aux variable.
39 * @param clsname The name of its associated class. May be blank.
40 *
41 * The name -> auxid lookup is done here.
42 */
43template <class PAYLOAD_T, class ALLOC>
44inline
45Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::Accessor (const std::string& name,
46 const std::string& clsname)
47 : Base (name, clsname)
48{
49}
50
51
52/**
53 * @brief Constructor taking an auxid directly.
54 * @param auxid ID for this auxiliary variable.
55 *
56 * Will throw @c SG::ExcAuxTypeMismatch if the types don't match.
57 */
58template <class PAYLOAD_T, class ALLOC>
59inline
60Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::Accessor (const SG::auxid_t auxid)
61 : Base (auxid)
62{
63 // cppcheck-suppress missingReturn; false positive
64}
65
66
67/**
68 * @brief Fetch the variable for one element, as a non-const reference.
69 * @param e The element for which to fetch the variable.
70 *
71 * Will return a proxy object, which will allow treating this
72 * jagged vector element as a vector.
73 */
74template <class PAYLOAD_T, class ALLOC>
75template <IsAuxElement ELT>
76inline
77auto
78Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator() (ELT& e) const
79 -> reference_type
80{
81 assert (e.container() != 0);
82 return (*this) (*e.container(), e.index());
83}
84
85
86/**
87 * @brief Fetch the variable for one element, as a non-const reference.
88 * @param container The container from which to fetch the variable.
89 * @param index The index of the desired element.
90 *
91 * This allows retrieving aux data by container / index.
92 *
93 * Will return a proxy object, which will allow treating this
94 * jagged vector element as a vector.
95 */
96#ifndef __CPPCHECK__ // cppcheck gets parse errors on this
97template <class PAYLOAD_T, class ALLOC>
98inline
99auto
100Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator() (AuxVectorData& container,
101 size_t index) const
102 -> reference_type
103{
104 (void)this->getEltArray (container); // const/locking checks
105 return reference_type (index,
106 *container.getDataSpan (this->m_linkedAuxid),
107 *container.getDataSpan (this->m_auxid),
108 container,
109 this->m_auxid);
110}
111#endif // not __CPPCHECK__
112
113
114/**
115 * @brief Set the variable for one element.
116 * @param e The element for which to fetch the variable.
117 * @param x The variable value to set.
118 */
119template <class PAYLOAD_T, class ALLOC>
120template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
121inline
122void Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::set (AuxElement& e,
123 const RANGE& x) const
124{
125 (*this) (*e.container(), e.index()) = x;
126}
127
128
129/**
130 * @brief Set the variable for one element.
131 * @param container The container from which to fetch the variable.
132 * @param index The index of the desired element.
133 * @param x The variable value to set.
134 */
135template <class PAYLOAD_T, class ALLOC>
136template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
137void Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::set (AuxVectorData& container,
138 size_t index,
139 const RANGE& x) const
140{
141 (*this) (container, index) = x;
142}
143
144
145/**
146 * @brief Get a pointer to the start of the array of @c JaggedVecElt objects.
147 * @param container The container from which to fetch the variable.
148 */
149template <class PAYLOAD_T, class ALLOC>
150inline
151auto
152Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltArray (AuxVectorData& container) const
153 -> Elt_t*
154{
155 return reinterpret_cast<Elt_t*>
156 (container.getDataArray (this->m_auxid));
157}
158
159
160/**
161 * @brief Get a pointer to the start of the payload array.
162 * @param container The container from which to fetch the variable.
163 */
164template <class PAYLOAD_T, class ALLOC>
165inline
166auto
167Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadArray (AuxVectorData& container) const
168 -> Payload_t*
169{
170 return reinterpret_cast<Payload_t*>
171 (container.getDataArray (this->m_linkedAuxid));
172}
173
174
175/**
176 * @brief Get a span over the array of @c JaggedVecElt objects.
177 * @param container The container from which to fetch the variable.
178 */
179template <class PAYLOAD_T, class ALLOC>
180inline
181auto
182Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltSpan (AuxVectorData& container) const
183 -> Elt_span
184{
185 auto beg = reinterpret_cast<Elt_t*> (container.getDataArray (this->m_auxid));
186 return Elt_span (beg, container.size_v());
187}
188
189
190/**
191 * @brief Get a span over the payload vector.
192 * @param container The container from which to fetch the variable.
193 */
194template <class PAYLOAD_T, class ALLOC>
195inline
196auto
197Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadSpan (AuxVectorData& container) const
198 -> Payload_span
199{
200 const AuxDataSpanBase* sp = container.getDataSpan (this->m_linkedAuxid);
201 return Payload_span (reinterpret_cast<Payload_t*>(sp->beg), sp->size);
202}
203
204
205/**
206 * @brief Get a span over spans representing the jagged vector.
207 * @param container The container from which to fetch the variable.
208 */
209template <class PAYLOAD_T, class ALLOC>
210inline
211auto
212Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getDataSpan (AuxVectorData& container) const
213 -> span
214{
215 return span (getEltSpan(container),
216 Converter_t (container, this->auxid(), this->linkedAuxid()));
217}
218
219
220/**
221 * @brief Test to see if this variable exists in the store and is writable.
222 * @param e An element of the container in which to test the variable.
223 */
224template <class PAYLOAD_T, class ALLOC>
225inline
226bool
227Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::isAvailableWritable (AuxElement& e) const
228{
229 return e.container() &&
230 e.container()->isAvailableWritable (this->m_auxid) &&
231 e.container()->isAvailableWritable (this->m_linkedAuxid);
232}
233
234
235/**
236 * @brief Test to see if this variable exists in the store and is writable.
237 * @param c The container in which to test the variable.
238 */
239template <class PAYLOAD_T, class ALLOC>
240inline
241bool
242Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::isAvailableWritable (AuxVectorData& c) const
243{
244 return c.isAvailableWritable (this->m_auxid) &&
245 c.isAvailableWritable (this->m_linkedAuxid);
246}
247
248
249} // namespace SG