ATLAS Offline Software
Loading...
Searching...
No Matches
VariantOptObjectId.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_VARIANT_VARIANT_OPT_OBJECT_ID_H
9#define COLUMNAR_VARIANT_VARIANT_OPT_OBJECT_ID_H
10
14
15namespace columnar
16{
17 template<ContainerIdConcept... CIList>
19 {
22 public:
23
24 using CI = VariantContainerId<CIList...>;
27
28 OptObjectId () noexcept = default;
29
30 OptObjectId (std::nullopt_t) noexcept {}
31
32 OptObjectId (const ObjectId<CI,ColumnarModeXAOD>& val_object) noexcept
33 : m_object (&val_object.getXAODObjectNoexcept())
34 {}
35
36 OptObjectId (xAODObject *val_object) noexcept
37 : m_object (val_object)
38 {}
39
40 template<ContainerIdConcept CI2>
41 requires (CI::template isValidContainer<CI2>())
43 : m_object (&val_object.getXAODObjectNoexcept())
44 {}
45
46 template<ContainerIdConcept CI2>
47 requires (CI::template isValidContainer<CI2>())
49 : m_object (val_object.getXAODObjectNoexcept())
50 {}
51
52 OptObjectId (const OptObjectId<CI,ColumnarModeXAOD>& that) noexcept = default;
53
54 OptObjectId& operator = (const OptObjectId<CI,ColumnarModeXAOD>& that) noexcept = default;
55
56 explicit operator bool () const noexcept {
57 return m_object != nullptr;}
58
59 [[nodiscard]] bool has_value () const noexcept {
60 return m_object != nullptr;}
61
62 [[nodiscard]] ObjectId<CI,ColumnarModeXAOD> value () const {
63 if (m_object == nullptr)
64 throw std::bad_optional_access();
65 // This object should ever be held within the context of a
66 // single thread (and generally on the stack), so the associated
67 // check is meaningless.
70
72 if (m_object == nullptr)
73 throw std::bad_optional_access();
75
76 [[nodiscard]] xAODObject *getXAODObject () const noexcept {
77 return m_object;}
78
79 // a version of `getXAODObject` that only exists when it is `noexcept`
80 [[nodiscard]] xAODObject *getXAODObjectNoexcept () const noexcept {
81 return m_object;}
82
83 [[nodiscard]] bool operator == (const OptObjectId<CI,ColumnarModeXAOD>& that) const noexcept {
84 return m_object == that.m_object;}
85
86
87
90 private:
91
92 xAODObject *m_object = nullptr;
93 };
94
95 template<ContainerIdConcept... CIList>
97 {
98 return str << &obj.getXAODObjectNoexcept() << "/" << obj.getXAODObjectNoexcept().index();
99 }
100
101 template<ContainerIdConcept... CIList>
103 {
104 return &lhs.getXAODObjectNoexcept() == &rhs.getXAODObjectNoexcept();
105 }
106
107 template<ContainerIdConcept... CIList>
109 {
110 return &lhs.getXAODObjectNoexcept() != &rhs.getXAODObjectNoexcept();
111 }
112
113
114
115
116 template<ContainerIdConcept... CIList> class OptObjectId<VariantContainerId<CIList...>,ColumnarModeArray> final
117 {
120 public:
121
122 using CI = VariantContainerId<CIList...>;
125 static constexpr std::size_t invalidVariantIndex = CI::numVariants;
126
127 OptObjectId () noexcept = default;
128
129 OptObjectId (std::nullopt_t) noexcept {}
130
132 : m_data (val_object.getData()), m_variantIndex (val_object.getVariantIndex()), m_objectIndex (val_object.getObjectIndex())
133 {}
134
135 template<ContainerIdConcept CI2>
136 requires (CI::template isValidContainer<CI2>())
138 : m_data (val_object.getData()), m_variantIndex (CI::template getVariantIndex<CI2>()), m_objectIndex (val_object.getIndex())
139 {}
140
141 template<ContainerIdConcept CI2>
142 requires (CI::template isValidContainer<CI2>())
144 : m_data (val_object.getData())
145 {
146 if (val_object.has_value())
147 {
148 m_variantIndex = CI::template getVariantIndex<CI2>();
149 m_objectIndex = val_object.getIndex();
150 } else
151 {
154 }
155 }
156
157 // Whatever you do: Do not remove this function. Yes, it will always
158 // throw. It is meant to throw in this template specialization, and
159 // only do something useful in the xAOD mode specialization. If you
160 // remove it you break the columnar mode.
161 OptObjectId (xAODObject * /*val_object*/)
162 {
163 throw std::logic_error ("can't call xAOD function in columnar mode");
164 }
165
166 OptObjectId (const OptObjectId<CI,ColumnarModeArray>& that) noexcept = default;
167
168 OptObjectId& operator = (const OptObjectId<CI,ColumnarModeArray>& that) noexcept = default;
169
170 // Whatever you do: Do not remove this function. Yes, it will always
171 // throw. It is meant to throw in this template specialization, and
172 // only do something useful in the xAOD mode specialization. If you
173 // remove it you break the columnar mode.
174 [[nodiscard]] xAODObject *getXAODObject () const {
175 throw std::logic_error ("can't call xAOD function in columnar mode");}
176
177 explicit operator bool () const noexcept {
179
180 [[nodiscard]] bool has_value () const noexcept {
182
183 [[nodiscard]] ObjectId<CI,ColumnarModeArray> value () const {
185 throw std::bad_optional_access();
187
190 throw std::bad_optional_access();
192 }
193
194 [[nodiscard]] bool operator == (const OptObjectId<CI,ColumnarModeArray>& that) const noexcept {
195 return m_variantIndex == that.m_variantIndex && m_objectIndex == that.m_objectIndex;
196 }
197
198
199
202 public:
203
204 explicit OptObjectId (void **val_data, std::size_t val_variantIndex, std::size_t val_objectIndex) noexcept
205 : m_data (val_data), m_variantIndex (val_variantIndex), m_objectIndex (val_objectIndex)
206 {}
207
208 [[nodiscard]] std::size_t getVariantIndex () const noexcept {
209 return m_variantIndex;}
210
211 [[nodiscard]] std::size_t getObjectIndex () const noexcept {
212 return m_objectIndex;}
213
214 [[nodiscard]] void **getData () const noexcept {
215 return m_data;}
216
217
218
221 private:
222
223 void **m_data = nullptr;
226 };
227
228 template<ContainerIdConcept... CIList>
230 {
231 using CI = VariantContainerId<CIList...>;
232 return str << CI::idNameArray.at(obj.getVariantIndex()) << "/" << obj.getObjectIndex();
233 }
234
235 template<ContainerIdConcept... CIList>
237 {
238 return lhs.getVariantIndex() == rhs.getVariantIndex() && lhs.getObjectIndex() == rhs.getObjectIndex();
239 }
240
241 template<ContainerIdConcept... CIList>
243 {
244 return lhs.getVariantIndex() != rhs.getVariantIndex() || lhs.getObjectIndex() != rhs.getObjectIndex();
245 }
246}
247
248#endif
xAOD::MissingET_v1 operator*(const xAOD::MissingET_v1 &met, float scale)
Create new MET object from source with scaled (weighted) kinematics.
#define ATLAS_THREAD_SAFE
a class representing a single object (electron, muons, etc.)
OptObjectId(const OptObjectId< CI, ColumnarModeArray > &that) noexcept=default
OptObjectId(ObjectId< CI, ColumnarModeArray > val_object) noexcept
OptObjectId(void **val_data, std::size_t val_variantIndex, std::size_t val_objectIndex) noexcept
OptObjectId(const ObjectId< CI, ColumnarModeXAOD > &val_object) noexcept
OptObjectId(const OptObjectId< CI, ColumnarModeXAOD > &that) noexcept=default
a class representing a single optional object (electron, muons, etc.)
concept for a container id
bool operator==(const ObjectId< CI, ColumnarModeXAOD > &lhs, const ObjectId< CI, ColumnarModeXAOD > &rhs)
Definition ObjectId.h:82
bool operator!=(const ObjectId< CI, ColumnarModeXAOD > &lhs, const ObjectId< CI, ColumnarModeXAOD > &rhs)
Definition ObjectId.h:88
constexpr ColumnarOffsetType invalidObjectIndex
the value for an invalid element index
std::ostream & operator<<(std::ostream &str, const ObjectId< CI, ColumnarModeXAOD > &obj)
Definition ObjectId.h:76
STL namespace.
a "variant" ContainerId
Definition VariantDef.h:98
static constexpr std::size_t numVariants
Definition VariantDef.h:128
typename CIBase::xAODObjectIdType xAODObjectIdType
Definition VariantDef.h:114
std::map< std::string, HypoJetVector >::const_iterator CI