tttr_toolbox/lib.rs
1//!
2//! # TTTR Toolbox
3//! The fastest streaming algorithms for your TTTR data.
4//!
5//! TTTR Toolbox can be used as a standalone Rust library. If you do most of your data
6//! analysis in Python you may prefer to check Trattoria, a wrapper library for this
7//! crate.
8//!
9//! ## Project Goals
10//! - Single threaded performance
11//! - Ease of extensibility
12//!
13//! ## Algorithms available
14//! - [second order autocorrelation](tttr_tools/g2/fn.g2.html)
15//! - [third order autocorrelation](tttr_tools/g3/fn.g3.html)
16//! - [third order autocorrelation](tttr_tools/synced_g3/fn.g3_sync.html)
17//! - [intensity time trace](tttr_tools/timetrace/fn.timetrace.html)
18//! - [record number time trace](tttr_tools/timetrace/fn.timetrace.html)
19//! - [zero delay finder](tttr_tools/zero_finder/fn.zerofinder.html)
20//! - [lifetimes](tttr_tools/lifetime/fn.lifetime.html)
21//!
22//! ## Supported file and record formats
23//! - PicoQuant PTU
24//! - PHT2
25//! - HHT2_HH1
26//! - HHT2_HH2
27//! - HHT3_HH2
28//!
29//! If you want support for more record formats and file formats please ask for it.
30//! At the very least we will need the file format specification and a file with some
31//! discernible features to test the implementation.
32//!
33//! ## Examples
34//! ```ignore
35//! pub fn main() {
36//! let filename = PathBuf::from("/Users/garfield/Downloads/20191205_Xminus_0p1Ve-6_CW_HBT.ptu");
37//! let ptu_file = File::PTU(PTUFile::new(filename).unwrap());
38//! // Unwrap the file so we can print the header
39//! let File::PTU(f) = &ptu_file;
40//! println!("{}", f);
41//!
42//! let params = G2Params {
43//! channel_1: 0,
44//! channel_2: 1,
45//! correlation_window: 50_000e-12,
46//! resolution: 600e-12,
47//! start_record: None,
48//! stop_record: None,
49//! };
50//! let g2_histogram = g2(&ptu_file, ¶ms).unwrap();
51//! println!("{:?}", g2_histogram.hist);
52//! }
53//! ```
54
55#[macro_use]
56extern crate num_derive;
57extern crate byteorder;
58
59pub mod errors;
60pub mod headers;
61pub mod parsers;
62pub mod tttr_tools;
63
64pub(crate) trait TTTRStream {
65 type RecordSize;
66 fn parse_record(&mut self, raw_record: Self::RecordSize) -> TTTRRecord;
67 fn time_resolution(&self) -> f64;
68}
69
70#[derive(Debug)]
71pub struct TTTRRecord {
72 channel: i32,
73 tof: u64,
74}
75
76pub(crate) trait Click {
77 fn channel(&self) -> &i32;
78 fn tof(&self) -> &u64;
79}
80
81impl Click for TTTRRecord {
82 #[inline]
83 fn channel(&self) -> &i32 {
84 &self.channel
85 }
86 #[inline]
87 fn tof(&self) -> &u64 {
88 &self.tof
89 }
90}
91
92/// The TTTRFile trait ensures that all files we support are aware of the time_resolution
93/// and the what type of records they contain.
94///
95/// TTTR files don't usually represent time in seconds but rather as a multiple of them
96/// that matches the equipment time resolution. This makes it possible to shave a few
97/// bits per record.
98pub trait TTTRFile {
99 fn time_resolution(&self) -> Result<f64, errors::Error>;
100 fn record_type(&self) -> Result<headers::RecordType, errors::Error>;
101}