]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ZDC/AliZDCRawStream.cxx
typo corrected
[u/mrichter/AliRoot.git] / ZDC / AliZDCRawStream.cxx
index 0d012388c816a4d89f292db2ee94c3b92b061954..ba0c166650409aacf9dc7acd2ea921b0918e7021 100644 (file)
@@ -40,20 +40,21 @@ ClassImp(AliZDCRawStream)
 AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
   fRawReader(rawReader),
   fBuffer(0),
+  fReadOutCard(-1),
   fEvType(0),
   fPosition(0),
   fIsCalib(kFALSE),
   fIsDARCHeader(kFALSE),
+  fIsHeaderMapping(kFALSE),
   fIsChMapping(kFALSE),
   fIsADCDataWord(kFALSE),
   fIsADCHeader(kFALSE),
   fIsADCEOB(kFALSE),
   fSODReading(kFALSE),
   fIsMapRead(kFALSE),
-  fDARCEvBlockLenght(0),  
-  fDARCBlockAttributes(0),
-  fDeadfaceOffset(0),
-  fDeadbeefOffset(0),
+  fReadCDH(kFALSE),
+  fDeadfaceOffset(-1),
+  fDeadbeefOffset(-1),
   fDataOffset(0),
   fModType(-1),
   fADCModule(-1),
@@ -61,21 +62,76 @@ AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
   fADCChannel(-1),      
   fADCValue(-1),        
   fADCGain(-1),
-  fScNWords(0),          
+  fIsUnderflow(kFALSE),
+  fIsOverflow(kFALSE),
   fScGeo(0),     
-  fScTS(0),      
+  fScNWords(0),          
+  fScTriggerSource(0),   
   fScTriggerNumber(0),
-  fIsScEventGood(kFALSE),
-  fNConnCh(-1),
-  fCabledSignal(-1)
+  fIsScEventGood(kTRUE),
+  fIsScHeaderRead(kFALSE),
+  fScStartCounter(0),
+  fScEvCounter(0),
+  fIsScalerWord(kFALSE),
+  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),
+  fCurrTDCCh(-1),
+  fIsADCEventGood(kTRUE),
+  fIsL0BitSet(kTRUE),
+  fIsPileUpEvent(kFALSE),
+  fIsADDChannel(kFALSE),
+  fADDADCdatum(0),
+  fIsTDCHeaderRead(kFALSE),
+  fTDCStartCounter(0),
+  fIsZDCTDCHeader(kFALSE),
+  fIsZDCTDCdatum(kFALSE),
+  fZDCTDCdatum(0),
+  fIsADDTDCHeader(kFALSE),
+  fIsADDTDCdatum(kFALSE),
+  fADDTDCdatum(0)
 {
   // Create an object to read ZDC raw digits
   fRawReader->Reset();
   fRawReader->Select("ZDC");
   //
-  for(Int_t i=0; i<48; i++){
-    for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
+  const int kNch = 48;
+  for(Int_t i=0; i<kNch; i++){
+    for(Int_t j=0; j<5; j++){
+      fMapADC[i][j]=-1;
+      if(i<32){
+        fScalerMap[i][j]=-1;
+        if(j<3) fTDCMap[i][j]=-1;
+      }
+    }
   }
+  
+  for(Int_t k=0; k<4; k++) fCPTInput[k] = 0;
 
 }
 
@@ -84,18 +140,19 @@ 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),
   fIsDARCHeader(stream.fIsDARCHeader), 
+  fIsHeaderMapping(stream.fIsHeaderMapping),
   fIsChMapping(stream.fIsChMapping),
   fIsADCDataWord(stream.fIsADCDataWord), 
   fIsADCHeader(stream.fIsADCHeader), 
   fIsADCEOB(stream.fIsADCEOB), 
   fSODReading(stream.fSODReading),
   fIsMapRead(stream.fIsMapRead),
-  fDARCEvBlockLenght(stream.fDARCEvBlockLenght),  
-  fDARCBlockAttributes(stream.fDARCBlockAttributes),
+  fReadCDH(stream.fReadCDH),
   fDeadfaceOffset(stream.GetDeadfaceOffset()),
   fDeadbeefOffset(stream.GetDeadbeefOffset()),
   fDataOffset(stream.GetDataOffset()),
@@ -105,19 +162,71 @@ AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
   fADCChannel(stream.GetADCChannel()),  
   fADCValue(stream.GetADCValue()),      
   fADCGain(stream.GetADCGain()),
-  fScNWords(stream.GetScNWords()),       
+  fIsUnderflow(stream.fIsUnderflow),
+  fIsOverflow(stream.fIsOverflow),
   fScGeo(stream.GetScGeo()),     
-  fScTS(stream.GetScTS()),       
+  fScNWords(stream.GetScNWords()),       
+  fScTriggerSource(stream.GetScTriggerSource()),         
   fScTriggerNumber(stream.fScTriggerNumber),
   fIsScEventGood(stream.fIsScEventGood),
-  fNConnCh(stream.fNConnCh),
-  fCabledSignal(stream.GetCabledSignal())
+  fIsScHeaderRead(stream.fIsScHeaderRead),
+  fScStartCounter(stream.fScStartCounter),
+  fScEvCounter(stream.fScEvCounter),
+  fIsScalerWord(stream.fIsScalerWord),
+  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),
+  fCurrTDCCh(stream.fCurrTDCCh),
+  fIsADCEventGood(stream.fIsADCEventGood),
+  fIsL0BitSet(stream.fIsL0BitSet),
+  fIsPileUpEvent(stream.fIsPileUpEvent),
+  fIsADDChannel(stream.fIsADDChannel),
+  fADDADCdatum(stream.fADDADCdatum),
+  fIsTDCHeaderRead(stream.fIsTDCHeaderRead),
+  fTDCStartCounter(stream.fTDCStartCounter),
+  fIsZDCTDCHeader(stream.fIsZDCTDCHeader),
+  fIsZDCTDCdatum(stream.fIsZDCTDCdatum),
+  fZDCTDCdatum(stream.fZDCTDCdatum),
+  fIsADDTDCHeader(stream.fIsADDTDCHeader),
+  fIsADDTDCdatum(stream.fIsADDTDCdatum),
+  fADDTDCdatum(stream.fADDTDCdatum)
 {
   // Copy constructor
+  const int kNch = 48;
   for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);    
-  for(Int_t i=0; i<48; i++){
-    for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
+  for(Int_t i=0; i<kNch; i++){
+    for(Int_t j=0; j<5; j++){
+      fMapADC[i][j] = stream.fMapADC[i][j];
+      if(i<32) fScalerMap[i][j] = stream.fMapADC[i][j];
+    }
   }
+  
+  for(Int_t k=0; k<4; k++) fCPTInput[k] = stream.fCPTInput[k];
 }
 
 //_____________________________________________________________________________
@@ -140,12 +249,14 @@ AliZDCRawStream::~AliZDCRawStream()
 void AliZDCRawStream::ReadChMap()
 {
   // Reading channel map
-  //printf("\n\t Reading map from OCDB\n");
+  const int kNch = 48;
+  AliDebug(2,"\t Reading ZDC ADC mapping from OCDB\n");
   AliZDCChMap * chMap = GetChMap();
-  for(Int_t i=0; i<48; i++){
+  //chMap->Print("");
+  for(Int_t i=0; i<kNch; i++){
     fMapADC[i][0] = chMap->GetADCModule(i);
     fMapADC[i][1] = chMap->GetADCChannel(i);
-    fMapADC[i][2] = -1;
+    fMapADC[i][2] = chMap->GetADCSignalCode(i);
     fMapADC[i][3] = chMap->GetDetector(i);
     fMapADC[i][4] = chMap->GetSector(i);
   }
@@ -157,84 +268,106 @@ void AliZDCRawStream::ReadCDHHeader()
 {
   // Reading CDH 
   const AliRawDataHeader* header = fRawReader->GetDataHeader();
-  if(!header) {
-      AliError("\t No CDH in raw data streaming\n");
+  const AliRawDataHeaderV3* headerV3 = fRawReader->GetDataHeaderV3();
+  if(!header && !headerV3) {
+      AliError(" No CDH in raw data streaming");
       fRawReader->AddMajorErrorLog(kCDHError);
       return;
   }
-  else{
-    //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
 
-    fDARCEvBlockLenght = header->fSize;
-    //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
-    
-    //UChar_t message = header->GetAttributes();
+    //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %x\n",fRawReader->GetDataSize());
+
+  UChar_t message = header ? header->GetAttributes() : headerV3->GetAttributes();
     //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
     
-    /*if(message & 0x10){ // COSMIC RUN
-       printf("\t STANDALONE_COSMIC RUN raw data found\n");
+    if((message & 0xf0) == 0x0){ // PHYSICS RUN
+       //printf("\t PHYSICS RUN raw data found\n");
     }
-    else if(message & 0x20){ // PEDESTAL RUN
-       printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
+    else if((message & 0xf0) == 0x10){ // COSMIC RUN
+       //printf("\t STANDALONE_COSMIC RUN raw data found\n");
     }
-    else if(message & 0x30){ // LASER RUN
-       printf("\t STANDALONE_LASER RUN raw data found\n");
-    }*/
-    
-    if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
-      fIsCalib = kTRUE;
+    else if((message & 0xf0) == 0x20){ // PEDESTAL RUN
+       //printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
+    }
+    else if((message & 0xf0) == 0x30){ // LASER RUN
+       //printf("\t STANDALONE_LASER RUN raw data found\n");
+    }
+    else if((message & 0xf0) == 0x40){ // CALIBRATION_CENTRAL RUN
+       //printf("\t CALIBRATION_CENTRAL RUN raw data found\n");
+    }
+    else if((message & 0xf0) == 0x50){ // CALIBRATION_SEMICENTRAL
+       //printf("\t CALIBRATION_SEMICENTRAL RUN raw data found\n");
+    }
+    else if((message & 0xf0) == 0x60){ // CALIBRATION_MB
+       //printf("\t CALIBRATION_MB RUN raw data found\n");
+    }
+    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");
+    }
+
+    fIsCalib = (header ? header->GetL1TriggerMessage() : headerV3->GetL1TriggerMessage()) & 0x1;
+
     //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
     //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);    
     
-    UInt_t status = header->GetStatus();
+/*    UInt_t status = header->GetStatus();
     //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
-    if(status & 0x000f == 0x0001){
-      AliWarning("CDH -> DARC trg0 overlap error\n");
+    if((status & 0x000f) == 0x0001){
+      AliDebug(2,"CDH -> DARC trg0 overlap error");
       fRawReader->AddMajorErrorLog(kDARCError);
     }
-    if(status & 0x000f == 0x0002){
-      AliWarning("CDH -> DARC trg0 missing error\n");
+    if((status & 0x000f) == 0x0002){
+      AliDebug(2,"CDH -> DARC trg0 missing error");
       fRawReader->AddMajorErrorLog(kDARCError);
     }
-    if(status & 0x000f == 0x0004){
-      AliWarning("CDH -> DARC data parity error\n");
+    if((status & 0x000f) == 0x0004){
+      AliDebug(2,"CDH -> DARC data parity error");
       fRawReader->AddMajorErrorLog(kDARCError);
     }
-    if(status & 0x000f == 0x0008){
-      AliWarning("CDH -> DARC ctrl parity error\n");
+    if((status & 0x000f) == 0x0008){
+      AliDebug(2,"CDH -> DARC ctrl parity error");
       fRawReader->AddMajorErrorLog(kDARCError);
     }
     //
-    if(status & 0x00f0 == 0x0010){
-      AliWarning("CDH -> DARC trg unavailable\n");
+    if((status & 0x00f0) == 0x0010){
+      AliDebug(2,"CDH -> DARC trg unavailable");
       fRawReader->AddMajorErrorLog(kDARCError);
     }
-    if(status & 0x00f0 == 0x0020){
-      AliWarning("CDH -> DARC FEE error\n");
+    if((status & 0x00f0) == 0x0020){
+      AliDebug(2,"CDH -> DARC FEE error");
       fRawReader->AddMajorErrorLog(kDARCError);
     }
     //
-    if(status & 0x0f00 == 0x0200){
-      AliWarning("CDH -> DARC L1 time violation\n");
+    if((status & 0x0f00) == 0x0200){
+      AliDebug(2,"CDH -> DARC L1 time violation");
       fRawReader->AddMajorErrorLog(kDARCError);
     }
-    if(status & 0x0f00 == 0x0400){
-      AliWarning("CDH -> DARC L2 time-out\n");
+    if((status & 0x0f00) == 0x0400){
+      AliDebug(2,"CDH -> DARC L2 time-out");
       fRawReader->AddMajorErrorLog(kDARCError);
     }
-    if(status & 0x0f00 == 0x0800){
-      AliWarning("CDH -> DARC prepulse time violation\n");
+    if((status & 0x0f00) == 0x0800){
+      AliDebug(2,"CDH -> DARC prepulse time violation");
       fRawReader->AddMajorErrorLog(kDARCError);
     }
     //
-    if(status & 0xf000 == 0x1000){
-      AliWarning("CDH -> DARC other error\n");
+    if((status & 0xf000) == 0x1000){
+      AliDebug(2,"CDH -> DARC other error");
       fRawReader->AddMajorErrorLog(kDARCError);
     }
-  }
-  //
-  fIsDARCHeader = kTRUE;
+    */
+  
 }
 
 //_____________________________________________________________________________
@@ -244,27 +377,39 @@ Bool_t AliZDCRawStream::Next()
   // Returns kFALSE if there is no digit left
 
   if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
-  fIsChMapping = kFALSE; fIsADCHeader = kFALSE; 
-  fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
-  
+  const int kNch = 48;
+  //
+  fIsHeaderMapping = kFALSE; fIsChMapping = kFALSE; 
+  fIsADCHeader = kFALSE; fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
+  fIsZDCTDCdatum = kFALSE; fIsADDChannel = kFALSE; fIsADDTDCdatum=kFALSE;
+  fIsUnderflow = kFALSE; fIsOverflow = kFALSE; fIsScalerWord = kFALSE;
+  fSector[0] = fSector[1] = -1;
+  for(Int_t kl=0; kl<4; kl++) fCPTInput[kl] = 0;
+
   fEvType = fRawReader->GetType();
-  //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
-  
   if(fPosition==0){
-    //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
-      //ReadEventHeader();
-      ReadCDHHeader();
-    //}
-    fNConnCh=0;
+    ReadCDHHeader();
+    // Needed to read simulated raw data (temporary solution?)
+    if(!fReadCDH) fReadOutCard=1;
+    fCurrentCh=0; fCurrScCh=0;  fCurrTDCCh=0;fNChannelsOn=0;
+    // Ch. debug
+    //printf("\n  AliZDCRawStream::Next() - ev. type %d",fEvType);
   }
+  // Ch. debug
   //printf("\n  AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
   
+  // *** End of ZDC event
+  if(fBuffer == 0xcafefade){
+    //printf("\n  AliZDCRawStream::Next() ***** End of ZDC event *****\n\n");
+    return kFALSE;
+  }
+  
   // -------------------------------------------
   // --- DARC header
   // -------------------------------------------
   // 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;
@@ -277,202 +422,288 @@ 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((fBuffer&0xff000000) == 0xff000000){
-        if(fPosition==(fDataOffset+1)){ 
-          printf("\n\n\t Reading ZDC mapping from StartOfData event\n");
-          fNConnCh=0;  
+    if(fPosition>=fDataOffset){
+      if((fBuffer&0xff000001) == 0xff000001){ // ************** Mapping
+        // 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; fCurrTDCCh=0;     
         }
        else{
-         printf("\n\t End of ZDC StartOfData event\n\n");
-          //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
+         printf(" ------ AliZDCRawStream -> End of ZDC StartOfData event ------\n\n");
+          fSODReading = kFALSE;
          return kFALSE;
        }
       }
-      else if((fBuffer&0x80000000)>>31 == 1){
-        // Mapping identification
-       fADCModule = ((fBuffer & 0x7f000000)>>24);
-       fModType = ((fBuffer & 0xfff00)>>8);
-       fADCNChannels = (fBuffer & 0xff);
+      else if((fBuffer&0xff000002) == 0xff000002){ // ************** Threshold settings
+        fPosition++;
+       return kFALSE; // !!!!!!!!!!!!!!!!!!!!!  For the moment thresholds are not read
+      }
+      else if((fBuffer&0x80000000)>>31 == 1){ // --- Mapping header
+        fIsHeaderMapping = kTRUE;
+       fADCModule = ((fBuffer & 0x7f000000)>>24); // GEO address!!!
+       fModType = ((fBuffer & 0x7ff00)>>8); 
+       fADCNChannels = (fBuffer & 0xff);          // # of channels following the header
        //
-       //printf("\tGEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
+       printf("  ******** GEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
       }
-      else if(fModType==1 && (fBuffer&0x80000000)>>31 == 0){
-        // Channel signal
-       if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
-         fIsChMapping = kTRUE;
-         fADCChannel = ((fBuffer & 0x3fff0000)>>16);
-         fCabledSignal = (fBuffer&0xffff);
-         //
-         //printf("\tADC ch. %d, signal %d\n",fADCChannel,fCabledSignal);
-         //
-         fMapADC[fNConnCh][0] = fADCModule;
-         fMapADC[fNConnCh][1] = fADCChannel;
-         fMapADC[fNConnCh][2] = fCabledSignal;
+      else if((fBuffer&0x80000000)>>31 == 0){ // --- Mapping channel
+       fADCChannel = ((fBuffer & 0x3fff0000)>>16);
+       fCabledSignal = (fBuffer&0xffff);
+        //
+       if(fModType == kV965){ // ******** ADCs ********************************
+          // Channel signal
+         if((fBuffer&0x40000000)>>30==0 && fADCModule<=kLastADCGeo){ // *ZDC* high range chain ADC
+            fIsChMapping = kTRUE;
+           fMapADC[fCurrentCh][0] = fADCModule;
+           fMapADC[fCurrentCh][1] = fADCChannel;
+           fMapADC[fCurrentCh][2] = fCabledSignal;
+           //  - No. of channels on
+           fNChannelsOn++;
+           //
+           // Determining detector and sector
+           // -----------------------------------------
+           //  For the decoding of the following lines 
+           //  look the enum in AliZDCRawStream.h file
+           // -----------------------------------------
+           if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
+             || fCabledSignal==24 || fCabledSignal==48){
+             fMapADC[fCurrentCh][3] = 4; //ZNA
+             //
+             if(fCabledSignal==kZNAC || fCabledSignal==kZNACoot)       fMapADC[fCurrentCh][4]=0;
+             else if(fCabledSignal==kZNA1 || fCabledSignal==kZNA1oot)  fMapADC[fCurrentCh][4]=1;
+             else if(fCabledSignal==kZNA2 || fCabledSignal==kZNA2oot)  fMapADC[fCurrentCh][4]=2;
+             else if(fCabledSignal==kZNA3 || fCabledSignal==kZNA3oot)  fMapADC[fCurrentCh][4]=3;
+             else if(fCabledSignal==kZNA4 || fCabledSignal==kZNA4oot)  fMapADC[fCurrentCh][4]=4;
+             else if(fCabledSignal==kZDCAMon || fCabledSignal==kZDCAMonoot) fMapADC[fCurrentCh][4]=5; //Reference PTM
+           }
+           else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
+             fMapADC[fCurrentCh][3] = 5; //ZPA
+             //
+             if(fCabledSignal==kZPAC || fCabledSignal==kZPACoot)      fMapADC[fCurrentCh][4]=0;
+             else if(fCabledSignal==kZPA1 || fCabledSignal==kZPA1oot) fMapADC[fCurrentCh][4]=1;
+             else if(fCabledSignal==kZPA2 || fCabledSignal==kZPA2oot) fMapADC[fCurrentCh][4]=2;
+             else if(fCabledSignal==kZPA3 || fCabledSignal==kZPA3oot) fMapADC[fCurrentCh][4]=3;
+             else if(fCabledSignal==kZPA4 || fCabledSignal==kZPA4oot) fMapADC[fCurrentCh][4]=4;
+           }
+           else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
+              || fCabledSignal==25 || fCabledSignal==49){
+             fMapADC[fCurrentCh][3] = 1; //ZNC
+             //
+             if(fCabledSignal==kZNCC || fCabledSignal==kZNCCoot)      fMapADC[fCurrentCh][4]=0;
+             else if(fCabledSignal==kZNC1 || fCabledSignal==kZNC1oot) fMapADC[fCurrentCh][4]=1;
+             else if(fCabledSignal==kZNC2 || fCabledSignal==kZNC2oot) fMapADC[fCurrentCh][4]=2;
+             else if(fCabledSignal==kZNC3 || fCabledSignal==kZNC3oot) fMapADC[fCurrentCh][4]=3;
+             else if(fCabledSignal==kZNC4 || fCabledSignal==kZNC4oot) fMapADC[fCurrentCh][4]=4;
+             else if(fCabledSignal==kZDCCMon || fCabledSignal==kZDCCMonoot) fMapADC[fCurrentCh][4]=5; //Reference PTM
+           }
+           else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
+             fMapADC[fCurrentCh][3] = 2; //ZPC
+             //
+             if(fCabledSignal==kZPCC || fCabledSignal==kZPCCoot)   fMapADC[fCurrentCh][4]=0;
+             else if(fCabledSignal==kZPC1 || fCabledSignal==kZPC1oot) fMapADC[fCurrentCh][4]=1;
+             else if(fCabledSignal==kZPC2 || fCabledSignal==kZPC2oot) fMapADC[fCurrentCh][4]=2;
+             else if(fCabledSignal==kZPC3 || fCabledSignal==kZPC3oot) fMapADC[fCurrentCh][4]=3;
+             else if(fCabledSignal==kZPC4 || fCabledSignal==kZPC4oot) fMapADC[fCurrentCh][4]=4;
+           }
+           else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
+             fMapADC[fCurrentCh][3] = 3; // ZEM
+             //
+             if(fCabledSignal==kZEM1 || fCabledSignal==kZEM1oot)      fMapADC[fCurrentCh][4]=1;
+             else if(fCabledSignal==kZEM2 || fCabledSignal==kZEM2oot) fMapADC[fCurrentCh][4]=2;
+           }
+           //Ch. debug
+           //printf("\tADC mod. %d ch. %d signal %d ",fADCModule,fADCChannel,fCabledSignal);
+           //printf("  det. %d sec. %d\n",fMapADC[fCurrentCh][3],fMapADC[fCurrentCh][4]);
+           //
+           fCurrentCh++;
+           //
+         } // high range channels
+        }// ModType=1 (ADC mapping)
+        else if(fModType == kV830){  // ******** VME scaler **************************
+          fIsChMapping = kTRUE;
+         fScalerMap[fCurrScCh][0] = fADCModule;
+         fScalerMap[fCurrScCh][1] = fADCChannel;
+         fScalerMap[fCurrScCh][2] = fCabledSignal;
          //
          // Determining detector and sector
          // -----------------------------------------
          //  For the decoding of the following lines 
          //  look the enum in AliZDCRawStream.h file
          // -----------------------------------------
-         if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
-            || fCabledSignal==24 || fCabledSignal==48){
-           fMapADC[fNConnCh][3] = 4; //ZNA
+         // NOT CONSIDERING OUT OF TIME OR REFERENCE SIGNALS FOR SCALER!!!!!
+         if((fCabledSignal>=2 && fCabledSignal<=6) ||
+            (fCabledSignal>=61 && fCabledSignal<=65)){
+           fScalerMap[fCurrScCh][3] = 4; //ZNA
            //
-           if(fCabledSignal==2 || fCabledSignal==26)       fMapADC[fNConnCh][4]=0;
-           else if(fCabledSignal==3 || fCabledSignal==27)  fMapADC[fNConnCh][4]=1;
-           else if(fCabledSignal==4 || fCabledSignal==28)  fMapADC[fNConnCh][4]=2;
-           else if(fCabledSignal==5 || fCabledSignal==29)  fMapADC[fNConnCh][4]=3;
-           else if(fCabledSignal==6 || fCabledSignal==30)  fMapADC[fNConnCh][4]=4;
-           else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
+           if(fCabledSignal==kZNAC || fCabledSignal==kZNACD)      fScalerMap[fCurrScCh][4]=0;
+           else if(fCabledSignal==kZNA1 || fCabledSignal==kZNA1D) fScalerMap[fCurrScCh][4]=1;
+           else if(fCabledSignal==kZNA2 || fCabledSignal==kZNA2D) fScalerMap[fCurrScCh][4]=2;
+           else if(fCabledSignal==kZNA3 || fCabledSignal==kZNA3D) fScalerMap[fCurrScCh][4]=3;
+           else if(fCabledSignal==kZNA4 || fCabledSignal==kZNA4D) fScalerMap[fCurrScCh][4]=4;
          }
-         else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
-           fMapADC[fNConnCh][3] = 5; //ZPA
+         else if((fCabledSignal>=7 && fCabledSignal<=11) ||
+            (fCabledSignal>=66 && fCabledSignal<=70)){
+           fScalerMap[fCurrScCh][3] = 5; //ZPA
            //
-           if(fCabledSignal==7 || fCabledSignal==31)       fMapADC[fNConnCh][4]=0;
-           else if(fCabledSignal==8 || fCabledSignal==32)  fMapADC[fNConnCh][4]=1;
-           else if(fCabledSignal==9 || fCabledSignal==33)  fMapADC[fNConnCh][4]=2;
-           else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
-           else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
+           if(fCabledSignal==kZPAC || fCabledSignal==kZPACD)      fScalerMap[fCurrScCh][4]=0;
+           else if(fCabledSignal==kZPA1 || fCabledSignal==kZPA1D) fScalerMap[fCurrScCh][4]=1;
+           else if(fCabledSignal==kZPA2 || fCabledSignal==kZPA2D) fScalerMap[fCurrScCh][4]=2;
+           else if(fCabledSignal==kZPA3 || fCabledSignal==kZPA3D) fScalerMap[fCurrScCh][4]=3;
+           else if(fCabledSignal==kZPA4 || fCabledSignal==kZPA4D) fScalerMap[fCurrScCh][4]=4;
          }
-         else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
-            || fCabledSignal==25 || fCabledSignal==49){
-           fMapADC[fNConnCh][3] = 1; //ZNC
+         else if((fCabledSignal>=12 && fCabledSignal<=16) ||
+            (fCabledSignal>=71 && fCabledSignal<=75)){
+           fScalerMap[fCurrScCh][3] = 1; //ZNC
            //
-           if(fCabledSignal==12 || fCabledSignal==36)      fMapADC[fNConnCh][4]=0;
-           else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
-           else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
-           else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
-           else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
-           else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
+           if(fCabledSignal==kZNCC || fCabledSignal==kZNCCD)      fScalerMap[fCurrScCh][4]=0;
+           else if(fCabledSignal==kZNC1 || fCabledSignal==kZNC1D) fScalerMap[fCurrScCh][4]=1;
+           else if(fCabledSignal==kZNC2 || fCabledSignal==kZNC2D) fScalerMap[fCurrScCh][4]=2;
+           else if(fCabledSignal==kZNC3 || fCabledSignal==kZNC3D) fScalerMap[fCurrScCh][4]=3;
+           else if(fCabledSignal==kZNC4 || fCabledSignal==kZNC4D) fScalerMap[fCurrScCh][4]=4;
          }
-         else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
-           fMapADC[fNConnCh][3] = 2; //ZPC
+         else if((fCabledSignal>=17 && fCabledSignal<=21) ||
+            (fCabledSignal>=76 && fCabledSignal<=80)){
+           fScalerMap[fCurrScCh][3] = 2; //ZPC
            //
-           if(fCabledSignal==17 || fCabledSignal==41)      fMapADC[fNConnCh][4]=0;
-           else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
-           else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
-           else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
-           else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
+           if(fCabledSignal==kZPCC || fCabledSignal==kZPCCD) fScalerMap[fCurrScCh][4]=0;
+           else if(fCabledSignal==kZPC1 || fCabledSignal==kZPC1D)  fScalerMap[fCurrScCh][4]=1;
+           else if(fCabledSignal==kZPC2 || fCabledSignal==kZPC2D)  fScalerMap[fCurrScCh][4]=2;
+           else if(fCabledSignal==kZPC3 || fCabledSignal==kZPC3D)  fScalerMap[fCurrScCh][4]=3;
+           else if(fCabledSignal==kZPC4 || fCabledSignal==kZPC4D)  fScalerMap[fCurrScCh][4]=4;
          }
-         else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
-           fMapADC[fNConnCh][3] = 3;
+         else if(fCabledSignal==22 || fCabledSignal==23 ||
+                 fCabledSignal==81 || fCabledSignal==82){
+           fScalerMap[fCurrScCh][3] = 3; // ZEM
            //
-           if(fCabledSignal==22 || fCabledSignal==46)      fMapADC[fNConnCh][4]=1;
-           else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
+           if(fCabledSignal==kZEM1 || fCabledSignal==kZEM1D)      fScalerMap[fCurrScCh][4]=1;
+           else if(fCabledSignal==kZEM2 || fCabledSignal==kZEM2D) fScalerMap[fCurrScCh][4]=2;
          }
-         //
-         //printf("AliZDCRawStream -> datum %d mod. %d ch. %d signal %d, det %d, tow %d\n",
-         //   fNConnCh,fADCModule,fADCChannel,fBuffer&0xffff,fMapADC[fNConnCh][3],fMapADC[fNConnCh][4]);
-         //
-         fNConnCh++;
-         if(fNConnCh>48){
-           // Protection manually set since it returns:
-           // RawData48 mod. 3 ch. 2048 signal 515
-           // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
-           //AliWarning("\t AliZDCRawStream -> ERROR: no. of cabled channels > 48!!!\n");
-           return kTRUE;
-         }
-       }
-      }// ModType=1 (ADC mapping)
+         // Ch debug.
+         /*printf("\t VME scaler mod. %d ch. %d, signal %d",fScalerMap[fCurrScCh][0],fADCChannel,fCabledSignal);
+         if(fCabledSignal!=0 && fCabledSignal!=1) printf("  det. %d sec. %d\n",fScalerMap[fCurrScCh][3],fScalerMap[fCurrScCh][4]);
+         else printf("  Signal void/not connected\n");*/
+         
+          fCurrScCh++;
+        }
+       else if(fModType==KV1290 && fADCModule==kZDCTDCGeo){  // ******** ZDC TDC **************************
+          fIsChMapping = kTRUE;
+         fTDCMap[fCurrTDCCh][0] = fADCModule;
+         fTDCMap[fCurrTDCCh][1] = fADCChannel;
+         fTDCMap[fCurrTDCCh][2] = fCabledSignal;
+          
+         fCurrTDCCh++;
+         
+         // Ch debug.
+         //printf("\tZDC TDC: mod. %d ch. %d, signal %d\n",fADCModule,fADCChannel,fCabledSignal);        
+        }
+       /*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 == kTRGI){ // **** trigger history from trigger card
+         //printf("\t Trigger card ch. %d, signal %d\n",fADCChannel,fCabledSignal);
+        }
+       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){
-      AliError("AliZDCRawStream -> NO deadface after DARC data\n");
-      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){
-      AliError("AliZDCRawStream -> NO deadbeef after DARC global data\n");
+      //AliWarning(" NO deadbeef after DARC global data");
       fRawReader->AddMajorErrorLog(kDARCError);  
+      fPosition++;
+      return kFALSE;
     }
     else{
       fPosition++;
       return kTRUE;
     }
-  }
-
-  // -------------------------------------------
+  } // ------------------------------- End of DARC data
+  
+  // ---------------------------------------------
   // --- ZDC data
-  // --- ADC buffer + scaler
-  // -------------------------------------------
+  // --- 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){
-        //printf("    AliZDCRawStream -> Not valid datum in ADC %d,"
-        //       "position %d in word data buffer\n",fADCModule,fPosition);
+    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;
+        //}
       }
-      else fRawReader->AddMajorErrorLog(kZDCDataError);
-    }
     
-    // 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!\n");
-        fRawReader->AddMajorErrorLog(kZDCDataError);
+      // 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;
+        }
       }
     }
      
-    // Get geo address of current word to determine
-    // if it is a scaler word (geo address == kScalerAddress)
-    // if it is an ADC word (geo address != 8)
-    Int_t kScalerAddress=8;
-    fADCModule = ((fBuffer & 0xf8000000)>>27);
-    if(fADCModule == kScalerAddress){
-      DecodeScaler();
-    }
-    else{//ADC module
-      // *** End of event
-      if(fBuffer == 0xcafefade){
-        //printf("  AliZDCRawStream ->  End of ZDC event!\n");
-      }
+    // Get geo address of current word
+    if(fIsTDCHeaderRead && fIsZDCTDCHeader) fADCModule = kZDCTDCGeo;
+    else if(fIsTDCHeaderRead && fIsADDTDCHeader) fADCModule = kADDTDCGeo;
+    else fADCModule = (Int_t) ((fBuffer & 0xf8000000)>>27);
+    
+    // ************************************ ADC MODULES ************************************
+    if(fADCModule>=kFirstADCGeo && fADCModule<=kLastADCGeo && 
+       !fIsTriggerHistory && !fIsScHeaderRead && !fIsTriggerScaler){
       // *** ADC header
-      else if((fBuffer & 0x07000000) == 0x02000000){
+      if((fBuffer & 0x07000000) == 0x02000000){
         fIsADCHeader = kTRUE;
        fADCNChannels = ((fBuffer & 0x00003f00)>>8);
-       //printf("  AliZDCRawStream -> HEADER: ADC mod.%d has %d ch. \n",fADCModule,fADCNChannels);
+       //printf("  AliZDCRawStream -> ADC HEADER: mod.%d has %d ch. \n",fADCModule,fADCNChannels);
       }
       // *** ADC data word
       else if((fBuffer & 0x07000000) == 0x00000000){
@@ -480,117 +711,273 @@ Bool_t AliZDCRawStream::Next()
         fADCChannel = ((fBuffer & 0x1e0000) >> 17);
         fADCGain = ((fBuffer & 0x10000) >> 16);       
         fADCValue = (fBuffer & 0xfff);  
-       
-       //printf("  AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
-       //  fADCModule,fADCChannel,fADCGain,fADCValue);
-
-       // Valid ADC data (not underflow nor overflow)
-        if(!(fBuffer & 0x1000) && !(fBuffer & 0x2000)){ 
+       //
+       //printf("  AliZDCRawStream -> ADC DATUM: mod. %d ch. %d gain %d value %d\n",
+         //fADCModule,fADCChannel,fADCGain,fADCValue);
        
-         // Checking if the channel map for the ADCs has been provided/read
-         if(fMapADC[0][0]==-1){
-           printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
-           return kFALSE;
-           // Temporary solution (to be changed!!!!)
-           // mapping read from ShuttleInput dir
-           /*char * mapFileName=gSystem->ExpandPathName("$(ALICE_ROOT)/ZDC/ShuttleInput/ZDCChMapping.dat");
-           FILE *file; 
-           Int_t ival[48][6];
-           if((file = fopen(mapFileName,"r")) != NULL){
-             for(Int_t j=0; j<48; j++){
-               for(Int_t k=0; k<6; k++){
-                 fscanf(file,"%d",&ival[j][k]);
-               }
-               fMapADC[j][0] = ival[j][1];
-               fMapADC[j][1] = ival[j][2];
-               fMapADC[j][2] = ival[j][3];
-               fMapADC[j][3] = ival[j][4];
-               fMapADC[j][4] = ival[j][5];
-              }
-           }
-           else{
-               printf("File %s not found\n",mapFileName);
-               return kFALSE;
-           }*/
-         }
-         //
-         /*for(Int_t ci=0; ci<48; ci++){
-           printf("  %d mod. %d ch. %d signal %d\n",ci,fMapADC[ci][0],
-            fMapADC[ci][1], fMapADC[ci][2]);
-         }
-         */
-         
-         // Scan of the map to assign the correct volumes
-         for(Int_t k=0; k<48; k++){
-            if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
-              fSector[0] = fMapADC[k][3];
-              fSector[1] = fMapADC[k][4];
-              break;
-            } 
-         }
-         //
-         //printf("AliZDCRawStream -> ADCmod. %d ADCch %d det %d, sec %d\n",
-         //  fADCModule,fADCChannel,fSector[0],fSector[1]);
-         
-         // Final checks
+       // Checking if the channel map for the ADCs has been provided/read
+       if(fMapADC[0][0]==-1){
+         printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
+         return kFALSE;
+       }
+       //
+       /*for(Int_t ci=0; ci<kNch; ci++){
+         printf("  %d mod %d ch %d det %d sec %d\n",ci,fMapADC[ci][0],
+          fMapADC[ci][1], fMapADC[ci][3], fMapADC[ci][4]);
+       }*/
+               
+       // Scan of the map to assign the correct volumes
+       Int_t foundMapEntry = kFALSE;
+       for(Int_t k=0; k<kNch; k++){
+          if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
+            fSector[0] = fMapADC[k][3];
+            fSector[1] = fMapADC[k][4];
+            foundMapEntry = kTRUE;
+            break;
+          } 
+       }
+       if(foundMapEntry==kFALSE && fEvType==7){
+         AliWarning(Form(" No valid entry in ADC mapping for raw data %d ADCmod. %d ch. %d\n",
+             fPosition,fADCModule,fADCChannel));
+       }
+
+       // Final checks
+       if(foundMapEntry==kTRUE && fEvType==7){
          if(fSector[0]<1 || fSector[0]>5){
-            AliError(Form("     AliZDCRawStream -> No valid detector assignment: %d\n",fSector[0]));
+            AliWarning(Form(" No valid detector assignment: %d",fSector[0]));
             fRawReader->AddMajorErrorLog(kInvalidSector);
          }
          //
          if(fSector[1]<0 || fSector[1]>5){
-            AliError(Form("     AliZDCRawStream -> No valid sector assignment: %d\n",fSector[1]));
+            AliWarning(Form(" No valid sector assignment: %d",fSector[1]));
             fRawReader->AddMajorErrorLog(kInvalidSector);
          }
          //
          if(fADCModule<0 || fADCModule>3){
-            AliError(Form("     AliZDCRawStream -> No valid ADC module: %d\n",fADCModule));
+            AliError(Form(" No valid ADC module: %d",fADCModule));
             fRawReader->AddMajorErrorLog(kInvalidADCModule);
           }
+       }
 
-        }//No underflow nor overflow   
+       // Checking the underflow and overflow bits
+        if(fBuffer & 0x1000)       fIsUnderflow = kTRUE;
+       else if (fBuffer & 0x2000) fIsOverflow = kTRUE; 
+               
       }//ADC data word
       // *** ADC EOB
       else if((fBuffer & 0x07000000) == 0x04000000){
         fIsADCEOB = kTRUE;
-       //printf("  AliZDCRawStream -> EOB --------------------------\n");
+       //printf("  AliZDCRawStream -> ADC EOB --------------------------\n");
+      }
+    }//ADC module
+    // ********************************* ADD ADC *********************************
+    else if(fADCModule == kADDADCGeo){
+      // *** ADC header
+      if((fBuffer & 0x07000000) == 0x02000000){
+        fIsADCHeader = kTRUE;
+       fADCNChannels = ((fBuffer & 0x00003f00)>>8);
+       //printf("  AliZDCRawStream -> ADD ADC HEADER: mod.%d has %d ch. \n",fADCModule,fADCNChannels);
+      }
+      // *** ADC data word
+      else if((fBuffer & 0x07000000) == 0x00000000){
+        fIsADDChannel = kTRUE;
+        fADCChannel = ((fBuffer & 0x1e0000) >> 17);
+        fADCGain = ((fBuffer & 0x10000) >> 16);       
+        fADCValue = (fBuffer & 0xfff);  
+       //
+       //printf("  ADD ADC DATUM -> mod. %d ch. %d gain %d value %d\n",
+       //  fADCModule,fADCChannel,fADCGain,fADCValue);
+      }
+      // *** ADC EOB
+      else if((fBuffer & 0x07000000) == 0x04000000){
+        fIsADCEOB = kTRUE;
+       //printf("  AliZDCRawStream -> ADD ADC EOB --------------------------\n");
+      }
+    }
+    // ********************************* TDC *********************************
+    else if(fADCModule==kTDCFakeGeo && fIsTDCHeaderRead==kFALSE){
+      // *** TDC header
+      fIsTDCHeaderRead = kTRUE;
+      fTDCStartCounter = fPosition;
+      // GEO address from TDC header
+      fADCModule = (Int_t) (fBuffer & 0x1f);
+      if(fADCModule==kZDCTDCGeo){ // *** ZDC TDC
+        fIsZDCTDCHeader = kTRUE;
+        //Ch. debug
+        //printf("  AliZDCRawStream -> ZDC TDC header: mod.%d\n",fADCModule);
+      }
+      else if(fADCModule==kADDTDCGeo){ // *** ADD TDC
+        fIsADDTDCHeader = kTRUE;
+        //Ch. debug
+        //printf("  AliZDCRawStream -> ADD TDC: mod.%d\n",fADCModule);
       }
-     }//ADC module
-        
+    }
+    // ********************************* VME SCALER HEADER *********************************
+    else if(fADCModule == kScalerGeo){
+      if(fBuffer & 0x04000000 && fIsScHeaderRead==kFALSE){ // *** Scaler header
+        fScGeo = (fBuffer & 0xf8000000)>>27;      
+        fScNWords = (fBuffer & 0x00fc0000)>>18;           
+        fScTriggerSource = (fBuffer & 0x00030000)>>16;    
+        fScTriggerNumber = (fBuffer & 0x0000ffff);
+        fIsScHeaderRead = kTRUE; 
+       fScStartCounter = fPosition;
+        //Ch. debug
+        //printf("  AliZDCRawStream -> VME SCALER HEADER: geo %d Nwords %d TrigSource %d TrigNo. %d\n",
+        //   fScGeo,fScNWords,fScTriggerSource,fScTriggerNumber);
+      } 
+      // Commented by C.O. & M.G. (23/09/2011)
+      //else if(!(fBuffer & 0x04000000) && fIsScHeaderRead==kFALSE){
+      //  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=kScalerGeo; 
+      fIsADCDataWord=kFALSE; 
+      fIsScalerWord=kTRUE;
+      fScEvCounter = fBuffer;
+      Int_t nWords = (Int_t) (fScNWords);
+      if(fPosition == fScStartCounter+nWords) fIsScHeaderRead = kFALSE;
+      //Ch. debug
+      //printf("  AliZDCRawStream -> scaler datum %x \n", fScEvCounter);
+    }
+    // ********************************** ZDC TDC DATA **********************************
+    //  ZDC TDC data
+    if(fIsTDCHeaderRead && fIsZDCTDCHeader && fPosition>=fTDCStartCounter+1){ 
+      fIsADCDataWord=kFALSE; fIsScalerWord=kFALSE;
+      if(((fBuffer & 0xf0000000)==0x00000000) && (((fBuffer & 0x08000000) >> 27) == 0)){ // TDC datum
+        fADCChannel = (Int_t) ((fBuffer & 0x3e00000) >> 21);
+       fIsZDCTDCdatum = kTRUE;
+       fZDCTDCdatum = (Int_t) (fBuffer & 0x1fffff);
+        // Ch. debug
+        //printf("  AliZDCRawStream -> ZDC TDC mod. %d ch. %d datum %d\n",fADCModule,fADCChannel,fZDCTDCdatum);
+      }
+      if(((fBuffer & 0xf0000000) == 0x80000000) && ((fBuffer & 0x08000000) >> 27) == 0){
+       // Trailer
+       fIsTDCHeaderRead = kFALSE;
+        // Ch. debug
+        //printf("  AliZDCRawStream -> ZDC TDC global trailer\n");
+      }
+    }
+    // ********************************** ADD TDC DATA **********************************
+    //  ADD TDC data
+    if(fIsTDCHeaderRead && fIsADDTDCHeader && fPosition>=fTDCStartCounter+1){ 
+      fIsADCDataWord=kFALSE; fIsScalerWord=kFALSE;
+      if(((fBuffer & 0xf0000000)==0x00000000) && (((fBuffer & 0x08000000) >> 27) == 0)){ // TDC datum
+        fADCChannel = (Int_t) ((fBuffer & 0x3e00000) >> 21);
+       fIsADDTDCdatum = kTRUE;
+       fADDTDCdatum = (Int_t) (fBuffer & 0x1fffff);
+        // Ch. debug
+        //printf("  AliZDCRawStream -> ADD TDC mod. %d ch. %d datum %d\n",fADCModule,fADCChannel,fADDTDCdatum);
+      }
+      if(((fBuffer & 0xf0000000) == 0x80000000) && ((fBuffer & 0x08000000) >> 27) == 0){
+       // Trailer
+       fIsTDCHeaderRead = kFALSE;
+        // Ch. debug
+        //printf("  AliZDCRawStream -> ADD TDC global trailer\n");
+      }
+    }
+    // ******************************** 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] %x\n", fPosition, fBuffer);
+    }
     
   }
+
   fPosition++;
 
   return kTRUE;
 }
 
-//_____________________________________________________________________________
-void AliZDCRawStream::DecodeScaler()
-{
-  // Decoding scaler event
-  
-  if(!fBuffer & 0x04000000){
-    AliWarning("       AliZDCRawStream -> Scaler header corrupted\n");
-    fIsScEventGood = kFALSE; 
-  }
-  Int_t scNwords = (Int_t) fScNWords;
-  if(fPosition==scNwords && fBuffer != 0x0){
-    AliWarning("       AliZDCRawStream -> Scaler trailer corrupted\n");
-    fIsScEventGood = kFALSE; 
-  }
-  fIsScEventGood = kTRUE;
-  
-  if(fPosition==0){
-    fScNWords = (fBuffer & 0x00fc0000)>>18;       
-    fScGeo = (fBuffer & 0xf8000000)>>27;          
-    fScTS = (fBuffer & 0x00030000)>>16;           
-    fScTriggerNumber = (fBuffer & 0x0000ffff);
-  }
-   
-  fPosition++;
-  
-}
-
 //_____________________________________________________________________________
 AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri) 
 {