ATLAS Offline Software
Loading...
Searching...
No Matches
ColumnarDef.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef COLUMNAR_CORE_COLUMNAR_DEF_H
6#define COLUMNAR_CORE_COLUMNAR_DEF_H
7
8#include <cstdint>
9#include <stdexcept>
10
11namespace columnar
12{
13 // This checks that COLUMNAR_DEFAULT_ACCESS_MODE is indeed defined, plus makes it
14 // available for use with `if constexpr`.
15 constexpr unsigned columnarAccessMode = COLUMNAR_DEFAULT_ACCESS_MODE;
16
18 {
20 static constexpr bool isColumnarMode = true;
21
23 static constexpr bool isXAOD = true;
24
26 static constexpr bool isArrayMode = false;
27
33 static constexpr bool inPlaceReplace = true;
34 };
35
36
37
39 {
41 static constexpr bool isColumnarMode = true;
42
44 static constexpr bool isXAOD = false;
45
47 static constexpr bool isArrayMode = true;
48
54 static constexpr bool inPlaceReplace = false;
55
56
78
80 using LinkIndexType = std::size_t;
81
83 static constexpr LinkIndexType invalidLinkValue = static_cast<LinkIndexType>(-1);
84
86 static constexpr unsigned linkKeyBits = 8;
87
89 using LinkKeyType = std::uint8_t;
90
92 static_assert (linkKeyBits <= 8 * sizeof(LinkKeyType), "Link key bits exceed key type size");
93 static_assert (linkKeyBits < 8 * sizeof(LinkIndexType), "Link key bits exceed link type size");
94 static constexpr unsigned linkIndexBits = 8 * sizeof(LinkIndexType) - linkKeyBits;
95 static constexpr LinkIndexType linkIndexMask = (static_cast<LinkIndexType>(1) << linkIndexBits) - 1;
96
98 static inline LinkKeyType getLinkKey (LinkIndexType link) {
99 return link >> linkIndexBits;
100 }
101
104 return link & linkIndexMask;
105 }
106
109 if (key >= (static_cast<LinkIndexType>(1) << linkKeyBits))
110 throw std::runtime_error ("link key too large to fit in link: " + std::to_string(key));
111 if (index & ~linkIndexMask)
112 throw std::runtime_error ("index too large to fit in link: " + std::to_string(index));
113 return index | (key << linkIndexBits);
114 }
115 };
116
117
118
120 {
122 static constexpr bool isColumnarMode = true;
123
125 static constexpr bool isXAOD = false;
126
128 static constexpr bool isArrayMode = true;
129
135 static constexpr bool inPlaceReplace = true;
136
137
138 // /// Element Link Definition
139 // /// =======================
140 // ///
141 // /// In general links are just represented by an integer index into
142 // /// the target container. However, for variant links (i.e. links
143 // /// pointing into one of multiple containers) we need to be able to
144 // /// identify the target container. This happens by using the top
145 // /// couple of bits of the index to identify the target container.
146 // ///
147 // /// For variant links there is also an additional column that
148 // /// contains the keys for the target containers for each link, in
149 // /// the order the tool defined. If there are multiple accessors for
150 // /// the same variant link column, they will share the same key
151 // /// column and as such need to define the variant in the same way.
152 // ///
153 // /// There are a couple of configurable aspects to this, like the
154 // /// exact types involved, as well as the number of bits used for the
155 // /// key, all of which can be configured through the columnar mode.
156 // /// Beyond that there are also a couple of helper functions and
157 // /// convenience definitions to avoid bit packing/unpacking code
158 // /// being repeated in multiple places.
159
161 using LinkIndexType = std::size_t;
162
164 static constexpr LinkIndexType invalidLinkValue = static_cast<LinkIndexType>(-1);
165
166 // /// the number of bits used for the key inside the link
167 // static constexpr unsigned linkKeyBits = 8;
168
170 using LinkKeyType = std::uint32_t;
171
172 // /// various helper definitions
173 // static_assert (linkKeyBits <= 8 * sizeof(LinkKeyType), "Link key bits exceed key type size");
174 // static_assert (linkKeyBits < 8 * sizeof(LinkIndexType), "Link key bits exceed link type size");
175 // static constexpr unsigned linkIndexBits = 8 * sizeof(LinkIndexType) - linkKeyBits;
176 // static constexpr LinkIndexType linkIndexMask = (static_cast<LinkIndexType>(1) << linkIndexBits) - 1;
177
178 // /// get the key value from a link value
179 // static inline LinkKeyType getLinkKey (LinkIndexType link) {
180 // return link >> linkIndexBits;
181 // }
182
183 // /// get the index value from a link value
184 // static inline LinkIndexType getLinkIndex (LinkIndexType link) {
185 // return link & linkIndexMask;
186 // }
187
188 // /// merge a key and index value into a link value
189 // static inline LinkIndexType mergeLinkKeyIndex (LinkIndexType key, LinkIndexType index) {
190 // if (key >= (static_cast<LinkIndexType>(1) << linkKeyBits))
191 // throw std::runtime_error ("link key too large to fit in link: " + std::to_string(key));
192 // if (index & ~linkIndexMask)
193 // throw std::runtime_error ("index too large to fit in link: " + std::to_string(index));
194 // return index | (key << linkIndexBits);
195 // }
196 };
197
198 template<typename Mode>
199 concept ColumnarMode = Mode::isColumnarMode;
200 template<typename Mode>
201 concept ColumnarArrayMode = ColumnarMode<Mode> && Mode::isArrayMode;
202
203
204
205#if COLUMNAR_DEFAULT_ACCESS_MODE == 0
207#elif COLUMNAR_DEFAULT_ACCESS_MODE == 2
209#elif COLUMNAR_DEFAULT_ACCESS_MODE == 100
211#else
212 #error "COLUMNAR_DEFAULT_ACCESS_MODE must be 0, 2, or 100"
213#endif
214}
215
216#endif
ColumnarModeXAOD ColumnarModeDefault
constexpr unsigned columnarAccessMode
Definition ColumnarDef.h:15
Definition index.py:1
static constexpr unsigned linkKeyBits
the number of bits used for the key inside the link
Definition ColumnarDef.h:86
static constexpr bool isXAOD
Whether this is the xAOD mode.
Definition ColumnarDef.h:44
static constexpr LinkIndexType linkIndexMask
Definition ColumnarDef.h:95
std::size_t LinkIndexType
the type used for columns that represent element links
Definition ColumnarDef.h:80
static constexpr unsigned linkIndexBits
various helper definitions
Definition ColumnarDef.h:94
static LinkKeyType getLinkKey(LinkIndexType link)
get the key value from a link value
Definition ColumnarDef.h:98
static constexpr LinkIndexType invalidLinkValue
the value used for an invalid link (a.k.a. empty/null link)
Definition ColumnarDef.h:83
static LinkIndexType mergeLinkKeyIndex(LinkIndexType key, LinkIndexType index)
merge a key and index value into a link value
static constexpr bool inPlaceReplace
Whether for this columnar mode decorators that replace the original column will also refer to the inp...
Definition ColumnarDef.h:54
static constexpr bool isArrayMode
Whether this is an array mode.
Definition ColumnarDef.h:47
std::uint8_t LinkKeyType
the type used for the key column
Definition ColumnarDef.h:89
static LinkIndexType getLinkIndex(LinkIndexType link)
get the index value from a link value
static constexpr bool isColumnarMode
Whather this is a columnar mode.
Definition ColumnarDef.h:41
static constexpr bool inPlaceReplace
Whether for this columnar mode decorators that replace the original column will also refer to the inp...
static constexpr LinkIndexType invalidLinkValue
the value used for an invalid link (a.k.a. empty/null link)
std::uint32_t LinkKeyType
the type used for the key column
static constexpr bool isArrayMode
Whether this is an array mode.
std::size_t LinkIndexType
the type used for columns that represent element links
static constexpr bool isColumnarMode
Whather this is a columnar mode.
static constexpr bool isXAOD
Whether this is the xAOD mode.
static constexpr bool isColumnarMode
Whather this is a columnar mode.
Definition ColumnarDef.h:20
static constexpr bool inPlaceReplace
Whether for this columnar mode decorators that replace the original column will also refer to the inp...
Definition ColumnarDef.h:33
static constexpr bool isXAOD
Whether this is the xAOD mode.
Definition ColumnarDef.h:23
static constexpr bool isArrayMode
Whether this is an array mode.
Definition ColumnarDef.h:26