Loading [MathJax]/jax/output/SVG/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ColumnAccessorXAOD.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /// @author Nils Krumnack
6 
7 
8 namespace columnar
9 {
10  // the xAOD specialization for native types
11  template<ContainerId CI,typename CT,ColumnAccessMode CAM>
12  requires (ColumnTypeTraits<CT,ColumnarModeXAOD>::isNativeType)
13  class AccessorTemplate<CI,CT,CAM,ColumnarModeXAOD> final
14  {
15  /// Common Public Members
16  /// =====================
17  public:
18 
19  static_assert (ContainerIdTraits<CI>::isDefined, "ContainerId not defined, include the appropriate header");
20  static_assert (!std::is_const_v<CT>, "CT must not be const");
21 
22  using CM = ColumnarModeXAOD;
23  using ColumnType = typename ColumnAccessModeTraits<CAM>::template ColumnType<typename ColumnTypeTraits<CT,ColumnarModeXAOD>::ColumnType>;
24  using AccessorType = typename ColumnAccessModeTraits<CAM>::template XAODAccessor<typename ColumnTypeTraits<CT,ColumnarModeXAOD>::ColumnType>;
25 
26  AccessorTemplate () = default;
27 
28  AccessorTemplate (ColumnarTool<CM>& columnBase,
29  const std::string& name, ColumnInfo&& info = {})
30  : m_accessor(name)
31  {
32  ColumnTypeTraits<CT,ColumnarModeXAOD>::updateColumnInfo (columnBase, info);
33  if (!info.replacesColumn.empty())
34  m_accessor = info.replacesColumn;
35  }
36 
37  AccessorTemplate (AccessorTemplate&& that)
38  {
39  m_accessor = that.m_accessor;
40  that.m_accessor = std::string("UNDEFINED_ACCESSOR_") + typeid (typename ColumnTypeTraits<CT,CM>::ColumnType).name();
41  }
42 
43  AccessorTemplate& operator = (AccessorTemplate&& that)
44  {
45  if (this != &that)
46  {
47  m_accessor = that.m_accessor;
48  that.m_accessor = std::string("UNDEFINED_ACCESSOR_") + typeid (typename ColumnTypeTraits<CT,CM>::ColumnType).name();
49  }
50  return *this;
51  }
52 
53  AccessorTemplate (const AccessorTemplate&) = delete;
54  AccessorTemplate& operator = (const AccessorTemplate&) = delete;
55 
56  [[nodiscard]] ColumnType& operator () (ObjectId<CI,CM> id) const noexcept
57  {
58  return m_accessor(id.getXAODObject());
59  }
60 
61  [[nodiscard]] std::span<ColumnType> operator () (ObjectRange<CI,CM> range) const noexcept
62  {
63  if (range.getXAODObject().empty())
64  return std::span<ColumnType> ();
65  return std::span<ColumnType> (&m_accessor (*range.getXAODObject()[0]), range.getXAODObject().size());
66  }
67 
68  [[nodiscard]] bool isAvailable (ObjectId<CI,CM> id) const noexcept
69  {
70  return m_accessor.isAvailable (id.getXAODObject());
71  }
72 
73  [[nodiscard]] std::optional<ColumnType> getOptional (ObjectId<CI,CM> id) const
74  {
75  if (m_accessor.isAvailable (id.getXAODObject()))
76  return m_accessor (id.getXAODObject());
77  else
78  return std::nullopt;
79  }
80 
81  /// Private Members
82  /// ===============
83  private:
84 
85  AccessorType m_accessor {std::string("UNDEFINED_ACCESSOR_") + typeid (typename ColumnTypeTraits<CT,CM>::ColumnType).name()};
86  };
87 }