-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor nexus writer #306
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 24 commits into
ISISNeutronMuon:main
from
Modularius:Refactor-Nexus-Writer
Feb 17, 2025
Merged
Changes from 14 commits
Commits
Show all changes
24 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 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,79 @@ | ||
| use super::{hdf5_file::NexusHDF5Error, NexusDateTime}; | ||
| use glob::{GlobError, PatternError}; | ||
| use std::{num::TryFromIntError, path::PathBuf}; | ||
| use supermusr_streaming_types::time_conversions::GpsTimeConversionError; | ||
| use thiserror::Error; | ||
|
|
||
| pub(crate) type NexusWriterResult<T> = Result<T, NexusWriterError>; | ||
|
|
||
| #[derive(Debug, Error)] | ||
| pub(crate) enum ErrorCodeLocation { | ||
| #[error("set_stop_if_valid")] | ||
| SetStopIfValid, | ||
| #[error("set_aborted_run")] | ||
| SetAbortedRun, | ||
| #[error("RunParameters::new")] | ||
| NewRunParamemters, | ||
| #[error("stop_command")] | ||
| StopCommand, | ||
| #[error("process_event_list")] | ||
| ProcessEventList, | ||
| #[error("resume_partial_runs local directory path")] | ||
| ResumePartialRunsLocalDirectoryPath, | ||
| #[error("resume_partial_runs file path")] | ||
| ResumePartialRunsFilePath, | ||
| } | ||
|
|
||
| #[derive(Debug, Error)] | ||
| pub(crate) enum NexusWriterError { | ||
| #[error("{0}")] | ||
| HDF5(#[from] NexusHDF5Error), | ||
| #[error("Flatbuffer Timestamp Conversion Error {0}")] | ||
| FlatBufferTimestampConversion(#[from] GpsTimeConversionError), | ||
| #[error("{0}")] | ||
| FlatBufferMissing(FlatBufferMissingError, ErrorCodeLocation), | ||
| #[error("Unexpected RunStop Command")] | ||
| UnexpectedRunStop(ErrorCodeLocation), | ||
| #[error("Cannot convert local path to string: {path}")] | ||
| CannotConvertPath { | ||
| path: PathBuf, | ||
| location: ErrorCodeLocation, | ||
| }, | ||
| #[error("Glob Pattern Error: {0}")] | ||
| GlobPattern(#[from] PatternError), | ||
| #[error("Glob Error: {0}")] | ||
| Glob(#[from] GlobError), | ||
| #[error("Integer Conversion Error")] | ||
| TryFromInt(#[from] TryFromIntError), | ||
| #[error("Start Time {int} Out of Range for DateTime at {location}")] | ||
| IntOutOfRangeForDateTime { | ||
| int: u64, | ||
| location: ErrorCodeLocation, | ||
| }, | ||
| #[error("Stop Command before Start Command at {0}")] | ||
| StopCommandBeforeStartCommand(ErrorCodeLocation), | ||
| #[error("Stop Time {stop} earlier than current Start Time {start} at {location}")] | ||
| StopTimeEarlierThanStartTime { | ||
| start: NexusDateTime, | ||
| stop: NexusDateTime, | ||
| location: ErrorCodeLocation, | ||
| }, | ||
| #[error("RunStop already set at {0}")] | ||
| RunStopAlreadySet(ErrorCodeLocation), | ||
| } | ||
|
|
||
| #[derive(Debug, Error)] | ||
| pub(crate) enum FlatBufferMissingError { | ||
| #[error("Flatbuffer Timestamp Missing")] | ||
| Timestamp, | ||
| #[error("Flatbuffer Channels Missing")] | ||
| Channels, | ||
| #[error("Flatbuffer Intensities Missing")] | ||
| Intensities, | ||
| #[error("Flatbuffer Times Missing")] | ||
| Times, | ||
| #[error("Flatbuffer Run Name Missing")] | ||
| RunName, | ||
| #[error("Flatbuffer Instrument Name Missing")] | ||
| InstrumentName, | ||
| } |
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,85 @@ | ||
| use crate::nexus::error::FlatBufferMissingError; | ||
| use hdf5::{types::TypeDescriptor, Attribute, Dataset, Group}; | ||
| use std::error::Error; | ||
| use supermusr_streaming_types::time_conversions::GpsTimeConversionError; | ||
| use thiserror::Error; | ||
|
|
||
| pub(crate) type NexusHDF5Result<T> = Result<T, NexusHDF5Error>; | ||
|
|
||
| pub(crate) trait ConvertResult<T, E> | ||
| where | ||
| E: Error + Into<NexusHDF5ErrorType>, | ||
| { | ||
| fn err_group(self, group: &Group) -> NexusHDF5Result<T>; | ||
| fn err_dataset(self, dataset: &Dataset) -> NexusHDF5Result<T>; | ||
| fn err_attribute(self, attribute: &Attribute) -> NexusHDF5Result<T>; | ||
| fn err_file(self) -> NexusHDF5Result<T>; | ||
| } | ||
|
|
||
| #[derive(Debug, Error)] | ||
| #[error("{error_type} at {context}")] | ||
| pub(crate) struct NexusHDF5Error { | ||
| error_type: NexusHDF5ErrorType, | ||
| context: String, | ||
| } | ||
|
|
||
| impl<T, E> ConvertResult<T, E> for Result<T, E> | ||
| where | ||
| E: Error + Into<NexusHDF5ErrorType>, | ||
| { | ||
| fn err_group(self, group: &Group) -> NexusHDF5Result<T> { | ||
| self.map_err(|e| NexusHDF5Error { | ||
| error_type: e.into(), | ||
| context: group.name(), | ||
| }) | ||
| } | ||
|
|
||
| fn err_dataset(self, dataset: &Dataset) -> NexusHDF5Result<T> { | ||
| self.map_err(|e| NexusHDF5Error { | ||
| error_type: e.into(), | ||
| context: dataset.name(), | ||
| }) | ||
| } | ||
|
|
||
| fn err_attribute(self, attribute: &Attribute) -> NexusHDF5Result<T> { | ||
| self.map_err(|e| NexusHDF5Error { | ||
| error_type: e.into(), | ||
| context: attribute.name(), | ||
| }) | ||
| } | ||
|
|
||
| fn err_file(self) -> NexusHDF5Result<T> { | ||
| self.map_err(|e| NexusHDF5Error { | ||
| error_type: e.into(), | ||
| context: "File Level".to_owned(), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Error)] | ||
| pub(crate) enum NexusHDF5ErrorType { | ||
| #[error("{0}")] | ||
| HDF5(#[from] hdf5::Error), | ||
| #[error("{0}")] | ||
| DateTimeConversion(#[from] chrono::ParseError), | ||
| #[error("{0}")] | ||
| HDF5String(#[from] hdf5::types::StringError), | ||
| #[error("Flatbuffer Timestamp Conversion Error {0}")] | ||
| FlatBufferTimestampConversion(#[from] GpsTimeConversionError), | ||
| #[error("Flatbuffer Timestamp Error Converting to Nanoseconds")] | ||
| FlatBufferTimestampConvertToNanoseconds, | ||
| #[error("{0}")] | ||
| FlatBufferMissing(FlatBufferMissingError), | ||
| #[error("Invalid FlatBuffer RunLog Data Type {0}")] | ||
| FlatBufferInvalidRunLogDataType(String), | ||
| #[error("Invalid FlatBuffer Sample Environment Log Data Type {0}")] | ||
| FlatBufferInvalidSELogDataType(String), | ||
| #[error("Inconsistent Numbers of SELog Times and Values {0} != {1}")] | ||
| FlatBufferInconsistentSELogTimeValueSizes(usize, usize), | ||
| #[error("Invalid HDF5 Type {0}")] | ||
| InvalidHDF5Type(TypeDescriptor), | ||
| #[error("Invalid HDF5 Conversion {0}")] | ||
| InvalidHDF5TypeConversion(TypeDescriptor), | ||
| #[error("IO Error {0}")] | ||
| IO(#[from] std::io::Error), | ||
| } | ||
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.