]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCAltroEmulator.cxx
Updated list of libraries
[u/mrichter/AliRoot.git] / TPC / AliTPCAltroEmulator.cxx
index 8dfb3a03237f4ad8fd1486c2582d9141ee40f574..35e3ce1fd2ae2d420ea98391b21f5f99f43526f3 100644 (file)
@@ -17,6 +17,7 @@
  *     \verbinclude Altro/Altro.C.log
  *
  */
+
 /////////////////////////////////////////////////////////////////////////////////////////////////////
 //     Class for emulation of the ALTRO chip (Altro digital Chain) in C++                          //
 //     Author: Roland Bramm                                                                        //
@@ -105,9 +106,10 @@ AliTPCAltroEmulator::AliTPCAltroEmulator(Int_t timebins, short* Channel) :
   
   fReader(0),           // for Altro Emulation on Raw Reader
   fDecoder(0),
-  fDDLFolderName("/tmp/"),
-  fOutputDateFileName("/tmp/tmp.date"),
-  fOutputRootFileName("/tmp/tmp.root"),
+  fRunNumber(0), 
+  fDDLFolderName("./"),
+  fOutputDateFileName("./tmpRaw.date"),
+  fOutputRootFileName("./tmpRaw.root"),
   fIsRandom(kTRUE),
   fChannels(0),
   fCDHs(0),
@@ -117,93 +119,20 @@ AliTPCAltroEmulator::AliTPCAltroEmulator(Int_t timebins, short* Channel) :
   //
   // Constructor of Altro Class
   //
-  /*
-  ftimebins = timebins;
-  
-  fChannelShort_T = Channel;
-  
-  fOnBSL1 = 0;
-  fOnTCF = 0;
-  fOnBSL2 = 0;
-  fOnClip = 0;
-  fOnZSU = 0;
-  
-  fConfiguredAltro = 0;
-  fConfiguredBSL1 = 0;
-  fConfiguredTCF = 0;
-  fConfiguredBSL2 = 0;
-  fConfiguredZSU = 0;
-  */
-}
 
+  fADCkeep = new Short_t[1024]; 
 
-AliTPCAltroEmulator::AliTPCAltroEmulator(const AliTPCAltroEmulator &altro):
-  TNamed(),
-  ftimebins(altro.ftimebins),
-//  fChannelIn(Channel),
-  fChannelShort(altro.fChannelShort), 
-  fADCkeep(0),     
-  fOnBSL1(0), 
-  fOnTCF(0),  
-  fOnBSL2(0), 
-  fOnClip(0), 
-  fOnZSU(0),  
-
-  fConfiguredAltro(0),   // ConfiguredAltro
-  fConfiguredBSL1(0),    // ConfiguredBSL1
-  fConfiguredTCF(0),     // ConfiguredTCF
-  fConfiguredTCFraw(0),  // ConfiguredTCF
-  fConfiguredBSL2(0),    // ConfiguredBSL2
-  fConfiguredZSU(0),     // ConfiguredZSU
-  fBSL1mode(0),          // BSL1mode
-  fBSL1ValuePeDestal(0), // BSL1ValuePeDestal
-  fBSL1PedestalMem(0),  // BSL1PedestalMem
-  fBSL1polarity(0),      // BSL1polarity
-
-  fTCFK1(0), // K1
-  fTCFK2(0), // K2
-  fTCFK3(0), // K3
-  fTCFL1(0), // L1
-  fTCFL2(0), // L2
-  fTCFL3(0), // L3
-
-  fTCFK1Int(0), // K1Int
-  fTCFK2Int(0), // K2Int
-  fTCFK3Int(0), // K3Int
-  fTCFL1Int(0), // L1Int
-  fTCFL2Int(0), // L2Int
-  fTCFL3Int(0), // L3Int
-
-  fBSL2HighThreshold(0), // BSL2HighThreshold
-  fBSL2LowThreshold(0),  // BSL2LowThreshold
-  fBSL2Offset(0),        // BSL2Offset
-  fBSL2Presamples(0),    // BSL2Presamples(0),
-  fBSL2Postsamples(0),   // BSL2Postsamples
-
-  fZSUThreshold(0),      // ZSUThreshold
-
-  fZSUMinSamplesaboveThreshold(0), // ZSUMinSamplesaboveThreshold
-  fZSUPresamples(0),     // ZSUPresamples
-  fZSUPostsamples(0),     // ZSUPostsamples
-
-  fReader(0),           // for Altro Emulation on Raw Reader
-  fDecoder(0),
-  fDDLFolderName("/tmp/"),
-  fOutputDateFileName("/tmp/tmp.date"),
-  fOutputRootFileName("/tmp/tmp.root"),
-  fIsRandom(kTRUE),
-  fChannels(0),
-  fCDHs(0),
-  fADCs(0),
-  fTrailers(0),
-  fRawData(0) {
-  //
-  // copy constructor of Altro Class
-  //
+  fTCFK1IntROC[0]=0; fTCFK1IntROC[1]=0; // dummy defaults
+  fTCFK2IntROC[0]=0; fTCFK2IntROC[1]=0; // dummy defaults
+  fTCFK3IntROC[0]=0; fTCFK3IntROC[1]=0; // dummy defaults
+  fTCFL1IntROC[0]=0; fTCFL1IntROC[1]=0; // dummy defaults
+  fTCFL2IntROC[0]=0; fTCFL2IntROC[1]=0; // dummy defaults
+  fTCFL3IntROC[0]=0; fTCFL3IntROC[1]=0; // dummy defaults
 
 }
 
 
+
 /**    @brief Destructor of Altro Class
  *
  *     Destructor of Altro Class\n
@@ -213,8 +142,8 @@ AliTPCAltroEmulator::~AliTPCAltroEmulator() {
   // Destructor of Altro Class
   //
 
-  if(fConfiguredZSU == 1)
-    delete fADCkeep;
+  //  if(fConfiguredZSU == 1)
+  delete[] fADCkeep;
 
   delete[] fChannels;
   delete[] fCDHs    ;
@@ -225,21 +154,6 @@ AliTPCAltroEmulator::~AliTPCAltroEmulator() {
 
 }
 
-//_____________________________________________________________________________
-AliTPCAltroEmulator& AliTPCAltroEmulator::operator = (const AliTPCAltroEmulator &source)
-{
-  //
-  // AliTPCAltroEmulator assignment operator
-  //
-
-  if (&source == this) return *this;
-  new (this) AliTPCAltroEmulator(source);
-
-  return *this;
-
-}
-
-
 
 /**  @brief Configures which modules of the Altro should be on.
  *
@@ -286,7 +200,7 @@ void AliTPCAltroEmulator::ConfigBaselineCorrection1(Int_t mode, Int_t ValuePeDes
   //
   // Configures the Base Line Correction 1 (BSL1) Module
   //
-  fBSL1mode          = InRange(mode,0,10,"AliTPCAltroEmulator::ConfigBaselineCorrection1","mode");
+  fBSL1mode          = InRange(mode,0,16,"AliTPCAltroEmulator::ConfigBaselineCorrection1","mode");
   fBSL1ValuePeDestal = InRange(ValuePeDestal,0,1023,"AliTPCAltroEmulator::BaselineCorrection1","ValuePeDestal");
   fBSL1PedestalMem = PedestalMem;
   fBSL1polarity = InRange(polarity,0,1,"AliTPCAltroEmulator::BaselineCorrection1","polarity");
@@ -324,7 +238,8 @@ void AliTPCAltroEmulator::ConfigTailCancellationFilter(Int_t K1, Int_t K2, Int_t
   fTCFL3Int = InRange(L3,0,65535,"AliTPCAltroEmulator::ConfigTailCancellationFilter","L3");
   fConfiguredTCF = 1;
 }
-void AliTPCAltroEmulator::ConfigTailCancellationFilterForRAWfiles(Int_t *K1, Int_t *K2, Int_t *K3, Int_t *L1, Int_t *L2, Int_t *L3){
+void AliTPCAltroEmulator::ConfigTailCancellationFilterForRAWfiles(const Int_t *K1, const Int_t *K2, const Int_t *K3, 
+                                                                 const Int_t *L1, const Int_t *L2, const Int_t *L3){
   //
   // Configures the Tail Cancellation Filter (TCF) Module - Different settings for IROC and OROC
   //
@@ -394,7 +309,6 @@ void AliTPCAltroEmulator::ConfigZerosuppression(Int_t Threshold, Int_t MinSample
   fZSUMinSamplesaboveThreshold = InRange(MinSamplesaboveThreshold,1,3,"AliTPCAltroEmulator::BaselineCorrection1","MinSamplesaboveThreshold");
   fZSUPresamples               = InRange(Presamples,0,3,"AliTPCAltroEmulator::BaselineCorrection1","Presamples");
   fZSUPostsamples              = InRange(Postsamples,0,7,"AliTPCAltroEmulator::BaselineCorrection1","Postsamples");
-  fADCkeep = (Short_t *)calloc(sizeof(short),ftimebins);
   
   for(Int_t i = 0; i < ftimebins; i++){
     fADCkeep[i] = 0;
@@ -564,7 +478,18 @@ void AliTPCAltroEmulator::BaselineCorrection1(Int_t mode, Int_t ValuePeDestal, I
 
   //VPD == 0 !!
   Int_t fixedPeDestal = 0;
-  
+
+  // take first and last bins to calculate a mean pedestal value
+  Int_t window = 3;
+  Int_t meanPeDestal = 0;
+  if (mode == kDINxMPD && ftimebins>=6) {
+    for(Int_t i = 0; i < window; i++) {
+      meanPeDestal += fChannelShort[i];
+      meanPeDestal += fChannelShort[ftimebins-1-i];
+    }
+    meanPeDestal /= (window*2);
+  }
+    
   if(polarity ==1){
     for(Int_t i = 0; i < ftimebins; i++){
       fChannelShort[i]  = 1023 - fChannelShort[i];
@@ -616,6 +541,10 @@ void AliTPCAltroEmulator::BaselineCorrection1(Int_t mode, Int_t ValuePeDestal, I
     for(Int_t i = 0; i < ftimebins; i++)
       fChannelShort[i]  = PedestalMem[i] - fixedPeDestal;
     break;
+  case kDINxMPD:
+    for(Int_t i = 0; i < ftimebins; i++)
+      fChannelShort[i]  = fChannelShort[i] - meanPeDestal;
+    break;
   }
 }
 
@@ -642,7 +571,7 @@ long long AliTPCAltroEmulator::Mask(long long in, Int_t left, Int_t right){
   long long retval;
   long long pattern;
   long long length = abs(left - right)+1;
-  pattern = ((1<<length)-1)<<right;
+  pattern = ((((long long)1)<<length)-1)<<right;
   retval = in&pattern;
   return retval;
 }
@@ -654,7 +583,7 @@ long long AliTPCAltroEmulator::Maskandshift(long long in, Int_t left, Int_t righ
   long long retval;
   long long pattern;
   long long length = abs(left - right)+1;
-  pattern = ((1<<length)-1);
+  pattern = ((((long long)1)<<length)-1);
   retval = (in>>right)&pattern;
   return retval;
 }
@@ -881,19 +810,20 @@ void AliTPCAltroEmulator::Zerosuppression(Int_t Threshold, Int_t MinSamplesabove
   //Int_t setPostsample = 0;
 
   for(Int_t i = 0; i < ftimebins; i++){
-    if(fChannelShort[i] >= Threshold){
+    if(fChannelShort[i] >= Threshold)
       fADCkeep[i] = 1;
-    }
+    else
+      fADCkeep[i] = 0;
   }
 
   Int_t startofclustersequence = -1;
   Int_t endofClustersInSequence = -1;
   
   for(Int_t i = 0; i < ftimebins; i++){
-    if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i-1) == -1) ){
+    if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i-1) == 0) ){
       startofclustersequence = i;
     }
-    if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i+1) == -1) ){
+    if( (fADCkeep[i] == 1) && (GetElement(fADCkeep,i+1) == 0) ){
       endofClustersInSequence = i;
     }
     //cout << i << " startofclustersequence: " << startofclustersequence << " endofClustersInSequence: " << endofClustersInSequence;
@@ -948,7 +878,7 @@ void AliTPCAltroEmulator::Zerosuppression(Int_t Threshold, Int_t MinSamplesabove
   }
 
   for(Int_t i = 0; i < ftimebins; i++){
-    if( !GetKeepChannel(i) || GetShortChannel(i)<Threshold) {
+    if( !GetKeepChannel(i) ) {
       SetElement(fChannelShort,i,-1); // set non relevant data to -1
     }
   }
@@ -1050,11 +980,11 @@ Int_t AliTPCAltroEmulator::InRange(Int_t parameter,Int_t Low,Int_t High,const ch
   char out[255];
   Int_t retval;
   if(parameter > High){
-    sprintf(out,"Error | %s | Parameter %s is to big, has to be %d <= %s <= %d, is %d, now set to %d",Module,ParameterName,Low,ParameterName,High,parameter,High);
+    snprintf(out,255,"Error | %s | Parameter %s is to big, has to be %d <= %s <= %d, is %d, now set to %d",Module,ParameterName,Low,ParameterName,High,parameter,High);
     cout << out << endl;
     retval = High;
   }else if(parameter < Low){
-    sprintf(out,"Error | %s | Parameter %s is to small, has to be %d <= %s <= %d, is %d, now set to %d",Module,ParameterName,Low,ParameterName,High,parameter,Low);
+    snprintf(out,255,"Error | %s | Parameter %s is to small, has to be %d <= %s <= %d, is %d, now set to %d",Module,ParameterName,Low,ParameterName,High,parameter,Low);
     cout << out << endl;
     retval = Low;
   }else{
@@ -1091,79 +1021,82 @@ Bool_t AliTPCAltroEmulator::WriteEvent(Int_t ievent) {
     FILE *file=fopen(Form("%s/raw%d/TPC_%03d.ddl",
                          fDDLFolderName.Data(),ievent,768+ddlID),
                     "wb");
-    if (!file) return kFALSE;
-    Int_t i32;
-    // write CDH (first word to be altered later)
-    for (i32=0;i32<8;++i32)
-      fRawData[i32]=cdhDDL[i32];
-
-    // process payload
-    for (Int_t hwaddr=0;hwaddr<4096;++hwaddr) if (channelsDDL[hwaddr]) {
-      Short_t *adcsChannel=adcsDDL+hwaddr*1024;
-      // merge custers
-      // TODO: acqusition window
-      for (Int_t it=0;it<1024-3;++it) {
-       if (adcsChannel[it]>=0&&adcsChannel[it+3]>=0) {
-         if (adcsChannel[it+1]<0) {
-           //      printf("merge");
-           adcsChannel[it+1]=0;
-         }
-         if (adcsChannel[it+2]<0) {
-           //      printf("merge");
-           adcsChannel[it+2]=0;
+    if (!file) {
+      return kFALSE;
+    } else { 
+      Int_t i32;
+      // write CDH (first word to be altered later)
+      for (i32=0;i32<8;++i32)
+       fRawData[i32]=cdhDDL[i32];
+      
+      // process payload
+      for (Int_t hwaddr=0;hwaddr<4096;++hwaddr) if (channelsDDL[hwaddr]) {
+       Short_t *adcsChannel=adcsDDL+hwaddr*1024;
+       // merge custers
+       // TODO: acqusition window
+       for (Int_t it=0;it<1024-3;++it) {
+         if (adcsChannel[it]>=0&&adcsChannel[it+3]>=0) {
+           if (adcsChannel[it+1]<0) {
+             //            printf("merge");
+             adcsChannel[it+1]=0;
+           }
+           if (adcsChannel[it+2]<0) {
+             //            printf("merge");
+             adcsChannel[it+2]=0;
+           }
          }
        }
-      }
-      Int_t i10=3;
-      Int_t icw=0;
-      Int_t its=1;
-      Int_t cw =0;
-      Int_t ts =0;
-      for (Int_t it=1023;it>=0;--it) {
-       Short_t w10=adcsChannel[it];
-       if (w10>=0) {
-         if (cw<0) {
-           icw=i10++;
-           its=i10++;
-           cw =0    ;
-           ts=it    ;
+       Int_t i10=3;
+       Int_t icw=0;
+       Int_t its=1;
+       Int_t cw =0;
+       Int_t ts =0;
+       for (Int_t it=1023;it>=0;--it) {
+         Short_t w10=adcsChannel[it];
+         if (w10>=0) {
+           if (cw<0) {
+             icw=i10++;
+             its=i10++;
+             cw =0    ;
+             ts=it    ;
+           }
+           fRawData[i32+i10/3]|=w10<<(10*(2-i10%3));
+           ++i10;
+           ++cw;
          }
-         fRawData[i32+i10/3]|=w10<<(10*(2-i10%3));
-         ++i10;
-         ++cw;
-       }
-       else {
-         if (cw>=0) {
-           cw+=2;
-           fRawData[i32+icw/3]|=cw <<(10*(2-icw%3));
-           fRawData[i32+its/3]|=ts <<(10*(2-its%3));
-           cw=-1;
+         else {
+           if (cw>=0) {
+             cw+=2;
+             fRawData[i32+icw/3]|=cw <<(10*(2-icw%3));
+             fRawData[i32+its/3]|=ts <<(10*(2-its%3));
+             cw=-1;
+           }
          }
        }
+       fRawData[i32]=0x1<<30|(i10-3)<<16|hwaddr;
+       i32+=(i10+2)/3;
+       
+       // clean up
+       for (Int_t i=0;i<1024;++i) adcsChannel[i]=-1;
+       channelsDDL[hwaddr]=kFALSE;
       }
-      fRawData[i32]=0x1<<30|(i10-3)<<16|hwaddr;
-      i32+=(i10+2)/3;
+      
+      // write RCU trailer
+      fRawData[i32]=0x2<<30|(i32-8);i32++;
+      for (Int_t i=0;i<8;++i)
+       fRawData[i32++]=trailerDDL[i];
+      
+      // write first word of CDH
+      fRawData[0]=i32*4;
+      
+      Int_t nwritten=fwrite(fRawData,sizeof(UInt_t),i32,file);
+      fclose(file);
 
+      if (nwritten!=i32) return kFALSE;
+      
       // clean up
-      for (Int_t i=0;i<1024;++i) adcsChannel[i]=-1;
-      channelsDDL[hwaddr]=kFALSE;
+      do {fRawData[--i32]=0;} while (i32>0);
     }
-
-    // write RCU trailer
-    fRawData[i32]=0x2<<30|(i32-8);i32++;
-    for (Int_t i=0;i<8;++i)
-      fRawData[i32++]=trailerDDL[i];
-
-    // write first word of CDH
-    fRawData[0]=i32*4;
-    
-    Int_t nwritten=fwrite(fRawData,sizeof(UInt_t),i32,file);
-    if (nwritten!=i32) return kFALSE;
-
-    // clean up
-    do {fRawData[--i32]=0;} while (i32>0);
-
-    fclose(file);
   }
   return kTRUE;
 }
@@ -1209,11 +1142,14 @@ Bool_t AliTPCAltroEmulator::ConvertRawFilesToDate(Int_t nevents) {
   
   char command[100];
   FILE *pipe;
-  if (fReader->GetRunNumber()>0)
+
+  printf(" RAW to DATE CONVERSION: Run Number %d\n",fRunNumber);
+
+  if (fRunNumber>0)
     pipe=gSystem->OpenPipe(Form("dateStream -c -s -D -o %s -C -# %d -run %d", 
                                fOutputDateFileName.Data(),
                                nevents,
-                               fReader->GetRunNumber()),
+                               fRunNumber),
                           "w");
   else
     pipe=gSystem->OpenPipe(Form("dateStream -c -s -D -o %s -C -# %d", 
@@ -1224,7 +1160,7 @@ Bool_t AliTPCAltroEmulator::ConvertRawFilesToDate(Int_t nevents) {
     fprintf(stderr,"error: cannot execute command: %s",command);
     return kFALSE;
   }
-  
+
   for (Int_t ievent=0;ievent<nevents;++ievent) {
     UInt_t detectorPattern = 0xFFFFFFFF;
     fprintf(pipe, "GDC DetectorPattern %u\n", detectorPattern);
@@ -1257,12 +1193,11 @@ Bool_t AliTPCAltroEmulator::ConvertRawFilesToDate(Int_t nevents) {
          fprintf(pipe, " LDC Id %d\n", ldcID);
          prevLDC = ldcID;
        }
-       fprintf(pipe,Form("  Equipment Id %d Payload %s/raw%d/%s\n",
+       fprintf(pipe,"  Equipment Id %d Payload %s/raw%d/%s\n",
                          ddlID,
                          fDDLFolderName.Data(),
                          ievent,
-                         AliDAQ::DdlFileName(iDet,iDDL))
-               );
+                         (char*)AliDAQ::DdlFileName(iDet,iDDL) );
       }
     }
   }
@@ -1294,6 +1229,8 @@ Bool_t AliTPCAltroEmulator::ConvertDateToRoot() {
 
   // from $ALICE_ROOT/STEER/AliSimulation.cxx
 
+  printf(" DATE to ROOT CONVERSION: Run Number %d\n",fRunNumber);
+
   // ALIMDC setup
   const Int_t kDBSize    = 2000000000; //2GB
   const Int_t kTagDBSize = 1000000000;
@@ -1350,12 +1287,11 @@ void AliTPCAltroEmulator::RunEmulationOnRAWdata(AliRawReader *reader, Int_t plot
 
   InitBuffers();
   
-  TH1F hisO("DINO","DINO",1014,0,1014); 
-  TH1F his("DIN","DIN",1014,0,1014); 
-
   Int_t chanCount=0;
+  TH1F hisO("DINO","DINO",1024,0,1024); 
+  TH1F his("DIN","DIN",1024,0,1024); 
   his.GetYaxis()->SetRangeUser(-20,90);
-  Short_t *data = new Short_t[1014]; 
+  Short_t *data = new Short_t[1024]; 
   TCanvas *c1 =0;
   if (plotFlag) {
     c1 = new TCanvas("c1","c1");
@@ -1366,6 +1302,7 @@ void AliTPCAltroEmulator::RunEmulationOnRAWdata(AliRawReader *reader, Int_t plot
   Int_t ievent=0;
   while (fReader->NextEvent()) {
     
+    if (fReader->GetRunNumber()>0) fRunNumber=fReader->GetRunNumber();
     gSystem->Exec(Form("mkdir -p %s/raw%d/",fDDLFolderName.Data(),ievent));
     GDC2DDLs(const_cast<AliRawVEvent*>(fReader->GetEvent()),ievent);
     
@@ -1374,15 +1311,15 @@ void AliTPCAltroEmulator::RunEmulationOnRAWdata(AliRawReader *reader, Int_t plot
       Int_t ddlID=fDecoder->GetDDLNumber();
       printf("ddl: %d (%d/216)\n",ddlID,++ddlC);
      
-      Bool_t  *channelsDDL=fChannels+ddlID*4096     ;
-      Short_t *adcsDDL    =fADCs    +ddlID*4096*1024;
-      UInt_t  *cdhDDL     =fCDHs    +ddlID*8        ;
-      UInt_t  *trailerDDL =fTrailers+ddlID*9        ;
+      Bool_t  *channelsDDL=fChannels+ddlID*4096      ;
+      Short_t *adcsDDL    =fADCs    +ddlID*4096*1024 ;
+      UInt_t  *cdhDDL     =fCDHs    +ddlID*8         ;
+      UInt_t  *trailerDDL =fTrailers+ddlID*9         ;
       
       // CDH 
       for (Int_t i=0;i<8;++i)
-       // just to show how ugly it is...
-       cdhDDL[i]=reinterpret_cast<UInt_t*>(const_cast<AliRawDataHeader*>(fReader->GetDataHeader()))[i]; 
+       // just to show how ugly it is...
+       cdhDDL[i]=reinterpret_cast<UInt_t*>(const_cast<AliRawDataHeader*>(fReader->GetDataHeader()))[i]; 
       
       // PAYLOAD
       while (fDecoder->NextChannel()) {
@@ -1399,7 +1336,7 @@ void AliTPCAltroEmulator::RunEmulationOnRAWdata(AliRawReader *reader, Int_t plot
            Short_t s=signals[ci];
            Int_t   t=ts-ci;
            // TODO aqcuisition window
-           if (20<=t&&t<=1014) {
+           if (0<=t&&t<(1024-3)) {
              channelsDDL[hwaddr]=kTRUE;
              if (adcsChannel[t]<0)
                adcsChannel[t]=s;
@@ -1414,12 +1351,11 @@ void AliTPCAltroEmulator::RunEmulationOnRAWdata(AliRawReader *reader, Int_t plot
        // search start of aquisition
        Int_t t0 = 0;    while (adcsChannel[t0]==-1) t0++;
        // search end of aquisition
-       Int_t tE = 1014; while (adcsChannel[tE]==-1) tE--;
+       Int_t tE = 1024; while (adcsChannel[tE]==-1) tE--;
        
-       // SR TEST:
        // channel is complete - Perform Altro Emulation
        if (plotFlag!=0 && !(chanCount%plotFlag) ) {
-         for (Int_t t=0; t<1014; t++) {
+         for (Int_t t=0; t<1024; t++) {
            his.SetBinContent(t+1,adcsChannel[t]);
          }
          his.SetTitle(Form("sig_sec%d_row%d_pad%d",sector,row,pad));
@@ -1428,7 +1364,7 @@ void AliTPCAltroEmulator::RunEmulationOnRAWdata(AliRawReader *reader, Int_t plot
        }
 
        // FEED THE ALTRO EMULATOR WITH CLEAN SIGNAL (no aquisition-window ghosts)
-       Int_t timebins = tE-t0;
+       Int_t timebins = tE-t0+1;
        for (Int_t t=t0;t<(t0+timebins);t++)
          data[t-t0]=adcsChannel[t];
        SetChannelData(timebins,data);
@@ -1438,15 +1374,16 @@ void AliTPCAltroEmulator::RunEmulationOnRAWdata(AliRawReader *reader, Int_t plot
        for (Int_t t=t0;t<(t0+timebins);t++) 
          adcsChannel[t]=data[t-t0];
          
-       // SR TEST:
        if (plotFlag!=0 && !(chanCount%plotFlag) ) {
-         for (Int_t t=0; t<1014; t++)
+         for (Int_t t=0; t<1024; t++)
            hisO.SetBinContent(t+1,adcsChannel[t]);
          hisO.SetStats(0); hisO.SetLineColor(2);
          hisO.DrawCopy("same");
            
-         c1->SaveAs(Form("/tmp/sig_sec%02d_row%02d_pad%03d_%d%d%d%d%d.png",
-                         sector,row,pad,fOnBSL1,fOnTCF,fOnBSL2,fOnClip,fOnZSU));
+         c1->SaveAs(Form("%s/sig_sec%02d_row%02d_pad%03d_%s_%d%d%d%d%d.png",
+                         fDDLFolderName.Data(),sector,row,pad,
+                         fOutputRootFileName.Data(),
+                         fOnBSL1,fOnTCF,fOnBSL2,fOnClip,fOnZSU));
            
          his.Reset();
          hisO.Reset();
@@ -1460,14 +1397,14 @@ void AliTPCAltroEmulator::RunEmulationOnRAWdata(AliRawReader *reader, Int_t plot
       UChar_t *rcuTrailer;
       fDecoder->GetRCUTrailerData(rcuTrailer);
       for (Int_t i=0;i<= /* (!) */ fDecoder->GetRCUTrailerSize()/4;++i)
-       trailerDDL[i]=reinterpret_cast<UInt_t*>(rcuTrailer)[i]; // again: UGLY!
+       trailerDDL[i]=reinterpret_cast<UInt_t*>(rcuTrailer)[i]; // again: UGLY!
       
     }
             
-    WriteEvent(ievent++);
+    if (ddlC>0) WriteEvent(ievent++);
   }
 
-  delete data; // free space
+  delete[] data; // free space
 
   // convert to date and back
   ConvertRawFilesToDate(ievent);