8#ifndef COLUMNAR_VARIANT_VARIANT_LINK_COLUMN_H
9#define COLUMNAR_VARIANT_VARIANT_LINK_COLUMN_H
68 explicit operator bool ()
const
90 template<ContainerIdConcept CI2>
93 static constexpr unsigned variantIndex = CI::template getVariantIndex<CI2>();
95 return m_link->isValid() &&
dynamic_cast<typename CI2::xAODObjectRangeType*
>(
m_link->getStorableObjectPointer());
99 template<ContainerIdConcept CI2>
102 static constexpr unsigned variantIndex = CI::template getVariantIndex<CI2>();
103 static_assert (variantIndex <
CI::numVariants,
"invalid container id");
104 return m_link->isValid() && (**m_link) == &
id.getXAODObject();
114 template<ContainerIdConcept CI2>
117 static constexpr unsigned variantIndex = CI::template getVariantIndex<CI2>();
118 static_assert (variantIndex <
CI::numVariants,
"invalid container id");
132 template<
typename... CIList>
135 return str << obj.getXAODObject() <<
"/" << obj.getXAODObject()->type();
142 template<ContainerIdConcept CIBase,
typename... CIList>
165 template<ContainerIdConcept CI2>
166 requires (CI::template isValidContainer<CI2>())
169 auto* container =
static_cast<const typename CIBase::xAODElementLinkType*
>(obj.getXAODObjectNoexcept().container());
170 link =
MemoryType(*container, obj.getXAODObjectNoexcept().index());
188 template<
unsigned numVariants>
193 std::array<std::unique_ptr<ColumnAccessorDataArray>,numVariants>
offsetData;
204 throw std::runtime_error (
"link key does not match any known container for column " + columnName +
": read key " + std::to_string (key) +
" in event " + std::to_string (event));
214 throw std::runtime_error (
"link target not in the same event as the link for column " + columnName +
": object " + std::to_string (objectIndex) +
" is outside the range of event " + std::to_string (event));
226 template<ContainerIdConcept CIBase,ContainerIdConcept... CIList,ContainerIdConcept ELT,ContainerIdConcept... ExtraELT>
229 static_assert ((
requires { ExtraELT::containerClid(); } && ...),
230 "the extra link types of a LinkCastColumn only add keys, so they need to provide a CLID");
240 requires (CM::useKeyIndexAsLink)
257 throw std::logic_error (
"can't call xAOD function in columnar mode");
261 explicit operator bool ()
const noexcept
291 template<ContainerIdConcept CI2>
294 static constexpr unsigned variantIndex = CI::template getVariantIndex<CI2>();
295 static_assert (variantIndex <
CI::numVariants,
"invalid container id");
300 template<ContainerIdConcept CI2>
303 static constexpr unsigned variantIndex = CI::template getVariantIndex<CI2>();
304 static_assert (variantIndex <
CI::numVariants,
"invalid container id");
324 if (
m_key == obj.m_key)
339 if (variant != obj.findVariant())
345 template<ContainerIdConcept CI2>
348 static constexpr unsigned variantIndex = CI::template getVariantIndex<CI2>();
349 static_assert (variantIndex <
CI::numVariants,
"invalid container id");
370 typename CM::LinkKeyColumnType
m_key = CM::nullLinkKey;
371 typename CM::LinkIndexColumnType
m_index = CM::nullLinkIndex;
394 template<
typename... CIList, ColumnarArrayModeConcept CM>
395 requires (CM::useKeyIndexAsLink)
398 return str << obj.getLinkKey() <<
"/" << obj.getLinkIndex();
421 template<
ColumnAccessMode CAM,ContainerIdConcept CIBase,ContainerIdConcept... CIList,ContainerIdConcept ELT,ContainerIdConcept... ExtraELT,ColumnarArrayModeConcept CM>
422 requires (CM::useKeyIndexAsLink)
440 m_targetKeys = std::make_shared<typename Link::KeyArray> ();
441 m_targets = std::make_unique<typename Link::Targets> ();
442 m_targets->columnName = optionsArray.baseName;
446 std::vector<CLID> clids;
448 for (
CLID clid : memberClids)
455 (*m_targetKeys)[i].assign (clids.size(), CM::nullLinkKey);
470 auto keyInfo = options.makeColumnInfo();
471 keyInfo.offsetName = optionsArray.offsetName;
474 columnarTool.addColumn (optionsArray.baseName +
"." + std::string (CM::linkKeyColumnName),
m_keyData.get(), std::move (keyInfo));
476 auto indexInfo = options.makeColumnInfo();
477 indexInfo.offsetName = optionsArray.offsetName;
480 columnarTool.addColumn (optionsArray.baseName +
"." + std::string (CM::linkIndexColumnName),
m_indexData.get(), std::move (indexInfo));
485 std::string eventName = optionsArray.numOffsets == 0u ? std::string (optionsArray.offsetName) : optionsArray.baseName;
487 eventName += CM::eventIndexColumnName;
489 eventInfo.
offsetName = optionsArray.offsetName;
494 columnarTool.addColumn (eventName,
m_eventData.get(), std::move (eventInfo));
521 return link (dataArea,
index).opt_value();
524 auto operator () (
void** dataArea, std::size_t beginIndex, std::size_t endIndex)
const
528 links (dataArea, beginIndex, endIndex));
532 [[nodiscard]]
auto link (
void** dataArea, std::size_t
index)
const noexcept
535 auto *keys =
static_cast<const typename CM::LinkKeyColumnType*
>(dataArea[
m_keyIndex]);
536 auto *
indices =
static_cast<const typename CM::LinkIndexColumnType*
>(dataArea[
m_indexIndex]);
542 [[nodiscard]]
auto links (
void** dataArea, std::size_t beginIndex, std::size_t endIndex)
const noexcept
546 std::views::iota (beginIndex, endIndex));
549 template<ContainerIdConcept CI2>
553 static constexpr unsigned variantIndex = VariantCI::template getVariantIndex<CI2>();
556 if constexpr (!CM::skipLinkValidation)
558 if (obj.getIndex() < offsets[event] || obj.getIndex() >= offsets[event+1])
562 static_cast<typename CM::LinkIndexColumnType*
>(dataArea[
m_indexIndex])[
index] = obj.getIndex() - offsets[event];
569 for (
unsigned offsetIndex :
m_targets->offsetIndices)
571 if (dataArea[offsetIndex] ==
nullptr)
581 std::array<typename CM::LinkKeyColumnType,VariantCI::numVariants> result {};
614 requires (CM::useKeyIndexAsLink)
639 [[nodiscard]]
auto operator () (
void** dataArea, std::size_t beginIndex, std::size_t endIndex)
const noexcept
642 return m_accessor.links (dataArea, beginIndex, endIndex);
645 template<ContainerIdConcept CI2>
ElementLink & operator=(const ElementLink &)=default
uint32_t CLID
The Class ID type.
std::vector< std::vector< int64_t > > indices
ElementLink implementation for ROOT usage.
a class representing a single object (electron, muons, etc.)
CM::LinkIndexColumnType m_index
OptObjectId< CI, CM > opt_value() const
get an OptObjectId for this link
const Targets * m_targets
CM::LinkKeyColumnType m_key
ColumnarOffsetType m_event
ObjectLink(typename CM::LinkKeyColumnType val_key, typename CM::LinkIndexColumnType val_index, ColumnarOffsetType val_event, const KeyArray *val_keys, const Targets *val_targets, void **val_dataArea)
bool isContainer() const
whether this link is valid and points to an object of the given container
unsigned findVariant() const noexcept
the first variant accepting the key, or CI::numVariants if there is none
auto getLinkIndex() const noexcept
VariantContainerId< CIBase, CIList... > CI
detail::VariantLinkTargets< CI::numVariants > Targets
auto getLinkKey() const noexcept
std::array< std::vector< typename CM::LinkKeyColumnType >, CI::numVariants > KeyArray
OptObjectId< CI2, CM > tryGetVariant() const
return the ObjectId if it is in the given container or nullopt otherwise
const CI::xAODObjectIdType * getXAODObject() const
std::size_t resolveIndex(unsigned variantIndex) const
bool has_value() const noexcept
whether this is a valid link
ElementLink< typename CI::xAODElementLinkType > LinkType
bool has_value() const
whether this is a valid link
OptObjectId< CI, CM > opt_value() const
get an OptObjectId for this link
VariantContainerId< CIBase, CIList... > CI
const CI::xAODObjectIdType * getXAODObject() const
ObjectLink(const LinkType *val_link)
bool isContainer() const
whether this link is valid and points to an object of the given container
OptObjectId< CI2, CM > tryGetVariant() const
return the ObjectId if it is in the given container or nullopt otherwise
a class representing a single optional object (electron, muons, etc.)
ObjectLink< VariantCI, CM > Link
ContainerFreeAccessor(ContainerFreeAccessor &&that)
auto link(void **dataArea, std::size_t index) const noexcept
get the ObjectLink for the given index
void set(void **dataArea, std::size_t index, ObjectId< CI2, CM > obj) const
VariantContainerId< CIBase, CIList... > VariantCI
auto targetKeys() const noexcept
the keys of the target containers based on their own types, in the order of the variants
ContainerFreeAccessor()=default
ContainerFreeAccessor(ColumnarTool< CM > &columnarTool, ColumnAccessorOptions &&options, ColumnAccessorOptionsArray &&optionsArray)
auto links(void **dataArea, std::size_t beginIndex, std::size_t endIndex) const noexcept
get the ObjectLink objects for the given index range
static constexpr unsigned internalOffsetColumns
bool isAvailable(void **dataArea) const noexcept
static constexpr bool isDefined
const auto & allTargetKeys() const noexcept
all the keys accepted for the target containers, in the order of the variants
std::unique_ptr< typename Link::Targets > m_targets
std::unique_ptr< ColumnAccessorDataArray > m_indexData
std::unique_ptr< ColumnAccessorDataArray > m_eventData
std::shared_ptr< typename Link::KeyArray > m_targetKeys
static constexpr std::array containerIdNames
std::unique_ptr< ColumnAccessorDataArray > m_keyData
static constexpr unsigned internalOffsetColumns
ContainerFreeAccessor< LinkCastColumn< VariantCI, CIBase >, CAM, CM > BaseAccessor
VariantContainerId< CIBase, CIList... > VariantCI
auto targetKeys() const noexcept
the keys of the target containers based on their own types, in the order of the variants
bool isAvailable(void **dataArea) const noexcept
ContainerFreeAccessor()=default
void set(void **dataArea, std::size_t index, ObjectId< CI2, CM > obj) const
ContainerFreeAccessor(ColumnarTool< CM > &columnarTool, ColumnAccessorOptions &&options, ColumnAccessorOptionsArray &&optionsArray)
static constexpr bool isDefined
const auto & allTargetKeys() const noexcept
all the keys accepted for the target containers, in the order of the variants
static constexpr bool isDefined
VariantContainerId< CIBase, CIList... > CI
static constexpr bool hasSetter
static constexpr bool viewIsReference
ElementLink< typename CI::xAODElementLinkType > MemoryType
static auto makeSetter(void **)
static auto makeViewer(void **)
a help implementation of AccessorTemplate that handles type conversions
concept for a container id
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
bool isNullLink(typename CM::LinkKeyColumnType key, typename CM::LinkIndexColumnType index) noexcept
whether the given key and index represent a null link
std::size_t resolveLinkIndex(void **dataArea, unsigned targetOffsetsIndex, ColumnarOffsetType event, std::size_t index, const std::string &columnName)
convert the event-relative index of a link into an index into the target column, checking it is insid...
void addLinkClid(std::vector< CLID > &clids, CLID clid)
add a CLID to the list of CLIDs a link accepts
void throwVariantLinkUnknownKey(const std::string &columnName, SG::sgkey_t key, ColumnarOffsetType event)
throw the exception for a link key that doesn't match any of the variants
void fillLinkKeys(std::vector< SG::sgkey_t > &keys, const std::string &name, const std::vector< CLID > &clids)
calculate the keys a link accepts for the given container name
VectorConvertView(FunctionType &&, ViewType &&) -> VectorConvertView< std::decay_t< FunctionType >, std::decay_t< ViewType > >
bool isLinkKey(const std::vector< SG::sgkey_t > &keys, SG::sgkey_t key) noexcept
whether the given key is in the list of accepted keys
typename LinkClidTypeImp< CI >::type LinkClidType
void throwVariantLinkOutsideEvent(const std::string &columnName, std::size_t objectIndex, ColumnarOffsetType event)
throw the exception for a link target that is not in the same event as the link
CLID linkTargetClid()
the CLID of the xAOD container a link column targets, or 0 if the container id does not provide one
void moveAccessor(unsigned &dataIndex, std::unique_ptr< ColumnAccessorDataArray > &accessorData, unsigned &sourceIndex, std::unique_ptr< ColumnAccessorDataArray > &sourceData)
bool operator==(const ObjectId< CI, ColumnarModeXAOD > &lhs, const ObjectId< CI, ColumnarModeXAOD > &rhs)
constexpr std::string_view eventContextCIName
the name for the event context container id
ColumnAccessMode
an enum for the different access modes for a column
void setColumnType(ColumnInfo &info) noexcept
set the type information in the ColumnInfo for the given C++ type
std::size_t ColumnarOffsetType
the type used for the size and offsets in the columnar data
std::ostream & operator<<(std::ostream &str, const ObjectId< CI, ColumnarModeXAOD > &obj)
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)
bool isOptional
whether this column is optional
bool isEventIndex
whether this is the index of the event for each entry
bool isOffset
whether this is an offset column
static constexpr unsigned numLinkTypes
a special column type that behaves like an OptObjectId, but applies an internal cast in xAOD mode
static constexpr std::size_t numVariants
typename CIBase::xAODObjectIdType xAODObjectIdType
the number of distinct types in a list of types, ignoring void
the offset maps of the targets of a key+index variant link
std::array< unsigned, numVariants > offsetIndices
std::array< std::unique_ptr< ColumnAccessorDataArray >, numVariants > offsetData