gondola_core/tof/
thread_control.rs

1//! Thread control structures as used in the TOF flight software 
2//! liftof. 
3// This file is part of gaps-online-software and published 
4// under the GPLv3 license
5
6use crate::prelude::*;
7
8/// Send runtime information 
9/// to threads via shared memory
10/// (Arc(Mutex)
11#[derive(Default, Debug)]
12pub struct ThreadControl {
13  /// Stop ALL threads
14  pub stop_flag                  : bool,
15  /// Received INT signal        
16  pub sigint_recvd               : bool,
17  /// signal to end all rb thread activity
18  pub end_all_rb_threads         : bool,
19  /// Trigger calibration thread
20  pub calibration_active         : bool,
21  /// Keep track on how many calibration 
22  /// packets we have received
23  pub finished_calibrations      : HashMap<u8,bool>,
24  /// Hold the actual calibration data
25  pub calibrations               : HashMap<u8, RBCalibrations>,
26  /// Hold off the master trigger thread, until everything else
27  /// is ready
28  pub holdoff_mtb_thread         : bool,
29  /// alive indicator for cmd dispatch thread
30  pub thread_cmd_dispatch_active : bool,
31  /// alive indicator for data sink thread
32  pub thread_data_sink_active    : bool,
33  /// alive indicator for runner thread
34  pub thread_runner_active       : bool,
35  /// alive indicator for event builder thread
36  pub thread_event_bldr_active   : bool,
37  /// alive indicator for master trigger thread
38  pub thread_master_trg_active   : bool,
39  /// alive indicator for monitoring thread
40  pub thread_monitoring_active   : bool,
41  /// Running readoutboard communicator threads - the key is associated rb id
42  pub thread_rbcomm_active       : HashMap<u8, bool>,
43  /// Manage CTRL+C (or CMD+C/Mac) input
44  pub thread_signal_hdlr_active  : bool,
45  /// The current run id
46  pub run_id                     : u32,
47  /// The number of boards available
48  pub n_rbs                      : u32,
49  #[cfg(feature = "database")]
50  /// The active readoutboards in the Tof
51  pub rb_list                    : Vec<ReadoutBoard>,
52  /// Verification run currently active
53  pub verification_active        : bool,
54  /// TOF Detector status - which channels are active?
55  pub detector_status            : TofDetectorStatus,
56  /// Decide if data is actually written to disk
57  pub write_data_to_disk         : bool,
58  /// indicator that a new 
59  /// run has started
60  /// (data sinks need to know)
61  pub new_run_start_flag         : bool,
62  /// initiate a MTB DAQ reset (if the queue is behind)
63  pub reset_mtb_daq              : bool,
64  pub liftof_settings            : LiftofSettings,
65  /// Have another variable to store bogus event ids on the RBs 
66  pub lost_event_ids             : f32,
67}
68
69impl ThreadControl {
70  pub fn new() -> Self {
71    Self {
72      stop_flag                  : false,
73      calibration_active         : false,
74      finished_calibrations      : HashMap::<u8,bool>::new(),
75      calibrations               : HashMap::<u8, RBCalibrations>::new(),
76      sigint_recvd               : false,
77      end_all_rb_threads         : false,
78      holdoff_mtb_thread         : false,
79      thread_cmd_dispatch_active : false,
80      thread_data_sink_active    : false,
81      thread_runner_active       : false,
82      thread_event_bldr_active   : false,
83      thread_master_trg_active   : false,
84      thread_monitoring_active   : false,
85      thread_rbcomm_active       : HashMap::<u8,bool>::new(),
86      // in principle this should always be active
87      thread_signal_hdlr_active  : true,
88      run_id                     : 0,
89      n_rbs                      : 0,
90      #[cfg(feature = "database")]
91      rb_list                    : Vec::<ReadoutBoard>::new(),
92      verification_active        : false,
93      detector_status            : TofDetectorStatus::new(),
94      write_data_to_disk         : false,
95      new_run_start_flag         : false,
96      reset_mtb_daq              : false,
97      liftof_settings            : LiftofSettings::new(),
98      lost_event_ids             : 0.0,
99    }
100  }
101}
102
103impl fmt::Display for ThreadControl {
104  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
105    let mut repr = String::from("<ThreadControl:");
106    repr        += &(format!("\n  Run ID         : {}", self.run_id));
107    repr        += &(format!("\n  N RBs          : {}", self.n_rbs));
108    repr        += &(format!("\n  wr to disk     : {}", self.write_data_to_disk));
109    repr        += "\n    -- reported RB calibration activity:";
110    repr        += &(format!("\n  RB cali active : {}", self.calibration_active));
111    for k in self.finished_calibrations.keys() {
112      repr        += &(format!("\n  -- finished  {}  : {}", k, self.finished_calibrations.get(k).unwrap()));       
113    }
114    repr        += &(format!("\n    -- verification run: {}", self.verification_active));
115    repr        += "\n    -- program status:";
116    repr        += &(format!("\n  stop flag        : {}", self.stop_flag));
117    repr        += "\n    -- reported thread activity:";
118    repr        += &(format!("\n  holdoff mtb thr. : {}", self.holdoff_mtb_thread));
119    repr        += &(format!("\n  cmd dispatcher   : {}", self.thread_cmd_dispatch_active));
120    repr        += &(format!("\n  runner           : {}", self.thread_runner_active));
121    repr        += &(format!("\n  data sink        : {}", self.thread_data_sink_active));
122    repr        += &(format!("\n  monitoring       : {}", self.thread_monitoring_active));
123    repr        += &(format!("\n  evt builder      : {}", self.thread_event_bldr_active));
124    repr        += &(format!("\n  master_trigger   : {}", self.thread_master_trg_active));
125    if self.thread_rbcomm_active.len() > 0 {
126      repr        += "\n -- active RB threads";
127      for k in self.thread_rbcomm_active.keys() {
128        repr      += &(format!("\n -- -- {} : {}", k, self.thread_rbcomm_active.get(k).unwrap()));
129      }
130    }
131    repr        += &(format!("\n  master trig    : {}>", self.thread_master_trg_active));
132    write!(f, "{}", repr)
133  }
134}
135