+ Int_t *adcValuesLow = new Int_t[pulse->GetRawFormatTimeBins()];
+ Int_t *adcValuesHigh= new Int_t[pulse->GetRawFormatTimeBins()];
+
+ 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 = dynamic_cast<AliPHOSDigit *>(digits->At(iDigit)) ;
+ if (digit->GetEnergy() < kThreshold)
+ continue;
+ Int_t relId[4];
+ geom->AbsToRelNumbering(digit->GetId(), relId);
+ Int_t module = 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<32 && 0<=col&&col<28) iRCU=0;
+
+ //RCU1
+ if(0<=row&&row<32 && 28<=col&&col<56) iRCU=1;
+
+ //RCU2
+ if(32<=row&&row<64 && 0<=col&&col<28) iRCU=2;
+
+ //RCU3
+ if(32<=row&&row<64 && 28<=col&&col<56) iRCU=3;
+
+
+ // PHOS EMCA has 4 DDL per module. Splitting is based on the (row,column) numbers.
+ // PHOS internal convention: 1<module<5.
+ Int_t iDDL = 4 * (module - 1) + iRCU;
+
+ // new DDL
+ if (iDDL != prevDDL) {
+ if (buffer[iDDL] == 0) {
+ // open new file and write dummy header
+ TString fileName = AliDAQ::DdlFileName("PHOS",iDDL);
+
+ TString path = gSystem->Getenv("ALICE_ROOT");
+ path += "/PHOS/mapping/RCU";
+ path += iRCU;
+ path += ".data";
+
+ mapping[iDDL] = (AliAltroMapping*)maps->At(iRCU);
+ 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 ) {
+ AliInfo("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 ;
+ module = relId[0];
+ if (digit->GetId() <= geom->GetNModules() * geom->GetNCristalsInModule()) {
+ energy=digit->GetEnergy();
+ if(energy>eMax) {eMax=energy; modMax=module; colMax=col; rowMax=row;}
+ }
+ else {
+ energy = 0; // CPV raw data format is now know yet
+ }
+ pulse->SetAmplitude(energy);
+ pulse->SetTZero(digit->GetTimeR());
+ 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);
+ }
+ }
+
+ // 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];
+ }
+ }