]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliAltroRawStream.cxx
First step towards reading of the new RCU firmware trailer. Thanks to Luciano we...
[u/mrichter/AliRoot.git] / RAW / AliAltroRawStream.cxx
index 97a37bee715f69e302ee1c7a76325ca07767f720..43b6ef57c37330cd558020eb405ce32dceab0886 100644 (file)
@@ -36,7 +36,6 @@ ClassImp(AliAltroRawStream)
 //_____________________________________________________________________________
 AliAltroRawStream::AliAltroRawStream(AliRawReader* rawReader) :
   fNoAltroMapping(kTRUE),
-  fIsOldRCUFormat(kFALSE),
   fIsShortDataHeader(kFALSE),
   fDDLNumber(-1),
   fPrevDDLNumber(-1),
@@ -64,7 +63,6 @@ AliAltroRawStream::AliAltroRawStream(AliRawReader* rawReader) :
 AliAltroRawStream::AliAltroRawStream(const AliAltroRawStream& stream) :
   TObject(stream),
   fNoAltroMapping(stream.fNoAltroMapping),
-  fIsOldRCUFormat(stream.fIsOldRCUFormat),
   fIsShortDataHeader(stream.fIsShortDataHeader),
   fDDLNumber(stream.fDDLNumber),
   fPrevDDLNumber(stream.fPrevDDLNumber),
@@ -95,7 +93,6 @@ AliAltroRawStream& AliAltroRawStream::operator = (const AliAltroRawStream& strea
   if(&stream == this) return *this;
 
   fNoAltroMapping    = stream.fNoAltroMapping;
-  fIsOldRCUFormat    = stream.fIsOldRCUFormat;
   fIsShortDataHeader = stream.fIsShortDataHeader;
   fDDLNumber         = stream.fDDLNumber;
   fPrevDDLNumber     = stream.fPrevDDLNumber;
@@ -276,7 +273,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 +313,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 +342,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--;
 
@@ -360,13 +369,36 @@ Int_t AliAltroRawStream::GetPosition()
   // The RCU trailer format is described
   // in details in the RCU manual.
 
-  if (!fIsOldRCUFormat) {
-    // First read 32-bit word with the
-    // trailer size (22 bits) and RCU ID (the rest)
-    Int_t index = fRawReader->GetDataSize();
-    UInt_t word = Get32bitWord(index);
-    fRCUId = (Int_t)(word >> 22);
-    Int_t trailerSize = (word & 0x3FFFFF);
+  // We use the last word of the payload
+  // in order to decide which RCU firmware
+  // was used during the data taking.
+  // The firmware v2 adds 0xAAAA as 16
+  // most significant bits and since the
+  // payload size (firmware v1) can not be
+  // that big, we use this as a unique
+  // label of the firmware version.
+
+  Int_t index = fRawReader->GetDataSize();
+  UInt_t word = Get32bitWord(index);
+  if (((word >> 16) == 0xaaaa) || (word == 2)) {
+    // This is RCU formware v2
+    // The statement word==2 is needed only temporary
+    // in order to be able to read previously generated
+    // aliroot raw data
+
+    Int_t trailerSize = 0;
+    if (word == 2) {
+      AliInfo("Old simulated raw data is assumed!");
+      trailerSize = 2;
+      fRCUId = 0;
+    }
+    else {
+      // First read 32-bit word with the
+      // trailer size (7 bits), RCU ID (9 bits) and
+      // 0xAAA (the rest - 16 bits)
+      fRCUId = (Int_t)((word >> 7) & 0x1ff);
+      trailerSize = (word & 0x7F);
+    }
 
     // Now read the beginning of the trailer
     // where the payload size is written
@@ -379,10 +411,12 @@ Int_t AliAltroRawStream::GetPosition()
     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);
@@ -410,8 +444,7 @@ Int_t AliAltroRawStream::GetPosition()
     // In case of the Old RCU trailer format
     // we have to read just the size of altro payload
     // in units of 40-bit words
-    Int_t index = fRawReader->GetDataSize();
-    Int_t position = Get32bitWord(index);
+    Int_t position = (Int_t)word;
 
     fRCUId = -1;
     fRCUTrailerSize = 0;