Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ColumnarToolWrapper.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 #ifndef COLUMNAR_PYTHON_WRAPPER_PYTHON_TOOL_WRAPPER_H
9 #define COLUMNAR_PYTHON_WRAPPER_PYTHON_TOOL_WRAPPER_H
10 
11 #include <memory>
12 #include <string>
13 #include <typeinfo>
14 #include <unordered_map>
15 #include <vector>
16 
17 namespace columnar
18 {
19  struct ColumnInfo;
20  class IColumnarTool;
21 
22 
34 
36  {
39 
40  public:
41 
43  explicit ColumnarToolWrapper (IColumnarTool *val_tool);
44 
46  explicit ColumnarToolWrapper (std::shared_ptr<IColumnarTool> val_tool);
47 
48 
49  // copying would need special handling, so disabling it until needed
52 
53 
61  [[nodiscard]] std::vector<std::string> getColumnNames () const;
62  [[nodiscard]] std::vector<ColumnInfo> getColumnInfo () const;
64 
65 
66 
69 
70  private:
71 
72  // These two classes work closely together, but for new users it
73  // seemed clearer to make it a friend instead of a nested class.
75 
76 
78  const IColumnarTool *m_tool = nullptr;
79 
81  std::shared_ptr<const IColumnarTool> m_toolOwn;
82 
83 
85  struct MyColumnInfo
86  {
87  const std::type_info *type = nullptr;
88 
89  bool isConst = false;
90 
91  unsigned index = 0u;
92 
93  unsigned fixedDimensions = 1u;
94 
95  bool isOffset = false;
96 
97  bool isOptional = false;
98 
99  int numpyType = -1;
100 
101  unsigned numpyBits = 0u;
102 
103  const std::pair<const std::string,MyColumnInfo> *offsets = nullptr;
104  };
105  std::unordered_map<std::string,MyColumnInfo> m_columns;
106 
107 
110  unsigned m_numColumns = 0u;
111  };
112 
113 
114 
134 
136  {
139 
140  public:
141 
143  explicit ColumnarToolWrapperData (const ColumnarToolWrapper *val_wrapper) noexcept;
144 
145 
148  template<typename CT>
149  void setColumn (const std::string& name, std::size_t size, CT* dataPtr) {
150  auto voidPtr = reinterpret_cast<const void*>(const_cast<const CT*>(dataPtr));
151  setColumnVoid (name, size, voidPtr, typeid (std::decay_t<CT>), std::is_const_v<CT>);
152  }
153 
154 
157  void setColumnVoid (const std::string& name, std::size_t size, const void *dataPtr, const std::type_info& type, bool isConst);
158 
159 
162  void setColumnNumpy (const std::string& name, std::size_t size, const void *dataPtr, int type, unsigned bits, bool isConst);
163 
164 
166  void call ();
167 
168 
169 
175 
176  public:
177 
178 
180  void checkColumnsValid ();
181 
182 
185  template<typename CT>
186  [[nodiscard]] std::pair<std::size_t,CT*>
187  getColumn (const std::string& name)
188  {
189  auto [size, ptr] = getColumnVoid (name, &typeid (std::decay_t<CT>), std::is_const_v<CT>);
190  if constexpr (std::is_const_v<CT>)
191  return std::make_pair (size, static_cast<CT*>(ptr));
192  else
193  return std::make_pair (size, static_cast<CT*>(const_cast<void*>(ptr)));
194  }
195 
197  [[nodiscard]] std::pair<std::size_t,const void*>
198  getColumnVoid (const std::string& name, const std::type_info *type, bool isConst);
199 
201  [[nodiscard]] void** data () noexcept {
202  return m_data.data();}
203 
204 
205 
208 
209  private:
210 
211  const ColumnarToolWrapper *m_wrapper = nullptr;
212 
213  std::vector<void*> m_data;
214  std::vector<std::size_t> m_dataSize;
215  std::vector<bool> m_columnIsChecked;
216  std::vector<bool> m_columnIsFilled;
217 
218  void checkColumn (const std::pair<const std::string,ColumnarToolWrapper::MyColumnInfo>& column);
219  };
220 }
221 
222 #endif
columnar::ColumnarToolWrapperData::m_wrapper
const ColumnarToolWrapper * m_wrapper
Definition: ColumnarToolWrapper.h:211
columnar::IColumnarTool
an interface for tools that operate on columnar data
Definition: IColumnarTool.h:214
columnar::ColumnarToolWrapperData::getColumnVoid
std::pair< std::size_t, const void * > getColumnVoid(const std::string &name, const std::type_info *type, bool isConst)
get the data for the given column in a type-erased manner
Definition: ColumnarToolWrapper.cxx:169
columnar::ColumnarToolWrapper::MyColumnInfo::isOffset
bool isOffset
Definition: ColumnarToolWrapper.h:95
index
Definition: index.py:1
columnar::ColumnarToolWrapper::m_toolOwn
std::shared_ptr< const IColumnarTool > m_toolOwn
the owning pointer to the tool
Definition: ColumnarToolWrapper.h:81
columnar::ColumnarToolWrapperData::checkColumnsValid
void checkColumnsValid()
check that all columns are valid
Definition: ColumnarToolWrapper.cxx:189
columnar::ColumnarToolWrapper::MyColumnInfo::isOptional
bool isOptional
Definition: ColumnarToolWrapper.h:97
columnar::ColumnarToolWrapper::getColumnNames
std::vector< std::string > getColumnNames() const
get information on all defined columns
Definition: ColumnarToolWrapper.cxx:250
DeMoUpdate.column
dictionary column
Definition: DeMoUpdate.py:1110
columnar::ColumnarToolWrapper::operator=
ColumnarToolWrapper & operator=(const ColumnarToolWrapper &)=delete
columnar::ColumnarToolWrapperData::m_data
std::vector< void * > m_data
Definition: ColumnarToolWrapper.h:213
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
columnar::ColumnarToolWrapper::MyColumnInfo::type
const std::type_info * type
Definition: ColumnarToolWrapper.h:87
columnar::ColumnarToolWrapperData::checkColumn
void checkColumn(const std::pair< const std::string, ColumnarToolWrapper::MyColumnInfo > &column)
Definition: ColumnarToolWrapper.cxx:207
columnar::ColumnarToolWrapper::MyColumnInfo::numpyType
int numpyType
Definition: ColumnarToolWrapper.h:99
columnar::ColumnarToolWrapperData::setColumnNumpy
void setColumnNumpy(const std::string &name, std::size_t size, const void *dataPtr, int type, unsigned bits, bool isConst)
set the data for the given column with the user passing in the type information from numpy
Definition: ColumnarToolWrapper.cxx:146
columnar::ColumnarToolWrapperData::setColumnVoid
void setColumnVoid(const std::string &name, std::size_t size, const void *dataPtr, const std::type_info &type, bool isConst)
set the data for the given column with the user passing in the type
Definition: ColumnarToolWrapper.cxx:123
columnar::ColumnarToolWrapperData::m_dataSize
std::vector< std::size_t > m_dataSize
Definition: ColumnarToolWrapper.h:214
columnar::ColumnarToolWrapperData::m_columnIsChecked
std::vector< bool > m_columnIsChecked
Definition: ColumnarToolWrapper.h:215
columnar::ColumnarToolWrapperData
a class that holds the columnar data for a single call to ColumnarToolWrapper
Definition: ColumnarToolWrapper.h:136
columnar::ColumnarToolWrapper::ColumnarToolWrapper
ColumnarToolWrapper(IColumnarTool *val_tool)
constructor: wrap the given tool (non-owning)
Definition: ColumnarToolWrapper.cxx:29
columnar::size
std::size_t size() const noexcept
Definition: ObjectRange.h:132
columnar::ColumnarToolWrapperData::m_columnIsFilled
std::vector< bool > m_columnIsFilled
Definition: ColumnarToolWrapper.h:216
columnar::ColumnarToolWrapper::MyColumnInfo::offsets
const std::pair< const std::string, MyColumnInfo > * offsets
Definition: ColumnarToolWrapper.h:103
columnar::ColumnarToolWrapper::getColumnInfo
std::vector< ColumnInfo > getColumnInfo() const
Definition: ColumnarToolWrapper.cxx:262
columnar::ColumnarToolWrapperData::setColumn
void setColumn(const std::string &name, std::size_t size, CT *dataPtr)
set the data for the given column picking up the type via a template
Definition: ColumnarToolWrapper.h:149
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
columnar::ColumnarToolWrapper::MyColumnInfo::numpyBits
unsigned numpyBits
Definition: ColumnarToolWrapper.h:101
columnar::final
CM final
Definition: ColumnAccessor.h:106
columnar::ColumnarToolWrapper
a class that wraps an IColumnarTool for use in Python
Definition: ColumnarToolWrapper.h:36
columnar::ColumnarToolWrapper::m_tool
const IColumnarTool * m_tool
the wrapped tool
Definition: ColumnarToolWrapper.h:78
columnar::ColumnarToolWrapper::MyColumnInfo::fixedDimensions
unsigned fixedDimensions
Definition: ColumnarToolWrapper.h:93
columnar::ColumnarToolWrapperData::ColumnarToolWrapperData
ColumnarToolWrapperData(const ColumnarToolWrapper *val_wrapper) noexcept
constructor: wrap the given tool
Definition: ColumnarToolWrapper.cxx:112
columnar::ColumnarToolWrapperData::getColumn
std::pair< std::size_t, CT * > getColumn(const std::string &name)
get the data for the given column picking up the type via a template
Definition: ColumnarToolWrapper.h:187
columnar::ColumnarToolWrapper::m_columns
std::unordered_map< std::string, MyColumnInfo > m_columns
Definition: ColumnarToolWrapper.h:105
columnar::CT
CT
Definition: ColumnAccessor.h:160
columnar::ColumnarToolWrapper::m_numColumns
unsigned m_numColumns
the number of columns that the tool expects (equal to the greatest column index + 1)
Definition: ColumnarToolWrapper.h:110
columnar
Definition: ClusterDef.h:16
columnar::ColumnarToolWrapper::MyColumnInfo::isConst
bool isConst
Definition: ColumnarToolWrapper.h:89
columnar::ColumnarToolWrapper::ColumnarToolWrapper
ColumnarToolWrapper(const ColumnarToolWrapper &)=delete
columnar::ColumnarToolWrapper::MyColumnInfo
my cached information for the various columns needed
Definition: ColumnarToolWrapper.h:86
columnar::ColumnarToolWrapperData::call
void call()
call the tool
Definition: ColumnarToolWrapper.cxx:198
columnar::ColumnarToolWrapperData::data
void ** data() noexcept
the data vector we have assembled
Definition: ColumnarToolWrapper.h:201