ATLAS Offline Software
Loading...
Searching...
No Matches
OptObjectId.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_OPT_OBJECT_ID_H
9#define COLUMNAR_CORE_OPT_OBJECT_ID_H
10
13
14namespace columnar
15{
24 template<ContainerIdConcept CI, typename CM> class OptObjectId;
25
26
27
28
29
30 template<ContainerIdConcept CI> class OptObjectId<CI,ColumnarModeXAOD> final
31 {
34 public:
35
36 using xAODObject = typename CI::xAODObjectIdType;
37
38 OptObjectId () noexcept = default;
39
40 OptObjectId (std::nullopt_t) noexcept {}
41
43 : m_object (&val_object.getXAODObjectNoexcept())
44 {}
45
46 OptObjectId (xAODObject *val_object) noexcept
47 : m_object (val_object)
48 {}
49
50 OptObjectId (const OptObjectId<CI,ColumnarModeXAOD>& that) noexcept = default;
51
52 OptObjectId& operator = (const OptObjectId<CI,ColumnarModeXAOD>& that) noexcept = default;
53
54 explicit operator bool () const noexcept {
55 return m_object != nullptr;}
56
57 [[nodiscard]] bool has_value () const noexcept {
58 return m_object != nullptr;}
59
60 [[nodiscard]] ObjectId<CI,ColumnarModeXAOD> value () const {
61 if (m_object == nullptr)
62 throw std::bad_optional_access();
63 // This object should ever be held within the context of a
64 // single thread (and generally on the stack), so the associated
65 // check is meaningless.
68
70 if (m_object == nullptr)
71 throw std::bad_optional_access();
73
74 [[nodiscard]] xAODObject *getXAODObject () const noexcept {
75 return m_object;}
76
77 // a version of `getXAODObject` that only exists when it is `noexcept`
78 [[nodiscard]] xAODObject *getXAODObjectNoexcept () const noexcept {
79 return m_object;}
80
81 [[nodiscard]] bool operator == (const OptObjectId<CI,ColumnarModeXAOD>& that) const noexcept {
82 return m_object == that.m_object;}
83
84
85
88 private:
89
90 xAODObject *m_object = nullptr;
91 };
92
93 template<ContainerIdConcept CI>
95 {
96 return lhs.getXAODObjectNoexcept() == rhs.getXAODObjectNoexcept();
97 }
98
99 template<ContainerIdConcept CI>
101 {
102 return lhs.getXAODObjectNoexcept() != rhs.getXAODObjectNoexcept();
103 }
104
105
106
107
108 template<ContainerIdConcept CI> class OptObjectId<CI,ColumnarModeArray> final
109 {
112 public:
113
114 using xAODObject = typename CI::xAODObjectIdType;
115
116 OptObjectId () noexcept = default;
117
118 OptObjectId (std::nullopt_t) noexcept {}
119
121 : m_data (val_object.getData()), m_index (val_object.getIndex())
122 {}
123
124 // Whatever you do: Do not remove this function. Yes, it will always
125 // throw. It is meant to throw in this template specialization, and
126 // only do something useful in the xAOD mode specialization. If you
127 // remove it you break the columnar mode.
128 OptObjectId (xAODObject * /*val_object*/)
129 {
130 throw std::logic_error ("can't call xAOD function in columnar mode");
131 }
132
133 OptObjectId (const OptObjectId<CI,ColumnarModeArray>& that) noexcept = default;
134
135 OptObjectId& operator = (const OptObjectId<CI,ColumnarModeArray>& that) noexcept = default;
136
137 // Whatever you do: Do not remove this function. Yes, it will always
138 // throw. It is meant to throw in this template specialization, and
139 // only do something useful in the xAOD mode specialization. If you
140 // remove it you break the columnar mode.
141 [[nodiscard]] xAODObject *getXAODObject () const {
142 throw std::logic_error ("can't call xAOD function in columnar mode");}
143
144 explicit operator bool () const noexcept {
145 return m_index != invalidObjectIndex;}
146
147 [[nodiscard]] bool has_value () const noexcept {
148 return m_index != invalidObjectIndex;}
149
150 [[nodiscard]] ObjectId<CI,ColumnarModeArray> value () const {
152 throw std::bad_optional_access();
154
157 throw std::bad_optional_access();
159
160 [[nodiscard]] bool operator == (const OptObjectId<CI,ColumnarModeArray>& that) const noexcept {
161 return m_index == that.m_index;}
162
163
164
167 public:
168
169 explicit OptObjectId (void **val_data, int val_index) noexcept
170 : m_data (val_data), m_index (val_index)
171 {}
172
173 explicit OptObjectId (void **val_data, unsigned val_index) noexcept
174 : m_data (val_data), m_index (val_index)
175 {}
176
177 explicit OptObjectId (void **val_data, std::size_t val_index) noexcept
178 : m_data (val_data), m_index (val_index)
179 {}
180
181 [[nodiscard]] std::size_t getIndex () const noexcept {
182 return m_index;}
183
184 [[nodiscard]] void **getData () const noexcept {
185 return m_data;}
186
187
188
191 private:
192
193 void **m_data = nullptr;
195 };
196
197 template<ContainerIdConcept CI>
199 {
200 return lhs.getIndex() == rhs.getIndex();
201 }
202
203 template<ContainerIdConcept CI>
205 {
206 return lhs.getIndex() != rhs.getIndex();
207 }
208}
209
210#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.)
ObjectId< CI, ColumnarModeArray > value() const
OptObjectId(void **val_data, std::size_t val_index) noexcept
OptObjectId(const OptObjectId< CI, ColumnarModeArray > &that) noexcept=default
OptObjectId(ObjectId< CI, ColumnarModeArray > val_object) noexcept
typename CI::xAODObjectIdType xAODObject
OptObjectId(void **val_data, int val_index) noexcept
OptObjectId(void **val_data, unsigned val_index) noexcept
ObjectId< CI, ColumnarModeXAOD > value() const
Definition OptObjectId.h:60
OptObjectId(const OptObjectId< CI, ColumnarModeXAOD > &that) noexcept=default
OptObjectId(ObjectId< CI, ColumnarModeXAOD > val_object) noexcept
Definition OptObjectId.h:42
OptObjectId(xAODObject *val_object) noexcept
Definition OptObjectId.h:46
xAODObject * getXAODObjectNoexcept() const noexcept
Definition OptObjectId.h:78
xAODObject * getXAODObject() const noexcept
Definition OptObjectId.h:74
typename CI::xAODObjectIdType xAODObject
Definition OptObjectId.h:36
a class representing a single optional object (electron, muons, etc.)
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
STL namespace.
std::map< std::string, HypoJetVector >::const_iterator CI