ATLAS Offline Software
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 
12 #include <ColumnarCore/ObjectId.h>
14 #include <exception>
15 
16 namespace 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.
43  auto *container ATLAS_THREAD_SAFE = m_container;
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.
51  auto *container ATLAS_THREAD_SAFE = m_container;
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.
58  auto *container ATLAS_THREAD_SAFE = m_container;
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.
64  auto *container ATLAS_THREAD_SAFE = m_container;
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.
70  auto *container ATLAS_THREAD_SAFE = m_container;
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.
76  auto *container ATLAS_THREAD_SAFE = m_container;
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 
103  xAODContainer *m_container = nullptr;
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 
120  ++ m_iterator; return *this;}
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 
188  xAODContainer *m_singlet = nullptr;
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 
231  return ObjectRangeIteratorArray<CI,1> (m_data, m_beginIndex);}
233  return ObjectRangeIteratorArray<CI,1> (m_data, m_endIndex);}
235  // note that as a reverse iterator, the meaning of begin and end
236  // is reversed, and the new "end" can be -1.
237  return ObjectRangeIteratorArray<CI,-1> (m_data, m_endIndex-1);}
239  // note that as a reverse iterator, the meaning of begin and end
240  // is reversed, and the new "end" can be -1.
241  return ObjectRangeIteratorArray<CI,-1> (m_data, m_beginIndex-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 {
271  return ObjectId<CI,CM> (m_data, index + m_beginIndex);
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 
322  return ObjectId<CI,CM> (m_data, m_index);
323  }
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
columnar::ObjectRange< CI, ColumnarModeXAOD >::getXAODObject
xAODContainer & getXAODObject() const noexcept
Definition: ObjectRange.h:39
columnar::ObjectRangeIteratorXAODContainer::operator*
ObjectId< CI, CM > operator*() const noexcept
Definition: ObjectRange.h:115
columnar::ObjectRange< CI, ColumnarModeXAOD >::end
auto end() const noexcept
Definition: ObjectRange.h:60
columnar::ObjectRangeIteratorArray::m_data
void ** m_data
Definition: ObjectRange.h:334
columnar::ObjectRangeIteratorXAODContainer::m_iterator
IteratorType m_iterator
Definition: ObjectRange.h:128
columnar::ObjectRangeIteratorXAODSinglet::m_object
XAODObjectType * m_object
Definition: ObjectRange.h:213
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:47
columnar::ObjectRangeIteratorXAODSinglet::operator!=
bool operator!=(const ObjectRangeIteratorXAODSinglet< CI > &that) const noexcept
Definition: ObjectRange.h:209
columnar::ObjectRange< CI, ColumnarModeArray >::size
std::size_t size() const noexcept
Definition: ObjectRange.h:260
index
Definition: index.py:1
columnar::ObjectRangeIteratorXAODSinglet::operator++
ObjectRangeIteratorXAODSinglet< CI > & operator++() noexcept
Definition: ObjectRange.h:204
m_data
std::vector< T > m_data
Definition: TrackTruthMatchingBaseAlg.cxx:660
columnar::getXAODObject
xAODContainer & getXAODObject() const noexcept
Definition: ObjectRange.h:151
columnar::ObjectRange< CI, ColumnarModeArray >::ObjectRange
ObjectRange(const xAODContainer &)
Definition: ObjectRange.h:252
columnar::getXAODObjectNoexcept
xAODContainer & getXAODObjectNoexcept() const noexcept
Definition: ObjectRange.h:155
columnar::ObjectRangeIteratorXAODContainer::operator!=
bool operator!=(const ObjectRangeIteratorXAODContainer< CI, IteratorType > &that) const noexcept
Definition: ObjectRange.h:124
columnar::ObjectRangeIteratorArray::operator++
ObjectRangeIteratorArray< CI, stepSize > & operator++() noexcept
Definition: ObjectRange.h:325
columnar::ObjectRange< CI, ColumnarModeArray >::empty
bool empty() const noexcept
Definition: ObjectRange.h:257
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
Args
Definition: test_lwtnn_fastgraph.cxx:12
columnar::ObjectRange
a class representing a continuous sequence of objects (a.k.a. a container)
Definition: ContainerId.h:177
CI
std::map< std::string, HypoJetVector >::const_iterator CI
Definition: xAODJetCollector.h:18
columnar::ObjectRange< CI, ColumnarModeArray >::begin
ObjectRangeIteratorArray< CI, 1 > begin() const noexcept
Definition: ObjectRange.h:230
columnar::ObjectRangeIteratorArray::operator==
bool operator==(const ObjectRangeIteratorArray< CI, stepSize > &that) const noexcept
Definition: ObjectRange.h:328
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
columnar::ObjectRangeIteratorArray::operator*
ObjectId< CI, CM > operator*() const noexcept
Definition: ObjectRange.h:321
columnar::ObjectRange< CI, ColumnarModeArray >::xAODContainer
typename CI::xAODObjectRangeType xAODContainer
Definition: ObjectRange.h:227
columnar::rend
auto rend() const noexcept
Definition: ObjectRange.h:164
columnar::ObjectRangeIteratorXAODContainer::ObjectRangeIteratorXAODContainer
ObjectRangeIteratorXAODContainer(IteratorType &&val_iterator) noexcept
Definition: ObjectRange.h:112
columnar::ObjectRange< CI, ColumnarModeXAOD >::xAODContainer
typename CI::xAODObjectRangeType xAODContainer
Definition: ObjectRange.h:32
columnar::ObjectRange< CI, ColumnarModeXAOD >::getIndexInRange
std::size_t getIndexInRange(const ObjectId< CI, CM > &obj) const
get the index inside the given range
Definition: ObjectRange.h:94
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
columnar::ObjectRange< CI, ColumnarModeArray >::end
ObjectRangeIteratorArray< CI, 1 > end() const noexcept
Definition: ObjectRange.h:232
columnar::ObjectRange< CI, ColumnarModeXAOD >::size
std::size_t size() const noexcept
Definition: ObjectRange.h:82
columnar::ObjectRange< CI, ColumnarModeArray >::getIndexInRange
std::size_t getIndexInRange(const ObjectId< CI, CM > &obj) const
get the index inside the given range
Definition: ObjectRange.h:280
columnar::ObjectRange< CI, ColumnarModeArray >::getData
void ** getData() const noexcept
Definition: ObjectRange.h:294
columnar::ObjectRangeIteratorArray
an iterator over objects in an ObjectRange
Definition: ObjectRange.h:219
columnar::size
std::size_t size() const noexcept
Definition: ObjectRange.h:170
columnar::ObjectRange< CI, ColumnarModeXAOD >::empty
bool empty() const noexcept
Definition: ObjectRange.h:79
columnar::ObjectRange
ObjectRange(xAODContainer &val_singlet) noexcept
Definition: ObjectRange.h:147
columnar::ObjectRangeIteratorArray::ObjectRangeIteratorArray
ObjectRangeIteratorArray(void **val_data, std::size_t val_index) noexcept
Definition: ObjectRange.h:318
columnar::ObjectRange< CI, ColumnarModeArray >::beginIndex
std::size_t beginIndex() const noexcept
Definition: ObjectRange.h:243
columnar::final
CM final
Definition: ColumnAccessor.h:106
columnar::begin
auto begin() const noexcept
Definition: ObjectRange.h:158
columnar::ObjectRangeIteratorXAODContainer::operator++
ObjectRangeIteratorXAODContainer< CI, IteratorType > & operator++() noexcept
Definition: ObjectRange.h:119
columnar::ObjectRange< CI, ColumnarModeXAOD >::getXAODObjectNoexcept
xAODContainer & getXAODObjectNoexcept() const noexcept
Definition: ObjectRange.h:47
columnar::ObjectId
a class representing a single object (electron, muons, etc.)
Definition: ContainerId.h:178
columnar::ObjectRangeIteratorXAODContainer::operator==
bool operator==(const ObjectRangeIteratorXAODContainer< CI, IteratorType > &that) const noexcept
Definition: ObjectRange.h:122
columnar::ObjectRangeIteratorArray::m_index
std::size_t m_index
Definition: ObjectRange.h:335
columnar::operator[]
ObjectId< CI, CM > operator[](std::size_t) const noexcept
Definition: ObjectRange.h:173
ObjectId.h
columnar::ColumnarModeArray
Definition: ColumnarDef.h:33
columnar::ObjectRange< CI, ColumnarModeXAOD >::rbegin
auto rbegin() const noexcept
Definition: ObjectRange.h:66
columnar::ObjectRange< CI, ColumnarModeArray >::getXAODObject
xAODContainer & getXAODObject() const
Definition: ObjectRange.h:267
columnar::ObjectRange< CI, ColumnarModeArray >::rbegin
ObjectRangeIteratorArray< CI,-1 > rbegin() const noexcept
Definition: ObjectRange.h:234
columnar::empty
bool empty() const noexcept
Definition: ObjectRange.h:167
columnar::ObjectRange< CI, ColumnarModeXAOD >::begin
auto begin() const noexcept
Definition: ObjectRange.h:54
columnar
Definition: ClusterDef.h:16
ContainerId.h
columnar::ObjectRangeIteratorXAODSinglet::operator==
bool operator==(const ObjectRangeIteratorXAODSinglet< CI > &that) const noexcept
Definition: ObjectRange.h:207
columnar::ObjectRange< CI, ColumnarModeXAOD >::rend
auto rend() const noexcept
Definition: ObjectRange.h:72
columnar::ColumnarModeXAOD
Definition: ColumnarDef.h:18
columnar::requires
requires requires
Definition: VariantAccessor.h:22
columnar::end
auto end() const noexcept
Definition: ObjectRange.h:160
columnar::ObjectRangeIteratorXAODSinglet::ObjectRangeIteratorXAODSinglet
ObjectRangeIteratorXAODSinglet(XAODObjectType *val_object) noexcept
Definition: ObjectRange.h:198
columnar::ObjectRangeIteratorXAODContainer
Definition: ObjectRange.h:24
columnar::ObjectRange< CI, ColumnarModeXAOD >::ObjectRange
ObjectRange(xAODContainer &val_container) noexcept
Definition: ObjectRange.h:35
columnar::m_singlet
xAODContainer * m_singlet
Definition: ObjectRange.h:188
columnar::ObjectRange< CI, ColumnarModeArray >::ObjectRange
ObjectRange(void **val_data, std::size_t val_beginIndex, std::size_t val_endIndex) noexcept
Definition: ObjectRange.h:289
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
columnar::ObjectRangeIteratorXAODSinglet::operator*
ObjectId< CI, CM > operator*() const noexcept
Definition: ObjectRange.h:201
checker_macros.h
Define macros for attributes used to control the static checker.
columnar::rbegin
auto rbegin() const noexcept
Definition: ObjectRange.h:162
python.PyAthena.obj
obj
Definition: PyAthena.py:132
columnar::ObjectRangeIteratorXAODSinglet::XAODObjectType
typename CI::xAODObjectIdType XAODObjectType
Definition: ObjectRange.h:196
columnar::ObjectRange< CI, ColumnarModeArray >::endIndex
std::size_t endIndex() const noexcept
Definition: ObjectRange.h:245
columnar::ObjectRangeIteratorArray::operator!=
bool operator!=(const ObjectRangeIteratorArray< CI, stepSize > &that) const noexcept
Definition: ObjectRange.h:330
columnar::ObjectRangeIteratorXAODSinglet
Definition: ObjectRange.h:133
columnar::ObjectRange< CI, ColumnarModeArray >::rend
ObjectRangeIteratorArray< CI,-1 > rend() const noexcept
Definition: ObjectRange.h:238