-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor nexus writer #331
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
Merged
DanNixon
merged 132 commits into
ISISNeutronMuon:main
from
Modularius:Refactor-Nexus-Writer
Apr 15, 2025
Merged
Changes from 127 commits
Commits
Show all changes
132 commits
Select commit
Hold shift + click to select a range
0c9144d
Added Ext Traits
Modularius 35a3bc3
Use Trait Methods
Modularius 8b1358d
Further Trait Methods
Modularius fa9c2a2
Tidying Up
Modularius 53bc3e6
Moved all control to Trait Methods
Modularius eea77cf
Added Thiserror
Modularius 9cb889b
Completed new error handling
Modularius ec310b9
Log time adjust to origin
Modularius f776e0f
Inputted adjust_nanoseconds_by_origin function
Modularius 5e9e17f
Changed log time units to seconds in floating point
Modularius b758556
Fix append_slice error
Modularius 8bf1d03
Fixed mistake with incomplete frame log times
Modularius 475ff09
Formatting
Modularius 9f788b0
Removed comments and made error name more descriptive
Modularius 2dcb8d1
Merge branch 'main' into Refactor-Nexus-Writer
Modularius b0f28d2
Removed unneeded comment block
Modularius cb99661
Merge branch 'main' into Refactor-Nexus-Writer
Modularius dd8ec61
Added hdf5_writer tests
Modularius b5fa879
Formatting
Modularius f927f5b
Fixed test file name
Modularius 26f60a1
Ammended error types
Modularius 056d287
Merge branch 'main' into Refactor-Nexus-Writer
Modularius b29b503
Now obtains temp file path from std::env::temp_dir()
Modularius 5b50612
treefmt
Modularius 2a1b507
Merge branch 'main' into Refactor-Nexus-Writer
Modularius 1b79232
Created some of the file structure
Modularius bb8dbc7
Add extra interval counter, and struct changes
Modularius 390609c
Moved local path to NexusSettings
Modularius 833042d
Moved flush thread to new file
Modularius 68c91ca
Tracing update
Modularius 8463777
Treefmt
Modularius 2dc8804
Formatting
Modularius cc03e6d
Tidying
Modularius 0a217eb
Changed local_path/temp directory to local_path for backwards compati…
Modularius cf6a73e
Merge branch 'Fine-Grained-Separation-Of-Files-In-Nexus-Writer' into …
Modularius 8ce0ac3
Fixing
Modularius e669a6f
Added constant datasets
Modularius 69fa13f
Newline
Modularius 673a80f
Building up File Structure
Modularius f16a0dc
Added File Structure
Modularius 8fe97e9
Introduce Topics structure
Modularius 2ec6f42
Refactored fb msg handling to new file
Modularius 8dcc202
Refactor new file
Modularius cf227d0
Added comments
Modularius b4b200e
Treefmt
Modularius 05f505e
Documenting NexusConfiguration
Modularius 245ed10
Added hdf files
Modularius 749e226
treefmt
Modularius 6b3a7a9
Restructured files
Modularius 66b08d1
Merge branch 'Route-SELogs-and-RunLogs-correctly' into Refactor-Nexus…
Modularius efb4be9
Merge branch 'Fine-Grained-Separation-Of-Files-In-Nexus-Writer' into …
Modularius 506bda2
Fixed merge mistake
Modularius 46f3171
Restructure
Modularius 8de5351
Merge branch 'main' into Fine-Grained-Separation-Of-Files-In-Nexus-Wr…
Modularius 5c451b1
Fix merge
Modularius e1a1e0d
Merge branch 'Fine-Grained-Separation-Of-Files-In-Nexus-Writer' into …
Modularius efcfe45
Allow Settings to be propagated
Modularius 8723ee5
Modify Message Handling
Modularius 5110f7a
Added set_string_to function
Modularius 93a191e
Made run_messages public
Modularius 51d5d83
Added more message handlers
Modularius 722dafc
Implemented Message Handlers
Modularius 2897cab
treefmt
Modularius 0b77da3
Moved run.rs and run_parameters.rs to folder
Modularius 2f4d4a4
Renamed schematic to nexus_structure
Modularius 40cf233
Renamed nexus to run_engine
Modularius 200aa23
Moved NexusSchematic, NexusGroup, NexusFile, NexusNoFile and NexusFil…
Modularius 0b0837e
Refactored NexusFile and NexusNoFile
Modularius 68010ad
Removed root.rs
Modularius c1bf170
Implement more message handling and simplify parameter extraction
Modularius 8e1875a
Added units handler
Modularius eb0981c
Implemented units.rs
Modularius b164cca
Added strum dependency
Modularius 6268581
Standardised function and method names, and ordering in code
Modularius 06ea89e
Moved nexus_classes into file, and general formatting
Modularius d164f29
Begun Refactoring Span Closures
Modularius ef85518
Removed unnecessary fields from RunParameters
Modularius 3cc191c
Factor out run span initiation
Modularius ea46d61
Formatting
Modularius e473327
Factor out search for valid run methods
Modularius 5527be0
Added some populate group methods
Modularius 2e104e4
Began log handling
Modularius dd9b1a8
Treefmt
Modularius 8e8a8fa
Logs
Modularius c495843
Formatting
Modularius c0b3e59
Added Logdata/Selog functions
Modularius 4738712
Added flatbuffer handle for dataset
Modularius 4656ca3
Refactored Log Structs
Modularius 2bcbc16
Progress on logging
Modularius a9df700
Fixed Log Errors
Modularius 970bac5
Improved Logs
Modularius f60fb7e
Formatting and adding classes
Modularius 1abf114
Found option transpose method
Modularius 7f7e15f
Treefmt
Modularius e23a9a7
flatten otel messages
Modularius 8cda0a8
Periods and Source
Modularius c12527b
Added Flush and Formatting
Modularius 17ffe3b
Added sample and geometry structures
Modularius 34537e1
Flush and close
Modularius 4ce19b4
Edit to Geometry and Formatting
Modularius 7de7f77
Refactoring of files/code
Modularius 4319f6e
Refactored logs in nexus_structure
Modularius 7781905
Refactored logs in nexus
Modularius 2f5ef54
Changed naming of methods
Modularius af89160
Added docstrings
Modularius e174907
Refactor File interface
Modularius a487213
treefmt
Modularius 3a9bdf2
Added close_all method
Modularius 2d1e384
Fixed create/open_rw typo
Modularius 410f92f
Fixed field name typos
Modularius cd2b7e8
Fixed group get_name error
Modularius 65d39c3
Improve error handling
Modularius d41a41a
Formatting
Modularius a5bf9e5
Implemented NexusClass struct
Modularius 4959414
Altered Settings for some nexus_structure
Modularius f8ab189
Readme to explain source
Modularius 19e2084
Simplify Error Names and Handling
Modularius 494bbbd
Made num_new_events more succinct
Modularius 4c71982
Formatting
Modularius 86d882c
Fixed int type mistake
Modularius 83b5a5f
Add warnings on error
Modularius 6bef543
Removed errant error checking
Modularius 240b750
Merge branch 'main' into Refactor-Nexus-Writer
Modularius f6917e4
Adding in further nexus fie;ds and formatting
Modularius db76d78
IDF_version unsigned
Modularius 7c7e660
As last
Modularius b6a7820
Removed obsolete files
Modularius 0822eb8
Fix use spacing style issues
Modularius 76d5f4e
Fix line spacing style issue and remove unused code
Modularius 4861993
Deleted unused file
Modularius 60a8dee
Treefmt
Modularius c72b4de
Error strings more descriptive, and used strum
Modularius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # nexus-writer source code description | ||
|
|
||
| This file explains the nexus-writer source code file structure. | ||
|
|
||
| ## Top-Level Modules | ||
|
|
||
| ### main.rs | ||
|
|
||
| This module operates in a similar way to other components, containing the `clap` Cli structure. | ||
|
|
||
| ### message_handlers.rs | ||
|
|
||
| Consists of functions which bridge the main `main` module and `run_engine`. | ||
|
|
||
| ### flush_to_archive.rs | ||
|
|
||
| Implements | ||
|
|
||
| ### error.rs | ||
|
|
||
| ### run_engine.rs | ||
|
|
||
| Manages the run cache, accepts flatbuffer messages via the `message_handler` module and passes them to the appropriate `run` object. | ||
|
|
||
| ### hdf5_handlers.rs | ||
|
|
||
| Extension Traits for `hdf5` objects. | ||
|
|
||
| ### nexus | ||
|
|
||
| Defines general structs and traits used in the `nexus_structure` module. | ||
|
|
||
| ### nexus_structure | ||
|
|
||
| This is where the nexus file structure is found, files and directories are set out in a way that roughly follows the group structure of the nexus format. | ||
|
|
||
| ## Lower-Level Modules | ||
|
|
||
| ### nexus.rs | ||
|
|
||
| Defines the `NexusSchematic` trait which is implemented by every struct in the `nexus_structure` module. | ||
| This trait standardises the creating and opening of the appropriate fields in nexus files. | ||
|
|
||
| Defines the `NexusMessageHandler<M>` trait which takes a generic `M`. This trait is implemented by structs in `nexus_structure` module which process messages `M`. | ||
|
|
||
| Defines the `NexusGroup<S>` struct which takes a generic `S : NexusSchematic`. This struct is a wrapper around the structs defined in the `nexus_structure` module. | ||
|
|
||
| Note that for every `S : NexusSchematic` which implements `NexusMessageHandler<M>`, `NexusGroup<S>` automatically implements `NexusMessageHandler<M>` and passes `M` to `S`. | ||
|
|
||
| #### file_interface.rs | ||
|
|
||
| This defines a trait which abstracts the hdf5 file functionality. This interface is injected into the Run object. This allows the hdf5 file to be mocked in unit tests. | ||
|
|
||
| #### logs.rs | ||
|
|
||
| This defines the `LogMessage` and `AlarmMessage` traits which are implemented on appropriate types of log message (e.g. flatbuffer logs). | ||
| This trait allows performs tasks such as getting the approprate `type_description` for the message, or writing its time/value to a given `Dataset`. | ||
|
|
||
| #### classes.rs | ||
|
|
||
| Implements the enum `NexusClass` which standardises the adding of attributes specifying the nexus classes of groups. | ||
|
|
||
| #### units.rs | ||
|
|
||
| Implements the enum `NexusUnits` which standardises the adding of attributes specifying physical units. | ||
|
|
||
| ### nexus_structure.rs | ||
|
|
||
| Defines the `Root` struct which is the top level of the nexus format. | ||
|
|
||
| #### entry.rs | ||
|
|
||
| Defines the `Entry` struct which contains most of the fields, and implements `NexusSchematic` for it. | ||
|
|
||
| ##### event_data.rs | ||
|
|
||
| Defines the `EventData` struct, and implements `NexusSchematic` for it. | ||
|
|
||
| ##### runlog.rs | ||
|
|
||
| Defines the `RunLog` struct, and implements `NexusSchematic` for it. | ||
|
|
||
| `RunLog` maintains a `HashMap` of `NexusGroup<Log>` keyed by `String`. | ||
|
|
||
| ##### selog.rs | ||
|
|
||
| Defines the `SELog` struct, and implements `NexusSchematic` for it. | ||
|
|
||
| `RunLog` maintains a `HashMap` of `NexusGroup<ValueLog>` keyed by `String`. | ||
|
|
||
| #### logs | ||
|
|
||
| Defines the `Log`, `ValueLog` and `AlarmLog` structs which are used in `runlog.rs` and `selog.rs`, and implements `NexusSchematic` for them. | ||
|
|
||
| The struct `ValueLog` consists of `Option<Log>` and `Option<AlarmLog>` fields. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| use super::{ | ||
| error::{ConvertResult, NexusHDF5Result}, | ||
| AttributeExt, | ||
| }; | ||
| use crate::run_engine::NexusDateTime; | ||
| use hdf5::{types::VarLenUnicode, Attribute}; | ||
|
|
||
| impl AttributeExt for Attribute { | ||
| #[tracing::instrument(skip_all, level = "trace", err(level = "warn"))] | ||
| fn get_datetime(&self) -> NexusHDF5Result<NexusDateTime> { | ||
| let string: VarLenUnicode = self.read_scalar().err_attribute(self)?; | ||
| string.parse().err_attribute(self) | ||
| } | ||
|
|
||
| #[tracing::instrument(skip_all, level = "trace", err(level = "warn"))] | ||
| fn set_string(&self, value: &str) -> NexusHDF5Result<()> { | ||
| self.write_scalar(&value.parse::<VarLenUnicode>().err_attribute(self)?) | ||
| .err_attribute(self) | ||
| } | ||
|
|
||
| #[tracing::instrument(skip_all, level = "trace", err(level = "warn"))] | ||
| fn get_string(&self) -> NexusHDF5Result<String> { | ||
| Ok(self | ||
| .read_scalar::<VarLenUnicode>() | ||
| .err_attribute(self)? | ||
| .to_string()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| use hdf5::{types::VarLenUnicode, Attribute, Dataset, H5Type}; | ||
| use ndarray::s; | ||
|
|
||
| use crate::run_engine::NexusDateTime; | ||
|
|
||
| use super::{ | ||
| error::{ConvertResult, NexusHDF5Result}, | ||
| DatasetExt, HasAttributesExt, | ||
| }; | ||
|
|
||
| impl HasAttributesExt for Dataset { | ||
| #[tracing::instrument(skip_all, level = "debug", err(level = "warn"))] | ||
| fn add_attribute<T: H5Type>(&self, attr: &str) -> NexusHDF5Result<Attribute> { | ||
| let attr = self.new_attr::<T>().create(attr).err_dataset(self)?; | ||
| Ok(attr) | ||
| } | ||
|
|
||
| fn add_string_attribute(&self, attr: &str) -> NexusHDF5Result<Attribute> { | ||
| self.add_attribute::<VarLenUnicode>(attr) | ||
| } | ||
|
|
||
| fn add_constant_string_attribute(&self, attr: &str, value: &str) -> NexusHDF5Result<Attribute> { | ||
| let attr = self.add_string_attribute(attr)?; | ||
| attr.write_scalar(&value.parse::<VarLenUnicode>().err_dataset(self)?) | ||
| .err_dataset(self)?; | ||
| Ok(attr) | ||
| } | ||
|
|
||
| #[tracing::instrument(skip_all, level = "debug", err(level = "warn"))] | ||
| fn get_attribute(&self, attr: &str) -> NexusHDF5Result<Attribute> { | ||
| self.attr(attr).err_dataset(self) | ||
| } | ||
| } | ||
|
|
||
| impl DatasetExt for Dataset { | ||
| #[tracing::instrument(skip_all, level = "debug", err(level = "warn"))] | ||
| fn set_scalar<T: H5Type>(&self, value: &T) -> NexusHDF5Result<()> { | ||
| self.write_scalar(value).err_dataset(self) | ||
| } | ||
|
|
||
| #[tracing::instrument(skip_all, level = "debug", err(level = "warn"))] | ||
| fn set_string(&self, value: &str) -> NexusHDF5Result<()> { | ||
| self.write_scalar(&value.parse::<VarLenUnicode>().err_dataset(self)?) | ||
| .err_dataset(self) | ||
| } | ||
|
|
||
| #[tracing::instrument(skip_all, level = "debug", err(level = "warn"))] | ||
| fn get_string(&self) -> NexusHDF5Result<String> { | ||
| let string: VarLenUnicode = self.read_scalar().err_dataset(self)?; | ||
| Ok(string.into()) | ||
| } | ||
|
|
||
| #[tracing::instrument(skip_all, level = "debug", err(level = "warn"))] | ||
| fn get_datetime(&self) -> NexusHDF5Result<NexusDateTime> { | ||
| let string: VarLenUnicode = self.read_scalar().err_dataset(self)?; | ||
| string.parse().err_dataset(self) | ||
| } | ||
|
|
||
| #[tracing::instrument(skip_all, level = "debug", err(level = "warn"))] | ||
| fn set_slice<T: H5Type>(&self, value: &[T]) -> NexusHDF5Result<()> { | ||
| self.resize(value.len()).err_dataset(self)?; | ||
| self.write_raw(value).err_dataset(self) | ||
| } | ||
|
|
||
| #[tracing::instrument(skip_all, level = "debug", err(level = "warn"))] | ||
| fn append_value<T: H5Type>(&self, value: T) -> NexusHDF5Result<()> { | ||
| self.append_slice(&[value]).err_dataset(self) | ||
| } | ||
|
|
||
| #[tracing::instrument(skip_all, level = "debug", err(level = "warn"))] | ||
| fn append_slice<T: H5Type>(&self, value: &[T]) -> NexusHDF5Result<()> { | ||
| let cur_size = self.size(); | ||
| let new_size = cur_size + value.len(); | ||
| self.resize(new_size).err_dataset(self)?; | ||
| self.write_slice(value, s![cur_size..new_size]) | ||
| .err_dataset(self) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.