8#ifndef COLUMNAR_CORE_LINK_COLUMN_H
9#define COLUMNAR_CORE_LINK_COLUMN_H
11#include <AthLinks/ElementLink.h>
38 requires requires { CI::containerClid(); }
48 template<
typename... Types>
50 template<
typename T,
typename... Rest>
51 struct LinkDistinctTypeCount<T,Rest...> final : std::integral_constant<unsigned,((std::is_void_v<T> || (std::is_same_v<T,Rest> || ...)) ? 0u : 1u) + LinkDistinctTypeCount<Rest...>::value> {};
96 static_assert ((
requires { ExtraELT::containerClid(); } && ...),
97 "the extra link types of a LinkCastColumn only add keys, so they need to provide a CLID");
116 template<ContainerIdConcept LT>
119 if constexpr (
requires { LT::containerClid(); })
120 return LT::containerClid();
128 template<ContainerIdConcept LT,ColumnarModeConcept CM>
129 requires (!CM::useKeyIndexAsLink)
144 return BaseAccessor::makeViewer(dataArea);
163 auto *ptr = *link.cptr();
165 auto *ptr2 =
dynamic_cast<typename LT::xAODObjectIdType*
>(ptr);
166 if (!ptr2)
throw std::runtime_error (
"link not of expected type");
180 template<ColumnarModeConcept CM>
181 [[nodiscard]]
bool isNullLink (
typename CM::LinkKeyColumnType key,
typename CM::LinkIndexColumnType
index)
noexcept
183 return key == CM::nullLinkKey ||
index == CM::nullLinkIndex;
192 if (clid != 0 && std::find (clids.begin(), clids.end(), clid) == clids.end())
193 clids.push_back (clid);
197 inline void fillLinkKeys (std::vector<SG::sgkey_t>& keys,
const std::string& name,
const std::vector<CLID>& clids)
200 for (
CLID clid : clids)
207 return std::find (keys.begin(), keys.end(), key) != keys.end();
218 [[noreturn]] [[gnu::cold]] [[gnu::noinline]]
226 [[noreturn]] [[gnu::cold]] [[gnu::noinline]]
231 template<
typename CM>
235 const std::size_t result = offsets[event] +
index;
236 if constexpr (!CM::skipLinkValidation)
238 if (result >= offsets[event+1])
258 requires (CM::useKeyIndexAsLink)
265 static_assert (LT::perEventRange,
"links can only target containers with per-event ranges");
275 std::vector<CLID> clids;
283 m_targetKeys = std::make_shared<std::vector<typename CM::LinkKeyColumnType>> (clids.size(), CM::nullLinkKey);
284 columnarTool.watchLinkTargetName (LT::idName, [keys =
m_targetKeys, clids = std::move (clids)] (
const std::string& name)
289 auto keyInfo = options.makeColumnInfo();
290 keyInfo.offsetName = optionsArray.offsetName;
293 columnarTool.addColumn (optionsArray.baseName +
"." + std::string (CM::linkKeyColumnName),
m_keyData.get(), std::move (keyInfo));
295 auto indexInfo = options.makeColumnInfo();
296 indexInfo.offsetName = optionsArray.offsetName;
299 columnarTool.addColumn (optionsArray.baseName +
"." + std::string (CM::linkIndexColumnName),
m_indexData.get(), std::move (indexInfo));
304 std::string eventName = optionsArray.numOffsets == 0u ? std::string (optionsArray.offsetName) : optionsArray.baseName;
306 eventName += CM::eventIndexColumnName;
308 eventInfo.
offsetName = optionsArray.offsetName;
313 columnarTool.addColumn (eventName,
m_eventData.get(), std::move (eventInfo));
321 columnarTool.addColumn (std::string (LT::idName),
m_targetOffsetsData.get(), std::move (targetInfo));
349 const auto key =
static_cast<const typename CM::LinkKeyColumnType*
>(dataArea[
m_keyIndex])[
index];
350 const auto linkIndex =
static_cast<const typename CM::LinkIndexColumnType*
>(dataArea[
m_indexIndex])[
index];
354 if constexpr (!CM::skipLinkValidation)
356 if constexpr (
LinkCastColumn<LT,ELT,ExtraELT...>::numLinkTypes == 1u)
370 [[nodiscard]]
auto operator () (
void** dataArea, std::size_t beginIndex, std::size_t endIndex)
const
373 std::views::iota (beginIndex, endIndex));
398 std::shared_ptr<std::vector<typename CM::LinkKeyColumnType>>
m_targetKeys;
410 template<RegularContainerIdConcept LT,ColumnarModeConcept CM>
411 requires (CM::useKeyIndexAsLink)
434 [[nodiscard]]
auto operator () (
void** dataArea, std::size_t beginIndex, std::size_t endIndex)
const
436 return m_accessor (dataArea, beginIndex, endIndex);
ElementLink & operator=(const ElementLink &)=default
uint32_t CLID
The Class ID type.
ElementLink implementation for ROOT usage.
a class representing a single optional object (electron, muons, etc.)
std::unique_ptr< ColumnAccessorDataArray > m_targetOffsetsData
ContainerFreeAccessor(ColumnarTool< CM > &columnarTool, ColumnAccessorOptions &&options, ColumnAccessorOptionsArray &&optionsArray)
ContainerFreeAccessor(ContainerFreeAccessor &&that)
std::shared_ptr< std::vector< typename CM::LinkKeyColumnType > > m_targetKeys
std::unique_ptr< ColumnAccessorDataArray > m_eventData
unsigned m_targetOffsetsIndex
const auto & allTargetKeys() const noexcept
all the keys accepted for the target container
bool isAvailable(void **dataArea) const noexcept
CM::LinkKeyColumnType targetKey() const noexcept
the key of the target container based on its own type
static constexpr unsigned internalOffsetColumns
ContainerFreeAccessor()=default
std::unique_ptr< ColumnAccessorDataArray > m_indexData
static constexpr bool isDefined
std::unique_ptr< ColumnAccessorDataArray > m_keyData
const auto & allTargetKeys() const noexcept
all the keys accepted for the target container
static constexpr bool isDefined
auto targetKey() const noexcept
the key of the target container based on its own type
bool isAvailable(void **dataArea) const noexcept
ContainerFreeAccessor()=default
ContainerFreeAccessor(ColumnarTool< CM > &columnarTool, ColumnAccessorOptions &&options, ColumnAccessorOptionsArray &&optionsArray)
static constexpr unsigned internalOffsetColumns
ContainerFreeAccessor< LinkCastColumn< LT >, ColumnAccessMode::input, CM > BaseAccessor
static constexpr bool isDefined
static constexpr bool hasSetter
static auto makeViewer(void **)
ElementLink< typename ELT::xAODElementLinkType > MemoryType
static constexpr bool viewIsReference
static auto makeViewer(void **dataArea)
static constexpr bool hasSetter
static constexpr bool isDefined
static constexpr bool viewIsReference
ElementLink< typename ELT::xAODElementLinkType > MemoryType
typename BaseAccessor::MemoryType MemoryType
static constexpr bool viewIsReference
MemoryAccessor< LinkCastColumn< LT >, CM > BaseAccessor
static constexpr bool isDefined
static auto makeViewer(void **dataArea)
static constexpr bool hasSetter
a help implementation of AccessorTemplate that handles type conversions
static constexpr bool isDefined
concept for a container id
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Container id definitions for the columnar infrastructure.
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 throwLinkIndexOutOfRange(const std::string &columnName, std::size_t index, ColumnarOffsetType event, std::size_t numTargets)
throw the exception for a link index outside its event
void addLinkClid(std::vector< CLID > &clids, CLID clid)
add a CLID to the list of CLIDs a link accepts
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
CLID linkTargetClid()
the CLID of the xAOD container a link column targets, or 0 if the container id does not provide one
void throwLinkKeyMismatch(const std::string &columnName, SG::sgkey_t key, ColumnarOffsetType event, const std::vector< SG::sgkey_t > &expected)
throw the exception for a link key that doesn't match any of the keys accepted for the link target
void moveAccessor(unsigned &dataIndex, std::unique_ptr< ColumnAccessorDataArray > &accessorData, unsigned &sourceIndex, std::unique_ptr< ColumnAccessorDataArray > &sourceData)
constexpr std::string_view eventContextCIName
the name for the event context container id
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
SG::sgkey_t computeSgKey(const std::string &name, std::uint32_t clid)
compute the StoreGate hashed key for a container
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
a special column type that behaves like an OptObjectId, but applies an internal cast in xAOD mode
static constexpr unsigned numLinkTypes
the number of keys a key+index link accepts for its target, i.e.
typename CI::xAODElementLinkType type
the type of the container a link column targets, for the purpose of counting the keys a link accepts,...
the number of distinct types in a list of types, ignoring void
std::map< std::string, HypoJetVector >::const_iterator CI