ATLAS Offline Software
Loading...
Searching...
No Matches
ObjectId.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_OBJECT_ID_H
9#define COLUMNAR_CORE_OBJECT_ID_H
10
13#include <iostream>
14#include <stdexcept>
15
16namespace columnar
17{
19 template<ContainerIdConcept CI, typename CM> class ObjectId;
20
21
22
23
24
25 template<ContainerIdConcept CI> class ObjectId<CI,ColumnarModeXAOD> final
26 {
29 public:
30
31 using xAODObject = typename CI::xAODObjectIdType;
32
33 ObjectId (xAODObject& val_object) noexcept
34 : m_object (&val_object)
35 {}
36
37 ObjectId (const ObjectId<CI,ColumnarModeXAOD>& that) noexcept = default;
38
39 template<ContainerIdConcept CI2> requires (CI2::isMutable && std::is_same_v<typename CI2::constId,CI>)
41 : m_object (&that.getXAODObjectNoexcept())
42 {}
43
44 ObjectId& operator = (const ObjectId<CI,ColumnarModeXAOD>& that) noexcept = default;
45
46 [[nodiscard]] xAODObject& getXAODObject () const noexcept {
47 // This object should ever be held within the context of a
48 // single thread (and generally on the stack), so the associated
49 // check is meaningless.
51 return *result;}
52
53 // a version of `getXAODObject` that only exists when it is `noexcept`
54 [[nodiscard]] xAODObject& getXAODObjectNoexcept () const noexcept {
55 // This object should ever be held within the context of a
56 // single thread (and generally on the stack), so the associated
57 // check is meaningless.
59 return *result;}
60
61 template<typename Acc,typename... Args>
62 requires std::invocable<Acc,ObjectId<CI,ColumnarModeXAOD>,Args...>
63 [[nodiscard]] decltype(auto) operator() (Acc& acc, Args&&... args) const {
64 return acc (*this, std::forward<Args> (args)...);}
65
66
67
70 private:
71
72 xAODObject *m_object = nullptr;
73 };
74
75 template<ContainerIdConcept CI>
76 std::ostream& operator<< (std::ostream& str, const ObjectId<CI,ColumnarModeXAOD>& obj)
77 {
78 return str << &obj.getXAODObjectNoexcept() << "/" << obj.getXAODObjectNoexcept().index();
79 }
80
81 template<ContainerIdConcept CI>
83 {
84 return &lhs.getXAODObjectNoexcept() == &rhs.getXAODObjectNoexcept();
85 }
86
87 template<ContainerIdConcept CI>
89 {
90 return &lhs.getXAODObjectNoexcept() != &rhs.getXAODObjectNoexcept();
91 }
92
93
94
95
96 template<ContainerIdConcept CI> class ObjectId<CI,ColumnarModeArray> final
97 {
100 public:
101
103 using xAODObject = typename CI::xAODObjectIdType;
104
105 // Whatever you do: Do not remove this function. Yes, it will always
106 // throw. It is meant to throw in this template specialization, and
107 // only do something useful in the xAOD mode specialization. If you
108 // remove it you break the columnar mode.
109 ObjectId (xAODObject& /*val_object*/)
110 {
111 throw std::logic_error ("can't call xAOD function in columnar mode");
112 }
113
114 ObjectId (const ObjectId<CI,ColumnarModeArray>& that) noexcept = default;
115
116 template<ContainerIdConcept CI2> requires (CI2::isMutable && std::is_same_v<typename CI2::constId,CI>)
118 : m_data (that.getData()), m_index (that.getIndex())
119 {}
120
121 ObjectId& operator = (const ObjectId<CI,ColumnarModeArray>& that) noexcept = default;
122
123 // Whatever you do: Do not remove this function. Yes, it will always
124 // throw. It is meant to throw in this template specialization, and
125 // only do something useful in the xAOD mode specialization. If you
126 // remove it you break the columnar mode.
127 [[nodiscard]] xAODObject& getXAODObject () const {
128 throw std::logic_error ("can't call xAOD function in columnar mode");}
129
130 template<typename Acc,typename... Args>
131 requires std::invocable<Acc,ObjectId<CI,ColumnarModeArray>,Args...>
132 [[nodiscard]] decltype(auto) operator() (Acc& acc, Args&&... args) const {
133 return acc (*this, std::forward<Args> (args)...);}
134
135
136
139 public:
140
141 explicit ObjectId (void **val_data, std::size_t val_index) noexcept
142 : m_data (val_data), m_index (val_index)
143 {}
144
145 [[nodiscard]] std::size_t getIndex () const noexcept {
146 return m_index;}
147
148 [[nodiscard]] void **getData () const noexcept {
149 return m_data;}
150
151
152
155 private:
156
157 void **m_data = nullptr;
158 std::size_t m_index = 0u;
159 };
160
161 template<ContainerIdConcept CI>
162 std::ostream& operator<< (std::ostream& str, const ObjectId<CI,ColumnarModeArray>& obj)
163 {
164 return str << CI::idName << "/" << obj.getIndex();
165 }
166
167 template<ContainerIdConcept CI>
169 {
170 return lhs.getIndex() == rhs.getIndex();
171 }
172
173 template<ContainerIdConcept CI>
175 {
176 return lhs.getIndex() != rhs.getIndex();
177 }
178}
179
180#endif
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
std::size_t getIndex() const noexcept
Definition ObjectId.h:145
ObjectId(const ObjectId< CI, ColumnarModeArray > &that) noexcept=default
ObjectId(void **val_data, std::size_t val_index) noexcept
Definition ObjectId.h:141
typename CI::xAODObjectIdType xAODObject
Definition ObjectId.h:103
ObjectId(xAODObject &val_object) noexcept
Definition ObjectId.h:33
ObjectId(const ObjectId< CI, ColumnarModeXAOD > &that) noexcept=default
typename CI::xAODObjectIdType xAODObject
Definition ObjectId.h:31
xAODObject & getXAODObjectNoexcept() const noexcept
Definition ObjectId.h:54
xAODObject & getXAODObject() const noexcept
Definition ObjectId.h:46
a class representing a single 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
std::ostream & operator<<(std::ostream &str, const ObjectId< CI, ColumnarModeXAOD > &obj)
Definition ObjectId.h:76
std::map< std::string, HypoJetVector >::const_iterator CI