]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ZDC/AliZDCRawStream.cxx
SOD enum updated to include logical combination of signals
[u/mrichter/AliRoot.git] / ZDC / AliZDCRawStream.cxx
index ccbffa27cbbae79a831363726511078e051943cd..30bd880d071415bb47e73bc925456dea08ade881 100644 (file)
@@ -40,6 +40,7 @@ ClassImp(AliZDCRawStream)
 AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
   fRawReader(rawReader),
   fBuffer(0),
+  fReadOutCard(-1),
   fEvType(0),
   fPosition(0),
   fIsCalib(kFALSE),
@@ -51,10 +52,8 @@ AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
   fIsADCEOB(kFALSE),
   fSODReading(kFALSE),
   fIsMapRead(kFALSE),
-  fDARCEvBlockLenght(0),  
-  fDARCBlockAttributes(0),
-  fDeadfaceOffset(0),
-  fDeadbeefOffset(0),
+  fDeadfaceOffset(-1),
+  fDeadbeefOffset(-1),
   fDataOffset(0),
   fModType(-1),
   fADCModule(-1),
@@ -72,13 +71,37 @@ AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
   fIsScHeaderRead(kFALSE),
   fScStartCounter(0),
   fScEvCounter(0),
+  fDetPattern(0),
+  fTrigCountNWords(0),
+  fIsTriggerScaler(kFALSE),
+  fTrigCountStart(0),
+  fMBTrigInput(0),        
+  fCentralTrigInput(0), 
+  fSCentralTrigInput(0),
+  fEMDTrigInput(0),     
+  fL0Received(0),         
+  fMBtrig2CTP(0),         
+  fCentralTrig2CTP(0),  
+  fSCentralTrig2CTP(0), 
+  fEMDTrig2CTP(0),           
+  fTrigHistNWords(0),
+  fIsTriggerHistory(kFALSE),
+  fTrigHistStart(0),
+  fPileUpBit1stWord(0),
+  fL0Bit1stWord(0),
+  fCentralTrigHist(0),
+  fMBTrigHist(0),
+  fPileUpBit2ndWord(0),
+  fL0Bit2ndWord(0), 
+  fSCentralTrigHist(0),
+  fEMDTrigHist(0),
   fNChannelsOn(0),
   fCurrentCh(-1),
   fCabledSignal(-1),
   fCurrScCh(-1),
-  fIsEventGood(kTRUE),
+  fIsADCEventGood(kTRUE),
   fIsL0BitSet(kTRUE),
-  fIsPileUpOff(kTRUE)
+  fIsPileUpEvent(kFALSE)
 {
   // Create an object to read ZDC raw digits
   fRawReader->Reset();
@@ -91,6 +114,8 @@ AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
       if(i<32) fScalerMap[i][j]=-1;
     }
   }
+  
+  for(Int_t k=0; k<4; k++) fCPTInput[k] = 0;
 
 }
 
@@ -99,6 +124,7 @@ AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
   TObject(stream),
   fRawReader(stream.fRawReader),
   fBuffer(stream.GetRawBuffer()),
+  fReadOutCard(stream.GetReadOutCard()),
   fEvType(stream.fEvType),
   fPosition(stream.fPosition),
   fIsCalib(stream.fIsCalib),
@@ -110,8 +136,6 @@ AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
   fIsADCEOB(stream.fIsADCEOB), 
   fSODReading(stream.fSODReading),
   fIsMapRead(stream.fIsMapRead),
-  fDARCEvBlockLenght(stream.fDARCEvBlockLenght),  
-  fDARCBlockAttributes(stream.fDARCBlockAttributes),
   fDeadfaceOffset(stream.GetDeadfaceOffset()),
   fDeadbeefOffset(stream.GetDeadbeefOffset()),
   fDataOffset(stream.GetDataOffset()),
@@ -131,13 +155,37 @@ AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
   fIsScHeaderRead(stream.fIsScHeaderRead),
   fScStartCounter(stream.fScStartCounter),
   fScEvCounter(stream.fScEvCounter),
+  fDetPattern(stream.fDetPattern),
+  fTrigCountNWords(stream.fTrigCountNWords),
+  fIsTriggerScaler(stream.fIsTriggerScaler),
+  fTrigCountStart(stream.fTrigCountStart),
+  fMBTrigInput(stream.fMBTrigInput),      
+  fCentralTrigInput(stream.fCentralTrigInput), 
+  fSCentralTrigInput(stream.fSCentralTrigInput),
+  fEMDTrigInput(stream.fEMDTrigInput),     
+  fL0Received(stream.fL0Received),        
+  fMBtrig2CTP(stream.fMBtrig2CTP),        
+  fCentralTrig2CTP(stream.fCentralTrig2CTP),  
+  fSCentralTrig2CTP(stream.fSCentralTrig2CTP), 
+  fEMDTrig2CTP(stream.fEMDTrig2CTP),         
+  fTrigHistNWords(stream.fTrigHistNWords),
+  fIsTriggerHistory(stream.fIsTriggerHistory),
+  fTrigHistStart(stream.fTrigHistStart),
+  fPileUpBit1stWord(stream.fPileUpBit1stWord),
+  fL0Bit1stWord(stream.fL0Bit1stWord), 
+  fCentralTrigHist(stream.fCentralTrigHist),
+  fMBTrigHist(stream.fMBTrigHist),
+  fPileUpBit2ndWord(stream.fPileUpBit2ndWord),
+  fL0Bit2ndWord(stream.fL0Bit2ndWord), 
+  fSCentralTrigHist(stream.fSCentralTrigHist),
+  fEMDTrigHist(stream.fEMDTrigHist),
   fNChannelsOn(stream.fNChannelsOn),
   fCurrentCh(stream.fCurrentCh),
   fCabledSignal(stream.GetCabledSignal()),
   fCurrScCh(stream.fCurrScCh),
-  fIsEventGood(stream.fIsEventGood),
+  fIsADCEventGood(stream.fIsADCEventGood),
   fIsL0BitSet(stream.fIsL0BitSet),
-  fIsPileUpOff(stream.fIsPileUpOff)
+  fIsPileUpEvent(stream.fIsPileUpEvent)
 
 {
   // Copy constructor
@@ -149,6 +197,8 @@ AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
       if(i<32) fScalerMap[i][j] = stream.fMapADC[i][j];
     }
   }
+  
+  for(Int_t k=0; k<4; k++) fCPTInput[k] = stream.fCPTInput[k];
 }
 
 //_____________________________________________________________________________
@@ -172,7 +222,7 @@ void AliZDCRawStream::ReadChMap()
 {
   // Reading channel map
   const int kNch = 48;
-  //printf("\t Reading ZDC ADC mapping from OCDB\n");
+  AliDebug(2,"\t Reading ZDC ADC mapping from OCDB\n");
   AliZDCChMap * chMap = GetChMap();
   //chMap->Print("");
   for(Int_t i=0; i<kNch; i++){
@@ -196,39 +246,47 @@ void AliZDCRawStream::ReadCDHHeader()
       return;
   }
   else{
-    //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
+    //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %x\n",fRawReader->GetDataSize());
 
-    fDARCEvBlockLenght = header->fSize;
-    //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
-    
     UChar_t message = header->GetAttributes();
     //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
     
-    if(message == 0x0){ // PHYSICS RUN
+    if((message & 0xf0) == 0x0){ // PHYSICS RUN
        //printf("\t PHYSICS RUN raw data found\n");
     }
-    else if(message == 0x10){ // COSMIC RUN
+    else if((message & 0xf0) == 0x10){ // COSMIC RUN
        //printf("\t STANDALONE_COSMIC RUN raw data found\n");
     }
-    else if(message == 0x20){ // PEDESTAL RUN
+    else if((message & 0xf0) == 0x20){ // PEDESTAL RUN
        //printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
     }
-    else if(message == 0x30){ // LASER RUN
+    else if((message & 0xf0) == 0x30){ // LASER RUN
        //printf("\t STANDALONE_LASER RUN raw data found\n");
     }
-    else if(message == 0x40){ // CALIBRATION_CENTRAL RUN
+    else if((message & 0xf0) == 0x40){ // CALIBRATION_CENTRAL RUN
        //printf("\t CALIBRATION_CENTRAL RUN raw data found\n");
     }
-    else if(message == 0x50){ // CALIBRATION_SEMICENTRAL
+    else if((message & 0xf0) == 0x50){ // CALIBRATION_SEMICENTRAL
        //printf("\t CALIBRATION_SEMICENTRAL RUN raw data found\n");
     }
-    else if(message == 0x60){ // CALIBRATION_MB
+    else if((message & 0xf0) == 0x60){ // CALIBRATION_MB
        //printf("\t CALIBRATION_MB RUN raw data found\n");
     }
-    else if(message == 0x70){ // CALIBRATION_EMD
+    else if((message & 0xf0) == 0x70){ // CALIBRATION_EMD
        //printf("\t CALIBRATION_EMD RUN raw data found\n");
     }
-    
+    // *** Checking the bit indicating the used readout card
+    // (the payload is different in the 2 cases!)
+    if((message & 0x08) == 0){  // ** DARC card
+       fReadOutCard = 0;
+       fIsDARCHeader = kTRUE;
+       AliInfo("\t ZDC readout card used: DARC");
+    }
+    else if((message & 0x08) == 0x08){  // ** ZRC card
+       fReadOutCard = 1;
+       AliInfo("\t ZDC readout card used: ZRC");
+    }
+
     if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
       fIsCalib = kTRUE;
     }
@@ -281,8 +339,7 @@ void AliZDCRawStream::ReadCDHHeader()
       fRawReader->AddMajorErrorLog(kDARCError);
     }
   }
-  //
-  fIsDARCHeader = kTRUE;
+  
 }
 
 //_____________________________________________________________________________
@@ -293,17 +350,17 @@ Bool_t AliZDCRawStream::Next()
 
   if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
   const int kNch = 48;
-  Bool_t readScaler = kFALSE;
   Int_t kFirstADCGeo=0, kLastADCGeo=3, kScalerGeo=8, kPUGeo=29, kTrigScales=30, kTrigHistory=31;
   fIsHeaderMapping = kFALSE; fIsChMapping = kFALSE; 
   fIsADCHeader = kFALSE; fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
   fIsUnderflow = kFALSE; fIsOverflow = kFALSE; 
   fSector[0] = fSector[1] = -1;
-  
+//  fTrigCountNWords = 9; fTrigHistNWords = 2;
+  for(Int_t kl=0; kl<4; kl++) fCPTInput[kl] = 0;
+
   fEvType = fRawReader->GetType();
   if(fPosition==0){
     //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
-      //ReadEventHeader();
       ReadCDHHeader();
     //}
     fCurrentCh=0; fCurrScCh=0; fNChannelsOn=0;
@@ -316,7 +373,7 @@ Bool_t AliZDCRawStream::Next()
   
   // *** End of ZDC event
   if(fBuffer == 0xcafefade){
-    //printf("\n-> AliZDCRawStream::Next() ***** End of ZDC event *****\n\n");
+    //printf("\n  AliZDCRawStream::Next() ***** End of ZDC event *****\n\n");
     return kFALSE;
   }
   
@@ -325,12 +382,11 @@ Bool_t AliZDCRawStream::Next()
   // -------------------------------------------
   // If the CDH has been read then 
   // the DARC header must follow
-  if(fIsDARCHeader){
+  if(fReadOutCard==0 && fIsDARCHeader){
     //printf("\t ---- DARC header ----\n");
     if(fIsCalib){
       fDeadfaceOffset = 9;
       fDeadbeefOffset = 25;
-      readScaler = kTRUE;
     }
     else{
       fDeadfaceOffset = 1;
@@ -339,31 +395,31 @@ Bool_t AliZDCRawStream::Next()
     fDataOffset = 1+fDeadbeefOffset;
     fIsDARCHeader = kFALSE;
   }
-
     
-  // -------------------------------------------
-  // --- Start of data event
-  // --- decoding mapping of connected ADC ch.
-  // -------------------------------------------
+  // ---------------------------------------------
+  // --- Start of data event (SOD)             ---
+  // --- decoding mapping of connected ADC ch. ---
+  // ---------------------------------------------
   // In the SOD event ADC ch. mapping is written
-  if(fEvType==10 && fSODReading){
-    //printf("\n-> AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
+  if(fEvType==10){
+   if(fSODReading){
     
-    if(fPosition>fDataOffset){
+    if(fPosition>=fDataOffset){
       if((fBuffer&0xff000001) == 0xff000001){ // ************** Mapping
-        if(fPosition==(fDataOffset+1)){ 
+        // DARC 1st datum @ fDataOffset+1 \ ZRC 1st valid datum @ fDataOffset=0
+        if((fPosition==fDataOffset+1) || (fPosition==fDataOffset)){ 
           printf("\n\n ------ AliZDCRawStream -> Reading mapping from StartOfData event ------\n");
           fCurrentCh=0; fCurrScCh=0;   
         }
        else{
          printf(" ------ AliZDCRawStream -> End of ZDC StartOfData event ------\n\n");
-          //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
+          fSODReading = kFALSE;
          return kFALSE;
        }
       }
       else if((fBuffer&0xff000002) == 0xff000002){ // ************** Threshold settings
         fPosition++;
-       return kFALSE;
+       return kFALSE; // !!!!!!!!!!!!!!!!!!!!!  For the moment thresholds are not read
       }
       else if((fBuffer&0x80000000)>>31 == 1){ // --- Mapping header
         fIsHeaderMapping = kTRUE;
@@ -377,7 +433,7 @@ Bool_t AliZDCRawStream::Next()
        fADCChannel = ((fBuffer & 0x3fff0000)>>16);
        fCabledSignal = (fBuffer&0xffff);
         //
-       if(fModType==1){ // ******** ADCs ********************************
+       if(fModType == kV965){ // ******** ADCs ********************************
            // Channel signal
          if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
             fIsChMapping = kTRUE;
@@ -396,7 +452,7 @@ Bool_t AliZDCRawStream::Next()
              || fCabledSignal==24 || fCabledSignal==48){
              fMapADC[fCurrentCh][3] = 4; //ZNA
              //
-             if(fCabledSignal==2 || fCabledSignal==26)       fMapADC[fCurrentCh][4]=0;
+             if(fCabledSignal==kZNAC || fCabledSignal==kZNACoot)   fMapADC[fCurrentCh][4]=0;
              else if(fCabledSignal==3 || fCabledSignal==27)  fMapADC[fCurrentCh][4]=1;
              else if(fCabledSignal==4 || fCabledSignal==28)  fMapADC[fCurrentCh][4]=2;
              else if(fCabledSignal==5 || fCabledSignal==29)  fMapADC[fCurrentCh][4]=3;
@@ -446,7 +502,7 @@ Bool_t AliZDCRawStream::Next()
            //
          } // high range channels
         }// ModType=1 (ADC mapping)
-        else if(fModType==2){  // ******** VME scaler **************************
+        else if(fModType == kV830){  // ******** VME scaler **************************
           fIsChMapping = kTRUE;
          fScalerMap[fCurrScCh][0] = fADCModule;
          fScalerMap[fCurrScCh][1] = fADCChannel;
@@ -507,85 +563,89 @@ Bool_t AliZDCRawStream::Next()
          
           fCurrScCh++;
         }
-       else if(fModType==3){ // **** scalers from trigger card
+       /*else if(fModType == kTRG){ // **** scalers from trigger card
          //printf("\t Trigger scaler mod. %d ch. %d, signal %d\n",fADCModule,fADCChannel,fCabledSignal);         
         }
-       else if(fModType==4){ // **** trigger history from trigger card
+       else if(fModType == kTRGI){ // **** trigger history from trigger card
          //printf("\t Trigger card ch. %d, signal %d\n",fADCChannel,fCabledSignal);
         }
-       else if(fModType==5){ // **** pattern unit
+       else if(fModType == kPU){ // **** pattern unit
          //printf("\t P.U. mod. %d ch. %d, signal %d\n",fADCModule,fADCChannel,fCabledSignal);
-        }
+        }*/
       }//reading channel mapping
     }
-    fPosition++;
-    return kTRUE;
-  } // SOD event
+   } // if fSODREading
+   fPosition++;
+   return kTRUE;
+  } // ------------------------------- SOD event
   
   // -------------------------------------------
   // --- DARC data
   // -------------------------------------------
-  if(fPosition<fDeadfaceOffset){
+  if(fPosition<fDeadfaceOffset && fReadOutCard==0){
     fPosition++;
     return kTRUE;
   }
-  else if(fPosition==fDeadfaceOffset){
+  else if(fPosition==fDeadfaceOffset && fReadOutCard==0){
     if(fBuffer != 0xdeadface){
-      AliWarning(" NO deadface after DARC data");
-      fRawReader->AddMajorErrorLog(kDARCError);  
+      //AliWarning(" NO deadface after DARC data");
+      fRawReader->AddMajorErrorLog(kDARCError); 
     }
     else{
       fPosition++;
       return kTRUE;
     }
   }
-  
-  // -------------------------------------------
-  // --- DARC global data
-  // -------------------------------------------
-  else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
+  else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset && fReadOutCard==0){
     fPosition++;
     return kTRUE;
   }
-  else if(fPosition==fDeadbeefOffset){
+  else if(fPosition==fDeadbeefOffset && fReadOutCard==0){
     if(fBuffer != 0xdeadbeef){
-      AliWarning(" NO deadbeef after DARC global data");
+      //AliWarning(" NO deadbeef after DARC global data");
       fRawReader->AddMajorErrorLog(kDARCError);  
+      fPosition++;
+      return kFALSE;
     }
     else{
       fPosition++;
       return kTRUE;
     }
-  }
-
-  // -------------------------------------------
+  } // ------------------------------- End of DARC data
+  
+  // ---------------------------------------------
   // --- ZDC data
   // --- ADCs + VME scaler + trigger card + P.U.
-  // -------------------------------------------
+  // ---------------------------------------------
   else if(fPosition>=fDataOffset){
     
     //printf("AliZDCRawStream: fSODReading = %d\n", fSODReading);
     if(!fSODReading && !fIsMapRead) ReadChMap();
     
+    //  !!!!!!!!!!!!!!! DARC readout card only !!!!!!!!!!!
     // Not valid datum before the event 
     // there MUST be a NOT valid datum before the event!!!
-    if(fPosition==fDataOffset){
-      //printf("\t **** ZDC data begin ****\n");
-      if((fBuffer & 0x07000000) != 0x06000000){
-        fRawReader->AddMajorErrorLog(kZDCDataError);
-      }
-      else if((fBuffer & 0x07000000) == 0x06000001){ // Corrupted event!!!
-        fIsEventGood = kFALSE;
+    if(fReadOutCard==0){
+      if(fPosition==fDataOffset){ 
+        //printf("\t **** ZDC data begin ****\n");
+        if((fBuffer & 0x07000000) != 0x06000000){
+          fRawReader->AddMajorErrorLog(kZDCDataError);
+        }
+        else if((fBuffer & 0x07000000) == 0x06000001){ // Corrupted event!!!
+          fIsADCEventGood = kFALSE;
+        }
       }
-    }
     
-    // If the not valid datum isn't followed by the 1st ADC header
-    // the event is corrupted (i.e., 2 gates arrived before trigger)
-    else if(fPosition==fDataOffset+1){
-      if((fBuffer & 0x07000000) != 0x02000000){
-        AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!");
-        fRawReader->AddMajorErrorLog(kZDCDataError);
-        fIsEventGood = kFALSE;
+      // If the not valid datum isn't followed by the 1st ADC header
+      // the event is corrupted (i.e., 2 gates arrived before trigger)
+      else if(fPosition==fDataOffset+1){ 
+        if((fBuffer & 0x07000000) != 0x02000000){
+          AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!");
+          fRawReader->AddMajorErrorLog(kZDCDataError);
+          fIsADCEventGood = kFALSE;
+         fPosition++;
+         return kFALSE;
+        }
       }
     }
      
@@ -596,7 +656,6 @@ Bool_t AliZDCRawStream::Next()
     // - Trigger card scales GEO = 30
     // - Trigger card history GEO = 31
     fADCModule = (Int_t) ((fBuffer & 0xf8000000)>>27);
-    //printf("  AliZDCRawStream -> Module GEO address %d\n",fADCModule);
     
     // ************************************ ADC MODULES ************************************
     if(fADCModule>=kFirstADCGeo && fADCModule<=kLastADCGeo){
@@ -674,7 +733,7 @@ Bool_t AliZDCRawStream::Next()
        //printf("  AliZDCRawStream -> EOB --------------------------\n");
       }
     }//ADC module
-    // ************************************ VME MODULES ************************************
+    // ********************************* VME SCALER HEADER *********************************
     else if(fADCModule == kScalerGeo){
       if(fBuffer & 0x04000000 && fIsScHeaderRead==kFALSE){ // *** Scaler header
         fScGeo = (fBuffer & 0xf8000000)>>27;      
@@ -682,34 +741,120 @@ Bool_t AliZDCRawStream::Next()
         fScTriggerSource = (fBuffer & 0x00030000)>>16;    
         fScTriggerNumber = (fBuffer & 0x0000ffff);
         fIsScHeaderRead = kTRUE; 
-       fScStartCounter = (Int_t) (fPosition);
+       fScStartCounter = fPosition;
         //Ch. debug
-        //printf("  AliZDCRawStream -> SCALER HEADER: geo %d Nwords %d TrigSource %d TrigNo. %d\n",
+        //printf("  AliZDCRawStream -> VME SCALER HEADER: geo %d Nwords %d TrigSource %d TrigNo. %d\n",
         //   fScGeo,fScNWords,fScTriggerSource,fScTriggerNumber);
       } 
       else if(!(fBuffer & 0x04000000)){
         fIsScEventGood = kFALSE;
       }
     }
+    // *********************************** PATTERN UNIT ***********************************
     else if(fADCModule == kPUGeo){
       // still to be implemented!!! Not yet in data!!!
+      fDetPattern = (fBuffer & 0x0000003f);
+      // Ch. debug
+      //printf("  AliZDCRawStream -> Pattern Unit\n");
+      
     }
+    // ******************************** TRIGGER CARD COUNTS ********************************
     else if(fADCModule == kTrigScales){
-      
+      if(fIsTriggerScaler == kFALSE){
+        fTrigCountNWords = (Int_t) ((fBuffer & 0xfc0000)>>17);
+        fTrigCountStart = fPosition;
+       fIsTriggerScaler = kTRUE;
+      }
+      // Ch. debug
+      //printf("  AliZDCRawStream -> Trigger Scaler header\n");      
     }
+    // ********************************** TRIGGER HISTORY **********************************
     else if(fADCModule == kTrigHistory){
+      if(fIsTriggerHistory == kFALSE){
+        fTrigHistNWords = (Int_t) ((fBuffer & 0xfc0000)>>17);
+       fTrigHistStart = fPosition;
+        fIsTriggerHistory = kTRUE;
+      }
+      // Ch. debug
+      //printf("  AliZDCRawStream -> Trigger History header\n");
+      
     } 
+    // ********************************** VME SCALER DATA **********************************
     //  Reading VME scaler data 
     if(fIsScHeaderRead && fPosition>=fScStartCounter+1){ // *** Scaler word
-      fADCModule = fScGeo;
+      fADCModule = kScalerGeo; fIsADCDataWord = kFALSE;        
       fScEvCounter = fBuffer;
       Int_t nWords = (Int_t) (fScNWords);
       if(fPosition == fScStartCounter+nWords) fIsScHeaderRead = kFALSE;
       //Ch. debug
       //printf("  AliZDCRawStream -> scaler datum %d", fScEvCounter);
     }
+    // ******************************** TRIGGER SCALER DATA ********************************
+    //  Reading trigger scaler data 
+    if(fIsTriggerScaler && fPosition>=fTrigCountStart+1){
+      fADCModule = kTrigScales; fIsADCDataWord = kFALSE;       
+      if(fPosition == fTrigCountStart+1)      fMBTrigInput = fBuffer;              
+      else if(fPosition == fTrigCountStart+2) fCentralTrigInput = fBuffer;                 
+      else if(fPosition == fTrigCountStart+3) fSCentralTrigInput = fBuffer;
+      else if(fPosition == fTrigCountStart+4) fEMDTrigInput = fBuffer; 
+      else if(fPosition == fTrigCountStart+5) fL0Received = fBuffer;
+      else if(fPosition == fTrigCountStart+6) fMBtrig2CTP = fBuffer;    
+      else if(fPosition == fTrigCountStart+7) fCentralTrig2CTP = fBuffer;  
+      else if(fPosition == fTrigCountStart+8) fSCentralTrig2CTP = fBuffer; 
+      else if(fPosition == fTrigCountStart+9){
+        fEMDTrig2CTP = fBuffer;       
+        fIsTriggerScaler = kFALSE;
+      }
+      // Ch. debug
+      //printf("  AliZDCRawStream -> Trigger Scaler datum %d\n", fPosition-fTrigCountStart);
+    }
+    // ******************************* TRIGGER HISTORY WORDS ******************************
+    //  Reading trigger history
+    if(fIsTriggerHistory && fPosition>=fTrigHistStart+1){
+       fADCModule = kTrigHistory; fIsADCDataWord = kFALSE;     
+       if(fPosition == fTrigHistStart+1){
+         fPileUpBit1stWord = (fBuffer & 0x80000000) >> 31;
+         fL0Bit1stWord = (fBuffer & 0x40000000) >> 30;        
+         fCentralTrigHist = (fBuffer & 0x3fff8000) >> 14; 
+         fMBTrigHist =  (fBuffer & 0x00007fff);        
+         //
+         fCPTInput[0] = (fBuffer & 0x00000080) >> 6;  // MB bit
+         fCPTInput[1] = (fBuffer & 0x00400000) >> 21; // CENTRAL bit
+        }
+       
+       else if(fPosition == fTrigHistStart+fTrigHistNWords){
+          fPileUpBit2ndWord = (fBuffer & 0x80000000) >> 31;
+          fL0Bit2ndWord = (fBuffer & 0x40000000) >> 30;             
+          fSCentralTrigHist = (fBuffer & 0x3fff8000) >> 14; 
+          fEMDTrigHist =  (fBuffer & 0x00007fff);       
+          //
+          fCPTInput[2] = (fBuffer & 0x00000080) >> 6;  // SEMICENTRAL bit
+          fCPTInput[3] = (fBuffer & 0x00400000) >> 21; // EMD bit
+         //
+         fIsTriggerHistory = kFALSE;
+          
+         // Checking if the event is good
+          // (1) both history word pile up bits must be = 0
+          if(fPileUpBit1stWord==0 && fPileUpBit2ndWord==0) fIsPileUpEvent = kFALSE;
+          else{
+            fIsPileUpEvent = kTRUE;
+           printf("  AliZDCRawStream -> PILE UP EVENT: bitPileUp0 %d bitPileUp1 %d\n",
+               fPileUpBit1stWord, fPileUpBit2ndWord);
+          }
+         // (2) both history word L0 bits must be = 1
+          if(fL0Bit1stWord==1 && fL0Bit2ndWord==1) fIsL0BitSet = kTRUE;
+          else{
+            fIsL0BitSet = kFALSE;
+           printf("  AliZDCRawStream -> L0 wrongly set: bitL0word0 %d bitL0word1 %d\n",
+               fL0Bit1stWord, fL0Bit2ndWord);
+          }
+        }       
+        // Ch. debug
+        //printf("  AliZDCRawStream -> Trigger history word %d\n", fPosition-fTrigHistStart);
+    }
     
   }
+
   fPosition++;
 
   return kTRUE;