ATLAS Offline Software
ObjectColumnArray.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /// @author Nils Krumnack
6 
7 
8 #include <ColumnarCore/ColumnarTool.h>
9 #include <ColumnarCore/ColumnAccessorDataArray.h>
10 #include <ColumnarCore/ObjectId.h>
11 #include <ColumnarCore/ObjectRange.h>
12 #include <ColumnarCore/ContainerId.h>
13 #include <cassert>
14 
15 namespace columnar
16 {
17  template<ContainerIdConcept CI>
18  class AccessorTemplate<CI,ObjectColumn,ColumnAccessMode::input,ColumnarModeArray> final
19  {
20  /// Common Public Members
21  /// =====================
22  public:
23 
24  static_assert (CI::perEventRange || CI::perEventId, "ObjectColumn can only be used with per-event ranges or IDs");
25 
26  using CM = ColumnarModeArray;
27 
28  AccessorTemplate () = default;
29 
30  AccessorTemplate (ColumnarTool<CM>& columnBase,
31  const std::string& name,
32  ColumnInfo&& info = {})
33  : m_columnBase (&columnBase),
34  m_name (name)
35  {
36  if (!name.empty())
37  columnBase.setContainerUserName (CI::idName, name);
38  m_offsetsData = std::make_unique<ColumnAccessorDataArray> (&m_offsetsIndex, &m_offsetsData, &typeid (ColumnarOffsetType), ColumnAccessMode::input);
39  info.offsetName = (CI::perEventRange ? numberOfEventsName : "");
40  info.isOffset = true;
41  columnBase.addColumn (std::string (CI::idName), m_offsetsData.get(), std::move(info));
42  }
43 
44  AccessorTemplate (AccessorTemplate&& that)
45  {
46  moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
47  }
48 
49  // cppcheck-suppress operatorEqVarError; m_columnBase not copied
50  AccessorTemplate& operator = (AccessorTemplate&& that)
51  {
52  if (this != &that)
53  moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
54  return *this;
55  }
56 
57  AccessorTemplate (const AccessorTemplate&) = delete;
58  AccessorTemplate& operator = (const AccessorTemplate&) = delete;
59 
60  ObjectRange<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
61  requires (CI::perEventRange)
62  {
63  auto *offsets = static_cast<const ColumnarOffsetType*>(eventId.getData()[m_offsetsIndex]);
64  return ObjectRange<CI,CM> (eventId.getData(), offsets[eventId.getIndex()], offsets[eventId.getIndex() + 1]);
65  }
66 
67  ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
68  requires (CI::perEventRange)
69  {
70  auto *offsets = static_cast<const ColumnarOffsetType*>(eventRange.getData()[m_offsetsIndex]);
71  return ObjectRange<CI,CM> (eventRange.getData(), offsets[eventRange.beginIndex()], offsets[eventRange.endIndex()]);
72  }
73 
74  ObjectId<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
75  requires (CI::perEventId)
76  {
77  return ObjectId<CI,CM> (eventId.getData(), eventId.getIndex());
78  }
79 
80  ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
81  requires (CI::perEventId)
82  {
83  return ObjectRange<CI,CM> (eventRange.getData(), eventRange.beginIndex(), eventRange.endIndex());
84  }
85 
86  [[nodiscard]] bool isAvailable (ObjectId<ContainerId::eventContext,CM> eventId) const noexcept
87  {
88  auto *offsets = static_cast<const ColumnarOffsetType*>(eventId.getData()[m_offsetsIndex]);
89  return offsets != nullptr;
90  }
91 
92 
93 
94  /// Private Members
95  /// ===============
96  private:
97 
98  ColumnarTool<CM> *m_columnBase = nullptr;
99 
100  std::string m_name;
101  unsigned m_offsetsIndex = 0;
102  std::unique_ptr<ColumnAccessorDataArray> m_offsetsData;
103  };
104 }