Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:42

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