]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/dateStream.cxx
Fix coverity defect (Jochen)
[u/mrichter/AliRoot.git] / RAW / dateStream.cxx
index 818b5755a0b52f9fa3ace95239a8dc82b1db1d84..2dbd84f9e3dc75e607a074518c318da197cacd69 100644 (file)
@@ -82,8 +82,9 @@ struct payloadDescriptorStruct {
   int size;
   void *data;
 } *payloadsHead, *payloadsTail;
-int lineNo;
+int lineNmb;
 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;
@@ -153,16 +156,16 @@ void dumpEvents() {
            gdc = gdc->next ) {
        struct ldcEventDescriptorStruct *ldc;
 
-       printf( " GDC (%p)\n", gdc );
+       printf( " GDC (%p)\n", (void*)gdc );
        for ( ldc = gdc->head; ldc != NULL; ldc = ldc->next ) {
          struct equipmentEventDescriptorStruct *eq;
            
-         printf( "   LDC (%p): %d\n", ldc, ldc->id );
+         printf( "   LDC (%p): %d\n", (void*)ldc, ldc->id );
          for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
            printf( "     EQUIPMENT (%p): %d PAYLOAD (%p):",
-                   eq,
+                   (void*)eq,
                    eq->id,
-                   eq->payload );
+                   (void*)eq->payload );
            fflush( stdout );
            printf( "\"%s\" (%d bytes)\n",
                    eq->payload->fileName,
@@ -183,9 +186,9 @@ void dumpEvents() {
        printf( "   LDC\n" );
        for ( eq = ldc->head; eq != NULL; eq = eq->next ) {
          printf( "     EQUIPMENT (%p): %d PAYLOAD (%p):",
-                 eq,
+                 (void*)eq,
                  eq->id,
-                 eq->payload );
+                 (void*)eq->payload );
          fflush( stdout );
          printf( "\"%s\" (%d bytes)\n",
                  eq->payload->fileName,
@@ -217,13 +220,13 @@ void getLine( char *line, const int maxSize ) {
   if ( read == maxSize && line[read] != '\n' ) {
     fprintf( stderr,
             "%s: Input line # %d too long (%d chars max)\n",
-            myName, lineNo, maxSize-1 );
+            myName, lineNmb, maxSize-1 );
     exit( 1 );
   }
   line[ read ] = 0;
   DBG_VERBOSE {
     if ( !( read == 0 && feof( stdin ) ) ) {
-      printf( "%d) [%3d] \"%s\"", lineNo, read, line );
+      printf( "%d) [%3d] \"%s\"", lineNmb, read, line );
     }
   }
   for ( c = 0; c != read; c++ ) {
@@ -356,7 +359,7 @@ void loadBuffer( struct payloadDescriptorStruct * const payload ) {
     fprintf( stderr,
             "%s: line:%d payload file \"%s\" not found or not readable, errno:%d. ",
             myName,
-            lineNo,
+            lineNmb,
             payload->fileName,
             errno );
     perror( "System-dependent error " );
@@ -366,7 +369,7 @@ void loadBuffer( struct payloadDescriptorStruct * const payload ) {
     fprintf( stderr,
             "%s: line:%d Failed to malloc for payload file \"%s\" size:%d errno:%d ",
             myName,
-            lineNo,
+            lineNmb,
             payload->fileName,
             payload->size,
             errno );
@@ -377,7 +380,7 @@ void loadBuffer( struct payloadDescriptorStruct * const payload ) {
     fprintf( stderr,
             "%s: line:%d Failed to read payload file \"%s\" size:%d requested:1 got:%d feof:%s ferror:%s errno:%d ",
             myName,
-            lineNo,
+            lineNmb,
             payload->fileName,
             payload->size,
             bytesRead,
@@ -439,7 +442,7 @@ void loadPayload( const char *fileName ) {
       fprintf( stderr,
               "%s: line:%d payload file \"%s\" not found or not readable, errno:%d. ",
               myName,
-              lineNo,
+              lineNmb,
               fileName,
               errno );
       perror( "System-dependent error " );
@@ -449,7 +452,7 @@ void loadPayload( const char *fileName ) {
       fprintf( stderr,
               "%s: line:%d Failed to seek payload file \"%s\" errno:%d ",
               myName,
-              lineNo,
+              lineNmb,
               fileName,
               errno );
       perror( "System-dependent error " );
@@ -459,7 +462,7 @@ void loadPayload( const char *fileName ) {
       fprintf( stderr,
               "%s: line:%d Failed to get file \"%s\" size size:%d errno:%d ",
               myName,
-              lineNo,
+              lineNmb,
               fileName,
               payload->size,
               errno );
@@ -487,11 +490,12 @@ void loadPayload( const char *fileName ) {
       int b, n;
 
       printf( "%d)       Payload \"%s\" loaded at %p\n",
-             lineNo,
+             lineNmb,
              fileName,
-             payload );
+             (void*)payload );
       if ( bufferData ) {
-       if ( handleCDH ) {
+       if ( handleCDH &&
+            strncmp(fileName,"TRG_",4) != 0 ) {
          struct commonDataHeaderStruct *cdh =
            (struct commonDataHeaderStruct *)payload->data;
 
@@ -646,9 +650,9 @@ void loadPayload( const char *fileName ) {
   } else {
     DBG_VERBOSE
       printf( "%d)       Payload \"%s\" already loaded at %p\n",
-             lineNo,
+             lineNmb,
              fileName,
-             payload );
+             (void*)payload );
   }
 
   currEvent->payload = payload;
@@ -675,7 +679,7 @@ void parseEquipment( char * const line ) {
   p = line;
   while ( (keyword = strtok_r( p, " \t", &p )) != NULL ) {
     DBG_VERBOSE printf( "%d)     Equipment - Keyword:\"%s\"\n",
-                       lineNo,
+                       lineNmb,
                        keyword );
     if ( strcasecmp( "id", keyword ) == 0 ) {
       char *idNum;
@@ -684,19 +688,19 @@ void parseEquipment( char * const line ) {
        fprintf( stderr,
                 "%s: line:%d EQUIPMENT declaration, ID needed",
                 myName,
-                lineNo );
+                lineNmb );
        exit( 1 );
       }
       if ( sscanf( idNum, "%d", &currEquipmentId ) != 1 ) {
        fprintf( stderr,
                 "%s: line:%d EQUIPMENT declaration, numeric ID needed (%s)",
                 myName,
-                lineNo,
+                lineNmb,
                 idNum );
        exit( 1 );
       }
       DBG_VERBOSE printf( "%d)     EQUIPMENT - ID:%d\n",
-                         lineNo,
+                         lineNmb,
                          currEquipmentId );
     } else if ( strncasecmp( "pay", keyword, 3 ) == 0 ) {
       char *fileName;
@@ -705,17 +709,17 @@ void parseEquipment( char * const line ) {
        fprintf( stderr,
                 "%s line:%d Payload without filename found\n",
                 myName,
-                lineNo );
+                lineNmb );
        exit( 1 );
       }
       DBG_VERBOSE printf( "%d)     Equipment - Payload:\"%s\"\n",
-                         lineNo,
+                         lineNmb,
                          fileName );
       if ( payloadFound ) {
        fprintf( stderr,
                 "%s line:%d Payload with multiple filenames found\n",
                 myName,
-                lineNo );
+                lineNmb );
        exit( 1 );
       }
       loadPayload( fileName );
@@ -724,7 +728,7 @@ void parseEquipment( char * const line ) {
       fprintf( stderr,
               "%s: line:%d Equipment declaration, unknown keyword \"%s\"\n",
               myName,
-              lineNo,
+              lineNmb,
               keyword );
       exit( 1 );
     }
@@ -733,7 +737,7 @@ void parseEquipment( char * const line ) {
     fprintf( stderr,
             "%s: line:%d Equipment without payload found\n",
             myName,
-            lineNo );
+            lineNmb );
     exit( 1 );
   }
 
@@ -760,25 +764,46 @@ void parseGdc( char * const line ) {
        fprintf( stderr,
                 "%s: line:%d GDC declaration, ID needed",
                 myName,
-                lineNo );
+                lineNmb );
        exit( 1 );
       }
-      if ( sscanf( idNum, "%d", &currGdcId ) != 1 ) {
+      if ( sscanf( idNum, "%d", (int*)&currGdcId ) != 1 ) {
        fprintf( stderr,
                 "%s: line:%d GDC declaration, numeric ID needed (%s)",
                 myName,
-                lineNo,
+                lineNmb,
                 idNum );
        exit( 1 );
       }
       DBG_VERBOSE printf( "%d)     GDC - ID:%d\n",
-                         lineNo,
+                         lineNmb,
                          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,
+                lineNmb );
+       exit( 1 );
+      }
+      if ( sscanf( detPattern, "%u", &currDetPattern ) != 1 ) {
+       fprintf( stderr,
+                "%s: line:%d GDC declaration, numeric DetectorPattern needed (%s)",
+                myName,
+                lineNmb,
+                detPattern );
+       exit( 1 );
+      }
+      DBG_VERBOSE printf( "%d)     GDC - DetectorPattern:%u\n",
+                         lineNmb,
+                         currDetPattern );
     } else {
       fprintf( stderr,
               "%s: line:%d GDC declaration, unknown keyword \"%s\"\n",
               myName,
-              lineNo,
+              lineNmb,
               keyword );
       exit( 1 );
     }  
@@ -798,25 +823,27 @@ void parseLdc( char * const line ) {
        fprintf( stderr,
                 "%s: line:%d LDC declaration, ID needed",
                 myName,
-                lineNo );
+                lineNmb );
        exit( 1 );
       }
-      if ( sscanf( idNum, "%d", &currLdcId ) != 1 ) {
+      int inCurrLdcId;
+      if ( sscanf( idNum, "%d", &inCurrLdcId ) != 1 ) {
        fprintf( stderr,
                 "%s: line:%d LDC declaration, numeric ID needed (%s)",
                 myName,
-                lineNo,
+                lineNmb,
                 idNum );
        exit( 1 );
       }
+      currLdcId = (eventLdcIdType)inCurrLdcId;
       DBG_VERBOSE printf( "%d)     LDC - ID:%d\n",
-                         lineNo,
+                         lineNmb,
                          currLdcId );
     } else {
       fprintf( stderr,
               "%s: line:%d LDC declaration, unknown keyword \"%s\"\n",
               myName,
-              lineNo,
+              lineNmb,
               keyword );
       exit( 1 );
     }  
@@ -828,20 +855,21 @@ void parseRules() {
 
   currLdcId = HOST_ID_MIN;
   currGdcId = HOST_ID_MIN;
+  currDetPattern = 0;
 
-  for ( lineNo = 1; !feof( stdin ); lineNo++ ) {
+  for ( lineNmb = 1; !feof( stdin ); lineNmb++ ) {
     getLine( line, sizeof(line) );
     if ( strlen(line) != 0 ) {
       char *p;
       char *keyword;
 
       if ( (keyword = strtok_r( line, " \t", &p )) != NULL ) {
-       DBG_VERBOSE printf( "%d)   Keyword:\"%s\"\n", lineNo, keyword );
+       DBG_VERBOSE printf( "%d)   Keyword:\"%s\"\n", lineNmb, keyword );
        if ( strcasecmp( "gdc", keyword ) == 0 ) {
          if ( workingAs != gdc && workingAs != unknown ) {
            fprintf( stderr,
                     "%s: line:%d GDC found when working in non-GDC mode (e.g. as a LDC)\n",
-                    myName, lineNo );
+                    myName, lineNmb );
            exit( 1 );
          }
          workingAs = gdc;
@@ -854,7 +882,7 @@ void parseRules() {
          if ( workingAs != gdc && workingAs != ldc && workingAs != unknown ) {
            fprintf( stderr,
                     "%s: line:%d LDC found when working in non-LDC/GDC mode\n",
-                    myName, lineNo );
+                    myName, lineNmb );
            exit( 1 );
          }
          if ( workingAs == unknown ) workingAs = ldc;
@@ -875,7 +903,7 @@ void parseRules() {
            fprintf( stderr,
                     "%s: line:%d Unexpected EQUIPMENT declaration (LDC or GDC needed first)\n",
                     myName,
-                    lineNo );
+                    lineNmb );
            exit( 1 );
          }
          parseEquipment( p );
@@ -884,19 +912,19 @@ void parseRules() {
          fprintf( stderr,
                   "%s: line:%d Parse error in \"%s\" unknown keyword\n",
                   myName,
-                  lineNo,
+                  lineNmb,
                   keyword );
          exit( 1 );
        }
       }
     }
-  } while ( !feof( stdin ) );
-  lineNo -= 2;
+  } while ( !feof( stdin ) ) {}
+  lineNmb -= 2;
 
   DBG_VERBOSE {
     printf( "End of parse: %d line%s found\n",
-           lineNo,
-           lineNo != 1 ? "s" : "" );
+           lineNmb,
+           lineNmb != 1 ? "s" : "" );
     printf( "Working as %s\n",
            workingAs == gdc ? "GDC" :
             workingAs == ldc ? "LDC" :
@@ -924,7 +952,7 @@ void parseRules() {
     assert( ldcsHead != NULL );
     assert( ldcsTail != NULL );
     assert( ldcsTail->next == NULL );
-    for ( ldc = ldcsHead; ldc->next != NULL; ldc = ldc->next );
+    for ( ldc = ldcsHead; ldc->next != NULL; ldc = ldc->next ) {}
     assert ( ldc == ldcsTail );
   }
 
@@ -1158,9 +1186,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 );
@@ -1171,7 +1203,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 );
@@ -1194,10 +1227,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 ) {
@@ -1210,6 +1244,7 @@ void createEvent( void ) {
        currGdc->loaded = TRUE;
       }
     }
+    cdhRef = NULL;
   } else if ( workingAs == ldc ) {
     struct equipmentEventDescriptorStruct *eq;
 
@@ -1219,12 +1254,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 );
 
@@ -1405,9 +1442,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;
@@ -1591,6 +1629,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;
 
@@ -1598,6 +1637,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 );
@@ -1607,7 +1647,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,
@@ -1615,6 +1655,7 @@ void initEvents() {
        }
        gdc->header.eventSize += ldc->header.eventSize;
       }
+      cdhRef = NULL;
     }
 
     DBG_VERBOSE {
@@ -1666,10 +1707,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" );