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}
66
67impl ThreadControl {
68  pub fn new() -> Self {
69    Self {
70      stop_flag                  : false,
71      calibration_active         : false,
72      finished_calibrations      : HashMap::<u8,bool>::new(),
73      calibrations               : HashMap::<u8, RBCalibrations>::new(),
74      sigint_recvd               : false,
75      end_all_rb_threads         : false,
76      holdoff_mtb_thread         : false,
77      thread_cmd_dispatch_active : false,
78      thread_data_sink_active    : false,
79      thread_runner_active       : false,
80      thread_event_bldr_active   : false,
81      thread_master_trg_active   : false,
82      thread_monitoring_active   : false,
83      thread_rbcomm_active       : HashMap::<u8,bool>::new(),
84      // in principle this should always be active
85      thread_signal_hdlr_active  : true,
86      run_id                     : 0,
87      n_rbs                      : 0,
88      #[cfg(feature = "database")]
89      rb_list                    : Vec::<ReadoutBoard>::new(),
90      verification_active        : false,
91      detector_status            : TofDetectorStatus::new(),
92      write_data_to_disk         : false,
93      new_run_start_flag         : false,
94      reset_mtb_daq              : false,
95      liftof_settings            : LiftofSettings::new(),
96    }
97  }
98}
99
100impl fmt::Display for ThreadControl {
101  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
102    let mut repr = String::from("<ThreadControl:");
103    repr        += &(format!("\n  Run ID         : {}", self.run_id));
104    repr        += &(format!("\n  N RBs          : {}", self.n_rbs));
105    repr        += &(format!("\n  wr to disk     : {}", self.write_data_to_disk));
106    repr        += "\n    -- reported RB calibration activity:";
107    repr        += &(format!("\n  RB cali active : {}", self.calibration_active));
108    for k in self.finished_calibrations.keys() {
109      repr        += &(format!("\n  -- finished  {}  : {}", k, self.finished_calibrations.get(k).unwrap()));       
110    }
111    repr        += &(format!("\n    -- verification run: {}", self.verification_active));
112    repr        += "\n    -- program status:";
113    repr        += &(format!("\n  stop flag        : {}", self.stop_flag));
114    repr        += "\n    -- reported thread activity:";
115    repr        += &(format!("\n  holdoff mtb thr. : {}", self.holdoff_mtb_thread));
116    repr        += &(format!("\n  cmd dispatcher   : {}", self.thread_cmd_dispatch_active));
117    repr        += &(format!("\n  runner           : {}", self.thread_runner_active));
118    repr        += &(format!("\n  data sink        : {}", self.thread_data_sink_active));
119    repr        += &(format!("\n  monitoring       : {}", self.thread_monitoring_active));
120    repr        += &(format!("\n  evt builder      : {}", self.thread_event_bldr_active));
121    repr        += &(format!("\n  master_trigger   : {}", self.thread_master_trg_active));
122    if self.thread_rbcomm_active.len() > 0 {
123      repr        += "\n -- active RB threads";
124      for k in self.thread_rbcomm_active.keys() {
125        repr      += &(format!("\n -- -- {} : {}", k, self.thread_rbcomm_active.get(k).unwrap()));
126      }
127    }
128    repr        += &(format!("\n  master trig    : {}>", self.thread_master_trg_active));
129    write!(f, "{}", repr)
130  }
131}
132