Skip to content
Merged
Show file tree
Hide file tree
Changes from 127 commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
0c9144d
Added Ext Traits
Modularius Jan 23, 2025
35a3bc3
Use Trait Methods
Modularius Jan 23, 2025
8b1358d
Further Trait Methods
Modularius Jan 23, 2025
fa9c2a2
Tidying Up
Modularius Jan 23, 2025
53bc3e6
Moved all control to Trait Methods
Modularius Jan 23, 2025
eea77cf
Added Thiserror
Modularius Jan 24, 2025
9cb889b
Completed new error handling
Modularius Jan 25, 2025
ec310b9
Log time adjust to origin
Modularius Jan 29, 2025
f776e0f
Inputted adjust_nanoseconds_by_origin function
Modularius Jan 29, 2025
5e9e17f
Changed log time units to seconds in floating point
Modularius Jan 29, 2025
b758556
Fix append_slice error
Modularius Jan 30, 2025
8bf1d03
Fixed mistake with incomplete frame log times
Modularius Jan 31, 2025
475ff09
Formatting
Modularius Jan 31, 2025
9f788b0
Removed comments and made error name more descriptive
Modularius Jan 31, 2025
2dcb8d1
Merge branch 'main' into Refactor-Nexus-Writer
Modularius Feb 4, 2025
b0f28d2
Removed unneeded comment block
Modularius Feb 5, 2025
cb99661
Merge branch 'main' into Refactor-Nexus-Writer
Modularius Feb 5, 2025
dd8ec61
Added hdf5_writer tests
Modularius Feb 10, 2025
b5fa879
Formatting
Modularius Feb 10, 2025
f927f5b
Fixed test file name
Modularius Feb 10, 2025
26f60a1
Ammended error types
Modularius Feb 14, 2025
056d287
Merge branch 'main' into Refactor-Nexus-Writer
Modularius Feb 17, 2025
b29b503
Now obtains temp file path from std::env::temp_dir()
Modularius Feb 17, 2025
5b50612
treefmt
Modularius Feb 17, 2025
2a1b507
Merge branch 'main' into Refactor-Nexus-Writer
Modularius Mar 4, 2025
1b79232
Created some of the file structure
Modularius Mar 10, 2025
bb8dbc7
Add extra interval counter, and struct changes
Modularius Mar 11, 2025
390609c
Moved local path to NexusSettings
Modularius Mar 12, 2025
833042d
Moved flush thread to new file
Modularius Mar 13, 2025
68c91ca
Tracing update
Modularius Mar 13, 2025
8463777
Treefmt
Modularius Mar 13, 2025
2dc8804
Formatting
Modularius Mar 14, 2025
cc03e6d
Tidying
Modularius Mar 14, 2025
0a217eb
Changed local_path/temp directory to local_path for backwards compati…
Modularius Mar 16, 2025
cf6a73e
Merge branch 'Fine-Grained-Separation-Of-Files-In-Nexus-Writer' into …
Modularius Mar 16, 2025
8ce0ac3
Fixing
Modularius Mar 17, 2025
e669a6f
Added constant datasets
Modularius Mar 17, 2025
69fa13f
Newline
Modularius Mar 17, 2025
673a80f
Building up File Structure
Modularius Mar 17, 2025
f16a0dc
Added File Structure
Modularius Mar 17, 2025
8fe97e9
Introduce Topics structure
Modularius Mar 17, 2025
2ec6f42
Refactored fb msg handling to new file
Modularius Mar 18, 2025
8dcc202
Refactor new file
Modularius Mar 18, 2025
cf227d0
Added comments
Modularius Mar 18, 2025
b4b200e
Treefmt
Modularius Mar 18, 2025
05f505e
Documenting NexusConfiguration
Modularius Mar 18, 2025
245ed10
Added hdf files
Modularius Mar 19, 2025
749e226
treefmt
Modularius Mar 19, 2025
6b3a7a9
Restructured files
Modularius Mar 19, 2025
66b08d1
Merge branch 'Route-SELogs-and-RunLogs-correctly' into Refactor-Nexus…
Modularius Mar 19, 2025
efb4be9
Merge branch 'Fine-Grained-Separation-Of-Files-In-Nexus-Writer' into …
Modularius Mar 19, 2025
506bda2
Fixed merge mistake
Modularius Mar 19, 2025
46f3171
Restructure
Modularius Mar 19, 2025
8de5351
Merge branch 'main' into Fine-Grained-Separation-Of-Files-In-Nexus-Wr…
Modularius Mar 19, 2025
5c451b1
Fix merge
Modularius Mar 19, 2025
e1a1e0d
Merge branch 'Fine-Grained-Separation-Of-Files-In-Nexus-Writer' into …
Modularius Mar 19, 2025
efcfe45
Allow Settings to be propagated
Modularius Mar 20, 2025
8723ee5
Modify Message Handling
Modularius Mar 20, 2025
5110f7a
Added set_string_to function
Modularius Mar 21, 2025
93a191e
Made run_messages public
Modularius Mar 21, 2025
51d5d83
Added more message handlers
Modularius Mar 21, 2025
722dafc
Implemented Message Handlers
Modularius Mar 22, 2025
2897cab
treefmt
Modularius Mar 22, 2025
0b77da3
Moved run.rs and run_parameters.rs to folder
Modularius Mar 22, 2025
2f4d4a4
Renamed schematic to nexus_structure
Modularius Mar 22, 2025
40cf233
Renamed nexus to run_engine
Modularius Mar 22, 2025
200aa23
Moved NexusSchematic, NexusGroup, NexusFile, NexusNoFile and NexusFil…
Modularius Mar 22, 2025
0b0837e
Refactored NexusFile and NexusNoFile
Modularius Mar 22, 2025
68010ad
Removed root.rs
Modularius Mar 22, 2025
c1bf170
Implement more message handling and simplify parameter extraction
Modularius Mar 22, 2025
8e1875a
Added units handler
Modularius Mar 22, 2025
eb0981c
Implemented units.rs
Modularius Mar 22, 2025
b164cca
Added strum dependency
Modularius Mar 22, 2025
6268581
Standardised function and method names, and ordering in code
Modularius Mar 23, 2025
06ea89e
Moved nexus_classes into file, and general formatting
Modularius Mar 23, 2025
d164f29
Begun Refactoring Span Closures
Modularius Mar 24, 2025
ef85518
Removed unnecessary fields from RunParameters
Modularius Mar 24, 2025
3cc191c
Factor out run span initiation
Modularius Mar 24, 2025
ea46d61
Formatting
Modularius Mar 24, 2025
e473327
Factor out search for valid run methods
Modularius Mar 24, 2025
5527be0
Added some populate group methods
Modularius Mar 24, 2025
2e104e4
Began log handling
Modularius Mar 25, 2025
dd9b1a8
Treefmt
Modularius Mar 25, 2025
8e8a8fa
Logs
Modularius Mar 25, 2025
c495843
Formatting
Modularius Mar 25, 2025
c0b3e59
Added Logdata/Selog functions
Modularius Mar 27, 2025
4738712
Added flatbuffer handle for dataset
Modularius Mar 27, 2025
4656ca3
Refactored Log Structs
Modularius Mar 28, 2025
2bcbc16
Progress on logging
Modularius Apr 4, 2025
a9df700
Fixed Log Errors
Modularius Apr 5, 2025
970bac5
Improved Logs
Modularius Apr 5, 2025
f60fb7e
Formatting and adding classes
Modularius Apr 5, 2025
1abf114
Found option transpose method
Modularius Apr 5, 2025
7f7e15f
Treefmt
Modularius Apr 5, 2025
e23a9a7
flatten otel messages
Modularius Apr 7, 2025
8cda0a8
Periods and Source
Modularius Apr 7, 2025
c12527b
Added Flush and Formatting
Modularius Apr 7, 2025
17ffe3b
Added sample and geometry structures
Modularius Apr 7, 2025
34537e1
Flush and close
Modularius Apr 7, 2025
4ce19b4
Edit to Geometry and Formatting
Modularius Apr 7, 2025
7de7f77
Refactoring of files/code
Modularius Apr 8, 2025
4319f6e
Refactored logs in nexus_structure
Modularius Apr 8, 2025
7781905
Refactored logs in nexus
Modularius Apr 8, 2025
2f5ef54
Changed naming of methods
Modularius Apr 8, 2025
af89160
Added docstrings
Modularius Apr 8, 2025
e174907
Refactor File interface
Modularius Apr 8, 2025
a487213
treefmt
Modularius Apr 8, 2025
3a9bdf2
Added close_all method
Modularius Apr 8, 2025
2d1e384
Fixed create/open_rw typo
Modularius Apr 8, 2025
410f92f
Fixed field name typos
Modularius Apr 8, 2025
cd2b7e8
Fixed group get_name error
Modularius Apr 8, 2025
65d39c3
Improve error handling
Modularius Apr 8, 2025
d41a41a
Formatting
Modularius Apr 8, 2025
a5bf9e5
Implemented NexusClass struct
Modularius Apr 8, 2025
4959414
Altered Settings for some nexus_structure
Modularius Apr 8, 2025
f8ab189
Readme to explain source
Modularius Apr 8, 2025
19e2084
Simplify Error Names and Handling
Modularius Apr 9, 2025
494bbbd
Made num_new_events more succinct
Modularius Apr 9, 2025
4c71982
Formatting
Modularius Apr 9, 2025
86d882c
Fixed int type mistake
Modularius Apr 9, 2025
83b5a5f
Add warnings on error
Modularius Apr 9, 2025
6bef543
Removed errant error checking
Modularius Apr 9, 2025
240b750
Merge branch 'main' into Refactor-Nexus-Writer
Modularius Apr 9, 2025
f6917e4
Adding in further nexus fie;ds and formatting
Modularius Apr 9, 2025
db76d78
IDF_version unsigned
Modularius Apr 9, 2025
7c7e660
As last
Modularius Apr 9, 2025
b6a7820
Removed obsolete files
Modularius Apr 9, 2025
0822eb8
Fix use spacing style issues
Modularius Apr 14, 2025
76d5f4e
Fix line spacing style issue and remove unused code
Modularius Apr 14, 2025
4861993
Deleted unused file
Modularius Apr 14, 2025
60a8dee
Treefmt
Modularius Apr 14, 2025
c72b4de
Error strings more descriptive, and used strum
Modularius Apr 14, 2025
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
25 changes: 24 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ rayon = "1.10.0"
rdkafka = { version = "0.37.0", features = ["cmake-build", "ssl", "gssapi", "sasl"] }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1.0.140" }
strum = { version = "0.26.3", features = ["derive"] }
supermusr-common = { path = "./common" }
supermusr-streaming-types = { path = "./streaming-types" }
taos = { version = "0.10.27", default-features = false, features = ["ws"] }
Expand Down
1 change: 1 addition & 0 deletions nexus-writer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ metrics.workspace = true
metrics-exporter-prometheus.workspace = true
ndarray.workspace = true
rdkafka.workspace = true
strum.workspace = true
supermusr-common.workspace = true
supermusr-streaming-types.workspace = true
thiserror.workspace = true
Expand Down
95 changes: 95 additions & 0 deletions nexus-writer/docs/README.md
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.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{hdf5_file::NexusHDF5Error, NexusDateTime};
use crate::{hdf5_handlers::NexusHDF5Error, run_engine::NexusDateTime};
use glob::{GlobError, PatternError};
use std::{num::TryFromIntError, path::PathBuf};
use supermusr_streaming_types::time_conversions::GpsTimeConversionError;
Expand Down Expand Up @@ -88,4 +88,10 @@ pub(crate) enum FlatBufferMissingError {
RunName,
#[error("Flatbuffer Instrument Name Missing")]
InstrumentName,
#[error("Flatbuffer Alarm Source Name")]
AlarmName,
#[error("Flatbuffer Alarm Severity")]
AlarmSeverity,
#[error("Flatbuffer Alarm Message")]
AlarmMessage,
}
4 changes: 2 additions & 2 deletions nexus-writer/src/flush_to_archive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
nexus::{ErrorCodeLocation, NexusWriterError},
NexusSettings, NexusWriterResult,
error::{ErrorCodeLocation, NexusWriterError, NexusWriterResult},
NexusSettings,
};
use std::path::{Path, PathBuf};
use tokio::{
Expand Down
28 changes: 28 additions & 0 deletions nexus-writer/src/hdf5_handlers/attribute.rs
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())
}
}
78 changes: 78 additions & 0 deletions nexus-writer/src/hdf5_handlers/dataset.rs
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)
}
}
Loading