Crate alice_protocol_reader

Source
Expand description

This module contains mainly the InputScanner that reads the input data, and the CdpArray data structure that wraps the data read from the input. Additionally it contains a helper function spawn_reader that spawns a thread that reads input and sents it to a channel that is returned from the function.

The InputScanner is a generic type that can be instantiated with any type that implements the BufferedReaderWrapper trait. This trait is implemented for the StdInReaderSeeker and the BufReader types. Allowing the InputScanner to read from both stdin and files, in a convenient and efficient way.

The CdpArray is a wrapper for the data read from the input, it contains the data and the memory address of the first byte of the data.

§Example

First add the alice_protocol_reader crate to your project

$ cargo add alice_protocol_reader

Then use the convenience init_reader()-function to add the appropriate reader (stdin or file) at runtime. Instantiate the InputScanner with the reader and start reading ALICE data.

use alice_protocol_reader::input_scanner::InputScanner;
use alice_protocol_reader::init_reader;
use alice_protocol_reader::rdh::RdhCru;

let reader = init_reader(&Some(test_file_path)).unwrap();

let mut input_scanner = InputScanner::minimal(reader);

let rdh = input_scanner.load_rdh_cru::<RdhCru<u8>>().unwrap();

println!("{rdh:?}");

Example output

RdhCru
        Rdh0 { header_id: 7, header_size: 64, fee_id: 20522, priority_bit: 0, system_id: 32, reserved0: 0 }
        offset_new_packet: 5088
        memory_size: 5088
        link_id: 0
        packet_counter: 0
        cruid_dw: 24
        Rdh1 { bc_reserved0: 0, orbit: 192796021 }
        dataformat_reserved0: 2
        Rdh2 { trigger_type: 27139, pages_counter: 0, stop_bit: 0, reserved0: 0 }
        reserved1: 0
        Rdh3 { detector_field: 0, par_bit: 0, reserved0: 0 }
        reserved2: 0

§Customize InputScanner behaviour with a config

Implement the FilterOpt on your own config struct and pass it to the InputScanner to customize its behaviour

use alice_protocol_reader::filter::FilterOpt;

struct MyCfg;

impl FilterOpt for MyCfg {
    fn skip_payload(&self) -> bool {
        // Implement your config rules for determining if you're skipping the payload (only reading `RDH`s)
    }

    fn filter_link(&self) -> Option<u8> {
        // Implement your config rules for setting a link to filter by
    }

    fn filter_fee(&self) -> Option<u16> {
        // Implement your config rules for setting a FEE ID to filter by
    }

    fn filter_its_stave(&self) -> Option<u16> {
        // Implement your config rules for setting an ITS Stave to filter by
    }
}

use alice_protocol_reader::input_scanner::InputScanner;
use alice_protocol_reader::init_reader;
use alice_protocol_reader::rdh::RdhCru;
pub fn main() {}
    let reader = init_reader(&Some(test_file_path)).unwrap();

    let mut input_scanner = input_scanner::InputScanner::new(&MyCfg, reader, None); // None: Option<flume::Sender<InputStatType>>

    let rdh = input_scanner.load_cdp::<RdhCru<u8>>();
}

Modules§

bufreader_wrapper
Wrapper trait for BufReader, requires that the reader implements Read and Seek
cdp_wrapper
Contains the wrappers for the loaded CDP batches.
config
Options for configuring the InputScanner
input_scanner
Contains the InputScanner & ScanCDP trait, responsible for reading and forwarding input data.
mem_pos_tracker
Contains the MemPosTracker struct that aids in tracking the memory position in the input data.
prelude
Includes all the basics for working with the ALICE DAQ input module.
rdh
This module contains all struct definitions for the words that are used in supported data formats.
scan_cdp
Contains the ScanCDP trait for reading CDPs from a file or stdin (readable instance)
stats
Contains the InputStatType enum for which kind of statistics are gathered, and the Stats struct for tracking and reporting statistics about the input data.
stdin_reader
Wrapper for a reader, implements BufferedReaderWrapper.

Macros§

load_bytes
Macro to load a given number of bytes from a reader into a byte array buffer, to avoid heap allocation.

Functions§

init_reader
Initializes the reader based on the input mode (file or stdin) and returns it
spawn_reader
Spawns a reader thread that reads CDPs from the input and sends them to a producer channel
spawn_vec_reader
Spawns a reader thread that reads CDPs from the input and sends them to a producer channel