LCOV - code coverage report
Current view: top level - EMCAL/EMCALbase - AliEMCALTriggerSTURawStream.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 56 462 12.1 %
Date: 2016-06-14 17:26:59 Functions: 5 22 22.7 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : //_________________________________________________________________________
      17             : //  This class provides access to EMCAL/DCAL STU DDL raw data.
      18             : //--
      19             : //  Author      : Hiroki Yokoyama (Univ. of TSUKUBA / Univ. of Grenoble)
      20             : //  contact     : hiroki.yokoyama@cern.ch
      21             : //  Last Update : 23. Nov. 2015
      22             : //_________________________________________________________________________
      23             : 
      24             : #include "AliEMCALTriggerSTURawStream.h"
      25             : #include "AliRawReader.h"
      26             : #include "AliDAQ.h"
      27             : #include "AliLog.h"
      28             : 
      29             : #include "Riostream.h"
      30             : #include "TBits.h"
      31             : 
      32             : #include <cstdlib>
      33             : #include <iostream>
      34             : 
      35             : 
      36             : using std::cout;
      37             : using std::setw;
      38             : using std::endl;
      39             : using std::dec;
      40          42 : ClassImp(AliEMCALTriggerSTURawStream)
      41             : 
      42             : //_____________________________________________________________________________
      43           0 : AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream() : TObject(),
      44           0 :   fRawReader(0x0)         ,
      45           0 :   fDetector(kEMCAL)       ,
      46           0 :   fGetRawData(0)          ,
      47           0 :   fPayload(V0)            ,
      48           0 :   fNL0GammaPatch(0)       ,
      49           0 :   fL0GammaPatchIndex()    ,
      50           0 :   fNL1GammaPatch()        ,
      51           0 :   fG()                    ,
      52           0 :   fL1GammaThreshold()     ,
      53           0 :   fL1GammaPatchIndex()    ,
      54           0 :   fNL1JetPatch()          ,
      55           0 :   fJ()                    ,
      56           0 :   fL1JetThreshold()       ,
      57           0 :   fL1JetPatchIndex()      ,
      58           0 :   fADC()                  ,
      59           0 :   fV0A(0)                 ,
      60           0 :   fV0C(0)                 ,
      61           0 :   fS()                    ,
      62           0 :   fRho(0)                 ,
      63           0 :   fPatchSize(0)           ,
      64           0 :   fRegionEnable(0)        ,
      65           0 :   fFrameReceived(0)       ,
      66           0 :   fFwVersion(0)     
      67           0 : {
      68           0 :   for(int i=0;i<max_L0GammaPatchIndex;i++) 
      69           0 :     fL0GammaPatchIndex[i]     = 0 ;
      70           0 :   for(int i=0;i<max_L1Gamma;          i++)
      71           0 :     fNL1GammaPatch   [i]      = 0 ;
      72           0 :   for(int i=0;i<max_L1Gamma;          i++)
      73           0 :     fL1GammaThreshold[i]      = 0 ;
      74           0 :   for(int i=0;i<max_L1Gamma;          i++)
      75           0 :   for(int j=0;j<3;                    j++)
      76           0 :     fG[j][i]                  = 0 ;
      77           0 :   for(int i=0;i<max_L1Gamma;          i++)
      78           0 :   for(int j=0;j<max_L1GammaPatchIndex;j++)
      79           0 :     fL1GammaPatchIndex[j][i]  = 0 ;
      80           0 :   for(int i=0;i<max_L1Jet;            i++)
      81           0 :     fNL1JetPatch[i]           = 0 ;
      82           0 :   for(int i=0;i<max_L1Jet;            i++)
      83           0 :     fL1JetThreshold[i]        = 0 ;
      84           0 :   for(int i=0;i<max_L1Jet;            i++)
      85           0 :   for(int j=0;j<3;                    j++)
      86           0 :     fJ[j][i]                  = 0 ;
      87           0 :   for(int i=0;i<max_L1Jet;            i++)
      88           0 :   for(int j=0;j<max_L1JetPatchIndex;  j++)
      89           0 :     fL1JetPatchIndex[j][i]    = 0 ;
      90           0 :   for(int i=0;i<max_nmoduleInTRU;     i++)
      91           0 :   for(int j=0;j<max_nTRU;             j++)
      92           0 :     fADC[j][i]                = 0 ;
      93           0 :   for(int i=0;i<4;                    i++)
      94           0 :     fS[i] = 0 ;
      95           0 : }
      96             : 
      97             : //_____________________________________________________________________________
      98           4 : AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream(AliRawReader* rawReader) : TObject(),
      99           4 :   fRawReader(rawReader)   ,
     100           4 :   fDetector(kEMCAL)       ,
     101           4 :   fGetRawData(0)          ,
     102           4 :   fPayload(V0)            ,
     103           4 :   fNL0GammaPatch(0)       ,
     104           4 :   fL0GammaPatchIndex()    ,
     105           4 :   fNL1GammaPatch()        ,
     106           4 :   fG()                    ,
     107           4 :   fL1GammaThreshold()     ,
     108           4 :   fL1GammaPatchIndex()    ,
     109           4 :   fNL1JetPatch()          ,
     110           4 :   fJ()                    ,
     111           4 :   fL1JetThreshold()       ,
     112           4 :   fL1JetPatchIndex()      ,
     113           4 :   fADC()                  ,
     114           4 :   fV0A(0)                 ,
     115           4 :   fV0C(0)                 ,
     116           4 :   fS()                    ,
     117           4 :   fRho(0)                 ,
     118           4 :   fPatchSize(0)           ,
     119           4 :   fRegionEnable(0)        ,
     120           4 :   fFrameReceived(0)       ,
     121           4 :   fFwVersion(0)     
     122          20 : {
     123       24808 :   for(int i=0;i<max_L0GammaPatchIndex;i++) 
     124       12400 :     fL0GammaPatchIndex[i]     = 0 ;
     125          24 :   for(int i=0;i<max_L1Gamma;          i++)
     126           8 :     fNL1GammaPatch   [i]      = 0 ;
     127          24 :   for(int i=0;i<max_L1Gamma;          i++)
     128           8 :     fL1GammaThreshold[i]      = 0 ;
     129          24 :   for(int i=0;i<max_L1Gamma;          i++)
     130          64 :   for(int j=0;j<3;                    j++)
     131          24 :     fG[j][i]                  = 0 ;
     132          24 :   for(int i=0;i<max_L1Gamma;          i++)
     133       49616 :   for(int j=0;j<max_L1GammaPatchIndex;j++)
     134       24800 :     fL1GammaPatchIndex[j][i]  = 0 ;
     135          24 :   for(int i=0;i<max_L1Jet;            i++)
     136           8 :     fNL1JetPatch[i]           = 0 ;
     137          24 :   for(int i=0;i<max_L1Jet;            i++)
     138           8 :     fL1JetThreshold[i]        = 0 ;
     139          24 :   for(int i=0;i<max_L1Jet;            i++)
     140          64 :   for(int j=0;j<3;                    j++)
     141          24 :     fJ[j][i]                  = 0 ;
     142          24 :   for(int i=0;i<max_L1Jet;            i++)
     143        3216 :   for(int j=0;j<max_L1JetPatchIndex;  j++)
     144        1600 :     fL1JetPatchIndex[j][i]    = 0 ;
     145         776 :   for(int i=0;i<max_nmoduleInTRU;     i++)
     146       25344 :   for(int j=0;j<max_nTRU;             j++)
     147       12288 :     fADC[j][i]                = 0 ;
     148          40 :   for(int i=0;i<4;                    i++)
     149          16 :     fS[i] = 0 ;
     150           8 : }
     151             : 
     152             : //_____________________________________________________________________________
     153             : AliEMCALTriggerSTURawStream::~AliEMCALTriggerSTURawStream()
     154           8 : {
     155             :   // destructor
     156          12 : }
     157             : 
     158             : //_____________________________________________________________________________
     159             : void AliEMCALTriggerSTURawStream::Reset()
     160             : {
     161             :   // Reset
     162           0 :   if (fRawReader) fRawReader->Reset();
     163           0 :   fNL0GammaPatch = 0;
     164           0 :   for(int i=0;i<max_L1Gamma;i++)fNL1GammaPatch[i] = 0 ;
     165           0 :   for(int i=0;i<max_L1Jet;  i++)fNL1JetPatch  [i] = 0 ;
     166           0 : }
     167             : 
     168             : //_____________________________________________________________________________
     169             : Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
     170             : {
     171           0 :   UInt_t word32[max_payload_size]; // 32b words
     172           0 :   for (Int_t i=0; i<max_payload_size; i++) word32[i] = 0;
     173             :   
     174             :   Int_t iword = 0;
     175             :   
     176           0 :   fNL0GammaPatch = 0;
     177           0 :   for(int i=0;i<max_L1Gamma ;i++)    fNL1GammaPatch  [i] = 0 ;
     178           0 :   for(int i=0;i<max_L1Jet   ;i++)    fNL1JetPatch    [i] = 0 ;
     179             :   
     180             :   Int_t eqId    = -1  ;
     181             :   Int_t eqSize  =  0  ;
     182             :   
     183           0 :   UInt_t w32;
     184             :  
     185             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     186             :   // migrate raw data to local array
     187             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     188           0 :   while (fRawReader->ReadNextInt(w32)){
     189           0 :     if (!iword){
     190           0 :       eqId   = fRawReader->GetEquipmentId();
     191           0 :       eqSize = fRawReader->GetEquipmentSize();
     192           0 :     }
     193           0 :     if(iword > max_payload_size -1 )return kFALSE ;
     194           0 :     word32[iword++] = w32;
     195             :     //cout<<dec<<setw(5)<<iword<<" , "<<hex<<setw(10)<<w32<<dec<<setw(10)<<w32<<endl;
     196             :   }
     197             : 
     198             :   Int_t   poffset = 0     ;
     199             :   
     200             :   //payload type selector
     201             :   if(false){}
     202           0 :   else if(iword==(kPayLoadSizeV0                                 )){
     203             :     poffset         = 0         ;
     204           0 :     fPayload        = V0        ; 
     205           0 :     fDetector       = kEMCAL    ;
     206           0 :   }
     207           0 :   else if(iword==(kPayLoadSizeV0       + kPayLoadSizeV0_Raw      )){
     208             :     poffset         = 0         ;
     209           0 :     fPayload        = V0Raw     ; 
     210           0 :     fDetector       = kEMCAL    ;
     211           0 :   }
     212           0 :   else if(iword==(kPayLoadSizeV1                                 )){
     213             :     poffset         = 0         ;
     214           0 :     fPayload        = V1        ; 
     215           0 :     fDetector       = kEMCAL    ;
     216           0 :   }
     217           0 :   else if(iword==(kPayLoadSizeV1       + kPayLoadSizeV1_Raw      )){
     218             :     poffset         = 0         ;
     219           0 :     fPayload        = V1Raw     ; 
     220           0 :     fDetector       = kEMCAL    ;
     221           0 :   }
     222           0 :   else if(iword==(kPayLoadSizeV1_2                               )){
     223             :     poffset         = 0         ;
     224           0 :     fPayload        = V1_2      ;
     225           0 :     fDetector       = kEMCAL    ;
     226           0 :   }
     227           0 :   else if(iword==(kPayLoadSizeV1_2     + kPayLoadSizeV1_2_Raw    )){
     228             :     poffset         = 0         ;
     229           0 :     fPayload        = V1_2Raw   ;
     230           0 :     fDetector       = kEMCAL    ;
     231           0 :   }
     232             :   
     233           0 :   else if(iword==(kPayLoadSizeV2_DCAL                            )){
     234             :     poffset         = 0         ;
     235           0 :     fPayload        = V2DCAL    ;
     236           0 :     fDetector       = kDCAL     ;
     237           0 :   }
     238             : 
     239           0 :   else if(iword==(kPayLoadSizeV2_EMCAL                           )){
     240             :     poffset         = 0         ;
     241           0 :     fPayload        = V2EMCAL   ;
     242           0 :     fDetector       = kEMCAL    ;
     243           0 :   }
     244             : 
     245           0 :   else if(iword==(kPayLoadSizeV2_DCAL  + kPayLoadSizeV2_DCAL_Raw )){
     246             :     poffset         = 0           ;
     247           0 :     fPayload        = V2DCALRaw   ;
     248           0 :     fDetector       = kDCAL       ;
     249           0 :   }
     250             : 
     251           0 :   else if(iword==(kPayLoadSizeV2_EMCAL + kPayLoadSizeV2_EMCAL_Raw)){
     252             :     poffset         = 0           ;
     253           0 :     fPayload        = V2EMCALRaw  ;
     254           0 :     fDetector       = kEMCAL      ;
     255             :   }
     256             :   
     257             :   else{
     258           0 :     AliError(Form("STU payload (eqId: %d, eqSize: %d) doesn't match expected size! %d word32", eqId, eqSize, iword));
     259           0 :     return kFALSE;
     260             :   }
     261           0 :   AliDebug(1, Form("STU (eqId: %d, eqSize: %d) payload size: %d word32", eqId, eqSize, iword));
     262             : 
     263           0 :   switch (fPayload){
     264           0 :     case V0         :    case V1         :    case V2EMCAL    :    case V2DCAL     :  case V1_2    :  {fGetRawData=0;  break;}
     265           0 :     case V0Raw      :    case V1Raw      :    case V2EMCALRaw :    case V2DCALRaw  :  case V1_2Raw :  {fGetRawData=1;  break;}
     266             :     default :    {}
     267             :   }//end case
     268             : 
     269             :   int index         = poffset;
     270             :   int offset        = 0;
     271             :   int nJetThresh    = 0;
     272             :   int nGammaThresh  = 0;
     273             :   
     274             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     275             :   // read setting parameters
     276             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     277           0 :   switch (fPayload){
     278             :     //##################################################
     279             :     case  V0         :
     280             :     case  V0Raw      :
     281             :     {
     282           0 :       fL1JetThreshold   [0] = ((word32[index]>>16) & 0xFFFF);
     283           0 :       fL1GammaThreshold [0] = ( word32[index]      & 0xFFFF);
     284             :       index++ ;
     285             :       offset        = 1 ;
     286             :       nJetThresh    = 1 ;
     287             :       nGammaThresh  = 1 ;
     288           0 :       break;
     289             :     }
     290             :     //##################################################
     291             :     case  V1         :
     292             :     case  V1Raw      :
     293             :     {
     294           0 :       fV0A = ((word32[index]>>16) & 0xFFFF);
     295           0 :       fV0C = ( word32[index]      & 0xFFFF);
     296             :       index++ ;
     297           0 :       for(int i=0;i<3;i++) fG[i][0] = word32[index++] ;
     298           0 :       for(int i=0;i<3;i++) fJ[i][0] = word32[index++] ;
     299           0 :       fRegionEnable  = word32[index++];
     300           0 :       fFrameReceived = word32[index++];
     301           0 :       fFwVersion     = word32[index++];
     302             :       offset = index;
     303             :       
     304           0 :       fL1GammaThreshold [0] = GetThreshold(fG[0][0], fG[1][0], fG[2][0], fV0A, fV0C); 
     305           0 :       fL1JetThreshold   [0] = GetThreshold(fJ[0][0], fJ[1][0], fJ[2][0], fV0A, fV0C);
     306             :       nJetThresh    = 1;
     307             :       nGammaThresh  = 1;
     308           0 :       break;
     309             :     }
     310             :     //##################################################
     311             :     case  V1_2    :
     312             :     case  V1_2Raw :
     313             :     {
     314           0 :       fV0A = ((word32[index]>>16) & 0xFFFF);
     315           0 :       fV0C = ( word32[index]      & 0xFFFF);
     316             :       index++ ;
     317           0 :       for(int i=0;i<3;i++) fG[i][0] = word32[index++] ;
     318           0 :       for(int i=0;i<3;i++) fJ[i][0] = word32[index++] ;
     319           0 :       for(int i=0;i<3;i++) fG[i][1] = word32[index++] ;
     320           0 :       for(int i=0;i<3;i++) fJ[i][1] = word32[index++] ;
     321           0 :       fRegionEnable   = word32[index++] ;
     322           0 :       fFrameReceived  = word32[index++] ;
     323           0 :       fFwVersion      = ( word32[index]        & 0x0000FFFF)  ;
     324           0 :       fPatchSize      = ((word32[index] >> 16) & 0x0000FFFF)  ;
     325           0 :       index++ ;
     326             :       offset = index  ;      
     327             :       
     328           0 :       fL1GammaThreshold [0] = GetThreshold(fG[0][0], fG[1][0], fG[2][0], fV0A, fV0C); 
     329           0 :       fL1JetThreshold   [0] = GetThreshold(fJ[0][0], fJ[1][0], fJ[2][0], fV0A, fV0C);
     330           0 :       fL1GammaThreshold [1] = GetThreshold(fG[0][1], fG[1][1], fG[2][1], fV0A, fV0C); 
     331           0 :       fL1JetThreshold   [1] = GetThreshold(fJ[0][1], fJ[1][1], fJ[2][1], fV0A, fV0C);
     332             :       nJetThresh    = 2;
     333             :       nGammaThresh  = 2;
     334           0 :       break;
     335             :     }
     336             : 
     337             :     //##################################################
     338             :     case  V2EMCAL    :
     339             :     case  V2EMCALRaw :
     340             :     {
     341           0 :       fV0A = ((word32[index]>>16) & 0xFFFF);
     342           0 :       fV0C = ( word32[index]      & 0xFFFF);
     343             :       index++ ;
     344           0 :       for(int i=0;i<3;i++) fG[i][0] = word32[index++] ;
     345           0 :       for(int i=0;i<3;i++) fJ[i][0] = word32[index++] ;
     346           0 :       for(int i=0;i<3;i++) fG[i][1] = word32[index++] ;
     347           0 :       for(int i=0;i<3;i++) fJ[i][1] = word32[index++] ;
     348           0 :       fRho            = word32[index++]        & 0x000FFFFF   ;
     349           0 :       fRegionEnable   = word32[index++] ;
     350           0 :       fFrameReceived  = word32[index++] ;
     351           0 :       fFwVersion      = ( word32[index]        & 0x0000FFFF)  ;
     352           0 :       fPatchSize      = ((word32[index] >> 16) & 0x0000FFFF)  ;
     353           0 :       index++ ;
     354             :       offset = index  ;      
     355             :       
     356           0 :       fL1GammaThreshold [0] = GetThreshold(fG[0][0], fG[1][0], fG[2][0], fV0A, fV0C); 
     357           0 :       fL1JetThreshold   [0] = GetThreshold(fJ[0][0], fJ[1][0], fJ[2][0], fV0A, fV0C);
     358           0 :       fL1GammaThreshold [1] = GetThreshold(fG[0][1], fG[1][1], fG[2][1], fV0A, fV0C); 
     359           0 :       fL1JetThreshold   [1] = GetThreshold(fJ[0][1], fJ[1][1], fJ[2][1], fV0A, fV0C);
     360             :       nJetThresh    = 2;
     361             :       nGammaThresh  = 2;
     362           0 :       break;
     363             :     }
     364             :     //##################################################
     365             :     case  V2DCAL     :
     366             :     case  V2DCALRaw  :
     367             :     {
     368           0 :       fV0A = ((word32[index]>>16) & 0xFFFF);
     369           0 :       fV0C = ( word32[index]      & 0xFFFF);
     370             :       index++ ;
     371           0 :       for(int i=0;i<3;i++) fG[i][0] = word32[index++] ;
     372           0 :       for(int i=0;i<3;i++) fJ[i][0] = word32[index++] ;
     373           0 :       for(int i=0;i<3;i++) fG[i][1] = word32[index++] ;
     374           0 :       for(int i=0;i<3;i++) fJ[i][1] = word32[index++] ;
     375           0 :       for(int i=0;i<4;i++) fS[i]    = word32[index++] ;
     376           0 :       fRho            = word32[index++] ; 
     377           0 :       fRegionEnable   = word32[index++] ;
     378           0 :       fFrameReceived  = word32[index++] ;
     379           0 :       fFwVersion      = ( word32[index]        & 0x0000FFFF)  ;
     380           0 :       fPatchSize      = ((word32[index] >> 16) & 0x0000FFFF)  ;
     381           0 :       index++ ;
     382             :       offset = index  ;
     383             :       
     384           0 :       fL1GammaThreshold [0] = GetThreshold(fG[0][0], fG[1][0], fG[2][0], fV0A, fV0C); 
     385           0 :       fL1JetThreshold   [0] = GetThreshold(fJ[0][0], fJ[1][0], fJ[2][0], fV0A, fV0C);
     386           0 :       fL1GammaThreshold [1] = GetThreshold(fG[0][1], fG[1][1], fG[2][1], fV0A, fV0C); 
     387           0 :       fL1JetThreshold   [1] = GetThreshold(fJ[0][1], fJ[1][1], fJ[2][1], fV0A, fV0C);
     388             :       nGammaThresh  = 2;
     389             :       nJetThresh    = 2;
     390           0 :       break;
     391             :     }
     392             :     default :
     393             :     {
     394           0 :       AliError(Form("STU payload (eqId: %d, eqSize: %d) doesn't match expected size! %d word32", eqId, eqSize, iword));
     395           0 :       return kFALSE;
     396             :     }
     397             :   }//end switch
     398             :   
     399             :   //##############################
     400             :   //firmware version confirmation    
     401             :   if( 
     402           0 :       (fDetector==kEMCAL && ((fFwVersion & 0xf000)!=0xb000) ) ||
     403           0 :       (fDetector==kDCAL  && ((fFwVersion & 0xf000)!=0xd000) ) 
     404             :     ){
     405           0 :     return kFALSE;
     406             :   }
     407             :   //##############################
     408             :   
     409             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     410             :   // start decoding
     411             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     412             : 
     413           0 :   int L1JetIndexOffset   = (fDetector == kEMCAL)? 11 : 
     414           0 :                            (fDetector == kDCAL )? 11 :
     415             :                            0 ;
     416           0 :   int L0GammaIndexOffset = (fDetector == kEMCAL)? 6 * nTRU_EMCAL / 2 : 
     417           0 :                            (fDetector == kDCAL )? 6 * nTRU_DCAL  / 2 :
     418             :                            0 ;
     419           0 :   int L1GammaIndexOffset = (fDetector == kEMCAL)? 8 * nTRU_EMCAL / 2 : 
     420           0 :                            (fDetector == kDCAL )? 8 * nTRU_DCAL  / 2 :
     421             :                            0 ;
     422             : 
     423             :   //Jet patch index
     424           0 :   for (int i = 0; i < nJetThresh; i++) {
     425           0 :     DecodeL1JetPatchIndexes(i, word32, offset);
     426           0 :     offset += L1JetIndexOffset ;
     427             :   }
     428             :   
     429             :   //L0 Gamma index
     430           0 :   DecodeL0GammaPatchIndexes(word32, offset);
     431           0 :   offset += L0GammaIndexOffset  ;
     432             :   
     433             :   //L1 Gamma index
     434           0 :   for (int i = 0; i < nGammaThresh; i++) {
     435           0 :     DecodeL1GammaPatchIndexes(i, word32, offset);  
     436           0 :     offset += L1GammaIndexOffset;
     437             :   }
     438             :  
     439             :   //decide if Raw data included 
     440           0 :   if (fGetRawData == 0){
     441           0 :     return kTRUE;
     442             :   }
     443             :   else{
     444           0 :     DecodeTRUADC(word32, offset);
     445             :     //DCAL : PHOSsubregion data
     446           0 :     if(fDetector == kDCAL){
     447           0 :       offset  += nTRU_DCAL * nMod_DCAL / 2  ;
     448           0 :       DecodePHOSSubregion(word32, offset);
     449           0 :     }
     450           0 :     return kTRUE;
     451             :   }
     452             :   return kFALSE ;
     453           0 : }
     454             : 
     455             : //_____________________________________________________________________________
     456             : void AliEMCALTriggerSTURawStream::DecodeL0GammaPatchIndexes(UInt_t *word32, const int offset)
     457             : {
     458           0 :   if(   fPayload == V0         
     459           0 :     ||  fPayload == V0Raw      
     460           0 :     ||  fPayload == V1         
     461           0 :     ||  fPayload == V1Raw      
     462           0 :     ||  fPayload == V1_2         
     463           0 :     ||  fPayload == V1_2Raw      
     464             :     )
     465             :   {
     466           0 :     unsigned short  truL0indexes[max_nTRU][6];
     467           0 :     Int_t nTRU  = GetnTRU();
     468             : 
     469             :     // extraction from stream
     470           0 :     for (Int_t index=0;index<6;index++)
     471           0 :     for (Int_t tru_num=0;tru_num<nTRU/2;tru_num++){
     472           0 :       truL0indexes[2*tru_num  ][index] = ( word32[offset + index * 16 + tru_num]        & 0xFFFF);
     473           0 :       truL0indexes[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
     474             :     }
     475           0 :     for (Int_t tru_num=0;tru_num<nTRU;tru_num++)
     476           0 :     for (Int_t index=0;index<6;index++)
     477           0 :     for (Int_t bit_num=0;bit_num<12;bit_num++){
     478           0 :       if ((truL0indexes[tru_num][index] & (1 << bit_num))){
     479           0 :         Int_t idx = 12 * index + bit_num;
     480           0 :         fNL0GammaPatch++;
     481           0 :         fL0GammaPatchIndex[fNL0GammaPatch-1] = (((idx << 5) & 0x7E0) | (tru_num & 0x1F));
     482           0 :       }
     483             :     }
     484             :   //V2 : L0 index is filled by 0  => no mean
     485           0 :   }else{
     486             :     return ; 
     487             :   }
     488           0 : }
     489             : 
     490             : //_____________________________________________________________________________
     491             : void AliEMCALTriggerSTURawStream::DecodeL1JetPatchIndexes(const int i, UInt_t *word32, const int offset)
     492             : {
     493           0 :   Int_t nSubregion_eta  = (fDetector == kEMCAL)? nSubregion_eta_EMCAL :
     494           0 :                           (fDetector == kDCAL )? nSubregion_eta_DCAL  :
     495             :                           0 ;
     496           0 :   Int_t nSubregion_phi  = (fDetector == kEMCAL)? nSubregion_phi_EMCAL :
     497           0 :                           (fDetector == kDCAL )? nSubregion_phi_DCAL  :
     498             :                           0 ;
     499             : 
     500           0 :   int jetSize = 2 + fPatchSize ; //0->2x2, 2->4x4
     501           0 :   for (Int_t ix = 0; ix < nSubregion_eta - (jetSize-1) ; ix++){
     502           0 :     UInt_t currentrow = word32[offset + ix];
     503           0 :     for (Int_t iy = 0; iy < nSubregion_phi - (jetSize-1); iy++){
     504           0 :       Int_t bit = (fDetector == kDCAL)? (currentrow & (1 << iy)) : (currentrow & (1<<(nSubregion_phi-jetSize-iy)));
     505             :       //if (currentrow & (1 << iy))
     506           0 :       if (bit){
     507           0 :         fNL1JetPatch[i]                          = fNL1JetPatch[i] + 1;
     508           0 :         fL1JetPatchIndex[fNL1JetPatch[i] - 1][i] = ((ix << 8) & 0xFF00) | (iy & 0xFF);
     509           0 :       }
     510             :     }
     511             :   }
     512             :   return ;
     513           0 : }
     514             : 
     515             : //_____________________________________________________________________________
     516             : void AliEMCALTriggerSTURawStream::DecodeL1GammaPatchIndexes(const int i, UInt_t *word32, const int offset)
     517             : {
     518           0 :   Int_t nTRU  = GetnTRU();
     519             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     520           0 :   if(   fPayload == V0         
     521           0 :     ||  fPayload == V0Raw      
     522           0 :     ||  fPayload == V1         
     523           0 :     ||  fPayload == V1Raw      
     524           0 :     ||  fPayload == V1_2         
     525           0 :     ||  fPayload == V1_2Raw      
     526             :     )
     527             :   {
     528           0 :     unsigned short  truL1indexes0[max_nTRU][8];
     529             :     // extraction from stream
     530           0 :     for (Int_t index  =0; index   <8      ; index++   )
     531           0 :     for (Int_t tru_num=0; tru_num <nTRU/2 ; tru_num++ ){
     532           0 :       truL1indexes0[2*tru_num  ][index] = ( word32[offset + index * 16 + tru_num]        & 0xFFFF);
     533           0 :       truL1indexes0[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
     534             :     }  
     535             :     // interpretation
     536             :     int gammacolnum;
     537             :     short indexcopy;
     538           0 :     for (Int_t tru_num=0; tru_num<nTRU ; tru_num++  )
     539           0 :     for (Int_t index  =0; index  <8    ; index++    )
     540           0 :     for (Int_t bit_num=0; bit_num<12   ; bit_num++  ){
     541           0 :       if ((truL1indexes0[tru_num][index] & (1<<bit_num)) != 0){
     542           0 :         if (index<4){ // Even
     543           0 :           gammacolnum = (2*bit_num  );
     544           0 :           indexcopy   = index;
     545           0 :         }
     546             :         else{         // Odd
     547           0 :           gammacolnum = (2*bit_num+1);
     548           0 :           indexcopy   = index-4;
     549             :         }            
     550           0 :         fNL1GammaPatch[i] = fNL1GammaPatch[i] + 1;
     551           0 :         fL1GammaPatchIndex[fNL1GammaPatch[i] - 1][i] = (
     552           0 :               ((indexcopy   << 10) & 0xC00) 
     553           0 :             | ((gammacolnum <<  5) & 0x3E0) 
     554           0 :             | ( tru_num            &  0x1F)
     555             :             );
     556           0 :       }//if
     557             :     }//for
     558           0 :   }//fPayload  
     559             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     560           0 :   else if(fPayload == V2EMCAL
     561           0 :       ||  fPayload == V2EMCALRaw
     562           0 :       ||  fPayload == V2DCAL
     563           0 :       ||  fPayload == V2DCALRaw
     564             :       )
     565             :   {
     566           0 :     Int_t thirdTRU  = (fDetector == kEMCAL)? 30 : 
     567           0 :                       (fDetector == kDCAL )? 12 :
     568             :                       0 ;
     569             :     const Int_t nModPhi = 12  ;
     570             :     const Int_t nModEta =  8  ;
     571           0 :     unsigned short  truL1indexes1[max_nTRU][nModPhi];
     572           0 :     for (Int_t iphi=0; iphi<nModPhi/2 ; iphi++)
     573           0 :     for (Int_t itru=0; itru<nTRU/2    ; itru++){
     574           0 :       truL1indexes1[2*itru  ][2*iphi   ] = ( word32[offset + iphi * nTRU/2 + itru] >> 0  & 0xFF);
     575           0 :       truL1indexes1[2*itru  ][2*iphi+1 ] = ( word32[offset + iphi * nTRU/2 + itru] >> 8  & 0xFF);
     576           0 :       truL1indexes1[2*itru+1][2*iphi   ] = ( word32[offset + iphi * nTRU/2 + itru] >> 16 & 0xFF);
     577           0 :       truL1indexes1[2*itru+1][2*iphi+1 ] = ( word32[offset + iphi * nTRU/2 + itru] >> 24 & 0xFF);
     578             :     }  
     579           0 :     for (Int_t itru=0; itru<nTRU    ; itru++)
     580           0 :     for (Int_t iphi=0; iphi<nModPhi ; iphi++)
     581           0 :     for (Int_t ieta=0; ieta<nModEta ; ieta++){
     582           0 :       if ( (truL1indexes1[itru][iphi] >> ieta) & 0x1 ){
     583           0 :         fNL1GammaPatch[i] = fNL1GammaPatch[i] + 1;
     584             :         
     585           0 :         short iphi_tmp  = (itru >= thirdTRU)? ( iphi%2 + 2* (int)(iphi/6)       ) : iphi  ;
     586           0 :         short ieta_tmp  = (itru >= thirdTRU)? ( ieta   + 8*((int)(iphi/2) % 3 ) ) : ieta  ;
     587             : 
     588           0 :         fL1GammaPatchIndex[fNL1GammaPatch[i] - 1][i] = (
     589           0 :               ((iphi_tmp  << 10) & 0x7C00) 
     590           0 :             | ((ieta_tmp  <<  5) & 0x03E0) 
     591           0 :             | ((itru      <<  0) & 0x001F)
     592             :             );
     593             :         
     594           0 :       }//if
     595             :     }//for
     596           0 :   }//fPayload  
     597           0 : }
     598             : 
     599             : //_____________________________________________________________________________
     600             : void AliEMCALTriggerSTURawStream::DecodeTRUADC(UInt_t *word32, const int offset)
     601             : {
     602           0 :   Int_t nTRU  = GetnTRU();
     603           0 :   Int_t nMod  = GetnMod();
     604             : 
     605             :   // extraction from stream
     606           0 :   for (Int_t index=0;index<nMod;index++){
     607           0 :     for (Int_t tru_num=0;tru_num<nTRU/2;tru_num++){
     608           0 :       fADC[2*tru_num  ][index] = ( word32[offset + index * nTRU/2 + tru_num]        & 0xFFFF);
     609           0 :       fADC[2*tru_num+1][index] = ((word32[offset + index * nTRU/2 + tru_num] >> 16) & 0xFFFF);
     610             :     }
     611             :   }  
     612             :  
     613           0 :   if(   fPayload == V0Raw         
     614           0 :     ||  fPayload == V1Raw      
     615           0 :     ||  fPayload == V1_2Raw      
     616             :     )
     617             :   {
     618           0 :     for (Int_t tru_num=16;tru_num<32;tru_num++){ // A side
     619           0 :       Int_t v[96];
     620           0 :       for (Int_t index=0;index<96;index++) v[index] = fADC[tru_num][95-index];
     621           0 :       for (Int_t index=0;index<96;index++) fADC[tru_num][index] = v[index];
     622           0 :     }
     623           0 :   }
     624           0 : }
     625             : 
     626             : //_____________________________________________________________________________
     627             : void AliEMCALTriggerSTURawStream::DecodePHOSSubregion(UInt_t *word32, const int offset){
     628           0 :   for (Int_t index=0;index<36;index++){
     629           0 :     fPHOSSubregion[index] = word32[offset + index] & 0xFFFFFFFF  ;
     630             :   }
     631           0 : }
     632             : 
     633             : //_____________________________________________________________________________
     634             : Bool_t AliEMCALTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, Int_t& idx) const
     635             : {
     636             :   // L0 gamma patches sent to STU (original access to L0 patch indexes)
     637             :   
     638           0 :   if (i > fNL0GammaPatch) return kFALSE;
     639             :   
     640           0 :   tru =  fL0GammaPatchIndex[i] & 0x1F;
     641           0 :   idx = (fL0GammaPatchIndex[i] & 0x7E0) >> 5;
     642             :   
     643           0 :   return kTRUE;
     644           0 : }
     645             : 
     646             : //_____________________________________________________________________________
     647             : Bool_t AliEMCALTriggerSTURawStream::GetL1GammaPatch(const Int_t i, const Int_t j, Int_t& tru, Int_t& col, Int_t& row) const
     648             : {
     649             :   // L1 gamma patch indexes
     650           0 :   if (j >= max_L1Gamma || i > fNL1GammaPatch[j]) return kFALSE;
     651           0 :   row = (fL1GammaPatchIndex[i][j] >> 10) & 0x1F ;
     652           0 :   col = (fL1GammaPatchIndex[i][j] >>  5) & 0x1F ;
     653           0 :   tru = (fL1GammaPatchIndex[i][j] >>  0) & 0x1F ;
     654           0 :   return kTRUE;
     655           0 : }
     656             : 
     657             : //_____________________________________________________________________________
     658             : Bool_t AliEMCALTriggerSTURawStream::GetL1JetPatch(const Int_t i, const Int_t j, Int_t& col, Int_t& row) const
     659             : {
     660             :   // L1 jet patch indexes
     661           0 :   if (j >= max_L1Jet || i > fNL1JetPatch[j]) return kFALSE;
     662           0 :   col = (fL1JetPatchIndex[i][j] >> 0) & 0xFF  ;
     663           0 :   row = (fL1JetPatchIndex[i][j] >> 8) & 0xFF  ;
     664           0 :   return kTRUE;
     665           0 : }
     666             : 
     667             : //_____________________________________________________________________________
     668             : void AliEMCALTriggerSTURawStream::GetADC(Int_t iTRU, UInt_t ADC[])
     669             : {
     670             :   // Time sums
     671           0 :   Int_t nMod  = GetnMod() ;
     672           0 :   for (Int_t i=0; i<nMod; i++) ADC[i] = fADC[iTRU][i];
     673           0 : }
     674             : //_____________________________________________________________________________
     675             : void AliEMCALTriggerSTURawStream::GetPHOSSubregion(UInt_t PHOSSubregion[])
     676             : {
     677           0 :   for (Int_t i=0; i<36; i++) PHOSSubregion[i] = fPHOSSubregion[i];
     678           0 : }
     679             : 
     680             : //_____________________________________________________________________________
     681             : void AliEMCALTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
     682             : {
     683             :   // Dump STU payload
     684             :   
     685           0 :   TString op = option;
     686             :   
     687           0 :   printf("V0A:             %d\n"  , fV0A              );
     688           0 :   printf("V0C:             %d\n"  , fV0C              );
     689             : 
     690           0 :   printf("Number of L0:    %d\n"  , fNL0GammaPatch    );
     691           0 :   for (int i = 0; i < max_L1Gamma; i++) {
     692           0 :     for (int j = 0; j < 3         ; j++) {
     693           0 :       printf("G[%d][%d]: %d\n", j, i, fG[j][i]);
     694             :     }
     695           0 :     printf("Gamma threshold[%d]: %d\n", i, fL1GammaThreshold[i]);
     696           0 :     printf("Number of L1-g[%d]: %d\n", i, fNL1GammaPatch[i]);
     697             :   }
     698           0 :   for (int i = 0; i < max_L1Jet; i++) {
     699           0 :     for (int j = 0; j < 3       ; j++) {
     700           0 :       printf("J[%d][%d]: %d\n", j, i, fJ[j][i]);
     701             :     }
     702           0 :     printf("Jet Threshold[%d]:   %d\n", i, fL1JetThreshold[i]);
     703           0 :     printf("Number of L1-j[%d]: %d\n", i, fNL1JetPatch[i]);
     704             :   }
     705             : 
     706           0 :   printf("Jet Rho:         %d\n"  , fRho              );
     707           0 :   printf("RegionEnable:    %8x\n" , fRegionEnable     ); 
     708           0 :   printf("FrameReceived:   %8x\n" , fFrameReceived    );
     709           0 :   printf("FwVersion:       %x\n"  , fFwVersion        );
     710           0 :   printf("PatchSize:       %d\n"  , fPatchSize        );
     711           0 :   printf("RawData:         %d\n"  , fGetRawData       );
     712             : 
     713           0 :   Int_t itru, col, row;
     714             :   // 
     715           0 :   if (op.Contains("L0") || op.Contains("ALL")){
     716           0 :     for (Int_t i = 0;i < fNL0GammaPatch; i++) {
     717           0 :       if (GetL0GammaPatch(i,itru,col)) 
     718           0 :         cout  << dec
     719           0 :               << "> Found L0 gamma in TRU #"  << setw(2) << itru 
     720           0 :               << " at idx: "                  << setw(2) << col 
     721           0 :               << endl;
     722             :     }
     723           0 :   }
     724             :   // 
     725           0 :   if (op.Contains("L1") || op.Contains("ALL")) {
     726           0 :     for (int j = 0; j < max_L1Gamma; j++) {
     727           0 :       for (Int_t i = 0; i < fNL1GammaPatch[j]; i++) {
     728           0 :         if (GetL1GammaPatch(i, j, itru, col, row)) 
     729           0 :           cout  << dec
     730           0 :                 << "> Found L1 gamma "  << j 
     731           0 :                 << " in TRU #"          << setw(2) << itru 
     732           0 :                 << " at: ( col: "       << setw(2) << col 
     733           0 :                 << " , row: "           << setw(2) << row 
     734           0 :                 << " )" << endl;
     735             :       }
     736             :     }
     737           0 :     for (int j = 0; j < max_L1Jet; j++) {
     738           0 :       for (Int_t i = 0; i < fNL1JetPatch[j]; i++) {
     739           0 :         if (GetL1JetPatch(i, j, col, row)) 
     740           0 :           cout  << dec 
     741           0 :                 << "> Found L1 jet "  << j 
     742           0 :                 << " at: ( col: "     << setw(2) << col 
     743           0 :                 << " , row: "         << setw(2) << row 
     744           0 :                 << " )" << endl;
     745             :       }
     746             :     }
     747           0 :   }
     748             :   
     749           0 :   if ((op.Contains("ADC") || op.Contains("ALL")) && fGetRawData) {
     750           0 :     for (Int_t i = 0; i < GetnTRU(); i++) {
     751           0 :       cout << "--------\n";
     752           0 :       cout << "TRU #" << setw(2) << dec << i << ":";
     753           0 :       for (Int_t j = 0;j < GetnMod(); j++) { 
     754             :         //TBits xadc(12); xadc.Set(12,&fADC[i][j]); 
     755           0 :         if ((j % 4) == 0) cout << endl;
     756             :         //cout << setw(2) << j << ": " << xadc << " ";
     757           0 :         printf("%2d: %3x / ",j,fADC[i][j]); 
     758             :       }
     759           0 :       cout << "\n";
     760             :     }
     761           0 :   }
     762           0 : }
     763             : 
     764             : //_____________________________________________________________________________
     765             : UShort_t AliEMCALTriggerSTURawStream::GetThreshold(Short_t A, Short_t B, Short_t C, UShort_t V0A, UShort_t V0C) const
     766             : {
     767             :   // Get threshold 
     768           0 :   ULong64_t v0sum = V0A + V0C;
     769           0 :   ULong64_t sqrV0 = v0sum * v0sum;          
     770           0 :   sqrV0 *= A;
     771           0 :   sqrV0 >>= 32;
     772           0 :   v0sum *= B;
     773           0 :   v0sum >>= 16;
     774           0 :   return (UShort_t)(sqrV0 + v0sum + C);
     775             : }

Generated by: LCOV version 1.11