Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 09:40:22

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Geometry/Extent.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Navigation/InternalNavigation.hpp"
0014 #include "Acts/Navigation/NavigationDelegates.hpp"
0015 #include "Acts/Utilities/AxisDefinitions.hpp"
0016 #include "Acts/Utilities/Enumerate.hpp"
0017 #include "Acts/Utilities/Grid.hpp"
0018 #include "Acts/Utilities/GridAxisGenerators.hpp"
0019 #include "Acts/Utilities/Logger.hpp"
0020 #include "Acts/Utilities/TypeList.hpp"
0021 #include "ActsPlugins/Json/AlgebraJsonConverter.hpp"
0022 #include "ActsPlugins/Json/DetrayJsonHelper.hpp"
0023 #include "ActsPlugins/Json/GridJsonConverter.hpp"
0024 #include "ActsPlugins/Json/IndexedGridJsonHelper.hpp"
0025 
0026 #include <climits>
0027 #include <vector>
0028 
0029 namespace Acts {
0030 
0031 using namespace GridAxisGenerators;
0032 
0033 namespace IndexedSurfacesJsonConverter {
0034 
0035 /// @brief Convert the single delegate if it is of the type of the reference
0036 ///
0037 /// @note It will do nothing if the type does not match
0038 ///
0039 /// @param jIndexedSurfaces the json object to be filled
0040 /// @param delegate the delegate to be translated
0041 /// @param detray if the detray json format is written
0042 /// @param refInstance is a reference instance of potential type casting
0043 template <typename instance_type>
0044 void convert(nlohmann::json& jIndexedSurfaces,
0045              const Experimental::InternalNavigationDelegate& delegate,
0046              bool detray, [[maybe_unused]] const instance_type& refInstance) {
0047   using GridType =
0048       typename instance_type::template grid_type<std::vector<std::size_t>>;
0049   // Defining a Delegate type
0050   using DelegateType = Experimental::IndexedSurfacesAllPortalsNavigation<
0051       GridType, Experimental::IndexedSurfacesNavigation>;
0052   using SubDelegateType = Experimental::IndexedSurfacesNavigation<GridType>;
0053 
0054   // Get the instance
0055   const auto* instance = delegate.instance();
0056   auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
0057   if (castedDelegate != nullptr) {
0058     // Get the surface updator
0059     auto indexedSurfaces = std::get<SubDelegateType>(castedDelegate->updators);
0060     jIndexedSurfaces = IndexedGridJsonHelper::convertImpl<SubDelegateType>(
0061         indexedSurfaces, detray, detray);
0062     if (detray) {
0063       nlohmann::json jAccLink;
0064       jAccLink["type"] =
0065           DetrayJsonHelper::accelerationLink(indexedSurfaces.casts);
0066       jAccLink["index"] = std::numeric_limits<std::size_t>::max();
0067       jIndexedSurfaces["grid_link"] = jAccLink;
0068     }
0069   }
0070 }
0071 
0072 /// @brief Unrolling function for catching the right instance
0073 ///
0074 /// @param jIndexedSurfaces the json object to be filled
0075 /// @param delegate the delegate to be translated
0076 /// @param detray if the detray json format is written
0077 template <typename... Args>
0078 void unrollConvert(nlohmann::json& jIndexedSurfaces,
0079                    const Experimental::InternalNavigationDelegate& delegate,
0080                    bool detray, TypeList<Args...> /*unused*/) {
0081   (convert(jIndexedSurfaces, delegate, detray, Args{}), ...);
0082 }
0083 
0084 /// Convert a surface updator
0085 ///
0086 /// @param delegate the delegate to be translated
0087 /// @param detray if the detray json format is written
0088 ///
0089 /// @note this is the entry point of the conversion, i.e. top of the
0090 /// unrolling loop
0091 ///
0092 /// @return a json object representing the surface updator
0093 static inline nlohmann::json toJson(
0094     const Experimental::InternalNavigationDelegate& delegate,
0095     bool detray = false) {
0096   // Convert if dynamic cast happens to work
0097   nlohmann::json jIndexedSurfaces;
0098   unrollConvert(jIndexedSurfaces, delegate, detray,
0099                 GridAxisGenerators::PossibleAxes{});
0100   // Return the newly filled ones
0101   if (!jIndexedSurfaces.is_null()) {
0102     jIndexedSurfaces["type"] = "IndexedSurfaces";
0103   }
0104   return jIndexedSurfaces;
0105 }
0106 
0107 /// @brief Convert the single delegate if it is of the type of the reference
0108 ///
0109 /// @param jSurfaceNavigation the json file to read from
0110 ///
0111 /// @return the surface navigation delegate
0112 Experimental::InternalNavigationDelegate fromJson(
0113     const nlohmann::json& jSurfaceNavigation);
0114 
0115 }  // namespace IndexedSurfacesJsonConverter
0116 }  // namespace Acts