127 {
128 module.doc() = "Nanobind bindings for PythonToolHandle";
129
131 throw nb::import_error("This module can only be used in columnar access mode. Try setting up a ColumnarAnalysis release instead.");
132
133 module.attr("numberOfEventsName") = &columnar::numberOfEventsName;
134
136 nb::enum_<columnar::ColumnAccessMode>(module, "ColumnAccessMode")
141 switch (mode) {
143 return "<ColumnAccessMode input>";
145 return "<ColumnAccessMode output>";
147 return "<ColumnAccessMode update>";
148 default:
149 return "<ColumnAccessMode update value=" + std::to_string(static_cast<int>(mode)) + ">";
150 }
151 })
152 .export_values();
153
154 nb::class_<columnar::ColumnInfo>(module, "ColumnInfo")
155 .def(nb::init<>())
160 })
170 std::string access_mode;
173 access_mode = "input";
174 break;
176 access_mode = "output";
177 break;
179 access_mode = "update";
180 break;
181 default:
182
183 access_mode = "unknown";
184 }
185 return "<ColumnInfo name='" + self.
name +
"'" +
187 ", access_mode='" + access_mode + "'" +
190 ">";
191 })
194 d[
"name"] = self.
name;
197 d[
"access_mode"] =
static_cast<int>(self.
accessMode);
206 });
207
208 nb::class_<columnar::PythonToolHandle>(module, "PythonToolHandle")
209 .def(nb::init())
210
211
216 std::cerr << "Warning: PythonToolHandle.type is empty."
217 << " Set with PythonToolHandle.set_type_and_name." << std::endl;
218 }
220 })
221
226 std::cerr << "Warning: PythonToolHandle.name is empty."
227 << " Set with PythonToolHandle.set_type_and_name." << std::endl;
228 }
230 })
231
232
233 .def("set_type_and_name",
236 },
237 "type_and_name"_a,
238 "Set the type and name of the tool.")
239
241 "key"_a, "value"_a,
242 "Set a property on the tool.")
243
245 "key"_a, "value"_a,
246 "Set a property on the tool.")
247
248 .def("preinitialize",
250 "Preinitialize the tool.")
251
252
253 .def("rename_containers",
255 "renames"_a,
256 "Rename the columns the tool uses.")
257
258
259 .def("rename_containers",
261 std::vector<std::pair<std::string, std::string>> vectorized;
262 for (
const auto&
pair : renames)
263 vectorized.emplace_back(
pair);
264
266 },
267 "renames"_a,
268 "Rename the columns the tool uses.")
269
270 .def("initialize",
272 "Initialize the tool.")
273
274 .def("apply_systematic_variation",
277 },
278 "sys_name"_a,
279 "Apply a systematic variation to the tool.")
280
281 .def("set_column",
284 },
285 "key"_a, "column"_a,
286 "Set a float column pointer.")
287
288 .def("set_column",
291 },
292 "key"_a, "column"_a,
293 "Set a char column pointer.")
294
295 .def("set_column",
298 },
299 "key"_a, "column"_a,
300 "Set an int column pointer.")
301
302 .def("set_column",
305 },
306 "key"_a, "column"_a,
307 "Set a uint8_t column pointer.")
308
309 .def("set_column",
312 },
313 "key"_a, "column"_a,
314 "Set a uint16_t column pointer.")
315
316 .def("set_column",
319 },
320 "key"_a, "column"_a,
321 "Set a uint32_t column pointer.")
322
323 .def("set_column",
326 },
327 "key"_a, "column"_a,
328 "Set a uint64_t column pointer.")
329
331
332 "key"_a, "column"_a, "is_const"_a = true,
333 "Set a void column pointer (nanobind version).")
334
336 "key"_a, "column"_a,
337 "Set a void immutable column pointer (nanobind version).")
338
339 .def("call",
341 "Call the tool and reset the columns.")
342
343 .def_prop_ro(
344 "columns",
346 "Get the expected column information."
347 )
348
349 .def("get_recommended_systematics",
351 "Get the recommended systematics.")
352
353
354
358 });
359}
std::string get_type_name(const std::type_info &type_info)
void setColumnVoid(columnar::PythonToolHandle &self, const std::string &key, nb::ndarray<> column, bool is_const=true)
void setProperty(columnar::PythonToolHandle &self, const std::string &key, nb::object value)
void setImmutableColumnVoid(columnar::PythonToolHandle &self, const std::string &key, nb::ndarray<> column)
std::string getAddressString(const columnar::PythonToolHandle &obj)
constexpr unsigned columnarAccessMode
ColumnAccessMode
an enum for the different access modes for a column
@ update
an updateable column
a struct that contains meta-information about each column that's needed to interface the column with ...
std::string offsetName
the name of the offset column used for this column (or empty string for none)
std::vector< unsigned > fixedDimensions
the fixed dimensions this column has (if any)
bool isOptional
whether this column is optional
std::string variantLinkKeyColumn
if this is a variant link column, this is the name of the column with the container keys
std::string name
the name of the column
std::vector< std::string > linkTargetNames
for link columns: the name(s) of the container(s) we link to
bool isOffset
whether this is an offset column
ColumnAccessMode accessMode
the access mode for the column
std::string replacesColumn
whether this replaces another column
unsigned index
the index of the column in the data array
const std::type_info * type
the type of the individual entries in the column