]>
Commit | Line | Data |
---|---|---|
ecf39416 | 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 | // This class provides access to TRD digits in raw data. // | |
21 | // // | |
22 | // It loops over all TRD digits in the raw data given by the AliRawReader. // | |
23 | // The Next method goes to the next digit. If there are no digits left // | |
24 | // it returns kFALSE. // | |
25 | // Several getters provide information about the current digit. // | |
26 | // // | |
27 | // Author: C. Lippmann (C.Lippmann@gsi.de) // | |
28 | // // | |
29 | /////////////////////////////////////////////////////////////////////////////// | |
30 | ||
31 | #include "AliLog.h" | |
32 | #include "AliRawReader.h" | |
0c349049 | 33 | |
ecf39416 | 34 | #include "AliTRDRawStreamV2.h" |
35 | #include "AliTRDgeometry.h" | |
36 | #include "AliTRDcalibDB.h" | |
37 | #include "AliTRDfeeParam.h" | |
ecf39416 | 38 | #include "AliTRDdigitsManager.h" |
39 | #include "AliTRDdataArrayI.h" | |
625f5260 | 40 | #include "AliTRDdataArrayS.h" |
ecf39416 | 41 | #include "AliTRDSignalIndex.h" |
42 | ||
ecf39416 | 43 | ClassImp(AliTRDRawStreamV2) |
44 | ||
45 | //_____________________________________________________________________________ | |
46 | AliTRDRawStreamV2::AliTRDRawStreamV2() | |
47 | :TObject() | |
0c349049 | 48 | ,fGeo(NULL) |
ecf39416 | 49 | ,fSig() |
50 | ,fADC(0) | |
51 | ,fTB(0) | |
52 | ,fEv(0) | |
53 | ,fROB(0) | |
54 | ,fMCM(0) | |
55 | ,fSM(0) | |
56 | ,fLAYER(0) | |
57 | ,fSTACK(0) | |
58 | ,fROC(0) | |
59 | ,fSIDE(0) | |
60 | ,fDCS(0) | |
61 | ,fROW(0) | |
62 | ,fCOL(0) | |
63 | ,fDET(0) | |
64 | ,fLastDET(-1) | |
65 | ,fBCctr(0) | |
66 | ,fPTctr(0) | |
67 | ,fPTphase(0) | |
68 | ,fRVmajor(0) | |
69 | ,fRVminor(0) | |
70 | ,fHCHWords(0) | |
71 | ,fTBins(0) | |
72 | ,fTCon(0) | |
73 | ,fPEDon(0) | |
74 | ,fGAINon(0) | |
75 | ,fXTon(0) | |
76 | ,fNonLinOn(0) | |
77 | ,fBypass(0) | |
78 | ,fCommonAdditive(0) | |
79 | ,fZeroSuppressed(0) | |
80 | ,fHCHctr1(0) | |
81 | ,fHCHctr2(0) | |
82 | ,fMCMHctr1(0) | |
83 | ,fMCMHctr2(0) | |
84 | ,fGTUctr1(0) | |
85 | ,fGTUctr2(0) | |
86 | ,fHCdataCtr(0) | |
87 | ,fTracklPID(0.) | |
88 | ,fTracklDefL(0.) | |
89 | ,fTracklPadPos(0.) | |
90 | ,fTracklPadRow(0) | |
91 | ,fGTUlinkMask() | |
92 | ,fMCMWordCrt(0) | |
93 | ,fMCMWordsExpected(0) | |
94 | ,fRawReader(NULL) | |
95 | ,fRawVersion(2) | |
96 | ,fRawDigitThreshold(0) | |
97 | ,fNextStatus(0) | |
98 | ,fLastStatus(0) | |
99 | ,fTbSwitch(0) | |
100 | ,fTbSwitchCtr(0) | |
101 | ,fTimeWords(0) | |
102 | ,fWordCtr(0) | |
103 | ,fRowMax(0) | |
104 | ,fColMax(0) | |
105 | ,fADCmask() | |
106 | ,fLastADCmask(0) | |
107 | ,fChamberDone() | |
108 | ,fRetVal(0) | |
109 | ,fEqID(0) | |
110 | ,fDataSize(0) | |
111 | ,fSizeOK(kFALSE) | |
112 | ,fCountBytes(0) | |
113 | ,fBufSize(0) | |
114 | ,fkBufferSet(kFALSE) | |
115 | ,fPos(NULL) | |
116 | ,fDataWord(NULL) | |
117 | ,fTimeBinsCalib(0) | |
118 | ,fADClookup() | |
119 | ,fNActiveADCs(0) | |
120 | ,fEndOfDataFlag(kFALSE) | |
ecf39416 | 121 | { |
122 | // | |
123 | // Default constructor | |
124 | // | |
125 | ||
126 | for (Int_t i = 0; i < 540; i++) { | |
127 | fChamberDone[i] = 0; | |
128 | } | |
129 | ||
130 | } | |
131 | ||
132 | //_____________________________________________________________________________ | |
133 | AliTRDRawStreamV2::AliTRDRawStreamV2(AliRawReader *rawReader) | |
134 | :TObject() | |
0c349049 | 135 | ,fGeo(NULL) |
ecf39416 | 136 | ,fADC(0) |
137 | ,fTB(0) | |
138 | ,fEv(0) | |
139 | ,fROB(0) | |
140 | ,fMCM(0) | |
141 | ,fSM(0) | |
142 | ,fLAYER(0) | |
143 | ,fSTACK(0) | |
144 | ,fROC(0) | |
145 | ,fSIDE(0) | |
146 | ,fDCS(0) | |
147 | ,fROW(0) | |
148 | ,fCOL(0) | |
149 | ,fDET(0) | |
150 | ,fLastDET(-1) | |
151 | ,fBCctr(0) | |
152 | ,fPTctr(0) | |
153 | ,fPTphase(0) | |
154 | ,fRVmajor(0) | |
155 | ,fRVminor(0) | |
156 | ,fHCHWords(0) | |
157 | ,fTBins(0) | |
158 | ,fTCon(0) | |
159 | ,fPEDon(0) | |
160 | ,fGAINon(0) | |
161 | ,fXTon(0) | |
162 | ,fNonLinOn(0) | |
163 | ,fBypass(0) | |
164 | ,fCommonAdditive(0) | |
165 | ,fZeroSuppressed(0) | |
166 | ,fHCHctr1(0) | |
167 | ,fHCHctr2(0) | |
168 | ,fMCMHctr1(0) | |
169 | ,fMCMHctr2(0) | |
170 | ,fGTUctr1(0) | |
171 | ,fGTUctr2(0) | |
172 | ,fHCdataCtr(0) | |
173 | ,fTracklPID(0.) | |
174 | ,fTracklDefL(0.) | |
175 | ,fTracklPadPos(0.) | |
176 | ,fTracklPadRow(0) | |
177 | ,fGTUlinkMask() | |
178 | ,fMCMWordCrt(0) | |
179 | ,fMCMWordsExpected(0) | |
180 | ,fRawReader(rawReader) | |
181 | ,fRawVersion(2) | |
182 | ,fRawDigitThreshold(0) | |
183 | ,fNextStatus(0) | |
184 | ,fLastStatus(0) | |
185 | ,fTbSwitch(0) | |
186 | ,fTbSwitchCtr(0) | |
187 | ,fTimeWords(0) | |
188 | ,fWordCtr(0) | |
189 | ,fRowMax(0) | |
190 | ,fColMax(0) | |
191 | ,fADCmask() | |
192 | ,fLastADCmask(0) | |
193 | ,fChamberDone() | |
194 | ,fRetVal(0) | |
195 | ,fEqID(0) | |
196 | ,fDataSize(0) | |
197 | ,fSizeOK(kFALSE) | |
198 | ,fCountBytes(0) | |
199 | ,fBufSize(0) | |
200 | ,fkBufferSet(kFALSE) | |
201 | ,fPos(NULL) | |
202 | ,fDataWord(NULL) | |
203 | ,fTimeBinsCalib(0) | |
204 | ,fADClookup() | |
205 | ,fNActiveADCs(0) | |
206 | ,fEndOfDataFlag(kFALSE) | |
ecf39416 | 207 | { |
208 | // | |
209 | // Create an object to read TRD raw digits | |
210 | // | |
211 | ||
212 | fRawReader->Select("TRD"); | |
213 | ||
214 | for (Int_t i = 0; i < 540; i++) { | |
215 | fChamberDone[i] = 0; | |
216 | } | |
217 | ||
218 | } | |
219 | ||
220 | //_____________________________________________________________________________ | |
221 | AliTRDRawStreamV2::AliTRDRawStreamV2(const AliTRDRawStreamV2& stream) | |
222 | :TObject(stream) | |
0c349049 | 223 | ,fGeo(NULL) |
ecf39416 | 224 | ,fSig() |
225 | ,fADC(-1) | |
226 | ,fTB(-1) | |
227 | ,fEv(-1) | |
228 | ,fROB(-1) | |
229 | ,fMCM(-1) | |
230 | ,fSM(-1) | |
231 | ,fLAYER(-1) | |
232 | ,fSTACK(-1) | |
233 | ,fROC(-1) | |
234 | ,fSIDE(-1) | |
235 | ,fDCS(-1) | |
236 | ,fROW(-1) | |
237 | ,fCOL(-1) | |
238 | ,fDET(0) | |
239 | ,fLastDET(-1) | |
240 | ,fBCctr(-1) | |
241 | ,fPTctr(-1) | |
242 | ,fPTphase(-1) | |
243 | ,fRVmajor(-1) | |
244 | ,fRVminor(-1) | |
245 | ,fHCHWords(-1) | |
246 | ,fTBins(-1) | |
247 | ,fTCon(0) | |
248 | ,fPEDon(0) | |
249 | ,fGAINon(0) | |
250 | ,fXTon(0) | |
251 | ,fNonLinOn(-1) | |
252 | ,fBypass(-1) | |
253 | ,fCommonAdditive(-1) | |
254 | ,fZeroSuppressed(0) | |
255 | ,fHCHctr1(-1) | |
256 | ,fHCHctr2(-1) | |
257 | ,fMCMHctr1(-1) | |
258 | ,fMCMHctr2(-1) | |
259 | ,fGTUctr1(-1) | |
260 | ,fGTUctr2(-1) | |
261 | ,fHCdataCtr(-1) | |
262 | ,fTracklPID(-1.) | |
263 | ,fTracklDefL(-1.) | |
264 | ,fTracklPadPos(-1.) | |
265 | ,fTracklPadRow(-1) | |
266 | ,fGTUlinkMask() | |
267 | ,fMCMWordCrt(0) | |
268 | ,fMCMWordsExpected(0) | |
269 | ,fRawReader(NULL) | |
270 | ,fRawVersion(-1) | |
271 | ,fRawDigitThreshold(0) | |
272 | ,fNextStatus(0) | |
273 | ,fLastStatus(0) | |
274 | ,fTbSwitch(0) | |
275 | ,fTbSwitchCtr(0) | |
276 | ,fTimeWords(0) | |
277 | ,fWordCtr(0) | |
278 | ,fRowMax(-1) | |
279 | ,fColMax(-1) | |
280 | ,fADCmask() | |
281 | ,fLastADCmask(0) | |
282 | ,fChamberDone() | |
283 | ,fRetVal(0) | |
284 | ,fEqID(0) | |
285 | ,fDataSize(0) | |
286 | ,fSizeOK(kFALSE) | |
287 | ,fCountBytes(0) | |
288 | ,fBufSize(0) | |
289 | ,fkBufferSet(kFALSE) | |
290 | ,fPos(NULL) | |
291 | ,fDataWord(NULL) | |
292 | ,fTimeBinsCalib(0) | |
293 | ,fADClookup() | |
294 | ,fNActiveADCs(0) | |
295 | ,fEndOfDataFlag(kFALSE) | |
ecf39416 | 296 | { |
297 | // | |
298 | // Copy constructor | |
299 | // | |
300 | ||
301 | AliFatal("Copy constructor not implemented"); | |
302 | ||
303 | } | |
304 | ||
305 | //_____________________________________________________________________________ | |
306 | AliTRDRawStreamV2& AliTRDRawStreamV2::operator = (const AliTRDRawStreamV2& | |
307 | /* stream */) | |
308 | { | |
309 | // | |
310 | // Assigment operator | |
311 | // | |
312 | ||
313 | Fatal("operator =", "assignment operator not implemented"); | |
314 | return *this; | |
315 | ||
316 | } | |
317 | ||
318 | //_____________________________________________________________________________ | |
319 | AliTRDRawStreamV2::~AliTRDRawStreamV2() | |
320 | { | |
321 | // | |
322 | // Destructor | |
323 | // | |
324 | ||
325 | if (fGeo) { | |
326 | delete fGeo; | |
327 | } | |
328 | ||
329 | } | |
330 | ||
331 | //_____________________________________________________________________________ | |
332 | void AliTRDRawStreamV2::SetRawReader(AliRawReader *rawReader) | |
333 | { | |
334 | // | |
335 | // Set the rawreader | |
336 | // | |
337 | ||
338 | if (rawReader) | |
339 | { | |
340 | fRawReader = rawReader; | |
341 | } | |
342 | } | |
343 | ||
344 | //_____________________________________________________________________________ | |
345 | Bool_t AliTRDRawStreamV2::SetRawVersion(Int_t rv) | |
346 | { | |
347 | // | |
348 | // Set the raw data version | |
349 | // | |
350 | ||
351 | if ( rv >= 0 && rv <= 3 ) { | |
352 | fRawVersion = rv; | |
353 | return kTRUE; | |
354 | } | |
355 | ||
356 | return kFALSE; | |
357 | ||
358 | } | |
359 | ||
ecf39416 | 360 | //____________________________________________________________________________ |
361 | Int_t AliTRDRawStreamV2::Init() | |
362 | { | |
363 | // | |
364 | // Initialization | |
365 | // | |
366 | ||
367 | if (!AliTRDcalibDB::Instance()) { | |
368 | AliError("Could not get calibration object"); | |
369 | return 0; | |
370 | } | |
371 | ||
372 | if (!fGeo) { | |
373 | fGeo = new AliTRDgeometry(); | |
374 | } | |
375 | ||
376 | fTimeBinsCalib = AliTRDcalibDB::Instance()->GetNumberOfTimeBins(); | |
377 | //AliDebug(2, Form("Number of Timebins read from CDB: %d", fTimeBinsCalib)); | |
378 | ||
379 | // The number of data words needed for this number of time bins (there | |
380 | // are 3 time bins in one word) | |
381 | fTimeWords = (fTimeBinsCalib-1)/3 + 1; | |
382 | ||
383 | fTbSwitch = 3; | |
384 | fTbSwitchCtr = 0; | |
385 | ||
386 | fHCHctr1 = fHCHctr2 = 0; | |
387 | fGTUctr1 = fGTUctr2 = -1; | |
388 | ||
389 | fHCdataCtr = 0; | |
390 | fWordCtr = 0; | |
391 | ||
392 | fDET = 0; | |
393 | fLastDET = -1; | |
394 | fRetVal = 0; | |
395 | fEqID = 0; | |
396 | fDataSize = 0; | |
397 | fSizeOK = kFALSE; | |
398 | ||
0c349049 | 399 | fLastStatus = kStart; |
400 | fNextStatus = kStart; | |
ecf39416 | 401 | |
402 | fCountBytes = 0; | |
403 | fBufSize = 0; | |
404 | fDataWord = NULL; | |
405 | fPos = NULL; | |
406 | fWordCtr = 0; | |
407 | fkBufferSet = kFALSE; | |
408 | ||
409 | fMCMWordCrt = 0; | |
410 | fMCMWordsExpected = 0; | |
411 | ||
412 | fEndOfDataFlag = kFALSE; | |
413 | // set all ADC active | |
0c349049 | 414 | // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20) |
415 | fNActiveADCs = ChannelsToRead(0x1fffff); | |
ecf39416 | 416 | |
417 | fLastADCmask = 0; | |
418 | ||
419 | return kTRUE; | |
420 | } | |
421 | ||
33dd2de9 | 422 | //____________________________________________________________________________ |
423 | void AliTRDRawStreamV2::SwapOnEndian() | |
424 | { | |
425 | // | |
426 | // Check the endian and swap if needed | |
427 | // | |
428 | ||
429 | int itemp = 1; | |
430 | char* ptemp = (char*) &itemp; | |
431 | if (ptemp[0] != 1) | |
432 | { | |
433 | // need to swap... | |
434 | // assume we are at the begining of the buffer! | |
435 | //AliDebug(5, "Swapping."); | |
436 | UInt_t *pbegin = (UInt_t*)fPos; | |
437 | UInt_t iutmp = 0; | |
438 | for (UInt_t i = 0; i < fBufSize / fgkSizeWord; i++) | |
439 | { | |
440 | fDataWord = pbegin + i; | |
441 | iutmp = (((*fDataWord & 0x000000ffU) << 24) | ((*fDataWord & 0x0000ff00U) << 8) | | |
442 | ((*fDataWord & 0x00ff0000U) >> 8) | ((*fDataWord & 0xff000000U) >> 24)); | |
443 | // here we override the value in the buffer! | |
444 | *fDataWord = iutmp; | |
445 | } | |
446 | fDataWord = pbegin; | |
447 | } | |
448 | } | |
ecf39416 | 449 | //____________________________________________________________________________ |
450 | Int_t AliTRDRawStreamV2::NextData() | |
451 | { | |
452 | // | |
453 | // Updates the next data word pointer | |
454 | // | |
455 | ||
0c349049 | 456 | if (fCountBytes + fgkSizeWord >= fBufSize) |
ecf39416 | 457 | { |
458 | fkBufferSet = fRawReader->ReadNextData(fPos); | |
459 | if (fkBufferSet == kTRUE) | |
460 | { | |
461 | fBufSize = fRawReader->GetDataSize(); | |
462 | fCountBytes = 0; | |
463 | fDataWord = (UInt_t*)fPos; | |
33dd2de9 | 464 | SwapOnEndian(); |
0c349049 | 465 | ChangeStatus(kNextSM); |
ecf39416 | 466 | fWordCtr = 0; |
0c349049 | 467 | return kNextSM; |
ecf39416 | 468 | } |
469 | else | |
470 | { | |
0c349049 | 471 | ChangeStatus(kStop); |
472 | return kNoMoreData; | |
ecf39416 | 473 | } |
474 | } | |
475 | else | |
476 | { | |
0c349049 | 477 | fPos += fgkSizeWord; |
478 | fCountBytes += fgkSizeWord; | |
ecf39416 | 479 | fDataWord = (UInt_t*)fPos; |
480 | fWordCtr++; | |
0c349049 | 481 | return kWordOK; |
ecf39416 | 482 | } |
483 | } | |
484 | ||
485 | //============================================================================ | |
486 | // Decoding functions | |
487 | //============================================================================ | |
488 | ||
ecf39416 | 489 | //____________________________________________________________________________ |
490 | void AliTRDRawStreamV2::DecodeHCheader(Int_t timeBins) | |
491 | { | |
492 | // | |
493 | // Decode the HC header (fRawVersion == 2, 3, 4, ???) | |
494 | // | |
495 | ||
496 | fRVmajor = (*fDataWord >> 24) & 0x7f; | |
497 | fRVminor = (*fDataWord >> 17) & 0x7f; | |
498 | ||
499 | if (fRVmajor < 2 || fRVmajor > 4) | |
500 | AliError(Form(" Unsupported raw version: %d", fRawVersion)) | |
501 | ||
502 | if ( fRawVersion != fRVmajor ) { | |
503 | ||
504 | AliWarning("==============================================================================="); | |
505 | AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)" | |
506 | ,fRawVersion,fRVmajor)); | |
507 | AliWarning(Form("Setting fRawVersion to %d", fRVmajor)); | |
508 | AliWarning("==============================================================================="); | |
509 | fRawVersion = fRVmajor; | |
510 | ||
511 | } | |
512 | ||
513 | // | |
514 | // check for zero suppression | |
515 | if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE; | |
516 | else fZeroSuppressed = kFALSE; | |
517 | ||
518 | // 1st word (h[0]) | |
519 | if ( (*fDataWord & 0x3) == 1 ) { | |
520 | ||
521 | fHCHWords = (*fDataWord >> 14) & 0x7; | |
522 | fSM = (*fDataWord >> 9) & 0x1f; | |
523 | fLAYER = (*fDataWord >> 6) & 0x7; | |
524 | fSTACK = (*fDataWord >> 3) & 0x7; | |
525 | fSIDE = (*fDataWord >> 2) & 0x1; | |
526 | ||
527 | fROC = fGeo->GetDetectorSec(fLAYER, fSTACK); | |
528 | ||
529 | //AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", *fDataWord, fSM, fROC, fSIDE+10)); | |
530 | //AliDebug(5, Form("0x%08x: HC header: expecting %d HC words", *fDataWord, fHCHWords)); | |
531 | ||
532 | if ((fSM < 0) || | |
533 | (fSM > 17) || | |
534 | (fLAYER < 0) || | |
535 | (fLAYER > 5) || | |
536 | (fSTACK < 0) || | |
537 | (fSTACK > 4) || | |
538 | (fSIDE < 0) || | |
539 | (fSIDE > 1)) | |
540 | { | |
541 | AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.", | |
542 | *fDataWord, fDCS, fSM, fLAYER, fSTACK)); | |
543 | fRawReader->AddMajorErrorLog(kHCHeaderCorrupt,Form("0x%08x:dcs=%d; sm=%d; layer=%d; stack=%d.", | |
544 | *fDataWord, fDCS, fSM, fLAYER, fSTACK)); | |
545 | } | |
546 | else | |
547 | { | |
548 | fHCHctr1++; | |
549 | fHCHctr2++; | |
550 | } | |
551 | } | |
552 | else | |
553 | { | |
554 | AliWarning(Form("0x%08x: No HC header when it was expected.", *fDataWord)); | |
555 | fRawReader->AddMajorErrorLog(kHCHeaderMissing,Form("0x%08x", *fDataWord)); | |
556 | } | |
557 | ||
558 | // 2nd word (h[1]) | |
559 | if ( fHCHWords >= 1 ) | |
560 | { | |
561 | // read one more word | |
0c349049 | 562 | if (NextData() != kWordOK) |
ecf39416 | 563 | { |
564 | AliWarning("Next HC word missing"); | |
565 | fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing"); | |
0c349049 | 566 | fNextStatus = kNextHC; |
ecf39416 | 567 | return; |
568 | } | |
569 | ||
570 | if ( (*fDataWord & 0x3) == 1 ) | |
571 | { | |
572 | ||
573 | fBCctr = (*fDataWord >> 16); | |
574 | fPTctr = (*fDataWord >> 12) & 0xf; | |
575 | fPTphase = (*fDataWord >> 8) & 0xf; | |
576 | fTBins = ((*fDataWord >> 2) & 0x3f) + 1; | |
577 | fTimeWords = (fTBins - 1)/3 + 1; | |
578 | ||
579 | // AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d" | |
580 | // , *fDataWord, fBCctr, fPTctr, fPTphase, fTBins)); | |
581 | ||
582 | if( fTBins != timeBins ) | |
583 | { | |
584 | AliWarning("==============================================================================="); | |
585 | AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)" | |
586 | , timeBins, fTBins)); | |
587 | AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins)); | |
588 | AliWarning("==============================================================================="); | |
589 | ||
590 | fTimeWords = (fTBins - 1)/3 + 1; | |
591 | } | |
592 | } | |
593 | } | |
594 | ||
595 | // 3nd word (h[2]) | |
596 | if ( fHCHWords >= 2 ) { | |
597 | // read one more word | |
0c349049 | 598 | if (NextData() != kWordOK) |
ecf39416 | 599 | { |
600 | AliWarning("Next HC word missing"); | |
601 | fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing"); | |
0c349049 | 602 | fNextStatus = kNextHC; |
ecf39416 | 603 | return; |
604 | } | |
605 | if ( (*fDataWord & 0x3) == 1 ) { | |
606 | ||
607 | fTCon = (*fDataWord >> 29) & 0x1; | |
608 | fPEDon = (*fDataWord >> 31) & 0x1; | |
609 | fGAINon = (*fDataWord >> 30) & 0x1; | |
610 | fXTon = (*fDataWord >> 28) & 0x1; | |
611 | fNonLinOn = (*fDataWord >> 27) & 0x1; | |
612 | fBypass = (*fDataWord >> 26) & 0x1; | |
613 | ||
614 | fCommonAdditive = (*fDataWord >> 20) & 0x3f; | |
615 | ||
616 | // AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d" | |
617 | // , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive)); | |
618 | } | |
619 | } | |
620 | ||
621 | } | |
622 | ||
623 | //____________________________________________________________________________ | |
624 | Int_t AliTRDRawStreamV2::ChannelsToRead(Int_t ADCmask) | |
625 | { | |
0c349049 | 626 | // |
627 | // Return the channels to read | |
628 | // | |
629 | ||
ecf39416 | 630 | memset(fADClookup, -1, 32 * sizeof(Int_t)); |
631 | fADClookup[0] = 0; // count entries | |
632 | fADClookup[1] = 2; // index - data start at 2 | |
633 | UInt_t mask = 0; | |
634 | for (Int_t i = 0; i < 30; i++) | |
635 | { | |
636 | mask = 1 << i; | |
637 | if ((ADCmask & mask)) | |
638 | { | |
639 | //AliDebug(9, Form("fDataWord=0x%08x mask=0x%08x i=%d", *fDataWord, mask, i)); | |
640 | fADClookup[fADClookup[1]] = i; | |
641 | ++fADClookup[0]; | |
642 | ++fADClookup[1]; | |
643 | } | |
644 | } | |
645 | ||
646 | // test the iteration - comment out for production | |
647 | // begin of comment out section | |
648 | char schannels[512]; | |
649 | sprintf(schannels, "ADC Channels to read: "); | |
650 | fADClookup[1] = 2; | |
651 | while(fADClookup[1] - 2 < fADClookup[0]) | |
652 | { | |
653 | //AliDebug(9, Form("max=%d index=%d adc=%d", fADClookup[0], fADClookup[1], fADClookup[fADClookup[1]])); | |
654 | strcat(schannels, Form("%d ", fADClookup[fADClookup[1]])); | |
655 | fADClookup[1]++; | |
656 | } | |
657 | //AliDebug(9, Form("%s", schannels)); | |
658 | //AliDebug(9, Form("ADC channels = %d", fADClookup[0])); | |
659 | // end of comment out section | |
660 | ||
661 | fADClookup[1] = 2; | |
662 | return fADClookup[0]; | |
663 | } | |
664 | ||
665 | //____________________________________________________________________________ | |
666 | void AliTRDRawStreamV2::DecodeTracklet() | |
667 | { | |
ecf39416 | 668 | // |
669 | // Decode the Tracklet | |
670 | // | |
671 | // this function is not tested yet on real tracklets | |
672 | // | |
673 | ||
674 | if ( fRawVersion < 1 || fRawVersion > 3 ) | |
675 | { | |
676 | AliError(Form(" Unsupported raw version: %d", fRawVersion)); | |
677 | } | |
678 | ||
679 | fTracklPID = (*fDataWord >> 24) & 0xff; | |
680 | fTracklPadRow = (*fDataWord >> 20) & 0xf; // 0:15 | |
681 | fTracklDefL = (*fDataWord >> 13) & 0x7f; | |
682 | fTracklPadPos = (*fDataWord) & 0x1fff; | |
683 | ||
684 | fTracklPID /= (Float_t)((1<<8) - 1); // 0:1 (steps of 0.39%) | |
685 | fTracklDefL = (fTracklDefL - ((1<< 7)-1)/2.) * 140.e-4; // -0.889:0.889cm | |
686 | fTracklPadPos = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm | |
687 | ||
688 | //AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f" | |
689 | // , *fDataWord, fSM, fLAYER, fSTACK, fSIDE+10 | |
690 | // , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID)); | |
691 | ||
692 | if( (fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0()) || | |
693 | (fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1()) ) { | |
694 | AliWarning(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow)); | |
695 | fRawReader->AddMajorErrorLog(kTrackletRowMismatch,Form("Word: %d", fTracklPadRow)); | |
696 | } | |
697 | ||
698 | } | |
699 | ||
700 | //____________________________________________________________________________ | |
701 | void AliTRDRawStreamV2::DecodeMCMheader() | |
702 | { | |
ecf39416 | 703 | // |
704 | // Decode the MCM header | |
705 | // | |
706 | ||
707 | if ( fRawVersion < 1 || fRawVersion > 3 ) | |
708 | { | |
709 | AliError(Form(" Unsupported raw version: %d", fRawVersion)); | |
710 | } | |
711 | ||
712 | fMCM = (*fDataWord & 0xff000000) >> 24; | |
713 | fEv = (*fDataWord & 0x00fffff0) >> 4; | |
714 | ||
715 | fROB = fMCM / 16; | |
716 | fMCM = fMCM % 16; | |
717 | ||
718 | fROW = AliTRDfeeParam::Instance()->GetPadRowFromMCM(fROB, fMCM); | |
719 | ||
720 | // AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d" | |
721 | // , *fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv)); | |
722 | ||
723 | if ( fROB % 2 == 0 && fSIDE == 1 ) { | |
724 | AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d" | |
725 | , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM )); | |
726 | fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d" | |
727 | , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM )); | |
728 | } | |
729 | if ( fROB % 2 != 0 && fSIDE == 0 ) { | |
730 | AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d" | |
731 | , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM )); | |
732 | fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d" | |
733 | , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM )); | |
734 | } | |
735 | if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) || | |
736 | (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) { | |
737 | AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d" | |
738 | , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM )); | |
739 | fRawReader->AddMajorErrorLog(kWrongPadrow,Form("SM%d L%dS%d: Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d" | |
740 | , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM )); | |
741 | } | |
742 | ||
743 | fMCMHctr1++; | |
744 | fMCMHctr2++; | |
745 | ||
746 | fMCMWordCrt = 1; // MCM header | |
747 | ||
748 | // AdcMask for Zero supressed data | |
749 | if ( fRawVersion == 3 ) | |
750 | { | |
751 | // read one more word | |
0c349049 | 752 | if (NextData() != kWordOK) |
ecf39416 | 753 | { |
754 | AliWarning("MCM ADC mask missing"); | |
755 | fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing"); | |
0c349049 | 756 | fNextStatus = kNextHC; |
ecf39416 | 757 | return; |
758 | } | |
759 | else | |
760 | { | |
761 | ++fMCMWordCrt; | |
762 | ||
763 | for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) { | |
764 | if ( (*fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE; | |
765 | else fADCmask[ctr] = kFALSE; | |
766 | } | |
767 | ||
768 | //AliDebug(4, Form("0x%08x: ADC mask", *fDataWord)); | |
769 | fNActiveADCs = ChannelsToRead(*fDataWord); | |
770 | } | |
771 | } | |
772 | ||
773 | if (fRawVersion <= 2) | |
774 | { | |
775 | // no zero suppression | |
776 | // raw version 2: | |
777 | // 1 MCM header + 21 * ( Ntimebin/3) | |
778 | // If NTimebin = 30, it is 211 words. | |
779 | //fMCMWordsExpected = 1 + 21 * (fTBins / 3); | |
780 | //fNActiveADCs = 21; | |
781 | fNActiveADCs = ChannelsToRead(0x1fffff); // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20) | |
782 | //fMCMWordsExpected = 1 + fNActiveADCs * ((fTBins-1) / 3. + 1.); | |
783 | //directly get it like that: | |
784 | fMCMWordsExpected = 1 + fNActiveADCs * fTBins / 3; | |
785 | } | |
786 | ||
787 | if (fRawVersion >= 3) | |
788 | { | |
789 | // raw version 3: | |
790 | // 1 MCM header + 1 ADC mask + NofActiveADCs * ( Ntimebin/3 ) | |
791 | //directly get it like that: | |
792 | fMCMWordsExpected = 1 + 1 + (fTBins * fNActiveADCs) / 3; | |
793 | } | |
794 | ||
795 | //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt)); | |
796 | } | |
797 | //____________________________________________________________________________ | |
798 | Bool_t AliTRDRawStreamV2::DecodeNextRawWord() | |
799 | { | |
0c349049 | 800 | // |
801 | // Decode the next raw data word | |
802 | // | |
803 | ||
ecf39416 | 804 | //AliDebug(8, Form("-----------------------------------------")); |
805 | //AliDebug(8, Form("DATA IS 0x%x", *fDataWord)); | |
806 | ||
807 | if (fADClookup[1] - 2 > fADClookup[0]) | |
808 | { | |
809 | // AliDebug(8, Form("Overflow Index ADC = %d Max Index = %d Value = %d. Done with ADCs in this MCM. Is this already MCM header 0x%x?", | |
810 | // fADClookup[1] - 2, fADClookup[0], fADClookup[fADClookup[1]], *fDataWord)); | |
811 | fTbSwitchCtr = 0; | |
812 | fMCMWordsExpected = 0; | |
813 | AliWarning("Trying to recover. Fall back to DecodeMCM."); | |
814 | DecodeMCM(); | |
0c349049 | 815 | //ChangeStatus(kNextMCM); |
ecf39416 | 816 | return kFALSE; |
817 | } | |
818 | ||
819 | if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) { | |
820 | AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord)); | |
821 | fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord)); | |
822 | fMCMWordsExpected = 0; | |
823 | AliWarning("Trying to recover. Fall back to DecodeMCM."); | |
824 | DecodeMCM(); | |
0c349049 | 825 | //ChangeStatus(kNextMCM); |
ecf39416 | 826 | return kFALSE; |
827 | } | |
828 | ||
f4611d14 | 829 | if ( (*fDataWord & 0x3) != fLastADCmask || fTbSwitchCtr > fTimeWords) |
ecf39416 | 830 | { |
831 | fADC = fADClookup[fADClookup[1]]; | |
832 | // AliDebug(8, Form("Next fADC = %d at index = %d MCM Word Number: %d Max MCM Words is %d", | |
833 | // fADC, fADClookup[1] - 2, fMCMWordCrt, fMCMWordsExpected)); | |
834 | ++fADClookup[1]; | |
835 | fTB = 0; | |
f4611d14 | 836 | fTbSwitchCtr = 0; |
0c349049 | 837 | fLastStatus = kNextData; |
ecf39416 | 838 | fLastADCmask = (*fDataWord) & 0x3; |
839 | } | |
840 | ||
f4611d14 | 841 | ++fTbSwitchCtr; |
842 | ||
ecf39416 | 843 | //decode data here |
844 | Bool_t kIsDataOK = kFALSE; | |
845 | ||
846 | // We have only 21 ADC channels. | |
847 | if ( fADC > (Int_t)fGeo->ADCmax() - 1 ) | |
848 | { | |
849 | AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC)); | |
850 | fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC)); | |
851 | } | |
852 | else | |
853 | { | |
854 | // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other | |
855 | // MCMs and are good for online tracking in the MCM. | |
856 | if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax() - 1 ) | |
857 | { | |
858 | ||
859 | // Get Pad column | |
860 | // fCOL = fFee->GetPadColFromADC(fROB, fMCM, fADC); | |
861 | fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fROB, fMCM, fADC); | |
862 | ||
863 | // We have only 144 Pad Columns | |
864 | //if ( fCOL > fColMax-1 || fCOL < 0 ) | |
865 | if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax ) | |
866 | { | |
867 | // Decode 32 bit data words with information from 3 time bins and copy the data | |
868 | fSig[0] = (*fDataWord & 0x00000ffc) >> 2; | |
869 | fSig[1] = (*fDataWord & 0x003ff000) >> 12; | |
870 | fSig[2] = (*fDataWord & 0xffc00000) >> 22; | |
871 | ||
872 | // Print data to screen: | |
873 | //AliDebug(5, Form("DATA : 0x%x", *fDataWord)); | |
874 | // AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n", | |
875 | // fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2])); | |
876 | kIsDataOK = kTRUE; | |
877 | } | |
878 | else | |
879 | { | |
880 | AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM, | |
881 | fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM )); | |
882 | fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM, | |
883 | fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM )); | |
884 | kIsDataOK = kFALSE; | |
885 | } | |
886 | } | |
887 | else | |
888 | { | |
889 | //AliDebug(5, Form("fADC not accepted %d - DATA : 0x%x", fADC, *fDataWord)); | |
890 | fCOL = -1; | |
891 | kIsDataOK = kFALSE; | |
892 | } | |
893 | }// if fADC is ok | |
894 | ||
895 | ++fMCMWordCrt; | |
896 | //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt)); | |
897 | ||
898 | // all mcm data processed go to next one | |
899 | if ( fMCMWordCrt >= fMCMWordsExpected) | |
900 | { | |
0c349049 | 901 | ChangeStatus(kNextMCM); |
ecf39416 | 902 | } |
903 | ||
904 | return kIsDataOK; | |
905 | } | |
906 | ||
907 | //____________________________________________________________________________ | |
908 | Bool_t AliTRDRawStreamV2::DecodeMCM() | |
909 | { | |
0c349049 | 910 | // |
911 | // Decode a single MCM | |
912 | // | |
913 | ||
ecf39416 | 914 | if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) ) |
915 | { // MCM Header | |
916 | DecodeMCMheader(); | |
917 | if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 ) | |
918 | { | |
919 | AliWarning("Wrong fMCM or fROB. Skip this data"); | |
920 | fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB)); | |
0c349049 | 921 | ChangeStatus(kNextHC); |
ecf39416 | 922 | return kFALSE; |
923 | } | |
924 | ||
925 | fTbSwitch = 3; // For first adc channel we expect: (*fDataWord & 3) = 3 | |
926 | fTbSwitchCtr = 0; // | |
927 | fADC = fTB = 0; // Reset Counter | |
928 | fLastADCmask = 0; // Reset | |
929 | ||
930 | if (fMCMWordCrt < fMCMWordsExpected) | |
931 | { | |
0c349049 | 932 | ChangeStatus(kNextData); |
ecf39416 | 933 | } |
934 | else | |
935 | { | |
0c349049 | 936 | ChangeStatus(kNextMCM); |
ecf39416 | 937 | } |
938 | return kTRUE; | |
939 | } | |
940 | ||
0c349049 | 941 | if ( *fDataWord == fgkEndofrawdatamarker ) |
ecf39416 | 942 | { // End of half-chamber data, finished |
943 | fGTUctr1 = -1; | |
0c349049 | 944 | ChangeStatus(kNextHC); |
ecf39416 | 945 | fEndOfDataFlag = kTRUE; |
946 | //AliDebug(5, "Expecting MCM header but got End-Of-Raw-Data Marker"); | |
947 | if (fMCMWordsExpected == 0 || fMCMWordsExpected == fMCMWordCrt) | |
948 | return kTRUE; | |
949 | else | |
950 | { | |
951 | //AliDebug(5, Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt)); | |
952 | //AliWarning(Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt)); | |
953 | return kFALSE; | |
954 | } | |
955 | } | |
956 | ||
957 | //AliDebug(3, Form("Expecting MCM header but got 0x%x. Going to Next MCM header.", *fDataWord)); | |
958 | AliWarning(Form("Expecting MCM header but got 0x%x. Fall back: Next MCM header.", *fDataWord)); | |
0c349049 | 959 | ChangeStatus(kNextMCM); |
ecf39416 | 960 | |
961 | return kFALSE; | |
962 | } | |
963 | ||
964 | //____________________________________________________________________________ | |
965 | Bool_t AliTRDRawStreamV2::DecodeHC() | |
966 | { | |
0c349049 | 967 | // |
968 | // Decode a half chamber | |
969 | // | |
970 | ||
971 | if ( fNextStatus == kNextHC ) | |
ecf39416 | 972 | { |
0c349049 | 973 | //AliDebug(5, "kNextHC"); |
ecf39416 | 974 | // |
975 | // 1) Find end_of_tracklet_marker | |
976 | // | |
977 | // GTU Link Mask? | |
978 | if (DecodeGTUlinkMask()) | |
979 | { | |
980 | return kTRUE; | |
981 | } | |
982 | ||
983 | // endoftrackletmarker? | |
0c349049 | 984 | if ( *fDataWord == fgkEndoftrackletmarker ) |
ecf39416 | 985 | { |
986 | //AliDebug(3, "End-of-tracklet-marker found"); | |
987 | //AliDebug(5, Form("Data 0x%x", *fDataWord)); | |
0c349049 | 988 | ChangeStatus(kSeekNonEoTracklet); |
ecf39416 | 989 | return kTRUE; |
990 | } | |
991 | else | |
992 | { | |
993 | // Tracklets found | |
994 | //AliDebug(3, "Tracklet found"); | |
995 | //AliDebug(5, Form("Tracklet data 0x%x", *fDataWord)); | |
996 | DecodeTracklet(); | |
997 | return kTRUE; | |
998 | } | |
999 | } // if next HC | |
1000 | ||
0c349049 | 1001 | if (fNextStatus == kSeekNonEoTracklet) |
ecf39416 | 1002 | { |
0c349049 | 1003 | //AliDebug(5, "kSeekNonEoTracklet"); |
ecf39416 | 1004 | |
1005 | // | |
1006 | // 2) Look for non-end_of_tracklet_marker | |
1007 | // | |
1008 | //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord); | |
1009 | ||
0c349049 | 1010 | if ( *fDataWord != fgkEndoftrackletmarker ) |
ecf39416 | 1011 | { |
0c349049 | 1012 | ChangeStatus(kDecodeHC); |
ecf39416 | 1013 | //AliDebug(3, "NON end-of-tracklet-marker found"); |
1014 | //AliDebug(5, Form("Data 0x%x", *fDataWord)); | |
1015 | //// no do not continue - this should be the hcheader | |
1016 | } | |
1017 | else | |
1018 | { | |
1019 | //just go on and find the non-end_of_tracklet_marker | |
1020 | return kTRUE; | |
1021 | } | |
1022 | } | |
1023 | ||
0c349049 | 1024 | if ( fNextStatus == kDecodeHC ) |
ecf39416 | 1025 | { |
0c349049 | 1026 | //AliDebug(5, "kDecodeHC"); |
ecf39416 | 1027 | |
1028 | // | |
1029 | // 3) This Word must be Half Chamber Header | |
1030 | // | |
1031 | if ( (*fDataWord & 0x00000003) == 1 ) | |
1032 | { // HC header | |
1033 | DecodeHCheader(fTimeBinsCalib); // This is the new header! | |
1034 | fLastDET = fDET; | |
1035 | fDET = fGeo->GetDetector(fLAYER, fSTACK, fSM); | |
1036 | fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM); | |
1037 | fColMax = fGeo->GetColMax(fROC); | |
1038 | ||
1039 | fMCMHctr2 = 0; | |
1040 | fHCdataCtr = 0; | |
1041 | fChamberDone[fDET]++; | |
1042 | //AliDebug(6, Form("-------------- DET %d fChamberDone[fDET]=%d", fDET, fChamberDone[fDET])); | |
1043 | ||
0c349049 | 1044 | ChangeStatus(kNextMCM); |
ecf39416 | 1045 | return kTRUE; |
1046 | } //HC header | |
1047 | else | |
1048 | { | |
1049 | AliWarning(Form("Expecting HC header mask but got 0x%x. Fall back: Next HC.", *fDataWord)); | |
0c349049 | 1050 | ChangeStatus(kNextHC); |
1051 | // before we went to //ChangeStatus(kNextSM); | |
ecf39416 | 1052 | } |
1053 | } // if decode HC | |
1054 | ||
1055 | return kFALSE; | |
1056 | } | |
0c349049 | 1057 | |
ecf39416 | 1058 | //____________________________________________________________________________ |
1059 | Bool_t AliTRDRawStreamV2::DecodeGTUlinkMask() | |
1060 | { | |
1061 | // | |
1062 | // Decode the link masks sent by the GTU. These marke the active optical links | |
1063 | // between GTU and Super Module. Up to now only fully active links are found | |
1064 | // (0xfff = 12 active links). | |
1065 | // | |
1066 | ||
1067 | if ( (*fDataWord & 0xfffff000) == 0xe0000000 ) | |
1068 | { | |
1069 | if ( fRawVersion < 1 || fRawVersion > 3 ) | |
1070 | { | |
1071 | AliError(Form(" Unsupported raw version: %d", fRawVersion)); | |
1072 | } | |
1073 | ||
1074 | if ( fGTUctr1 == -1 ) fGTUctr2++; | |
1075 | fGTUctr1++; | |
1076 | ||
1077 | if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) ) | |
1078 | { | |
1079 | fGTUlinkMask[fGTUctr2][fGTUctr1] = (*fDataWord & 0xfff); | |
1080 | } | |
1081 | ||
1082 | //AliDebug(5, Form("GTU link mask 0x%x decoded 0x%x", *fDataWord, fGTUlinkMask[fGTUctr2][fGTUctr1])); | |
1083 | return kTRUE; | |
1084 | } | |
1085 | ||
1086 | return kFALSE; | |
1087 | } | |
1088 | ||
0c349049 | 1089 | //____________________________________________________________________________ |
ecf39416 | 1090 | void AliTRDRawStreamV2::ChangeStatus(Int_t kstat) |
1091 | { | |
0c349049 | 1092 | // |
1093 | // Change the status | |
1094 | // | |
1095 | ||
ecf39416 | 1096 | fLastStatus = fNextStatus; |
1097 | fNextStatus = kstat; | |
1098 | } | |
1099 | ||
1100 | //____________________________________________________________________________ | |
1101 | Bool_t AliTRDRawStreamV2::DecodeSM() | |
1102 | { | |
0c349049 | 1103 | // |
1104 | // Decode a supermodule | |
1105 | // | |
1106 | ||
ecf39416 | 1107 | fDET = 0; |
1108 | fRetVal = 0; | |
1109 | fEqID = 0; | |
1110 | fDataSize = 0; | |
1111 | fSizeOK = kFALSE; | |
1112 | ||
1113 | // After reading the first word check for size of this data and get Eq. ID | |
1114 | if ( fWordCtr == 1 ) | |
1115 | { | |
1116 | fDataSize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words | |
1117 | fEqID = fRawReader->GetEquipmentId(); // Get Equipment ID | |
1118 | if ( fDataSize > 0 ) fSizeOK = kTRUE; | |
1119 | //AliDebug(3, Form("fDataSize=%d fEqID=%d", fDataSize, fEqID)); | |
1120 | } | |
1121 | ||
1122 | // GTU Link Mask? | |
1123 | if ( DecodeGTUlinkMask() ) | |
1124 | { | |
0c349049 | 1125 | ChangeStatus(kNextHC); |
ecf39416 | 1126 | return kTRUE; |
1127 | } | |
1128 | else | |
1129 | { | |
1130 | AliWarning(Form("Equipment %d: First data word is not GTU Link Mask! Fall back: None. Stop.", fEqID)); | |
1131 | fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID)); | |
0c349049 | 1132 | ChangeStatus(kStop); |
ecf39416 | 1133 | } |
1134 | ||
1135 | return kFALSE; | |
1136 | } | |
1137 | ||
1138 | //____________________________________________________________________________ | |
1139 | Bool_t AliTRDRawStreamV2::Next() | |
1140 | { | |
1141 | // | |
1142 | // Updates the next data word pointer | |
1143 | // | |
1144 | ||
0c349049 | 1145 | if (fNextStatus == kStart) |
ecf39416 | 1146 | { |
1147 | Init(); | |
1148 | } | |
1149 | ||
0c349049 | 1150 | while (fNextStatus != kStop) |
1151 | { // !kStop | |
ecf39416 | 1152 | NextData(); |
1153 | ||
1154 | switch (fNextStatus) | |
1155 | { | |
0c349049 | 1156 | case kNextData: |
ecf39416 | 1157 | { |
1158 | if (DecodeNextRawWord() == kTRUE) | |
1159 | { | |
1160 | fTB += 3; | |
1161 | if (fSig[0] > fRawDigitThreshold || fSig[1] > fRawDigitThreshold || fSig[2] > fRawDigitThreshold) | |
1162 | return kTRUE; | |
1163 | } | |
1164 | }; break; | |
0c349049 | 1165 | case kNextMCM: |
ecf39416 | 1166 | { |
1167 | if (DecodeMCM() == kFALSE) | |
1168 | AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos)); | |
1169 | }; break; | |
0c349049 | 1170 | case kNextHC: |
1171 | case kSeekNonEoTracklet: | |
1172 | case kDecodeHC: | |
ecf39416 | 1173 | { |
1174 | if (DecodeHC() == kFALSE) | |
1175 | { | |
1176 | AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos)); | |
1177 | } | |
1178 | else | |
1179 | { | |
1180 | //the hc header should be decoded by now | |
0c349049 | 1181 | if (fLastStatus == kDecodeHC) |
ecf39416 | 1182 | { |
1183 | fLastDET = fDET; | |
1184 | fChamberDone[fDET]++; | |
1185 | } | |
1186 | } | |
1187 | }; break; | |
0c349049 | 1188 | case kNextSM: |
ecf39416 | 1189 | { |
1190 | if (DecodeSM() == kFALSE) | |
1191 | AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos)); | |
1192 | }; break; | |
0c349049 | 1193 | case kStop: |
ecf39416 | 1194 | ; break; |
1195 | default: | |
1196 | AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos)); | |
0c349049 | 1197 | ChangeStatus(kStop); |
ecf39416 | 1198 | }; |
1199 | ||
0c349049 | 1200 | } // not kStop |
ecf39416 | 1201 | |
1202 | //AliDebug(1, Form("That's all folks! %d", fSM)); | |
1203 | return kFALSE; | |
1204 | } | |
1205 | ||
1206 | //____________________________________________________________________________ | |
1207 | Int_t AliTRDRawStreamV2::NextChamber(AliTRDdigitsManager *man) | |
1208 | { | |
1209 | // | |
1210 | // Fills single chamber digit array | |
1211 | // Return value is the detector number | |
1212 | // | |
1213 | ||
625f5260 | 1214 | AliTRDdataArrayS *digits = 0; |
ecf39416 | 1215 | AliTRDdataArrayI *track0 = 0; |
1216 | AliTRDdataArrayI *track1 = 0; | |
1217 | AliTRDdataArrayI *track2 = 0; | |
1218 | AliTRDSignalIndex *indexes = 0; | |
1219 | ||
0c349049 | 1220 | if (fNextStatus == kStart) |
ecf39416 | 1221 | { |
1222 | Init(); | |
1223 | } | |
1224 | ||
0c349049 | 1225 | // while (fNextStatus != kStop) |
1226 | // { // !kStop | |
ecf39416 | 1227 | // NextData(); |
1228 | // // catch 3 things | |
1229 | // // 1) if end of raw data - if chamber complete return | |
1230 | // // 2) fill the data with signals if data decoded ok | |
1231 | // // 3) initialize (destroy old) after the det has changed -> just after HC header decoding | |
0c349049 | 1232 | // } // not kStop |
ecf39416 | 1233 | |
0c349049 | 1234 | while (fNextStatus != kStop) |
1235 | { // !kStop | |
ecf39416 | 1236 | NextData(); |
1237 | ||
1238 | switch (fNextStatus) | |
1239 | { | |
1240 | ||
0c349049 | 1241 | case kNextData: |
ecf39416 | 1242 | { |
1243 | if (DecodeNextRawWord() == kTRUE) | |
1244 | { | |
1245 | for (Int_t it = 0; it < 3; it++) | |
1246 | { | |
1247 | if ( fTB + it < fTBins ) | |
1248 | { | |
1249 | if ( fSig[it] > fRawDigitThreshold ) | |
1250 | { | |
1251 | digits->SetDataUnchecked(fROW, fCOL, fTB + it, fSig[it]); | |
1252 | indexes->AddIndexTBin(fROW, fCOL, fTB + it); | |
1253 | if (man->UsesDictionaries()) | |
1254 | { | |
1255 | track0->SetDataUnchecked(fROW, fCOL, fTB + it, 0); | |
1256 | track1->SetDataUnchecked(fROW, fCOL, fTB + it, 0); | |
1257 | track2->SetDataUnchecked(fROW, fCOL, fTB + it, 0); | |
1258 | } // if dictionaries | |
1259 | } // signal above zero | |
1260 | } // check the tbins range | |
1261 | } // for each tbin of current 3 | |
1262 | fTB += 3; | |
1263 | } | |
1264 | else | |
1265 | { | |
1266 | // can be here as a fall back from decode raw data calling decodemcm | |
1267 | if (fEndOfDataFlag == kTRUE) | |
1268 | { | |
1269 | if (fChamberDone[fDET] == 2) | |
1270 | { | |
1271 | return fDET; | |
1272 | } | |
1273 | fEndOfDataFlag = kFALSE; | |
1274 | } | |
1275 | } | |
1276 | }; break; | |
1277 | ||
0c349049 | 1278 | case kNextMCM: |
ecf39416 | 1279 | { |
1280 | if (DecodeMCM() == kFALSE) | |
1281 | { | |
1282 | AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos)); | |
1283 | } | |
1284 | // default place for end of raw data... | |
1285 | if (fEndOfDataFlag == kTRUE) | |
1286 | { | |
1287 | if (fChamberDone[fDET] == 2) | |
1288 | { | |
1289 | return fDET; | |
1290 | } | |
1291 | fEndOfDataFlag = kFALSE; | |
1292 | } | |
1293 | }; break; | |
1294 | ||
0c349049 | 1295 | case kNextHC: |
1296 | case kSeekNonEoTracklet: | |
1297 | case kDecodeHC: | |
ecf39416 | 1298 | { |
1299 | if (DecodeHC() == kFALSE) | |
1300 | { | |
1301 | AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos)); | |
1302 | } | |
1303 | else | |
1304 | { | |
1305 | //the hc header should be decoded by now | |
0c349049 | 1306 | if (fLastStatus == kDecodeHC) |
ecf39416 | 1307 | { |
1308 | // AliDebug(4, Form("???? New DET ???? %d last %d", fDET, fLastDET)); | |
1309 | // allocate stuff for the new det | |
1310 | //man->ResetArrays(); | |
625f5260 | 1311 | digits = (AliTRDdataArrayS *) man->GetDigits(fDET); |
1312 | track0 = (AliTRDdataArrayI *) man->GetDictionary(fDET,0); | |
1313 | track1 = (AliTRDdataArrayI *) man->GetDictionary(fDET,1); | |
1314 | track2 = (AliTRDdataArrayI *) man->GetDictionary(fDET,2); | |
ecf39416 | 1315 | |
1316 | // Allocate memory space for the digits buffer | |
1317 | if (digits->GetNtime() == 0) | |
1318 | { | |
1319 | // AliDebug(5, Form("Alloc digits for det %d rows %d cols %d tbins %d", fDET, fRowMax, fColMax, fTBins)); | |
1320 | digits->Allocate(fRowMax, fColMax, fTBins); | |
1321 | if (man->UsesDictionaries()) | |
1322 | { | |
1323 | track0->Allocate(fRowMax, fColMax, fTBins); | |
1324 | track1->Allocate(fRowMax, fColMax, fTBins); | |
1325 | track2->Allocate(fRowMax, fColMax, fTBins); | |
1326 | } | |
1327 | } | |
1328 | ||
1329 | indexes = man->GetIndexes(fDET); | |
1330 | indexes->SetSM(fSM); | |
1331 | indexes->SetStack(fSTACK); | |
1332 | indexes->SetLayer(fLAYER); | |
1333 | indexes->SetDetNumber(fDET); | |
1334 | ||
1335 | if (indexes->IsAllocated() == kFALSE) | |
1336 | { | |
1337 | // AliDebug(4, "Allocating indexes"); | |
1338 | indexes->Allocate(fRowMax, fColMax, fTBins); | |
1339 | } | |
1340 | } // is the HC header already decoded? | |
1341 | } // decode hc ok | |
1342 | }; break; | |
1343 | ||
0c349049 | 1344 | case kNextSM: |
ecf39416 | 1345 | { |
1346 | if (DecodeSM() == kFALSE) | |
1347 | AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos)); | |
1348 | }; break; | |
1349 | ||
0c349049 | 1350 | case kStop: |
ecf39416 | 1351 | ; break; |
1352 | ||
1353 | default: | |
1354 | AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos)); | |
0c349049 | 1355 | ChangeStatus(kStop); |
ecf39416 | 1356 | }; |
1357 | ||
0c349049 | 1358 | } // not kStop |
ecf39416 | 1359 | |
1360 | // we do not return chambers for which the end-of-data was not received twice (for each HC) | |
1361 | ||
1362 | //AliDebug(1, Form("That's all folks! %d", fSM)); | |
1363 | //return kFALSE; | |
1364 | return -1; | |
1365 | } |