+ const Int_t maxDDL = 20;
+ AliAltroBuffer *buffer[maxDDL];
+ AliAltroMapping *mapping[maxDDL];
+
+ for(Int_t jDDL=0; jDDL<maxDDL; jDDL++) {
+ buffer[jDDL]=0;
+ mapping[jDDL]=0;
+ }
+
+ //!!!!for debug!!!
+ Int_t modMax=-111;
+ Int_t colMax=-111;
+ Int_t rowMax=-111;
+ Float_t eMax=-333;
+ //!!!for debug!!!
+
+ // loop over digits (assume ordered digits)
+ for (Int_t iDigit = 0; iDigit < digits->GetEntries(); iDigit++) {
+ AliPHOSDigit* digit = static_cast<AliPHOSDigit *>(digits->At(iDigit)) ;
+
+ // Skip small energy below treshold
+ if (digit->GetEnergy() < kThreshold)
+ continue;
+
+ Int_t relId[4];
+ geom->AbsToRelNumbering(digit->GetId(), relId);
+ Int_t module = 5-relId[0];
+
+ // Begin FIXME
+ if (relId[1] != 0)
+ continue; // ignore digits from CPV
+ // End FIXME
+
+ Int_t row = relId[2]-1;
+ Int_t col = relId[3]-1;
+
+ Int_t iRCU = -111;
+
+ //RCU0
+ if(0<=row&&row<16 && 0<=col&&col<56) iRCU=0;
+
+ //RCU1
+ if(16<=row&&row<32 && 0<=col&&col<56) iRCU=1;
+
+ //RCU2
+ if(32<=row&&row<48 && 0<=col&&col<56) iRCU=2;
+
+ //RCU3
+ if(48<=row&&row<64 && 0<=col&&col<56) iRCU=3;
+
+
+ // PHOS EMCA has 4 DDL per module. Splitting is based on the (row,column) numbers.
+ // here module already in PHOS online convention: 0<module<4 and inverse order.
+ Int_t iDDL = 4 * module + iRCU;
+
+ // new DDL
+ if (iDDL != prevDDL) {
+ if (buffer[iDDL] == 0) {
+ // open new file and write dummy header
+ TString fileName = AliDAQ::DdlFileName("PHOS",iDDL);
+
+ mapping[iDDL] = (AliAltroMapping*)maps->At(iDDL);
+ buffer[iDDL] = new AliAltroBuffer(fileName.Data(),mapping[iDDL]);
+ buffer[iDDL]->WriteDataHeader(kTRUE, kFALSE); //Dummy;
+ }
+ prevDDL = iDDL;
+ }
+
+ AliDebug(2,Form("digit E=%.4f GeV, t=%g s, (mod,col,row)=(%d,%d,%d)\n",
+ digit->GetEnergy(),digit->GetTimeR(),
+ relId[0]-1,relId[3]-1,relId[2]-1));
+ // if a signal is out of time range, write only trailer
+ if (digit->GetTimeR() > pulse->GetRawFormatTimeMax()*0.5 ) {
+ AliDebug(2,"Signal is out of time range.\n");
+ buffer[iDDL]->FillBuffer(0);
+ buffer[iDDL]->FillBuffer(pulse->GetRawFormatTimeBins() ); // time bin
+ buffer[iDDL]->FillBuffer(3); // bunch length
+ buffer[iDDL]->WriteTrailer(3, relId[3]-1, relId[2]-1, 0); // trailer
+
+ // calculate the time response function
+ } else {
+ Double_t energy = 0 ;
+ if (digit->GetId() <= geom->GetNModules() * geom->GetNCristalsInModule()) {
+ energy=digit->GetEnergy();
+ if(energy>eMax) {eMax=energy; modMax=relId[0]; colMax=col; rowMax=row;}
+ }
+ else {
+ energy = 0; // CPV raw data format is now know yet
+ }
+ pulse->SetAmplitude(energy);
+ pulse->SetTZero(digit->GetTimeR());
+ Double_t r =fgCalibData->GetHighLowRatioEmc(relId[0],relId[3],relId[2]) ;
+ pulse->SetHG2LGRatio(r) ;
+ pulse->MakeSamples();
+ pulse->GetSamples(adcValuesHigh, adcValuesLow) ;
+
+ buffer[iDDL]->WriteChannel(relId[3]-1, relId[2]-1, 0,
+ pulse->GetRawFormatTimeBins(), adcValuesLow , kAdcThreshold);
+ buffer[iDDL]->WriteChannel(relId[3]-1, relId[2]-1, 1,
+ pulse->GetRawFormatTimeBins(), adcValuesHigh, kAdcThreshold);
+ }
+ }
+ delete [] adcValuesLow;
+ delete [] adcValuesHigh;
+
+ // write real header and close last file
+ for (Int_t iDDL=0; iDDL<maxDDL; iDDL++) {
+ if (buffer[iDDL]) {
+ buffer[iDDL]->Flush();
+ buffer[iDDL]->WriteDataHeader(kFALSE, kFALSE);
+ delete buffer[iDDL];
+ //if (mapping[iDDL]) delete mapping[iDDL];
+ }
+ }
+
+ AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n",
+ modMax,colMax,rowMax,eMax));
+
+ delete pulse;
+ loader->UnloadDigits();