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
14 V01.04 15/10/2010 RD Added possibility to set the run number
27 #define DESCRIPTION "DATE raw data stream simulator"
31 char fileHandlerIdent[]= "@(#)""" __FILE__ """: """ DESCRIPTION \
33 """ compiled """ __DATE__ """ """ __TIME__;
35 #define DBG_BASE if ( debug > 0 )
36 #define DBG_DETAILED if ( debug > 1 )
37 #define DBG_VERBOSE if ( debug > 2 )
40 # define TRUE (0 == 0)
43 # define FALSE (0 == 1)
49 typedef enum { unknown, ldc, gdc } workingAsType;
50 typedef enum { collider, fixedTarget } workingModeType;
51 workingAsType workingAs;
52 workingModeType workingMode;
53 struct ldcDescriptorStruct {
55 struct ldcDescriptorStruct *next;
56 } *ldcsHead, *ldcsTail;
57 void *eventsHead, *eventsTail;
58 struct gdcEventDescriptorStruct {
59 struct ldcEventDescriptorStruct *head;
60 struct ldcEventDescriptorStruct *tail;
61 struct gdcEventDescriptorStruct *next;
62 struct eventHeaderStruct header;
64 unsigned long32 detPattern;
65 eventTimestampSecType timestamp;
67 struct ldcEventDescriptorStruct {
68 struct equipmentEventDescriptorStruct *head;
69 struct equipmentEventDescriptorStruct *tail;
70 struct ldcEventDescriptorStruct *next;
72 struct eventHeaderStruct header;
74 unsigned long32 detPattern;
75 eventTimestampSecType timestamp;
77 struct equipmentEventDescriptorStruct {
78 struct equipmentEventDescriptorStruct *next;
80 struct payloadDescriptorStruct *payload;
81 struct equipmentHeaderStruct header;
83 struct payloadDescriptorStruct {
84 struct payloadDescriptorStruct *next;
89 } *payloadsHead, *payloadsTail;
91 eventGdcIdType currGdcId;
92 unsigned long32 currDetPattern;
93 eventTimestampSecType currTimestamp;
94 eventLdcIdType currLdcId;
95 equipmentIdType currEquipmentId;
101 eventIdType oneEventDelta;
102 eventIdType currEventId;
106 struct commonDataHeaderStruct *cdhRef = NULL;
108 void dumpPayload( const struct payloadDescriptorStruct *p ) {
113 if ( p->data != NULL ) {
114 for ( i = 0, c = (char *)p->data, printable = TRUE;
115 printable && i != p->size;
117 printable = isascii( *c );
120 for ( i = 0, c = (char *)p->data; i != p->size; c++, i++ ) {
126 if ( *c != '\n' ) printf( "\"\n" );
129 for ( i = 0, v = (long32 *)p->data;
132 if ( i % (4*8) == 0 ) {
133 if ( i != 0 ) printf( "\n" );
136 printf( "%08x ", *v );
142 while ( i != p->size ) {
143 printf( "%02x ", *((char *)p->data + p->size - j - 1) & 0xff );
151 } /* End of dumpPayload */
154 assert( workingAs == ldc || workingAs == gdc );
155 if ( eventsHead != NULL ) {
156 printf( "Events:\n" );
157 if ( workingAs == gdc ) {
158 struct gdcEventDescriptorStruct *gdc;
160 for ( gdc = (struct gdcEventDescriptorStruct *)eventsHead;
163 struct ldcEventDescriptorStruct *ldc;
165 printf( " GDC (%p)\n", (void*)gdc );
166 for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) {
167 struct equipmentEventDescriptorStruct *eq;
169 printf( " LDC (%p): %d\n", (void*)ldc, ldc->id );
170 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
171 printf( " EQUIPMENT (%p): %d PAYLOAD (%p):",
174 (void*)eq->payload );
176 printf( "\"%s\" (%d bytes)\n",
177 eq->payload->fileName,
179 dumpPayload( eq->payload );
184 if ( workingAs == ldc ) {
185 struct ldcEventDescriptorStruct *ldc;
187 for ( ldc = (struct ldcEventDescriptorStruct *)eventsHead;
190 struct equipmentEventDescriptorStruct *eq;
193 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
194 printf( " EQUIPMENT (%p): %d PAYLOAD (%p):",
197 (void*)eq->payload );
199 printf( "\"%s\" (%d bytes)\n",
200 eq->payload->fileName,
202 dumpPayload( eq->payload );
207 printf( "Events: EMPTY\n" );
209 } /* End of dumpEvents */
211 void getLine( char *line, const int maxSize ) {
215 for ( read = 0; !feof( stdin ) && !ferror( stdin ) && read != maxSize; read++ ) {
216 if ( (line[read] = getchar()) == '\n' ) break;
218 if ( ferror( stdin ) ) {
220 "%s: failed to read configuration input errno:%d ",
225 if ( feof( stdin ) ) read--;
226 if ( read == maxSize && line[read] != '\n' ) {
228 "%s: Input line # %d too long (%d chars max)\n",
229 myName, lineNmb, maxSize-1 );
234 if ( !( read == 0 && feof( stdin ) ) ) {
235 printf( "%d) [%3d] \"%s\"", lineNmb, read, line );
238 for ( c = 0; c != read; c++ ) {
239 if ( line[c] == '#' ) {
246 printf( " => \"%s\"", line );
248 if ( feof( stdin ) ) printf( "<<< EOF >>>" );
249 if ( ferror( stdin ) ) printf( "<<< FERROR >>>" );
252 } /* End of getLine */
254 void handleLdc( eventLdcIdType ldcId ) {
255 struct ldcDescriptorStruct *ldc;
257 if ( ldcsHead != NULL ) {
258 for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) {
259 if ( ldc->id == ldcId ) {
264 if ( (ldc = (struct ldcDescriptorStruct *)malloc( sizeof( *ldc ) )) == NULL ) {
266 "%s: Failed to malloc for %d bytes (struct ldcDescriptorStruct)\n",
267 myName, (int)sizeof( *ldc ) );
272 if ( ldcsHead == NULL ) {
273 ldcsHead = ldcsTail = ldc;
275 ldcsTail->next = ldc;
279 } /* End of handleLdc */
281 void createNewEvent() {
282 assert( workingAs == ldc || workingAs == gdc );
283 if ( workingAs == ldc ) {
284 struct ldcEventDescriptorStruct *p;
286 if ( (p = (struct ldcEventDescriptorStruct *)malloc( sizeof( *p ) ))
289 "%s: failed to malloc for %d bytes (createNewEvent: struct ldcEventDescriptorStruct)",
290 myName, (int)sizeof( *p ) );
295 p->head = p->tail = NULL;
298 if ( eventsHead == NULL ) {
299 eventsHead = eventsTail = p;
301 struct ldcEventDescriptorStruct *q =
302 (struct ldcEventDescriptorStruct *)eventsTail;
308 p->detPattern = currDetPattern;
309 p->timestamp = currTimestamp;
310 } else if ( workingAs == gdc ) {
311 struct gdcEventDescriptorStruct *p;
313 if ( (p = (struct gdcEventDescriptorStruct *)malloc( sizeof( *p ) ))
316 "%s: failed to malloc for %d bytes (createNewEvent: struct gdcEventDescriptorStruct)",
317 myName, (int)sizeof( *p ) );
323 p->head = p->tail = NULL;
325 if ( eventsHead == NULL ) {
326 eventsHead = eventsTail = p;
328 struct gdcEventDescriptorStruct *q =
329 (struct gdcEventDescriptorStruct *)eventsTail;
334 p->detPattern = currDetPattern;
335 p->timestamp = currTimestamp;
337 } /* End of createNewEvent */
339 void createNewLdcEvent() {
340 struct gdcEventDescriptorStruct *gdcDesc;
341 struct ldcEventDescriptorStruct *p;
343 if ( (p = (struct ldcEventDescriptorStruct *)malloc( sizeof( *p ) ))
346 "%s: failed to malloc for %d bytes (createNewLdcEvent: struct ldcEventDescriptorStruct)",
347 myName, (int)sizeof( *p ) );
352 p->detPattern = currDetPattern;
353 p->timestamp = currTimestamp;
354 p->head = p->tail = NULL;
356 gdcDesc = (struct gdcEventDescriptorStruct *)eventsTail;
357 if ( gdcDesc->head == NULL ) {
358 gdcDesc->head = gdcDesc->tail = p;
360 gdcDesc->tail->next = p;
364 } /* End of createNewLdcEvent */
366 void loadBuffer( struct payloadDescriptorStruct * const payload ) {
370 if ( (f = fopen( payload->fileName, "r" )) == NULL ) {
372 "%s: line:%d payload file \"%s\" not found or not readable, errno:%d. ",
377 perror( "System-dependent error " );
380 if ( (payload->data = malloc( payload->size )) == NULL ) {
382 "%s: line:%d Failed to malloc for payload file \"%s\" size:%d errno:%d ",
388 perror( "System-dependent status " );
391 if ( (bytesRead = fread( payload->data, payload->fileSize, 1, f )) != 1 ) {
393 "%s: line:%d Failed to read payload file \"%s\" size:%d requested:1 got:%d feof:%s ferror:%s errno:%d ",
399 feof(f) ? "TRUE" : "false",
400 ferror(f) ? "TRUE" : "false",
402 perror( "System-dependent status " );
406 if ( payload->size != payload->fileSize ) {
407 memset( (char *)payload->data + payload->fileSize,
409 payload->size - payload->fileSize );
411 } /* End of loadBuffer */
413 void unloadBuffer( struct payloadDescriptorStruct * const payload ) {
414 if ( payload->data != NULL ) {
415 free( payload->data );
416 payload->data = NULL;
418 } /* End of unloadBuffer */
420 void unloadAllBuffers() {
421 struct payloadDescriptorStruct *payload;
423 for ( payload = payloadsHead; payload != NULL; payload = payload->next ) {
424 unloadBuffer( payload );
426 } /* End of unloadAllBuffers */
428 void loadPayload( const char *fileName ) {
429 struct payloadDescriptorStruct *payload;
431 for ( payload = payloadsHead; payload != NULL; payload = payload->next ) {
432 if ( strcmp( fileName, payload->fileName ) == 0 )
435 if ( payload == NULL ) {
438 if ( (payload = (struct payloadDescriptorStruct *)malloc( sizeof( *payload ) ))
441 "%s: failed to malloc for %d bytes (loadPayload/payloadDescriptorStruct)\n",
443 (int)sizeof( *payload ) );
446 if ( (payload->fileName = strdup( fileName )) == NULL ) {
448 "%s: failed to duplicate string \"%s\" (loadPaload/fileName)\n",
453 if ( (f = fopen( fileName, "r" )) == NULL ) {
455 "%s: line:%d payload file \"%s\" not found or not readable, errno:%d. ",
460 perror( "System-dependent error " );
463 if ( fseek( f, 0L, SEEK_END ) != 0 ) {
465 "%s: line:%d Failed to seek payload file \"%s\" errno:%d ",
470 perror( "System-dependent error " );
473 if ( (payload->size = ftell( f )) <= 0 ) {
475 "%s: line:%d Failed to get file \"%s\" size size:%d errno:%d ",
481 perror( "System-dependent status " );
484 payload->fileSize = payload->size;
485 while ( (payload->size & 3) != 0 ) payload->size++;
489 loadBuffer( payload );
491 payload->data = NULL;
494 payload->next = NULL;
495 if ( payloadsHead == NULL ) {
496 payloadsHead = payloadsTail = payload;
498 payloadsTail->next = payload;
499 payloadsTail = payload;
504 printf( "%d) Payload \"%s\" loaded at %p\n",
510 strncmp(fileName,"TRG_",4) != 0 ) {
511 struct commonDataHeaderStruct *cdh =
512 (struct commonDataHeaderStruct *)payload->data;
514 printf( " CDH: blockLenght:%d=0x%08x ",
515 cdh->cdhBlockLength, cdh->cdhBlockLength );
516 if ( cdh->cdhBlockLength < sizeof( *cdh ) ) {
517 printf( "TOO SMALL (minimum:%ld=0x%08lx)\n",
518 (unsigned long)sizeof( *cdh ),
519 (unsigned long)sizeof( *cdh ) );
521 printf( "version:%d=0x%x ", cdh->cdhVersion, cdh->cdhVersion );
522 if ( cdh->cdhVersion != CDH_VERSION ) {
523 printf( "EXPECTED:%d=%x (decoding may be inaccurate) ",
524 CDH_VERSION, CDH_VERSION );
527 printf( "L1TriggerMessage:0x%x", cdh->cdhL1TriggerMessage );
528 if ( cdh->cdhL1TriggerMessage != 0 ) {
529 for ( b = 0, n = 0; b != 10; b++ ) {
530 if ( (cdh->cdhL1TriggerMessage & (1<<b)) != 0 ) {
531 if ( n++ != 0 )printf( "+" );
533 case 0: printf( "L1SwC" ); break;
534 case 1: printf( "ESR" ); break;
535 case 2: printf( "RoC1" ); break;
536 case 3: printf( "RoC2" ); break;
537 case 4: printf( "RoC3" ); break;
538 case 5: printf( "RoC4" ); break;
539 case 6: printf( "ClT" ); break;
540 default: printf( "spare %d", b+14 );
547 if ( cdh->cdhMBZ0 != 0 )
548 printf( "MBZ0:0x%x ",
553 printf( "EventId2(orbit):%d=0x%x ",
554 cdh->cdhEventId2, cdh->cdhEventId2 );
555 printf( "EventId1(bunchCrossing):%d=0x%x ",
556 cdh->cdhEventId1, cdh->cdhEventId1 );
560 if ( cdh->cdhMBZ1 != 0 )
561 printf( "MBZ1:0x%x ",
563 printf( "BlockAttributes:0x%x",
564 cdh->cdhBlockAttributes );
565 if ( cdh->cdhBlockAttributes != 0 ) {
567 for ( b = 0, n = 0; b != 8; b++ ) {
568 if ( (cdh->cdhBlockAttributes & (1<<b)) != 0 ) {
577 printf( "ParticipatingSubDetectors:0x%x ",
578 cdh->cdhParticipatingSubDetectors );
582 printf( "Status/Error:0x%x", cdh->cdhStatusErrorBits );
583 if ( cdh->cdhStatusErrorBits != 0 ) {
585 for ( b = 0,n = 0; b != 16; b++ ) {
586 if ( (cdh->cdhStatusErrorBits & (1<<b)) != 0 ) {
587 if ( n++ != 0 ) printf( "+" );
589 case 0: printf( "TriggerOverLapError" ); break;
590 case 1: printf( "TriggerMissingError" ); break;
591 case 2: printf( "DataParityError" ); break;
592 case 3: printf( "ControlParityError" ); break;
593 case 4: printf( "TriggerInformationUnavailable" ); break;
594 case 5: printf( "FEEError" ); break;
595 case 6: printf( "HLTDecision" ); break;
596 case 7: printf( "HLTPayload" ); break;
597 case 8: printf( "DDGPayload" ); break;
598 default: printf( "spare %d", b );
605 printf( "MiniEventId(bunchCrossing):%d=0x%x ",
606 cdh->cdhMiniEventId, cdh->cdhMiniEventId );
610 printf( "Trigger classes: 0x(%05x-%08x)",
611 cdh->cdhTriggerClassesHigh,
612 cdh->cdhTriggerClassesLow );
613 if ( cdh->cdhTriggerClassesHigh != 0
614 || cdh->cdhTriggerClassesLow != 0 ) {
616 for ( b=0, n=0; b != 32; b++ ) {
617 if ( (cdh->cdhTriggerClassesLow & (1<<b)) != 0 ) {
618 if ( n++ != 0 ) printf( "+" );
622 for ( b=0; b != 18; b++ ) {
623 if ( (cdh->cdhTriggerClassesHigh & (1<<b)) != 0 ) {
624 if ( n++ != 0 ) printf( "+" );
625 printf( "%d", b+32 );
633 printf( "ROI:0x(%08x-%01x)", cdh->cdhRoiHigh, cdh->cdhRoiLow );
634 if ( cdh->cdhRoiHigh != 0
635 || cdh->cdhRoiLow != 0 ) {
637 for ( b=0, n=0; b != 5; b++ ) {
638 if ( (cdh->cdhRoiLow & (1<<b)) != 0 ) {
639 if ( n++ != 0 ) printf( "+" );
643 for ( b=0; b != 32; b++ ) {
644 if ( (cdh->cdhRoiHigh & (1<<b)) != 0 ) {
645 if ( n++ != 0 ) printf( "+" );
657 printf( "%d) Payload \"%s\" already loaded at %p\n",
663 currEvent->payload = payload;
664 } /* End of loadPayload */
666 void parseEquipment( char * const line ) {
667 struct equipmentEventDescriptorStruct *equipment;
668 int payloadFound = FALSE;
673 (struct equipmentEventDescriptorStruct *)malloc( sizeof( *equipment ) )) == NULL ) {
675 "%s: filed to malloc for %d bytes (parseEquipment/equipmentEventDescriptorStruct) errno:%d ",
677 (int)sizeof( *equipment ),
682 currEvent = equipment;
685 while ( (keyword = strtok_r( p, " \t", &p )) != NULL ) {
686 DBG_VERBOSE printf( "%d) Equipment - Keyword:\"%s\"\n",
689 if ( strcasecmp( "id", keyword ) == 0 ) {
692 if ( (idNum = strtok_r( p, " \t", &p )) == NULL ) {
694 "%s: line:%d EQUIPMENT declaration, ID needed",
699 if ( sscanf( idNum, "%d", &currEquipmentId ) != 1 ) {
701 "%s: line:%d EQUIPMENT declaration, numeric ID needed (%s)",
707 DBG_VERBOSE printf( "%d) EQUIPMENT - ID:%d\n",
710 } else if ( strncasecmp( "pay", keyword, 3 ) == 0 ) {
713 if ( (fileName = strtok_r( p, " \t", &p )) == NULL ) {
715 "%s line:%d Payload without filename found\n",
720 DBG_VERBOSE printf( "%d) Equipment - Payload:\"%s\"\n",
723 if ( payloadFound ) {
725 "%s line:%d Payload with multiple filenames found\n",
730 loadPayload( fileName );
734 "%s: line:%d Equipment declaration, unknown keyword \"%s\"\n",
741 if ( !payloadFound ) {
743 "%s: line:%d Equipment without payload found\n",
749 equipment->id = currEquipmentId;
750 equipment->next = NULL;
751 if ( currLdc->head == NULL ) {
752 currLdc->head = currLdc->tail = equipment;
754 currLdc->tail->next = equipment;
755 currLdc->tail = equipment;
757 } /* End of parseEquipment */
759 void parseGdc( char * const line ) {
764 while ( (keyword = strtok_r( p, " \t", &p )) != NULL ) {
765 if ( strcasecmp( "id", keyword ) == 0 ) {
768 if ( (idNum = strtok_r( p, " \t", &p )) == NULL ) {
770 "%s: line:%d GDC declaration, ID needed",
776 if ( sscanf( idNum, "%d", &inCurrGdcId ) != 1 ) {
778 "%s: line:%d GDC declaration, numeric ID needed (%s)",
784 currGdcId = (eventGdcIdType)inCurrGdcId;
785 DBG_VERBOSE printf( "%d) GDC - ID:%d\n",
788 } else if ( strcasecmp( "DetectorPattern", keyword ) == 0 ) {
791 if ( (detPattern = strtok_r( p, " \t", &p )) == NULL ) {
793 "%s: line:%d GDC declaration, DetectorPattern needed",
798 if ( sscanf( detPattern, "%u", &currDetPattern ) != 1 ) {
800 "%s: line:%d GDC declaration, numeric DetectorPattern needed (%s)",
806 DBG_VERBOSE printf( "%d) GDC - DetectorPattern:%u\n",
809 } else if ( strcasecmp( "Timestamp", keyword ) == 0 ) {
812 if ( (timestamp = strtok_r( p, " \t", &p )) == NULL ) {
814 "%s: line:%d GDC declaration, Timestamp needed",
819 if ( sscanf( timestamp, "%u", &currTimestamp ) != 1 ) {
821 "%s: line:%d GDC declaration, numeric Timestamp needed (%s)",
827 DBG_VERBOSE printf( "%d) GDC - Timestamp:%u\n",
832 "%s: line:%d GDC declaration, unknown keyword \"%s\"\n",
839 } /* End of parseGdc */
841 void parseLdc( char * const line ) {
846 while ( (keyword = strtok_r( p, " \t", &p )) != NULL ) {
847 if ( strcasecmp( "id", keyword ) == 0 ) {
850 if ( (idNum = strtok_r( p, " \t", &p )) == NULL ) {
852 "%s: line:%d LDC declaration, ID needed",
858 if ( sscanf( idNum, "%d", &inCurrLdcId ) != 1 ) {
860 "%s: line:%d LDC declaration, numeric ID needed (%s)",
866 currLdcId = (eventLdcIdType)inCurrLdcId;
867 DBG_VERBOSE printf( "%d) LDC - ID:%d\n",
872 "%s: line:%d LDC declaration, unknown keyword \"%s\"\n",
879 } /* End of parseLdc */
884 currLdcId = HOST_ID_MIN;
885 currGdcId = HOST_ID_MIN;
889 for ( lineNmb = 1; !feof( stdin ); lineNmb++ ) {
890 getLine( line, sizeof(line) );
891 if ( strlen(line) != 0 ) {
895 if ( (keyword = strtok_r( line, " \t", &p )) != NULL ) {
896 DBG_VERBOSE printf( "%d) Keyword:\"%s\"\n", lineNmb, keyword );
897 if ( strcasecmp( "gdc", keyword ) == 0 ) {
898 if ( workingAs != gdc && workingAs != unknown ) {
900 "%s: line:%d GDC found when working in non-GDC mode (e.g. as a LDC)\n",
907 currLdcId = HOST_ID_MIN;
910 } else if ( strcasecmp( "ldc", keyword ) == 0 ) {
911 if ( workingAs != gdc && workingAs != ldc && workingAs != unknown ) {
913 "%s: line:%d LDC found when working in non-LDC/GDC mode\n",
917 if ( workingAs == unknown ) workingAs = ldc;
919 if ( workingAs == ldc ) {
924 handleLdc( currLdcId );
928 } else if ( strncasecmp( "equ", keyword, 3 ) == 0 ) {
929 if ( workingAs == unknown
930 || (workingAs == ldc && currLdc == NULL )
931 || (workingAs == gdc && currGdc == NULL ) ) {
933 "%s: line:%d Unexpected EQUIPMENT declaration (LDC or GDC needed first)\n",
942 "%s: line:%d Parse error in \"%s\" unknown keyword\n",
950 } while ( !feof( stdin ) ) {}
954 printf( "End of parse: %d line%s found\n",
956 lineNmb != 1 ? "s" : "" );
957 printf( "Working as %s\n",
958 workingAs == gdc ? "GDC" :
959 workingAs == ldc ? "LDC" :
961 if ( workingAs == gdc ) {
962 struct ldcDescriptorStruct *ldc;
964 printf( "LDCs (%d):", numOfLdcs );
965 for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) {
966 printf( " %d", ldc->id );
973 if ( workingAs == ldc ) {
974 assert( ldcsHead == ldcsTail );
975 assert( ldcsTail == NULL );
978 if ( workingAs == gdc ) {
979 struct ldcDescriptorStruct *ldc;
981 assert( ldcsHead != NULL );
982 assert( ldcsTail != NULL );
983 assert( ldcsTail->next == NULL );
984 for ( ldc = ldcsHead; ldc->next != NULL; ldc = ldc->next ) {}
985 assert ( ldc == ldcsTail );
988 if ( workingAs == unknown ) {
989 DBG_VERBOSE printf( "Empty configuration: nothing to do!\n" );
993 assert( (eventsHead == NULL && eventsTail == NULL)
994 || (eventsHead != NULL && eventsTail != NULL) );
995 } /* End of parseRules */
997 void initEvent( struct eventHeaderStruct * const ev ) {
998 memset( ev, 0, sizeof( *ev ) );
1000 ev->eventMagic = EVENT_MAGIC_NUMBER;
1001 ev->eventHeadSize = EVENT_HEAD_BASE_SIZE;
1002 ev->eventVersion = EVENT_CURRENT_VERSION;
1003 ev->eventRunNb = currRunNb;
1004 ZERO_EVENT_ID( ev->eventId );
1005 ZERO_TRIGGER_PATTERN( ev->eventTriggerPattern );
1006 ZERO_DETECTOR_PATTERN( ev->eventDetectorPattern );
1007 RESET_ATTRIBUTES( ev->eventTypeAttribute );
1008 if ( workingMode == collider )
1009 SET_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_ORBIT_BC );
1010 ev->eventLdcId = VOID_ID;
1011 ev->eventGdcId = VOID_ID;
1012 } /* End of initEvent */
1016 // Swap the endianess of the integer value 'x'
1018 return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) << 8) |
1019 ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24));
1022 void outputEvent( const void * const ev,
1027 const long32 * const v = (long32 *)ev;
1028 printf( "Writing %d bytes @ %p (%d)\n", size, ev, *v );
1031 // .............................Test endianess..............................
1033 char* ptemp = (char*) &temp;
1035 if (ptemp[0]!=1) { // Mac platform: ptemp != 1..............................................................................
1036 int bufSize= size; if (bufSize > (int) sizeof(eventHeaderStruct)) { bufSize = sizeof(eventHeaderStruct); }
1037 char* evTemp = (char*) malloc (bufSize);
1038 memcpy(evTemp, ev, bufSize);
1040 if ((bufSize % sizeof(int)) != 0) {
1041 fprintf( stderr, "%s: size of the input buffer ev is not multiple of 4 (size = %d)\n", myName, bufSize);
1045 // Invert header to evTemp.....................................................
1046 int* buf = (int*) evTemp;
1047 for (int i=0; i < (int) (bufSize / sizeof(int)); i++, buf++) {
1048 int value = Swap(*buf);
1049 memcpy(evTemp + (i * sizeof(int)), &value, sizeof(int));
1052 // Write inverted header to file...............................................
1053 if ((done = fwrite( evTemp, bufSize, 1, outF )) != 1 ) {
1054 fprintf( stderr, "%s: failed to write inverted header. event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) );
1058 if (size > bufSize) { // Still theraw-data payload to write (but not inverted, since it is inverted eariler).............
1059 if ((done = fwrite( (char*)ev + bufSize, size - bufSize, 1, outF )) != 1 ) {
1060 fprintf( stderr, "%s: failed to write additional event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) );
1067 else { // Intel platform: ptemp == 1............................................................................
1068 if ((done = fwrite( ev, size, 1, outF )) != 1 ) {
1069 fprintf( stderr, "%s: failed to write event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) );
1073 } /* End of outputEvent */
1075 void createSorAndEor( const int sor ) {
1076 unsigned char event[ 1000 ];
1077 struct eventHeaderStruct *ev;
1078 struct eventHeaderStruct sev;
1080 assert( workingAs == ldc || workingAs == gdc );
1082 if ( !createSorEor ) return;
1083 ev = (struct eventHeaderStruct *)event;
1085 ev->eventSize = sizeof( event );
1086 ev->eventType = sor ? START_OF_RUN : END_OF_RUN;
1087 if ( workingMode == fixedTarget )
1088 LOAD_RAW_EVENT_ID( ev->eventId, 0, 0, 0 );
1090 LOAD_EVENT_ID( ev->eventId, 0, 0, 0 );
1091 SET_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_P_START );
1093 if ( workingAs == ldc ) {
1094 currLdc = (struct ldcEventDescriptorStruct *)eventsHead;
1096 if ( workingAs == gdc ) {
1098 sev.eventGdcId = currGdcId;
1099 ev->eventGdcId = currGdcId;
1100 currGdc = (struct gdcEventDescriptorStruct *)eventsHead;
1101 currLdc = currGdc->head;
1103 ev->eventLdcId = currLdc->id;
1105 if ( workingAs == ldc ) {
1106 outputEvent( ev, ev->eventSize );
1108 if ( workingAs == gdc ) {
1109 struct ldcDescriptorStruct *ldc;
1111 sev.eventSize = sizeof( sev ) + numOfLdcs * ev->eventSize;
1112 sev.eventType = sor ? START_OF_RUN : END_OF_RUN ;
1113 COPY_EVENT_ID( ev->eventId, sev.eventId );
1114 COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute );
1115 SET_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT );
1116 outputEvent( &sev, sizeof( sev ) );
1118 ev->eventGdcId = currGdcId;
1119 for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) {
1120 ev->eventLdcId = ldc->id;
1121 outputEvent( ev, ev->eventSize );
1125 ADD_EVENT_ID( ev->eventId, oneEventDelta );
1126 ev->eventSize = ev->eventSize / 2;
1127 ev->eventType = sor ? START_OF_RUN_FILES : END_OF_RUN_FILES;
1128 CLEAR_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_P_START );
1129 if ( workingAs == ldc ) {
1130 outputEvent( ev, ev->eventSize );
1132 if ( workingAs == gdc ) {
1133 struct ldcDescriptorStruct *ldc;
1135 sev.eventSize = ev->eventSize;
1136 sev.eventType = sor ? START_OF_RUN_FILES : END_OF_RUN_FILES;
1137 COPY_EVENT_ID( ev->eventId, sev.eventId );
1138 COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute );
1139 CLEAR_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT );
1140 outputEvent( &sev, sizeof( sev ) );
1141 outputEvent( ev, ev->eventSize - sizeof( sev ) );
1143 sev.eventSize = sizeof( sev ) + ev->eventSize;
1144 sev.eventType = sor ? START_OF_RUN_FILES : END_OF_RUN_FILES;
1145 COPY_EVENT_ID( ev->eventId, sev.eventId );
1146 COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute );
1147 SET_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT );
1149 ev->eventGdcId = currGdcId;
1150 for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) {
1151 outputEvent( &sev, sizeof( sev ) );
1152 ev->eventLdcId = ldc->id;
1153 outputEvent( ev, ev->eventSize );
1157 ADD_EVENT_ID( ev->eventId, oneEventDelta );
1158 ev->eventSize = sizeof( *ev );
1159 ev->eventType = sor ? START_OF_RUN : END_OF_RUN;
1160 SET_SYSTEM_ATTRIBUTE( ev->eventTypeAttribute, ATTR_P_END );
1161 if ( workingAs == ldc ) {
1162 outputEvent( ev, ev->eventSize );
1164 if ( workingAs == gdc ) {
1165 struct ldcDescriptorStruct *ldc;
1167 sev.eventSize = sizeof( sev ) + numOfLdcs * ev->eventSize;
1168 sev.eventType = sor ? START_OF_RUN : END_OF_RUN;
1169 COPY_EVENT_ID( ev->eventId, sev.eventId );
1170 COPY_SYSTEM_ATTRIBUTES( ev->eventTypeAttribute, sev.eventTypeAttribute );
1171 SET_SYSTEM_ATTRIBUTE( sev.eventTypeAttribute, ATTR_SUPER_EVENT );
1173 outputEvent( &sev, sizeof( sev ) );
1175 for ( ldc = ldcsHead; ldc != NULL; ldc = ldc->next ) {
1176 ev->eventLdcId = ldc->id;
1177 outputEvent( ev, ev->eventSize );
1180 } /* End of createSorEor */
1183 createSorAndEor( TRUE );
1184 } /* End of createSor */
1187 createSorAndEor( FALSE );
1188 } /* End of createEor */
1190 void loadCdh( struct commonDataHeaderStruct * const cdh,
1191 eventIdType * const eventId,
1192 equipmentIdType id ) {
1193 if ( !handleCDH ) return;
1195 // CTP raw-data does not contain CDH
1196 if ( id == 4352) return;
1198 if ( gotAliceTrigger ) {
1199 cdh->cdhEventId1 = EVENT_ID_GET_BUNCH_CROSSING( *eventId );
1200 cdh->cdhEventId2 = EVENT_ID_GET_ORBIT( *eventId );
1202 cdh->cdhEventId1 = 0;
1203 cdh->cdhEventId2 = EVENT_ID_GET_NB_IN_RUN( *eventId );
1205 cdh->cdhMiniEventId = cdh->cdhEventId1;
1207 void decodeCDH( struct ldcEventDescriptorStruct * const ldc,
1208 const struct payloadDescriptorStruct * const payloadDesc,
1209 equipmentIdType id );
1211 void createEvent( void ) {
1212 assert( workingAs == ldc || workingAs == gdc );
1214 /* Step 1: load all buffers (if needed) and compose the GDC/LDC headers */
1215 if ( workingAs == gdc ) {
1216 struct ldcEventDescriptorStruct *ldc;
1218 for( ldc = currGdc->head; ldc != NULL; ldc = ldc->next ) {
1219 COPY_EVENT_ID( currEventId, ldc->header.eventId );
1221 COPY_EVENT_ID( currEventId, currGdc->header.eventId );
1223 for( ldc = currGdc->head; ldc != NULL; ldc = ldc->next ) {
1224 struct equipmentEventDescriptorStruct *eq;
1227 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1228 if ( !bufferData ) {
1229 loadBuffer( eq->payload );
1230 decodeCDH( ldc, eq->payload, eq->id );
1232 loadCdh( (struct commonDataHeaderStruct*)eq->payload->data,
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;
1248 } else if ( workingAs == ldc ) {
1249 struct equipmentEventDescriptorStruct *eq;
1251 COPY_EVENT_ID( currEventId, currLdc->header.eventId );
1253 for ( eq = currLdc->head; eq != NULL; eq = eq->next ) {
1254 if ( !bufferData ) {
1255 loadBuffer( eq->payload );
1256 decodeCDH( currLdc, eq->payload, eq->id );
1258 loadCdh( (struct commonDataHeaderStruct*)eq->payload->data,
1261 currLdc->loaded = TRUE;
1265 ADD_EVENT_ID( currEventId, oneEventDelta );
1267 /* Step 2: output the event */
1268 if ( workingAs == gdc ) {
1269 struct ldcEventDescriptorStruct *ldc;
1271 outputEvent( &currGdc->header, sizeof( currGdc->header ) );
1273 for( ldc = currGdc->head; ldc != NULL; ldc = ldc->next ) {
1274 struct equipmentEventDescriptorStruct *eq;
1276 outputEvent( &ldc->header, sizeof( ldc->header ) );
1278 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1279 outputEvent( &eq->header, sizeof( eq->header ) );
1280 outputEvent( eq->payload->data, eq->payload->size );
1281 if ( !bufferData ) unloadBuffer( eq->payload );
1284 if ( (currGdc = currGdc->next) == NULL )
1285 currGdc = (struct gdcEventDescriptorStruct *)eventsHead;
1286 } else if ( workingAs == ldc ) {
1287 struct equipmentEventDescriptorStruct *eq;
1289 outputEvent( &currLdc->header, sizeof( currLdc->header ) );
1291 for ( eq = currLdc->head; eq != NULL; eq = eq->next ) {
1292 outputEvent( &eq->header, sizeof( eq->header ) );
1293 outputEvent( eq->payload->data, eq->payload->size );
1294 if ( !bufferData ) unloadBuffer( eq->payload );
1296 if ( (currLdc = currLdc->next) == NULL )
1297 currLdc = (struct ldcEventDescriptorStruct *)eventsHead;
1299 } /* End of createEvent */
1301 void createEvents() {
1304 currGdc = (struct gdcEventDescriptorStruct *)eventsHead;
1305 currLdc = (struct ldcEventDescriptorStruct *)eventsHead;
1310 eventNum != numOfEvents && numOfEvents != 0;
1315 } /* End of createEvents */
1319 "Usage: %s [-?][-d][-i definitionFile][-o outputFile][-# numOfEvents][-s][-F|-C]\n\
1321 -v Print version ID and exit\n\
1322 -d Enable debug (repeat for more verbosity)\n\
1323 -i definitionFile File with the description of the events to create (default: stdin)\n\
1324 -o outputFile File used to store events (default: stdout)\n\
1325 -# numOfEvents Number of events to generate (default: 1 event)\n\
1326 -s Do not generate SOR/EOR files (valid only for GDCs)\n\
1327 -F/-C Working in Fixed Target (F) or Collider (C) mode\n\
1329 -D Direct disc access (no buffering)\n",
1332 } /* End of usage */
1334 void parseArgs( int argc, char **argv ) {
1336 int inFileName = -1;
1337 int outFileName = -1;
1340 while ( arg < argc ) {
1341 if ( strcmp( "-?", argv[ arg ] ) == 0 ) {
1345 if ( strcmp( "-i", argv[ arg ] ) == 0 ) {
1346 if ( ++arg == argc ) exit( usage() );
1348 if ( freopen( argv[arg], "r", stdin ) == NULL ){
1350 "%s: failed to open input definition \"%s\" errno:%d ",
1351 myName, argv[arg], errno );
1355 } else if ( strcmp( "-v", argv[ arg ] ) == 0 ) {
1356 printf( "%s\n", fileHandlerIdent );
1358 } else if ( strcmp( "-o", argv[ arg ] ) == 0 ) {
1359 if ( ++arg == argc ) exit( usage() );
1361 } else if ( strcmp( "-#", argv[ arg ] ) == 0 ) {
1364 if ( ++arg == argc ) exit( usage() );
1365 if ( sscanf( argv[ arg ], "%d", &n ) != 1 ) exit( usage() );
1366 if ( n < 0 ) exit( usage() );
1368 } else if ( strcmp( "-s", argv[ arg ] ) == 0 ) {
1369 createSorEor = FALSE;
1370 } else if ( strcmp( "-F", argv[ arg ] ) == 0 ) {
1371 workingMode = fixedTarget;
1372 } else if ( strcmp( "-C", argv[ arg ] ) == 0 ) {
1373 workingMode = collider;
1374 } else if ( strcmp( "-d", argv[ arg ] ) == 0 ) {
1376 } else if ( strcmp( "-c", argv[ arg ] ) == 0 ) {
1378 } else if ( strcmp( "-D", argv[ arg ] ) == 0 ) {
1380 } else if ( strcmp( "-run", argv[ arg ] ) == 0 ) {
1382 if ( ++arg == argc ) exit( usage() );
1383 if ( sscanf( argv[ arg ], "%d", &runnumber ) != 1 ) exit( usage() );
1384 if ( runnumber < 0 ) exit( usage() );
1385 currRunNb = runnumber;
1387 fprintf( stderr, "%s: Unknown switch \"%s\"\n", myName, argv[argc] );
1393 if ( workingMode == fixedTarget )
1394 LOAD_RAW_EVENT_ID( oneEventDelta, 1, 0, 1 );
1396 LOAD_EVENT_ID( oneEventDelta, 0, 0, 1 );
1397 ZERO_EVENT_ID( currEventId );
1400 printf( "Configuration:\n" );
1401 printf( " Debug level: %d\n", debug );
1402 printf( " Configuration: %s\n",
1403 inFileName == -1 ? "stdin" : argv[ inFileName ] );
1404 printf( " Output: %s\n",
1405 outFileName == -1 ? "stdout" : argv[ outFileName ] );
1406 printf( " Working mode: %s\n",
1407 workingMode == fixedTarget ? "fixed target" : "collider" );
1408 printf( " Number of events: %d\n", numOfEvents );
1409 printf( " %s SOR/EOR files\n",
1410 createSorEor ? "Create" : "Do not create" );
1411 printf( " CDH handling: %s\n",
1412 handleCDH ? "enabled" : "disabled" );
1413 printf( " data buffering: %s\n",
1414 bufferData ? "enabled" : "DISABLED" );
1417 if ( outFileName == -1 ) {
1419 printf( "No more trace information from this point...\n" );
1423 if ( ( outF = fopen( argv[ outFileName ], "w" ) ) == NULL ) {
1425 "%s: failed to open output file \"%s\" for writing, errno:%d (%s)\n",
1427 argv[ outFileName ],
1429 strerror( errno ) );
1433 printf( "Output file \"%s\" opened OK for writing\n",
1434 argv[ outFileName ] );
1436 } /* End of parseArgs */
1437 void initEquipment( struct equipmentHeaderStruct * const eq ) {
1438 memset( eq, 0, sizeof( *eq ) );
1439 RESET_ATTRIBUTES( eq->equipmentTypeAttribute );
1440 eq->equipmentBasicElementSize = 4;
1441 } /* End of initEquipment */
1443 void decodeCDH( struct ldcEventDescriptorStruct * const ldc,
1444 const struct payloadDescriptorStruct * const payloadDesc,
1445 equipmentIdType id ) {
1448 struct commonDataHeaderStruct *cdh;
1449 static int softwareTriggerIndicator = FALSE;
1453 if ( payloadDesc->size < CDH_SIZE ) {
1455 "%s: payload too small got:%d CDH:%d\n",
1461 if ( (cdh = (struct commonDataHeaderStruct *)payloadDesc->data) != NULL ) {
1462 if ( cdh->cdhVersion != CDH_VERSION ) {
1464 "%s: CDH version mismatch expected:%d got:%d\n",
1470 if ( cdhRef == NULL ) {
1472 #define CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK (1<<CDH_TRIGGER_INFORMATION_UNAVAILABLE_BIT)
1473 gotAliceTrigger = (cdhRef->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) == 0;
1474 if ( gotAliceTrigger && workingMode == fixedTarget ) {
1476 "%s: ALICE trigger and fixed target mode are not compatible.\n\
1477 Either work in Collider mode or set the trigger unavailable status bit in the CDH.\n",
1481 if ( gotAliceTrigger ) {
1482 if ( (cdh->cdhL1TriggerMessage & 0x40) != 0 ) {
1484 "%s: CDH is a calibration trigger (unsupported) L1TriggerMessage:0x%x\n",
1485 myName, cdh->cdhL1TriggerMessage );
1488 if ( (cdh->cdhL1TriggerMessage & 0x01) != 0 ) {
1489 softwareTriggerIndicator = TRUE;
1491 if ( softwareTriggerIndicator ) {
1492 switch ((cdh->cdhL1TriggerMessage >> 2) & 0xF) {
1499 /* L1SwC bit = on, Clt bit = off, RoC[4..1] = 0xD --> SYNC */
1501 /* L1SwC bit = on, Clt bit = off, RoC[4..1] = 0xF --> END_OF_DATA */
1503 /* L1SwC bit = on, Clt bit = off, RoC[4..1] = 0xE0 --> START_OF_DATA */
1505 /* L1SwC bit = on, Clt bit = off, RoC[4] = 1, but not 0xE or 0xF
1506 --> SYSTEM_SOFTWARE_TRIGGER_EVENT */
1508 /* L1SwC bit = on, Clt bit = off, RoC[4] = 0
1509 --> DETECTOR_SOFTWARE_TRIGGER_EVENT */
1511 "%s: CDH trigger SOD/EOD/SST/DST/SYNC (unsupported) \
1512 L1TriggerMessage:0x%x ALICETrigger:%s\n",
1514 cdh->cdhL1TriggerMessage,
1515 gotAliceTrigger ? "yes" : "no" );
1521 if ( (cdh->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) !=
1522 (cdhRef->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) ) {
1524 "%s: CDH coherency check failed. \
1525 Trigger information reference:%savailable current:%savailable\n",
1527 (cdhRef->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) == 0 ? "UN" : "",
1528 (cdh->cdhStatusErrorBits & CDH_TRIGGER_INFORMATION_UNAVAILABLE_MASK) == 0 ? "UN" : "" );
1531 if ( gotAliceTrigger ) {
1532 if ( cdhRef->cdhL1TriggerMessage != cdh->cdhL1TriggerMessage ) {
1534 "%s: CDH coherency check failed. \
1535 L1 trigger message reference:0x%x current:0x%x\n",
1537 cdhRef->cdhL1TriggerMessage,
1538 cdh->cdhL1TriggerMessage );
1541 if ( cdh->cdhParticipatingSubDetectors != cdhRef->cdhParticipatingSubDetectors ) {
1543 "%s: CDH coherency check failed. \
1544 ParticipatingSubDetectors reference:0x%x current:0x%x\n",
1546 cdhRef->cdhParticipatingSubDetectors,
1547 cdh->cdhParticipatingSubDetectors );
1550 if ( cdh->cdhTriggerClassesLow != cdhRef->cdhTriggerClassesLow
1551 || cdh->cdhTriggerClassesHigh != cdhRef->cdhTriggerClassesHigh ) {
1553 "%s: CDH coherency check failed. \
1554 TriggerClassesHigh/Low reference:0x%x-%x current:0x%x-%x\n",
1556 cdhRef->cdhTriggerClassesHigh, cdhRef->cdhTriggerClassesLow,
1557 cdh ->cdhTriggerClassesHigh, cdh ->cdhTriggerClassesLow );
1560 if ( cdh->cdhBlockLength != 0xffffffff ) {
1561 if ( (unsigned)payloadDesc->size != cdh->cdhBlockLength ) {
1563 "%s: CDH coherency check failed. \
1564 Payload size:%d (0x%08x) CDH block length:%d (0x%08x)\n",
1566 payloadDesc->size, payloadDesc->size,
1567 cdh->cdhBlockLength, cdh->cdhBlockLength );
1571 if ( cdh->cdhRoiLow != cdhRef->cdhRoiLow
1572 || cdh->cdhRoiHigh != cdhRef->cdhRoiHigh ) {
1574 "%s: CDH coherency check failed. \
1575 RoiHigh/Low reference:0x%x-%x current:0x%x-%x\n",
1577 cdhRef->cdhRoiHigh, cdhRef->cdhRoiLow,
1578 cdh ->cdhRoiHigh, cdh ->cdhRoiLow );
1582 if ( cdh->cdhMBZ0 != 0
1583 || cdh->cdhMBZ1 != 0
1584 || cdh->cdhMBZ4 != 0 ) {
1586 "%s: CDH check failed. MBZ0:0x%x MBZ1:0x%x MBZ4:0x%x\n",
1588 cdh->cdhMBZ0, cdh->cdhMBZ1, cdh->cdhMBZ4 );
1592 for ( attr = 0; attr != 8; attr++ ) {
1593 if ( (cdh->cdhBlockAttributes & (1<<attr)) != 0 ) {
1594 SET_USER_ATTRIBUTE( ldc->header.eventTypeAttribute, attr );
1597 for ( trig = 0; trig != 32; trig++ ) {
1598 if ( (cdh->cdhTriggerClassesLow & (1<<trig)) != 0 ) {
1599 SET_TRIGGER_IN_PATTERN( ldc->header.eventTriggerPattern,
1603 for ( trig = 0; trig != 18; trig++ ) {
1604 if ( (cdh->cdhTriggerClassesMiddleLow & (1<<trig)) != 0 ) {
1605 SET_TRIGGER_IN_PATTERN( ldc->header.eventTriggerPattern,
1609 for ( trig = 0; trig != 32; trig++ ) {
1610 if ( (cdh->cdhTriggerClassesMiddleHigh & (1<<trig)) != 0 ) {
1611 SET_TRIGGER_IN_PATTERN( ldc->header.eventTriggerPattern,
1615 for ( trig = 0; trig != 18; trig++ ) {
1616 if ( (cdh->cdhTriggerClassesHigh & (1<<trig)) != 0 ) {
1617 SET_TRIGGER_IN_PATTERN( ldc->header.eventTriggerPattern,
1621 if ( gotAliceTrigger )
1622 VALIDATE_TRIGGER_PATTERN( ldc->header.eventTriggerPattern );
1625 } /* End of decodeCDH */
1628 assert( workingAs == ldc || workingAs == gdc );
1630 if ( workingAs == gdc ) {
1631 struct gdcEventDescriptorStruct *gdc;
1633 for ( gdc = (struct gdcEventDescriptorStruct *)eventsHead;
1636 struct ldcEventDescriptorStruct *ldc;
1638 initEvent( &gdc->header );
1639 gdc->header.eventSize = gdc->header.eventHeadSize;
1640 gdc->header.eventType = PHYSICS_EVENT;
1641 SET_SYSTEM_ATTRIBUTE( gdc->header.eventTypeAttribute, ATTR_SUPER_EVENT );
1642 gdc->header.eventGdcId = currGdcId;
1643 COPY_DETECTOR_PATTERN(&gdc->detPattern, gdc->header.eventDetectorPattern);
1644 gdc->header.eventTimestamp = gdc->timestamp;
1645 for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) {
1646 struct equipmentEventDescriptorStruct *eq;
1648 initEvent( &ldc->header );
1649 ldc->header.eventSize = ldc->header.eventHeadSize;
1650 ldc->header.eventType = PHYSICS_EVENT;
1651 ldc->header.eventGdcId = currGdcId;
1652 COPY_DETECTOR_PATTERN(&ldc->detPattern, ldc->header.eventDetectorPattern);
1653 ldc->header.eventTimestamp = ldc->timestamp;
1654 ldc->header.eventLdcId = ldc->id;
1655 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1656 initEquipment( &eq->header );
1657 eq->header.equipmentId = eq->id;
1658 if ( workingMode == collider )
1659 SET_SYSTEM_ATTRIBUTE( eq->header.equipmentTypeAttribute,
1661 eq->header.equipmentSize = eq->payload->size + sizeof( eq->header );
1662 ldc->header.eventSize += eq->header.equipmentSize;
1663 decodeCDH( ldc, eq->payload, eq->id );
1664 OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute,
1665 ldc->header.eventTypeAttribute );
1666 OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute,
1667 gdc->header.eventTypeAttribute );
1669 gdc->header.eventSize += ldc->header.eventSize;
1675 printf( "Headers:\n" );
1676 for ( gdc = (struct gdcEventDescriptorStruct *)eventsHead;
1679 struct ldcEventDescriptorStruct *ldc;
1681 printf( " GDC:%d size:%d vers:%08x\n",
1683 gdc->header.eventSize,
1684 gdc->header.eventVersion);
1685 for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) {
1686 struct equipmentEventDescriptorStruct *eq;
1688 printf( " LDC:%d size:%d vers:%08x\n",
1690 ldc->header.eventSize,
1691 ldc->header.eventVersion );
1692 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1693 printf( " EQ:%d size:%d %spayload:%d\n",
1695 eq->header.equipmentSize,
1696 eq->header.equipmentSize - sizeof( struct equipmentHeaderStruct ) == (unsigned)eq->payload->size ? "" : "-ERROR",
1697 eq->payload->size );
1702 } else if ( workingAs == ldc ) {
1703 struct ldcEventDescriptorStruct *ldc;
1705 for ( ldc = (struct ldcEventDescriptorStruct *)eventsHead;
1708 struct equipmentEventDescriptorStruct *eq;
1710 initEvent( &ldc->header );
1711 ldc->header.eventSize = ldc->header.eventHeadSize;
1712 ldc->header.eventType = PHYSICS_EVENT;
1713 ldc->header.eventGdcId = VOID_ID;
1714 ldc->header.eventLdcId = ldc->id;
1715 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1716 initEquipment( &eq->header );
1717 eq->header.equipmentId = eq->id;
1718 if ( workingMode == collider )
1719 SET_SYSTEM_ATTRIBUTE( eq->header.equipmentTypeAttribute,
1721 eq->header.equipmentSize = eq->payload->size + sizeof( eq->header );
1722 ldc->header.eventSize += eq->header.equipmentSize;
1723 decodeCDH( ldc, eq->payload, eq->id );
1724 OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute,
1725 ldc->header.eventTypeAttribute );
1730 printf( "Headers:\n" );
1731 for ( ldc = (struct ldcEventDescriptorStruct *)eventsHead;
1734 struct equipmentEventDescriptorStruct *eq;
1736 printf( " LDC:%d size:%d vers:%08x\n",
1738 ldc->header.eventSize,
1739 ldc->header.eventVersion );
1740 for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
1741 printf( " EQ:%d size:%d %spayload:%d\n",
1743 eq->header.equipmentSize,
1744 eq->header.equipmentSize - sizeof( struct equipmentHeaderStruct ) == (unsigned)eq->payload->size ? "" : "-ERROR",
1745 eq->payload->size );
1750 } /* End of initEvents */
1754 workingAs = unknown;
1755 workingMode = fixedTarget;
1756 ldcsHead = ldcsTail = NULL;
1757 eventsHead = eventsTail = NULL;
1761 payloadsHead = payloadsTail = NULL;
1765 createSorEor = TRUE;
1767 gotAliceTrigger = TRUE;
1769 } /* End of initVars */
1771 int main( int argc, char **argv ) {
1773 parseArgs( argc, argv );