5 Utility to simulate a DATE raw data stream using a given set of raw
6 data files and a configuration file.
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
26 #define DESCRIPTION "DATE raw data stream simulator"
30 char fileHandlerIdent[]= "@(#)""" __FILE__ """: """ DESCRIPTION \
32 """ compiled """ __DATE__ """ """ __TIME__;
34 #define DBG_BASE if ( debug > 0 )
35 #define DBG_DETAILED if ( debug > 1 )
36 #define DBG_VERBOSE if ( debug > 2 )
39 # define TRUE (0 == 0)
42 # define FALSE (0 == 1)
48 typedef enum { unknown, ldc, gdc } workingAsType;
49 typedef enum { collider, fixedTarget } workingModeType;
50 workingAsType workingAs;
51 workingModeType workingMode;
52 struct ldcDescriptorStruct {
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;
63 unsigned long32 detPattern;
64 eventTimestampSecType timestamp;
66 struct ldcEventDescriptorStruct {
67 struct equipmentEventDescriptorStruct *head;
68 struct equipmentEventDescriptorStruct *tail;
69 struct ldcEventDescriptorStruct *next;
71 struct eventHeaderStruct header;
73 unsigned long32 detPattern;
74 eventTimestampSecType timestamp;
76 struct equipmentEventDescriptorStruct {
77 struct equipmentEventDescriptorStruct *next;
79 struct payloadDescriptorStruct *payload;
80 struct equipmentHeaderStruct header;
82 struct payloadDescriptorStruct {
83 struct payloadDescriptorStruct *next;
88 } *payloadsHead, *payloadsTail;
90 eventGdcIdType currGdcId;
91 unsigned long32 currDetPattern;
92 eventTimestampSecType currTimestamp;
93 eventLdcIdType currLdcId;
94 equipmentIdType currEquipmentId;
100 eventIdType oneEventDelta;
101 eventIdType currEventId;
105 struct commonDataHeaderStruct *cdhRef = NULL;
107 void dumpPayload( const struct payloadDescriptorStruct *p ) {
112 if ( p->data != NULL ) {
113 for ( i = 0, c = (char *)p->data, printable = TRUE;
114 printable && i != p->size;
116 printable = isascii( *c );
119 for ( i = 0, c = (char *)p->data; i != p->size; c++, i++ ) {
125 if ( *c != '\n' ) printf( "\"\n" );
128 for ( i = 0, v = (long32 *)p->data;
131 if ( i % (4*8) == 0 ) {
132 if ( i != 0 ) printf( "\n" );
135 printf( "%08x ", *v );
141 while ( i != p->size ) {
142 printf( "%02x ", *((char *)p->data + p->size - j - 1) & 0xff );
150 } /* End of dumpPayload */
153 assert( workingAs == ldc || workingAs == gdc );
154 if ( eventsHead != NULL ) {
155 printf( "Events:\n" );
156 if ( workingAs == gdc ) {
157 struct gdcEventDescriptorStruct *gdc;
159 for ( gdc = (struct gdcEventDescriptorStruct *)eventsHead;
162 struct ldcEventDescriptorStruct *ldc;
164 printf( " GDC (%p)\n", (void*)gdc );
165 for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) {
166 struct equipmentEventDescriptorStruct *eq;
168 printf( " LDC (%p): %d\n", (void*)ldc, ldc->id );
169 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
170 printf( " EQUIPMENT (%p): %d PAYLOAD (%p):",
173 (void*)eq->payload );
175 printf( "\"%s\" (%d bytes)\n",
176 eq->payload->fileName,
178 dumpPayload( eq->payload );
183 if ( workingAs == ldc ) {
184 struct ldcEventDescriptorStruct *ldc;
186 for ( ldc = (struct ldcEventDescriptorStruct *)eventsHead;
189 struct equipmentEventDescriptorStruct *eq;
192 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
193 printf( " EQUIPMENT (%p): %d PAYLOAD (%p):",
196 (void*)eq->payload );
198 printf( "\"%s\" (%d bytes)\n",
199 eq->payload->fileName,
201 dumpPayload( eq->payload );
206 printf( "Events: EMPTY\n" );
208 } /* End of dumpEvents */
210 void getLine( char *line, const int maxSize ) {
214 for ( read = 0; !feof( stdin ) && !ferror( stdin ) && read != maxSize; read++ ) {
215 if ( (line[read] = getchar()) == '\n' ) break;
217 if ( ferror( stdin ) ) {
219 "%s: failed to read configuration input errno:%d ",
224 if ( feof( stdin ) ) read--;
225 if ( read == maxSize && line[read] != '\n' ) {
227 "%s: Input line # %d too long (%d chars max)\n",
228 myName, lineNmb, maxSize-1 );
233 if ( !( read == 0 && feof( stdin ) ) ) {
234 printf( "%d) [%3d] \"%s\"", lineNmb, read, line );
237 for ( c = 0; c != read; c++ ) {
238 if ( line[c] == '#' ) {
245 printf( " => \"%s\"", line );
247 if ( feof( stdin ) ) printf( "<<< EOF >>>" );
248 if ( ferror( stdin ) ) printf( "<<< FERROR >>>" );
251 } /* End of getLine */
253 void handleLdc( eventLdcIdType ldcId ) {
254 struct ldcDescriptorStruct *ldc;
256 if ( ldcsHead != NULL ) {
257 for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) {
258 if ( ldc->id == ldcId ) {
263 if ( (ldc = (struct ldcDescriptorStruct *)malloc( sizeof( *ldc ) )) == NULL ) {
265 "%s: Failed to malloc for %d bytes (struct ldcDescriptorStruct)\n",
266 myName, (int)sizeof( *ldc ) );
271 if ( ldcsHead == NULL ) {
272 ldcsHead = ldcsTail = ldc;
274 ldcsTail->next = ldc;
278 } /* End of handleLdc */
280 void createNewEvent() {
281 assert( workingAs == ldc || workingAs == gdc );
282 if ( workingAs == ldc ) {
283 struct ldcEventDescriptorStruct *p;
285 if ( (p = (struct ldcEventDescriptorStruct *)malloc( sizeof( *p ) ))
288 "%s: failed to malloc for %d bytes (createNewEvent: struct ldcEventDescriptorStruct)",
289 myName, (int)sizeof( *p ) );
294 p->head = p->tail = NULL;
297 if ( eventsHead == NULL ) {
298 eventsHead = eventsTail = p;
300 struct ldcEventDescriptorStruct *q =
301 (struct ldcEventDescriptorStruct *)eventsTail;
307 p->detPattern = currDetPattern;
308 p->timestamp = currTimestamp;
309 } else if ( workingAs == gdc ) {
310 struct gdcEventDescriptorStruct *p;
312 if ( (p = (struct gdcEventDescriptorStruct *)malloc( sizeof( *p ) ))
315 "%s: failed to malloc for %d bytes (createNewEvent: struct gdcEventDescriptorStruct)",
316 myName, (int)sizeof( *p ) );
322 p->head = p->tail = NULL;
324 if ( eventsHead == NULL ) {
325 eventsHead = eventsTail = p;
327 struct gdcEventDescriptorStruct *q =
328 (struct gdcEventDescriptorStruct *)eventsTail;
333 p->detPattern = currDetPattern;
334 p->timestamp = currTimestamp;
336 } /* End of createNewEvent */
338 void createNewLdcEvent() {
339 struct gdcEventDescriptorStruct *gdcDesc;
340 struct ldcEventDescriptorStruct *p;
342 if ( (p = (struct ldcEventDescriptorStruct *)malloc( sizeof( *p ) ))
345 "%s: failed to malloc for %d bytes (createNewLdcEvent: struct ldcEventDescriptorStruct)",
346 myName, (int)sizeof( *p ) );
351 p->detPattern = currDetPattern;
352 p->timestamp = currTimestamp;
353 p->head = p->tail = NULL;
355 gdcDesc = (struct gdcEventDescriptorStruct *)eventsTail;
356 if ( gdcDesc->head == NULL ) {
357 gdcDesc->head = gdcDesc->tail = p;
359 gdcDesc->tail->next = p;
363 } /* End of createNewLdcEvent */
365 void loadBuffer( struct payloadDescriptorStruct * const payload ) {
369 if ( (f = fopen( payload->fileName, "r" )) == NULL ) {
371 "%s: line:%d payload file \"%s\" not found or not readable, errno:%d. ",
376 perror( "System-dependent error " );
379 if ( (payload->data = malloc( payload->size )) == NULL ) {
381 "%s: line:%d Failed to malloc for payload file \"%s\" size:%d errno:%d ",
387 perror( "System-dependent status " );
390 if ( (bytesRead = fread( payload->data, payload->fileSize, 1, f )) != 1 ) {
392 "%s: line:%d Failed to read payload file \"%s\" size:%d requested:1 got:%d feof:%s ferror:%s errno:%d ",
398 feof(f) ? "TRUE" : "false",
399 ferror(f) ? "TRUE" : "false",
401 perror( "System-dependent status " );
405 if ( payload->size != payload->fileSize ) {
406 memset( (char *)payload->data + payload->fileSize,
408 payload->size - payload->fileSize );
410 } /* End of loadBuffer */
412 void unloadBuffer( struct payloadDescriptorStruct * const payload ) {
413 if ( payload->data != NULL ) {
414 free( payload->data );
415 payload->data = NULL;
417 } /* End of unloadBuffer */
419 void unloadAllBuffers() {
420 struct payloadDescriptorStruct *payload;
422 for ( payload = payloadsHead; payload != NULL; payload = payload->next ) {
423 unloadBuffer( payload );
425 } /* End of unloadAllBuffers */
427 void loadPayload( const char *fileName ) {
428 struct payloadDescriptorStruct *payload;
430 for ( payload = payloadsHead; payload != NULL; payload = payload->next ) {
431 if ( strcmp( fileName, payload->fileName ) == 0 )
434 if ( payload == NULL ) {
437 if ( (payload = (struct payloadDescriptorStruct *)malloc( sizeof( *payload ) ))
440 "%s: failed to malloc for %d bytes (loadPayload/payloadDescriptorStruct)\n",
442 (int)sizeof( *payload ) );
445 if ( (payload->fileName = strdup( fileName )) == NULL ) {
447 "%s: failed to duplicate string \"%s\" (loadPaload/fileName)\n",
452 if ( (f = fopen( fileName, "r" )) == NULL ) {
454 "%s: line:%d payload file \"%s\" not found or not readable, errno:%d. ",
459 perror( "System-dependent error " );
462 if ( fseek( f, 0L, SEEK_END ) != 0 ) {
464 "%s: line:%d Failed to seek payload file \"%s\" errno:%d ",
469 perror( "System-dependent error " );
472 if ( (payload->size = ftell( f )) <= 0 ) {
474 "%s: line:%d Failed to get file \"%s\" size size:%d errno:%d ",
480 perror( "System-dependent status " );
483 payload->fileSize = payload->size;
484 while ( (payload->size & 3) != 0 ) payload->size++;
488 loadBuffer( payload );
490 payload->data = NULL;
493 payload->next = NULL;
494 if ( payloadsHead == NULL ) {
495 payloadsHead = payloadsTail = payload;
497 payloadsTail->next = payload;
498 payloadsTail = payload;
503 printf( "%d) Payload \"%s\" loaded at %p\n",
509 strncmp(fileName,"TRG_",4) != 0 ) {
510 struct commonDataHeaderStruct *cdh =
511 (struct commonDataHeaderStruct *)payload->data;
513 printf( " CDH: blockLenght:%d=0x%08x ",
514 cdh->cdhBlockLength, cdh->cdhBlockLength );
515 if ( cdh->cdhBlockLength < sizeof( *cdh ) ) {
516 printf( "TOO SMALL (minimum:%ld=0x%08lx)\n",
517 (unsigned long)sizeof( *cdh ),
518 (unsigned long)sizeof( *cdh ) );
520 printf( "version:%d=0x%x ", cdh->cdhVersion, cdh->cdhVersion );
521 if ( cdh->cdhVersion != CDH_VERSION ) {
522 printf( "EXPECTED:%d=%x (decoding may be inaccurate) ",
523 CDH_VERSION, CDH_VERSION );
526 printf( "L1TriggerMessage:0x%x", cdh->cdhL1TriggerMessage );
527 if ( cdh->cdhL1TriggerMessage != 0 ) {
528 for ( b = 0, n = 0; b != 10; b++ ) {
529 if ( (cdh->cdhL1TriggerMessage & (1<<b)) != 0 ) {
530 if ( n++ != 0 )printf( "+" );
532 case 0: printf( "L1SwC" ); break;
533 case 1: printf( "ESR" ); break;
534 case 2: printf( "RoC1" ); break;
535 case 3: printf( "RoC2" ); break;
536 case 4: printf( "RoC3" ); break;
537 case 5: printf( "RoC4" ); break;
538 case 6: printf( "ClT" ); break;
539 default: printf( "spare %d", b+14 );
546 if ( cdh->cdhMBZ0 != 0 )
547 printf( "MBZ0:0x%x ",
552 printf( "EventId2(orbit):%d=0x%x ",
553 cdh->cdhEventId2, cdh->cdhEventId2 );
554 printf( "EventId1(bunchCrossing):%d=0x%x ",
555 cdh->cdhEventId1, cdh->cdhEventId1 );
559 if ( cdh->cdhMBZ1 != 0 )
560 printf( "MBZ1:0x%x ",
562 printf( "BlockAttributes:0x%x",
563 cdh->cdhBlockAttributes );
564 if ( cdh->cdhBlockAttributes != 0 ) {
566 for ( b = 0, n = 0; b != 8; b++ ) {
567 if ( (cdh->cdhBlockAttributes & (1<<b)) != 0 ) {
576 printf( "ParticipatingSubDetectors:0x%x ",
577 cdh->cdhParticipatingSubDetectors );
581 if ( cdh->cdhMBZ2 != 0 )
582 printf( "MBZ2:0x%x ",
584 printf( "Status/Error:0x%x", cdh->cdhStatusErrorBits );
585 if ( cdh->cdhStatusErrorBits != 0 ) {
587 for ( b = 0,n = 0; b != 16; b++ ) {
588 if ( (cdh->cdhStatusErrorBits & (1<<b)) != 0 ) {
589 if ( n++ != 0 ) printf( "+" );
591 case 0: printf( "TriggerOverLapError" ); break;
592 case 1: printf( "TriggerMissingError" ); break;
593 case 2: printf( "DataParityError" ); break;
594 case 3: printf( "ControlParityError" ); break;
595 case 4: printf( "TriggerInformationUnavailable" ); break;
596 case 5: printf( "FEEError" ); break;
597 case 6: printf( "HLTDecision" ); break;
598 case 7: printf( "HLTPayload" ); break;
599 case 8: printf( "DDGPayload" ); break;
600 default: printf( "spare %d", b );
607 printf( "MiniEventId(bunchCrossing):%d=0x%x ",
608 cdh->cdhMiniEventId, cdh->cdhMiniEventId );
612 printf( "Trigger classes: 0x(%05x-%08x)",
613 cdh->cdhTriggerClassesHigh,
614 cdh->cdhTriggerClassesLow );
615 if ( cdh->cdhTriggerClassesHigh != 0
616 || cdh->cdhTriggerClassesLow != 0 ) {
618 for ( b=0, n=0; b != 32; b++ ) {
619 if ( (cdh->cdhTriggerClassesLow & (1<<b)) != 0 ) {
620 if ( n++ != 0 ) printf( "+" );
624 for ( b=0; b != 18; b++ ) {
625 if ( (cdh->cdhTriggerClassesHigh & (1<<b)) != 0 ) {
626 if ( n++ != 0 ) printf( "+" );
627 printf( "%d", b+32 );
635 printf( "ROI:0x(%08x-%01x)", cdh->cdhRoiHigh, cdh->cdhRoiLow );
636 if ( cdh->cdhRoiHigh != 0
637 || cdh->cdhRoiLow != 0 ) {
639 for ( b=0, n=0; b != 5; b++ ) {
640 if ( (cdh->cdhRoiLow & (1<<b)) != 0 ) {
641 if ( n++ != 0 ) printf( "+" );
645 for ( b=0; b != 32; b++ ) {
646 if ( (cdh->cdhRoiHigh & (1<<b)) != 0 ) {
647 if ( n++ != 0 ) printf( "+" );
659 printf( "%d) Payload \"%s\" already loaded at %p\n",
665 currEvent->payload = payload;
666 } /* End of loadPayload */
668 void parseEquipment( char * const line ) {
669 struct equipmentEventDescriptorStruct *equipment;
670 int payloadFound = FALSE;
675 (struct equipmentEventDescriptorStruct *)malloc( sizeof( *equipment ) )) == NULL ) {
677 "%s: filed to malloc for %d bytes (parseEquipment/equipmentEventDescriptorStruct) errno:%d ",
679 (int)sizeof( *equipment ),
684 currEvent = equipment;
687 while ( (keyword = strtok_r( p, " \t", &p )) != NULL ) {
688 DBG_VERBOSE printf( "%d) Equipment - Keyword:\"%s\"\n",
691 if ( strcasecmp( "id", keyword ) == 0 ) {
694 if ( (idNum = strtok_r( p, " \t", &p )) == NULL ) {
696 "%s: line:%d EQUIPMENT declaration, ID needed",
701 if ( sscanf( idNum, "%d", &currEquipmentId ) != 1 ) {
703 "%s: line:%d EQUIPMENT declaration, numeric ID needed (%s)",
709 DBG_VERBOSE printf( "%d) EQUIPMENT - ID:%d\n",
712 } else if ( strncasecmp( "pay", keyword, 3 ) == 0 ) {
715 if ( (fileName = strtok_r( p, " \t", &p )) == NULL ) {
717 "%s line:%d Payload without filename found\n",
722 DBG_VERBOSE printf( "%d) Equipment - Payload:\"%s\"\n",
725 if ( payloadFound ) {
727 "%s line:%d Payload with multiple filenames found\n",
732 loadPayload( fileName );
736 "%s: line:%d Equipment declaration, unknown keyword \"%s\"\n",
743 if ( !payloadFound ) {
745 "%s: line:%d Equipment without payload found\n",
751 equipment->id = currEquipmentId;
752 equipment->next = NULL;
753 if ( currLdc->head == NULL ) {
754 currLdc->head = currLdc->tail = equipment;
756 currLdc->tail->next = equipment;
757 currLdc->tail = equipment;
759 } /* End of parseEquipment */
761 void parseGdc( char * const line ) {
766 while ( (keyword = strtok_r( p, " \t", &p )) != NULL ) {
767 if ( strcasecmp( "id", keyword ) == 0 ) {
770 if ( (idNum = strtok_r( p, " \t", &p )) == NULL ) {
772 "%s: line:%d GDC declaration, ID needed",
778 if ( sscanf( idNum, "%d", &inCurrGdcId ) != 1 ) {
780 "%s: line:%d GDC declaration, numeric ID needed (%s)",
786 currGdcId = (eventGdcIdType)inCurrGdcId;
787 DBG_VERBOSE printf( "%d) GDC - ID:%d\n",
790 } else if ( strcasecmp( "DetectorPattern", keyword ) == 0 ) {
793 if ( (detPattern = strtok_r( p, " \t", &p )) == NULL ) {
795 "%s: line:%d GDC declaration, DetectorPattern needed",
800 if ( sscanf( detPattern, "%u", &currDetPattern ) != 1 ) {
802 "%s: line:%d GDC declaration, numeric DetectorPattern needed (%s)",
808 DBG_VERBOSE printf( "%d) GDC - DetectorPattern:%u\n",
811 } else if ( strcasecmp( "Timestamp", keyword ) == 0 ) {
814 if ( (timestamp = strtok_r( p, " \t", &p )) == NULL ) {
816 "%s: line:%d GDC declaration, Timestamp needed",
821 if ( sscanf( timestamp, "%u", &currTimestamp ) != 1 ) {
823 "%s: line:%d GDC declaration, numeric Timestamp needed (%s)",
829 DBG_VERBOSE printf( "%d) GDC - Timestamp:%u\n",
834 "%s: line:%d GDC declaration, unknown keyword \"%s\"\n",
841 } /* End of parseGdc */
843 void parseLdc( char * const line ) {
848 while ( (keyword = strtok_r( p, " \t", &p )) != NULL ) {
849 if ( strcasecmp( "id", keyword ) == 0 ) {
852 if ( (idNum = strtok_r( p, " \t", &p )) == NULL ) {
854 "%s: line:%d LDC declaration, ID needed",
860 if ( sscanf( idNum, "%d", &inCurrLdcId ) != 1 ) {
862 "%s: line:%d LDC declaration, numeric ID needed (%s)",
868 currLdcId = (eventLdcIdType)inCurrLdcId;
869 DBG_VERBOSE printf( "%d) LDC - ID:%d\n",
874 "%s: line:%d LDC declaration, unknown keyword \"%s\"\n",
881 } /* End of parseLdc */
886 currLdcId = HOST_ID_MIN;
887 currGdcId = HOST_ID_MIN;
891 for ( lineNmb = 1; !feof( stdin ); lineNmb++ ) {
892 getLine( line, sizeof(line) );
893 if ( strlen(line) != 0 ) {
897 if ( (keyword = strtok_r( line, " \t", &p )) != NULL ) {
898 DBG_VERBOSE printf( "%d) Keyword:\"%s\"\n", lineNmb, keyword );
899 if ( strcasecmp( "gdc", keyword ) == 0 ) {
900 if ( workingAs != gdc && workingAs != unknown ) {
902 "%s: line:%d GDC found when working in non-GDC mode (e.g. as a LDC)\n",
909 currLdcId = HOST_ID_MIN;
912 } else if ( strcasecmp( "ldc", keyword ) == 0 ) {
913 if ( workingAs != gdc && workingAs != ldc && workingAs != unknown ) {
915 "%s: line:%d LDC found when working in non-LDC/GDC mode\n",
919 if ( workingAs == unknown ) workingAs = ldc;
921 if ( workingAs == ldc ) {
926 handleLdc( currLdcId );
930 } else if ( strncasecmp( "equ", keyword, 3 ) == 0 ) {
931 if ( workingAs == unknown
932 || (workingAs == ldc && currLdc == NULL )
933 || (workingAs == gdc && currGdc == NULL ) ) {
935 "%s: line:%d Unexpected EQUIPMENT declaration (LDC or GDC needed first)\n",
944 "%s: line:%d Parse error in \"%s\" unknown keyword\n",
952 } while ( !feof( stdin ) ) {}
956 printf( "End of parse: %d line%s found\n",
958 lineNmb != 1 ? "s" : "" );
959 printf( "Working as %s\n",
960 workingAs == gdc ? "GDC" :
961 workingAs == ldc ? "LDC" :
963 if ( workingAs == gdc ) {
964 struct ldcDescriptorStruct *ldc;
966 printf( "LDCs (%d):", numOfLdcs );
967 for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) {
968 printf( " %d", ldc->id );
975 if ( workingAs == ldc ) {
976 assert( ldcsHead == ldcsTail );
977 assert( ldcsTail == NULL );
980 if ( workingAs == gdc ) {
981 struct ldcDescriptorStruct *ldc;
983 assert( ldcsHead != NULL );
984 assert( ldcsTail != NULL );
985 assert( ldcsTail->next == NULL );
986 for ( ldc = ldcsHead; ldc->next != NULL; ldc = ldc->next ) {}
987 assert ( ldc == ldcsTail );
990 if ( workingAs == unknown ) {
991 DBG_VERBOSE printf( "Empty configuration: nothing to do!\n" );
995 assert( (eventsHead == NULL && eventsTail == NULL)
996 || (eventsHead != NULL && eventsTail != NULL) );
997 } /* End of parseRules */
999 void initEvent( struct eventHeaderStruct * const ev ) {
1000 memset( ev, 0, sizeof( *ev ) );
1002 ev->eventMagic = EVENT_MAGIC_NUMBER;
1003 ev->eventHeadSize = EVENT_HEAD_BASE_SIZE;
1004 ev->eventVersion = EVENT_CURRENT_VERSION;
1005 ev->eventRunNb = currRunNb;
1006 ZERO_EVENT_ID( ev->eventId );
1007 ZERO_TRIGGER_PATTERN( ev->eventTriggerPattern );
1008 ZERO_DETECTOR_PATTERN( ev->eventDetectorPattern );
1009 RESET_ATTRIBUTES( ev->eventTypeAttribute );
1010 if ( workingMode == collider )
1011 SET_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_ORBIT_BC );
1012 ev->eventLdcId = VOID_ID;
1013 ev->eventGdcId = VOID_ID;
1014 } /* End of initEvent */
1018 // Swap the endianess of the integer value 'x'
1020 return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) << 8) |
1021 ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24));
1024 void outputEvent( const void * const ev,
1029 const long32 * const v = (long32 *)ev;
1030 printf( "Writing %d bytes @ %p (%d)\n", size, ev, *v );
1033 // .............................Test endianess..............................
1035 char* ptemp = (char*) &temp;
1037 if (ptemp[0]!=1) { // Mac platform: ptemp != 1..............................................................................
1038 int bufSize= size; if (bufSize > (int) sizeof(eventHeaderStruct)) { bufSize = sizeof(eventHeaderStruct); }
1039 char* evTemp = (char*) malloc (bufSize);
1040 memcpy(evTemp, ev, bufSize);
1042 if ((bufSize % sizeof(int)) != 0) {
1043 fprintf( stderr, "%s: size of the input buffer ev is not multiple of 4 (size = %d)\n", myName, bufSize);
1047 // Invert header to evTemp.....................................................
1048 int* buf = (int*) evTemp;
1049 for (int i=0; i < (int) (bufSize / sizeof(int)); i++, buf++) {
1050 int value = Swap(*buf);
1051 memcpy(evTemp + (i * sizeof(int)), &value, sizeof(int));
1054 // Write inverted header to file...............................................
1055 if ((done = fwrite( evTemp, bufSize, 1, outF )) != 1 ) {
1056 fprintf( stderr, "%s: failed to write inverted header. event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) );
1060 if (size > bufSize) { // Still theraw-data payload to write (but not inverted, since it is inverted eariler).............
1061 if ((done = fwrite( (char*)ev + bufSize, size - bufSize, 1, outF )) != 1 ) {
1062 fprintf( stderr, "%s: failed to write additional event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) );
1069 else { // Intel platform: ptemp == 1............................................................................
1070 if ((done = fwrite( ev, size, 1, outF )) != 1 ) {
1071 fprintf( stderr, "%s: failed to write event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) );
1075 } /* End of outputEvent */
1077 void createSorAndEor( const int sor ) {
1078 unsigned char event[ 1000 ];
1079 struct eventHeaderStruct *ev;
1080 struct eventHeaderStruct sev;
1082 assert( workingAs == ldc || workingAs == gdc );
1084 if ( !createSorEor ) return;
1085 ev = (struct eventHeaderStruct *)event;
1087 ev->eventSize = sizeof( event );
1088 ev->eventType = sor ? START_OF_RUN : END_OF_RUN;
1089 if ( workingMode == fixedTarget )
1090 LOAD_RAW_EVENT_ID( ev->eventId, 0, 0, 0 );
1092 LOAD_EVENT_ID( ev->eventId, 0, 0, 0 );
1093 SET_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_P_START );
1095 if ( workingAs == ldc ) {
1096 currLdc = (struct ldcEventDescriptorStruct *)eventsHead;
1098 if ( workingAs == gdc ) {
1100 sev.eventGdcId = currGdcId;
1101 ev->eventGdcId = currGdcId;
1102 currGdc = (struct gdcEventDescriptorStruct *)eventsHead;
1103 currLdc = currGdc->head;
1105 ev->eventLdcId = currLdc->id;
1107 if ( workingAs == ldc ) {
1108 outputEvent( ev, ev->eventSize );
1110 if ( workingAs == gdc ) {
1111 struct ldcDescriptorStruct *ldc;
1113 sev.eventSize = sizeof( sev ) + numOfLdcs * ev->eventSize;
1114 sev.eventType = sor ? START_OF_RUN : END_OF_RUN ;
1115 COPY_EVENT_ID( ev->eventId, sev.eventId );
1116 COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute );
1117 SET_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT );
1118 outputEvent( &sev, sizeof( sev ) );
1120 ev->eventGdcId = currGdcId;
1121 for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) {
1122 ev->eventLdcId = ldc->id;
1123 outputEvent( ev, ev->eventSize );
1127 ADD_EVENT_ID( ev->eventId, oneEventDelta );
1128 ev->eventSize = ev->eventSize / 2;
1129 ev->eventType = sor ? START_OF_RUN_FILES : END_OF_RUN_FILES;
1130 CLEAR_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_P_START );
1131 if ( workingAs == ldc ) {
1132 outputEvent( ev, ev->eventSize );
1134 if ( workingAs == gdc ) {
1135 struct ldcDescriptorStruct *ldc;
1137 sev.eventSize = ev->eventSize;
1138 sev.eventType = sor ? START_OF_RUN_FILES : END_OF_RUN_FILES;
1139 COPY_EVENT_ID( ev->eventId, sev.eventId );
1140 COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute );
1141 CLEAR_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT );
1142 outputEvent( &sev, sizeof( sev ) );
1143 outputEvent( ev, ev->eventSize - sizeof( sev ) );
1145 sev.eventSize = sizeof( sev ) + ev->eventSize;
1146 sev.eventType = sor ? START_OF_RUN_FILES : END_OF_RUN_FILES;
1147 COPY_EVENT_ID( ev->eventId, sev.eventId );
1148 COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute );
1149 SET_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT );
1151 ev->eventGdcId = currGdcId;
1152 for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) {
1153 outputEvent( &sev, sizeof( sev ) );
1154 ev->eventLdcId = ldc->id;
1155 outputEvent( ev, ev->eventSize );
1159 ADD_EVENT_ID( ev->eventId, oneEventDelta );
1160 ev->eventSize = sizeof( *ev );
1161 ev->eventType = sor ? START_OF_RUN : END_OF_RUN;
1162 SET_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_P_END );
1163 if ( workingAs == ldc ) {
1164 outputEvent( ev, ev->eventSize );
1166 if ( workingAs == gdc ) {
1167 struct ldcDescriptorStruct *ldc;
1169 sev.eventSize = sizeof( sev ) + numOfLdcs * ev->eventSize;
1170 sev.eventType = sor ? START_OF_RUN : END_OF_RUN;
1171 COPY_EVENT_ID( ev->eventId, sev.eventId );
1172 COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute );
1173 SET_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT );
1175 outputEvent( &sev, sizeof( sev ) );
1177 for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) {
1178 ev->eventLdcId = ldc->id;
1179 outputEvent( ev, ev->eventSize );
1182 } /* End of createSorEor */
1185 createSorAndEor( TRUE );
1186 } /* End of createSor */
1189 createSorAndEor( FALSE );
1190 } /* End of createEor */
1192 void loadCdh( struct commonDataHeaderStruct * const cdh,
1193 eventIdType * const eventId,
1194 equipmentIdType id ) {
1195 if ( !handleCDH ) return;
1197 // CTP raw-data does not contain CDH
1198 if ( id == 4352) return;
1200 if ( gotAliceTrigger ) {
1201 cdh->cdhEventId1 = EVENT_ID_GET_BUNCH_CROSSING( *eventId );
1202 cdh->cdhEventId2 = EVENT_ID_GET_ORBIT( *eventId );
1204 cdh->cdhEventId1 = 0;
1205 cdh->cdhEventId2 = EVENT_ID_GET_NB_IN_RUN( *eventId );
1207 cdh->cdhMiniEventId = cdh->cdhEventId1;
1209 void decodeCDH( struct ldcEventDescriptorStruct * const ldc,
1210 const struct payloadDescriptorStruct * const payloadDesc,
1211 equipmentIdType id );
1213 void createEvent( void ) {
1214 assert( workingAs == ldc || workingAs == gdc );
1216 /* Step 1: load all buffers (if needed) and compose the GDC/LDC headers */
1217 if ( workingAs == gdc ) {
1218 struct ldcEventDescriptorStruct *ldc;
1220 for( ldc = currGdc->head; ldc != NULL; ldc = ldc->next ) {
1221 COPY_EVENT_ID( currEventId, ldc->header.eventId );
1223 COPY_EVENT_ID( currEventId, currGdc->header.eventId );
1225 for( ldc = currGdc->head; ldc != NULL; ldc = ldc->next ) {
1226 struct equipmentEventDescriptorStruct *eq;
1229 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1230 if ( !bufferData ) {
1231 loadBuffer( eq->payload );
1232 decodeCDH( ldc, eq->payload, eq->id );
1234 loadCdh( (struct commonDataHeaderStruct*)eq->payload->data,
1239 if ( !currGdc->loaded ) {
1240 for ( n = 0; n != EVENT_TRIGGER_PATTERN_WORDS; n++ )
1241 currGdc->header.eventTriggerPattern[n] |= ldc->header.eventTriggerPattern[n];
1242 for ( n = 0; n != EVENT_DETECTOR_PATTERN_WORDS; n++ )
1243 currGdc->header.eventDetectorPattern[n] |= ldc->header.eventDetectorPattern[n];
1244 for ( n = 0; n != ALL_ATTRIBUTE_WORDS; n++ )
1245 currGdc->header.eventTypeAttribute[n] |= ldc->header.eventTypeAttribute[n];
1246 currGdc->loaded = TRUE;
1250 } else if ( workingAs == ldc ) {
1251 struct equipmentEventDescriptorStruct *eq;
1253 COPY_EVENT_ID( currEventId, currLdc->header.eventId );
1255 for ( eq = currLdc->head; eq != NULL; eq = eq->next ) {
1256 if ( !bufferData ) {
1257 loadBuffer( eq->payload );
1258 decodeCDH( currLdc, eq->payload, eq->id );
1260 loadCdh( (struct commonDataHeaderStruct*)eq->payload->data,
1263 currLdc->loaded = TRUE;
1267 ADD_EVENT_ID( currEventId, oneEventDelta );
1269 /* Step 2: output the event */
1270 if ( workingAs == gdc ) {
1271 struct ldcEventDescriptorStruct *ldc;
1273 outputEvent( &currGdc->header, sizeof( currGdc->header ) );
1275 for( ldc = currGdc->head; ldc != NULL; ldc = ldc->next ) {
1276 struct equipmentEventDescriptorStruct *eq;
1278 outputEvent( &ldc->header, sizeof( ldc->header ) );
1280 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1281 outputEvent( &eq->header, sizeof( eq->header ) );
1282 outputEvent( eq->payload->data, eq->payload->size );
1283 if ( !bufferData ) unloadBuffer( eq->payload );
1286 if ( (currGdc = currGdc->next) == NULL )
1287 currGdc = (struct gdcEventDescriptorStruct *)eventsHead;
1288 } else if ( workingAs == ldc ) {
1289 struct equipmentEventDescriptorStruct *eq;
1291 outputEvent( &currLdc->header, sizeof( currLdc->header ) );
1293 for ( eq = currLdc->head; eq != NULL; eq = eq->next ) {
1294 outputEvent( &eq->header, sizeof( eq->header ) );
1295 outputEvent( eq->payload->data, eq->payload->size );
1296 if ( !bufferData ) unloadBuffer( eq->payload );
1298 if ( (currLdc = currLdc->next) == NULL )
1299 currLdc = (struct ldcEventDescriptorStruct *)eventsHead;
1301 } /* End of createEvent */
1303 void createEvents() {
1306 currGdc = (struct gdcEventDescriptorStruct *)eventsHead;
1307 currLdc = (struct ldcEventDescriptorStruct *)eventsHead;
1312 eventNum != numOfEvents && numOfEvents != 0;
1317 } /* End of createEvents */
1321 "Usage: %s [-?][-d][-i definitionFile][-o outputFile][-# numOfEvents][-s][-F|-C]\n\
1323 -v Print version ID and exit\n\
1324 -d Enable debug (repeat for more verbosity)\n\
1325 -i definitionFile File with the description of the events to create (default: stdin)\n\
1326 -o outputFile File used to store events (default: stdout)\n\
1327 -# numOfEvents Number of events to generate (default: 1 event)\n\
1328 -s Do not generate SOR/EOR files (valid only for GDCs)\n\
1329 -F/-C Working in Fixed Target (F) or Collider (C) mode\n\
1331 -D Direct disc access (no buffering)\n",
1334 } /* End of usage */
1336 void parseArgs( int argc, char **argv ) {
1338 int inFileName = -1;
1339 int outFileName = -1;
1342 while ( arg < argc ) {
1343 if ( strcmp( "-?", argv[ arg ] ) == 0 ) {
1347 if ( strcmp( "-i", argv[ arg ] ) == 0 ) {
1348 if ( ++arg == argc ) exit( usage() );
1350 if ( freopen( argv[arg], "r", stdin ) == NULL ){
1352 "%s: failed to open input definition \"%s\" errno:%d ",
1353 myName, argv[arg], errno );
1357 } else if ( strcmp( "-v", argv[ arg ] ) == 0 ) {
1358 printf( "%s\n", fileHandlerIdent );
1360 } else if ( strcmp( "-o", argv[ arg ] ) == 0 ) {
1361 if ( ++arg == argc ) exit( usage() );
1363 } else if ( strcmp( "-#", argv[ arg ] ) == 0 ) {
1366 if ( ++arg == argc ) exit( usage() );
1367 if ( sscanf( argv[ arg ], "%d", &n ) != 1 ) exit( usage() );
1368 if ( n < 0 ) exit( usage() );
1370 } else if ( strcmp( "-s", argv[ arg ] ) == 0 ) {
1371 createSorEor = FALSE;
1372 } else if ( strcmp( "-F", argv[ arg ] ) == 0 ) {
1373 workingMode = fixedTarget;
1374 } else if ( strcmp( "-C", argv[ arg ] ) == 0 ) {
1375 workingMode = collider;
1376 } else if ( strcmp( "-d", argv[ arg ] ) == 0 ) {
1378 } else if ( strcmp( "-c", argv[ arg ] ) == 0 ) {
1380 } else if ( strcmp( "-D", argv[ arg ] ) == 0 ) {
1382 } else if ( strcmp( "-run", argv[ arg ] ) == 0 ) {
1384 if ( ++arg == argc ) exit( usage() );
1385 if ( sscanf( argv[ arg ], "%d", &runnumber ) != 1 ) exit( usage() );
1386 if ( runnumber < 0 ) exit( usage() );
1387 currRunNb = runnumber;
1389 fprintf( stderr, "%s: Unknown switch \"%s\"\n", myName, argv[argc] );
1395 if ( workingMode == fixedTarget )
1396 LOAD_RAW_EVENT_ID( oneEventDelta, 1, 0, 1 );
1398 LOAD_EVENT_ID( oneEventDelta, 0, 0, 1 );
1399 ZERO_EVENT_ID( currEventId );
1402 printf( "Configuration:\n" );
1403 printf( " Debug level: %d\n", debug );
1404 printf( " Configuration: %s\n",
1405 inFileName == -1 ? "stdin" : argv[ inFileName ] );
1406 printf( " Output: %s\n",
1407 outFileName == -1 ? "stdout" : argv[ outFileName ] );
1408 printf( " Working mode: %s\n",
1409 workingMode == fixedTarget ? "fixed target" : "collider" );
1410 printf( " Number of events: %d\n", numOfEvents );
1411 printf( " %s SOR/EOR files\n",
1412 createSorEor ? "Create" : "Do not create" );
1413 printf( " CDH handling: %s\n",
1414 handleCDH ? "enabled" : "disabled" );
1415 printf( " data buffering: %s\n",
1416 bufferData ? "enabled" : "DISABLED" );
1419 if ( outFileName == -1 ) {
1421 printf( "No more trace information from this point...\n" );
1425 if ( ( outF = fopen( argv[ outFileName ], "w" ) ) == NULL ) {
1427 "%s: failed to open output file \"%s\" for writing, errno:%d (%s)\n",
1429 argv[ outFileName ],
1431 strerror( errno ) );
1435 printf( "Output file \"%s\" opened OK for writing\n",
1436 argv[ outFileName ] );
1438 } /* End of parseArgs */
1439 void initEquipment( struct equipmentHeaderStruct * const eq ) {
1440 memset( eq, 0, sizeof( *eq ) );
1441 RESET_ATTRIBUTES( eq->equipmentTypeAttribute );
1442 eq->equipmentBasicElementSize = 4;
1443 } /* End of initEquipment */
1445 void decodeCDH( struct ldcEventDescriptorStruct * const ldc,
1446 const struct payloadDescriptorStruct * const payloadDesc,
1447 equipmentIdType id ) {
1450 struct commonDataHeaderStruct *cdh;
1451 static int softwareTriggerIndicator = FALSE;
1455 if ( payloadDesc->size < CDH_SIZE ) {
1457 "%s: payload too small got:%d CDH:%d\n",
1463 if ( (cdh = (struct commonDataHeaderStruct *)payloadDesc->data) != NULL ) {
1464 if ( cdh->cdhVersion != CDH_VERSION ) {
1466 "%s: CDH version mismatch expected:%d got:%d\n",
1472 if ( cdhRef == NULL ) {
1474 #define CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK (1<<CDH_TRIGGER_INFORMATION_UNAVAILABLE_BIT)
1475 gotAliceTrigger = (cdhRef->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) == 0;
1476 if ( gotAliceTrigger && workingMode == fixedTarget ) {
1478 "%s: ALICE trigger and fixed target mode are not compatible.\n\
1479 Either work in Collider mode or set the trigger unavailable status bit in the CDH.\n",
1483 if ( gotAliceTrigger ) {
1484 if ( (cdh->cdhL1TriggerMessage & 0x40) != 0 ) {
1486 "%s: CDH is a calibration trigger (unsupported) L1TriggerMessage:0x%x\n",
1487 myName, cdh->cdhL1TriggerMessage );
1490 if ( (cdh->cdhL1TriggerMessage & 0x01) != 0 ) {
1491 softwareTriggerIndicator = TRUE;
1493 if ( softwareTriggerIndicator ) {
1494 switch ((cdh->cdhL1TriggerMessage >> 2) & 0xF) {
1502 /* L1SwC bit = on, Clt bit = off, RoC[4..1] = 0xF --> END_OF_DATA */
1504 /* L1SwC bit = on, Clt bit = off, RoC[4..1] = 0xE0 --> START_OF_DATA */
1506 /* L1SwC bit = on, Clt bit = off, RoC[4] = 1, but not 0xE or 0xF
1507 --> SYSTEM_SOFTWARE_TRIGGER_EVENT */
1509 /* L1SwC bit = on, Clt bit = off, RoC[4] = 0
1510 --> DETECTOR_SOFTWARE_TRIGGER_EVENT */
1512 "%s: CDH trigger SOD/EOD/SST/DST (unsupported) \
1513 L1TriggerMessage:0x%x ALICETrigger:%s\n",
1515 cdh->cdhL1TriggerMessage,
1516 gotAliceTrigger ? "yes" : "no" );
1522 if ( (cdh->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) !=
1523 (cdhRef->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) ) {
1525 "%s: CDH coherency check failed. \
1526 Trigger information reference:%savailable current:%savailable\n",
1528 (cdhRef->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) == 0 ? "UN" : "",
1529 (cdh->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) == 0 ? "UN" : "" );
1532 if ( gotAliceTrigger ) {
1533 if ( cdhRef->cdhL1TriggerMessage != cdh->cdhL1TriggerMessage ) {
1535 "%s: CDH coherency check failed. \
1536 L1 trigger message reference:0x%x current:0x%x\n",
1538 cdhRef->cdhL1TriggerMessage,
1539 cdh->cdhL1TriggerMessage );
1542 if ( cdh->cdhParticipatingSubDetectors != cdhRef->cdhParticipatingSubDetectors ) {
1544 "%s: CDH coherency check failed. \
1545 ParticipatingSubDetectors reference:0x%x current:0x%x\n",
1547 cdhRef->cdhParticipatingSubDetectors,
1548 cdh->cdhParticipatingSubDetectors );
1551 if ( cdh->cdhTriggerClassesLow != cdhRef->cdhTriggerClassesLow
1552 || cdh->cdhTriggerClassesHigh != cdhRef->cdhTriggerClassesHigh ) {
1554 "%s: CDH coherency check failed. \
1555 TriggerClassesHigh/Low reference:0x%x-%x current:0x%x-%x\n",
1557 cdhRef->cdhTriggerClassesHigh, cdhRef->cdhTriggerClassesLow,
1558 cdh ->cdhTriggerClassesHigh, cdh ->cdhTriggerClassesLow );
1561 if ( cdh->cdhBlockLength != 0xffffffff ) {
1562 if ( (unsigned)payloadDesc->size != cdh->cdhBlockLength ) {
1564 "%s: CDH coherency check failed. \
1565 Payload size:%d (0x%08x) CDH block length:%d (0x%08x)\n",
1567 payloadDesc->size, payloadDesc->size,
1568 cdh->cdhBlockLength, cdh->cdhBlockLength );
1572 if ( cdh->cdhRoiLow != cdhRef->cdhRoiLow
1573 || cdh->cdhRoiHigh != cdhRef->cdhRoiHigh ) {
1575 "%s: CDH coherency check failed. \
1576 RoiHigh/Low reference:0x%x-%x current:0x%x-%x\n",
1578 cdhRef->cdhRoiHigh, cdhRef->cdhRoiLow,
1579 cdh ->cdhRoiHigh, cdh ->cdhRoiLow );
1583 if ( cdh->cdhMBZ0 != 0
1584 || cdh->cdhMBZ1 != 0
1585 || cdh->cdhMBZ2 != 0
1588 "%s: CDH check failed. MBZ0:0x%x MBZ1:0x%x MBZ2:0x%x\n",
1590 cdh->cdhMBZ0, cdh->cdhMBZ1, cdh->cdhMBZ2 );
1594 for ( attr = 0; attr != 8; attr++ ) {
1595 if ( (cdh->cdhBlockAttributes & (1<<attr)) != 0 ) {
1596 SET_USER_ATTRIBUTE( ldc->header.eventTypeAttribute, attr );
1599 for ( trig = 0; trig != 32; trig++ ) {
1600 if ( (cdh->cdhTriggerClassesLow & (1<<trig)) != 0 ) {
1601 SET_TRIGGER_IN_PATTERN( ldc->header.eventTriggerPattern,
1605 for ( trig = 0; trig != 18; trig++ ) {
1606 if ( (cdh->cdhTriggerClassesHigh & (1<<trig)) != 0 ) {
1607 SET_TRIGGER_IN_PATTERN( ldc->header.eventTriggerPattern,
1611 if ( gotAliceTrigger )
1612 VALIDATE_TRIGGER_PATTERN( ldc->header.eventTriggerPattern );
1615 } /* End of decodeCDH */
1618 assert( workingAs == ldc || workingAs == gdc );
1620 if ( workingAs == gdc ) {
1621 struct gdcEventDescriptorStruct *gdc;
1623 for ( gdc = (struct gdcEventDescriptorStruct *)eventsHead;
1626 struct ldcEventDescriptorStruct *ldc;
1628 initEvent( &gdc->header );
1629 gdc->header.eventSize = gdc->header.eventHeadSize;
1630 gdc->header.eventType = PHYSICS_EVENT;
1631 SET_SYSTEM_ATTRIBUTE( gdc->header.eventTypeAttribute, ATTR_SUPER_EVENT );
1632 gdc->header.eventGdcId = currGdcId;
1633 COPY_DETECTOR_PATTERN(&gdc->detPattern, gdc->header.eventDetectorPattern);
1634 gdc->header.eventTimestamp = gdc->timestamp;
1635 for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) {
1636 struct equipmentEventDescriptorStruct *eq;
1638 initEvent( &ldc->header );
1639 ldc->header.eventSize = ldc->header.eventHeadSize;
1640 ldc->header.eventType = PHYSICS_EVENT;
1641 ldc->header.eventGdcId = currGdcId;
1642 COPY_DETECTOR_PATTERN(&ldc->detPattern, ldc->header.eventDetectorPattern);
1643 ldc->header.eventTimestamp = ldc->timestamp;
1644 ldc->header.eventLdcId = ldc->id;
1645 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1646 initEquipment( &eq->header );
1647 eq->header.equipmentId = eq->id;
1648 if ( workingMode == collider )
1649 SET_SYSTEM_ATTRIBUTE( eq->header.equipmentTypeAttribute,
1651 eq->header.equipmentSize = eq->payload->size + sizeof( eq->header );
1652 ldc->header.eventSize += eq->header.equipmentSize;
1653 decodeCDH( ldc, eq->payload, eq->id );
1654 OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute,
1655 ldc->header.eventTypeAttribute );
1656 OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute,
1657 gdc->header.eventTypeAttribute );
1659 gdc->header.eventSize += ldc->header.eventSize;
1665 printf( "Headers:\n" );
1666 for ( gdc = (struct gdcEventDescriptorStruct *)eventsHead;
1669 struct ldcEventDescriptorStruct *ldc;
1671 printf( " GDC:%d size:%d vers:%08x\n",
1673 gdc->header.eventSize,
1674 gdc->header.eventVersion);
1675 for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) {
1676 struct equipmentEventDescriptorStruct *eq;
1678 printf( " LDC:%d size:%d vers:%08x\n",
1680 ldc->header.eventSize,
1681 ldc->header.eventVersion );
1682 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1683 printf( " EQ:%d size:%d %spayload:%d\n",
1685 eq->header.equipmentSize,
1686 eq->header.equipmentSize - sizeof( struct equipmentHeaderStruct ) == (unsigned)eq->payload->size ? "" : "-ERROR",
1687 eq->payload->size );
1692 } else if ( workingAs == ldc ) {
1693 struct ldcEventDescriptorStruct *ldc;
1695 for ( ldc = (struct ldcEventDescriptorStruct *)eventsHead;
1698 struct equipmentEventDescriptorStruct *eq;
1700 initEvent( &ldc->header );
1701 ldc->header.eventSize = ldc->header.eventHeadSize;
1702 ldc->header.eventType = PHYSICS_EVENT;
1703 ldc->header.eventGdcId = VOID_ID;
1704 ldc->header.eventLdcId = ldc->id;
1705 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1706 initEquipment( &eq->header );
1707 eq->header.equipmentId = eq->id;
1708 if ( workingMode == collider )
1709 SET_SYSTEM_ATTRIBUTE( eq->header.equipmentTypeAttribute,
1711 eq->header.equipmentSize = eq->payload->size + sizeof( eq->header );
1712 ldc->header.eventSize += eq->header.equipmentSize;
1713 decodeCDH( ldc, eq->payload, eq->id );
1714 OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute,
1715 ldc->header.eventTypeAttribute );
1720 printf( "Headers:\n" );
1721 for ( ldc = (struct ldcEventDescriptorStruct *)eventsHead;
1724 struct equipmentEventDescriptorStruct *eq;
1726 printf( " LDC:%d size:%d vers:%08x\n",
1728 ldc->header.eventSize,
1729 ldc->header.eventVersion );
1730 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1731 printf( " EQ:%d size:%d %spayload:%d\n",
1733 eq->header.equipmentSize,
1734 eq->header.equipmentSize - sizeof( struct equipmentHeaderStruct ) == (unsigned)eq->payload->size ? "" : "-ERROR",
1735 eq->payload->size );
1740 } /* End of initEvents */
1744 workingAs = unknown;
1745 workingMode = fixedTarget;
1746 ldcsHead = ldcsTail = NULL;
1747 eventsHead = eventsTail = NULL;
1751 payloadsHead = payloadsTail = NULL;
1755 createSorEor = TRUE;
1757 gotAliceTrigger = TRUE;
1759 } /* End of initVars */
1761 int main( int argc, char **argv ) {
1763 parseArgs( argc, argv );