diff --git a/src/apitypes.rs b/src/apitypes.rs index b73ca9e..7faf991 100644 --- a/src/apitypes.rs +++ b/src/apitypes.rs @@ -45,6 +45,11 @@ where let tss: Vec<_> = self.tss.into_iter().map(|x| x.ns()).collect(); let mut ret = self.values.into_user_facing_fields(); ret.push(("tss".into(), Box::new(tss))); + // Clients rely on `scalar_type` to create correctly typed HDF5 datasets. + ret.push(( + "scalar_type".into(), + Box::new(EVT::scalar_type_name_string()), + )); if self.range_final { ret.push(("rangeFinal".into(), Box::new(true))); } diff --git a/src/binning/container_events.rs b/src/binning/container_events.rs index 4d0b59b..64cd0b9 100644 --- a/src/binning/container_events.rs +++ b/src/binning/container_events.rs @@ -9,9 +9,6 @@ use crate::log::*; use crate::offsets::pulse_offs_from_abs; use core::fmt; use core::ops::Range; -use daqbuf_err as err; -use err::thiserror; -use err::ThisError; use items_0::apitypes::ToUserFacingApiType; use items_0::apitypes::UserApiType; use items_0::collect_s::CollectableDyn; @@ -44,9 +41,19 @@ use std::collections::VecDeque; macro_rules! trace_init { ($($arg:tt)*) => ( if false { trace!($($arg)*); }) } -#[derive(Debug, ThisError)] -#[cstm(name = "ValueContainerError")] -pub enum ValueContainerError {} +autoerr::create_error_v1!( + name(Error, "ValueContainerError"), + enum variants { + Logic, + }, +); + +autoerr::create_error_v1!( + name(EventsContainerError, "EventsContainerError"), + enum variants { + Unordered, + }, +); pub trait Container: fmt::Debug + Send + Unpin + Clone + PreviewRange + Serialize + for<'a> Deserialize<'a> @@ -75,6 +82,7 @@ pub trait EventValueType: fmt::Debug + Clone + PartialOrd + Send + Unpin + 'stat const SERDE_ID: u32; const BYTE_ESTIMATE_V00: u32; fn to_f32_for_binning_v01(&self) -> f32; + fn scalar_type_name_string() -> String; } impl Container for VecDeque @@ -150,7 +158,7 @@ impl Container for VecDeque { } macro_rules! impl_event_value_type { - ($evt:ty) => { + ($evt:ty, $sctname:expr) => { impl EventValueType for $evt { type Container = VecDeque; type AggregatorTimeWeight = AggregatorNumeric; @@ -161,6 +169,9 @@ macro_rules! impl_event_value_type { fn to_f32_for_binning_v01(&self) -> f32 { *self as _ } + fn scalar_type_name_string() -> String { + $sctname.to_string() + } } impl PartialOrdEvtA<$evt> for $evt { @@ -171,14 +182,14 @@ macro_rules! impl_event_value_type { }; } -impl_event_value_type!(u8); -impl_event_value_type!(u16); -impl_event_value_type!(u32); -impl_event_value_type!(u64); -impl_event_value_type!(i8); -impl_event_value_type!(i16); -impl_event_value_type!(i32); -impl_event_value_type!(i64); +impl_event_value_type!(u8, "u8"); +impl_event_value_type!(u16, "u16"); +impl_event_value_type!(u32, "u32"); +impl_event_value_type!(u64, "u64"); +impl_event_value_type!(i8, "i8"); +impl_event_value_type!(i16, "i16"); +impl_event_value_type!(i32, "i32"); +impl_event_value_type!(i64, "i64"); // impl_event_value_type!(f32); // impl_event_value_type!(f64); @@ -216,6 +227,9 @@ impl EventValueType for f32 { fn to_f32_for_binning_v01(&self) -> f32 { *self as _ } + fn scalar_type_name_string() -> String { + "f32".to_string() + } } impl EventValueType for f64 { @@ -228,6 +242,9 @@ impl EventValueType for f64 { fn to_f32_for_binning_v01(&self) -> f32 { *self as _ } + fn scalar_type_name_string() -> String { + "f64".to_string() + } } impl EventValueType for bool { @@ -240,6 +257,9 @@ impl EventValueType for bool { fn to_f32_for_binning_v01(&self) -> f32 { f32::from(*self) } + fn scalar_type_name_string() -> String { + "bool".to_string() + } } impl EventValueType for String { @@ -252,10 +272,13 @@ impl EventValueType for String { fn to_f32_for_binning_v01(&self) -> f32 { self.len() as _ } + fn scalar_type_name_string() -> String { + "string".to_string() + } } macro_rules! impl_event_value_type_vec { - ($evt:ty) => { + ($evt:ty, $sctname:expr) => { impl EventValueType for Vec<$evt> { type Container = VecDeque; type AggregatorTimeWeight = AggregatorVecNumeric; @@ -267,6 +290,9 @@ macro_rules! impl_event_value_type_vec { fn to_f32_for_binning_v01(&self) -> f32 { self.iter().fold(0., |a, x| a + *x as f32) } + fn scalar_type_name_string() -> String { + $sctname.to_string() + } } impl PartialOrdEvtA> for Vec<$evt> { @@ -277,16 +303,16 @@ macro_rules! impl_event_value_type_vec { }; } -impl_event_value_type_vec!(u8); -impl_event_value_type_vec!(u16); -impl_event_value_type_vec!(u32); -impl_event_value_type_vec!(u64); -impl_event_value_type_vec!(i8); -impl_event_value_type_vec!(i16); -impl_event_value_type_vec!(i32); -impl_event_value_type_vec!(i64); -impl_event_value_type_vec!(f32); -impl_event_value_type_vec!(f64); +impl_event_value_type_vec!(u8, "u8"); +impl_event_value_type_vec!(u16, "u16"); +impl_event_value_type_vec!(u32, "u32"); +impl_event_value_type_vec!(u64, "u64"); +impl_event_value_type_vec!(i8, "i8"); +impl_event_value_type_vec!(i16, "i16"); +impl_event_value_type_vec!(i32, "i32"); +impl_event_value_type_vec!(i64, "i64"); +impl_event_value_type_vec!(f32, "f32"); +impl_event_value_type_vec!(f64, "f64"); // impl_event_value_type_vec!(String); // impl_event_value_type_vec!(EnumVariant); @@ -301,6 +327,9 @@ impl EventValueType for Vec { fn to_f32_for_binning_v01(&self) -> f32 { self.iter().fold(0., |a, x| a + f32::from(*x)) } + fn scalar_type_name_string() -> String { + "bool".to_string() + } } impl PartialOrdEvtA> for Vec { @@ -320,6 +349,9 @@ impl EventValueType for Vec { fn to_f32_for_binning_v01(&self) -> f32 { self.iter().fold(0., |a, x| a + x.len() as f32) } + fn scalar_type_name_string() -> String { + "string".to_string() + } } impl PartialOrdEvtA> for Vec { @@ -339,6 +371,9 @@ impl EventValueType for Vec { fn to_f32_for_binning_v01(&self) -> f32 { self.iter().fold(0., |a, x| a + x.ix() as f32) } + fn scalar_type_name_string() -> String { + "enum".to_string() + } } impl PartialOrdEvtA> for Vec { @@ -538,6 +573,9 @@ where fn to_f32_for_binning_v01(&self) -> f32 { self.1.to_f32_for_binning_v01() } + fn scalar_type_name_string() -> String { + EVT::scalar_type_name_string() + } } #[derive(Debug, Clone)] @@ -581,12 +619,6 @@ where } } -#[derive(Debug, ThisError)] -#[cstm(name = "EventsContainerError")] -pub enum EventsContainerError { - Unordered, -} - #[derive(Clone)] pub struct ContainerEvents where @@ -1317,3 +1349,18 @@ mod test_serde_opt { assert_eq!(s, r#"{"a":null,"b":null}"#); } } + +#[test] +fn float_cmp_00() { + use std::cmp::Ordering; + assert_eq!(f32::INFINITY.partial_cmp(&2.0_f32), Some(Ordering::Greater)); + assert_eq!( + f32::INFINITY.partial_cmp(&f32::NEG_INFINITY), + Some(Ordering::Greater) + ); + assert_eq!( + f32::INFINITY.partial_cmp(&f32::INFINITY), + Some(Ordering::Equal) + ); + assert_eq!(f32::NAN.partial_cmp(&f32::INFINITY), None); +} diff --git a/src/binning/timeweight/timeweight_events.rs b/src/binning/timeweight/timeweight_events.rs index 9bb1edd..640b076 100644 --- a/src/binning/timeweight/timeweight_events.rs +++ b/src/binning/timeweight/timeweight_events.rs @@ -9,8 +9,6 @@ use crate::binning::container_events::PartialOrdEvtA; use crate::log::*; use core::fmt; use daqbuf_err as err; -use err::thiserror; -use err::ThisError; use netpod::BinnedRange; use netpod::DtNano; use netpod::TsNano; @@ -43,20 +41,21 @@ fn cold() {} const DEBUG_CHECKS: bool = true; -#[derive(Debug, ThisError)] -#[cstm(name = "BinnedEventsTimeweight")] -pub enum Error { - BadContainer(#[from] super::super::container_events::EventsContainerError), - Unordered, - EventAfterRange, - NoLstAfterFirst, - EmptyContainerInnerHandler, - NoLstButMinMax, - WithLstButEventBeforeRange, - WithMinMaxButEventBeforeRange, - NoMinMaxAfterInit, - ExpectEventWithinRange, -} +autoerr::create_error_v1!( + name(Error, "BinnedEventsTimeweight"), + enum variants { + BadContainer(#[from] super::super::container_events::EventsContainerError), + Unordered, + EventAfterRange, + NoLstAfterFirst, + EmptyContainerInnerHandler, + NoLstButMinMax, + WithLstButEventBeforeRange, + WithMinMaxButEventBeforeRange, + NoMinMaxAfterInit, + ExpectEventWithinRange, + }, +); type MinMax = (EventSingle, EventSingle); @@ -254,7 +253,6 @@ where impl InnerA where EVT: EventValueType, - // BVT: BinAggedType, { fn apply_min_max(ev: &EventSingleRef, minmax: &mut MinMax) { if let Some(std::cmp::Ordering::Less) = ev.val.cmp_a(&minmax.0.val) { diff --git a/src/binning/valuetype.rs b/src/binning/valuetype.rs index 66c56c7..e6c2e77 100644 --- a/src/binning/valuetype.rs +++ b/src/binning/valuetype.rs @@ -145,6 +145,9 @@ impl EventValueType for EnumVariant { fn to_f32_for_binning_v01(&self) -> f32 { self.ix() as _ } + fn scalar_type_name_string() -> String { + "enum".to_string() + } } impl PartialOrdEvtA for netpod::UnsupEvt { @@ -212,7 +215,10 @@ impl EventValueType for netpod::UnsupEvt { const SERDE_ID: u32 = ::SUB as u32; const BYTE_ESTIMATE_V00: u32 = 4; fn to_f32_for_binning_v01(&self) -> f32 { - todo!() + 0. + } + fn scalar_type_name_string() -> String { + "unsupevt".to_string() } } @@ -224,6 +230,9 @@ impl EventValueType for Vec { const SERDE_ID: u32 = ::SUB as u32; const BYTE_ESTIMATE_V00: u32 = 4; fn to_f32_for_binning_v01(&self) -> f32 { - todo!() + 0. + } + fn scalar_type_name_string() -> String { + "unsupevt".to_string() } }