File indexing completed on 2026-06-17 07:47:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/Json/VolumeBoundsJsonConverter.hpp"
0010
0011 #include "Acts/Geometry/ConeVolumeBounds.hpp"
0012 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0013 #include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp"
0014 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0015 #include "Acts/Geometry/DiamondVolumeBounds.hpp"
0016 #include "Acts/Geometry/GenericCuboidVolumeBounds.hpp"
0017 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0018 #include "Acts/Geometry/VolumeBounds.hpp"
0019
0020 #include <algorithm>
0021 #include <stdexcept>
0022
0023 void Acts::to_json(nlohmann::json& j, const VolumeBounds& bounds) {
0024 j["type"] = bounds.type();
0025 j["values"] = bounds.values();
0026 }
0027
0028 nlohmann::json Acts::VolumeBoundsJsonConverter::toJson(
0029 const VolumeBounds& bounds) {
0030 return nlohmann::json(bounds);
0031 }
0032
0033 std::unique_ptr<Acts::VolumeBounds> Acts::VolumeBoundsJsonConverter::fromJson(
0034 const nlohmann::json& jVolumeBounds) {
0035 const auto type = jVolumeBounds["type"].get<VolumeBounds::BoundsType>();
0036
0037 switch (type) {
0038 case VolumeBounds::BoundsType::eCone:
0039 return fromJson<ConeVolumeBounds>(jVolumeBounds);
0040 case VolumeBounds::BoundsType::eCuboid:
0041 return fromJson<CuboidVolumeBounds>(jVolumeBounds);
0042 case VolumeBounds::BoundsType::eCutoutCylinder:
0043 return fromJson<CutoutCylinderVolumeBounds>(jVolumeBounds);
0044 case VolumeBounds::BoundsType::eCylinder:
0045 return fromJson<CylinderVolumeBounds>(jVolumeBounds);
0046 case VolumeBounds::BoundsType::eTrapezoid:
0047 return fromJson<TrapezoidVolumeBounds>(jVolumeBounds);
0048 case VolumeBounds::BoundsType::eDiamond:
0049 return fromJson<DiamondVolumeBounds>(jVolumeBounds);
0050 case VolumeBounds::BoundsType::eGenericCuboid:
0051 return fromJson<GenericCuboidVolumeBounds>(jVolumeBounds);
0052 default:
0053 throw std::invalid_argument("Unknown volume bounds type!");
0054 }
0055 return nullptr;
0056 }