ATLAS Offline Software
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 
16 namespace 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>)
40  ObjectId (const ObjectId<CI2,ColumnarModeXAOD>& that) noexcept
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.
50  auto *result ATLAS_THREAD_SAFE = m_object;
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.
58  auto *result ATLAS_THREAD_SAFE = m_object;
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>)
117  ObjectId (const ObjectId<CI2,ColumnarModeArray>& that) noexcept
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
columnar::ObjectId< CI, ColumnarModeArray >::ObjectId
ObjectId(void **val_data, std::size_t val_index) noexcept
Definition: ObjectId.h:141
columnar::ObjectId< CI, ColumnarModeXAOD >::requires
requires(CI2::isMutable &&std::is_same_v< typename CI2::constId, CI >) ObjectId(const ObjectId< CI2
InDetSimDataHelpers::getData
const InDetSimData * getData(const InDetSimDataCollection &coll, const Identifier &id)
Definition: InDetSimDataDict.h:24
get_generator_info.result
result
Definition: get_generator_info.py:21
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:47
columnar::ObjectId< CI, ColumnarModeArray >::xAODObject
typename CI::xAODObjectIdType xAODObject
Definition: ObjectId.h:103
columnar::ObjectId< CI, ColumnarModeArray >::getXAODObject
xAODObject & getXAODObject() const
Definition: ObjectId.h:127
columnar::ObjectId< CI, ColumnarModeXAOD >::getXAODObjectNoexcept
xAODObject & getXAODObjectNoexcept() const noexcept
Definition: ObjectId.h:54
m_data
std::vector< T > m_data
Definition: TrackTruthMatchingBaseAlg.cxx:660
columnar::ObjectId< CI, ColumnarModeXAOD >::ObjectId
ObjectId(const ObjectId< CI, ColumnarModeXAOD > &that) noexcept=default
columnar::ObjectId< CI, ColumnarModeArray >::ObjectId
ObjectId(xAODObject &)
Definition: ObjectId.h:109
columnar::getXAODObjectNoexcept
xAODContainer & getXAODObjectNoexcept() const noexcept
Definition: ObjectRange.h:155
columnar::ObjectId< CI, ColumnarModeArray >::getIndex
std::size_t getIndex() const noexcept
Definition: ObjectId.h:145
columnar::operator=
AccessorTemplate & operator=(AccessorTemplate &&that)
Definition: VectorColumn.h:88
columnar::ObjectId< CI, ColumnarModeXAOD >::xAODObject
typename CI::xAODObjectIdType xAODObject
Definition: ObjectId.h:31
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
Args
Definition: test_lwtnn_fastgraph.cxx:12
CI
std::map< std::string, HypoJetVector >::const_iterator CI
Definition: xAODJetCollector.h:18
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
columnar::operator==
bool operator==(const ObjectId< CI, ColumnarModeXAOD > &lhs, const ObjectId< CI, ColumnarModeXAOD > &rhs)
Definition: ObjectId.h:82
columnar::ObjectId< CI, ColumnarModeArray >::getData
void ** getData() const noexcept
Definition: ObjectId.h:148
columnar::operator!=
bool operator!=(const ObjectId< CI, ColumnarModeXAOD > &lhs, const ObjectId< CI, ColumnarModeXAOD > &rhs)
Definition: ObjectId.h:88
columnar::ObjectId< CI, ColumnarModeArray >::requires
requires(CI2::isMutable &&std::is_same_v< typename CI2::constId, CI >) ObjectId(const ObjectId< CI2
columnar::ObjectId< CI, ColumnarModeXAOD >
Definition: ObjectId.h:26
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
columnar::final
CM final
Definition: ColumnAccessor.h:106
columnar::ObjectId< CI, ColumnarModeArray >::ObjectId
ObjectId(const ObjectId< CI, ColumnarModeArray > &that) noexcept=default
columnar::ObjectId
a class representing a single object (electron, muons, etc.)
Definition: ContainerId.h:178
columnar::ColumnarModeArray
Definition: ColumnarDef.h:33
columnar
Definition: ClusterDef.h:16
ContainerId.h
columnar::ColumnarModeXAOD
Definition: ColumnarDef.h:18
columnar::requires
requires requires
Definition: VariantAccessor.h:22
columnar::ObjectId< CI, ColumnarModeXAOD >::getXAODObject
xAODObject & getXAODObject() const noexcept
Definition: ObjectId.h:46
str
Definition: BTagTrackIpAccessor.cxx:11
columnar::ObjectId< CI, ColumnarModeXAOD >::ObjectId
ObjectId(xAODObject &val_object) noexcept
Definition: ObjectId.h:33
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
columnar::ObjectId< CI, ColumnarModeArray >
Definition: ObjectId.h:97
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
columnar::operator<<
std::ostream & operator<<(std::ostream &str, const ObjectId< CI, ColumnarModeXAOD > &obj)
Definition: ObjectId.h:76