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