]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONRawStreamTrackerHP.cxx
Adding the cascade performance task (Antonin Maire)
[u/mrichter/AliRoot.git] / MUON / AliMUONRawStreamTrackerHP.cxx
index 48937336a69d242e0a799dd4d76df3ef75fe7599..2ac1a28182bcb47abfb6bb35c81e2541c4bf4347 100644 (file)
 //-----------------------------------------------------------------------------
 
 #include "AliMUONRawStreamTrackerHP.h"
+#include "AliMUONTrackerDDLDecoder.h"
+#include "AliMUONDspHeader.h"
+#include "AliMUONBlockHeader.h"
+#include "AliMUONBusStruct.h"
+#include "AliMUONDDLTracker.h"
 #include "AliRawReader.h"
 #include "AliLog.h"
 #include <cassert>
 #include <iostream>
-#include <iomanip>
 using std::cout;
 using std::endl;
 using std::hex;
@@ -65,11 +69,12 @@ AliMUONRawStreamTrackerHP::AliMUONRawStreamTrackerHP() :
        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)
+       fDone(kFALSE),
+       fDDLObject(NULL)
 {
        ///
        /// Default constructor.
@@ -96,11 +101,12 @@ AliMUONRawStreamTrackerHP::AliMUONRawStreamTrackerHP(AliRawReader* rawReader) :
        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)
+       fDone(kFALSE),
+       fDDLObject(NULL)
 {
        ///
        /// Constructor with AliRawReader as argument.
@@ -131,6 +137,10 @@ AliMUONRawStreamTrackerHP::~AliMUONRawStreamTrackerHP()
        {
                delete [] fBuffer;
        }
+       if (fDDLObject != NULL)
+       {
+               delete fDDLObject;
+       }
 }
 
 
@@ -155,10 +165,18 @@ Bool_t AliMUONRawStreamTrackerHP::NextDDL()
 
        assert( GetReader() != NULL );
        
+       // The temporary object if generated in GetDDLTracker, is now stale,
+       // so delete it.
+       if (fDDLObject != NULL)
+       {
+               delete fDDLObject;
+               fDDLObject = NULL;
+       }
+       
        // Better to reset these pointers.
-       fCurrentBusPatch = NULL;
-       fCurrentData = NULL;
-       fEndOfData = NULL;
+       fkCurrentBusPatch = NULL;
+       fkCurrentData = NULL;
+       fkEndOfData = NULL;
        
        while (fDDL < GetMaxDDL())
        {
@@ -231,18 +249,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.
@@ -272,15 +290,15 @@ Bool_t AliMUONRawStreamTrackerHP::Next(
        /// \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
@@ -289,13 +307,13 @@ 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();
                                goto retry;
                        }
                }
@@ -309,6 +327,62 @@ retry:
 }
 
 
+AliMUONDDLTracker* AliMUONRawStreamTrackerHP::GetDDLTracker() const
+{
+       /// Construct and return a pointer to the DDL payload object.
+       /// \return Pointer to internally constructed AliMUONDDLTracker object.
+       ///         The object is owned by this class and should not be deleted
+       ///         by the caller.
+       ///
+       /// \note This method should not be used just to gain access to the DDL
+       /// payload, unless there is a good reason to have the AliMUONDDLTracker
+       /// object. For example, if you want to modify the data and then save it
+       /// to another DDL stream. Otherwise it can be an order of magnitude
+       /// faster to access the DDL headers and data with the GetBlockHeader,
+       /// GetDspHeader and GetBusPatch methods for example.
+       /// Refer to the MUONRawStreamTracker.C macro to see how to use the fast
+       /// decoder interface optimally.
+       
+       if (fDDLObject != NULL) return fDDLObject;
+       
+       fDDLObject = new AliMUONDDLTracker;
+       for (Int_t iBlock = 0; iBlock < (Int_t)GetBlockCount(); iBlock++)
+       {
+               AliMUONBlockHeader blockHeader;
+               AliMUONDspHeader dspHeader;
+               AliMUONBusStruct busPatch;
+               
+               const AliBlockHeader* bh = GetBlockHeader(iBlock);
+               // Copy block header and add it to the DDL object.
+               memcpy(blockHeader.GetHeader(), bh->GetHeader(), sizeof(AliMUONBlockHeaderStruct));
+               fDDLObject->AddBlkHeader(blockHeader);
+               
+               for (Int_t iDsp = 0; iDsp < (Int_t)bh->GetDspCount(); iDsp++)
+               {
+                       const AliDspHeader* dh = bh->GetDspHeader(iDsp);
+                       // Copy DSP header and add it to the DDL object.
+                       memcpy(dspHeader.GetHeader(), dh->GetHeader(), sizeof(AliMUONDSPHeaderStruct));
+                       fDDLObject->AddDspHeader(dspHeader, iBlock);
+                       
+                       const AliBusPatch* bp = dh->GetFirstBusPatch();
+                       while (bp != NULL)
+                       {
+                               // Copy bus patch header, data and add everything into DDL object.
+                               memcpy(busPatch.GetHeader(), bp->GetHeader(), sizeof(AliMUONBusPatchHeaderStruct));
+                               busPatch.SetAlloc(bp->GetLength());
+                               memcpy(busPatch.GetData(), bp->GetData(), bp->GetDataCount()*sizeof(UInt_t));
+                               busPatch.SetBlockId(iBlock);
+                               busPatch.SetDspId(iDsp);
+                               fDDLObject->AddBusPatch(busPatch, iBlock, iDsp);
+                               bp = bp->Next();
+                       }
+               }
+       }
+       
+       return fDDLObject;
+}
+
+
 void AliMUONRawStreamTrackerHP::SetMaxBlock(Int_t blk)
 {
        /// Set maximum number of blocks per DDL allowed.