ATLAS Offline Software
Loading...
Searching...
No Matches
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
8namespace columnar
9{
10 // the xAOD specialization for native types
11 template<ContainerIdConcept 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 (!std::is_const_v<CT>, "CT must not be const");
20
21 using CM = ColumnarModeXAOD;
22 using ColumnType = typename ColumnAccessModeTraits<CAM>::template ColumnType<typename ColumnTypeTraits<CT,ColumnarModeXAOD>::ColumnType>;
23 using AccessorType = typename ColumnAccessModeTraits<CAM>::template XAODAccessor<typename ColumnTypeTraits<CT,ColumnarModeXAOD>::ColumnType>;
24
25 AccessorTemplate () = default;
26
27 AccessorTemplate (ColumnarTool<CM>& columnBase,
28 const std::string& name, ColumnInfo&& info = {})
29 : m_accessor(name)
30 {
31 if (info.addMTDependency)
32 throw std::runtime_error ("adding MT dependencies not yet supported for individual decorations");
33 ColumnTypeTraits<CT,ColumnarModeXAOD>::updateColumnInfo (columnBase, info);
34 if (!info.replacesColumn.empty())
35 m_accessor = info.replacesColumn;
36 }
37
38 AccessorTemplate (AccessorTemplate&& that)
39 : m_accessor (that.m_accessor)
40 {
41 that.m_accessor = std::string("UNDEFINED_ACCESSOR_") + typeid (typename ColumnTypeTraits<CT,CM>::ColumnType).name();
42 }
43
44 AccessorTemplate& operator = (AccessorTemplate&& that)
45 {
46 if (this != &that)
47 {
48 m_accessor = that.m_accessor;
49 that.m_accessor = std::string("UNDEFINED_ACCESSOR_") + typeid (typename ColumnTypeTraits<CT,CM>::ColumnType).name();
50 }
51 return *this;
52 }
53
54 AccessorTemplate (const AccessorTemplate&) = delete;
55 AccessorTemplate& operator = (const AccessorTemplate&) = delete;
56
57 [[nodiscard]] ColumnType& operator () (ObjectId<CI,CM> id) const
58 {
59 return m_accessor(id.getXAODObjectNoexcept());
60 }
61
62 [[nodiscard]] std::span<ColumnType> operator () (ObjectRange<CI,CM> range) const
63 {
64 if (range.getXAODObjectNoexcept().empty())
65 return std::span<ColumnType> ();
66 return std::span<ColumnType> (&m_accessor (*range.getXAODObjectNoexcept()[0]), range.getXAODObjectNoexcept().size());
67 }
68
69 [[nodiscard]] bool isAvailable (ObjectId<CI,CM> id) const noexcept
70 {
71 return m_accessor.isAvailable (id.getXAODObjectNoexcept());
72 }
73
74 [[nodiscard]] std::optional<ColumnType> getOptional (ObjectId<CI,CM> id) const
75 {
76 if (m_accessor.isAvailable (id.getXAODObjectNoexcept()))
77 return m_accessor (id.getXAODObjectNoexcept());
78 else
79 return std::nullopt;
80 }
81
82 /// Private Members
83 /// ===============
84 private:
85
86 AccessorType m_accessor {std::string("UNDEFINED_ACCESSOR_") + typeid (typename ColumnTypeTraits<CT,CM>::ColumnType).name()};
87 };
88}