ATLAS Offline Software
Loading...
Searching...
No Matches
LinkColumn.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8#ifndef COLUMNAR_CORE_LINK_COLUMN_H
9#define COLUMNAR_CORE_LINK_COLUMN_H
10
11#include <AthLinks/ElementLink.h>
14
15namespace columnar
16{
24 template<ContainerIdConcept LT,typename ELT>
25 struct LinkCastColumn {};
26
27
28
29 // in xAOD mode we can do a straightforward conversion from
30 // ElementLink to OptObjectId, as ElementLink contains all the
31 // information about the object
32 template<ContainerIdConcept LT>
34 {
38 static constexpr bool isNativeType = false;
39 static constexpr bool useConvertInput = true;
40 static constexpr bool useConvertWithDataInput = false;
41 static ColumnInfo& updateColumnInfo (ColumnarTool<CM>& /*columnarTool*/, ColumnInfo& info) {return info;}
42
44 {
45 if (link.isValid())
46 {
47 typename LT::xAODObjectIdType *ptr = *link.cptr();
48 return OptObjectId<LT,CM> (ptr);
49 } else
50 {
51 return OptObjectId<LT,CM> ();
52 }
53 }
54 };
55
56
57 template<ContainerIdConcept LT,typename ELT>
59 {
63 static constexpr bool isNativeType = false;
64 static constexpr bool useConvertInput = true;
65 static constexpr bool useConvertWithDataInput = false;
66 static ColumnInfo& updateColumnInfo (ColumnarTool<CM>& /*columnarTool*/, ColumnInfo& info) {return info;}
67
69 {
70 if (link.isValid())
71 {
72 auto *ptr = *link.cptr();
73 if (!ptr) return OptObjectId<LT,CM> ();
74 auto *ptr2 = dynamic_cast<typename LT::xAODObjectIdType*>(ptr);
75 if (!ptr2) throw std::runtime_error ("link not of expected type");
76 return OptObjectId<LT,CM> (ptr2);
77 } else
78 {
79 return OptObjectId<LT,CM> ();
80 }
81 }
82 };
83
84
85
86
87
88 // in Array mode we take an index from the underlying column and
89 // combine it with the data vector from the input to get the new
90 // OptObjectId
91 template<ContainerIdConcept LT>
93 {
95 using ColumnType = typename CM::LinkIndexType;
97 using DataType = void **;
98 static constexpr bool isNativeType = false;
99 static constexpr bool useConvertInput = false;
100 static constexpr bool useConvertWithDataInput = true;
101 static ColumnInfo& updateColumnInfo (ColumnarTool<CM>& /*columnarTool*/, ColumnInfo& info)
102 {
103 info.linkTargetNames = {std::string{LT::idName}};
104 return info;
105 }
106
107 static OptObjectId<LT> convertInput (void **data, typename CM::LinkIndexType link)
108 {
109 if (link == invalidObjectIndex)
110 return OptObjectId<LT,CM> ();
111 return OptObjectId<LT,CM> (data, link);
112 }
113 };
114
115 // I'm just inheriting the ColumnTypeTraits from OptObjectId, as the
116 // behavior is exactly the same. Note that this is only for regular
117 // container IDs, as e.g. VariantContainerId needs special handling.
118 template<RegularContainerIdConcept LT,typename ELT>
119 struct ColumnTypeTraits<LinkCastColumn<LT,ELT>,ColumnarModeArray> : ColumnTypeTraits<OptObjectId<LT>,ColumnarModeArray> {};
120}
121
122#endif
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
the base class for all columnar components
a class representing a single optional object (electron, muons, etc.)
constexpr ColumnarOffsetType invalidObjectIndex
the value for an invalid element index
a struct that contains meta-information about each column that's needed to interface the column with ...
Definition ColumnInfo.h:35
static OptObjectId< LT > convertInput(const ElementLink< ELT > &link)
Definition LinkColumn.h:68
static ColumnInfo & updateColumnInfo(ColumnarTool< CM > &, ColumnInfo &info)
Definition LinkColumn.h:66
static OptObjectId< LT > convertInput(void **data, typename CM::LinkIndexType link)
Definition LinkColumn.h:107
static ColumnInfo & updateColumnInfo(ColumnarTool< CM > &, ColumnInfo &info)
Definition LinkColumn.h:101
NativeColumn< ElementLink< typename LT::xAODElementLinkType > > ColumnType
Definition LinkColumn.h:36
static OptObjectId< LT > convertInput(const ElementLink< typename LT::xAODElementLinkType > &link)
Definition LinkColumn.h:43
static ColumnInfo & updateColumnInfo(ColumnarTool< CM > &, ColumnInfo &info)
Definition LinkColumn.h:41
a trait class to provide information about the column type
std::size_t LinkIndexType
the type used for columns that represent element links
Definition ColumnarDef.h:68
a special column type that behaves like an OptObjectId, but applies an internal cast in xAOD mode
Definition LinkColumn.h:25
a type wrapper to force AccessorTemplate to treat the type as native