Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:42

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022-2023 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 http://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 "Acts/Plugins/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 void to_json(nlohmann::json& j, const VolumeBounds& bounds);
0029 
0030 namespace VolumeBoundsJsonConverter {
0031 
0032 /// Conversion to Json from volume bounds
0033 ///
0034 /// @param bounds is the bounds object
0035 ///
0036 /// @return the json object
0037 nlohmann::json toJson(const VolumeBounds& bounds);
0038 
0039 /// Conversion to volume bounds from json
0040 ///
0041 /// The type is given as a template argument in order to be able
0042 /// to construct the correct fitting types for surfaces.
0043 ///
0044 /// @param jVolumeBounds the read-in json object
0045 ///
0046 /// @return a unique_ptr to a volume bounds object for type polymorphism
0047 template <typename bounds_t>
0048 std::unique_ptr<bounds_t> fromJson(const nlohmann::json& jVolumeBounds) {
0049   constexpr std::size_t kValues = bounds_t::BoundValues::eSize;
0050   std::array<ActsScalar, kValues> bValues{};
0051   std::vector<ActsScalar> bVector = jVolumeBounds["values"];
0052   std::copy_n(bVector.begin(), kValues, bValues.begin());
0053   return std::make_unique<bounds_t>(bValues);
0054 }
0055 
0056 /// Conversion to volume bounds from json
0057 /// @param jVolumeBounds the read-in json object
0058 ///
0059 /// @return a unique_ptr to a volume bounds object for type polymorphism
0060 std::unique_ptr<VolumeBounds> fromJson(const nlohmann::json& jVolumeBounds);
0061 
0062 }  // namespace VolumeBoundsJsonConverter
0063 
0064 // This macro creates a conversion for the volume bounds type
0065 NLOHMANN_JSON_SERIALIZE_ENUM(
0066     VolumeBounds::BoundsType,
0067     {{VolumeBounds::BoundsType::eCone, "Cone"},
0068      {VolumeBounds::BoundsType::eCuboid, "Cuboid"},
0069      {VolumeBounds::BoundsType::eCutoutCylinder, "CutoutCylinder"},
0070      {VolumeBounds::BoundsType::eCylinder, "Cylinder"},
0071      {VolumeBounds::BoundsType::eGenericCuboid, "GenericCuboid"},
0072      {VolumeBounds::BoundsType::eTrapezoid, "Trapezoid"}})
0073 
0074 }  // namespace Acts