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 |
|
---|
32 | typedef 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 |
|
---|
45 | typedef 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 |
|
---|
76 | typedef struct {
|
---|
77 | uint16_t id;
|
---|
78 | uint16_t start_cell;
|
---|
79 | uint16_t roi;
|
---|
80 | uint16_t filling;
|
---|
81 | uint16_t adc_data[];
|
---|
82 | } __attribute__((__packed__)) PCHANNEL;
|
---|
83 |
|
---|
84 |
|
---|
85 | typedef struct {
|
---|
86 | uint16_t package_crc;
|
---|
87 | uint16_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 |
|
---|
96 | typedef 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 |
|
---|
103 | typedef 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 |
|
---|
116 | typedef struct {
|
---|
117 | uint16_t Roi ; // #slices per pixel (same for all pixels and tmarks)
|
---|
118 | uint32_t EventNum ; // EventNumber as from FTM
|
---|
119 | uint16_t TriggerType ; // Trigger Type from FTM
|
---|
120 |
|
---|
121 | uint32_t SoftTrig ; // SoftTrigger Info (TBD)
|
---|
122 | uint32_t PCTime ; // when did event start to arrive at PC
|
---|
123 |
|
---|
124 | uint32_t BoardTime[NBOARDS];//
|
---|
125 |
|
---|
126 | int16_t StartPix[NPIX]; // First Channel per Pixel (Pixels sorted according Software ID) ; -1 if not filled
|
---|
127 |
|
---|
128 | int16_t StartTM[NTMARK]; // First Channel for TimeMark (sorted Hardware ID) ; -1 if not filled
|
---|
129 |
|
---|
130 | uint16_t Adc_Data[1]; // final length defined by malloc ....
|
---|
131 |
|
---|
132 | } EVENT ;
|
---|
133 |
|
---|
134 |
|
---|
135 |
|
---|
136 | //---------------------------------------------------------------
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 | typedef struct {
|
---|
142 | uint32_t Version ;
|
---|
143 | uint32_t RunType ;
|
---|
144 | uint16_t NBoard ;
|
---|
145 | uint16_t NPix ;
|
---|
146 | uint16_t NTm ;
|
---|
147 | uint16_t Nroi ;
|
---|
148 |
|
---|
149 | //headers of all FAD-boards for first event ==> all FAD configs
|
---|
150 | PEVNT_HEADER *FADhead; // [ NBoards ] sorted Board Headers (according Hardware ID)
|
---|
151 |
|
---|
152 | //do we also have info about FTM config we want to add here ???
|
---|
153 | } RUN_HEAD ;
|
---|
154 |
|
---|
155 |
|
---|
156 | //---------------------------------------------------------------
|
---|
157 |
|
---|
158 |
|
---|
159 | typedef struct {
|
---|
160 | uint32_t nEventsOk ; //how many events were written
|
---|
161 | uint32_t nEventsRej; //how many events were rejected by SW-trig
|
---|
162 | uint32_t nEventsBad; //how many events were rejected by Error
|
---|
163 |
|
---|
164 | uint32_t PCtime0 ; //time when first event received
|
---|
165 | uint32_t PCtimeX ; //time when last event received
|
---|
166 |
|
---|
167 |
|
---|
168 | //probably more to come ...
|
---|
169 | } RUN_TAIL ;
|
---|
170 |
|
---|
171 |
|
---|
172 |
|
---|
173 | //---------------------------------------------------------------
|
---|
174 |
|
---|
175 | #define MAX_RUN 256
|
---|
176 | #define MAX_EVT 32768 //don't worry, for events is MAX_RUN*MAX_EVT
|
---|
177 |
|
---|
178 | typedef void* FileHandle_t ;
|
---|
179 |
|
---|
180 | typedef struct {
|
---|
181 | uint32_t runId ; //run number
|
---|
182 | uint32_t lastTime ; //time when last event written so far
|
---|
183 | uint32_t closeTime ; //time when run should be closed
|
---|
184 | uint32_t nextEvt ; //next event number to be written
|
---|
185 | uint32_t waitEvt ; //event that would be ready to be written
|
---|
186 | int32_t fileId ; //<0 never opened, 0=open, >0 closed
|
---|
187 | FileHandle_t fileHd ; //fileHandle (NULL if not open)
|
---|
188 | int16_t ctrlId[MAX_EVT] ; //index to buffId (sorted list; -1 =end)
|
---|
189 | uint16_t buffId[MAX_EVT] ; //index to mBuffer(buffered raw data)
|
---|
190 | } RUN_CTRL ;
|
---|
191 |
|
---|
192 |
|
---|
193 |
|
---|
194 | //---------------------------------------------------------------
|
---|
195 |
|
---|
196 |
|
---|
197 | typedef struct {
|
---|
198 | int32_t evNum ;
|
---|
199 | int32_t runNum ;
|
---|
200 | int32_t fadLen ;
|
---|
201 | int32_t nBoard ;
|
---|
202 | int16_t board[ NBOARDS ];
|
---|
203 | int32_t nRoi ;
|
---|
204 | int32_t pcTime ;
|
---|
205 | int32_t evtLen ;
|
---|
206 | EVENT *fEvent ;
|
---|
207 | PEVNT_HEADER *FADhead; //
|
---|
208 |
|
---|
209 | } WRK_DATA ; //internal to eventbuilder
|
---|
210 |
|
---|
211 |
|
---|
212 | //---------------------------------------------------------------
|
---|
213 |
|
---|
214 |
|
---|
215 | typedef struct {
|
---|
216 | int frstPtr ; //first used index
|
---|
217 | int lastPtr ; //last used index
|
---|
218 | int evtBuf[MAX_EVT*MAX_RUN] ; //index of event in mBuffer
|
---|
219 | int evtStat[MAX_EVT*MAX_RUN] ; //status of event:
|
---|
220 | // -1=empty
|
---|
221 | // 1..NBoards reading #Boards
|
---|
222 | // 90-99 : end reading
|
---|
223 | //128-255: processing
|
---|
224 | //256-
|
---|
225 | //201=start processing
|
---|
226 | //299=end processing
|
---|
227 | //901=start writing
|
---|
228 | //999=finished writing
|
---|
229 | //(TO BE REVISED)
|
---|
230 |
|
---|
231 | int pcTime[MAX_EVT*MAX_RUN] ; //time when last action happened
|
---|
232 | } EVT_CTRL ;
|
---|
233 |
|
---|
234 | //---------------------------------------------------------------
|
---|
235 |
|
---|
236 |
|
---|
237 | typedef struct {
|
---|
238 | struct sockaddr_in sockAddr ;
|
---|
239 | int sockDef ; //<0 not defined/ ==0 not to be used/ >0 used
|
---|
240 | } FACT_SOCK ;
|
---|
241 |
|
---|
242 |
|
---|
243 | #endif
|
---|