]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderDate.cxx
Fix for possible use of AliCFManager without containers, just cuts.
[u/mrichter/AliRoot.git] / RAW / AliRawReaderDate.cxx
index 64e760357cff1d2f430b18b1fb9a2b764bb00ee2..fa0ef4c6a39af68681a251af4833d6abd05c24ca 100644 (file)
@@ -76,6 +76,7 @@ AliRawReaderDate::AliRawReaderDate(
   fFile = fopen(fileName, "rb");
   if (!fFile) {
     Error("AliRawReaderDate", "could not open file %s", fileName);
+    fIsValid = kFALSE;
     return;
   }
   if (eventNumber < 0) return;
@@ -85,7 +86,7 @@ AliRawReaderDate::AliRawReaderDate(
   while (fread(&header, 1, headerSize, fFile) == headerSize) {
     if (eventNumber == 0) {
       UChar_t* buffer = new UChar_t[header.eventSize];
-      fseek(fFile, -headerSize, SEEK_CUR);
+      fseek(fFile, -(long)headerSize, SEEK_CUR);
       if (fread(buffer, 1, header.eventSize, fFile) != header.eventSize) break;
       fEvent = (eventHeaderStruct*) buffer;
       break;
@@ -244,17 +245,28 @@ UInt_t AliRawReaderDate::GetGDCId() const
 #endif
 }
 
+UInt_t AliRawReaderDate::GetTimestamp() const
+{
+// get the timestamp from the event header
+
+#ifdef ALI_DATE
+  if (!fEvent) return 0;
+  return fEvent->eventTimestamp;
+#else
+  return 0;
+#endif
+}
 
 Int_t AliRawReaderDate::GetEquipmentSize() const
 {
-// get the size of the equipment (without header)
+// get the size of the equipment (including the header)
 
 #ifdef ALI_DATE
   if (!fEquipment) return 0;
   if (fSubEvent->eventVersion <= 0x00030001) {
-    return fEquipment->equipmentSize;
+    return fEquipment->equipmentSize + sizeof(equipmentHeaderStruct);
   } else {
-    return fEquipment->equipmentSize - sizeof(equipmentHeaderStruct);
+    return fEquipment->equipmentSize;
   }
 #else
   return 0;
@@ -309,6 +321,16 @@ Int_t AliRawReaderDate::GetEquipmentElementSize() const
 #endif
 }
 
+Int_t AliRawReaderDate::GetEquipmentHeaderSize() const
+{
+  // Get the equipment header size
+  // 28 bytes by default
+#ifdef ALI_DATE
+  return sizeof(equipmentHeaderStruct);
+#else
+  return 0;
+#endif
+}
 
 Bool_t AliRawReaderDate::ReadHeader()
 {
@@ -402,6 +424,14 @@ Bool_t AliRawReaderDate::ReadHeader()
 
       // "read" the data header
       fHeader = (AliRawDataHeader*) fPosition;
+      if ((fPosition + fHeader->fSize) != fEnd) {
+       if ((fHeader->fSize != 0xFFFFFFFF) &&
+           (fEquipment->equipmentId != 4352))
+         Warning("ReadHeader",
+                 "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
+                 fHeader->fSize, fEnd - fPosition);
+       fHeader->fSize = fEnd - fPosition;
+      }
       fPosition += sizeof(AliRawDataHeader);
     }
 
@@ -486,7 +516,14 @@ Bool_t AliRawReaderDate::NextEvent()
 // go to the next event in the date file
 
 #ifdef ALI_DATE
-  if (!fFile) return kFALSE;
+  if (!fFile) {
+    if (fEventNumber < 0 && fEvent) {
+      fEventNumber++;
+      return kTRUE;
+    }
+    else
+      return kFALSE;
+  }
 
   Reset();
   eventHeaderStruct header;
@@ -500,13 +537,14 @@ Bool_t AliRawReaderDate::NextEvent()
       continue;
     }
     UChar_t* buffer = new UChar_t[header.eventSize];
-    fseek(fFile, -headerSize, SEEK_CUR);
+    fseek(fFile, -(long)headerSize, SEEK_CUR);
     if (fread(buffer, 1, header.eventSize, fFile) != header.eventSize) {
       Error("NextEvent", "could not read event from file");
       delete[] buffer;
       break;
     }
     fEvent = (eventHeaderStruct*) buffer;
+    fEventNumber++;
     return kTRUE;
   };
 
@@ -520,9 +558,10 @@ Bool_t AliRawReaderDate::RewindEvents()
 {
 // go back to the beginning of the date file
 
-  if (!fFile) return kFALSE;
+  if (fFile)
+    fseek(fFile, 0, SEEK_SET);
 
-  fseek(fFile, 0, SEEK_SET);
+  fEventNumber = -1;
   return Reset();
 }
 
@@ -582,8 +621,13 @@ Int_t AliRawReaderDate::CheckData() const
 
       // check consistency of data size in the data header and in the sub event
       AliRawDataHeader* header = (AliRawDataHeader*) position;
-      if (header->fSize != 0xFFFFFFFF) {
-       if (position + header->fSize > end) result |= kErrSize;
+      if ((position + header->fSize) != end) {
+       if (header->fSize != 0xFFFFFFFF)
+         Warning("ReadHeader",
+                 "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
+                 header->fSize, end - position);
+       header->fSize = end - position;
+       result |= kErrSize;
       }
     }
     position = end;