LCOV - code coverage report
Current view: top level - PHOS/PHOSbase - AliPHOSTriggerSTURawStream.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 51 206 24.8 %
Date: 2016-06-14 17:26:59 Functions: 6 18 33.3 %

          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 PHOS 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 "AliPHOSTriggerSTURawStream.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             : 
      34             : 
      35             : using std::cout;
      36             : using std::setw;
      37             : using std::endl;
      38          22 : ClassImp(AliPHOSTriggerSTURawStream)
      39             : 
      40             : //_____________________________________________________________________________
      41           0 : AliPHOSTriggerSTURawStream::AliPHOSTriggerSTURawStream() : TObject(),
      42           0 :   fRawReader(0x0)         ,
      43           0 :   fGetRawData(0)          ,
      44           0 :   fPayload(V2PHOS)        ,
      45           0 :   fNL0GammaPatch(0)       ,
      46           0 :   fL0GammaPatchIndex()    ,
      47           0 :   fNL1GammaPatch()        ,
      48           0 :   fG()                    ,
      49           0 :   fL1GammaThreshold()     ,
      50           0 :   fL1GammaPatchIndex()    ,
      51           0 :   fADC()                  ,
      52           0 :   fV0A(0)                 ,
      53           0 :   fV0C(0)                 ,
      54           0 :   fRegionEnable(0)        ,
      55           0 :   fFrameReceived(0)       ,
      56           0 :   fFwVersion(0)     
      57           0 : {
      58           0 :   for(int i=0;i<max_L0GammaPatchIndex;i++) 
      59           0 :     fL0GammaPatchIndex[i]     = 0 ;
      60           0 :   for(int i=0;i<max_L1Gamma;          i++)
      61           0 :     fNL1GammaPatch   [i]      = 0 ;
      62           0 :   for(int i=0;i<max_L1Gamma;          i++)
      63           0 :     fL1GammaThreshold[i]      = 0 ;
      64           0 :   for(int i=0;i<max_L1Gamma;          i++)
      65           0 :   for(int j=0;j<3;                    j++)
      66           0 :     fG[j][i]                  = 0 ;
      67           0 :   for(int i=0;i<max_L1Gamma;          i++)
      68           0 :   for(int j=0;j<max_L1GammaPatchIndex;j++)
      69           0 :     fL1GammaPatchIndex[j][i]  = 0 ;
      70           0 :   for(int i=0;i<max_nmoduleInTRU;     i++)
      71           0 :   for(int j=0;j<max_nTRU;             j++)
      72           0 :     fADC[j][i]                = 0 ;
      73           0 : }
      74             : 
      75             : //_____________________________________________________________________________
      76           4 : AliPHOSTriggerSTURawStream::AliPHOSTriggerSTURawStream(AliRawReader* rawReader) : TObject(),
      77           4 :   fRawReader(rawReader)   ,
      78           4 :   fGetRawData(0)          ,
      79           4 :   fPayload(V2PHOS)        ,
      80           4 :   fNL0GammaPatch(0)       ,
      81           4 :   fL0GammaPatchIndex()    ,
      82           4 :   fNL1GammaPatch()        ,
      83           4 :   fG()                    ,
      84           4 :   fL1GammaThreshold()     ,
      85           4 :   fL1GammaPatchIndex()    ,
      86           4 :   fADC()                  ,
      87           4 :   fV0A(0)                 ,
      88           4 :   fV0C(0)                 ,
      89           4 :   fRegionEnable(0)        ,
      90           4 :   fFrameReceived(0)       ,
      91           4 :   fFwVersion(0)     
      92          20 : {
      93             :   //
      94           4 :   fRawReader->Reset();
      95           4 :   fRawReader->Select("PHOS",20);
      96             :   //
      97       24808 :   for(int i=0;i<max_L0GammaPatchIndex;i++) 
      98       12400 :     fL0GammaPatchIndex[i]     = 0 ;
      99          32 :   for(int i=0;i<max_L1Gamma;          i++)
     100          12 :     fNL1GammaPatch   [i]      = 0 ;
     101          32 :   for(int i=0;i<max_L1Gamma;          i++)
     102          12 :     fL1GammaThreshold[i]      = 0 ;
     103          32 :   for(int i=0;i<max_L1Gamma;          i++)
     104          96 :   for(int j=0;j<3;                    j++)
     105          36 :     fG[j][i]                  = 0 ;
     106          32 :   for(int i=0;i<max_L1Gamma;          i++)
     107       74424 :   for(int j=0;j<max_L1GammaPatchIndex;j++)
     108       37200 :     fL1GammaPatchIndex[j][i]  = 0 ;
     109         904 :   for(int i=0;i<max_nmoduleInTRU;     i++)
     110       25984 :   for(int j=0;j<max_nTRU;             j++)
     111       12544 :     fADC[j][i]                = 0 ;
     112           8 : }
     113             : 
     114             : //_____________________________________________________________________________
     115             : AliPHOSTriggerSTURawStream::~AliPHOSTriggerSTURawStream()
     116           8 : {
     117             :   // destructor
     118          12 : }
     119             : 
     120             : //_____________________________________________________________________________
     121             : void AliPHOSTriggerSTURawStream::Reset()
     122             : {
     123             :   // Reset
     124           0 :   if (fRawReader) fRawReader->Reset();
     125           0 :   fNL0GammaPatch = 0;
     126           0 :   for(int i=0;i<max_L1Gamma;i++)fNL1GammaPatch[i] = 0 ;
     127           0 : }
     128             : 
     129             : //_____________________________________________________________________________
     130             : Bool_t AliPHOSTriggerSTURawStream::ReadPayLoad()
     131             : {
     132           8 :   UInt_t word32[max_payload_size]; // 32b words
     133       16016 :   for (Int_t i=0; i<max_payload_size; i++) 
     134        8004 :     word32[i] = 0;
     135             :   
     136             :   Int_t iword = 0;
     137             :   
     138           4 :   fNL0GammaPatch = 0;
     139          32 :   for(int i=0;i<max_L1Gamma;i++)
     140          12 :     fNL1GammaPatch  [i] = 0 ;
     141             :   
     142             :   Int_t eqId    = -1  ;
     143             :   Int_t eqSize  =  0  ;
     144             :   
     145           4 :   UInt_t w32;
     146             :  
     147             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     148             :   // migrate raw data to local array
     149             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     150           8 :   while (fRawReader->ReadNextInt(w32)){
     151           0 :     if (!iword){
     152           0 :       eqId   = fRawReader->GetEquipmentId();
     153           0 :       eqSize = fRawReader->GetEquipmentSize();
     154           0 :     }
     155           0 :     word32[iword++] = w32;
     156             :   }
     157             : 
     158             :   //payload type selector
     159             :   if(false){}
     160           4 :   else if(iword==(kPayLoadSizeV2_PHOS                            )){fPayload = V2PHOS     ;}
     161           4 :   else if(iword==(kPayLoadSizeV2_PHOS  + kPayLoadSizeV2_PHOS_Raw )){fPayload = V2PHOSRaw  ;}
     162             :   else{
     163           4 :     AliError(Form("STU payload (eqId: %d, eqSize: %d) doesn't match expected size! %d word32", eqId, eqSize, iword));
     164           4 :     return kFALSE;
     165             :   }
     166           0 :   AliDebug(1, Form("STU (eqId: %d, eqSize: %d) payload size: %d word32", eqId, eqSize, iword));
     167             : 
     168           0 :   switch (fPayload){
     169           0 :     case V2PHOS     :    {fGetRawData=0;  break;}
     170           0 :     case V2PHOSRaw  :    {fGetRawData=1;  break;}
     171             :     default :    {}
     172             :   }//end case
     173             : 
     174             :   int offset        = 0;
     175             :   int nGammaThresh  = 0;
     176             :   
     177             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     178             :   // read setting parameters
     179             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     180           0 :   switch (fPayload){
     181             :     //##################################################
     182             :     case  V2PHOS     :
     183             :     case  V2PHOSRaw  :
     184             :     {
     185             :       int index = 0 ;
     186           0 :       fV0A = ((word32[index]>>16) & 0xFFFF);
     187           0 :       fV0C = ( word32[index]      & 0xFFFF);
     188             :       index++ ;
     189           0 :       for(int i=0;i<3;i++) fG[i][0] = word32[index++] ;
     190           0 :       for(int i=0;i<3;i++) fG[i][1] = word32[index++] ;
     191           0 :       for(int i=0;i<3;i++) fG[i][2] = word32[index++] ;
     192           0 :       fRegionEnable   = word32[index++] ;
     193           0 :       fFrameReceived  = word32[index++] ;
     194           0 :       fFwVersion      = word32[index++] ;
     195             :       offset = index  ;
     196             :       
     197           0 :       fL1GammaThreshold [0] = GetThreshold(fG[0][0], fG[1][0], fG[2][0], fV0A, fV0C); 
     198           0 :       fL1GammaThreshold [1] = GetThreshold(fG[0][1], fG[1][1], fG[2][1], fV0A, fV0C); 
     199           0 :       fL1GammaThreshold [2] = GetThreshold(fG[0][2], fG[1][2], fG[2][2], fV0A, fV0C); 
     200             :       nGammaThresh  = 3;
     201             :       break;
     202             :     }
     203             :     default :
     204             :     {
     205           0 :       AliError(Form("STU payload (eqId: %d, eqSize: %d) doesn't match expected size! %d word32", eqId, eqSize, iword));
     206           0 :       return kFALSE;
     207             :     }
     208             :   }//end switch
     209             :   
     210             :   
     211             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     212             :   // start decoding
     213             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     214             : 
     215             :   int L0GammaIndexOffset = 6 * nTRU_PHOS  / 2 ;
     216             :   int L1GammaIndexOffset = 8 * nTRU_PHOS  / 2 ;
     217             : 
     218             :   //L0 Gamma index
     219           0 :   DecodeL0GammaPatchIndexes(word32, offset);
     220           0 :   offset += L0GammaIndexOffset  ;
     221             :  
     222             :   //L1 Gamma index
     223           0 :   for (int i = 0; i < nGammaThresh; i++) {
     224           0 :     DecodeL1GammaPatchIndexes(i, word32, offset);  
     225           0 :     offset += L1GammaIndexOffset;
     226             :   }
     227             :  
     228             :   //decide if Raw data included 
     229           0 :   if (fGetRawData == 0){
     230           0 :     return kTRUE;
     231             :   }
     232             :   else{
     233           0 :     DecodeTRUADC(word32, offset);
     234           0 :     return kTRUE;
     235             :   }
     236             :   return kFALSE ;
     237           4 : }
     238             : 
     239             : //_____________________________________________________________________________
     240             : void AliPHOSTriggerSTURawStream::DecodeL0GammaPatchIndexes(UInt_t *word32, const int offset)
     241             : {
     242           0 :   return ; 
     243             : }
     244             : 
     245             : //_____________________________________________________________________________
     246             : void AliPHOSTriggerSTURawStream::DecodeL1GammaPatchIndexes(const int i, UInt_t *word32, const int offset)
     247             : {
     248           0 :   Int_t nTRU  = GetnTRU();
     249             :   //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     250           0 :   if(     fPayload == V2PHOS
     251           0 :       ||  fPayload == V2PHOSRaw
     252             :       )
     253             :   {
     254             :     const Int_t nModPhi =  8   ;
     255             :     const Int_t nModEta =  14  ;
     256           0 :     unsigned short  truL1indexes2[max_nTRU][nModPhi];
     257           0 :     for (Int_t iphi=0; iphi<nModPhi   ; iphi++)
     258           0 :     for (Int_t itru=0; itru<nTRU/2    ; itru++){
     259           0 :       truL1indexes2[2*itru  ][iphi ] = ( word32[offset + iphi * nTRU/2 + itru] >> 0  & 0x3FFF);
     260           0 :       truL1indexes2[2*itru+1][iphi ] = ( word32[offset + iphi * nTRU/2 + itru] >> 16 & 0x3FFF);
     261             :     }  
     262           0 :     for (Int_t itru=0; itru<nTRU    ; itru++)
     263           0 :     for (Int_t iphi=0; iphi<nModPhi ; iphi++)
     264           0 :     for (Int_t ieta=0; ieta<nModEta ; ieta++){
     265           0 :       if ( (truL1indexes2[itru][iphi] >> ieta) & 0x1 ){
     266           0 :         fNL1GammaPatch[i] = fNL1GammaPatch[i] + 1;
     267             :         
     268           0 :         short iphi_tmp  = iphi  ;
     269           0 :         short ieta_tmp  = ieta  ;
     270             : 
     271           0 :         fL1GammaPatchIndex[fNL1GammaPatch[i] - 1][i] = (
     272           0 :               ((iphi_tmp  << 10) & 0x7C00) 
     273           0 :             | ((ieta_tmp  <<  5) & 0x03E0) 
     274           0 :             | ((itru      <<  0) & 0x001F)
     275             :             );
     276             :         
     277           0 :       }//if
     278             :     }//for
     279           0 :   }//fPayload  
     280           0 : }
     281             : 
     282             : //_____________________________________________________________________________
     283             : void AliPHOSTriggerSTURawStream::DecodeTRUADC(UInt_t *word32, const int offset)
     284             : {
     285           0 :   Int_t nTRU  = GetnTRU();
     286           0 :   Int_t nMod  = GetnMod();
     287             : 
     288             :   // extraction from stream
     289           0 :   for (Int_t index=0;index<nMod;index++){
     290           0 :     for (Int_t tru_num=0;tru_num<nTRU/2;tru_num++){
     291           0 :       fADC[2*tru_num  ][index] = ( word32[offset + index * nTRU/2 + tru_num]        & 0xFFFF);
     292           0 :       fADC[2*tru_num+1][index] = ((word32[offset + index * nTRU/2 + tru_num] >> 16) & 0xFFFF);
     293             :     }
     294             :   }  
     295           0 : }
     296             : 
     297             : //_____________________________________________________________________________
     298             : Bool_t AliPHOSTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, Int_t& idx) const
     299             : {
     300             :   // L0 gamma patches sent to STU (original access to L0 patch indexes)
     301             :   
     302           0 :   if (i > fNL0GammaPatch) return kFALSE;
     303             :   
     304           0 :   tru =  fL0GammaPatchIndex[i] & 0x1F;
     305           0 :   idx = (fL0GammaPatchIndex[i] & 0x7E0) >> 5;
     306             :   
     307           0 :   return kTRUE;
     308           0 : }
     309             : 
     310             : //_____________________________________________________________________________
     311             : Bool_t AliPHOSTriggerSTURawStream::GetL1GammaPatch(const Int_t i, const Int_t j, Int_t& tru, Int_t& col, Int_t& row) const
     312             : {
     313             :   // L1 gamma patch indexes
     314           0 :   if (j >= max_L1Gamma || i > fNL1GammaPatch[j]) return kFALSE;
     315           0 :   row = (fL1GammaPatchIndex[i][j] >> 10) & 0x1F ;
     316           0 :   col = (fL1GammaPatchIndex[i][j] >>  5) & 0x1F ;
     317           0 :   tru = (fL1GammaPatchIndex[i][j] >>  0) & 0x1F ;
     318           0 :   return kTRUE;
     319           0 : }
     320             : 
     321             : //_____________________________________________________________________________
     322             : void AliPHOSTriggerSTURawStream::GetADC(Int_t iTRU, UInt_t ADC[])
     323             : {
     324             :   // Time sums
     325           0 :   Int_t nMod  = GetnMod() ;
     326           0 :   for (Int_t i=0; i<nMod; i++) ADC[i] = fADC[iTRU][i];
     327           0 : }
     328             : 
     329             : //_____________________________________________________________________________
     330             : void AliPHOSTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
     331             : {
     332             :   // Dump STU payload
     333             :   
     334           0 :   TString op = option;
     335             :   
     336           0 :   printf("V0A:             %d\n"  , fV0A              );
     337           0 :   printf("V0C:             %d\n"  , fV0C              );
     338             : 
     339           0 :   printf("Number of L0:    %d\n"  , fNL0GammaPatch    );
     340           0 :   for (int i = 0; i < max_L1Gamma; i++) {
     341           0 :     for (int j = 0; j < 3         ; j++) {
     342           0 :       printf("G[%d][%d]: %d\n", j, i, fG[j][i]);
     343             :     }
     344           0 :     printf("Gamma threshold[%d]: %d\n", i, fL1GammaThreshold[i]);
     345           0 :     printf("Number of L1-g[%d]: %d\n", i, fNL1GammaPatch[i]);
     346             :   }
     347             : 
     348           0 :   printf("RegionEnable:    %8x\n" , fRegionEnable     ); 
     349           0 :   printf("FrameReceived:   %8x\n" , fFrameReceived    );
     350           0 :   printf("FwVersion:       %x\n"  , fFwVersion        );
     351           0 :   printf("RawData:         %d\n"  , fGetRawData       );
     352             : 
     353           0 :   Int_t itru, col, row;
     354             :   // 
     355           0 :   if (op.Contains("L0") || op.Contains("ALL")){
     356           0 :     for (Int_t i = 0;i < fNL0GammaPatch; i++) {
     357           0 :       if (GetL0GammaPatch(i,itru,col)) 
     358           0 :         cout << "> Found L0 gamma in TRU #" << setw(2) << itru <<  " at idx: " << setw(2) << col << endl;
     359             :     }
     360           0 :   }
     361             :   // 
     362           0 :   if (op.Contains("L1") || op.Contains("ALL")) {
     363           0 :     for (int j = 0; j < max_L1Gamma; j++) {
     364           0 :       for (Int_t i = 0; i < fNL1GammaPatch[j]; i++) {
     365           0 :         if (GetL1GammaPatch(i, j, itru, col, row)) 
     366           0 :           cout << "> Found L1 gamma " << j << " in TRU #" << setw(2) << itru <<  " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
     367             :       }
     368             :     }
     369           0 :   }
     370             :   
     371           0 :   if ((op.Contains("ADC") || op.Contains("ALL")) && fGetRawData) {
     372           0 :     for (Int_t i = 0; i < GetnTRU(); i++) {
     373           0 :       cout << "--------\n";
     374           0 :       cout << "TRU #" << setw(2) << i << ":";
     375           0 :       for (Int_t j = 0;j < GetnMod(); j++) { 
     376             :         //TBits xadc(12); xadc.Set(12,&fADC[i][j]); 
     377           0 :         if ((j % 4) == 0) cout << endl;
     378             :         //cout << setw(2) << j << ": " << xadc << " ";
     379           0 :         printf("%2d: %3x / ",j,fADC[i][j]); 
     380             :       }
     381           0 :       cout << "\n";
     382             :     }
     383           0 :   }
     384           0 : }
     385             : 
     386             : //_____________________________________________________________________________
     387             : UShort_t AliPHOSTriggerSTURawStream::GetThreshold(Short_t A, Short_t B, Short_t C, UShort_t V0A, UShort_t V0C) const
     388             : {
     389             :   // Get threshold 
     390           0 :   ULong64_t v0sum = V0A + V0C;
     391           0 :   ULong64_t sqrV0 = v0sum * v0sum;          
     392           0 :   sqrV0 *= A;
     393           0 :   sqrV0 >>= 32;
     394           0 :   v0sum *= B;
     395           0 :   v0sum >>= 16;
     396           0 :   return (UShort_t)(sqrV0 + v0sum + C);
     397             : }

Generated by: LCOV version 1.11