]>
Commit | Line | Data |
---|---|---|
f3a800f8 | 1 | /* |
2 | dateStream.c | |
3 | ============ | |
4 | ||
5 | Utility to simulate a DATE raw data stream using a given set of raw | |
6 | data files and a configuration file. | |
7 | ||
8 | Revision history: | |
9 | ||
10 | V01.00 4/05/2004 RD Created | |
11 | V01.01 25/10/2005 RD Support added for timestamp | |
12 | V01.02 4/04/2006 RD Support for CDH | |
13 | V01.03 24/05/2006 RD Added "Direct disk access" option | |
14 | */ | |
15 | #define VID "1.03" | |
16 | ||
17 | #include <stdio.h> | |
18 | #include <stdlib.h> | |
19 | #include <errno.h> | |
20 | #include <assert.h> | |
21 | #include <ctype.h> | |
22 | #include <time.h> | |
21e7df44 | 23 | #include <cassert> |
f3a800f8 | 24 | #include "event.h" |
25 | ||
26 | #define DESCRIPTION "DATE raw data stream simulator" | |
27 | #ifdef AIX | |
28 | static | |
29 | #endif | |
30 | char fileHandlerIdent[]= "@(#)""" __FILE__ """: """ DESCRIPTION \ | |
31 | """ """ VID """ """ \ | |
32 | """ compiled """ __DATE__ """ """ __TIME__; | |
33 | ||
34 | #define DBG_BASE if ( debug > 0 ) | |
35 | #define DBG_DETAILED if ( debug > 1 ) | |
36 | #define DBG_VERBOSE if ( debug > 2 ) | |
37 | ||
38 | #ifndef TRUE | |
39 | # define TRUE (0 == 0) | |
40 | #endif | |
41 | #ifndef FALSE | |
42 | # define FALSE (0 == 1) | |
43 | #endif | |
44 | ||
45 | const char *myName; | |
46 | int debug; | |
47 | FILE *outF; | |
a8bf0b36 | 48 | typedef enum { unknown, ldc, gdc } workingAsType; |
49 | typedef enum { collider, fixedTarget } workingModeType; | |
50 | workingAsType workingAs; | |
51 | workingModeType workingMode; | |
f3a800f8 | 52 | struct ldcDescriptorStruct { |
53 | eventLdcIdType id; | |
54 | struct ldcDescriptorStruct *next; | |
55 | } *ldcsHead, *ldcsTail; | |
56 | void *eventsHead, *eventsTail; | |
57 | struct gdcEventDescriptorStruct { | |
58 | struct ldcEventDescriptorStruct *head; | |
59 | struct ldcEventDescriptorStruct *tail; | |
60 | struct gdcEventDescriptorStruct *next; | |
61 | struct eventHeaderStruct header; | |
62 | int loaded; | |
63 | } *currGdc; | |
64 | struct ldcEventDescriptorStruct { | |
65 | struct equipmentEventDescriptorStruct *head; | |
66 | struct equipmentEventDescriptorStruct *tail; | |
67 | struct ldcEventDescriptorStruct *next; | |
68 | eventLdcIdType id; | |
69 | struct eventHeaderStruct header; | |
70 | int loaded; | |
71 | } *currLdc; | |
72 | struct equipmentEventDescriptorStruct { | |
73 | struct equipmentEventDescriptorStruct *next; | |
74 | equipmentIdType id; | |
75 | struct payloadDescriptorStruct *payload; | |
76 | struct equipmentHeaderStruct header; | |
77 | } *currEvent; | |
78 | struct payloadDescriptorStruct { | |
79 | struct payloadDescriptorStruct *next; | |
80 | char *fileName; | |
81 | int fileSize; | |
82 | int size; | |
83 | void *data; | |
84 | } *payloadsHead, *payloadsTail; | |
4c166a14 | 85 | int lineNmb; |
f3a800f8 | 86 | eventGdcIdType currGdcId; |
f59c50c6 | 87 | unsigned long32 currDetPattern; |
f3a800f8 | 88 | eventLdcIdType currLdcId; |
89 | equipmentIdType currEquipmentId; | |
90 | int currRunNb; | |
91 | int numOfLdcs; | |
92 | int numOfEvents; | |
93 | int createSorEor; | |
94 | int handleCDH; | |
95 | eventIdType oneEventDelta; | |
96 | eventIdType currEventId; | |
97 | int gotAliceTrigger; | |
98 | int bufferData; | |
99 | ||
5d4d6c66 | 100 | struct commonDataHeaderStruct *cdhRef = NULL; |
101 | ||
f3a800f8 | 102 | void dumpPayload( const struct payloadDescriptorStruct *p ) { |
103 | char *c; | |
104 | int i; | |
105 | int printable; | |
106 | ||
107 | if ( p->data != NULL ) { | |
108 | for ( i = 0, c = (char *)p->data, printable = TRUE; | |
109 | printable && i != p->size; | |
110 | c++, i++ ) | |
111 | printable = isascii( *c ); | |
112 | if ( printable ) { | |
113 | printf( " \"" ); | |
114 | for ( i = 0, c = (char *)p->data; i != p->size; c++, i++ ) { | |
115 | if ( *c == '\n' ) | |
116 | printf( "\"\n \"" ); | |
117 | else | |
118 | putchar( *c ); | |
119 | } | |
120 | if ( *c != '\n' ) printf( "\"\n" ); | |
121 | } else { | |
122 | long32 *v; | |
123 | for ( i = 0, v = (long32 *)p->data; | |
124 | i+4 <= p->size; | |
125 | v++, i += 4 ) { | |
126 | if ( i % (4*8) == 0 ) { | |
127 | if ( i != 0 ) printf( "\n" ); | |
128 | printf( " " ); | |
129 | } | |
130 | printf( "%08x ", *v ); | |
131 | } | |
132 | if ( i < p->size ) { | |
133 | int j = 0; | |
a8bf0b36 | 134 | |
f3a800f8 | 135 | printf( "\n " ); |
136 | while ( i != p->size ) { | |
137 | printf( "%02x ", *((char *)p->data + p->size - j - 1) & 0xff ); | |
138 | j++; | |
139 | i++; | |
140 | } | |
141 | } | |
142 | } | |
143 | printf( "\n" ); | |
144 | } | |
145 | } /* End of dumpPayload */ | |
146 | ||
147 | void dumpEvents() { | |
148 | assert( workingAs == ldc || workingAs == gdc ); | |
149 | if ( eventsHead != NULL ) { | |
150 | printf( "Events:\n" ); | |
151 | if ( workingAs == gdc ) { | |
152 | struct gdcEventDescriptorStruct *gdc; | |
153 | ||
154 | for ( gdc = (struct gdcEventDescriptorStruct *)eventsHead; | |
155 | gdc != NULL; | |
156 | gdc = gdc->next ) { | |
157 | struct ldcEventDescriptorStruct *ldc; | |
158 | ||
3b5a3b55 | 159 | printf( " GDC (%p)\n", (void*)gdc ); |
f3a800f8 | 160 | for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) { |
161 | struct equipmentEventDescriptorStruct *eq; | |
162 | ||
3b5a3b55 | 163 | printf( " LDC (%p): %d\n", (void*)ldc, ldc->id ); |
f3a800f8 | 164 | for ( eq = ldc->head; eq != NULL; eq = eq->next ) { |
165 | printf( " EQUIPMENT (%p): %d PAYLOAD (%p):", | |
3b5a3b55 | 166 | (void*)eq, |
f3a800f8 | 167 | eq->id, |
3b5a3b55 | 168 | (void*)eq->payload ); |
f3a800f8 | 169 | fflush( stdout ); |
170 | printf( "\"%s\" (%d bytes)\n", | |
171 | eq->payload->fileName, | |
172 | eq->payload->size ); | |
173 | dumpPayload( eq->payload ); | |
174 | } | |
175 | } | |
176 | } | |
177 | } | |
178 | if ( workingAs == ldc ) { | |
179 | struct ldcEventDescriptorStruct *ldc; | |
180 | ||
181 | for ( ldc = (struct ldcEventDescriptorStruct *)eventsHead; | |
182 | ldc != NULL; | |
183 | ldc = ldc->next ) { | |
184 | struct equipmentEventDescriptorStruct *eq; | |
185 | ||
186 | printf( " LDC\n" ); | |
187 | for ( eq = ldc->head; eq != NULL; eq = eq->next ) { | |
188 | printf( " EQUIPMENT (%p): %d PAYLOAD (%p):", | |
3b5a3b55 | 189 | (void*)eq, |
f3a800f8 | 190 | eq->id, |
3b5a3b55 | 191 | (void*)eq->payload ); |
f3a800f8 | 192 | fflush( stdout ); |
193 | printf( "\"%s\" (%d bytes)\n", | |
194 | eq->payload->fileName, | |
195 | eq->payload->size ); | |
196 | dumpPayload( eq->payload ); | |
197 | } | |
198 | } | |
199 | } | |
200 | } else { | |
201 | printf( "Events: EMPTY\n" ); | |
202 | } | |
203 | } /* End of dumpEvents */ | |
204 | ||
205 | void getLine( char *line, const int maxSize ) { | |
206 | int read; | |
207 | int c; | |
a8bf0b36 | 208 | |
f3a800f8 | 209 | for ( read = 0; !feof( stdin ) && !ferror( stdin ) && read != maxSize; read++ ) { |
210 | if ( (line[read] = getchar()) == '\n' ) break; | |
211 | } | |
212 | if ( ferror( stdin ) ) { | |
213 | fprintf( stderr, | |
214 | "%s: failed to read configuration input errno:%d ", | |
215 | myName, errno ); | |
216 | perror( "" ); | |
217 | exit( 1 ); | |
218 | } | |
219 | if ( feof( stdin ) ) read--; | |
220 | if ( read == maxSize && line[read] != '\n' ) { | |
221 | fprintf( stderr, | |
222 | "%s: Input line # %d too long (%d chars max)\n", | |
4c166a14 | 223 | myName, lineNmb, maxSize-1 ); |
f3a800f8 | 224 | exit( 1 ); |
225 | } | |
226 | line[ read ] = 0; | |
227 | DBG_VERBOSE { | |
228 | if ( !( read == 0 && feof( stdin ) ) ) { | |
4c166a14 | 229 | printf( "%d) [%3d] \"%s\"", lineNmb, read, line ); |
f3a800f8 | 230 | } |
231 | } | |
232 | for ( c = 0; c != read; c++ ) { | |
233 | if ( line[c] == '#' ) { | |
234 | line[c] = 0; | |
235 | break; | |
236 | } | |
237 | } | |
238 | DBG_VERBOSE { | |
239 | if ( read != c ) { | |
240 | printf( " => \"%s\"", line ); | |
241 | } | |
242 | if ( feof( stdin ) ) printf( "<<< EOF >>>" ); | |
243 | if ( ferror( stdin ) ) printf( "<<< FERROR >>>" ); | |
244 | printf( "\n" ); | |
245 | } | |
246 | } /* End of getLine */ | |
247 | ||
248 | void handleLdc( eventLdcIdType ldcId ) { | |
249 | struct ldcDescriptorStruct *ldc; | |
250 | ||
251 | if ( ldcsHead != NULL ) { | |
252 | for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) { | |
253 | if ( ldc->id == ldcId ) { | |
254 | return; | |
255 | } | |
256 | } | |
257 | } | |
258 | if ( (ldc = (struct ldcDescriptorStruct *)malloc( sizeof( *ldc ) )) == NULL ) { | |
259 | fprintf( stderr, | |
260 | "%s: Failed to malloc for %d bytes (struct ldcDescriptorStruct)\n", | |
261 | myName, (int)sizeof( *ldc ) ); | |
262 | exit( 1 ); | |
263 | } | |
264 | ldc->id = ldcId; | |
265 | ldc->next = NULL; | |
266 | if ( ldcsHead == NULL ) { | |
267 | ldcsHead = ldcsTail = ldc; | |
268 | } else { | |
269 | ldcsTail->next = ldc; | |
270 | ldcsTail = ldc; | |
271 | } | |
272 | numOfLdcs++; | |
273 | } /* End of handleLdc */ | |
274 | ||
275 | void createNewEvent() { | |
276 | assert( workingAs == ldc || workingAs == gdc ); | |
277 | if ( workingAs == ldc ) { | |
278 | struct ldcEventDescriptorStruct *p; | |
279 | ||
280 | if ( (p = (struct ldcEventDescriptorStruct *)malloc( sizeof( *p ) )) | |
281 | == NULL ) { | |
282 | fprintf( stderr, | |
283 | "%s: failed to malloc for %d bytes (createNewEvent: struct ldcEventDescriptorStruct)", | |
284 | myName, (int)sizeof( *p ) ); | |
285 | perror( "" ); | |
286 | exit( 1 ); | |
287 | } | |
288 | p->loaded = FALSE; | |
289 | p->head = p->tail = NULL; | |
290 | p->next = NULL; | |
291 | currLdc = p; | |
292 | if ( eventsHead == NULL ) { | |
293 | eventsHead = eventsTail = p; | |
294 | } else { | |
295 | struct ldcEventDescriptorStruct *q = | |
296 | (struct ldcEventDescriptorStruct *)eventsTail; | |
a8bf0b36 | 297 | |
f3a800f8 | 298 | q->next = p; |
299 | eventsTail = p; | |
300 | } | |
301 | p->id = currLdcId; | |
302 | } else if ( workingAs == gdc ) { | |
303 | struct gdcEventDescriptorStruct *p; | |
304 | ||
305 | if ( (p = (struct gdcEventDescriptorStruct *)malloc( sizeof( *p ) )) | |
306 | == NULL ) { | |
307 | fprintf( stderr, | |
308 | "%s: failed to malloc for %d bytes (createNewEvent: struct gdcEventDescriptorStruct)", | |
309 | myName, (int)sizeof( *p ) ); | |
310 | perror( "" ); | |
311 | exit( 1 ); | |
312 | } | |
313 | p->loaded = FALSE; | |
314 | p->next = NULL; | |
315 | p->head = p->tail = NULL; | |
316 | currGdc = p; | |
317 | if ( eventsHead == NULL ) { | |
318 | eventsHead = eventsTail = p; | |
319 | } else { | |
320 | struct gdcEventDescriptorStruct *q = | |
321 | (struct gdcEventDescriptorStruct *)eventsTail; | |
a8bf0b36 | 322 | |
f3a800f8 | 323 | q->next = p; |
324 | eventsTail = p; | |
325 | } | |
326 | } | |
327 | } /* End of createNewEvent */ | |
328 | ||
329 | void createNewLdcEvent() { | |
330 | struct gdcEventDescriptorStruct *gdcDesc; | |
331 | struct ldcEventDescriptorStruct *p; | |
332 | ||
333 | if ( (p = (struct ldcEventDescriptorStruct *)malloc( sizeof( *p ) )) | |
334 | == NULL ) { | |
335 | fprintf( stderr, | |
336 | "%s: failed to malloc for %d bytes (createNewLdcEvent: struct ldcEventDescriptorStruct)", | |
337 | myName, (int)sizeof( *p ) ); | |
338 | perror( "" ); | |
339 | exit( 1 ); | |
340 | } | |
341 | p->id = currLdcId; | |
342 | p->head = p->tail = NULL; | |
343 | p->next = NULL; | |
344 | gdcDesc = (struct gdcEventDescriptorStruct *)eventsTail; | |
345 | if ( gdcDesc->head == NULL ) { | |
346 | gdcDesc->head = gdcDesc->tail = p; | |
347 | } else { | |
348 | gdcDesc->tail->next = p; | |
349 | gdcDesc->tail = p; | |
350 | } | |
351 | currLdc = p; | |
352 | } /* End of createNewLdcEvent */ | |
353 | ||
354 | void loadBuffer( struct payloadDescriptorStruct * const payload ) { | |
355 | FILE *f; | |
356 | int bytesRead; | |
a8bf0b36 | 357 | |
f3a800f8 | 358 | if ( (f = fopen( payload->fileName, "r" )) == NULL ) { |
359 | fprintf( stderr, | |
360 | "%s: line:%d payload file \"%s\" not found or not readable, errno:%d. ", | |
361 | myName, | |
4c166a14 | 362 | lineNmb, |
f3a800f8 | 363 | payload->fileName, |
364 | errno ); | |
365 | perror( "System-dependent error " ); | |
366 | exit( 1 ); | |
367 | } | |
368 | if ( (payload->data = malloc( payload->size )) == NULL ) { | |
369 | fprintf( stderr, | |
370 | "%s: line:%d Failed to malloc for payload file \"%s\" size:%d errno:%d ", | |
371 | myName, | |
4c166a14 | 372 | lineNmb, |
f3a800f8 | 373 | payload->fileName, |
374 | payload->size, | |
375 | errno ); | |
376 | perror( "System-dependent status " ); | |
377 | exit( 1 ); | |
378 | } | |
379 | if ( (bytesRead = fread( payload->data, payload->fileSize, 1, f )) != 1 ) { | |
380 | fprintf( stderr, | |
381 | "%s: line:%d Failed to read payload file \"%s\" size:%d requested:1 got:%d feof:%s ferror:%s errno:%d ", | |
382 | myName, | |
4c166a14 | 383 | lineNmb, |
f3a800f8 | 384 | payload->fileName, |
385 | payload->size, | |
386 | bytesRead, | |
387 | feof(f) ? "TRUE" : "false", | |
388 | ferror(f) ? "TRUE" : "false", | |
389 | errno ); | |
390 | perror( "System-dependent status " ); | |
391 | exit( 1 ); | |
392 | } | |
393 | fclose(f); | |
394 | if ( payload->size != payload->fileSize ) { | |
395 | memset( (char *)payload->data + payload->fileSize, | |
396 | 0, | |
397 | payload->size - payload->fileSize ); | |
398 | } | |
399 | } /* End of loadBuffer */ | |
400 | ||
401 | void unloadBuffer( struct payloadDescriptorStruct * const payload ) { | |
402 | if ( payload->data != NULL ) { | |
403 | free( payload->data ); | |
404 | payload->data = NULL; | |
405 | } | |
406 | } /* End of unloadBuffer */ | |
407 | ||
408 | void unloadAllBuffers() { | |
409 | struct payloadDescriptorStruct *payload; | |
410 | ||
411 | for ( payload = payloadsHead; payload != NULL; payload = payload->next ) { | |
412 | unloadBuffer( payload ); | |
413 | } | |
414 | } /* End of unloadAllBuffers */ | |
415 | ||
416 | void loadPayload( const char *fileName ) { | |
417 | struct payloadDescriptorStruct *payload; | |
418 | ||
419 | for ( payload = payloadsHead; payload != NULL; payload = payload->next ) { | |
420 | if ( strcmp( fileName, payload->fileName ) == 0 ) | |
421 | break; | |
422 | } | |
423 | if ( payload == NULL ) { | |
424 | FILE *f; | |
a8bf0b36 | 425 | |
f3a800f8 | 426 | if ( (payload = (struct payloadDescriptorStruct *)malloc( sizeof( *payload ) )) |
427 | == NULL ) { | |
428 | fprintf( stderr, | |
429 | "%s: failed to malloc for %d bytes (loadPayload/payloadDescriptorStruct)\n", | |
430 | myName, | |
431 | (int)sizeof( *payload ) ); | |
432 | exit( 1 ); | |
433 | } | |
434 | if ( (payload->fileName = strdup( fileName )) == NULL ) { | |
435 | fprintf( stderr, | |
436 | "%s: failed to duplicate string \"%s\" (loadPaload/fileName)\n", | |
437 | myName, | |
438 | fileName ); | |
439 | exit( 1 ); | |
440 | } | |
441 | if ( (f = fopen( fileName, "r" )) == NULL ) { | |
442 | fprintf( stderr, | |
443 | "%s: line:%d payload file \"%s\" not found or not readable, errno:%d. ", | |
444 | myName, | |
4c166a14 | 445 | lineNmb, |
f3a800f8 | 446 | fileName, |
447 | errno ); | |
448 | perror( "System-dependent error " ); | |
449 | exit( 1 ); | |
450 | } | |
451 | if ( fseek( f, 0L, SEEK_END ) != 0 ) { | |
452 | fprintf( stderr, | |
453 | "%s: line:%d Failed to seek payload file \"%s\" errno:%d ", | |
454 | myName, | |
4c166a14 | 455 | lineNmb, |
f3a800f8 | 456 | fileName, |
457 | errno ); | |
458 | perror( "System-dependent error " ); | |
459 | exit( 1 ); | |
460 | } | |
461 | if ( (payload->size = ftell( f )) <= 0 ) { | |
462 | fprintf( stderr, | |
463 | "%s: line:%d Failed to get file \"%s\" size size:%d errno:%d ", | |
464 | myName, | |
4c166a14 | 465 | lineNmb, |
f3a800f8 | 466 | fileName, |
467 | payload->size, | |
468 | errno ); | |
469 | perror( "System-dependent status " ); | |
470 | exit( 1 ); | |
471 | } | |
472 | payload->fileSize = payload->size; | |
473 | while ( (payload->size & 3) != 0 ) payload->size++; | |
474 | fclose( f ); | |
a8bf0b36 | 475 | |
f3a800f8 | 476 | if ( bufferData ) { |
477 | loadBuffer( payload ); | |
478 | } else { | |
479 | payload->data = NULL; | |
480 | } | |
481 | ||
482 | payload->next = NULL; | |
483 | if ( payloadsHead == NULL ) { | |
484 | payloadsHead = payloadsTail = payload; | |
485 | } else { | |
486 | payloadsTail->next = payload; | |
487 | payloadsTail = payload; | |
488 | } | |
489 | DBG_VERBOSE { | |
490 | int b, n; | |
a8bf0b36 | 491 | |
f3a800f8 | 492 | printf( "%d) Payload \"%s\" loaded at %p\n", |
4c166a14 | 493 | lineNmb, |
f3a800f8 | 494 | fileName, |
3b5a3b55 | 495 | (void*)payload ); |
f3a800f8 | 496 | if ( bufferData ) { |
43e9e2a9 | 497 | if ( handleCDH && |
498 | strncmp(fileName,"TRG_",4) != 0 ) { | |
f3a800f8 | 499 | struct commonDataHeaderStruct *cdh = |
500 | (struct commonDataHeaderStruct *)payload->data; | |
501 | ||
502 | printf( " CDH: blockLenght:%d=0x%08x ", | |
503 | cdh->cdhBlockLength, cdh->cdhBlockLength ); | |
504 | if ( cdh->cdhBlockLength < sizeof( *cdh ) ) { | |
73d4128a | 505 | printf( "TOO SMALL (minimum:%ld=0x%08lx)\n", |
a8bf0b36 | 506 | (unsigned long)sizeof( *cdh ), |
507 | (unsigned long)sizeof( *cdh ) ); | |
f3a800f8 | 508 | } else { |
509 | printf( "version:%d=0x%x ", cdh->cdhVersion, cdh->cdhVersion ); | |
510 | if ( cdh->cdhVersion != CDH_VERSION ) { | |
511 | printf( "EXPECTED:%d=%x (decoding may be inaccurate) ", | |
512 | CDH_VERSION, CDH_VERSION ); | |
513 | } | |
514 | } | |
515 | printf( "L1TriggerMessage:0x%x", cdh->cdhL1TriggerMessage ); | |
516 | if ( cdh->cdhL1TriggerMessage != 0 ) { | |
517 | for ( b = 0, n = 0; b != 10; b++ ) { | |
518 | if ( (cdh->cdhL1TriggerMessage & (1<<b)) != 0 ) { | |
519 | if ( n++ != 0 )printf( "+" ); | |
520 | switch (b) { | |
521 | case 0: printf( "L1SwC" ); break; | |
522 | case 1: printf( "ESR" ); break; | |
523 | case 2: printf( "RoC1" ); break; | |
524 | case 3: printf( "RoC2" ); break; | |
525 | case 4: printf( "RoC3" ); break; | |
526 | case 5: printf( "RoC4" ); break; | |
527 | case 6: printf( "ClT" ); break; | |
528 | default: printf( "spare %d", b+14 ); | |
529 | } | |
530 | } | |
531 | } | |
532 | printf( ">" ); | |
533 | } | |
534 | printf( " " ); | |
535 | if ( cdh->cdhMBZ0 != 0 ) | |
536 | printf( "MBZ0:0x%x ", | |
537 | cdh->cdhMBZ0 ); | |
538 | printf( "\n" ); | |
539 | ||
540 | printf( " " ); | |
541 | printf( "EventId2(orbit):%d=0x%x ", | |
542 | cdh->cdhEventId2, cdh->cdhEventId2 ); | |
543 | printf( "EventId1(bunchCrossing):%d=0x%x ", | |
544 | cdh->cdhEventId1, cdh->cdhEventId1 ); | |
545 | printf( "\n" ); | |
546 | ||
547 | printf( " " ); | |
548 | if ( cdh->cdhMBZ1 != 0 ) | |
549 | printf( "MBZ1:0x%x ", | |
550 | cdh->cdhMBZ1 ); | |
551 | printf( "BlockAttributes:0x%x", | |
552 | cdh->cdhBlockAttributes ); | |
553 | if ( cdh->cdhBlockAttributes != 0 ) { | |
554 | printf( "=<" ); | |
555 | for ( b = 0, n = 0; b != 8; b++ ) { | |
556 | if ( (cdh->cdhBlockAttributes & (1<<b)) != 0 ) { | |
557 | if ( n++ != 0 ) | |
558 | printf( "+" ); | |
559 | printf( "%d", b ); | |
560 | } | |
561 | } | |
562 | printf( ">" ); | |
563 | } | |
564 | printf( " " ); | |
565 | printf( "ParticipatingSubDetectors:0x%x ", | |
566 | cdh->cdhParticipatingSubDetectors ); | |
567 | printf( "\n" ); | |
568 | printf( " " ); | |
569 | ||
570 | if ( cdh->cdhMBZ2 != 0 ) | |
571 | printf( "MBZ2:0x%x ", | |
572 | cdh->cdhMBZ2 ); | |
573 | printf( "Status/Error:0x%x", cdh->cdhStatusErrorBits ); | |
574 | if ( cdh->cdhStatusErrorBits != 0 ) { | |
575 | printf( "=<" ); | |
576 | for ( b = 0,n = 0; b != 16; b++ ) { | |
577 | if ( (cdh->cdhStatusErrorBits & (1<<b)) != 0 ) { | |
578 | if ( n++ != 0 ) printf( "+" ); | |
579 | switch (b) { | |
580 | case 0: printf( "TriggerOverLapError" ); break; | |
581 | case 1: printf( "TriggerMissingError" ); break; | |
582 | case 2: printf( "DataParityError" ); break; | |
583 | case 3: printf( "ControlParityError" ); break; | |
584 | case 4: printf( "TriggerInformationUnavailable" ); break; | |
585 | case 5: printf( "FEEError" ); break; | |
586 | case 6: printf( "HLTDecision" ); break; | |
587 | case 7: printf( "HLTPayload" ); break; | |
588 | case 8: printf( "DDGPayload" ); break; | |
589 | default: printf( "spare %d", b ); | |
590 | } | |
591 | } | |
592 | } | |
593 | printf( ">" ); | |
594 | } | |
595 | printf( " " ); | |
596 | printf( "MiniEventId(bunchCrossing):%d=0x%x ", | |
597 | cdh->cdhMiniEventId, cdh->cdhMiniEventId ); | |
598 | printf( "\n" ); | |
599 | ||
600 | printf( " " ); | |
601 | printf( "Trigger classes: 0x(%05x-%08x)", | |
602 | cdh->cdhTriggerClassesHigh, | |
603 | cdh->cdhTriggerClassesLow ); | |
604 | if ( cdh->cdhTriggerClassesHigh != 0 | |
605 | || cdh->cdhTriggerClassesLow != 0 ) { | |
606 | printf( "=<" ); | |
607 | for ( b=0, n=0; b != 32; b++ ) { | |
608 | if ( (cdh->cdhTriggerClassesLow & (1<<b)) != 0 ) { | |
609 | if ( n++ != 0 ) printf( "+" ); | |
610 | printf( "%d", b ); | |
611 | } | |
612 | } | |
613 | for ( b=0; b != 18; b++ ) { | |
614 | if ( (cdh->cdhTriggerClassesHigh & (1<<b)) != 0 ) { | |
615 | if ( n++ != 0 ) printf( "+" ); | |
616 | printf( "%d", b+32 ); | |
617 | } | |
618 | } | |
619 | printf( ">" ); | |
620 | } | |
621 | printf( "\n" ); | |
622 | ||
623 | printf( " " ); | |
624 | if ( cdh->cdhMBZ3 != 0 ) { | |
625 | printf( "MBZ3:0x%x ", | |
626 | cdh->cdhMBZ3 ); | |
627 | } | |
628 | printf( "ROI:0x(%08x-%01x)", cdh->cdhRoiHigh, cdh->cdhRoiLow ); | |
629 | if ( cdh->cdhRoiHigh != 0 | |
630 | || cdh->cdhRoiLow != 0 ) { | |
631 | printf( "=<" ); | |
632 | for ( b=0, n=0; b != 5; b++ ) { | |
633 | if ( (cdh->cdhRoiLow & (1<<b)) != 0 ) { | |
634 | if ( n++ != 0 ) printf( "+" ); | |
635 | printf( "%d", b ); | |
636 | } | |
637 | } | |
638 | for ( b=0; b != 32; b++ ) { | |
639 | if ( (cdh->cdhRoiHigh & (1<<b)) != 0 ) { | |
640 | if ( n++ != 0 ) printf( "+" ); | |
641 | printf( "%d", b+4 ); | |
642 | } | |
643 | } | |
644 | printf( ">" ); | |
645 | } | |
646 | printf( "\n" ); | |
647 | } | |
648 | } | |
649 | } | |
650 | } else { | |
651 | DBG_VERBOSE | |
652 | printf( "%d) Payload \"%s\" already loaded at %p\n", | |
4c166a14 | 653 | lineNmb, |
f3a800f8 | 654 | fileName, |
3b5a3b55 | 655 | (void*)payload ); |
f3a800f8 | 656 | } |
657 | ||
658 | currEvent->payload = payload; | |
659 | } /* End of loadPayload */ | |
660 | ||
661 | void parseEquipment( char * const line ) { | |
662 | struct equipmentEventDescriptorStruct *equipment; | |
663 | int payloadFound = FALSE; | |
664 | char *p; | |
665 | char *keyword; | |
666 | ||
667 | if ( (equipment = | |
668 | (struct equipmentEventDescriptorStruct *)malloc( sizeof( *equipment ) )) == NULL ) { | |
669 | fprintf( stderr, | |
670 | "%s: filed to malloc for %d bytes (parseEquipment/equipmentEventDescriptorStruct) errno:%d ", | |
671 | myName, | |
672 | (int)sizeof( *equipment ), | |
673 | errno ); | |
674 | perror( "" ); | |
675 | exit( 1 ); | |
676 | } | |
677 | currEvent = equipment; | |
678 | ||
679 | p = line; | |
680 | while ( (keyword = strtok_r( p, " \t", &p )) != NULL ) { | |
681 | DBG_VERBOSE printf( "%d) Equipment - Keyword:\"%s\"\n", | |
4c166a14 | 682 | lineNmb, |
f3a800f8 | 683 | keyword ); |
684 | if ( strcasecmp( "id", keyword ) == 0 ) { | |
685 | char *idNum; | |
686 | ||
687 | if ( (idNum = strtok_r( p, " \t", &p )) == NULL ) { | |
688 | fprintf( stderr, | |
689 | "%s: line:%d EQUIPMENT declaration, ID needed", | |
690 | myName, | |
4c166a14 | 691 | lineNmb ); |
f3a800f8 | 692 | exit( 1 ); |
693 | } | |
694 | if ( sscanf( idNum, "%d", &currEquipmentId ) != 1 ) { | |
695 | fprintf( stderr, | |
696 | "%s: line:%d EQUIPMENT declaration, numeric ID needed (%s)", | |
697 | myName, | |
4c166a14 | 698 | lineNmb, |
f3a800f8 | 699 | idNum ); |
700 | exit( 1 ); | |
701 | } | |
702 | DBG_VERBOSE printf( "%d) EQUIPMENT - ID:%d\n", | |
4c166a14 | 703 | lineNmb, |
f3a800f8 | 704 | currEquipmentId ); |
705 | } else if ( strncasecmp( "pay", keyword, 3 ) == 0 ) { | |
706 | char *fileName; | |
707 | ||
708 | if ( (fileName = strtok_r( p, " \t", &p )) == NULL ) { | |
709 | fprintf( stderr, | |
710 | "%s line:%d Payload without filename found\n", | |
711 | myName, | |
4c166a14 | 712 | lineNmb ); |
f3a800f8 | 713 | exit( 1 ); |
714 | } | |
715 | DBG_VERBOSE printf( "%d) Equipment - Payload:\"%s\"\n", | |
4c166a14 | 716 | lineNmb, |
f3a800f8 | 717 | fileName ); |
718 | if ( payloadFound ) { | |
719 | fprintf( stderr, | |
720 | "%s line:%d Payload with multiple filenames found\n", | |
721 | myName, | |
4c166a14 | 722 | lineNmb ); |
f3a800f8 | 723 | exit( 1 ); |
724 | } | |
725 | loadPayload( fileName ); | |
726 | payloadFound = TRUE; | |
727 | } else { | |
728 | fprintf( stderr, | |
729 | "%s: line:%d Equipment declaration, unknown keyword \"%s\"\n", | |
730 | myName, | |
4c166a14 | 731 | lineNmb, |
f3a800f8 | 732 | keyword ); |
733 | exit( 1 ); | |
734 | } | |
735 | } | |
736 | if ( !payloadFound ) { | |
737 | fprintf( stderr, | |
738 | "%s: line:%d Equipment without payload found\n", | |
739 | myName, | |
4c166a14 | 740 | lineNmb ); |
f3a800f8 | 741 | exit( 1 ); |
742 | } | |
743 | ||
744 | equipment->id = currEquipmentId; | |
745 | equipment->next = NULL; | |
746 | if ( currLdc->head == NULL ) { | |
747 | currLdc->head = currLdc->tail = equipment; | |
748 | } else { | |
749 | currLdc->tail->next = equipment; | |
750 | currLdc->tail = equipment; | |
751 | } | |
752 | } /* End of parseEquipment */ | |
753 | ||
754 | void parseGdc( char * const line ) { | |
755 | char *p; | |
756 | char *keyword; | |
a8bf0b36 | 757 | |
f3a800f8 | 758 | p = line; |
759 | while ( (keyword = strtok_r( p, " \t", &p )) != NULL ) { | |
760 | if ( strcasecmp( "id", keyword ) == 0 ) { | |
761 | char *idNum; | |
762 | ||
763 | if ( (idNum = strtok_r( p, " \t", &p )) == NULL ) { | |
764 | fprintf( stderr, | |
765 | "%s: line:%d GDC declaration, ID needed", | |
766 | myName, | |
4c166a14 | 767 | lineNmb ); |
f3a800f8 | 768 | exit( 1 ); |
769 | } | |
3b5a3b55 | 770 | if ( sscanf( idNum, "%d", (int*)&currGdcId ) != 1 ) { |
f3a800f8 | 771 | fprintf( stderr, |
772 | "%s: line:%d GDC declaration, numeric ID needed (%s)", | |
773 | myName, | |
4c166a14 | 774 | lineNmb, |
f3a800f8 | 775 | idNum ); |
776 | exit( 1 ); | |
777 | } | |
778 | DBG_VERBOSE printf( "%d) GDC - ID:%d\n", | |
4c166a14 | 779 | lineNmb, |
f3a800f8 | 780 | currGdcId ); |
f59c50c6 | 781 | } else if ( strcasecmp( "DetectorPattern", keyword ) == 0 ) { |
782 | char *detPattern; | |
783 | ||
784 | if ( (detPattern = strtok_r( p, " \t", &p )) == NULL ) { | |
785 | fprintf( stderr, | |
786 | "%s: line:%d GDC declaration, DetectorPattern needed", | |
787 | myName, | |
4c166a14 | 788 | lineNmb ); |
f59c50c6 | 789 | exit( 1 ); |
790 | } | |
791 | if ( sscanf( detPattern, "%u", &currDetPattern ) != 1 ) { | |
792 | fprintf( stderr, | |
793 | "%s: line:%d GDC declaration, numeric DetectorPattern needed (%s)", | |
794 | myName, | |
4c166a14 | 795 | lineNmb, |
f59c50c6 | 796 | detPattern ); |
797 | exit( 1 ); | |
798 | } | |
799 | DBG_VERBOSE printf( "%d) GDC - DetectorPattern:%u\n", | |
4c166a14 | 800 | lineNmb, |
f59c50c6 | 801 | currDetPattern ); |
f3a800f8 | 802 | } else { |
803 | fprintf( stderr, | |
804 | "%s: line:%d GDC declaration, unknown keyword \"%s\"\n", | |
805 | myName, | |
4c166a14 | 806 | lineNmb, |
f3a800f8 | 807 | keyword ); |
808 | exit( 1 ); | |
809 | } | |
810 | } | |
811 | } /* End of parseGdc */ | |
812 | ||
813 | void parseLdc( char * const line ) { | |
814 | char *p; | |
815 | char *keyword; | |
a8bf0b36 | 816 | |
f3a800f8 | 817 | p = line; |
818 | while ( (keyword = strtok_r( p, " \t", &p )) != NULL ) { | |
819 | if ( strcasecmp( "id", keyword ) == 0 ) { | |
820 | char *idNum; | |
821 | ||
822 | if ( (idNum = strtok_r( p, " \t", &p )) == NULL ) { | |
823 | fprintf( stderr, | |
824 | "%s: line:%d LDC declaration, ID needed", | |
825 | myName, | |
4c166a14 | 826 | lineNmb ); |
f3a800f8 | 827 | exit( 1 ); |
828 | } | |
18c9ced3 | 829 | int inCurrLdcId; |
830 | if ( sscanf( idNum, "%d", &inCurrLdcId ) != 1 ) { | |
f3a800f8 | 831 | fprintf( stderr, |
832 | "%s: line:%d LDC declaration, numeric ID needed (%s)", | |
833 | myName, | |
4c166a14 | 834 | lineNmb, |
f3a800f8 | 835 | idNum ); |
836 | exit( 1 ); | |
837 | } | |
18c9ced3 | 838 | currLdcId = (eventLdcIdType)inCurrLdcId; |
f3a800f8 | 839 | DBG_VERBOSE printf( "%d) LDC - ID:%d\n", |
4c166a14 | 840 | lineNmb, |
f3a800f8 | 841 | currLdcId ); |
842 | } else { | |
843 | fprintf( stderr, | |
844 | "%s: line:%d LDC declaration, unknown keyword \"%s\"\n", | |
845 | myName, | |
4c166a14 | 846 | lineNmb, |
f3a800f8 | 847 | keyword ); |
848 | exit( 1 ); | |
849 | } | |
850 | } | |
851 | } /* End of parseLdc */ | |
852 | ||
853 | void parseRules() { | |
854 | char line[ 1025 ]; | |
855 | ||
856 | currLdcId = HOST_ID_MIN; | |
857 | currGdcId = HOST_ID_MIN; | |
f59c50c6 | 858 | currDetPattern = 0; |
f3a800f8 | 859 | |
4c166a14 | 860 | for ( lineNmb = 1; !feof( stdin ); lineNmb++ ) { |
f3a800f8 | 861 | getLine( line, sizeof(line) ); |
862 | if ( strlen(line) != 0 ) { | |
863 | char *p; | |
864 | char *keyword; | |
865 | ||
866 | if ( (keyword = strtok_r( line, " \t", &p )) != NULL ) { | |
4c166a14 | 867 | DBG_VERBOSE printf( "%d) Keyword:\"%s\"\n", lineNmb, keyword ); |
f3a800f8 | 868 | if ( strcasecmp( "gdc", keyword ) == 0 ) { |
869 | if ( workingAs != gdc && workingAs != unknown ) { | |
870 | fprintf( stderr, | |
871 | "%s: line:%d GDC found when working in non-GDC mode (e.g. as a LDC)\n", | |
4c166a14 | 872 | myName, lineNmb ); |
f3a800f8 | 873 | exit( 1 ); |
874 | } | |
875 | workingAs = gdc; | |
876 | parseGdc( p ); | |
877 | createNewEvent(); | |
878 | currLdcId = HOST_ID_MIN; | |
879 | currLdc = NULL; | |
880 | currEquipmentId = 0; | |
881 | } else if ( strcasecmp( "ldc", keyword ) == 0 ) { | |
882 | if ( workingAs != gdc && workingAs != ldc && workingAs != unknown ) { | |
883 | fprintf( stderr, | |
884 | "%s: line:%d LDC found when working in non-LDC/GDC mode\n", | |
4c166a14 | 885 | myName, lineNmb ); |
f3a800f8 | 886 | exit( 1 ); |
887 | } | |
888 | if ( workingAs == unknown ) workingAs = ldc; | |
889 | parseLdc( p ); | |
890 | if ( workingAs == ldc ) { | |
891 | createNewEvent(); | |
892 | currEquipmentId = 0; | |
893 | } else { | |
894 | createNewLdcEvent(); | |
895 | handleLdc( currLdcId ); | |
896 | currLdcId++; | |
897 | } | |
898 | currEvent = NULL; | |
899 | } else if ( strncasecmp( "equ", keyword, 3 ) == 0 ) { | |
900 | if ( workingAs == unknown | |
901 | || (workingAs == ldc && currLdc == NULL ) | |
902 | || (workingAs == gdc && currGdc == NULL ) ) { | |
903 | fprintf( stderr, | |
904 | "%s: line:%d Unexpected EQUIPMENT declaration (LDC or GDC needed first)\n", | |
905 | myName, | |
4c166a14 | 906 | lineNmb ); |
f3a800f8 | 907 | exit( 1 ); |
908 | } | |
909 | parseEquipment( p ); | |
910 | currEquipmentId++; | |
911 | } else { | |
912 | fprintf( stderr, | |
913 | "%s: line:%d Parse error in \"%s\" unknown keyword\n", | |
914 | myName, | |
4c166a14 | 915 | lineNmb, |
f3a800f8 | 916 | keyword ); |
917 | exit( 1 ); | |
918 | } | |
919 | } | |
920 | } | |
0c1b2fb2 | 921 | } while ( !feof( stdin ) ) {} |
4c166a14 | 922 | lineNmb -= 2; |
f3a800f8 | 923 | |
924 | DBG_VERBOSE { | |
925 | printf( "End of parse: %d line%s found\n", | |
4c166a14 | 926 | lineNmb, |
927 | lineNmb != 1 ? "s" : "" ); | |
f3a800f8 | 928 | printf( "Working as %s\n", |
929 | workingAs == gdc ? "GDC" : | |
930 | workingAs == ldc ? "LDC" : | |
931 | "UNKNOWN" ); | |
932 | if ( workingAs == gdc ) { | |
933 | struct ldcDescriptorStruct *ldc; | |
a8bf0b36 | 934 | |
f3a800f8 | 935 | printf( "LDCs (%d):", numOfLdcs ); |
936 | for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) { | |
937 | printf( " %d", ldc->id ); | |
938 | } | |
939 | printf( "\n" ); | |
940 | } | |
941 | dumpEvents(); | |
942 | } | |
943 | ||
944 | if ( workingAs == ldc ) { | |
945 | assert( ldcsHead == ldcsTail ); | |
946 | assert( ldcsTail == NULL ); | |
947 | } | |
948 | ||
949 | if ( workingAs == gdc ) { | |
950 | struct ldcDescriptorStruct *ldc; | |
a8bf0b36 | 951 | |
f3a800f8 | 952 | assert( ldcsHead != NULL ); |
953 | assert( ldcsTail != NULL ); | |
954 | assert( ldcsTail->next == NULL ); | |
0c1b2fb2 | 955 | for ( ldc = ldcsHead; ldc->next != NULL; ldc = ldc->next ) {} |
f3a800f8 | 956 | assert ( ldc == ldcsTail ); |
957 | } | |
958 | ||
959 | if ( workingAs == unknown ) { | |
960 | DBG_VERBOSE printf( "Empty configuration: nothing to do!\n" ); | |
961 | exit( 0 ); | |
962 | } | |
963 | ||
964 | assert( (eventsHead == NULL && eventsTail == NULL) | |
965 | || (eventsHead != NULL && eventsTail != NULL) ); | |
966 | } /* End of parseRules */ | |
967 | ||
968 | void loadTimestamp( struct eventHeaderStruct * const ev ) { | |
969 | time_t t; | |
a8bf0b36 | 970 | |
f3a800f8 | 971 | if ( time( &t ) == (time_t)-1 ) { |
972 | fprintf( stderr, | |
973 | "%s: failed to get system time errno:%d (%s)\n", | |
974 | myName, errno, strerror( errno ) ); | |
975 | exit( 1 ); | |
976 | } | |
977 | ev->eventTimestamp = (eventTimestampType)t; | |
978 | } /* End of loadTimestamp */ | |
979 | ||
980 | void initEvent( struct eventHeaderStruct * const ev ) { | |
981 | memset( ev, 0, sizeof( *ev ) ); | |
982 | ||
983 | ev->eventMagic = EVENT_MAGIC_NUMBER; | |
984 | ev->eventHeadSize = EVENT_HEAD_BASE_SIZE; | |
985 | ev->eventVersion = EVENT_CURRENT_VERSION; | |
986 | ev->eventRunNb = currRunNb; | |
987 | ZERO_EVENT_ID( ev->eventId ); | |
988 | ZERO_TRIGGER_PATTERN( ev->eventTriggerPattern ); | |
989 | ZERO_DETECTOR_PATTERN( ev->eventDetectorPattern ); | |
990 | RESET_ATTRIBUTES( ev->eventTypeAttribute ); | |
991 | if ( workingMode == collider ) | |
992 | SET_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_ORBIT_BC ); | |
993 | ev->eventLdcId = VOID_ID; | |
994 | ev->eventGdcId = VOID_ID; | |
995 | loadTimestamp( ev ); | |
996 | } /* End of initEvent */ | |
997 | ||
f6508a2e | 998 | int Swap(int x) |
999 | { | |
1000 | // Swap the endianess of the integer value 'x' | |
1001 | ||
1002 | return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) << 8) | | |
1003 | ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24)); | |
1004 | } | |
1005 | ||
f3a800f8 | 1006 | void outputEvent( const void * const ev, |
1007 | const int size ) { | |
1008 | int done; | |
1009 | ||
1010 | DBG_VERBOSE { | |
f6508a2e | 1011 | const long32 * const v = (long32 *)ev; |
f3a800f8 | 1012 | printf( "Writing %d bytes @ %p (%d)\n", size, ev, *v ); |
1013 | } | |
a8bf0b36 | 1014 | |
f6508a2e | 1015 | // .............................Test endianess.............................. |
1016 | int temp = 1; | |
1017 | char* ptemp = (char*) &temp; | |
1018 | ||
1019 | if (ptemp[0]!=1) { // Mac platform: ptemp != 1.............................................................................. | |
1020 | int bufSize= size; if (bufSize > (int) sizeof(eventHeaderStruct)) { bufSize = sizeof(eventHeaderStruct); } | |
1021 | char* evTemp = (char*) malloc (bufSize); | |
1022 | memcpy(evTemp, ev, bufSize); | |
1023 | ||
1024 | if ((bufSize % sizeof(int)) != 0) { | |
1025 | fprintf( stderr, "%s: size of the input buffer ev is not multiple of 4 (size = %d)\n", myName, bufSize); | |
1026 | exit( 1 ); | |
1027 | } | |
1028 | else { | |
1029 | // Invert header to evTemp..................................................... | |
1030 | int* buf = (int*) evTemp; | |
1031 | for (int i=0; i < (int) (bufSize / sizeof(int)); i++, buf++) { | |
1032 | int value = Swap(*buf); | |
1033 | memcpy(evTemp + (i * sizeof(int)), &value, sizeof(int)); | |
1034 | } | |
1035 | ||
1036 | // Write inverted header to file............................................... | |
1037 | if ((done = fwrite( evTemp, bufSize, 1, outF )) != 1 ) { | |
1038 | fprintf( stderr, "%s: failed to write inverted header. event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) ); | |
1039 | exit( 1 ); | |
1040 | } | |
1041 | ||
1042 | if (size > bufSize) { // Still theraw-data payload to write (but not inverted, since it is inverted eariler)............. | |
1043 | if ((done = fwrite( (char*)ev + bufSize, size - bufSize, 1, outF )) != 1 ) { | |
1044 | fprintf( stderr, "%s: failed to write additional event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) ); | |
1045 | exit( 1 ); | |
1046 | } | |
1047 | } | |
1048 | } | |
1049 | free(evTemp); | |
1050 | } | |
1051 | else { // Intel platform: ptemp == 1............................................................................ | |
1052 | if ((done = fwrite( ev, size, 1, outF )) != 1 ) { | |
1053 | fprintf( stderr, "%s: failed to write event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) ); | |
1054 | exit( 1 ); | |
1055 | } | |
f3a800f8 | 1056 | } |
1057 | } /* End of outputEvent */ | |
1058 | ||
1059 | void createSorAndEor( const int sor ) { | |
1060 | unsigned char event[ 1000 ]; | |
1061 | struct eventHeaderStruct *ev; | |
1062 | struct eventHeaderStruct sev; | |
1063 | ||
1064 | assert( workingAs == ldc || workingAs == gdc ); | |
a8bf0b36 | 1065 | |
f3a800f8 | 1066 | if ( !createSorEor ) return; |
1067 | ev = (struct eventHeaderStruct *)event; | |
1068 | initEvent( ev ); | |
1069 | ev->eventSize = sizeof( event ); | |
1070 | ev->eventType = sor ? START_OF_RUN : END_OF_RUN; | |
1071 | if ( workingMode == fixedTarget ) | |
1072 | LOAD_RAW_EVENT_ID( ev->eventId, 0, 0, 0 ); | |
1073 | else | |
1074 | LOAD_EVENT_ID( ev->eventId, 0, 0, 0 ); | |
1075 | SET_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_P_START ); | |
1076 | ||
1077 | if ( workingAs == ldc ) { | |
1078 | currLdc = (struct ldcEventDescriptorStruct *)eventsHead; | |
1079 | } | |
1080 | if ( workingAs == gdc ) { | |
1081 | initEvent( &sev ); | |
1082 | sev.eventGdcId = currGdcId; | |
1083 | ev->eventGdcId = currGdcId; | |
1084 | currGdc = (struct gdcEventDescriptorStruct *)eventsHead; | |
1085 | currLdc = currGdc->head; | |
1086 | } | |
1087 | ev->eventLdcId = currLdc->id; | |
a8bf0b36 | 1088 | |
f3a800f8 | 1089 | if ( workingAs == ldc ) { |
1090 | loadTimestamp( ev ); | |
1091 | outputEvent( ev, ev->eventSize ); | |
1092 | } | |
1093 | if ( workingAs == gdc ) { | |
1094 | struct ldcDescriptorStruct *ldc; | |
1095 | ||
1096 | loadTimestamp( ev ); | |
a8bf0b36 | 1097 | |
f3a800f8 | 1098 | sev.eventSize = sizeof( sev ) + numOfLdcs * ev->eventSize; |
1099 | sev.eventType = sor ? START_OF_RUN : END_OF_RUN ; | |
1100 | COPY_EVENT_ID( ev->eventId, sev.eventId ); | |
1101 | COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute ); | |
1102 | SET_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT ); | |
1103 | loadTimestamp( &sev ); | |
1104 | outputEvent( &sev, sizeof( sev ) ); | |
1105 | ||
1106 | ev->eventGdcId = currGdcId; | |
1107 | for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) { | |
1108 | ev->eventLdcId = ldc->id; | |
1109 | outputEvent( ev, ev->eventSize ); | |
1110 | } | |
1111 | } | |
a8bf0b36 | 1112 | |
f3a800f8 | 1113 | ADD_EVENT_ID( ev->eventId, oneEventDelta ); |
1114 | ev->eventSize = ev->eventSize / 2; | |
1115 | ev->eventType = sor ? START_OF_RUN_FILES : END_OF_RUN_FILES; | |
1116 | CLEAR_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_P_START ); | |
1117 | if ( workingAs == ldc ) { | |
1118 | loadTimestamp( ev ); | |
1119 | outputEvent( ev, ev->eventSize ); | |
1120 | } | |
1121 | if ( workingAs == gdc ) { | |
1122 | struct ldcDescriptorStruct *ldc; | |
1123 | ||
1124 | loadTimestamp( ev ); | |
a8bf0b36 | 1125 | |
f3a800f8 | 1126 | sev.eventSize = ev->eventSize; |
1127 | sev.eventType = sor ? START_OF_RUN_FILES : END_OF_RUN_FILES; | |
1128 | COPY_EVENT_ID( ev->eventId, sev.eventId ); | |
1129 | COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute ); | |
1130 | CLEAR_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT ); | |
1131 | outputEvent( &sev, sizeof( sev ) ); | |
1132 | outputEvent( ev, ev->eventSize - sizeof( sev ) ); | |
1133 | ||
1134 | sev.eventSize = sizeof( sev ) + ev->eventSize; | |
1135 | sev.eventType = sor ? START_OF_RUN_FILES : END_OF_RUN_FILES; | |
1136 | COPY_EVENT_ID( ev->eventId, sev.eventId ); | |
1137 | COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute ); | |
1138 | SET_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT ); | |
a8bf0b36 | 1139 | |
f3a800f8 | 1140 | loadTimestamp( &sev ); |
1141 | ||
1142 | ev->eventGdcId = currGdcId; | |
1143 | for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) { | |
1144 | loadTimestamp( &sev ); | |
1145 | outputEvent( &sev, sizeof( sev ) ); | |
1146 | ev->eventLdcId = ldc->id; | |
1147 | outputEvent( ev, ev->eventSize ); | |
1148 | } | |
1149 | } | |
1150 | ||
1151 | ADD_EVENT_ID( ev->eventId, oneEventDelta ); | |
1152 | ev->eventSize = sizeof( *ev ); | |
1153 | ev->eventType = sor ? START_OF_RUN : END_OF_RUN; | |
1154 | SET_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_P_END ); | |
1155 | if ( workingAs == ldc ) { | |
1156 | loadTimestamp( ev ); | |
1157 | outputEvent( ev, ev->eventSize ); | |
1158 | } | |
1159 | if ( workingAs == gdc ) { | |
1160 | struct ldcDescriptorStruct *ldc; | |
1161 | ||
1162 | loadTimestamp( ev ); | |
1163 | ||
1164 | sev.eventSize = sizeof( sev ) + numOfLdcs * ev->eventSize; | |
1165 | sev.eventType = sor ? START_OF_RUN : END_OF_RUN; | |
1166 | COPY_EVENT_ID( ev->eventId, sev.eventId ); | |
1167 | COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute ); | |
1168 | SET_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT ); | |
1169 | loadTimestamp( &sev ); | |
a8bf0b36 | 1170 | |
f3a800f8 | 1171 | outputEvent( &sev, sizeof( sev ) ); |
1172 | ||
1173 | for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) { | |
1174 | ev->eventLdcId = ldc->id; | |
1175 | outputEvent( ev, ev->eventSize ); | |
1176 | } | |
1177 | } | |
1178 | } /* End of createSorEor */ | |
1179 | ||
1180 | void createSor() { | |
1181 | createSorAndEor( TRUE ); | |
1182 | } /* End of createSor */ | |
1183 | ||
1184 | void createEor() { | |
1185 | createSorAndEor( FALSE ); | |
1186 | } /* End of createEor */ | |
1187 | ||
1188 | void loadCdh( struct commonDataHeaderStruct * const cdh, | |
43e9e2a9 | 1189 | eventIdType * const eventId, |
1190 | equipmentIdType id ) { | |
f3a800f8 | 1191 | if ( !handleCDH ) return; |
1192 | ||
43e9e2a9 | 1193 | // CTP raw-data does not contain CDH |
1194 | if ( id == 4352) return; | |
1195 | ||
f3a800f8 | 1196 | if ( gotAliceTrigger ) { |
1197 | cdh->cdhEventId1 = EVENT_ID_GET_BUNCH_CROSSING( *eventId ); | |
1198 | cdh->cdhEventId2 = EVENT_ID_GET_ORBIT( *eventId ); | |
1199 | } else { | |
1200 | cdh->cdhEventId1 = 0; | |
1201 | cdh->cdhEventId2 = EVENT_ID_GET_NB_IN_RUN( *eventId ); | |
1202 | } | |
1203 | cdh->cdhMiniEventId = cdh->cdhEventId1; | |
1204 | } | |
1205 | void decodeCDH( struct ldcEventDescriptorStruct * const ldc, | |
43e9e2a9 | 1206 | const struct payloadDescriptorStruct * const payloadDesc, |
1207 | equipmentIdType id ); | |
f3a800f8 | 1208 | |
1209 | void createEvent( void ) { | |
1210 | assert( workingAs == ldc || workingAs == gdc ); | |
1211 | ||
1212 | /* Step 1: load all buffers (if needed) and compose the GDC/LDC headers */ | |
1213 | if ( workingAs == gdc ) { | |
1214 | struct ldcEventDescriptorStruct *ldc; | |
a8bf0b36 | 1215 | |
f3a800f8 | 1216 | for( ldc = currGdc->head; ldc != NULL; ldc = ldc->next ) { |
1217 | COPY_EVENT_ID( currEventId, ldc->header.eventId ); | |
1218 | loadTimestamp( &ldc->header ); | |
1219 | } | |
1220 | COPY_EVENT_ID( currEventId, currGdc->header.eventId ); | |
1221 | loadTimestamp( &currGdc->header ); | |
a8bf0b36 | 1222 | |
f3a800f8 | 1223 | for( ldc = currGdc->head; ldc != NULL; ldc = ldc->next ) { |
1224 | struct equipmentEventDescriptorStruct *eq; | |
1225 | int n; | |
1226 | ||
1227 | for ( eq = ldc->head; eq != NULL; eq = eq->next ) { | |
1228 | if ( !bufferData ) { | |
1229 | loadBuffer( eq->payload ); | |
43e9e2a9 | 1230 | decodeCDH( ldc, eq->payload, eq->id ); |
f3a800f8 | 1231 | } |
1232 | loadCdh( (struct commonDataHeaderStruct*)eq->payload->data, | |
43e9e2a9 | 1233 | &currEventId, |
1234 | eq->id); | |
f3a800f8 | 1235 | } |
1236 | ||
1237 | if ( !currGdc->loaded ) { | |
1238 | for ( n = 0; n != EVENT_TRIGGER_PATTERN_WORDS; n++ ) | |
1239 | currGdc->header.eventTriggerPattern[n] |= ldc->header.eventTriggerPattern[n]; | |
1240 | for ( n = 0; n != EVENT_DETECTOR_PATTERN_WORDS; n++ ) | |
1241 | currGdc->header.eventDetectorPattern[n] |= ldc->header.eventDetectorPattern[n]; | |
1242 | for ( n = 0; n != ALL_ATTRIBUTE_WORDS; n++ ) | |
1243 | currGdc->header.eventTypeAttribute[n] |= ldc->header.eventTypeAttribute[n]; | |
1244 | currGdc->loaded = TRUE; | |
1245 | } | |
1246 | } | |
5d4d6c66 | 1247 | cdhRef = NULL; |
f3a800f8 | 1248 | } else if ( workingAs == ldc ) { |
1249 | struct equipmentEventDescriptorStruct *eq; | |
1250 | ||
1251 | COPY_EVENT_ID( currEventId, currLdc->header.eventId ); | |
1252 | loadTimestamp( &currLdc->header ); | |
1253 | ||
1254 | for ( eq = currLdc->head; eq != NULL; eq = eq->next ) { | |
1255 | if ( !bufferData ) { | |
1256 | loadBuffer( eq->payload ); | |
43e9e2a9 | 1257 | decodeCDH( currLdc, eq->payload, eq->id ); |
f3a800f8 | 1258 | } |
1259 | loadCdh( (struct commonDataHeaderStruct*)eq->payload->data, | |
43e9e2a9 | 1260 | &currEventId, |
1261 | eq->id); | |
f3a800f8 | 1262 | currLdc->loaded = TRUE; |
1263 | } | |
5d4d6c66 | 1264 | cdhRef = NULL; |
f3a800f8 | 1265 | } |
1266 | ADD_EVENT_ID( currEventId, oneEventDelta ); | |
1267 | ||
1268 | /* Step 2: output the event */ | |
1269 | if ( workingAs == gdc ) { | |
1270 | struct ldcEventDescriptorStruct *ldc; | |
a8bf0b36 | 1271 | |
f3a800f8 | 1272 | outputEvent( &currGdc->header, sizeof( currGdc->header ) ); |
1273 | ||
1274 | for( ldc = currGdc->head; ldc != NULL; ldc = ldc->next ) { | |
1275 | struct equipmentEventDescriptorStruct *eq; | |
a8bf0b36 | 1276 | |
f3a800f8 | 1277 | outputEvent( &ldc->header, sizeof( ldc->header ) ); |
1278 | ||
1279 | for ( eq = ldc->head; eq != NULL; eq = eq->next ) { | |
1280 | outputEvent( &eq->header, sizeof( eq->header ) ); | |
1281 | outputEvent( eq->payload->data, eq->payload->size ); | |
1282 | if ( !bufferData ) unloadBuffer( eq->payload ); | |
1283 | } | |
1284 | } | |
1285 | if ( (currGdc = currGdc->next) == NULL ) | |
1286 | currGdc = (struct gdcEventDescriptorStruct *)eventsHead; | |
1287 | } else if ( workingAs == ldc ) { | |
1288 | struct equipmentEventDescriptorStruct *eq; | |
a8bf0b36 | 1289 | |
f3a800f8 | 1290 | outputEvent( &currLdc->header, sizeof( currLdc->header ) ); |
a8bf0b36 | 1291 | |
f3a800f8 | 1292 | for ( eq = currLdc->head; eq != NULL; eq = eq->next ) { |
1293 | outputEvent( &eq->header, sizeof( eq->header ) ); | |
1294 | outputEvent( eq->payload->data, eq->payload->size ); | |
1295 | if ( !bufferData ) unloadBuffer( eq->payload ); | |
1296 | } | |
1297 | if ( (currLdc = currLdc->next) == NULL ) | |
1298 | currLdc = (struct ldcEventDescriptorStruct *)eventsHead; | |
1299 | } | |
1300 | } /* End of createEvent */ | |
1301 | ||
1302 | void createEvents() { | |
1303 | int eventNum = 0; | |
1304 | ||
1305 | currGdc = (struct gdcEventDescriptorStruct *)eventsHead; | |
1306 | currLdc = (struct ldcEventDescriptorStruct *)eventsHead; | |
1307 | currEvent = NULL; | |
1308 | ||
1309 | createSor(); | |
1310 | for ( eventNum = 0; | |
1311 | eventNum != numOfEvents && numOfEvents != 0; | |
1312 | eventNum++ ) { | |
1313 | createEvent(); | |
1314 | } | |
1315 | createEor(); | |
1316 | } /* End of createEvents */ | |
1317 | ||
1318 | int usage() { | |
1319 | fprintf( stderr, | |
1320 | "Usage: %s [-?][-d][-i definitionFile][-o outputFile][-# numOfEvents][-s][-F|-C]\n\ | |
1321 | -? This text\n\ | |
1322 | -v Print version ID and exit\n\ | |
1323 | -d Enable debug (repeat for more verbosity)\n\ | |
1324 | -i definitionFile File with the description of the events to create (default: stdin)\n\ | |
1325 | -o outputFile File used to store events (default: stdout)\n\ | |
1326 | -# numOfEvents Number of events to generate (default: 1 event)\n\ | |
1327 | -s Do not generate SOR/EOR files (valid only for GDCs)\n\ | |
1328 | -F/-C Working in Fixed Target (F) or Collider (C) mode\n\ | |
1329 | -c Handles CDH\n\ | |
1330 | -D Direct disc access (no buffering)\n", | |
1331 | myName ); | |
1332 | return 1; | |
1333 | } /* End of usage */ | |
1334 | ||
1335 | void parseArgs( int argc, char **argv ) { | |
1336 | int arg = 1; | |
1337 | int inFileName = -1; | |
1338 | int outFileName = -1; | |
1339 | ||
1340 | myName = argv[0] ; | |
1341 | while ( arg < argc ) { | |
1342 | if ( strcmp( "-?", argv[ arg ] ) == 0 ) { | |
1343 | usage(); | |
1344 | exit( 0 ); | |
1345 | } | |
1346 | if ( strcmp( "-i", argv[ arg ] ) == 0 ) { | |
1347 | if ( ++arg == argc ) exit( usage() ); | |
1348 | inFileName = arg; | |
1349 | if ( freopen( argv[arg], "r", stdin ) == NULL ){ | |
1350 | fprintf( stderr, | |
1351 | "%s: failed to open input definition \"%s\" errno:%d ", | |
1352 | myName, argv[arg], errno ); | |
1353 | perror( "" ); | |
1354 | exit( 1 ); | |
1355 | } | |
1356 | } else if ( strcmp( "-v", argv[ arg ] ) == 0 ) { | |
1357 | printf( "%s\n", fileHandlerIdent ); | |
1358 | exit( 0 ); | |
1359 | } else if ( strcmp( "-o", argv[ arg ] ) == 0 ) { | |
1360 | if ( ++arg == argc ) exit( usage() ); | |
1361 | outFileName = arg; | |
1362 | } else if ( strcmp( "-#", argv[ arg ] ) == 0 ) { | |
1363 | int n; | |
a8bf0b36 | 1364 | |
f3a800f8 | 1365 | if ( ++arg == argc ) exit( usage() ); |
1366 | if ( sscanf( argv[ arg ], "%d", &n ) != 1 ) exit( usage() ); | |
1367 | if ( n < 0 ) exit( usage() ); | |
1368 | numOfEvents = n; | |
1369 | } else if ( strcmp( "-s", argv[ arg ] ) == 0 ) { | |
1370 | createSorEor = FALSE; | |
1371 | } else if ( strcmp( "-F", argv[ arg ] ) == 0 ) { | |
1372 | workingMode = fixedTarget; | |
1373 | } else if ( strcmp( "-C", argv[ arg ] ) == 0 ) { | |
1374 | workingMode = collider; | |
1375 | } else if ( strcmp( "-d", argv[ arg ] ) == 0 ) { | |
1376 | debug++; | |
1377 | } else if ( strcmp( "-c", argv[ arg ] ) == 0 ) { | |
1378 | handleCDH = TRUE; | |
1379 | } else if ( strcmp( "-D", argv[ arg ] ) == 0 ) { | |
1380 | bufferData = FALSE; | |
f76a839a | 1381 | } else if ( strcmp( "-run", argv[ arg ] ) == 0 ) { |
1382 | int runnumber; | |
1383 | if ( ++arg == argc ) exit( usage() ); | |
1384 | if ( sscanf( argv[ arg ], "%d", &runnumber ) != 1 ) exit( usage() ); | |
1385 | if ( runnumber < 0 ) exit( usage() ); | |
1386 | currRunNb = runnumber; | |
f3a800f8 | 1387 | } else { |
1388 | fprintf( stderr, "%s: Unknown switch \"%s\"\n", myName, argv[argc] ); | |
1389 | exit( usage() ); | |
1390 | } | |
1391 | arg++; | |
1392 | } | |
1393 | ||
1394 | if ( workingMode == fixedTarget ) | |
1395 | LOAD_RAW_EVENT_ID( oneEventDelta, 1, 0, 1 ); | |
1396 | else | |
1397 | LOAD_EVENT_ID( oneEventDelta, 0, 0, 1 ); | |
1398 | ZERO_EVENT_ID( currEventId ); | |
1399 | ||
1400 | DBG_VERBOSE { | |
1401 | printf( "Configuration:\n" ); | |
1402 | printf( " Debug level: %d\n", debug ); | |
1403 | printf( " Configuration: %s\n", | |
1404 | inFileName == -1 ? "stdin" : argv[ inFileName ] ); | |
1405 | printf( " Output: %s\n", | |
1406 | outFileName == -1 ? "stdout" : argv[ outFileName ] ); | |
1407 | printf( " Working mode: %s\n", | |
1408 | workingMode == fixedTarget ? "fixed target" : "collider" ); | |
1409 | printf( " Number of events: %d\n", numOfEvents ); | |
1410 | printf( " %s SOR/EOR files\n", | |
1411 | createSorEor ? "Create" : "Do not create" ); | |
1412 | printf( " CDH handling: %s\n", | |
1413 | handleCDH ? "enabled" : "disabled" ); | |
1414 | printf( " data buffering: %s\n", | |
1415 | bufferData ? "enabled" : "DISABLED" ); | |
1416 | } | |
1417 | ||
1418 | if ( outFileName == -1 ) { | |
1419 | DBG_BASE | |
1420 | printf( "No more trace information from this point...\n" ); | |
1421 | debug = 0; | |
1422 | outF = stdout; | |
1423 | } else { | |
1424 | if ( ( outF = fopen( argv[ outFileName ], "w" ) ) == NULL ) { | |
1425 | fprintf( stderr, | |
1426 | "%s: failed to open output file \"%s\" for writing, errno:%d (%s)\n", | |
1427 | myName, | |
1428 | argv[ outFileName ], | |
1429 | errno, | |
1430 | strerror( errno ) ); | |
1431 | exit( 1 ); | |
1432 | } | |
1433 | DBG_DETAILED | |
1434 | printf( "Output file \"%s\" opened OK for writing\n", | |
1435 | argv[ outFileName ] ); | |
1436 | } | |
1437 | } /* End of parseArgs */ | |
1438 | void initEquipment( struct equipmentHeaderStruct * const eq ) { | |
1439 | memset( eq, 0, sizeof( *eq ) ); | |
1440 | RESET_ATTRIBUTES( eq->equipmentTypeAttribute ); | |
1441 | eq->equipmentBasicElementSize = 4; | |
1442 | } /* End of initEquipment */ | |
1443 | ||
1444 | void decodeCDH( struct ldcEventDescriptorStruct * const ldc, | |
43e9e2a9 | 1445 | const struct payloadDescriptorStruct * const payloadDesc, |
1446 | equipmentIdType id ) { | |
1447 | if ( handleCDH && | |
1448 | id != 4352 ) { | |
f3a800f8 | 1449 | struct commonDataHeaderStruct *cdh; |
1450 | static int softwareTriggerIndicator = FALSE; | |
1451 | int attr; | |
1452 | int trig; | |
a8bf0b36 | 1453 | |
f3a800f8 | 1454 | if ( payloadDesc->size < CDH_SIZE ) { |
1455 | fprintf( stderr, | |
1456 | "%s: payload too small got:%d CDH:%d\n", | |
1457 | myName, | |
1458 | payloadDesc->size, | |
1459 | CDH_SIZE ); | |
1460 | exit( 1 ); | |
1461 | } | |
1462 | if ( (cdh = (struct commonDataHeaderStruct *)payloadDesc->data) != NULL ) { | |
1463 | if ( cdh->cdhVersion != CDH_VERSION ) { | |
1464 | fprintf( stderr, | |
1465 | "%s: CDH version mismatch expected:%d got:%d\n", | |
1466 | myName, | |
1467 | CDH_VERSION, | |
1468 | cdh->cdhVersion ); | |
1469 | exit( 1 ); | |
1470 | } | |
1471 | if ( cdhRef == NULL ) { | |
1472 | cdhRef = cdh; | |
1473 | #define CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK (1<<CDH_TRIGGER_INFORMATION_UNAVAILABLE_BIT) | |
1474 | gotAliceTrigger = (cdhRef->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) == 0; | |
1475 | if ( gotAliceTrigger && workingMode == fixedTarget ) { | |
1476 | fprintf( stderr, | |
1477 | "%s: ALICE trigger and fixed target mode are not compatible.\n\ | |
1478 | Either work in Collider mode or set the trigger unavailable status bit in the CDH.\n", | |
1479 | myName ); | |
1480 | exit( 1 ); | |
1481 | } | |
1482 | if ( gotAliceTrigger ) { | |
1483 | if ( (cdh->cdhL1TriggerMessage & 0x40) != 0 ) { | |
1484 | fprintf( stderr, | |
1485 | "%s: CDH is a calibration trigger (unsupported) L1TriggerMessage:0x%x\n", | |
1486 | myName, cdh->cdhL1TriggerMessage ); | |
1487 | exit( 1 ); | |
1488 | } | |
1489 | if ( (cdh->cdhL1TriggerMessage & 0x01) != 0 ) { | |
1490 | softwareTriggerIndicator = TRUE; | |
1491 | } | |
1492 | if ( softwareTriggerIndicator ) { | |
1493 | switch ((cdh->cdhL1TriggerMessage >> 2) & 0xF) { | |
1494 | case 0xD: | |
1495 | case 0xC: | |
1496 | case 0xB: | |
1497 | case 0xA: | |
1498 | case 0x9: | |
1499 | break; | |
1500 | case 0xF: | |
1501 | /* L1SwC bit = on, Clt bit = off, RoC[4..1] = 0xF --> END_OF_DATA */ | |
1502 | case 0xE: | |
1503 | /* L1SwC bit = on, Clt bit = off, RoC[4..1] = 0xE0 --> START_OF_DATA */ | |
1504 | case 0x8: | |
1505 | /* L1SwC bit = on, Clt bit = off, RoC[4] = 1, but not 0xE or 0xF | |
1506 | --> SYSTEM_SOFTWARE_TRIGGER_EVENT */ | |
1507 | default: | |
1508 | /* L1SwC bit = on, Clt bit = off, RoC[4] = 0 | |
1509 | --> DETECTOR_SOFTWARE_TRIGGER_EVENT */ | |
1510 | fprintf( stderr, | |
1511 | "%s: CDH trigger SOD/EOD/SST/DST (unsupported) \ | |
1512 | L1TriggerMessage:0x%x ALICETrigger:%s\n", | |
1513 | myName, | |
1514 | cdh->cdhL1TriggerMessage, | |
1515 | gotAliceTrigger ? "yes" : "no" ); | |
1516 | exit( 1 ); | |
1517 | } | |
1518 | } | |
1519 | } | |
1520 | } else { | |
1521 | if ( (cdh->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) != | |
1522 | (cdhRef->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) ) { | |
1523 | fprintf( stderr, | |
1524 | "%s: CDH coherency check failed. \ | |
1525 | Trigger information reference:%savailable current:%savailable\n", | |
1526 | myName, | |
1527 | (cdhRef->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) == 0 ? "UN" : "", | |
1528 | (cdh->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) == 0 ? "UN" : "" ); | |
1529 | exit( 1 ); | |
1530 | } | |
1531 | if ( gotAliceTrigger ) { | |
1532 | if ( cdhRef->cdhL1TriggerMessage != cdh->cdhL1TriggerMessage ) { | |
1533 | fprintf( stderr, | |
1534 | "%s: CDH coherency check failed. \ | |
1535 | L1 trigger message reference:0x%x current:0x%x\n", | |
1536 | myName, | |
1537 | cdhRef->cdhL1TriggerMessage, | |
1538 | cdh->cdhL1TriggerMessage ); | |
1539 | exit( 1 ); | |
1540 | } | |
1541 | if ( cdh->cdhParticipatingSubDetectors != cdhRef->cdhParticipatingSubDetectors ) { | |
1542 | fprintf( stderr, | |
1543 | "%s: CDH coherency check failed. \ | |
1544 | ParticipatingSubDetectors reference:0x%x current:0x%x\n", | |
1545 | myName, | |
1546 | cdhRef->cdhParticipatingSubDetectors, | |
1547 | cdh->cdhParticipatingSubDetectors ); | |
1548 | exit( 1 ); | |
1549 | } | |
1550 | if ( cdh->cdhTriggerClassesLow != cdhRef->cdhTriggerClassesLow | |
1551 | || cdh->cdhTriggerClassesHigh != cdhRef->cdhTriggerClassesHigh ) { | |
1552 | fprintf( stderr, | |
1553 | "%s: CDH coherency check failed. \ | |
1554 | TriggerClassesHigh/Low reference:0x%x-%x current:0x%x-%x\n", | |
1555 | myName, | |
1556 | cdhRef->cdhTriggerClassesHigh, cdhRef->cdhTriggerClassesLow, | |
1557 | cdh ->cdhTriggerClassesHigh, cdh ->cdhTriggerClassesLow ); | |
1558 | exit( 1 ); | |
1559 | } | |
1560 | if ( cdh->cdhBlockLength != 0xffffffff ) { | |
1561 | if ( (unsigned)payloadDesc->size != cdh->cdhBlockLength ) { | |
1562 | fprintf( stderr, | |
1563 | "%s: CDH coherency check failed. \ | |
1564 | Payload size:%d (0x%08x) CDH block length:%d (0x%08x)\n", | |
1565 | myName, | |
1566 | payloadDesc->size, payloadDesc->size, | |
1567 | cdh->cdhBlockLength, cdh->cdhBlockLength ); | |
1568 | exit( 1 ); | |
1569 | } | |
1570 | } | |
1571 | if ( cdh->cdhRoiLow != cdhRef->cdhRoiLow | |
1572 | || cdh->cdhRoiHigh != cdhRef->cdhRoiHigh ) { | |
1573 | fprintf( stderr, | |
1574 | "%s: CDH coherency check failed. \ | |
1575 | RoiHigh/Low reference:0x%x-%x current:0x%x-%x\n", | |
1576 | myName, | |
1577 | cdhRef->cdhRoiHigh, cdhRef->cdhRoiLow, | |
1578 | cdh ->cdhRoiHigh, cdh ->cdhRoiLow ); | |
1579 | exit( 1 ); | |
1580 | } | |
1581 | } | |
1582 | if ( cdh->cdhMBZ0 != 0 | |
1583 | || cdh->cdhMBZ1 != 0 | |
1584 | || cdh->cdhMBZ2 != 0 | |
1585 | || cdh->cdhMBZ3 != 0 ) { | |
1586 | fprintf( stderr, | |
1587 | "%s: CDH check failed. MBZ0:0x%x MBZ1:0x%x MBZ2:0x%x MBZ3:0x%x\n", | |
1588 | myName, | |
1589 | cdh->cdhMBZ0, cdh->cdhMBZ1, cdh->cdhMBZ2, cdh->cdhMBZ3 ); | |
1590 | exit( 1 ); | |
1591 | } | |
1592 | } | |
1593 | for ( attr = 0; attr != 8; attr++ ) { | |
1594 | if ( (cdh->cdhBlockAttributes & (1<<attr)) != 0 ) { | |
1595 | SET_USER_ATTRIBUTE( ldc->header.eventTypeAttribute, attr ); | |
1596 | } | |
1597 | } | |
1598 | for ( trig = 0; trig != 32; trig++ ) { | |
1599 | if ( (cdh->cdhTriggerClassesLow & (1<<trig)) != 0 ) { | |
1600 | SET_TRIGGER_IN_PATTERN( ldc->header.eventTriggerPattern, | |
1601 | trig ); | |
1602 | } | |
1603 | } | |
1604 | for ( trig = 0; trig != 18; trig++ ) { | |
1605 | if ( (cdh->cdhTriggerClassesHigh & (1<<trig)) != 0 ) { | |
1606 | SET_TRIGGER_IN_PATTERN( ldc->header.eventTriggerPattern, | |
1607 | 32+trig ); | |
1608 | } | |
1609 | } | |
1610 | if ( gotAliceTrigger ) | |
1611 | VALIDATE_TRIGGER_PATTERN( ldc->header.eventTriggerPattern ); | |
1612 | } | |
1613 | } | |
1614 | } /* End of decodeCDH */ | |
1615 | ||
1616 | void initEvents() { | |
1617 | assert( workingAs == ldc || workingAs == gdc ); | |
1618 | ||
1619 | if ( workingAs == gdc ) { | |
1620 | struct gdcEventDescriptorStruct *gdc; | |
1621 | ||
1622 | for ( gdc = (struct gdcEventDescriptorStruct *)eventsHead; | |
1623 | gdc != NULL; | |
1624 | gdc = gdc->next ) { | |
1625 | struct ldcEventDescriptorStruct *ldc; | |
a8bf0b36 | 1626 | |
f3a800f8 | 1627 | initEvent( &gdc->header ); |
1628 | gdc->header.eventSize = gdc->header.eventHeadSize; | |
1629 | gdc->header.eventType = PHYSICS_EVENT; | |
1630 | SET_SYSTEM_ATTRIBUTE( gdc->header.eventTypeAttribute, ATTR_SUPER_EVENT ); | |
1631 | gdc->header.eventGdcId = currGdcId; | |
f59c50c6 | 1632 | COPY_DETECTOR_PATTERN(&currDetPattern, gdc->header.eventDetectorPattern); |
f3a800f8 | 1633 | for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) { |
1634 | struct equipmentEventDescriptorStruct *eq; | |
1635 | ||
1636 | initEvent( &ldc->header ); | |
1637 | ldc->header.eventSize = ldc->header.eventHeadSize; | |
1638 | ldc->header.eventType = PHYSICS_EVENT; | |
1639 | ldc->header.eventGdcId = currGdcId; | |
f59c50c6 | 1640 | COPY_DETECTOR_PATTERN(&currDetPattern, ldc->header.eventDetectorPattern); |
f3a800f8 | 1641 | ldc->header.eventLdcId = ldc->id; |
1642 | for ( eq = ldc->head; eq != NULL; eq = eq->next ) { | |
1643 | initEquipment( &eq->header ); | |
1644 | eq->header.equipmentId = eq->id; | |
1645 | if ( workingMode == collider ) | |
1646 | SET_SYSTEM_ATTRIBUTE( eq->header.equipmentTypeAttribute, | |
1647 | ATTR_ORBIT_BC ); | |
1648 | eq->header.equipmentSize = eq->payload->size + sizeof( eq->header ); | |
1649 | ldc->header.eventSize += eq->header.equipmentSize; | |
43e9e2a9 | 1650 | decodeCDH( ldc, eq->payload, eq->id ); |
f3a800f8 | 1651 | OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute, |
1652 | ldc->header.eventTypeAttribute ); | |
1653 | OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute, | |
1654 | gdc->header.eventTypeAttribute ); | |
1655 | } | |
1656 | gdc->header.eventSize += ldc->header.eventSize; | |
1657 | } | |
5d4d6c66 | 1658 | cdhRef = NULL; |
f3a800f8 | 1659 | } |
1660 | ||
1661 | DBG_VERBOSE { | |
1662 | printf( "Headers:\n" ); | |
1663 | for ( gdc = (struct gdcEventDescriptorStruct *)eventsHead; | |
1664 | gdc != NULL; | |
1665 | gdc = gdc->next ) { | |
1666 | struct ldcEventDescriptorStruct *ldc; | |
1667 | ||
1668 | printf( " GDC:%d size:%d vers:%08x\n", | |
1669 | currGdcId, | |
1670 | gdc->header.eventSize, | |
1671 | gdc->header.eventVersion); | |
1672 | for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) { | |
1673 | struct equipmentEventDescriptorStruct *eq; | |
1674 | ||
1675 | printf( " LDC:%d size:%d vers:%08x\n", | |
1676 | ldc->id, | |
1677 | ldc->header.eventSize, | |
1678 | ldc->header.eventVersion ); | |
1679 | for ( eq = ldc->head; eq != NULL; eq = eq->next ) { | |
1680 | printf( " EQ:%d size:%d %spayload:%d\n", | |
1681 | eq->id, | |
1682 | eq->header.equipmentSize, | |
1683 | eq->header.equipmentSize - sizeof( struct equipmentHeaderStruct ) == (unsigned)eq->payload->size ? "" : "-ERROR", | |
1684 | eq->payload->size ); | |
1685 | } | |
1686 | } | |
1687 | } | |
1688 | } | |
1689 | } else if ( workingAs == ldc ) { | |
1690 | struct ldcEventDescriptorStruct *ldc; | |
a8bf0b36 | 1691 | |
f3a800f8 | 1692 | for ( ldc = (struct ldcEventDescriptorStruct *)eventsHead; |
1693 | ldc != NULL; | |
1694 | ldc = ldc->next ) { | |
1695 | struct equipmentEventDescriptorStruct *eq; | |
1696 | ||
1697 | initEvent( &ldc->header ); | |
1698 | ldc->header.eventSize = ldc->header.eventHeadSize; | |
1699 | ldc->header.eventType = PHYSICS_EVENT; | |
1700 | ldc->header.eventGdcId = VOID_ID; | |
1701 | ldc->header.eventLdcId = ldc->id; | |
1702 | for ( eq = ldc->head; eq != NULL; eq = eq->next ) { | |
1703 | initEquipment( &eq->header ); | |
1704 | eq->header.equipmentId = eq->id; | |
1705 | if ( workingMode == collider ) | |
1706 | SET_SYSTEM_ATTRIBUTE( eq->header.equipmentTypeAttribute, | |
1707 | ATTR_ORBIT_BC ); | |
1708 | eq->header.equipmentSize = eq->payload->size + sizeof( eq->header ); | |
1709 | ldc->header.eventSize += eq->header.equipmentSize; | |
43e9e2a9 | 1710 | decodeCDH( ldc, eq->payload, eq->id ); |
f3a800f8 | 1711 | OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute, |
1712 | ldc->header.eventTypeAttribute ); | |
1713 | } | |
5d4d6c66 | 1714 | cdhRef = NULL; |
f3a800f8 | 1715 | } |
1716 | DBG_VERBOSE { | |
1717 | printf( "Headers:\n" ); | |
1718 | for ( ldc = (struct ldcEventDescriptorStruct *)eventsHead; | |
1719 | ldc != NULL; | |
1720 | ldc = ldc->next ) { | |
1721 | struct equipmentEventDescriptorStruct *eq; | |
1722 | ||
1723 | printf( " LDC:%d size:%d vers:%08x\n", | |
1724 | ldc->id, | |
1725 | ldc->header.eventSize, | |
1726 | ldc->header.eventVersion ); | |
1727 | for ( eq = ldc->head; eq != NULL; eq = eq->next ) { | |
1728 | printf( " EQ:%d size:%d %spayload:%d\n", | |
1729 | eq->id, | |
1730 | eq->header.equipmentSize, | |
1731 | eq->header.equipmentSize - sizeof( struct equipmentHeaderStruct ) == (unsigned)eq->payload->size ? "" : "-ERROR", | |
1732 | eq->payload->size ); | |
1733 | } | |
1734 | } | |
1735 | } | |
1736 | } | |
1737 | } /* End of initEvents */ | |
1738 | ||
1739 | void initVars() { | |
1740 | debug = 0; | |
1741 | workingAs = unknown; | |
1742 | workingMode = fixedTarget; | |
1743 | ldcsHead = ldcsTail = NULL; | |
1744 | eventsHead = eventsTail = NULL; | |
1745 | currGdc = NULL; | |
1746 | currLdc = NULL; | |
1747 | currEvent = NULL; | |
1748 | payloadsHead = payloadsTail = NULL; | |
f76a839a | 1749 | currRunNb = -1; |
f3a800f8 | 1750 | numOfLdcs = 0; |
1751 | numOfEvents = 1; | |
1752 | createSorEor = TRUE; | |
1753 | handleCDH = FALSE; | |
1754 | gotAliceTrigger = TRUE; | |
1755 | bufferData=TRUE; | |
1756 | } /* End of initVars */ | |
1757 | ||
1758 | int main( int argc, char **argv ) { | |
1759 | initVars(); | |
1760 | parseArgs( argc, argv ); | |
1761 | parseRules(); | |
1762 | initEvents(); | |
1763 | createEvents(); | |
1764 | return 0; | |
1765 | } /* End of main */ |