]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSDDLRawData.cxx
Modifs to have 8 bit ADC values in the compressed format of SDD raw data (F. Prino)
[u/mrichter/AliRoot.git] / ITS / AliITSDDLRawData.cxx
index 7aeab223da71f08f744b75a845e56a2d7a65fc9c..9cde520cbf4d0375011431eb9dccea2a3236248f 100644 (file)
@@ -31,7 +31,9 @@
 #include "AliRawDataHeaderSim.h"
 #include "AliITSRawStreamSPD.h"
 #include "AliITSRawStreamSDD.h"
+#include "AliITSDDLModuleMapSDD.h"
 #include "AliITSRawStreamSSD.h"
+#include "AliITSIntMap.h"
 #include "AliBitPacking.h"
 #include "AliDAQ.h"
 #include "AliFstream.h"
@@ -42,7 +44,8 @@ ClassImp(AliITSDDLRawData)
 AliITSDDLRawData::AliITSDDLRawData():
 fVerbose(0),
 fIndex(-1),
-fHalfStaveModule(-1){
+fHalfStaveModule(-1),
+fUseCompressedSDDFormat(0){
   //Default constructor
 
 }
@@ -53,7 +56,8 @@ AliITSDDLRawData::AliITSDDLRawData(const AliITSDDLRawData &source) :
     TObject(source),
 fVerbose(source.fVerbose),
 fIndex(source.fIndex),
-fHalfStaveModule(source.fHalfStaveModule){
+fHalfStaveModule(source.fHalfStaveModule),
+fUseCompressedSDDFormat(source.fUseCompressedSDDFormat){
   //Copy Constructor
 }
 
@@ -64,6 +68,7 @@ AliITSDDLRawData& AliITSDDLRawData::operator=(const AliITSDDLRawData &source){
   this->fIndex=source.fIndex;
   this->fHalfStaveModule=source.fHalfStaveModule;
   this->fVerbose=source.fVerbose;
+  this->fUseCompressedSDDFormat=source.fUseCompressedSDDFormat;
   return *this;
 }
 
@@ -123,6 +128,41 @@ void AliITSDDLRawData::GetDigitsSSD(TClonesArray *ITSdigits,Int_t mod,Int_t modR
 //Silicon Drift Detector
 //
 
+void AliITSDDLRawData::GetDigitsSDDCompressed(TClonesArray *ITSdigits, Int_t mod, UInt_t *buf){ 
+//This method packs the SDD digits in the compressed format (32 bit per digit)
+// see AliITSRawStreamSDDCompressed for details on the dta format
+
+  UInt_t dataWord=0;
+  Int_t ndigits = ITSdigits->GetEntries();
+  AliITSdigit *digs;
+  if(ndigits){
+    for (Int_t digit=0;digit<ndigits;digit++) {
+      digs = (AliITSdigit*)ITSdigits->UncheckedAt(digit);
+      Int_t iz=digs->GetCoord1();  // Anode
+      Int_t ix=digs->GetCoord2();  // Time
+      Int_t is=digs->GetCompressedSignal();  // ADC Signal - 8 bit
+      dataWord=mod<<27;
+      Int_t sid=0;
+      if(iz>=256){
+       sid=1;
+       iz-=256;
+      }
+      dataWord+=sid<<26;
+      dataWord+=iz<<18;
+      dataWord+=ix<<10;
+      dataWord+=is;
+      fIndex++;
+      buf[fIndex]=dataWord;
+    }
+  }
+  UInt_t finalWord=15<<28;
+  finalWord+=mod;
+  fIndex++;
+  buf[fIndex]=finalWord;  
+}
+
+//______________________________________________________________________
+
 void AliITSDDLRawData::GetDigitsSDD(TClonesArray *ITSdigits,Int_t mod,Int_t modR,Int_t ddl,UInt_t *buf){  
   //This method packs the SDD digits in a proper 32 bits structure
   Int_t ix;
@@ -378,19 +418,23 @@ void AliITSDDLRawData::GetDigitsSPD(TClonesArray *ITSdigits,Int_t mod,Int_t ddl,
   //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.
-  //The index of the half stave is calculated as (mod/2).
-  Int_t ix;
-  Int_t iz;
-  Int_t chipNo=0;
+
+  Int_t chipLow  = AliITSRawStreamSPD::GetOnlineChipFromOffline(mod,0);
+  Int_t chipHigh = AliITSRawStreamSPD::GetOnlineChipFromOffline(mod,159);
+
+  if (chipLow>chipHigh) {chipLow  -= 4; chipHigh += 4;}
+  UInt_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(mod);
+
+  // create int map to later hold all digits sorted
+  AliITSIntMap* digMap = new AliITSIntMap();
+
   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
@@ -400,77 +444,79 @@ void AliITSDDLRawData::GetDigitsSPD(TClonesArray *ITSdigits,Int_t mod,Int_t ddl,
       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 0 to 159.  Therefore,
-       *     to get the chip address (0 to 4), we need to divide column number by 32.
+       *     So, the cell number in Z direction varies from 0 to 159.
        *     ---------------------------------------------------------------------*/
-      iz=digs->GetCoord1();  // Cell number in Z direction 
-      ix=digs->GetCoord2();  // Cell number in X direction
-      chipNo=iz/32;
+      Int_t iz=digs->GetCoord1();  // Cell number in Z direction 
+      Int_t ix=digs->GetCoord2();  // Cell number in X direction
+
       if(fVerbose==2)
        ftxt<<"DDL:"<<ddl<<" Mod:"<<mod<<" Row:"<<ix<<" Col:"<<iz<<endl;
-      hitRow=iz-chipNo*32;
-      if(fHalfStaveModule){
-       chipNo+=5;
-       fHalfStaveModule=-1;
-      }//end if
-      if(previousChip==-1){
+      UInt_t dummyDDL,dummyHS,chip,col,row;
+      AliITSRawStreamSPD::OfflineToOnline(mod,iz,ix,dummyDDL,dummyHS,chip,col,row);
+
+      //  insert digit into map...
+      // (reverse order of cols and rows as in real raw data)
+      digMap->Insert(chip*256*32+(31-col)*256+(255-row),row);
+    }
+  }
+
+  UInt_t nrHits = digMap->GetNrEntries();
+  if (nrHits>0) {
+    Int_t chip = 0;
+    for (UInt_t nHit=0; nHit<nrHits; nHit++) {
+      Int_t key = digMap->GetKeyIndex(nHit);
+      chip = key/(256*32);
+      Int_t col = 31 - (key%(256*32))/256;
+      Int_t row = digMap->GetValIndex(nHit);
+
+      if(previousChip==-1) { // first hit
        //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);
-         else
-           WriteChipHeader(i,(mod/2),baseWord);
-         WriteChipTrailer(buf,chipHitCount,baseWord);
-         chipHitCount=0;
-       }//end for
-       WriteChipHeader(chipNo,(mod/2),baseWord);
+       for (Int_t i=chipLow; i<chip; i++) {
+         WriteChipHeader(i,hs,baseWord);
+         WriteChipTrailer(buf,0,baseWord);
+       }
+       WriteChipHeader(chip,hs,baseWord);
+       WriteHit(buf,row,col,baseWord);
        chipHitCount++;
-       WriteHit(buf,ix,hitRow,baseWord);
-       previousChip=chipNo;
+       previousChip=chip;
       }//end if
       else{
-       if(previousChip!=chipNo){
+       if(previousChip!=(Int_t)chip) {
          WriteChipTrailer(buf,chipHitCount,baseWord);
          chipHitCount=0;
-         for(Int_t i=previousChip+1;i<chipNo;i++){
-           WriteChipHeader(i,(mod/2),baseWord);
+         for(Int_t i=previousChip+1; i<chip; i++) {
+           WriteChipHeader(i,hs,baseWord);
            WriteChipTrailer(buf,0,baseWord);
-           chipHitCount=0;
          }//end for
-         WriteChipHeader(chipNo,(mod/2),baseWord);
-         previousChip=chipNo;
+         WriteChipHeader(chip,hs,baseWord);
+         previousChip=chip;
        }//end if
        chipHitCount++;
-       WriteHit(buf,ix,hitRow,baseWord);
+       WriteHit(buf,row,col,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);
     chipHitCount=0;
-    for(Int_t i=chipNo+1;i<=end;i++){
-      WriteChipHeader(i,(mod/2),baseWord);
+    for(Int_t i=chip+1;i<=chipHigh;i++){
+      WriteChipHeader(i,hs,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;
-      fHalfStaveModule=-1;
-    }//end if
-    for(Int_t i=0;i<5;i++){
-      WriteChipHeader(chipNo+i,(mod/2),baseWord);
-      WriteChipTrailer(buf,chipHitCount,baseWord);
-      chipHitCount=0;
+    //the chip header and chip trailer are stored anyway
+    for(Int_t i=chipLow; i<=chipHigh; i++){
+      WriteChipHeader(i,hs,baseWord);
+      WriteChipTrailer(buf,0,baseWord);
     }//end for
   }//end else 
+
+  delete digMap;
+
   if(fVerbose==2)
     ftxt.close();
   return;
@@ -490,20 +536,20 @@ Int_t AliITSDDLRawData::RawDataSPD(TBranch* branch){
   AliRawDataHeaderSim header;
 
   //loop over DDLs
-  for(Int_t i=0;i<AliDAQ::NumberOfDdls("ITSSPD");i++){
-    strcpy(fileName,AliDAQ::DdlFileName("ITSSPD",i)); //The name of the output file.
+  for(Int_t ddl=0;ddl<AliDAQ::NumberOfDdls("ITSSPD");ddl++){
+    strcpy(fileName,AliDAQ::DdlFileName("ITSSPD",ddl)); //The name of the output file.
     outfile = new AliFstream(fileName);
     //write Dummy DATA HEADER
     UInt_t dataHeaderPosition=outfile->Tellp();
     outfile->WriteBuffer((char*)(&header),sizeof(header));
     //Loops over Modules of a particular DDL
     for (Int_t mod=0; mod<AliITSRawStreamSPD::kModulesPerDDL; mod++){
-      Int_t moduleNumber = AliITSRawStreamSPD::GetModuleNumber(i, mod);
+      Int_t moduleNumber = AliITSRawStreamSPD::GetModuleNumber(ddl, mod);
       digits->Clear();
       branch->GetEvent(moduleNumber);
       //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(digits,mod,i,buf);
+      GetDigitsSPD(digits,moduleNumber,ddl,buf);
       outfile->WriteBuffer((char *)buf,((fIndex+1)*sizeof(UInt_t)));
       for(Int_t i=0;i<(fIndex+1);i++){
        buf[i]=0;
@@ -572,7 +618,7 @@ Int_t AliITSDDLRawData::RawDataSSD(TBranch* branch){
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-Int_t AliITSDDLRawData::RawDataSDD(TBranch* branch){
+Int_t AliITSDDLRawData::RawDataSDD(TBranch* branch, AliITSDDLModuleMapSDD* ddlsdd){
     //This method creates the Raw data files for SDD detectors
   const Int_t kSize=131072; //256*512
   UInt_t buf[kSize];      
@@ -598,12 +644,14 @@ Int_t AliITSDDLRawData::RawDataSDD(TBranch* branch){
 
 
     //first 1 "dummy" word to be skipped
-    retcode = AliBitPacking::PackWord(0xFFFFFFFF,skippedword,0,31);
-    outfile->WriteBuffer((char*)(&skippedword),sizeof(skippedword));
+    if(!fUseCompressedSDDFormat){
+      retcode = AliBitPacking::PackWord(0xFFFFFFFF,skippedword,0,31);
+      outfile->WriteBuffer((char*)(&skippedword),sizeof(skippedword));
+    }
 
     //Loops over Modules of a particular DDL
     for (Int_t mod=0; mod<AliITSRawStreamSDD::kModulesPerDDL; mod++){
-      Int_t moduleNumber = AliITSRawStreamSDD::GetModuleNumber(i, mod);
+      Int_t moduleNumber = ddlsdd->GetModuleNumber(i, mod);
       if(moduleNumber!=-1){
        digits->Clear();
        branch->GetEvent(moduleNumber);
@@ -611,17 +659,22 @@ Int_t AliITSDDLRawData::RawDataSDD(TBranch* branch){
        //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:"<<mapSDD[i][mod]<<endl;
-       GetDigitsSDD(digits,mod,moduleNumber,i,buf);
-       outfile->WriteBuffer((char *)buf,((fIndex+1)*sizeof(UInt_t)));
-       for(Int_t iw=0;iw<3;iw++) outfile->WriteBuffer((char*)(&carlosFooterWord),sizeof(carlosFooterWord));
+       if(fUseCompressedSDDFormat){
+         GetDigitsSDDCompressed(digits,mod,buf);
+         outfile->WriteBuffer((char *)buf,((fIndex+1)*sizeof(UInt_t)));
+       }else{
+         GetDigitsSDD(digits,mod,moduleNumber,i,buf);
+         outfile->WriteBuffer((char *)buf,((fIndex+1)*sizeof(UInt_t)));
+         for(Int_t iw=0;iw<3;iw++) outfile->WriteBuffer((char*)(&carlosFooterWord),sizeof(carlosFooterWord));
+       }
        fIndex=-1;
       }//end if
     }//end for
     // 12 words with FIFO footers (=4 FIFO x 3 3F1F1F1F words per DDL)
-    for(Int_t iw=0;iw<12;iw++) outfile->WriteBuffer((char*)(&fifoFooterWord),sizeof(fifoFooterWord));
-   
-    outfile->WriteBuffer((char*)(&jitterWord),sizeof(jitterWord));      
-    
+    if(!fUseCompressedSDDFormat){
+      for(Int_t iw=0;iw<12;iw++) outfile->WriteBuffer((char*)(&fifoFooterWord),sizeof(fifoFooterWord));
+      outfile->WriteBuffer((char*)(&jitterWord),sizeof(jitterWord));      
+    }
     //Write REAL DATA HEADER
     UInt_t currentFilePosition=outfile->Tellp();
     outfile->Seekp(dataHeaderPosition);
@@ -683,4 +736,3 @@ void  AliITSDDLRawData::WriteHit(UInt_t *buf,Int_t RowAddr,Int_t HitAddr,UInt_t
   }//end else
   return;
 }//end WriteHit
-