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
12
13#include <cstdint>
14#include <span>
15#include <string>
16#include <typeinfo>
17#include <unordered_map>
18#include <vector>
19
20namespace columnar
21{
22 class IColumnarTool;
23
24
31
33 {
45 std::string debugName;
46
47
49 const std::type_info *type = nullptr;
50
51
53 bool isOptional = true;
54
55
60 bool readOnly = true;
61
62
70 bool isOffset = false;
71
72
78 unsigned arraySize = 1u;
79
80
87 std::size_t offsetIndex = 0u;
88
89
92
94 std::string offsetName;
95
97 std::string soleLinkTargetName;
98
100 std::uint32_t soleLinkTargetClid = 0;
101
103 bool isVariantLink = false;
104
106 std::vector<std::string> variantLinkTargetNames;
107
110
112 std::vector<unsigned> fixedDimensions;
113 };
114
115
116
123
125 {
128 public:
129
131 static constexpr std::size_t nullIndex = 0u;
132
134 static constexpr std::size_t sizeIndex = 1u;
135
137 static constexpr std::size_t unsetIndex = static_cast<std::size_t>(-1);
138
140 static constexpr std::size_t numFixedColumns = 2u;
141
144
145
147 [[nodiscard]] std::size_t addColumn (const ColumnInfo& columnInfo);
148
150 void setOffsetColumn (std::size_t columnIndex, std::size_t offsetIndex);
151
152
154 [[nodiscard]] std::size_t numColumns () const noexcept {
155 return m_elements.size(); }
156
158 [[nodiscard]] const ColumnVectorElementHeader&
159 getColumn (std::size_t index) const {
160 return m_elements.at (index); }
161
163 [[nodiscard]] std::size_t
164 getColumnIndex (const std::string& name) const noexcept {
165 auto iter = m_nameToIndex.find(name);
166 return (iter != m_nameToIndex.end()) ? iter->second : nullIndex; }
167
169 [[nodiscard]] std::unordered_map<std::string, ColumnInfo> getAllColumnInfo() const;
170
171
173 void checkSelf () const;
174
176 void checkData (std::span<const void*const> data) const;
177
178
181 private:
182
184 std::vector<ColumnVectorElementHeader> m_elements;
185
187 std::unordered_map<std::string, std::size_t> m_nameToIndex;
188 };
189
190
191
196
198 {
201 public:
202
204 explicit ColumnVectorData (const ColumnVectorHeader *val_header);
205
206
208 template<typename CT>
209 void setColumn (std::size_t columnIndex, std::size_t size, CT* dataPtr) {
210 auto voidPtr = reinterpret_cast<const void*>(const_cast<const CT*>(dataPtr));
211 setColumnVoid (columnIndex, size, voidPtr, typeid (std::decay_t<CT>), std::is_const_v<CT>);
212 }
213 void setColumnVoid (std::size_t columnIndex, std::size_t size, const void *dataPtr, const std::type_info& type, bool isConst);
214
215
217 template<typename CT>
218 [[nodiscard]] std::pair<std::size_t,CT*>
219 getColumn (std::size_t columnIndex)
220 {
221 auto [size, ptr] = getColumnVoid (columnIndex, &typeid (std::decay_t<CT>), std::is_const_v<CT>);
222 if constexpr (std::is_const_v<CT>)
223 return std::make_pair (size, static_cast<CT*>(ptr));
224 else
225 return std::make_pair (size, static_cast<CT*>(const_cast<void*>(ptr)));
226 }
227 [[nodiscard]] std::pair<std::size_t,const void*>
228 getColumnVoid (std::size_t columnIndex, const std::type_info *type, bool isConst) const;
229
230
232 void checkData () const {
233 m_header->checkData (m_data);
234 }
235
238 void callNoCheck (const IColumnarTool& tool);
239
240
243 private:
244
245 const ColumnVectorHeader *m_header = nullptr;
246 std::vector<void*> m_data;
247 std::vector<std::size_t> m_dataSize;
248 };
249}
250
251#endif
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
size_t size() const
Number of registered mappings.
std::pair< std::size_t, const void * > getColumnVoid(std::size_t columnIndex, const std::type_info *type, bool isConst) const
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
std::unordered_map< std::string, std::size_t > m_nameToIndex
map from column name to index for deduplication
static constexpr std::size_t unsetIndex
the number used for an unset but non-null index
std::size_t getColumnIndex(const std::string &name) const noexcept
get the column index for the given name, or nullIndex if not found
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
std::unordered_map< std::string, ColumnInfo > getAllColumnInfo() const
get all columns as a map of ColumnInfo for use with IColumnData::connect
static constexpr std::size_t sizeIndex
the index used for the column size column
an interface for tools that operate on columnar data
ColumnAccessMode
an enum for the different access modes for a column
Definition ColumnInfo.h:20
@ input
an input column
Definition ColumnInfo.h:22
Definition index.py:1
a struct that contains meta-information about each column that's needed to interface the column with ...
Definition ColumnInfo.h:36
the header information for a single element in the columnar data vector
std::vector< unsigned > fixedDimensions
the fixed dimensions (if any)
std::uint32_t soleLinkTargetClid
for simple link columns: the target container CLID (or 0)
bool isVariantLink
whether this is a variant link column
std::string soleLinkTargetName
for simple link columns: the target container name
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
ColumnAccessMode accessMode
the access mode for the column
std::string keyColumnForVariantLink
if this is a key column for a variant link, the name of the link column
std::string offsetName
the name of the offset column (or empty for none)
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
std::vector< std::string > variantLinkTargetNames
for variant link key columns: the target container names