]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Made changes to use common online/offline fast decoder.
authoraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 14 May 2008 15:10:32 +0000 (15:10 +0000)
committeraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 14 May 2008 15:10:32 +0000 (15:10 +0000)
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructor.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructor.h
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructorComponent.cxx

index 330f3b15dce2bd34ec7f1e21655b859b0937c030..c53955ab1a988c2490ecf23c1d43b3c4e1005c08 100644 (file)
   Completely reimplemented the lookup table to a simplified format.
 **********************************************************************/
 
-///*
-//
-//  The trigger reconstructor class is designed to deal the rawdata inputfiles
-//  to findout the the reconstructed hits at the trigger DDL. The output is send
-//  to the output block for further processing.
-//
-//  Author : Indranil Das ( indra.das@saha.ac.in || indra.ehep@gmail.com )
-// 
-//*/
+///
+///  @file   AliHLTMUONTriggerReconstructor.cxx
+///  @author Indranil Das <indra.das@saha.ac.in>,
+///          Artur Szostak <artursz@iafrica.com>
+///  @date   16 May 2007
+///  @brief  Implementation of the AliHLTMUONTriggerReconstructor class.
+///
+///  The trigger reconstructor class is designed to deal the rawdata inputfiles
+///  to findout the the reconstructed hits at the trigger DDL. The output is send
+///  to the output block for further processing.
+///
 
 #include "AliHLTMUONTriggerReconstructor.h"
 #include "AliHLTMUONTriggerRecordsBlockStruct.h"
 #include "AliHLTMUONUtils.h"
 #include "AliHLTMUONConstants.h"
 #include "AliHLTMUONCalculations.h"
+#include "AliRawDataHeader.h"
 #include <vector>
 #include <cassert>
 
 
 AliHLTMUONTriggerReconstructor::AliHLTMUONTriggerReconstructor() :
-       fMaxRecPointsCount(0),
+       AliHLTLogging(),
+       fDecoder()
+{
+       /// Default constructor.
+}
+
+
+AliHLTMUONTriggerReconstructor::~AliHLTMUONTriggerReconstructor()
+{
+       /// Default destructor.
+}
+
+
+bool AliHLTMUONTriggerReconstructor::Run(
+               const AliHLTUInt8_t* rawData,
+               AliHLTUInt32_t rawDataSize,
+               AliHLTMUONTriggerRecordStruct* trigRecord,
+               AliHLTUInt32_t& nofTrigRec,
+               bool suppressPartialTrigs
+       )
+{
+       /// Runs the trigger reconstruction algorithm on the raw data.
+       
+       // Reset and initialise some variables in the decoder.
+       fDecoder.GetHandler().MaxOutputTrigRecs(nofTrigRec);
+       fDecoder.GetHandler().OutputTrigRecs(trigRecord);
+       fDecoder.GetHandler().SuppressPartialTriggers(suppressPartialTrigs);
+       
+       fDecoder.Decode(rawData, rawDataSize);
+       
+       // nofTrigRec now becomes the output of how many trigger records were found.
+       nofTrigRec = fDecoder.GetHandler().OutputTrigRecsCount();
+       
+       return not fDecoder.GetHandler().OverflowedOutputBuffer();
+}
+
+
+AliHLTMUONTriggerReconstructor::AliDecoderHandler::AliDecoderHandler() :
+       AliMUONTriggerDDLDecoderEventHandler(),
+       AliHLTLogging(),
+       fLookupTable(),
+       fBufferStart(NULL),
+       fMaxOutputTrigRecs(0),
+       fOutputTrigRecsCount(0),
+       fOutputTrigRecs(NULL),
        fTrigRecId(0),
-       fLookupTable()
+       fCurrentRegional(0),
+       fCurrentLocal(0),
+       fSuppressPartialTriggers(false),
+       fOverflowed(false)
 {
-       // ctor
+       /// Default constructor just resets the lookup table to zero.
        
        for (Int_t i = 0; i < 8; i++)
        for (Int_t j = 0; j < 16; j++)
@@ -67,217 +117,179 @@ AliHLTMUONTriggerReconstructor::AliHLTMUONTriggerReconstructor() :
 }
 
 
-AliHLTMUONTriggerReconstructor::~AliHLTMUONTriggerReconstructor()
+void AliHLTMUONTriggerReconstructor::AliDecoderHandler::OnNewBuffer(
+               const void* buffer, UInt_t /*bufferSize*/
+       )
 {
-       // dtor
+       /// Called for each new buffer. Sets the buffer and resets the structure
+       /// counters.
+       
+       assert( buffer != NULL );
+       fBufferStart = buffer;
+       
+       // Start from -1 since we increment immediately in OnNewRegionalStruct.
+       fCurrentRegional = fCurrentLocal = -1;
 }
 
 
-bool AliHLTMUONTriggerReconstructor::Run(
-               const AliHLTUInt32_t* rawData,
-               // TODO: if we are not checking rawDataSize then it means we are
-               // not parsing the raw data safely or checking for corruption carefully.
-               // This must be fixed at some point.
-               AliHLTUInt32_t /*rawDataSize*/,
-               AliHLTMUONTriggerRecordStruct* trigRecord,
-               AliHLTUInt32_t& nofTrigRec,
-               bool suppressPartialTrigs
+void AliHLTMUONTriggerReconstructor::AliDecoderHandler::OnLocalStruct(
+               const AliMUONLocalInfoStruct* localStruct,
+               const AliMUONLocalScalarsStruct* /*scalars*/
        )
 {
-       fMaxRecPointsCount = nofTrigRec;
-       
-       // nofTrigRec now becomes the output of how many trigger records were found.
-       nofTrigRec = 0;
-       
-       int index = 0;
-       int reg_output, reg_phys_trig_occur;
-       int iLocIndex,loc,locDec,triggY,sign,loDev,triggX;
-       short pattern[2][4]; // 2 stands for two cathode planes and 4 stands for 4 chambers
-       
-       int phys_trig_occur = (rawData[index]>>30)&0x1; // 1 for physics trigger, 0 for software trigger
-       
-       if (not phys_trig_occur) // for software trigger
-               index += 8 ;// corresponding to scalar words
-       
-       index += 1 ; // To skip the separator 0xDEADFACE
+       /// Converts a local trigger structure from the L0 into a trigger record.
+       /// The dHLT trigger records is then used as a seed for tracking algorithms.
+       /// \note fOutputTrigRecs must be set before calling the decoder to decode
+       ///    a new raw data buffer.
+       /// \param localStruct  This is a pointer to the local L0 trigger structure data.
+
+       assert(localStruct != NULL);
+       assert(fOutputTrigRecs != NULL);
+
+       fCurrentLocal++;
+       AliHLTInt32_t iReg = fCurrentRegional;
+       AliHLTInt32_t iLoc = fCurrentLocal;
+       assert(iReg >= 0);
+       assert(iLoc >= 0);
+
+       // Check if there is anything in the trigger patterns at all.
+       // If nothing then ignore this local L0 trigger.
+       if (localStruct->fX2X1 == 0 and localStruct->fX4X3 == 0 and
+           localStruct->fY2Y1 == 0 and localStruct->fY4Y3 == 0
+          )
+       {
+               return;
+       }
        
-       index += 4 ; // corresponding to global input
+       // Check that we will not overflow the output buffer.
+       if (fOutputTrigRecsCount >= fMaxOutputTrigRecs)
+       {
+               HLTError("Output buffer has overflowed maximum element count of %d.",
+                       fMaxOutputTrigRecs
+               );
+               fOverflowed = true;
+               return;
+       }
        
-       index += 1 ; // reaches to global output
+       UShort_t pattern[2][4]; // 2 stands for two cathode planes and the 4 stands for 4 chambers.
+       pattern[0][0] = GetLocalX1(localStruct); // x-strip pattern for chamber 0
+       pattern[0][1] = GetLocalX2(localStruct); // x-strip pattern for chamber 1
+       pattern[0][2] = GetLocalX3(localStruct); // x-strip pattern for chamber 2
+       pattern[0][3] = GetLocalX4(localStruct); // x-strip pattern for chamber 3
+       pattern[1][0] = GetLocalY1(localStruct); // y-strip pattern for chamber 0
+       pattern[1][1] = GetLocalY2(localStruct); // y-strip pattern for chamber 1
+       pattern[1][2] = GetLocalY3(localStruct); // y-strip pattern for chamber 2
+       pattern[1][3] = GetLocalY4(localStruct); // y-strip pattern for chamber 3
+
+       bool setX[4] = {false, false, false, false};
+       bool setY[4] = {false, false, false, false};
+
+       for (int iChamber = 0; iChamber < 4; iChamber++) //4 chambers
+       for (int iPlane = 0; iPlane < 2; iPlane++) // 2 cathode planes
+       {
+               for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
+               {
+                       if (((pattern[iPlane][iChamber] >> ibitxy) & 0x1) != 0x1)
+                               continue;
+                       
+                       if (iPlane == 1)
+                       {
+                               fOutputTrigRecs[fOutputTrigRecsCount].fHit[iChamber].fX =
+                                       fLookupTable.fRow[iReg][iLoc][iChamber][iPlane][ibitxy].fX;
+                               setX[iChamber] = true;
+                       }
+                       else
+                       {
+                               fOutputTrigRecs[fOutputTrigRecsCount].fHit[iChamber].fY =
+                                       fLookupTable.fRow[iReg][iLoc][iChamber][iPlane][ibitxy].fY;
+                               fOutputTrigRecs[fOutputTrigRecsCount].fHit[iChamber].fZ =
+                                       fLookupTable.fRow[iReg][iLoc][iChamber][iPlane][ibitxy].fZ;
+                               setY[iChamber] = true;
+                       }
+               }
+       }
+
+       // hitset indicates which hits on chambers 7 to 10 have been found and filled.
+       bool hitset[4] = {false, false, false, false};
        
-       if (not phys_trig_occur) index += 10; // corresponds to scalar words
+       // Fill the hitset flags and make sure the hit structures that were not
+       // filled (set) get set to a nil value.
+       for (int i = 0; i < 4; i++)
+       {
+               hitset[i] = setX[i] and setY[i];
+               
+               if (not hitset[i])
+               {
+                       fOutputTrigRecs[fOutputTrigRecsCount].fHit[i]
+                               = AliHLTMUONConstants::NilRecHitStruct();
+               }
+       }
+
+       fOutputTrigRecs[fOutputTrigRecsCount].fId = fTrigRecId;
+
+       // Increment trigger record Id and keep it positive.
+       if (fTrigRecId < 0x7FFFFFFF)
+               fTrigRecId++;
+       else
+               fTrigRecId = 0;
        
-       index += 1; // separator 0xDEADBEEF 
+       AliHLTMUONRecHitStruct* hit1 = NULL;
+       if (hitset[0])
+               hit1 = &fOutputTrigRecs[fOutputTrigRecsCount].fHit[0];
+       else if (hitset[1])
+               hit1 = &fOutputTrigRecs[fOutputTrigRecsCount].fHit[1];
+       AliHLTMUONRecHitStruct* hit2 = NULL;
+       if (hitset[2])
+               hit2 = &fOutputTrigRecs[fOutputTrigRecsCount].fHit[2];
+       else if (hitset[3])
+               hit2 = &fOutputTrigRecs[fOutputTrigRecsCount].fHit[3];
        
-       for (int iReg = 0; iReg < 8; iReg++)
+       if (hit1 != NULL and hit2 != NULL)
        {
-               index += 1; // DARC Status Word
-               index += 1; // Regeional Word
-               reg_output = rawData[index] & 0xFF;
-               reg_phys_trig_occur = ( rawData[index] >> 31) & 0x1;
-               
-               index += 2; // 2 words for regional input
-               
-               index += 1; // L0 counter
-               
-               if (not reg_phys_trig_occur) index += 10;
+               // Calculate the momentum and fill in the flags and momentum fields.
+               AliHLTMUONCalculations::ComputeMomentum(
+                               hit1->fX,
+                               hit1->fY, hit2->fY,
+                               hit1->fZ, hit2->fZ
+                       );
+               fOutputTrigRecs[fOutputTrigRecsCount].fPx = AliHLTMUONCalculations::Px();
+               fOutputTrigRecs[fOutputTrigRecsCount].fPy = AliHLTMUONCalculations::Py();
+               fOutputTrigRecs[fOutputTrigRecsCount].fPz = AliHLTMUONCalculations::Pz();
+
+               fOutputTrigRecs[fOutputTrigRecsCount].fFlags =
+                       AliHLTMUONUtils::PackTriggerRecordFlags(
+                               AliHLTMUONCalculations::Sign(),
+                               hitset
+                       );
                
-               index += 1; // end of Regeonal header 0xBEEFFACE
+               fOutputTrigRecsCount++;
+       }
+       else if ((hit1 != NULL or hit2 != NULL) and not fSuppressPartialTriggers)
+       {
+               fOutputTrigRecs[fOutputTrigRecsCount].fPx = 0;
+               fOutputTrigRecs[fOutputTrigRecsCount].fPy = 0;
+               fOutputTrigRecs[fOutputTrigRecsCount].fPz = 0;
+
+               fOutputTrigRecs[fOutputTrigRecsCount].fFlags =
+                       AliHLTMUONUtils::PackTriggerRecordFlags(
+                               kSignUnknown,
+                               hitset
+                       );
                
-               for(int iLoc = 0; iLoc < 16 ; iLoc++)
-               {
-                       iLocIndex = index;
-                       
-                       loc = (rawData[index+5] >> 19) &  0xF ;
-                       
-                       locDec = (rawData[index+5] >> 15) & 0xF;
-                       triggY = (rawData[index+5] >> 14) & 0x1;
-                       sign = (rawData[index+5] >> 9) & 0x1;
-                       loDev = (rawData[index+5] >> 5) & 0xF ;
-                       triggX = (loDev >> 4 & 0x1 ) && !(loDev & 0xF);
-                       
-                       if( locDec != 0x9 )
-                       { // check for Dec
-                       
-                               index += 1;
-                               pattern[0][0] = rawData[index] & 0xFFFF; // x-strip pattern for chamber 0 
-                               pattern[0][1] = (rawData[index] >> 16) & 0xFFFF; // x-strip pattern for chamber 1
-                               index += 1; 
-                               pattern[0][2] = rawData[index] & 0xFFFF; 
-                               pattern[0][3] = (rawData[index] >> 16) & 0xFFFF; 
-                               
-                               index += 1;
-                               pattern[1][0] = rawData[index] & 0xFFFF; // y-strip pattern for chamber 0
-                               pattern[1][1] = (rawData[index] >> 16) & 0xFFFF; // y-strip pattern for chamber 0 
-                               index += 1; 
-                               pattern[1][2] = rawData[index] & 0xFFFF; 
-                               pattern[1][3] = (rawData[index] >> 16) & 0xFFFF; 
-                       
-                               if (pattern[0][0] || pattern[0][1] || pattern[0][2] || pattern[0][3]
-                                  || pattern[1][0] || pattern[1][1] || pattern[1][2] || pattern[1][3]
-                               )
-                               {
-                                       if (nofTrigRec == fMaxRecPointsCount)
-                                       {
-                                               HLTError("Output buffer is overflowed maximum assiged arraysize : %d, present array index : %d",
-                                                       fMaxRecPointsCount, nofTrigRec
-                                               );
-                                               return false;
-                                       }
-                               
-                                       bool Xset[4] = {false, false, false, false};
-                                       bool Yset[4] = {false, false, false, false};
-                               
-                                       for (int iChamber = 0; iChamber < 4 ; iChamber++) //4 chambers per DDL 
-                                       for (int iPlane = 0; iPlane < 2 ; iPlane++) // 2 cathode plane
-                                       {
-                                               for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
-                                               {
-                                                       if (((pattern[iPlane][iChamber] >> ibitxy) & 0x1) != 0x1)
-                                                               continue;
-                                                       
-                                                       if (iPlane == 1)
-                                                       {
-                                                               trigRecord[nofTrigRec].fHit[iChamber].fX =
-                                                                       fLookupTable.fRow[iReg][iLoc][iChamber][iPlane][ibitxy].fX;
-                                                               Xset[iChamber] = true;
-                                                       }
-                                                       else
-                                                       {
-                                                               trigRecord[nofTrigRec].fHit[iChamber].fY =
-                                                                       fLookupTable.fRow[iReg][iLoc][iChamber][iPlane][ibitxy].fY;
-                                                               trigRecord[nofTrigRec].fHit[iChamber].fZ =
-                                                                       fLookupTable.fRow[iReg][iLoc][iChamber][iPlane][ibitxy].fZ;
-                                                               Yset[iChamber] = true;
-                                                       }
-                                                       
-                                               }// loop of ibitxy
-                                       }// ichamber, iplane
-                               
-                                       // hitset indicates which hits on chambers 7 to 10 have been found and filled.
-                                       bool hitset[4] = {false, false, false, false};
-                                       
-                                       // Fill the hitset flags and make sure the hit structures that were not
-                                       // filled (set) get set to a nil value.
-                                       for (int i = 0; i < 4; i++)
-                                       {
-                                               hitset[i] = Xset[i] and Yset[i];
-                                               
-                                               if (not hitset[i])
-                                               {
-                                                       trigRecord[nofTrigRec].fHit[i]
-                                                               = AliHLTMUONConstants::NilRecHitStruct();
-                                               }
-                                       }
-                       
-                                       trigRecord[nofTrigRec].fId = fTrigRecId;
-                               
-                                       // Increment trigger record Id and keep it positive.
-                                       //TODO: handle the wrapparound better.
-                                       if (fTrigRecId < 0x7FFFFFFF)
-                                               fTrigRecId++;
-                                       else
-                                               fTrigRecId = 0;
-                                       
-                                       AliHLTMUONRecHitStruct* hit1 = NULL;
-                                       if (hitset[0])
-                                               hit1 = &trigRecord[nofTrigRec].fHit[0];
-                                       else if (hitset[1])
-                                               hit1 = &trigRecord[nofTrigRec].fHit[1];
-                                       AliHLTMUONRecHitStruct* hit2 = NULL;
-                                       if (hitset[2])
-                                               hit2 = &trigRecord[nofTrigRec].fHit[2];
-                                       else if (hitset[3])
-                                               hit2 = &trigRecord[nofTrigRec].fHit[3];
-                                       
-                                       if (hit1 != NULL and hit2 != NULL)
-                                       {
-                                               // Calculate the momentum and fill in the flags and momentum fields.
-                                               AliHLTMUONCalculations::ComputeMomentum(
-                                                               hit1->fX,
-                                                               hit1->fY, hit2->fY,
-                                                               hit1->fZ, hit2->fZ
-                                                       );
-                                               trigRecord[nofTrigRec].fPx = AliHLTMUONCalculations::Px();
-                                               trigRecord[nofTrigRec].fPy = AliHLTMUONCalculations::Py();
-                                               trigRecord[nofTrigRec].fPz = AliHLTMUONCalculations::Pz();
-                       
-                                               trigRecord[nofTrigRec].fFlags =
-                                                       AliHLTMUONUtils::PackTriggerRecordFlags(
-                                                               AliHLTMUONCalculations::Sign(),
-                                                               hitset
-                                                       );
-                                               
-                                               nofTrigRec++;
-                                       }
-                                       else if ((hit1 != NULL or hit2 != NULL) and not suppressPartialTrigs)
-                                       {
-                                               trigRecord[nofTrigRec].fPx = 0;
-                                               trigRecord[nofTrigRec].fPy = 0;
-                                               trigRecord[nofTrigRec].fPz = 0;
-                       
-                                               trigRecord[nofTrigRec].fFlags =
-                                                       AliHLTMUONUtils::PackTriggerRecordFlags(
-                                                               kSignUnknown,
-                                                               hitset
-                                                       );
-                                               
-                                               nofTrigRec++;
-                                       }
-                               
-                               }// if any non zero pattern found
-                       
-                               index += 1 ; // the last word, important one
-                       }// Dec Condn
-                       
-                       if (not reg_phys_trig_occur)
-                               index += 45;
-                               
-                       index += 1; // end of local Data 0xCAFEFADE
-                       
-                       index = iLocIndex + 6; //important to reset the index counter for fake locids like 235 
-               }// iLoc loop
-       }// iReg Loop
+               fOutputTrigRecsCount++;
+       }
+}
+
+
+void AliHLTMUONTriggerReconstructor::AliDecoderHandler::OnError(
+               ErrorCode code, const void* location
+       )
+{
+       /// Logs an error message if there was a decoding problem with the DDL payload.
        
-       return true;
+       long bytepos = long(location) - long(fBufferStart) + sizeof(AliRawDataHeader);
+       HLTError("There is a problem with decoding the raw data. %s (Error code: %d, at byte %d)",
+               ErrorCodeToMessage(code), code, bytepos
+       );
 }
+
index 798907ed1143c7174e4c04009839bb4b9c090e1c..6e716e049e7f084baedcf593ab670bfb347e07d4 100644 (file)
   Completely reimplemented the lookup table to a simplified format.
 **********************************************************************/
 
+///
+///  @file   AliHLTMUONTriggerReconstructor.h
+///  @author Indranil Das <indra.das@saha.ac.in>,
+///          Artur Szostak <artursz@iafrica.com>
+///  @date   16 May 2007
+///  @brief  Declaration of the AliHLTMUONTriggerReconstructor class for processing trigger DDL data.
+///
+
 #include "AliHLTLogging.h"
 #include "AliHLTMUONDataTypes.h"
+#include "AliMUONTriggerDDLDecoder.h"
+#include "AliMUONTriggerDDLDecoderEventHandler.h"
 
 extern "C" struct AliHLTMUONTriggerRecordStruct;
 
@@ -31,24 +41,150 @@ public:
        virtual ~AliHLTMUONTriggerReconstructor();
 
        bool Run(
-                       const AliHLTUInt32_t* rawData,
+                       const AliHLTUInt8_t* rawData,
                        AliHLTUInt32_t rawDataSize,
                        AliHLTMUONTriggerRecordStruct* trigRecord,
                        AliHLTUInt32_t& nofTrigRec,
                        bool suppressPartialTrigs = false
                );
 
-       AliHLTMUONTriggerRecoLookupTable* LookupTableBuffer() { return &fLookupTable; }
-       size_t LookupTableSize() const { return sizeof(fLookupTable); }
+       /**
+        * Returns a pointer to the lookup table used to map between channel
+        * addresses and geometrical strip positions.
+        */
+       AliHLTMUONTriggerRecoLookupTable* LookupTableBuffer() { return fDecoder.GetHandler().LookupTableBuffer(); }
+       
+       /// Returns the size of the lookup table.
+       size_t LookupTableSize() const { return fDecoder.GetHandler().LookupTableSize(); }
 
 private:
 
+       class AliDecoderHandler : public AliMUONTriggerDDLDecoderEventHandler, public AliHLTLogging
+       {
+       public:
+       
+               AliDecoderHandler();
+               
+               /// Default destructor.
+               virtual ~AliDecoderHandler() {}
+               
+               /// Returns a pointer to the lookup table.
+               AliHLTMUONTriggerRecoLookupTable* LookupTableBuffer() { return &fLookupTable; }
+               
+               /// Returns the size of the lookup table.
+               size_t LookupTableSize() const { return sizeof(fLookupTable); }
+               
+               /**
+                * Returns the maximum number of trigger records that can be
+                * written to the output buffer.
+                */
+               AliHLTUInt32_t MaxOutputTrigRecs() const { return fMaxOutputTrigRecs; }
+               
+               /**
+                * Sets the maximum number of trigger records that can be
+                * written to the output buffer.
+                */
+               void MaxOutputTrigRecs(AliHLTUInt32_t n) { fMaxOutputTrigRecs = n; }
+               
+               /**
+                * Returns the number of reconstructed trigger records actually
+                * stored in the output buffer.
+                */
+               AliHLTUInt32_t OutputTrigRecsCount() const { return fOutputTrigRecsCount; }
+               
+               /**
+                * Returns the pointer to the output buffer which stores reconstructed
+                * trigger records.
+                */
+               AliHLTMUONTriggerRecordStruct* OutputTrigRecs() const { return fOutputTrigRecs; }
+               
+               /**
+                * Sets the pointer to the output buffer which stores reconstructed
+                * trigger records. Also resets the number of trigger records stored.
+                */
+               void OutputTrigRecs(AliHLTMUONTriggerRecordStruct* buf)
+               {
+                       fOutputTrigRecs = buf;
+                       fOutputTrigRecsCount = 0;
+                       fOverflowed = false;
+               }
+               
+               /**
+                * Returns the flag specifying if we should suppress partial trigger records.
+                */
+               bool SuppressPartialTriggers() const { return fSuppressPartialTriggers; }
+               
+               /**
+                * Sets the flag specifying if we should suppress partial trigger records.
+                */
+               void SuppressPartialTriggers(bool s) { fSuppressPartialTriggers = s; }
+               
+               /**
+                * Returns true if the output buffer was overflowed.
+                */
+               bool OverflowedOutputBuffer() const { return fOverflowed; }
+               
+               
+               // Methods inherited from AliMUONTriggerDDLDecoderEventHandler:
+               
+               /// Called for each new buffer.
+               void OnNewBuffer(const void* buffer, UInt_t /*bufferSize*/);
+               
+               /// Increments a counter for every new regional structure.
+               void OnNewRegionalStruct(
+                               const AliMUONRegionalHeaderStruct* /*regionalStruct*/,
+                               const AliMUONRegionalScalarsStruct* /*scalars*/,
+                               const void* /*data*/
+                       )
+               {
+                       fCurrentRegional++;
+               }
+               
+               /// Reset the counter for every new regional structure.
+               void OnEndOfRegionalStruct(
+                               const AliMUONRegionalHeaderStruct* /*regionalStruct*/,
+                               const AliMUONRegionalScalarsStruct* /*scalars*/,
+                               const void* /*data*/
+                       )
+               {
+                       // Start from -1 since we increment immediately in OnLocalStruct.
+                       fCurrentLocal = -1;
+               }
+               
+               /// Converts a local trigger structure from the L0 into a trigger record.
+               void OnLocalStruct(
+                               const AliMUONLocalInfoStruct* localStruct,
+                               const AliMUONLocalScalarsStruct* scalars
+                       );
+               
+               /// Logs an error message if there was a decoding problem with the DDL payload.
+               void OnError(ErrorCode code, const void* location);
+       
+       private:
+               // Do not allow copying of this class.
+               /// Not implemented
+               AliDecoderHandler(const AliDecoderHandler& rhs); // copy constructor
+               /// Not implemented
+               AliDecoderHandler& operator = (const AliDecoderHandler& rhs); // assignment operator
+               
+               AliHLTMUONTriggerRecoLookupTable fLookupTable;  ///< The lookup table used for mapping between channel addresses and geometrical information.
+               const void* fBufferStart; ///< Pointer to the start of the current DDL payload buffer.
+               AliHLTUInt32_t fMaxOutputTrigRecs;  ///< Maximum number of reconstructed trigger records that can be stored in fOutputTrigRecs.
+               AliHLTUInt32_t fOutputTrigRecsCount;  ///< The number of reconstructed trigger records actually stored in fOutputTrigRecs.
+               AliHLTMUONTriggerRecordStruct* fOutputTrigRecs;  ///< Pointer to the output buffer of trigger records structures.
+               AliHLTInt32_t fTrigRecId;  ///< A running counter for the trigger record ID.
+               AliHLTInt32_t fCurrentRegional;  ///< The current regional trigger structure number.
+               AliHLTInt32_t fCurrentLocal;  ///< The current local trigger structure number.
+               bool fSuppressPartialTriggers;  ///< Flag to indicate if we should suppres partial triggers.
+               bool fOverflowed;  ///< Flag to indicate if we overflowed the output buffer.
+       };
+
+       /// Not implemented
        AliHLTMUONTriggerReconstructor(const AliHLTMUONTriggerReconstructor& rhs); // copy constructor
-       AliHLTMUONTriggerReconstructor& operator=(const AliHLTMUONTriggerReconstructor& rhs); // assignment operator
+       /// Not implemented
+       AliHLTMUONTriggerReconstructor& operator = (const AliHLTMUONTriggerReconstructor& rhs); // assignment operator
 
-       AliHLTUInt32_t fMaxRecPointsCount;   // max nof reconstructed hit
-       AliHLTInt32_t fTrigRecId;  // A running counter for the trigger record ID.
-       AliHLTMUONTriggerRecoLookupTable fLookupTable;  // The lookup table used for mapping between channel addresses and geometrical information.
+       AliMUONTriggerDDLDecoder<AliDecoderHandler> fDecoder; ///< Raw DDL data decoder.
 };
 
 #endif // AliHLTMUONTRIGGERRECONSTRUCTOR_H
index 2a70a3ef444e5abbe3332a2a48c385c01f3cf752..9c9035bf00c0f180e1dac67ee9273fa45a871385 100644 (file)
@@ -30,6 +30,7 @@
 #include "AliHLTMUONConstants.h"
 #include "AliHLTMUONUtils.h"
 #include "AliHLTMUONDataBlockWriter.h"
+#include "AliRawDataHeader.h"
 #include "AliCDBManager.h"
 #include "AliCDBStorage.h"
 #include "AliGeomManager.h"
@@ -402,7 +403,7 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                AliHLTMUONTriggerRecordsBlockWriter block(outputPtr+totalSize, size-totalSize);
                if (not block.InitCommonHeader())
                {
-                       HLTError("There is not enough space in the output buffer for the new data block.",
+                       HLTError("There is not enough space in the output buffer for the new data block."
                                 " We require at least %ufTrigRec->GetkDDLHeaderSize() bytes, but have %u bytes left.",
                                sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType),
                                block.BufferSize()
@@ -410,13 +411,23 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                        break;
                }
 
-               AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
-               AliHLTUInt32_t ddlRawDataSize = totalDDLSize - 8;
-               AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) + 8;
+               AliHLTUInt32_t totalDDLSize = blocks[n].fSize;
+               if (totalDDLSize < sizeof(AliRawDataHeader))
+               {
+                       HLTError("Raw data block %d is %d bytes in size and is too short to"
+                                " possibly contain valid DDL raw data. We expect it to have"
+                                " at least %d bytes for the commond data header.",
+                               n, totalDDLSize, sizeof(AliRawDataHeader)
+                       );
+                       continue;
+               }
+               AliHLTUInt32_t payloadSize = totalDDLSize - sizeof(AliRawDataHeader);
+               AliHLTUInt8_t* buffer =
+                       reinterpret_cast<AliHLTUInt8_t*>(blocks[n].fPtr) + sizeof(AliRawDataHeader);
                AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries();
 
                bool runOk = fTrigRec->Run(
-                               buffer, ddlRawDataSize,
+                               buffer, payloadSize,
                                block.GetArray(), nofTrigRec,
                                fSuppressPartialTrigs
                        );