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>
15
16namespace columnar
17{
25 template<ContainerIdConcept LT,typename ELT>
26 struct LinkCastColumn {};
27
28
29
30 namespace detail
31 {
34 template<ContainerIdConcept LT>
36 {
37 if constexpr (requires { LT::containerClid(); })
38 return LT::containerClid();
39 else
40 return 0;
41 }
42
43 // if the columnar mode uses typed links, then the links with the
44 // implicit types can simply redirect to the code for typed links
45 template<ContainerIdConcept LT,ColumnarMode CM>
46 requires (CM::hasTypedLinks == true)
48 {
49 public:
50
52 static_assert (BaseAccessor::isDefined, "MemoryAccessor for LinkCastColumn must be defined");
53
54 static constexpr bool isDefined = true;
55 static constexpr bool viewIsReference = BaseAccessor::viewIsReference;
56 static constexpr bool hasSetter = false;
57 using MemoryType = typename BaseAccessor::MemoryType;
58
59 static void updateColumnInfo (ColumnInfo& info)
60 {
61 BaseAccessor::updateColumnInfo (info);
62 }
63
64 [[nodiscard]] static auto makeViewer (void** dataArea)
65 {
66 return BaseAccessor::makeViewer(dataArea);
67 }
68 };
69
70 // I'm just using the MemoryAccessor from OptObjectId, as the
71 // behavior is exactly the same. Note that this is only for regular
72 // container IDs, as e.g. VariantContainerId needs special handling.
73 template<RegularContainerIdConcept LT,typename ELT,ColumnarMode CM>
74 requires (CM::hasTypedLinks == false && MemoryAccessor<OptObjectId<LT>,CM>::isDefined)
76 {
77 public:
78
80
81 static constexpr bool isDefined = true;
82 static constexpr bool viewIsReference = BaseAccessor::viewIsReference;
83 static constexpr bool hasSetter = false;
84 using MemoryType = typename BaseAccessor::MemoryType;
85
86 static void updateColumnInfo (ColumnInfo& info)
87 {
88 BaseAccessor::updateColumnInfo (info);
89 // the persistified links are typed on ELT, so that is the CLID
90 // entering the stored keys
91 info.soleLinkTargetClid = clidForType<ELT>();
92 }
93
94 [[nodiscard]] static auto makeViewer (void** dataArea)
95 {
96 return BaseAccessor::makeViewer(dataArea);
97 }
98 };
99
100
101
102 template<ContainerIdConcept LT,typename ELT>
104 {
105 public:
107 static constexpr bool isDefined = true;
108 static constexpr bool viewIsReference = false;
109 static constexpr bool hasSetter = false;
111 static auto makeViewer (void**)
112 {
113 return [] (const ElementLink<ELT>& link)
114 {
115 if (link.isValid())
116 {
117 auto *ptr = *link.cptr();
118 if (!ptr) return OptObjectId<LT,CM> ();
119 auto *ptr2 = dynamic_cast<typename LT::xAODObjectIdType*>(ptr);
120 if (!ptr2) throw std::runtime_error ("link not of expected type");
121 return OptObjectId<LT,CM> (ptr2);
122 } else
123 {
124 return OptObjectId<LT,CM> ();
125 }
126 };
127 }
128 };
129
130
131
132
133 // in Array mode we take an index from the underlying column and
134 // combine it with the data vector from the input to get the new
135 // OptObjectId
136 template<ContainerIdConcept LT>
138 {
139 public:
140
142 static constexpr bool isDefined = true;
143 static constexpr bool viewIsReference = false;
144 static constexpr bool hasSetter = false;
146
147 static void updateColumnInfo (ColumnInfo& info)
148 {
149 info.soleLinkTargetName = LT::idName;
150 info.soleLinkTargetClid = linkTargetClid<LT>();
151 }
152
153 [[nodiscard]] static auto makeViewer (void** dataArea)
154 {
155 return [dataArea](const MemoryType& link)
156 {
157 if (link == invalidObjectIndex)
158 return OptObjectId<LT,CM> ();
159 return OptObjectId<LT,CM> (dataArea, link);
160 };
161 }
162 };
163
164
165
166 template<ContainerIdConcept LT,typename ELT>
168 {
169 public:
171 static constexpr bool isDefined = true;
172 static constexpr bool viewIsReference = false;
173 static constexpr bool hasSetter = false;
175
176 static void updateColumnInfo (ColumnInfo& info)
177 {
178 info.soleLinkTargetName = LT::idName;
179 info.soleLinkTargetClid = clidForType<ELT>();
180 }
181
182 static auto makeViewer (void** dataArea)
183 {
184 return [dataArea] (const ElementLink<ELT>& link)
185 {
186 if (link.isValid())
187 {
188 return OptObjectId<LT,CM> (dataArea, link.index());
189 } else
190 {
191 return OptObjectId<LT,CM> ();
192 }
193 };
194 }
195 };
196 }
197}
198
199#endif
uint32_t CLID
The Class ID type.
a class representing a single optional object (electron, muons, etc.)
MemoryAccessor< OptObjectId< LT >, CM > BaseAccessor
Definition LinkColumn.h:79
MemoryAccessor< LinkCastColumn< LT, typename LT::xAODElementLinkType >, CM > BaseAccessor
Definition LinkColumn.h:51
a help implementation of AccessorTemplate that handles type conversions
CLID clidForType()
the CLID of a container type, or 0 when it cannot be determined
CLID linkTargetClid()
the CLID of the xAOD container a link column targets, or 0 if the container id does not provide one
Definition LinkColumn.h:35
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:36
std::size_t LinkIndexType
the type used for columns that represent element links
a special column type that behaves like an OptObjectId, but applies an internal cast in xAOD mode
Definition LinkColumn.h:26