Coverity defects (next round)
[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 }
83c48644 161 delete [] initData;
f21d3ce9 162
f9720615 163 AliTRDptrgParam::AliTRDptrgPTmasks* masks =
164 new AliTRDptrgParam::AliTRDptrgPTmasks();
165 masks->fLUTs[0] = kTRUE;
166 masks->fLUTs[1] = kTRUE;
7788992c 167 masks->fLUTs[2] = kTRUE;
f9720615 168 this->fPTmasks = masks;
169 }
170 return false;
171}
172
173//______________________________________________________________________________
174Int_t* AliTRDptrgCBB::Simulate()
175{
176 // Simulate the CBB behavior of event
177 //
178 // returns array containing:
179 // 0: array element count
180 // 1..count-2: LUT results
181 // count-1: pretrigger decision
182
183 Int_t nLUTs = this->fLUTArray.GetEntries();
184
185 Int_t inputVector = 0x0;
186 // initialize partResults
187 Int_t** partResults = 0x0;
188 partResults = new Int_t* [3]; // CB-A, CB-C, TLMU
189
190 // get partResults
191 partResults[0] = this->fCBA->Simulate(); // CB-A
192 partResults[1] = this->fCBC->Simulate(); // CB-C
193 partResults[2] = this->fTLMU->Simulate(); // TLMU
194
f9720615 195 // combine partResults and create inputVectors
f9720615 196 Int_t mask = 0x1;
197 for (Int_t i = 0; i < 3 ; i++) {
198 for (Int_t j = 1; j <= partResults[i][0]; j++) {
199 if (partResults[i][j] > 0) {
200 inputVector |= mask; // Add bit to the inputVector
201 }
202 mask <<= 1;
203 }
204 }
205
206 AliDebug(5, Form("Inputvectors: 0x%x", inputVector));
207
208 // perform look up
209 Int_t* result = new Int_t[nLUTs + 2]; // generate new return array
210 result[0] = nLUTs + 1; // storage array length in the first array value
211 for (Int_t iLUT = 0; iLUT < nLUTs; iLUT++) {
212 // process the return value for each LUT and store the result in the array
f21d3ce9 213 AliTRDptrgLUT *lutTmp = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[iLUT]);
214 if (lutTmp) {
215 result[iLUT + 1] = lutTmp->LookUp(inputVector);
216 }
f9720615 217 AliDebug(4, Form("CBB result[%d] = 0x%x\n",(iLUT + 1),result[iLUT + 1]));
218 }
219
220 // evaluate PT decision
221 // stored in result[nLUTs + 1]
222 result[nLUTs + 1] = 0;
223
224 for (Int_t i = 0; i < 2; i++) {
225 // CB-A
226 if (this->fPTmasks->fCBA[i] && partResults[0][i + 1]) {
227 result[nLUTs + 1]++;
228 }
229 // CB-C
230 if (this->fPTmasks->fCBC[i] && partResults[1][i + 1]) {
231 result[nLUTs + 1]++;
232 }
233 // CB-B (own LUTs)
234 if (this->fPTmasks->fLUTs[i] && result[i + 1]) {
235 result[nLUTs + 1]++;
236 }
237 }
7788992c 238 if (this->fPTmasks->fLUTs[2] && result[3]) { // CB-B (third own LUT)
239 result[nLUTs + 1]++;
240 }
241
f9720615 242 // TLMU
243 for (Int_t i = 0; i < 8; i++) {
244 if (this->fPTmasks->fTLMU[i] && partResults[2][i + 1]) {
245 result[nLUTs + 1]++;
246 }
247 }
248 AliDebug(4, Form("CBB TRD Wake up result = %d", result[nLUTs + 1]));
f21d3ce9 249
250 delete [] partResults;
251
f9720615 252 return result;
f21d3ce9 253
f9720615 254}
255
256//______________________________________________________________________________
257Bool_t AliTRDptrgCBB::GetPT() {
258 // evaluates the pre trigger decision
259
260 Int_t* LUTresults = this->Simulate();
261 if (LUTresults[(LUTresults[0] - 1)]) {
262 delete[] LUTresults;
263 return kTRUE;
264 }
265 else {
266 delete[] LUTresults;
267 return kFALSE;
268 }
269}