Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VolumeBoundsJsonConverter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VolumeBoundsJsonConverter.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022-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 
15 
16 #include <array>
17 #include <cstddef>
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include <nlohmann/json.hpp>
23 
24 // Custom Json encoder/decoders. Naming is mandated by nlohmann::json and thus
25 // can not match our naming guidelines.
26 namespace Acts {
27 
28 class VolumeBounds;
29 
30 void to_json(nlohmann::json& j, const VolumeBounds& bounds);
31 
32 namespace VolumeBoundsJsonConverter {
33 
39 nlohmann::json toJson(const VolumeBounds& bounds);
40 
49 template <typename bounds_t>
50 std::unique_ptr<bounds_t> fromJson(const nlohmann::json& jVolumeBounds) {
51  constexpr size_t kValues = bounds_t::BoundValues::eSize;
52  std::array<ActsScalar, kValues> bValues{};
53  std::vector<ActsScalar> bVector = jVolumeBounds["values"];
54  std::copy_n(bVector.begin(), kValues, bValues.begin());
55  return std::make_unique<bounds_t>(bValues);
56 }
57 
62 std::unique_ptr<VolumeBounds> fromJson(const nlohmann::json& jVolumeBounds);
63 
64 } // namespace VolumeBoundsJsonConverter
65 
66 // This macro creates a conversion for the volume bounds type
67 NLOHMANN_JSON_SERIALIZE_ENUM(
69  {{VolumeBounds::BoundsType::eCone, "Cone"},
70  {VolumeBounds::BoundsType::eCuboid, "Cuboid"},
71  {VolumeBounds::BoundsType::eCutoutCylinder, "CutoutCylinder"},
72  {VolumeBounds::BoundsType::eCylinder, "Cylinder"},
73  {VolumeBounds::BoundsType::eGenericCuboid, "GenericCuboid"},
74  {VolumeBounds::BoundsType::eTrapezoid, "Trapezoid"}})
75 
76 } // namespace Acts