StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
itpcFCF.h
1 #ifndef _ITPC_FCF_H_
2 #define _ITPC_FCF_H_
3 
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <getopt.h>
7 #include <sys/types.h>
8 #include <stdlib.h>
9 #include <time.h>
10 #include <arpa/inet.h>
11 #include <sys/time.h>
12 
13 
14 //#include <rtsLog.h> // for my LOG() call
15 //#include <rtsSystems.h>
16 
17 // this needs to be always included
18 //#include <DAQ_READER/daqReader.h>
19 //#include <DAQ_READER/daq_dta.h>
20 
21 //#include <trgDataDefs.h>
22 //#include "trgConfNum.h"
23 
24 // only the detectors we will use need to be included
25 // for their structure definitions...
26 //#include <DAQ_TPX/daq_tpx.h>
27 //#include <DAQ_TPX/tpxFCF_flags.h>
28 
29 //#include <DAQ_ITPC/daq_itpc.h>
30 //#include <DAQ_ITPC/itpcCore.h>
31 #include <DAQ_ITPC/itpcPed.h>
32 //#include <DAQ_ITPC/itpcInterpreter.h>
33 //#include <DAQ_ITPC/itpc_rowlen.h>
34 
35 struct daq_dta ;
36 
37 class itpc_fcf_c : public itpcPed {
38 public:
39  itpc_fcf_c() ;
40  ~itpc_fcf_c() ;
41 
42 
43 
44  void run_start() ;
45  void run_stop() ;
46  void event_start() ; // mostly to zap some debugging counters
47 
48  int do_ch(int fee_id, int fee_ch, u_int *data, int words) ;
49  int do_ch_sim(int row, int pad, u_short *tb_buff, u_short *track_id) ;
50 
51  int do_fcf(void *storage, int bytes) ;
52 
53 
54  int init(int sector, const char *fname=0) ;
55  int init(daq_dta *gain) ;
56 
57  static int get_bad(int sec1, int row1, int pad1) ;
58  static float get_gain(int sec1, int row1, int pad1) ;
59  static void set_gain(int sec1, int row1, int pad1, float gain) ;
60 
61  static float get_t0(int sec1, int row1, int pad1) ;
62 
63  static u_char get_flags(int sec1, int row1, int pad1) ;
64  static void set_flags(int sec1, int row1, int pad1, u_char flags) ;
65 
66  void zap_fee(int sec1, int rdo1, int port1) ;
67 
68  static int fcf_decode(unsigned int *p_buff, daq_cld *dc, unsigned int version) ;
69  static int fcf_decode(unsigned int *p_buff, daq_sim_cld_x *dc, unsigned int version) ;
70 
71  int my_id ;
72  int version ;
73  int sector_id ;
74  int offline ;
75 
76  int words_per_cluster ;
77 
78  // statistics
79 
80  struct f_stat_t {
81  double tm[10] ;
82  u_int evt_cou ;
83 
84  u_int toobigs ;
85 
86  u_int s1_found ; // storage during 1 event
87 
88  u_int max_s1_found ;
89  u_int max_s1_len ;
90  u_int max_blob_cou ;
91  } f_stat ;
92 
93  int det_type ; // TPC=0, ITPC=1, OTHER=2
94  int y_is_timebin ; // 1=normal cluster finder ("across-rows") (x=pad,y=timebin,slice=row)
95  // 0=across timebin ("across-timebins") (x=pad,y=row,slice=timebin)
96 
97  int max_x ; // max pad ever e.g. 182 TPC or 120 ITPC or any other number for OTHER
98  int max_y ; // max timebin or row ever e.g. 512
99  int max_slice ; // rows or timebins e.g. 40 ITPC, 45 TPC or 512 for across-timebin
100 
101  int pad_to_x(int pad, int y) ;
102 
103  int x_max(int slice, int y) ;
104 private:
105 
106  static const int MAX_SEC = 24 ; // sectors; stay as a constant
107 
108 // static const int MAX_ROW = 40 ; // row or timebin; 40,45,512
109 // static const int MAX_PAD = 120 ; // pad or pad; 182, 120
110 // static const int MAX_TB = 512 ; // timebin or row; 512, 40, 45
111 
112  static const int MAX_TB_EVER = 512 ; // for some simple allocations
113  static const int MAX_BLOB = 16*1024 ; // possibly realloced dynamically?
114  static const int MAX_PEAKS = 1000 ; // per blob! This should not be dramatically high
115  static const int MAX_BLOB_SIZE = 64*1024 ;
116 
117  // used for actual physical ADC channels, mostly for the gain correction; big enough for TPX and iTPC!
118  static const int MAX_PHYS_ROW = 45 ;
119  static const int MAX_PHYS_PAD = 182 ;
120 
121 
122 
123 // static int rowlen[45+1] ; // depends on ITPC vs TPX; but is _constant_ 120 or 182 for timebin-across
124  // so I will dimension it for the largest case and that is 45!
125 
126  int x_min(int slice, int y) ;
127  int y_max() ;
128  int y_min() ;
129 
130 
131 
132 
133  // ************ gains and flags
134  // ACTUAL: physical electronics gains!!!
135  struct gain_rp_t {
136  float gain ;
137  float t0 ;
138  u_char flags ;
139  } ;
140 
141  // I keep and allocate statically for ALL sectors
142  static gain_rp_t *sec_gains[MAX_SEC+1] ;
143 
144  gain_rp_t *get_gain(int phys_row, int phys_pad) ;
145 
146  int use_gain ;
147 
148  // ********* input stage (do_ch)
149  // for do_ch and itpc unpacking
150  u_short tb_buff[MAX_TB_EVER] ; // where I stohre the y data -- just max it out
151 
152  // this is where we store unpacked data from the detector or user input
153  int s1_data_length ;
154  struct rp_t {
155  u_short s1_len ;
156  u_short s1_data[] ;
157  } ;
158 
159  u_short *row_pad_store ;
160 
161  inline struct rp_t *get_row_pad(int row, int pad) ;
162 
163  // ********** stage 1
164  u_short blob_ix[MAX_BLOB] ;
165 
166  struct blob_t {
167  int cou ;
168  int merges ;
169 
170  u_short seq_cou ;
171  u_short p1, p2 ;
172  u_short t1, t2 ;
173 
174  u_short flags ;
175 
176  float tot_charge ;
177  u_short pixels ;
178 
179  } blob[MAX_BLOB] ;
180 
181  u_short blob_cou ;
182 
183  // *********** stage 2 -- various extents
184 
185 
186  // *********** stage 3
187 
188  short smooth_dta[MAX_BLOB_SIZE] ; // for smoothing
189  u_short *track_dta ; // for Offline simulation
190 
191  struct {
192  u_short i ;
193  u_short j ;
194  u_short adc ;
195  } peaks[MAX_PEAKS+1] ;
196 
197  // misc
198  u_int blob_id ; // for debugging
199 
200  // final output
201  u_int *out_store ;
202  int max_out_bytes ;
203 
204 
205 
206 
207 
208  int do_blobs_stage1(int row) ;
209  int do_blobs_stage2(int row) ;
210  int do_blobs_stage3(int row) ;
211 
212 
213  int do_row_check(int row) ;
214 
215 
216 } ;
217 
218 #endif