File indexing completed on 2025-01-18 09:12:01
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Detector/Detector.hpp"
0010 #include "Acts/Plugins/Detray/DetrayConverter.hpp"
0011 #include "Acts/Plugins/Python/Utilities.hpp"
0012
0013 #include <memory>
0014 #include <string>
0015
0016 #include <detray/builders/detector_builder.hpp>
0017 #include <pybind11/pybind11.h>
0018 #include <vecmem/memory/host_memory_resource.hpp>
0019 #include <vecmem/memory/memory_resource.hpp>
0020
0021 namespace py = pybind11;
0022 using namespace pybind11::literals;
0023
0024 using namespace Acts;
0025 using namespace detray;
0026 using namespace detray::io::detail;
0027
0028 namespace Acts::Python {
0029
0030 void addDetray(Context& ctx) {
0031 auto [m, mex] = ctx.get("main", "examples");
0032
0033 auto detray = m.def_submodule("detray");
0034 {
0035 py::class_<detector<default_metadata>,
0036 std::shared_ptr<detector<default_metadata>>>(detray,
0037 "detray_detector");
0038 }
0039
0040 {
0041
0042
0043
0044
0045 detray.def("writeToJson", [](const GeometryContext& gctx,
0046 const Experimental::Detector& detector) {
0047 auto memoryResource = vecmem::host_memory_resource();
0048
0049 DetrayConverter::Options options;
0050 options.writeToJson = true;
0051 options.convertMaterial = false;
0052 options.convertSurfaceGrids = true;
0053 auto DetrayHostDetector =
0054 DetrayConverter().convert<>(gctx, detector, memoryResource, options);
0055 });
0056 }
0057
0058 {
0059 auto converter = py::class_<DetrayConverter>(detray, "DetrayConverter");
0060
0061 auto options = py::class_<DetrayConverter::Options>(converter, "Options")
0062 .def(py::init<>());
0063
0064 ACTS_PYTHON_STRUCT_BEGIN(options, DetrayConverter::Options);
0065 ACTS_PYTHON_MEMBER(convertMaterial);
0066 ACTS_PYTHON_MEMBER(convertSurfaceGrids);
0067 ACTS_PYTHON_MEMBER(writeToJson);
0068 ACTS_PYTHON_STRUCT_END();
0069 }
0070 }
0071 }