From 1711e5cc634118cddfd153e1ef7bcfb9a24d9ce8 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Mon, 30 Sep 2024 17:37:04 +0200 Subject: [PATCH 1/3] adding possibility to read flat surface container --- .../Io/Json/JsonSurfacesReader.hpp | 8 +++++++ Examples/Io/Json/src/JsonSurfacesReader.cpp | 22 +++++++++++++++++++ Examples/Python/src/Json.cpp | 6 ++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp index fcd16b97a8e..7eca8979726 100644 --- a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp +++ b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp @@ -36,4 +36,12 @@ struct Options { Acts::GeometryHierarchyMap> read( const Options& options); +/// @brief Read the sflat surfaces urfaces from the input file +/// +/// @param inputFile is the input file to read from +/// +/// @return a vector of surfaces +std::vector> readSurfaces( + const Options& options); + } // namespace ActsExamples::JsonSurfacesReader diff --git a/Examples/Io/Json/src/JsonSurfacesReader.cpp b/Examples/Io/Json/src/JsonSurfacesReader.cpp index fdc80f5c144..655c8f06797 100644 --- a/Examples/Io/Json/src/JsonSurfacesReader.cpp +++ b/Examples/Io/Json/src/JsonSurfacesReader.cpp @@ -50,4 +50,26 @@ JsonSurfacesReader::read(const JsonSurfacesReader::Options& options) { return SurfaceHierachyMap(std::move(surfaceElements)); } +std::vector> JsonSurfacesReader::readSurfaces( + const Options& options) { + // Read the json file into a json object + nlohmann::json j; + std::ifstream in(options.inputFile); + in >> j; + in.close(); + + // Walk down the path to the surface entries + nlohmann::json jSurfaces = j; + for (const auto& jep : options.jsonEntryPath) { + jSurfaces = jSurfaces[jep]; + } + + std::vector> surfaces; + for (const auto& jSurface : jSurfaces) { + auto surface = Acts::SurfaceJsonConverter::fromJson(jSurface); + surfaces.push_back(surface); + } + return surfaces; +} + } // namespace ActsExamples diff --git a/Examples/Python/src/Json.cpp b/Examples/Python/src/Json.cpp index fce16c5d558..24b7c352d62 100644 --- a/Examples/Python/src/Json.cpp +++ b/Examples/Python/src/Json.cpp @@ -163,7 +163,11 @@ void addJson(Context& ctx) { ACTS_PYTHON_MEMBER(jsonEntryPath); ACTS_PYTHON_STRUCT_END(); - mex.def("readSurfaceFromJson", ActsExamples::JsonSurfacesReader::read); + mex.def("readSurfaceHierarchyMapFromJson", + ActsExamples::JsonSurfacesReader::read); + + mex.def("readSurfacesFromJson", + ActsExamples::JsonSurfacesReader::readSurfaces); } { From dba07dc8b37a4cb76c21abda32bc8c66d7fc5828 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Mon, 30 Sep 2024 21:34:31 +0200 Subject: [PATCH 2/3] Update Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp Co-authored-by: Alexander J. Pfleger <70842573+AJPfleger@users.noreply.github.com> --- .../Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp index 7eca8979726..f2c0348c005 100644 --- a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp +++ b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp @@ -36,7 +36,7 @@ struct Options { Acts::GeometryHierarchyMap> read( const Options& options); -/// @brief Read the sflat surfaces urfaces from the input file +/// @brief Read the flat surfaces from the input file /// /// @param inputFile is the input file to read from /// From 96f9648c4023931fed872c4eea630c09e396678d Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Mon, 30 Sep 2024 22:10:19 +0200 Subject: [PATCH 3/3] adressing PR comments --- .../include/ActsExamples/Io/Json/JsonSurfacesReader.hpp | 5 ++--- Examples/Io/Json/src/JsonSurfacesReader.cpp | 5 +++-- Examples/Python/src/Json.cpp | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp index f2c0348c005..4df2743e66e 100644 --- a/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp +++ b/Examples/Io/Json/include/ActsExamples/Io/Json/JsonSurfacesReader.hpp @@ -33,7 +33,7 @@ struct Options { /// @param options specifies which file and what to read /// /// @return a vector of surfaces -Acts::GeometryHierarchyMap> read( +Acts::GeometryHierarchyMap> readHierarchyMap( const Options& options); /// @brief Read the flat surfaces from the input file @@ -41,7 +41,6 @@ Acts::GeometryHierarchyMap> read( /// @param inputFile is the input file to read from /// /// @return a vector of surfaces -std::vector> readSurfaces( - const Options& options); +std::vector> readVector(const Options& options); } // namespace ActsExamples::JsonSurfacesReader diff --git a/Examples/Io/Json/src/JsonSurfacesReader.cpp b/Examples/Io/Json/src/JsonSurfacesReader.cpp index 655c8f06797..7c9d14eb520 100644 --- a/Examples/Io/Json/src/JsonSurfacesReader.cpp +++ b/Examples/Io/Json/src/JsonSurfacesReader.cpp @@ -20,7 +20,8 @@ namespace ActsExamples { Acts::GeometryHierarchyMap> -JsonSurfacesReader::read(const JsonSurfacesReader::Options& options) { +JsonSurfacesReader::readHierarchyMap( + const JsonSurfacesReader::Options& options) { // Read the json file into a json object nlohmann::json j; std::ifstream in(options.inputFile); @@ -50,7 +51,7 @@ JsonSurfacesReader::read(const JsonSurfacesReader::Options& options) { return SurfaceHierachyMap(std::move(surfaceElements)); } -std::vector> JsonSurfacesReader::readSurfaces( +std::vector> JsonSurfacesReader::readVector( const Options& options) { // Read the json file into a json object nlohmann::json j; diff --git a/Examples/Python/src/Json.cpp b/Examples/Python/src/Json.cpp index 24b7c352d62..13f9155dde3 100644 --- a/Examples/Python/src/Json.cpp +++ b/Examples/Python/src/Json.cpp @@ -164,10 +164,10 @@ void addJson(Context& ctx) { ACTS_PYTHON_STRUCT_END(); mex.def("readSurfaceHierarchyMapFromJson", - ActsExamples::JsonSurfacesReader::read); + ActsExamples::JsonSurfacesReader::readHierarchyMap); - mex.def("readSurfacesFromJson", - ActsExamples::JsonSurfacesReader::readSurfaces); + mex.def("readSurfaceVectorFromJson", + ActsExamples::JsonSurfacesReader::readVector); } {