File indexing completed on 2025-01-30 09:15:17
0001
0002
0003
0004
0005
0006
0007
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/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 Acts {
0021
0022 Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>>
0023 JsonSurfacesReader::readHierarchyMap(
0024 const JsonSurfacesReader::Options& options) {
0025
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 using GeometryIdHelper = Acts::GeometryHierarchyMapJsonConverter<bool>;
0034 std::vector<SurfaceHierachyMap::InputElement> surfaceElements;
0035
0036
0037 nlohmann::json jSurfaces = j;
0038 for (const auto& jep : options.jsonEntryPath) {
0039 jSurfaces = jSurfaces[jep];
0040 }
0041
0042
0043 surfaceElements.reserve(jSurfaces.size());
0044 for (const auto& jSurface : jSurfaces) {
0045
0046 Acts::GeometryIdentifier geoId =
0047 GeometryIdHelper::decodeIdentifier(jSurface);
0048 auto surface = Acts::SurfaceJsonConverter::fromJson(jSurface["value"]);
0049 surfaceElements.emplace_back(geoId, surface);
0050 }
0051 return SurfaceHierachyMap(std::move(surfaceElements));
0052 }
0053
0054 std::vector<std::shared_ptr<Acts::Surface>> JsonSurfacesReader::readVector(
0055 const Options& options) {
0056
0057 nlohmann::json j;
0058 std::ifstream in(options.inputFile);
0059 in >> j;
0060 in.close();
0061
0062
0063 nlohmann::json jSurfaces = j;
0064 for (const auto& jep : options.jsonEntryPath) {
0065 jSurfaces = jSurfaces[jep];
0066 }
0067
0068 std::vector<std::shared_ptr<Acts::Surface>> surfaces;
0069 for (const auto& jSurface : jSurfaces) {
0070 auto surface = Acts::SurfaceJsonConverter::fromJson(jSurface);
0071 surfaces.push_back(surface);
0072 }
0073 return surfaces;
0074 }
0075
0076 std::vector<std::shared_ptr<Acts::JsonDetectorElement>>
0077 JsonSurfacesReader::readDetectorElements(const Options& options,
0078 double thickness = 0.0) {
0079 nlohmann::json j;
0080 {
0081 std::ifstream in(options.inputFile);
0082 in >> j;
0083 }
0084
0085
0086 nlohmann::json jSurfaces = j;
0087 for (const auto& jep : options.jsonEntryPath) {
0088 jSurfaces = jSurfaces[jep];
0089 }
0090
0091 std::vector<std::shared_ptr<Acts::JsonDetectorElement>> elements;
0092 for (const auto& jSurface : jSurfaces) {
0093 elements.emplace_back(
0094 std::make_shared<Acts::JsonDetectorElement>(jSurface, thickness));
0095 }
0096 return elements;
0097 }
0098
0099 }