]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliAltroRawStreamV3.cxx
Add-on by F. Blanco: code to manage leading particle and cuts with respect to that
[u/mrichter/AliRoot.git] / RAW / AliAltroRawStreamV3.cxx
index 73f883075fc2bce26da6ec037c07ba318e3821bc..74f16d881661fa2533ff56b1e4952d17240a40a9 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),
@@ -92,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),
@@ -134,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;
@@ -171,6 +175,7 @@ void AliAltroRawStreamV3::Reset()
   fBunchLength = fStartTimeBin = -1;
   fBadChannel = kFALSE;
   fPayloadSize = -1;
+  fChannelPayloadSize = -1;
   fBunchDataPointer = NULL;
   fBunchDataIndex = -1;
 
@@ -200,6 +205,7 @@ Bool_t AliAltroRawStreamV3::NextDDL()
   } while (fRawReader->GetDataSize() == 0);
 
   fDDLNumber = fRawReader->GetDDLID();
+  fChannelPayloadSize = -1;
 
   UChar_t rcuVer = fRawReader->GetBlockAttributes();
 
@@ -224,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;
   }
@@ -241,7 +249,10 @@ 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;
   }
 
@@ -262,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
@@ -275,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;
@@ -313,17 +326,19 @@ Bool_t AliAltroRawStreamV3::NextBunch()
   fBunchLength = fBunchData[fBunchDataIndex];
   if (fBunchLength <= 2) {
     // Invalid bunch size
-    AliWarning(Form("Too short bunch length (%d) in Address=0x%x !",
-                   fBunchLength,fHWAddress));
+    AliWarning(Form("Too short bunch length (%d) in Address=0x%x (DDL=%03d)!",
+                   fBunchLength,fDDLNumber,fHWAddress));
     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 in Address=0x%x (DDL=%03d) ! Expected <= %d 10-bit words, found %d !",
+                   fHWAddress,fDDLNumber,fCount-fBunchDataIndex,fBunchLength));
     fRawReader->AddMinorErrorLog(kAltroBunchHeadErr,Form("hw=0x%x",fHWAddress));
+    if (AliDebugLevel() > 0) HexDumpChannel();
     fCount = fBunchLength = -1;
     return kFALSE;
   }
@@ -333,16 +348,18 @@ Bool_t AliAltroRawStreamV3::NextBunch()
   fStartTimeBin = fBunchData[fBunchDataIndex++];
   if (fCheckAltroPayload) {
     if ((fStartTimeBin-fBunchLength+1) < 0) {
-      AliWarning(Form("Invalid start time-bin in Address=0x%x ! (%d-%d+1) < 0",
-                     fHWAddress,fStartTimeBin,fBunchLength));
+      AliWarning(Form("Invalid start time-bin in Address=0x%x (DDL=%03d)! (%d-%d+1) < 0",
+                     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 in Address=0x%x ! (%d>=%d)",
-                     fHWAddress,fStartTimeBin,prevTimeBin));
+      AliWarning(Form("Invalid start time-bin in Address=0x%x (DDL=%03d)! (%d>=%d)",
+                     fHWAddress,fDDLNumber,fStartTimeBin,prevTimeBin));
       fRawReader->AddMinorErrorLog(kAltroPayloadErr,Form("hw=0x%x",fHWAddress));
+      if (AliDebugLevel() > 0) HexDumpChannel();
       fCount = fBunchLength = -1;
       return kFALSE;
     }
@@ -660,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.;
   }
@@ -677,3 +694,53 @@ 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\n");
+    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\n",
+            word32,marker>>1,marker&0x1,word101,word102,word103);
+    }
+  }
+}