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