]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALTriggerSTURawStream.cxx
Re-enable trigger calculation removing STU OCDB access. Improve simulation (L0 time...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerSTURawStream.cxx
index 38b96e0d89ba7183ee1eb710df1973e900deb64e..de4b2c430b86c834158a73503eb052146fcb3ce4 100644 (file)
@@ -1,3 +1,4 @@
+
 /**************************************************************************
  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  *                                                                        *
@@ -32,7 +33,8 @@ Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
 
 namespace
 {
-       const Int_t kPayLoadSize = 944;
+       const Int_t kPayLoadSizeOld     = 236;
+       const Int_t kPayLoadSizeNew     = 245;        
 }
 
 ClassImp(AliEMCALTriggerSTURawStream)
@@ -42,13 +44,24 @@ AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream() : TObject(),
 fRawReader(0x0),
 fL1JetThreshold(0),
 fL1GammaThreshold(0),
-fL0GammaPatchIndex(0x0),
-fL1GammaPatchIndex(0x0),
-fL1JetPatchIndex(0x0),
+fL0GammaPatchIndex(),
+fL1GammaPatchIndex(),
+fL1JetPatchIndex(),
 fNL0GammaPatch(0),
 fNL1JetPatch(0),
 fNL1GammaPatch(0),
-fL0(0)
+fGetRawData(0),
+fV0A(0),
+fV0C(0),
+fGA(0),
+fGB(0),
+fGC(0),
+fJA(0),
+fJB(0),
+fJC(0),
+fRegionEnable(0),
+fFrameReceived(0),
+fFwVersion(0)
 {
        //
 }
@@ -58,13 +71,24 @@ AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream(AliRawReader* rawReader
 fRawReader(rawReader),
 fL1JetThreshold(0),
 fL1GammaThreshold(0),
-fL0GammaPatchIndex(0x0),
-fL1GammaPatchIndex(0x0),
-fL1JetPatchIndex(0x0),
+fL0GammaPatchIndex(),
+fL1GammaPatchIndex(),
+fL1JetPatchIndex(),
 fNL0GammaPatch(0),
 fNL1JetPatch(0),
 fNL1GammaPatch(0),
-fL0(0)
+fGetRawData(0),
+fV0A(0),
+fV0C(0),
+fGA(0),
+fGB(0),
+fGC(0),
+fJA(0),
+fJB(0),
+fJC(0),
+fRegionEnable(0),
+fFrameReceived(0),
+fFwVersion(0)
 {
        //
        fRawReader->Reset();
@@ -80,85 +104,131 @@ AliEMCALTriggerSTURawStream::~AliEMCALTriggerSTURawStream()
 //_____________________________________________________________________________
 void AliEMCALTriggerSTURawStream::Reset()
 {
-       //
+       // Reset
+       
        if (fRawReader) fRawReader->Reset();
-
+       
        fNL0GammaPatch = 0;
        fNL1GammaPatch = 0;
        fNL1JetPatch   = 0;     
-       
-       delete fL0GammaPatchIndex; fL0GammaPatchIndex = 0x0;
-       delete fL1GammaPatchIndex; fL1GammaPatchIndex = 0x0;
-       delete fL1JetPatchIndex;   fL1JetPatchIndex   = 0x0;    
 }
 
 //_____________________________________________________________________________
 Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
 {
        // STU data decoder from Olivier Bourrion LPSC CNRS-IN2P3
-       // bourrion@lpsc.in2p3.fr
+       // bourrion_at_lpsc_dot_in2p3_dot_fr
+       
+       UInt_t word32[kPayLoadSizeNew + 1536]; // 32b words
+       for (Int_t i = 0;i < kPayLoadSizeNew + 1536; i++) word32[i] = 0;
        
-       UInt_t word32[1772]; // 32b words
-
        Int_t iword = 0;
        
        fNL0GammaPatch = 0;
        fNL1GammaPatch = 0;
        fNL1JetPatch   = 0;
        
-       delete fL0GammaPatchIndex; fL0GammaPatchIndex = 0x0;
-       delete fL1GammaPatchIndex; fL1GammaPatchIndex = 0x0;
-       delete fL1JetPatchIndex;   fL1JetPatchIndex   = 0x0;
+       Int_t eqId = -1, eqSize = 0;
        
        UInt_t w32;
-       while (fRawReader->ReadNextInt(w32)) word32[iword++] = w32;
        
-       if (iword < kPayLoadSize
+       while (fRawReader->ReadNextInt(w32)
        {
-               AliError(Form("STU raw data size is too small: %d word32 only!", iword));
+               if (!iword)
+               {
+                       eqId   = fRawReader->GetEquipmentId();
+                       eqSize = fRawReader->GetEquipmentSize();
+               }
+               
+               word32[iword++] = w32;
+       }
+       if (iword != kPayLoadSizeOld && iword != kPayLoadSizeNew && iword != (kPayLoadSizeOld + 1536) && iword != (kPayLoadSizeNew + 1536))
+       {
+               AliError(Form("STU payload (eqId: %d, eqSize: %d) doesn't match expected size! %d word32",
+                                         eqId, eqSize, iword));
                return kFALSE;
-       } 
-       else if (iword > kPayLoadSize )
+       }
+       
+       if (AliDebugLevel())
        {
-               AliLog::Message(AliLog::kInfo, "TRU raw data in the STU payload enabled","EMCAL","AliEMCALTriggerSTURawStream","ReadPayLoad()","AliEMCALTriggerSTURawStream.cxx",104);
+               AliInfo(Form("STU (eqId: %d, eqSize: %d) payload size: %d word32",
+                                        eqId, eqSize, iword));
        }
-
-       fL0 = 0;
        
-         fL1JetThreshold = ((word32[0]>>16) & 0xFFF);
-       fL1GammaThreshold =  (word32[0]      & 0xFFF);
+       int offset = 0, jetSize = 2;
        
-       for (Int_t jet_row=0; jet_row<11; jet_row++)
+       switch (iword) 
        {
-               UInt_t currentrow = word32[1+jet_row];
+               case kPayLoadSizeOld:
+               case kPayLoadSizeOld + 1536:
+               {
+                       fL1JetThreshold   = ((word32[0]>>16) & 0xFFFF);
+                       fL1GammaThreshold =  (word32[0]      & 0xFFFF);
+                       
+                       break;
+               }
+               case kPayLoadSizeNew:
+               case kPayLoadSizeNew + 1536:
+               {
+                       fV0A = ((word32[0]>>16) & 0xFFFF);
+                       fV0C =  (word32[0]      & 0xFFFF);
+                       
+                       fGA            = word32[1];
+                       fGB            = word32[2];
+                       fGC            = word32[3];
+                       fJA            = word32[4];
+                       fJB            = word32[5];
+                       fJC            = word32[6];             
+                       fRegionEnable  = word32[7];
+                       fFrameReceived = word32[8];
+                       fFwVersion     = word32[9];
+                       
+                       jetSize += (fFwVersion >> 16);
+                       
+                       fL1JetThreshold   = GetThreshold(fJA, fJB, fJC, fV0A, fV0C);
+                       fL1GammaThreshold = GetThreshold(fGA, fGB, fGC, fV0A, fV0C); 
+                       
+                       offset = 9;
+                       
+                       break;
+               }
+       }
+       
+       ///////////
+       // START DECODING
+       //////////
+
+       for (Int_t jet_row = 0; jet_row < 12 - (jetSize - 1); jet_row++)
+       {
+               UInt_t currentrow = word32[offset + 1 + jet_row];
                
-               for (Int_t jet_col=0; jet_col<15; jet_col++)
+               for (Int_t jet_col = 0; jet_col < 15; jet_col++)
                {
                        if (currentrow & (1 << jet_col))
                        {
                                fNL1JetPatch++;
-                               fL1JetPatchIndex = (UShort_t*)realloc(fL1JetPatchIndex, fNL1JetPatch * sizeof(UShort_t));
-                               if (fL1JetPatchIndex == NULL) {AliError("Error (re)allocating L1 jet patch memory");}
                                
                                fL1JetPatchIndex[fNL1JetPatch-1] = ((jet_row << 8) & 0xFF00) | (jet_col & 0xFF);
                        }
                }
        }
+               
        
        //////////////////////////////////////////////////////////
        // index des L0                                         //
        //////////////////////////////////////////////////////////
-       // FIXME: still not interpreted to be done with Jiri
+       // FIXME: sounds like not valid data
        
-       unsigned short TRU_L0_indexes[32][6];
+       unsigned short truL0indexes[32][6];
        
        // extraction from stream
        for (Int_t index=0;index<6;index++)
        {
                for (Int_t tru_num=0;tru_num<16;tru_num++)
                {
-                       TRU_L0_indexes[2*tru_num  ][index] = ( word32[12+index*16+tru_num]      & 0xFFFF);
-                       TRU_L0_indexes[2*tru_num+1][index] = ((word32[12+index*16+tru_num]>>16) & 0xFFFF);
+                       truL0indexes[2*tru_num  ][index] = ( word32[offset + 12 + index * 16 + tru_num]        & 0xFFFF);
+                       truL0indexes[2*tru_num+1][index] = ((word32[offset + 12 + index * 16 + tru_num] >> 16) & 0xFFFF);
                }
        }
 
@@ -168,21 +238,13 @@ Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
                {
                        for (Int_t bit_num=0;bit_num<12;bit_num++)
                        {
-                               if ((TRU_L0_indexes[tru_num][index] & (1 << bit_num)))
+                               if ((truL0indexes[tru_num][index] & (1 << bit_num)))
                                {
-                                       fL0 = 1;
-
                                        Int_t idx = 12 * index + bit_num;
-                                       
-                                       Int_t col = idx / 3;
-                                       Int_t row = idx % 3;
-                                       
+                                                                               
                                        fNL0GammaPatch++;
-                                       fL0GammaPatchIndex = (UShort_t*)realloc(fL0GammaPatchIndex, fNL0GammaPatch * sizeof(UShort_t));
-                                       
-                                       if (fL0GammaPatchIndex == NULL) {AliError("Error (re)allocating L0 gamma patch memory");}
                                        
-                                       fL0GammaPatchIndex[fNL0GammaPatch-1] = (((row << 10) & 0xC00) | ((col << 5) & 0x3E0) | (tru_num & 0x1F));
+                                       fL0GammaPatchIndex[fNL0GammaPatch-1] = (((idx << 5) & 0x7E0) | (tru_num & 0x1F));
                                }
                        }
                }
@@ -192,15 +254,15 @@ Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
        // index des L1 gamma                                   //
        //////////////////////////////////////////////////////////
        
-       unsigned short TRU_L1_indexes[32][8];
+       unsigned short truL1indexes[32][8];
        
        // extraction from stream
        for (Int_t index=0;index<8;index++)
        {
                for (Int_t tru_num=0;tru_num<16;tru_num++)
                {
-                       TRU_L1_indexes[2*tru_num  ][index] = ( word32[108+index*16+tru_num]      & 0xFFFF);
-                       TRU_L1_indexes[2*tru_num+1][index] = ((word32[108+index*16+tru_num]>>16) & 0xFFFF);
+                       truL1indexes[2*tru_num  ][index] = ( word32[offset + 108 + index * 16 + tru_num]        & 0xFFFF);
+                       truL1indexes[2*tru_num+1][index] = ((word32[offset + 108 + index * 16 + tru_num] >> 16) & 0xFFFF);
                }
        }       
 
@@ -214,7 +276,7 @@ Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
                {
                        for (Int_t bit_num=0; bit_num<12; bit_num++)
                        {
-                               if ((TRU_L1_indexes[tru_num][index] & (1<<bit_num)) != 0)
+                               if ((truL1indexes[tru_num][index] & (1<<bit_num)) != 0)
                                {
                                        if (index<4) // Even
                                        {
@@ -228,9 +290,6 @@ Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
                                        }                                               
                                        
                                        fNL1GammaPatch++;
-                                       fL1GammaPatchIndex = (UShort_t*)realloc(fL1GammaPatchIndex, fNL1GammaPatch * sizeof(UShort_t));
-
-                                       if (fL1GammaPatchIndex == NULL) {AliError("Error (re)allocating L1 gamma patch memory");}
                                        
                                        fL1GammaPatchIndex[fNL1GammaPatch-1] = (((indexcopy << 10) & 0xC00) | ((gammacolnum << 5) & 0x3E0) | (tru_num & 0x1F));
                                }
@@ -242,38 +301,44 @@ Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
        // raw output                                           //
        //////////////////////////////////////////////////////////
        
-       if ( iword <= kPayLoadSize ) return kFALSE;
+       if (iword == kPayLoadSizeOld || iword == kPayLoadSizeNew) 
+       {
+               fGetRawData = 0;
+               return kTRUE;
+       }
+       
+       fGetRawData = 1;
        
        // extraction from stream
        for (Int_t index=0;index<96;index++)
        {
                for (Int_t tru_num=0;tru_num<16;tru_num++)
                {
-                       fADC[2*tru_num  ][index] = ( word32[236+index*16+tru_num]      & 0xFFFF);
-                       fADC[2*tru_num+1][index] = ((word32[236+index*16+tru_num]>>16) & 0xFFFF);
+                       fADC[2*tru_num  ][index] = ( word32[offset + 236 + index * 16 + tru_num]        & 0xFFFF);
+                       fADC[2*tru_num+1][index] = ((word32[offset + 236 + index * 16 + tru_num] >> 16) & 0xFFFF);
                }
        }       
 
        for (Int_t tru_num=16;tru_num<32;tru_num++) // A side
        {
-               for (Int_t index=0;index<96;index++)
-               {
-                       fADC[tru_num][index] = fADC[tru_num][95-index];
-               }
+               Int_t v[96];
+               for (Int_t index=0;index<96;index++) v[index] = fADC[tru_num][95-index];
+               
+               for (Int_t index=0;index<96;index++) fADC[tru_num][index] = v[index];
        }
        
-       return kFALSE;
+       return kTRUE;
 }
 
 //_____________________________________________________________________________
-Bool_t AliEMCALTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, Int_t& col, Int_t& row) const
+Bool_t AliEMCALTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, Int_t& idx) const
 {
-       //
+       // L0 gamma patches sent to STU (original access to L0 patch indexes)
+       
        if (i > fNL0GammaPatch) return kFALSE;
        
        tru =  fL0GammaPatchIndex[i] & 0x1F;
-       col = (fL0GammaPatchIndex[i] & 0x3E0) >> 5;
-       row = (fL0GammaPatchIndex[i] & 0xC00) >> 10;
+       idx = (fL0GammaPatchIndex[i] & 0x7E0) >> 5;
        
        return kTRUE;
 }
@@ -281,7 +346,8 @@ Bool_t AliEMCALTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, I
 //_____________________________________________________________________________
 Bool_t AliEMCALTriggerSTURawStream::GetL1GammaPatch(const Int_t i, Int_t& tru, Int_t& col, Int_t& row) const
 {
-       //
+       // L1 gamma patch indexes
+       
        if (i > fNL1GammaPatch) return kFALSE;
        
        tru =  fL1GammaPatchIndex[i] & 0x1F;
@@ -294,7 +360,8 @@ Bool_t AliEMCALTriggerSTURawStream::GetL1GammaPatch(const Int_t i, Int_t& tru, I
 //_____________________________________________________________________________
 Bool_t AliEMCALTriggerSTURawStream::GetL1JetPatch(const Int_t i, Int_t& col, Int_t& row) const
 {
-       //
+       // L1 jet patch indexes
+       
        if (i > fNL1JetPatch) return kFALSE;
        
        col =  fL1JetPatchIndex[i] & 0xFF;
@@ -306,29 +373,45 @@ Bool_t AliEMCALTriggerSTURawStream::GetL1JetPatch(const Int_t i, Int_t& col, Int
 //_____________________________________________________________________________
 void AliEMCALTriggerSTURawStream::GetADC(Int_t iTRU, UInt_t ADC[])
 {
-       //
+       // Time sums
+       
        for (Int_t i=0; i<96; i++) ADC[i] = fADC[iTRU][i];
 }
 
 //_____________________________________________________________________________
 void AliEMCALTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
 {
-       //
+       // Dump STU payload
+       
        TString op = option;
        
-       cout << "Jet Threshold: " << fL1JetThreshold << " Gamma threshold: " << fL1GammaThreshold << endl;
+       printf("V0A:             %d\n", fV0A);
+       printf("V0C:             %d\n", fV0C);
+       printf("G_A:             %d\n", fGA);
+       printf("G_B:             %d\n", fGB);
+       printf("G_C:             %d\n", fGC);
+       printf("Gamma threshold: %d\n", fL1GammaThreshold);
+       printf("J_A:             %d\n", fJA);
+       printf("J_B:             %d\n", fJB);
+       printf("J_C:             %d\n", fJC);
+       printf("Jet Threshold:   %d\n", fL1JetThreshold);
+       printf("RawData:         %d\n", fGetRawData);
+       printf("RegionEnable:    %8x\n", fRegionEnable); 
+       printf("FrameReceived:   %8x\n", fFrameReceived);
+       printf("FwVersion:       %x\n", fFwVersion);
+       printf("Number of L0:    %d\n", fNL0GammaPatch);
+       printf("Number of L1-g:  %d\n", fNL1GammaPatch);
+       printf("Number of L1-j:  %d\n", fNL1JetPatch);
        
        Int_t itru, col, row;
-
-       Bool_t isOK;
        
        if (op.Contains("L0") || op.Contains("ALL"))
        {
                for (Int_t i=0;i<fNL0GammaPatch;i++)
                {
-                       isOK = GetL0GammaPatch(i,itru,col,row);
-                       if (isOK) cout << "> Found L0 gamma in TRU #" << setw(2) << itru
-                                               <<  " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
+                       
+                       if (GetL0GammaPatch(i,itru,col)) 
+                               cout << "> Found L0 gamma in TRU #" << setw(2) << itru <<  " at idx: " << setw(2) << col << endl;
                }
        }
        
@@ -336,19 +419,19 @@ void AliEMCALTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
        {
                for (Int_t i=0;i<fNL1GammaPatch;i++)
                {
-                       isOK = GetL1GammaPatch(i,itru,col,row);
-                       if (isOK) cout << "> Found L1 gamma in TRU #" << setw(2) << itru
-                                               <<  " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
+                       if (GetL1GammaPatch(i,itru,col,row)) 
+                               cout << "> Found L1 gamma in TRU #" << setw(2) << itru <<  " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
                }
 
                for (Int_t i=0;i<fNL1JetPatch;i++)
                {
-                       isOK = GetL1JetPatch(i,col,row);
-                       if (isOK) cout << "> Found L1 jet at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
+                       if (GetL1JetPatch(i,col,row)) cout << "> Found L1 jet at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
                }
        }
        
-       if (op.Contains("ADC") || op.Contains("ALL"))
+       
+       
+       if ( (op.Contains("ADC") || op.Contains("ALL")) && fGetRawData )
        {
                for (Int_t i=0;i<32;i++)
                {
@@ -365,3 +448,22 @@ void AliEMCALTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
                }
        }
 }
+
+//_____________________________________________________________________________
+UShort_t AliEMCALTriggerSTURawStream::GetThreshold(Short_t A, Short_t B, Short_t C, UShort_t V0A, UShort_t V0C) const
+{
+       // Get threshold 
+  ULong64_t v0sum = V0A + V0C;
+  
+  ULong64_t sqrV0 = v0sum * v0sum;                                     
+                                       
+  sqrV0 *= A;
+                                       
+  sqrV0 >>= 32;
+                               
+  v0sum *= B;
+                                       
+  v0sum >>= 16;
+                                       
+  return (UShort_t)(sqrV0 + v0sum + C);
+}