Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 09:40:23

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 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GenericCuboidVolumeBounds.hpp"
0013 #include "Acts/Geometry/VolumeBounds.hpp"
0014 #include "ActsPlugins/Json/ActsJson.hpp"
0015 
0016 #include <array>
0017 #include <cstddef>
0018 #include <memory>
0019 #include <string>
0020 #include <vector>
0021 
0022 #include <nlohmann/json.hpp>
0023 
0024 // Custom Json encoder/decoders. Naming is mandated by nlohmann::json and thus
0025 // can not match our naming guidelines.
0026 namespace Acts {
0027 
0028 /// Convert VolumeBounds to JSON
0029 /// @param j Destination JSON object
0030 /// @param bounds Source VolumeBounds to convert
0031 void to_json(nlohmann::json& j, const VolumeBounds& bounds);
0032 
0033 namespace VolumeBoundsJsonConverter {
0034 
0035 /// Conversion to Json from volume bounds
0036 ///
0037 /// @param bounds is the bounds object
0038 ///
0039 /// @return the json object
0040 nlohmann::json toJson(const VolumeBounds& bounds);
0041 
0042 /// Conversion to volume bounds from json
0043 ///
0044 /// The type is given as a template argument in order to be able
0045 /// to construct the correct fitting types for surfaces.
0046 ///
0047 /// @param jVolumeBounds the read-in json object
0048 ///
0049 /// @return a unique_ptr to a volume bounds object for type polymorphism
0050 template <typename bounds_t>
0051 std::unique_ptr<bounds_t> fromJson(const nlohmann::json& jVolumeBounds) {
0052   constexpr std::size_t kValues = bounds_t::BoundValues::eSize;
0053   std::array<double, kValues> bValues{};
0054   std::vector<double> bVector = jVolumeBounds["values"];
0055   std::copy_n(bVector.begin(), kValues, bValues.begin());
0056   return std::make_unique<bounds_t>(bValues);
0057 }
0058 
0059 /// Conversion to volume bounds from json
0060 /// @param jVolumeBounds the read-in json object
0061 ///
0062 /// @return a unique_ptr to a volume bounds object for type polymorphism
0063 std::unique_ptr<VolumeBounds> fromJson(const nlohmann::json& jVolumeBounds);
0064 
0065 }  // namespace VolumeBoundsJsonConverter
0066 
0067 // This macro creates a conversion for the volume bounds type
0068 NLOHMANN_JSON_SERIALIZE_ENUM(
0069     VolumeBounds::BoundsType,
0070     {{VolumeBounds::BoundsType::eCone, "Cone"},
0071      {VolumeBounds::BoundsType::eCuboid, "Cuboid"},
0072      {VolumeBounds::BoundsType::eCutoutCylinder, "CutoutCylinder"},
0073      {VolumeBounds::BoundsType::eCylinder, "Cylinder"},
0074      {VolumeBounds::BoundsType::eGenericCuboid, "GenericCuboid"},
0075      {VolumeBounds::BoundsType::eTrapezoid, "Trapezoid"}})
0076 
0077 }  // namespace Acts