Can show pulse id diff from sf-databuffer
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
use crate::AsAnyMut;
|
||||
use crate::AsAnyRef;
|
||||
use crate::Events;
|
||||
use crate::TimeBinned;
|
||||
use crate::TypeName;
|
||||
use crate::WithLen;
|
||||
use err::Error;
|
||||
use netpod::log::*;
|
||||
use netpod::range::evrange::SeriesRange;
|
||||
use netpod::BinnedRangeEnum;
|
||||
use serde::Serialize;
|
||||
use std::any;
|
||||
use std::any::Any;
|
||||
use std::fmt;
|
||||
|
||||
@@ -88,12 +91,23 @@ where
|
||||
T: fmt::Debug + CollectorType + 'static,
|
||||
{
|
||||
fn ingest(&mut self, src: &mut dyn Collectable) {
|
||||
let x = src.as_any_mut().downcast_mut();
|
||||
if x.is_none() {
|
||||
warn!("TODO handle the case of incoming Box");
|
||||
if let Some(src) = src.as_any_mut().downcast_mut::<<T as CollectorType>::Input>() {
|
||||
info!("sees incoming &mut ref");
|
||||
T::ingest(self, src)
|
||||
} else {
|
||||
if let Some(src) = src.as_any_mut().downcast_mut::<Box<<T as CollectorType>::Input>>() {
|
||||
info!("sees incoming &mut Box");
|
||||
T::ingest(self, src)
|
||||
} else {
|
||||
error!(
|
||||
"No idea what this is. Expect: {} input {} got: {} {:?}",
|
||||
any::type_name::<T>(),
|
||||
any::type_name::<<T as CollectorType>::Input>(),
|
||||
src.type_name(),
|
||||
src
|
||||
);
|
||||
}
|
||||
}
|
||||
let src: &mut <T as CollectorType>::Input = x.expect("can not downcast");
|
||||
T::ingest(self, src)
|
||||
}
|
||||
|
||||
fn set_range_complete(&mut self) {
|
||||
@@ -115,15 +129,21 @@ where
|
||||
}
|
||||
|
||||
// TODO rename to `Typed`
|
||||
pub trait CollectableType: fmt::Debug + AsAnyRef + AsAnyMut {
|
||||
pub trait CollectableType: fmt::Debug + AsAnyRef + AsAnyMut + TypeName {
|
||||
type Collector: CollectorType<Input = Self>;
|
||||
fn new_collector() -> Self::Collector;
|
||||
}
|
||||
|
||||
pub trait Collectable: fmt::Debug + AsAnyRef + AsAnyMut {
|
||||
pub trait Collectable: fmt::Debug + AsAnyRef + AsAnyMut + TypeName {
|
||||
fn new_collector(&self) -> Box<dyn Collector>;
|
||||
}
|
||||
|
||||
impl TypeName for Box<dyn Events> {
|
||||
fn type_name(&self) -> String {
|
||||
self.as_ref().type_name()
|
||||
}
|
||||
}
|
||||
|
||||
impl Collectable for Box<dyn Events> {
|
||||
fn new_collector(&self) -> Box<dyn Collector> {
|
||||
self.as_ref().new_collector()
|
||||
@@ -139,6 +159,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeName for Box<dyn Collectable> {
|
||||
fn type_name(&self) -> String {
|
||||
self.as_ref().type_name()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO do this with some blanket impl:
|
||||
impl Collectable for Box<dyn Collectable> {
|
||||
fn new_collector(&self) -> Box<dyn Collector> {
|
||||
@@ -146,13 +172,19 @@ impl Collectable for Box<dyn Collectable> {
|
||||
}
|
||||
}
|
||||
|
||||
impl WithLen for Box<dyn crate::TimeBinned> {
|
||||
impl WithLen for Box<dyn TimeBinned> {
|
||||
fn len(&self) -> usize {
|
||||
self.as_ref().len()
|
||||
}
|
||||
}
|
||||
|
||||
impl Collectable for Box<dyn crate::TimeBinned> {
|
||||
impl TypeName for Box<dyn TimeBinned> {
|
||||
fn type_name(&self) -> String {
|
||||
self.as_ref().type_name()
|
||||
}
|
||||
}
|
||||
|
||||
impl Collectable for Box<dyn TimeBinned> {
|
||||
fn new_collector(&self) -> Box<dyn Collector> {
|
||||
self.as_ref().new_collector()
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ pub mod isodate;
|
||||
pub mod scalar_ops;
|
||||
pub mod streamitem;
|
||||
pub mod subfr;
|
||||
pub mod transform;
|
||||
|
||||
pub mod bincode {
|
||||
pub use bincode::*;
|
||||
@@ -79,7 +80,7 @@ where
|
||||
}
|
||||
|
||||
/// Data in time-binned form.
|
||||
pub trait TimeBinned: Any + TimeBinnable + Collectable + erased_serde::Serialize {
|
||||
pub trait TimeBinned: Any + TypeName + TimeBinnable + Collectable + erased_serde::Serialize {
|
||||
fn as_time_binnable_dyn(&self) -> &dyn TimeBinnable;
|
||||
fn as_collectable_mut(&mut self) -> &mut dyn Collectable;
|
||||
fn edges_slice(&self) -> (&[u64], &[u64]);
|
||||
@@ -187,30 +188,3 @@ impl PartialEq for Box<dyn Events> {
|
||||
Events::partial_eq_dyn(self.as_ref(), other.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TransformProperties {
|
||||
pub needs_one_before_range: bool,
|
||||
pub needs_value: bool,
|
||||
}
|
||||
|
||||
pub trait EventTransform {
|
||||
fn query_transform_properties(&self) -> TransformProperties;
|
||||
}
|
||||
|
||||
impl<T> EventTransform for Box<T>
|
||||
where
|
||||
T: EventTransform,
|
||||
{
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
self.as_ref().query_transform_properties()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> EventTransform for std::pin::Pin<Box<T>>
|
||||
where
|
||||
T: EventTransform,
|
||||
{
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
self.as_ref().query_transform_properties()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,19 @@ macro_rules! on_sitemty_range_complete {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! on_sitemty_data {
|
||||
($item:expr, $ex:expr) => {
|
||||
if let Ok($crate::streamitem::StreamItem::DataItem($crate::streamitem::RangeCompletableItem::Data(item))) =
|
||||
$item
|
||||
{
|
||||
$ex(item)
|
||||
} else {
|
||||
$item
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn sitem_data<X>(x: X) -> Sitemty<X> {
|
||||
Ok(StreamItem::DataItem(RangeCompletableItem::Data(x)))
|
||||
}
|
||||
|
||||
57
items_0/src/transform.rs
Normal file
57
items_0/src/transform.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use std::pin;
|
||||
|
||||
use crate::Events;
|
||||
|
||||
pub struct TransformProperties {
|
||||
pub needs_one_before_range: bool,
|
||||
pub needs_value: bool,
|
||||
}
|
||||
|
||||
pub trait EventTransform {
|
||||
fn query_transform_properties(&self) -> TransformProperties;
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events>;
|
||||
}
|
||||
|
||||
impl<T> EventTransform for Box<T>
|
||||
where
|
||||
T: EventTransform,
|
||||
{
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
self.as_ref().query_transform_properties()
|
||||
}
|
||||
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> EventTransform for pin::Pin<Box<T>>
|
||||
where
|
||||
T: EventTransform,
|
||||
{
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
self.as_ref().query_transform_properties()
|
||||
}
|
||||
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct IdentityTransform {}
|
||||
|
||||
impl IdentityTransform {
|
||||
pub fn default() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl EventTransform for IdentityTransform {
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events> {
|
||||
src
|
||||
}
|
||||
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user