Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:13:39

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 #include "Acts/Plugins/Json/JsonSurfacesReader.hpp"
0010 
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "Acts/Plugins/Json/ActsJson.hpp"
0013 #include "Acts/Plugins/Json/GeometryIdentifierJsonConverter.hpp"
0014 #include "Acts/Plugins/Json/SurfaceJsonConverter.hpp"
0015 #include "Acts/Surfaces/Surface.hpp"
0016 
0017 #include <fstream>
0018 #include <iostream>
0019 
0020 namespace Acts {
0021 
0022 Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>>
0023 JsonSurfacesReader::readHierarchyMap(
0024     const JsonSurfacesReader::Options& options) {
0025   // Read the json file into a json object
0026   nlohmann::json j;
0027   std::ifstream in(options.inputFile);
0028   in >> j;
0029   in.close();
0030 
0031   using SurfaceHierachyMap =
0032       Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>>;
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     GeometryIdentifier geoId =
0046         GeometryIdentifierJsonConverter::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 std::vector<std::shared_ptr<Acts::Surface>> JsonSurfacesReader::readVector(
0054     const Options& options) {
0055   // Read the json file into a json object
0056   nlohmann::json j;
0057   std::ifstream in(options.inputFile);
0058   in >> j;
0059   in.close();
0060 
0061   // Walk down the path to the surface entries
0062   nlohmann::json jSurfaces = j;
0063   for (const auto& jep : options.jsonEntryPath) {
0064     jSurfaces = jSurfaces[jep];
0065   }
0066 
0067   std::vector<std::shared_ptr<Acts::Surface>> surfaces;
0068   for (const auto& jSurface : jSurfaces) {
0069     auto surface = Acts::SurfaceJsonConverter::fromJson(jSurface);
0070     surfaces.push_back(surface);
0071   }
0072   return surfaces;
0073 }
0074 
0075 std::vector<std::shared_ptr<Acts::JsonDetectorElement>>
0076 JsonSurfacesReader::readDetectorElements(const Options& options,
0077                                          double thickness = 0.0) {
0078   nlohmann::json j;
0079   {
0080     std::ifstream in(options.inputFile);
0081     in >> j;
0082   }
0083 
0084   // Walk down the path to the surface entries
0085   nlohmann::json jSurfaces = j;
0086   for (const auto& jep : options.jsonEntryPath) {
0087     jSurfaces = jSurfaces[jep];
0088   }
0089 
0090   std::vector<std::shared_ptr<Acts::JsonDetectorElement>> elements;
0091   for (const auto& jSurface : jSurfaces) {
0092     elements.emplace_back(
0093         std::make_shared<Acts::JsonDetectorElement>(jSurface, thickness));
0094   }
0095   return elements;
0096 }
0097 
0098 }  // namespace Acts