Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:15:19

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Plugins/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/GenericCuboidVolumeBounds.hpp"
0016 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0017 #include "Acts/Geometry/VolumeBounds.hpp"
0018 
0019 #include <algorithm>
0020 #include <stdexcept>
0021 
0022 void Acts::to_json(nlohmann::json& j, const VolumeBounds& bounds) {
0023   j["type"] = bounds.type();
0024   j["values"] = bounds.values();
0025 }
0026 
0027 nlohmann::json Acts::VolumeBoundsJsonConverter::toJson(
0028     const VolumeBounds& bounds) {
0029   return nlohmann::json(bounds);
0030 }
0031 
0032 std::unique_ptr<Acts::VolumeBounds> Acts::VolumeBoundsJsonConverter::fromJson(
0033     const nlohmann::json& jVolumeBounds) {
0034   const auto type = jVolumeBounds["type"].get<VolumeBounds::BoundsType>();
0035 
0036   switch (type) {
0037     case VolumeBounds::BoundsType::eCone:
0038       return fromJson<ConeVolumeBounds>(jVolumeBounds);
0039     case VolumeBounds::BoundsType::eCuboid:
0040       return fromJson<CuboidVolumeBounds>(jVolumeBounds);
0041     case VolumeBounds::BoundsType::eCutoutCylinder:
0042       return fromJson<CutoutCylinderVolumeBounds>(jVolumeBounds);
0043     case VolumeBounds::BoundsType::eCylinder:
0044       return fromJson<CylinderVolumeBounds>(jVolumeBounds);
0045     case VolumeBounds::BoundsType::eTrapezoid:
0046       return fromJson<TrapezoidVolumeBounds>(jVolumeBounds);
0047     case VolumeBounds::BoundsType::eGenericCuboid:
0048       return fromJson<GenericCuboidVolumeBounds>(jVolumeBounds);
0049     default:
0050       throw std::invalid_argument("Unknown volume bounds type!");
0051   }
0052   return nullptr;
0053 }  // namespace Acts