193 {
194 module.doc() = "Nanobind bindings for PythonToolHandle";
195
197 throw nb::import_error("This module can only be used in columnar access mode. Try setting up a ColumnarAnalysis release instead.");
198
199 module.attr("numberOfEventsName") = &columnar::eventRangeColumnName;
200 module.attr("eventRangeColumnName") = &columnar::eventRangeColumnName;
201
202
203#ifdef XAOD_STANDALONE
204
205 module.def("set_python_printer", &set_printer_from_callable, nb::arg("callback"),
206 "Install a Python callable(level: int, name: str, text: str) as the global "
207 "C++ message printer.");
208
209
210 module.def("set_python_printer", &clear_printer,
211 "Reset to the default stdout message printer.");
212#else
213
214
215 module.def("set_python_printer", [](nb::args, nb::kwargs) {
216 throw std::runtime_error(
217 "set_python_printer is only available in standalone "
218 "(AnalysisBase/ColumnarAnalysis) builds, not in Athena/AthAnalysis.");
219 }, "Not available in Athena/AthAnalysis builds.");
220#endif
221
223 nb::enum_<columnar::ColumnAccessMode>(module, "ColumnAccessMode")
228 switch (mode) {
230 return "<ColumnAccessMode input>";
232 return "<ColumnAccessMode output>";
234 return "<ColumnAccessMode update>";
235 default:
236 return "<ColumnAccessMode update value=" + std::to_string(static_cast<int>(mode)) + ">";
237 }
238 })
239 .export_values();
240
241 nb::enum_<MSG::Level>(module, "MsgLevel", nb::is_arithmetic())
242 .value("NIL", MSG::NIL)
243 .value("VERBOSE", MSG::VERBOSE)
244 .value("DEBUG", MSG::DEBUG)
245 .value("INFO", MSG::INFO)
246 .value("WARNING", MSG::WARNING)
247 .value("ERROR", MSG::ERROR)
248 .value("FATAL", MSG::FATAL)
249 .export_values();
250
251 nb::class_<columnar::ColumnInfo>(module, "ColumnInfo")
252 .def(nb::init<>())
257 })
267 std::string access_mode;
270 access_mode = "input";
271 break;
273 access_mode = "output";
274 break;
276 access_mode = "update";
277 break;
278 default:
279
280 access_mode = "unknown";
281 }
282 return "<ColumnInfo name='" + self.
name +
"'" +
284 ", access_mode='" + access_mode + "'" +
287 ">";
288 })
291 d[
"name"] = self.
name;
294 d[
"access_mode"] =
static_cast<int>(self.
accessMode);
303 });
304
305 nb::class_<columnar::PythonToolHandle>(module, "PythonToolHandle")
306 .def(nb::init())
307
308
313 std::cerr << "Warning: PythonToolHandle.type is empty."
314 << " Set with PythonToolHandle.set_type_and_name." << std::endl;
315 }
317 })
318
323 std::cerr << "Warning: PythonToolHandle.name is empty."
324 << " Set with PythonToolHandle.set_type_and_name." << std::endl;
325 }
327 })
328
329
330 .def("set_type_and_name",
333 },
334 "type_and_name"_a,
335 "Set the type and name of the tool.")
336
338 "key"_a, "value"_a,
339 "Set a property on the tool.")
340
342 "key"_a, "value"_a,
343 "Set a property on the tool.")
344
345 .def("preinitialize",
347 "Preinitialize the tool.")
348
349
350 .def("rename_containers",
352 "renames"_a,
353 "Rename the columns the tool uses.")
354
355
356 .def("rename_containers",
358 std::vector<std::pair<std::string, std::string>> vectorized;
359 for (
const auto&
pair : renames)
360 vectorized.emplace_back(
pair);
361
363 },
364 "renames"_a,
365 "Rename the columns the tool uses.")
366
367 .def("initialize",
369 "Initialize the tool.")
370
371 .def("apply_systematic_variation",
374 },
375 "sys_name"_a,
376 "Apply a systematic variation to the tool.")
377
378 .def("set_column",
381 },
382 "key"_a, "column"_a,
383 "Set a float column pointer.")
384
385 .def("set_column",
388 },
389 "key"_a, "column"_a,
390 "Set a char column pointer.")
391
392 .def("set_column",
395 },
396 "key"_a, "column"_a,
397 "Set an int column pointer.")
398
399 .def("set_column",
402 },
403 "key"_a, "column"_a,
404 "Set a uint8_t column pointer.")
405
406 .def("set_column",
409 },
410 "key"_a, "column"_a,
411 "Set a uint16_t column pointer.")
412
413 .def("set_column",
416 },
417 "key"_a, "column"_a,
418 "Set a uint32_t column pointer.")
419
420 .def("set_column",
423 },
424 "key"_a, "column"_a,
425 "Set a uint64_t column pointer.")
426
428
429 "key"_a, "column"_a, "is_const"_a = true,
430 "Set a void column pointer (nanobind version).")
431
433 "key"_a, "column"_a,
434 "Set a void immutable column pointer (nanobind version).")
435
437 "key"_a,
438 "Get a column as a numpy array (zero-copy view into the tool's buffer).")
439
440 .def("keys",
442 "Return the column names (enables dict(handle)).")
443
444 .def("call",
446 "Call the tool and reset the columns.")
447
448 .def_prop_ro(
449 "columns",
451 "Get the expected column information."
452 )
453
454 .def("get_recommended_systematics",
456 "Get the recommended systematics.")
457
458
459
463 });
464}
nb::object getColumnVoid(columnar::PythonToolHandle &self, const std::string &key)
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