+ //-----------------------------------------------------------------
+ // Use HLT clusters
+ //-----------------------------------------------------------------
+ fUseHLTClusters = fRecoParam->GetUseHLTClusters();
+
+ AliInfo(Form("Usage of HLT clusters in TPC reconstruction : %d",fUseHLTClusters));
+
+ if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
+ AliInfo("Using HLT clusters for TPC off-line reconstruction");
+ fZWidth = fParam->GetZWidth();
+ Int_t iResult = ReadHLTClusters();
+
+ // HLT clusters present
+ if (iResult >= 0 && fNclusters > 0)
+ return;
+
+ // HLT clusters not present
+ if (iResult < 0 || fNclusters == 0) {
+ if (fUseHLTClusters == 3) {
+ AliError("No HLT clusters present, but requested.");
+ return;
+ }
+ else {
+ AliInfo("Now trying to read TPC RAW");
+ }
+ }
+ // Some other problem during cluster reading
+ else {
+ AliWarning("Some problem while unpacking of HLT clusters.");
+ return;
+ }
+ } // if (fUseHLTClusters == 3 || fUseHLTClusters == 4) {
+
+ //-----------------------------------------------------------------
+ // Run TPC off-line clusterer
+ //-----------------------------------------------------------------
+ AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
+ AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
+ //
+ AliTPCRawStreamV3 input(rawReader,(AliAltroMapping**)mapping);
+ fEventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
+ if (fEventHeader){
+ fTimeStamp = fEventHeader->Get("Timestamp");
+ fEventType = fEventHeader->Get("Type");
+ AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
+ transform->SetCurrentTimeStamp(fTimeStamp);
+ transform->SetCurrentRun(rawReader->GetRunNumber());
+ }
+
+ // creaate one TClonesArray for all clusters
+ if(fBClonesArray && !fOutputClonesArray) fOutputClonesArray = new TClonesArray("AliTPCclusterMI",1000);
+ // reset counter
+ fNclusters = 0;
+
+ fMaxTime = fRecoParam->GetLastBin() + 6; // add 3 virtual time bins before and 3 after
+// const Int_t kNIS = fParam->GetNInnerSector();
+// const Int_t kNOS = fParam->GetNOuterSector();
+// const Int_t kNS = kNIS + kNOS;
+ fZWidth = fParam->GetZWidth();
+ Int_t zeroSup = fParam->GetZeroSup();
+ //
+ // Clean-up
+ //
+ AliTPCROC * roc = AliTPCROC::Instance();
+ Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
+ Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
+ for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
+ //
+ Int_t maxBin = fMaxTime*(nPadsMax+6); // add 3 virtual pads before and 3 after
+ memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
+ fAllNSigBins[iRow]=0;
+ }
+
+ Int_t prevSector=-1;
+ rawReader->Reset();
+ Int_t digCounter=0;
+ //
+ // Loop over DDLs
+ //
+ const Int_t kNIS = fParam->GetNInnerSector();
+ const Int_t kNOS = fParam->GetNOuterSector();
+ const Int_t kNS = kNIS + kNOS;
+
+ for(fSector = 0; fSector < kNS; fSector++) {
+
+ Int_t nRows = 0;
+ Int_t nDDLs = 0, indexDDL = 0;
+ if (fSector < kNIS) {
+ nRows = fParam->GetNRowLow();
+ fSign = (fSector < kNIS/2) ? 1 : -1;
+ nDDLs = 2;
+ indexDDL = fSector * 2;
+ }
+ else {
+ nRows = fParam->GetNRowUp();
+ fSign = ((fSector-kNIS) < kNOS/2) ? 1 : -1;
+ nDDLs = 4;
+ indexDDL = (fSector-kNIS) * 4 + kNIS * 2;
+ }
+
+ // load the raw data for corresponding DDLs
+ rawReader->Reset();
+ rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
+
+ while (input.NextDDL()){
+ if (input.GetSector() != fSector)
+ AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",fSector,input.GetSector()));
+
+ //Int_t nRows = fParam->GetNRow(fSector);
+
+ AliTPCCalROC * gainROC = gainTPC->GetCalROC(fSector); // pad gains per given sector
+ // Begin loop over altro data
+ Bool_t calcPedestal = fRecoParam->GetCalcPedestal();
+ Float_t gain =1;
+
+ //loop over pads
+ while ( input.NextChannel() ) {
+ Int_t iRow = input.GetRow();
+ if (iRow < 0){
+ continue;
+ }
+ if (iRow >= nRows){
+ AliError(Form("Pad-row index (%d) outside the range (%d -> %d) !",
+ iRow, 0, nRows -1));
+ continue;
+ }
+ //pad
+ Int_t iPad = input.GetPad();
+ if (iPad < 0 || iPad >= nPadsMax) {
+ AliError(Form("Pad index (%d) outside the range (%d -> %d) !",
+ iPad, 0, nPadsMax-1));
+ continue;
+ }
+ gain = gainROC->GetValue(iRow,iPad);
+ iPad+=3;
+
+ //loop over bunches
+ while ( input.NextBunch() ){
+ Int_t startTbin = (Int_t)input.GetStartTimeBin();
+ Int_t bunchlength = (Int_t)input.GetBunchLength();
+ const UShort_t *sig = input.GetSignals();
+ for (Int_t iTime = 0; iTime<bunchlength; iTime++){
+ Int_t iTimeBin=startTbin-iTime;
+ if ( iTimeBin < fRecoParam->GetFirstBin() || iTimeBin >= fRecoParam->GetLastBin()){
+ continue;
+ AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
+ iTimeBin, 0, iTimeBin -1));
+ }
+ iTimeBin+=3;
+ //signal
+ Float_t signal=(Float_t)sig[iTime];
+ if (!calcPedestal && signal <= zeroSup) continue;
+
+ if (!calcPedestal) {
+ Int_t bin = iPad*fMaxTime+iTimeBin;
+ if (gain>0){
+ fAllBins[iRow][bin] = signal/gain;
+ }else{
+ fAllBins[iRow][bin] =0;
+ }
+ fAllSigBins[iRow][fAllNSigBins[iRow]++] = bin;
+ }else{
+ fAllBins[iRow][iPad*fMaxTime+iTimeBin] = signal;
+ }
+ fAllBins[iRow][iPad*fMaxTime+0]+=1.; // pad with signal
+
+ // Temporary
+ digCounter++;
+ }// end loop signals in bunch
+ }// end loop bunches
+ } // end loop pads
+ //
+ //
+ //
+ //
+ // Now loop over rows and perform pedestal subtraction
+ if (digCounter==0) continue;
+ } // End of loop over sectors
+ //process last sector
+ if ( digCounter>0 ){
+ ProcessSectorData();
+ for (Int_t iRow = 0; iRow < fParam->GetNRow(fSector); iRow++) {
+ Int_t maxPad = fParam->GetNPads(fSector,iRow);
+ Int_t maxBin = fMaxTime*(maxPad+6); // add 3 virtual pads before and 3 after
+ memset(fAllBins[iRow],0,sizeof(Float_t)*maxBin);
+ fAllNSigBins[iRow] = 0;
+ }
+ prevSector=fSector;
+ digCounter=0;