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> class ObjectId<VariantContainerId<CIList...>,ColumnarModeArray> final
108 {
111 public:
112
113 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
127
128 template<ContainerIdConcept CI2>
129 requires (CI2::regularObjectId && CI::template isValidContainer<CI2>())
131 : m_data (that.getData()), m_variantIndex (CI::template getVariantIndex<CI2>()), m_objectIndex (that.getIndex())
132 {}
133
134 ObjectId& operator = (const ObjectId<VariantContainerId<CIList...>,ColumnarModeArray>& that) noexcept = default;
135
136 // Whatever you do: Do not remove this function. Yes, it will always
137 // throw. It is meant to throw in this template specialization, and
138 // only do something useful in the xAOD mode specialization. If you
139 // remove it you break the columnar mode.
140 [[nodiscard]] xAODObject& getXAODObject () const {
141 throw std::logic_error ("can't call xAOD function in columnar mode");}
142
143 template<ContainerIdConcept CI2>
144 requires (CI::template isValidContainer<CI2>())
145 [[nodiscard]] OptObjectId<CI2,CM> tryGetVariant () const
146 {
147 if (m_variantIndex == CI::template getVariantIndex<CI2>())
149 else
150 return OptObjectId<CI2,CM> ();
151 }
152
153 template<typename Acc,typename... Args>
154 requires std::invocable<Acc,ObjectId<VariantContainerId<CIList...>,ColumnarModeArray>,Args...>
155 [[nodiscard]] decltype(auto) operator() (Acc& acc, Args&&... args) const {
156 return acc (*this, std::forward<Args> (args)...);}
157
158
159
162 public:
163
164 explicit ObjectId (void **val_data, std::size_t val_variantIndex, std::size_t val_objectIndex) noexcept
165 : m_data (val_data), m_variantIndex (val_variantIndex), m_objectIndex (val_objectIndex)
166 {}
167
168 [[nodiscard]] std::size_t getVariantIndex () const noexcept {
169 return m_variantIndex;}
170
171 [[nodiscard]] std::size_t getObjectIndex () const noexcept {
172 return m_objectIndex;}
173
174 [[nodiscard]] void **getData () const noexcept {
175 return m_data;}
176
177
178
181 private:
182
183 void **m_data = nullptr;
184 std::size_t m_variantIndex = 0u;
185 std::size_t m_objectIndex = 0u;
186 };
187
188 template<ContainerIdConcept... CIList>
190 {
191 using CI = VariantContainerId<CIList...>;
192 return str << CI::idNameArray.at(obj.getVariantIndex()) << "/" << obj.getObjectIndex();
193 }
194
195 template<ContainerIdConcept... CIList>
197 {
198 return lhs.getVariantIndex() == rhs.getVariantIndex() && lhs.getObjectIndex() == rhs.getObjectIndex();
199 }
200
201 template<ContainerIdConcept... CIList>
203 {
204 return lhs.getVariantIndex() != rhs.getVariantIndex() || lhs.getObjectIndex() != rhs.getObjectIndex();
205 }
206}
207
208#endif
#define ATLAS_THREAD_SAFE
ObjectId(void **val_data, std::size_t val_variantIndex, std::size_t val_objectIndex) noexcept
ObjectId(const ObjectId< VariantContainerId< CIList... >, ColumnarModeArray > &that) noexcept=default
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