Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VolumeBoundsJsonConverter.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VolumeBoundsJsonConverter.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 
10 
18 
19 #include <algorithm>
20 #include <stdexcept>
21 
22 void Acts::to_json(nlohmann::json& j, const VolumeBounds& bounds) {
23  j["type"] = bounds.type();
24  j["values"] = bounds.values();
25 }
26 
28  const VolumeBounds& bounds) {
29  return nlohmann::json(bounds);
30 }
31 
32 std::unique_ptr<Acts::VolumeBounds> Acts::VolumeBoundsJsonConverter::fromJson(
33  const nlohmann::json& jVolumeBounds) {
34  const auto type = jVolumeBounds["type"].get<VolumeBounds::BoundsType>();
35 
36  switch (type) {
37  case VolumeBounds::BoundsType::eCone: {
38  return fromJson<ConeVolumeBounds>(jVolumeBounds);
39  } break;
40  case VolumeBounds::BoundsType::eCuboid: {
41  return fromJson<CuboidVolumeBounds>(jVolumeBounds);
42  } break;
43  case VolumeBounds::BoundsType::eCutoutCylinder: {
44  return fromJson<CutoutCylinderVolumeBounds>(jVolumeBounds);
45  } break;
46  case VolumeBounds::BoundsType::eCylinder: {
47  return fromJson<CylinderVolumeBounds>(jVolumeBounds);
48  } break;
49  case VolumeBounds::BoundsType::eTrapezoid: {
50  return fromJson<TrapezoidVolumeBounds>(jVolumeBounds);
51  } break;
52  case VolumeBounds::BoundsType::eGenericCuboid: {
53  return fromJson<GenericCuboidVolumeBounds>(jVolumeBounds);
54  } break;
55  default: {
56  throw std::invalid_argument("Unknown volume bounds type!");
57  }
58  }
59  return nullptr;
60 } // namespace Acts