]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliAltroRawStreamV3.cxx
Bug #83805. Better hex dumps and correct some debug/warning messages (Christian).
[u/mrichter/AliRoot.git] / RAW / AliAltroRawStreamV3.cxx
index 2a0c50104be91adc53dc45774408e4975c18f9ce..e79cff2d84c80a49ac2aa25358118a5a67f5d997 100644 (file)
@@ -30,6 +30,7 @@
 #include "AliRawReader.h"
 #include "AliLog.h"
 #include "AliAltroRawStream.h"
+#include "AliRawEventHeaderBase.h"
 
 ClassImp(AliAltroRawStreamV3)
 
@@ -48,6 +49,7 @@ AliAltroRawStreamV3::AliAltroRawStreamV3(AliRawReader* rawReader) :
   fBunchLength(-1),
   fBadChannel(kFALSE),
   fPayloadSize(-1),
+  fChannelPayloadSize(-1),
   fBunchDataPointer(NULL),
   fBunchDataIndex(-1),
   fRCUTrailerData(NULL),
@@ -60,7 +62,8 @@ AliAltroRawStreamV3::AliAltroRawStreamV3(AliRawReader* rawReader) :
   fActiveFECsB(0),
   fAltroCFG1(0),
   fAltroCFG2(0),
-  fOldStream(NULL)
+  fOldStream(NULL),
+  fCheckAltroPayload(kTRUE)
 {
   // Constructor
   // Create an object to read Altro raw digits in
@@ -91,6 +94,7 @@ AliAltroRawStreamV3::AliAltroRawStreamV3(const AliAltroRawStreamV3& stream) :
   fBunchLength(stream.fBunchLength),
   fBadChannel(stream.fBadChannel),
   fPayloadSize(stream.fPayloadSize),
+  fChannelPayloadSize(stream.fChannelPayloadSize),
   fBunchDataPointer(stream.fBunchDataPointer),
   fBunchDataIndex(stream.fBunchDataIndex),
   fRCUTrailerData(stream.fRCUTrailerData),
@@ -103,7 +107,8 @@ AliAltroRawStreamV3::AliAltroRawStreamV3(const AliAltroRawStreamV3& stream) :
   fActiveFECsB(stream.fActiveFECsB),
   fAltroCFG1(stream.fAltroCFG1),
   fAltroCFG2(stream.fAltroCFG2),
-  fOldStream(NULL)
+  fOldStream(NULL),
+  fCheckAltroPayload(stream.fCheckAltroPayload)
 {
   // Copy constructor
   // Copy the bunch data array
@@ -132,6 +137,7 @@ AliAltroRawStreamV3& AliAltroRawStreamV3::operator = (const AliAltroRawStreamV3&
   fBunchLength       = stream.fBunchLength;
   fBadChannel        = stream.fBadChannel;
   fPayloadSize       = stream.fPayloadSize;
+  fChannelPayloadSize= stream.fChannelPayloadSize;
   fBunchDataPointer  = stream.fBunchDataPointer;
   fBunchDataIndex    = stream.fBunchDataIndex;
   fRCUTrailerData    = stream.fRCUTrailerData;
@@ -153,6 +159,8 @@ AliAltroRawStreamV3& AliAltroRawStreamV3::operator = (const AliAltroRawStreamV3&
     *fOldStream = *stream.fOldStream;
   }
 
+  fCheckAltroPayload = stream.fCheckAltroPayload;
+
   return *this;
 }
 
@@ -167,6 +175,7 @@ void AliAltroRawStreamV3::Reset()
   fBunchLength = fStartTimeBin = -1;
   fBadChannel = kFALSE;
   fPayloadSize = -1;
+  fChannelPayloadSize = -1;
   fBunchDataPointer = NULL;
   fBunchDataIndex = -1;
 
@@ -196,6 +205,7 @@ Bool_t AliAltroRawStreamV3::NextDDL()
   } while (fRawReader->GetDataSize() == 0);
 
   fDDLNumber = fRawReader->GetDDLID();
+  fChannelPayloadSize = -1;
 
   UChar_t rcuVer = fRawReader->GetBlockAttributes();
 
@@ -220,6 +230,8 @@ Bool_t AliAltroRawStreamV3::NextDDL()
       fActiveFECsB = fOldStream->GetActiveFECsB();
       fAltroCFG1 = fOldStream->GetAltroCFG1();
       fAltroCFG2 = fOldStream->GetAltroCFG2();
+      if (fRawReader->GetType() == AliRawEventHeaderBase::kStartOfData)
+       fPayloadSize = fOldStream->GetRCUPayloadSizeInSOD();
     }
     return status;
   }
@@ -237,13 +249,17 @@ Bool_t AliAltroRawStreamV3::NextChannel()
   // RCU signals readout error in this channel
   if (fOldStream) {
     Bool_t status = fOldStream->NextChannel();
-    if (status) fHWAddress = fOldStream->GetHWAddress();
+    if (status) {
+      fHWAddress = fOldStream->GetHWAddress();
+      fChannelPayloadSize = fOldStream->GetChannelPayloadSize();
+    }
     return status;
   }
 
   fCount = -1;
   fBadChannel = kFALSE;
   fBunchDataIndex = 0;
+  fBunchLength = -1;
 
   UInt_t word = 0;
   do {
@@ -257,6 +273,7 @@ Bool_t AliAltroRawStreamV3::NextChannel()
 
   // extract channel payload and hw address
   fCount = (word >> 16) & 0x3FF; 
+  fChannelPayloadSize = fCount;
   fHWAddress = word & 0xFFF;
 
   // Now unpack the altro data
@@ -270,9 +287,10 @@ Bool_t AliAltroRawStreamV3::NextChannel()
     word = Get32bitWord(fPosition++);
     if ((word >> 30) != 0) {
       // Unexpected end of altro channel payload
-      AliWarning(Form("Unexpected end of payload in altro channel payload! Address=0x%x, word=0x%x",
-                     fHWAddress,word));
+      AliWarning(Form("Unexpected end of payload in altro channel payload! DDL=%03d, Address=0x%x, word=0x%x",
+                     fDDLNumber,fHWAddress,word));
       fRawReader->AddMinorErrorLog(kAltroPayloadErr,Form("hw=0x%x",fHWAddress));
+      if (AliDebugLevel() > 0) HexDumpChannel();
       fCount = -1;
       fPosition--;
       return kFALSE;
@@ -299,17 +317,28 @@ Bool_t AliAltroRawStreamV3::NextBunch()
     return status;
   }
 
+  Int_t prevTimeBin = (fBunchLength > 0) ? fStartTimeBin-fBunchLength+1 : 1024;
   fBunchLength = fStartTimeBin = -1;
   fBunchDataPointer = NULL;
 
   if ((fBunchDataIndex >= fCount) || fBadChannel) return kFALSE;
 
   fBunchLength = fBunchData[fBunchDataIndex];
+  if (fBunchLength <= 2) {
+    // Invalid bunch size
+    AliWarning(Form("Too short bunch length (%d) @ %d in Address=0x%x (DDL=%03d)!",
+                   fBunchLength,fBunchDataIndex,fHWAddress,fDDLNumber));
+    fRawReader->AddMinorErrorLog(kAltroBunchHeadErr,Form("hw=0x%x",fHWAddress));
+    if (AliDebugLevel() > 0) HexDumpChannel();
+    fCount = fBunchLength = -1;
+    return kFALSE;
+  }
   if ((fBunchDataIndex + fBunchLength) > fCount) {
     // Too long bunch detected
-    AliWarning(Form("Too long bunch detected in Address=0x%x ! Expected <= %d 10-bit words, found %d !",
-                   fHWAddress,fCount-fBunchDataIndex,fBunchLength));
+    AliWarning(Form("Too long bunch detected @ %d in Address=0x%x (DDL=%03d) ! Expected <= %d 10-bit words, found %d !", fBunchDataIndex,
+                   fHWAddress,fDDLNumber,fCount-fBunchDataIndex,fBunchLength));
     fRawReader->AddMinorErrorLog(kAltroBunchHeadErr,Form("hw=0x%x",fHWAddress));
+    if (AliDebugLevel() > 0) HexDumpChannel();
     fCount = fBunchLength = -1;
     return kFALSE;
   }
@@ -317,6 +346,24 @@ Bool_t AliAltroRawStreamV3::NextBunch()
   fBunchLength -= 2;
 
   fStartTimeBin = fBunchData[fBunchDataIndex++];
+  if (fCheckAltroPayload) {
+    if ((fStartTimeBin-fBunchLength+1) < 0) {
+      AliWarning(Form("Invalid start time-bin @ %d in Address=0x%x (DDL=%03d)! (%d-%d+1) < 0", fBunchDataIndex-1,
+                     fHWAddress,fDDLNumber,fStartTimeBin,fBunchLength));
+      fRawReader->AddMinorErrorLog(kAltroPayloadErr,Form("hw=0x%x",fHWAddress));
+      if (AliDebugLevel() > 0) HexDumpChannel();
+      fCount = fBunchLength = -1;
+      return kFALSE;
+    }
+    if (fStartTimeBin >= prevTimeBin) {
+      AliWarning(Form("Invalid start time-bin @ %d in Address=0x%x (DDL=%03d)! (%d>=%d)", fBunchDataIndex-1,
+                     fHWAddress,fDDLNumber,fStartTimeBin,prevTimeBin));
+      fRawReader->AddMinorErrorLog(kAltroPayloadErr,Form("hw=0x%x",fHWAddress));
+      if (AliDebugLevel() > 0) HexDumpChannel();
+      fCount = fBunchLength = -1;
+      return kFALSE;
+    }
+  }
 
   fBunchDataPointer = &fBunchData[fBunchDataIndex];
 
@@ -630,7 +677,7 @@ Double_t AliAltroRawStreamV3::GetL1Phase() const
 
   Double_t tSample = GetTSample();
   if (phase >= tSample) {
-    AliWarning(Form("Invalid L1 trigger phase (%f >= %d) !",
+    AliWarning(Form("Invalid L1 trigger phase (%f >= %f) !",
                    phase,tSample));
     phase = 0.;
   }
@@ -647,3 +694,61 @@ void AliAltroRawStreamV3::AddMappingErrorLog(const char *message)
 
   if (fRawReader) fRawReader->AddMinorErrorLog(kBadAltroMapping,message);
 }
+
+//_____________________________________________________________________________
+UChar_t *AliAltroRawStreamV3::GetRCUPayloadInSOD() const
+{
+  // Get a pointer to the data in case
+  // of SOD events
+  if (fRawReader) {
+    if (fRawReader->GetType() == AliRawEventHeaderBase::kStartOfData) {
+      return fData;
+    }
+  }
+  return NULL;
+}
+
+//_____________________________________________________________________________
+Int_t AliAltroRawStreamV3::GetRCUPayloadSizeInSOD() const
+{
+  // Get the size of the RCU data in case
+  // of SOD events
+  if (fRawReader) {
+    if (fRawReader->GetType() == AliRawEventHeaderBase::kStartOfData) {
+      return fPayloadSize;
+    }
+  }
+  return -1;
+}
+
+//_____________________________________________________________________________
+
+void AliAltroRawStreamV3::HexDumpChannel() const
+{
+  // Print of the Hex Data of the current channel
+  // to decipher read-out warnings and errors
+  if (fCount>0 && fPosition>0) {
+    printf("Hex-Dump of DDL: %3d, RCU ID: %d, HWADDR: 0x%03x\n",
+           fDDLNumber,fRCUId,fHWAddress);
+    printf("32-bit     - 2bit 10bit 10bit 10bit - ");
+    printf("Index 10bit  10bit  10bit\n");
+    printf("**********   **** ***** ***** ***** - ");
+    printf("***** ****** ****** ******\n");
+    Int_t nwords = (fCount+2)/3+1;
+    for (Int_t iword = 0; iword < nwords; iword++) {
+      UInt_t word32 = Get32bitWord(fPosition-nwords+iword);
+      UInt_t marker  = word32 >> 30 & 0x3;
+      UInt_t word101 = word32 >> 20 & 0x3FF;
+      UInt_t word102 = word32 >> 10 & 0x3FF;
+      UInt_t word103 = word32 >> 00 & 0x3FF; // nice octal number
+      printf("0x%08x - 0b%1d%1d 0x%03x 0x%03x 0x%03x",
+            word32,marker>>1,marker&0x1,word101,word102,word103);
+      if (iword == 0) { printf(" - Channel Header\n"); continue; }
+      Int_t base = 3*(iword-1);
+      printf(" - %5d 0x%03x%c 0x%03x%c 0x%03x%c\n", base,
+            fBunchData[base],   (fBunchDataIndex == base   ? '*' : ' '),
+            fBunchData[base+1], (fBunchDataIndex == base+1 ? '*' : ' '),
+            fBunchData[base+2], (fBunchDataIndex == base+2 ? '*' : ' '));
+    }
+  }
+}