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/Surfaces/SurfaceBounds.hpp"
0013 #include "ActsPlugins/Json/ActsJson.hpp"
0014 
0015 #include <array>
0016 #include <cstddef>
0017 #include <memory>
0018 #include <string>
0019 #include <vector>
0020 
0021 #include <nlohmann/json.hpp>
0022 
0023 // Custom Json encoder/decoders.
0024 namespace Acts {
0025 class SurfaceBounds;
0026 
0027 /// Convert SurfaceBounds to JSON
0028 /// @param j Destination JSON object
0029 /// @param bounds Source SurfaceBounds to convert
0030 void to_json(nlohmann::json& j, const SurfaceBounds& bounds);
0031 
0032 namespace SurfaceBoundsJsonConverter {
0033 
0034 /// Interface with detray conversion option
0035 /// @param bounds is the bounds object
0036 /// @return the json object
0037 nlohmann::json toJson(const SurfaceBounds& bounds);
0038 
0039 /// Interface with detray conversion option
0040 /// @param bounds is the bounds object
0041 /// @param portal is the flag for conversion into detray portal format
0042 ///
0043 /// @note reading back detray json format to Acts is not supported
0044 ///
0045 /// @return the json object
0046 nlohmann::json toJsonDetray(const SurfaceBounds& bounds, bool portal = false);
0047 
0048 /// Conversion to surfaceBounds from json
0049 ///
0050 /// The type is given as a template argument in order to be able
0051 /// to construct the correct fitting types for surfaces.
0052 ///
0053 /// @param j the read-in json object
0054 ///
0055 /// @return a shared_ptr to a surface object for type polymorphism
0056 template <typename bounds_t>
0057 std::shared_ptr<const bounds_t> fromJson(const nlohmann::json& j) {
0058   const std::size_t kValues = bounds_t::BoundValues::eSize;
0059   std::array<double, kValues> bValues{};
0060   std::vector<double> bVector = j["values"];
0061   std::copy_n(bVector.begin(), kValues, bValues.begin());
0062   return std::make_shared<const bounds_t>(bValues);
0063 }
0064 
0065 }  // namespace SurfaceBoundsJsonConverter
0066 
0067 // This macro create a conversion for the surface bounds type
0068 NLOHMANN_JSON_SERIALIZE_ENUM(
0069     SurfaceBounds::BoundsType,
0070     {{SurfaceBounds::BoundsType::eCone, "ConeBounds"},
0071      {SurfaceBounds::BoundsType::eCylinder, "CylinderBounds"},
0072      {SurfaceBounds::BoundsType::eDiamond, "DiamondBounds"},
0073      {SurfaceBounds::BoundsType::eDisc, "RadialBounds"},
0074      {SurfaceBounds::BoundsType::eEllipse, "EllipseBounds"},
0075      {SurfaceBounds::BoundsType::eLine, "LineBounds"},
0076      {SurfaceBounds::BoundsType::eRectangle, "RectangleBounds"},
0077      {SurfaceBounds::BoundsType::eTrapezoid, "TrapezoidBounds"},
0078      {SurfaceBounds::BoundsType::eTriangle, "TriangleBounds"},
0079      {SurfaceBounds::BoundsType::eDiscTrapezoid, "DiscTrapezoidBounds"},
0080      {SurfaceBounds::BoundsType::eConvexPolygon, "ConvexPolygonBounds"},
0081      {SurfaceBounds::BoundsType::eAnnulus, "AnnulusBounds"},
0082      {SurfaceBounds::BoundsType::eBoundless, "Boundless"},
0083      {SurfaceBounds::BoundsType::eOther, "OtherBounds"}})
0084 
0085 }  // namespace Acts