Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceBoundsJsonConverter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SurfaceBoundsJsonConverter.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021-2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
14 
15 #include <array>
16 #include <cstddef>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 #include <nlohmann/json.hpp>
22 
23 // Custom Json encoder/decoders.
24 namespace Acts {
25 class SurfaceBounds;
26 
27 void to_json(nlohmann::json& j, const SurfaceBounds& bounds);
28 
29 namespace SurfaceBoundsJsonConverter {
30 
34 nlohmann::json toJson(const SurfaceBounds& bounds);
35 
43 nlohmann::json toJsonDetray(const SurfaceBounds& bounds, bool portal = false);
44 
53 template <typename bounds_t>
54 std::shared_ptr<const bounds_t> fromJson(const nlohmann::json& j) {
55  const size_t kValues = bounds_t::BoundValues::eSize;
56  std::array<ActsScalar, kValues> bValues{};
57  std::vector<ActsScalar> bVector = j["values"];
58  std::copy_n(bVector.begin(), kValues, bValues.begin());
59  return std::make_shared<const bounds_t>(bValues);
60 }
61 
62 } // namespace SurfaceBoundsJsonConverter
63 
64 // This macro create a conversion for the surface bounds type
65 NLOHMANN_JSON_SERIALIZE_ENUM(
67  {{SurfaceBounds::BoundsType::eCone, "ConeBounds"},
68  {SurfaceBounds::BoundsType::eCylinder, "CylinderBounds"},
69  {SurfaceBounds::BoundsType::eDiamond, "DiamondBounds"},
70  {SurfaceBounds::BoundsType::eDisc, "RadialBounds"},
71  {SurfaceBounds::BoundsType::eEllipse, "EllipseBounds"},
72  {SurfaceBounds::BoundsType::eLine, "LineBounds"},
73  {SurfaceBounds::BoundsType::eRectangle, "RectangleBounds"},
74  {SurfaceBounds::BoundsType::eTrapezoid, "TrapezoidBounds"},
75  {SurfaceBounds::BoundsType::eTriangle, "TriangleBounds"},
76  {SurfaceBounds::BoundsType::eDiscTrapezoid, "DiscTrapezoidBounds"},
77  {SurfaceBounds::BoundsType::eConvexPolygon, "ConvexPolygonBounds"},
78  {SurfaceBounds::BoundsType::eAnnulus, "AnnulusBounds"},
79  {SurfaceBounds::BoundsType::eBoundless, "Boundless"},
80  {SurfaceBounds::BoundsType::eOther, "OtherBounds"}})
81 
82 } // namespace Acts