ATLAS Offline Software
Loading...
Searching...
No Matches
VectorColumn.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8#ifndef COLUMNAR_CORE_VECTOR_COLUMN_H
9#define COLUMNAR_CORE_VECTOR_COLUMN_H
10
13#include <span>
14#include <vector>
15
16namespace columnar
17{
28
29
30
31 namespace detail
32 {
33 template<typename CT,ColumnarMode CM>
34 requires (CM::useNestedVectors)
35 class MemoryAccessor<std::vector<CT>,CM> final
36 {
39 public:
40
42 static_assert (BaseAccessor::isDefined, "Element type for std::vector has no accessor defined. Please check includes and whether the type is supported.");
43
45
46 static constexpr bool isDefined = true;
47 static constexpr bool viewIsReference = false;
48 static constexpr bool hasSetter = false;
50 using MemoryType = std::vector<ElementType>;
51
52 static void updateColumnInfo (ColumnInfo& /*info*/)
53 {}
54
55 [[nodiscard]] static auto makeViewer (void** dataArea)
56 {
58 return [] (const MemoryType& value) {return std::span<const ElementType> (value);};
59 else
60 {
61 return [viewer = BaseAccessor::makeViewer(dataArea)] (const MemoryType& value) {return VectorConvertView (viewer, std::span<const ElementType> (value));};
62 }
63 }
64 };
65
66
67
68
69 // the column accessor for std::vector in ColumnarModeArray
70 //
71 // This is one of the more tricky accessors, as it need to connect to
72 // two underlying columns. The first column is the offset column, the
73 // second is the data column.
74 template<typename CT>
77 {
80 public:
81
84
85 static constexpr bool isDefined = true;
87
89
90 ContainerFreeAccessor (ColumnarTool<CM>& columnarTool, ColumnAccessorOptions&& options, ColumnAccessorOptionsArray&& optionsArray)
91 {
92 std::string offsetColumn;
93 if (optionsArray.numOffsets + internalOffsetColumns == 1u)
94 offsetColumn = optionsArray.baseName + ".offset";
95 else if (optionsArray.numOffsets + internalOffsetColumns == 2u)
96 {
97 if (optionsArray.numOffsets == 0u)
98 offsetColumn = optionsArray.baseName + ".outerOffset";
99 else
100 offsetColumn = optionsArray.baseName + ".innerOffset";
101 } else
102 {
103 offsetColumn = optionsArray.baseName + ".offset" + std::to_string(optionsArray.numOffsets);
104 }
105
106 auto offsetInfo = options.makeColumnInfo();
107 offsetInfo.offsetName = optionsArray.offsetName;
108 offsetInfo.isOffset = true;
109 m_offsetData = std::make_unique<ColumnAccessorDataArray> (&m_offsetIndex, &m_offsetData, &typeid (ColumnarOffsetType), ColumnAccessMode::input);
110 columnarTool.addColumn (offsetColumn, m_offsetData.get(), std::move (offsetInfo));
111 auto dataOptions = optionsArray;
112 dataOptions.offsetName = offsetColumn;
113 dataOptions.dataSuffix = ".data";
114 dataOptions.numOffsets += 1u;
115 m_dataAccessor = ContainerFreeAccessor<CT,ColumnAccessMode::input,CM> (columnarTool, std::move (options), std::move (dataOptions));
116 }
117
119 : m_dataAccessor (std::move (that.m_dataAccessor))
120 {
121 moveAccessor (m_offsetIndex, m_offsetData, that.m_offsetIndex, that.m_offsetData);
122 }
123
125 {
126 if (this != &that)
127 {
128 moveAccessor (m_offsetIndex, m_offsetData, that.m_offsetIndex, that.m_offsetData);
129 m_dataAccessor = std::move (that.m_dataAccessor);
130 }
131 return *this;
132 }
133
134 auto operator () (void** dataArea, std::size_t index) const noexcept
135 {
136 auto *offset = static_cast<const ColumnarOffsetType*>(dataArea[m_offsetIndex]);
137 return m_dataAccessor(dataArea, offset[index], offset[index+1]);
138 }
139
140 auto operator () (void** dataArea, std::size_t beginIndex, std::size_t endIndex) const noexcept
141 {
142 auto *offset = static_cast<const ColumnarOffsetType*>(dataArea[m_offsetIndex]);
143 return detail::VectorConvertView ([&dataAccessor = m_dataAccessor, dataArea] (const auto& internalIndex) noexcept {
144 const ColumnarOffsetType& thisEndIndex = (&internalIndex)[1];
145 return dataAccessor (dataArea, internalIndex, thisEndIndex);},
146 std::span<const ColumnarOffsetType> (offset + beginIndex, offset + endIndex));
147 }
148
149 bool isAvailable (void** dataArea) const noexcept
150 {
151 return m_dataAccessor.isAvailable (dataArea);
152 }
153
156 private:
157
158 unsigned m_offsetIndex = 0u;
159 std::unique_ptr<ColumnAccessorDataArray> m_offsetData;
161 };
162 }
163}
164
165#endif
the base class for all columnar components
ContainerFreeAccessor< CT, ColumnAccessMode::input, ColumnarModeArray > m_dataAccessor
ContainerFreeAccessor(ColumnarTool< CM > &columnarTool, ColumnAccessorOptions &&options, ColumnAccessorOptionsArray &&optionsArray)
a help implementation of AccessorTemplate that handles type conversions
VectorConvertView(FunctionType &&, ViewType &&) -> VectorConvertView< std::decay_t< FunctionType >, std::decay_t< ViewType > >
void moveAccessor(unsigned &dataIndex, std::unique_ptr< ColumnAccessorDataArray > &accessorData, unsigned &sourceIndex, std::unique_ptr< ColumnAccessorDataArray > &sourceData)
ColumnAccessMode
an enum for the different access modes for a column
Definition ColumnInfo.h:19
@ input
an input column
Definition ColumnInfo.h:21
std::size_t ColumnarOffsetType
the type used for the size and offsets in the columnar data
Definition index.py:1
STL namespace.
a struct that contains meta-information about each column that's needed to interface the column with ...
Definition ColumnInfo.h:35