]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ZDC/AliZDCRawStream.cxx
Update serial number for DE513
[u/mrichter/AliRoot.git] / ZDC / AliZDCRawStream.cxx
index 344a3f41c5c7b5f94367b5340ce1e502836f8c3f..d1379b2de86ebd11f60c36fb24e5f2365e60e19b 100644 (file)
 /* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
-///
-/// This class provides access to ZDC digits in raw data.
-///
-/// It loops over all ZDC digits in the raw data given by the AliRawReader.
-/// The Next method goes to the next digit. If there are no digits left
-/// it returns kFALSE.
-/// Getters provide information about the current digit.
-///
+//                                                                          //
+// This class provides access to ZDC digits in raw data.                    //
+//                                                                          //
+// It loops over all ZDC digits in the raw data given by the AliRawReader.   //
+// The Next method goes to the next digit. If there are no digits left      //
+// it returns kFALSE.                                                       //
+// Getters provide information about the current digit.                     //
+//                                                                          //
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "AliZDCRawStream.h"
 #include "AliRawReader.h"
+#include "AliLog.h"
 
 ClassImp(AliZDCRawStream)
 
@@ -35,31 +36,39 @@ ClassImp(AliZDCRawStream)
 //_____________________________________________________________________________
 AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
   fRawReader(rawReader),
-  fADCValue(-1)
+  fRawADC(0),   
+  fADCModule(0),
+  fADCChannel(-1),      
+  fADCValue(-1),        
+  fADCGain(0),
+  fIsADCDataWord(kFALSE)
 {
-// create an object to read ZDC raw digits
+  // Create an object to read ZDC raw digits
 
-  fSector[0] = 1;
-  fSector[1] = -1;
-  fRawReader->Select(kDDLOffset / 0x100);
+  fRawReader->Select("ZDC");
 }
 
 //_____________________________________________________________________________
 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
   TObject(stream),
-  fADCValue(-1)
+  fRawReader(stream.fRawReader),
+  fRawADC(stream.GetADCRaw()),
+  fADCModule(stream.GetADCModule()),    
+  fADCChannel(stream.GetADCChannel()),  
+  fADCValue(stream.GetADCValue()),      
+  fADCGain(stream.GetADCGain()),
+  fIsADCDataWord(stream.IsADCDataWord()) 
 {
-// copy constructor
-
-  Fatal("AliZDCRawStream", "copy constructor not implemented");
+  // Copy constructor
+  for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);    
+    
 }
 
 //_____________________________________________________________________________
 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream& 
                                              /* stream */)
 {
-// assignment operator
-
+  // Assignment operator
   Fatal("operator =", "assignment operator not implemented");
   return *this;
 }
@@ -67,7 +76,7 @@ AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream&
 //_____________________________________________________________________________
 AliZDCRawStream::~AliZDCRawStream()
 {
-// destructor
+// Destructor
 
 }
 
@@ -75,43 +84,103 @@ AliZDCRawStream::~AliZDCRawStream()
 //_____________________________________________________________________________
 Bool_t AliZDCRawStream::Next()
 {
-// read the next raw digit
-// returns kFALSE if there is no digit left
+  // Read the next raw digit
+  // Returns kFALSE if there is no digit left
 
-  if (!fRawReader->ReadNextInt((UInt_t&) fRawADC)) return kFALSE;
+  if(!fRawReader->ReadNextInt((UInt_t&) fRawADC)) return kFALSE;
   fIsADCDataWord = kFALSE;
-  
-  //ADC Header
-  if (fRawADC & 0x2000000) {
-    printf("This is the ADC Header\n");
-    printf("%d data words will follow \n",2*((fRawADC & 0x3f00) >> 8));
+  //
+  // --- DARC header
+  if((fRawADC == 0xe52b6300) || (fRawADC == 0xe52c0300) ||  (fRawADC == 0xffffffff) ||
+     (fRawADC == 0xdeadface) || (fRawADC == 0xdeadbeef)){
+    //printf("    This is a DARC header!!!\n");
+  }
+  // --- End of data
+  else if(fRawADC == 0xcafefade){
+    //printf("    End of data!\n");
   } 
-  //ADC EOB
-  else if (fRawADC & 0x4000000) {
-    printf("This is the ADC End Of Block\n");
-    printf("This was event number %d\n",(fRawADC & 0xffffff));
-  } else 
-  //ADC Data Words
-  {
-    printf("This is an ADC Data Word\n");
-    printf("Channel %d range %d\n", 
-           (fRawADC & 0x1e0000) >> 17, (fRawADC & 0x10000) >> 16);
-    if(fRawADC & 0x1000) printf("Data = overflow\n");
-    fADCGain = (fRawADC & 0x10000) >> 16;
-    fADCValue = (fRawADC & 0xfff);   
-    fIsADCDataWord = kTRUE;
-
-    Int_t ADCChannel = (fRawADC & 0x1e0000) >> 17;
-    if (ADCChannel >= 0 && ADCChannel <= 4) { 
-      fSector[0] = 1;
-      fSector[1] = ADCChannel;
-    } else if (ADCChannel >= 8 && ADCChannel <= 12) {
-      fSector[0] = 2;
-      fSector[1] = ADCChannel-8;
-    } else if (ADCChannel == 5 || ADCChannel == 13){
-      fSector[0] = 3;
-      fSector[1] = (ADCChannel-5)/8;
+  // --- ADC buffer
+  else{
+    Bool_t firstADCHeader = kTRUE;
+    //
+    if((fRawADC & 0x6000000) == 0x6000000){ // Not valid datum BEFORE valid data!
+      firstADCHeader = kFALSE;
+      //printf("    AliZDCRawStream -> Not valid datum in ADC module!!! %d\n",fADCModule);
     }
-  }
+    else if((fRawADC & 0x4000000) == 0x4000000){ // ADC EOB
+      //printf("    AliZDCRawStream -> ADC %d End Of Block - Event no. %d\n\n",fADCModule, (fRawADC & 0xffffff));
+      fSector[0] = fSector[1] = 99;
+    } 
+    else if((fRawADC & 0x2000000) == 0x2000000){ // ADC Header
+      //printf("  fRawADC %x\n",fRawADC);
+      // Reading the GEO address to determine ADC module
+      fADCModule = (fRawADC & 0xf8000000) >> 27;
+      fADCModule ++;
+      // If the not valid datum isn't followed by the 1st ADC header
+      // the event is corrupted (i.e., 2 gates arrived before trigger)
+      if(fADCModule == 1) firstADCHeader = kTRUE;
+      //if(fADCModule == 1) printf(" fADCModule %d, firstADCHeader %d\n",fADCModule,firstADCHeader);
+      //printf("  AliZDCRawStream -> HEADER: ADC mod. %d contains %d data words \n",fADCModule,((fRawADC & 0x3f00) >> 8));
+    }
+    else{ // ADC data word
+      fIsADCDataWord = kTRUE;
+      //printf(" fRawADC = %x firstADCHeader %d\n",fRawADC,firstADCHeader);
+      //
+      if(!(fRawADC & 0x1000) && !(fRawADC & 0x2000) && firstADCHeader){ // Valid ADC data
+        fADCGain = (fRawADC & 0x10000) >> 16;
+        fADCValue = (fRawADC & 0xfff);   
+        //
+        fADCChannel = (fRawADC & 0x1e0000) >> 17;
+       //
+       // If raw data corresponds to an ADC ch. without physical signal
+       // fsector[0] = fSector[1] = -1
+       for(Int_t i=0; i<2; i++)fSector[i] = -1;
+        //if(fSector[0]!=-1) printf(" \t \t ADC Data Word: ADC ch. %d",fADCChannel);
+       //
+        if(fADCModule==1 || fADCModule==3){  //1st & 3rd ADC modules
+          if(fADCChannel >= 0 && fADCChannel <= 4){ 
+            fSector[0] = 1; // ZN1
+            fSector[1] = fADCChannel;
+          } 
+          else if(fADCChannel >= 8 && fADCChannel <= 12){
+            fSector[0] = 2; // ZP1
+            fSector[1] = fADCChannel-8;
+          } 
+          else if(fADCChannel == 5 || fADCChannel == 13){
+            fSector[0] = 3; // ZEM 1,2
+            fSector[1] = ((fADCChannel-5)/8)+1;
+          }
+        }
+        else if(fADCModule==2 || fADCModule==4){  //2nd & 4rth ADC modules
+          if(fADCChannel >= 0 && fADCChannel <= 4){ 
+            fSector[0] = 4; // ZN2
+          fSector[1] = fADCChannel;
+          } 
+          else if(fADCChannel >= 8 && fADCChannel <= 12){
+            fSector[0] = 5; // ZP2
+            fSector[1] = fADCChannel-8;
+          } 
+          else if(fADCChannel == 5 || fADCChannel == 13){
+            fSector[0] = (fADCChannel-5)*3/8+1; // PM Ref 1,2
+            fSector[1] = 5;
+          }
+        }
+        else{
+          AliWarning("    AliZDCRawStream -> No valid ADC module\n");
+          fRawReader->AddMajorErrorLog(kInvalidADCModule);
+        }
+        //printf("  ADC %d ch %d range %d -> det %d quad %d value %x\n",
+        //   fADCModule, fADCChannel, fADCGain, fSector[0], fSector[1], fADCValue);//Chiara debugging
+      
+      }// Valid ADC data
+      else if(fRawADC & 0x1000){ 
+        //printf("  ADC %d ch %d range %d  overflow\n",fADCModule, (fRawADC & 0x1e0000) >> 17, fADCGain); // Overflow
+      }
+      else if(fRawADC & 0x2000){ 
+        //printf("  ADC %d ch %d range %d  underflow\n",fADCModule, (fRawADC & 0x1e0000) >> 17, fADCGain); // Underflow
+      }
+    }// ADC word
+  }//Not DARC Header
+
   return kTRUE;
 }