2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5/// @author Nils Krumnack
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>
17 struct ColumnAccessorDataArray;
18 struct ColumnarToolDataArray;
20 /// @brief a common base class for all columnar tools using an array mode
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
30 class ColumnarToolArray : public IColumnarTool
32 /// Common Public Members
33 /// =====================
36 /// @brief whether this tool can only be called for a single event
37 static constexpr bool singleEvent = false;
40 /// @brief standard (virtual) destructor
41 virtual ~ColumnarToolArray ();
44 /// @brief initialize the columns/column handles
46 /// This should be called at the end of initialize after all data handles
47 /// have been declared.
48 StatusCode initializeColumns ();
52 /// Inherited Members from IColumnarTool
53 /// ====================================
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;
62 /// Internal/Detail Members
63 /// =======================
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.
70 void setContainerUserName (std::string_view ciName, const std::string& name);
71 void addColumn (const std::string& name, ColumnAccessorDataArray *accessorData, ColumnInfo&& info);
78 friend struct ColumnarToolDataArray;
81 // most of our data is stored in a pimpl structure
82 std::shared_ptr<ColumnarToolDataArray> m_data;
84 // we may have to access the event offset column, so hard-coding
86 unsigned m_eventsIndex = 0u;
87 std::unique_ptr<ColumnAccessorDataArray> m_eventsData;
90 /// standard constructors
91 ColumnarToolArray (ColumnarToolArray* val_parent);
92 ColumnarToolArray (const ColumnarToolArray&) = delete;
93 ColumnarToolArray& operator = (const ColumnarToolArray&) = delete;
95 /// @brief add the given sub-tool
96 void addSubtool (ColumnarToolArray& subtool);
101 template<ColumnarArrayMode CM>
102 class ColumnarTool<CM> : public ColumnarToolArray
104 /// Common Public Members
105 /// =====================
108 ColumnarTool () : ColumnarToolArray (nullptr) {};
109 explicit ColumnarTool (ColumnarTool<CM>* val_parent) : ColumnarToolArray (val_parent) {};
112 /// @brief add the given sub-tool
113 void addSubtool (ColumnarTool<CM>& subtool) {
114 ColumnarToolArray::addSubtool (subtool); }
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");}
123 /// Inherited Members from IColumnarTool
124 /// ====================================
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])); }