File indexing completed on 2025-07-02 07:51:59
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/Json/ProtoAxisJsonConverter.hpp"
0010
0011 #include "Acts/Plugins/Json/GridJsonConverter.hpp"
0012 #include "Acts/Plugins/Json/UtilitiesJsonConverter.hpp"
0013 #include "Acts/Utilities/AxisDefinitions.hpp"
0014
0015 nlohmann::json Acts::ProtoAxisJsonConverter::toJson(const Acts::ProtoAxis& pa) {
0016 nlohmann::json j;
0017 j["axis"] = AxisJsonConverter::toJson(pa.getAxis());
0018 j["autorange"] = pa.isAutorange();
0019 return j;
0020 }
0021
0022 Acts::ProtoAxis Acts::ProtoAxisJsonConverter::fromJson(
0023 const nlohmann::json& j) {
0024 auto axisBoundaryType =
0025 j.at("axis").at("boundary_type").get<Acts::AxisBoundaryType>();
0026 if (auto axisType = j.at("axis").at("type").get<Acts::AxisType>();
0027 axisType == AxisType::Equidistant) {
0028 auto nbins = j.at("axis").at("bins").get<std::size_t>();
0029 if (nbins == 0) {
0030 throw std::invalid_argument("Number of bins must be positive");
0031 }
0032
0033 if (j.at("autorange").get<bool>()) {
0034 return ProtoAxis(axisBoundaryType, nbins);
0035 }
0036 auto min = j.at("axis").at("range").at(0).get<double>();
0037 auto max = j.at("axis").at("range").at(1).get<double>();
0038 if (min >= max) {
0039 throw std::invalid_argument("Invalid range: min must be less than max");
0040 }
0041 return ProtoAxis(axisBoundaryType, min, max, nbins);
0042 }
0043 auto binEdges = j.at("axis").at("boundaries").get<std::vector<double>>();
0044 if (binEdges.size() < 2) {
0045 throw std::invalid_argument("At least two bin edges required");
0046 }
0047 if (!std::ranges::is_sorted(binEdges)) {
0048 throw std::invalid_argument("Bin edges must be sorted in ascending order");
0049 }
0050 return ProtoAxis(axisBoundaryType, binEdges);
0051 }