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>
impl<'a> EventView<'a>
Sourcepub fn id(&self) -> u16
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
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}Sourcepub fn trigger_mask(&self) -> u16
pub fn trigger_mask(&self) -> u16
Returns the trigger mask of the event.
Sourcepub fn serial_number(&self) -> u32
pub fn serial_number(&self) -> u32
Returns the serial number of the event.
Trait Implementations§
Source§impl<'a, 'b> IntoIterator for &'b EventView<'a>
impl<'a, 'b> IntoIterator for &'b EventView<'a>
Source§impl<'a> IntoIterator for EventView<'a>
impl<'a> IntoIterator for EventView<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more