pub struct FileView<'a> { /* private fields */ }
Expand description
An immutable view to a MIDAS file.
A file is a collection of EventView
s wrapped by two dumps of the Online
DataBase (ODB) at the beginning and end of the sub-run.
Implementations§
Source§impl<'a> FileView<'a>
impl<'a> FileView<'a>
Sourcepub fn try_from_bytes(bytes: &'a [u8]) -> Result<Self, ParseError>
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
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}
Sourcepub fn run_number(&self) -> u32
pub fn run_number(&self) -> u32
Returns the run number of the file.
Sourcepub fn initial_timestamp(&self) -> u32
pub fn initial_timestamp(&self) -> u32
Returns the unix timestamp of the initial ODB dump.
Sourcepub fn initial_odb(&self) -> &'a [u8] ⓘ
pub fn initial_odb(&self) -> &'a [u8] ⓘ
Returns the initial ODB dump.
Sourcepub fn final_timestamp(&self) -> u32
pub fn final_timestamp(&self) -> u32
Returns the unix timestamp of the final ODB dump.
Trait Implementations§
Source§impl<'a, 'b> IntoIterator for &'b FileView<'a>
impl<'a, 'b> IntoIterator for &'b FileView<'a>
Source§impl<'a> IntoIterator for FileView<'a>
impl<'a> IntoIterator for FileView<'a>
Source§impl<'a, 'b> IntoParallelIterator for &'b FileView<'a>
Available on crate feature rayon
only.
impl<'a, 'b> IntoParallelIterator for &'b FileView<'a>
Available on crate feature
rayon
only.Source§impl<'a> IntoParallelIterator for FileView<'a>
Available on crate feature rayon
only.
impl<'a> IntoParallelIterator for FileView<'a>
Available on crate feature
rayon
only.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> 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