ATLAS Offline Software
Loading...
Searching...
No Matches
columnar::ColumnVectorHeader Class Referencefinal

the header information for the entire columnar data vector More...

#include <ColumnVectorWrapper.h>

Collaboration diagram for columnar::ColumnVectorHeader:

Public Member Functions

 ColumnVectorHeader ()
 standard contructor
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
std::size_t numColumns () const noexcept
 the number of columns in the columnar data vector
const ColumnVectorElementHeadergetColumn (std::size_t index) const
 get the column for the given index
void checkSelf () const
 check the self-consistency of the header
void checkData (std::span< const void *const > data) const
 do a basic check of the data vector

Static Public Attributes

static constexpr std::size_t nullIndex = 0u
 the index used for an invalid index (always has to be 0)
static constexpr std::size_t sizeIndex = 1u
 the index used for the column size column
static constexpr std::size_t unsetIndex = static_cast<std::size_t>(-1)
 the number used for an unset but non-null index
static constexpr std::size_t numFixedColumns = 2u
 the number of fix elements in the columnar data vector

Private Attributes

std::vector< ColumnVectorElementHeaderm_elements
 the elements in the columnar data vector

Detailed Description

the header information for the entire columnar data vector

At its core this is just a vector of ColumnVectorElementHeader, with some extra helper functions. Note that this is completely independent of the tool used, and can indeed be used with multiple tools.

Definition at line 96 of file ColumnVectorWrapper.h.

Constructor & Destructor Documentation

◆ ColumnVectorHeader()

columnar::ColumnVectorHeader::ColumnVectorHeader ( )

standard contructor

Definition at line 28 of file ColumnVectorWrapper.cxx.

30 {
32
33 // we always reserve the first column as having a null value
34 m_elements.at(nullIndex).debugName = "<null>";
35 m_elements.at(nullIndex).isOptional = true;
36
37 // we always reserve the second column as the size column
38 m_elements.at(sizeIndex).debugName = "<size>";
39 m_elements.at(sizeIndex).type = &typeid(std::size_t);
40 m_elements.at(sizeIndex).isOptional = false;
41 m_elements.at(sizeIndex).readOnly = true;
42 }
static constexpr std::size_t nullIndex
the index used for an invalid index (always has to be 0)
static constexpr std::size_t numFixedColumns
the number of fix elements in the columnar data vector
std::vector< ColumnVectorElementHeader > m_elements
the elements in the columnar data vector
static constexpr std::size_t sizeIndex
the index used for the column size column

Member Function Documentation

◆ addColumn()

std::size_t columnar::ColumnVectorHeader::addColumn ( const ColumnInfo & columnInfo)
nodiscard

add a column for the given ColumnInfo, returning its index

Definition at line 46 of file ColumnVectorWrapper.cxx.

48 {
49 m_elements.emplace_back();
50 m_elements.at(sizeIndex).arraySize = m_elements.size();
51
52 auto& header = m_elements.back();
53 header.debugName = columnInfo.name;
54 header.type = columnInfo.type;
55
56 switch (columnInfo.accessMode)
57 {
59 break;
61 header.readOnly = false;
62 break;
64 header.readOnly = false;
65 break;
66 }
67 for (unsigned dim : columnInfo.fixedDimensions)
68 header.arraySize *= dim;
69 header.isOffset = columnInfo.isOffset;
70 if (!columnInfo.isOptional)
71 header.isOptional = false;
72 if (!columnInfo.offsetName.empty())
73 header.offsetIndex = unsetIndex;
74 return m_elements.size() - 1;
75 }
static constexpr std::size_t unsetIndex
the number used for an unset but non-null index
@ update
an updateable column
Definition ColumnInfo.h:27
@ output
an output column
Definition ColumnInfo.h:24
@ input
an input column
Definition ColumnInfo.h:21

◆ checkData()

void columnar::ColumnVectorHeader::checkData ( std::span< const void *const > data) const

do a basic check of the data vector

Definition at line 136 of file ColumnVectorWrapper.cxx.

138 {
139 if (data.size() != m_elements.size())
140 throw std::logic_error ("data vector has wrong size, expected " + std::to_string(m_elements.size()) + " but got " + std::to_string(data.size()));
141 if (data[nullIndex] != nullptr)
142 throw std::logic_error ("null column is not set to a nullptr value");
143 const auto* sizeVector = static_cast<const std::size_t*>(data[sizeIndex]);
144 for (std::size_t columnIndex = 0u; columnIndex != m_elements.size(); ++ columnIndex)
145 {
146 const auto& column = m_elements[columnIndex];
147 if (data[columnIndex] == nullptr)
148 {
149 if (column.isOptional)
150 continue;
151 if (column.offsetIndex != nullIndex && data[column.offsetIndex] == nullptr)
152 continue;
153 throw std::logic_error ("column " + column.debugName + " was not set");
154 }
155 if (column.isOffset)
156 {
157 const auto size = sizeVector[columnIndex];
158 if (size < 1)
159 throw std::runtime_error ("offset column " + column.debugName + " has size " + std::to_string(size) + ", but needs at least 1 element");
160 auto *offsets = static_cast<const ColumnarOffsetType*>(data[columnIndex]);
161 if (offsets[0] != 0)
162 throw std::runtime_error ("offset column doesn't start with 0: " + column.debugName);
163 for (std::size_t i = 1u; i != size; ++ i)
164 {
165 if (offsets[i] < offsets[i-1])
166 throw std::runtime_error ("offset column " + column.debugName + " is not monotonically increasing at index " + std::to_string(i) + ": " + std::to_string(offsets[i-1]) + " > " + std::to_string(offsets[i]));
167 }
168 }
169 }
170 for (std::size_t columnIndex = 0u; columnIndex != m_elements.size(); ++ columnIndex)
171 {
172 if (data[columnIndex] == nullptr)
173 continue;
174 const auto& column = m_elements[columnIndex];
175 std::size_t expectedSize = 1u;
176 if (column.offsetIndex != ColumnVectorHeader::nullIndex)
177 {
178 if (data[column.offsetIndex] == nullptr)
179 throw std::runtime_error ("column " + column.debugName + " uses offset column " + m_elements[column.offsetIndex].debugName + " that is not set");
180 const auto offsetIndex = column.offsetIndex;
181 auto *offsetsPtr = static_cast<const ColumnarOffsetType*>(data[offsetIndex]);
182 expectedSize = offsetsPtr[sizeVector[offsetIndex]-1];
183 }
184 expectedSize *= column.arraySize;
185
186 if (column.isOffset)
187 expectedSize += 1u;
188
189 if (sizeVector[columnIndex] != expectedSize)
190 throw std::runtime_error ("column size doesn't match expected size: " + column.debugName + ", found " + std::to_string (sizeVector[columnIndex]) + " vs exptected=" + std::to_string (expectedSize) + " isOffset=" + std::to_string (column.isOffset));
191 }
192 }
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::size_t ColumnarOffsetType
the type used for the size and offsets in the columnar data

◆ checkSelf()

void columnar::ColumnVectorHeader::checkSelf ( ) const

check the self-consistency of the header

Definition at line 97 of file ColumnVectorWrapper.cxx.

99 {
100 if (m_elements.size() < numFixedColumns)
101 throw std::logic_error ("header has too few m_elements, expected at least " + std::to_string(numFixedColumns) + " but got " + std::to_string(m_elements.size()));
102 if (m_elements[sizeIndex].arraySize != m_elements.size())
103 throw std::logic_error ("size column has wrong array size, expected " + std::to_string(m_elements.size()) + " but got " + std::to_string(m_elements[sizeIndex].arraySize));
104
105 // skipping the first column, which is always the null column
106 // and behaves in a funny manner
107 for (std::size_t columnIndex = 1u; columnIndex != m_elements.size(); ++ columnIndex)
108 {
109 const auto& column = m_elements[columnIndex];
110 if (column.debugName.empty())
111 throw std::logic_error ("column " + std::to_string(columnIndex) + " has no name");
112 if (column.type == nullptr)
113 throw std::logic_error ("column " + column.debugName + " has no type");
114 if (column.isOffset && *column.type != typeid(ColumnarOffsetType))
115 throw std::logic_error ("column " + column.debugName + " is an offset column that is of type " + boost::core::demangle(column.type->name()) + " instead of ColumnarOffsetType");
116 }
117
118 for (std::size_t columnIndex = 1u; columnIndex != m_elements.size(); ++ columnIndex)
119 {
120 const auto& column = m_elements[columnIndex];
121 if (column.offsetIndex != nullIndex)
122 {
123 if (column.offsetIndex == unsetIndex)
124 throw std::logic_error ("column " + column.debugName + " has an offset index that was never set");
125 if (column.offsetIndex >= m_elements.size())
126 throw std::logic_error ("column " + column.debugName + " has invalid offset index " + std::to_string(column.offsetIndex) + " (max is " + std::to_string(m_elements.size()-1) + ")");
127 const auto& offsetElement = m_elements[column.offsetIndex];
128 if (!offsetElement.isOffset)
129 throw std::logic_error ("column " + column.debugName + " has offset index that is not marked as offset");
130 }
131 }
132 }

◆ getColumn()

const ColumnVectorElementHeader & columnar::ColumnVectorHeader::getColumn ( std::size_t index) const
inlinenodiscard

get the column for the given index

Definition at line 131 of file ColumnVectorWrapper.h.

131 {
132 return m_elements.at (index); }

◆ numColumns()

std::size_t columnar::ColumnVectorHeader::numColumns ( ) const
inlinenodiscardnoexcept

the number of columns in the columnar data vector

Definition at line 126 of file ColumnVectorWrapper.h.

126 {
127 return m_elements.size(); }

◆ setOffsetColumn()

void columnar::ColumnVectorHeader::setOffsetColumn ( std::size_t columnIndex,
std::size_t offsetIndex )

set the index of the offset column for the given column

Definition at line 79 of file ColumnVectorWrapper.cxx.

81 {
82 if (columnIndex >= m_elements.size())
83 throw std::logic_error ("column index out of range");
84 if (offsetIndex >= m_elements.size())
85 throw std::logic_error ("offset index out of range");
86 auto& column = m_elements.at(columnIndex);
87 auto& offset = m_elements.at(offsetIndex);
88 if (!offset.isOffset)
89 throw std::runtime_error ("trying to set " + offset.debugName + " as offset column for " + column.debugName + ", but it is not marked as offset column");
90 if (column.offsetIndex != unsetIndex && column.offsetIndex != offsetIndex)
91 throw std::runtime_error ("trying to set " + offset.debugName + " as offset column for " + column.debugName + ", but it is already set to " + m_elements.at(column.offsetIndex).debugName);
92 column.offsetIndex = offsetIndex;
93 }

Member Data Documentation

◆ m_elements

std::vector<ColumnVectorElementHeader> columnar::ColumnVectorHeader::m_elements
private

the elements in the columnar data vector

Private Members

Definition at line 147 of file ColumnVectorWrapper.h.

◆ nullIndex

std::size_t columnar::ColumnVectorHeader::nullIndex = 0u
staticconstexpr

the index used for an invalid index (always has to be 0)

Public Members

Definition at line 103 of file ColumnVectorWrapper.h.

◆ numFixedColumns

std::size_t columnar::ColumnVectorHeader::numFixedColumns = 2u
staticconstexpr

the number of fix elements in the columnar data vector

Definition at line 112 of file ColumnVectorWrapper.h.

◆ sizeIndex

std::size_t columnar::ColumnVectorHeader::sizeIndex = 1u
staticconstexpr

the index used for the column size column

Definition at line 106 of file ColumnVectorWrapper.h.

◆ unsetIndex

std::size_t columnar::ColumnVectorHeader::unsetIndex = static_cast<std::size_t>(-1)
staticconstexpr

the number used for an unset but non-null index

Definition at line 109 of file ColumnVectorWrapper.h.


The documentation for this class was generated from the following files: