]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDRawStream.cxx
Compiler warnings
[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"
7925de54 33#include "AliTRDdigitsManager.h"
34#include "AliTRDdataArrayI.h"
2745a409 35
36#include "AliTRDRawStream.h"
7925de54 37#include "AliTRDgeometry.h"
38#include "AliTRDCommonParam.h"
3551db50 39#include "AliTRDcalibDB.h"
b864d801 40
41ClassImp(AliTRDRawStream)
42
2745a409 43//_____________________________________________________________________________
44AliTRDRawStream::AliTRDRawStream()
45 :TObject()
7925de54 46 ,fSig()
47 ,fADC(0)
48 ,fTB(0)
49 ,fEv(0)
50 ,fROB(0)
51 ,fMCM(0)
52 ,fSM(0)
53 ,fLAYER(0)
54 ,fSTACK(0)
55 ,fROC(0)
56 ,fSIDE(0)
57 ,fDCS(0)
58 ,fROW(0)
59 ,fCOL(0)
60 ,fBCctr(0)
61 ,fPTctr(0)
62 ,fPTphase(0)
63 ,fRVmajor(0)
64 ,fRVminor(0)
65 ,fHCHWords(0)
66 ,fTBins(0)
67 ,fTCon(0)
68 ,fPEDon(0)
69 ,fGAINon(0)
bd63bf88 70 ,fXTon(0)
71 ,fNonLinOn(0)
72 ,fBypass(0)
73 ,fCommonAdditive(0)
74 ,fZeroSuppressed(0)
7925de54 75 ,fHCHctr1(0)
76 ,fHCHctr2(0)
77 ,fMCMHctr1(0)
78 ,fMCMHctr2(0)
79 ,fGTUctr1(0)
80 ,fGTUctr2(0)
bd63bf88 81 ,fHCdataCtr(0)
82 ,fTracklPID(0.)
83 ,fTracklDefL(0.)
84 ,fTracklPadPos(0.)
7925de54 85 ,fTracklPadRow(0)
86 ,fGTUlinkMask()
87 ,fRawReader(NULL)
2745a409 88 ,fCount(0)
89 ,fDetector(-1)
90 ,fPrevDetector(-1)
91 ,fNPads(-1)
92 ,fRow(-1)
93 ,fPrevRow(-1)
94 ,fColumn(-1)
95 ,fPrevColumn(-1)
96 ,fTime(-1)
97 ,fSignal(-1)
bd63bf88 98 ,fRawVersion(2)
7925de54 99 ,fDataWord(0)
100 ,fStatus(0)
bd63bf88 101 ,fTbSwitch(0)
102 ,fTbSwitchCtr(0)
103 ,fTimeWords(0)
104 ,fWordCtr(0)
7925de54 105 ,fRowMax(0)
106 ,fColMax(0)
bd63bf88 107 ,fADCmask()
7925de54 108 ,fChamberDone()
109 ,fGeo(NULL)
110 ,fDigitsManager(NULL)
111 ,fDigits(NULL)
112 ,fTrack0(NULL)
113 ,fTrack1(NULL)
114 ,fTrack2(NULL)
2745a409 115{
116 //
117 // Default constructor
118 //
b864d801 119
7925de54 120 for (Int_t i = 0; i < 540; i++) {
121 fChamberDone[i] = 0;
122 }
123
124}
125
126//_____________________________________________________________________________
127AliTRDRawStream::AliTRDRawStream(AliRawReader *rawReader
128 , AliTRDdigitsManager *man
129 , AliTRDdataArrayI *dig)
130 :TObject()
131 ,fSig()
132 ,fADC(0)
133 ,fTB(0)
134 ,fEv(0)
135 ,fROB(0)
136 ,fMCM(0)
137 ,fSM(0)
138 ,fLAYER(0)
139 ,fSTACK(0)
140 ,fROC(0)
141 ,fSIDE(0)
142 ,fDCS(0)
143 ,fROW(0)
144 ,fCOL(0)
145 ,fBCctr(0)
146 ,fPTctr(0)
147 ,fPTphase(0)
148 ,fRVmajor(0)
149 ,fRVminor(0)
150 ,fHCHWords(0)
151 ,fTBins(0)
152 ,fTCon(0)
153 ,fPEDon(0)
154 ,fGAINon(0)
bd63bf88 155 ,fXTon(0)
156 ,fNonLinOn(0)
157 ,fBypass(0)
158 ,fCommonAdditive(0)
159 ,fZeroSuppressed(0)
7925de54 160 ,fHCHctr1(0)
161 ,fHCHctr2(0)
162 ,fMCMHctr1(0)
163 ,fMCMHctr2(0)
164 ,fGTUctr1(0)
165 ,fGTUctr2(0)
bd63bf88 166 ,fHCdataCtr(0)
167 ,fTracklPID(0.)
168 ,fTracklDefL(0.)
169 ,fTracklPadPos(0.)
7925de54 170 ,fTracklPadRow(0)
171 ,fGTUlinkMask()
172 ,fRawReader(rawReader)
173 ,fCount(0)
174 ,fDetector(-1)
175 ,fPrevDetector(-1)
176 ,fNPads(-1)
177 ,fRow(-1)
178 ,fPrevRow(-1)
179 ,fColumn(-1)
180 ,fPrevColumn(-1)
181 ,fTime(-1)
182 ,fSignal(-1)
bd63bf88 183 ,fRawVersion(2)
7925de54 184 ,fDataWord(0)
185 ,fStatus(0)
bd63bf88 186 ,fTbSwitch(0)
187 ,fTbSwitchCtr(0)
188 ,fTimeWords(0)
189 ,fWordCtr(0)
7925de54 190 ,fRowMax(0)
191 ,fColMax(0)
bd63bf88 192 ,fADCmask()
7925de54 193 ,fChamberDone()
194 ,fGeo(NULL)
195 ,fDigitsManager(man)
196 ,fDigits(dig)
197 ,fTrack0(NULL)
198 ,fTrack1(NULL)
199 ,fTrack2(NULL)
200
201{
202 //
203 // Create an object to read TRD raw digits
204 //
205
206 fGeo = new AliTRDgeometry();
207
208 fRawReader->Select("TRD");
209
210 for (Int_t i = 0; i < 540; i++) {
211 fChamberDone[i] = 0;
212 }
213
2745a409 214}
215
216//_____________________________________________________________________________
7925de54 217AliTRDRawStream::AliTRDRawStream(AliRawReader *rawReader)
2745a409 218 :TObject()
7925de54 219 ,fSig()
220 ,fADC(0)
221 ,fTB(0)
222 ,fEv(0)
223 ,fROB(0)
224 ,fMCM(0)
225 ,fSM(0)
226 ,fLAYER(0)
227 ,fSTACK(0)
228 ,fROC(0)
229 ,fSIDE(0)
230 ,fDCS(0)
231 ,fROW(0)
232 ,fCOL(0)
233 ,fBCctr(0)
234 ,fPTctr(0)
235 ,fPTphase(0)
236 ,fRVmajor(0)
237 ,fRVminor(0)
238 ,fHCHWords(0)
239 ,fTBins(0)
240 ,fTCon(0)
241 ,fPEDon(0)
242 ,fGAINon(0)
bd63bf88 243 ,fXTon(0)
244 ,fNonLinOn(0)
245 ,fBypass(0)
246 ,fCommonAdditive(0)
247 ,fZeroSuppressed(0)
7925de54 248 ,fHCHctr1(0)
249 ,fHCHctr2(0)
250 ,fMCMHctr1(0)
251 ,fMCMHctr2(0)
252 ,fGTUctr1(0)
253 ,fGTUctr2(0)
bd63bf88 254 ,fHCdataCtr(0)
255 ,fTracklPID(0.)
256 ,fTracklDefL(0.)
257 ,fTracklPadPos(0.)
7925de54 258 ,fTracklPadRow(0)
259 ,fGTUlinkMask()
2745a409 260 ,fRawReader(rawReader)
261 ,fCount(0)
262 ,fDetector(-1)
263 ,fPrevDetector(-1)
264 ,fNPads(-1)
265 ,fRow(-1)
266 ,fPrevRow(-1)
267 ,fColumn(-1)
268 ,fPrevColumn(-1)
269 ,fTime(-1)
270 ,fSignal(-1)
bd63bf88 271 ,fRawVersion(2)
7925de54 272 ,fDataWord(0)
273 ,fStatus(0)
bd63bf88 274 ,fTbSwitch(0)
275 ,fTbSwitchCtr(0)
276 ,fTimeWords(0)
277 ,fWordCtr(0)
7925de54 278 ,fRowMax(0)
279 ,fColMax(0)
bd63bf88 280 ,fADCmask()
7925de54 281 ,fChamberDone()
282 ,fGeo(NULL)
283 ,fDigitsManager(NULL)
284 ,fDigits(NULL)
285 ,fTrack0(NULL)
286 ,fTrack1(NULL)
287 ,fTrack2(NULL)
288
b864d801 289{
2745a409 290 //
291 // Create an object to read TRD raw digits
292 //
b864d801 293
362c9d61 294 fRawReader->Select("TRD");
2745a409 295
7925de54 296 for (Int_t i = 0; i < 540; i++) {
297 fChamberDone[i] = 0;
298 }
299
b864d801 300}
301
2745a409 302//_____________________________________________________________________________
7925de54 303AliTRDRawStream::AliTRDRawStream(const AliTRDRawStream& stream)
304 :TObject(stream)
305 ,fSig()
bd63bf88 306 ,fADC(-1)
307 ,fTB(-1)
308 ,fEv(-1)
309 ,fROB(-1)
310 ,fMCM(-1)
311 ,fSM(-1)
312 ,fLAYER(-1)
313 ,fSTACK(-1)
314 ,fROC(-1)
315 ,fSIDE(-1)
316 ,fDCS(-1)
317 ,fROW(-1)
318 ,fCOL(-1)
319 ,fBCctr(-1)
320 ,fPTctr(-1)
321 ,fPTphase(-1)
322 ,fRVmajor(-1)
323 ,fRVminor(-1)
324 ,fHCHWords(-1)
325 ,fTBins(-1)
7925de54 326 ,fTCon(0)
327 ,fPEDon(0)
328 ,fGAINon(0)
bd63bf88 329 ,fXTon(0)
330 ,fNonLinOn(-1)
331 ,fBypass(-1)
332 ,fCommonAdditive(-1)
333 ,fZeroSuppressed(0)
334 ,fHCHctr1(-1)
335 ,fHCHctr2(-1)
336 ,fMCMHctr1(-1)
337 ,fMCMHctr2(-1)
338 ,fGTUctr1(-1)
339 ,fGTUctr2(-1)
340 ,fHCdataCtr(-1)
341 ,fTracklPID(-1.)
342 ,fTracklDefL(-1.)
343 ,fTracklPadPos(-1.)
344 ,fTracklPadRow(-1)
7925de54 345 ,fGTUlinkMask()
346 ,fRawReader(NULL)
bd63bf88 347 ,fCount(-1)
7925de54 348 ,fDetector(-1)
349 ,fPrevDetector(-1)
350 ,fNPads(-1)
351 ,fRow(-1)
352 ,fPrevRow(-1)
353 ,fColumn(-1)
354 ,fPrevColumn(-1)
355 ,fTime(-1)
356 ,fSignal(-1)
bd63bf88 357 ,fRawVersion(-1)
7925de54 358 ,fDataWord(0)
bd63bf88 359 ,fStatus(-1)
360 ,fTbSwitch(0)
361 ,fTbSwitchCtr(0)
362 ,fTimeWords(0)
363 ,fWordCtr(0)
364 ,fRowMax(-1)
365 ,fColMax(-1)
366 ,fADCmask()
7925de54 367 ,fChamberDone()
368 ,fGeo(NULL)
369 ,fDigitsManager(NULL)
370 ,fDigits(NULL)
371 ,fTrack0(NULL)
372 ,fTrack1(NULL)
373 ,fTrack2(NULL)
374
b864d801 375{
2745a409 376 //
377 // Copy constructor
378 //
379
380 AliFatal("Copy constructor not implemented");
381
b864d801 382}
383
2745a409 384//_____________________________________________________________________________
b864d801 385AliTRDRawStream& AliTRDRawStream::operator = (const AliTRDRawStream&
386 /* stream */)
387{
2745a409 388 //
389 // Assigment operator
390 //
391
b864d801 392 Fatal("operator =", "assignment operator not implemented");
393 return *this;
2745a409 394
b864d801 395}
396
2745a409 397//_____________________________________________________________________________
b864d801 398AliTRDRawStream::~AliTRDRawStream()
399{
2745a409 400 //
401 // Destructor
402 //
b864d801 403
7925de54 404}
405
406//_____________________________________________________________________________
407Bool_t AliTRDRawStream::SetRawVersion(Int_t rv)
408{
409 //
410 // Set the raw data version
411 //
412
bd63bf88 413 if ( rv >= 0 && rv <= 3 ) {
7925de54 414 fRawVersion = rv;
415 return kTRUE;
416 }
417
418 return kFALSE;
419
b864d801 420}
421
2745a409 422//_____________________________________________________________________________
b864d801 423Bool_t AliTRDRawStream::Next()
424{
2745a409 425 //
7925de54 426 // This is Bogdans code for reading raw data (offline use only).
427 // It is used for fRawVersion == 0. This funcyion read the next raw digit.
2745a409 428 // Returns kFALSE if there is no digit left
429 //
b864d801 430
431 fPrevDetector = fDetector;
2745a409 432 fPrevRow = fRow;
433 fPrevColumn = fColumn;
b864d801 434 UChar_t data;
435
7925de54 436 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
437 if (!calibration) return kFALSE;
3551db50 438
439 Int_t timeBins = calibration->GetNumberOfTimeBins();
440
b864d801 441 while (fCount >= 0) {
442
443 while (fCount == 0) { // next detector
7925de54 444
b864d801 445 // read the flag
7925de54 446 if (!fRawReader->ReadNextChar(data)) {
447 return kFALSE;
448 }
b864d801 449 if (data != 0xBB) {
2745a409 450 AliError(Form("wrong flag: %x", data));
b864d801 451 fCount = -1;
452 return kFALSE;
453 }
454
455 // read the detector number
456 if (!fRawReader->ReadNextChar(data)) {
2745a409 457 AliError("Could not read detector number");
b864d801 458 fCount = -1;
459 return kFALSE;
460 }
461 fDetector = data;
462 if (!fRawReader->ReadNextChar(data)) {
2745a409 463 AliError("Could not read detector number");
b864d801 464 fCount = -1;
465 return kFALSE;
466 }
467 fDetector += (UInt_t(data) << 8);
468
469 // read the number of byts
470 if (!fRawReader->ReadNextChar(data)) {
2745a409 471 AliError("Could not read number of bytes");
b864d801 472 fCount = -1;
473 return kFALSE;
474 }
475 fCount = data;
476 if (!fRawReader->ReadNextChar(data)) {
2745a409 477 AliError("Could not read number of bytes");
b864d801 478 fCount = -1;
479 return kFALSE;
480 }
481 fCount += (UInt_t(data) << 8);
928e9fae 482 if (!fRawReader->ReadNextChar(data)) {
2745a409 483 AliError("Could not read number of bytes");
928e9fae 484 fCount = -1;
485 return kFALSE;
486 }
487 fCount += (UInt_t(data) << 16);
b864d801 488
489 // read the number of active pads
490 if (!fRawReader->ReadNextChar(data)) {
2745a409 491 AliError("Could not read number of active pads");
b864d801 492 fCount = -1;
493 return kFALSE;
494 }
495 fNPads = data;
496 if (!fRawReader->ReadNextChar(data)) {
2745a409 497 AliError("Could not read number of active pads");
b864d801 498 fCount = -1;
499 return kFALSE;
500 }
501 fNPads += (UInt_t(data) << 8);
502
3551db50 503 fTime = timeBins;
b864d801 504
b864d801 505 }
506
507 // read the pad row and column number
3551db50 508 if ((fTime >= timeBins) && (fCount > 2)) {
b864d801 509 if (!fRawReader->ReadNextChar(data)) {
2745a409 510 AliError("Could not read row number");
b864d801 511 fCount = -1;
512 return kFALSE;
513 }
514 fCount--;
515 fRow = data - 1;
516 if (!fRawReader->ReadNextChar(data)) {
2745a409 517 AliError("Could not read column number");
b864d801 518 fCount = -1;
519 return kFALSE;
520 }
521 fCount--;
522 fColumn = data - 1;
523 fTime = 0;
524 }
525
526 // read the next data byte
527 if (!fRawReader->ReadNextChar(data)) {
2745a409 528 AliError("Could not read data");
b864d801 529 fCount = -1;
530 return kFALSE;
531 }
532 fCount--;
533
534 if (data == 0) { // zeros
535 if (!fRawReader->ReadNextChar(data)) {
2745a409 536 AliError("Could not read time value");
b864d801 537 fCount = -1;
538 return kFALSE;
539 }
540 fCount--;
541 fTime += data + 1;
542
2745a409 543 }
544 else { // signal
b864d801 545 fSignal = (UInt_t(data & 0x7F) << 8);
546 if (!fRawReader->ReadNextChar(data)) {
2745a409 547 AliError("Could not read ADC value");
b864d801 548 fCount = -1;
549 return kFALSE;
550 }
551 fCount--;
552 fSignal += data;
553 fTime++;
554 return kTRUE;
555 }
556 }
557
558 return kFALSE;
2745a409 559
b864d801 560}
7925de54 561
562//____________________________________________________________________________
bd63bf88 563Int_t AliTRDRawStream::ReadAll()
7925de54 564{
565
566 //
41235089 567 // Read all TRD raw data word (32 bits). This is for all fRawVersion > 0.
bd63bf88 568 // Return 0 if something is not cool, 2 if data seems empty
7925de54 569 //
570 // by C. Lippmann
571 //
572
573 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
574 if (!commonParam) {
575 AliError("Could not get common parameters");
bd63bf88 576 return 0;
7925de54 577 }
578
579 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
580 if (!calibration) {
581 AliError("Could not get calibration object");
bd63bf88 582 return 0;
7925de54 583 }
584
585 UInt_t timeTotal = calibration->GetNumberOfTimeBins();
bd63bf88 586 AliDebug(2, Form("Number of Timebins read from CDB: %d", timeTotal));
7925de54 587
588 // The number of data words needed for this number of time bins (there
589 // are 3 time bins in one word)
bd63bf88 590 fTimeWords = (timeTotal-1)/3 + 1;
7925de54 591
bd63bf88 592 fTbSwitch = 3;
593 fTbSwitchCtr = 0;
594
595 Int_t EqID = 0;
596 UInt_t datasize = 0;
597 Int_t iDET = 0;
598
599 Int_t retval = 0;
7925de54 600
bd63bf88 601 Bool_t sizeOK = kFALSE;
7925de54 602
603 fHCHctr1 = fHCHctr2 = 0;
604 fGTUctr1 = fGTUctr2 = -1;
605
bd63bf88 606 fHCdataCtr = 0;
607 fWordCtr = 0;
608
7925de54 609 AliInfo("Converting TRD raw data to digits ...");
610
611 while ( 1 ) { // loop over all supermodules
612
bd63bf88 613 fWordCtr = 0;
7925de54 614 fHCHctr1 = 0;
615 fMCMHctr1 = 0;
616
617 //
618 // 0) Find first GTU Link Mask and test if we can read data
619 //
620 do {
621
41235089 622 if ( !fRawReader->ReadNextInt( fDataWord ) ) { // This is the standard exit point
623 // Compress also the digits from the last detector
624 if ( fChamberDone[iDET] == 2 ) {
625 //printf("Compressing data for det %d\n", iDET);
626 fDigits->Compress(1,0);
627 fTrack0->Compress(1,0);
628 fTrack1->Compress(1,0);
629 fTrack2->Compress(1,0);
630 }
7925de54 631 AliInfo(Form("Finished processing TRD raw data: Found %d Half-Chambers", fHCHctr2));
41235089 632 //
633 /*
634 fDigits = fDigitsManager->GetDigits(iDET+1);
635 fTrack0 = fDigitsManager->GetDictionary(iDET+1,0);
636 fTrack1 = fDigitsManager->GetDictionary(iDET+1,1);
637 fTrack2 = fDigitsManager->GetDictionary(iDET+1,2);
638 fDigits->Allocate(fRowMax,fColMax,timeTotal);
639 fTrack0->Allocate(fRowMax,fColMax,timeTotal);
640 fTrack1->Allocate(fRowMax,fColMax,timeTotal);
641 fTrack2->Allocate(fRowMax,fColMax,timeTotal);
642 fDigits->SetDataUnchecked(0, 0, 0, 50);
643 fTrack0->SetDataUnchecked(0, 0, 0, 0);
bd63bf88 644 fTrack1->Set
41235089 645 fTrack2->SetDataUnchecked(0, 0, 0, 0);
646 fDigits->Compress(1,0);
647 fTrack0->Compress(1,0);
648 fTrack1->Compress(1,0);
649 fTrack2->Compress(1,0);
650 */
651 //
bd63bf88 652 if ( sizeOK ) return 1;
653 else return 2;
7925de54 654 }
bd63bf88 655
656 fWordCtr++;
7925de54 657
658 // After reading the first word check for size of this data and get Eq. ID
bd63bf88 659 if ( fWordCtr == 1 ) {
660 datasize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
7925de54 661 EqID = fRawReader->GetEquipmentId(); // Get Equipment ID
bd63bf88 662 //if ( sizeOK = kFALSE && datasize > 0 ) { sizeOK = kTRUE; printf("Yo\n"); }
663 if ( datasize > 0 ) sizeOK = kTRUE;
7925de54 664 }
665
666 // GTU Link Mask?
667 if ( (fDataWord & 0xfffff000) == 0xe0000000 ) {
668 fStatus = 1; // GTU link mask found
669 DecodeGTUlinkMask();
670 break;
671 }
672 else {
673 AliError(Form("Equipment %d: First data word is not GTU Link Mask!", EqID));
bd63bf88 674 return 0;
7925de54 675 }
676
677 }
bd63bf88 678 while ( fWordCtr < datasize );
7925de54 679
680 //
681 // loop over all half chambers in one supermodule
682 //
bd63bf88 683 while ( fWordCtr < datasize ) {
7925de54 684
685 //
686 // 1) Find end_of_tracklet_marker
687 //
bd63bf88 688 while ( fWordCtr < datasize ) {
7925de54 689
690 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
691 AliError("Could not read data");
bd63bf88 692 return 0;
7925de54 693 }
bd63bf88 694 fWordCtr++;
7925de54 695
696 // GTU Link Mask?
697 if ( (fDataWord & 0xfffff000) == 0xe0000000 ) {
698 DecodeGTUlinkMask();
699 continue;
700 }
701
41235089 702 // endoftrackletmarker?
bd63bf88 703 if ( fDataWord == kEndoftrackletmarker ) {
41235089 704 AliDebug(3, "end-of-tracklet-marker found");
7925de54 705 fStatus = 1;
706 break;
707 }
708 else {
709 // Tracklets found
710 AliDebug(3, "Tracklet found");
711 DecodeTracklet();
712 }
713
714 }
715
716 if ( fStatus == 0 ) break;
717
718 //
719 // 2) Look for non-end_of_tracklet_marker
720 //
721 fStatus = 0;
bd63bf88 722 while ( fWordCtr < datasize ) {
7925de54 723
724 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
725 AliError("Could not read data");
bd63bf88 726 return 0;
7925de54 727 }
bd63bf88 728 fWordCtr++;
729 //printf("Word %d: 0x%08x\n", fWordCtr, fDataWord);
7925de54 730
bd63bf88 731 if ( fDataWord != kEndoftrackletmarker ) {
7925de54 732 fStatus = 1;
733 break;
734 }
735
736 }
737
738 if ( fStatus == 0 ) break;
739
740 //
741 // 3) This Word must be Half Chamber Header
742 //
743 fStatus = 0;
744 if ( (fDataWord & 0x00000003) == 1 ) { // HC header
745
746 // If both half chambers of chamber corresponding to previous header
747 // were already processed, we can compress these digits
bd63bf88 748 iDET = fGeo->GetDetector(fLAYER, fSTACK, fSM); // !!this is still the previous HC!!
7925de54 749 if ( fChamberDone[iDET] == 2 ) {
41235089 750 //printf("Compressing data for det %d\n", iDET);
7925de54 751 fDigits->Compress(1,0);
752 fTrack0->Compress(1,0);
753 fTrack1->Compress(1,0);
754 fTrack2->Compress(1,0);
755 }
7925de54 756 // Read from new HC header the chamber position (fLAYER, fSTACK, fSM)
41235089 757 DecodeHCheader(timeTotal); // This is the new header!
7925de54 758 iDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
759 fRowMax = commonParam->GetRowMax(fLAYER,fSTACK,fSM);
760 fColMax = commonParam->GetColMax(fROC);
761
41235089 762 // The container for the digits of this detector
7925de54 763 fDigits = fDigitsManager->GetDigits(iDET);
764 fTrack0 = fDigitsManager->GetDictionary(iDET,0);
765 fTrack1 = fDigitsManager->GetDictionary(iDET,1);
766 fTrack2 = fDigitsManager->GetDictionary(iDET,2);
767
7925de54 768 // Allocate memory if it was not already done
769 if (fDigits->GetNtime() == 0) {
41235089 770 //printf("Allocating digits memory for det %d\n", iDET);
bd63bf88 771 fDigits->Allocate(fRowMax, fColMax, fTBins);
772 fTrack0->Allocate(fRowMax, fColMax, fTBins);
773 fTrack1->Allocate(fRowMax, fColMax, fTBins);
774 fTrack2->Allocate(fRowMax, fColMax, fTBins);
775 }
776 if ( fZeroSuppressed ) { // Make sure digits in this HC are 0
777 for ( Int_t colctr = fSIDE*fColMax/2; colctr < fColMax*(1+fSIDE)/2; colctr++ ) {
778 for ( Int_t rowctr = 0; rowctr < fRowMax; rowctr++ ) {
779 for ( Int_t timectr = 0; timectr < fTBins; timectr++ ) {
780 fDigits->SetDataUnchecked(rowctr, colctr, timectr, 0);
781 fTrack0->SetDataUnchecked(rowctr, colctr, timectr, 0);
782 fTrack1->SetDataUnchecked(rowctr, colctr, timectr, 0);
783 fTrack2->SetDataUnchecked(rowctr, colctr, timectr, 0);
784 }
785 }
786 }
7925de54 787 }
7925de54 788 fMCMHctr2 = 0;
bd63bf88 789 fHCdataCtr = 0;
7925de54 790
8c56d8cc 791 fChamberDone[iDET]++;
41235089 792
7925de54 793 }
794
795 //
796 // 4) Scan MCM data
797 //
798 fStatus = 0;
bd63bf88 799 while ( fWordCtr < datasize ) {
7925de54 800
801 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
802 AliError("Could not read data");
bd63bf88 803 return 0;
7925de54 804 }
bd63bf88 805 fWordCtr++;
806 //printf("Word %d: 0x%08x\n", fWordCtr, fDataWord);
7925de54 807
bd63bf88 808 fHCdataCtr += 4;
809
810 //if( (fDataWord & 0x0000000f) == 0xC ) { // MCM Header
811 if( ((fDataWord & 0x80000000) == 0x0) && ((fDataWord & 0x0000000f) == 0xC) ) { // MCM Header
7925de54 812 DecodeMCMheader();
813 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 ) {
814 AliError("Wrong fMCM or fROB. Skip this data");
815 break;
816 }
bd63bf88 817 fTbSwitch = 3; // For first adc channel we expect: (fDataWord & 3) = 3
818 fTbSwitchCtr = 0; //
819 fADC = fTB = 0; // Reset Counter
820 fStatus = 1; // Now 1 means MCM header is found
7925de54 821 continue;
822 }
823
bd63bf88 824 if ( fDataWord == kEndofrawdatamarker ) { // End of half-chamber data, finished
7925de54 825 fGTUctr1 = -1;
826 break;
827 }
828
829 if ( fStatus == 1 ) { // MCM header is set, ADC data is valid.
830
7925de54 831 // Found some data. Decode it now:
bd63bf88 832 retval = DecodeDataWord();
833 if ( retval == 0 ) continue;
834 if ( retval == -1 ) break;
835
7925de54 836 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 ) {
837
7925de54 838 // Write Digits
839 if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax ) { // A real pad
41235089 840 for ( Int_t ctr = 0; ctr < 3; ctr++ ) {
7925de54 841 if ( fTB+ctr < (Int_t)timeTotal ) {
41235089 842 /*
7925de54 843 fDigits->SetDataUnchecked(fROW, fCOL, fTB+ctr, fSig[ctr]);
844 fTrack0->SetDataUnchecked(fROW, fCOL, fTB+ctr, 0);
845 fTrack1->SetDataUnchecked(fROW, fCOL, fTB+ctr, 0);
846 fTrack2->SetDataUnchecked(fROW, fCOL, fTB+ctr, 0);
41235089 847 */
bd63bf88 848
849 //
850 // Pedestal subtraction done here (???):
851 //
852 //fDigits->SetData(fROW, fCOL, fTB+ctr, fSig[ctr] - fCommonAdditive);
41235089 853 fDigits->SetData(fROW, fCOL, fTB+ctr, fSig[ctr]);
854 fTrack0->SetData(fROW, fCOL, fTB+ctr, 0);
855 fTrack1->SetData(fROW, fCOL, fTB+ctr, 0);
856 fTrack2->SetData(fROW, fCOL, fTB+ctr, 0);
7925de54 857 }
858 }
859 }
860
861 fTB += 3;
862
bd63bf88 863 }
7925de54 864 else {
865
866 fCOL = -1;
867
868 }
869
870 }
bd63bf88 871
7925de54 872 }
873
bd63bf88 874 AliDebug(2, Form("SM%02d L%dS%d side %x: Processed %dMCMs=%dbyte", fSM, fLAYER, fSTACK, fSIDE+10,
875 fMCMHctr2, fHCdataCtr));
7925de54 876
877 } // End Half-Chamber loop
878
bd63bf88 879 AliDebug(1, Form("SM%02d (Eq %d): Processed %d HC (%dMCMs=%dbyte)", fSM, EqID, fHCHctr1, fMCMHctr1,
880 datasize*4));
881
7925de54 882 } // End Super Module loop
883
41235089 884 // Compress also the digits from the last detector
885 if ( fChamberDone[iDET] == 2 ) {
886 //printf("Compressing data for det %d\n", iDET);
887 fDigits->Compress(1,0);
888 fTrack0->Compress(1,0);
889 fTrack1->Compress(1,0);
890 fTrack2->Compress(1,0);
891 }
892
bd63bf88 893 if ( sizeOK ) return 1;
894 else return 2;
7925de54 895
896}
897
898//============================================================================
899// Decoding functions
900//============================================================================
901
902//____________________________________________________________________________
903void AliTRDRawStream::DecodeHCheader(Int_t timeBins)
904{
905 //
906 // Decode a half chamber header
907 //
908
bd63bf88 909 if ( (fDataWord >> 31) == 0 ) { // Can only happen for fRawVersion == 1
910
911 if ( fRawVersion != 1 ) {
912
913 AliWarning("===============================================================================");
914 AliWarning(Form("Mismatch between fRawVersion (%d) and HC header signature", fRawVersion));
915 AliWarning("Setting fRawVersion to 1");
916 AliWarning("===============================================================================");
917 fRawVersion = 1;
7925de54 918
7925de54 919 }
bd63bf88 920
921 DecodeHCheaderV1();
7925de54 922 return;
923
924 }
925 else {
926
927 fRVmajor = (fDataWord >> 24) & 0x7f;
928 fRVminor = (fDataWord >> 17) & 0x7f;
bd63bf88 929
7925de54 930 if ( fRawVersion != fRVmajor ) {
bd63bf88 931
932 AliWarning("===============================================================================");
933 AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)"
934 ,fRawVersion,fRVmajor));
935 AliWarning(Form("Setting fRawVersion to %d", fRVmajor));
936 AliWarning("===============================================================================");
937 fRawVersion = fRVmajor;
938
7925de54 939 }
bd63bf88 940 if ( fRawVersion >= 2 && fRawVersion <= 3 ) {
941 DecodeHCheaderV2V3(timeBins);
7925de54 942 }
bd63bf88 943
944 //
945 // check for zero suppression
946 if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
947 else fZeroSuppressed = kFALSE;
948
7925de54 949 return;
950
951 }
952
953 AliError(Form(" Unsupported raw version: %d", fRawVersion));
954 return;
955
956}
957
958//____________________________________________________________________________
959void AliTRDRawStream::DecodeHCheaderV1()
960{
961
962 //
963 // Decode the HC header (fRawVersion == 1, SM I Commissioning 06)
964 //
965
966 if ( (fDataWord & 0x3) == 1 ) {
967
968 fDCS = (fDataWord >> 20);
969 fSM = (fDataWord >> 15) & 0x1f;
970 fLAYER = (fDataWord >> 12) & 0x7;
971 fSTACK = (fDataWord >> 9) & 0x7;
972 fSIDE = (fDataWord >> 8) & 0x1;
973
974 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
975
976 //AliDebug(3, Form("0x%08x: HC header: dcs=%d; sm=%d; roc=%d; side=%x", fDataWord, fDCS, fSM, fROC, fSIDE+10));
bd63bf88 977
7925de54 978 if ((fSM < 0) ||
979 (fSM > 17) ||
980 (fLAYER < 0) ||
981 (fLAYER > 5) ||
982 (fSTACK < 0) ||
983 (fSTACK > 4) ||
984 (fSIDE < 0) ||
985 (fSIDE > 1)) {
bd63bf88 986 AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
987 fDataWord, fDCS, fSM, fLAYER, fSTACK));
7925de54 988 }
989 else {
990 fStatus = 1;
991 fHCHctr1++;
992 fHCHctr2++;
993 }
994 fHCHWords = 0;
995
996 }
997 else {
998
999 AliError(Form("0x%08x: No HC header when it was expected.", fDataWord));
1000
1001 }
1002
1003}
1004
1005
1006//____________________________________________________________________________
bd63bf88 1007void AliTRDRawStream::DecodeHCheaderV2V3(Int_t timeBins)
7925de54 1008{
1009 //
bd63bf88 1010 // Decode the HC header (fRawVersion == 2, 3, 4, ???)
7925de54 1011 //
1012
bd63bf88 1013 // 1st word (h[0])
7925de54 1014 if ( (fDataWord & 0x3) == 1 ) {
1015
1016 fHCHWords = (fDataWord >> 14) & 0x7;
1017 fSM = (fDataWord >> 9) & 0x1f;
1018 fLAYER = (fDataWord >> 6) & 0x7;
1019 fSTACK = (fDataWord >> 3) & 0x7;
1020 fSIDE = (fDataWord >> 2) & 0x1;
1021
1022 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
1023
1024 AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", fDataWord, fSM, fROC, fSIDE+10));
1025
1026 if ((fSM < 0) ||
1027 (fSM > 17) ||
1028 (fLAYER < 0) ||
1029 (fLAYER > 5) ||
1030 (fSTACK < 0) ||
1031 (fSTACK > 4) ||
1032 (fSIDE < 0) ||
1033 (fSIDE > 1)) {
1034 AliError(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
1035 fDataWord, fDCS, fSM, fLAYER, fSTACK));
1036 }
1037 else {
1038 fStatus = 1;
1039 fHCHctr1++;
1040 fHCHctr2++;
1041 }
1042 }
1043 else {
1044 AliError(Form("0x%08x: No HC header when it was expected.", fDataWord));
1045 }
1046
bd63bf88 1047 // 2nd word (h[1])
7925de54 1048 if ( fHCHWords >= 1 ) {
1049 // read one more word
1050 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
1051 AliError("Could not read data");
1052 return;
1053 }
bd63bf88 1054 fWordCtr++;
7925de54 1055 if ( (fDataWord & 0x3) == 1 ) {
1056
1057 fBCctr = (fDataWord >> 16);
1058 fPTctr = (fDataWord >> 12) & 0xf;
1059 fPTphase = (fDataWord >> 8) & 0xf;
1060 fTBins = ((fDataWord >> 2) & 0x3f) + 1;
1061
1062 AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
1063 , fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
1064
1065 if( fTBins != timeBins ) {
bd63bf88 1066
1067 AliWarning("===============================================================================");
1068 AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)"
1069 , timeBins, fTBins));
1070 AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins));
1071 AliWarning("===============================================================================");
1072
7925de54 1073 }
1074
1075 }
1076
1077 }
1078
bd63bf88 1079 // 3nd word (h[2])
7925de54 1080 if ( fHCHWords >= 2 ) {
1081 // read one more word
1082 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
1083 AliError("Could not read data");
1084 return;
1085 }
bd63bf88 1086 fWordCtr++;
7925de54 1087 if ( (fDataWord & 0x3) == 1 ) {
bd63bf88 1088
1089 fTCon = (fDataWord >> 29) & 0x1;
1090 fPEDon = (fDataWord >> 31) & 0x1;
1091 fGAINon = (fDataWord >> 30) & 0x1;
1092 fXTon = (fDataWord >> 28) & 0x1;
1093 fNonLinOn = (fDataWord >> 27) & 0x1;
1094 fBypass = (fDataWord >> 26) & 0x1;
1095
1096 fCommonAdditive = (fDataWord >> 20) & 0x3f;
1097
1098 AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d"
1099 , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive));
1100
1101 if( fTBins != timeBins ) {
1102 AliError(Form("Mismatch between Number of Time Bins from CDB (%d) and from HC header (%d)"
1103 , timeBins, fTBins));
1104 }
1105
7925de54 1106 }
1107
1108 }
1109
1110}
1111
1112//____________________________________________________________________________
1113void AliTRDRawStream::DecodeMCMheader()
1114{
1115 //
1116 //
1117 //
1118
bd63bf88 1119 if ( fRawVersion >= 1 && fRawVersion <= 3 ) {
1120 DecodeMCMheaderVx();
7925de54 1121 return;
1122 }
1123
1124 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1125 return;
1126
1127}
1128
1129//____________________________________________________________________________
bd63bf88 1130void AliTRDRawStream::DecodeMCMheaderVx()
7925de54 1131{
1132
1133 //
1134 // Decode the MCM header
1135 //
1136
1137 fMCM = (fDataWord & 0xff000000) >> 24;
1138 fEv = (fDataWord & 0x00fffff0) >> 4;
1139
1140 fROB = fMCM / 16;
1141 fMCM = fMCM % 16;
1142
bd63bf88 1143 fROW = fGeo->GetPadRowFromMCM(fROB, fMCM);
7925de54 1144
1145 AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d"
1146 , fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv));
1147
1148 if ( fROB % 2 == 0 && fSIDE == 1 ) {
1149 AliError(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
1150 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
1151 }
1152 if ( fROB % 2 != 0 && fSIDE == 0 ) {
1153 AliError(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
1154 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
1155 }
bd63bf88 1156 if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
1157 (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
7925de54 1158 AliError(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1159 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
1160 }
1161
1162 fMCMHctr1++;
1163 fMCMHctr2++;
1164
bd63bf88 1165 // AdcMask for Zero supressed data
1166 if ( fRawVersion == 3 ) {
1167 // read one more word
1168 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
1169 AliError("Could not read data");
1170 return;
1171 }
1172 fWordCtr++;
1173 if ( (fDataWord & 0x000007ff) == 0xC ) { // at the moment bits 4-10 are empty
1174 //if ( (fDataWord & 0x0000000f) == 0xC ) {
1175
1176 for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
1177 if ( (fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
1178 else fADCmask[ctr] = kFALSE;
1179 }
1180
1181 AliDebug(4, Form("0x%08x: ADC mask", fDataWord));
1182
1183 }
1184 else {
1185 AliError("Expected ADC mask but did not find one!");
1186 }
1187
1188 }
1189
7925de54 1190}
1191
1192//____________________________________________________________________________
1193void AliTRDRawStream::DecodeTracklet()
1194{
1195 //
1196 //
1197 //
1198
bd63bf88 1199 if ( fRawVersion >= 1 && fRawVersion <= 3 ) {
1200 DecodeTrackletVx();
7925de54 1201 return;
1202 }
1203
1204 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1205 return;
1206
1207}
1208
1209//____________________________________________________________________________
bd63bf88 1210void AliTRDRawStream::DecodeTrackletVx()
7925de54 1211{
1212
1213 //
1214 // Decode the Tracklet
1215 //
1216 // this function is not tested yet on real tracklets
1217 //
1218
1219 fTracklPID = (fDataWord >> 24) & 0xff;
1220 fTracklPadRow = (fDataWord >> 20) & 0xf; // 0:15
1221 fTracklDefL = (fDataWord >> 13) & 0x7f;
1222 fTracklPadPos = (fDataWord) & 0x1fff;
1223
1224 fTracklPID /= (Float_t)((1<<8) - 1); // 0:1 (steps of 0.39%)
1225 fTracklDefL = (fTracklDefL - ((1<< 7)-1)/2.) * 140.e-4; // -0.889:0.889cm
1226 fTracklPadPos = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm
1227
1228 AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f"
1229 , fDataWord, fSM, fLAYER, fSTACK, fSIDE+10
1230 , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID));
1231
f78960c8 1232 if( (fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0()) ||
1233 (fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1()) ) {
7925de54 1234 AliError(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow));
1235 }
1236
1237}
1238
1239//____________________________________________________________________________
1240void AliTRDRawStream::DecodeGTUlinkMask()
1241{
1242 //
1243 //
1244 //
1245
bd63bf88 1246 if ( fRawVersion >= 1 && fRawVersion <= 3 ) {
1247 DecodeGTUlinkMaskVx();
7925de54 1248 return;
1249 }
1250
1251 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1252 return;
1253
1254}
1255
1256//____________________________________________________________________________
bd63bf88 1257void AliTRDRawStream::DecodeGTUlinkMaskVx()
7925de54 1258{
1259
1260 //
1261 // Decode the link masks sent by the GTU. These marke the active optical links
1262 // between GTU and Super Module. Up to now only fully active links are found
1263 // (0xfff = 12 active links).
1264 //
1265
1266 if ( fGTUctr1 == -1 ) fGTUctr2++;
1267 fGTUctr1++;
1268
1269 //printf("fGTUctr=%d",fGTUctr);
1270 //printf("fGTUctr1=%d, fGTUctr2=%d",fGTUctr1, fGTUctr2);
1271
1272 if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) ) {
1273 fGTUlinkMask[fGTUctr2][fGTUctr1] = (fDataWord & 0xfff);
1274 }
1275
1276 for ( Int_t ctr = 0; ctr < 12; ctr++ ) {
1277 if ( IsGTULinkActive(fGTUctr2, ctr/2, fGTUctr1, ctr%2) ) {
1278 AliDebug(3, Form("SM %2d Stack %d: GTU Link %2d is active!", fGTUctr2, fGTUctr1, ctr));
1279 }
1280 }
1281
1282}
1283
bd63bf88 1284//____________________________________________________________________________
1285Int_t AliTRDRawStream::DecodeDataWord()
1286{
1287
1288 //
1289 // Decode the Data
1290 //
1291
1292 if ( fRawVersion >= 1 && fRawVersion <= 2 ) {
1293 return DecodeDataWordV1V2();
1294 }
1295 else if ( fRawVersion >= 3 && fRawVersion <= 3 ) {
1296 return DecodeDataWordV3();
1297 }
1298
1299 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1300 return -1;
1301
1302}
1303
1304//____________________________________________________________________________
1305Int_t AliTRDRawStream::DecodeDataWordV1V2()
1306{
1307
1308 //
1309 // Decode the Data (full raw data. No zero suppression. 21 adc channels)
1310 //
1311 // return 0 means continue to next data word
1312 // return -1 means break data loop
1313 //
1314
1315 if ( (fDataWord & 0x00000003) != 0x2 && (fDataWord & 0x00000003) != 0x3) {
1316 AliError(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)fDataWord));
1317 return -1;
1318 }
1319
1320 if ( (fDataWord & 0x00000003) != fTbSwitch ) { // Next ADC channel found
1321 //if ( fTB+1 != timeBins ) AliError(Form("Time bins in data (%d) != DB (%d)", fTB+1, timeBins));
1322 fTbSwitch = (fTbSwitch & 2) | !(fTbSwitch & 1); // 0x3 <--> 0x2
1323 fTbSwitchCtr = 0;
1324 fADC++;
1325 fTB=0;
1326 }
1327
1328 fTbSwitchCtr++; // Just read one word
1329
1330 // We have only timeTotal time bins
1331 if ( fTbSwitchCtr > fTimeWords ) {
1332 AliError(Form("Data is strange. Already found %d words for this ADC channel", (Int_t)fTbSwitchCtr));
1333 return 0;
1334 }
1335
1336 // We have only 21 ADC channels.
1337 if ( fADC > (Int_t)fGeo->ADCmax()-1 ) {
1338 AliError(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)fDataWord, (Int_t)fADC));
1339 return 0;
1340 }
1341
1342 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
1343 // MCMs and are good for online tracking in the MCM.
1344 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 ) {
1345
1346 // Get Pad column
1347 fCOL = fGeo->GetPadColFromADC(fROB, fMCM, fADC);
1348
1349 // We have only 144 Pad Columns
1350 if ( fCOL > fColMax-1 || fCOL < 0 ) {
1351 AliError(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
1352 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
1353 }
1354
1355 // Decode 32 bit data words with information from 3 time bins and copy the data
1356 fSig[0] = (fDataWord & 0x00000ffc) >> 2;
1357 fSig[1] = (fDataWord & 0x003ff000) >> 12;
1358 fSig[2] = (fDataWord & 0xffc00000) >> 22;
1359
1360 // Print data to screen:
1361 AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
1362 fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
1363
1364 }
1365 else {
1366
1367 fCOL = -1;
1368
1369 }
1370
5a21f812 1371 return 1;
1372
bd63bf88 1373}
1374
1375//____________________________________________________________________________
1376Int_t AliTRDRawStream::DecodeDataWordV3()
1377{
1378
1379 //
1380 // Decode the data (Zero suppresses data. 21 adc channels)
1381 //
1382 // return 0 means continue to next data word
1383 // return -1 means break data loop
1384 //
1385 // NOT TESTED YET!!!!!!!!
1386 //
1387
1388 if ( (fDataWord & 0x00000003) != 0x2 && (fDataWord & 0x00000003) != 0x3) {
1389 AliError(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)fDataWord));
1390 return -1;
1391 }
1392
1393 if ( (fDataWord & 0x00000003) != fTbSwitch ) { // Next ADC channel found
1394 //if ( fTB+1 != timeBins ) AliError(Form("Time bins in data (%d) != DB (%d)", fTB+1, timeBins));
1395 fTbSwitch = (fTbSwitch & 2) | !(fTbSwitch & 1); // 0x3 <--> 0x2
1396 fTbSwitchCtr = 0;
1397 //
1398 // Jump to next ADC channel that is not masked
1399 do {
1400 fADC++;
1401 } while ( ((fADC < fGeo->ADCmax()) && (fADCmask[fADC] == kFALSE)) || (fADC >= fGeo->ADCmax()) );
1402 fTB=0;
1403 }
1404
1405 fTbSwitchCtr++; // Just read one word
1406
1407 // We have only timeTotal time bins
1408 if ( fTbSwitchCtr > fTimeWords ) {
1409 AliError(Form("Data is strange. Already found %d words for this ADC channel", (Int_t)fTbSwitchCtr));
1410 return 0;
1411 }
1412
1413 // We have only 21 ADC channels.
1414 if ( fADC > (Int_t)fGeo->ADCmax()-1 ) {
1415 AliError(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)fDataWord, (Int_t)fADC));
1416 return 0;
1417 }
1418
1419 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
1420 // MCMs and are good for online tracking in the MCM.
1421 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 ) {
1422
1423 // Get Pad column
1424 fCOL = fGeo->GetPadColFromADC(fROB, fMCM, fADC);
1425
1426 // We have only 144 Pad Columns
1427 if ( fCOL > fColMax-1 || fCOL < 0 ) {
1428 AliError(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
1429 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
1430 }
1431
1432 // Decode 32 bit data words with information from 3 time bins and copy the data
1433 fSig[0] = (fDataWord & 0x00000ffc) >> 2;
1434 fSig[1] = (fDataWord & 0x003ff000) >> 12;
1435 fSig[2] = (fDataWord & 0xffc00000) >> 22;
1436
1437 // Print data to screen:
1438 AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
1439 fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
1440
1441 }
1442 else {
1443
1444 fCOL = -1;
1445
1446 }
1447
5a21f812 1448 return 1;
1449
bd63bf88 1450}