]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
- changing the digit format to now come as a linked list instead of an array
authorodjuvsla <odjuvsla@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 4 Nov 2009 01:59:51 +0000 (01:59 +0000)
committerodjuvsla <odjuvsla@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 4 Nov 2009 01:59:51 +0000 (01:59 +0000)
  - will slow down digit maker, but give a significant speed up of the clusterizer at high multiplicities
  - also need to always ship the full list of digits, even after clusterisation, but
    this is anyway needed if one is to provide AliESDCaloCells in the ESDs
- now sorting the digits

HLT/PHOS/AliHLTPHOSClusterAnalyser.cxx
HLT/PHOS/AliHLTPHOSClusterAnalyserComponent.cxx
HLT/PHOS/AliHLTPHOSClusterizer.cxx
HLT/PHOS/AliHLTPHOSClusterizer.h
HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
HLT/PHOS/AliHLTPHOSDigitDataStruct.h
HLT/PHOS/AliHLTPHOSDigitMaker.cxx
HLT/PHOS/AliHLTPHOSDigitMaker.h
HLT/PHOS/AliHLTPHOSMapper.h
HLT/PHOS/AliHLTPHOSRecPointDataStruct.h

index d9243cd2daed8e4f52941af536cf922d8b53ba47..4aa6056799894984d7b1cf2b1c6966f798e7d34d 100644 (file)
@@ -67,10 +67,11 @@ AliHLTPHOSClusterAnalyser::SetCaloClusterDataPtr(AliHLTCaloClusterDataStruct *ca
   fCaloClusterDataPtr = caloClusterDataPtr; 
 }
 void
-AliHLTPHOSClusterAnalyser::SetRecPointDataPtr(AliHLTPHOSRecPointHeaderStruct *recPointDataPtr)
+AliHLTPHOSClusterAnalyser::SetRecPointDataPtr(AliHLTPHOSRecPointHeaderStruct *recPointDataPtr, AliHLTPHOSDigitHeaderStruct *digitHeaderPtr)
 { 
   fNRecPoints = recPointDataPtr->fNRecPoints;
   fRecPointDataPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(reinterpret_cast<Char_t*>(recPointDataPtr)+sizeof(AliHLTPHOSRecPointHeaderStruct)); 
+  fDigitHeaderPtr = digitHeaderPtr;
 }
 
 Int_t
@@ -92,10 +93,11 @@ AliHLTPHOSClusterAnalyser::CalculateCenterOfGravity()
 
   for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++) 
     {
-      digit = &(recPoint->fDigits);
-      for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
+      digit = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(reinterpret_cast<Int_t>(fDigitHeaderPtr) + recPoint->fStartDigitOffset);
+      AliHLTPHOSDigitReader reader;
+      reader->SetCurrentDigit(digit);
+      while(digit)
        {
-         
          xi = digit->fX;
          zi = digit->fZ;
          //  cout << "COG digits (x:z:E:time): " << xi << " : " << zi << " : " << digit->fEnergy << " : " << digit->fTime << endl;
@@ -106,9 +108,8 @@ AliHLTPHOSClusterAnalyser::CalculateCenterOfGravity()
              z    += zi * w ;
              wtot += w ;
            }
-         digit++;
+         digit = reader->NextDigit();
        }
-      //cout << endl;
       if (wtot>0) 
        {
          recPoint->fX = x/wtot ;
@@ -154,7 +155,10 @@ AliHLTPHOSClusterAnalyser::CreateClusters(UInt_t availableSize, UInt_t& totSize)
   UInt_t maxClusterSize = sizeof(AliHLTCaloClusterDataStruct) + (6 << 7); //Reasonable estimate... (6 = sizeof(Short_t) + sizeof(Float_t)
 
   AliHLTPHOSRecPointDataStruct* recPointPtr = fRecPointDataPtr;
-  AliHLTPHOSDigitDataStruct* digitPtr = &(recPointPtr->fDigits);  
+  AliHLTPHOSDigitDataStruct* digitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(reinterpret_cast<Int_t>(fDigitHeaderPtr) + recPoint->fStartDigitOffset);
+
+  AliHLTPHOSReader reader;
+  reader.SetCurrentDigit(digitPtr);
  
   AliHLTCaloClusterDataStruct* caloClusterPtr = fCaloClusterDataPtr;
   UShort_t* cellIDPtr = &(caloClusterPtr->fCellsAbsId);
@@ -181,14 +185,14 @@ AliHLTPHOSClusterAnalyser::CreateClusters(UInt_t availableSize, UInt_t& totSize)
       cellIDPtr = &(caloClusterPtr->fCellsAbsId);
       cellAmpFracPtr = &(caloClusterPtr->fCellsAmpFraction);
      
-      for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
+      while(digitPtr)
        {
          fPHOSGeometry->RelPosToAbsId((Int_t)(recPointPtr->fModule), (double)(digitPtr->fX), (double)(digitPtr->fZ), id);
          *cellIDPtr = id;
          *cellAmpFracPtr = digitPtr->fEnergy/recPointPtr->fAmp;
-         digitPtr++;
          cellIDPtr = reinterpret_cast<UShort_t*>(reinterpret_cast<char*>(cellAmpFracPtr) + sizeof(Float_t)); 
          cellAmpFracPtr = reinterpret_cast<Float_t*>(reinterpret_cast<char*>(cellIDPtr) + sizeof(Short_t)); 
+         digitPtr = reader.NextDigit()
        }
 
       caloClusterPtr->fEnergy = recPointPtr->fAmp;
index 1b3c1687ac45748199a077c5ecff75a83c5d5eda..a3267698273a0a91d3c39d0c26c80047a7ed79b0 100644 (file)
@@ -152,8 +152,9 @@ AliHLTPHOSClusterAnalyserComponent::DoEvent(const AliHLTComponentEventData& evtD
          continue;
         }
       specification = specification|iter->fSpecification;
-      fClusterAnalyserPtr->SetRecPointDataPtr(reinterpret_cast<AliHLTPHOSRecPointHeaderStruct*>(iter->fPtr));
-      //      HLTDebug("Number of rec points: %d", (reinterpret_cast<AliHLTPHOSRecPointHeaderStruct*>(iter->fPtr))->fNRecPoints);
+      AliHLTPHOSDigitHeaderStruct *digitHeader = reinterpret_cast<AliHLTPHOSDigitHeaderStruct>(iter->fPtr);
+      
+      fClusterAnalyserPtr->SetRecPointDataPtr(reinterpret_cast<AliHLTPHOSRecPointHeaderStruct*>(iter->fPtr + sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeader->fNDigits*sizeof(AliHLTPHOSDigitDataStruct)));
 
       if(fDoDeconvolution)
        {
index 83159dfeb6114cdb7cd72718c4b48eee543d5444..63b9a70380f0f57ef9723a480adc43bcf12333f7 100644 (file)
@@ -58,12 +58,15 @@ AliHLTPHOSClusterizer::AliHLTPHOSClusterizer():
   fEmcTimeGate(0),
   fDigitsInCluster(0),
   fDigitContainerPtr(0),
-  fMaxDigitIndexDiff(2*NZROWSMOD)
+  fMaxDigitIndexDiff(2*NZROWSMOD),
+  fDigitReader(0)
 {
   //See header file for documentation
   fEmcClusteringThreshold = 0.2;
   fEmcMinEnergyThreshold = 0.03;
   fEmcTimeGate = 1.e-6 ;
+
+  fDigitReader = new AliHLTPHOSDigitReader();
 }//end
 
 
@@ -80,51 +83,51 @@ AliHLTPHOSClusterizer::SetRecPointDataPtr(AliHLTPHOSRecPointDataStruct* recPoint
 }
 
 Int_t 
-AliHLTPHOSClusterizer::ClusterizeEvent(UInt_t availableSize, UInt_t& totSize)
+AliHLTPHOSClusterizer::ClusterizeEvent(AliHLTPHOSDigitHeaderStruct *digitHeader, UInt_t availableSize, UInt_t& totSize)
 {
   //see header file for documentation
   Int_t nRecPoints = 0;
 
   fAvailableSize = availableSize;
 
+  fDigitReader->SetDigitHeader(digitHeader);
+
   //  UInt_t maxRecPointSize = sizeof(AliHLTPHOSRecPointDataStruct) + (sizeof(AliHLTPHOSDigitDataStruct) << 7); //Reasonable estimate... 
 
   //Clusterization starts
-  for(UInt_t i = 0; i < fDigitContainerPtr->fNDigits; i++)
+  while((fCurrentDigit = fDigitReader->NextDigit()) != 0)
     { 
+
       fDigitsInCluster = 0;
       
-      if(fDigitContainerPtr->fDigitDataStruct[i].fEnergy < fEmcClusteringThreshold)
+      if(fCurrentDigit.fEnergy < fEmcClusteringThreshold)
        {
          continue;
        }
+
       if(fAvailableSize < (sizeof(AliHLTPHOSRecPointDataStruct)))
        {
          HLTError("Out of buffer, stopping clusterisation");
          return -1; 
        }
 
-      // First digit is placed at the fDigits member variable in the recpoint
-      fDigitDataPtr = &(fRecPointDataPtr->fDigits);
+      // Save the starting digit
+      fStartDigit = fCurrentDigit;
+      fPreviousDigit = fStartDigit;
+      // Get the offset of the digit starting the cluster relative to the start of the digit block
+      fRecPointDataPtr->fStartDigitOffset = fDigitReader->GetCurrentDigitOffset();
+      fDigitReader->DropDigit();
 
       fRecPointDataPtr->fAmp = 0;
-      fRecPointDataPtr->fModule = fDigitContainerPtr->fDigitDataStruct[i].fModule;
-
-      // Assigning digit data to the digit pointer
-      fRecPointDataPtr->fDigits = fDigitContainerPtr->fDigitDataStruct[i];
-
-      fAvailableSize -= (sizeof(AliHLTPHOSRecPointDataStruct));
+      fRecPointDataPtr->fModule = fCurrentDigit->fModule;
 
-      // Incrementing the pointer to be ready for new entry
-      fDigitDataPtr++;
-
-      fRecPointDataPtr->fAmp += fDigitContainerPtr->fDigitDataStruct[i].fEnergy;
-      fDigitContainerPtr->fDigitDataStruct[i].fEnergy = 0;
+      fRecPointDataPtr->fAmp += fCurrentDigit->fEnergy;
       fDigitsInCluster++;
+
       nRecPoints++;
 
       // Scanning for the neighbours
-      if(ScanForNeighbourDigits(i, fRecPointDataPtr) < 0)
+      if(ScanForNeighbourDigits(fRecPointDataPtr) < 0)
        {
          return -1;
        }
@@ -134,48 +137,36 @@ AliHLTPHOSClusterizer::ClusterizeEvent(UInt_t availableSize, UInt_t& totSize)
       
       fRecPointDataPtr->fMultiplicity = fDigitsInCluster;     
 
-      fRecPointDataPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(fDigitDataPtr);
+      fRecPointDataPtr++;
     }//end of clusterization
 
    return nRecPoints;
 }
 
 Int_t
-AliHLTPHOSClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTPHOSRecPointDataStruct* recPoint)
+AliHLTPHOSClusterizer::ScanForNeighbourDigits(AliHLTPHOSRecPointDataStruct* recPoint)
 {
   //see header file for documentation
+
   Int_t max = TMath::Min((Int_t)fDigitContainerPtr->fNDigits, (Int_t)fMaxDigitIndexDiff+index);
   Int_t min = TMath::Max(0, (Int_t)(index - (Int_t)fMaxDigitIndexDiff));
 
   max = fDigitContainerPtr->fNDigits;
   min = 0;
-  for(Int_t j = min; j < max; j++)
+
+  fDigitReader->Rewind();
+
+  while((fCurrentDigit = fDigitReader->NextDigit()))
     {
-      if(fDigitContainerPtr->fDigitDataStruct[j].fEnergy > fEmcMinEnergyThreshold)
+      if(fCurrentDigit->fEnergy > fEmcMinEnergyThreshold)
        {
-         if(j != index)
+         if(AreNeighbours(fStartDigit, fCurrentDigit))
            {
-             if(AreNeighbours(&(fDigitContainerPtr->fDigitDataStruct[index]),
-                              &(fDigitContainerPtr->fDigitDataStruct[j])))
-               {
-                 // Assigning value to digit ptr
-                 if(fAvailableSize < sizeof(AliHLTPHOSDigitDataStruct))
-                   {
-                     HLTError("Out of buffer, stopping clusterisation");
-                     return -1; 
-                   }
-                 fAvailableSize -= sizeof(AliHLTPHOSDigitDataStruct);
-
-                 *fDigitDataPtr = fDigitContainerPtr->fDigitDataStruct[j];
-                 // Incrementing digit pointer to be ready for new entry
-
-                 fDigitDataPtr++;
-
-                 recPoint->fAmp += fDigitContainerPtr->fDigitDataStruct[j].fEnergy;
-                 fDigitContainerPtr->fDigitDataStruct[j].fEnergy = 0;        
-                 fDigitsInCluster++;
-                 ScanForNeighbourDigits(j, recPoint);
-               }
+             fDigitReader->DropDigit();
+             fPreviousDigit->fMemOffsetNext = reinterpret_cast<Int_t>(fCurrentDigit) - reinterpret_cast<Int_t>(fPreviousDigit);
+             recPoint->fAmp += fCurrentDigit.fEnergy;
+             fDigitsInCluster++;
+             ScanForNeighbourDigits(recPoint);
            }
        }
     }
index cff5f4b058975013746e1404c889b3797bfce5e7..4f8fa488f0ce63846ba405b60f47cd5c479680eb 100644 (file)
@@ -152,6 +152,9 @@ protected:
   /** Current available buffer size */
   UInt_t fAvailableSize;                                       //COMMENT
 
+  /** object reading the digit */
+  AliHLTPHOSDigitReader *fDigitReader;                         //COMMENT
+
   ClassDef(AliHLTPHOSClusterizer, 0);
 };
 
index bdba0b0d69bc4d662ddf2195e1ae02c50bfbe0a4..80037de3b80aaf4b3f7a0de21e11c05c684530c0 100644 (file)
@@ -124,8 +124,8 @@ AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData,
   UInt_t mysize           = 0;
   Int_t nRecPoints        = 0;
   Int_t nDigits           = 0;
-  Int_t j                 = 0;
-  
+
+  UInt_t availableSize = size;
   AliHLTUInt8_t* outBPtr;
   outBPtr = outputPtr;
   const AliHLTComponentBlockData* iter = 0;
@@ -133,45 +133,102 @@ AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData,
   
   UInt_t specification = 0;
   
-  AliHLTPHOSDigitDataStruct *digitDataPtr = 0;
-  
-  AliHLTPHOSRecPointHeaderStruct* recPointHeaderPtr = reinterpret_cast<AliHLTPHOSRecPointHeaderStruct*>(outBPtr);
+  AliHLTPHOSDigitHeaderStruct *digitHeaderPtr = 0;
+  AliHLTPHOSDigitHeaderStruct *outputDigitHeaderPtr = reinterpret_cast<AliHLTPHOSDigitHeaderStruct*>(outBPtr);
 
-  fClusterizerPtr->SetRecPointDataPtr(reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(outBPtr+sizeof(AliHLTPHOSRecPointHeaderStruct)));
+  AliHLTPHOSDigitDataStruct *firstDigitPtr = 0;
+  AliHLTPHOSDigitDataStruct *lastDigitPtr = 0;
   
+  // Adding together all the digits, should be put in standalone method  
   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
     {
       iter = blocks+ndx;
       if (iter->fDataType == AliHLTPHOSDefinitions::fgkDigitDataType)
        {
+         // Update the number of digits
+         nDigits += digitHeaderPtr->fNDigits;
+
+         // Get the specification
          specification = specification|iter->fSpecification;
-         nDigits = iter->fSize/sizeof(AliHLTPHOSDigitDataStruct);
-         digitDataPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(iter->fPtr);
-         for (Int_t i = 0; i < nDigits; i++)
+         
+         // Get the digit header
+         digitHeaderPtr = reinterpret_cast<AliHLTPHOSDigitHeaderStruct*>(iter->fPtr);
+         
+         // Check if we have the first buffer in the event
+         if(!firstDigitPtr)
+           {
+             if(availableSize < digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct) + sizeof(AliHLTPHOSDigitHeaderStruct))
+               {
+                 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
+                 return -1;
+               }
+             // If so, lets copy the header and the corresponding digits to the output
+             memcpy(outBPtr, iter->fPtr, digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct) + sizeof(AliHLTPHOSDigitHeaderStruct));
+
+             // Set the pointer to the first digit in the list
+             firstDigitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr + sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeaderPtr->fFirstDigitOffset);
+
+             lastDigitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr + sizeof(AliHLTPHOSDigitHeaderStruct) + digitHeaderPtr->fLastDigitOffset);
+             
+             // Update the amount of the output buffer we have used
+             mysize += digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct) + sizeof(AliHLTPHOSDigitHeaderStruct);
+           }
+         else
            {
-             fAllDigitsPtr->fDigitDataStruct[j].fX = digitDataPtr->fX;
-             fAllDigitsPtr->fDigitDataStruct[j].fZ = digitDataPtr->fZ;
-             fAllDigitsPtr->fDigitDataStruct[j].fEnergy = digitDataPtr->fEnergy;
-             fAllDigitsPtr->fDigitDataStruct[j].fTime = digitDataPtr->fTime;
-             fAllDigitsPtr->fDigitDataStruct[j].fCrazyness = digitDataPtr->fCrazyness;
-             fAllDigitsPtr->fDigitDataStruct[j].fModule = digitDataPtr->fModule;
-             j++;
-             digitDataPtr++;
+             // Check if we have space for 
+             if(availableSize < digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct))
+               {
+                 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
+                 return -1;
+               }
+
+             // If we already have copied the first buffer to the output copy only the digits
+             memcpy(outBPtr, (iter->fPtr+sizeof(AliHLTPHOSDigitHeaderStruct)), digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct));
+
+             // Check if the first digit in this buffer has a ID less than the first digit in the previous
+             if(firstDigitPtr->fID > reinterpret_cast<AliHLTPHOSDigitDataStruct*>(iter->fPtr + sizeof(AliHLTPHOSDigitDataStruct) + digitHeaderPtr->fFirstDigitOffset)->fID)
+               {
+                 // If that is the case we have to take care of the ordering
+                                 
+                 // The last digit in the current buffer has to link to the first digit in the previous buffer
+                 lastDigitPtr->fMemOffsetNext = outBPtr + digitHeaderPtr->fFirstDigitOffset - reinterpret_cast<Int_t>(lastDigitPtr);
+
+                 // Setting the pointer to the new first digit
+                 firstDigitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr + digitHeaderPtr->fFirstDigitOffset);
+               }
+             else
+               {
+                 // Previous last digit need to link to the current first digit
+                 lastDigitPtr->fMemOffsetNext = outBPtr + digitHeaderPtr->fFirstDigitOffset;             
+                 
+                 // We need to change the last digit pointer
+                 lastDigitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outBPtr + digitHeaderPtr->fLastDigitOffset);
+               }
+             // Update the amount of the output buffer we have used
+             mysize += digitHeaderPtr->fNDigits*sizeof(AliHLTPHOSDigitDataStruct);
            }
+
+         outBPtr += mysize;
        }
     }
+  
+  // The digit header in the output needs to know about the position of the new first digit (the last digit is still the same)
+  outputDigitHeaderPtr->fFirstDigitOffset = reinterpret_cast<Int_t>(firstDigitPtr) - reinterpret_cast<Int_t>(outputDigitHeaderPtr) + sizeof(AliHLTPHOSDigitHeaderStruct);
+  
+  // The digit header in the output needs to know about the position of the new last digit (the first digit is still the same)
+  outputDigitHeaderPtr->fLastDigitOffset = reinterpret_cast<Int_t>(lastDigitPtr) - reinterpret_cast<Int_t>(outputDigitHeaderPtr) + sizeof(AliHLTPHOSDigitHeaderStruct);
+                 
 
-  fAllDigitsPtr->fNDigits = j;
-  HLTDebug("Number of digits: %d", j);
-  nRecPoints = fClusterizerPtr->ClusterizeEvent(size, mysize);
+  HLTDebug("Number of digits: %d", nDigits);
 
-  if(nRecPoints == -1)
-    {
-      HLTError("Running out of buffer, exiting for safety.");
-      return -ENOBUFS;
-    }
+  AliHLTPHOSRecPointHeaderStruct* recPointHeaderPtr = reinterpret_cast<AliHLTPHOSRecPointHeaderStruct*>(outBPtr);
+
+  fClusterizerPtr->SetRecPointDataPtr(reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(outBPtr+sizeof(AliHLTPHOSRecPointHeaderStruct)));
+
+  nRecPoints = fClusterizerPtr->ClusterizeEvent(firstDigitPtr, size, mysize);
 
   recPointHeaderPtr->fNRecPoints = nRecPoints;
+
   mysize += sizeof(AliHLTPHOSRecPointHeaderStruct);
   
   HLTDebug("Number of clusters: %d", nRecPoints);
index 7630677eea6078f6115265d4c048de3bb5ff3da6..d0ec12fd50520de8215f92315edbda4320040423 100644 (file)
 // or
 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 
+/**
+ * @struct AliHLTPHOSDigitHeaderStruct 
+ * Header used to pass digits around
+ * @ingroup alihlt_phos
+ */
+struct AliHLTPHOSDigitHeaderStruct
+{
+  /** Number of digits */
+  UInt_t fNDigits;
+
+  /** Start pointer */
+  Char_t *fStartPtr;
+  
+  /** The relative offset in bytes to the first digit in the list */
+  Int_t fFirstDigitOffset;
+
+  /** The relative offset in bytes to the last digit in the list */
+  Int_t fLastDigitOffset;
+      
+};
+
 /**
  * @struct AliHLTPHOSDigitDataStruct
  * Digit struct for PHOS HLT
@@ -77,6 +98,12 @@ struct AliHLTPHOSDigitDataStruct
 
   /** The baseline */
   Float_t fBaseline;
+  
+  /** Relative offset in memory to next digit */
+  Int_t fMemOffsetNext;
+
+  /** Digit ID */
+  UInt_t fID;
 
 };
 
index 7abb28b93ee4bd44656b78a46b5cfead84268b73..6af0cc59980c7dc17c28a1daea39f0bc8eaac211 100644 (file)
@@ -1,4 +1,4 @@
-// $Id$
+3// $Id$
 
 /**************************************************************************
  * This file is property of and copyright by the ALICE HLT Project        * 
@@ -40,9 +40,8 @@
 #include "AliHLTPHOSChannelDataHeaderStruct.h"
 #include "AliHLTPHOSDigitDataStruct.h"
 #include "AliHLTPHOSSharedMemoryInterfacev2.h" // added by PTH
-#include "AliPHOSEMCAGeometry.h"
 #include "TH2F.h"
-
+#include <cstdlib>
 
 ClassImp(AliHLTPHOSDigitMaker);
 
@@ -54,7 +53,8 @@ AliHLTPHOSDigitMaker::AliHLTPHOSDigitMaker() :
   fDigitStructPtr(0),
   fDigitCount(0),
   fOrdered(true),
-  fMapperPtr(0)
+  fMapperPtr(0),
+  fDigitPtrArray(0)
 {
   // See header file for documentation
 
@@ -71,6 +71,8 @@ AliHLTPHOSDigitMaker::AliHLTPHOSDigitMaker() :
        }
     }    
   fMapperPtr = new AliHLTPHOSMapper();
+
+  fDigitPtrArray = new AliHLTPHOSDigitDataStruct*[NZROWSRCU*NXCOLUMNSMOD];
 }
    
 AliHLTPHOSDigitMaker::~AliHLTPHOSDigitMaker() 
@@ -83,9 +85,12 @@ AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataH
 {
   //See header file for documentation
   
+  fAvailableSize = availableSize;
   Int_t j = 0;
   UInt_t totSize = sizeof(AliHLTPHOSDigitDataStruct);
   
+  
+
 //   Int_t xMod = -1;
 //   Int_t zMod = -1;
   
@@ -116,7 +121,7 @@ AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataH
              if(currentchannel->fEnergy < MAXBINVALUE) // Make sure we don't have signal overflow
                {
                  AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
-                 AddDigit(currentchannel, coord1, locCoord);
+                 if(!AddDigit(currentchannel, coord1, locCoord)) return -1;
                  j++;        
                  totSize += sizeof(AliHLTPHOSDigitDataStruct);
 
@@ -141,7 +146,7 @@ AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataH
                      if(coord2[0] == coord1[0] && coord2[1] == coord1[1]) // It is a low gain channel with the same coordinates, we may use it
                        {
                          AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
-                         AddDigit(currentchannel, coord2, locCoord);
+                         if(!AddDigit(currentchannel, coord2, locCoord)) return -1;
                          j++;
                          totSize += sizeof(AliHLTPHOSDigitDataStruct);
                          currentchannel = fShmPtr->NextChannel();                    
@@ -150,7 +155,7 @@ AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataH
                      else // No low gain channel with information about the overflow channel so we just use the overflowed one...
                        {
                          AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
-                         AddDigit(tmpchannel, coord1, locCoord);
+                         if(!AddDigit(tmpchannel, coord1, locCoord)) return -1;
                          j++;        
                          totSize += sizeof(AliHLTPHOSDigitDataStruct);
                          // no need to get the next channel here, we already did...
@@ -162,7 +167,7 @@ AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataH
          else // Well, there seem to be missing a high gain channel for this crystal, let's use the low gain one
            {    
              AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);  
-             AddDigit(tmpchannel, coord1, locCoord);
+             if(!AddDigit(tmpchannel, coord1, locCoord)) return -1;
              j++;            
              totSize += sizeof(AliHLTPHOSDigitDataStruct);
              currentchannel = fShmPtr->NextChannel(); 
@@ -185,7 +190,7 @@ AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataH
                      if(currentchannel->fEnergy < MAXBINVALUE)  // To overflow or not to overflow?
                        {
                          AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
-                         AddDigit(currentchannel, coord2, locCoord);
+                         if(!AddDigit(currentchannel, coord2, locCoord)) return -1;
                          j++;
                          totSize += sizeof(AliHLTPHOSDigitDataStruct);
                          currentchannel = fShmPtr->NextChannel();
@@ -193,7 +198,7 @@ AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataH
                      else // Oh well, better use the low gain channel then
                        {
                          AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
-                         AddDigit(currentchannelLG, coord1, locCoord);
+                         if(!AddDigit(currentchannelLG, coord1, locCoord)) return -1;
                          j++;
                          totSize += sizeof(AliHLTPHOSDigitDataStruct);
                          currentchannel = fShmPtr->NextChannel();
@@ -202,7 +207,7 @@ AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataH
                  else // No available high gain channel for this crystal, adding the low gain one
                    {
                      AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
-                     AddDigit(currentchannelLG, coord1, locCoord);
+                     if(!AddDigit(currentchannelLG, coord1, locCoord)) return -1;
                      j++;
                      totSize += sizeof(AliHLTPHOSDigitDataStruct);
                    }
@@ -210,7 +215,7 @@ AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataH
              else //Fine, no more channels, better add this one...
                {
                  AliHLTPHOSMapper::GetLocalCoord(currentchannelLG->fChannelID, locCoord);
-                 AddDigit(currentchannelLG, coord1, locCoord);
+                 if(!AddDigit(currentchannelLG, coord1, locCoord)) return -1;
                  j++;
                  totSize += sizeof(AliHLTPHOSDigitDataStruct);
                }
@@ -218,14 +223,13 @@ AliHLTPHOSDigitMaker::MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataH
          else // Cool, no annoying low gain channel for this channel
            {
              AliHLTPHOSMapper::GetLocalCoord(currentchannel->fChannelID, locCoord);
-             AddDigit(currentchannel, coord1, locCoord);
+             if(!AddDigit(currentchannel, coord1, locCoord)) return -1;
              j++;
              currentchannel = fShmPtr->NextChannel();
            }
        }
     }
 
-  fDigitCount += j;
   return fDigitCount; 
 }
 
@@ -258,6 +262,7 @@ AliHLTPHOSDigitMaker::SetGlobalLowGainFactor(Float_t factor)
 void
 AliHLTPHOSDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannelLGHist, Float_t qCut)
 {
+  // See header file for documentation
  for(int x = 0; x < NXCOLUMNSMOD; x++)
     {
       for(int z = 0; z < NZROWSMOD; z++)
@@ -282,3 +287,26 @@ AliHLTPHOSDigitMaker::SetBadChannelMask(TH2F* badChannelHGHist, TH2F* badChannel
     }
 }
 
+void
+AliHLTPHOSDigitMaker::SortDigits()
+{
+
+  // See header file for documentation
+  qsort(fDigitPtrArray, fDigitCount, sizeof(AliHLTPHOSDigitDataStruct*), AliHLTPHOSDigitMaker::CompareDigits);
+
+  fDigitHeaderPtr->fFirstDigitOffset = fDigitPtrArray[0] - (fDigitHeaderPtr + sizeof(AliHLTPHOSDigitHeaderStruct));
+  for(Int_t i = 0; i < fDigitCount-1; i++)
+    {
+      fDigitPtrArray[0]->fMemOffsetNext = fDigitPtrArray[i+1] - fDigitPtrArray[i];
+    }
+  fDigitHeaderPtr->fLastDigitOffset = fDigitPtrArray[fDigitCount-1] - (fDigitHeaderPtr + sizeof(AliHLTPHOSDigitHeaderStruct));
+  fDigitPtrArray[fDigitCount-1]->fMemOffsetNext = 0;
+}
+
+Int_t
+AliHLTPHOSDigitMaker::CompareDigits(const void *dig0, const void *dig1)
+{
+  // See header file for documentation
+  return *((AliHLTPHOSDigitDataStruct**)(dig0))->fID - *((AliHLTPHOSDigitDataStruct**)(dig1))->fID;
+}
+
index 530c0b6d1cf27059269b3e44e8031eba1c60233c..2d67d8dc4b833ca90feeef7bbee233a7fb7f6633 100644 (file)
@@ -89,8 +89,12 @@ public:
    * Sets the pointer to the output
    * @param the output pointer
    */
-  void SetDigitDataPtr(AliHLTPHOSDigitDataStruct *digitDataPtr) 
-  { fDigitStructPtr = digitDataPtr; }
+  void SetDigitDataHeaderPtr(AliHLTPHOSDigitHeaderStruct *digitHeaderPtr) 
+  { 
+    fDigitHeaderPtr = digitHeaderPtr;
+    fDigitStructPtr = digitHeaderPtr + sizeof(AliHLTPHOSDigitHeaderStruct);
+    fDigitHeaderPtr.fStartPtr = reinterpret_cast<Char_t*>(fDigitStructPtr);
+  }
 
   /**
    * Set the global high gain conversion factory 
@@ -109,7 +113,7 @@ public:
    * @param channelDataHeader is the data header from the AliHLTPHOSRawAnalyzer
    * @return the number of digits found
    */
-  Int_t MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize);
+  Int_t MakeDigits(AliHLTPHOSChannelDataHeaderStruct* channelDataHeader, AliHLTUInt32_t availableSize)
 
 
   /**
@@ -124,22 +128,46 @@ public:
    * Set ordering of gains or not
    */
   void SetOrdered(bool val) { fOrdered = val; }
-  
+
+  /**
+   * Reset the digit maker */
+   */
   void Reset() { fDigitCount = 0; }
 
+  /**
+   * Sort the digits and make internal links between them
+   */
+  void SortDigits();
+
+  /** 
+   * Compare two digits, used during the sorting
+   */
+  Int_t CompareDigits(const void *dig0, const void *dig);
+
+  
 private:
 
   /**
    * Add a new digit
    * @param channelData is the channel data
    * @param coordinates is the coordinates of the channel, including gain and module
+   * @return true if the digit is added correctly, false if out of buffer
    */
-  void AddDigit(AliHLTPHOSChannelDataStruct* channelData, UShort_t* channelCoordinates, Float_t* localCoordinates)
+  bool AddDigit(AliHLTPHOSChannelDataStruct* channelData, UShort_t* channelCoordinates, Float_t* localCoordinates)
   {
+    if(fAvailableSize < sizeof(AliHLTPHOSDigitDataStruct))
+      {
+       HLTError("Output buffer is full, stopping digit making");
+       return false;
+      }
+
+    fAvailableSize -= sizeof(AliHLTPHOSDigitDataStruct);
 
     fDigitStructPtr->fX = channelCoordinates[0];
     fDigitStructPtr->fZ = channelCoordinates[1];
 
+    fDigitStructPtr->fID = fDigitStructPtr->fZ * NXCOLUMNSRCU + fDigitStructPtr->fX;
+
     fDigitStructPtr->fLocX = localCoordinates[0];
     fDigitStructPtr->fLocZ = localCoordinates[1];
 
@@ -156,6 +184,9 @@ private:
     fDigitStructPtr->fTime = channelData->fTime * 0.0000001; //TODO
     fDigitStructPtr->fCrazyness = channelData->fCrazyness;
     fDigitStructPtr->fModule = channelCoordinates[3];
+
+    fDigitPtrArray[fDigitCount] = fDigitStructPtr;
+    fDigitCount++;
     fDigitStructPtr++;
   }
 
@@ -183,6 +214,11 @@ private:
   /** Bad channel mask */
   Float_t fBadChannelMask[NXCOLUMNSMOD][NZROWSMOD][NGAINS]; //COMMENT
 
+  /** Array of digit pointers */
+  AliHLTPHOSDigitDataStruct **fDigitPtrArray;               //COMMENT
+  
+  /** The available size of the output buffer */
+  AliHLTUInt32_t fAvailableSize;                            //COMMENT
 
   ClassDef(AliHLTPHOSDigitMaker, 0); 
 
index a79937281eba4c82a77d7b12e79c3234ec684d86..30a837287e7345a5c007e29a596b040f336d9d1f 100644 (file)
@@ -48,7 +48,7 @@ class AliHLTPHOSMapper : public AliHLTLogging
   static void GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord);
   static void ChannelId2Coordinate(const UShort_t channelId, AliHLTPHOSCoordinate &channelCoord );
   static void GetLocalCoord(const UShort_t channelId, Float_t* localCoord);
-  int GetDDLFromSpec(Int_t specification);
+  static int GetDDLFromSpec(Int_t specification);
   int GetModuleFromSpec(Int_t specification);
 
   struct fAltromap{ 
index d796b8237c4d2adf6eb2bc9ddd82f4c85f7c0283..9bcb481b4ca316456044a4a0db76c8ae2e58a2d4 100644 (file)
@@ -1,4 +1,4 @@
-//-*- Mode: C++ -*-
+\//-*- Mode: C++ -*-
 // $Id$
 
 
@@ -80,8 +80,11 @@ struct AliHLTPHOSRecPointDataStruct
   /** Distance to nearest bad channel */
   Float_t fDistanceToBadChannel;              //COMMENT
 
-  /** Digits in the rec point */
-  AliHLTPHOSDigitDataStruct fDigits;          //COMMENT
+  /** 
+   * Digit offset for the first digit in the 
+   * rec point.
+   */
+  Int_t fStartDigitOffset;                    //COMMENT
 
 };