ATLAS Offline Software
Loading...
Searching...
No Matches
VectorColumn.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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,ColumnarModeConcept 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 [[nodiscard]] static auto makeViewer (void** dataArea)
53 {
55 return [] (const MemoryType& value) {return std::span<const ElementType> (value);};
56 else
57 {
58 return [viewer = BaseAccessor::makeViewer(dataArea)] (const MemoryType& value) {return VectorConvertView (viewer, std::span<const ElementType> (value));};
59 }
60 }
61 };
62
63
64
65
66 // the column accessor for std::vector when using offset maps
67 //
68 // This is one of the more tricky accessors, as it need to connect to
69 // two underlying columns. The first column is the offset column, the
70 // second is the data column.
71 template<typename CT,ColumnarModeConcept CM>
72 requires (CM::useOffsetMaps && ContainerFreeAccessor<CT,ColumnAccessMode::input,CM>::isDefined)
73 class ContainerFreeAccessor<std::vector<CT>,ColumnAccessMode::input,CM> final
74 {
77 public:
78
80
81 static constexpr bool isDefined = true;
83
85
86 ContainerFreeAccessor (ColumnarTool<CM>& columnarTool, ColumnAccessorOptions&& options, ColumnAccessorOptionsArray&& optionsArray)
87 {
88 std::string offsetColumn;
89 if (optionsArray.numOffsets + internalOffsetColumns == 1u)
90 offsetColumn = optionsArray.baseName + ".offset";
91 else if (optionsArray.numOffsets + internalOffsetColumns == 2u)
92 {
93 if (optionsArray.numOffsets == 0u)
94 offsetColumn = optionsArray.baseName + ".outerOffset";
95 else
96 offsetColumn = optionsArray.baseName + ".innerOffset";
97 } else
98 {
99 offsetColumn = optionsArray.baseName + ".offset" + std::to_string(optionsArray.numOffsets);
100 }
101
102 auto offsetInfo = options.makeColumnInfo();
103 offsetInfo.offsetName = optionsArray.offsetName;
104 offsetInfo.isOffset = true;
106 m_offsetData = std::make_unique<ColumnAccessorDataArray> (&m_offsetIndex, &m_offsetData, &typeid (ColumnarOffsetType), ColumnAccessMode::input);
107 columnarTool.addColumn (offsetColumn, m_offsetData.get(), std::move (offsetInfo));
108 auto dataOptions = optionsArray;
109 dataOptions.offsetName = offsetColumn;
110 dataOptions.dataSuffix = ".data";
111 dataOptions.numOffsets += 1u;
112 m_dataAccessor = ContainerFreeAccessor<CT,ColumnAccessMode::input,CM> (columnarTool, std::move (options), std::move (dataOptions));
113 }
114
116 : m_dataAccessor (std::move (that.m_dataAccessor))
117 {
118 moveAccessor (m_offsetIndex, m_offsetData, that.m_offsetIndex, that.m_offsetData);
119 }
120
122 {
123 if (this != &that)
124 {
125 moveAccessor (m_offsetIndex, m_offsetData, that.m_offsetIndex, that.m_offsetData);
126 m_dataAccessor = std::move (that.m_dataAccessor);
127 }
128 return *this;
129 }
130
131 auto operator () (void** dataArea, std::size_t index) const
132 {
133 auto *offset = static_cast<const ColumnarOffsetType*>(dataArea[m_offsetIndex]);
134 return m_dataAccessor(dataArea, offset[index], offset[index+1]);
135 }
136
137 auto operator () (void** dataArea, std::size_t beginIndex, std::size_t endIndex) const
138 {
139 auto *offset = static_cast<const ColumnarOffsetType*>(dataArea[m_offsetIndex]);
140 return detail::VectorConvertView ([&dataAccessor = m_dataAccessor, dataArea] (const auto& internalIndex) {
141 const ColumnarOffsetType& thisEndIndex = (&internalIndex)[1];
142 return dataAccessor (dataArea, internalIndex, thisEndIndex);},
143 std::span<const ColumnarOffsetType> (offset + beginIndex, offset + endIndex));
144 }
145
146 bool isAvailable (void** dataArea) const noexcept
147 {
148 return m_dataAccessor.isAvailable (dataArea);
149 }
150
153 private:
154
155 unsigned m_offsetIndex = 0u;
156 std::unique_ptr<ColumnAccessorDataArray> m_offsetData;
158 };
159 }
160}
161
162#endif
void operator()(T1)
the base class for all columnar components
ContainerFreeAccessor< CT, ColumnAccessMode::input, CM > m_dataAccessor
ContainerFreeAccessor(ColumnarTool< CM > &columnarTool, ColumnAccessorOptions &&options, ColumnAccessorOptionsArray &&optionsArray)
a help implementation of AccessorTemplate that handles type conversions
Container id definitions for the columnar infrastructure.
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:20
@ input
an input column
Definition ColumnInfo.h:22
void setColumnType(ColumnInfo &info) noexcept
set the type information in the ColumnInfo for the given C++ type
Definition ColumnInfo.h:227
std::size_t ColumnarOffsetType
the type used for the size and offsets in the columnar data
Definition index.py:1
STL namespace.