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,ColumnarArrayMode CM>
18 class AccessorTemplate<CI,ObjectColumn,ColumnAccessMode::input,CM> 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 AccessorTemplate () = default;
28 AccessorTemplate (ColumnarTool<CM>& columnBase,
29 const std::string& name,
30 ColumnAccessorOptions&& options = {})
31 : m_columnBase (&columnBase),
35 columnBase.setContainerUserName (CI::idName, name);
36 m_offsetsData = std::make_unique<ColumnAccessorDataArray> (&m_offsetsIndex, &m_offsetsData, &typeid (ColumnarOffsetType), ColumnAccessMode::input);
37 auto info = options.makeColumnInfo();
38 info.offsetName = (CI::perEventRange ? numberOfEventsName : "");
40 columnBase.addColumn (std::string (CI::idName), m_offsetsData.get(), std::move (info));
43 AccessorTemplate (AccessorTemplate&& that)
45 moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
48 // cppcheck-suppress operatorEqVarError; m_columnBase not copied
49 AccessorTemplate& operator = (AccessorTemplate&& that)
52 moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
56 AccessorTemplate (const AccessorTemplate&) = delete;
57 AccessorTemplate& operator = (const AccessorTemplate&) = delete;
59 ObjectRange<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
60 requires (CI::perEventRange)
62 auto *offsets = static_cast<const ColumnarOffsetType*>(eventId.getDataArea()[m_offsetsIndex]);
63 return ObjectRange<CI,CM> (eventId.getDataArea(), offsets[eventId.getIndex()], offsets[eventId.getIndex() + 1]);
66 ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
67 requires (CI::perEventRange)
69 auto *offsets = static_cast<const ColumnarOffsetType*>(eventRange.getDataArea()[m_offsetsIndex]);
70 return ObjectRange<CI,CM> (eventRange.getDataArea(), offsets[eventRange.beginIndex()], offsets[eventRange.endIndex()]);
73 ObjectId<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
74 requires (CI::perEventId)
76 return ObjectId<CI,CM> (eventId.getDataArea(), eventId.getIndex());
79 ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
80 requires (CI::perEventId)
82 return ObjectRange<CI,CM> (eventRange.getDataArea(), eventRange.beginIndex(), eventRange.endIndex());
85 [[nodiscard]] bool isAvailable (ObjectId<ContainerId::eventContext,CM> eventId) const noexcept
87 auto *offsets = static_cast<const ColumnarOffsetType*>(eventId.getDataArea()[m_offsetsIndex]);
88 return offsets != nullptr;
97 ColumnarTool<CM> *m_columnBase = nullptr;
100 unsigned m_offsetsIndex = 0;
101 std::unique_ptr<ColumnAccessorDataArray> m_offsetsData;