source: trunk/FACT++/src/FAD.h@ 15474

Last change on this file since 15474 was 15474, checked in by tbretz, 12 years ago
Removed MAX_SOCK
File size: 11.8 KB
Line 
1#ifndef FACT_FAD_H
2#define FACT_FAD_H
3
4//---------------------------------------------------------------
5//
6// FAD internal structures
7//
8//---------------------------------------------------------------
9
10 //
11// Other definitions
12//
13#define MAX_ADDR 0xFF // highest address in Config-RAM
14#define BADDR_ROI 0x00 // Baseaddress ROI-Values
15#define BADDR_DAC 0x24 // Baseaddress DAC-Values
16#define BADDR_CONT_TRIGGER_TIME 0x2C // Baseaddress for the continouus trigger timing.
17#define ADDR_RUNNUMBER 0x2D //
18#define MAX_VAL 65535
19#define MAX_ROIVAL 1024
20#define MAX_DACVAL 65535
21
22#define NChannels 9
23#define NBins 1024
24#define NChips 4
25#define NTemp 4
26#define NDAC 8
27
28//
29// Data structures
30//
31
32typedef struct{
33 int hardID ; //hardware ID
34 int pos_i ; //geometrical positon row
35 int pos_j ; // column
36 int G_APD ; //G-APD identifier
37 double V_op ; //operation voltage
38 int HV_B ; //HV Board
39 int HV_C ; //HV Channel
40 double pos_X ; //geometrical position in pixel units
41 double pos_Y ; //
42} PIX_MAP ;
43
44
45typedef struct {
46
47 uint16_t start_package_flag;
48 uint16_t package_length;
49 uint16_t version_no;
50 uint16_t PLLLCK;
51
52 uint16_t trigger_crc;
53 uint16_t trigger_type;
54 uint32_t trigger_id;
55
56 uint32_t fad_evt_counter;
57 uint32_t REFCLK_frequency;
58
59 uint16_t board_id;
60 uint8_t zeroes;
61 int8_t adc_clock_phase_shift;
62 uint16_t number_of_triggers_to_generate;
63 uint16_t trigger_generator_prescaler;
64
65 uint64_t DNA;
66
67 uint32_t time;
68 uint32_t runnumber;
69
70 int16_t drs_temperature[NTemp];
71
72 uint16_t dac[NDAC];
73
74} __attribute__((__packed__)) PEVNT_HEADER;
75
76typedef struct {
77uint16_t id;
78uint16_t start_cell;
79uint16_t roi;
80uint16_t filling;
81 int16_t adc_data[];
82} __attribute__((__packed__)) PCHANNEL;
83
84
85typedef struct {
86uint16_t package_crc;
87uint16_t end_package_flag;
88} __attribute__((__packed__)) PEVNT_FOOTER;
89
90#define NBOARDS 40 // max. number of boards
91#define NPIX 1440 // max. number of pixels
92#define NTMARK 160 // max. number of timeMarker signals
93//#define MAX_SOCK 280 // NBOARDS * 7
94
95
96typedef union {
97 uint8_t B[8] ; //8 bytes
98 uint16_t S[4] ; //4 short
99 uint32_t I[2] ; //2 int
100 uint64_t L ; //1 long
101} L_WORD ;
102
103typedef union {
104 uint8_t B[4] ; //4 bytes
105 uint16_t S[2] ; //2 short
106 uint32_t I ; //1 int
107} I_WORD ;
108
109
110//---------------------------------------------------------------
111//
112// Data structures
113//
114//---------------------------------------------------------------
115
116typedef struct _EVENT {
117 uint16_t Roi ; // #slices per pixel (same for all pixels)
118 uint16_t RoiTM ; // #slices per pixel (same for all tmarks) [ 0 or Roi ]
119 uint32_t EventNum ; // EventNumber as from FADs
120 uint32_t TriggerNum ; // EventNumber as from FTM
121 uint16_t TriggerType ; // Trigger Type from FTM
122
123 uint32_t NumBoards ; // number of active boards included
124 uint8_t Errors[4] ; // indicator for mismatches
125
126 uint32_t SoftTrig ; // SoftTrigger Info (TBD)
127 uint32_t PCTime ; // epoch
128 uint32_t PCUsec ; // micro-seconds
129
130 uint32_t BoardTime[NBOARDS];//
131
132 int16_t StartPix[NPIX]; // First Channel per Pixel (Pixels sorted according Software ID) ; -1 if not filled
133
134 int16_t StartTM[NTMARK]; // First Channel for TimeMark (sorted Hardware ID) ; -1 if not filled
135
136 int16_t Adc_Data[]; // final length defined by malloc ....
137
138} __attribute__((__packed__)) EVENT ;
139
140
141
142//---------------------------------------------------------------
143
144typedef struct _RUN_HEAD {
145 uint32_t Version ;
146 uint32_t RunType ;
147 uint32_t RunTime ; //unix epoch for first event
148 uint32_t RunUsec ; //microseconds
149 uint16_t NBoard ; //#boards (always 40)
150 uint16_t NPix ; //#pixels (always 1440)
151 uint16_t NTm ; //#TM (always 160)
152 uint16_t Nroi ; //roi for pixels
153 uint16_t NroiTM ; //roi for TM <=0 if TM is empty
154
155//headers of all FAD-boards for first event ==> all FAD configs
156 PEVNT_HEADER FADhead[NBOARDS]; // [ NBoards ] sorted Board Headers (according Hardware ID)
157
158//do we also have info about FTM config we want to add here ???
159} __attribute__((__packed__)) RUN_HEAD ;
160
161
162//---------------------------------------------------------------
163
164typedef struct _RUN_TAIL {
165/* uint32_t nEventsOk ; //how many events were written
166 uint32_t nEventsRej; //how many events were rejected by SW-trig
167 uint32_t nEventsBad; //how many events were rejected by Error
168
169 uint32_t PCtime0 ; //time when first event received
170 uint32_t PCtimeX ; //time when last event received
171
172*/
173//probably more to come ...
174} __attribute__((__packed__)) RUN_TAIL ;
175
176
177
178//---------------------------------------------------------------
179
180#define MAX_RUN 8
181#define MAX_EVT 32768 //don't worry, for events is MAX_RUN*MAX_EVT
182
183typedef void* FileHandle_t ;
184
185typedef struct {
186 uint32_t runId ; //run number
187// uint32_t firstTime ; //epoch of first event received
188// uint32_t firstUsec ; //epoch of first event received
189 uint32_t lastTime ; //time when last event written so far
190 uint32_t closeTime ; //time when run should be closed
191 uint32_t maxEvt ; //maximum number of events to write
192 uint32_t actEvt ; //actual number of events written so far
193 uint32_t procEvt ; //actual number of events processed so far
194 int32_t lastEvt ; //last event of this run read so far
195// uint32_t nextEvt ; //next event number to be written
196// uint32_t waitEvt ; //event that would be ready to be written
197 int16_t fileId ; //<0 never opened, 0=open, >0 closed
198 int16_t procId ; //processing <0 never opened, 0=open, >0 closed
199 int16_t roi0 ; //roi for normal pixels
200 int16_t roi8 ; //roi for pixels8
201
202 FileHandle_t fileHd ; //fileHandle (NULL if not open)
203// int16_t ctrlId[MAX_EVT] ; //index to buffId (sorted list; -1 =end)
204// uint16_t buffId[MAX_EVT] ; //index to mBuffer(buffered raw data)
205} RUN_CTRL ;
206
207
208
209//---------------------------------------------------------------
210
211/*
212typedef struct {
213 int32_t evNum ;
214 int32_t fadNum ;
215 int32_t trgNum ;
216 int32_t trgTyp ;
217 uint32_t runNum ;
218 int32_t fadLen ;
219 int32_t nBoard ;
220 int16_t board[ NBOARDS ];
221 int16_t nRoi ;
222 int16_t nRoiTM ;
223 uint32_t pcTime[2] ;
224// int32_t evtLen ;
225 uint8_t Errors[4] ;
226
227 uint32_t evtCtrl_idx;
228
229 EVENT *fEvent ;
230 PEVNT_HEADER *FADhead; //
231// int8_t *buffer ;
232
233} WRK_DATA ; //internal to eventbuilder
234*/
235
236//---------------------------------------------------------------
237
238
239typedef struct {
240// int frstPtr ; //first used index
241// int lastPtr ; //last used index
242// int mBuffer_idx;//[MAX_EVT*MAX_RUN] ; //index of event in mBuffer
243 int evtStat;//[MAX_EVT*MAX_RUN] ; //status of event:
244 // -1=empty
245 // 1..NBoards reading #Boards
246 // 90-99 : end reading
247 //128-255: processing
248 //256-
249 //201=start processing
250 //299=end processing
251 //901=start writing
252 //999=finished writing
253 //(TO BE REVISED)
254
255 // uint32_t lastRecv;//[MAX_EVT*MAX_RUN] ; //time when last action happened
256
257
258 // ====================================================
259
260 int32_t evNum;
261 int32_t fadNum;
262 int32_t trgNum;
263 int32_t trgTyp;
264 uint32_t runNum;
265 int32_t fadLen;
266 int32_t nBoard;
267 int16_t board[NBOARDS];
268 int16_t nRoi;
269 int16_t nRoiTM;
270 uint32_t pcTime[2] ;
271 uint8_t Errors[4] ;
272
273 uint32_t evtCtrl_idx;
274
275 EVENT *fEvent ;
276 PEVNT_HEADER *FADhead; //
277
278 // ====================================================
279
280
281} EVT_CTRL ; //internal to eventbuilder
282
283//---------------------------------------------------------------
284
285// FIXME: This doesn't neet to be here... it is inlcuded in all
286// data processors
287
288#include <netinet/in.h>
289
290typedef struct {
291 struct sockaddr_in sockAddr ;
292 int sockDef ; //<0 not defined/ ==0 not to be used/ >0 used
293} FACT_SOCK ; //internal to eventbuilder
294
295
296//---------------------------------------------------------------
297
298typedef struct {
299
300 //some info about what happened since start of program (or last 'reset')
301 uint32_t reset ; //#if increased, reset all counters
302 uint32_t numRead[NBOARDS] ; //how often succesfull read from N sockets per loop
303
304 uint64_t gotByte[NBOARDS] ; //#Bytes read per Board
305 uint32_t gotErr[NBOARDS] ; //#Communication Errors per Board
306 uint32_t evtGet; //#new Start of Events read
307 uint32_t evtTot; //#complete Events read
308 uint32_t evtErr; //#Events with Errors
309 uint32_t evtSkp; //#Events incomplete (timeout)
310
311 uint32_t procTot; //#Events processed
312 uint32_t procErr; //#Events showed problem in processing
313 uint32_t procTrg; //#Events accepted by SW trigger
314 uint32_t procSkp; //#Events rejected by SW trigger
315
316 uint32_t feedTot; //#Events used for feedBack system
317 uint32_t feedErr; //#Events rejected by feedBack
318
319 uint32_t wrtTot; //#Events written to disk
320 uint32_t wrtErr; //#Events with write-error
321
322 uint32_t runOpen; //#Runs opened
323 uint32_t runClose; //#Runs closed
324 uint32_t runErr; //#Runs with open/close errors
325
326
327 //info about current connection status
328 uint8_t numConn[NBOARDS] ; //#Sockets succesfully open per board
329
330} __attribute__((__packed__)) EVT_STAT ; //EventBuilder Status
331
332typedef struct {
333 //info about status of the main threads
334 int32_t readStat ; //read thread
335 int32_t procStat ; //processing thread(s)
336 int32_t writStat ; //write thread
337
338 //info about (current state of) the buffer
339 int32_t bufNew ; //# incomplete events in buffer
340 int32_t bufEvt ; //# complete events in buffer
341 int32_t bufTot ; //# total events currently in buffer
342 int32_t maxEvt ; //# maximum events in buffer past cycle
343 int32_t xxxEvt ; //# maximum events ever in buffer
344 uint64_t totMem; //# Bytes available in Buffer
345 uint64_t usdMem; //# Bytes currently used
346 uint64_t xxxMem; //max # Bytes ever used **
347 uint64_t maxMem; //max # Bytes used during past cycle
348
349 //counters
350 int32_t evtSkip ; //# incomplete Events skipped (timeout)
351 int32_t evtWrite ; //# Events written (or flushed if noWrite)
352 int32_t evtErr ; //# Events with errors
353 int32_t badRoiE; //# boards with wrong roi (inconsistent in event)
354 int32_t badRoiR; //# boards with wrong roi (inconsistent in run)
355 int32_t badRoiB; //# boards with wrong roi (inconsistent in board)
356 int32_t badRoi[NBOARDS]; //# boards with wrong roi
357
358 //rates
359 int32_t deltaT ; //time in milli-seconds for rates
360 int32_t rateNew ; //#New start events recieved
361 int32_t rateWrite ; //#Complete events written (or flushed)
362
363 //connections
364 int8_t numConn[NBOARDS] ; //#connections per board (at the moment)
365 //int32_t errConn[NBOARDS] ; //#I/O errors per board (counter)
366 int32_t rateBytes[NBOARDS]; //#Bytes read this cycle **
367 int64_t totBytes[NBOARDS]; //#Bytes read (counter)
368
369
370 // ** // if counter and rates exist, do only update the rates in
371 // ** // real time;
372 // ** // counters will be updated only once per cycle based on rates
373
374} __attribute__((__packed__)) GUI_STAT ; //EventBuilder Status
375
376#endif
Note: See TracBrowser for help on using the repository browser.