1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // This class provides access to TRD digits in raw data. //
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. //
27 // Author: C. Lippmann (C.Lippmann@gsi.de) //
29 ///////////////////////////////////////////////////////////////////////////////
32 #include "AliRawReader.h"
33 #include "AliTRDdigitsManager.h"
34 #include "AliTRDdataArrayI.h"
36 #include "AliTRDRawStream.h"
37 #include "AliTRDgeometry.h"
38 #include "AliTRDCommonParam.h"
39 #include "AliTRDcalibDB.h"
41 ClassImp(AliTRDRawStream)
43 //_____________________________________________________________________________
44 AliTRDRawStream::AliTRDRawStream()
110 ,fDigitsManager(NULL)
117 // Default constructor
120 for (Int_t i = 0; i < 540; i++) {
126 //_____________________________________________________________________________
127 AliTRDRawStream::AliTRDRawStream(AliRawReader *rawReader
128 , AliTRDdigitsManager *man
129 , AliTRDdataArrayI *dig)
172 ,fRawReader(rawReader)
203 // Create an object to read TRD raw digits
206 fGeo = new AliTRDgeometry();
208 fRawReader->Select("TRD");
210 for (Int_t i = 0; i < 540; i++) {
216 //_____________________________________________________________________________
217 AliTRDRawStream::AliTRDRawStream(AliRawReader *rawReader)
260 ,fRawReader(rawReader)
283 ,fDigitsManager(NULL)
291 // Create an object to read TRD raw digits
294 fRawReader->Select("TRD");
296 for (Int_t i = 0; i < 540; i++) {
302 //_____________________________________________________________________________
303 AliTRDRawStream::AliTRDRawStream(const AliTRDRawStream& stream)
369 ,fDigitsManager(NULL)
380 AliFatal("Copy constructor not implemented");
384 //_____________________________________________________________________________
385 AliTRDRawStream& AliTRDRawStream::operator = (const AliTRDRawStream&
389 // Assigment operator
392 Fatal("operator =", "assignment operator not implemented");
397 //_____________________________________________________________________________
398 AliTRDRawStream::~AliTRDRawStream()
406 //_____________________________________________________________________________
407 Bool_t AliTRDRawStream::SetRawVersion(Int_t rv)
410 // Set the raw data version
413 if ( rv >= 0 && rv <= 3 ) {
422 //_____________________________________________________________________________
423 Bool_t AliTRDRawStream::Next()
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.
428 // Returns kFALSE if there is no digit left
431 fPrevDetector = fDetector;
433 fPrevColumn = fColumn;
436 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
437 if (!calibration) return kFALSE;
439 Int_t timeBins = calibration->GetNumberOfTimeBins();
441 while (fCount >= 0) {
443 while (fCount == 0) { // next detector
446 if (!fRawReader->ReadNextChar(data)) {
450 AliError(Form("wrong flag: %x", data));
455 // read the detector number
456 if (!fRawReader->ReadNextChar(data)) {
457 AliError("Could not read detector number");
462 if (!fRawReader->ReadNextChar(data)) {
463 AliError("Could not read detector number");
467 fDetector += (UInt_t(data) << 8);
469 // read the number of byts
470 if (!fRawReader->ReadNextChar(data)) {
471 AliError("Could not read number of bytes");
476 if (!fRawReader->ReadNextChar(data)) {
477 AliError("Could not read number of bytes");
481 fCount += (UInt_t(data) << 8);
482 if (!fRawReader->ReadNextChar(data)) {
483 AliError("Could not read number of bytes");
487 fCount += (UInt_t(data) << 16);
489 // read the number of active pads
490 if (!fRawReader->ReadNextChar(data)) {
491 AliError("Could not read number of active pads");
496 if (!fRawReader->ReadNextChar(data)) {
497 AliError("Could not read number of active pads");
501 fNPads += (UInt_t(data) << 8);
507 // read the pad row and column number
508 if ((fTime >= timeBins) && (fCount > 2)) {
509 if (!fRawReader->ReadNextChar(data)) {
510 AliError("Could not read row number");
516 if (!fRawReader->ReadNextChar(data)) {
517 AliError("Could not read column number");
526 // read the next data byte
527 if (!fRawReader->ReadNextChar(data)) {
528 AliError("Could not read data");
534 if (data == 0) { // zeros
535 if (!fRawReader->ReadNextChar(data)) {
536 AliError("Could not read time value");
545 fSignal = (UInt_t(data & 0x7F) << 8);
546 if (!fRawReader->ReadNextChar(data)) {
547 AliError("Could not read ADC value");
562 //____________________________________________________________________________
563 Int_t AliTRDRawStream::ReadAll()
567 // Read all TRD raw data word (32 bits). This is for all fRawVersion > 0.
568 // Return 0 if something is not cool, 2 if data seems empty
573 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
575 AliError("Could not get common parameters");
579 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
581 AliError("Could not get calibration object");
585 UInt_t timeTotal = calibration->GetNumberOfTimeBins();
586 AliDebug(2, Form("Number of Timebins read from CDB: %d", timeTotal));
588 // The number of data words needed for this number of time bins (there
589 // are 3 time bins in one word)
590 fTimeWords = (timeTotal-1)/3 + 1;
601 Bool_t sizeOK = kFALSE;
603 fHCHctr1 = fHCHctr2 = 0;
604 fGTUctr1 = fGTUctr2 = -1;
609 AliInfo("Converting TRD raw data to digits ...");
611 while ( 1 ) { // loop over all supermodules
618 // 0) Find first GTU Link Mask and test if we can read data
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);
631 AliInfo(Form("Finished processing TRD raw data: Found %d Half-Chambers", fHCHctr2));
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);
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);
652 if ( sizeOK ) return 1;
658 // After reading the first word check for size of this data and get Eq. ID
659 if ( fWordCtr == 1 ) {
660 datasize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
661 EqID = fRawReader->GetEquipmentId(); // Get Equipment ID
662 //if ( sizeOK = kFALSE && datasize > 0 ) { sizeOK = kTRUE; printf("Yo\n"); }
663 if ( datasize > 0 ) sizeOK = kTRUE;
667 if ( (fDataWord & 0xfffff000) == 0xe0000000 ) {
668 fStatus = 1; // GTU link mask found
673 AliError(Form("Equipment %d: First data word is not GTU Link Mask!", EqID));
678 while ( fWordCtr < datasize );
681 // loop over all half chambers in one supermodule
683 while ( fWordCtr < datasize ) {
686 // 1) Find end_of_tracklet_marker
688 while ( fWordCtr < datasize ) {
690 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
691 AliError("Could not read data");
697 if ( (fDataWord & 0xfffff000) == 0xe0000000 ) {
702 // endoftrackletmarker?
703 if ( fDataWord == kEndoftrackletmarker ) {
704 AliDebug(3, "end-of-tracklet-marker found");
710 AliDebug(3, "Tracklet found");
716 if ( fStatus == 0 ) break;
719 // 2) Look for non-end_of_tracklet_marker
722 while ( fWordCtr < datasize ) {
724 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
725 AliError("Could not read data");
729 //printf("Word %d: 0x%08x\n", fWordCtr, fDataWord);
731 if ( fDataWord != kEndoftrackletmarker ) {
738 if ( fStatus == 0 ) break;
741 // 3) This Word must be Half Chamber Header
744 if ( (fDataWord & 0x00000003) == 1 ) { // HC header
746 // If both half chambers of chamber corresponding to previous header
747 // were already processed, we can compress these digits
748 iDET = fGeo->GetDetector(fLAYER, fSTACK, fSM); // !!this is still the previous HC!!
749 if ( fChamberDone[iDET] == 2 ) {
750 //printf("Compressing data for det %d\n", iDET);
751 fDigits->Compress(1,0);
752 fTrack0->Compress(1,0);
753 fTrack1->Compress(1,0);
754 fTrack2->Compress(1,0);
756 // Read from new HC header the chamber position (fLAYER, fSTACK, fSM)
757 DecodeHCheader(timeTotal); // This is the new header!
758 iDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
759 fRowMax = commonParam->GetRowMax(fLAYER,fSTACK,fSM);
760 fColMax = commonParam->GetColMax(fROC);
762 // The container for the digits of this detector
763 fDigits = fDigitsManager->GetDigits(iDET);
764 fTrack0 = fDigitsManager->GetDictionary(iDET,0);
765 fTrack1 = fDigitsManager->GetDictionary(iDET,1);
766 fTrack2 = fDigitsManager->GetDictionary(iDET,2);
768 // Allocate memory if it was not already done
769 if (fDigits->GetNtime() == 0) {
770 //printf("Allocating digits memory for det %d\n", iDET);
771 fDigits->Allocate(fRowMax, fColMax, fTBins);
772 fTrack0->Allocate(fRowMax, fColMax, fTBins);
773 fTrack1->Allocate(fRowMax, fColMax, fTBins);
774 fTrack2->Allocate(fRowMax, fColMax, fTBins);
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);
791 fChamberDone[iDET]++;
799 while ( fWordCtr < datasize ) {
801 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
802 AliError("Could not read data");
806 //printf("Word %d: 0x%08x\n", fWordCtr, fDataWord);
810 //if( (fDataWord & 0x0000000f) == 0xC ) { // MCM Header
811 if( ((fDataWord & 0x80000000) == 0x0) && ((fDataWord & 0x0000000f) == 0xC) ) { // MCM Header
813 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 ) {
814 AliError("Wrong fMCM or fROB. Skip this data");
817 fTbSwitch = 3; // For first adc channel we expect: (fDataWord & 3) = 3
819 fADC = fTB = 0; // Reset Counter
820 fStatus = 1; // Now 1 means MCM header is found
824 if ( fDataWord == kEndofrawdatamarker ) { // End of half-chamber data, finished
829 if ( fStatus == 1 ) { // MCM header is set, ADC data is valid.
831 // Found some data. Decode it now:
832 retval = DecodeDataWord();
833 if ( retval == 0 ) continue;
834 if ( retval == -1 ) break;
836 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 ) {
839 if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax ) { // A real pad
840 for ( Int_t ctr = 0; ctr < 3; ctr++ ) {
841 if ( fTB+ctr < (Int_t)timeTotal ) {
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);
850 // Pedestal subtraction done here (???):
852 //fDigits->SetData(fROW, fCOL, fTB+ctr, fSig[ctr] - fCommonAdditive);
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);
874 AliDebug(2, Form("SM%02d L%dS%d side %x: Processed %dMCMs=%dbyte", fSM, fLAYER, fSTACK, fSIDE+10,
875 fMCMHctr2, fHCdataCtr));
877 } // End Half-Chamber loop
879 AliDebug(1, Form("SM%02d (Eq %d): Processed %d HC (%dMCMs=%dbyte)", fSM, EqID, fHCHctr1, fMCMHctr1,
882 } // End Super Module loop
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);
893 if ( sizeOK ) return 1;
898 //============================================================================
899 // Decoding functions
900 //============================================================================
902 //____________________________________________________________________________
903 void AliTRDRawStream::DecodeHCheader(Int_t timeBins)
906 // Decode a half chamber header
909 if ( (fDataWord >> 31) == 0 ) { // Can only happen for fRawVersion == 1
911 if ( fRawVersion != 1 ) {
913 AliWarning("===============================================================================");
914 AliWarning(Form("Mismatch between fRawVersion (%d) and HC header signature", fRawVersion));
915 AliWarning("Setting fRawVersion to 1");
916 AliWarning("===============================================================================");
927 fRVmajor = (fDataWord >> 24) & 0x7f;
928 fRVminor = (fDataWord >> 17) & 0x7f;
930 if ( fRawVersion != fRVmajor ) {
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;
940 if ( fRawVersion >= 2 && fRawVersion <= 3 ) {
941 DecodeHCheaderV2V3(timeBins);
945 // check for zero suppression
946 if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
947 else fZeroSuppressed = kFALSE;
953 AliError(Form(" Unsupported raw version: %d", fRawVersion));
958 //____________________________________________________________________________
959 void AliTRDRawStream::DecodeHCheaderV1()
963 // Decode the HC header (fRawVersion == 1, SM I Commissioning 06)
966 if ( (fDataWord & 0x3) == 1 ) {
968 fDCS = (fDataWord >> 20);
969 fSM = (fDataWord >> 15) & 0x1f;
970 fLAYER = (fDataWord >> 12) & 0x7;
971 fSTACK = (fDataWord >> 9) & 0x7;
972 fSIDE = (fDataWord >> 8) & 0x1;
974 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
976 //AliDebug(3, Form("0x%08x: HC header: dcs=%d; sm=%d; roc=%d; side=%x", fDataWord, fDCS, fSM, fROC, fSIDE+10));
986 AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
987 fDataWord, fDCS, fSM, fLAYER, fSTACK));
999 AliError(Form("0x%08x: No HC header when it was expected.", fDataWord));
1006 //____________________________________________________________________________
1007 void AliTRDRawStream::DecodeHCheaderV2V3(Int_t timeBins)
1010 // Decode the HC header (fRawVersion == 2, 3, 4, ???)
1014 if ( (fDataWord & 0x3) == 1 ) {
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;
1022 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
1024 AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", fDataWord, fSM, fROC, fSIDE+10));
1034 AliError(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
1035 fDataWord, fDCS, fSM, fLAYER, fSTACK));
1044 AliError(Form("0x%08x: No HC header when it was expected.", fDataWord));
1048 if ( fHCHWords >= 1 ) {
1049 // read one more word
1050 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
1051 AliError("Could not read data");
1055 if ( (fDataWord & 0x3) == 1 ) {
1057 fBCctr = (fDataWord >> 16);
1058 fPTctr = (fDataWord >> 12) & 0xf;
1059 fPTphase = (fDataWord >> 8) & 0xf;
1060 fTBins = ((fDataWord >> 2) & 0x3f) + 1;
1062 AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
1063 , fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
1065 if( fTBins != timeBins ) {
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("===============================================================================");
1080 if ( fHCHWords >= 2 ) {
1081 // read one more word
1082 if ( !fRawReader->ReadNextInt( fDataWord ) ) {
1083 AliError("Could not read data");
1087 if ( (fDataWord & 0x3) == 1 ) {
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;
1096 fCommonAdditive = (fDataWord >> 20) & 0x3f;
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));
1101 if( fTBins != timeBins ) {
1102 AliError(Form("Mismatch between Number of Time Bins from CDB (%d) and from HC header (%d)"
1103 , timeBins, fTBins));
1112 //____________________________________________________________________________
1113 void AliTRDRawStream::DecodeMCMheader()
1119 if ( fRawVersion >= 1 && fRawVersion <= 3 ) {
1120 DecodeMCMheaderVx();
1124 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1129 //____________________________________________________________________________
1130 void AliTRDRawStream::DecodeMCMheaderVx()
1134 // Decode the MCM header
1137 fMCM = (fDataWord & 0xff000000) >> 24;
1138 fEv = (fDataWord & 0x00fffff0) >> 4;
1143 fROW = fGeo->GetPadRowFromMCM(fROB, fMCM);
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));
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 ));
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 ));
1156 if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
1157 (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
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 ));
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");
1173 if ( (fDataWord & 0x000007ff) == 0xC ) { // at the moment bits 4-10 are empty
1174 //if ( (fDataWord & 0x0000000f) == 0xC ) {
1176 for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
1177 if ( (fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
1178 else fADCmask[ctr] = kFALSE;
1181 AliDebug(4, Form("0x%08x: ADC mask", fDataWord));
1185 AliError("Expected ADC mask but did not find one!");
1192 //____________________________________________________________________________
1193 void AliTRDRawStream::DecodeTracklet()
1199 if ( fRawVersion >= 1 && fRawVersion <= 3 ) {
1204 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1209 //____________________________________________________________________________
1210 void AliTRDRawStream::DecodeTrackletVx()
1214 // Decode the Tracklet
1216 // this function is not tested yet on real tracklets
1219 fTracklPID = (fDataWord >> 24) & 0xff;
1220 fTracklPadRow = (fDataWord >> 20) & 0xf; // 0:15
1221 fTracklDefL = (fDataWord >> 13) & 0x7f;
1222 fTracklPadPos = (fDataWord) & 0x1fff;
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
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));
1232 if( (fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0()) ||
1233 (fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1()) ) {
1234 AliError(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow));
1239 //____________________________________________________________________________
1240 void AliTRDRawStream::DecodeGTUlinkMask()
1246 if ( fRawVersion >= 1 && fRawVersion <= 3 ) {
1247 DecodeGTUlinkMaskVx();
1251 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1256 //____________________________________________________________________________
1257 void AliTRDRawStream::DecodeGTUlinkMaskVx()
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).
1266 if ( fGTUctr1 == -1 ) fGTUctr2++;
1269 //printf("fGTUctr=%d",fGTUctr);
1270 //printf("fGTUctr1=%d, fGTUctr2=%d",fGTUctr1, fGTUctr2);
1272 if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) ) {
1273 fGTUlinkMask[fGTUctr2][fGTUctr1] = (fDataWord & 0xfff);
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));
1284 //____________________________________________________________________________
1285 Int_t AliTRDRawStream::DecodeDataWord()
1292 if ( fRawVersion >= 1 && fRawVersion <= 2 ) {
1293 return DecodeDataWordV1V2();
1295 else if ( fRawVersion >= 3 && fRawVersion <= 3 ) {
1296 return DecodeDataWordV3();
1299 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1304 //____________________________________________________________________________
1305 Int_t AliTRDRawStream::DecodeDataWordV1V2()
1309 // Decode the Data (full raw data. No zero suppression. 21 adc channels)
1311 // return 0 means continue to next data word
1312 // return -1 means break data loop
1315 if ( (fDataWord & 0x00000003) != 0x2 && (fDataWord & 0x00000003) != 0x3) {
1316 AliError(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)fDataWord));
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
1328 fTbSwitchCtr++; // Just read one word
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));
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));
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 ) {
1347 fCOL = fGeo->GetPadColFromADC(fROB, fMCM, fADC);
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 ));
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;
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]));
1375 //____________________________________________________________________________
1376 Int_t AliTRDRawStream::DecodeDataWordV3()
1380 // Decode the data (Zero suppresses data. 21 adc channels)
1382 // return 0 means continue to next data word
1383 // return -1 means break data loop
1385 // NOT TESTED YET!!!!!!!!
1388 if ( (fDataWord & 0x00000003) != 0x2 && (fDataWord & 0x00000003) != 0x3) {
1389 AliError(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)fDataWord));
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
1398 // Jump to next ADC channel that is not masked
1401 } while ( ((fADC < fGeo->ADCmax()) && (fADCmask[fADC] == kFALSE)) || (fADC >= fGeo->ADCmax()) );
1405 fTbSwitchCtr++; // Just read one word
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));
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));
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 ) {
1424 fCOL = fGeo->GetPadColFromADC(fROB, fMCM, fADC);
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 ));
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;
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]));