Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding possibility to read flat surface container #3668

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ struct Options {
/// @param options specifies which file and what to read
///
/// @return a vector of surfaces
Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>> read(
Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>> readHierarchyMap(
const Options& options);

/// @brief Read the flat surfaces from the input file
///
/// @param inputFile is the input file to read from
///
/// @return a vector of surfaces
std::vector<std::shared_ptr<Acts::Surface>> readVector(const Options& options);

} // namespace ActsExamples::JsonSurfacesReader
25 changes: 24 additions & 1 deletion Examples/Io/Json/src/JsonSurfacesReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
namespace ActsExamples {

Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>>
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);
Expand Down Expand Up @@ -50,4 +51,26 @@ JsonSurfacesReader::read(const JsonSurfacesReader::Options& options) {
return SurfaceHierachyMap(std::move(surfaceElements));
}

std::vector<std::shared_ptr<Acts::Surface>> JsonSurfacesReader::readVector(
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<std::shared_ptr<Acts::Surface>> surfaces;
for (const auto& jSurface : jSurfaces) {
auto surface = Acts::SurfaceJsonConverter::fromJson(jSurface);
surfaces.push_back(surface);
}
return surfaces;
}

} // namespace ActsExamples
6 changes: 5 additions & 1 deletion Examples/Python/src/Json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::readHierarchyMap);

mex.def("readSurfaceVectorFromJson",
ActsExamples::JsonSurfacesReader::readVector);
}

{
Expand Down
Loading