]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Decoding raw event is under test
authordibari <dibari@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 19 Dec 2007 14:39:04 +0000 (14:39 +0000)
committerdibari <dibari@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 19 Dec 2007 14:39:04 +0000 (14:39 +0000)
HMPID/AliHMPIDRawStream.cxx
HMPID/AliHMPIDRawStream.h

index c137d6f0d400c8560f53b14497e9246af77e47f9..19e87f8049d308b85b7f9971e9b801f23f835edd 100644 (file)
@@ -25,6 +25,9 @@
 #include "AliRawReader.h"
 #include "AliLog.h"
 
+Int_t fPos[170000];
+Int_t iPos = 0;
+//static Bool_t stDeb = kTRUE;
 
 ClassImp(AliHMPIDRawStream)
 
@@ -62,12 +65,15 @@ void AliHMPIDRawStream::Init()
 {
   // Initalize the container
   // with the pad charges
+  Int_t n=0;
+  iPos = 0;
   for(Int_t h = 0; h < kNDDL; h++) {  
     for(Int_t i = 0; i < kNRows; i++){
       for(Int_t j = 0; j < kNDILOGICAdd; j++){
        for(Int_t k = 0; k < kNPadAdd; k++){
          fCharge[h][i][j][k] = -1;
          fPad[h][i][j][k]=-1;
+          fPos[++n] = 0;
        }
       }
     }
@@ -76,7 +82,7 @@ void AliHMPIDRawStream::Init()
   
   for(Int_t l=1; l < kSumErr; l++) fNumOfErr[l]=0;               //reset errors
 }//Init()
-//_____________________________________________________________________________
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 void AliHMPIDRawStream::Reset()
 {
   // reset raw stream params
@@ -87,7 +93,7 @@ void AliHMPIDRawStream::Reset()
   fData = NULL;
   if (fRawReader) fRawReader->Reset();
 }
-//_____________________________________________________________________________
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 Bool_t AliHMPIDRawStream::Next()
 {
   // read next DDL raw data from the HMPID raw data stream
@@ -97,7 +103,7 @@ Bool_t AliHMPIDRawStream::Next()
     if (!fRawReader->ReadNextData(fData)) return kFALSE;
   } while (fRawReader->GetDataSize() == 0);
   
+     
   /*
   Event type is selected as in $ALICE_ROOT/RAW/event.h  
   #define START_OF_RUN                    ((eventTypeType) 1)
@@ -116,145 +122,302 @@ Bool_t AliHMPIDRawStream::Next()
   #define EVENT_TYPE_MIN                  1
   #define EVENT_TYPE_MAX                  13 
   */
-      
+
+  fPosition = 0;
+  Bool_t status;
+  
   if(fRawReader->GetType() == 7)  {                             //New: Select Physics events, Old: Raw data size is not 0 and not 47148 (pedestal)
   
     fDDLNumber = fRawReader->GetDDLID();
-    fPosition = 0;
-  
+    
     Init();
     
-    // Look over rows
-    for(Int_t iRow = 1; iRow <= kNRows; iRow++) {
-      UInt_t rowMarker = GetNextWord();                                 // Read row marker
-      
-      Int_t numRows= rowMarker >> 16 & 0xfff;                        // Number of words after the row marker         
-      
-      if ( numRows > 490 ) {      //The row marker is fixed and we cannot have more than 490 words!!!
-       fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
-        AliWarning(Form("Wrong row marker size %x for row %d, value: %d expected < 490!",rowMarker,iRow,numRows));
-        fNumOfErr[kRowMarkerSizeErr]++;
-       return kTRUE;
-      }//check for row marker
-      
-      if ((rowMarker >> 0 & 0xffff) != 0x32a8  ) {      //The row marker is fixed and we cannot have more than 490 words!!!
-       fRawReader->AddMajorErrorLog(kRowMarkerErr);
-        AliWarning(Form("Wrong row marker %x for row %d, expected 0x32a8!",rowMarker,iRow));
-         fNumOfErr[kRowMarkerErr]++;
-       return kTRUE;
-      }//check for row marker
-      UInt_t dilogic = 0, row = 0;
-      UInt_t cntData=0;
-      UInt_t cntEoE=0;
-      //molnarl: lets read how many rows we have from the marker; 10 dilogic EoE so we can get the number of data words they should be in order
-      for(Int_t iWordInRow=0; iWordInRow<numRows;iWordInRow++) //loop over words 
-       {     
-         UInt_t tmpword=GetNextWord();               
-         UInt_t eOfEvent = tmpword;                     // always assume that it is an EoE. If bit 
-         if (!((eOfEvent >> 27) & 0x1)) {               // if it is not EoE then data!
-           UInt_t data=tmpword;
-           row = (data >> 22) & 0x1f;                                                  //row information in raw word is between bits: 22...26
-           if (row < 1 || row > kNRows) {                                              //select bits from 22 and with 0x1f ask for the next 5 bits 
-             fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
-             AliWarning(Form("Wrong row index: %d, expected (1 -> %d)!",row,kNRows));
-              fNumOfErr[kWrongRowErr]++;
-             // row = iRow;
-           }
-           dilogic = (data >> 18) & 0xf;                                              //dilogic info in raw word is between bits: 18...21
-           if (dilogic < 1 || dilogic > kNDILOGICAdd) {
-             fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
-             AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));
-              fNumOfErr[kWrongDilogicErr]++;
-             //dilogic = iDILOGIC;
-           }
-           UInt_t pad = (data >> 12) & 0x3f;                                                    //pad info in raw word is between bits: 12...17
-           if (pad >= kNPadAdd) {
-             fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
-             AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));
-              fNumOfErr[kWrongPadErr]++;
-             //pad = iPad;
-           }
-           fCharge[fDDLNumber][row][dilogic][pad] = data & 0xfff;  cntData++;
-           
-         }//not EoE but data!
-         //if it is EoE
-         else{
-           if (!((eOfEvent >> 27) & 0x1)) {                                                  //check 27th bit in EoE. It must be 1!
-             fRawReader->AddMajorErrorLog(kEoEFlagErr);
-             AliWarning(Form("Missing end-of-event flag! (%x)",eOfEvent));
-              fNumOfErr[kEoEFlagErr]++;
-             return kTRUE;
-           }
-           UInt_t wc = eOfEvent & 0x7f;
-           if (wc != cntData) {
-             fRawReader->AddMajorErrorLog(kEoESizeErr,Form("eoe size=%d",wc));
-             AliWarning(Form("Wrong end-of-event word-count: %d, expected: %d!",wc,cntData));
-              fNumOfErr[kEoESizeErr]++;
-             return kTRUE;
-           }
-           UInt_t da = (eOfEvent >> 18) & 0xf;
-           if (cntData!=0 && da != dilogic) {
-             fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
-             AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
-              fNumOfErr[kEoEDILOGICErr]++;
-             return kTRUE;
-           }
-           UInt_t ca = (eOfEvent >> 22) & 0x1f;
-           if (cntData!=0 &&  ca != row) {
-             fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
-             AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
-              fNumOfErr[kEoERowErr]++;
-             return kTRUE;
-           }
-           cntData=0;  cntEoE++;//zero it and wait for new data words
-         } //EoE word
-         
-       } //loop over rows within two markers
-      
-      
-      
-      // Read the segment marker
-      // One maker per 8 rows
-      
-      if (iRow%8 == 0) {
-       UInt_t segWord = GetNextWord();          
-       if ((segWord >> 8) != 0xab0f59) {
-         fRawReader->AddMajorErrorLog(kBadSegWordErr);
-         AliWarning(Form("Wrong segment word signature: %x, expected 0xab0f59!",(segWord >> 8)));
-          fNumOfErr[kBadSegWordErr]++;
-         return kTRUE;
-       }
-       
-       if ((segWord & 0xff) != (((UInt_t)iRow + 7) / 8)) {
-         fRawReader->AddMajorErrorLog(kWrongSegErr,Form("seg %d != %d",segWord & 0xff,(iRow + 7) / 8));
-         AliWarning(Form("Segment index (%d) does not correspond to the one expected from row index (%d)!",segWord & 0xff,(iRow + 7) / 8));
-          fNumOfErr[kWrongSegErr]++;
-         return kTRUE;
-       }
-      }
-    }//loop of Row   
-  }//REal data files selected by data lenght
+    status = ReadHMPIDRawData();
+//    if(status) Printf("Event DDL %i successfully decoded!.",fDDLNumber);
+// Just for test...
+//    for(Int_t i=0;i<fRawReader->GetDataSize()/4;i++) {
+//      GetWord();
+//    }
+//...
+    
+//    if(stDeb) DumpData(fRawReader->GetDataSize());
+//    stDeb=kFALSE;
+  }
+  return status;
+}
+    
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDRawStream::ReadHMPIDRawData()
+{
+  Int_t cntGlob = fRawReader->GetDataSize()/4;
+  Int_t cnt = cntGlob;
+  UInt_t word32;
+  Int_t nwSeg;
+  Int_t cntSegment;
+
+  word32 = GetWord(cnt);cnt--;
+
+  
+  while (cnt>0) {
+    
+    nwSeg = (word32 >> kbit8) & 0xfff;
+    if(!CheckSegment(word32)) return kFALSE;
+    if(!ReadSegment(word32,cntSegment)) return kFALSE;
+
+    if(nwSeg != cntSegment) {Printf("Error in Segment counters: %i different wrt %i",nwSeg,cntSegment);return kFALSE;}
+    Printf(" cnt %i cntSegment %i",cnt,cntSegment);
+    word32 = GetWord(cntSegment+1,kBwd);
+    cnt-=cntSegment+1;
+  }
   
-  AliDebug(1,"Stop."); 
   return kTRUE;
+  
 }
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDRawStream::ReadSegment(UInt_t word32,Int_t &cntSegment)
+{
+  cntSegment = (word32 >> kbit8) & 0xfff;
+  Int_t cnt = cntSegment;
+  Int_t cntRow;
+  Int_t nwRow;
 
-//_____________________________________________________________________________
-UInt_t AliHMPIDRawStream::GetNextWord()
+  word32 = GetWord(cnt,kBwd);
+  cntRow  = (word32 >> kbit16) & 0xfff;
+  
+  while (cnt>0) {
+
+    if(!CheckRowMarker(word32)) return kFALSE;
+    if(!ReadRow(word32,nwRow)) return kFALSE;
+
+    if(nwRow != cntRow) {Printf("Error in Row counters: %i different wrt %i",nwRow,cntRow);return kFALSE;}
+    word32 = GetWord(cntRow+1);
+    cnt -= cntRow+1;
+    
+  }
+
+  cntSegment -= cnt;
+  
+  return kTRUE;
+    
+}    
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDRawStream::ReadRow(UInt_t word32,Int_t &cntRow)
+{
+  Int_t cnt;
+  Int_t cntDilogic;
+  Int_t nwDil;
+  
+  cntRow  = (word32 >> kbit16) & 0xfff;
+  cnt = cntRow;  
+  
+  word32 = GetWord(cntRow);
+  
+  while (cnt>0) {
+    
+    if(!CheckEoE(word32,nwDil)) return kFALSE;
+    if(!ReadDilogic(word32,cntDilogic)) return kFALSE;
+    
+    if(nwDil != cntDilogic) {Printf("Error in Dilogic counters: %i different wrt %i",nwDil,cntDilogic);return kFALSE;}
+    cnt -= cntDilogic;
+    word32 = GetWord(1,kBwd); // go to next Dilogic bank...
+    cnt--;
+//    Printf(" cnt %i cntDilogic %i ",cnt,cntDilogic);
+  }
+  
+  cntRow -= cnt;  
+  
+  return kTRUE;
+  
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDRawStream::ReadDilogic(UInt_t word32,Int_t &cntDilogic)
+{
+  cntDilogic = word32 & 0x7f;
+  
+  Int_t cnt = cntDilogic;
+
+  for(Int_t iDil=0;iDil<cntDilogic;iDil++) {
+    UInt_t dilogic = 0, row = 0;
+    word32 = GetWord(1,kBwd);
+//check on row number      
+    cnt--;
+    row = (word32 >> kbit22) & 0xf;
+    if(!CheckRow(row)) continue;
+//check dilogic number     
+    dilogic = (word32 >> kbit18) & 0xf;                                              //dilogic info in raw word is between bits: 18...21
+    if(!CheckDilogic(dilogic)) continue;
+//check pad number
+    UInt_t pad = (word32 >> kbit12) & 0x2f;                                          //pad info in raw word is between bits: 12...17
+    if(!CheckPad(pad)) continue;
+    fCharge[fDDLNumber][row][dilogic][pad] = word32 & 0xfff;
+//            Printf(" (word %08X) DDL %i row %i dil %i pad %i ",word32,fDDLNumber,row,dilogic,pad);
+  }
+
+  cntDilogic -= cnt;  
+  return kTRUE;  
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDRawStream::CheckSegment(UInt_t word)
 {
-  // This method returns the next 32 bit word
+  UInt_t markSegment = 0xAB0;
+  /*
+  if (iRow%8 == 0) {
+    UInt_t segWord = GetWord();          
+    if ((segWord >> 20) != statusSegWord) {
+      fRawReader->AddMajorErrorLog(kBadSegWordErr);
+      AliWarning(Form("Wrong segment word signature: %x, expected 0xab0!",(segWord >> 20)));
+      fNumOfErr[kBadSegWordErr]++;
+      return kTRUE;
+    }
+*/
+  UInt_t segMarker = (word >> kbit20) & 0xfff;
+  if (segMarker != markSegment ) {
+    fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment marker %0X wrong (expected %0X) at address %i in word %0X!",segMarker,markSegment,fPosition/4,word));
+    AliWarning(Form("Segment marker %X wrong (expected %0X)! at address %i in word %0X!",segMarker,markSegment,fPosition/4,word));
+    fNumOfErr[kWrongSegErr]++;
+    return kFALSE;
+  }
+  
+  UInt_t segAddress = word & 0xff;
+  if (segAddress<1 ||segAddress>3) {
+    fRawReader->AddMajorErrorLog(kWrongSegErr,Form("Segment address %d not in the valid range [1-3] at address %i in word %0X",segAddress,fPosition/4,word));
+    AliWarning(Form("Segment address %d not in the valid range [1-3]",segAddress));
+    fNumOfErr[kWrongSegErr]++;
+    return kFALSE;
+  }
+  Printf("Segment Marker found! Number of segment is %i",segAddress);
+  return kTRUE;
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDRawStream::CheckRow(UInt_t row)
+{
+//check on row number      
+  if(row>=1 && row <=kNRows) return kTRUE;
+  
+  fRawReader->AddMajorErrorLog(kWrongRowErr,Form("row %d",row));
+  AliWarning(Form("Wrong row index: %d, expected (1 -> %d)!",row,kNRows));
+  fNumOfErr[kWrongRowErr]++;
+  return kFALSE;
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDRawStream::CheckDilogic(UInt_t dilogic)
+{
+//check dilogic number     
+  if (dilogic>= 1 && dilogic <=kNDILOGICAdd) return kTRUE;
+
+  fRawReader->AddMajorErrorLog(kWrongDilogicErr,Form("dil %d",dilogic));
+  AliWarning(Form("Wrong DILOGIC index: %d, expected (1 -> %d)!",dilogic,kNDILOGICAdd));
+  fNumOfErr[kWrongDilogicErr]++;
+  //dilogic = iDILOGIC;
+  return kFALSE;
+}      
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDRawStream::CheckPad(UInt_t pad)
+{
+//check pad number     
+  if (pad < kNPadAdd) return kTRUE;
+  
+  fRawReader->AddMajorErrorLog(kWrongPadErr,Form("pad %d",pad));
+  AliWarning(Form("Wrong pad index: %d, expected (0 -> %d)!",pad,kNPadAdd));
+  fNumOfErr[kWrongPadErr]++;
+  return kFALSE;
+}    
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDRawStream::CheckEoE(UInt_t word,Int_t &nDil)
+{
+  if (!((word >> kbit27) & 0x1)) {                                                //check 27th bit in EoE. It must be 1!
+    fRawReader->AddMajorErrorLog(kEoEFlagErr);
+    AliWarning(Form("Missing end-of-event flag! (%08X)",word));
+    fNumOfErr[kEoEFlagErr]++;
+    return kFALSE;
+  }
+  nDil = word & 0x7f;
+  if(nDil < 1 || nDil > 48 ) {
+    fRawReader->AddMajorErrorLog(kEoESizeErr,Form("EoE size=%d",nDil));
+    AliWarning(Form("Wrong end-of-event word-count: %08X",word));
+    fNumOfErr[kEoESizeErr]++;
+    return kFALSE;
+  }
+//  UInt_t da = (eOfEvent >> 18) & 0xf;
+//  if (cntData!=0 && da != dilogic) {
+//    fRawReader->AddMajorErrorLog(kEoEDILOGICErr,Form("eoe dil %d != %d",da,dilogic));
+//    AliWarning(Form("Wrong DILOGIC address found in end-of-event: %d, expected %d!",da,dilogic));
+//    fNumOfErr[kEoEDILOGICErr]++;
+//    return kFALSE;  AliQAChecker::Instance()->Run(AliQA::kHMPID, task, obj) ;  
+
+//  }
+//  UInt_t ca = (eOfEvent >> 22) & 0x1f;
+//  if (cntData!=0 &&  ca != row) {
+//    fRawReader->AddMajorErrorLog(kEoERowErr,Form("eoe row %d != %d",ca,row));
+//    AliWarning(Form("Wrong row index found in end-of-event: %d, expected %d!",ca,row));
+//    fNumOfErr[kEoERowErr]++;
+//    return kFALSE;
+//  }
+  return kTRUE;
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDRawStream::CheckRowMarker(UInt_t word)
+{
+  UInt_t nMAXwordsInRow = 0x1EA;
+  UInt_t statusControlRow = 0x32a8; // 0x36a8 for zero suppression
+//First check on row marker    
+  UInt_t rowControlWord = word >> kbit0 & 0xfbff;
+  
+  if(rowControlWord != statusControlRow) {
+    fRawReader->AddMajorErrorLog(kRowMarkerErr);
+    AliWarning(Form("Wrong row marker %x expected 0x32a8!",rowControlWord));
+    fNumOfErr[kRowMarkerErr]++;
+    return kFALSE;
+  }
+//Second check on row marker    
+   UInt_t wordsInRow = word >> kbit16 & 0x0fff;                // Number of words after the row marker
+  
+  if (wordsInRow > nMAXwordsInRow) {
+    fRawReader->AddMajorErrorLog(kRowMarkerSizeErr);
+    AliWarning(Form(" FATAL: Number of words %x in a row exceeds the expected value: 0x1EA !",wordsInRow));
+    fNumOfErr[kRowMarkerSizeErr]++;
+    return kFALSE;
+  }
+  
+  return kTRUE;
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+UInt_t AliHMPIDRawStream::GetWord(Int_t n,EDirection dir)
+{
+  // This method returns the n-th 32 bit word
   // inside the raw data payload.
   // The method is supposed to be endian (platform)
   // independent.
   if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
   
   UInt_t word = 0;
+  
+  if(dir==kBwd) n = -n; 
+  fPosition+=4*n-4;
+  
+  StorePosition();
+  
   word |= fData[fPosition++];
   word |= fData[fPosition++] << 8;
   word |= fData[fPosition++] << 16;
   word |= fData[fPosition++] << 24;
-  
+
   return word;
 }
-
-//_____________________________________________________________________________
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+void AliHMPIDRawStream::DumpData(Int_t nw)
+{
+   for(Int_t i=0;i<nw;i+=4) {
+     if(!(i%16)) printf(" \n %8i) ",i);
+     printf("%02X%02X%02X%02X [ %06i ] ",fData[i+3],fData[i+2],fData[i+1],fData[i+0],fPos[i]);
+   }
+   Printf(" \n -----end of dump ----------- ");
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+void AliHMPIDRawStream::StorePosition()
+{
+//  if(fPos[fPosition]!=0) {Printf("Position already stored!!! Value %i at address %i",fPos[fPosition],fPosition); return;}
+  iPos++;
+  fPos[fPosition] = iPos;
+//  if(stDeb)Printf("%i - Actual position %i",iPos,fPosition); 
+}
index 07d5566e87b81a00f21a52bc4dd68e91299d5199..35780f095526932243f401006558f686db23e107 100644 (file)
@@ -36,7 +36,7 @@ class AliHMPIDRawStream: public TObject {
            Int_t    Ch( Int_t ddl,Int_t row,Int_t dil,Int_t pad    ) {return AliHMPIDParam::A2C(fPad[ddl][row][dil][pad]); }            //chamber number
            
            Int_t GetDDLNumber()  const { return fDDLNumber; }                                                                            // Provide current DDL number
-    inline Int_t GetCharge(Int_t ddl,Int_t row, Int_t dilogic, Int_t pad);                                                                         // Provide the charge observed in certain row,dilogic,pad channel
+    inline  Int_t GetCharge(Int_t ddl,Int_t row, Int_t dilogic, Int_t pad);                                                                         // Provide the charge observed in certain row,dilogic,pad channel
            inline Int_t GetPad(Int_t ddl,Int_t row,Int_t dil,Int_t pad);                                                                        //
            
            Int_t   Pc          ( Int_t ddl,Int_t row,Int_t dil,Int_t pad                            ) {return AliHMPIDParam::A2P(fPad[ddl][row][dil][pad]);}                                                 //PC position number
@@ -46,7 +46,21 @@ class AliHMPIDRawStream: public TObject {
            inline  Bool_t SetZeroSup (Bool_t isSup);
     inline  Bool_t GetZeroSup(); 
     inline  Int_t GetErrors(Int_t eType);                                                                                          //Get errors and occurance
-                     
+    
+    Bool_t ReadHMPIDRawData();                           // Read HMPID Raw data
+    Bool_t ReadSegment(UInt_t word32,Int_t &cntSegment); // Read Segment
+    Bool_t ReadRow(UInt_t word32,Int_t &cntRow);         // Read Row
+    Bool_t ReadDilogic(UInt_t word32,Int_t &cntDilogic); // Read Dilogic
+
+    Bool_t CheckRow(UInt_t row);                   // Check Row
+    Bool_t CheckDilogic(UInt_t dilogic);           // Check Dilogic
+    Bool_t CheckPad(UInt_t pad);                   // Check pad
+    Bool_t CheckEoE(UInt_t word,Int_t &nDil);       // Check EoE
+    Bool_t CheckRowMarker(UInt_t word);            // Check RowMarker
+    Bool_t CheckSegment(UInt_t word);              // Check Segment
+    void   DumpData(Int_t nw);                     // Dump Data
+    void   StorePosition();                        //
+    
     inline void    Raw            (UInt_t &w32,Int_t &ddl,Int_t &r,Int_t &d,Int_t &a);                                              //digit->(w32,ddl,r,d,a)
     inline void    Raw            (Int_t ddl,Int_t r,Int_t d,Int_t a);                                                              //raw->abs pad number
     inline Bool_t  Raw            (UInt_t  w32,Int_t  ddl,AliRawReader *pRR);                                                       //(w32,ddl)->digit
@@ -57,6 +71,12 @@ class AliHMPIDRawStream: public TObject {
     inline void   WriteSegMarker  (AliFstream *ddl,UInt_t row);   
     
 //    inline TClonesArray  ReMap(TClonesArray *pDigIn);
+enum EDirection {kFwd,kBwd};
+
+enum Ebits {kbit0,kbit1 , kbit2, kbit3, kbit4, kbit5, kbit6, kbit7, kbit8,
+                  kbit9 ,kbit10,kbit11,kbit12,kbit13,kbit14,kbit15,kbit16,
+                  kbit17,kbit18,kbit19,kbit20,kbit21,kbit22,kbit23,kbit24,
+                  kbit25,kbit26,kbit27,kbit28,kbit29,kbit30,kbit31,kbit32};
     
     enum EHMPIDRawStreamError {
       kRawDataSizeErr = 1,
@@ -91,27 +111,19 @@ class AliHMPIDRawStream: public TObject {
     AliHMPIDRawStream& operator = (const AliHMPIDRawStream& stream);
     AliHMPIDRawStream(const AliHMPIDRawStream& stream);
 
-    UInt_t           GetNextWord();
-
+    UInt_t           GetWord(Int_t n=1,EDirection dir=kFwd);             // Get n-th word
+    UInt_t           GetNextWord();                                      // Get next word
     Int_t            fCharge[kNDDL][kNRows+1][kNDILOGICAdd+1][kNPadAdd]; // Array for charge values for all channels in one DDL
-    
-    Int_t            fPad[kNDDL][kNRows+1][kNDILOGICAdd+1][kNPadAdd]; // Array for abs pad values for all channels in one DDL
-
-    UInt_t           fRawWord[kNDDL][kNRows+1][kNDILOGICAdd+1][kNPadAdd];
-    
-    Int_t            fNumOfErr[kSumErr];    // Store the numner of errors for a given error type
-        
-    Int_t            fDDLNumber;    // index of current DDL number
-
-    AliRawReader*    fRawReader;    // object for reading the raw data
-
-    UChar_t*         fData;         // raw data
-
-    Int_t            fPosition;     // current position in fData
-    
+    Int_t            fPad[kNDDL][kNRows+1][kNDILOGICAdd+1][kNPadAdd];    // Array for abs pad values for all channels in one DDL
+    UInt_t           fRawWord[kNDDL][kNRows+1][kNDILOGICAdd+1][kNPadAdd];// Array of raw words
+    Int_t            fNumOfErr[kSumErr];                                 // Store the numner of errors for a given error type
+    Int_t            fDDLNumber;                                         // index of current DDL number
+    AliRawReader*    fRawReader;                                         // object for reading the raw data
+    UChar_t*         fData;                                              // raw data
+    Int_t            fPosition;                                          // current position in fData
     Bool_t           fZeroSup;
 
-    ClassDef(AliHMPIDRawStream, 1)  // base class for reading HMPID raw digits
+    ClassDef(AliHMPIDRawStream, 1)                                       // base class for reading HMPID raw digits
 };
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 void AliHMPIDRawStream::Raw(UInt_t &w32,Int_t &ddl,Int_t &r,Int_t &d,Int_t &a)