]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliAltroRawStream.cxx
Fix in order to eliminate SSD overlaps (E. Cattaruzza)
[u/mrichter/AliRoot.git] / RAW / AliAltroRawStream.cxx
index f75f95b5881bc82c5682d182f42dd1bd954335e6..a91cbb7140c3cf172f2190af975055d08ec65fe7 100644 (file)
@@ -276,7 +276,13 @@ Bool_t AliAltroRawStream::ReadTrailer()
   }
   fCount |= ((temp & 0x3FF) >> 6);
   if (fCount == 0) return kFALSE;
-
+  if (fCount >= fPosition) {
+    fRawReader->AddMajorErrorLog(kAltroTrailerErr,"invalid size");
+    //    PrintDebug();
+    AliWarning(Form("Incorrect trailer found ! The altro payload size is invalid (%d >= %d) !",fCount,fPosition));
+    fCount = 0;
+    return kFALSE;
+  }
   temp = GetNextWord();
   fHWAddress |= temp;
 
@@ -310,21 +316,24 @@ void AliAltroRawStream::ReadBunch()
 {
   // Read altro payload in 
   // backward direction
-  if (fPosition <= 0) {
+  if (fCount <= 2) {
     fRawReader->AddMinorErrorLog(kBunchLengthReadErr,"");
     //    PrintDebug();
-    AliWarning("Could not read bunch length !");
+    AliWarning(Form("Could not read bunch length and time bin ! Only %d 10-bit words are left !",fCount));
+    fBunchLength = fTimeBunch = fCount = 0;
+    return;
   }
 
   fBunchLength = GetNextWord() - 2;
-  fTimeBunch = fBunchLength;
-  fCount--;
-
-  if (fPosition <= 0) {
-    fRawReader->AddMinorErrorLog(kTimeBinReadErr,"");
+  if (fBunchLength > fCount) {
+    fRawReader->AddMinorErrorLog(kBunchLengthReadErr,Form("bl=%d",fBunchLength));
     //    PrintDebug();
-    AliWarning("Could not read time bin !");
+    AliWarning(Form("Could not read bunch length ! Bunch length = %d (>%d)",fBunchLength,fCount));
+    fBunchLength = fTimeBunch = fCount = 0;
+    return;
   }
+  fTimeBunch = fBunchLength;
+  fCount--;
 
   fTime = GetNextWord();
   fCount--;
@@ -336,13 +345,16 @@ void AliAltroRawStream::ReadBunch()
 void AliAltroRawStream::ReadAmplitude()
 {
   // Read next time bin amplitude
-  if (fPosition <= 0) {
+  if (fCount <= 0) {
     fRawReader->AddMinorErrorLog(kAmplitudeReadErr,"");
     //    PrintDebug();
     AliWarning("Could not read sample amplitude !");
+    fCount = fSignal = fBunchLength = 0;
+    return;
   }
 
   fSignal = GetNextWord();
+
   fCount--;
   fBunchLength--;
 
@@ -371,16 +383,20 @@ Int_t AliAltroRawStream::GetPosition()
     // Now read the beginning of the trailer
     // where the payload size is written
     if (trailerSize < 2) {
-      PrintDebug();
-      AliFatal(Form("Invalid trailer size found (%d bytes) !",trailerSize*4));
+      fRawReader->AddMajorErrorLog(kRCUTrailerErr,Form("tr=%d bytes",
+                                                      trailerSize*4));
+      AliWarning(Form("Invalid trailer size found (%d bytes) !",
+                     trailerSize*4));
     }
     fRCUTrailerSize = (trailerSize-2)*4;
     index -= fRCUTrailerSize;
     if (index < 4) {
-      PrintDebug();
-      AliFatal(Form("Invalid trailer size found (%d bytes) ! The size is bigger than the raw data size (%d bytes)!",
-                   trailerSize*4,
-                   fRawReader->GetDataSize()));
+      fRawReader->AddMajorErrorLog(kRCUTrailerErr,Form("tr=%d raw=%d bytes",
+                                                       trailerSize*4,
+                                                      fRawReader->GetDataSize()));
+      AliWarning(Form("Invalid trailer size found (%d bytes) ! The size is bigger than the raw data size (%d bytes)!",
+                     trailerSize*4,
+                     fRawReader->GetDataSize()));
     }
     fRCUTrailerData = fData + index;
     Int_t position = Get32bitWord(index);
@@ -389,12 +405,17 @@ Int_t AliAltroRawStream::GetPosition()
     position *= 5;
 
     // Check the consistency of the header and trailer
-    if ((fRawReader->GetDataSize() - trailerSize*4) != position) {
-      PrintDebug();
-      AliFatal(Form("Inconsistent raw data size ! Raw data size - %d bytes (from the header), RCU trailer - %d bytes, raw data paylod - %d bytes !",
+    if (((fRawReader->GetDataSize() - trailerSize*4) < position) ||
+       ((fRawReader->GetDataSize() - trailerSize*4) >= (position + 4))) {
+      fRawReader->AddMajorErrorLog(kRCUTrailerSizeErr,Form("h=%d tr=%d rcu=%d bytes",
+                                                          fRawReader->GetDataSize(),
+                                                          trailerSize*4,
+                                                          position));
+      AliWarning(Form("Inconsistent raw data size ! Raw data size - %d bytes (from the header), RCU trailer - %d bytes, raw data paylod - %d bytes !",
                    fRawReader->GetDataSize(),
                    trailerSize*4,
                    position));
+      position = fRawReader->GetDataSize() - trailerSize*4;
     }
 
     return position * 8 / 10;
@@ -417,7 +438,8 @@ Int_t AliAltroRawStream::GetPosition()
     if (!fIsShortDataHeader) {
 
       // Check the consistency of the header and trailer
-      if ((fRawReader->GetDataSize() - 4) != position) {
+      if (((fRawReader->GetDataSize() - 4) < position) ||
+          ((fRawReader->GetDataSize() - 4) >= (position + 4))) {
        fRawReader->AddMajorErrorLog(kRCUTrailerSizeErr,Form("h=%d rcu=%d bytes",
                                                             fRawReader->GetDataSize()-4,
                                                             position));
@@ -431,7 +453,8 @@ Int_t AliAltroRawStream::GetPosition()
     else {
       // Check the consistency of the header and trailer
       // In this case the header is shorter by 4 bytes
-      if (fRawReader->GetDataSize() != position) {
+      if ((fRawReader->GetDataSize() < position) ||
+          (fRawReader->GetDataSize() >= (position + 4))) {
        fRawReader->AddMajorErrorLog(kRCUTrailerSizeErr,Form("h=%d rcu=%d bytes",
                                                             fRawReader->GetDataSize(),
                                                             position));