21 #include <unordered_map>
23 #include <pybind11/eval.h>
24 #include <pybind11/pybind11.h>
25 #include <pybind11/stl.h>
27 namespace py = pybind11;
28 using namespace pybind11::literals;
30 namespace Acts::Python {
33 auto&
m = ctx.
get(
"main");
34 auto u =
m.def_submodule(
"UnitConstants");
36 #define UNIT(x) u.attr(#x) = Acts::UnitConstants::x;
100 auto&
m = ctx.
get(
"main");
101 auto logging =
m.def_submodule(
"logging",
"");
103 auto levelEnum = py::enum_<Acts::Logging::Level>(logging,
"Level")
121 return self >= other;
127 auto locals = py::dict();
128 locals[
"args"] =
args;
130 py::exec(R
"(
message = fmt % args
)",
131 py::globals(), locals);
140 py::class_<PythonLogger, std::shared_ptr<PythonLogger>>(logging,
"Logger")
141 .def(
"log", &PythonLogger::log)
148 .def(
"setLevel", &PythonLogger::setLevel);
150 static std::unordered_map<std::string, std::shared_ptr<PythonLogger>>
151 pythonLoggers = {{
"root", std::make_shared<PythonLogger>(
157 if (pythonLoggers.find(name) == pythonLoggers.end()) {
158 pythonLoggers[
name] =
161 return pythonLoggers[
name];
163 py::arg(
"name") =
"root");
166 pythonLoggers.at(
"root")->setLevel(level);
171 auto locals = py::dict();
172 locals[
"args"] =
args;
174 py::exec(R
"(
message = fmt % args
)",
175 py::globals(), locals);
179 pythonLoggers.at(
"root")->log(level,
message);
186 static py::exception<Logging::ThresholdFailure> exc(
187 logging,
"ThresholdFailure", PyExc_RuntimeError);
189 py::register_exception_translator([](std::exception_ptr
p) {
192 std::rethrow_exception(p);
194 }
catch (
const std::exception&
e) {
196 if (what.find(
"ACTS_LOG_FAILURE_THRESHOLD") != std::string::npos) {
199 std::rethrow_exception(p);
213 auto&
m = ctx.
get(
"main");
214 py::enum_<Acts::PdgParticle>(
m,
"PdgParticle")
235 auto&
m = ctx.
get(
"main");
237 py::class_<Acts::Vector2>(
m,
"Vector2")
238 .def(py::init<double, double>())
239 .def(
py::init([](std::array<double, 2>
a) {
247 py::class_<Acts::Vector3>(
m,
"Vector3")
248 .def(py::init<double, double, double>())
249 .def(
py::init([](std::array<double, 3> a) {
251 v << a[0], a[1], a[2];
257 py::class_<Acts::Vector4>(
m,
"Vector4")
258 .def(py::init<double, double, double, double>())
259 .def(
py::init([](std::array<double, 4> a) {
261 v << a[0], a[1], a[2], a[3];
267 py::class_<Acts::Transform3>(
m,
"Transform3")
271 Acts::Vector3(translation[0], translation[1], translation[2]));
280 auto& m = ctx.get(
"main");
281 auto binning = m.def_submodule(
"Binning",
"");
283 auto binningValue = py::enum_<Acts::BinningValue>(binning,
"BinningValue")
292 py::enum_<Acts::detail::AxisBoundaryType>(binning,
"AxisBoundaryType")
293 .
value(
"bound", Acts::detail::AxisBoundaryType::Bound)
294 .value(
"closed", Acts::detail::AxisBoundaryType::Closed)
295 .value(
"open", Acts::detail::AxisBoundaryType::Open)
298 auto axisType = py::enum_<Acts::detail::AxisType>(binning,
"AxisType")
299 .
value(
"equidistant", Acts::detail::AxisType::Equidistant)
300 .value(
"variable", Acts::detail::AxisType::Variable)