]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HMPID/AliHMPIDRawStream.h
Move HMPID QA code to PWG1.
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDRawStream.h
index da40cee519f71914daa632169bda99e89464711d..c3283d19d8368b1ac32bb6006aa9c26059046667 100644 (file)
 ///////////////////////////////////////////////////////////////////////////////
 
 #include <TObject.h>
-#include <TRandom.h>
+#include <TH1F.h>
+#include <TH2F.h>
+#include <TFile.h>
 #include "AliHMPIDParam.h"
 #include <AliBitPacking.h>
 #include <AliFstream.h>
 #include "AliHMPIDDigit.h"
 #include "AliDAQ.h"
 #include "AliRawDataHeaderSim.h"
+
 class AliRawReader;
 
 class AliHMPIDRawStream: public TObject {
@@ -34,10 +37,10 @@ class AliHMPIDRawStream: public TObject {
             void     InitVars(Int_t n);
             void     DelVars();
     
-           Int_t GetDDLNumber()  const { return fDDLNumber; }                                                                          // Provide current DDL number
-   static  inline Int_t GetPad(Int_t ddl,Int_t row,Int_t dil,Int_t pad);                                                                 //
-   static  inline Int_t GetNDDL()     { return kNDDL;}                                 //return the number of max # of DDLs
-   static  inline Int_t GetNErrors()  { return kSumErr;}                               //return the number of max # of Error Types
+   static  inline Int_t GetPad(Int_t ddl,Int_t row,Int_t dil,Int_t pad);               //get absolute pad number
+   static  inline Int_t GetFee(Int_t ddl,Int_t row);                                   //get the FEE number
+   static  Int_t GetNDDL()     { return kNDDL;}                                        //return the number of max # of DDLs
+   static  Int_t GetNErrors()  { return kSumErr;}                                      //return the number of max # of Error Types
 
            Int_t   GetNPads()         const { return fNPads;}                         //Get number of pads present in the stream
             Int_t*  GetPadArray()      const { return fPad;}                           //Get pad array from stream decoded
@@ -48,16 +51,17 @@ class AliHMPIDRawStream: public TObject {
            Int_t   PadPcX      ( Int_t ddl,Int_t row,Int_t dil,Int_t pad                            ) {return AliHMPIDParam::A2X(GetPad(ddl,row,dil,pad));}                                                 //pad pc x # 0..79
            Int_t   PadPcY      ( Int_t ddl,Int_t row,Int_t dil,Int_t pad                            ) {return AliHMPIDParam::A2Y(GetPad(ddl,row,dil,pad));}                                                 //pad pc y # 0..47
 
-    static inline  Char_t* GetErrName(Int_t eType);      
+    static inline const Char_t* GetErrName(Int_t eType);      
     inline  Bool_t SetZeroSup (Bool_t isSup);
-    inline  Bool_t GetZeroSup(); 
-    inline  Int_t  GetErrors(Int_t ddl,Int_t eType);                                                                                   //Get errors and occurance
-    inline  Int_t  GetDDLNumber() { return fDDLNumber;} //return the number of DDL actually being decoded
-    inline  UInt_t  GetLDCNumber() { return fLDCNumber;} //return the number of LDC actually being decoded
-    inline  UInt_t  GetTimeStamp() { return fTimeStamp;} //return the time stamp of the event actually being decoded
+    inline  Bool_t GetZeroSup()const
+    inline  Int_t  GetErrors(Int_t ddl,Int_t eType)const;                                                                                   //Get errors and occurance
+    Int_t  GetDDLNumber() const{ return fDDLNumber;} //return the number of DDL actually being decoded
+    UInt_t GetLDCNumber() const{ return fLDCNumber;} //return the number of LDC actually being decoded
+    UInt_t GetTimeStamp() const{ return fTimeStamp;} //return the time stamp of the event actually being decoded
 
-  
-        
+    void   SetTurbo(Bool_t isTurbo){fTurbo=isTurbo;}     // Enable/Disable Turbo
+    Bool_t GetTurbo(){ return fTurbo;}                   // Enable Turbo
+    Bool_t Turbo();                                      // Read HMPID Raw data without error checks
     Bool_t ReadHMPIDRawData();                           // Read HMPID Raw data
     Bool_t ReadSegment(Int_t &cntSegment);               // Read Segment
     Bool_t ReadRow(Int_t &cntRow);                       // Read Row
@@ -72,13 +76,17 @@ class AliHMPIDRawStream: public TObject {
     void   DumpData(Int_t nw);                           // Dump Data
     void   StorePosition();                              //Debug purpose
     
+    Double_t GetDdlDataSize()      { return 4.0*fRawDataSize;} //returns the data size for the DDL which is decoded in Next(); fRawDataSize = Bytes/4  
+    
 //    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
-    inline void    WriteRaw       (TObjArray *pDigLst                             );                                                      //write as raw stream     
-    inline void   WriteRowMarker  (AliFstream *ddl,UInt_t size);
-    inline void   WriteEoE        (AliFstream *ddl,UInt_t row,UInt_t dil,UInt_t wordCnt);  
-    inline void   WriteSegMarker  (AliFstream *ddl,UInt_t row, Int_t nwInSeg);   
+
+    inline void   WriteRaw       (TObjArray *pDigLst                             );                 //write as raw stream     
+    inline void   WriteRowMarker  (AliFstream *ddl,UInt_t size);                                    //write row marker in simulation
+    inline void   WriteEoE        (AliFstream *ddl,UInt_t row,UInt_t dil,UInt_t wordCnt);           //write Enf Of Event word in simulation
+    inline void   WriteSegMarker  (AliFstream *ddl,UInt_t row, Int_t nwInSeg);                      //write Segment Marker word in simulation
+    inline void   Write5FirmwareWords(AliFstream *ddl);                                             //write the firmware control words in simulation
     
 //    inline TClonesArray  ReMap(TClonesArray *pDigIn);
 enum EDirection {kFwd,kBwd};
@@ -129,7 +137,9 @@ enum Ebits {kbit0,kbit1 , kbit2, kbit3, kbit4, kbit5, kbit6, kbit7, kbit8,
     Bool_t           fZeroSup;                                           // set if zero suppression is applied
     Int_t           *fPos;                                               // for debug purposes
     Int_t            fiPos;                                              // counter for debug
-    ClassDef(AliHMPIDRawStream, 2)                                       // base class for reading HMPID raw digits
+    Bool_t           fTurbo;                                             // kTRUE = Turbo decoding is called. DEFAULT: kFALSE = normal decoding is called
+    Int_t            fRawDataSize;
+    ClassDef(AliHMPIDRawStream, 4)                                       // base class for reading HMPID raw digits
 };
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     /*
@@ -197,16 +207,13 @@ Int_t AliHMPIDRawStream::GetPad(Int_t ddl,Int_t row,Int_t dil,Int_t pad)
   // in case the charge from the channels
   // has not been read or invalid arguments
  
-  assert(0<=ddl&&ddl<=13);  
-  assert(1<=row&&row<=24); 
-  assert(1<=dil&&dil<=10);   
-  assert(0<=pad&&pad<=47);  
-  
+  if(ddl<0 || ddl >13 || row<1 || row >25 || dil<1 || dil >10 || pad<0 || pad >47 ) return -1;
   Int_t a2y[6]={3,2,4,1,5,0};     //pady for a given padress (for single DILOGIC chip)
-                                  Int_t ch=ddl/2;
+  Int_t ch=ddl/2;
   Int_t tmp=(24-row)/8;
   Int_t pc=(ddl%2)?5-2*tmp:2*tmp;
-  Int_t px=(dil-1)*8+pad/6;
+  Int_t px=(kNDILOGICAdd+1 - dil)*8-pad/6-1;  //flip according to Paolo (2-9-2008)
 
   tmp=(ddl%2)?row-1:(24-row);
   Int_t py=6*(tmp%8)+a2y[pad%6];
@@ -214,6 +221,24 @@ Int_t AliHMPIDRawStream::GetPad(Int_t ddl,Int_t row,Int_t dil,Int_t pad)
   return AliHMPIDParam::Abs(ch,pc,px,py);
 }//GetPad()
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Int_t AliHMPIDRawStream::GetFee(Int_t ddl,Int_t row)
+{
+   // The method returns the FEE number or -1 
+   // in case of invalid argument(s)
+   if(ddl<0 || ddl >13 || row<1 || row >25  ) return -1;
+   Int_t fee=-1, kLeft=0, kRight=0;
+   if(ddl%2==0) {kLeft=1;kRight=0;}
+   if(ddl%2!=0) {kLeft=0;kRight=1;}
+   if((kLeft==1 && row<=24 && row>=21) || (kRight==1 && row<=4  && row>=1)) fee=0;    //calculation of FEE values based on Giacomos pedestal macro
+   if((kLeft==1 && row<=20 && row>=17) || (kRight==1 && row<=8  && row>=5)) fee=1;
+   if((kLeft==1 && row<=16 && row>=13) || (kRight==1 && row<=12 && row>=9)) fee=2;
+   if((kLeft==1 && row<=12 && row>=9)  || (kRight==1 && row<=16 && row>=13))fee=3;
+   if((kLeft==1 && row<=8  && row>=5)  || (kRight==1 && row<=20 && row>=17))fee=4;
+   if((kLeft==1 && row<=4  && row>=1)  || (kRight==1 && row<=24 && row>=21))fee=5;
+   return fee;
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 void AliHMPIDRawStream::WriteRowMarker(AliFstream *ddl,UInt_t size)
 {
   //Writes the row marker for real data and pedestal into the ddl stream
@@ -257,6 +282,24 @@ void AliHMPIDRawStream::WriteSegMarker(AliFstream *ddl,UInt_t row, Int_t nwInSeg
       //Printf("Segment word created is: %x",w32);
 }      
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
+void AliHMPIDRawStream::Write5FirmwareWords(AliFstream *ddl)
+{
+  //Before each DDL payload 5 words are written: 
+  // 1.) Firmware version,              for sim = 999
+  // 2.) Status and error bits from CD, for sim = 0
+  // 3.) # FEE RESET received         , for sim = 0
+  // 4.) # TTC READY                  , for sim = 0  
+  // 5.) Spare/Reserved               , for sim = 0
+  //Returns:   nothing
+  UInt_t w32=0;
+  AliBitPacking::PackWord((UInt_t)999,w32,0,31); ddl->WriteBuffer((char*)&w32,sizeof(w32));              
+  AliBitPacking::PackWord((UInt_t) 10,w32,0,31); ddl->WriteBuffer((char*)&w32,sizeof(w32));              
+  AliBitPacking::PackWord((UInt_t) 11,w32,0,31); ddl->WriteBuffer((char*)&w32,sizeof(w32));              
+  AliBitPacking::PackWord((UInt_t) 12,w32,0,31); ddl->WriteBuffer((char*)&w32,sizeof(w32));              
+  AliBitPacking::PackWord((UInt_t) 13,w32,0,31); ddl->WriteBuffer((char*)&w32,sizeof(w32));              
+  
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
 Bool_t AliHMPIDRawStream::SetZeroSup (Bool_t isSup)
 {
   //Prevision to turn OFF zero suppression
@@ -266,7 +309,7 @@ Bool_t AliHMPIDRawStream::SetZeroSup (Bool_t isSup)
   return fZeroSup;
 }
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
-Bool_t AliHMPIDRawStream::GetZeroSup()
+Bool_t AliHMPIDRawStream::GetZeroSup()const
 {
   if(fZeroSup==kTRUE) return kTRUE;
   else                return kFALSE;
@@ -318,6 +361,11 @@ void AliHMPIDRawStream::WriteRaw(TObjArray *pDigAll)
     UInt_t w32=0;                 //32 bits data word 
     digcnt=0;
     
+    //added frimware control words
+    Write5FirmwareWords(ddlL);  cntL+=5;
+    Write5FirmwareWords(ddlR);  cntR+=5;
+   
+    
     TClonesArray *pDigCh=(TClonesArray *)pDigAll->At(iCh); //list of digits for current chamber 
    
     for(Int_t iDig=0;iDig<pDigCh->GetEntriesFast();iDig++){//digits loop
@@ -365,7 +413,7 @@ void AliHMPIDRawStream::WriteRaw(TObjArray *pDigAll)
   }//chambers loop
 }//WriteRaw()
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-Int_t AliHMPIDRawStream::GetErrors(Int_t ddl,Int_t eType)
+Int_t AliHMPIDRawStream::GetErrors(Int_t ddl,Int_t eType)const
 {
 // Return the number of errors for a given error tye during raw data reading
 // Arguments: errorType
@@ -375,16 +423,16 @@ Int_t AliHMPIDRawStream::GetErrors(Int_t ddl,Int_t eType)
   else return fNumOfErr[ddl][eType];
 } //GetErrors()     
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-Char_t* AliHMPIDRawStream::GetErrName(Int_t eType)
+const Char_t* AliHMPIDRawStream::GetErrName(Int_t eType)
 {
   // Return the name of the error for a given error tye during raw data reading
   // Arguments: errorType
   // Returns: error or -999 if error Type does not exist
-  Char_t *eName[]={ "kRawDataSizeErr",  "kRowMarkerErr" , "kWrongRowErr" , "kWrongDilogicErr",
+  const Char_t *eName[]={ "kRawDataSizeErr",  "kRowMarkerErr" , "kWrongRowErr" , "kWrongDilogicErr",
                     "kWrongPadErr"   ,  "kEoEFlagErr"   , "kEoESizeErr"  , "kEoEDILOGICErr",
                     "kEoERowErr"     ,  "kBadSegWordErr", "kWrongSegErr" , "kRowMarkerSizeErr",
                     "kPedQZero"      ,  "kSumErr"        };                       
-  Char_t *eNoErr="NotDefinedErrorType";
+  const Char_t *eNoErr="NotDefinedErrorType";
   if(eType<0 || eType>kSumErr) return eNoErr;
   else                         return eName[eType];
 }//GetErrName()