Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:18

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 #include "Acts/Plugins/Json/IndexedSurfacesJsonConverter.hpp"
0010 
0011 #include "Acts/Navigation/NavigationStateUpdaters.hpp"
0012 #include "Acts/Plugins/Json/GridJsonConverter.hpp"
0013 #include "Acts/Plugins/Json/IndexedGridJsonHelper.hpp"
0014 #include "Acts/Plugins/Json/UtilitiesJsonConverter.hpp"
0015 #include "Acts/Utilities/GridAxisGenerators.hpp"
0016 
0017 #include <array>
0018 #include <memory>
0019 #include <tuple>
0020 #include <vector>
0021 
0022 namespace {
0023 
0024 /// @brief  The generator struct
0025 struct IndexedSurfacesGenerator {
0026   using value_type = std::vector<std::size_t>;
0027 
0028   /// @brief  Helper function to create and connect the IndexedSurfacesImpl
0029   ///
0030   /// @tparam grid_type the type of the grid, indicates also the dimension
0031   ///
0032   /// @param grid the grid object
0033   /// @param bv the bin value array
0034   /// @param transform the transform for the indexed surfaces inmplementaiton
0035   ///
0036   /// @return a connected SurfaceCandidatesUpdater object
0037   template <typename grid_type>
0038   Acts::Experimental::SurfaceCandidatesUpdater createUpdater(
0039       grid_type&& grid,
0040       const std::array<Acts::BinningValue, grid_type::DIM>& bv,
0041       const Acts::Transform3& transform) {
0042     Acts::Experimental::IndexedSurfacesImpl<grid_type> indexedSurfaces(
0043         std::move(grid), bv, transform);
0044 
0045     // The portal delegate
0046     Acts::Experimental::AllPortalsImpl allPortals;
0047 
0048     // The chained delegate: indexed surfaces and all portals
0049     using DelegateType = Acts::Experimental::IndexedSurfacesAllPortalsImpl<
0050         grid_type, Acts::Experimental::IndexedSurfacesImpl>;
0051     auto indexedSurfacesAllPortals = std::make_unique<const DelegateType>(
0052         std::tie(allPortals, indexedSurfaces));
0053 
0054     // Create the delegate and connect it
0055     Acts::Experimental::SurfaceCandidatesUpdater nStateUpdater;
0056     nStateUpdater.connect<&DelegateType::update>(
0057         std::move(indexedSurfacesAllPortals));
0058 
0059     return nStateUpdater;
0060   }
0061 };
0062 
0063 }  // namespace
0064 
0065 Acts::Experimental::SurfaceCandidatesUpdater
0066 Acts::IndexedSurfacesJsonConverter::fromJson(
0067     const nlohmann::json& jSurfaceNavigation) {
0068   if (!jSurfaceNavigation.is_null()) {
0069     // The return object
0070     auto sfCandidates = IndexedGridJsonHelper::generateFromJson<
0071         Experimental::SurfaceCandidatesUpdater, IndexedSurfacesGenerator>(
0072         jSurfaceNavigation, "IndexedSurfaces");
0073     if (sfCandidates.connected()) {
0074       return sfCandidates;
0075     }
0076   }
0077   // Return the object
0078   return Experimental::tryAllPortalsAndSurfaces();
0079 }