StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fcs_data_c.h
1 #ifndef _FCS_DATA_C_H_
2 #define _FCS_DATA_C_H_
3 
4 #include <pthread.h>
5 
6 
7 #define FCS_SECTOR_COU 12
8 
9 
10 
11 #include <sys/types.h>
12 typedef unsigned int u_int;
13 typedef unsigned short u_short;
14 typedef unsigned char u_char;
15 
16 
17 // Helper class for various things (data extraction, pedestal calculation etc)
18 class fcs_data_c {
19 public:
20 
21 
22  fcs_data_c() {
23  sector = 0 ;
24  rdo = 0 ;
25  id = 0 ;
26  board_id = 0 ;
27 
28  version = 0 ;
29 
30 
31  realtime = 0 ;
32  log_level = 0 ;
33 
34  // these are statics but stil...
35  run_type = 0 ;
36  run_number = 0 ;
37 
38  n_sigma = 4.0 ;
39  n_sigma_hcal = 4.0 ;
40  n_sigma_epd = 4.0 ;
41  n_pre = 8 ;
42  n_post = 8 ;
43  n_cou = 4 ;
44 
45  rhic_freq = 0 ;
46  fee_state = 0 ;
47 
48  bad_error = 0 ;
49  err_count = 0 ;
50  } ;
51 
52  ~fcs_data_c() {
53 // LOG(WARN,"fcs_data_c: destructor?") ;
54  } ;
55 
56 
57 
58  // per run
59  void run_start(u_int run_number, int type) ;
60  void run_stop(int bad_ped) ;
61 
62  void ped_start() ;
63  void ped_stop(int bad_ped) ;
64 
65 
66 
67  // per event
68  int start(u_short *d16, int shorts) ;
69  int hdr_event() ;
70  int event() ;
71  int accum(u_int ch, u_int tb, u_short adc) ;
72  int ana_ch() ;
73  int event_end(int how) ;
74 
75  int event_stream() ;
76  int event_pre_fy19() ;
77  int accum_pre_fy19(u_int ch, u_int tb, u_short adc) ;
78 
79 
80  u_short set_rdo(int rdo1) ;
81 
82 
83 
84 
85  u_char log_level ;
86  u_int events ; // for this instance
87  u_char realtime ; // to disable some checks
88  char want_saved ;
89 
90  u_char id ; // when I have an array of fcs_data_c classes; id=0 is special
91 
92  u_short *dta_p ;
93  u_short *dta_stop ;
94  u_short *dta_start ;
95  int dta_shorts ;
96 
97  u_int bad_error ;
98  u_int err_count ;
99 
100  // streaming specific
101 
102  // count of xings per run entered in the worker thread
103  // and later summed and presented/saved at the end of the run
104 
105  // occupancy
106  u_int adc_xings[FCS_SECTOR_COU][8][32] ; // sector,rdo,channel
107 
108  // for ZS
109  int zs_start(u_short *results) ;
110  u_char mark[8*1024] ;
111 
112 
113  // for a specific instance
114  u_char sector ;
115  u_char rdo ;
116  u_short board_id ;
117 
118  u_int rhic_freq ;
119  u_char fee_state ;
120 
121  // temporary storage for the current board and event
122  u_int version ;
123  u_int hdr_trg_word ;
124  u_int hdr_rhic_counter ;
125  u_short hdr_board_id ;
126  int hdr_sector ;
127  int hdr_rdo ;
128  u_int hdr_det ;
129  u_int hdr_ns ;
130  u_int hdr_dep ;
131  short token ;
132  u_char daq_cmd ;
133  u_char trg_cmd ;
134 
135  u_char trgd_event ;
136 // u_char has_ascii ;
137  char *ascii_p ;
138  int ascii_words ;
139  static u_char ascii_no ;
140 
141  // temprorary storage for the current board, event and for a single channel
142  int ch ; // channel [0..32]
143  int tb_cou ;
144  u_short adc[8*1024] ; // storage for 1 channel
145  int ch_count ; // debugging
146  u_int rhic_start ; // debugging
147  unsigned long long ch_mask_seen ; // debugging
148  int first_tb_cou;
149 
150  // I don't remember what the stuff is? Pre FY19.
151 // int first_rhic_strobe_tick ;
152 // int trigger_tick ;
153 
155  u_char fmt_version ; //1= 16 params,pre 24-Nov-2021; 2=32 params
156  u_char det ;
157  u_char ns ;
158  u_char dep ;
159 
160  u_short params[32] ; // stage params
161 
162  union {
163  struct { // DEP/ADC
164  u_short ped ;
165  u_short gain ;
166  } ped[32] ;
167 
168  struct { // STAGE2 & 3
169  unsigned long long ch_mask ;
170  u_char dsm_delay ;
171  u_char dsm_mode ;
172  u_char dsm_pattern ;
173  } ;
174  } ;
175 
176  u_char s1_delay ; // delay of the strobe_in
177  } ;
178 
179  struct fcs_ped_t {
180  double mean[37] ;
181  double rms[37] ;
182  u_int cou[37] ;
183 
184  u_int bad_4[37] ;
185 
186  double mean_8[37] ;
187  double rms_8[37] ;
188  u_int cou_8[37] ;
189 
190  double tmp_val_8[37] ;
191  u_int tmp_cou_8[37] ;
192 
193  float el_gain[37] ; // electronics gain
194  float et_gain[37] ; // the Et adjustment due to position, from e.g. Akio
195 
196 
197  // loaded into DEP for trigger
198  u_short i_ped[37] ; // integerized, multipled by 8
199  u_short i_gain[37] ; // integerized in the 4.8 (12 bit) form
200  } ;
201 
202  struct rdo_map_t {
203  u_char det ; //0=ECAL,1=HCAL,2=PRE,3=Main
204  u_char ns ; //0=North,1=South
205  u_char dep ; // from 0 ;
206 
207  u_char crate ; // 0..4
208  u_char slot ; // 0..19
209 
210  u_char crt ; // from Akio's file
211  u_char slt ; // from Akio's file
212 
213  struct { // from Akio's file
214  u_short id ;
215  u_char row ;
216  u_char col ;
217  u_char sc_dep ;
218  u_char sc_bra ;
219  u_char sc_add ;
220  u_char sc_sipm ;
221  } ch[32] ;
222 
223  unsigned long long ch_mask ;
224  } ;
225 
226  struct det_map_t {
227  u_char sector ;
228  u_char rdo ;
229  } ;
230 
231 
232  // statics, common to all instalnces
233  static u_int run_number ;
234  static u_int run_type ;
235 
236  // for ZS
237  static float n_sigma ;
238  static float n_sigma_epd ;
239  static float n_sigma_hcal ;
240  static short n_pre ;
241  static short n_post ;
242  static short n_cou ;
243  static char n_mode ; // 0: use rms, 1: fixed threshold in n_sigma
244 
245  // set in send_config, for shared access during data-checking
246  static u_short ht_threshold ;
247  static u_short tb_pre ;
248  static u_short tb_all ;
249 
250 
251  static struct fcs_ped_t ped[FCS_SECTOR_COU][8] ; // sector,rdo
252  static struct rdo_map_t rdo_map[FCS_SECTOR_COU][8] ; // sector,rdo
253  static struct det_map_t det_map[4][2][24] ; // reverse map: det,ns,dep
254  static u_char rdo_map_loaded ; // boolean
255 
256  static int ped_from_cache(const char *fname) ;
257  static int gain_from_cache(const char *fname=0) ;
258  static int load_rdo_map(const char *fname=0) ;
259  static int load_readout_map(const char *fname=0) ;
260  static int load_sc_map(const char *fname=0) ;
261 
262  static u_char fcs_bad_ch_all[FCS_SECTOR_COU][8][34] ;
263  static u_char fcs_bad_ch[8][34] ;
264 
265  static int load_bad_ch(const char *fname=0, int sector=0) ;
266 
267  static const char *stage_labels[32] ;
268  static int stage_params_txt[32] ; // from the params_xx file below
269  static int load_stage_params(int sec1, const char *fname=0) ;
270 
271  // mutex for pedestals but also for statistics
272  static struct statistics_t {
273  float temperature ;
274  float deadtime ;
275  float rx_throttle ;
276  int ht_rate ;
277 // u_int odd_ped[32] ;
278  } statistics[8] ;
279 
280 
281 
282 
283 
284 #ifndef __CINT__
285  static pthread_mutex_t ped_mutex ;
286  static void ped_lock() {
287  pthread_mutex_lock(&ped_mutex) ;
288  } ;
289  static void ped_unlock() {
290  pthread_mutex_unlock(&ped_mutex) ;
291  } ;
292  static void ped_mutex_init() {
293  pthread_mutex_init(&ped_mutex,0) ;
294  } ;
295 #endif
296 
297  static long dep_to_char(int det, int ns, int dep) ;
298 
299 private:
300  u_short set_board_id() ;
301 
302 } ;
303 
304 
305 
306 #endif
307