2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5 /// @author Nils Krumnack
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>
17 template<ContainerIdConcept CI>
18 class AccessorTemplate<CI,ObjectColumn,ColumnAccessMode::input,ColumnarModeArray> final
20 /// Common Public Members
21 /// =====================
24 static_assert (CI::perEventRange || CI::perEventId, "ObjectColumn can only be used with per-event ranges or IDs");
26 using CM = ColumnarModeArray;
28 AccessorTemplate () = default;
30 AccessorTemplate (ColumnarTool<CM>& columnBase,
31 const std::string& name,
32 ColumnInfo&& info = {})
33 : m_columnBase (&columnBase),
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 : "");
41 columnBase.addColumn (std::string (CI::idName), m_offsetsData.get(), std::move(info));
44 AccessorTemplate (AccessorTemplate&& that)
46 moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
49 // cppcheck-suppress operatorEqVarError; m_columnBase not copied
50 AccessorTemplate& operator = (AccessorTemplate&& that)
53 moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
57 AccessorTemplate (const AccessorTemplate&) = delete;
58 AccessorTemplate& operator = (const AccessorTemplate&) = delete;
60 ObjectRange<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
61 requires (CI::perEventRange)
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]);
67 ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
68 requires (CI::perEventRange)
70 auto *offsets = static_cast<const ColumnarOffsetType*>(eventRange.getData()[m_offsetsIndex]);
71 return ObjectRange<CI,CM> (eventRange.getData(), offsets[eventRange.beginIndex()], offsets[eventRange.endIndex()]);
74 ObjectId<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
75 requires (CI::perEventId)
77 return ObjectId<CI,CM> (eventId.getData(), eventId.getIndex());
80 ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
81 requires (CI::perEventId)
83 return ObjectRange<CI,CM> (eventRange.getData(), eventRange.beginIndex(), eventRange.endIndex());
86 [[nodiscard]] bool isAvailable (ObjectId<ContainerId::eventContext,CM> eventId) const noexcept
88 auto *offsets = static_cast<const ColumnarOffsetType*>(eventId.getData()[m_offsetsIndex]);
89 return offsets != nullptr;
98 ColumnarTool<CM> *m_columnBase = nullptr;
101 unsigned m_offsetsIndex = 0;
102 std::unique_ptr<ColumnAccessorDataArray> m_offsetsData;