Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:49

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 "ActsExamples/Io/Json/JsonSurfacesReader.hpp"
0010 
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "Acts/Plugins/Json/ActsJson.hpp"
0013 #include "Acts/Plugins/Json/GeometryHierarchyMapJsonConverter.hpp"
0014 #include "Acts/Plugins/Json/SurfaceJsonConverter.hpp"
0015 #include "Acts/Surfaces/Surface.hpp"
0016 
0017 #include <fstream>
0018 #include <iostream>
0019 
0020 namespace ActsExamples {
0021 
0022 Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>>
0023 JsonSurfacesReader::read(const JsonSurfacesReader::Options& options) {
0024   // Read the json file into a json object
0025   nlohmann::json j;
0026   std::ifstream in(options.inputFile);
0027   in >> j;
0028   in.close();
0029 
0030   using SurfaceHierachyMap =
0031       Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>>;
0032   using GeometryIdHelper = Acts::GeometryHierarchyMapJsonConverter<bool>;
0033   std::vector<SurfaceHierachyMap::InputElement> surfaceElements;
0034 
0035   // Walk down the path to the surface entries
0036   nlohmann::json jSurfaces = j;
0037   for (const auto& jep : options.jsonEntryPath) {
0038     jSurfaces = jSurfaces[jep];
0039   }
0040 
0041   // Loop over the surfaces
0042   surfaceElements.reserve(jSurfaces.size());
0043   for (const auto& jSurface : jSurfaces) {
0044     // Decode the surface identifier
0045     Acts::GeometryIdentifier geoId =
0046         GeometryIdHelper::decodeIdentifier(jSurface);
0047     auto surface = Acts::SurfaceJsonConverter::fromJson(jSurface["value"]);
0048     surfaceElements.emplace_back(geoId, surface);
0049   }
0050   return SurfaceHierachyMap(std::move(surfaceElements));
0051 }
0052 
0053 }  // namespace ActsExamples