liftof_lib/
thread_control.rs1use std::collections::HashMap;
4use std::fmt;
5
6#[cfg(feature = "database")]
7use tof_dataclasses::database::ReadoutBoard;
8
9use tof_dataclasses::status::TofDetectorStatus;
10use tof_dataclasses::calibrations::RBCalibrations;
11
12use crate::settings::LiftofSettings;
13
14#[derive(Default, Debug)]
18pub struct ThreadControl {
19 pub stop_flag : bool,
21 pub sigint_recvd : bool,
23 pub end_all_rb_threads : bool,
25 pub calibration_active : bool,
27 pub finished_calibrations : HashMap<u8,bool>,
30 pub calibrations : HashMap<u8, RBCalibrations>,
32 pub holdoff_mtb_thread : bool,
35 pub thread_cmd_dispatch_active : bool,
37 pub thread_data_sink_active : bool,
39 pub thread_runner_active : bool,
41 pub thread_event_bldr_active : bool,
43 pub thread_master_trg_active : bool,
45 pub thread_monitoring_active : bool,
47 pub thread_rbcomm_active : HashMap<u8, bool>,
49 pub thread_signal_hdlr_active : bool,
51 pub run_id : u32,
53 pub n_rbs : u32,
55 #[cfg(feature = "database")]
56 pub rb_list : Vec<ReadoutBoard>,
58 pub verification_active : bool,
60 pub detector_status : TofDetectorStatus,
62 pub write_data_to_disk : bool,
64 pub new_run_start_flag : bool,
68 pub reset_mtb_daq : bool,
70 pub liftof_settings : LiftofSettings,
71}
72
73impl ThreadControl {
74 pub fn new() -> Self {
75 Self {
76 stop_flag : false,
77 calibration_active : false,
78 finished_calibrations : HashMap::<u8,bool>::new(),
79 calibrations : HashMap::<u8, RBCalibrations>::new(),
80 sigint_recvd : false,
81 end_all_rb_threads : false,
82 holdoff_mtb_thread : false,
83 thread_cmd_dispatch_active : false,
84 thread_data_sink_active : false,
85 thread_runner_active : false,
86 thread_event_bldr_active : false,
87 thread_master_trg_active : false,
88 thread_monitoring_active : false,
89 thread_rbcomm_active : HashMap::<u8,bool>::new(),
90 thread_signal_hdlr_active : true,
92 run_id : 0,
93 n_rbs : 0,
94 #[cfg(feature = "database")]
95 rb_list : Vec::<ReadoutBoard>::new(),
96 verification_active : false,
97 detector_status : TofDetectorStatus::new(),
98 write_data_to_disk : false,
99 new_run_start_flag : false,
100 reset_mtb_daq : false,
101 liftof_settings : LiftofSettings::new(),
102 }
103 }
104}
105
106impl fmt::Display for ThreadControl {
107 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
108 let mut repr = String::from("<ThreadControl:");
109 repr += &(format!("\n Run ID : {}", self.run_id));
110 repr += &(format!("\n N RBs : {}", self.n_rbs));
111 repr += &(format!("\n wr to disk : {}", self.write_data_to_disk));
112 repr += "\n -- reported RB calibration activity:";
113 repr += &(format!("\n RB cali active : {}", self.calibration_active));
114 for k in self.finished_calibrations.keys() {
115 repr += &(format!("\n -- finished {} : {}", k, self.finished_calibrations.get(k).unwrap()));
116 }
117 repr += &(format!("\n -- verification run: {}", self.verification_active));
118 repr += "\n -- program status:";
119 repr += &(format!("\n stop flag : {}", self.stop_flag));
120 repr += "\n -- reported thread activity:";
121 repr += &(format!("\n holdoff mtb thr. : {}", self.holdoff_mtb_thread));
122 repr += &(format!("\n cmd dispatcher : {}", self.thread_cmd_dispatch_active));
123 repr += &(format!("\n runner : {}", self.thread_runner_active));
124 repr += &(format!("\n data sink : {}", self.thread_data_sink_active));
125 repr += &(format!("\n monitoring : {}", self.thread_monitoring_active));
126 repr += &(format!("\n evt builder : {}", self.thread_event_bldr_active));
127 repr += &(format!("\n master_trigger : {}", self.thread_master_trg_active));
128 if self.thread_rbcomm_active.len() > 0 {
129 repr += "\n -- active RB threads";
130 for k in self.thread_rbcomm_active.keys() {
131 repr += &(format!("\n -- -- {} : {}", k, self.thread_rbcomm_active.get(k).unwrap()));
132 }
133 }
134 repr += &(format!("\n master trig : {}>", self.thread_master_trg_active));
135 write!(f, "{}", repr)
136 }
137}
138