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