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 A or C for simulation //
21 : // //
22 : // Authors: F. Reidt (Felix.Reidt@cern.ch) //
23 : // //
24 : ////////////////////////////////////////////////////////////////////////////
25 :
26 : #include <stdio.h>
27 :
28 : #include "AliRun.h"
29 : #include "AliRunLoader.h"
30 :
31 : #include "AliLog.h"
32 :
33 : #include "AliTRDptrgParam.h"
34 : #include "AliTRDptrgFEB.h"
35 : #include "AliTRDptrgLUT.h"
36 :
37 : #include "AliTRDptrgCBAC.h"
38 :
39 12 : ClassImp(AliTRDptrgCBAC)
40 :
41 : //______________________________________________________________________________
42 : AliTRDptrgCBAC::AliTRDptrgCBAC(AliRunLoader *rl)
43 0 : : TObject(),
44 0 : fRunLoader(rl),
45 0 : fLUTArray(),
46 0 : fFEBArray(),
47 0 : fPosition(AliTRDptrgParam::kUnknown),
48 0 : fOperatingMode(AliTRDptrgParam::kDigits),
49 0 : fParam(0x0)
50 0 : {
51 : //
52 : // ctor
53 : //
54 :
55 0 : AliError("default ctor - usage not recommended");
56 :
57 0 : }
58 :
59 : //______________________________________________________________________________
60 : AliTRDptrgCBAC::AliTRDptrgCBAC(AliRunLoader *rl,
61 : AliTRDptrgParam::AliTRDptrgFEBPosition_t position,
62 : AliTRDptrgParam::AliTRDptrgOperatingMode_t operatingMode,
63 : AliTRDptrgParam *param)
64 8 : : TObject(),
65 8 : fRunLoader(rl),
66 8 : fLUTArray(),
67 8 : fFEBArray(),
68 8 : fPosition(position),
69 8 : fOperatingMode(operatingMode),
70 8 : fParam(param)
71 40 : {
72 : //
73 : // ctor
74 : //
75 :
76 8 : this->LoadParams(); // load parameters
77 :
78 : // T0
79 24 : AliTRDptrgFEB *FEB = new AliTRDptrgFEB(this->fRunLoader, AliTRDptrgParam::kTZERO,
80 8 : this->fOperatingMode, this->fPosition,
81 8 : 0, this->fParam);
82 8 : this->fFEBArray.AddLast(FEB);
83 :
84 : // V0-1
85 24 : FEB = new AliTRDptrgFEB(this->fRunLoader, AliTRDptrgParam::kVZERO, this->fOperatingMode,
86 8 : this->fPosition, 1, this->fParam);
87 8 : this->fFEBArray.AddLast(FEB);
88 :
89 : // V0-2
90 24 : FEB = new AliTRDptrgFEB(this->fRunLoader, AliTRDptrgParam::kVZERO, this->fOperatingMode,
91 8 : this->fPosition, 2, this->fParam);
92 8 : this->fFEBArray.AddLast(FEB);
93 :
94 : // V0-3
95 24 : FEB = new AliTRDptrgFEB(this->fRunLoader, AliTRDptrgParam::kVZERO, this->fOperatingMode,
96 8 : this->fPosition, 3, this->fParam);
97 8 : this->fFEBArray.AddLast(FEB);
98 :
99 : // V0-4
100 24 : FEB = new AliTRDptrgFEB(this->fRunLoader, AliTRDptrgParam::kVZERO, this->fOperatingMode,
101 8 : this->fPosition, 4, this->fParam);
102 8 : this->fFEBArray.AddLast(FEB);
103 :
104 16 : }
105 :
106 : //______________________________________________________________________________
107 : Bool_t AliTRDptrgCBAC::LoadParams()
108 : {
109 : //
110 : // Load configuration parameters
111 : //
112 :
113 16 : if (this->fParam != 0x0) {
114 : // read AliTRDptrgParam
115 :
116 : // get LUTs
117 : AliTRDptrgLUT* lut = 0x0;
118 : // 0
119 8 : lut = new AliTRDptrgLUT();
120 8 : lut->InitTable(10, 10, this->fParam->GetCBLUT(this->fPosition, 0), kFALSE);
121 : // do not copy table data
122 8 : this->fLUTArray.AddLast(lut);
123 : // 1
124 8 : lut = new AliTRDptrgLUT();
125 8 : lut->InitTable(10, 10, this->fParam->GetCBLUT(this->fPosition, 1), kFALSE);
126 : // do not copy table data
127 8 : this->fLUTArray.AddLast(lut);
128 8 : }
129 : else {
130 : // load default parameters
131 0 : AliTRDptrgLUT* lut = new AliTRDptrgLUT();
132 0 : this->fLUTArray.AddLast(lut);
133 0 : lut = new AliTRDptrgLUT();
134 0 : this->fLUTArray.AddLast(lut);
135 : // the following lines are only needed for test reasons
136 0 : lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
137 0 : if (lut) {
138 0 : Int_t* initData = new Int_t[1024]; // 2^10
139 0 : for (Int_t i = 0; i < 1024; i++ ) {
140 0 : initData[i] = i;
141 : }
142 0 : lut->InitTable(10, 10, initData, kTRUE); // copy initData
143 0 : lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
144 0 : if (lut) {
145 0 : for (Int_t i = 1023; i >= 0; i--) {
146 0 : initData[31 - i] = i; // inverse ramp
147 : }
148 0 : lut->InitTable(10, 10, initData, kTRUE); // copy initData
149 0 : }
150 0 : }
151 : }
152 :
153 8 : return false;
154 :
155 0 : }
156 :
157 : //______________________________________________________________________________
158 : AliTRDptrgCBAC::~AliTRDptrgCBAC()
159 48 : {
160 : //
161 : // Destructor
162 : //
163 :
164 8 : this->fLUTArray.Delete();
165 8 : this->fFEBArray.Delete();
166 :
167 24 : }
168 :
169 : //______________________________________________________________________________
170 : Int_t* AliTRDptrgCBAC::Simulate()
171 : {
172 : //
173 : // Simulate the CBAC behavior of event
174 : //
175 :
176 16 : Int_t nFEBs = this->fFEBArray.GetEntries();
177 8 : Int_t nLUTs = this->fLUTArray.GetEntries();
178 :
179 : Int_t inputVector = 0x0;
180 :
181 : Int_t** partResults = 0x0;
182 8 : partResults = new Int_t* [nFEBs];
183 :
184 96 : for (Int_t iFEB = 0; iFEB < nFEBs; iFEB++) {
185 : AliTRDptrgFEB *feb = 0x0;
186 120 : if ((feb = dynamic_cast<AliTRDptrgFEB*>(this->fFEBArray.At(iFEB)))) {
187 40 : partResults[iFEB] = feb->Simulate();
188 40 : }
189 : }
190 :
191 : // combine partResults and create inputVector
192 : Int_t iBit = 0;
193 : Int_t mask = 0x1;
194 96 : for (Int_t iFEB = 0; iFEB < nFEBs ; iFEB++) {
195 240 : for (Int_t j = 1; j <= partResults[iFEB][0]; j++) {
196 240 : AliTRDptrgLUT *lut0 = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[0]);
197 240 : AliTRDptrgLUT *lut1 = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[1]);
198 80 : if (lut0 && lut1) {
199 160 : if ((iBit > lut0->GetInputWidth())
200 160 : || (iBit > lut1->GetInputWidth())) {
201 0 : AliError("FEB result width does not match CB-A/C input with!");
202 0 : }
203 : }
204 80 : iBit++;
205 80 : if (partResults[iFEB][j] > 0) {
206 52 : inputVector |= mask; // Add bit to the corresponding inputVector
207 52 : mask <<= 1;
208 52 : }
209 : }
210 : }
211 :
212 24 : AliDebug(5, Form("Inputvector: 0x%x", inputVector));
213 :
214 : // perform look up
215 8 : Int_t* result = new Int_t[nLUTs + 1]; // generate new return array
216 8 : result[0] = nLUTs; // storage array length in the first array value
217 48 : 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 48 : if ((lutTmp = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[iLUT]))) {
221 16 : result[iLUT + 1] = lutTmp->LookUp(inputVector);
222 16 : }
223 48 : AliDebug(4, Form("CBAC result[%d] = 0x%x",(iLUT + 1),result[iLUT + 1]));
224 : }
225 :
226 : // Clean up
227 16 : delete [] partResults;
228 :
229 8 : return result;
230 :
231 : }
232 :
233 :
234 :
|