]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TRD/AliTRDtrapConfigHandler.cxx
- fix
[u/mrichter/AliRoot.git] / TRD / AliTRDtrapConfigHandler.cxx
... / ...
CommitLineData
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////////////////////////////////////////////////////////////////////////////
17// //
18// MCM configuraton handler //
19// //
20// Author: U. Westerhoff //
21// //
22////////////////////////////////////////////////////////////////////////////
23
24#include "AliTRDtrapConfigHandler.h"
25
26#include <iostream>
27#include <sstream>
28#include <iomanip>
29
30#include "AliLog.h"
31
32#include "AliTRDfeeParam.h"
33#include "AliTRDtrapConfig.h"
34#include "AliTRDmcmSim.h"
35#include "AliTRDgeometry.h"
36#include "AliTRDcalibDB.h"
37
38#include "TMath.h"
39#include "TGeoMatrix.h"
40#include "TGraph.h"
41
42#include "Cal/AliTRDCalOnlineGainTable.h"
43#include "Cal/AliTRDCalOnlineGainTableROC.h"
44#include "Cal/AliTRDCalOnlineGainTableMCM.h"
45
46using namespace std;
47
48AliTRDtrapConfigHandler::AliTRDtrapConfigHandler(AliTRDtrapConfig *cfg) :
49 ltuParam()
50 , fRestrictiveMask((0x3ffff << 11) | (0x1f << 6) | 0x3f)
51 , fTrapConfig(cfg)
52 , fGtbl()
53{
54
55}
56
57
58AliTRDtrapConfigHandler::~AliTRDtrapConfigHandler()
59{
60
61}
62
63void AliTRDtrapConfigHandler::Init()
64{
65 if (!fTrapConfig) {
66 AliError("No TRAPconfig given");
67 return;
68 }
69
70 // setup of register allocation
71 // I/O configuration which we don't care about
72 fTrapConfig->SetTrapRegAlloc(AliTRDtrapConfig::kSEBDOU, AliTRDtrapConfig::kAllocNone);
73 // position look-up table by layer
74 for (Int_t iBin = 0; iBin < 128; iBin++)
75 fTrapConfig->SetTrapRegAlloc((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iBin), AliTRDtrapConfig::kAllocByLayer);
76 // ... individual
77 fTrapConfig->SetTrapRegAlloc(AliTRDtrapConfig::kC14CPUA, AliTRDtrapConfig::kAllocByMCM);
78 fTrapConfig->SetTrapRegAlloc(AliTRDtrapConfig::kC15CPUA, AliTRDtrapConfig::kAllocByMCM);
79
80 // setup of DMEM allocation
81 for(Int_t iAddr = AliTRDtrapConfig::fgkDmemStartAddress;
82 iAddr < (AliTRDtrapConfig::fgkDmemWords + AliTRDtrapConfig::fgkDmemStartAddress); iAddr++) {
83
84 if(iAddr == AliTRDmcmSim::fgkDmemAddrDeflCorr)
85 fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByMCMinSM);
86
87 else if(iAddr == AliTRDmcmSim::fgkDmemAddrNdrift)
88 fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByDetector);
89
90 else if((iAddr >= AliTRDmcmSim::fgkDmemAddrDeflCutStart) && (iAddr <= AliTRDmcmSim::fgkDmemAddrDeflCutEnd))
91 fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByMCMinSM);
92
93 else if((iAddr >= AliTRDmcmSim::fgkDmemAddrTrackletStart) && (iAddr <= AliTRDmcmSim::fgkDmemAddrTrackletEnd))
94 fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByMCM);
95
96 else if((iAddr >= AliTRDmcmSim::fgkDmemAddrLUTStart) && (iAddr <= AliTRDmcmSim::fgkDmemAddrLUTEnd))
97 fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocGlobal);
98
99 else if(iAddr == AliTRDmcmSim::fgkDmemAddrLUTcor0)
100 fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByMCMinSM);
101
102 else if(iAddr == AliTRDmcmSim::fgkDmemAddrLUTcor1)
103 fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocByMCMinSM);
104
105 else if(iAddr == AliTRDmcmSim::fgkDmemAddrLUTnbins)
106 fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocGlobal);
107
108 else if(iAddr == AliTRDmcmSim::fgkDmemAddrLUTLength)
109 fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocGlobal);
110
111 else
112 fTrapConfig->SetDmemAlloc(iAddr, AliTRDtrapConfig::kAllocGlobal);
113 }
114}
115
116void AliTRDtrapConfigHandler::ResetMCMs()
117{
118 //
119 // Reset all MCM registers and DMEM
120 //
121
122 if (!fTrapConfig) {
123 AliError("No TRAPconfig given");
124 return;
125 }
126
127 fTrapConfig->ResetRegs();
128 fTrapConfig->ResetDmem();
129}
130
131
132Int_t AliTRDtrapConfigHandler::LoadConfig()
133{
134 // load a default configuration which is suitable for simulation
135 // for a detailed description of the registers see the TRAP manual
136 // if you want to resimulate tracklets on real data use the appropriate config instead
137
138 if (!fTrapConfig) {
139 AliError("No TRAPconfig given");
140 return -1;
141 }
142
143 // prepare ltuParam
144 // ndrift (+ 5 binary digits)
145 ltuParam.SetNtimebins(20 << 5);
146 // deflection + tilt correction
147 ltuParam.SetRawOmegaTau(0.16133);
148 // deflection range table
149 ltuParam.SetRawPtMin(0.1);
150 // magnetic field
151 ltuParam.SetRawMagField(0.0);
152 // scaling factors for q0, q1
153 ltuParam.SetRawScaleQ0(0);
154 ltuParam.SetRawScaleQ1(0);
155 // disable length correction and tilting correction
156 ltuParam.SetRawLengthCorrectionEnable(kFALSE);
157 ltuParam.SetRawTiltCorrectionEnable(kFALSE);
158
159 for (Int_t iDet = 0; iDet < 540; iDet++) {
160 // HC header configuration bits
161 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC15CPUA, 0x2102, iDet); // zs, deh
162
163 // no. of timebins
164 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC13CPUA, 24, iDet);
165
166 // pedestal filter
167 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFPNP, 4*10, iDet);
168 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFPTC, 0, iDet);
169 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFPBY, 0, iDet); // bypassed!
170
171 // gain filter
172 for (Int_t adc = 0; adc < 20; adc++) {
173 fTrapConfig->SetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGA0+adc), 40, iDet);
174 fTrapConfig->SetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGF0+adc), 15, iDet);
175 }
176 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFGTA, 20, iDet);
177 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFGTB, 2060, iDet);
178 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFGBY, 0, iDet); // bypassed!
179
180 // tail cancellation
181 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFTAL, 200, iDet);
182 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFTLL, 0, iDet);
183 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFTLS, 200, iDet);
184 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kFTBY, 0, iDet);
185
186 // tracklet calculation
187 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPQS0, 5, iDet);
188 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPQE0, 10, iDet);
189 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPQS1, 11, iDet);
190 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPQE1, 20, iDet);
191 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPFS, 5, iDet);
192 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPFE, 20, iDet);
193 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPVBY, 0, iDet);
194 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPVT, 10, iDet);
195 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPHT, 150, iDet);
196 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPFP, 40, iDet);
197 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPCL, 1, iDet);
198 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kTPCT, 10, iDet);
199
200 // apply ltuParams
201 ConfigureDyCorr(iDet);
202 ConfigureDRange(iDet); // deflection range
203 ConfigureNTimebins(iDet); // timebins in the drift region
204 ConfigurePIDcorr(iDet); // scaling parameters for the PID
205
206 // event buffer
207 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kEBSF, 1, iDet); // 0: store filtered; 1: store unfiltered
208
209 // zs applied to data stored in event buffer (sel. by EBSF)
210 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kEBIS, 15 << 2, iDet); // single indicator threshold (plus two digits)
211 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kEBIT, 30 << 2, iDet); // sum indicator threshold (plus two digits)
212 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kEBIL, 0xf0, iDet); // lookup table
213 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kEBIN, 0, iDet); // neighbour sensitivity
214
215 // raw data
216 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kNES, (0x0000 << 16) | 0x1000, iDet);
217 }
218
219 // ****** hit position LUT
220
221 // now calculate it from PRF
222 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
223
224 Double_t padResponse[3]; // pad response left, central, right
225 Double_t padResponseR[3]; // pad response left, central, right
226 Double_t padResponseL[3]; // pad response left, central, right
227
228 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
229 TGraph gr(128);
230 for (Int_t iBin = 0; iBin < 256*0.5; iBin++) {
231 cal->PadResponse(1., iBin*1./256., iLayer, padResponse);
232 cal->PadResponse(1., iBin*1./256.-1., iLayer, padResponseR);
233 cal->PadResponse(1., iBin*1./256.+1., iLayer, padResponseL);
234 gr.SetPoint(iBin, (0.5 * (padResponseR[1] - padResponseL[1])/padResponse[1] * 256), iBin);
235 }
236 for (Int_t iBin = 0; iBin < 128; iBin++) {
237 Int_t corr = (Int_t) (gr.Eval(iBin)) - iBin;
238 if (corr < 0)
239 corr = 0;
240 else if (corr > 31)
241 corr = 31;
242 for (Int_t iStack = 0; iStack < 540/6; iStack++) {
243 fTrapConfig->SetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + iBin), corr, 6*iStack + iLayer);
244 }
245 }
246 }
247 // ****** hit position LUT configuration end
248
249 return 0;
250}
251
252
253Int_t AliTRDtrapConfigHandler::LoadConfig(TString filename)
254{
255 //
256 // load a TRAP configuration from a file
257 // The file format is the format created by the standalone
258 // command coder scc / show_cfdat but without the running number
259 // scc /show_cfdat adds as the first column
260 // which are two tools to inspect/export configurations from wingDB
261 //
262
263 if (!fTrapConfig) {
264 AliError("No TRAPconfig given");
265 return -1;
266 }
267
268 Int_t ignoredLines=0;
269 Int_t ignoredCmds=0;
270 Int_t readLines=0;
271
272
273 AliDebug(5, Form("Processing file %s", filename.Data()));
274 std::ifstream infile;
275 infile.open(filename.Data(), std::ifstream::in);
276 if (!infile.is_open()) {
277 AliError(Form("Can not open MCM configuration file %s", filename.Data()));
278 return kFALSE;
279 }
280
281 UInt_t cmd;
282 Int_t extali, addr, data;
283
284 // reset restrictive mask
285 fRestrictiveMask = (0x3ffff << 11) | (0x1f << 6) | 0x3f;
286 char linebuffer[512];
287 istringstream line;
288
289 while(infile.getline(linebuffer, 512) && infile.good()) {
290 line.clear();
291 line.str(linebuffer);
292 cmd=999;
293 extali=-1;
294 addr=-1;
295 data=-1;
296 line >> std::skipws >> cmd >> addr >> data >> extali; // the lines read from config file can contain additional columns.
297 // Therefore the detour via istringstream
298
299 if(cmd!=999 && addr != -1 && data!= -1 && extali!=-1) {
300
301 if(cmd==fgkScsnCmdWrite) {
302 for(Int_t det=0; det<AliTRDgeometry::Ndet(); det++) {
303 UInt_t rocpos = (1 << (AliTRDgeometry::GetSector(det)+11)) | (1 << (AliTRDgeometry::GetStack(det)+6)) | (1 << AliTRDgeometry::GetLayer(det));
304 AliDebug(1, Form("checking restriction: mask=0x%08x, rocpos=0x%08x", fRestrictiveMask, rocpos));
305 if ((fRestrictiveMask & rocpos) == rocpos) {
306 AliDebug(1, Form("match: %i %i %i %i", cmd, extali, addr, data));
307 AddValues(det, cmd, extali, addr, data);
308 }
309 }
310 }
311
312 else if(cmd == fgkScsnLTUparam) {
313 ProcessLTUparam(extali, addr, data);
314 }
315
316 else if(cmd == fgkScsnCmdRestr) {
317 fRestrictiveMask = data;
318 AliDebug(1, Form("updated restrictive mask to 0x%08x", fRestrictiveMask));
319 }
320
321 else if((cmd == fgkScsnCmdReset) ||
322 (cmd == fgkScsnCmdRobReset)) {
323 fTrapConfig->ResetRegs();
324 }
325
326 else if (cmd == fgkScsnCmdSetHC) {
327 Int_t fullVersion = ((data & 0x7F00) >> 1) | (data & 0x7f);
328
329 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
330 Int_t smls = (AliTRDgeometry::GetSector(iDet) << 6) | (AliTRDgeometry::GetLayer(iDet) << 3) | AliTRDgeometry::GetStack(iDet);
331
332 for (Int_t iRob = 0; iRob < 8; iRob++) {
333 // HC mergers
334 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC14CPUA, 0xc << 16, iDet, iRob, 17);
335 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC15CPUA, ((1<<29) | (fullVersion<<15) | (1<<12) | (smls<<1) | (iRob%2)), iDet, iRob, 17);
336
337 // board mergers
338 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC14CPUA, 0, iDet, iRob, 16);
339 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC15CPUA, ((1<<29) | (fullVersion<<15) | (1<<12) | (smls<<1) | (iRob%2)), iDet, iRob, 16);
340
341 // and now for the others
342 for (Int_t iMcm = 0; iMcm < 16; iMcm++) {
343 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC14CPUA, iMcm | (iRob << 4) | (3 << 16), iDet, iRob, iMcm);
344 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kC15CPUA, ((1<<29) | (fullVersion<<15) | (1<<12) | (smls<<1) | (iRob%2)), iDet, iRob, iMcm);
345 }
346 }
347 }
348 }
349
350 else if((cmd == fgkScsnCmdRead) ||
351 (cmd == fgkScsnCmdPause) ||
352 (cmd == fgkScsnCmdPtrg) ||
353 (cmd == fgkScsnCmdHwPtrg) ||
354 (cmd == fgkScsnCmdRobPower) ||
355 (cmd == fgkScsnCmdTtcRx) ||
356 (cmd == fgkScsnCmdMcmTemp) ||
357 (cmd == fgkScsnCmdOri) ||
358 (cmd == fgkScsnCmdPM) ) {
359 AliDebug(2, Form("ignored SCSN command: %i %i %i %i", cmd, addr, data, extali));
360 }
361
362 else {
363 AliWarning(Form("unknown SCSN command: %i %i %i %i", cmd, addr, data, extali));
364 ignoredCmds++;
365 }
366
367 readLines++;
368 }
369
370 else if(!infile.eof() && !infile.good()) {
371 infile.clear();
372 infile.ignore(256, '\n');
373 ignoredLines++;
374 }
375
376 if(!infile.eof())
377 infile.clear();
378 }
379
380 infile.close();
381
382 AliDebug(5, Form("Ignored lines: %i, ignored cmds: %i", ignoredLines, ignoredCmds));
383
384
385 if(ignoredLines>readLines)
386 AliError(Form("More than 50 %% of the input file could not be processed. Perhaps you should check the input file %s", filename.Data()));
387
388
389 return kTRUE;
390}
391
392
393
394Int_t AliTRDtrapConfigHandler::SetGaintable(AliTRDCalOnlineGainTable const &gtbl)
395{
396 fGtbl=gtbl;
397 return 0;
398}
399
400
401void AliTRDtrapConfigHandler::ProcessLTUparam(Int_t dest, Int_t addr, UInt_t data)
402{
403 //
404 // Process the LTU parameters and stores them in internal class variables
405 // or transfer the stored values to AliTRDtrapConfig, depending on the dest parameter
406 //
407
408 switch (dest) {
409
410 case 0: // set the parameters in AliTRDtrapConfig
411 for(Int_t det=0; det<AliTRDgeometry::Ndet(); det++) {
412 ConfigureDyCorr(det);
413 ConfigureDRange(det); // deflection range
414 ConfigureNTimebins(det); // timebins in the drift region
415 ConfigurePIDcorr(det); // scaling parameters for the PID
416 }
417 break;
418
419 case 1: // set variables
420 switch (addr) {
421
422 case 0: ltuParam.SetPtMin(data); break; // pt_min in GeV/c (*1000)
423 case 1: ltuParam.SetMagField(data); break; // B in T (*1000)
424 case 2: ltuParam.SetOmegaTau(data); break; // omega*tau
425 case 3: ltuParam.SetNtimebins(data); break;
426 // ntimbins: drift time (for 3 cm) in timebins (5 add. bin. digits)
427 case 4: ltuParam.SetScaleQ0(data); break;
428 case 5: ltuParam.SetScaleQ1(data); break;
429 case 6: ltuParam.SetLengthCorrectionEnable(data); break;
430 case 7: ltuParam.SetTiltCorrectionEnable(data); break;
431 }
432 break;
433
434 default:
435 AliError(Form("dest %i not implemented", dest));
436 }
437
438}
439
440
441void AliTRDtrapConfigHandler::ConfigureNTimebins(Int_t det)
442{
443 //
444 // Set timebins in the drift region
445 //
446
447 if (!fTrapConfig) {
448 AliError("No TRAPconfig given");
449 return;
450 }
451
452 AddValues(det, fgkScsnCmdWrite, 127, AliTRDmcmSim::fgkDmemAddrNdrift, ltuParam.GetNtimebins());
453}
454
455
456
457void AliTRDtrapConfigHandler::ConfigureDyCorr(Int_t det)
458{
459 //
460 // Deflection length correction
461 // due to Lorentz angle and tilted pad correction
462 // This correction is in units of padwidth / (256*32)
463 //
464
465 if (!fTrapConfig) {
466 AliError("No TRAPconfig given");
467 return;
468 }
469
470 Int_t nRobs = AliTRDgeometry::GetStack(det) == 2 ? 6 : 8;
471
472 for (Int_t r = 0; r < nRobs; r++) {
473 for (Int_t m = 0; m < 16; m++) {
474 Int_t dest = 1<<10 | r<<7 | m;
475 Int_t dyCorrInt = ltuParam.GetDyCorrection(det, r, m);
476 AddValues(det, fgkScsnCmdWrite, dest, AliTRDmcmSim::fgkDmemAddrDeflCorr, dyCorrInt);
477 }
478 }
479}
480
481
482
483
484
485void AliTRDtrapConfigHandler::ConfigureDRange(Int_t det)
486{
487 //
488 // deflection range LUT
489 // range calculated according to B-field (in T) and pt_min (in GeV/c)
490 // if pt_min < 0.1 GeV/c the maximal allowed range for the tracklet
491 // deflection (-64..63) is used
492 //
493
494 if (!fTrapConfig) {
495 AliError("No TRAPconfig given");
496 return;
497 }
498
499 Int_t nRobs = AliTRDgeometry::GetStack(det) == 2 ? 6 : 8;
500
501 Int_t dyMinInt;
502 Int_t dyMaxInt;
503
504 for (Int_t r = 0; r < nRobs; r++) {
505 for (Int_t m = 0; m < 16; m++) {
506 for (Int_t c = 0; c < 18; c++) {
507
508 // cout << "maxdefl: " << maxDeflAngle << ", localPhi " << localPhi << endl;
509 // cout << "r " << r << ", m" << m << ", c " << c << ", min angle: " << localPhi-maxDeflAngle << ", max: " << localPhi+maxDeflAngle
510 // << ", min int: " << dyMinInt << ", max int: " << dyMaxInt << endl;
511 Int_t dest = 1<<10 | r<<7 | m;
512 Int_t lutAddr = AliTRDmcmSim::fgkDmemAddrDeflCutStart + 2*c;
513 ltuParam.GetDyRange(det, r, m, c, dyMinInt, dyMaxInt);
514 AddValues(det, fgkScsnCmdWrite, dest, lutAddr+0, dyMinInt);
515 AddValues(det, fgkScsnCmdWrite, dest, lutAddr+1, dyMaxInt);
516 }
517 }
518 }
519}
520
521void AliTRDtrapConfigHandler::PrintGeoTest()
522{
523 //
524 // Prints some information about the geometry. Only for debugging
525 //
526
527 int sm=0;
528 // for(int sm=0; sm<6; sm++) {
529 for(int stack=0; stack<5; stack++) {
530 for(int layer=0; layer<6; layer++) {
531
532 Int_t det = sm*30+stack*6+layer;
533 for (Int_t r = 0; r < 6; r++) {
534 for (Int_t m = 0; m < 16; m++) {
535 for (Int_t c = 7; c < 8; c++) {
536 cout << stack << ";" << layer << ";" << r << ";" << m
537 << ";" << ltuParam.GetX(det, r, m)
538 << ";" << ltuParam.GetLocalY(det, r, m, c)
539 << ";" << ltuParam.GetLocalZ(det, r, m) << endl;
540 }
541 }
542 }
543 }
544 }
545 // }
546}
547
548
549void AliTRDtrapConfigHandler::ConfigurePIDcorr(Int_t det)
550{
551 //
552 // Calculate the MCM individual correction factors for the PID
553 // and transfer them to AliTRDtrapConfig
554 //
555
556 if (!fTrapConfig) {
557 AliError("No TRAPconfig given");
558 return;
559 }
560
561 static const Int_t addrLUTcor0 = AliTRDmcmSim::fgkDmemAddrLUTcor0;
562 static const Int_t addrLUTcor1 = AliTRDmcmSim::fgkDmemAddrLUTcor1;
563
564 UInt_t cor0;
565 UInt_t cor1;
566
567 Int_t nRobs = AliTRDgeometry::GetStack(det) == 2 ? 6 : 8;
568
569 for (Int_t r=0; r<nRobs; r++) {
570 for(Int_t m=0; m<16; m++) {
571 Int_t dest = 1<<10 | r<<7 | m;
572 if(fGtbl.GetGainTableROC(det) && fGtbl.GetGainTableROC(det)->GetGainTableMCM(r, m))
573 ltuParam.GetCorrectionFactors(det, r, m, 9, cor0, cor1, fGtbl.GetGainTableROC(det)->GetGainTableMCM(r, m)->GetMCMGain());
574 else
575 ltuParam.GetCorrectionFactors(det, r, m, 9, cor0, cor1);
576 AddValues(det, fgkScsnCmdWrite, dest, addrLUTcor0, cor0);
577 AddValues(det, fgkScsnCmdWrite, dest, addrLUTcor1, cor1);
578 }
579 }
580}
581
582
583Bool_t AliTRDtrapConfigHandler::AddValues(UInt_t det, UInt_t cmd, UInt_t extali, Int_t addr, UInt_t data)
584{
585 // transfer the informations provided by LoadConfig to the internal class variables
586
587 if (!fTrapConfig) {
588 AliError("No TRAPconfig given");
589 return kFALSE;
590 }
591
592 if(cmd != fgkScsnCmdWrite) {
593 AliError(Form("Invalid command received: %i", cmd));
594 return kFALSE;
595 }
596
597 AliTRDtrapConfig::TrapReg_t mcmReg = fTrapConfig->GetRegByAddress(addr);
598 Int_t rocType = AliTRDgeometry::GetStack(det) == 2 ? 0 : 1;
599
600 static const int mcmListSize=40; // 40 is more or less arbitrary
601 Int_t mcmList[mcmListSize];
602
603 // configuration registers
604 if(mcmReg >= 0 && mcmReg < AliTRDtrapConfig::kLastReg) {
605
606 for(Int_t linkPair=0; linkPair<fgkMaxLinkPairs; linkPair++) {
607 if(AliTRDfeeParam::ExtAliToAli(extali, linkPair, rocType, mcmList, mcmListSize)!=0) {
608 Int_t i=0;
609 while(mcmList[i] != -1 && i<mcmListSize) {
610 if(mcmList[i]==127) {
611 AliDebug(1, Form("broadcast write to %s: 0x%08x",
612 fTrapConfig->GetRegName((AliTRDtrapConfig::TrapReg_t) mcmReg), data));
613 fTrapConfig->SetTrapReg( (AliTRDtrapConfig::TrapReg_t) mcmReg, data, det);
614 }
615 else {
616 AliDebug(1, Form("individual write to %s (%i, %i): 0x%08x",
617 fTrapConfig->GetRegName((AliTRDtrapConfig::TrapReg_t) mcmReg), (mcmList[i]>>7), (mcmList[i]&0x7F), data));
618 fTrapConfig->SetTrapReg( (AliTRDtrapConfig::TrapReg_t) mcmReg, data, det, (mcmList[i]>>7)&0x7, (mcmList[i]&0x7F));
619 }
620 i++;
621 }
622 }
623 }
624 return kTRUE;
625 }
626 // DMEM
627 else if ( (addr >= AliTRDtrapConfig::fgkDmemStartAddress) &&
628 (addr < (AliTRDtrapConfig::fgkDmemStartAddress + AliTRDtrapConfig::fgkDmemWords))) {
629 for(Int_t linkPair=0; linkPair<fgkMaxLinkPairs; linkPair++) {
630 if(AliTRDfeeParam::ExtAliToAli(extali, linkPair, rocType, mcmList, mcmListSize)!=0) {
631 Int_t i=0;
632 while(mcmList[i] != -1 && i < mcmListSize) {
633 if(mcmList[i] == 127)
634 fTrapConfig->SetDmem(addr, data, det, 0, 127);
635 else
636 fTrapConfig->SetDmem(addr, data, det, mcmList[i] >> 7, mcmList[i] & 0x7f);
637 i++;
638 }
639 }
640 }
641 return kTRUE;
642 }
643 else if ( (addr >= AliTRDtrapConfig::fgkImemStartAddress) &&
644 (addr < (AliTRDtrapConfig::fgkImemStartAddress + AliTRDtrapConfig::fgkImemWords))) {
645 // IMEM is ignored for now
646 return kTRUE;
647 }
648 else if ( (addr >= AliTRDtrapConfig::fgkDbankStartAddress) &&
649 (addr < (AliTRDtrapConfig::fgkDbankStartAddress + AliTRDtrapConfig::fgkImemWords))) {
650 // DBANK is ignored for now
651 return kTRUE;
652 }
653 else {
654 AliError(Form("Writing to unhandled address 0x%04x", addr));
655 return kFALSE;
656 }
657}