ATLAS Offline Software
Loading...
Searching...
No Matches
ColumnVectorWrapper.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_TOOL_WRAPPER_COLUMN_VECTOR_WRAPPER_H
9#define COLUMNAR_TOOL_WRAPPER_COLUMN_VECTOR_WRAPPER_H
10
11#include <span>
12#include <string>
13#include <typeinfo>
14#include <vector>
15
16namespace columnar
17{
18 struct ColumnInfo;
19 class IColumnarTool;
20
21
28
30 {
42 std::string debugName;
43
44
46 const std::type_info *type = nullptr;
47
48
50 bool isOptional = true;
51
52
57 bool readOnly = true;
58
59
67 bool isOffset = false;
68
69
75 unsigned arraySize = 1u;
76
77
84 std::size_t offsetIndex = 0u;
85 };
86
87
88
95
97 {
100 public:
101
103 static constexpr std::size_t nullIndex = 0u;
104
106 static constexpr std::size_t sizeIndex = 1u;
107
109 static constexpr std::size_t unsetIndex = static_cast<std::size_t>(-1);
110
112 static constexpr std::size_t numFixedColumns = 2u;
113
116
117
119 [[nodiscard]] std::size_t addColumn (const ColumnInfo& columnInfo);
120
122 void setOffsetColumn (std::size_t columnIndex, std::size_t offsetIndex);
123
124
126 [[nodiscard]] std::size_t numColumns () const noexcept {
127 return m_elements.size(); }
128
130 [[nodiscard]] const ColumnVectorElementHeader&
131 getColumn (std::size_t index) const {
132 return m_elements.at (index); }
133
134
136 void checkSelf () const;
137
139 void checkData (std::span<const void*const> data) const;
140
141
144 private:
145
147 std::vector<ColumnVectorElementHeader> m_elements;
148 };
149
150
151
156
158 {
161 public:
162
164 explicit ColumnVectorData (const ColumnVectorHeader *val_header);
165
166
168 template<typename CT>
169 void setColumn (std::size_t columnIndex, std::size_t size, CT* dataPtr) {
170 auto voidPtr = reinterpret_cast<const void*>(const_cast<const CT*>(dataPtr));
171 setColumnVoid (columnIndex, size, voidPtr, typeid (std::decay_t<CT>), std::is_const_v<CT>);
172 }
173 void setColumnVoid (std::size_t columnIndex, std::size_t size, const void *dataPtr, const std::type_info& type, bool isConst);
174
175
177 template<typename CT>
178 [[nodiscard]] std::pair<std::size_t,CT*>
179 getColumn (std::size_t columnIndex)
180 {
181 auto [size, ptr] = getColumnVoid (columnIndex, &typeid (std::decay_t<CT>), std::is_const_v<CT>);
182 if constexpr (std::is_const_v<CT>)
183 return std::make_pair (size, static_cast<CT*>(ptr));
184 else
185 return std::make_pair (size, static_cast<CT*>(const_cast<void*>(ptr)));
186 }
187 [[nodiscard]] std::pair<std::size_t,const void*>
188 getColumnVoid (std::size_t columnIndex, const std::type_info *type, bool isConst);
189
190
192 void checkData () const {
193 m_header->checkData (m_data);
194 }
195
198 void callNoCheck (const IColumnarTool& tool);
199
200
203 private:
204
205 const ColumnVectorHeader *m_header = nullptr;
206 std::vector<void*> m_data;
207 std::vector<std::size_t> m_dataSize;
208 };
209}
210
211#endif
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::pair< std::size_t, const void * > getColumnVoid(std::size_t columnIndex, const std::type_info *type, bool isConst)
void setColumnVoid(std::size_t columnIndex, std::size_t size, const void *dataPtr, const std::type_info &type, bool isConst)
const ColumnVectorHeader * m_header
void checkData() const
do a basic check of the data vector
void callNoCheck(const IColumnarTool &tool)
call the tool with the assembled data, without performing any checks on the data
void setColumn(std::size_t columnIndex, std::size_t size, CT *dataPtr)
set the data for the given column
std::pair< std::size_t, CT * > getColumn(std::size_t columnIndex)
get the data for the given column
std::vector< std::size_t > m_dataSize
ColumnVectorData(const ColumnVectorHeader *val_header)
standard constructor
the header information for the entire columnar data vector
std::size_t addColumn(const ColumnInfo &columnInfo)
add a column for the given ColumnInfo, returning its index
void setOffsetColumn(std::size_t columnIndex, std::size_t offsetIndex)
set the index of the offset column for the given column
static constexpr std::size_t nullIndex
the index used for an invalid index (always has to be 0)
void checkData(std::span< const void *const > data) const
do a basic check of the data vector
static constexpr std::size_t numFixedColumns
the number of fix elements in the columnar data vector
void checkSelf() const
check the self-consistency of the header
static constexpr std::size_t unsetIndex
the number used for an unset but non-null index
std::vector< ColumnVectorElementHeader > m_elements
the elements in the columnar data vector
std::size_t numColumns() const noexcept
the number of columns in the columnar data vector
const ColumnVectorElementHeader & getColumn(std::size_t index) const
get the column for the given index
ColumnVectorHeader()
standard contructor
static constexpr std::size_t sizeIndex
the index used for the column size column
an interface for tools that operate on columnar data
Definition index.py:1
a struct that contains meta-information about each column that's needed to interface the column with ...
Definition ColumnInfo.h:35
the header information for a single element in the columnar data vector
bool isOffset
whether this is an offset column
unsigned arraySize
the total size of all inner array dimensions
bool readOnly
whether this column will only be used for read access
std::size_t offsetIndex
the index of the offset column (or nullIndex for none)
const std::type_info * type
the type to use for the column
bool isOptional
whether this column is optional
std::string debugName
the name of the column to use in messages