ATLAS Offline Software
Loading...
Searching...
No Matches
ColumnarToolArray.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 <AsgMessaging/StatusCode.h>
9#include <ColumnarCore/ContainerId.h>
10#include <ColumnarCore/ObjectRange.h>
11#include <ColumnarInterfaces/ColumnInfo.h>
12#include <ColumnarInterfaces/IColumnarTool.h>
13#include <memory>
14
15namespace columnar
16{
17 struct ColumnAccessorDataArray;
18 struct ColumnarToolDataArray;
19
20 /// @brief a common base class for all columnar tools using an array mode
21 ///
22 /// Essentially the idea is that there are multiple columnar modes
23 /// that have the same basic structure of having an underlying array
24 /// with one entry per column, pointing to the column data. So this
25 /// class contains all the common functionality for such modes, and
26 /// the actual `ColumnarTool` specializations inherit from this class
27 /// and then do the mode-specific wrapping (to avoid mixing modes
28 /// within a tool).
29
30 class ColumnarToolArray : public IColumnarTool
31 {
32 /// Common Public Members
33 /// =====================
34 public:
35
36 /// @brief whether this tool can only be called for a single event
37 static constexpr bool singleEvent = false;
38
39
40 /// @brief standard (virtual) destructor
41 virtual ~ColumnarToolArray ();
42
43
44 /// @brief initialize the columns/column handles
45 ///
46 /// This should be called at the end of initialize after all data handles
47 /// have been declared.
48 StatusCode initializeColumns ();
49
50
51
52 /// Inherited Members from IColumnarTool
53 /// ====================================
54 public:
55
56 std::vector<ColumnInfo> getColumnInfo () const final;
57 void renameColumn (const std::string& from, const std::string& to) final;
58 void setColumnIndex (const std::string& name, std::size_t index) final;
59
60
61
62 /// Internal/Detail Members
63 /// =======================
64 ///
65 /// These are technically public members, but are not intended for
66 /// the user to call, and are only public because they need to be
67 /// for other parts of the prototype to call.
68 public:
69
70 void setContainerUserName (std::string_view ciName, const std::string& name);
71 void addColumn (const std::string& name, ColumnAccessorDataArray *accessorData, ColumnInfo&& info);
72
73
74 /// Protected Members
75 /// =================
76 protected:
77
78 friend struct ColumnarToolDataArray;
79
80
81 // most of our data is stored in a pimpl structure
82 std::shared_ptr<ColumnarToolDataArray> m_data;
83
84 // we may have to access the event offset column, so hard-coding
85 // that here
86 unsigned m_eventsIndex = 0u;
87 std::unique_ptr<ColumnAccessorDataArray> m_eventsData;
88
89
90 /// standard constructors
91 ColumnarToolArray (ColumnarToolArray* val_parent);
92 ColumnarToolArray (const ColumnarToolArray&) = delete;
93 ColumnarToolArray& operator = (const ColumnarToolArray&) = delete;
94
95 /// @brief add the given sub-tool
96 void addSubtool (ColumnarToolArray& subtool);
97 };
98
99
100
101 template<ColumnarArrayMode CM>
102 class ColumnarTool<CM> : public ColumnarToolArray
103 {
104 /// Common Public Members
105 /// =====================
106 public:
107
108 ColumnarTool () : ColumnarToolArray (nullptr) {};
109 explicit ColumnarTool (ColumnarTool<CM>* val_parent) : ColumnarToolArray (val_parent) {};
110
111
112 /// @brief add the given sub-tool
113 void addSubtool (ColumnarTool<CM>& subtool) {
114 ColumnarToolArray::addSubtool (subtool); }
115
116
117 /// @brief call the tool for the given event range
118 virtual void callEvents (ObjectRange<ContainerId::eventContext,CM> /*events*/) const {
119 throw std::runtime_error ("tool didn't implement callEvents");}
120
121
122
123 /// Inherited Members from IColumnarTool
124 /// ====================================
125 public:
126
127 void callVoid (void **data) const final {
128 auto eventsOffset = static_cast<const ColumnarOffsetType*> (data[m_eventsIndex]);
129 callEvents (ObjectRange<ContainerId::eventContext,CM> (data, eventsOffset[0], eventsOffset[1])); }
130 };
131}