+void AliEMCALRawUtils::Raw2Digits(AliRawReader* reader,TClonesArray *digitsArr, const AliCaloCalibPedestal* pedbadmap, TClonesArray *digitsTRG, AliEMCALTriggerData* trgData)
+{
+ //conversion of raw data to digits
+ if ( digitsArr) digitsArr->Clear("C");
+ if (!digitsArr) { Error("Raw2Digits", "no digits found !");return;}
+ if (!reader) {Error("Raw2Digits", "no raw reader found !");return;}
+ AliEMCALTriggerSTURawStream inSTU(reader);
+ AliCaloRawStreamV3 in(reader,"EMCAL",fMapping);
+ reader->Select("EMCAL",0,39); // 39 = AliEMCALGeoParams::fgkLastAltroDDL
+ fTriggerRawDigitMaker->Reset();
+ fTriggerRawDigitMaker->SetIO(reader, in, inSTU, digitsTRG, trgData);
+ fRawAnalyzer->SetIsZeroSuppressed(true); // TMP - should use stream->IsZeroSuppressed(), or altro cfg registers later
+
+ Int_t lowGain = 0;
+ Int_t caloFlag = 0; // low, high gain, or TRU, or LED ref.
+
+ Float_t bcTimePhaseCorr = 0; // for BC-based L1 phase correction
+ Int_t bcMod4 = (reader->GetBCID() % 4); // LHC uses 40 MHz, EMCal uses 10 MHz clock
+
+ //AliCDBManager* man = AliCDBManager::Instance();
+ //Int_t runNumber = man->GetRun();
+
+ Int_t runNumber = reader->GetRunNumber();
+
+ if ((runNumber >130850 ) && (bcMod4==0 || bcMod4==1))
+ bcTimePhaseCorr = -1e-7; // subtract 100 ns for certain BC values
+
+ while (in.NextDDL())
+ {
+ while (in.NextChannel())
+ {
+ caloFlag = in.GetCaloFlag();
+ if (caloFlag > 2) continue; // Work with ALTRO and FALTRO
+ if(caloFlag < 2 && fRemoveBadChannels && pedbadmap->IsBadChannel(in.GetModule(),in.GetColumn(),in.GetRow()))
+ {
+ continue;
+ }
+ vector<AliCaloBunchInfo> bunchlist;
+ while (in.NextBunch())
+ {
+ bunchlist.push_back( AliCaloBunchInfo(in.GetStartTimeBin(), in.GetBunchLength(), in.GetSignals() ) );
+ }
+ if (bunchlist.size() == 0) continue;
+ if ( caloFlag < 2 )
+ { // ALTRO
+ Int_t id = fGeom->GetAbsCellIdFromCellIndexes(in.GetModule(), in.GetRow(), in.GetColumn()) ;
+ lowGain = in.IsLowGain();
+ fRawAnalyzer->SetL1Phase( in.GetL1Phase() );
+ AliCaloFitResults res = fRawAnalyzer->Evaluate( bunchlist, in.GetAltroCFG1(), in.GetAltroCFG2());
+ if(res.GetAmp() >= fNoiseThreshold )
+ {
+ AddDigit(digitsArr, id, lowGain, res.GetAmp(), res.GetTime()+bcTimePhaseCorr, res.GetChi2(), res.GetNdf() );
+ }
+ }//ALTRO
+ else if(fUseFALTRO)
+ {// Fake ALTRO
+ fTriggerRawDigitMaker->Add( bunchlist );
+ }//Fake ALTRO
+ } // end while over channel
+ } //end while over DDL's, of input stream
+ fTriggerRawDigitMaker->PostProcess();
+ TrimDigits(digitsArr);
+}