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 2 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 @@ -36,4 +36,12 @@ struct Options {
Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>> read(
const Options& options);

/// @brief Read the sflat surfaces urfaces from the input file
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
///
/// @param inputFile is the input file to read from
///
/// @return a vector of surfaces
std::vector<std::shared_ptr<Acts::Surface>> readSurfaces(
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
const Options& options);

} // namespace ActsExamples::JsonSurfacesReader
22 changes: 22 additions & 0 deletions Examples/Io/Json/src/JsonSurfacesReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,26 @@ JsonSurfacesReader::read(const JsonSurfacesReader::Options& options) {
return SurfaceHierachyMap(std::move(surfaceElements));
}

std::vector<std::shared_ptr<Acts::Surface>> 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<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::read);

mex.def("readSurfacesFromJson",
ActsExamples::JsonSurfacesReader::readSurfaces);
}

{
Expand Down
Loading