19#include <boost/core/demangle.hpp>
50 [[nodiscard]] std::size_t ColumnVectorHeader ::
57 auto& existingHeader =
m_elements.at(iter->second);
60 if (existingHeader.type != columnInfo.
type)
61 throw std::runtime_error(
"column " + columnInfo.
name +
" type mismatch");
65 if (existingHeader.offsetName != columnInfo.
offsetName)
66 throw std::runtime_error(
"column " + columnInfo.
name +
" offset name mismatch: " + existingHeader.offsetName +
" vs " + columnInfo.
offsetName);
67 if (existingHeader.isOffset != columnInfo.
isOffset)
68 throw std::runtime_error(
"column " + columnInfo.
name +
" isOffset mismatch");
70 throw std::runtime_error(
"column " + columnInfo.
name +
" fixed dimensions mismatch");
71 if (existingHeader.isEventIndex != columnInfo.
isEventIndex)
72 throw std::runtime_error(
"column " + columnInfo.
name +
" isEventIndex mismatch");
76 throw std::runtime_error(
"column " + columnInfo.
name +
" already registered as input, cannot register as output");
79 existingHeader.readOnly =
false;
84 existingHeader.isOptional =
false;
116 header.isOptional =
false;
120 const std::size_t newIndex =
m_elements.size() - 1;
127 void ColumnVectorHeader ::
128 setOffsetColumn (std::size_t columnIndex, std::size_t offsetIndex)
131 throw std::logic_error (
"column index out of range");
133 throw std::logic_error (
"offset index out of range");
136 if (!offset.isOffset)
137 throw std::runtime_error (
"trying to set " + offset.debugName +
" as offset column for " + column.debugName +
", but it is not marked as offset column");
138 if (column.offsetIndex !=
unsetIndex && column.offsetIndex != offsetIndex)
139 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);
140 column.offsetIndex = offsetIndex;
145 void ColumnVectorHeader ::
149 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()));
151 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));
155 for (std::size_t columnIndex = 1u; columnIndex !=
m_elements.size(); ++ columnIndex)
158 if (column.debugName.empty())
159 throw std::logic_error (
"column " + std::to_string(columnIndex) +
" has no name");
160 if (column.type ==
nullptr)
161 throw std::logic_error (
"column " + column.debugName +
" has no type");
163 throw std::logic_error (
"column " + column.debugName +
" is an offset column that is of type " + boost::core::demangle(column.type->name()) +
" instead of ColumnarOffsetType");
166 for (std::size_t columnIndex = 1u; columnIndex !=
m_elements.size(); ++ columnIndex)
172 throw std::logic_error (
"column " + column.debugName +
" has an offset index that was never set");
174 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) +
")");
175 const auto& offsetElement =
m_elements[column.offsetIndex];
176 if (!offsetElement.isOffset)
177 throw std::logic_error (
"column " + column.debugName +
" has offset index that is not marked as offset");
184 void ColumnVectorHeader ::
185 checkData (std::span<const void* const> data)
const
188 throw std::logic_error (
"data vector has wrong size, expected " + std::to_string(
m_elements.size()) +
" but got " + std::to_string(data.size()));
190 throw std::logic_error (
"null column is not set to a nullptr value");
191 const auto* sizeVector =
static_cast<const std::size_t*
>(data[
sizeIndex]);
192 for (std::size_t columnIndex = 0u; columnIndex !=
m_elements.size(); ++ columnIndex)
195 if (data[columnIndex] ==
nullptr)
197 if (column.isOptional)
199 if (column.offsetIndex !=
nullIndex && data[column.offsetIndex] ==
nullptr)
201 throw std::logic_error (
"column " + column.debugName +
" was not set");
205 const auto size = sizeVector[columnIndex];
207 throw std::runtime_error (
"offset column " + column.debugName +
" has size " + std::to_string(
size) +
", but needs at least 1 element");
210 throw std::runtime_error (
"offset column doesn't start with 0: " + column.debugName);
211 for (std::size_t i = 1u; i !=
size; ++ i)
213 if (offsets[i] < offsets[i-1])
214 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]));
218 for (std::size_t columnIndex = 0u; columnIndex !=
m_elements.size(); ++ columnIndex)
220 if (data[columnIndex] ==
nullptr)
223 std::size_t expectedSize = 1u;
226 if (data[column.offsetIndex] ==
nullptr)
227 throw std::runtime_error (
"column " + column.debugName +
" uses offset column " +
m_elements[column.offsetIndex].debugName +
" that is not set");
228 const auto offsetIndex = column.offsetIndex;
230 expectedSize = offsetsPtr[sizeVector[offsetIndex]-1];
232 expectedSize *= column.arraySize;
237 if (sizeVector[columnIndex] != expectedSize)
238 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));
257 const bool readOnly = isConst ||
header.readOnly;
260 std::string message =
"invalid type for column: " +
header.debugName +
", got ";
262 message += boost::core::demangle (
type->name()) +
" ";
263 message +=
"(" + std::string (
columnTypeCategoryName (typeCategory)) +
", " + std::to_string (sizeOfType) +
" byte(s)) but expected ";
264 if (
header.type !=
nullptr)
265 message += boost::core::demangle (
header.type->name()) +
" ";
268 message +=
", boolean data can only be written to boolean columns";
269 throw std::runtime_error (message);
278 m_data (val_header->numColumns(), nullptr),
286 void ColumnVectorData ::
287 setColumnVoid (std::size_t columnIndex, std::size_t
size,
const void *dataPtr,
const std::type_info *
type,
ColumnTypeCategory typeCategory,
unsigned sizeOfType,
bool isConst)
290 throw std::logic_error (
"cannot set the null column");
291 if (columnIndex >=
m_header->numColumns())
292 throw std::logic_error (
"invalid column index: " + std::to_string(columnIndex) +
" (max is " + std::to_string(
m_header->numColumns()-1) +
")");
299 if (dataPtr ==
nullptr)
302 throw std::logic_error (
"dataPtr is null but size is not zero for column: " +
header.debugName);
303 static const unsigned dummyValue = 0;
304 dataPtr = &dummyValue;
307 checkColumnType (
header,
type, typeCategory, sizeOfType, isConst);
308 if (isConst && !
header.readOnly)
309 throw std::runtime_error (
"assigning const vector to a column that is not read-only: " +
header.debugName);
310 if (
m_data[columnIndex] !=
nullptr)
311 throw std::runtime_error (
"column filled multiple times: " +
header.debugName);
313 m_data[columnIndex] = castDataPtr;
319 std::pair<std::size_t,const void*> ColumnVectorData ::
320 getColumnVoid (std::size_t columnIndex,
const std::type_info *
type,
ColumnTypeCategory typeCategory,
unsigned sizeOfType,
bool isConst)
const
322 if (columnIndex >=
m_header->numColumns())
323 throw std::runtime_error (
"invalid column index: " + std::to_string(columnIndex) +
" (max is " + std::to_string(
m_header->numColumns()-1) +
")");
326 checkColumnType (
header,
type, typeCategory, sizeOfType, isConst);
327 if (!isConst &&
header.readOnly)
328 throw std::runtime_error (
"retrieving non-const vector from a read-only column: " +
header.debugName);
329 if (
m_data[columnIndex] !=
nullptr)
332 return std::make_pair (0u,
nullptr);
337 void ColumnVectorData ::
340 tool.callVoid (
m_data.data());
345 std::unordered_map<std::string, ColumnInfo> ColumnVectorHeader ::
346 getAllColumnInfo ()
const
348 std::unordered_map<std::string, ColumnInfo> result;
354 info.name =
header.debugName;
355 info.index =
static_cast<unsigned>(i);
357 info.sizeOfType =
header.sizeOfType;
358 info.typeCategory =
header.typeCategory;
359 info.accessMode =
header.accessMode;
360 info.offsetName =
header.offsetName;
361 info.fixedDimensions =
header.fixedDimensions;
362 info.isOffset =
header.isOffset;
363 info.isOptional =
header.isOptional;
364 info.isEventIndex =
header.isEventIndex;
365 result.emplace(info.name, std::move(info));
helper functions for working with the type information in columnar::ColumnInfo
size_t size() const
Number of registered mappings.
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
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::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
ColumnTypeCategory
the category of type we use for a column
constexpr const char * columnTypeCategoryName(ColumnTypeCategory category) noexcept
a human readable name for the category (for messages)
constexpr ColumnTypeCategory mergeColumnTypeCategory(ColumnTypeCategory a, ColumnTypeCategory b) noexcept
merge the type categories of two users of the same column (with the same type), the strictest one win...
constexpr ColumnTypeCategory columnTypeCategoryFor() noexcept
the default ColumnTypeCategory for the given C++ type
constexpr bool isColumnTypeCompatible(ColumnTypeCategory columnCategory, unsigned columnSize, ColumnTypeCategory dataCategory, unsigned dataSize, bool isConst) noexcept
whether data of the given category and size can be used for a column with the given category and size
@ 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)
ColumnTypeCategory typeCategory
the type category for the individual entries in the column
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 isEventIndex
whether this is the index of the event for each entry
bool isOffset
whether this is an offset column
ColumnAccessMode accessMode
the access mode for the column
unsigned sizeOfType
the size (in bytes) of the individual entries in the column
const std::type_info * type
the type of the individual entries in the column
the header information for a single element in the columnar data vector