Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IndexedSurfacesJsonConverter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file IndexedSurfacesJsonConverter.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 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 
13 #include "Acts/Geometry/Extent.hpp"
23 
24 #include <tuple>
25 #include <vector>
26 
27 namespace Acts {
28 
29 using namespace Experimental::detail::GridAxisGenerators;
30 
31 namespace IndexedSurfacesJsonConverter {
32 
33 // Generate the possible axes in this case
34 static auto s_possibleAxes =
35  std::tuple<EqBound, EqOpen, EqClosed,
36  // All 1D Var options
38  // All 2D EqEq options
42  // All 2D EqVar options
46  // All 2D VarEq options
50  // All 2D VarEq options
54 
56 template <typename index_grid>
57 nlohmann::json convertImpl(const index_grid& indexGrid) {
58  nlohmann::json jIndexedSurfaces;
59 
60  // Fill the casts
61  nlohmann::json jCasts;
62  // 1D casts
63  if constexpr (index_grid::grid_type::DIM == 1u) {
64  jCasts.push_back(indexGrid.casts[0u]);
65  }
66  // 1D casts
67  if constexpr (index_grid::grid_type::DIM == 2u) {
68  jCasts.push_back(indexGrid.casts[0u]);
69  jCasts.push_back(indexGrid.casts[1u]);
70  }
71  jIndexedSurfaces["casts"] = jCasts;
72  jIndexedSurfaces["transform"] =
73  Transform3JsonConverter::toJson(indexGrid.transform);
74  jIndexedSurfaces["grid"] = GridJsonConverter::toJson(indexGrid.grid);
75  return jIndexedSurfaces;
76 }
77 
85 template <typename instance_type>
86 void convert(nlohmann::json& jIndexedSurfaces,
88  [[maybe_unused]] const instance_type& refInstance) {
89  using GridType =
90  typename instance_type::template grid_type<std::vector<std::size_t>>;
91  // Defining a Delegate type
94  using SubDelegateType = Experimental::IndexedSurfacesImpl<GridType>;
95 
96  // Get the instance
97  const auto* instance = delegate.instance();
98  auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
99  if (castedDelegate != nullptr) {
100  // Get the surface updator
101  auto indexedSurfaces = std::get<SubDelegateType>(castedDelegate->updators);
102  jIndexedSurfaces = convertImpl<SubDelegateType>(indexedSurfaces);
103  }
104 }
105 
113 template <typename tuple_type, std::size_t... I>
114 void unrollConvert(nlohmann::json& jIndexedSurfaces,
116  const tuple_type& axesTuple,
117  std::index_sequence<I...> /*unused*/) {
118  (convert(jIndexedSurfaces, delegate, std::get<I>(axesTuple)), ...);
119 }
120 
129 static inline nlohmann::json toJson(
130  const Experimental::SurfaceCandidatesUpdator& delegate) {
131  // Convert if dynamic cast happens to work
132  nlohmann::json jIndexedSurfaces;
133  unrollConvert(jIndexedSurfaces, delegate, s_possibleAxes,
134  std::make_index_sequence<
135  std::tuple_size<decltype(s_possibleAxes)>::value>());
136  // Return the newly filled ones
137  jIndexedSurfaces["type"] = "IndexedSurfaces";
138  return jIndexedSurfaces;
139 }
140 
147  const nlohmann::json& jSurfaceNavigation);
148 
149 } // namespace IndexedSurfacesJsonConverter
150 } // namespace Acts