ATLAS Offline Software
Loading...
Searching...
No Matches
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
15namespace columnar
16{
17 template<ContainerIdConcept CI,ColumnarArrayMode CM>
18 class AccessorTemplate<CI,ObjectColumn,ColumnAccessMode::input,CM> 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 AccessorTemplate () = default;
27
28 AccessorTemplate (ColumnarTool<CM>& columnBase,
29 const std::string& name,
30 ColumnAccessorOptions&& options = {})
31 : m_columnBase (&columnBase),
32 m_name (name)
33 {
34 if (!name.empty())
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 : "");
39 info.isOffset = true;
40 columnBase.addColumn (std::string (CI::idName), m_offsetsData.get(), std::move (info));
41 }
42
43 AccessorTemplate (AccessorTemplate&& that)
44 {
45 moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
46 }
47
48 // cppcheck-suppress operatorEqVarError; m_columnBase not copied
49 AccessorTemplate& operator = (AccessorTemplate&& that)
50 {
51 if (this != &that)
52 moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
53 return *this;
54 }
55
56 AccessorTemplate (const AccessorTemplate&) = delete;
57 AccessorTemplate& operator = (const AccessorTemplate&) = delete;
58
59 ObjectRange<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
60 requires (CI::perEventRange)
61 {
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]);
64 }
65
66 ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
67 requires (CI::perEventRange)
68 {
69 auto *offsets = static_cast<const ColumnarOffsetType*>(eventRange.getDataArea()[m_offsetsIndex]);
70 return ObjectRange<CI,CM> (eventRange.getDataArea(), offsets[eventRange.beginIndex()], offsets[eventRange.endIndex()]);
71 }
72
73 ObjectId<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
74 requires (CI::perEventId)
75 {
76 return ObjectId<CI,CM> (eventId.getDataArea(), eventId.getIndex());
77 }
78
79 ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
80 requires (CI::perEventId)
81 {
82 return ObjectRange<CI,CM> (eventRange.getDataArea(), eventRange.beginIndex(), eventRange.endIndex());
83 }
84
85 [[nodiscard]] bool isAvailable (ObjectId<ContainerId::eventContext,CM> eventId) const noexcept
86 {
87 auto *offsets = static_cast<const ColumnarOffsetType*>(eventId.getDataArea()[m_offsetsIndex]);
88 return offsets != nullptr;
89 }
90
91
92
93 /// Private Members
94 /// ===============
95 private:
96
97 ColumnarTool<CM> *m_columnBase = nullptr;
98
99 std::string m_name;
100 unsigned m_offsetsIndex = 0;
101 std::unique_ptr<ColumnAccessorDataArray> m_offsetsData;
102 };
103}