]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliAltroRawStream.cxx
New methods to retrieve altro hardware address information - branch, fec, altro chip...
[u/mrichter/AliRoot.git] / RAW / AliAltroRawStream.cxx
index 82e7bf83c66a9eafc51d8996f8216ffa0e1df4a8..4232d9e49b8ee724054efe3ab4c10fdafd6a158c 100644 (file)
@@ -37,6 +37,7 @@ ClassImp(AliAltroRawStream)
 AliAltroRawStream::AliAltroRawStream(AliRawReader* rawReader) :
   fNoAltroMapping(kTRUE),
   fIsOldRCUFormat(kFALSE),
+  fIsShortDataHeader(kFALSE),
   fDDLNumber(-1),
   fPrevDDLNumber(-1),
   fRCUId(-1),
@@ -64,6 +65,7 @@ AliAltroRawStream::AliAltroRawStream(const AliAltroRawStream& stream) :
   TObject(stream),
   fNoAltroMapping(kTRUE),
   fIsOldRCUFormat(kFALSE),
+  fIsShortDataHeader(kFALSE),
   fDDLNumber(-1),
   fPrevDDLNumber(-1),
   fRCUId(-1),
@@ -162,6 +164,15 @@ void AliAltroRawStream::SelectRawData(Int_t detId)
   fRawReader->Select(detId);
 }
 
+//_____________________________________________________________________________
+void AliAltroRawStream::SelectRawData(const char *detName)
+{
+  // Select the raw data for specific
+  // detector name
+  AliDebug(1,Form("Selecting raw data for detector %s",detName));
+  fRawReader->Select(detName);
+}
+
 //_____________________________________________________________________________
 UShort_t AliAltroRawStream::GetNextWord()
 {
@@ -196,21 +207,29 @@ Bool_t AliAltroRawStream::ReadTrailer()
   UShort_t temp;
   Int_t nFillWords = 0;
   while ((temp = GetNextWord()) == 0x2AA) nFillWords++;
-  if (nFillWords == 0)
+  if (nFillWords == 0) {
+    PrintDebug();
     AliFatal("Incorrect trailer found ! Expected 0x2AA not found !");
+  }
 
   //Then read the trailer
-  if (fPosition <= 4)
+  if (fPosition <= 4) {
+    PrintDebug();
     AliFatal(Form("Incorrect raw data size ! Expected at lest 4 words but found %d !",fPosition));
+  }
 
   fCount = (temp << 4) & 0x3FF;
-  if ((temp >> 6) != 0xA)
+  if ((temp >> 6) != 0xA) {
+    PrintDebug();
     AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
+  }
 
   temp = GetNextWord();
   fHWAddress = (temp & 0x3) << 10;
-  if (((temp >> 2) & 0xF) != 0xA)
+  if (((temp >> 2) & 0xF) != 0xA) {
+    PrintDebug();
     AliFatal(Form("Incorrect trailer found ! Expecting second 0xA but found %x !",(temp >> 2) & 0xF));
+  }
   fCount |= ((temp & 0x3FF) >> 6);
   if (fCount == 0) return kFALSE;
 
@@ -247,15 +266,19 @@ void AliAltroRawStream::ReadBunch()
 {
   // Read altro payload in 
   // backward direction
-  if (fPosition <= 0)
+  if (fPosition <= 0) {
+    PrintDebug();
     AliFatal("Could not read bunch length !");
+  }
 
   fBunchLength = GetNextWord() - 2;
   fTimeBunch = fBunchLength;
   fCount--;
 
-  if (fPosition <= 0)
+  if (fPosition <= 0) {
+    PrintDebug();
     AliFatal("Could not read time bin !");
+  }
 
   fTime = GetNextWord();
   fCount--;
@@ -267,8 +290,10 @@ void AliAltroRawStream::ReadBunch()
 void AliAltroRawStream::ReadAmplitude()
 {
   // Read next time bin amplitude
-  if (fPosition <= 0)
+  if (fPosition <= 0) {
+    PrintDebug();
     AliFatal("Could not read sample amplitude !");
+  }
 
   fSignal = GetNextWord();
   fCount--;
@@ -298,14 +323,18 @@ Int_t AliAltroRawStream::GetPosition()
 
     // Now read the beginning of the trailer
     // where the payload size is written
-    if (trailerSize < 2)
+    if (trailerSize < 2) {
+      PrintDebug();
       AliFatal(Form("Invalid trailer size found (%d bytes) !",trailerSize*4));
+    }
     fRCUTrailerSize = (trailerSize-2)*4;
     index -= fRCUTrailerSize;
-    if (index < 4)
+    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()));
+    }
     fRCUTrailerData = fData + index;
     Int_t position = Get32bitWord(index);
     // The size is specified in a number of 40bits
@@ -313,11 +342,13 @@ Int_t AliAltroRawStream::GetPosition()
     position *= 5;
 
     // Check the consistency of the header and trailer
-    if ((fRawReader->GetDataSize() - trailerSize*4) != position)
+    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 !",
                    fRawReader->GetDataSize(),
                    trailerSize*4,
                    position));
+    }
 
     return position * 8 / 10;
   }
@@ -336,12 +367,32 @@ Int_t AliAltroRawStream::GetPosition()
     // Therefore we need to transform it to number of bytes
     position *= 5;
 
-    // Check the consistency of the header and trailer
-    if ((fRawReader->GetDataSize() - 4) != position)
-      AliFatal(Form("Inconsistent raw data size ! Expected %d bytes (from the header), found %d bytes (in the RCU trailer)!",
-                   fRawReader->GetDataSize()-4,
-                   position));
+    if (!fIsShortDataHeader) {
 
+      // Check the consistency of the header and trailer
+      if ((fRawReader->GetDataSize() - 4) != position) {
+       PrintDebug();
+       AliFatal(Form("Inconsistent raw data size ! Expected %d bytes (from the header), found %d bytes (in the RCU trailer)!",
+                     fRawReader->GetDataSize()-4,
+                     position));
+      }
+    }
+    else {
+      // Check the consistency of the header and trailer
+      // In this case the header is shorter by 4 bytes
+      if (fRawReader->GetDataSize() != position) {
+       PrintDebug();
+       AliFatal(Form("Inconsistent raw data size ! Expected %d bytes (from the header), found %d bytes (in the RCU trailer)!",
+                     fRawReader->GetDataSize(),
+                     position));
+      }
+
+      // 7 32-bit words Common Data Header
+      // therefore we have to shift back by 4 bytes
+      // the pointer to the raw data payload
+      fData -= 4;
+    }
+     
     // Return the position in units of 10-bit words
     return position*8/10;
   }
@@ -355,10 +406,15 @@ UInt_t AliAltroRawStream::Get32bitWord(Int_t &index)
   // The 'index' points to the beginning of the next word.
   // The method is supposed to be endian (platform)
   // independent.
-  if (!fData)
+  if (!fData) {
+    PrintDebug();
     AliFatal("Raw data paylod buffer is not yet initialized !");
-  if (index < 4)
+  }
+
+  if (index < 4) {
+    PrintDebug();
     AliFatal(Form("Invalid raw data payload index (%d) !",index));
+  }
 
   UInt_t word = 0;
   word  = fData[--index] << 24;
@@ -386,3 +442,66 @@ Bool_t AliAltroRawStream::GetRCUTrailerData(UChar_t*& data) const
 
   return kTRUE;
 }
+
+//_____________________________________________________________________________
+void AliAltroRawStream::PrintDebug() const
+{
+  // The method prints all the available
+  // debug information.
+  // Its is used in case of decoding errors.
+
+  AliError("Start of debug printout\n--------------------");
+
+  Dump();
+  if (fRawReader) fRawReader->Dump();
+
+  AliError("End of debug printout\n--------------------");
+}
+
+//_____________________________________________________________________________
+Int_t AliAltroRawStream::GetBranch() const
+{
+  // The method provides the RCU branch index (0 or 1)
+  // for the current hardware address.
+  // In case the hardware address has not been yet
+  // initialized, the method returns -1
+  if (fHWAddress == -1) return -1;
+
+  return ((fHWAddress >> 11) & 0x1);
+}
+
+//_____________________________________________________________________________
+Int_t AliAltroRawStream::GetFEC() const
+{
+  // The method provides the front-end card index
+  // for the current hardware address.
+  // In case the hardware address has not been yet
+  // initialized, the method returns -1
+  if (fHWAddress == -1) return -1;
+
+  return ((fHWAddress >> 7) & 0xF);
+}
+
+//_____________________________________________________________________________
+Int_t AliAltroRawStream::GetAltro() const
+{
+  // The method provides the altro chip index
+  // for the current hardware address.
+  // In case the hardware address has not been yet
+  // initialized, the method returns -1
+  if (fHWAddress == -1) return -1;
+
+  return ((fHWAddress >> 4) & 0x7);
+}
+
+//_____________________________________________________________________________
+Int_t AliAltroRawStream::GetChannel() const
+{
+  // The method provides the channel index
+  // for the current hardware address.
+  // In case the hardware address has not been yet
+  // initialized, the method returns -1
+  if (fHWAddress == -1) return -1;
+
+  return (fHWAddress & 0xF);
+}