StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
itpcInterpreter.h
1 #ifndef _ITPC_INTERPRETER_
2 #define _ITPC_INTERPRETER_
3 
4 #include <sys/types.h>
5 #include <stdio.h>
6 #include <I386/atomic.h>
7 
8 class itpcData ;
9 
10 #define ERR_UNKNOWN 0
11 #define ERR_DIFFERENT_FEE_IDS 1
12 
14 {
15 public:
16 
17  itpcInterpreter() ;
18 
19  ~itpcInterpreter() {;} ;
20 
21  FILE *fout ; // as stdout
22 
23  void run_start(u_int run) ;
24  void run_stop() ;
25  void start_event(u_int bytes) ;
26  void stop_event() ;
27 
28  void fee_dbase(const char *fname=0) ;
29 
30 
31  int rdo_scan_top(u_int *ddata, int words) ; // new!
32 
33  int ana_send_config(u_int *data, u_int *data_end) ;
34  int ana_pedestal(u_int *data, u_int *data_end) ;
35  int ana_triggered(u_int *data, u_int *data_end) ;
36 
37  int rdo_scan(u_int *ddata, int words) ;
38 
39 
40  u_int *fee_scan(u_int *start, u_int *end) ;
41  u_int *sampa_lane_scan(u_int *start, u_int *end) ;
42  u_int *sampa_ch_hunt(u_int *start, u_int *end) ;
43  int sampa_ch_scan() ;
44 
45  void run_err_add(int rdo1, int type) ;
46 
47  // filled by client
48  int id ;
49  int dbg_level ;
50  int realtime ; // running in realtime
51  u_int run_number ;
52  int sector_id ;
53  int rdo_id ;
54 
55  u_int evt_status ;
56 
57  u_int status ;
58  u_int evt_bytes ;
59  u_int word_ix ;
60  u_int evt_ix ;
61 
62  u_int fee_evt_cou ; // events with FEEs
63 
64  enum s_type {S_IDLE, S_FEE_ASCII, S_FEE_ASCII_END,S_FEE_PORT, S_TRIGGER, S_FEE_END_A, S_FEE_END_B, S_FEE_END_HDR} ;
65  s_type state ;
66 
67  itpcData *ped_c ;
68 
69  u_int evt_err[8] ; // zapped before every event, logged after
70 
71  //run errors, for all RDOs, for all workers!
72  static atomic_t run_errors[4][16] ;
73 
74  // various variables filled in as we go
75  u_int rdo_wire1_id ;
76  struct fee_t {
77  u_int padplane_id ;
78  u_int wire1_id ;
79  u_int send_config_errs ;
80  u_int event_errs ;
81  u_int pedestal_errs ;
82  u_int ch_errs ;
83  } fee[17] ; // index is RDO port starting from 1!
84 
85  // FPGA versions
86  u_int fpga_fee_v_all ;
87 
88  // electronics format versions
89  int rdo_version ;
90  int expected_rdo_version ;
91  int fee_version ;
92  int expected_fee_version ;
93 
94  // filled in fee_scan
95  int fee_port ; // from 1..16
96  u_int fee_id ; // padplane id: 0..63 (although 55 is the last valid value)
97  u_int fee_bx ;
98 
99  // filled in sampa_lane_scan
100  u_int found_ch_mask ;
101  int sampa_bx ; // for cross checks
102  int sampa_id ;
103  int sampa_ch ; //0..31
104  int fee_ch ; //0..63
105 
106  // used by sampa_ch_scan
107  int tb_cou ;
108  u_short tb_buff[1024] ;
109 
110  int d_cou ;
111 
112 
113  // for various ASCII packets from RDO or FEE
114  int ascii_cou ;
115  char ascii_dta[1024] ;
116 
117 
118  static struct itpc_config_t {
119  struct {
120  int rdo_id ;
121  u_int wire1 ;
122  u_int fee_mask ; // if 0: whole RDO is masked!
123  int phase ;
124  int fee_count ;
125 
126  struct {
127  u_int wire1 ;
128  u_char padplane_id ;
129  u_char sampa_version ; // 2, 3 or 4
130  u_char lane_dead_mask ; // 4 bits; normally 0
131  u_char sampa_dead_mask ; // 2 bits; normally 0
132  } fee[17] ; // index is port (from 1)
133 
134 
135  } rdo[4] ; // index is rb/gtp (from 0)
136 
137  } itpc_config[25] ; // index is sector (from 1)
138 
139  static int itpc_fee_map[24][4][16] ;
140  static u_int ifee_mask(int sec1, int rdo1) ;
141  static int fee_map_check() ;
142 
143  static int parse_config(const char *fname) ;
144  static int parse_default() ;
145 
146 } ;
147 
148 
149 #endif
150