+//____________________________________________________________________________
+void AliEMCAL::Digits2Raw()
+{
+// convert digits of the current event to raw data
+
+ // get the digits
+ AliEMCALGetter * gime = AliEMCALGetter::Instance(AliRunLoader::GetGAliceName()) ;
+ if (!gime) {
+ Error("Digits2Raw", "EMCAL Getter not instantiated") ;
+ return ;
+ }
+ gime->Event(gime->EventNumber(), "D") ;
+ TClonesArray* digits = gime->Digits() ;
+
+ if (!digits) {
+ Error("Digits2Raw", "no digits found !");
+ return;
+ }
+
+ // get the geometry
+ AliEMCALGeometry* geom = gime->EMCALGeometry();
+ if (!geom) {
+ Error("Digits2Raw", "no geometry found !");
+ return;
+ }
+
+ // some digitization constants
+ const Int_t kDDLOffset = 0x800;
+ const Int_t kThreshold = 3;
+ const Int_t kChannelsperDDL = 897 ;
+
+ AliAltroBuffer* buffer = NULL;
+ Int_t prevDDL = -1;
+ Int_t adcValuesLow[fkTimeBins];
+ Int_t adcValuesHigh[fkTimeBins];
+
+ // loop over digits (assume ordered digits)
+ for (Int_t iDigit = 0; iDigit < digits->GetEntries(); iDigit++) {
+ AliEMCALDigit* digit = gime->Digit(iDigit);
+ if (digit->GetAmp() < kThreshold)
+ continue;
+ Int_t iDDL = digit->GetId() / kChannelsperDDL ;
+ // for each DDL id is numbered from 1 to kChannelsperDDL -1
+ Int_t idDDL = digit->GetId() - iDDL * ( kChannelsperDDL - 1 ) ;
+ // new DDL
+ if (iDDL != prevDDL) {
+ // write real header and close previous file
+ if (buffer) {
+ buffer->Flush();
+ buffer->WriteDataHeader(kFALSE, kFALSE);
+ delete buffer;
+ }
+
+ // open new file and write dummy header
+ TString fileName("EMCAL_") ;
+ fileName += (iDDL + kDDLOffset) ;
+ fileName += ".ddl" ;
+ buffer = new AliAltroBuffer(fileName.Data(), 1);
+ buffer->WriteDataHeader(kTRUE, kFALSE); //Dummy;
+
+ prevDDL = iDDL;
+ }
+
+ // out of time range signal (?)
+ if (digit->GetTimeR() > fTimeMax) {
+ buffer->FillBuffer(digit->GetAmp());
+ buffer->FillBuffer(fkTimeBins); // time bin
+ buffer->FillBuffer(3); // bunch length
+ buffer->WriteTrailer(3, idDDL, 0, 0); // trailer
+
+ // simulate linear rise and gaussian decay of signal
+ } else {
+ Bool_t highGain = kFALSE;
+
+ // write low and eventually high gain channel
+ buffer->WriteChannel(iDDL, 0, 0,
+ fkTimeBins, adcValuesLow, kThreshold);
+ if (highGain) {
+ buffer->WriteChannel(iDDL, 0, fHighGainOffset,
+ fkTimeBins, adcValuesHigh, 1);
+ }
+ }
+ }
+ // write real header and close last file
+ if (buffer) {
+ buffer->Flush();
+ buffer->WriteDataHeader(kFALSE, kFALSE);
+ delete buffer;
+ }
+ gime->EmcalLoader()->UnloadDigits();
+}
+