Struct FileView

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

An immutable view to a MIDAS file.

A file is a collection of EventViews wrapped by two dumps of the Online DataBase (ODB) at the beginning and end of the sub-run.

Implementations§

Source§

impl<'a> FileView<'a>

Source

pub fn try_from_bytes(bytes: &'a [u8]) -> Result<Self, ParseError>

Create a native view to the underlying file from its representation as a byte slice.

Examples found in repository?
examples/single_bank.rs (line 5)
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 13)
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 run_number(&self) -> u32

Returns the run number of the file.

Source

pub fn initial_timestamp(&self) -> u32

Returns the unix timestamp of the initial ODB dump.

Source

pub fn initial_odb(&self) -> &'a [u8]

Returns the initial ODB dump.

Source

pub fn final_timestamp(&self) -> u32

Returns the unix timestamp of the final ODB dump.

Source

pub fn final_odb(&self) -> &'a [u8]

Returns the final ODB dump.

Source

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

Returns an iterator over the events of the file.

Trait Implementations§

Source§

impl<'a> Clone for FileView<'a>

Source§

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

Returns a copy 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 FileView<'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 FileView<'a>

Source§

type Item = &'b EventView<'a>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'b, EventView<'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 FileView<'a>

Source§

type Item = EventView<'a>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<EventView<'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, 'b> IntoParallelIterator for &'b FileView<'a>

Available on crate feature rayon only.
Source§

type Item = &'b EventView<'a>

The type of item that the parallel iterator will produce.
Source§

type Iter = Iter<'b, EventView<'a>>

The parallel iterator type that will be created.
Source§

fn into_par_iter(self) -> Self::Iter

Converts self into a parallel iterator. Read more
Source§

impl<'a> IntoParallelIterator for FileView<'a>

Available on crate feature rayon only.
Source§

type Item = EventView<'a>

The type of item that the parallel iterator will produce.
Source§

type Iter = IntoIter<EventView<'a>>

The parallel iterator type that will be created.
Source§

fn into_par_iter(self) -> Self::Iter

Converts self into a parallel iterator. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for FileView<'a>

§

impl<'a> RefUnwindSafe for FileView<'a>

§

impl<'a> Send for FileView<'a>

§

impl<'a> Sync for FileView<'a>

§

impl<'a> Unpin for FileView<'a>

§

impl<'a> UnwindSafe for FileView<'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<'data, I> IntoParallelRefIterator<'data> for I
where I: 'data + ?Sized, &'data I: IntoParallelIterator,

Source§

type Iter = <&'data I as IntoParallelIterator>::Iter

The type of the parallel iterator that will be returned.
Source§

type Item = <&'data I as IntoParallelIterator>::Item

The type of item that the parallel iterator will produce. This will typically be an &'data T reference type.
Source§

fn par_iter(&'data self) -> <I as IntoParallelRefIterator<'data>>::Iter

Converts self into a parallel iterator. Read more
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.