LCOV - code coverage report
Current view: top level - TRD/TRDsim - AliTRDptrgCBB.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 85 136 62.5 %
Date: 2016-06-14 17:26:59 Functions: 8 11 72.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             : /* $Id$ */
      17             : 
      18             : ////////////////////////////////////////////////////////////////////////////
      19             : //                                                                        //
      20             : //  Pre-Trigger Control-Box bottom class                                  //
      21             : //                                                                        //
      22             : //  Authors: F. Reidt (Felix.Reidt@cern.ch)                               //
      23             : //                                                                        //
      24             : ////////////////////////////////////////////////////////////////////////////
      25             : 
      26             : 
      27             : #include "TROOT.h"
      28             : 
      29             : #include "AliRun.h"
      30             : #include "AliRunLoader.h"
      31             : 
      32             : #include "AliTRDptrgLUT.h"
      33             : #include "AliTRDptrgParam.h"
      34             : #include "AliTRDptrgCBAC.h"
      35             : #include "AliTRDptrgTLMU.h"
      36             : #include "AliTRDptrgCBB.h"
      37             : #include "AliLog.h"
      38          12 : ClassImp(AliTRDptrgCBB)
      39             : 
      40             : AliTRDptrgCBB::AliTRDptrgCBB(AliRunLoader *rl) 
      41           0 :   : TObject(),
      42           0 :   fRunLoader(rl),
      43           0 :   fParam(0),
      44           0 :   fOperatingMode(AliTRDptrgParam::kDigits),
      45           0 :   fCBA(0),
      46           0 :   fCBC(0),
      47           0 :   fTLMU(0),
      48           0 :   fLUTArray(0),
      49           0 :   fPTmasks(0x0)
      50           0 : {
      51             :   // default ctor
      52           0 :   AliError("default ctor - usage not recommended\n");
      53           0 : }
      54             : 
      55             : 
      56             : AliTRDptrgCBB::AliTRDptrgCBB(AliRunLoader *rl, AliTRDptrgParam* param, 
      57             :                              AliTRDptrgParam::AliTRDptrgOperatingMode_t operatingMode)
      58           4 :   : TObject(),
      59           4 :   fRunLoader(rl),
      60           4 :   fParam(param),
      61           4 :   fOperatingMode(operatingMode),
      62           4 :   fCBA(0),
      63           4 :   fCBC(0),
      64           4 :   fTLMU(0),
      65           4 :   fLUTArray(0),
      66           4 :   fPTmasks(0x0) 
      67          20 : {
      68             :   // recommended ctor
      69          12 :   this->fCBA = new AliTRDptrgCBAC(rl, AliTRDptrgParam::kA, operatingMode, param);
      70          12 :   this->fCBC = new AliTRDptrgCBAC(rl, AliTRDptrgParam::kC, operatingMode, param);
      71          12 :   this->fTLMU = new AliTRDptrgTLMU(rl, param, operatingMode);
      72             : 
      73           4 :   this->LoadParams();
      74           8 : }
      75             : 
      76             : AliTRDptrgCBB::~AliTRDptrgCBB() 
      77          24 : {
      78             :   // destructor
      79             : 
      80           4 :   if (this->fCBA != 0x0) {
      81           8 :     delete this->fCBA;
      82           4 :     this->fCBA = 0x0;
      83           4 :   }
      84             : 
      85           4 :   if (this->fCBC != 0x0) {
      86           8 :     delete this->fCBC;
      87           4 :     this->fCBC = 0x0;
      88           4 :   }
      89             : 
      90           4 :   if (this->fTLMU != 0x0) {
      91           8 :     delete this->fTLMU;
      92           4 :     this->fTLMU = 0x0;
      93           4 :   }
      94             : 
      95           4 :   this->fLUTArray.Delete();
      96          12 : }
      97             : 
      98             : 
      99             : //______________________________________________________________________________
     100             : Bool_t AliTRDptrgCBB::LoadParams() 
     101             : {
     102             :   // load configuration parameters
     103             : 
     104           8 :   if (this->fParam != 0x0) {
     105             :     // read AliTRDptrgParam
     106             :     
     107             :     // get LUTs
     108             :     // 0
     109           4 :     AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
     110           4 :     LUT->InitTable(12, 12, this->fParam->GetCBLUT(0, 0), kFALSE);
     111             :     // get CB-B_0 and do not copy lut content
     112           4 :     this->fLUTArray.AddLast(LUT);
     113             :  
     114             :     // 1
     115           4 :     LUT = new AliTRDptrgLUT();
     116           4 :     LUT->InitTable(12, 12, this->fParam->GetCBLUT(0, 1), kFALSE);
     117             :     // get CB-B_1 and do not copy lut content
     118           4 :     this->fLUTArray.AddLast(LUT);
     119             : 
     120             :     // 2
     121           4 :     LUT = new AliTRDptrgLUT();
     122           4 :     LUT->InitTable(12, 12, this->fParam->GetCBLUT(0, 2), kFALSE);
     123             :     // get CB-B_2 and do not copy lut content
     124           4 :     this->fLUTArray.AddLast(LUT);
     125             : 
     126             :     // masks
     127           4 :     this->fPTmasks = this->fParam->GetPTmasks();
     128           4 :   }
     129             :   else {
     130             :     // load default parameters 
     131             :     // initialize LUTsoutputWidth=<value optimized out>
     132           0 :     AliTRDptrgLUT* lut = new AliTRDptrgLUT();
     133           0 :     this->fLUTArray.AddLast(lut);
     134           0 :     lut = new AliTRDptrgLUT(); // this->fRunLoader
     135           0 :     this->fLUTArray.AddLast(lut);
     136           0 :     lut = new AliTRDptrgLUT(); // this->fRunLoader
     137           0 :     this->fLUTArray.AddLast(lut);
     138             :     // the following lines are only needed for test reasons
     139           0 :     Int_t* initData = new Int_t[4096]; // 2^12
     140           0 :     lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
     141           0 :     if (lut) {
     142           0 :       for (Int_t i = 0; i < 4096; i++ ) {
     143           0 :         initData[i] = i;
     144             :       }
     145           0 :       lut->InitTable(12, 12, initData, kTRUE); // make a copy
     146           0 :     }
     147           0 :     lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
     148           0 :     if (lut) {
     149           0 :       for (Int_t i = 0; i < 4096; i++ ) {
     150           0 :         initData[i] = i;
     151             :       }
     152           0 :       lut->InitTable(12, 12, initData, kTRUE); // make a copy
     153           0 :     }
     154           0 :     lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
     155           0 :     if (lut) {
     156             :       //for (Int_t i = 4096; i >= 0; i--) {
     157           0 :       for (Int_t i = 4096; i > 0; i--) {
     158           0 :         initData[4096 - i] = i;  // inverse ramp
     159             :       }
     160           0 :       lut->InitTable(12, 12, initData, kTRUE); // make a copy 
     161           0 :     }
     162           0 :     delete [] initData;
     163             : 
     164             :     AliTRDptrgParam::AliTRDptrgPTmasks* masks = 
     165           0 :       new AliTRDptrgParam::AliTRDptrgPTmasks();  
     166           0 :     masks->fLUTs[0] = kTRUE;
     167           0 :     masks->fLUTs[1] = kTRUE;
     168           0 :     masks->fLUTs[2] = kTRUE;
     169           0 :     this->fPTmasks = masks;
     170             :   }  
     171           4 :   return false;
     172           0 : }
     173             : 
     174             : //______________________________________________________________________________
     175             : Int_t* AliTRDptrgCBB::Simulate()
     176             : { 
     177             :   // Simulate the CBB behavior of event
     178             :   //
     179             :   // returns array containing:
     180             :   // 0: array element count
     181             :   // 1..count-2: LUT results
     182             :   // count-1: pretrigger decision
     183             : 
     184           8 :   Int_t nLUTs = this->fLUTArray.GetEntries();
     185             : 
     186             :   Int_t inputVector = 0x0;
     187             :   // initialize partResults
     188             :   Int_t** partResults = 0x0;  
     189           4 :   partResults = new Int_t* [3]; // CB-A, CB-C, TLMU
     190             :  
     191             :   // get partResults
     192           4 :   partResults[0] = this->fCBA->Simulate(); // CB-A
     193           4 :   partResults[1] = this->fCBC->Simulate(); // CB-C
     194           4 :   partResults[2] = this->fTLMU->Simulate(); // TLMU
     195             :   
     196             :   // combine partResults and create inputVectors  
     197             :   Int_t mask = 0x1;
     198          32 :   for (Int_t i = 0; i < 3 ; i++) {
     199         120 :     for (Int_t j = 1; j <= partResults[i][0]; j++) {
     200          48 :       if (partResults[i][j] > 0) {
     201          36 :         inputVector |= mask; // Add bit to the  inputVector
     202          36 :       }
     203          48 :       mask <<= 1;
     204             :     }
     205             :   }
     206             :   
     207          12 :   AliDebug(5, Form("Inputvectors: 0x%x", inputVector));
     208             :     
     209             :   // perform look up
     210           4 :   Int_t* result = new Int_t[nLUTs + 2]; // generate new return array
     211           4 :   result[0] = nLUTs + 1; // storage array length in the first array value
     212          32 :   for (Int_t iLUT = 0; iLUT < nLUTs; iLUT++) { 
     213             :     // process the return value for each LUT and store the result in the array
     214          36 :     AliTRDptrgLUT *lutTmp = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[iLUT]);
     215          12 :     if (lutTmp) {
     216          12 :       result[iLUT + 1] = lutTmp->LookUp(inputVector);
     217          12 :     }
     218          36 :     AliDebug(4, Form("CBB result[%d] = 0x%x\n",(iLUT + 1),result[iLUT + 1])); 
     219             :   }
     220             :   
     221             :   // evaluate PT decision
     222             :   // stored in result[nLUTs + 1]
     223           4 :   result[nLUTs + 1] = 0;
     224             : 
     225          24 :   for (Int_t i = 0; i < 2; i++) {
     226             :     // CB-A
     227          12 :     if (this->fPTmasks->fCBA[i] && partResults[0][i + 1]) {
     228           4 :       result[nLUTs + 1]++;
     229           4 :     }
     230             :     // CB-C
     231          12 :     if (this->fPTmasks->fCBC[i] && partResults[1][i + 1]) {
     232           4 :       result[nLUTs + 1]++;
     233           4 :     }
     234             :     // CB-B (own LUTs)
     235          16 :     if (this->fPTmasks->fLUTs[i] && result[i + 1]) {
     236           8 :       result[nLUTs + 1]++;
     237           8 :     }       
     238             :   }
     239           8 :   if (this->fPTmasks->fLUTs[2] && result[3]) { // CB-B (third own LUT)
     240           4 :     result[nLUTs + 1]++;
     241           4 :   }
     242             : 
     243             :   // TLMU
     244          72 :   for (Int_t i = 0; i < 8; i++) {
     245          56 :     if (this->fPTmasks->fTLMU[i] && partResults[2][i + 1]) {
     246          12 :       result[nLUTs + 1]++;
     247          12 :     }
     248             :   }
     249          12 :   AliDebug(4, Form("CBB TRD Wake up result = %d", result[nLUTs + 1]));
     250             : 
     251           8 :   delete [] partResults;
     252             : 
     253           4 :   return result;
     254             : 
     255             : }
     256             : 
     257             : //______________________________________________________________________________
     258             : Bool_t AliTRDptrgCBB::GetPT() {
     259             :   // evaluates the pre trigger decision
     260             : 
     261           0 :   Int_t* LUTresults = this->Simulate();
     262           0 :   if (LUTresults[(LUTresults[0] - 1)]) {
     263           0 :     delete[] LUTresults;
     264           0 :     return kTRUE;
     265             :   }
     266             :   else {
     267           0 :     delete[] LUTresults;
     268           0 :     return kFALSE;
     269             :   }
     270           0 : }

Generated by: LCOV version 1.11