ATLAS Offline Software
Loading...
Searching...
No Matches
VariantObjectId.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_OBJECT_ID_H
9#define COLUMNAR_VARIANT_VARIANT_OBJECT_ID_H
10
13
14namespace columnar
15{
16 template<ContainerIdConcept... CIList>
18 {
21 public:
22
23 using CI = VariantContainerId<CIList...>;
26
27 ObjectId (xAODObject& val_object) noexcept
28 : m_object (&val_object)
29 {}
30
32
33 template<ContainerIdConcept CI2>
34 requires (CI::template isValidContainer<CI2>())
35 ObjectId (const ObjectId<CI2,CM>& that) noexcept
36 : m_object (&that.getXAODObject())
37 {}
38
39 ObjectId& operator = (const ObjectId<VariantContainerId<CIList...>,ColumnarModeXAOD>& that) noexcept = default;
40
41 [[nodiscard]] xAODObject& getXAODObject () const noexcept {
42 // This object should ever be held within the context of a
43 // single thread (and generally on the stack), so the associated
44 // check is meaningless.
46 return *result;}
47
48 // a version of `getXAODObject` that only exists when it is `noexcept`
49 [[nodiscard]] xAODObject& getXAODObjectNoexcept () const noexcept {
50 // This object should ever be held within the context of a
51 // single thread (and generally on the stack), so the associated
52 // check is meaningless.
54 return *result;}
55
56 template<ContainerIdConcept CI2>
57 requires (CI::template isValidContainer<CI2>())
58 [[nodiscard]] OptObjectId<CI2,CM> tryGetVariant () const
59 {
60 return OptObjectId<CI2,CM> (dynamic_cast<typename CI2::xAODObjectIdType*>(m_object));
61 }
62
63 template<typename Acc,typename... Args>
64 requires std::invocable<Acc,ObjectId<VariantContainerId<CIList...>,ColumnarModeXAOD>,Args...>
65 [[nodiscard]] decltype(auto) operator() (Acc& acc, Args&&... args) const {
66 return acc (*this, std::forward<Args> (args)...);}
67
68
71 public:
72
77
78
81 private:
82
83 xAODObject *m_object = nullptr;
84 };
85
86 template<ContainerIdConcept... CIList>
87 std::ostream& operator<< (std::ostream& str, const ObjectId<VariantContainerId<CIList...>,ColumnarModeXAOD>& obj)
88 {
89 return str << &obj.getXAODObjectNoexcept() << "/" << obj.getXAODObjectNoexcept().index();
90 }
91
92 template<ContainerIdConcept... CIList>
94 {
95 return &lhs.getXAODObjectNoexcept() == &rhs.getXAODObjectNoexcept();
96 }
97
98 template<ContainerIdConcept... CIList>
100 {
101 return &lhs.getXAODObjectNoexcept() != &rhs.getXAODObjectNoexcept();
102 }
103
104
105
106
107 template<ContainerIdConcept... CIList, ColumnarArrayMode CM>
108 class ObjectId<VariantContainerId<CIList...>,CM> final
109 {
112 public:
113
114 using CI = VariantContainerId<CIList...>;
116
117 // Whatever you do: Do not remove this function. Yes, it will always
118 // throw. It is meant to throw in this template specialization, and
119 // only do something useful in the xAOD mode specialization. If you
120 // remove it you break the columnar mode.
121 ObjectId (xAODObject& /*val_object*/)
122 {
123 throw std::logic_error ("can't call xAOD function in columnar mode");
124 }
125
126 ObjectId (const ObjectId<VariantContainerId<CIList...>,CM>& that) noexcept = default;
127
128 template<ContainerIdConcept CI2>
129 requires (CI2::regularObjectId && CI::template isValidContainer<CI2>())
130 ObjectId (const ObjectId<CI2,CM>& that) noexcept
131 : m_data (that.getData()), m_variantIndex (CI::template getVariantIndex<CI2>()), m_objectIndex (that.getIndex())
132 {}
133
134 ObjectId& operator = (const ObjectId<VariantContainerId<CIList...>,CM>& that) noexcept = default;
135 // Whatever you do: Do not remove this function. Yes, it will always
136 // throw. It is meant to throw in this template specialization, and
137 // only do something useful in the xAOD mode specialization. If you
138 // remove it you break the columnar mode.
139 [[nodiscard]] xAODObject& getXAODObject () const {
140 throw std::logic_error ("can't call xAOD function in columnar mode");}
141
142 template<ContainerIdConcept CI2>
143 requires (CI::template isValidContainer<CI2>())
144 [[nodiscard]] OptObjectId<CI2,CM> tryGetVariant () const
145 {
146 if (m_variantIndex == CI::template getVariantIndex<CI2>())
148 else
149 return OptObjectId<CI2,CM> ();
150 }
151
152 template<typename Acc,typename... Args>
153 requires std::invocable<Acc,ObjectId<VariantContainerId<CIList...>,CM>,Args...>
154 [[nodiscard]] decltype(auto) operator() (Acc& acc, Args&&... args) const {
155 return acc (*this, std::forward<Args> (args)...);}
156
157
158
161 public:
162
163 explicit ObjectId (void **val_data, std::size_t val_variantIndex, std::size_t val_objectIndex) noexcept
164 : m_data (val_data), m_variantIndex (val_variantIndex), m_objectIndex (val_objectIndex)
165 {}
166
167 [[nodiscard]] std::size_t getVariantIndex () const noexcept {
168 return m_variantIndex;}
169
170 [[nodiscard]] std::size_t getObjectIndex () const noexcept {
171 return m_objectIndex;}
172
173 [[nodiscard]] void **getData () const noexcept {
174 return m_data;}
175
176
177
180 private:
181
182 void **m_data = nullptr;
183 std::size_t m_variantIndex = 0u;
184 std::size_t m_objectIndex = 0u;
185 };
186
187 template<ContainerIdConcept... CIList, ColumnarArrayMode CM>
188 std::ostream& operator<< (std::ostream& str, const ObjectId<VariantContainerId<CIList...>,CM>& obj)
189 {
190 using CI = VariantContainerId<CIList...>;
191 return str << CI::idNameArray.at(obj.getVariantIndex()) << "/" << obj.getObjectIndex();
192 }
193
194 template<ContainerIdConcept... CIList, ColumnarArrayMode CM>
196 {
197 return lhs.getVariantIndex() == rhs.getVariantIndex() && lhs.getObjectIndex() == rhs.getObjectIndex();
198 }
199
200 template<ContainerIdConcept... CIList, ColumnarArrayMode CM>
202 {
203 return lhs.getVariantIndex() != rhs.getVariantIndex() || lhs.getObjectIndex() != rhs.getObjectIndex();
204 }
205}
206
207#endif
#define ATLAS_THREAD_SAFE
ObjectId(const ObjectId< VariantContainerId< CIList... >, CM > &that) noexcept=default
ObjectId(void **val_data, std::size_t val_variantIndex, std::size_t val_objectIndex) noexcept
ObjectId(const ObjectId< VariantContainerId< CIList... >, ColumnarModeXAOD > &that) noexcept=default
a class representing a single object (electron, muons, etc.)
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
std::ostream & operator<<(std::ostream &str, const ObjectId< CI, ColumnarModeXAOD > &obj)
Definition ObjectId.h:76
a "variant" ContainerId
Definition VariantDef.h:98
typename CIBase::xAODObjectIdType xAODObjectIdType
Definition VariantDef.h:114
std::map< std::string, HypoJetVector >::const_iterator CI