]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/AliHLTTPCDigitReaderUnpacked.cxx
The segmentations are made data member of the AliITSUGeomTGeo, will be loaded
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitReaderUnpacked.cxx
index 810a66b2323f885ec36476ccd78a2e70826c5741..85fbb454fdd8dc3f6b3c835a6c8f391818ede9fe 100644 (file)
     @brief  A digit reader implementation for unpacked TPC data.
 */
 
-#if __GNUC__== 3
-using namespace std;
-#endif
-
 #include <cassert>
 #include "AliHLTTPCDigitReaderUnpacked.h"
 #include "AliHLTTPCDigitData.h"
@@ -35,6 +31,8 @@ using namespace std;
 #include "AliHLTStdIncludes.h"
 #include "AliHLTTPCMapping.h"
 
+using namespace std;
+
 ClassImp(AliHLTTPCDigitReaderUnpacked)
 
 AliHLTTPCDigitReaderUnpacked::AliHLTTPCDigitReaderUnpacked()
@@ -57,11 +55,12 @@ AliHLTTPCDigitReaderUnpacked::AliHLTTPCDigitReaderUnpacked()
   fPrevTime(0),
   fEndTimeBinOfBunch(0),
   fPrevSignal(0),
-  fPrevPad(0),
+  fPrevPad(-1),
   fPrevRow(-1),
   fNextChannelIsAlreadyConfirmed(kFALSE),
   fMapping(NULL),
   fDigitsVector(),
+  fBinRowPositionSorted(),
   fPatch(0)
 {
   // see header file for class documentation
@@ -73,6 +72,10 @@ AliHLTTPCDigitReaderUnpacked::AliHLTTPCDigitReaderUnpacked()
 
 AliHLTTPCDigitReaderUnpacked::~AliHLTTPCDigitReaderUnpacked(){
   // see header file for class documentation
+  if(fMapping){
+    delete fMapping;
+  }
+  fMapping=NULL;
 }
 
 int AliHLTTPCDigitReaderUnpacked::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t slice){
@@ -83,6 +86,15 @@ int AliHLTTPCDigitReaderUnpacked::InitBlock(void* ptr,unsigned long size, Int_t
   fSize = size;
 
   fPatch=patch;
+  fEndOfDataReached=kFALSE;
+  fEndOfChannelReached=kFALSE;
+  fPrevTime=0;
+  fEndTimeBinOfBunch=0;
+  fPrevSignal=0;
+  fPrevPad=-1;
+  fPrevRow=-1;
+  fNextChannelIsAlreadyConfirmed=kFALSE;
+  fDigitsVector.clear();
 
   tmpptr = reinterpret_cast<AliHLTTPCUnpackedRawData*>(fPtr);
   fDigitRowData = (AliHLTTPCDigitRowData*) tmpptr->fDigits;
@@ -120,6 +132,7 @@ int AliHLTTPCDigitReaderUnpacked::GetNextRowData(AliHLTTPCDigitRowData*& pRow) c
   AliHLTTPCDigitRowData* pCurrent=pRow;
   assert(pCurrent);
   pRow=NULL;
+  if (!pCurrent) return -EINVAL;
   Byte_t *tmp = (Byte_t*) pCurrent;
   Int_t size = sizeof(AliHLTTPCDigitRowData) + pCurrent->fNDigit*sizeof(AliHLTTPCDigitData);
   tmp += size;
@@ -146,6 +159,34 @@ int AliHLTTPCDigitReaderUnpacked::GetNextRowData(AliHLTTPCDigitRowData*& pRow) c
     
   return iResult;
 }
+void AliHLTTPCDigitReaderUnpacked::SortBunchBinVector(){
+  fBinRowPositionSorted.clear();
+
+  fBinRowPositionSorted.push_back(0);
+  Int_t nAdded=0;
+  Int_t beginningOfPadIndex=0;
+  Int_t totalAdded=0;
+  for(Int_t i=1;i<(Int_t)fActRowData->fNDigit;i++){
+     if(fData[i-1].fPad == fData[i].fPad){// means that these sinals belong to the same pad
+      if(fData[i-1].fTime+1 == fData[i].fTime){ //means that the signal belong to the same bunch
+       nAdded++;
+       totalAdded++;
+       fBinRowPositionSorted.insert(fBinRowPositionSorted.begin()+beginningOfPadIndex+nAdded,i);
+      }
+      else{//we have a new bunch on this pad, put it in fornt of the previous bunch
+       totalAdded++;
+       nAdded=0;
+       fBinRowPositionSorted.insert(fBinRowPositionSorted.begin()+beginningOfPadIndex,i);
+      }
+    }
+    else{
+      totalAdded++;
+      beginningOfPadIndex=totalAdded;
+      fBinRowPositionSorted.push_back(i);
+      nAdded=0;
+    }
+  }
+}
 
 bool AliHLTTPCDigitReaderUnpacked::NextSignal(){
   // see header file for class documentation
@@ -155,31 +196,38 @@ bool AliHLTTPCDigitReaderUnpacked::NextSignal(){
 
   fBin++;
 
-  if ( fBin >= (Int_t)fActRowData->fNDigit ){
+  while ( fBin >= (Int_t)fActRowData->fNDigit ){
     fRow++;
     if ((fRow >= fFirstRow) && (fRow <= fLastRow)){
-
+      
       //new row 
       if (GetNextRowData(fActRowData)<0) {
        rreadvalue = false;
        return rreadvalue;
       }
-
       fBin = 0;
     }
     else {
       rreadvalue = false;
       return rreadvalue;
     }
-  if(!fActRowData){
-    return false;
-  }
+    if(!fActRowData){
+      return false;
+    }
     if ((Int_t)fActRowData->fRow != fRow){
       HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow);
     }
   }
-
+  
   fData = fActRowData->fDigitData;
+
+  if(fBin==0){
+    SortBunchBinVector(); 
+  }
+
+  if(fPrevPad == -1){
+    fPrevPad = GetSortedPad();
+  }
  
   return rreadvalue;
 }
@@ -243,12 +291,19 @@ AliHLTUInt32_t AliHLTTPCDigitReaderUnpacked::GetAltroBlockHWaddr() const
   return (AliHLTUInt32_t)(fMapping->GetHwAddress((UInt_t)GetSortedRow(),(UInt_t)GetSortedPad()));//fTPCRawStream->GetHWAddress();
 }
 
+AliHLTTPCDigitData AliHLTTPCDigitReaderUnpacked::GetSortedDigit(){
+  // see header file for class documentation
+  assert(fData);
+  if (!fData) return AliHLTTPCDigitData();
+  return fData[fBinRowPositionSorted.at(fBin)];
+}
+
 Int_t AliHLTTPCDigitReaderUnpacked::GetSortedTime(){
   // see header file for class documentation
   assert(fData);
   if (!fData) return -1;
   int rtime;
-  rtime = (int)fData[fBin].fTime;
+  rtime = (int)fData[fBinRowPositionSorted.at(fBin)].fTime;
   if(fDataBunch.size()>1){
     fEndTimeBinOfBunch=rtime;
   }
@@ -260,7 +315,7 @@ Int_t AliHLTTPCDigitReaderUnpacked::GetSortedSignal(){
   assert(fData);
   if (!fData) return -1;
   int rsignal;
-  rsignal = (int)fData[fBin].fCharge;
+  rsignal = (int)fData[fBinRowPositionSorted.at(fBin)].fCharge;
   return rsignal;
 
 }
@@ -270,7 +325,7 @@ Int_t AliHLTTPCDigitReaderUnpacked::GetSortedPad() const{
   assert(fData);
   if (!fData) return -1;
   int rpad;
-  rpad = (int)fData[fBin].fPad;
+  rpad = (int)fData[fBinRowPositionSorted.at(fBin)].fPad;
   return rpad   ;
 }
 
@@ -300,9 +355,20 @@ bool AliHLTTPCDigitReaderUnpacked::NextChannel()
     fPrevSignal=GetSortedSignal();
     fPrevPad = GetSortedPad();
     fPrevRow = GetSortedRow();
+
+    if(GetAltroBlockHWaddr() == (UInt_t)-1){
+      fPrevPad = -1;
+      return NextChannel();
+    }
+
     return true;
   }
   else if(NextSignal()) { // there is data
+
+    if(GetAltroBlockHWaddr() == (UInt_t)-1){
+      fPrevPad = -1;
+      return NextChannel();
+    }
     return true;
   }
   return false;
@@ -329,7 +395,7 @@ int AliHLTTPCDigitReaderUnpacked::NextBunch()
   fPrevPad = GetSortedPad();
   fPrevRow = GetSortedRow();
   fDataBunch.push_back(GetSortedSignal());
-  fDigitsVector.push_back(fData[fBin]);
+  fDigitsVector.push_back(GetSortedDigit());
 
   do{
     if(NextSignal()){
@@ -338,7 +404,7 @@ int AliHLTTPCDigitReaderUnpacked::NextBunch()
            fPrevTime = GetSortedTime();
            //fDataBunch.insert(fDataBunch.begin(), GetSortedSignal());// add the signal to the beginning of the buffer     
            fDataBunch.push_back(GetSortedSignal());// add the signal to the beginning of the buffer
-           fDigitsVector.push_back(fData[fBin]);
+           fDigitsVector.push_back(GetSortedDigit());
          }
          else{//end of bunch but not of channel
            break;