]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDRawStream.cxx
Coding conventions
[u/mrichter/AliRoot.git] / TRD / AliTRDRawStream.cxx
CommitLineData
b864d801 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///////////////////////////////////////////////////////////////////////////////
2745a409 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// //
7925de54 27// Author: C. Lippmann (C.Lippmann@gsi.de) //
28// //
b864d801 29///////////////////////////////////////////////////////////////////////////////
30
2745a409 31#include "AliLog.h"
b864d801 32#include "AliRawReader.h"
2745a409 33#include "AliTRDRawStream.h"
7925de54 34#include "AliTRDgeometry.h"
3551db50 35#include "AliTRDcalibDB.h"
b864d801 36
37ClassImp(AliTRDRawStream)
38
2745a409 39//_____________________________________________________________________________
40AliTRDRawStream::AliTRDRawStream()
41 :TObject()
7925de54 42 ,fSig()
43 ,fADC(0)
44 ,fTB(0)
45 ,fEv(0)
46 ,fROB(0)
47 ,fMCM(0)
48 ,fSM(0)
49 ,fLAYER(0)
50 ,fSTACK(0)
51 ,fROC(0)
52 ,fSIDE(0)
53 ,fDCS(0)
54 ,fROW(0)
55 ,fCOL(0)
50378239 56 ,fDET(0)
7925de54 57 ,fBCctr(0)
58 ,fPTctr(0)
59 ,fPTphase(0)
60 ,fRVmajor(0)
61 ,fRVminor(0)
62 ,fHCHWords(0)
63 ,fTBins(0)
64 ,fTCon(0)
65 ,fPEDon(0)
66 ,fGAINon(0)
bd63bf88 67 ,fXTon(0)
68 ,fNonLinOn(0)
69 ,fBypass(0)
70 ,fCommonAdditive(0)
71 ,fZeroSuppressed(0)
7925de54 72 ,fHCHctr1(0)
73 ,fHCHctr2(0)
74 ,fMCMHctr1(0)
75 ,fMCMHctr2(0)
76 ,fGTUctr1(0)
77 ,fGTUctr2(0)
bd63bf88 78 ,fHCdataCtr(0)
79 ,fTracklPID(0.)
80 ,fTracklDefL(0.)
81 ,fTracklPadPos(0.)
7925de54 82 ,fTracklPadRow(0)
83 ,fGTUlinkMask()
84 ,fRawReader(NULL)
bd63bf88 85 ,fRawVersion(2)
50378239 86 ,fNextStatus(0)
bd63bf88 87 ,fTbSwitch(0)
88 ,fTbSwitchCtr(0)
89 ,fTimeWords(0)
90 ,fWordCtr(0)
7925de54 91 ,fRowMax(0)
92 ,fColMax(0)
bd63bf88 93 ,fADCmask()
7925de54 94 ,fChamberDone()
50378239 95 ,fRetVal(0)
96 ,fEqID(0)
97 ,fDataSize(0)
98 ,fSizeOK(kFALSE)
99 ,fCountBytes(0)
100 ,fBufSize(0)
101 ,fkBufferSet(kFALSE)
102 ,fPos(NULL)
103 ,fDataWord(NULL)
104 ,fTimeBinsCalib(0)
7925de54 105 ,fGeo(NULL)
7925de54 106{
107 //
50378239 108 // Default constructor
7925de54 109 //
110
7925de54 111 for (Int_t i = 0; i < 540; i++) {
112 fChamberDone[i] = 0;
113 }
114
2745a409 115}
116
117//_____________________________________________________________________________
7925de54 118AliTRDRawStream::AliTRDRawStream(AliRawReader *rawReader)
2745a409 119 :TObject()
7925de54 120 ,fSig()
121 ,fADC(0)
122 ,fTB(0)
123 ,fEv(0)
124 ,fROB(0)
125 ,fMCM(0)
126 ,fSM(0)
127 ,fLAYER(0)
128 ,fSTACK(0)
129 ,fROC(0)
130 ,fSIDE(0)
131 ,fDCS(0)
132 ,fROW(0)
133 ,fCOL(0)
50378239 134 ,fDET(0)
7925de54 135 ,fBCctr(0)
136 ,fPTctr(0)
137 ,fPTphase(0)
138 ,fRVmajor(0)
139 ,fRVminor(0)
140 ,fHCHWords(0)
141 ,fTBins(0)
142 ,fTCon(0)
143 ,fPEDon(0)
144 ,fGAINon(0)
bd63bf88 145 ,fXTon(0)
146 ,fNonLinOn(0)
147 ,fBypass(0)
148 ,fCommonAdditive(0)
149 ,fZeroSuppressed(0)
7925de54 150 ,fHCHctr1(0)
151 ,fHCHctr2(0)
152 ,fMCMHctr1(0)
153 ,fMCMHctr2(0)
154 ,fGTUctr1(0)
155 ,fGTUctr2(0)
bd63bf88 156 ,fHCdataCtr(0)
157 ,fTracklPID(0.)
158 ,fTracklDefL(0.)
159 ,fTracklPadPos(0.)
7925de54 160 ,fTracklPadRow(0)
161 ,fGTUlinkMask()
2745a409 162 ,fRawReader(rawReader)
bd63bf88 163 ,fRawVersion(2)
50378239 164 ,fNextStatus(0)
bd63bf88 165 ,fTbSwitch(0)
166 ,fTbSwitchCtr(0)
167 ,fTimeWords(0)
168 ,fWordCtr(0)
7925de54 169 ,fRowMax(0)
170 ,fColMax(0)
bd63bf88 171 ,fADCmask()
7925de54 172 ,fChamberDone()
50378239 173 ,fRetVal(0)
174 ,fEqID(0)
175 ,fDataSize(0)
176 ,fSizeOK(kFALSE)
177 ,fCountBytes(0)
178 ,fBufSize(0)
179 ,fkBufferSet(kFALSE)
180 ,fPos(NULL)
181 ,fDataWord(NULL)
182 ,fTimeBinsCalib(0)
7925de54 183 ,fGeo(NULL)
b864d801 184{
2745a409 185 //
186 // Create an object to read TRD raw digits
187 //
b864d801 188
362c9d61 189 fRawReader->Select("TRD");
2745a409 190
7925de54 191 for (Int_t i = 0; i < 540; i++) {
192 fChamberDone[i] = 0;
193 }
194
b864d801 195}
196
2745a409 197//_____________________________________________________________________________
7925de54 198AliTRDRawStream::AliTRDRawStream(const AliTRDRawStream& stream)
199 :TObject(stream)
200 ,fSig()
bd63bf88 201 ,fADC(-1)
202 ,fTB(-1)
203 ,fEv(-1)
204 ,fROB(-1)
205 ,fMCM(-1)
206 ,fSM(-1)
207 ,fLAYER(-1)
208 ,fSTACK(-1)
209 ,fROC(-1)
210 ,fSIDE(-1)
211 ,fDCS(-1)
212 ,fROW(-1)
213 ,fCOL(-1)
50378239 214 ,fDET(0)
bd63bf88 215 ,fBCctr(-1)
216 ,fPTctr(-1)
217 ,fPTphase(-1)
218 ,fRVmajor(-1)
219 ,fRVminor(-1)
220 ,fHCHWords(-1)
221 ,fTBins(-1)
7925de54 222 ,fTCon(0)
223 ,fPEDon(0)
224 ,fGAINon(0)
bd63bf88 225 ,fXTon(0)
226 ,fNonLinOn(-1)
227 ,fBypass(-1)
228 ,fCommonAdditive(-1)
229 ,fZeroSuppressed(0)
230 ,fHCHctr1(-1)
231 ,fHCHctr2(-1)
232 ,fMCMHctr1(-1)
233 ,fMCMHctr2(-1)
234 ,fGTUctr1(-1)
235 ,fGTUctr2(-1)
236 ,fHCdataCtr(-1)
237 ,fTracklPID(-1.)
238 ,fTracklDefL(-1.)
239 ,fTracklPadPos(-1.)
240 ,fTracklPadRow(-1)
7925de54 241 ,fGTUlinkMask()
242 ,fRawReader(NULL)
bd63bf88 243 ,fRawVersion(-1)
50378239 244 ,fNextStatus(0)
bd63bf88 245 ,fTbSwitch(0)
246 ,fTbSwitchCtr(0)
247 ,fTimeWords(0)
248 ,fWordCtr(0)
249 ,fRowMax(-1)
250 ,fColMax(-1)
251 ,fADCmask()
7925de54 252 ,fChamberDone()
50378239 253 ,fRetVal(0)
254 ,fEqID(0)
255 ,fDataSize(0)
256 ,fSizeOK(kFALSE)
257 ,fCountBytes(0)
258 ,fBufSize(0)
259 ,fkBufferSet(kFALSE)
260 ,fPos(NULL)
261 ,fDataWord(NULL)
262 ,fTimeBinsCalib(0)
263 ,fGeo(NULL)
b864d801 264{
2745a409 265 //
266 // Copy constructor
267 //
268
269 AliFatal("Copy constructor not implemented");
270
b864d801 271}
272
2745a409 273//_____________________________________________________________________________
b864d801 274AliTRDRawStream& AliTRDRawStream::operator = (const AliTRDRawStream&
275 /* stream */)
276{
2745a409 277 //
278 // Assigment operator
279 //
280
b864d801 281 Fatal("operator =", "assignment operator not implemented");
282 return *this;
2745a409 283
b864d801 284}
285
2745a409 286//_____________________________________________________________________________
b864d801 287AliTRDRawStream::~AliTRDRawStream()
288{
2745a409 289 //
290 // Destructor
291 //
f162af62 292
293 if (fGeo) {
294 delete fGeo;
295 }
296
7925de54 297}
298
50378239 299//_____________________________________________________________________________
300void AliTRDRawStream::SetRawReader(AliRawReader *rawReader)
301{
302 if (rawReader)
303 {
304 fRawReader = rawReader;
305 }
306}
f162af62 307
7925de54 308//_____________________________________________________________________________
309Bool_t AliTRDRawStream::SetRawVersion(Int_t rv)
310{
311 //
312 // Set the raw data version
313 //
314
bd63bf88 315 if ( rv >= 0 && rv <= 3 ) {
7925de54 316 fRawVersion = rv;
317 return kTRUE;
318 }
319
320 return kFALSE;
321
b864d801 322}
323
7925de54 324
325//____________________________________________________________________________
50378239 326Int_t AliTRDRawStream::Init()
7925de54 327{
7925de54 328 //
50378239 329 // Initialization
7925de54 330 //
50378239 331
f162af62 332 if (!AliTRDcalibDB::Instance()) {
7925de54 333 AliError("Could not get calibration object");
bd63bf88 334 return 0;
7925de54 335 }
50378239 336
f162af62 337 if (!fGeo) {
338 fGeo = new AliTRDgeometry();
339 }
7925de54 340
f162af62 341 fTimeBinsCalib = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
50378239 342 AliDebug(2, Form("Number of Timebins read from CDB: %d", fTimeBinsCalib));
7925de54 343
344 // The number of data words needed for this number of time bins (there
345 // are 3 time bins in one word)
50378239 346 fTimeWords = (fTimeBinsCalib-1)/3 + 1;
7925de54 347
bd63bf88 348 fTbSwitch = 3;
349 fTbSwitchCtr = 0;
350
7925de54 351 fHCHctr1 = fHCHctr2 = 0;
352 fGTUctr1 = fGTUctr2 = -1;
353
bd63bf88 354 fHCdataCtr = 0;
50378239 355 fWordCtr = 0;
7925de54 356
50378239 357 fDET = 0;
358 fRetVal = 0;
359 fEqID = 0;
360 fDataSize = 0;
361 fSizeOK = kFALSE;
362
363 fNextStatus = fkStart;
364
365 fCountBytes = 0;
366 fBufSize = 0;
367 fDataWord = NULL;
368 fPos = NULL;
369 fWordCtr = 0;
370 fkBufferSet = kFALSE;
371 return kTRUE;
372}
7925de54 373
50378239 374//____________________________________________________________________________
375Int_t AliTRDRawStream::NextData()
376{
377 //
378 // Updates the next data word pointer
379 //
7925de54 380
50378239 381 if (fCountBytes + kSizeWord >= fBufSize)
382 {
383 fkBufferSet = fRawReader->ReadNextData(fPos);
384 if (fkBufferSet == kTRUE)
385 {
386 fBufSize = fRawReader->GetDataSize();
387 fCountBytes = 0;
388 fDataWord = (UInt_t*)fPos;
389 fNextStatus = fkNextSM;
390 fWordCtr = 0;
391 return fkNextSM;
7925de54 392 }
50378239 393 else
394 {
395 fNextStatus = fkStop;
396 return fkNoMoreData;
7925de54 397 }
50378239 398 }
399 else
400 {
7925de54 401
50378239 402 fPos += kSizeWord;
403 fCountBytes += kSizeWord;
404 fDataWord = (UInt_t*)fPos;
405 fWordCtr++;
406 return fkWordOK;
407 }
408}
7925de54 409
50378239 410//____________________________________________________________________________
411Bool_t AliTRDRawStream::Next()
412{
413 //
414 // Updates the next data word pointer
415 //
7925de54 416
50378239 417 if (fNextStatus == fkStart)
418 {
419 Init();
420 }
7925de54 421
50378239 422 while (fNextStatus != fkStop)
423 { // !fkStop
424 NextData();
425
426 if (fNextStatus == fkNextMCM || fNextStatus == fkNextData)
427 {
428 fHCdataCtr += 4;
429
430 if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) )
431 { // MCM Header
432 DecodeMCMheader();
433 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 )
434 {
435 AliWarning("Wrong fMCM or fROB. Skip this data");
436 fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB));
437 fNextStatus = fkNextHC;
438 continue;
bd63bf88 439 }
50378239 440 fTbSwitch = 3; // For first adc channel we expect: (*fDataWord & 3) = 3
441 fTbSwitchCtr = 0; //
442 fADC = fTB = 0; // Reset Counter
443 fNextStatus = fkNextData;
444 continue;
bd63bf88 445 }
7925de54 446
50378239 447 if ( *fDataWord == kEndofrawdatamarker )
448 { // End of half-chamber data, finished
449 fGTUctr1 = -1;
450 fNextStatus = fkNextHC;
451 continue;
7925de54 452 }
7925de54 453
50378239 454 if (fNextStatus == fkNextData )
455 { // MCM header is set, ADC data is valid.
7925de54 456
50378239 457 // Found some data. Decode it now:
458 fRetVal = DecodeDataWord();
459 if ( fRetVal == 0 ) continue;
460 if ( fRetVal == -1 )
461 {
462 fNextStatus = fkNextHC;
463 continue;
464 }
465 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 )
466 {
467 // Write Digits
468 if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax )
469 { // A real pad
470 fTB += 3;
471 return kTRUE;
472 }
7925de54 473 }
50378239 474 else
475 {
476 fCOL = -1;
477 }
478 }// fkNextData
479
480 continue;
481 } //next mcm
482
483 if ( fNextStatus == fkNextHC )
484 {
485 //
486 // 1) Find end_of_tracklet_marker
487 //
488 // GTU Link Mask?
489 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
490 {
491 DecodeGTUlinkMask();
492 continue;
493 }
494
495 // endoftrackletmarker?
496 if ( *fDataWord == kEndoftrackletmarker )
497 {
498 AliDebug(3, "end-of-tracklet-marker found");
499 fNextStatus = fkSeekNonEoTracklet;
500 continue;
501 }
502 else
503 {
504 // Tracklets found
505 AliDebug(3, "Tracklet found");
506 DecodeTracklet();
507 continue;
508 }
509 } //if next HC
510
511 if (fNextStatus == fkSeekNonEoTracklet)
512 {
513 //
514 // 2) Look for non-end_of_tracklet_marker
515 //
516 //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord);
517
518 if ( *fDataWord != kEndoftrackletmarker )
519 {
520 fNextStatus = fkDecodeHC;
521 AliDebug(3, "NON end-of-tracklet-marker found");
522 //// no do not continue - this should be the hcheader
523 }
524 else
525 {
526 //just go on and find the non-end_of_tracklet_marker
527 continue;
7925de54 528 }
7925de54 529 }
bd63bf88 530
50378239 531 if ( fNextStatus == fkDecodeHC )
532 {
533 AliDebug(3, "Decode HC");
534
535 //
536 // 3) This Word must be Half Chamber Header
537 //
538 if ( (*fDataWord & 0x00000003) == 1 )
539 { // HC header
540 DecodeHCheader(fTimeBinsCalib); // This is the new header!
541 fDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
f162af62 542 fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM);
543 fColMax = fGeo->GetColMax(fROC);
50378239 544
545 fMCMHctr2 = 0;
546 fHCdataCtr = 0;
547
548 fChamberDone[fDET]++;
549 fNextStatus = fkNextMCM;
550 AliDebug(3, "Decode HC OK");
551 continue;
552 } //HC header
553 else
554 {
555 AliDebug(3, "Decode HC NOT OK");
556 fNextStatus = fkNextSM;
557 continue;
558 }
559 } // if decode HC
7925de54 560
50378239 561 if (fNextStatus == fkNextSM)
562 {
563
564 fDET = 0;
565 fRetVal = 0;
566 fEqID = 0;
567 fDataSize = 0;
568 fSizeOK = kFALSE;
569
570 // After reading the first word check for size of this data and get Eq. ID
571 if ( fWordCtr == 1 )
572 {
573 fDataSize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
574 fEqID = fRawReader->GetEquipmentId(); // Get Equipment ID
575 if ( fDataSize > 0 ) fSizeOK = kTRUE;
576 }
577
578 // GTU Link Mask?
579 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
580 {
581 DecodeGTUlinkMask();
582 fNextStatus = fkNextHC;
583 continue;
584 }
585 else
586 {
587 AliWarning(Form("Equipment %d: First data word is not GTU Link Mask!", fEqID));
588 fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID));
589 fNextStatus = fkStop;
590 }
591 }// if nextSM
592
593 } // not fkStop
594
595 AliDebug(1, Form("That's all folks! %d", fSM));
596 return kFALSE;
7925de54 597}
598
599//============================================================================
600// Decoding functions
601//============================================================================
602
7925de54 603
604//____________________________________________________________________________
50378239 605void AliTRDRawStream::DecodeHCheader(Int_t timeBins)
7925de54 606{
7925de54 607 //
50378239 608 // Decode the HC header (fRawVersion == 2, 3, 4, ???)
7925de54 609 //
610
50378239 611 fRVmajor = (*fDataWord >> 24) & 0x7f;
612 fRVminor = (*fDataWord >> 17) & 0x7f;
7925de54 613
50378239 614 if (fRVmajor < 2 || fRVmajor > 4)
615 AliError(Form(" Unsupported raw version: %d", fRawVersion))
616
617 if ( fRawVersion != fRVmajor ) {
618
619 AliWarning("===============================================================================");
620 AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)"
621 ,fRawVersion,fRVmajor));
622 AliWarning(Form("Setting fRawVersion to %d", fRVmajor));
623 AliWarning("===============================================================================");
624 fRawVersion = fRVmajor;
7925de54 625
626 }
627
7925de54 628 //
50378239 629 // check for zero suppression
630 if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
631 else fZeroSuppressed = kFALSE;
632
bd63bf88 633 // 1st word (h[0])
50378239 634 if ( (*fDataWord & 0x3) == 1 ) {
7925de54 635
50378239 636 fHCHWords = (*fDataWord >> 14) & 0x7;
637 fSM = (*fDataWord >> 9) & 0x1f;
638 fLAYER = (*fDataWord >> 6) & 0x7;
639 fSTACK = (*fDataWord >> 3) & 0x7;
640 fSIDE = (*fDataWord >> 2) & 0x1;
7925de54 641
642 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
643
50378239 644 AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", *fDataWord, fSM, fROC, fSIDE+10));
7925de54 645
646 if ((fSM < 0) ||
647 (fSM > 17) ||
648 (fLAYER < 0) ||
649 (fLAYER > 5) ||
650 (fSTACK < 0) ||
651 (fSTACK > 4) ||
652 (fSIDE < 0) ||
653 (fSIDE > 1)) {
50378239 654 AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
655 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
656 fRawReader->AddMajorErrorLog(kHCHeaderCorrupt,Form("0x%08x:dcs=%d; sm=%d; layer=%d; stack=%d.",
657 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
7925de54 658 }
659 else {
7925de54 660 fHCHctr1++;
661 fHCHctr2++;
662 }
663 }
664 else {
50378239 665 AliWarning(Form("0x%08x: No HC header when it was expected.", *fDataWord));
666 fRawReader->AddMajorErrorLog(kHCHeaderMissing,Form("0x%08x", *fDataWord));
7925de54 667 }
668
bd63bf88 669 // 2nd word (h[1])
7925de54 670 if ( fHCHWords >= 1 ) {
671 // read one more word
50378239 672 if (NextData() != fkWordOK)
673 {
674 AliWarning("Next HC word missing");
675 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
676 fNextStatus = fkNextHC;
677 return;
678 }
679 if ( (*fDataWord & 0x3) == 1 ) {
7925de54 680
50378239 681 fBCctr = (*fDataWord >> 16);
682 fPTctr = (*fDataWord >> 12) & 0xf;
683 fPTphase = (*fDataWord >> 8) & 0xf;
684 fTBins = ((*fDataWord >> 2) & 0x3f) + 1;
7925de54 685
686 AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
50378239 687 , *fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
7925de54 688
689 if( fTBins != timeBins ) {
bd63bf88 690
691 AliWarning("===============================================================================");
692 AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)"
693 , timeBins, fTBins));
694 AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins));
695 AliWarning("===============================================================================");
696
50378239 697 fTimeWords = (fTBins - 1)/3 + 1;
7925de54 698 }
699
700 }
701
702 }
703
bd63bf88 704 // 3nd word (h[2])
7925de54 705 if ( fHCHWords >= 2 ) {
706 // read one more word
50378239 707 if (NextData() != fkWordOK)
708 {
709 AliWarning("Next HC word missing");
710 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
711 fNextStatus = fkNextHC;
712 return;
713 }
714 if ( (*fDataWord & 0x3) == 1 ) {
bd63bf88 715
50378239 716 fTCon = (*fDataWord >> 29) & 0x1;
717 fPEDon = (*fDataWord >> 31) & 0x1;
718 fGAINon = (*fDataWord >> 30) & 0x1;
719 fXTon = (*fDataWord >> 28) & 0x1;
720 fNonLinOn = (*fDataWord >> 27) & 0x1;
721 fBypass = (*fDataWord >> 26) & 0x1;
bd63bf88 722
50378239 723 fCommonAdditive = (*fDataWord >> 20) & 0x3f;
bd63bf88 724
725 AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d"
726 , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive));
7925de54 727 }
7925de54 728 }
729
730}
731
732//____________________________________________________________________________
733void AliTRDRawStream::DecodeMCMheader()
7925de54 734{
735
736 //
737 // Decode the MCM header
738 //
739
50378239 740 if ( fRawVersion < 1 || fRawVersion > 3 )
741 {
742 AliError(Form(" Unsupported raw version: %d", fRawVersion));
743 }
744
745 fMCM = (*fDataWord & 0xff000000) >> 24;
746 fEv = (*fDataWord & 0x00fffff0) >> 4;
7925de54 747
748 fROB = fMCM / 16;
749 fMCM = fMCM % 16;
750
bd63bf88 751 fROW = fGeo->GetPadRowFromMCM(fROB, fMCM);
7925de54 752
753 AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d"
50378239 754 , *fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv));
7925de54 755
756 if ( fROB % 2 == 0 && fSIDE == 1 ) {
50378239 757 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
758 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
759 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
760 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
7925de54 761 }
762 if ( fROB % 2 != 0 && fSIDE == 0 ) {
50378239 763 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
764 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
765 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
766 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
7925de54 767 }
bd63bf88 768 if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
769 (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
50378239 770 AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
771 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
772 fRawReader->AddMajorErrorLog(kWrongPadrow,Form("SM%d L%dS%d: Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
773 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
7925de54 774 }
775
776 fMCMHctr1++;
777 fMCMHctr2++;
778
bd63bf88 779 // AdcMask for Zero supressed data
780 if ( fRawVersion == 3 ) {
781 // read one more word
50378239 782 if (NextData() != fkWordOK)
783 {
784 AliWarning("MCM ADC mask missing");
785 fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
786 fNextStatus = fkNextHC;
787 return;
788 }
789 if ( (*fDataWord & 0x000007ff) == 0xC ) { // at the moment bits 4-10 are empty
bd63bf88 790
791 for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
50378239 792 if ( (*fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
bd63bf88 793 else fADCmask[ctr] = kFALSE;
794 }
795
50378239 796 AliDebug(4, Form("0x%08x: ADC mask", *fDataWord));
bd63bf88 797
798 }
799 else {
50378239 800 AliWarning("Expected ADC mask but did not find one!");
801 fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Decode error");
bd63bf88 802 }
803
804 }
805
7925de54 806}
807
808//____________________________________________________________________________
809void AliTRDRawStream::DecodeTracklet()
7925de54 810{
811
812 //
813 // Decode the Tracklet
814 //
815 // this function is not tested yet on real tracklets
816 //
817
50378239 818 if ( fRawVersion < 1 || fRawVersion > 3 )
819 {
820 AliError(Form(" Unsupported raw version: %d", fRawVersion));
821 }
822
823 fTracklPID = (*fDataWord >> 24) & 0xff;
824 fTracklPadRow = (*fDataWord >> 20) & 0xf; // 0:15
825 fTracklDefL = (*fDataWord >> 13) & 0x7f;
826 fTracklPadPos = (*fDataWord) & 0x1fff;
7925de54 827
828 fTracklPID /= (Float_t)((1<<8) - 1); // 0:1 (steps of 0.39%)
829 fTracklDefL = (fTracklDefL - ((1<< 7)-1)/2.) * 140.e-4; // -0.889:0.889cm
830 fTracklPadPos = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm
831
50378239 832 //AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f"
833 // , *fDataWord, fSM, fLAYER, fSTACK, fSIDE+10
834 // , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID));
7925de54 835
f78960c8 836 if( (fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0()) ||
837 (fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1()) ) {
50378239 838 AliWarning(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow));
839 fRawReader->AddMajorErrorLog(kTrackletRowMismatch,Form("Word: %d", fTracklPadRow));
7925de54 840 }
841
842}
843
844//____________________________________________________________________________
845void AliTRDRawStream::DecodeGTUlinkMask()
7925de54 846{
847
848 //
849 // Decode the link masks sent by the GTU. These marke the active optical links
850 // between GTU and Super Module. Up to now only fully active links are found
851 // (0xfff = 12 active links).
852 //
853
50378239 854 if ( fRawVersion < 1 || fRawVersion > 3 )
855 {
856 AliError(Form(" Unsupported raw version: %d", fRawVersion));
857 }
858
7925de54 859 if ( fGTUctr1 == -1 ) fGTUctr2++;
860 fGTUctr1++;
861
7925de54 862 if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) ) {
50378239 863 fGTUlinkMask[fGTUctr2][fGTUctr1] = (*fDataWord & 0xfff);
7925de54 864 }
865
866}
867
bd63bf88 868//____________________________________________________________________________
869Int_t AliTRDRawStream::DecodeDataWord()
870{
871
872 //
873 // Decode the Data
874 //
875
876 if ( fRawVersion >= 1 && fRawVersion <= 2 ) {
877 return DecodeDataWordV1V2();
878 }
879 else if ( fRawVersion >= 3 && fRawVersion <= 3 ) {
880 return DecodeDataWordV3();
881 }
882
883 AliError(Form(" Unsupported raw version: %d", fRawVersion));
884 return -1;
885
886}
887
888//____________________________________________________________________________
889Int_t AliTRDRawStream::DecodeDataWordV1V2()
890{
891
892 //
893 // Decode the Data (full raw data. No zero suppression. 21 adc channels)
894 //
895 // return 0 means continue to next data word
896 // return -1 means break data loop
897 //
898
50378239 899 if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
900 AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
901 fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
bd63bf88 902 return -1;
903 }
904
50378239 905 if ( (*fDataWord & 0x00000003) != fTbSwitch ) { // Next ADC channel found
bd63bf88 906 fTbSwitch = (fTbSwitch & 2) | !(fTbSwitch & 1); // 0x3 <--> 0x2
907 fTbSwitchCtr = 0;
908 fADC++;
909 fTB=0;
910 }
911
912 fTbSwitchCtr++; // Just read one word
913
914 // We have only timeTotal time bins
915 if ( fTbSwitchCtr > fTimeWords ) {
50378239 916 AliWarning(Form("Data is strange. Already found %d words for this ADC channel", (Int_t)fTbSwitchCtr));
917 fRawReader->AddMinorErrorLog(kADCNumberOverflow,Form("%d words", (Int_t)fTbSwitchCtr));
bd63bf88 918 return 0;
919 }
920
921 // We have only 21 ADC channels.
922 if ( fADC > (Int_t)fGeo->ADCmax()-1 ) {
50378239 923 AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
924 fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
bd63bf88 925 return 0;
926 }
927
928 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
929 // MCMs and are good for online tracking in the MCM.
930 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 ) {
931
932 // Get Pad column
933 fCOL = fGeo->GetPadColFromADC(fROB, fMCM, fADC);
934
935 // We have only 144 Pad Columns
936 if ( fCOL > fColMax-1 || fCOL < 0 ) {
50378239 937 AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
938 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
939 fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
bd63bf88 940 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
941 }
942
943 // Decode 32 bit data words with information from 3 time bins and copy the data
50378239 944 fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
945 fSig[1] = (*fDataWord & 0x003ff000) >> 12;
946 fSig[2] = (*fDataWord & 0xffc00000) >> 22;
bd63bf88 947
948 // Print data to screen:
9f5053b6 949 // Do NOT switch on for default production, it is VERY slow
950 // AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
951 // fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
bd63bf88 952
953 }
954 else {
955
956 fCOL = -1;
957
958 }
959
5a21f812 960 return 1;
961
bd63bf88 962}
963
964//____________________________________________________________________________
965Int_t AliTRDRawStream::DecodeDataWordV3()
966{
967
968 //
969 // Decode the data (Zero suppresses data. 21 adc channels)
970 //
971 // return 0 means continue to next data word
972 // return -1 means break data loop
973 //
974 // NOT TESTED YET!!!!!!!!
975 //
976
50378239 977 if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
978 AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
979 fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
bd63bf88 980 return -1;
981 }
982
50378239 983 if ( (*fDataWord & 0x00000003) != fTbSwitch ) { // Next ADC channel found
bd63bf88 984 fTbSwitch = (fTbSwitch & 2) | !(fTbSwitch & 1); // 0x3 <--> 0x2
985 fTbSwitchCtr = 0;
986 //
987 // Jump to next ADC channel that is not masked
988 do {
989 fADC++;
990 } while ( ((fADC < fGeo->ADCmax()) && (fADCmask[fADC] == kFALSE)) || (fADC >= fGeo->ADCmax()) );
991 fTB=0;
992 }
993
994 fTbSwitchCtr++; // Just read one word
995
996 // We have only timeTotal time bins
997 if ( fTbSwitchCtr > fTimeWords ) {
50378239 998 AliWarning(Form("Data is strange. Already found %d words for this ADC channel", (Int_t)fTbSwitchCtr));
999 fRawReader->AddMinorErrorLog(kADCNumberOverflow,Form("%d words", (Int_t)fTbSwitchCtr));
bd63bf88 1000 return 0;
1001 }
1002
1003 // We have only 21 ADC channels.
1004 if ( fADC > (Int_t)fGeo->ADCmax()-1 ) {
50378239 1005 AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
1006 fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
bd63bf88 1007 return 0;
1008 }
1009
1010 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
1011 // MCMs and are good for online tracking in the MCM.
1012 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 ) {
1013
1014 // Get Pad column
1015 fCOL = fGeo->GetPadColFromADC(fROB, fMCM, fADC);
1016
1017 // We have only 144 Pad Columns
1018 if ( fCOL > fColMax-1 || fCOL < 0 ) {
50378239 1019 AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
1020 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
1021 fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
bd63bf88 1022 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
1023 }
1024
1025 // Decode 32 bit data words with information from 3 time bins and copy the data
50378239 1026 fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
1027 fSig[1] = (*fDataWord & 0x003ff000) >> 12;
1028 fSig[2] = (*fDataWord & 0xffc00000) >> 22;
bd63bf88 1029
1030 // Print data to screen:
1031 AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
1032 fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
1033
1034 }
1035 else {
1036
1037 fCOL = -1;
1038
1039 }
1040
5a21f812 1041 return 1;
1042
bd63bf88 1043}