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 (ColumnarTool<CM>& columnBase,
29  const std::string& name)
30  : m_columnBase (&columnBase),
31  m_name (name)
32  {
33  columnBase.setContainerStoreName (CI::idName, name);
34  m_offsetsData = std::make_unique<ColumnAccessorDataArray> (&m_offsetsIndex, &m_offsetsData, &typeid (ColumnarOffsetType), ColumnAccessMode::input);
35  columnBase.addColumn (name, m_offsetsData.get(), {.offsetName = (CI::perEventRange ? numberOfEventsName : ""), .isOffset = true});
36  }
37 
38  AccessorTemplate (AccessorTemplate&& that)
39  {
40  moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
41  }
42 
43  // cppcheck-suppress operatorEqVarError; m_columnBase not copied
44  AccessorTemplate& operator = (AccessorTemplate&& that)
45  {
46  if (this != &that)
47  moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
48  return *this;
49  }
50 
51  AccessorTemplate (const AccessorTemplate&) = delete;
52  AccessorTemplate& operator = (const AccessorTemplate&) = delete;
53 
54  ObjectRange<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
55  requires (CI::perEventRange)
56  {
57  auto *offsets = static_cast<const ColumnarOffsetType*>(eventId.getData()[m_offsetsIndex]);
58  return ObjectRange<CI,CM> (eventId.getData(), offsets[eventId.getIndex()], offsets[eventId.getIndex() + 1]);
59  }
60 
61  ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
62  requires (CI::perEventRange)
63  {
64  auto *offsets = static_cast<const ColumnarOffsetType*>(eventRange.getData()[m_offsetsIndex]);
65  return ObjectRange<CI,CM> (eventRange.getData(), offsets[eventRange.beginIndex()], offsets[eventRange.endIndex()]);
66  }
67 
68  ObjectId<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
69  requires (CI::perEventId)
70  {
71  return ObjectId<CI,CM> (eventId.getData(), eventId.getIndex());
72  }
73 
74  ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
75  requires (CI::perEventId)
76  {
77  return ObjectRange<CI,CM> (eventRange.getData(), eventRange.beginIndex(), eventRange.endIndex());
78  }
79 
80 
81 
82  /// Private Members
83  /// ===============
84  private:
85 
86  ColumnarTool<CM> *m_columnBase = nullptr;
87 
88  std::string m_name;
89  unsigned m_offsetsIndex = 0;
90  std::unique_ptr<ColumnAccessorDataArray> m_offsetsData;
91  };
92 }