Struct EventView

Source
pub struct EventView<'a> { /* private fields */ }
Expand description

An immutable view to an event in a MIDAS file.

An event is a collection of BankViews.

Implementations§

Source§

impl<'a> EventView<'a>

Source

pub fn id(&self) -> u16

Returns the event ID.

Examples found in repository?
examples/single_bank.rs (line 8)
1fn main() -> Result<(), Box<dyn std::error::Error>> {
2    let contents = std::fs::read("example.mid")?;
3    // Note that if your MIDAS file is compressed, you will need to decompress
4    // its contents (using an external crate) before parsing it.
5    let file_view = midasio::FileView::try_from_bytes(&contents)?;
6
7    // Iterate only through events with an ID of 1
8    for event in file_view.into_iter().filter(|event| event.id() == 1) {
9        // Lets assume that these events have multiple data banks, but they are
10        // guaranteed to have a single bank with the name "TRGB" (which is the
11        // one we are interested in)
12        let [trg_bank] = event
13            .into_iter()
14            .filter(|bank| bank.name() == *b"TRGB")
15            .collect::<Vec<_>>()[..]
16        else {
17            unreachable!();
18        };
19        // You can now access the data in the bank
20        let _trg_data = trg_bank.data();
21    }
22
23    Ok(())
24}
More examples
Hide additional examples
examples/parallel.rs (line 23)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let contents = std::fs::read("example.mid")?;
11    // Note that if your MIDAS file is compressed, you will need to decompress
12    // its contents (using an external crate) before parsing it.
13    let file_view = midasio::FileView::try_from_bytes(&contents)?;
14
15    // We want to process all events with an ID of 1. This can be any complex
16    // operation, e.g. reconstructing a vertex
17    let mut results = Vec::new();
18
19    #[cfg(feature = "rayon")]
20    results.par_extend(
21        file_view
22            .into_par_iter()
23            .filter(|event| event.id() == 1)
24            .map(|event| {
25                // This is a placeholder for a complex operation
26                event.into_iter().count()
27            }),
28    );
29    // The equivalent non-parallel version would be:
30    #[cfg(not(feature = "rayon"))]
31    results.extend(
32        file_view
33            .into_iter()
34            .filter(|event| event.id() == 1)
35            .map(|event| event.into_iter().count()),
36    );
37
38    Ok(())
39}
Source

pub fn trigger_mask(&self) -> u16

Returns the trigger mask of the event.

Source

pub fn serial_number(&self) -> u32

Returns the serial number of the event.

Source

pub fn timestamp(&self) -> u32

Returns the unix timestamp of the event.

Source

pub fn iter(&self) -> Iter<'_, BankView<'a>>

Returns an iterator over the data banks of the event.

Trait Implementations§

Source§

impl<'a> Clone for EventView<'a>

Source§

fn clone(&self) -> EventView<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for EventView<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, 'b> IntoIterator for &'b EventView<'a>

Source§

type Item = &'b BankView<'a>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'b, BankView<'a>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for EventView<'a>

Source§

type Item = BankView<'a>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<BankView<'a>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for EventView<'a>

§

impl<'a> RefUnwindSafe for EventView<'a>

§

impl<'a> Send for EventView<'a>

§

impl<'a> Sync for EventView<'a>

§

impl<'a> Unpin for EventView<'a>

§

impl<'a> UnwindSafe for EventView<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.