18#include <boost/core/demangle.hpp>
46 [[nodiscard]] std::size_t ColumnVectorHeader ::
79 void ColumnVectorHeader ::
80 setOffsetColumn (std::size_t columnIndex, std::size_t offsetIndex)
83 throw std::logic_error (
"column index out of range");
85 throw std::logic_error (
"offset index out of range");
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;
97 void ColumnVectorHeader ::
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()));
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));
107 for (std::size_t columnIndex = 1u; columnIndex !=
m_elements.size(); ++ 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");
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");
118 for (std::size_t columnIndex = 1u; columnIndex !=
m_elements.size(); ++ columnIndex)
124 throw std::logic_error (
"column " + column.debugName +
" has an offset index that was never set");
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");
136 void ColumnVectorHeader ::
137 checkData (std::span<const void* const>
data)
const
140 throw std::logic_error (
"data vector has wrong size, expected " + std::to_string(
m_elements.size()) +
" but got " + std::to_string(
data.size()));
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)
147 if (
data[columnIndex] ==
nullptr)
149 if (column.isOptional)
151 if (column.offsetIndex !=
nullIndex &&
data[column.offsetIndex] ==
nullptr)
153 throw std::logic_error (
"column " + column.debugName +
" was not set");
157 const auto size = sizeVector[columnIndex];
159 throw std::runtime_error (
"offset column " + column.debugName +
" has size " + std::to_string(size) +
", but needs at least 1 element");
162 throw std::runtime_error (
"offset column doesn't start with 0: " + column.debugName);
163 for (std::size_t i = 1u; i != size; ++ i)
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]));
170 for (std::size_t columnIndex = 0u; columnIndex !=
m_elements.size(); ++ columnIndex)
172 if (
data[columnIndex] ==
nullptr)
175 std::size_t expectedSize = 1u;
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;
182 expectedSize = offsetsPtr[sizeVector[offsetIndex]-1];
184 expectedSize *= column.arraySize;
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));
199 m_data (val_header->numColumns(), nullptr),
207 void ColumnVectorData ::
208 setColumnVoid (std::size_t columnIndex, std::size_t size,
const void *dataPtr,
const std::type_info&
type,
bool isConst)
211 throw std::logic_error (
"cannot set the null column");
212 if (columnIndex >=
m_header->numColumns())
213 throw std::logic_error (
"invalid column index: " + std::to_string(columnIndex) +
" (max is " + std::to_string(
m_header->numColumns()-1) +
")");
220 if (dataPtr ==
nullptr)
223 throw std::logic_error (
"dataPtr is null but size is not zero for column: " +
header.debugName);
224 static const unsigned dummyValue = 0;
225 dataPtr = &dummyValue;
229 throw std::runtime_error (
"invalid type for column: " +
header.debugName);
230 if (isConst && !
header.readOnly)
231 throw std::runtime_error (
"assigning const vector to a column that is not read-only: " +
header.debugName);
232 if (
m_data[columnIndex] !=
nullptr)
233 throw std::runtime_error (
"column filled multiple times: " +
header.debugName);
235 m_data[columnIndex] = castDataPtr;
241 std::pair<std::size_t,const void*> ColumnVectorData ::
242 getColumnVoid (std::size_t columnIndex,
const std::type_info *
type,
bool isConst)
244 if (columnIndex >=
m_header->numColumns())
245 throw std::runtime_error (
"invalid column index: " + std::to_string(columnIndex) +
" (max is " + std::to_string(
m_header->numColumns()-1) +
")");
249 throw std::runtime_error (
"invalid type for column: " +
header.debugName);
250 if (!isConst &&
header.readOnly)
251 throw std::runtime_error (
"retrieving non-const vector from a read-only column: " +
header.debugName);
252 if (
m_data[columnIndex] !=
nullptr)
255 return std::make_pair (0u,
nullptr);
260 void ColumnVectorData ::
263 tool.callVoid (
m_data.data());
char data[hepevt_bytes_allocation_ATLAS]
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
const ColumnVectorHeader * m_header
std::vector< void * > m_data
void setColumn(std::size_t columnIndex, std::size_t size, CT *dataPtr)
set the data for the given column
std::vector< std::size_t > m_dataSize
the header information for the entire columnar data vector
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
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
static constexpr std::size_t sizeIndex
the index used for the column size column
@ update
an updateable column
std::size_t ColumnarOffsetType
the type used for the size and offsets in the columnar data
a struct that contains meta-information about each column that's needed to interface the column with ...
std::string offsetName
the name of the offset column used for this column (or empty string for none)
std::vector< unsigned > fixedDimensions
the fixed dimensions this column has (if any)
bool isOptional
whether this column is optional
std::string name
the name of the column
bool isOffset
whether this is an offset column
ColumnAccessMode accessMode
the access mode for the column
const std::type_info * type
the type of the individual entries in the column