]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Added a new component (AliHLTTPCHWCFDataReverterComponent) which reads the data,...
authorkaamodt <kaamodt@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 17 Nov 2008 13:35:11 +0000 (13:35 +0000)
committerkaamodt <kaamodt@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 17 Nov 2008 13:35:11 +0000 (13:35 +0000)
Moved around the functions of the AliHLTTPCClusterFinder so the ones belonging to the ClusterFinderDecoder is at the top of the files, and the ClusterFinderPacked functions on the bottom.
Also changed from fMaxQ to fQMax in the AliHLTSpacePointData.h so that we only have one name convention for max charge of a cluster. This led to changes in KryptonClusterfinder, *Cluster*, Noise map, TrackHistoComponent.
In AliHLTAltroEncoder; added the functionality to revert 40 bit words.

18 files changed:
HLT/AliHLTTPCLinkDef.h
HLT/RCU/AliHLTAltroEncoder.cxx
HLT/RCU/AliHLTAltroEncoder.h
HLT/TPCLib/AliHLTTPCAgent.cxx
HLT/TPCLib/AliHLTTPCClusterDumpComponent.cxx
HLT/TPCLib/AliHLTTPCClusterFinder.cxx
HLT/TPCLib/AliHLTTPCClusterFinder.h
HLT/TPCLib/AliHLTTPCClusterFinderComponent.cxx
HLT/TPCLib/AliHLTTPCClusterHistoComponent.cxx
HLT/TPCLib/AliHLTTPCHWCFDataReverterComponent.cxx [new file with mode: 0755]
HLT/TPCLib/AliHLTTPCHWCFDataReverterComponent.h [new file with mode: 0755]
HLT/TPCLib/AliHLTTPCKryptonClusterFinder.cxx
HLT/TPCLib/AliHLTTPCKryptonClusterFinderComponent.cxx
HLT/TPCLib/AliHLTTPCNoiseMapComponent.cxx
HLT/TPCLib/AliHLTTPCSpacePointData.h
HLT/TPCLib/AliHLTTPCTrackHistoComponent.cxx
HLT/TPCLib/offline/AliHLTTPCOfflineCluster.cxx
HLT/libAliHLTTPC.pkg

index 9fce0d24f2589ce80f00a924f5cfc3c4118c2e57..a1b8425f04e5198a6f551f6809f4a9bfbcd8ed29 100644 (file)
@@ -70,4 +70,6 @@
 #pragma link C++ class  AliHLTTPCEventStatisticsProducerComponent+;
 #pragma link C++ class  AliHLTTPCRunStatistics+;
 #pragma link C++ class  AliHLTTPCRunStatisticsProducerComponent+;
+#pragma link C++ class  AliHLTTPCHWCFDataReverterComponent+;
+
 #endif
index 58d2c1ff44d60bf1bdbfa34c642710760ae5899a..8e50876ac0729efce99efcb2b59a9d2339693f9e 100644 (file)
@@ -310,3 +310,29 @@ int AliHLTAltroEncoder::SetLength()
   }
   return fOffset;
 }
+
+void AliHLTAltroEncoder::Revert40BitWords(Int_t CDHSize, Int_t trailerSize)
+{
+  // see headerfile for class documentation
+  
+  //initialize to last 40 bit word in the payload
+  AliHLTUInt8_t * pointerToHighEnd40BitWord = fpBuffer + fOffset - trailerSize -5;
+  
+  //initialize to first 40 bit word in the payload
+  AliHLTUInt8_t * pointerToLowEnd40BitWord = fpBuffer+CDHSize;
+
+  assert(((pointerToHighEnd40BitWord - pointerToLowEnd40BitWord)+5)%5 == 0 );//check that it is a whole number of 40 bit words
+
+  Int_t total40BitWords = ((pointerToHighEnd40BitWord - pointerToLowEnd40BitWord) + 5)/(5);
+
+  AliHLTUInt8_t tmp8BitWords[5] = {0,0,0,0,0};
+
+  for(Int_t numberOf40BitWordMoves = 0 ; numberOf40BitWordMoves < total40BitWords/2 ; numberOf40BitWordMoves++){
+    memcpy(&tmp8BitWords, pointerToLowEnd40BitWord, 5);              // copy 40 bit word in to temporary from low side
+    memcpy(pointerToLowEnd40BitWord, pointerToHighEnd40BitWord, 5); // copy the high side 40 bit word to the low side
+    memcpy(pointerToHighEnd40BitWord, &tmp8BitWords, 5);             // copy from the temporary to the high side 40 bits 
+    pointerToLowEnd40BitWord += 5;
+    pointerToHighEnd40BitWord -= 5;
+  }
+
+}
index 01bae80b604323a3d18010114e34d8f7ee9d2683..c07f1cc3cebee4284779c6d2c6d7121b71a2db46 100644 (file)
@@ -138,6 +138,11 @@ class AliHLTAltroEncoder : AliHLTLogging {
 
   int GetOffset(){return fOffset;}
 
+  /**
+   * Revert the 40 bit altro data
+   */
+  void Revert40BitWords(Int_t CDHSize, Int_t trailerSize);
+
   enum {
     kUnknownOrder = 0,
     kAscending,
index 1c8725aaf57fcb76bbf1dbe8aa3a3cd92cc76c0e..c25bf70671ad1f684fe669d43162901b3c9c628a 100644 (file)
@@ -64,7 +64,7 @@ AliHLTTPCAgent gAliHLTTPCAgent;
 #include "AliHLTTPCCalibTracksComponent.h"
 #include "AliHLTTPCTrackHistoComponent.h"
 #include "AliHLTTPCTrackDumpComponent.h"
-
+#include "AliHLTTPCHWCFDataReverterComponent.h"
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTTPCAgent)
@@ -240,7 +240,8 @@ int AliHLTTPCAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
   pHandler->AddComponent(new AliHLTTPCCalibTracksComponent);
   pHandler->AddComponent(new AliHLTTPCTrackHistoComponent);
   pHandler->AddComponent(new AliHLTTPCTrackDumpComponent);
-  
+  pHandler->AddComponent(new AliHLTTPCHWCFDataReverterComponent);
+
   return 0;
 }
 
index 249632fefbe2eb4ec19c577fbf3068f9170e76d5..64e18fa56085d120826b4635b2430aecf56bfb98 100644 (file)
@@ -160,7 +160,7 @@ int AliHLTTPCClusterDumpComponent::DumpEvent( const AliHLTComponentEventData& /*
         AliHLTTPCTransform::LocHLT2Raw(xyz,(Int_t)(clusters[i].fID/10),(Int_t)(clusters[i].fID%10));
         dump << "[R,P,T]:       [" << xyz[0]<<" , "<<xyz[1]<<" , "<<xyz[2] <<"]"<< endl;
         dump << "Total Charge:  " << clusters[i].fCharge         << endl;
-        dump << "Q Max:         " << clusters[i].fMaxQ           << endl;
+        dump << "Q Max:         " << clusters[i].fQMax           << endl;
         spacePointCounter++;
        }
        
index cf01733be852e4d126c201b561d9e6bfe1b89180..12f27e872797b77988314cf6edf71a8dea28f45f 100644 (file)
@@ -81,8 +81,9 @@ AliHLTTPCClusterFinder::AliHLTTPCClusterFinder()
   //constructor  
 }
 
-AliHLTTPCClusterFinder::~AliHLTTPCClusterFinder()
-{
+AliHLTTPCClusterFinder::~AliHLTTPCClusterFinder(){
+  // see header file for class documentation
+  
   //destructor
   if(fVectorInitialized){
     DeInitializePadArray();
@@ -92,16 +93,17 @@ AliHLTTPCClusterFinder::~AliHLTTPCClusterFinder()
     fNumberOfPadsInRow=NULL;
   }
 }
-void AliHLTTPCClusterFinder::InitSlice(Int_t slice,Int_t patch,Int_t firstrow, Int_t lastrow,Int_t nmaxpoints)
-{
+
+void AliHLTTPCClusterFinder::InitSlice(Int_t slice,Int_t patch,Int_t nmaxpoints){
+  // see header file for class documentation
+
   //init slice
   fNClusters = 0;
   fMaxNClusters = nmaxpoints;
   fCurrentSlice = slice;
   fCurrentPatch = patch;
-  fFirstRow = firstrow;
-  fLastRow = lastrow;
+  fFirstRow=AliHLTTPCTransform::GetFirstRow(patch);
+  fLastRow=AliHLTTPCTransform::GetLastRow(patch);
 }
 
 void AliHLTTPCClusterFinder::InitializePadArray(){
@@ -135,9 +137,9 @@ void AliHLTTPCClusterFinder::InitializePadArray(){
   fVectorInitialized=kTRUE;
 }
 
-Int_t AliHLTTPCClusterFinder::DeInitializePadArray()
-{
+Int_t AliHLTTPCClusterFinder::DeInitializePadArray(){
   // see header file for class documentation
+
   for(UInt_t i=0;i<fNumberOfRows;i++){
     for(UInt_t j=0;j<=fNumberOfPadsInRow[i];j++){
       delete fRowPadVector[i][j];
@@ -150,194 +152,473 @@ Int_t AliHLTTPCClusterFinder::DeInitializePadArray()
 } 
 
 
-void AliHLTTPCClusterFinder::InitSlice(Int_t slice,Int_t patch,Int_t nmaxpoints)
-{
-  //init slice
-  fNClusters = 0;
-  fMaxNClusters = nmaxpoints;
-  fCurrentSlice = slice;
-  fCurrentPatch = patch;
-  fFirstRow=AliHLTTPCTransform::GetFirstRow(patch);
-  fLastRow=AliHLTTPCTransform::GetLastRow(patch);
-}
 
-void AliHLTTPCClusterFinder::SetOutputArray(AliHLTTPCSpacePointData *pt)
-{
+void AliHLTTPCClusterFinder::SetOutputArray(AliHLTTPCSpacePointData *pt){
+  // see header file for class documentation
   //set pointer to output
   fSpacePointData = pt;
 }
 
-void AliHLTTPCClusterFinder::Read(void* ptr,unsigned long size){
+
+void AliHLTTPCClusterFinder::ReadDataUnsorted(void* ptr,unsigned long size){
+  // see header file for class documentation
   //set input pointer
   fPtr = (UChar_t*)ptr;
   fSize = size;
-}
-
-void AliHLTTPCClusterFinder::ProcessDigits()
-{
-  int iResult=0;
-  bool readValue = true;
-  Int_t newRow = 0;    
-  Int_t rowOffset = 0;
-  UShort_t time=0,newTime=0;
-  UInt_t pad=0,newPad=0;
-  AliHLTTPCSignal_t charge=0;
-
-  fNClusters = 0;
-
-  // initialize block for reading packed data
-  iResult=fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice);
-  if (iResult<0) return;
-
-  readValue = fDigitReader->Next();
-
-  // Matthias 08.11.2006 the following return would cause termination without writing the
-  // ClusterData and thus would block the component. I just want to have the commented line
-  // here for information
-  //if (!readValue)return;
-
-  pad = fDigitReader->GetPad();
-  time = fDigitReader->GetTime();
-  fCurrentRow = fDigitReader->GetRow();
-
-  if ( fCurrentPatch >= 2 ) // Outer sector, patches 2, 3, 4, 5
-    rowOffset = AliHLTTPCTransform::GetFirstRow( 2 );
-
-  fCurrentRow += rowOffset;
-
-  UInt_t lastpad = 123456789;
-  const UInt_t kPadArraySize=5000;
-  const UInt_t kClusterListSize=10000;
-  AliClusterData *pad1[kPadArraySize]; //2 lists for internal memory=2pads
-  AliClusterData *pad2[kPadArraySize]; //2 lists for internal memory=2pads
-  AliClusterData clusterlist[kClusterListSize]; //Clusterlist
 
-  AliClusterData **currentPt;  //List of pointers to the current pad
-  AliClusterData **previousPt; //List of pointers to the previous pad
-  currentPt = pad2;
-  previousPt = pad1;
-  UInt_t nprevious=0,ncurrent=0,ntotal=0;
-
-  /* quick implementation of baseline calculation and zero suppression
-     open a pad object for each pad and delete it after processing.
-     later a list of pad objects with base line history can be used
-     The whole thing only works if we really get unprocessed raw data, if
-     the data is already zero suppressed, there might be gaps in the time
-     bins.
-   */
-  Int_t gatingGridOffset=50;
-  if(fFirstTimeBin>0){
-    gatingGridOffset=fFirstTimeBin;
+  if(!fVectorInitialized){
+    InitializePadArray();
   }
-  AliHLTTPCPad baseline(gatingGridOffset, AliHLTTPCTransform::GetNTimeBins());
-  // just to make later conversion to a list of objects easier
-  AliHLTTPCPad* pCurrentPad=NULL;
-  /*
-    if (fSignalThreshold>=0) {
-    pCurrentPad=&baseline;
-    baseline.SetThreshold(fSignalThreshold);
+
+  if (fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice)<0) {
+    HLTError("failed setting up digit reader (InitBlock)");
+    return;
   }
-  */
-  while ( readValue!=0 && iResult>=0){   // Reads through all digits in block
-    iResult=0;
+  
+  while(fDigitReader->NextChannel()){
+    UInt_t row=fDigitReader->GetRow();
+    UInt_t pad=fDigitReader->GetPad();
 
-    if(pad != lastpad){
-      //This is a new pad
-      
-      //Switch the lists:
-      if(currentPt == pad2){
-       currentPt = pad1;
-       previousPt = pad2;
-      }
-      else {
-       currentPt = pad2;
-       previousPt = pad1;
-      }
-      nprevious = ncurrent;
-      ncurrent = 0;
-      if(pad != lastpad+1){
-       //this happens if there is a pad with no signal.
-       nprevious = ncurrent = 0;
-      }
-      lastpad = pad;
+    if(row>=fRowPadVector.size()){
+      HLTError("Row number is to large: %d, max is %d",row,fRowPadVector.size()-1);
+      continue;
     }
-
-    Bool_t newcluster = kTRUE;
-    UInt_t seqcharge=0,seqaverage=0,seqerror=0;
-    AliHLTTPCSignal_t lastcharge=0;
-    UInt_t bLastWasFalling=0;
-    Int_t newbin=-1;
-
-
-    if(fDeconvTime){
-      redo: //This is a goto.
-      
-      if(newbin > -1){
-       //bin = newbin;
-       newbin = -1;
-      }
-         
-      lastcharge=0;
-      bLastWasFalling = 0;
+    if(pad>=fRowPadVector[row].size()){
+      HLTError("Pad number is to large: %d, max is %d",pad,fRowPadVector[row].size());
+      continue;
     }
 
-    while(iResult>=0){ //Loop over time bins of current pad
-      // read all the values for one pad at once to calculate the base line
-      if (pCurrentPad) {
-       if (!pCurrentPad->IsStarted()) {
-         //HLTDebug("reading data for pad %d, padrow %d", fDigitReader->GetPad(), fDigitReader->GetRow()+rowOffset);
-         pCurrentPad->SetID(fDigitReader->GetRow()+rowOffset,fDigitReader->GetPad());
-         if ((pCurrentPad->StartEvent())>=0) {
-           do {
-             if ((fDigitReader->GetRow()+rowOffset)!=pCurrentPad->GetRowNumber()) break;
-             if (fDigitReader->GetPad()!=pCurrentPad->GetPadNumber()) break;
-             pCurrentPad->SetRawData(fDigitReader->GetTime(), fDigitReader->GetSignal());
-             //HLTDebug("set raw data to pad: bin %d charge %d", fDigitReader->GetTime(), fDigitReader->GetSignal());
-           } while ((readValue = fDigitReader->Next())!=0);
+    while(fDigitReader->NextBunch()){
+      if(fDigitReader->GetBunchSize()>1){//to remove single timebin values, this will have to change at some point
+       UInt_t time = fDigitReader->GetTime();
+       if((Int_t)time>=fFirstTimeBin && (Int_t)time+fDigitReader->GetBunchSize()<=fLastTimeBin){
+         const UInt_t *bunchData= fDigitReader->GetSignals();
+         AliHLTTPCClusters candidate;
+         for(Int_t i=0;i<fDigitReader->GetBunchSize();i++){
+           candidate.fTotalCharge+=bunchData[i];       
+           candidate.fTime += time*bunchData[i];
+           candidate.fTime2 += time*time*bunchData[i];
+           if(bunchData[i]>candidate.fQMax){
+             candidate.fQMax=bunchData[i];
+           }
+           time++;
          }
-         pCurrentPad->CalculateBaseLine(AliHLTTPCTransform::GetNTimeBins()/2);
-         if (pCurrentPad->Next(kTRUE/*do zero suppression*/)==0) {
-           //HLTDebug("no data available after zero suppression");
-           pCurrentPad->StopEvent();
-           pCurrentPad->ResetHistory();
-           break;
+         if(candidate.fTotalCharge>0){
+           candidate.fMean=candidate.fTime/candidate.fTotalCharge;
+           candidate.fPad=candidate.fTotalCharge*pad;
+           candidate.fPad2=candidate.fPad*pad;
+           candidate.fLastMergedPad=pad;
+           candidate.fRowNumber=row+fDigitReader->GetRowOffset();
          }
-         time=pCurrentPad->GetCurrentPosition();
-         if (time>pCurrentPad->GetSize()) {
-           HLTError("invalid time bin for pad");
-           break;
+         if(fRowPadVector[row][pad] != NULL){
+           fRowPadVector[row][pad]->AddClusterCandidate(candidate);
          }
        }
       }
-      if (pCurrentPad) {
-       Float_t occupancy=pCurrentPad->GetOccupancy();
-       //HLTDebug("pad %d occupancy level: %f", pCurrentPad->GetPadNumber(), occupancy);
-       if ( occupancy < fOccupancyLimit ) {
-         charge = pCurrentPad->GetCorrectedData();
-       } else {
-         charge = 0;
-         //HLTDebug("ignoring pad %d with occupancy level %f", pCurrentPad->GetPadNumber(), occupancy);
-       }
-      } else {
-       charge = fDigitReader->GetSignal();
-      }
-      //HLTDebug("get next charge value: position %d charge %d", time, charge);
+    }
+  }
+}
 
+void AliHLTTPCClusterFinder::ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned long size){
+  // see header file for class documentation
 
-      // CHARGE DEBUG
-      if (fDigitReader->GetRow() == 90){
-/////    LOG(AliHLTTPCLog::kFatal,"AliHLTTPCClusterFinder::Row","row90")  << "PAD=" <<  fDigitReader->GetPad() << "  TIME=" <<  fDigitReader->GetTime() 
-         //                                       << "  SIGNAL=" <<  fDigitReader->GetSignal() << ENDLOG;
+  //set input pointer
+  fPtr = (UChar_t*)ptr;
+  fSize = size;
 
-      }
+  if(!fVectorInitialized){
+    InitializePadArray();
+  }
 
-      if(time >= AliHLTTPCTransform::GetNTimeBins()){
-       HLTWarning("Pad %d: Timebin (%d) out of range (%d)", pad, time, AliHLTTPCTransform::GetNTimeBins());
-       iResult=-ERANGE;
-      }
+  if (fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice)<0) {
+    HLTError("failed setting up digit reader (InitBlock)");
+    return;
+  }
+  
+  while(fDigitReader->NextChannel()){
+    UInt_t row=fDigitReader->GetRow();
+    UInt_t pad=fDigitReader->GetPad();
 
+    while(fDigitReader->NextBunch()){
+      if(fDigitReader->GetBunchSize()>1){//to remove single timebin values, this will have to change at some point
+       UInt_t time = fDigitReader->GetTime();
+       if((Int_t)time>=fFirstTimeBin && (Int_t)time+fDigitReader->GetBunchSize()<=fLastTimeBin){
+         Int_t indexInBunchData=0;
+         Bool_t moreDataInBunch=kFALSE;
+         UInt_t prevSignal=0;
+         Bool_t signalFalling=kFALSE;
+         const UInt_t *bunchData= fDigitReader->GetSignals();
+         do{
+           AliHLTTPCClusters candidate;
+           for(Int_t i=indexInBunchData;i<fDigitReader->GetBunchSize();i++){
+             // Checks if one need to deconvolute the signals
+             if(bunchData[i]>prevSignal && signalFalling==kTRUE){
+               if(i<fDigitReader->GetBunchSize()-1){ // means there are more than one signal left in the bunch
+                 moreDataInBunch=kTRUE;
+                 prevSignal=0;
+               }
+               break;
+             }
+             
+             // Checks if the signal is 0, then quit processing the data.
+             if(bunchData[i]==0 && i<fDigitReader->GetBunchSize()-1){//means we have 0 data fom the rcu, might happen depending on the configuration settings
+               moreDataInBunch=kTRUE;
+               prevSignal=0;
+               break;
+             }
 
-      //Get the current ADC-value
+             if(prevSignal>bunchData[i]){//means the peak of the signal has been reached and deconvolution will happen if the signal rise again.
+               signalFalling=kTRUE;
+             }
+             candidate.fTotalCharge+=bunchData[i];     
+             candidate.fTime += time*bunchData[i];
+             candidate.fTime2 += time*time*bunchData[i];
+             if(bunchData[i]>candidate.fQMax){
+               candidate.fQMax=bunchData[i];
+             }
+
+             prevSignal=bunchData[i];
+             time++;
+             indexInBunchData++;
+           }
+           if(candidate.fTotalCharge>0){
+             candidate.fMean=candidate.fTime/candidate.fTotalCharge;
+             candidate.fPad=candidate.fTotalCharge*pad;
+             candidate.fPad2=candidate.fPad*pad;
+             candidate.fLastMergedPad=pad;
+             candidate.fRowNumber=row+fDigitReader->GetRowOffset();
+           }
+           fRowPadVector[row][pad]->AddClusterCandidate(candidate);
+           if(indexInBunchData<fDigitReader->GetBunchSize()-1){
+             moreDataInBunch=kFALSE;
+           }
+         }while(moreDataInBunch);
+       }
+      }
+    }
+  }
+}
+
+Bool_t AliHLTTPCClusterFinder::ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCClusters* cluster,Int_t nextPadToRead){
+  // see header file for class documentation
+
+  //Checking if we have a match on the next pad
+  for(UInt_t candidateNumber=0;candidateNumber<nextPad->fClusterCandidates.size();candidateNumber++){
+    AliHLTTPCClusters *candidate =&nextPad->fClusterCandidates[candidateNumber]; 
+    if(cluster->fMean-candidate->fMean==1 || candidate->fMean-cluster->fMean==1 || cluster->fMean-candidate->fMean==0){
+      if(fDeconvPad){
+       if(candidate->fTotalCharge<fTotalChargeOfPreviousClusterCandidate){//peak is reached
+         fChargeOfCandidatesFalling=kTRUE;
+       }
+       if(candidate->fTotalCharge>fTotalChargeOfPreviousClusterCandidate && fChargeOfCandidatesFalling==kTRUE){//we have deconvolution
+         return kFALSE;
+       }
+      }
+      cluster->fMean=candidate->fMean;
+      cluster->fTotalCharge+=candidate->fTotalCharge;
+      cluster->fTime += candidate->fTime;
+      cluster->fTime2 += candidate->fTime2;
+      cluster->fPad+=candidate->fPad;
+      cluster->fPad2+=candidate->fPad2;
+      cluster->fLastMergedPad=candidate->fPad;
+      if(candidate->fQMax>cluster->fQMax){
+       cluster->fQMax=candidate->fQMax;
+      }
+      
+      if(fDoPadSelection){
+       UInt_t rowNo = nextPad->GetRowNumber();
+       UInt_t padNo = nextPad->GetPadNumber();
+       if(padNo-1>0){
+         fRowPadVector[rowNo][padNo-2]->fSelectedPad=kTRUE;
+         fRowPadVector[rowNo][padNo-2]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo-2);
+       }
+       fRowPadVector[rowNo][padNo-1]->fSelectedPad=kTRUE;// quick solution to set the first pad to selected
+       fRowPadVector[rowNo][padNo-1]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo-1);
+       fRowPadVector[rowNo][padNo]->fSelectedPad=kTRUE;
+       fRowPadVector[rowNo][padNo]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo);
+      }
+
+      //setting the matched pad to used
+      nextPad->fUsedClusterCandidates[candidateNumber]=1;
+      nextPadToRead++;
+      if(nextPadToRead<(Int_t)fNumberOfPadsInRow[fRowOfFirstCandidate]){
+       nextPad=fRowPadVector[fRowOfFirstCandidate][nextPadToRead];
+       ComparePads(nextPad,cluster,nextPadToRead);
+      }
+      else{
+       return kFALSE;
+      }
+    }
+    else{
+      return kFALSE;
+    }
+  }
+  return kFALSE;
+}
+
+Int_t AliHLTTPCClusterFinder::FillHWAddressList(AliHLTUInt16_t *hwaddlist, Int_t maxHWadd){
+  // see header file for class documentation
+
+  Int_t counter=0;
+  for(UInt_t row=0;row<fNumberOfRows;row++){
+    for(UInt_t pad=0;pad<fNumberOfPadsInRow[row]-1;pad++){
+      if(fRowPadVector[row][pad]->fSelectedPad){
+       if(counter<maxHWadd){
+        hwaddlist[counter]=(AliHLTUInt16_t)fRowPadVector[row][pad]->fHWAddress;
+        counter++;
+       }
+       else{
+        HLTWarning("To many hardwareaddresses, skip adding");
+       }
+       
+      }
+    }
+  }  
+  return counter;
+}
+
+void AliHLTTPCClusterFinder::FindClusters(){
+  // see header file for function documentation
+
+  AliHLTTPCClusters* tmpCandidate=NULL;
+  for(UInt_t row=0;row<fNumberOfRows;row++){
+    fRowOfFirstCandidate=row;
+    for(UInt_t pad=0;pad<fNumberOfPadsInRow[row];pad++){
+      AliHLTTPCPad *tmpPad=fRowPadVector[row][pad];
+      for(size_t candidate=0;candidate<tmpPad->fClusterCandidates.size();candidate++){
+       if(tmpPad->fUsedClusterCandidates[candidate]){
+         continue;
+       }
+       tmpCandidate=&tmpPad->fClusterCandidates[candidate];
+       UInt_t tmpTotalCharge=tmpCandidate->fTotalCharge;
+
+       ComparePads(fRowPadVector[row][pad+1],tmpCandidate,pad+1);
+       if(tmpCandidate->fTotalCharge>tmpTotalCharge){
+         //we have a cluster
+         fClusters.push_back(*tmpCandidate);
+       }
+      }
+      tmpPad->ClearCandidates();
+    }
+    fRowPadVector[row][fNumberOfPadsInRow[row]]->ClearCandidates();
+  }
+
+  HLTInfo("Found %d clusters.",fClusters.size());
+
+  //TODO:  Change so it stores AliHLTTPCSpacePointData directly, instead of this copying
+  
+  AliClusterData * clusterlist = new AliClusterData[fClusters.size()]; //Clusterlist
+  for(unsigned int i=0;i<fClusters.size();i++){
+    clusterlist[i].fTotalCharge = fClusters[i].fTotalCharge;
+    clusterlist[i].fPad = fClusters[i].fPad;
+    clusterlist[i].fPad2 = fClusters[i].fPad2;
+    clusterlist[i].fTime = fClusters[i].fTime;
+    clusterlist[i].fTime2 = fClusters[i].fTime2;
+    clusterlist[i].fMean = fClusters[i].fMean;
+    clusterlist[i].fFlags = fClusters[i].fFlags;
+    clusterlist[i].fChargeFalling = fClusters[i].fChargeFalling;
+    clusterlist[i].fLastCharge = fClusters[i].fLastCharge;
+    clusterlist[i].fLastMergedPad = fClusters[i].fLastMergedPad;
+    clusterlist[i].fRow = fClusters[i].fRowNumber;
+    clusterlist[i].fQMax = fClusters[i].fQMax;
+  }
+
+  WriteClusters(fClusters.size(),clusterlist);
+  delete [] clusterlist;
+  fClusters.clear();
+}
+
+
+//---------------------------------- Under this line the old sorted clusterfinder functions can be found --------------------------------
+
+
+void AliHLTTPCClusterFinder::PrintClusters(){
+  // see header file for class documentation
+
+  for(size_t i=0;i<fClusters.size();i++){
+    HLTInfo("Cluster number: %d",i);
+    HLTInfo("Row: %d \t Pad: %d",fClusters[i].fRowNumber,fClusters[i].fPad/fClusters[i].fTotalCharge);
+    HLTInfo("Total Charge:   %d",fClusters[i].fTotalCharge);
+    HLTInfo("fPad:           %d",fClusters[i].fPad);
+    HLTInfo("PadError:       %d",fClusters[i].fPad2);
+    HLTInfo("TimeMean:       %d",fClusters[i].fTime/fClusters[i].fTotalCharge);
+    HLTInfo("TimeError:      %d",fClusters[i].fTime2);
+    HLTInfo("EndOfCluster:");
+  }
+}
+
+void AliHLTTPCClusterFinder::Read(void* ptr,unsigned long size){
+  //set input pointer
+  fPtr = (UChar_t*)ptr;
+  fSize = size;
+}
+
+void AliHLTTPCClusterFinder::ProcessDigits(){
+  // see header file for class documentation
+
+  int iResult=0;
+  bool readValue = true;
+  Int_t newRow = 0;    
+  Int_t rowOffset = 0;
+  UShort_t time=0,newTime=0;
+  UInt_t pad=0,newPad=0;
+  AliHLTTPCSignal_t charge=0;
+
+  fNClusters = 0;
+
+  // initialize block for reading packed data
+  iResult=fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice);
+  if (iResult<0) return;
+
+  readValue = fDigitReader->Next();
+
+  // Matthias 08.11.2006 the following return would cause termination without writing the
+  // ClusterData and thus would block the component. I just want to have the commented line
+  // here for information
+  //if (!readValue)return;
+
+  pad = fDigitReader->GetPad();
+  time = fDigitReader->GetTime();
+  fCurrentRow = fDigitReader->GetRow();
+
+  if ( fCurrentPatch >= 2 ) // Outer sector, patches 2, 3, 4, 5
+    rowOffset = AliHLTTPCTransform::GetFirstRow( 2 );
+
+  fCurrentRow += rowOffset;
+
+  UInt_t lastpad = 123456789;
+  const UInt_t kPadArraySize=5000;
+  const UInt_t kClusterListSize=10000;
+  AliClusterData *pad1[kPadArraySize]; //2 lists for internal memory=2pads
+  AliClusterData *pad2[kPadArraySize]; //2 lists for internal memory=2pads
+  AliClusterData clusterlist[kClusterListSize]; //Clusterlist
+
+  AliClusterData **currentPt;  //List of pointers to the current pad
+  AliClusterData **previousPt; //List of pointers to the previous pad
+  currentPt = pad2;
+  previousPt = pad1;
+  UInt_t nprevious=0,ncurrent=0,ntotal=0;
+
+  /* quick implementation of baseline calculation and zero suppression
+     open a pad object for each pad and delete it after processing.
+     later a list of pad objects with base line history can be used
+     The whole thing only works if we really get unprocessed raw data, if
+     the data is already zero suppressed, there might be gaps in the time
+     bins.
+   */
+  Int_t gatingGridOffset=50;
+  if(fFirstTimeBin>0){
+    gatingGridOffset=fFirstTimeBin;
+  }
+  AliHLTTPCPad baseline(gatingGridOffset, AliHLTTPCTransform::GetNTimeBins());
+  // just to make later conversion to a list of objects easier
+  AliHLTTPCPad* pCurrentPad=NULL;
+  /*
+    if (fSignalThreshold>=0) {
+    pCurrentPad=&baseline;
+    baseline.SetThreshold(fSignalThreshold);
+  }
+  */
+  while ( readValue!=0 && iResult>=0){   // Reads through all digits in block
+    iResult=0;
+
+    if(pad != lastpad){
+      //This is a new pad
+      
+      //Switch the lists:
+      if(currentPt == pad2){
+       currentPt = pad1;
+       previousPt = pad2;
+      }
+      else {
+       currentPt = pad2;
+       previousPt = pad1;
+      }
+      nprevious = ncurrent;
+      ncurrent = 0;
+      if(pad != lastpad+1){
+       //this happens if there is a pad with no signal.
+       nprevious = ncurrent = 0;
+      }
+      lastpad = pad;
+    }
+
+    Bool_t newcluster = kTRUE;
+    UInt_t seqcharge=0,seqaverage=0,seqerror=0;
+    AliHLTTPCSignal_t lastcharge=0;
+    UInt_t bLastWasFalling=0;
+    Int_t newbin=-1;
+
+
+    if(fDeconvTime){
+      redo: //This is a goto.
+      
+      if(newbin > -1){
+       //bin = newbin;
+       newbin = -1;
+      }
+         
+      lastcharge=0;
+      bLastWasFalling = 0;
+    }
+
+    while(iResult>=0){ //Loop over time bins of current pad
+      // read all the values for one pad at once to calculate the base line
+      if (pCurrentPad) {
+       if (!pCurrentPad->IsStarted()) {
+         //HLTDebug("reading data for pad %d, padrow %d", fDigitReader->GetPad(), fDigitReader->GetRow()+rowOffset);
+         pCurrentPad->SetID(fDigitReader->GetRow()+rowOffset,fDigitReader->GetPad());
+         if ((pCurrentPad->StartEvent())>=0) {
+           do {
+             if ((fDigitReader->GetRow()+rowOffset)!=pCurrentPad->GetRowNumber()) break;
+             if (fDigitReader->GetPad()!=pCurrentPad->GetPadNumber()) break;
+             pCurrentPad->SetRawData(fDigitReader->GetTime(), fDigitReader->GetSignal());
+             //HLTDebug("set raw data to pad: bin %d charge %d", fDigitReader->GetTime(), fDigitReader->GetSignal());
+           } while ((readValue = fDigitReader->Next())!=0);
+         }
+         pCurrentPad->CalculateBaseLine(AliHLTTPCTransform::GetNTimeBins()/2);
+         if (pCurrentPad->Next(kTRUE/*do zero suppression*/)==0) {
+           //HLTDebug("no data available after zero suppression");
+           pCurrentPad->StopEvent();
+           pCurrentPad->ResetHistory();
+           break;
+         }
+         time=pCurrentPad->GetCurrentPosition();
+         if (time>pCurrentPad->GetSize()) {
+           HLTError("invalid time bin for pad");
+           break;
+         }
+       }
+      }
+      if (pCurrentPad) {
+       Float_t occupancy=pCurrentPad->GetOccupancy();
+       //HLTDebug("pad %d occupancy level: %f", pCurrentPad->GetPadNumber(), occupancy);
+       if ( occupancy < fOccupancyLimit ) {
+         charge = pCurrentPad->GetCorrectedData();
+       } else {
+         charge = 0;
+         //HLTDebug("ignoring pad %d with occupancy level %f", pCurrentPad->GetPadNumber(), occupancy);
+       }
+      } else {
+       charge = fDigitReader->GetSignal();
+      }
+      //HLTDebug("get next charge value: position %d charge %d", time, charge);
+
+
+      // CHARGE DEBUG
+      if (fDigitReader->GetRow() == 90){
+/////    LOG(AliHLTTPCLog::kFatal,"AliHLTTPCClusterFinder::Row","row90")  << "PAD=" <<  fDigitReader->GetPad() << "  TIME=" <<  fDigitReader->GetTime() 
+         //                                       << "  SIGNAL=" <<  fDigitReader->GetSignal() << ENDLOG;
+
+      }
+
+      if(time >= AliHLTTPCTransform::GetNTimeBins()){
+       HLTWarning("Pad %d: Timebin (%d) out of range (%d)", pad, time, AliHLTTPCTransform::GetNTimeBins());
+       iResult=-ERANGE;
+      }
+
+
+      //Get the current ADC-value
       if(fDeconvTime){
 
        //Check if the last pixel in the sequence is smaller than this
@@ -524,8 +805,9 @@ void AliHLTTPCClusterFinder::ProcessDigits()
 
 } // ENDEND
 
-void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
-{
+void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list){
+  // see header file for class documentation
+
   //write cluster to output pointer
   Int_t thisrow=-1,thissector=-1;
   UInt_t counter = fNClusters;
@@ -546,427 +828,149 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliClusterData *list)
 
 
 
-      if(fUnsorted){
-       fCurrentRow=list[j].fRow;
-      }
-
-   
-      if(fCalcerr) { //calc the errors, otherwice take the fixed error 
-       Int_t patch = AliHLTTPCTransform::GetPatch(fCurrentRow);
-       UInt_t q2=list[j].fTotalCharge*list[j].fTotalCharge;
-       //      Float_t sy2=list[j].fPad2 * list[j].fTotalCharge - list[j].fPad * list[j].fPad;
-       Float_t sy2=(Float_t)list[j].fPad2 * list[j].fTotalCharge - (Float_t)list[j].fPad * list[j].fPad;
-       sy2/=q2;
-       if(sy2 < 0) {
-           LOG(AliHLTTPCLog::kError,"AliHLTTPCClusterFinder::WriteClusters","Cluster width")
-             <<"SigmaY2 negative "<<sy2<<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
-           continue;
-       } else {
-         if(!fRawSP){
-           fpad2 = (sy2 + 1./12)*AliHLTTPCTransform::GetPadPitchWidth(patch)*AliHLTTPCTransform::GetPadPitchWidth(patch);
-           if(sy2 != 0){
-             fpad2*=0.108; //constants are from offline studies
-             if(patch<2)
-               fpad2*=2.07;
-           }
-         } else fpad2=sy2; //take the width not the error
-       }
-       //      Float_t sz2=list[j].fTime2*list[j].fTotalCharge - list[j].fTime*list[j].fTime;
-       Float_t sz2=(Float_t)list[j].fTime2*list[j].fTotalCharge - (Float_t)list[j].fTime*list[j].fTime;
-       sz2/=q2;
-       if(sz2 < 0){
-         LOG(AliHLTTPCLog::kError,"AliHLTTPCClusterFinder::WriteClusters","Cluster width")
-           <<"SigmaZ2 negative "<<sz2<<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
-         continue;
-       } else {
-         if(!fRawSP){
-           ftime2 = (sz2 + 1./12)*AliHLTTPCTransform::GetZWidth()*AliHLTTPCTransform::GetZWidth();
-           if(sz2 != 0) {
-             ftime2 *= 0.169; //constants are from offline studies
-             if(patch<2)
-               ftime2 *= 1.77;
-           }
-         } else ftime2=sz2; //take the width, not the error
-       }
-      }
-      if(fStdout==kTRUE)
-       HLTInfo("WriteCluster: padrow %d pad %d +- %d time +- %d charge %d",fCurrentRow, fpad, fpad2, ftime, ftime2, list[j].fTotalCharge);
-      
-      if(!fRawSP){
-       AliHLTTPCTransform::Slice2Sector(fCurrentSlice,fCurrentRow,thissector,thisrow);
-       AliHLTTPCTransform::Raw2Local(xyz,thissector,thisrow,fpad,ftime);
-       
-       if(xyz[0]==0) LOG(AliHLTTPCLog::kError,"AliHLTTPCClustFinder","Cluster Finder")
-         <<AliHLTTPCLog::kDec<<"Zero cluster"<<ENDLOG;
-       if(fNClusters >= fMaxNClusters)
-         {
-           LOG(AliHLTTPCLog::kError,"AliHLTTPCClustFinder::WriteClusters","Cluster Finder")
-             <<AliHLTTPCLog::kDec<<"Too many clusters "<<fNClusters<<ENDLOG;
-           return;
-         }  
-       
-       fSpacePointData[counter].fX = xyz[0];
-       //      fSpacePointData[counter].fY = xyz[1];
-       if(fCurrentSlice<18){
-         fSpacePointData[counter].fY = xyz[1];
-       }
-       else{
-         fSpacePointData[counter].fY = -1*xyz[1];
-       }
-       fSpacePointData[counter].fZ = xyz[2];
-
-      } else {
-       fSpacePointData[counter].fX = fCurrentRow;
-       fSpacePointData[counter].fY = fpad;
-       fSpacePointData[counter].fZ = ftime;
-      }
-      
-      fSpacePointData[counter].fCharge = list[j].fTotalCharge;
-      fSpacePointData[counter].fPadRow = fCurrentRow;
-      fSpacePointData[counter].fSigmaY2 = fpad2;
-      fSpacePointData[counter].fSigmaZ2  = ftime2;
-
-      fSpacePointData[counter].fMaxQ = list[j].fQMax;
-
-      fSpacePointData[counter].fUsed = kFALSE;         // only used / set in AliHLTTPCDisplay
-      fSpacePointData[counter].fTrackN = -1;           // only used / set in AliHLTTPCDisplay
-
-      Int_t patch=fCurrentPatch;
-      if(patch==-1) patch=0; //never store negative patch number
-      fSpacePointData[counter].fID = counter
-       +((fCurrentSlice&0x7f)<<25)+((patch&0x7)<<22);//Uli
-
-#ifdef do_mc
-      Int_t trackID[3];
-      GetTrackID((Int_t)rint(fpad),(Int_t)rint(ftime),trackID);
-
-      fSpacePointData[counter].fTrackID[0] = trackID[0];
-      fSpacePointData[counter].fTrackID[1] = trackID[1];
-      fSpacePointData[counter].fTrackID[2] = trackID[2];
-
-#endif
-      
-      fNClusters++;
-      counter++;
-    }
-}
-
-// STILL TO FIX  ----------------------------------------------------------------------------
-
-#ifdef do_mc
-void AliHLTTPCClusterFinder::GetTrackID(Int_t pad,Int_t time,Int_t *trackID)
-{
-  //get mc id
-  AliHLTTPCDigitRowData *rowPt = (AliHLTTPCDigitRowData*)fDigitRowData;
-  
-  trackID[0]=trackID[1]=trackID[2]=-2;
-  for(Int_t i=fFirstRow; i<=fLastRow; i++){
-    if(rowPt->fRow < (UInt_t)fCurrentRow){
-      AliHLTTPCMemHandler::UpdateRowPointer(rowPt);
-      continue;
-    }
-    AliHLTTPCDigitData *digPt = (AliHLTTPCDigitData*)rowPt->fDigitData;
-    for(UInt_t j=0; j<rowPt->fNDigit; j++){
-      Int_t cpad = digPt[j].fPad;
-      Int_t ctime = digPt[j].fTime;
-      if(cpad != pad) continue;
-      if(ctime != time) continue;
-
-      trackID[0] = digPt[j].fTrackID[0];
-      trackID[1] = digPt[j].fTrackID[1];
-      trackID[2] = digPt[j].fTrackID[2];
-      
-      break;
-    }
-    break;
-  }
-}
-#endif
-
-//----------------------------------Methods for the new unsorted way of reading the data --------------------------------
-
-void AliHLTTPCClusterFinder::ReadDataUnsorted(void* ptr,unsigned long size)
-{
-  //set input pointer
-  fPtr = (UChar_t*)ptr;
-  fSize = size;
-
-  if(!fVectorInitialized){
-    InitializePadArray();
-  }
-
-  if (fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice)<0) {
-    HLTError("failed setting up digit reader (InitBlock)");
-    return;
-  }
-  
-  while(fDigitReader->NextChannel()){
-    UInt_t row=fDigitReader->GetRow();
-    UInt_t pad=fDigitReader->GetPad();
-
-    if(row>=fRowPadVector.size()){
-      HLTError("Row number is to large: %d, max is %d",row,fRowPadVector.size()-1);
-      continue;
-    }
-    if(pad>=fRowPadVector[row].size()){
-      HLTError("Pad number is to large: %d, max is %d",pad,fRowPadVector[row].size());
-      continue;
-    }
-
-    while(fDigitReader->NextBunch()){
-      if(fDigitReader->GetBunchSize()>1){//to remove single timebin values, this will have to change at some point
-       UInt_t time = fDigitReader->GetTime();
-       if((Int_t)time>=fFirstTimeBin && (Int_t)time+fDigitReader->GetBunchSize()<=fLastTimeBin){
-         const UInt_t *bunchData= fDigitReader->GetSignals();
-         AliHLTTPCClusters candidate;
-         for(Int_t i=0;i<fDigitReader->GetBunchSize();i++){
-           candidate.fTotalCharge+=bunchData[i];       
-           candidate.fTime += time*bunchData[i];
-           candidate.fTime2 += time*time*bunchData[i];
-           if(bunchData[i]>candidate.fQMax){
-             candidate.fQMax=bunchData[i];
-           }
-           time++;
-         }
-         if(candidate.fTotalCharge>0){
-           candidate.fMean=candidate.fTime/candidate.fTotalCharge;
-           candidate.fPad=candidate.fTotalCharge*pad;
-           candidate.fPad2=candidate.fPad*pad;
-           candidate.fLastMergedPad=pad;
-           candidate.fRowNumber=row+fDigitReader->GetRowOffset();
-         }
-         if(fRowPadVector[row][pad] != NULL){
-           fRowPadVector[row][pad]->AddClusterCandidate(candidate);
-         }
-       }
-      }
-    }
-  }
-}
-
-void AliHLTTPCClusterFinder::ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned long size)
-{
-  //set input pointer
-  fPtr = (UChar_t*)ptr;
-  fSize = size;
-
-  if(!fVectorInitialized){
-    InitializePadArray();
-  }
-
-  if (fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice)<0) {
-    HLTError("failed setting up digit reader (InitBlock)");
-    return;
-  }
-  
-  while(fDigitReader->NextChannel()){
-    UInt_t row=fDigitReader->GetRow();
-    UInt_t pad=fDigitReader->GetPad();
-
-    while(fDigitReader->NextBunch()){
-      if(fDigitReader->GetBunchSize()>1){//to remove single timebin values, this will have to change at some point
-       UInt_t time = fDigitReader->GetTime();
-       if((Int_t)time>=fFirstTimeBin && (Int_t)time+fDigitReader->GetBunchSize()<=fLastTimeBin){
-         Int_t indexInBunchData=0;
-         Bool_t moreDataInBunch=kFALSE;
-         UInt_t prevSignal=0;
-         Bool_t signalFalling=kFALSE;
-         const UInt_t *bunchData= fDigitReader->GetSignals();
-         do{
-           AliHLTTPCClusters candidate;
-           for(Int_t i=indexInBunchData;i<fDigitReader->GetBunchSize();i++){
-             // Checks if one need to deconvolute the signals
-             if(bunchData[i]>prevSignal && signalFalling==kTRUE){
-               if(i<fDigitReader->GetBunchSize()-1){ // means there are more than one signal left in the bunch
-                 moreDataInBunch=kTRUE;
-                 prevSignal=0;
-               }
-               break;
-             }
-             
-             // Checks if the signal is 0, then quit processing the data.
-             if(bunchData[i]==0 && i<fDigitReader->GetBunchSize()-1){//means we have 0 data fom the rcu, might happen depending on the configuration settings
-               moreDataInBunch=kTRUE;
-               prevSignal=0;
-               break;
-             }
-
-             if(prevSignal>bunchData[i]){//means the peak of the signal has been reached and deconvolution will happen if the signal rise again.
-               signalFalling=kTRUE;
-             }
-             candidate.fTotalCharge+=bunchData[i];     
-             candidate.fTime += time*bunchData[i];
-             candidate.fTime2 += time*time*bunchData[i];
-             if(bunchData[i]>candidate.fQMax){
-               candidate.fQMax=bunchData[i];
-             }
-
-             prevSignal=bunchData[i];
-             time++;
-             indexInBunchData++;
-           }
-           if(candidate.fTotalCharge>0){
-             candidate.fMean=candidate.fTime/candidate.fTotalCharge;
-             candidate.fPad=candidate.fTotalCharge*pad;
-             candidate.fPad2=candidate.fPad*pad;
-             candidate.fLastMergedPad=pad;
-             candidate.fRowNumber=row+fDigitReader->GetRowOffset();
-           }
-           fRowPadVector[row][pad]->AddClusterCandidate(candidate);
-           if(indexInBunchData<fDigitReader->GetBunchSize()-1){
-             moreDataInBunch=kFALSE;
-           }
-         }while(moreDataInBunch);
-       }
+      if(fUnsorted){
+       fCurrentRow=list[j].fRow;
       }
-    }
-  }
-}
 
-Bool_t AliHLTTPCClusterFinder::ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCClusters* cluster,Int_t nextPadToRead){
-  //Checking if we have a match on the next pad
-  for(UInt_t candidateNumber=0;candidateNumber<nextPad->fClusterCandidates.size();candidateNumber++){
-    AliHLTTPCClusters *candidate =&nextPad->fClusterCandidates[candidateNumber]; 
-    if(cluster->fMean-candidate->fMean==1 || candidate->fMean-cluster->fMean==1 || cluster->fMean-candidate->fMean==0){
-      if(fDeconvPad){
-       if(candidate->fTotalCharge<fTotalChargeOfPreviousClusterCandidate){//peak is reached
-         fChargeOfCandidatesFalling=kTRUE;
+   
+      if(fCalcerr) { //calc the errors, otherwice take the fixed error 
+       Int_t patch = AliHLTTPCTransform::GetPatch(fCurrentRow);
+       UInt_t q2=list[j].fTotalCharge*list[j].fTotalCharge;
+       //      Float_t sy2=list[j].fPad2 * list[j].fTotalCharge - list[j].fPad * list[j].fPad;
+       Float_t sy2=(Float_t)list[j].fPad2 * list[j].fTotalCharge - (Float_t)list[j].fPad * list[j].fPad;
+       sy2/=q2;
+       if(sy2 < 0) {
+           LOG(AliHLTTPCLog::kError,"AliHLTTPCClusterFinder::WriteClusters","Cluster width")
+             <<"SigmaY2 negative "<<sy2<<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
+           continue;
+       } else {
+         if(!fRawSP){
+           fpad2 = (sy2 + 1./12)*AliHLTTPCTransform::GetPadPitchWidth(patch)*AliHLTTPCTransform::GetPadPitchWidth(patch);
+           if(sy2 != 0){
+             fpad2*=0.108; //constants are from offline studies
+             if(patch<2)
+               fpad2*=2.07;
+           }
+         } else fpad2=sy2; //take the width not the error
        }
-       if(candidate->fTotalCharge>fTotalChargeOfPreviousClusterCandidate && fChargeOfCandidatesFalling==kTRUE){//we have deconvolution
-         return kFALSE;
+       //      Float_t sz2=list[j].fTime2*list[j].fTotalCharge - list[j].fTime*list[j].fTime;
+       Float_t sz2=(Float_t)list[j].fTime2*list[j].fTotalCharge - (Float_t)list[j].fTime*list[j].fTime;
+       sz2/=q2;
+       if(sz2 < 0){
+         LOG(AliHLTTPCLog::kError,"AliHLTTPCClusterFinder::WriteClusters","Cluster width")
+           <<"SigmaZ2 negative "<<sz2<<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
+         continue;
+       } else {
+         if(!fRawSP){
+           ftime2 = (sz2 + 1./12)*AliHLTTPCTransform::GetZWidth()*AliHLTTPCTransform::GetZWidth();
+           if(sz2 != 0) {
+             ftime2 *= 0.169; //constants are from offline studies
+             if(patch<2)
+               ftime2 *= 1.77;
+           }
+         } else ftime2=sz2; //take the width, not the error
        }
       }
-      cluster->fMean=candidate->fMean;
-      cluster->fTotalCharge+=candidate->fTotalCharge;
-      cluster->fTime += candidate->fTime;
-      cluster->fTime2 += candidate->fTime2;
-      cluster->fPad+=candidate->fPad;
-      cluster->fPad2+=candidate->fPad2;
-      cluster->fLastMergedPad=candidate->fPad;
-      if(candidate->fQMax>cluster->fQMax){
-       cluster->fQMax=candidate->fQMax;
-      }
+      if(fStdout==kTRUE)
+       HLTInfo("WriteCluster: padrow %d pad %d +- %d time +- %d charge %d",fCurrentRow, fpad, fpad2, ftime, ftime2, list[j].fTotalCharge);
       
-      if(fDoPadSelection){
-       UInt_t rowNo = nextPad->GetRowNumber();
-       UInt_t padNo = nextPad->GetPadNumber();
-       if(padNo-1>0){
-         fRowPadVector[rowNo][padNo-2]->fSelectedPad=kTRUE;
-         fRowPadVector[rowNo][padNo-2]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo-2);
+      if(!fRawSP){
+       AliHLTTPCTransform::Slice2Sector(fCurrentSlice,fCurrentRow,thissector,thisrow);
+       AliHLTTPCTransform::Raw2Local(xyz,thissector,thisrow,fpad,ftime);
+       
+       if(xyz[0]==0) LOG(AliHLTTPCLog::kError,"AliHLTTPCClustFinder","Cluster Finder")
+         <<AliHLTTPCLog::kDec<<"Zero cluster"<<ENDLOG;
+       if(fNClusters >= fMaxNClusters)
+         {
+           LOG(AliHLTTPCLog::kError,"AliHLTTPCClustFinder::WriteClusters","Cluster Finder")
+             <<AliHLTTPCLog::kDec<<"Too many clusters "<<fNClusters<<ENDLOG;
+           return;
+         }  
+       
+       fSpacePointData[counter].fX = xyz[0];
+       //      fSpacePointData[counter].fY = xyz[1];
+       if(fCurrentSlice<18){
+         fSpacePointData[counter].fY = xyz[1];
        }
-       fRowPadVector[rowNo][padNo-1]->fSelectedPad=kTRUE;// quick solution to set the first pad to selected
-       fRowPadVector[rowNo][padNo-1]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo-1);
-       fRowPadVector[rowNo][padNo]->fSelectedPad=kTRUE;
-       fRowPadVector[rowNo][padNo]->fHWAddress=(AliHLTUInt16_t)fDigitReader->GetAltroBlockHWaddr(rowNo,padNo);
-      }
+       else{
+         fSpacePointData[counter].fY = -1*xyz[1];
+       }
+       fSpacePointData[counter].fZ = xyz[2];
 
-      //setting the matched pad to used
-      nextPad->fUsedClusterCandidates[candidateNumber]=1;
-      nextPadToRead++;
-      if(nextPadToRead<(Int_t)fNumberOfPadsInRow[fRowOfFirstCandidate]){
-       nextPad=fRowPadVector[fRowOfFirstCandidate][nextPadToRead];
-       ComparePads(nextPad,cluster,nextPadToRead);
-      }
-      else{
-       return kFALSE;
+      } else {
+       fSpacePointData[counter].fX = fCurrentRow;
+       fSpacePointData[counter].fY = fpad;
+       fSpacePointData[counter].fZ = ftime;
       }
-    }
-    else{
-      return kFALSE;
-    }
-  }
-  return kFALSE;
-}
+      
+      fSpacePointData[counter].fCharge = list[j].fTotalCharge;
+      fSpacePointData[counter].fPadRow = fCurrentRow;
+      fSpacePointData[counter].fSigmaY2 = fpad2;
+      fSpacePointData[counter].fSigmaZ2  = ftime2;
 
-Int_t AliHLTTPCClusterFinder::FillHWAddressList(AliHLTUInt16_t *hwaddlist, Int_t maxHWadd){
-  Int_t counter=0;
-  for(UInt_t row=0;row<fNumberOfRows;row++){
-    for(UInt_t pad=0;pad<fNumberOfPadsInRow[row]-1;pad++){
-      if(fRowPadVector[row][pad]->fSelectedPad){
-       if(counter<maxHWadd){
-        hwaddlist[counter]=(AliHLTUInt16_t)fRowPadVector[row][pad]->fHWAddress;
-        counter++;
-       }
-       else{
-        HLTWarning("To many hardwareaddresses, skip adding");
-       }
-       
-      }
-    }
-  }  
-  return counter;
-}
+      fSpacePointData[counter].fQMax = list[j].fQMax;
 
-void AliHLTTPCClusterFinder::FindClusters()
-{
-  // see header file for function documentation
+      fSpacePointData[counter].fUsed = kFALSE;         // only used / set in AliHLTTPCDisplay
+      fSpacePointData[counter].fTrackN = -1;           // only used / set in AliHLTTPCDisplay
 
-  AliHLTTPCClusters* tmpCandidate=NULL;
-  for(UInt_t row=0;row<fNumberOfRows;row++){
-    fRowOfFirstCandidate=row;
-    for(UInt_t pad=0;pad<fNumberOfPadsInRow[row];pad++){
-      AliHLTTPCPad *tmpPad=fRowPadVector[row][pad];
-      for(size_t candidate=0;candidate<tmpPad->fClusterCandidates.size();candidate++){
-       if(tmpPad->fUsedClusterCandidates[candidate]){
-         continue;
-       }
-       tmpCandidate=&tmpPad->fClusterCandidates[candidate];
-       UInt_t tmpTotalCharge=tmpCandidate->fTotalCharge;
+      Int_t patch=fCurrentPatch;
+      if(patch==-1) patch=0; //never store negative patch number
+      fSpacePointData[counter].fID = counter
+       +((fCurrentSlice&0x7f)<<25)+((patch&0x7)<<22);//Uli
 
-       ComparePads(fRowPadVector[row][pad+1],tmpCandidate,pad+1);
-       if(tmpCandidate->fTotalCharge>tmpTotalCharge){
-         //we have a cluster
-         fClusters.push_back(*tmpCandidate);
-       }
-      }
-      tmpPad->ClearCandidates();
+#ifdef do_mc
+      Int_t trackID[3];
+      GetTrackID((Int_t)rint(fpad),(Int_t)rint(ftime),trackID);
+
+      fSpacePointData[counter].fTrackID[0] = trackID[0];
+      fSpacePointData[counter].fTrackID[1] = trackID[1];
+      fSpacePointData[counter].fTrackID[2] = trackID[2];
+
+#endif
+      
+      fNClusters++;
+      counter++;
     }
-    fRowPadVector[row][fNumberOfPadsInRow[row]]->ClearCandidates();
-  }
+}
 
-  HLTInfo("Found %d clusters.",fClusters.size());
+// STILL TO FIX  ----------------------------------------------------------------------------
 
-  //TODO:  Change so it stores AliHLTTPCSpacePointData directly, instead of this copying
+#ifdef do_mc
+void AliHLTTPCClusterFinder::GetTrackID(Int_t pad,Int_t time,Int_t *trackID){
+  // see header file for class documentation
+
+  //get mc id
+  AliHLTTPCDigitRowData *rowPt = (AliHLTTPCDigitRowData*)fDigitRowData;
   
-  AliClusterData * clusterlist = new AliClusterData[fClusters.size()]; //Clusterlist
-  for(unsigned int i=0;i<fClusters.size();i++){
-    clusterlist[i].fTotalCharge = fClusters[i].fTotalCharge;
-    clusterlist[i].fPad = fClusters[i].fPad;
-    clusterlist[i].fPad2 = fClusters[i].fPad2;
-    clusterlist[i].fTime = fClusters[i].fTime;
-    clusterlist[i].fTime2 = fClusters[i].fTime2;
-    clusterlist[i].fMean = fClusters[i].fMean;
-    clusterlist[i].fFlags = fClusters[i].fFlags;
-    clusterlist[i].fChargeFalling = fClusters[i].fChargeFalling;
-    clusterlist[i].fLastCharge = fClusters[i].fLastCharge;
-    clusterlist[i].fLastMergedPad = fClusters[i].fLastMergedPad;
-    clusterlist[i].fRow = fClusters[i].fRowNumber;
-    clusterlist[i].fQMax = fClusters[i].fQMax;
+  trackID[0]=trackID[1]=trackID[2]=-2;
+  for(Int_t i=fFirstRow; i<=fLastRow; i++){
+    if(rowPt->fRow < (UInt_t)fCurrentRow){
+      AliHLTTPCMemHandler::UpdateRowPointer(rowPt);
+      continue;
+    }
+    AliHLTTPCDigitData *digPt = (AliHLTTPCDigitData*)rowPt->fDigitData;
+    for(UInt_t j=0; j<rowPt->fNDigit; j++){
+      Int_t cpad = digPt[j].fPad;
+      Int_t ctime = digPt[j].fTime;
+      if(cpad != pad) continue;
+      if(ctime != time) continue;
 
+      trackID[0] = digPt[j].fTrackID[0];
+      trackID[1] = digPt[j].fTrackID[1];
+      trackID[2] = digPt[j].fTrackID[2];
+      
+      break;
+    }
+    break;
   }
-  //  PrintClusters();
-  WriteClusters(fClusters.size(),clusterlist);
-  delete [] clusterlist;
-  fClusters.clear();
 }
+#endif
 
-void AliHLTTPCClusterFinder::PrintClusters()
-{
+
+
+void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *list){//This is used when using the AliHLTTPCClusters class for cluster data
   // see header file for class documentation
-  for(size_t i=0;i<fClusters.size();i++){
-    HLTInfo("Cluster number: %d",i);
-    HLTInfo("Row: %d \t Pad: %d",fClusters[i].fRowNumber,fClusters[i].fPad/fClusters[i].fTotalCharge);
-    HLTInfo("Total Charge:   %d",fClusters[i].fTotalCharge);
-    HLTInfo("fPad:           %d",fClusters[i].fPad);
-    HLTInfo("PadError:       %d",fClusters[i].fPad2);
-    HLTInfo("TimeMean:       %d",fClusters[i].fTime/fClusters[i].fTotalCharge);
-    HLTInfo("TimeError:      %d",fClusters[i].fTime2);
-    HLTInfo("EndOfCluster:");
-  }
-}
 
-void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *list)//This is used when using the AliHLTTPCClusters class for cluster data
-{
   //write cluster to output pointer
   Int_t thisrow,thissector;
   UInt_t counter = fNClusters;
@@ -1056,7 +1060,7 @@ void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *li
       fSpacePointData[counter].fSigmaY2 = fpad2;
       fSpacePointData[counter].fSigmaZ2  = ftime2;
 
-      fSpacePointData[counter].fMaxQ = list[j].fQMax;
+      fSpacePointData[counter].fQMax = list[j].fQMax;
 
       fSpacePointData[counter].fUsed = kFALSE;         // only used / set in AliHLTTPCDisplay
       fSpacePointData[counter].fTrackN = -1;           // only used / set in AliHLTTPCDisplay
index 2796afe0e326a747be6324f906dc34363d98fc94..b5fb2c3576e221634f6de6f562e32865df322cf8 100644 (file)
@@ -122,23 +122,59 @@ class AliHLTTPCClusterFinder : public AliHLTLogging {
 
   /** standard constructor */
   AliHLTTPCClusterFinder();
+
   /** destructor */
   virtual ~AliHLTTPCClusterFinder();
 
-  void Read(void* ptr,unsigned long size);
-
-  void InitSlice(Int_t slice,Int_t patch,Int_t firstrow, Int_t lastrow,Int_t maxpoints);
+  /** Initialize the slice */
   void InitSlice(Int_t slice,Int_t patch,Int_t maxpoints);
-  void ProcessDigits();
 
+  /** Initializes the pad array (vector)*/
+  void InitializePadArray();
+
+  /** Deinitialize the pad array (vector)*/
+  Int_t DeInitializePadArray();
+
+  /** Read the data in unsorted format, storing the clustercandidates */
+  void ReadDataUnsorted(void* ptr,unsigned long size);
+
+  /** Read the data in unsorted format, and deconvolute the signals for each pad in time direction */
+  void ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned long size);
+
+  /** Loops over all rows finding the clusters */
+  void FindClusters();
+
+  /** Compare two neighbouring pads for matching clustercandidates */
+  Bool_t ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCClusters* candidate,Int_t nextPadToRead);
+  
+  /**  Fills the hw address list */
+  Int_t FillHWAddressList(AliHLTUInt16_t *hwaddlist, Int_t maxHWAddress);
+
+  /** Set the pointer to the outputbuffer */
   void SetOutputArray(AliHLTTPCSpacePointData *pt);
+
+  /** Returns the number of clusters */
+  Int_t GetNumberOfClusters() const {return fNClusters;}
+
+  // setters
+  void SetDeconv(Bool_t f) {fDeconvPad=f; fDeconvTime=f;}
+  void SetDeconvPad(Bool_t f) {fDeconvPad=f;}
+  void SetDeconvTime(Bool_t f) {fDeconvTime=f;}
+  void SetUnsorted(Int_t unsorted){fUnsorted=unsorted;}
+  void SetPatch(Int_t patch){fCurrentPatch=patch;}
+  void SetDoPadSelection(Bool_t input){fDoPadSelection=input;}
+  void SetLastTimeBin(Int_t ltb){fLastTimeBin=ltb;}
+  void SetFirstTimeBin(Int_t ftb){fFirstTimeBin=ftb;}
+  void UpdateLastTimeBin(){fLastTimeBin=AliHLTTPCTransform::GetNTimeBins();}
+
+//---------------------------------- Under this line the old sorted clusterfinder functions can be found --------------------------------
+  void Read(void* ptr,unsigned long size);
+  void ProcessDigits();
   void WriteClusters(Int_t n_clusters,AliClusterData *list);
+  void WriteClusters(Int_t nclusters,AliHLTTPCClusters *list);
   void PrintClusters();
   void SetXYError(Float_t f) {fXYErr=f;}
   void SetZError(Float_t f) {fZErr=f;}
-  void SetDeconv(Bool_t f) {fDeconvPad=f; fDeconvTime=f;}
-  void SetDeconvPad(Bool_t f) {fDeconvPad=f;}
-  void SetDeconvTime(Bool_t f) {fDeconvTime=f;}
   void SetThreshold(UInt_t i) {fThreshold=i;}
   void SetOccupancyLimit(Float_t f) {fOccupancyLimit=f;}
   void SetMatchWidth(UInt_t i) {fMatch=i;}
@@ -146,28 +182,6 @@ class AliHLTTPCClusterFinder : public AliHLTLogging {
   void SetCalcErr(Bool_t f=kTRUE) {fCalcerr=f;}
   void SetRawSP(Bool_t f=kFALSE) {fRawSP=f;}
   void SetReader(AliHLTTPCDigitReader* f){fDigitReader = f;}
-  Int_t GetNumberOfClusters() const {return fNClusters;}
-
-  //----------------------------------Methods for the new unsorted way of reading data ----------
-  void ReadDataUnsorted(void* ptr,unsigned long size);
-  void ReadDataUnsortedDeconvoluteTime(void* ptr,unsigned long size);
-  void FindClusters();
-  void WriteClusters(Int_t nclusters,AliHLTTPCClusters *list);
-  void SetUnsorted(Int_t unsorted){fUnsorted=unsorted;}
-  void SetPatch(Int_t patch){fCurrentPatch=patch;}
-  void InitializePadArray();
-  Int_t DeInitializePadArray();
-  Bool_t ComparePads(AliHLTTPCPad *nextPad,AliHLTTPCClusters* candidate,Int_t nextPadToRead);
-
-  void SetDoPadSelection(Bool_t input){fDoPadSelection=input;}
-  
-  Int_t FillHWAddressList(AliHLTUInt16_t *hwaddlist, Int_t maxHWAddress);
-
-  void UpdateLastTimeBin(){fLastTimeBin=AliHLTTPCTransform::GetNTimeBins();}
-
-  void SetLastTimeBin(Int_t ltb){fLastTimeBin=ltb;}
-
-  void SetFirstTimeBin(Int_t ftb){fFirstTimeBin=ftb;}
   
   vector<AliHLTUInt16_t> fClustersHWAddressVector;  //! transient
   
@@ -184,32 +198,32 @@ class AliHLTTPCClusterFinder : public AliHLTLogging {
   AliHLTTPCSpacePointData *fSpacePointData; //! array of space points
   AliHLTTPCDigitReader *fDigitReader;       //! reader instance
 
-  UChar_t* fPtr;   //! pointer to packed block
-  unsigned long fSize; //packed block size
-  Bool_t fDeconvTime;  //deconv in time direction
-  Bool_t fDeconvPad;  //deconv in pad direction
-  Bool_t fStdout;     //have print out in write clusters
-  Bool_t fCalcerr;    //calculate centroid sigmas
-  Bool_t fRawSP;      //store centroids in raw system
-
-
-  Int_t fFirstRow;       //first row
-  Int_t fLastRow;        //last row
-  Int_t fCurrentRow;     //current active row
-  Int_t fCurrentSlice;   //current slice
-  Int_t fCurrentPatch;   //current patch
-  Int_t fMatch;          //size of match
-  UInt_t fThreshold;     //threshold for clusters
-  Int_t fNClusters;      //number of found clusters
-  Int_t fMaxNClusters;   //max. number of clusters
-  Float_t fXYErr;        //fixed error in XY
-  Float_t fZErr;         //fixed error in Z
+  UChar_t* fPtr;           //! pointer to packed block
+  unsigned long fSize;     //! packed block size
+  Bool_t fDeconvTime;      //! deconv in time direction
+  Bool_t fDeconvPad;       //! deconv in pad direction
+  Bool_t fStdout;          //! have print out in write clusters
+  Bool_t fCalcerr;         //! calculate centroid sigmas
+  Bool_t fRawSP;           //! store centroids in raw system
+
+
+  Int_t fFirstRow;       //first row
+  Int_t fLastRow;        //last row
+  Int_t fCurrentRow;     //current active row
+  Int_t fCurrentSlice;   //current slice
+  Int_t fCurrentPatch;   //current patch
+  Int_t fMatch;          //size of match
+  UInt_t fThreshold;     //threshold for clusters
+  Int_t fNClusters;      //number of found clusters
+  Int_t fMaxNClusters;   //max. number of clusters
+  Float_t fXYErr;        //fixed error in XY
+  Float_t fZErr;         //fixed error in Z
   
-  Float_t fOccupancyLimit; // Occupancy Limit
-
-  Int_t fUnsorted;       // enable for processing of unsorted digit data
-  Bool_t fVectorInitialized;
+  Float_t fOccupancyLimit;    //! Occupancy Limit
 
+  Int_t fUnsorted;            //! enable for processing of unsorted digit data
+  Bool_t fVectorInitialized;  //! flag to check if pad vector is initialized
   vector<AliHLTTPCClusters> fClusters;                             //! transient
   
   UInt_t* fNumberOfPadsInRow;                                      //! transient
index 8ee19d4d4c663aae9594f28e7d14ad66d8e10bcc..e19425498da60452b0b87ce9103ab6f3f79a0490 100644 (file)
@@ -86,9 +86,6 @@ const char* AliHLTTPCClusterFinderComponent::GetComponentID()
   case kClusterFinderPacked:
     return "TPCClusterFinderPacked";
     break;
-  case kClusterFinderUnpacked:
-    return "TPCClusterFinderUnpacked";
-    break;
   case kClusterFinderDecoder:
     return "TPCClusterFinderDecoder";
     break;
@@ -105,9 +102,6 @@ void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentD
   case kClusterFinderPacked:
     list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
     break;
-  case kClusterFinderUnpacked:
-    list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );
-    break;
   case kClusterFinderDecoder:
     list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
     break;
@@ -162,24 +156,13 @@ int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
 
   fClusterFinder = new AliHLTTPCClusterFinder();
 
-  //  Int_t sigthresh = -1;
-  //  Double_t sigmathresh= -1;
   Float_t occulimit = 1.0;
-  //  Int_t oldRCUFormat=0;
-  // Data Format version numbers:
-  // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
-  // 1: As 0, but pads/padrows are delivered "as is", without sorting
-  // 2: As 0, but RCU trailer is 3 32 bit words.
-  // 3: As 1, but RCU trailer is 3 32 bit words.
-  // -1: use offline raw reader
 
   Int_t i = 0;
   Char_t* cpErr;
 
   while ( i < argc ) {      
 
-
-
     // -- deconvolute-time option
     if ( !strcmp( argv[i], "-deconvolute-time" ) ) {
       fDeconvTime = kTRUE;
@@ -284,7 +267,6 @@ int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
       continue;
     }
 
-
     // -- raw reader mode option
     if ( !strcmp( argv[i], "rawreadermode" ) ) {
       if ( argc <= i+1 ) {
@@ -298,7 +280,6 @@ int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
       continue;
     }
 
-
     // -- pp-run option
     if ( !strcmp( argv[i], "pp-run") ) {
       HLTWarning("Argument 'pp-run' is obsolete, deconvolution is swiched off in both time and pad directions by default.");
@@ -319,7 +300,6 @@ int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
       continue;
     }
 
-
     // -- checking for rcu format
     if ( !strcmp( argv[i], "oldrcuformat" ) ) {
       strtoul( argv[i+1], &cpErr ,0);
@@ -379,24 +359,9 @@ int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
   if (fModeSwitch==kClusterFinderPacked) {
       HLTDebug("using AliHLTTPCDigitReaderPacked");
       fReader = new AliHLTTPCDigitReaderPacked();
-      /*
-       if(oldRCUFormat==1){
-       fReader->SetOldRCUFormat(kTRUE);
-       }
-       else if(oldRCUFormat!=0){
-       HLTWarning("Wrong oldrcuformat specifier %d; oldrcuformat set to default(kFALSE)",oldRCUFormat);
-       }
-      */
-      if(fUnsorted==1){
-       fReader->SetUnsorted(kTRUE);
-      }
+      if(fUnsorted==1){        fReader->SetUnsorted(kTRUE); }
       fClusterFinder->SetReader(fReader);
   }
-  else if(fModeSwitch==kClusterFinderUnpacked){
-    HLTDebug("using AliHLTTPCDigitReaderUnpacked");
-    fReader = new AliHLTTPCDigitReaderUnpacked();
-    fClusterFinder->SetReader(fReader);
-  }
   else if(fModeSwitch==kClusterFinderDecoder){
     HLTDebug("using AliHLTTPCDigitReaderDecoder");
     fReader = new AliHLTTPCDigitReaderDecoder();
@@ -420,8 +385,6 @@ int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
   if ( (fXYClusterError>0) && (fZClusterError>0) ){
     fClusterFinder->SetCalcErr( false );
   }
-  //  fClusterFinder->SetSignalThreshold(sigthresh);
-  //  fClusterFinder->SetNSigmaThreshold(sigmathresh);
 
   if(fFirstTimeBin>0){
     fClusterFinder->SetFirstTimeBin(fFirstTimeBin);
@@ -456,6 +419,12 @@ int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& ev
 {
   // see header file for class documentation
 
+  if(fReader == NULL){
+    HLTFatal("Digit reader not initialized, aborting event.");
+    size=0;
+    return 0;    
+  }
+
   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
     size=0;
     return 0;
@@ -474,7 +443,7 @@ int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& ev
   outBPtr = outputPtr;
   outPtr = (AliHLTTPCClusterData*)outBPtr;
 
-  Int_t slice, patch, row[2];
+  Int_t slice, patch;
   unsigned long maxPoints, realPoints = 0;
 
   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
@@ -502,20 +471,16 @@ int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& ev
 
       }
       else if(fModeSwitch==1){
+       HLTWarning("Unpacked data type depreciated, block aborted");
        HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
                 evtData.fEventID, evtData.fEventID, 
                 DataType2Text( iter->fDataType).c_str(), 
                 DataType2Text(AliHLTTPCDefinitions::fgkUnpackedRawDataType).c_str());
-
-       if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
-
+       continue;
       }
 
       slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
       patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
-      row[0] = AliHLTTPCTransform::GetFirstRow( patch );
-      row[1] = AliHLTTPCTransform::GetLastRow( patch );
-
 
       if(fUnsorted){
        fClusterFinder->SetUnsorted(fUnsorted);
@@ -526,14 +491,13 @@ int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& ev
 
       maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
 
-      fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
+      fClusterFinder->InitSlice( slice, patch, maxPoints );
       fClusterFinder->SetOutputArray( (AliHLTTPCSpacePointData*)outPtr->fSpacePoints );
        
       if(fUnsorted){
        if(fGetActivePads){
          fClusterFinder->SetDoPadSelection(kTRUE);
-       }
-       
+       }       
        if(fDeconvTime){
          fClusterFinder->ReadDataUnsortedDeconvoluteTime(iter->fPtr, iter->fSize);
        }
@@ -547,6 +511,7 @@ int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& ev
        fClusterFinder->Read(iter->fPtr, iter->fSize );
        fClusterFinder->ProcessDigits();
       }
+
       realPoints = fClusterFinder->GetNumberOfClusters();
        
       outPtr->fSpacePointCnt = realPoints;
@@ -555,14 +520,13 @@ int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& ev
 
       Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints", 
               "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
-              realPoints, slice, patch, row[0], row[1] );
+              realPoints, slice, patch,AliHLTTPCTransform::GetFirstRow( patch ) , AliHLTTPCTransform::GetLastRow( patch ) );
       AliHLTComponentBlockData bd;
       FillBlockData( bd );
       bd.fOffset = offset;
       bd.fSize = mysize;
       bd.fSpecification = iter->fSpecification;
       bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
-      //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
       outputBlocks.push_back( bd );
        
       tSize += mysize;
index f9460412b22db12fa308a3a0777cd35f57011658..3d72260da0316469b52b4add0774e2ce4bc45133 100644 (file)
@@ -209,15 +209,15 @@ int AliHLTTPCClusterHistoComponent::DoEvent(const AliHLTComponentEventData& /*ev
        
       }
       if(fPlotQmaxPartAll){
-       if(clusters[i].fMaxQ>tmpQPart){
-         fQMaxPartitionAll->SetBinContent(patch+6*slice,clusters[i].fMaxQ);
-         tmpQPart=clusters[i].fMaxQ;
+       if(clusters[i].fQMax>tmpQPart){
+         fQMaxPartitionAll->SetBinContent(patch+6*slice,clusters[i].fQMax);
+         tmpQPart=clusters[i].fQMax;
        }
       }
       if(fPlotQmaxROCAll){
-       if(clusters[i].fMaxQ>fQMaxROCAll->GetBinContent(thissector)){
-         fQMaxROCAll->SetBinContent(thissector,clusters[i].fMaxQ);
-         //      tmpQROC=clusters[i].fMaxQ;
+       if(clusters[i].fQMax>fQMaxROCAll->GetBinContent(thissector)){
+         fQMaxROCAll->SetBinContent(thissector,clusters[i].fQMax);
+         //      tmpQROC=clusters[i].fQMax;
        }
       }
     }
diff --git a/HLT/TPCLib/AliHLTTPCHWCFDataReverterComponent.cxx b/HLT/TPCLib/AliHLTTPCHWCFDataReverterComponent.cxx
new file mode 100755 (executable)
index 0000000..f8f807f
--- /dev/null
@@ -0,0 +1,411 @@
+/**************************************************************************
+ * This file is property of and copyright by the ALICE HLT Project        * 
+ * ALICE Experiment at CERN, All rights reserved.                         *
+ *                                                                        *
+ * Primary Authors: Kenneth Aamodt <Kenneth.Aamodt@student.uib.no>        *
+ *                  for The ALICE HLT Project.                            *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCHWCFDataReverterComponent.cxx
+    @author Kenneth Aamodt
+    @date   
+    @brief  Component for reverting data for the HW clusterfinder
+*/
+
+// see header file for class documentation                                   //
+// or                                                                        //
+// refer to README to build package                                          //
+// or                                                                        //
+// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt                          //
+
+#if __GNUC__>= 3
+using namespace std;
+#endif
+#include "AliHLTTPCHWCFDataReverterComponent.h"
+#include "AliHLTTPCDigitReaderDecoder.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCDefinitions.h"
+#include "AliHLTTPCDigitData.h"
+#include "AliHLTTPCMapping.h"
+#include <cstdlib>
+#include <cerrno>
+#include <cassert>
+#include "TString.h"
+#include <sys/time.h>
+#include "AliHLTAltroEncoder.h"
+#include "AliRawDataHeader.h"
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTTPCHWCFDataReverterComponent)
+
+  AliHLTTPCHWCFDataReverterComponent::AliHLTTPCHWCFDataReverterComponent()
+    :
+    fDigitReader(NULL),
+    fRowPadVector(),
+    fNumberOfPadsInRow(NULL),
+    fFirstPadHigh(NULL),
+    fNumberOfRows(0),
+    fCurrentPatch(0),
+    fFirstRow(0),
+    fLastRow(0),
+    fNTimeBins(0),
+    fVectorInitialized(kFALSE),
+    fMapping(NULL)
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+}
+
+AliHLTTPCHWCFDataReverterComponent::~AliHLTTPCHWCFDataReverterComponent()
+{
+  // see header file for class documentation
+  if(fVectorInitialized){
+    DeInitializePadArray();
+  }
+  if(fNumberOfPadsInRow){
+    delete [] fNumberOfPadsInRow;
+    fNumberOfPadsInRow=NULL;
+  }
+  if(fFirstPadHigh){
+    delete [] fFirstPadHigh;
+    fFirstPadHigh=NULL;
+  }
+  if(fDigitReader){
+    delete fDigitReader;
+    fDigitReader=NULL;
+  }
+  if(fMapping){
+    delete fMapping;
+    fMapping = NULL;
+  }
+}
+
+// Public functions to implement AliHLTComponent's interface.
+// These functions are required for the registration process
+
+const char* AliHLTTPCHWCFDataReverterComponent::GetComponentID()
+{
+  // see header file for class documentation
+  return "TPCHWCFDataReverter";
+}
+
+void AliHLTTPCHWCFDataReverterComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
+{
+  // see header file for class documentation
+  list.clear(); 
+  list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
+}
+
+AliHLTComponentDataType AliHLTTPCHWCFDataReverterComponent::GetOutputDataType()
+{
+  // see header file for class documentation
+  return kAliHLTDataTypeDDLRaw;
+}
+
+int AliHLTTPCHWCFDataReverterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
+{
+  // see header file for class documentation
+  tgtList.clear();
+  tgtList.push_back(kAliHLTDataTypeDDLRaw);
+  return tgtList.size();
+}
+
+void AliHLTTPCHWCFDataReverterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+{
+  // see header file for class documentation
+  constBase=0;
+  inputMultiplier=1.0;
+}
+
+AliHLTComponent* AliHLTTPCHWCFDataReverterComponent::Spawn()
+{
+  // see header file for class documentation
+  return new AliHLTTPCHWCFDataReverterComponent();
+}
+       
+int AliHLTTPCHWCFDataReverterComponent::DoInit( int argc, const char** argv )
+{
+  // see header file for class documentation
+
+  Int_t i = 0;
+  Char_t* cpErr;
+
+  while ( i < argc ) {      
+
+    // -- number of timebins
+    if ( !strcmp( argv[i], "-timebins" )) {
+      fNTimeBins = strtoul( argv[i+1], &cpErr ,0);
+      AliHLTTPCTransform::SetNTimeBins(fNTimeBins);
+      if ( *cpErr ) {
+       HLTError("Cannot convert ntimebins specifier '%s'.", argv[i+1]);
+       return EINVAL;
+      }
+      i+=2;
+      continue;
+    }
+     
+    HLTError("HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
+
+    return EINVAL;
+  }
+
+  HLTDebug("using AliHLTTPCDigitReaderDecoder");
+  fDigitReader = new AliHLTTPCDigitReaderDecoder();
+
+  return 0;
+}
+
+int AliHLTTPCHWCFDataReverterComponent::DoDeinit()
+{
+  // see header file for class documentation
+  return 0;
+}
+
+Int_t AliHLTTPCHWCFDataReverterComponent::DeInitializePadArray()
+{
+  // see header file for class documentation
+  if(fVectorInitialized){
+    for(Int_t i=0;i<fNumberOfRows;i++){
+      for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
+       delete fRowPadVector[i][j];
+       fRowPadVector[i][j]=NULL;
+      }
+      fRowPadVector[i].clear();
+    }
+    fRowPadVector.clear();
+  }
+  return 1;
+} 
+
+void AliHLTTPCHWCFDataReverterComponent::InitializePadArray(){
+  // see header file for class documentation
+  if(fCurrentPatch>5){
+    HLTFatal("Patch is not set");
+    return;
+  }
+
+  fFirstRow = AliHLTTPCTransform::GetFirstRow(fCurrentPatch);
+  fLastRow = AliHLTTPCTransform::GetLastRow(fCurrentPatch);
+
+  fNumberOfRows=fLastRow-fFirstRow+1;
+  fNumberOfPadsInRow= new Int_t[fNumberOfRows];
+  fFirstPadHigh= new Int_t[fNumberOfRows];
+
+  memset( fNumberOfPadsInRow, 0, sizeof(Int_t)*(fNumberOfRows));
+  memset( fFirstPadHigh, 0, sizeof(Int_t)*(fNumberOfRows));
+
+  for(Int_t i=0;i<fNumberOfRows;i++){
+    fNumberOfPadsInRow[i]=AliHLTTPCTransform::GetNPads(i+fFirstRow);
+    AliHLTTPCPadVector tmpRow;
+    for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
+      AliHLTTPCPad *tmpPad = new AliHLTTPCPad();
+      if(fFirstPadHigh[i] != 0){
+       if(fMapping->GetHwAddress(i,j) > 2047){
+         fFirstPadHigh[i]=j;
+       }
+      }
+      tmpPad->SetID(i,j);
+      tmpRow.push_back(tmpPad);
+    }
+    fRowPadVector.push_back(tmpRow);
+  }
+  fVectorInitialized=kTRUE;
+}
+
+
+int AliHLTTPCHWCFDataReverterComponent::DoEvent( const AliHLTComponentEventData& evtData, 
+                                                const AliHLTComponentBlockData* blocks, 
+                                                AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
+                                                AliHLTUInt32_t& size, 
+                                                vector<AliHLTComponentBlockData>& outputBlocks )
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (!fDigitReader) return -ENODEV;
+
+  AliHLTUInt32_t capacity=size;
+  size=0;
+  if (!IsDataEvent()) return 0;
+
+  //  == init iter (pointer to datablock)
+  const AliHLTComponentBlockData* iter = NULL;
+  unsigned long ndx;
+
+  //reading the data
+  for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ){
+
+    iter = blocks+ndx;
+      
+    HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
+            evtData.fEventID, evtData.fEventID, 
+            DataType2Text( iter->fDataType).c_str(), 
+            DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
+
+    if ( iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC)){
+      continue;
+    }
+
+    if (iter->fSize<=sizeof(AliRawDataHeader)) {
+      // forward empty DDLs
+      outputBlocks.push_back(*iter);
+      continue;
+    }
+
+    UInt_t slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
+    UInt_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
+
+    if(fDigitReader->InitBlock(iter->fPtr,iter->fSize,patch,slice)<0){
+      HLTWarning("Decoder failed to initialize, event aborted.");
+      continue;
+    }
+      
+    fMapping = new AliHLTTPCMapping(patch);
+
+    if(!fVectorInitialized){
+      fCurrentPatch=patch;
+      InitializePadArray();
+    }
+
+    //Here the reading of the data and the zerosuppression takes place
+    while(fDigitReader->NextChannel()){//Pad
+
+      Int_t row=fDigitReader->GetRow();
+      Int_t pad=fDigitReader->GetPad();
+
+      if(row >= fNumberOfRows || row < 0){
+       continue;
+      }
+      else if(pad >= fNumberOfPadsInRow[row] || pad < 0){
+       continue;
+      }  
+       
+      AliHLTTPCPad *tmpPad = fRowPadVector[row][pad];
+      if (tmpPad){
+       tmpPad->SetDataToDefault();
+      }
+       
+      //reading data to pad
+      while(fDigitReader->NextBunch()){
+       const UInt_t *bunchData= fDigitReader->GetSignals();
+       Int_t time=fDigitReader->GetTime();
+       for(Int_t i=0;i<fDigitReader->GetBunchSize();i++){
+         if(bunchData[i]>0){// disregarding 0 data.
+           if(time+i >= 0 && time+i < AliHLTTPCTransform::GetNTimeBins()){
+             if (tmpPad){
+               tmpPad->SetDataSignal(time+i,bunchData[i]);
+             }
+           }
+         }
+       }
+      }
+    }
+
+    if( iter->fSize > sizeof(AliRawDataHeader )){
+  
+      AliHLTAltroEncoder *altroEncoder = new AliHLTAltroEncoder;
+      altroEncoder->SetBuffer(outputPtr,capacity); //tests if one overwrite the buffer is done in the encoder
+
+      // set CDH from the beginning of buffer
+      altroEncoder->SetCDH((AliHLTUInt8_t*)iter->fPtr,sizeof(AliRawDataHeader));
+
+      UChar_t *RCUTrailer=NULL;
+      Int_t RCUTrailerSize=fDigitReader->GetRCUTrailerSize();
+      if (RCUTrailerSize<=0 || !fDigitReader->GetRCUTrailerData( RCUTrailer )) {
+       if(RCUTrailer==NULL){
+         HLTWarning("can not find RCU trailer for data block %s 0x%08x: skipping data block",
+                    DataType2Text(iter->fDataType).c_str(), iter->fSpecification);
+         continue;
+       }
+      }
+      altroEncoder->SetRCUTrailer(RCUTrailer, RCUTrailerSize);
+
+      for(Int_t row = 0; row< fNumberOfRows;row++){
+       Int_t padHigh=fFirstPadHigh[row];
+
+       Int_t padLowIndex=0;
+       Int_t padHighIndex= padHigh;
+         
+       while(padLowIndex < padHigh || padHighIndex < fNumberOfPadsInRow[row]){
+         Int_t currentTime = 0;
+         Int_t bunchSize = 0;
+         //add the data from low side
+         if(padLowIndex < padHigh){
+           AliHLTTPCPad * lowPad= fRowPadVector[row][padLowIndex];
+           while(lowPad->GetNextGoodSignal(currentTime, bunchSize)){
+             for(Int_t i=0;i<bunchSize;i++){
+               if (altroEncoder->AddSignal((AliHLTUInt16_t)(lowPad->GetDataSignal(currentTime+i)),(AliHLTUInt16_t)(currentTime+i))<0) {
+                 HLTWarning("can not add channel: slice %d, partition %d, hw address %d, row %d, pad %d, time %d, bunch size %d",
+                            slice, patch, fMapping->GetHwAddress(row,padLowIndex), row, padLowIndex, currentTime+i, bunchSize);
+                 break;
+               }
+             }
+           }
+           altroEncoder->SetChannel(fMapping->GetHwAddress(row,padLowIndex));
+         }
+         currentTime = 0;
+         bunchSize = 0;
+         //add the data from the high side
+         if(padHighIndex < fNumberOfPadsInRow[row]){
+           AliHLTTPCPad * highPad= fRowPadVector[row][padHighIndex];
+           while(highPad->GetNextGoodSignal(currentTime, bunchSize)){
+             for(Int_t i=0;i<bunchSize;i++){
+               if (altroEncoder->AddSignal((AliHLTUInt16_t)(highPad->GetDataSignal(currentTime+i)),(AliHLTUInt16_t)(currentTime+i))<0) {
+                 HLTWarning("can not add channel: slice %d, partition %d, hw address %d, row %d, pad %d, time %d, bunch size %d",
+                            slice, patch, fMapping->GetHwAddress(row,padHighIndex), row, padHighIndex, currentTime+i, bunchSize);
+                 break;
+               }
+             }
+           }
+           altroEncoder->SetChannel(fMapping->GetHwAddress(row,padHighIndex));
+         }
+         padLowIndex++;
+         padHighIndex++;
+       }
+      }
+       
+      altroEncoder->Revert40BitWords(sizeof(AliRawDataHeader),RCUTrailerSize);
+
+      int sizeOfData=altroEncoder->SetLength();
+
+      if (sizeOfData<0) {
+       HLTError("data encoding failed");
+       iResult=sizeOfData;
+       break;
+      }
+      if(sizeOfData>(int)capacity){
+       HLTWarning("Buffer too small too add the altrodata: %d of %d byte(s) already used", sizeOfData, capacity);
+       iResult=-ENOSPC;
+       break;
+      }
+
+      AliHLTComponentBlockData bd;
+      FillBlockData( bd );
+      bd.fOffset = 0;
+      bd.fSize = sizeOfData;
+      bd.fDataType = kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC;
+      bd.fSpecification = iter->fSpecification;
+      outputBlocks.push_back( bd );
+
+      size+=sizeOfData;
+    }
+    fDigitReader->Reset();
+  }
+  
+  if(iResult < 0) {
+    fDigitReader->Reset();
+    size=0;
+  }
+  HLTDebug("Total size of output is: %d ",size);
+  return iResult;
+}
diff --git a/HLT/TPCLib/AliHLTTPCHWCFDataReverterComponent.h b/HLT/TPCLib/AliHLTTPCHWCFDataReverterComponent.h
new file mode 100755 (executable)
index 0000000..f8fde33
--- /dev/null
@@ -0,0 +1,121 @@
+// XEmacs -*-C++-*-
+
+#ifndef ALIHLTTPCHWCFDATAREVERTERCOMPONENT_H
+#define ALIHLTTPCHWCFDATAREVERTERCOMPONENT_H
+
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//* See cxx source for full Copyright notice                               *
+
+/** @file   AliHLTTPCHWCFDataReverterComponent.h
+    @author Kenneth Aamodt
+    @date   
+    @brief  Component for reverting data for the HW clusterfinder
+*/
+
+#include "AliHLTProcessor.h"
+#include "AliHLTTPCPad.h"
+#include "AliHLTDataTypes.h"
+
+class AliHLTTPCDigitReader;
+class AliHLTTPCMapping;
+
+/**
+ * @class AliHLTTPCHWCFDataReverterComponent
+ * Implementation of the zero suppression component.
+ * The component implements the interface methods of the @ref AliHLTProcessor.
+ *
+ * The component orders the data in the format the Hardware ClusterFinder 
+ * expects, and revert the 40 bit altro words.
+ * 
+ * The component has the following component arguments:
+ *
+ * @ingroup alihlt_tpc_components
+ */
+class AliHLTTPCHWCFDataReverterComponent : public AliHLTProcessor
+    {
+    public:
+        /** constructor */
+       AliHLTTPCHWCFDataReverterComponent();
+       /** destructor */
+       virtual ~AliHLTTPCHWCFDataReverterComponent();
+
+       // Public functions to implement AliHLTComponent's interface.
+       // These functions are required for the registration process
+
+  /** interface function, see AliHLTComponent for description */
+  const char* GetComponentID();
+  /** interface function, see AliHLTComponent for description */
+  void GetInputDataTypes( vector<AliHLTComponentDataType>& list);
+  /** interface function, see AliHLTComponent for description */
+  AliHLTComponentDataType GetOutputDataType();
+  /** interface function, see AliHLTComponent for description */
+  int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
+  /** interface function, see AliHLTComponent for description */
+  virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+  /** interface function, see AliHLTComponent for description */
+  AliHLTComponent* Spawn();
+
+      Int_t DeInitializePadArray();
+      void InitializePadArray();
+      
+    protected:
+       
+       // Protected functions to implement AliHLTComponent's interface.
+       // These functions provide initialization as well as the actual processing
+       // capabilities of the component. 
+
+       int DoInit( int argc, const char** argv );
+       int DoDeinit();
+        int DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
+                    AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
+                    AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks );
+       using AliHLTProcessor::DoEvent;
+
+    private:
+
+      /** copy constructor prohibited */
+      AliHLTTPCHWCFDataReverterComponent(const AliHLTTPCHWCFDataReverterComponent&);
+       
+      /** assignment operator prohibited */
+      AliHLTTPCHWCFDataReverterComponent& operator=(const AliHLTTPCHWCFDataReverterComponent&);
+       
+      /** the reader object for data decoding */
+      AliHLTTPCDigitReader* fDigitReader;                              //!transient
+
+      /** Vector of pointers to pad objects */
+      typedef vector<AliHLTTPCPad*> AliHLTTPCPadVector;
+      
+      /** 2D vector of pointers to pad objects (vector of vectors)*/
+      vector<AliHLTTPCPadVector> fRowPadVector;                        //! transient
+      
+      /** Array containing number of pads in the different rows */
+      Int_t* fNumberOfPadsInRow;                                      //! transient
+      
+      /** Array containing the index f forst pad on row with hwaddress > 2048 */
+      Int_t* fFirstPadHigh;                                      //! transient
+
+      /** Number of rows the patch has */
+      Int_t fNumberOfRows;                                            //! transient
+
+      /** Current patch number */
+      UInt_t fCurrentPatch;                                            //! transient
+
+      /** First row in patch */
+      UInt_t fFirstRow;                                                //! transient
+
+      /** Last row in patch */
+      UInt_t fLastRow;                                                 //! transient
+      
+      /** Number of timebins */
+      Int_t fNTimeBins;                                                //! transient
+
+      /** Flag to check if the 2d vector is initialized */
+      Bool_t fVectorInitialized;                                       //! transient
+
+      /** pointer to mapping object */
+      AliHLTTPCMapping *fMapping;
+
+      ClassDef(AliHLTTPCHWCFDataReverterComponent, 0)  
+    };
+#endif
index 1eb8523644ec8985651ffd510ac27c76c57a1c12..0496ff39bd21e11d7d76da6b7851d061baa86ec0 100644 (file)
@@ -313,11 +313,11 @@ void AliHLTTPCKryptonClusterFinder::FindKryptonClusters()
          fSpacePointData[fNKryptonClusters].fY = xyz[1];
          fSpacePointData[fNKryptonClusters].fZ = xyz[2];
          fSpacePointData[fNKryptonClusters].fCharge = tmpCluster->fTotalCharge;
-         fSpacePointData[fNKryptonClusters].fMaxQ = tmpCluster->fQMax;
+         fSpacePointData[fNKryptonClusters].fQMax = tmpCluster->fQMax;
          fSpacePointData[fNKryptonClusters].fPadRow = tmpCluster->fRowNumber/tmpCluster->fTotalCharge;
          HLTDebug("Krypton cluster found");
          HLTDebug("xyz=[%f,%f,%f]",fSpacePointData[fNKryptonClusters].fX,fSpacePointData[fNKryptonClusters].fY,fSpacePointData[fNKryptonClusters].fZ);
-         HLTDebug("TotalCharge = %d    and   QMax = %d",fSpacePointData[fNKryptonClusters].fCharge,fSpacePointData[fNKryptonClusters].fMaxQ);
+         HLTDebug("TotalCharge = %d    and   QMax = %d",fSpacePointData[fNKryptonClusters].fCharge,fSpacePointData[fNKryptonClusters].fQMax);
          fNKryptonClusters++;
          break;
        }
index 7216d8e2c7281933eb648e580694fe4a4507a6bf..baa9dc2452770b332dae5d558ada35651abbefbc 100644 (file)
@@ -179,7 +179,7 @@ int AliHLTTPCKryptonClusterFinderComponent::DoEvent( const AliHLTComponentEventD
   //  == init iter (pointer to datablock)
   const AliHLTComponentBlockData* iter = NULL;
 
-  Int_t slice, patch, row[2];
+  Int_t slice, patch;
 
   unsigned long maxPoints = 0;
 
@@ -207,13 +207,11 @@ int AliHLTTPCKryptonClusterFinderComponent::DoEvent( const AliHLTComponentEventD
       
     slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
     patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
-    row[0] = AliHLTTPCTransform::GetFirstRow( patch );
-    row[1] = AliHLTTPCTransform::GetLastRow( patch );
 
 
     fKryptonClusterFinder->SetPatch(patch);
 
-    fKryptonClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
+    fKryptonClusterFinder->InitSlice( slice, patch, maxPoints );
 
     fKryptonClusterFinder->SetOutputArray((AliHLTTPCSpacePointData*)outPtr->fSpacePoints);
     
index e3c73faadca392efa0a13feb7e872bf3b4d9835d..5c01e1f4da4292132f56400b80210f18959a5361 100644 (file)
@@ -248,7 +248,7 @@ int AliHLTTPCNoiseMapComponent::DoInit( int argc, const char** argv ) {
 } // end DoInit()
 
 int AliHLTTPCNoiseMapComponent::DoDeinit() { 
-// see header file for class documentation  
+  // see header file for class documentation  
 
   if(fHistMaxSignal) delete fHistMaxSignal; fHistMaxSignal = NULL;
   if(fHistTotSignal) delete fHistTotSignal; fHistTotSignal = NULL;
@@ -260,7 +260,7 @@ int AliHLTTPCNoiseMapComponent::DoDeinit() {
 }
 
 int AliHLTTPCNoiseMapComponent::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/){
-// see header file for class documentation
+  // see header file for class documentation
  
   //HLTInfo("--- Entering DoEvent() in TPCNoiseMap ---");
  
@@ -273,34 +273,41 @@ int AliHLTTPCNoiseMapComponent::DoEvent(const AliHLTComponentEventData& evtData,
     
   for(iter = GetFirstInputBlock(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC); iter != NULL; iter = GetNextInputBlock()){
       
-     HLTInfo("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s", 
-              evtData.fEventID, evtData.fEventID,
-              DataType2Text(iter->fDataType).c_str(), 
-             DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
-
-     if (iter->fDataType == AliHLTTPCDefinitions::fgkDDLPackedRawDataType && GetEventCount()<2){
-         HLTWarning("data type %s is depricated, use %s (kAliHLTDataTypeDDLRaw)!", 
-        DataType2Text(AliHLTTPCDefinitions::fgkDDLPackedRawDataType).c_str(),
-         DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
-     }      
+    HLTInfo("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s", 
+           evtData.fEventID, evtData.fEventID,
+           DataType2Text(iter->fDataType).c_str(), 
+           DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
+
+    if (iter->fDataType == AliHLTTPCDefinitions::fgkDDLPackedRawDataType && GetEventCount()<2){
+      HLTWarning("data type %s is depricated, use %s (kAliHLTDataTypeDDLRaw)!", 
+                DataType2Text(AliHLTTPCDefinitions::fgkDDLPackedRawDataType).c_str(),
+                DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
+    }      
      
-     if (iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC)) continue;
+    if (iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC)) continue;
       
-     UInt_t slice     = AliHLTTPCDefinitions::GetMinSliceNr(*iter); 
-     UInt_t partition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
+    UInt_t slice     = AliHLTTPCDefinitions::GetMinSliceNr(*iter); 
+    UInt_t partition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
      
-     fSpecification = iter->fSpecification;
+    fSpecification = iter->fSpecification;
      
-     AliHLTTPCDigitReader *pDigitReader = new AliHLTTPCDigitReaderDecoder;
+    AliHLTTPCDigitReader *pDigitReader = new AliHLTTPCDigitReaderDecoder;
 
-     pDigitReader->InitBlock(iter->fPtr,iter->fSize,partition,slice);
-     if(!pDigitReader) break;
+    pDigitReader->InitBlock(iter->fPtr,iter->fSize,partition,slice);
+    if(!pDigitReader) break;
        
-     //sprintf(name,"hMaxSignal_slice%d_partition%d", slice, partition);
-     //fHistMaxSignal = new TH2F(name,name,250,-250,250,250,-250,250);
+    //sprintf(name,"hMaxSignal_slice%d_partition%d", slice, partition);
+    //fHistMaxSignal = new TH2F(name,name,250,-250,250,250,-250,250);
             
-     while(pDigitReader->Next()){ 
-     //while( pDigitReader->NextChannel()) { // pad loop 
+    //  while(pDigitReader->Next()){ 
+
+
+    Float_t maxSignal     = 0.;
+    Float_t totalSignal   = 0.;
+    Float_t squaredSignal = 0.;
+    Float_t rms = 0.; 
+    
+    while( pDigitReader->NextChannel()) { // pad loop 
       
       fCurrentRow  = pDigitReader->GetRow();  
       fCurrentRow += pDigitReader->GetRowOffset();
@@ -319,49 +326,53 @@ int AliHLTTPCNoiseMapComponent::DoEvent(const AliHLTComponentEventData& evtData,
       // transformation from pad-row coordinates to global ones
       // time info is not taken into account
       
-//       AliTPCCalROC *calRoc = noisePad->GetCalROC(thissector);
-//       calRoc->GetValue(thisrow,pDigitReader->GetPad());
+      //       AliTPCCalROC *calRoc = noisePad->GetCalROC(thissector);
+      //       calRoc->GetValue(thisrow,pDigitReader->GetPad());
+      
       
-      //while( pDigitReader->NextBunch()) {
+      while( pDigitReader->NextBunch()) {
     
-      const UInt_t *bunchData = pDigitReader->GetSignals();
-      Float_t maxSignal     = 0.;
-      Float_t totalSignal   = 0.;
-      Float_t squaredSignal = 0.;
-      Float_t rms = 0.; 
+       const UInt_t *bunchData = pDigitReader->GetSignals();
       
-      //fHistSignal = new TH1F("fHistSignal", "signal distribution per pad",1024,0,1024);
+       //fHistSignal = new TH1F("fHistSignal", "signal distribution per pad",1024,0,1024);
       
-      //fHistSignal->Reset();
-      //Int_t time = pDigitReader->GetTime();
+       //fHistSignal->Reset();
+       //Int_t time = pDigitReader->GetTime();
      
-      for(Int_t i=0;i<pDigitReader->GetBunchSize();i++){
+       for(Int_t i=0;i<pDigitReader->GetBunchSize();i++){
           
          if((Float_t)(bunchData[i])>maxSignal){ maxSignal = (Float_t)(bunchData[i]); }
          totalSignal += (Float_t)bunchData[i];
          squaredSignal += (Float_t)bunchData[i]*(Float_t)bunchData[i];
          //fHistSignal->Fill(time+i, bunchData[i]);
-      } // end for loop over bunches
-      rms = TMath::Sqrt(squaredSignal/pDigitReader->GetBunchSize());
+       } // end for loop over bunches
+       rms = TMath::Sqrt(squaredSignal/pDigitReader->GetBunchSize());
             
-      //} // end of inner while loop
+      } // end of inner while loop
            
-      fHistMaxSignal->Fill(xyz[0],xyz[1],maxSignal);
-      fHistTotSignal->Fill(xyz[0],xyz[1],totalSignal);
-            
-      fHistPadRMS->Fill(xyz[0],xyz[1],rms);
+    } // end of while loop over pads
      
-      //fHistPadRMS->Fill(xyz[0],xyz[1],fHistSignal->GetRMS());
-      //delete fHistSignal; fHistSignal = NULL;
-            
-      if(fPlotSideA || fPlotSideC){
-         if(slice<18) fHistSideA->Fill(xyz[0],xyz[1],maxSignal);
-         else        fHistSideC->Fill(xyz[0],xyz[1],maxSignal);                             
-      } // end if plotting sides    
-     } // end of while loop over pads
-   
-     pDigitReader->Reset();
-     delete pDigitReader;
+    fHistMaxSignal->Fill(xyz[0],xyz[1],maxSignal);
+    fHistTotSignal->Fill(xyz[0],xyz[1],totalSignal);
+     
+    fHistPadRMS->Fill(xyz[0],xyz[1],rms);
+      
+    //fHistPadRMS->Fill(xyz[0],xyz[1],fHistSignal->GetRMS());
+    //delete fHistSignal; fHistSignal = NULL;
+      
+    if(fPlotSideA || fPlotSideC){
+      if(slice<18) fHistSideA->Fill(xyz[0],xyz[1],maxSignal);
+      else           fHistSideC->Fill(xyz[0],xyz[1],maxSignal);                             
+    } // end if plotting sides    
+      
+    
+    maxSignal     = 0.;
+    totalSignal   = 0.;
+    squaredSignal = 0.;
+    rms = 0.; 
+
+    pDigitReader->Reset();
+    delete pDigitReader;
   } // end of for loop over data blocks
  
   if(fResetHistograms) ResetHistograms();
index dc3966cb8fa07c6a4115db7951c3bbe10380e30b..36b8f3003d1e27ce6c1b247be7f7c5d0440121be 100644 (file)
@@ -28,7 +28,7 @@ struct AliHLTTPCSpacePointData{
   Float_t fSigmaY2; // error (former width) of the clusters
   Float_t fSigmaZ2; // error (former width) of the clusters
   UInt_t fCharge;   // total charge of cluster
-  UInt_t fMaxQ;     // QMax of cluster
+  UInt_t fQMax;     // QMax of cluster
   Bool_t fUsed;     // only used in AliHLTTPCDisplay 
   Int_t fTrackN;    // only used in AliHLTTPCDisplay 
 };
index 23dfd969e512879562b4d7101062fe5b3d76bcc0..107873415df5bb5344559400135d2429a60d2fca 100644 (file)
@@ -236,13 +236,13 @@ int AliHLTTPCTrackHistoComponent::DoEvent(const AliHLTComponentEventData& /*evtD
       Int_t patchCl = (idCluster>>22) & 0x7;
       UInt_t pos = idCluster&0x3fffff;
       if(fPlotChargeClusters || fPlotAll){fHistoChargeAllClusters->Fill(clusters[i].fCharge);}
-      if(fPlotQMaxClusters || fPlotAll){fHistoQMaxAllClusters->Fill(clusters[i].fMaxQ);}
+      if(fPlotQMaxClusters || fPlotAll){fHistoQMaxAllClusters->Fill(clusters[i].fQMax);}
       for(UInt_t id=0;id<fTrackClusterID[sliceCl][patchCl].size();id++){
        if(fTrackClusterID[sliceCl][patchCl][id]==pos){
          clusters[i].fUsed=kTRUE;
          nClustersUsed++;
          if(fPlotChargeUsedClusters || fPlotAll){fHistoChargeUsedClusters->Fill(clusters[i].fCharge);}
-         if(fPlotQMaxUsedClusters || fPlotAll){fHistoQMaxUsedClusters->Fill(clusters[i].fMaxQ);}
+         if(fPlotQMaxUsedClusters || fPlotAll){fHistoQMaxUsedClusters->Fill(clusters[i].fQMax);}
        }
       } 
       fClusters.push_back(clusters[i]);
index a77e3888525d5cdcc7656dd5b4aba0071aaa91b2..e82f1d0100e1dc35bf619248bf2eac203250191b 100644 (file)
@@ -64,7 +64,7 @@ AliTPCclusterMI* AliHLTTPCOfflineCluster::ConvertHLTToOffline(AliHLTTPCSpacePoin
    offCluster->SetRow((Int_t)spacePoint.fPadRow); // row 
    offCluster->SetTimeBin(spacePoint.fZ);         // time bin
    offCluster->SetQ(spacePoint.fCharge);         // charge
-   offCluster->SetMax(spacePoint.fMaxQ);         // max Q (amplitude)
+   offCluster->SetMax(spacePoint.fQMax);         // max Q (amplitude)
    //offCluster->SetDetector(0);                 // detector/slice
    //offCluster->SetType(0);                     // default from constructor
    //offCluster->IsUsed(0);                      // default from constructor
@@ -83,7 +83,7 @@ AliHLTTPCSpacePointData AliHLTTPCOfflineCluster::ConvertOfflineToHLT(AliTPCclust
    spacePoint.fPadRow = offCluster->GetRow();
    spacePoint.fZ      = offCluster->GetTimeBin();
    spacePoint.fCharge = (UInt_t)offCluster->GetQ();
-   spacePoint.fMaxQ   = (UInt_t)offCluster->GetMax();
+   spacePoint.fQMax   = (UInt_t)offCluster->GetMax();
 
    return spacePoint;
    
index ed6be7f2326a6a8906b0dd1cda6e90adf6603985..b5a4b3050e4c6e61c59ca652e1740a44da1183bd 100644 (file)
@@ -93,7 +93,8 @@ CLASS_HDRS:=          AliHLTTPCTransform.h \
                AliHLTTPCTrackHistoComponent.h \
                AliHLTTPCTrackDumpComponent.h \
                AliHLTTPCClusterDumpComponent.h \
-               AliHLTTPCCalibTracksComponent.h
+               AliHLTTPCCalibTracksComponent.h \
+               AliHLTTPCHWCFDataReverterComponent.h