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 namespace detail
30 {
31 // if the columnar mode uses typed links, then the links with the
32 // implicit types can simply redirect to the code for typed links
33 template<ContainerIdConcept LT,ColumnarMode CM>
34 requires (CM::hasTypedLinks == true)
36 {
37 public:
38
40 static_assert (BaseAccessor::isDefined, "MemoryAccessor for LinkCastColumn must be defined");
41
42 static constexpr bool isDefined = true;
43 static constexpr bool viewIsReference = BaseAccessor::viewIsReference;
44 static constexpr bool hasSetter = false;
45 using MemoryType = typename BaseAccessor::MemoryType;
46
47 static void updateColumnInfo (ColumnInfo& info)
48 {
49 BaseAccessor::updateColumnInfo (info);
50 }
51
52 [[nodiscard]] static auto makeViewer (void** dataArea)
53 {
54 return BaseAccessor::makeViewer(dataArea);
55 }
56 };
57
58 // I'm just using the MemoryAccessor from OptObjectId, as the
59 // behavior is exactly the same. Note that this is only for regular
60 // container IDs, as e.g. VariantContainerId needs special handling.
61 template<RegularContainerIdConcept LT,typename ELT,ColumnarMode CM>
62 requires (CM::hasTypedLinks == false && MemoryAccessor<OptObjectId<LT>,CM>::isDefined)
64 {
65 public:
66
68
69 static constexpr bool isDefined = true;
70 static constexpr bool viewIsReference = BaseAccessor::viewIsReference;
71 static constexpr bool hasSetter = false;
72 using MemoryType = typename BaseAccessor::MemoryType;
73
74 static void updateColumnInfo (ColumnInfo& info)
75 {
76 BaseAccessor::updateColumnInfo (info);
77 }
78
79 [[nodiscard]] static auto makeViewer (void** dataArea)
80 {
81 return BaseAccessor::makeViewer(dataArea);
82 }
83 };
84
85
86
87 template<ContainerIdConcept LT,typename ELT>
89 {
90 public:
92 static constexpr bool isDefined = true;
93 static constexpr bool viewIsReference = false;
94 static constexpr bool hasSetter = false;
96 static auto makeViewer (void**)
97 {
98 return [] (const ElementLink<ELT>& link)
99 {
100 if (link.isValid())
101 {
102 auto *ptr = *link.cptr();
103 if (!ptr) return OptObjectId<LT,CM> ();
104 auto *ptr2 = dynamic_cast<typename LT::xAODObjectIdType*>(ptr);
105 if (!ptr2) throw std::runtime_error ("link not of expected type");
106 return OptObjectId<LT,CM> (ptr2);
107 } else
108 {
109 return OptObjectId<LT,CM> ();
110 }
111 };
112 }
113 };
114
115
116
117
118 // in Array mode we take an index from the underlying column and
119 // combine it with the data vector from the input to get the new
120 // OptObjectId
121 template<ContainerIdConcept LT>
123 {
124 public:
125
127 static constexpr bool isDefined = true;
128 static constexpr bool viewIsReference = false;
129 static constexpr bool hasSetter = false;
131
132 static void updateColumnInfo (ColumnInfo& info)
133 {
134 info.linkTargetNames = {std::string{LT::idName}};
135 }
136
137 [[nodiscard]] static auto makeViewer (void** dataArea)
138 {
139 return [dataArea](const MemoryType& link)
140 {
141 if (link == invalidObjectIndex)
142 return OptObjectId<LT,CM> ();
143 return OptObjectId<LT,CM> (dataArea, link);
144 };
145 }
146 };
147
148
149
150 template<ContainerIdConcept LT,typename ELT>
152 {
153 public:
155 static constexpr bool isDefined = true;
156 static constexpr bool viewIsReference = false;
157 static constexpr bool hasSetter = false;
159
160 static void updateColumnInfo (ColumnInfo& info)
161 {
162 info.linkTargetNames = {std::string{LT::idName}};
163 }
164
165 static auto makeViewer (void** dataArea)
166 {
167 return [dataArea] (const ElementLink<ELT>& link)
168 {
169 if (link.isValid())
170 {
171 return OptObjectId<LT,CM> (dataArea, link.index());
172 } else
173 {
174 return OptObjectId<LT,CM> ();
175 }
176 };
177 }
178 };
179 }
180}
181
182#endif
a class representing a single optional object (electron, muons, etc.)
MemoryAccessor< OptObjectId< LT >, CM > BaseAccessor
Definition LinkColumn.h:67
MemoryAccessor< LinkCastColumn< LT, typename LT::xAODElementLinkType >, CM > BaseAccessor
Definition LinkColumn.h:39
a help implementation of AccessorTemplate that handles type conversions
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
std::size_t LinkIndexType
the type used for columns that represent element links
Definition ColumnarDef.h:92
a special column type that behaves like an OptObjectId, but applies an internal cast in xAOD mode
Definition LinkColumn.h:25