]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSDDLRawData.cxx
Typo
[u/mrichter/AliRoot.git] / ITS / AliITSDDLRawData.cxx
index 56f96431abd10f800def435882d8d53cc3817dd0..0da200d76f3491787ed4c39ef879a4d5039cd391 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+/* $Id$ */
+
+
+//This class contains all the necessary methods to create the Raw Data
+//files (slides) for the ITS data challenges for:
+//SPD 
+//SDD
+//SSD
+
 #include <stdlib.h>
-#include "Riostream.h"
+#include <Riostream.h>
 #include <TClonesArray.h>
 #include <TTree.h>
-#include "TMath.h"
-#include <AliITS.h>
-#include <AliITSgeom.h>
-#include <AliITSdigit.h>
+#include <TMath.h>
+#include "AliITS.h"
+#include "AliITSgeom.h"
+#include "AliITSdigitSPD.h"
+#include "AliITSdigitSDD.h"
+#include "AliITSdigitSSD.h"
 #include "AliITSDDLRawData.h"
 
 ClassImp(AliITSDDLRawData)
 
 ////////////////////////////////////////////////////////////////////////////////////////
 AliITSDDLRawData::AliITSDDLRawData(){
+  //Default constructor
   fIndex=-1;
   fHalfStaveModule=-1;
+  fVerbose=0;
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////
 
-AliITSDDLRawData::AliITSDDLRawData(const AliITSDDLRawData &source){
-  // Copy Constructor
+AliITSDDLRawData::AliITSDDLRawData(const AliITSDDLRawData &source) : 
+    TObject(source){
+  //Copy Constructor
   this->fIndex=source.fIndex;
   this->fHalfStaveModule=source.fHalfStaveModule;
+  this->fVerbose=source.fVerbose;
   return;
 }
 
@@ -46,6 +61,7 @@ AliITSDDLRawData& AliITSDDLRawData::operator=(const AliITSDDLRawData &source){
   //Assigment operator
   this->fIndex=source.fIndex;
   this->fHalfStaveModule=source.fHalfStaveModule;
+  this->fVerbose=source.fVerbose;
   return *this;
 }
 
@@ -53,34 +69,43 @@ AliITSDDLRawData& AliITSDDLRawData::operator=(const AliITSDDLRawData &source){
 //STRIP 
 //
 
-void AliITSDDLRawData::GetDigitsSSD(TClonesArray *ITSdigits,Int_t mod, ULong_t *buf){
+void AliITSDDLRawData::GetDigitsSSD(TClonesArray *ITSdigits,Int_t mod,Int_t modR,Int_t ddl,UInt_t *buf){
+  //This method packs the SSD digits in a proper 32 bits structure
   Int_t ix;
   Int_t iz;
   Int_t is;
-  ULong_t Word;
-  ULong_t BaseWord;
+  UInt_t word;
+  UInt_t baseWord;
   Int_t ndigits = ITSdigits->GetEntries();
   AliITSdigit *digs;
+  ofstream ftxt;
   if(ndigits){
+    if (fVerbose==2){
+      ftxt.open("SSDdigits.txt",ios::app);
+    }
     for (Int_t digit=0;digit<ndigits;digit++) {
       digs = (AliITSdigit*)ITSdigits->UncheckedAt(digit);
-      iz=digs->fCoord1;  // If iz==0, N side and if iz=1 P side
-      ix=digs->fCoord2;  // Strip Numbar
-      is=digs->fSignal;  // ADC Signal
+      iz=digs->GetCoord1();  // If iz==0, N side and if iz=1 P side
+      ix=digs->GetCoord2();  // Strip Numbar
+      is=digs->GetSignal();  // ADC Signal
       // cout<<" Module:"<<mod-500<<" N/P side:"<<iz<<" Strip Number:"<<ix<<" Amplidute:"<<is-1<<endl;
-      BaseWord=0;
-      Word=is-1;
-      PackWord(BaseWord,Word,0,9);//ADC data
-      Word=ix;
-      PackWord(BaseWord,Word,10,19);//Strip Number
-      Word=iz;      
-      PackWord(BaseWord,Word,20,20);//ADC Channel ID (N or P side)
-      Word=mod;
-      PackWord(BaseWord,Word,21,31);//ADC module ID
+      if (fVerbose==2)
+       ftxt<<"DDL:"<<ddl<<" Mod: "<<modR<<" N/P: "<<iz<<" Strip: "<<ix<<" Value: "<<is-1<<endl;
+      baseWord=0;
+      word=is-1;
+      PackWord(baseWord,word,0,9);//ADC data
+      word=ix;
+      PackWord(baseWord,word,10,19);//Strip Number
+      word=iz;      
+      PackWord(baseWord,word,20,20);//ADC Channel ID (N or P side)
+      word=mod;
+      PackWord(baseWord,word,21,31);//ADC module ID
       fIndex++;
-      buf[fIndex]=BaseWord;
+      buf[fIndex]=baseWord;
     }//end for
   }//end if
+  if (fVerbose==2)
+    ftxt.close();
   return;
 }//end GetDigitsSSD
 
@@ -88,50 +113,58 @@ void AliITSDDLRawData::GetDigitsSSD(TClonesArray *ITSdigits,Int_t mod, ULong_t *
 //Silicon Drift Detector
 //
 
-void AliITSDDLRawData::GetDigitsSDD(TClonesArray *ITSdigits,Int_t mod, ULong_t *buf){  
+void AliITSDDLRawData::GetDigitsSDD(TClonesArray *ITSdigits,Int_t mod,Int_t modR,Int_t ddl,UInt_t *buf){  
+  //This method packs the SSD digits in a proper 32 bits structure
   Int_t ix;
   Int_t iz;
   Int_t is;
-  ULong_t Word;
-  ULong_t BaseWord;
+  UInt_t word;
+  UInt_t baseWord;
   Int_t ndigits = ITSdigits->GetEntries();
   AliITSdigit *digs;
+  ofstream ftxt;
   if(ndigits){
     //cout<<"Mudule "<<mod<<" number of digits "<<ndigits<<endl;
+    if (fVerbose==2)
+      ftxt.open("SDDdigits.txt",ios::app);
     for (Int_t digit=0;digit<ndigits;digit++) {
       digs = (AliITSdigit*)ITSdigits->UncheckedAt(digit);
-      iz=digs->fCoord1;  // Anode
-      ix=digs->fCoord2;  // Time
-      is=digs->fSignal;  // ADC Signal
+      iz=digs->GetCoord1();  // Anode
+      ix=digs->GetCoord2();  // Time
+      is=digs->GetSignal();  // ADC Signal
+      if (fVerbose==2)
+       ftxt<<"DDL:"<<ddl<<" MID:"<<modR<<" An:"<<iz<<" T:"<<ix<<" A:"<<is<<endl;
       //      cout<<"Amplitude value:"<<is<<" Time Bucket:"<<ix<<" Anode:"<<iz<<endl;
       if (is>255){cout<<"WARNING (!) bits words is needed)!!!\n";}
-      BaseWord=0;
+      baseWord=0;
       /*
       //10 bits words for amplitude value
-      Word=is;
-      PackWord(BaseWord,Word,0,9);//ADC data
-      Word=ix;
-      PackWord(BaseWord,Word,10,17);//Time bucket
-      Word=iz;
-      PackWord(BaseWord,Word,18,26);//Anode Number
-      Word=mod;
-      PackWord(BaseWord,Word,27,31);//Module number
+      word=is;
+      PackWord(baseWord,word,0,9);//ADC data
+      word=ix;
+      PackWord(baseWord,word,10,17);//Time bucket
+      word=iz;
+      PackWord(baseWord,word,18,26);//Anode Number
+      word=mod;
+      PackWord(baseWord,word,27,31);//Module number
       */
       
       //8bits words for amplitude value
-      Word=is;
-      PackWord(BaseWord,Word,0,7);//ADC data
-      Word=ix;
-      PackWord(BaseWord,Word,8,15);//Time bucket
-      Word=iz;
-      PackWord(BaseWord,Word,16,24);//Anode Number
-      Word=mod;
-      PackWord(BaseWord,Word,25,31);//Module number
+      word=is;
+      PackWord(baseWord,word,0,7);//ADC data
+      word=ix;
+      PackWord(baseWord,word,8,15);//Time bucket
+      word=iz;
+      PackWord(baseWord,word,16,24);//Anode Number
+      word=mod;
+      PackWord(baseWord,word,25,31);//Module number
      
       fIndex++;
-      buf[fIndex]=BaseWord;
+      buf[fIndex]=baseWord;
     }//end for
   }//end if
+  if(fVerbose==2)
+    ftxt.close();
   return;
 }//end GetDigitsSDD
 
@@ -139,143 +172,162 @@ void AliITSDDLRawData::GetDigitsSDD(TClonesArray *ITSdigits,Int_t mod, ULong_t *
 //PIXEL 
 //
 
-void AliITSDDLRawData::GetDigitsSPD(TClonesArray *ITSdigits,Int_t mod, ULong_t *buf){
+void AliITSDDLRawData::GetDigitsSPD(TClonesArray *ITSdigits,Int_t mod,Int_t ddl, UInt_t *buf){
+  //This method packs the SPD digits in a proper 32 structure
+  //Since data is zero suppressed,the coordinates for the chip having zero digits 
+  //doesn't get listed in the galice.root file. However the SPD format requires 
+  //the empty chip to be written with chip header and chip trailer.
   Int_t ix;
   Int_t iz;
-  Int_t ChipNo=0;
-  ULong_t BaseWord=0;
-  ULong_t HitRow=0;
-  Int_t ChipHitCount=0;  //Number of Hit in the current chip
-  Int_t PreviousChip=-1; //Previuos chip respect to the actual aone
+  Int_t chipNo=0;
+  UInt_t baseWord=0;
+  UInt_t hitRow=0;
+  Int_t chipHitCount=0;  //Number of Hit in the current chip
+  Int_t previousChip=-1; //Previuos chip respect to the actual aone
   Int_t ndigits = ITSdigits->GetEntries(); //number of digits in the current module
   //cout<<"      Number of digits in the current module:"<<ndigits<<" module:"<<mod<<endl;
   AliITSdigit *digs;
   fHalfStaveModule++;    //It's a private variable used to distinguish between the firs  
                          //and the second module of an Half Stave Module
+  ofstream ftxt;
   if(ndigits){
     //loop over digits
+    if (fVerbose==2)
+      ftxt.open("SPDdigits.txt",ios::app);
     for (Int_t digit=0;digit<ndigits;digit++){
       digs = (AliITSdigit*)ITSdigits->UncheckedAt(digit);
       /*---------------------------------------------------------------------------
        *     Each module contains 5 read out chips of 256 rows and 32 columns.
-       *     So, the cell number in Z direction varies from 1 to 160.  Therefore,
+       *     So, the cell number in Z direction varies from 0 to 159.  Therefore,
        *     to get the chip address (0 to 4), we need to divide column number by 32.
        *     ---------------------------------------------------------------------*/
-      iz=digs->fCoord1;  // Cell number in Z direction 
-      ix=digs->fCoord2;  // Cell number in X direction
-      ChipNo=iz/32;
-      HitRow=iz-ChipNo*32;
+      iz=digs->GetCoord1();  // Cell number in Z direction 
+      ix=digs->GetCoord2();  // Cell number in X direction
+      chipNo=iz/32;
+      if(fVerbose==2)
+       ftxt<<"DDL:"<<ddl<<" Mod:"<<mod<<" Row:"<<ix<<" Col:"<<iz<<endl;
+      hitRow=iz-chipNo*32;
       if(fHalfStaveModule){
-       ChipNo+=5;
+       chipNo+=5;
        fHalfStaveModule=-1;
       }//end if
-      //cout<<"Chip number of the current digit:"<<ChipNo<<" Row:"<<HitRow<<" Column:"<<ix<<endl;
-      if(PreviousChip==-1){
+      if(previousChip==-1){
        //loop over chip without digits 
        //Even if there aren't digits for a given chip 
        //the chip header and the chip trailer are stored
        for(Int_t i=0;i<(iz/32);i++){
-         if(ChipNo>4)
-           WriteChipHeader(i+5,(mod/2),BaseWord);
+         if(chipNo>4)
+           WriteChipHeader(i+5,(mod/2),baseWord);
          else
-           WriteChipHeader(i,(mod/2),BaseWord);
-         WriteChipTrailer(buf,ChipHitCount,BaseWord);
+           WriteChipHeader(i,(mod/2),baseWord);
+         WriteChipTrailer(buf,chipHitCount,baseWord);
+         chipHitCount=0;
        }//end for
-       PreviousChip=ChipNo;
-       WriteChipHeader(ChipNo,(mod/2),BaseWord);
-       ChipHitCount++;
-       WriteHit(buf,ix,HitRow,BaseWord);
+       WriteChipHeader(chipNo,(mod/2),baseWord);
+       chipHitCount++;
+       WriteHit(buf,ix,hitRow,baseWord);
+       previousChip=chipNo;
       }//end if
       else{
-       ChipHitCount++;
-       if(PreviousChip!=ChipNo){
-         WriteChipTrailer(buf,ChipHitCount-1,BaseWord);
-         for(Int_t i=PreviousChip+1;i<ChipNo;i++){
-           WriteChipHeader(i,(mod/2),BaseWord);
-           WriteChipTrailer(buf,0,BaseWord);
+       if(previousChip!=chipNo){
+         WriteChipTrailer(buf,chipHitCount,baseWord);
+         chipHitCount=0;
+         for(Int_t i=previousChip+1;i<chipNo;i++){
+           WriteChipHeader(i,(mod/2),baseWord);
+           WriteChipTrailer(buf,0,baseWord);
+           chipHitCount=0;
          }//end for
-         WriteChipHeader(ChipNo,(mod/2),BaseWord);
-         PreviousChip=ChipNo;
+         WriteChipHeader(chipNo,(mod/2),baseWord);
+         previousChip=chipNo;
        }//end if
-       WriteHit(buf,ix,HitRow,BaseWord);
+       chipHitCount++;
+       WriteHit(buf,ix,hitRow,baseWord);
       }//end else
     }//end for
     //Even if there aren't digits for a given chip 
     //the chip header and the chip trailer are stored
-    Int_t End=4;
-    if(ChipNo>4)End+=5;
-    WriteChipTrailer(buf,ChipHitCount,BaseWord);
-    for(Int_t i=ChipNo+1;i<=End;i++){
-      WriteChipHeader(i,(mod/2),BaseWord);
-      WriteChipTrailer(buf,0,BaseWord);
+    Int_t end=4;
+    if(chipNo>4)end+=5;
+    WriteChipTrailer(buf,chipHitCount,baseWord);
+    chipHitCount=0;
+    for(Int_t i=chipNo+1;i<=end;i++){
+      WriteChipHeader(i,(mod/2),baseWord);
+      WriteChipTrailer(buf,0,baseWord);
+      chipHitCount=0;
     }//end for
   }//end if
   else{
     //In this module there aren't digits but
     //the chip header and chip trailer are store anyway
     if(fHalfStaveModule){
-      ChipNo=5;
+      chipNo=5;
       fHalfStaveModule=-1;
     }//end if
     for(Int_t i=0;i<5;i++){
-      WriteChipHeader(ChipNo+i,(mod/2),BaseWord);
-      WriteChipTrailer(buf,ChipHitCount,BaseWord);
+      WriteChipHeader(chipNo+i,(mod/2),baseWord);
+      WriteChipTrailer(buf,chipHitCount,baseWord);
+      chipHitCount=0;
     }//end for
   }//end else 
+  if(fVerbose==2)
+    ftxt.close();
   return;
 }//end GetDigitsSPD
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-void AliITSDDLRawData::PackWord(ULong_t &BaseWord, ULong_t Word, Int_t StartBit, Int_t StopBit){
-  ULong_t DummyWord,OffSet;
-  Int_t   Length;
-  ULong_t Sum;
+void AliITSDDLRawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit){
+  //This method packs a word into the Baseword buffer starting form the "StartBit" 
+  //and tacking StopBit-StertBit+1 bits
+  UInt_t dummyWord,offSet;
+  Int_t   length;
+  UInt_t sum;
   //The BaseWord is being filled with 1 from StartBit to StopBit
-  Length=StopBit-StartBit+1;
-  Sum=(ULong_t)TMath::Power(2,Length)-1;
-  if(Word > Sum){
+  length=StopBit-StartBit+1;
+  sum=(UInt_t)TMath::Power(2,length)-1;
+  if(Word > sum){
     cout<<"WARNING::Word to be filled is not within desired length"<<endl;
     cout<<"Word:"<<Word<<" Start bit:"<<StartBit<<" Stop Bit:"<<StopBit<<endl;
     exit(-1);
   }
-  OffSet=Sum;
-  OffSet<<=StartBit;
-  BaseWord=BaseWord|OffSet;
+  offSet=sum;
+  offSet<<=StartBit;
+  BaseWord=BaseWord|offSet;
   //The Word to be filled is shifted to the position StartBit
   //and the remaining  Left and Right bits are filled with 1
-  Sum=(ULong_t)TMath::Power(2,StartBit)-1;
-  DummyWord=0xFFFFFFFF<<Length;
-  DummyWord +=Word;
-  DummyWord<<=StartBit;
-  DummyWord+=Sum;
-  BaseWord=BaseWord&DummyWord;
+  sum=(UInt_t)TMath::Power(2,StartBit)-1;
+  dummyWord=0xFFFFFFFF<<length;
+  dummyWord +=Word;
+  dummyWord<<=StartBit;
+  dummyWord+=sum;
+  BaseWord=BaseWord&dummyWord;
   return;
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-void AliITSDDLRawData::UnpackWord(ULong_t PackedWord, Int_t StartBit, Int_t StopBit, ULong_t &Word){   
-  ULong_t OffSet;
-  Int_t Length;
-  Length=StopBit-StartBit+1;
-  OffSet=(ULong_t)TMath::Power(2,Length)-1;
-  OffSet<<=StartBit;
-  Word=PackedWord&OffSet;
+void AliITSDDLRawData::UnpackWord(UInt_t PackedWord, Int_t StartBit, Int_t StopBit, UInt_t &Word){     
+  //This method unpacks a words of StopBit-StertBit+1 bits starting from "StopBits"  
+  UInt_t offSet;
+  Int_t length;
+  length=StopBit-StartBit+1;
+  offSet=(UInt_t)TMath::Power(2,length)-1;
+  offSet<<=StartBit;
+  Word=PackedWord&offSet;
   Word>>=StartBit;
   return;
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-Int_t AliITSDDLRawData::RawDataSPD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
-
+Int_t AliITSDDLRawData::RawDataSPD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber,Int_t eventNumber){
+  //This method creates the Raw data files for SPD detectors
   //Silicon Pixel Detector
-  const Int_t DDLNumber=20;       // Number of DDL in SPD
-  const Int_t ModulePerDDL=12;    // Number of modules in each DDL 
+  const Int_t kDDLsNumber=20;       // Number of DDL in SPD
+  const Int_t kModulesPerDDL=12;    // Number of modules in each DDL 
   //Row    ==> DDLs
   //Column ==> Modules
-  Int_t SPDMap[DDLNumber][ModulePerDDL]={{ 0, 1, 4, 5, 80, 81, 84, 85, 88, 89, 92, 93},
+  Int_t mapSPD[kDDLsNumber][kModulesPerDDL]={{ 0, 1, 4, 5, 80, 81, 84, 85, 88, 89, 92, 93},
                                         { 2, 3, 6, 7, 82, 83, 86, 87, 90, 91, 94, 95},
                                         { 8, 9,12,13, 96, 97,100,101,104,105,108,109},
                                         {10,11,14,15, 98, 99,102,103,106,107,110,111},
@@ -287,7 +339,7 @@ Int_t AliITSDDLRawData::RawDataSPD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
                                         {34,35,38,39,146,147,150,151,154,155,158,159},
                                         {40,41,44,45,160,161,164,165,168,169,172,173},
                                         {42,43,46,47,162,163,166,167,170,171,174,175},
-                                        {48,47,50,51,176,177,180,181,184,185,188,189},
+                                        {48,49,52,53,176,177,180,181,184,185,188,189},
                                         {50,51,54,55,178,179,182,183,186,187,190,191},
                                         {56,57,60,61,192,193,196,197,200,201,204,205},
                                         {58,59,62,63,194,195,198,199,202,203,206,207},
@@ -295,51 +347,56 @@ Int_t AliITSDDLRawData::RawDataSPD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
                                         {66,67,70,71,210,211,214,215,218,219,222,223},
                                         {72,73,76,77,224,225,228,229,232,233,236,237},
                                         {74,75,78,79,226,227,230,231,234,235,238,239}};
-  Int_t DDLPerFile=DDLNumber/LDCsNumber;
-  if(DDLNumber%LDCsNumber)DDLPerFile++;
-  cout<<"Number of DDL per File: "<<DDLPerFile<<endl;
+  Int_t ddlsPerFile=kDDLsNumber/LDCsNumber;
+  if(kDDLsNumber%LDCsNumber)ddlsPerFile++;
+  if(fVerbose)
+    cout<<"Number of DDL per File: "<<ddlsPerFile<<endl;
   Int_t subd=0;
-  Int_t CountDDL=0;
-  Int_t SliceNumber=1;
-  const Int_t size=21000; //256*32*5=40960 max number of digits per module
-  ULong_t buf[size];      //One buffer cell can contain 2 digits 
+  Int_t countDDL=0;
+  Int_t sliceNumber=1;
+  const Int_t kSize=21000; //256*32*5=40960 max number of digits per module
+  UInt_t buf[kSize];      //One buffer cell can contain 2 digits 
   fIndex=-1;
-  TClonesArray *ITSdigits  = ITS->DigitsAddress(subd);
+  TClonesArray *digitsInITS  = ITS->DigitsAddress(subd);
 
   Int_t nbytes = 0; 
   char fileName[15];
 
-  ULong_t MiniHeaderPosition=0; //variable used to store the position of the Mini Header inside a file
+  UInt_t miniHeaderPosition=0; //variable used to store the position of the Mini Header inside a file
   ofstream outfile;         // logical name of the output file 
-  Int_t Flag=0;             // 0==> Uncompressed data 1==>Compressed Data
-  Int_t Detector=1;         // 1==>ITS (Pixel) 2==>ITS (Drift) 3==>ITS (Strip) 0==>TPC ......
-  ULong_t Size=0;           // Size of the data block that follows the mini header
-  Int_t MagicWord=0x123456;  // Magic word used to distinguish between data and garbage
-  sprintf(fileName,"SPDslice%d",SliceNumber); //The name of  the output file. There are as many slides as the number of LDC
+  Int_t flag=0;             // 0==> Uncompressed data 1==>Compressed Data
+  Int_t detector=1;         // 1==>ITS (Pixel) 2==>ITS (Drift) 3==>ITS (Strip) 0==>TPC ......
+  UInt_t size=0;           // size of the data block that follows the mini header
+  Int_t magicWord=0x123456;  // Magic word used to distinguish between data and garbage
+  sprintf(fileName,"Ev%dSPDslice%d",eventNumber,sliceNumber); //The name of  the output file. There are as many slides as the number of LDC
+#ifndef __DECCXX
   outfile.open(fileName,ios::binary);
-  ULong_t MiniHeader[3];
-  Int_t MiniHeaderSize=sizeof(ULong_t)*3;
-  Int_t Version=1;          //Version of the mini header 
+#else
+  outfile.open(fileName);
+#endif
+  UInt_t miniHeader[3];
+  Int_t miniHeaderSize=sizeof(UInt_t)*3;
+  Int_t version=1;          //version of the mini header 
   //loop over DDLs
-  for(Int_t i=0;i<DDLNumber;i++){
-    CountDDL++;
+  for(Int_t i=0;i<kDDLsNumber;i++){
+    countDDL++;
     //write Dummy MINI HEADER
-    MiniHeader[0]=Size;
-    PackWord(MiniHeader[1],MagicWord,8,31);
-    PackWord(MiniHeader[1],Detector,0,7);
-    PackWord(MiniHeader[2],i,16,31);
-    PackWord(MiniHeader[2],Flag,8,15);
-    PackWord(MiniHeader[2],Version,0,7);
-    MiniHeaderPosition=outfile.tellp();
-    outfile.write((char*)(MiniHeader),MiniHeaderSize);
+    miniHeader[0]=size;
+    PackWord(miniHeader[1],magicWord,8,31);
+    PackWord(miniHeader[1],detector,0,7);
+    PackWord(miniHeader[2],i,16,31);
+    PackWord(miniHeader[2],flag,8,15);
+    PackWord(miniHeader[2],version,0,7);
+    miniHeaderPosition=outfile.tellp();
+    outfile.write((char*)(miniHeader),miniHeaderSize);
     //Loops over Modules of a particular DDL
-    for (Int_t mod=0; mod<ModulePerDDL; mod++){
+    for (Int_t mod=0; mod<kModulesPerDDL; mod++){
       ITS->ResetDigits();
-      nbytes += TD->GetEvent(SPDMap[i][mod]);
+      nbytes += TD->GetEvent(mapSPD[i][mod]);
       //For each Module, buf contains the array of data words in Binary format   
       //fIndex gives the number of 32 bits words in the buffer for each module
-      GetDigitsSPD(ITSdigits,SPDMap[i][mod],buf);
-      outfile.write((char *)buf,((fIndex+1)*sizeof(ULong_t)));
+      GetDigitsSPD(digitsInITS,mapSPD[i][mod],i,buf);
+      outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
       for(Int_t i=0;i<(fIndex+1);i++){
        buf[i]=0;
       }//end for
@@ -347,19 +404,23 @@ Int_t AliITSDDLRawData::RawDataSPD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
     }//end for
     
     //Write REAL MINI HEADER
-    ULong_t CurrentFilePosition=outfile.tellp();
-    outfile.seekp(MiniHeaderPosition);
-    Size=CurrentFilePosition-MiniHeaderPosition-MiniHeaderSize;
+    UInt_t currentFilePosition=outfile.tellp();
+    outfile.seekp(miniHeaderPosition);
+    size=currentFilePosition-miniHeaderPosition-miniHeaderSize;
     
-    outfile.write((char*)(&Size),sizeof(ULong_t));
-    outfile.seekp(CurrentFilePosition);
-    if(CountDDL==DDLPerFile){
+    outfile.write((char*)(&size),sizeof(UInt_t));
+    outfile.seekp(currentFilePosition);
+    if(countDDL==ddlsPerFile){
       outfile.close();
-      SliceNumber++;
-      sprintf(fileName,"SPDslice%d",SliceNumber); 
-      if(i!=(DDLNumber-1))
+      sliceNumber++;
+      sprintf(fileName,"Ev%dSPDslice%d",eventNumber,sliceNumber); 
+      if(i!=(kDDLsNumber-1))
+#ifndef __DECCXX
        outfile.open(fileName,ios::binary);
-      CountDDL=0;
+#else
+       outfile.open(fileName);
+#endif
+      countDDL=0;
     }//end if
   }//end for
   outfile.close();
@@ -368,14 +429,15 @@ Int_t AliITSDDLRawData::RawDataSPD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
+Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber,Int_t eventNumber){
+  //This method creates the Raw data files for SSD detectors
   //Strip detector
-  const Int_t DDLNumber=16;        // Number of DDL in SSD
-  const Int_t ModulePerDDL=109;    // Number of modules in each DDL 
+  const Int_t kDDLsNumber=16;        // Number of DDL in SSD
+  const Int_t kModulesPerDDL=109;    // Number of modules in each DDL 
   //DDL from 32 to 47 (16 DDL)
   //Row    ==> DDLs
   //Column ==> Modules
-  Int_t SSDMap[DDLNumber][ModulePerDDL]={
+  Int_t mapSSD[kDDLsNumber][kModulesPerDDL]={
     //104
     //DDL[32][]=
     { 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510,
@@ -389,15 +451,15 @@ Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
       2173,2174,2175,2176,2177,2178,2179,2180,2181,2182,2183,2184,-1,-1,-1,-1,-1},    
     //93
     //DDL[33][]=
-    { 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576,
+    { 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554,
+      566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576,
       588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598,
       610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620,
       1273,1274,1275,1276,1277,1278,1279,1280,1281,1282,1283,1284,
       1298,1299,1300,1301,1302,1303,1304,1305,1306,1307,1308,1309,
       1323,1324,1325,1326,1327,1328,1329,1330,1331,1332,1333,1334,
       1348,1349,1350,1351,1352,1353,1354,1355,1356,1357,1358,1359,
-      1373,1374,1375,1376,1377,1378,1379,1380,1381,1382,1383,1384,
-      -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,-1,-1,-1,-1},
+      1373,1374,1375,1376,1377,1378,1379,1380,1381,1382,1383,1384,-1,-1,-1,-1,-1},
     //103
     //DDL[34][]=
     { 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642,
@@ -428,7 +490,7 @@ Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
       896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906,
       1623,1624,1625,1626,1627,1628,1629,1630,1631,1632,1633,1634,
       1648,1649,1650,1651,1652,1653,1654,1655,1656,1657,1658,1659,
-      1673,1674,1675,1676,1677,1678,1679,1680,1681,1682,1682,1684,
+      1673,1674,1675,1676,1677,1678,1679,1680,1681,1682,1683,1684,
       1698,1699,1700,1701,1702,1703,1704,1705,1706,1707,1708,1709,
       1723,1724,1725,1726,1727,1728,1729,1730,1731,1732,1733,1734,-1,-1,-1,-1,-1},
     //104
@@ -483,7 +545,7 @@ Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
       621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631,
       1285,1286,1287,1288,1289,1290,1291,1292,1293,1294,1295,1296,1297,
       1310,1311,1312,1313,1314,1315,1316,1317,1318,1319,1320,1321,1322,
-      1335,1336,1337,1338,1339,1340,1341,1342,1443,1344,1345,1346,1347,
+      1335,1336,1337,1338,1339,1340,1341,1342,1343,1344,1345,1346,1347,
       1360,1361,1362,1363,1364,1365,1366,1367,1368,1369,1370,1371,1372,
       1385,1386,1387,1388,1389,1390,1391,1392,1393,1394,1395,1396,1397},
     //107
@@ -506,7 +568,7 @@ Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
       1510,1511,1512,1513,1514,1515,1516,1517,1518,1519,1520,1521,1522,
       1535,1536,1537,1538,1539,1540,1541,1542,1543,1544,1545,1546,1547,
       1560,1561,1562,1563,1564,1565,1566,1567,1568,1569,1570,1571,1572,
-      1585,1586,1587,1588,1589,1590,1591,1592,1593,1584,1595,1596,1597,
+      1585,1586,1587,1588,1589,1590,1591,1592,1593,1594,1595,1596,1597,
       1610,1611,1612,1613,1614,1615,1616,1617,1618,1619,1620,1621,1622},
     //109
     //DDL[44][]=
@@ -554,53 +616,58 @@ Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
      2085,2086,2087,2088,2089,2090,2091,2092,2093,2094,2095,2096,2097} };
 
 
-  Int_t DDLPerFile=DDLNumber/LDCsNumber;
-  if(20%LDCsNumber)DDLPerFile++;
-  cout<<"Number of DDL per File: "<<DDLPerFile<<endl;
+  Int_t ddlsPerFile=kDDLsNumber/LDCsNumber;
+  if(kDDLsNumber%LDCsNumber)ddlsPerFile++;
+  if(fVerbose)
+    cout<<"Number of DDL per File: "<<ddlsPerFile<<endl;
   Int_t subd=2;          //SSD
-  Int_t CountDDL=0;
-  Int_t SliceNumber=1;
-  const Int_t size=1536;//768*2 Number of stripe * number of sides(N and P)
-  ULong_t buf[size];      
+  Int_t countDDL=0;
+  Int_t sliceNumber=1;
+  const Int_t kSize=1536;//768*2 Number of stripe * number of sides(N and P)
+  UInt_t buf[kSize];      
   fIndex=-1;
   Int_t nbytes = 0; 
-  TClonesArray *ITSdigits  = ITS->DigitsAddress(subd);
+  TClonesArray *digitsInITS  = ITS->DigitsAddress(subd);
   char fileName[15];
 
-  ULong_t MiniHeaderPosition=0; //variable used to store the position of the Mini Header inside the file
+  UInt_t miniHeaderPosition=0; //variable used to store the position of the Mini Header inside the file
   ofstream outfile;             // logical name of the output file 
-  Int_t Flag=0;                 // 0==> Uncompressed data 1==>Compressed Data
-  Int_t Detector=3;             // 1==>ITS (Pixel) 2==>ITS (Drift) 3==>ITS (Strip) 0==>TPC ......
-  ULong_t Size=0;               // Size of the data block that follows the mini header
-  Int_t MagicWord=0x123456;     // Magic word used to distinguish between data and garbage
-  sprintf(fileName,"SSDslice%d",SliceNumber); //The name of  the output file. There are as many slides as the number of LDC
+  Int_t flag=0;                 // 0==> Uncompressed data 1==>Compressed Data
+  Int_t detector=3;             // 1==>ITS (Pixel) 2==>ITS (Drift) 3==>ITS (Strip) 0==>TPC ......
+  UInt_t size=0;               // size of the data block that follows the mini header
+  Int_t magicWord=0x123456;     // Magic word used to distinguish between data and garbage
+  sprintf(fileName,"Ev%dSSDslice%d",eventNumber,sliceNumber); //The name of  the output file. There are as many slides as the number of LDC
+#ifndef __DECCXX
   outfile.open(fileName,ios::binary);
-  ULong_t MiniHeader[3];
-  Int_t MiniHeaderSize=sizeof(ULong_t)*3;
-  Int_t Version=1;              //Version of the mini header 
+#else
+  outfile.open(fileName);
+#endif
+  UInt_t miniHeader[3];
+  Int_t miniHeaderSize=sizeof(UInt_t)*3;
+  Int_t version=1;              //version of the mini header 
   //loop over DDLs
   
-  for(Int_t i=0;i<DDLNumber;i++){
-    CountDDL++;
+  for(Int_t i=0;i<kDDLsNumber;i++){
+    countDDL++;
     //write Dummy MINI HEADER
-    MiniHeader[0]=Size;
-    PackWord(MiniHeader[1],MagicWord,8,31);
-    PackWord(MiniHeader[1],Detector,0,7);
-    PackWord(MiniHeader[2],i,16,31);
-    PackWord(MiniHeader[2],Flag,8,15);
-    PackWord(MiniHeader[2],Version,0,7);
-    MiniHeaderPosition=outfile.tellp();
-    outfile.write((char*)(MiniHeader),MiniHeaderSize);
+    miniHeader[0]=size;
+    PackWord(miniHeader[1],magicWord,8,31);
+    PackWord(miniHeader[1],detector,0,7);
+    PackWord(miniHeader[2],i,16,31);
+    PackWord(miniHeader[2],flag,8,15);
+    PackWord(miniHeader[2],version,0,7);
+    miniHeaderPosition=outfile.tellp();
+    outfile.write((char*)(miniHeader),miniHeaderSize);
     
     //Loops over Modules of a particular DDL
-    for (Int_t mod=0; mod<ModulePerDDL; mod++){
-      if(SSDMap[i][mod]!=-1){
+    for (Int_t mod=0; mod<kModulesPerDDL; mod++){
+      if(mapSSD[i][mod]!=-1){
        ITS->ResetDigits();
-       nbytes += TD->GetEvent(SSDMap[i][mod]);
+       nbytes += TD->GetEvent(mapSSD[i][mod]);
        //For each Module, buf contains the array of data words in Binary format          
        //fIndex gives the number of 32 bits words in the buffer for each module
-       GetDigitsSSD(ITSdigits,mod,buf);
-       outfile.write((char *)buf,((fIndex+1)*sizeof(ULong_t)));
+       GetDigitsSSD(digitsInITS,mod,mapSSD[i][mod],i,buf);
+       outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
        for(Int_t i=0;i<(fIndex+1);i++){
          buf[i]=0;
        }//end for
@@ -608,19 +675,23 @@ Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
       }//end if
     }//end for
     //Write REAL MINI HEADER
-    ULong_t CurrentFilePosition=outfile.tellp();
-    outfile.seekp(MiniHeaderPosition);
-    Size=CurrentFilePosition-MiniHeaderPosition-MiniHeaderSize;
+    UInt_t currentFilePosition=outfile.tellp();
+    outfile.seekp(miniHeaderPosition);
+    size=currentFilePosition-miniHeaderPosition-miniHeaderSize;
     
-    outfile.write((char*)(&Size),sizeof(ULong_t));
-    outfile.seekp(CurrentFilePosition);
-    if(CountDDL==DDLPerFile){
+    outfile.write((char*)(&size),sizeof(UInt_t));
+    outfile.seekp(currentFilePosition);
+    if(countDDL==ddlsPerFile){
       outfile.close();
-      SliceNumber++;
-      sprintf(fileName,"SSDslice%d",SliceNumber); 
-      if(i!=(DDLNumber-1))
+      sliceNumber++;
+      sprintf(fileName,"Ev%dSSDslice%d",eventNumber,sliceNumber); 
+      if(i!=(kDDLsNumber-1))
+#ifndef __DECCXX
        outfile.open(fileName,ios::binary);
-      CountDDL=0;
+#else
+       outfile.open(fileName);
+#endif
+      countDDL=0;
     }//end if
   }//end for
   outfile.close();
@@ -629,13 +700,14 @@ Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-Int_t AliITSDDLRawData::RawDataSDD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
-  //Silicon Drift Detector
-  const Int_t DDLNumber=12;       // Number of DDL in SPD
-  const Int_t ModulePerDDL=22;    // Number of modules in each DDL 
+Int_t AliITSDDLRawData::RawDataSDD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber,Int_t eventNumber){
+    //This method creates the Raw data files for SDD detectors
+  //Silicon Drift detector
+  const Int_t kDDLsNumber=12;       // Number of DDL in SPD
+  const Int_t kModulesPerDDL=22;    // Number of modules in each DDL 
   //Row    ==> DDLs
   //Column ==> Modules  
-  Int_t SDDMap[DDLNumber][ModulePerDDL]= {{240,241,242,246,247,248,252,253,254,258,259,260,264,265,266,270,271,272,276,277,278,-1},
+  Int_t mapSDD[kDDLsNumber][kModulesPerDDL]= {{240,241,242,246,247,248,252,253,254,258,259,260,264,265,266,270,271,272,276,277,278,-1},
                                          {243,244,245,249,250,251,255,256,257,261,262,263,267,268,269,273,274,275,279,280,281,-1},
                                          {282,283,284,288,289,290,294,295,296,300,301,302,306,307,308,312,313,314,318,319,320,-1},
                                          {285,286,287,291,292,293,297,298,299,303,304,305,309,310,311,315,316,317,321,322,323,-1},
@@ -643,57 +715,62 @@ Int_t AliITSDDLRawData::RawDataSDD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
                                          {328,329,330,331,336,337,338,339,344,345,346,347,352,353,354,355,360,361,362,363,368,369},
                                          {366,367,372,373,374,375,380,381,382,383,388,389,390,391,396,397,398,399,404,405,406,407},
                                          {370,371,376,377,378,379,384,385,386,387,392,393,394,395,400,401,402,403,408,409,410,411},
-                                         {412,413,414,415,420,421,422,423,428,429,430,431,436,436,438,439,444,445,446,447,452,453},
+                                         {412,413,414,415,420,421,422,423,428,429,430,431,436,437,438,439,444,445,446,447,452,453},
                                          {416,417,418,419,424,425,426,427,432,433,434,435,440,441,442,443,448,449,450,451,456,457},
                                          {454,455,460,461,462,463,468,469,470,471,476,477,478,479,484,485,486,487,492,493,494,495},
                                          {458,459,464,465,466,467,472,473,474,475,480,481,482,483,488,489,490,491,496,497,498,499}};
   
-  Int_t DDLPerFile=DDLNumber/LDCsNumber;
-  if(DDLNumber%LDCsNumber)DDLPerFile++;
-  cout<<"Number of DDL per File: "<<DDLPerFile<<endl;
+  Int_t ddlsPerFile=kDDLsNumber/LDCsNumber;
+  if(kDDLsNumber%LDCsNumber)ddlsPerFile++;
+  if(fVerbose)
+    cout<<"Number of DDL per File: "<<ddlsPerFile<<endl;
   Int_t subd=1;
-  Int_t CountDDL=0;
-  Int_t SliceNumber=1;
-  const Int_t size=131072; //256*512
-  ULong_t buf[size];      
+  Int_t countDDL=0;
+  Int_t sliceNumber=1;
+  const Int_t kSize=131072; //256*512
+  UInt_t buf[kSize];      
   fIndex=-1;
   Int_t nbytes = 0; 
-  TClonesArray *ITSdigits  = ITS->DigitsAddress(subd);
+  TClonesArray *digitsInITS  = ITS->DigitsAddress(subd);
   char fileName[15];
 
-  ULong_t MiniHeaderPosition=0; // variable used to store the position of the Mini Header inside a file
+  UInt_t miniHeaderPosition=0; // variable used to store the position of the Mini Header inside a file
   ofstream outfile;             // logical name of the output file 
-  Int_t Flag=0;                 // 0==> Uncompressed data 1==>Compressed Data
-  Int_t Detector=2;             // 1==>ITS (Pixel) 2==>ITS (Drift) 3==>ITS (Strip) 0==>TPC ......
-  ULong_t Size=0;               // Size of the data block that follows the mini header
-  Int_t MagicWord=0x123456;     // Magic word used to distinguish between data and garbage
-  sprintf(fileName,"SDDslice%d",SliceNumber); //The name of  the output file. There are as many slides as the number of LDC
+  Int_t flag=0;                 // 0==> Uncompressed data 1==>Compressed Data
+  Int_t detector=2;             // 1==>ITS (Pixel) 2==>ITS (Drift) 3==>ITS (Strip) 0==>TPC ......
+  UInt_t size=0;               // size of the data block that follows the mini header
+  Int_t magicWord=0x123456;     // Magic word used to distinguish between data and garbage
+  sprintf(fileName,"Ev%dSDDslice%d",eventNumber,sliceNumber); //The name of  the output file. There are as many slides as the number of LDC
+#ifndef __DECCXX
   outfile.open(fileName,ios::binary);
-  ULong_t MiniHeader[3];
-  Int_t MiniHeaderSize=sizeof(ULong_t)*3;
-  Int_t Version=1;             //Version of the mini header 
+#else
+  outfile.open(fileName);
+#endif
+  UInt_t miniHeader[3];
+  Int_t miniHeaderSize=sizeof(UInt_t)*3;
+  Int_t version=1;             //version of the mini header 
   //loop over DDLs
-  for(Int_t i=0;i<DDLNumber;i++){
-    CountDDL++;
+  for(Int_t i=0;i<kDDLsNumber;i++){
+    countDDL++;
     //write Dummy MINI HEADER
-    MiniHeader[0]=Size;
-    PackWord(MiniHeader[1],MagicWord,8,31);
-    PackWord(MiniHeader[1],Detector,0,7);
-    PackWord(MiniHeader[2],i,16,31);
-    PackWord(MiniHeader[2],Flag,8,15);
-    PackWord(MiniHeader[2],Version,0,7);
-    MiniHeaderPosition=outfile.tellp();
-    outfile.write((char*)(MiniHeader),MiniHeaderSize);
+    miniHeader[0]=size;
+    PackWord(miniHeader[1],magicWord,8,31);
+    PackWord(miniHeader[1],detector,0,7);
+    PackWord(miniHeader[2],i,16,31);
+    PackWord(miniHeader[2],flag,8,15);
+    PackWord(miniHeader[2],version,0,7);
+    miniHeaderPosition=outfile.tellp();
+    outfile.write((char*)(miniHeader),miniHeaderSize);
     //Loops over Modules of a particular DDL
-    for (Int_t mod=0; mod<ModulePerDDL; mod++){
-      if(SDDMap[i][mod]!=-1){
+    for (Int_t mod=0; mod<kModulesPerDDL; mod++){
+      if(mapSDD[i][mod]!=-1){
        ITS->ResetDigits();
-       nbytes += TD->GetEvent(SDDMap[i][mod]);
+       nbytes += TD->GetEvent(mapSDD[i][mod]);
        //For each Module, buf contains the array of data words in Binary format          
        //fIndex gives the number of 32 bits words in the buffer for each module
-       //      cout<<"MODULE NUMBER:"<<SDDMap[i][mod]<<endl;
-       GetDigitsSDD(ITSdigits,mod,buf);
-       outfile.write((char *)buf,((fIndex+1)*sizeof(ULong_t)));
+       //      cout<<"MODULE NUMBER:"<<mapSDD[i][mod]<<endl;
+       GetDigitsSDD(digitsInITS,mod,mapSDD[i][mod],i,buf);
+       outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
        for(Int_t i=0;i<(fIndex+1);i++){
          buf[i]=0;
        }//end for
@@ -702,19 +779,23 @@ Int_t AliITSDDLRawData::RawDataSDD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
     }//end for
     
     //Write REAL MINI HEADER
-    ULong_t CurrentFilePosition=outfile.tellp();
-    outfile.seekp(MiniHeaderPosition);
-    Size=CurrentFilePosition-MiniHeaderPosition-MiniHeaderSize;
+    UInt_t currentFilePosition=outfile.tellp();
+    outfile.seekp(miniHeaderPosition);
+    size=currentFilePosition-miniHeaderPosition-miniHeaderSize;
     
-    outfile.write((char*)(&Size),sizeof(ULong_t));
-    outfile.seekp(CurrentFilePosition);
-    if(CountDDL==DDLPerFile){
+    outfile.write((char*)(&size),sizeof(UInt_t));
+    outfile.seekp(currentFilePosition);
+    if(countDDL==ddlsPerFile){
       outfile.close();
-      SliceNumber++;
-      sprintf(fileName,"SDDslice%d",SliceNumber); 
-      if(i!=(DDLNumber-1))
+      sliceNumber++;
+      sprintf(fileName,"Ev%dSDDslice%d",eventNumber,sliceNumber); 
+      if(i!=(kDDLsNumber-1))
+#ifndef __DECCXX
        outfile.open(fileName,ios::binary);
-      CountDDL=0;
+#else
+       outfile.open(fileName);
+#endif
+      countDDL=0;
     }//end if
   }//end for
   outfile.close();
@@ -723,7 +804,8 @@ Int_t AliITSDDLRawData::RawDataSDD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-void AliITSDDLRawData::WriteChipHeader(Int_t ChipAddr,Int_t EventCnt,ULong_t &BaseWord){
+void AliITSDDLRawData::WriteChipHeader(Int_t ChipAddr,Int_t EventCnt,UInt_t &BaseWord){
+  //This method writes a chip header 
   //cout<<"Chip: "<<ChipAddr<<" Half Stave module:"<<EventCnt<<endl;
   BaseWord=0;
   PackWord(BaseWord,ChipAddr,0,3);
@@ -735,22 +817,25 @@ void AliITSDDLRawData::WriteChipHeader(Int_t ChipAddr,Int_t EventCnt,ULong_t &Ba
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-void AliITSDDLRawData::ReadChipHeader(Int_t &ChipAddr,Int_t &EventCnt,ULong_t BaseWord){
-  ULong_t temp=0;
+void AliITSDDLRawData::ReadChipHeader(Int_t &ChipAddr,Int_t &EventCnt,UInt_t BaseWord){
+  //This method reads a chip header
+  UInt_t temp=0;
   UnpackWord(BaseWord,0,3,temp);
   ChipAddr=(Int_t)temp;
   UnpackWord(BaseWord,4,10,temp);
   EventCnt=(Int_t)temp;
-  cout<<"Chip: "<<ChipAddr<<" Half Stave module:"<<EventCnt<<endl;
+  if(fVerbose)
+    cout<<"Chip: "<<ChipAddr<<" Half Stave module:"<<EventCnt<<endl;
   return;
 }//end ReadChipHeader
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-void  AliITSDDLRawData::WriteChipTrailer(ULong_t *buf,Int_t ChipHitCount,ULong_t &BaseWord){
+void  AliITSDDLRawData::WriteChipTrailer(UInt_t *buf,Int_t ChipHitCount,UInt_t &BaseWord){
+  //This method writes a chip trailer
   //pixel fill word
   if((ChipHitCount%2)!=0){
-    PackWord(BaseWord,0xFECD,0,15);
+    PackWord(BaseWord,0xFEDC,0,15);
   }
   PackWord(BaseWord,ChipHitCount,16,28);
   PackWord(BaseWord,0x0,30,31);
@@ -762,8 +847,9 @@ void  AliITSDDLRawData::WriteChipTrailer(ULong_t *buf,Int_t ChipHitCount,ULong_t
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-void  AliITSDDLRawData::ReadChipTrailer(Int_t &ChipHitCount,ULong_t BaseWord){
-  ULong_t temp=0;
+void  AliITSDDLRawData::ReadChipTrailer(Int_t &ChipHitCount,UInt_t BaseWord){
+  //This method reads a chip trailer
+  UInt_t temp=0;
   UnpackWord(BaseWord,16,28,temp);
   ChipHitCount=(Int_t)temp;
   return;
@@ -771,7 +857,8 @@ void  AliITSDDLRawData::ReadChipTrailer(Int_t &ChipHitCount,ULong_t BaseWord){
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-void  AliITSDDLRawData::WriteHit(ULong_t *buf,Int_t RowAddr,Int_t HitAddr,ULong_t &BaseWord){
+void  AliITSDDLRawData::WriteHit(UInt_t *buf,Int_t RowAddr,Int_t HitAddr,UInt_t &BaseWord){
+  //This method writs an hit
   if(!BaseWord){
     PackWord(BaseWord,HitAddr,0,4);
     PackWord(BaseWord,RowAddr,5,12);
@@ -790,109 +877,90 @@ void  AliITSDDLRawData::WriteHit(ULong_t *buf,Int_t RowAddr,Int_t HitAddr,ULong_
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-void AliITSDDLRawData::TestFormat(){
+void AliITSDDLRawData::TestFormat(Int_t eventNumber){
+  //This method generates a text file containing SPD information
+  //Used for debugging
   ifstream f;
-  Int_t  LDCsNumber=2;
+  Int_t  ldcsNumber=2;
   ofstream ftxt("File2.txt");
-  ULong_t Size=0;
+  UInt_t size=0;
   char filename[15];
-  ULong_t DDLNumber=0;
-  ULong_t MiniHeader[3];
-  Int_t MiniHeaderSize=sizeof(ULong_t)*3;
-  for(Int_t i=1;i<=LDCsNumber;i++){
-    sprintf(filename,"SPDslice%d",i);  
+  UInt_t ddlsNumber=0;
+  UInt_t miniHeader[3];
+  Int_t miniHeaderSize=sizeof(UInt_t)*3;
+  for(Int_t i=1;i<=ldcsNumber;i++){
+    sprintf(filename,"Ev%dSPDslice%d",eventNumber,i);  
+#ifndef __DECCXX
     f.open(filename,ios::binary|ios::in);
+#else
+    f.open(filename,ios::in);
+#endif
     if(!f){exit(1);}
     //loop over the DDL block 
     //here the Mini Header is read
-    while( f.read((char*)(MiniHeader),MiniHeaderSize)){
-      //cout<<"Block Size: "<<Size<<endl;
-      Size=MiniHeader[0];
-      UnpackWord(MiniHeader[2],16,31,DDLNumber);
-      ftxt<<"DDL NUMBER:"<<DDLNumber<<endl;
-      ULong_t Word=0;
-      ULong_t Code=0;
-      ULong_t Decoded1,Decoded2=0;
-      for(ULong_t j=0;j<(Size/4);j++){
-       f.read((char*)(&Word),sizeof(Word)); //32 bits word
-       Code=0;
-       UnpackWord(Word,14,15,Code);
-       DecodeWord(Code,Word,0,Decoded1,Decoded2);
-       switch (Code){
-       case 0://trailer
-         ftxt<<"Number of Hit:"<<Decoded1<<endl;
-         break;
-       case 1://header
-         ftxt<<"Half Stave Number:"<<Decoded1<<" Chip Number:"<<Decoded2<<endl;
-         break;
-       case 2://hit
-         ftxt<<"Row:"<<Decoded1<<" Column:"<<Decoded2<<endl;
-         break;
-       case 3://fill word
-         break;
-       }//end switch
-       Code=0;
-       UnpackWord(Word,30,31,Code);
-       DecodeWord(Code,Word,1,Decoded1,Decoded2);
-       switch (Code){
-       case 0://trailer
-         ftxt<<"Number of Hit:"<<Decoded1<<endl;
-         break;
-       case 1://header
-         ftxt<<"Half Stave Number:"<<Decoded1<<" Chip Number:"<<Decoded2<<endl;
-         break;
-       case 2://hit
-         ftxt<<"Row:"<<Decoded1<<" Column:"<<Decoded2<<endl;
-         break;
-       case 3://fill word
-         break;
-       }//end switch
+    while( f.read((char*)(miniHeader),miniHeaderSize)){
+      //cout<<"Block Size: "<<size<<endl;
+      size=miniHeader[0];
+      UnpackWord(miniHeader[2],16,31,ddlsNumber);
+      //ftxt<<"DDL NUMBER:"<<ddlsNumber<<endl;
+      UInt_t word=0;
+      UInt_t codeH,codeL=0;
+      UInt_t chip=0;
+      UInt_t half=0;
+      UInt_t col=0;
+      UInt_t row=0;
+      Int_t moduleID=0;
+      UInt_t hitscount=0;
+      Int_t previous=-1;
+      for(UInt_t j=0;j<(size/4);j++){
+       f.read((char*)(&word),sizeof(word)); //32 bits word
+       UnpackWord(word,30,31,codeH);
+       UnpackWord(word,14,15,codeL);
+       if ((codeH==2)&&(codeL==1)){
+         UnpackWord(word,0,3,chip);
+         UnpackWord(word,4,10,half);
+         moduleID=half*2+chip/5;
+         if (moduleID!=previous){
+           if (hitscount){
+             previous=moduleID;
+             hitscount=0;
+           }
+         }
+         chip=chip%5;
+         row=col=0;
+         UnpackWord(word,21,28,row);
+         UnpackWord(word,16,20,col); 
+         col=col+32*chip;
+         hitscount++;
+         ftxt<<"DDL:"<<ddlsNumber<<" Mod:"<<moduleID<<" Row:"<<row<<" Col:"<<col<<endl;
+       }//end if
+       else if ((codeH==2)&&(codeL==2)){
+         row=col=0;
+         UnpackWord(word,5,12,row);
+         UnpackWord(word,0,4,col);
+         col=col+32*chip;
+         ftxt<<"DDL:"<<ddlsNumber<<" Mod:"<<moduleID<<" Row:"<<row<<" Col:"<<col<<endl;
+         row=col=0;
+         UnpackWord(word,21,28,row);
+         UnpackWord(word,16,20,col); 
+         col=col+32*chip;
+         ftxt<<"DDL:"<<ddlsNumber<<" Mod:"<<moduleID<<" Row:"<<row<<" Col:"<<col<<endl;
+         hitscount++;
+         hitscount++;
+       }//end else if
+       else if ((codeH==0)&&(codeL==2)){
+         row=col=0;
+         UnpackWord(word,5,12,row);
+         UnpackWord(word,0,4,col);
+         col=col+32*chip;
+         hitscount++;
+         ftxt<<"DDL:"<<ddlsNumber<<" Mod:"<<moduleID<<" Row:"<<row<<" Col:"<<col<<endl;
+       }//end else if
       }//end for
     }//end while
+    f.clear();
     f.close();
   }//end for
   ftxt.close();
   return;
 }
-
-void AliITSDDLRawData::DecodeWord(ULong_t Code,ULong_t BaseWord,Int_t FirstHalf,ULong_t &Decoded1,ULong_t &Decoded2){
-  //FirstHalf=0 ==>bits from 0 to 15
-  //FirstHalf=1 ==>bits from 16 to 31
-  if(!FirstHalf){
-    switch (Code){
-    case 0://trailer
-      UnpackWord(BaseWord,0,12,Decoded1);
-      break;
-    case 1://header
-      UnpackWord(BaseWord,4,10,Decoded1);
-      UnpackWord(BaseWord,0,3,Decoded2);
-      break;
-    case 2://hit
-      UnpackWord(BaseWord,5,12,Decoded1);
-      UnpackWord(BaseWord,0,4,Decoded2);
-      break;//fill word
-    case 3:
-      UnpackWord(BaseWord,0,13,Decoded1);
-      break;
-    }//end switch
-  }
-  else{
-    switch (Code){
-    case 0://trailer
-      UnpackWord(BaseWord,16,28,Decoded1);
-      break;
-    case 1://header
-      UnpackWord(BaseWord,20,26,Decoded1);
-      UnpackWord(BaseWord,16,19,Decoded2);
-      break;
-    case 2://hit
-      UnpackWord(BaseWord,21,28,Decoded1);
-      UnpackWord(BaseWord,16,20,Decoded2);
-      break;
-    case 3://fill word
-      UnpackWord(BaseWord,16,29,Decoded1);
-      break;
-    }//end switch
-  }
-  return;
-}