]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONRawStreamTrackerHP.cxx
Renamed output file to Vertex.Performance.root
[u/mrichter/AliRoot.git] / MUON / AliMUONRawStreamTrackerHP.cxx
index bf9049548456912bbadcdcc032998a34b3bd3f3f..aa82a6ee5768d75ed94eb3fae0a5134dba4d1f92 100644 (file)
@@ -44,6 +44,7 @@
 //-----------------------------------------------------------------------------
 
 #include "AliMUONRawStreamTrackerHP.h"
+#include "AliMUONTrackerDDLDecoder.h"
 #include "AliMUONDspHeader.h"
 #include "AliMUONBlockHeader.h"
 #include "AliMUONBusStruct.h"
@@ -52,7 +53,6 @@
 #include "AliLog.h"
 #include <cassert>
 #include <iostream>
-#include <iomanip>
 using std::cout;
 using std::endl;
 using std::hex;
@@ -62,19 +62,25 @@ using std::dec;
 ClassImp(AliMUONRawStreamTrackerHP)
 /// \endcond
 
+const Int_t AliMUONRawStreamTrackerHP::fgkMaxDDL = 20;
 
 AliMUONRawStreamTrackerHP::AliMUONRawStreamTrackerHP() :
-       AliMUONVRawStreamTracker(),
+       TObject(),
+       fEnableErrorLogger(kFALSE),
        fDecoder(),
        fDDL(0),
        fBufferSize(8192),
        fBuffer(new UChar_t[8192]),
-       fCurrentBusPatch(NULL),
-       fCurrentData(NULL),
-       fEndOfData(NULL),
+       fkCurrentBusPatch(NULL),
+       fkCurrentData(NULL),
+       fkEndOfData(NULL),
        fHadError(kFALSE),
        fDone(kFALSE),
-       fDDLObject(NULL)
+       fDDLObject(NULL),
+       fTotalNumberOfGlitchErrors(0),
+       fTotalNumberOfParityErrors(0),
+       fTotalNumberOfPaddingErrors(0),
+       fTotalNumberOfTokenLostErrors(0)
 {
        ///
        /// Default constructor.
@@ -90,23 +96,26 @@ AliMUONRawStreamTrackerHP::AliMUONRawStreamTrackerHP() :
                        fDecoder.MaxDSPs(),
                        fDecoder.MaxBusPatches()
                );
-
-       fDecoder.GetHandler().SetRawStream(this);
 }
 
 
 AliMUONRawStreamTrackerHP::AliMUONRawStreamTrackerHP(AliRawReader* rawReader) :
-       AliMUONVRawStreamTracker(rawReader),
+       TObject(),
+       fEnableErrorLogger(kFALSE),
        fDecoder(),
        fDDL(0),
        fBufferSize(8192),
        fBuffer(new UChar_t[8192]),
-       fCurrentBusPatch(NULL),
-       fCurrentData(NULL),
-       fEndOfData(NULL),
+       fkCurrentBusPatch(NULL),
+       fkCurrentData(NULL),
+       fkEndOfData(NULL),
        fHadError(kFALSE),
        fDone(kFALSE),
-       fDDLObject(NULL)
+       fDDLObject(NULL),
+       fTotalNumberOfGlitchErrors(0),
+       fTotalNumberOfParityErrors(0),
+       fTotalNumberOfPaddingErrors(0),
+       fTotalNumberOfTokenLostErrors(0)
 {
        ///
        /// Constructor with AliRawReader as argument.
@@ -123,7 +132,7 @@ AliMUONRawStreamTrackerHP::AliMUONRawStreamTrackerHP(AliRawReader* rawReader) :
                        fDecoder.MaxBusPatches()
                );
        
-       fDecoder.GetHandler().SetRawStream(this);
+       fDecoder.GetHandler().SetReader(rawReader);
 }
 
 
@@ -154,6 +163,10 @@ void AliMUONRawStreamTrackerHP::First()
        fDDL = 0;
        fDone = kFALSE;
        NextDDL();
+       fTotalNumberOfGlitchErrors = 0;
+       fTotalNumberOfPaddingErrors = 0;
+       fTotalNumberOfParityErrors = 0;
+       fTotalNumberOfTokenLostErrors = 0;
 }
 
 
@@ -174,9 +187,9 @@ Bool_t AliMUONRawStreamTrackerHP::NextDDL()
        }
        
        // Better to reset these pointers.
-       fCurrentBusPatch = NULL;
-       fCurrentData = NULL;
-       fEndOfData = NULL;
+       fkCurrentBusPatch = NULL;
+       fkCurrentData = NULL;
+       fkEndOfData = NULL;
        
        while (fDDL < GetMaxDDL())
        {
@@ -241,6 +254,10 @@ Bool_t AliMUONRawStreamTrackerHP::NextDDL()
                // handler we need to trap any memory allocation exception to be robust.
                result = fDecoder.Decode(fBuffer, dataSize);
                fHadError = (result == true ? kFALSE : kTRUE);
+               fTotalNumberOfGlitchErrors += fDecoder.GetHandler().GlitchErrorCount();
+               fTotalNumberOfParityErrors += fDecoder.GetHandler().ParityErrorCount();
+               fTotalNumberOfPaddingErrors += fDecoder.GetHandler().PaddingErrorCount();
+               fTotalNumberOfTokenLostErrors += fDecoder.GetHandler().TokenLostCount();
        }
        catch (const std::bad_alloc&)
        {
@@ -249,18 +266,18 @@ Bool_t AliMUONRawStreamTrackerHP::NextDDL()
        }
 
        // Update the current bus patch pointers.
-       fCurrentBusPatch = fDecoder.GetHandler().FirstBusPatch();
-       if (fCurrentBusPatch != fDecoder.GetHandler().EndOfBusPatch())
+       fkCurrentBusPatch = fDecoder.GetHandler().FirstBusPatch();
+       if (fkCurrentBusPatch != fDecoder.GetHandler().EndOfBusPatch())
        {
-               fCurrentData = fCurrentBusPatch->GetData();
-               fEndOfData = fCurrentData + fCurrentBusPatch->GetDataCount();
+               fkCurrentData = fkCurrentBusPatch->GetData();
+               fkEndOfData = fkCurrentData + fkCurrentBusPatch->GetDataCount();
        }
        else
        {
                // If the DDL did not have any bus patches then mark both fCurrentData
                // and fEndOfData as NULL so that in Next() we are forced to find the
                // first non empty DDL.
-               fCurrentData = fEndOfData = NULL;
+               fkCurrentData = fkEndOfData = NULL;
        }
 
        fDDL++; // Remember to increment index to next DDL.
@@ -277,28 +294,31 @@ Bool_t AliMUONRawStreamTrackerHP::IsDone() const
 }
 
 
-Bool_t AliMUONRawStreamTrackerHP::Next(
-               Int_t& busPatchId, UShort_t& manuId, UChar_t& manuChannel,
-               UShort_t& adc
-       )
+Bool_t AliMUONRawStreamTrackerHP::Next(Int_t& busPatchId, 
+                                       UShort_t& manuId, 
+                                       UChar_t& manuChannel,
+                                       UShort_t& adc, 
+                                       Bool_t skipParityErrors)
 {
        /// Advance one step in the iteration. Returns false if finished.
        /// [out] \param busPatchId  This is filled with the bus patch ID of the digit.
        /// [out] \param manuId      This is filled with the MANU ID of the digit.
        /// [out] \param manuChannel This is filled with the MANU channel ID of the digit.
        /// [out] \param adc         This is filled with the ADC signal value of the digit.
+       /// [in] \param skipParityErrors If this is kTRUE, we'll skip the buspatches that
+       ///                              have some parity errors
        /// \return kTRUE if we read another digit and kFALSE if we have read all the
        ///    digits already, i.e. at the end of the iteration.
        
-       if (fCurrentData == NULL) return kFALSE;
+       if (fkCurrentData == NULL) return kFALSE;
        
 retry:
        // Check if we still have data to be returned for the current bus patch.
-       if (fCurrentData != fEndOfData)
+       if (fkCurrentData != fkEndOfData)
        {
-               busPatchId = fCurrentBusPatch->GetBusPatchId();
-               AliMUONTrackerDDLDecoderEventHandler::UnpackADC(*fCurrentData, manuId, manuChannel, adc);
-               fCurrentData++;
+               busPatchId = fkCurrentBusPatch->GetBusPatchId();
+               AliMUONTrackerDDLDecoderEventHandler::UnpackADC(*fkCurrentData, manuId, manuChannel, adc);
+               fkCurrentData++;
                return kTRUE;
        }
        else
@@ -307,13 +327,22 @@ retry:
                // bus patches to process for the current DDL. If we do, then increment
                // the current bus patch, make sure it is not the last one and then try
                // reading the first element again.
-               if (fCurrentBusPatch != fDecoder.GetHandler().EndOfBusPatch())
+               if (fkCurrentBusPatch != fDecoder.GetHandler().EndOfBusPatch())
                {
-                       fCurrentBusPatch++;
-                       if (fCurrentBusPatch != fDecoder.GetHandler().EndOfBusPatch())
+                       fkCurrentBusPatch++;
+                       if (fkCurrentBusPatch != fDecoder.GetHandler().EndOfBusPatch())
                        {
-                               fCurrentData = fCurrentBusPatch->GetData();
-                               fEndOfData = fCurrentData + fCurrentBusPatch->GetDataCount();
+                               fkCurrentData = fkCurrentBusPatch->GetData();
+                               fkEndOfData = fkCurrentData + fkCurrentBusPatch->GetDataCount();
+                               if ( skipParityErrors )
+                               {
+                                       Bool_t ok(kTRUE);
+                                       for ( Int_t i = 0; i < fkCurrentBusPatch->GetLength() && ok; ++ i )
+                                       {
+                                               ok = fkCurrentBusPatch->IsParityOk(i);
+                                       }
+                                       if (!ok) fkCurrentData = fkEndOfData;
+                               }
                                goto retry;
                        }
                }
@@ -421,6 +450,16 @@ void AliMUONRawStreamTrackerHP::SetMaxBus(Int_t bus)
                );
 }
 
+AliRawReader* AliMUONRawStreamTrackerHP::GetReader()
+{
+  return fDecoder.GetHandler().GetReader();
+}
+
+void AliMUONRawStreamTrackerHP::SetReader(AliRawReader* reader)
+{
+  fDecoder.GetHandler().SetReader(reader);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 void AliMUONRawStreamTrackerHP::AliBlockHeader::Print() const
@@ -491,7 +530,7 @@ void AliMUONRawStreamTrackerHP::AliBusPatch::Print(const Option_t* opt) const
 ///////////////////////////////////////////////////////////////////////////////
 
 AliMUONRawStreamTrackerHP::AliDecoderEventHandler::AliDecoderEventHandler() :
-       fRawStream(NULL),
+       fRawReader(0x0),
        fBufferStart(NULL),
        fBlockCount(0),
        fBlocks(NULL),
@@ -507,7 +546,11 @@ AliMUONRawStreamTrackerHP::AliDecoderEventHandler::AliDecoderEventHandler() :
        fParityErrors(0),
        fGlitchErrors(0),
        fPaddingErrors(0),
-       fWarnings(kTRUE)
+       fTokenLostErrors(0),
+       fWarnings(kTRUE),
+       fMaxBlocks(),
+       fMaxDsps(),
+       fMaxBusPatches()
 {
        /// Default constructor initialises the internal parity flags buffer to
        /// store 8192 elements. This array will grow dynamically if needed.
@@ -556,6 +599,10 @@ void AliMUONRawStreamTrackerHP::AliDecoderEventHandler::SetMaxStructs(
        fDSPs = new AliDspHeader[maxBlocks*maxDsps];
        fBusPatches = new AliBusPatch[maxBlocks*maxDsps*maxBusPatches];
        fEndOfBusPatches = fBusPatches;
+
+       fMaxBlocks = maxBlocks;
+       fMaxDsps = maxDsps;
+       fMaxBusPatches = maxBusPatches;
 }
 
 
@@ -568,8 +615,6 @@ void AliMUONRawStreamTrackerHP::AliDecoderEventHandler::OnNewBuffer(
        /// \param buffer  The pointer to the buffer storing the DDL payload.
        /// \param bufferSize  The size of the buffer in bytes.
 
-       assert( fRawStream != NULL );
-       
        // remember the start of the buffer to be used in OnError.
        fBufferStart = buffer;
 
@@ -577,6 +622,7 @@ void AliMUONRawStreamTrackerHP::AliDecoderEventHandler::OnNewBuffer(
        fParityErrors = 0;
        fGlitchErrors = 0;
        fPaddingErrors = 0;
+       fTokenLostErrors = 0;
 
        // Check if we will have enough space in the fParityOk array.
        // If we do not then we need to resize the array.
@@ -619,8 +665,7 @@ void AliMUONRawStreamTrackerHP::AliDecoderEventHandler::OnError(
        /// \param location  A pointer to the location within the DDL payload buffer
        ///              being decoded where the problem with the data was found.
 
-       assert( fRawStream != NULL );
-       assert( fRawStream->GetReader() != NULL );
+       assert( fRawReader != NULL );
        
        Char_t* message = NULL;
        UInt_t word = 0;
@@ -630,10 +675,10 @@ void AliMUONRawStreamTrackerHP::AliDecoderEventHandler::OnError(
        case kGlitchFound:
                fGlitchErrors++;
                message = Form(
-                       "Glitch error detected in DSP %d, skipping event ",
-                       fCurrentBlock->GetDspId()
+                       "Glitch error detected in DSP %d (0x%X), skipping event ",
+                       fCurrentBlock->GetDspId(), fCurrentBlock->GetDspId()
                );
-               fRawStream->GetReader()->AddMajorErrorLog(error, message);
+               fRawReader->AddMajorErrorLog(error, message);
                break;
 
        case kBadPaddingWord:
@@ -646,7 +691,7 @@ void AliMUONRawStreamTrackerHP::AliDecoderEventHandler::OnError(
                        fCurrentBlock->GetDspCount()-1,
                        fCurrentDSP->GetBusPatchCount()-1
                );
-               fRawStream->GetReader()->AddMinorErrorLog(error, message);
+               fRawReader->AddMinorErrorLog(error, message);
                break;
 
        case kParityError:
@@ -664,7 +709,19 @@ void AliMUONRawStreamTrackerHP::AliDecoderEventHandler::OnError(
                        fCurrentBusPatch->GetChannelId(word),
                        fCurrentBusPatch->GetBusPatchId()
                );
-               fRawStream->GetReader()->AddMinorErrorLog(error, message);
+               fRawReader->AddMinorErrorLog(error, message);
+               break;
+               
+       case kTokenLost:
+               fTokenLostErrors++;
+               word = *reinterpret_cast<const UInt_t*>(location);
+               message = Form(
+                       "Lost token error detected in DSP %d (0x%X) with address 0x%X and code %d.",
+                       fCurrentBlock->GetDspId(), fCurrentBlock->GetDspId(),
+                       ((word & 0xFFFF0000) >> 16),
+                       (word & 0xF)
+               );
+               fRawReader->AddMinorErrorLog(error, message);
                break;
 
        default:
@@ -673,7 +730,7 @@ void AliMUONRawStreamTrackerHP::AliDecoderEventHandler::OnError(
                        ErrorCodeToMessage(error),
                        (unsigned long)location - (unsigned long)fBufferStart + sizeof(AliRawDataHeader)
                );
-               fRawStream->GetReader()->AddMajorErrorLog(error, message);
+               fRawReader->AddMajorErrorLog(error, message);
                break;
        }