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
Simplify data export/import process #210
Conversation
- Add ImportData as a single struct to be saved to the ROOT file for easier readability. - RootImporter not yet updated. At the end, it will - Only load ImportData into memory. - Param classes might have a from_import(ImportData& data) or similar function that will construct the loaded data. Another option is to create helper classes to construct the Params ptrs.
- Clean up RootImporter - Fix RootImporter.noroot - Add TEST_IF_CELERITAS_USE_ROOT macro in gtest/detail/Macros.hh for enabling/disabling from_import() tests in all classes that have this functionality - Update RootImporter test to read the new ROOT file
- RootImporter::operator() now needs the tree and branch names to read the ROOT file. This provides the flexibility to users to write the file as they please - Refactor geant-exporter functions/classes to better match their purposes - Improve documentation
- Extend, update, or improve doxygen documentation in a set of files - Rename slabsGeometry.gdml to four-steel-slabs.gdml to avoid confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! This is on the right track and probably 95% to the goal. The RootImporter
operator is a little funky, and some of the from_import
methods need to be handed existing "pre-converted" data structures rather than rebuilding them.
Now that Two points of discussion are:
|
I'd like the "import" layer to be as simple as possible, so we move the data as quickly as possible into our more feature-rich Params classes, which offers the finding/mapping functionality we need. It could make sense to have an extra mapping layer at the import layer if we were filtering out data at problem setup time, but at this point it looks like our import layer will always be loading all of the data because it's so interconnected. Any extra useful mapping functionality should be added to the Params classes or a helper function/class that uses multiple params classes. I don't think that removing the GdmlMap would make construction more complicated—the data is stored as vectors and we need it as vectors, so there shouldn't be much mapping involved. |
It mostly does not, so I have removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, Stefano, thanks for the updates. Regarding the helper functions: are they used anywhere? I don't think we should ever need to "search" through the import data (especially since the search criterion is just the index of an element/material in its vector), and as I commented there I think the new element/material ID accessors are redundant in the context of loading an entire ImportFile.
geant-exporter: - Each ImportData member has its own store function for easier code maintenance. - Vectors for element, material, and volume are resized according to the number of entities and each enttity is stored at position EntityID() in the vector. This makes sure that the entity's position always matches its id. geant-exporter-cat: - Each ImportData member has its own print function for easier code maintenance.
Sorry for not waiting on another PR to address some new improvements, but they fit in the current scope. After we moved from a "geometry" idea (
Currently geant-exporter-cat print functions still rely on a mixed bag of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great aside from one final scaling issue in the geant exporter that I'd like to have addressed... sorry!
- Add assertion before storing a material in geant-exporter::store_materials() - Improve code documentation - Remove ImportProcessConverter::remove_empty() function in favor of a much simpler solution: use operator bool to check if ImportProcess is not empty before adding it to the vector<ImportProcess>
I've added a much simpler (and kinda obvious) solution regarding the empty We simply use
|
@stognini great idea! One final gotcha there though is the distinction between copy and move. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a bunch, @stognini !
This PR updates the Geant4 data export/import to a simpler mechanism:
ImportData
.ImportData
, all other import classes used by geant-exporter were moved toio/detail
.ImportData
into a single TTree entry, vastly simplifying both writing and reading processes.RootImporter::operator()("tree_name", "branch_name")
returns theImportData
object stored in the ROOT file. It now takes the names of the tree and branch as input parameters to avoid any hardcoded string name.from_import(ImportData& data)
function that returns a constructedshared_ptr
.test/gtest/detail/Macros.hh
now includesTEST_IF_CELERITAS_USE_ROOT
. This allows disabling individual tests accordingly and is currently used to enable/disable allfrom_import(...)
tests added to the host/device classes.Example code on how the data is now imported into Celeritas: