otsdaq-mu2e-stm  5.02.01
dataVars.hh
1 
5 #ifndef DATAVARS_hh
6 #define DATAVARS_hh
7 
8 #include <iostream>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <bits/stdc++.h>
12 
13 // Hex reader
14 #include "STMDAQ-TestBeam/utils/Hex.hh"
15 
16 // XML interface
17 #include "STMDAQ-TestBeam/utils/xml.hh"
18 #include "STMDAQ-TestBeam/utils/EnvVars.hh"
19 
20 #ifndef DATAVARS_hh_DEFINED
21 #define DATAVARS_hh_DEFINED
22 class dataVars;
23 #endif
24 
25 // Max int16_t value
26 static const uint INT16_T_MAX = 32767;
27 // Max uint16_t value
28 static const uint16_t UINT16_T_MAX = 0xFFFF;
29 // Max uint32_t value
30 static const uint32_t UINT32_T_MAX = 0XFFFFFFFF;
31 
32 // Number of data channels
33 static const int CHNUM = 2;
34 // Signal HPGE data as CHANNEL 0
35 static const int HPGE = 0;
36 // Signal LABR data as CHANNEL 1
37 static const int LABR = 1;
38 
39 // Signal firmware IP/PORT with 0
40 static const int FW = 0;
41 // Signal software IP/PORT with 1
42 static const int SW = 1;
43 // Signal DQM IP/PORT with 2
44 static const int DQM = 2;
45 
46 // Maxiumum packet size in bytes
47 // (Maximum packet size - UDP checksum)
48 static const uint16_t MAX_PACKET_SIZE = 8198;
49 // Max length of packet in number of int16_t values
50 static const uint16_t MAX_PACKET_LEN = MAX_PACKET_SIZE/2;
51 
52 // // The theoretical maximum udp datagram size
53 // static const uint32_t MAX_UDP_SIZE = 65535;
54 // // The optimised SO_RCVBUF size
55 // static const uint64_t RCVBUF_SZ = 1e5*pow(2,21);
56 // // The optimised SO_SNDBUF soize
57 // static const uint64_t SNDBUF_SZ = 1e2*pow(2,21);
58 
59 // // Recvfrom non-blocking timeout time
60 // static const uint TIMEOUT_SECS = 0; // Secs
61 // static const uint TIMEOUT_USECS = 500; // usecs
62 // // The number of non-blocking timeouts to wait before exit
63 // static const uint TIMEOUT_MAX = 5e7;
64 
65 // Number of slices per packet
66 // NOT TO BE HARD-CODED. JUST UNTIL ERDEM FIXES THE SLICES.
67 static const uint slicesPerPacket = 2;
68 
69 static const uint on_spill_len = 510;
70 static const uint on_spill_size = 2*on_spill_len;
71 
72 static const uint off_spill_len = 30000;
73 static const uint off_spill_size = 2*off_spill_len;
74 
75 // Firmware packet header size in bytes
76 static const uint fw_pHdr_Size = 6;
77 // Firmware packet header length
78 static const uint fw_pHdr_Len = fw_pHdr_Size/2;
79 // Firmware packet header elements
80 static const uint fw_pHdr_pNum1 = 0; // Packet number 2
81 static const uint fw_pHdr_pNum2 = 1; // Packet number 1
82 static const uint fw_pHdr_end = 2; // Packet checksum
83 static const uint16_t fw_pHdr_end_data = 0xFFEE;
84 
85 // 0xDEADBEEF
86 static const uint16_t DEAD = 0xDEAD;
87 static const uint16_t BEEF = 0xBEEF;
88 
89 // Firmware trigger header size in bytes
90 static const uint fw_tHdr_Size = 64;
91 // Firmware trigger header length
92 static const uint fw_tHdr_Len = fw_tHdr_Size/2;
93 
94 struct test{
95  static constexpr int testArr[2] = {1,2};
96 };
97 
98 // Firmware trigger header elements
99 struct fw_tHdr{
100 
101  // Size in bytes of the trigger header
102  static const uint size = fw_tHdr_Size;
103  // Length in int16_t values of the trigger header
104  static const uint len = fw_tHdr_Len;
105 
106  // Index positions of trigger header components
107  static const uint HdrStart_0 = 0; // 0xCAFE
108  static const uint HdrStart_1 = 1; // 0xBBBB
109  static const uint HdrStart_2 = 2; // 0xAAAA
110  static const uint HdrStart_3 = 3; // 0xCAFE
111  static const uint ADCclk_0 = 4; // ADC Clock (75 MHz) 0
112  static const uint ADCclk_1 = 5; // ADC Clock (75 MHz) 1
113  static const uint ADCclk_2 = 6; // ADC Clock (75 MHz) 2
114  static const uint ADCclk_3 = 7; // ADC Clock (75 MHz) 3
115  static const uint EvNum_0 = 8; // Event Number 0
116  static const uint EvNum_1 = 9; // Event Number 1
117  static const uint EvNum_2 = 10; // Event Number 2
118  static const uint EWT_0 = 11; // DTC Event Window Tag 0
119  static const uint EWT_1 = 12; // DTC Event Window Tag 1
120  static const uint EWT_2 = 13; // DTC Event Window Tag 2
121  static const uint EM_0 = 14; // DTC Event Mode 0
122  static const uint EM_1 = 15; // DTC Event Mode 1
123  static const uint EM_2_DRTDC = 16; // DTC Event Mode 2 + Delivery Ring TDC
124  static const uint EvStart = 17; // Event Start Offset
125  static const uint EvInPacket = 18; // Portion of event in packet
126  static const uint Beef = 19; // 0xBEEF
127  static const uint SubRunNum_0 = 20; // Incrementing subrun number from FW 1
128  static const uint SubRunNum_1 = 21; // Incrementing subrun number from FW 2
129  static const uint ZSflag_PreVal = 22; // ZS flag + prescale value
130  static const uint EvLen = 23; // Total length of event
131  static const uint RunNum_0 = 24; // Run number from DCS write 1
132  static const uint RunNum_1 = 25; // Run number from DCS write 2
133  static const uint RunNum_2 = 26; // Run number from DCS write 3
134  static const uint RunNum_3 = 27; // Run number from DCS write 4
135  static const uint Ch_DTCclk_0 = 28; // Channel [0/1] + DTC Clock (200 MHz) 1
136  static const uint DTCclk_1 = 29; // DTC Clock (200 MHz) 1
137  static const uint DTCclk_2 = 30; // DTC Clock (200 MHz) 2
138  static const uint DTCclk_3 = 31; // DTC Clock (200 MHz) 3
139 
140  // Size in bytes of the header end
141  static const uint HdrStart_size = 8;
142  // Length in int16_t values of the header end
143  static const uint HdrStart_len = HdrStart_size/2;
144  // Starting index of the header end
145  static const uint HdrStart_start = 0;
146 
147  // Trigger header end data
148  static const int16_t HdrStart_data[HdrStart_len];
149 
150 };
151 
152 // Define trigger header struct
153 const fw_tHdr tHdr_vars;
154 
155 // Struct containing experimental configuration info from xml
156 struct expConfig{
157 
158  // Accelerator clock frequency
159  double trigger_time_clock; // MHz
160  // Macropulse width
161  double macropulse_width; // ms
162  // Macropulse frequency
163  double macropulse_freq; // Hz
164 
165  // ADC clock frequency
166  double adc_time_clock; // MHz
167  // Sample period of ADC (microsec)
168  double adc_time_clock_period; // us
169 
170  // ADC offset clock frequency
171  double adc_offset_time_clock; // MHz
172 
173  // ADC prescale
174  uint16_t prescale;
175 
176  // External mode ADC offset
177  uint32_t ext_ADC_offset; // Multiple of fADCoffset
178  // Slice length - external mode
179  uint32_t ext_slice_length; // Number of int16_t values
180  // Number of slices - external mode
181  uint16_t ext_slice_num;
182 
183  // The time T after a trigger to wait for a new trigger
184  // before switching to external mode
185  uint32_t ext_trig_timeout;
186 
187  // The offset in time to wait after external mode
188  // before sending the first internal trigger.
189  uint32_t ext_int_delay;
190 
191  // The number of internal triggers to generate.
192  uint16_t int_trig_num;
193  // Internal mode ADC offset
194  uint32_t int_ADC_offset; // Multiple of fADCoffset
195  // Slice length - internal mode
196  uint32_t int_slice_length; // Number of int16_t values
197  // Number of slices - internal mode
198  uint16_t int_slice_num;
199 
200  // ADC sampling time in external mode
201  double ext_sample_time; // us
202  // ADC sampling time in internal mode
203  double int_sample_time; // us
204 
205 
206 
207 };
208 
209 class dataVars{
210 
211 public:
212 
213  // Standard constructor - shouldn't be used
214  dataVars();
215 
216  // Set experimental configuration values from xml
217  expConfig getXMLvalues(expConfig exp);
218 
219  // Check experimental configuation values from xml
220  int checkExpConfig(expConfig exp);
221 
222  // Form uin32_t out of 2 x int16_t
223  uint32_t make_uint32_t(int16_t p0, int16_t p1);
224 
225  // Form uin64_t out of 4 x int16_t
226  uint64_t make_uint64_t(int16_t p0, int16_t p1, int16_t p2, int16_t p3);
227 
228  // Split uin32_t into 2 x int16_t
229  int16_t* split_uint32_t(uint32_t value);
230 
231  // Split uin64_t into 4 x int16_t
232  int16_t* split_uint64_t(uint64_t value);
233 
234  // Get just the event number from the event header
235  uint64_t get_event_number(int16_t *data, uint64_t hdr_start_loc);
236 
237  // Get just the EWT from the event header
238  uint64_t get_EWT(int16_t *data, uint64_t hdr_start_loc);
239 
240  // Check the end of a packet for repeated 0xDEADBEEF
241  uint16_t check_dead_beef(int16_t* data, uint64_t packet_start, uint16_t leftInPacket);
242 
243  // Data for a single event
244  struct event{
245  // Data size
246  uint16_t size = 0;
247  // Data array
248  int16_t* data;
249  // // Data size
250  // uint16_t size = fw_tHdr_Size + off_spill_size;
251  // // Data array
252  // int16_t data[fw_tHdr_Len + off_spill_len] = {};
253 
254 
255  };
256 
257  int16_t tpacket[MAX_PACKET_LEN] = {};
258  // int16_t tevent[MAX_UDP_SIZE/2] = {};
259 
260  // // Data for a single event
261  // struct tevent{
262  // // Data size
263  // uint16_t size = 10;
264  // // Data array
265  // int16_t data[5] = {};
266  // };
267 
268  // Data for a single on-spill event
269  struct on_event{
270  // Data size
271  uint16_t size = fw_tHdr_Size + on_spill_size;
272  // Data array
273  int16_t data[fw_tHdr_Len + on_spill_len] = {};
274  };
275 
276  // Data for a single off-spill event
277  struct off_event{
278  // Total payload size (kb)
279  uint16_t size = 0;
280  // Event number
281  uint64_t number = 0;
282  // Event length
283  uint16_t length = 0;
284  // Data array
285  int16_t data[fw_tHdr_Len + off_spill_len] = {};
286  };
287 
288  // Data for a single prescaled event (header only)
289  struct ps_hdr_event{
290  // Data size
291  uint16_t size = fw_tHdr_Size;
292  // Data array
293  int16_t data[fw_tHdr_Len] = {};
294  };
295 
296 
297 
298 private:
299 
300 };
301 
302 #endif
Definition: dqm.hh:51
Definition: data.hh:4
Definition: dataVars.hh:94