File indexing completed on 2025-08-05 08:10:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/Json/ExtentJsonConverter.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Plugins/Json/UtilitiesJsonConverter.hpp"
0013 #include "Acts/Utilities/BinningType.hpp"
0014 #include "Acts/Utilities/Enumerate.hpp"
0015 #include "Acts/Utilities/RangeXD.hpp"
0016
0017 #include <array>
0018 #include <iterator>
0019 #include <vector>
0020
0021 void Acts::to_json(nlohmann::json& j, const Acts::Extent& e) {
0022 const auto& bValueNames = binningValueNames();
0023
0024 {
0025 nlohmann::json jrange;
0026 const auto& xrange = e.range();
0027 for (auto [ib, ibv] : enumerate(s_binningValues)) {
0028 if (e.constrains(ibv)) {
0029 jrange[bValueNames[ib]] = xrange[ib];
0030 }
0031 }
0032 j["range"] = jrange;
0033 }
0034
0035 {
0036 nlohmann::json jenvelope;
0037 const auto& envelope = e.envelope();
0038 for (auto [ib, ibv] : enumerate(s_binningValues)) {
0039 if (envelope[ibv] != zeroEnvelope) {
0040 jenvelope[bValueNames[ib]] =
0041 Range1D<ActsScalar>(envelope[ib][0], envelope[ib][1]);
0042 }
0043 }
0044 if (!jenvelope.empty()) {
0045 j["envelope"] = jenvelope;
0046 }
0047 }
0048 }
0049
0050 void Acts::from_json(const nlohmann::json& j, Acts::Extent& e) {
0051 const auto& bValueNames = binningValueNames();
0052
0053 {
0054 const auto& jrange = j["range"];
0055 for (auto [ib, bvn] : enumerate(bValueNames)) {
0056 if (jrange.contains(bvn)) {
0057 e.set(static_cast<BinningValue>(ib), jrange[bvn]["min"],
0058 jrange[bvn]["max"]);
0059 }
0060 }
0061 }
0062
0063 if (j.contains("envelope")) {
0064 const auto& jenvelope = j["envelope"];
0065 ExtentEnvelope envelope;
0066 for (auto [ib, bvn] : enumerate(bValueNames)) {
0067 if (jenvelope.find(bvn) != jenvelope.end()) {
0068 envelope[ib] = {jenvelope[bvn]["min"], jenvelope[bvn]["max"]};
0069 }
0070 }
0071 e.setEnvelope(envelope);
0072 }
0073 }