]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/dateStream.cxx
mixing example
[u/mrichter/AliRoot.git] / RAW / dateStream.cxx
index a0ac2a1184080bdf2e37c5fe131ff4688d3b27a0..de83c5cc63b4596e89e6f0b92cd67ff1c9bd9081 100644 (file)
@@ -84,6 +84,7 @@ struct payloadDescriptorStruct {
 } *payloadsHead, *payloadsTail;
 int lineNo;
 eventGdcIdType currGdcId;
+unsigned long32 currDetPattern; 
 eventLdcIdType currLdcId;
 equipmentIdType currEquipmentId;
 int currRunNb;
@@ -96,6 +97,8 @@ eventIdType currEventId;
 int gotAliceTrigger;
 int bufferData;
 
+struct commonDataHeaderStruct *cdhRef = NULL;
+
 void dumpPayload( const struct payloadDescriptorStruct *p ) {
   char *c;
   int i;
@@ -491,7 +494,8 @@ void loadPayload( const char *fileName ) {
              fileName,
              payload );
       if ( bufferData ) {
-       if ( handleCDH ) {
+       if ( handleCDH &&
+            strncmp(fileName,"TRG_",4) != 0 ) {
          struct commonDataHeaderStruct *cdh =
            (struct commonDataHeaderStruct *)payload->data;
 
@@ -774,6 +778,27 @@ void parseGdc( char * const line ) {
       DBG_VERBOSE printf( "%d)     GDC - ID:%d\n",
                          lineNo,
                          currGdcId );
+    } else if ( strcasecmp( "DetectorPattern", keyword ) == 0 ) {
+      char *detPattern;
+
+      if ( (detPattern = strtok_r( p, " \t", &p )) == NULL ) {
+       fprintf( stderr,
+                "%s: line:%d GDC declaration, DetectorPattern needed",
+                myName,
+                lineNo );
+       exit( 1 );
+      }
+      if ( sscanf( detPattern, "%u", &currDetPattern ) != 1 ) {
+       fprintf( stderr,
+                "%s: line:%d GDC declaration, numeric DetectorPattern needed (%s)",
+                myName,
+                lineNo,
+                detPattern );
+       exit( 1 );
+      }
+      DBG_VERBOSE printf( "%d)     GDC - DetectorPattern:%u\n",
+                         lineNo,
+                         currDetPattern );
     } else {
       fprintf( stderr,
               "%s: line:%d GDC declaration, unknown keyword \"%s\"\n",
@@ -828,6 +853,7 @@ void parseRules() {
 
   currLdcId = HOST_ID_MIN;
   currGdcId = HOST_ID_MIN;
+  currDetPattern = 0;
 
   for ( lineNo = 1; !feof( stdin ); lineNo++ ) {
     getLine( line, sizeof(line) );
@@ -967,20 +993,64 @@ void initEvent( struct eventHeaderStruct * const ev ) {
   loadTimestamp( ev );
 } /* End of initEvent */
 
+int Swap(int x)
+{
+   // Swap the endianess of the integer value 'x'
+
+   return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) <<  8) |
+           ((x & 0x00ff0000U) >>  8) | ((x & 0xff000000U) >> 24));
+}
+
 void outputEvent( const void * const ev,
                  const int size ) {
   int done;
 
   DBG_VERBOSE {
-    const long32 * const v = (long32 *)ev;
+    const long32 * const v = (long32 *)ev; 
     printf( "Writing %d bytes @ %p (%d)\n", size, ev, *v );
   }
 
-  if ( (done = fwrite( ev, size, 1, outF )) != 1 ) {
-    fprintf( stderr,
-            "%s: failed to write event size:%d bytes, errno:%d (%s)\n",
-            myName, size, errno, strerror( errno ) );
-    exit( 1 );
+  // .............................Test endianess..............................
+  int temp = 1;
+  char* ptemp = (char*) &temp;
+
+  if (ptemp[0]!=1) { // Mac platform: ptemp != 1..............................................................................
+     int  bufSize= size; if (bufSize > (int) sizeof(eventHeaderStruct)) { bufSize = sizeof(eventHeaderStruct); }
+     char* evTemp = (char*) malloc (bufSize);
+     memcpy(evTemp, ev, bufSize);
+
+     if ((bufSize % sizeof(int)) != 0) {
+            fprintf( stderr, "%s: size of the input buffer ev is not multiple of 4 (size = %d)\n", myName, bufSize);
+            exit( 1 );
+          }
+     else {
+            // Invert header to evTemp.....................................................
+            int* buf = (int*) evTemp; 
+            for (int i=0; i < (int) (bufSize / sizeof(int)); i++, buf++) {
+                 int value = Swap(*buf); 
+                 memcpy(evTemp + (i * sizeof(int)), &value, sizeof(int)); 
+            }
+
+            // Write inverted header to file...............................................
+            if ((done = fwrite( evTemp, bufSize, 1, outF )) != 1 ) {
+                 fprintf( stderr, "%s: failed to write inverted header. event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) );
+                 exit( 1 );
+            }
+
+            if (size > bufSize) {  // Still theraw-data payload to write (but not inverted, since it is inverted eariler).............
+                if ((done = fwrite( (char*)ev + bufSize, size - bufSize, 1, outF )) != 1 ) {
+                    fprintf( stderr, "%s: failed to write additional event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) );
+                    exit( 1 );
+               }
+            }
+     }
+     free(evTemp);
+  }
+  else {             // Intel platform: ptemp == 1............................................................................
+     if ((done = fwrite( ev, size, 1, outF )) != 1 ) {
+          fprintf( stderr, "%s: failed to write event size:%d bytes, errno:%d (%s)\n", myName, size, errno, strerror( errno ) );
+          exit( 1 );
+     }
   }
 } /* End of outputEvent */
 
@@ -1114,9 +1184,13 @@ void createEor() {
 } /* End of createEor */
 
 void loadCdh( struct commonDataHeaderStruct * const cdh,
-                    eventIdType            * const eventId ) {
+                    eventIdType            * const eventId,
+                    equipmentIdType id ) {
   if ( !handleCDH ) return;
 
+  // CTP raw-data does not contain CDH
+  if ( id == 4352) return;
+
   if ( gotAliceTrigger ) {
     cdh->cdhEventId1 = EVENT_ID_GET_BUNCH_CROSSING( *eventId );
     cdh->cdhEventId2 = EVENT_ID_GET_ORBIT( *eventId );
@@ -1127,7 +1201,8 @@ void loadCdh( struct commonDataHeaderStruct * const cdh,
   cdh->cdhMiniEventId = cdh->cdhEventId1;
 }
 void decodeCDH( struct ldcEventDescriptorStruct       * const ldc,
-               const struct payloadDescriptorStruct  * const payloadDesc );
+               const struct payloadDescriptorStruct  * const payloadDesc,
+               equipmentIdType id );
 
 void createEvent( void ) {
   assert( workingAs == ldc || workingAs == gdc );
@@ -1150,10 +1225,11 @@ void createEvent( void ) {
       for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
        if ( !bufferData ) {
          loadBuffer( eq->payload );
-         if ( !currGdc->loaded ) decodeCDH( ldc, eq->payload );
+         decodeCDH( ldc, eq->payload, eq->id );
        }
        loadCdh( (struct commonDataHeaderStruct*)eq->payload->data,
-                &currEventId );
+                &currEventId,
+                eq->id);
       }
 
       if ( !currGdc->loaded ) {
@@ -1166,6 +1242,7 @@ void createEvent( void ) {
        currGdc->loaded = TRUE;
       }
     }
+    cdhRef = NULL;
   } else if ( workingAs == ldc ) {
     struct equipmentEventDescriptorStruct *eq;
 
@@ -1175,12 +1252,14 @@ void createEvent( void ) {
     for ( eq = currLdc->head; eq != NULL; eq = eq->next ) {
       if ( !bufferData ) {
        loadBuffer( eq->payload );
-       if ( !currLdc->loaded ) decodeCDH( currLdc, eq->payload );
+       decodeCDH( currLdc, eq->payload, eq->id );
       }
       loadCdh( (struct commonDataHeaderStruct*)eq->payload->data,
-              &currEventId );
+              &currEventId,
+              eq->id);
       currLdc->loaded = TRUE;
     }
+    cdhRef = NULL;
   }
   ADD_EVENT_ID( currEventId, oneEventDelta );
 
@@ -1297,6 +1376,12 @@ void parseArgs( int argc, char **argv ) {
       handleCDH = TRUE;
     } else if ( strcmp( "-D", argv[ arg ] ) == 0 ) {
       bufferData = FALSE;
+    } else if ( strcmp( "-run", argv[ arg ] ) == 0 ) {
+      int runnumber;
+      if ( ++arg == argc ) exit( usage() );
+      if ( sscanf( argv[ arg ], "%d", &runnumber ) != 1 ) exit( usage() );
+      if ( runnumber < 0 ) exit( usage() );
+      currRunNb = runnumber;
     } else {
       fprintf( stderr, "%s: Unknown switch \"%s\"\n", myName, argv[argc] );
       exit( usage() );
@@ -1355,9 +1440,10 @@ void initEquipment( struct equipmentHeaderStruct * const eq ) {
 } /* End of initEquipment */
 
 void decodeCDH(       struct ldcEventDescriptorStruct * const ldc,
-               const struct payloadDescriptorStruct  * const payloadDesc ) {
-  if ( handleCDH ) {
-    static struct commonDataHeaderStruct *cdhRef = NULL;
+               const struct payloadDescriptorStruct  * const payloadDesc,
+                     equipmentIdType id ) {
+  if ( handleCDH && 
+       id != 4352 ) {
     struct commonDataHeaderStruct *cdh;
     static int softwareTriggerIndicator = FALSE;
     int attr;
@@ -1541,6 +1627,7 @@ void initEvents() {
       gdc->header.eventType = PHYSICS_EVENT;
       SET_SYSTEM_ATTRIBUTE( gdc->header.eventTypeAttribute, ATTR_SUPER_EVENT );
       gdc->header.eventGdcId = currGdcId;
+      COPY_DETECTOR_PATTERN(&currDetPattern, gdc->header.eventDetectorPattern);
       for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) {
        struct equipmentEventDescriptorStruct *eq;
 
@@ -1548,6 +1635,7 @@ void initEvents() {
        ldc->header.eventSize = ldc->header.eventHeadSize;
        ldc->header.eventType = PHYSICS_EVENT;
        ldc->header.eventGdcId = currGdcId;
+       COPY_DETECTOR_PATTERN(&currDetPattern, ldc->header.eventDetectorPattern);
        ldc->header.eventLdcId = ldc->id;
        for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
          initEquipment( &eq->header );
@@ -1557,7 +1645,7 @@ void initEvents() {
                                  ATTR_ORBIT_BC );
          eq->header.equipmentSize = eq->payload->size + sizeof( eq->header );
          ldc->header.eventSize += eq->header.equipmentSize;
-         decodeCDH( ldc, eq->payload );
+         decodeCDH( ldc, eq->payload, eq->id );
          OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute,
                             ldc->header.eventTypeAttribute );
          OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute,
@@ -1565,6 +1653,7 @@ void initEvents() {
        }
        gdc->header.eventSize += ldc->header.eventSize;
       }
+      cdhRef = NULL;
     }
 
     DBG_VERBOSE {
@@ -1616,10 +1705,11 @@ void initEvents() {
                                ATTR_ORBIT_BC );
        eq->header.equipmentSize = eq->payload->size + sizeof( eq->header );
        ldc->header.eventSize += eq->header.equipmentSize;
-       decodeCDH( ldc, eq->payload );
+       decodeCDH( ldc, eq->payload, eq->id );
        OR_ALL_ATTRIBUTES( eq->header.equipmentTypeAttribute,
                           ldc->header.eventTypeAttribute );
       }
+      cdhRef = NULL;
     }
     DBG_VERBOSE {
       printf( "Headers:\n" );
@@ -1654,7 +1744,7 @@ void initVars() {
   currLdc = NULL;
   currEvent = NULL;
   payloadsHead = payloadsTail = NULL;
-  currRunNb = 1;
+  currRunNb = -1;
   numOfLdcs = 0;
   numOfEvents = 1;
   createSorEor = TRUE;