File indexing completed on 2026-01-09 09:26:47
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Definitions/Algebra.hpp"
0010 #include "Acts/Utilities/Logger.hpp"
0011 #include "ActsExamples/Framework/ProcessCode.hpp"
0012 #include "ActsExamples/Io/Json/JsonDigitizationConfig.hpp"
0013 #include "ActsExamples/Io/Json/JsonGeometryList.hpp"
0014 #include "ActsExamples/Io/Json/JsonMaterialWriter.hpp"
0015 #include "ActsExamples/Io/Json/JsonSurfacesWriter.hpp"
0016 #include "ActsExamples/Io/Json/JsonTrackParamsLookupReader.hpp"
0017 #include "ActsExamples/Io/Json/JsonTrackParamsLookupWriter.hpp"
0018 #include "ActsPython/Utilities/Helpers.hpp"
0019 #include "ActsPython/Utilities/Macros.hpp"
0020
0021 #include <fstream>
0022 #include <initializer_list>
0023 #include <memory>
0024 #include <string>
0025 #include <tuple>
0026 #include <vector>
0027
0028 #include <nlohmann/json.hpp>
0029 #include <pybind11/pybind11.h>
0030 #include <pybind11/stl.h>
0031
0032 namespace Acts {
0033 class IMaterialDecorator;
0034 }
0035 namespace ActsExamples {
0036 class IMaterialWriter;
0037 class IWriter;
0038
0039 namespace Experimental {
0040 class ITrackParamsLookupWriter;
0041 }
0042
0043 }
0044
0045 namespace py = pybind11;
0046 using namespace pybind11::literals;
0047
0048 using namespace Acts;
0049 using namespace ActsExamples;
0050 using namespace ActsPython;
0051
0052 PYBIND11_MODULE(ActsExamplesPythonBindingsJson, json) {
0053 {
0054 py::enum_<JsonFormat>(json, "JsonFormat")
0055 .value("NoOutput", JsonFormat::NoOutput)
0056 .value("Json", JsonFormat::Json)
0057 .value("Cbor", JsonFormat::Cbor)
0058 .value("All", JsonFormat::All);
0059 }
0060
0061 {
0062 auto cls =
0063 py::class_<JsonMaterialWriter, IMaterialWriter,
0064 std::shared_ptr<JsonMaterialWriter>>(json,
0065 "JsonMaterialWriter")
0066 .def(py::init<const JsonMaterialWriter::Config&, Logging::Level>(),
0067 py::arg("config"), py::arg("level"))
0068 .def("writeMaterial", &JsonMaterialWriter::writeMaterial)
0069 .def("write", &JsonMaterialWriter::write)
0070 .def_property_readonly("config", &JsonMaterialWriter::config);
0071
0072 auto c =
0073 py::class_<JsonMaterialWriter::Config>(cls, "Config").def(py::init<>());
0074 ACTS_PYTHON_STRUCT(c, converterCfg, fileName, writeFormat);
0075 }
0076
0077 {
0078 using IWriter = ITrackParamsLookupWriter;
0079 using Writer = JsonTrackParamsLookupWriter;
0080 using Config = Writer::Config;
0081
0082 auto cls = py::class_<Writer, IWriter, std::shared_ptr<Writer>>(
0083 json, "JsonTrackParamsLookupWriter")
0084 .def(py::init<const Config&>(), py::arg("config"))
0085 .def("writeLookup", &Writer::writeLookup)
0086 .def_property_readonly("config", &Writer::config);
0087
0088 auto c = py::class_<Config>(cls, "Config")
0089 .def(py::init<>())
0090 .def(py::init<const std::string&>(), py::arg("path"));
0091 ACTS_PYTHON_STRUCT(c, path);
0092 }
0093
0094 {
0095 using IReader = ITrackParamsLookupReader;
0096 using Reader = JsonTrackParamsLookupReader;
0097 using Config = Reader::Config;
0098
0099 auto cls = py::class_<Reader, IReader, std::shared_ptr<Reader>>(
0100 json, "JsonTrackParamsLookupReader")
0101 .def(py::init<const Config&>(), py::arg("config"))
0102 .def("readLookup", &Reader::readLookup)
0103 .def_property_readonly("config", &Reader::config);
0104
0105 auto c =
0106 py::class_<Config>(cls, "Config")
0107 .def(py::init<>())
0108 .def(
0109 py::init<std::unordered_map<GeometryIdentifier, const Surface*>,
0110 std::pair<double, double>>(),
0111 py::arg("refLayers"), py::arg("bins"));
0112 ACTS_PYTHON_STRUCT(c, refLayers, bins);
0113 }
0114
0115 {
0116 auto cls =
0117 py::class_<JsonSurfacesWriter, IWriter,
0118 std::shared_ptr<JsonSurfacesWriter>>(json,
0119 "JsonSurfacesWriter")
0120 .def(py::init<const JsonSurfacesWriter::Config&, Logging::Level>(),
0121 py::arg("config"), py::arg("level"))
0122 .def("write", &JsonSurfacesWriter::write)
0123 .def_property_readonly("config", &JsonSurfacesWriter::config);
0124
0125 auto c =
0126 py::class_<JsonSurfacesWriter::Config>(cls, "Config").def(py::init<>());
0127
0128 ACTS_PYTHON_STRUCT(c, trackingGeometry, outputDir, outputPrecision,
0129 writeLayer, writeApproach, writeSensitive, writeBoundary,
0130 writePerEvent, writeOnlyNames);
0131 }
0132
0133 json.def("readJsonGeometryList", readJsonGeometryList);
0134
0135 {
0136 json.def("readDigiConfigFromJson", readDigiConfigFromJson);
0137 json.def("writeDigiConfigToJson", writeDigiConfigToJson);
0138 }
0139 }