diff --git a/libertem_qd_mpx/src/background_thread.rs b/libertem_qd_mpx/src/background_thread.rs index ddf6a509..9f6eadcd 100644 --- a/libertem_qd_mpx/src/background_thread.rs +++ b/libertem_qd_mpx/src/background_thread.rs @@ -10,7 +10,6 @@ use std::{ use common::{ background_thread::{BackgroundThread, BackgroundThreadSpawnError, ControlMsg, ReceiverMsg}, frame_stack::{FrameMeta, FrameStackForWriting, FrameStackWriteError, WriteGuard}, - generic_connection::AcquisitionConfig, tcp::{self, ReadExactError}, utils::{num_from_byte_slice, NumParseError}, }; @@ -18,13 +17,13 @@ use ipc_test::{slab::ShmError, SharedSlabAllocator}; use log::{debug, error, info, trace, warn}; use crate::base_types::{ - AcqHeaderParseError, FrameMetaParseError, QdAcquisitionHeader, QdDetectorConnConfig, - QdFrameMeta, RecoveryStrategy, PREFIX_SIZE, + AcqHeaderParseError, FrameMetaParseError, QdAcquisitionConfig, QdAcquisitionHeader, + QdDetectorConnConfig, QdFrameMeta, RecoveryStrategy, PREFIX_SIZE, }; type QdControlMsg = ControlMsg<()>; -type QdReceiverMsg = ReceiverMsg; +type QdReceiverMsg = ReceiverMsg; #[derive(Debug, thiserror::Error)] pub enum AcquisitionError { @@ -407,7 +406,10 @@ fn acquisition( let mut last_control_check = Instant::now(); from_thread_s.send(ReceiverMsg::AcquisitionStart { - pending_acquisition: acquisition_header.clone(), + pending_acquisition: QdAcquisitionConfig::new( + acquisition_header.clone(), + first_frame_meta.clone(), + ), })?; let mut frame_stack = make_frame_stack(shm, config, first_frame_meta, to_thread_r)?; @@ -714,7 +716,7 @@ impl QdBackgroundThread { impl BackgroundThread for QdBackgroundThread { type FrameMetaImpl = QdFrameMeta; - type AcquisitionConfigImpl = QdAcquisitionHeader; + type AcquisitionConfigImpl = QdAcquisitionConfig; type ExtraControl = (); fn channel_to_thread( @@ -760,7 +762,9 @@ mod test { time::timeout, }; - use crate::base_types::{QdAcquisitionHeader, QdDetectorConnConfig, RecoveryStrategy}; + use crate::base_types::{ + QdAcquisitionConfig, QdAcquisitionHeader, QdDetectorConnConfig, RecoveryStrategy, + }; use super::QdBackgroundThread; @@ -934,7 +938,7 @@ End // we let the `GenericConnection` drive the background thread: let bg = QdBackgroundThread::spawn(config, &shm).unwrap(); - let mut conn: GenericConnection = + let mut conn: GenericConnection = GenericConnection::new(bg, &shm).unwrap(); conn.start_passive( || Ok::<(), ConnectionError>(()), @@ -1006,7 +1010,7 @@ End // we let the `GenericConnection` drive the background thread: let bg = QdBackgroundThread::spawn(config, &shm).unwrap(); - let mut conn: GenericConnection = + let mut conn: GenericConnection = GenericConnection::new(bg, &shm).unwrap(); conn.start_passive( || Ok::<(), ConnectionError>(()), @@ -1093,7 +1097,7 @@ End // we let the `GenericConnection` drive the background thread: let bg = QdBackgroundThread::spawn(config, &shm).unwrap(); - let mut conn: GenericConnection = + let mut conn: GenericConnection = GenericConnection::new(bg, &shm).unwrap(); conn.start_passive( || Ok::<(), ConnectionError>(()), @@ -1208,7 +1212,7 @@ End // we let the `GenericConnection` drive the background thread: let bg = QdBackgroundThread::spawn(config, &shm).unwrap(); - let mut conn: GenericConnection = + let mut conn: GenericConnection = GenericConnection::new(bg, &shm).unwrap(); conn.start_passive( || Ok::<(), ConnectionError>(()), @@ -1313,7 +1317,7 @@ End // we let the `GenericConnection` drive the background thread: let bg = QdBackgroundThread::spawn(config, &shm).unwrap(); - let mut conn: GenericConnection = + let mut conn: GenericConnection = GenericConnection::new(bg, &shm).unwrap(); conn.start_passive( || Ok::<(), ConnectionError>(()), @@ -1423,7 +1427,7 @@ End // we let the `GenericConnection` drive the background thread: let bg = QdBackgroundThread::spawn(config, &shm).unwrap(); - let mut conn: GenericConnection = + let mut conn: GenericConnection = GenericConnection::new(bg, &shm).unwrap(); conn.start_passive( || Ok::<(), ConnectionError>(()), @@ -1535,7 +1539,7 @@ End // we let the `GenericConnection` drive the background thread: let bg = QdBackgroundThread::spawn(config, &shm).unwrap(); - let mut conn: GenericConnection = + let mut conn: GenericConnection = GenericConnection::new(bg, &shm).unwrap(); conn.start_passive( || Ok::<(), ConnectionError>(()), @@ -1639,7 +1643,7 @@ End // we let the `GenericConnection` drive the background thread: let bg = QdBackgroundThread::spawn(config, &shm).unwrap(); - let mut conn: GenericConnection = + let mut conn: GenericConnection = GenericConnection::new(bg, &shm).unwrap(); conn.start_passive( || Ok::<(), ConnectionError>(()), @@ -1774,7 +1778,7 @@ End // we let the `GenericConnection` drive the background thread: let bg = QdBackgroundThread::spawn(config, &shm).unwrap(); - let mut conn: GenericConnection = + let mut conn: GenericConnection = GenericConnection::new(bg, &shm).unwrap(); conn.start_passive( || Ok::<(), ConnectionError>(()), @@ -1921,7 +1925,7 @@ End // we let the `GenericConnection` drive the background thread: let bg = QdBackgroundThread::spawn(config, &shm).unwrap(); - let mut conn: GenericConnection = + let mut conn: GenericConnection = GenericConnection::new(bg, &shm).unwrap(); conn.start_passive( || Ok::<(), ConnectionError>(()), diff --git a/libertem_qd_mpx/src/base_types.rs b/libertem_qd_mpx/src/base_types.rs index 76bb6a8d..62cdf174 100644 --- a/libertem_qd_mpx/src/base_types.rs +++ b/libertem_qd_mpx/src/base_types.rs @@ -518,12 +518,6 @@ pub struct QdAcquisitionHeader { raw_kv: HashMap, } -impl AcquisitionConfig for QdAcquisitionHeader { - fn num_frames(&self) -> usize { - self.frames_in_acquisition - } -} - #[pymethods] impl QdAcquisitionHeader { #[classmethod] @@ -539,8 +533,14 @@ impl QdAcquisitionHeader { fn frames_per_trigger(&self) -> usize { self.frames_per_trigger } +} - fn nav_shape(&self) -> Option<(usize, usize)> { +impl QdAcquisitionHeader { + pub fn num_frames(&self) -> usize { + self.frames_in_acquisition + } + + pub fn nav_shape(&self) -> Option<(usize, usize)> { if let (Some(scan_x), Some(scan_y)) = (self.scan_x, self.scan_y) { return Some((scan_y, scan_x)); } @@ -742,9 +742,53 @@ impl DetectorConnectionConfig for QdDetectorConnConfig { } } +#[pyclass] +#[derive(Debug, Clone)] +pub struct QdAcquisitionConfig { + acq_header: QdAcquisitionHeader, + frame_header: QdFrameMeta, +} + +impl QdAcquisitionConfig { + pub fn new(acq_header: QdAcquisitionHeader, frame_header: QdFrameMeta) -> Self { + Self { + acq_header, + frame_header, + } + } +} + +impl AcquisitionConfig for QdAcquisitionConfig { + fn num_frames(&self) -> usize { + self.acq_header.frames_in_acquisition + } +} + +#[pymethods] +impl QdAcquisitionConfig { + fn frames_in_acquisition(&self) -> usize { + self.acq_header.frames_in_acquisition + } + + fn frames_per_trigger(&self) -> usize { + self.acq_header.frames_per_trigger + } + + fn nav_shape(&self) -> Option<(usize, usize)> { + self.acq_header.nav_shape() + } + + fn detector_shape(&self) -> (u32, u32) { + ( + self.frame_header.height_in_pixels, + self.frame_header.width_in_pixels, + ) + } +} + #[cfg(test)] mod test { - use common::{frame_stack::FrameMeta, generic_connection::AcquisitionConfig}; + use common::frame_stack::FrameMeta; use crate::base_types::{DType, Layout}; diff --git a/libertem_qd_mpx/src/main_py.rs b/libertem_qd_mpx/src/main_py.rs index 8f001405..4f411f1d 100644 --- a/libertem_qd_mpx/src/main_py.rs +++ b/libertem_qd_mpx/src/main_py.rs @@ -9,7 +9,7 @@ use pyo3::{ use common::{impl_py_cam_client, impl_py_connection}; -use crate::base_types::{QdDetectorConnConfig, QdFrameMeta, RecoveryStrategy}; +use crate::base_types::{QdAcquisitionConfig, QdDetectorConnConfig, QdFrameMeta, RecoveryStrategy}; use crate::decoder::QdDecoder; use crate::{background_thread::QdBackgroundThread, base_types::QdAcquisitionHeader}; @@ -19,6 +19,7 @@ fn libertem_qd_mpx(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_class::()?; let env = env_logger::Env::default() .filter_or("LIBERTEM_QD_LOG_LEVEL", "error") @@ -35,7 +36,7 @@ impl_py_connection!( QdFrameStack, QdFrameMeta, QdBackgroundThread, - QdAcquisitionHeader, + QdAcquisitionConfig, libertem_qd_mpx ); @@ -90,13 +91,13 @@ impl QdConnection { ); let shm = - GenericConnection::::shm_from_config(&config) + GenericConnection::::shm_from_config(&config) .map_err(|e| PyConnectionError::new_err(e.to_string()))?; let bg_thread = QdBackgroundThread::spawn(&config, &shm) .map_err(|e| PyConnectionError::new_err(e.to_string()))?; let generic_conn = - GenericConnection::::new(bg_thread, &shm) + GenericConnection::::new(bg_thread, &shm) .map_err(|e| PyConnectionError::new_err(e.to_string()))?; let conn = _PyQdConnection::new(shm, generic_conn); @@ -108,7 +109,7 @@ impl QdConnection { &mut self, timeout: Option, py: Python<'_>, - ) -> PyResult> { + ) -> PyResult> { self.conn.wait_for_arm(timeout, py) }