ATLAS Offline Software
Loading...
Searching...
No Matches
ObjectRange.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8#ifndef COLUMNAR_CORE_OBJECT_RANGE_H
9#define COLUMNAR_CORE_OBJECT_RANGE_H
10
14#include <exception>
15
16namespace columnar
17{
19 template<ContainerIdConcept CI,typename CM> class ObjectRange;
20
21
22
23
24 template<ContainerIdConcept CI,typename IteratorType> class ObjectRangeIteratorXAODContainer;
25
26 template<ContainerIdConcept CI> class ObjectRange<CI,ColumnarModeXAOD> final
27 {
30 public:
31
32 using xAODContainer = typename CI::xAODObjectRangeType;
34
35 ObjectRange (xAODContainer& val_container) noexcept
36 : m_container (&val_container)
37 {}
38
39 [[nodiscard]] xAODContainer& getXAODObject () const noexcept {
40 // This object should ever be held within the context of a
41 // single thread (and generally on the stack), so the associated
42 // check is meaningless.
44 return *container;}
45
46 // a version of `getXAODObject` that only exists when it is `noexcept`
47 [[nodiscard]] xAODContainer& getXAODObjectNoexcept () const noexcept {
48 // This object should ever be held within the context of a
49 // single thread (and generally on the stack), so the associated
50 // check is meaningless.
52 return *container;}
53
54 auto begin () const noexcept {
55 // This object should ever be held within the context of a
56 // single thread (and generally on the stack), so the associated
57 // check is meaningless.
59 return ObjectRangeIteratorXAODContainer<CI,decltype(container->begin())> (container->begin());}
60 auto end () const noexcept {
61 // This object should ever be held within the context of a
62 // single thread (and generally on the stack), so the associated
63 // check is meaningless.
65 return ObjectRangeIteratorXAODContainer<CI,decltype(container->end())> (container->end());}
66 auto rbegin () const noexcept {
67 // This object should ever be held within the context of a
68 // single thread (and generally on the stack), so the associated
69 // check is meaningless.
71 return ObjectRangeIteratorXAODContainer<CI,decltype(container->rbegin())> (container->rbegin());}
72 auto rend () const noexcept {
73 // This object should ever be held within the context of a
74 // single thread (and generally on the stack), so the associated
75 // check is meaningless.
77 return ObjectRangeIteratorXAODContainer<CI,decltype(container->rend())> (container->rend());}
78
79 [[nodiscard]] bool empty () const noexcept {
80 return m_container->empty();}
81
82 [[nodiscard]] std::size_t size () const noexcept {
83 return m_container->size();}
84
85 [[nodiscard]] ObjectId<CI,CM> operator [] (std::size_t index) const noexcept {
86 return ObjectId<CI,CM> (*(*m_container)[index]);}
87
88 template<typename Acc,typename... Args>
89 requires std::invocable<Acc,ObjectRange<CI,ColumnarModeXAOD>,Args...>
90 [[nodiscard]] decltype(auto) operator() (Acc& acc, Args&&... args) const {
91 return acc (*this, std::forward<Args> (args)...);}
92
94 [[nodiscard]] std::size_t getIndexInRange (const ObjectId<CI,CM>& obj) const {
95 return obj.getXAODObjectNoexcept().index(); }
96
97
98
101 private:
102
104 };
105
106 template<ContainerIdConcept CI,typename IteratorType> class ObjectRangeIteratorXAODContainer final
107 {
108 public:
109
111
112 ObjectRangeIteratorXAODContainer (IteratorType&& val_iterator) noexcept
113 : m_iterator (std::move (val_iterator)) {}
114
116 return ObjectId<CI,CM> (**m_iterator);
117 }
118
121
123 return m_iterator == that.m_iterator;}
125 return m_iterator != that.m_iterator;}
126
127 private:
128 IteratorType m_iterator;
129 };
130
131
132
133 template<ContainerIdConcept CI> class ObjectRangeIteratorXAODSinglet;
134
135 // template specialization for EventInfo objects (and potentially other singlet objects)
136 template<ContainerIdConcept CI>
137 requires (std::is_same_v<typename CI::xAODObjectRangeType,typename CI::xAODObjectIdType>)
139 {
142 public:
143
144 using xAODContainer = typename CI::xAODObjectRangeType;
146
147 ObjectRange (xAODContainer& val_singlet) noexcept
148 : m_singlet (&val_singlet)
149 {}
150
151 [[nodiscard]] xAODContainer& getXAODObject () const noexcept {
152 return *m_singlet;}
153
154 // a version of `getXAODObject` that only exists when it is `noexcept`
155 [[nodiscard]] xAODContainer& getXAODObjectNoexcept () const noexcept {
156 return *m_singlet;}
157
158 auto begin () const noexcept {
160 auto end () const noexcept {
161 return ObjectRangeIteratorXAODSinglet<CI> (nullptr);}
162 auto rbegin () const noexcept {
164 auto rend () const noexcept {
165 return ObjectRangeIteratorXAODSinglet<CI> (nullptr);}
166
167 [[nodiscard]] bool empty () const noexcept {
168 return false;}
169
170 [[nodiscard]] std::size_t size () const noexcept {
171 return 1;}
172
173 [[nodiscard]] ObjectId<CI,CM> operator [] (std::size_t /*index*/) const noexcept {
174 return ObjectId<CI,CM> (*m_singlet);
175 }
176
177 template<typename Acc,typename... Args>
178 requires std::invocable<Acc,ObjectRange<CI,ColumnarModeXAOD>,Args...>
179 [[nodiscard]] decltype(auto) operator() (Acc& acc, Args&&... args) const {
180 return acc (*this, std::forward<Args> (args)...);}
181
182
183
186 private:
187
189 };
190
191 template<ContainerIdConcept CI> class ObjectRangeIteratorXAODSinglet final
192 {
193 public:
194
196 using XAODObjectType = typename CI::xAODObjectIdType;
197
199 : m_object (val_object) {}
200
202 return *m_object;}
203
205 m_object = nullptr; return *this;}
206
207 bool operator == (const ObjectRangeIteratorXAODSinglet<CI>& that) const noexcept {
208 return m_object == that.m_object;}
209 bool operator != (const ObjectRangeIteratorXAODSinglet<CI>& that) const noexcept {
210 return m_object != that.m_object;}
211
212 private:
214 };
215
216
217
218
219 template<ContainerIdConcept CI,int stepSize> class ObjectRangeIteratorArray;
220
221 template<ContainerIdConcept CI> class ObjectRange<CI,ColumnarModeArray> final
222 {
225 public:
226
227 using xAODContainer = typename CI::xAODObjectRangeType;
229
235 // note that as a reverse iterator, the meaning of begin and end
236 // is reversed, and the new "end" can be -1.
239 // note that as a reverse iterator, the meaning of begin and end
240 // is reversed, and the new "end" can be -1.
242
243 [[nodiscard]] std::size_t beginIndex () const noexcept {
244 return m_beginIndex;}
245 [[nodiscard]] std::size_t endIndex () const noexcept {
246 return m_endIndex;}
247
248 // Whatever you do: Do not remove this function. Yes, it will always
249 // throw. It is meant to throw in this template specialization, and
250 // only do something useful in the xAOD mode specialization. If you
251 // remove it you break the columnar mode.
252 ObjectRange (const xAODContainer& /*val_container*/)
253 {
254 throw std::logic_error ("can't call xAOD function in columnar mode");
255 }
256
257 [[nodiscard]] bool empty () const noexcept {
258 return m_beginIndex == m_endIndex;}
259
260 [[nodiscard]] std::size_t size () const noexcept {
261 return m_endIndex - m_beginIndex;}
262
263 // Whatever you do: Do not remove this function. Yes, it will always
264 // throw. It is meant to throw in this template specialization, and
265 // only do something useful in the xAOD mode specialization. If you
266 // remove it you break the columnar mode.
267 [[nodiscard]] xAODContainer& getXAODObject () const {
268 throw std::logic_error ("can't call xAOD function in columnar mode");}
269
270 [[nodiscard]] ObjectId<CI,CM> operator [] (std::size_t index) const noexcept {
272 }
273
274 template<typename Acc,typename... Args>
275 requires std::invocable<Acc,ObjectRange<CI,ColumnarModeArray>,Args...>
276 [[nodiscard]] decltype(auto) operator() (Acc& acc, Args&&... args) const {
277 return acc (*this, std::forward<Args> (args)...);}
278
280 [[nodiscard]] std::size_t getIndexInRange (const ObjectId<CI,CM>& obj) const {
281 return obj.getIndex() - m_beginIndex; }
282
283
284
287 public:
288
289 explicit ObjectRange (void **val_data, std::size_t val_beginIndex,
290 std::size_t val_endIndex) noexcept
291 : m_data (val_data), m_beginIndex (val_beginIndex), m_endIndex (val_endIndex)
292 {}
293
294 [[nodiscard]] void **getData () const noexcept {
295 return m_data;}
296
297
298
301 private:
302
303 void **m_data = nullptr;
304 std::size_t m_beginIndex = 0u;
305 std::size_t m_endIndex = 0u;
306 };
307
311
312 template<ContainerIdConcept CI,int stepSize> class ObjectRangeIteratorArray final
313 {
314 public:
315
317
318 ObjectRangeIteratorArray (void **val_data, std::size_t val_index) noexcept
319 : m_data (val_data), m_index (val_index) {}
320
324
326 m_index += stepSize; return *this;}
327
328 bool operator == (const ObjectRangeIteratorArray<CI,stepSize>& that) const noexcept {
329 return m_index == that.m_index;}
330 bool operator != (const ObjectRangeIteratorArray<CI,stepSize>& that) const noexcept {
331 return m_index != that.m_index;}
332
333 private:
334 void **m_data = nullptr;
335 std::size_t m_index = 0u;
336 };
337}
338
339#endif
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
a class representing a single object (electron, muons, etc.)
an iterator over objects in an ObjectRange
ObjectId< CI, CM > operator*() const noexcept
bool operator==(const ObjectRangeIteratorArray< CI, stepSize > &that) const noexcept
bool operator!=(const ObjectRangeIteratorArray< CI, stepSize > &that) const noexcept
ObjectRangeIteratorArray< CI, stepSize > & operator++() noexcept
ObjectRangeIteratorArray(void **val_data, std::size_t val_index) noexcept
ObjectRangeIteratorXAODContainer(IteratorType &&val_iterator) noexcept
bool operator==(const ObjectRangeIteratorXAODContainer< CI, IteratorType > &that) const noexcept
bool operator!=(const ObjectRangeIteratorXAODContainer< CI, IteratorType > &that) const noexcept
ObjectRangeIteratorXAODContainer< CI, IteratorType > & operator++() noexcept
ObjectId< CI, CM > operator*() const noexcept
bool operator==(const ObjectRangeIteratorXAODSinglet< CI > &that) const noexcept
ObjectRangeIteratorXAODSinglet(XAODObjectType *val_object) noexcept
typename CI::xAODObjectIdType XAODObjectType
bool operator!=(const ObjectRangeIteratorXAODSinglet< CI > &that) const noexcept
ObjectId< CI, CM > operator*() const noexcept
ObjectRangeIteratorXAODSinglet< CI > & operator++() noexcept
typename CI::xAODObjectRangeType xAODContainer
ObjectRangeIteratorArray< CI, 1 > begin() const noexcept
std::size_t beginIndex() const noexcept
ObjectRangeIteratorArray< CI,-1 > rbegin() const noexcept
ObjectRangeIteratorArray< CI,-1 > rend() const noexcept
std::size_t getIndexInRange(const ObjectId< CI, CM > &obj) const
get the index inside the given range
ObjectRangeIteratorArray< CI, 1 > end() const noexcept
ObjectRange(void **val_data, std::size_t val_beginIndex, std::size_t val_endIndex) noexcept
std::size_t getIndexInRange(const ObjectId< CI, CM > &obj) const
get the index inside the given range
Definition ObjectRange.h:94
ObjectRange(xAODContainer &val_singlet) noexcept
ObjectRange(xAODContainer &val_container) noexcept
Definition ObjectRange.h:35
xAODContainer & getXAODObjectNoexcept() const noexcept
Definition ObjectRange.h:47
typename CI::xAODObjectRangeType xAODContainer
Definition ObjectRange.h:32
xAODContainer & getXAODObject() const noexcept
Definition ObjectRange.h:39
a class representing a continuous sequence of objects (a.k.a. a container)
Definition index.py:1
std::map< std::string, HypoJetVector >::const_iterator CI