1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // Pre-Trigger Control-Box A or C for simulation //
22 // Authors: F. Reidt (Felix.Reidt@cern.ch) //
24 ////////////////////////////////////////////////////////////////////////////
29 #include "AliRunLoader.h"
33 #include "AliTRDptrgParam.h"
34 #include "AliTRDptrgFEB.h"
35 #include "AliTRDptrgLUT.h"
37 #include "AliTRDptrgCBAC.h"
39 ClassImp(AliTRDptrgCBAC)
41 //______________________________________________________________________________
42 AliTRDptrgCBAC::AliTRDptrgCBAC(AliRunLoader *rl)
48 fOperatingMode(kDigits),
55 AliError("default ctor - usage not recommended");
59 //______________________________________________________________________________
60 AliTRDptrgCBAC::AliTRDptrgCBAC(AliRunLoader *rl,
61 AliTRDptrgFEBPosition_t position,
62 AliTRDptrgOperatingMode_t operatingMode,
63 AliTRDptrgParam *param)
69 fOperatingMode(operatingMode),
76 this->LoadParams(); // load parameters
79 AliTRDptrgFEB *FEB = new AliTRDptrgFEB(this->fRunLoader, kTZERO,
80 this->fOperatingMode, this->fPosition,
82 this->fFEBArray.AddLast(FEB);
85 FEB = new AliTRDptrgFEB(this->fRunLoader, kVZERO, this->fOperatingMode,
86 this->fPosition, 1, this->fParam);
87 this->fFEBArray.AddLast(FEB);
90 FEB = new AliTRDptrgFEB(this->fRunLoader, kVZERO, this->fOperatingMode,
91 this->fPosition, 2, this->fParam);
92 this->fFEBArray.AddLast(FEB);
95 FEB = new AliTRDptrgFEB(this->fRunLoader, kVZERO, this->fOperatingMode,
96 this->fPosition, 3, this->fParam);
97 this->fFEBArray.AddLast(FEB);
100 FEB = new AliTRDptrgFEB(this->fRunLoader, kVZERO, this->fOperatingMode,
101 this->fPosition, 4, this->fParam);
102 this->fFEBArray.AddLast(FEB);
106 //______________________________________________________________________________
107 Bool_t AliTRDptrgCBAC::LoadParams()
110 // Load configuration parameters
113 if (this->fParam != 0x0) {
114 // read AliTRDptrgParam
117 AliTRDptrgLUT* lut = 0x0;
119 lut = new AliTRDptrgLUT();
120 lut->InitTable(10, 10, this->fParam->GetCBLUT(this->fPosition, 0), kFALSE);
121 // do not copy table data
122 this->fLUTArray.AddLast(lut);
124 lut = new AliTRDptrgLUT();
125 lut->InitTable(10, 10, this->fParam->GetCBLUT(this->fPosition, 1), kFALSE);
126 // do not copy table data
127 this->fLUTArray.AddLast(lut);
130 // load default parameters
131 AliTRDptrgLUT* lut = new AliTRDptrgLUT();
132 this->fLUTArray.AddLast(lut);
133 lut = new AliTRDptrgLUT();
134 this->fLUTArray.AddLast(lut);
135 // the following lines are only needed for test reasons
136 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
138 Int_t* initData = new Int_t[1024]; // 2^10
139 for (Int_t i = 0; i < 1024; i++ ) {
142 lut->InitTable(10, 10, initData, kTRUE); // copy initData
143 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
145 for (Int_t i = 1023; i >= 0; i--) {
146 initData[31 - i] = i; // inverse ramp
148 lut->InitTable(10, 10, initData, kTRUE); // copy initData
157 //______________________________________________________________________________
158 AliTRDptrgCBAC::~AliTRDptrgCBAC()
164 this->fLUTArray.Delete();
165 this->fFEBArray.Delete();
169 //______________________________________________________________________________
170 Int_t* AliTRDptrgCBAC::Simulate()
173 // Simulate the CBAC behavior of event
176 Int_t nFEBs = this->fFEBArray.GetEntries();
177 Int_t nLUTs = this->fLUTArray.GetEntries();
179 Int_t inputVector = 0x0;
181 Int_t** partResults = 0x0;
182 partResults = new Int_t* [nFEBs];
184 for (Int_t iFEB = 0; iFEB < nFEBs; iFEB++) {
185 AliTRDptrgFEB *feb = 0x0;
186 if ((feb = dynamic_cast<AliTRDptrgFEB*>(this->fFEBArray.At(iFEB)))) {
187 partResults[iFEB] = feb->Simulate();
191 // combine partResults and create inputVector
194 for (Int_t iFEB = 0; iFEB < nFEBs ; iFEB++) {
195 for (Int_t j = 1; j <= partResults[iFEB][0]; j++) {
196 AliTRDptrgLUT *lut0 = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[0]);
197 AliTRDptrgLUT *lut1 = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[1]);
199 if ((iBit > lut0->GetInputWidth())
200 || (iBit > lut1->GetInputWidth())) {
201 AliError("FEB result width does not match CB-A/C input with!");
205 if (partResults[iFEB][j] > 0) {
206 inputVector |= mask; // Add bit to the corresponding inputVector
212 AliDebug(5, Form("Inputvector: 0x%x", inputVector));
215 Int_t* result = new Int_t[nLUTs + 1]; // generate new return array
216 result[0] = nLUTs; // storage array length in the first array value
217 for (Int_t iLUT = 0; iLUT < nLUTs; iLUT++) {
218 // process the return value for each LUT and store the result in the array
219 AliTRDptrgLUT *lutTmp = 0x0;
220 if ((lutTmp = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[iLUT]))) {
221 result[iLUT + 1] = lutTmp->LookUp(inputVector);
223 AliDebug(4, Form("CBAC result[%d] = 0x%x",(iLUT + 1),result[iLUT + 1]));
227 delete [] partResults;