ATLAS Offline Software
Loading...
Searching...
No Matches
ObjectColumnArray.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#include <ColumnarCore/ColumnarTool.h>
9#include <ColumnarCore/ColumnAccessorDataArray.h>
10#include <ColumnarCore/ObjectId.h>
11#include <ColumnarCore/ObjectRange.h>
12#include <ColumnarCore/ContainerId.h>
13#include <cassert>
14
15namespace columnar
16{
17 template<ContainerIdConcept CI,ColumnarArrayMode CM>
18 class AccessorTemplate<CI,ObjectColumn,ColumnAccessMode::input,CM> final
19 {
20 /// Common Public Members
21 /// =====================
22 public:
23
24 static_assert (CI::perEventRange || CI::perEventId, "ObjectColumn can only be used with per-event ranges or IDs");
25
26 AccessorTemplate () = default;
27
28 AccessorTemplate (ColumnarTool<CM>& columnBase,
29 const std::string& name,
30 ColumnInfo&& info = {})
31 : m_columnBase (&columnBase),
32 m_name (name)
33 {
34 if (!name.empty())
35 columnBase.setContainerUserName (CI::idName, name);
36 m_offsetsData = std::make_unique<ColumnAccessorDataArray> (&m_offsetsIndex, &m_offsetsData, &typeid (ColumnarOffsetType), ColumnAccessMode::input);
37 info.offsetName = (CI::perEventRange ? numberOfEventsName : "");
38 info.isOffset = true;
39 columnBase.addColumn (std::string (CI::idName), m_offsetsData.get(), std::move(info));
40 }
41
42 AccessorTemplate (AccessorTemplate&& that)
43 {
44 moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
45 }
46
47 // cppcheck-suppress operatorEqVarError; m_columnBase not copied
48 AccessorTemplate& operator = (AccessorTemplate&& that)
49 {
50 if (this != &that)
51 moveAccessor (m_offsetsIndex, m_offsetsData, that.m_offsetsIndex, that.m_offsetsData);
52 return *this;
53 }
54
55 AccessorTemplate (const AccessorTemplate&) = delete;
56 AccessorTemplate& operator = (const AccessorTemplate&) = delete;
57
58 ObjectRange<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
59 requires (CI::perEventRange)
60 {
61 auto *offsets = static_cast<const ColumnarOffsetType*>(eventId.getData()[m_offsetsIndex]);
62 return ObjectRange<CI,CM> (eventId.getData(), offsets[eventId.getIndex()], offsets[eventId.getIndex() + 1]);
63 }
64
65 ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
66 requires (CI::perEventRange)
67 {
68 auto *offsets = static_cast<const ColumnarOffsetType*>(eventRange.getData()[m_offsetsIndex]);
69 return ObjectRange<CI,CM> (eventRange.getData(), offsets[eventRange.beginIndex()], offsets[eventRange.endIndex()]);
70 }
71
72 ObjectId<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> eventId) const
73 requires (CI::perEventId)
74 {
75 return ObjectId<CI,CM> (eventId.getData(), eventId.getIndex());
76 }
77
78 ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> eventRange) const
79 requires (CI::perEventId)
80 {
81 return ObjectRange<CI,CM> (eventRange.getData(), eventRange.beginIndex(), eventRange.endIndex());
82 }
83
84 [[nodiscard]] bool isAvailable (ObjectId<ContainerId::eventContext,CM> eventId) const noexcept
85 {
86 auto *offsets = static_cast<const ColumnarOffsetType*>(eventId.getData()[m_offsetsIndex]);
87 return offsets != nullptr;
88 }
89
90
91
92 /// Private Members
93 /// ===============
94 private:
95
96 ColumnarTool<CM> *m_columnBase = nullptr;
97
98 std::string m_name;
99 unsigned m_offsetsIndex = 0;
100 std::unique_ptr<ColumnAccessorDataArray> m_offsetsData;
101 };
102}