18#include <boost/core/demangle.hpp>
47 [[nodiscard]] std::size_t ColumnVectorHeader ::
54 auto& existingHeader =
m_elements.at(iter->second);
59 std::string uniqueName;
60 for (
unsigned suffix = 1; ; ++suffix)
62 uniqueName = columnInfo.
name +
"." + std::to_string(suffix);
67 renamedInfo.
name = std::move(uniqueName);
72 if (existingHeader.type != columnInfo.
type)
73 throw std::runtime_error(
"column " + columnInfo.
name +
" type mismatch");
74 if (existingHeader.offsetName != columnInfo.
offsetName)
75 throw std::runtime_error(
"column " + columnInfo.
name +
" offset name mismatch: " + existingHeader.offsetName +
" vs " + columnInfo.
offsetName);
76 if (existingHeader.isOffset != columnInfo.
isOffset)
77 throw std::runtime_error(
"column " + columnInfo.
name +
" isOffset mismatch");
79 throw std::runtime_error(
"column " + columnInfo.
name +
" fixed dimensions mismatch");
81 throw std::runtime_error(
"column " + columnInfo.
name +
" sole link target name mismatch");
83 throw std::runtime_error(
"column " + columnInfo.
name +
" sole link target clid mismatch");
85 throw std::runtime_error(
"column " + columnInfo.
name +
" isVariantLink mismatch");
87 throw std::runtime_error(
"column " + columnInfo.
name +
" variant link target names mismatch");
89 throw std::runtime_error(
"column " + columnInfo.
name +
" key column for variant link mismatch");
93 throw std::runtime_error(
"column " + columnInfo.
name +
" already registered as input, cannot register as output");
96 existingHeader.readOnly =
false;
131 header.isOptional =
false;
135 const std::size_t newIndex =
m_elements.size() - 1;
142 void ColumnVectorHeader ::
143 setOffsetColumn (std::size_t columnIndex, std::size_t offsetIndex)
146 throw std::logic_error (
"column index out of range");
148 throw std::logic_error (
"offset index out of range");
151 if (!offset.isOffset)
152 throw std::runtime_error (
"trying to set " + offset.debugName +
" as offset column for " + column.debugName +
", but it is not marked as offset column");
153 if (column.offsetIndex !=
unsetIndex && column.offsetIndex != offsetIndex)
154 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);
155 column.offsetIndex = offsetIndex;
160 void ColumnVectorHeader ::
164 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()));
166 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));
170 for (std::size_t columnIndex = 1u; columnIndex !=
m_elements.size(); ++ columnIndex)
173 if (column.debugName.empty())
174 throw std::logic_error (
"column " + std::to_string(columnIndex) +
" has no name");
175 if (column.type ==
nullptr)
176 throw std::logic_error (
"column " + column.debugName +
" has no type");
178 throw std::logic_error (
"column " + column.debugName +
" is an offset column that is of type " + boost::core::demangle(column.type->name()) +
" instead of ColumnarOffsetType");
181 for (std::size_t columnIndex = 1u; columnIndex !=
m_elements.size(); ++ columnIndex)
187 throw std::logic_error (
"column " + column.debugName +
" has an offset index that was never set");
189 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) +
")");
190 const auto& offsetElement =
m_elements[column.offsetIndex];
191 if (!offsetElement.isOffset)
192 throw std::logic_error (
"column " + column.debugName +
" has offset index that is not marked as offset");
199 void ColumnVectorHeader ::
200 checkData (std::span<const void* const>
data)
const
203 throw std::logic_error (
"data vector has wrong size, expected " + std::to_string(
m_elements.size()) +
" but got " + std::to_string(
data.size()));
205 throw std::logic_error (
"null column is not set to a nullptr value");
206 const auto* sizeVector =
static_cast<const std::size_t*
>(
data[
sizeIndex]);
207 for (std::size_t columnIndex = 0u; columnIndex !=
m_elements.size(); ++ columnIndex)
210 if (
data[columnIndex] ==
nullptr)
212 if (column.isOptional)
214 if (column.offsetIndex !=
nullIndex &&
data[column.offsetIndex] ==
nullptr)
216 throw std::logic_error (
"column " + column.debugName +
" was not set");
220 const auto size = sizeVector[columnIndex];
222 throw std::runtime_error (
"offset column " + column.debugName +
" has size " + std::to_string(
size) +
", but needs at least 1 element");
225 throw std::runtime_error (
"offset column doesn't start with 0: " + column.debugName);
226 for (std::size_t i = 1u; i !=
size; ++ i)
228 if (offsets[i] < offsets[i-1])
229 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]));
233 for (std::size_t columnIndex = 0u; columnIndex !=
m_elements.size(); ++ columnIndex)
235 if (
data[columnIndex] ==
nullptr)
238 std::size_t expectedSize = 1u;
241 if (
data[column.offsetIndex] ==
nullptr)
242 throw std::runtime_error (
"column " + column.debugName +
" uses offset column " +
m_elements[column.offsetIndex].debugName +
" that is not set");
243 const auto offsetIndex = column.offsetIndex;
245 expectedSize = offsetsPtr[sizeVector[offsetIndex]-1];
247 expectedSize *= column.arraySize;
252 if (sizeVector[columnIndex] != expectedSize)
253 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));
262 m_data (val_header->numColumns(), nullptr),
270 void ColumnVectorData ::
271 setColumnVoid (std::size_t columnIndex, std::size_t
size,
const void *dataPtr,
const std::type_info&
type,
bool isConst)
274 throw std::logic_error (
"cannot set the null column");
275 if (columnIndex >=
m_header->numColumns())
276 throw std::logic_error (
"invalid column index: " + std::to_string(columnIndex) +
" (max is " + std::to_string(
m_header->numColumns()-1) +
")");
283 if (dataPtr ==
nullptr)
286 throw std::logic_error (
"dataPtr is null but size is not zero for column: " +
header.debugName);
287 static const unsigned dummyValue = 0;
288 dataPtr = &dummyValue;
292 throw std::runtime_error (
"invalid type for column: " +
header.debugName);
293 if (isConst && !
header.readOnly)
294 throw std::runtime_error (
"assigning const vector to a column that is not read-only: " +
header.debugName);
295 if (
m_data[columnIndex] !=
nullptr)
296 throw std::runtime_error (
"column filled multiple times: " +
header.debugName);
298 m_data[columnIndex] = castDataPtr;
304 std::pair<std::size_t,const void*> ColumnVectorData ::
305 getColumnVoid (std::size_t columnIndex,
const std::type_info *
type,
bool isConst)
const
307 if (columnIndex >=
m_header->numColumns())
308 throw std::runtime_error (
"invalid column index: " + std::to_string(columnIndex) +
" (max is " + std::to_string(
m_header->numColumns()-1) +
")");
312 throw std::runtime_error (
"invalid type for column: " +
header.debugName);
313 if (!isConst &&
header.readOnly)
314 throw std::runtime_error (
"retrieving non-const vector from a read-only column: " +
header.debugName);
315 if (
m_data[columnIndex] !=
nullptr)
318 return std::make_pair (0u,
nullptr);
323 void ColumnVectorData ::
326 tool.callVoid (
m_data.data());
331 std::unordered_map<std::string, ColumnInfo> ColumnVectorHeader ::
332 getAllColumnInfo ()
const
334 std::unordered_map<std::string, ColumnInfo> result;
340 info.name =
header.debugName;
341 info.index =
static_cast<unsigned>(i);
343 info.accessMode =
header.accessMode;
344 info.offsetName =
header.offsetName;
345 info.fixedDimensions =
header.fixedDimensions;
346 info.isOffset =
header.isOffset;
347 info.isOptional =
header.isOptional;
348 info.soleLinkTargetName =
header.soleLinkTargetName;
349 info.soleLinkTargetClid =
header.soleLinkTargetClid;
350 info.isVariantLink =
header.isVariantLink;
351 info.variantLinkTargetNames =
header.variantLinkTargetNames;
352 info.keyColumnForVariantLink =
header.keyColumnForVariantLink;
353 result.emplace(info.name, std::move(info));
char data[hepevt_bytes_allocation_ATLAS]
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
std::size_t addColumn(const ColumnInfo &columnInfo)
add a column for the given ColumnInfo, returning its index
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
@ 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::string soleLinkTargetName
for simple link columns: the name of the target container
std::string keyColumnForVariantLink
if this is a key column for a variant link, the name of the associated link column
std::uint32_t soleLinkTargetClid
for simple link columns: the CLID of the target container
std::vector< unsigned > fixedDimensions
the fixed dimensions this column has (if any)
bool isOptional
whether this column is optional
std::vector< std::string > variantLinkTargetNames
for variant link key columns: the names of the containers we can link to
std::string name
the name of the column
bool isOffset
whether this is an offset column
ColumnAccessMode accessMode
the access mode for the column
bool isVariantLink
whether this is a variant link column
const std::type_info * type
the type of the individual entries in the column