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 "AliTRDRawStream.h"
34 #include "AliTRDgeometry.h"
35 #include "AliTRDcalibDB.h"
37 #include "AliTRDdigitsManager.h"
38 #include "AliTRDdataArrayI.h"
39 #include "AliTRDSignalIndex.h"
41 ClassImp(AliTRDRawStream)
43 //_____________________________________________________________________________
44 AliTRDRawStream::AliTRDRawStream()
113 // Default constructor
116 for (Int_t i = 0; i < 540; i++) {
122 //_____________________________________________________________________________
123 AliTRDRawStream::AliTRDRawStream(AliRawReader *rawReader)
168 ,fRawReader(rawReader)
192 // Create an object to read TRD raw digits
195 fRawReader->Select("TRD");
197 for (Int_t i = 0; i < 540; i++) {
203 //_____________________________________________________________________________
204 AliTRDRawStream::AliTRDRawStream(const AliTRDRawStream& stream)
276 AliFatal("Copy constructor not implemented");
280 //_____________________________________________________________________________
281 AliTRDRawStream& AliTRDRawStream::operator = (const AliTRDRawStream&
285 // Assigment operator
288 Fatal("operator =", "assignment operator not implemented");
293 //_____________________________________________________________________________
294 AliTRDRawStream::~AliTRDRawStream()
306 //_____________________________________________________________________________
307 void AliTRDRawStream::SetRawReader(AliRawReader *rawReader)
311 fRawReader = rawReader;
315 //_____________________________________________________________________________
316 Bool_t AliTRDRawStream::SetRawVersion(Int_t rv)
319 // Set the raw data version
322 if ( rv >= 0 && rv <= 3 ) {
332 //____________________________________________________________________________
333 Int_t AliTRDRawStream::Init()
339 if (!AliTRDcalibDB::Instance()) {
340 AliError("Could not get calibration object");
345 fGeo = new AliTRDgeometry();
348 fTimeBinsCalib = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
349 AliDebug(2, Form("Number of Timebins read from CDB: %d", fTimeBinsCalib));
351 // The number of data words needed for this number of time bins (there
352 // are 3 time bins in one word)
353 fTimeWords = (fTimeBinsCalib-1)/3 + 1;
358 fHCHctr1 = fHCHctr2 = 0;
359 fGTUctr1 = fGTUctr2 = -1;
371 fNextStatus = fkStart;
378 fkBufferSet = kFALSE;
382 //____________________________________________________________________________
383 Int_t AliTRDRawStream::NextData()
386 // Updates the next data word pointer
389 if (fCountBytes + kSizeWord >= fBufSize)
391 fkBufferSet = fRawReader->ReadNextData(fPos);
392 if (fkBufferSet == kTRUE)
394 fBufSize = fRawReader->GetDataSize();
396 fDataWord = (UInt_t*)fPos;
397 fNextStatus = fkNextSM;
403 fNextStatus = fkStop;
411 fCountBytes += kSizeWord;
412 fDataWord = (UInt_t*)fPos;
418 //____________________________________________________________________________
419 Bool_t AliTRDRawStream::Next()
422 // Updates the next data word pointer
425 if (fNextStatus == fkStart)
430 while (fNextStatus != fkStop)
433 if (fNextStatus == fkNextMCM || fNextStatus == fkNextData)
437 if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) )
440 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 )
442 AliWarning("Wrong fMCM or fROB. Skip this data");
443 fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB));
444 fNextStatus = fkNextHC;
447 fTbSwitch = 3; // For first adc channel we expect: (*fDataWord & 3) = 3
449 fADC = fTB = 0; // Reset Counter
450 fNextStatus = fkNextData;
454 if ( *fDataWord == kEndofrawdatamarker )
455 { // End of half-chamber data, finished
457 fNextStatus = fkNextHC;
461 if (fNextStatus == fkNextData )
462 { // MCM header is set, ADC data is valid.
464 // Found some data. Decode it now:
465 fRetVal = DecodeDataWord();
466 if ( fRetVal == 0 ) continue;
469 fNextStatus = fkNextHC;
479 // following ifs have been moved to DEcodeDatawordV1V2
480 // if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 )
483 // if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax )
498 if ( fNextStatus == fkNextHC )
501 // 1) Find end_of_tracklet_marker
504 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
510 // endoftrackletmarker?
511 if ( *fDataWord == kEndoftrackletmarker )
513 AliDebug(3, "end-of-tracklet-marker found");
514 fNextStatus = fkSeekNonEoTracklet;
520 AliDebug(3, "Tracklet found");
526 if (fNextStatus == fkSeekNonEoTracklet)
529 // 2) Look for non-end_of_tracklet_marker
531 //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord);
533 if ( *fDataWord != kEndoftrackletmarker )
535 fNextStatus = fkDecodeHC;
536 AliDebug(3, "NON end-of-tracklet-marker found");
537 //// no do not continue - this should be the hcheader
541 //just go on and find the non-end_of_tracklet_marker
546 if ( fNextStatus == fkDecodeHC )
548 AliDebug(3, "Decode HC");
551 // 3) This Word must be Half Chamber Header
553 if ( (*fDataWord & 0x00000003) == 1 )
555 DecodeHCheader(fTimeBinsCalib); // This is the new header!
557 fDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
558 fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM);
559 fColMax = fGeo->GetColMax(fROC);
564 fChamberDone[fDET]++;
565 fNextStatus = fkNextMCM;
566 AliDebug(3, "Decode HC OK");
571 AliDebug(3, "Decode HC NOT OK");
572 fNextStatus = fkNextSM;
577 if (fNextStatus == fkNextSM)
586 // After reading the first word check for size of this data and get Eq. ID
589 fDataSize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
590 fEqID = fRawReader->GetEquipmentId(); // Get Equipment ID
591 if ( fDataSize > 0 ) fSizeOK = kTRUE;
595 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
598 fNextStatus = fkNextHC;
603 AliWarning(Form("Equipment %d: First data word is not GTU Link Mask!", fEqID));
604 fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID));
605 fNextStatus = fkStop;
611 AliDebug(1, Form("That's all folks! %d", fSM));
615 //____________________________________________________________________________
616 Int_t AliTRDRawStream::NextChamber(AliTRDdigitsManager *man)
619 // Updates the next data word pointer
622 AliTRDdataArrayI *digits = 0;
623 AliTRDdataArrayI *track0 = 0;
624 AliTRDdataArrayI *track1 = 0;
625 AliTRDdataArrayI *track2 = 0;
626 AliTRDSignalIndex *indexes = 0;
628 if (fNextStatus == fkStart)
633 while (fNextStatus != fkStop)
636 if (fNextStatus == fkNextMCM || fNextStatus == fkNextData)
637 //while (fNextStatus == fkNextMCM || fNextStatus == fkNextData)
641 if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) )
644 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 )
646 AliWarning("Wrong fMCM or fROB. Skip this data");
647 fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB));
648 fNextStatus = fkNextHC;
651 fTbSwitch = 3; // For first adc channel we expect: (*fDataWord & 3) = 3
653 fADC = fTB = 0; // Reset Counter
654 fNextStatus = fkNextData;
656 // NextData(); // if while loop!
660 if ( *fDataWord == kEndofrawdatamarker )
661 { // End of half-chamber data, finished
663 fNextStatus = fkNextHC;
664 // full chamber processed ?
665 if (fChamberDone[fDET] == 2)
671 // break; // if while loop
676 if (fNextStatus == fkNextData )
677 { // MCM header is set, ADC data is valid.
679 // Found some data. Decode it now:
680 fRetVal = DecodeDataWord();
681 if ( fRetVal == 0 ) continue;
684 fNextStatus = fkNextHC;
686 // NextData(); // if while loop!
687 // break; //if while loop!
694 // here fill the data arrays
696 for (Int_t it = 0; it < 3; it++)
698 if ( GetTimeBin() + it < GetNumberOfTimeBins() )
700 if (GetSignals()[it] > 0)
702 digits->SetDataUnchecked(fROW, fCOL, fTB + it, fSig[it]);
703 indexes->AddIndexTBin(fROW, fCOL, fTB + it);
704 track0->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
705 track1->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
706 track2->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
708 } // check the tbins range
709 } // for each tbin of current 3
714 // following ifs have been moved to DEcodeDatawordV1V2
715 // if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 )
718 // if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax )
730 // NextData(); // if while loop!
734 if ( fNextStatus == fkNextHC )
737 // 1) Find end_of_tracklet_marker
740 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
746 // endoftrackletmarker?
747 if ( *fDataWord == kEndoftrackletmarker )
749 AliDebug(3, "end-of-tracklet-marker found");
750 fNextStatus = fkSeekNonEoTracklet;
756 AliDebug(3, "Tracklet found");
762 if (fNextStatus == fkSeekNonEoTracklet)
765 // 2) Look for non-end_of_tracklet_marker
767 //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord);
769 if ( *fDataWord != kEndoftrackletmarker )
771 fNextStatus = fkDecodeHC;
772 AliDebug(3, "NON end-of-tracklet-marker found");
773 //// no do not continue - this should be the hcheader
777 //just go on and find the non-end_of_tracklet_marker
782 if ( fNextStatus == fkDecodeHC )
784 AliDebug(3, "Decode HC");
787 // 3) This Word must be Half Chamber Header
789 if ( (*fDataWord & 0x00000003) == 1 )
791 DecodeHCheader(fTimeBinsCalib); // This is the new header!
792 fDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
793 fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM);
794 fColMax = fGeo->GetColMax(fROC);
796 if (fLastDET != fDET)
798 AliDebug(4, "New DET!");
799 // allocate stuff for the new det
800 digits = man->GetDigits(fDET);
801 track0 = man->GetDictionary(fDET,0);
802 track1 = man->GetDictionary(fDET,1);
803 track2 = man->GetDictionary(fDET,2);
805 // Allocate memory space for the digits buffer
806 if (digits->GetNtime() == 0)
808 AliDebug(4, "Allocating digits");
809 //AliDebug(5, Form("Alloc digits for det %d", det));
810 digits->Allocate(fRowMax, fColMax, fTBins);
811 track0->Allocate(fRowMax, fColMax, fTBins);
812 track1->Allocate(fRowMax, fColMax, fTBins);
813 track2->Allocate(fRowMax, fColMax, fTBins);
816 indexes = man->GetIndexes(fDET);
818 indexes->SetStack(fSTACK);
819 indexes->SetLayer(fLAYER);
820 indexes->SetDetNumber(fDET);
822 if (indexes->IsAllocated() == kFALSE)
824 AliDebug(4, "Allocating indexes");
825 indexes->Allocate(fRowMax, fColMax, fTBins);
833 fChamberDone[fDET]++;
834 fNextStatus = fkNextMCM;
835 AliDebug(3, "Decode HC OK");
840 AliDebug(3, "Decode HC NOT OK");
841 fNextStatus = fkNextSM;
846 if (fNextStatus == fkNextSM)
855 // After reading the first word check for size of this data and get Eq. ID
858 fDataSize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
859 fEqID = fRawReader->GetEquipmentId(); // Get Equipment ID
860 if ( fDataSize > 0 ) fSizeOK = kTRUE;
864 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
867 fNextStatus = fkNextHC;
872 AliWarning(Form("Equipment %d: First data word is not GTU Link Mask!", fEqID));
873 fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID));
874 fNextStatus = fkStop;
880 AliDebug(1, Form("That's all folks! %d", fSM));
885 //============================================================================
886 // Decoding functions
887 //============================================================================
890 //____________________________________________________________________________
891 void AliTRDRawStream::DecodeHCheader(Int_t timeBins)
894 // Decode the HC header (fRawVersion == 2, 3, 4, ???)
897 fRVmajor = (*fDataWord >> 24) & 0x7f;
898 fRVminor = (*fDataWord >> 17) & 0x7f;
900 if (fRVmajor < 2 || fRVmajor > 4)
901 AliError(Form(" Unsupported raw version: %d", fRawVersion))
903 if ( fRawVersion != fRVmajor ) {
905 AliWarning("===============================================================================");
906 AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)"
907 ,fRawVersion,fRVmajor));
908 AliWarning(Form("Setting fRawVersion to %d", fRVmajor));
909 AliWarning("===============================================================================");
910 fRawVersion = fRVmajor;
915 // check for zero suppression
916 if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
917 else fZeroSuppressed = kFALSE;
920 if ( (*fDataWord & 0x3) == 1 ) {
922 fHCHWords = (*fDataWord >> 14) & 0x7;
923 fSM = (*fDataWord >> 9) & 0x1f;
924 fLAYER = (*fDataWord >> 6) & 0x7;
925 fSTACK = (*fDataWord >> 3) & 0x7;
926 fSIDE = (*fDataWord >> 2) & 0x1;
928 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
930 AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", *fDataWord, fSM, fROC, fSIDE+10));
940 AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
941 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
942 fRawReader->AddMajorErrorLog(kHCHeaderCorrupt,Form("0x%08x:dcs=%d; sm=%d; layer=%d; stack=%d.",
943 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
951 AliWarning(Form("0x%08x: No HC header when it was expected.", *fDataWord));
952 fRawReader->AddMajorErrorLog(kHCHeaderMissing,Form("0x%08x", *fDataWord));
956 if ( fHCHWords >= 1 ) {
957 // read one more word
958 if (NextData() != fkWordOK)
960 AliWarning("Next HC word missing");
961 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
962 fNextStatus = fkNextHC;
965 if ( (*fDataWord & 0x3) == 1 ) {
967 fBCctr = (*fDataWord >> 16);
968 fPTctr = (*fDataWord >> 12) & 0xf;
969 fPTphase = (*fDataWord >> 8) & 0xf;
970 fTBins = ((*fDataWord >> 2) & 0x3f) + 1;
972 AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
973 , *fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
975 if( fTBins != timeBins ) {
977 AliWarning("===============================================================================");
978 AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)"
979 , timeBins, fTBins));
980 AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins));
981 AliWarning("===============================================================================");
983 fTimeWords = (fTBins - 1)/3 + 1;
991 if ( fHCHWords >= 2 ) {
992 // read one more word
993 if (NextData() != fkWordOK)
995 AliWarning("Next HC word missing");
996 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
997 fNextStatus = fkNextHC;
1000 if ( (*fDataWord & 0x3) == 1 ) {
1002 fTCon = (*fDataWord >> 29) & 0x1;
1003 fPEDon = (*fDataWord >> 31) & 0x1;
1004 fGAINon = (*fDataWord >> 30) & 0x1;
1005 fXTon = (*fDataWord >> 28) & 0x1;
1006 fNonLinOn = (*fDataWord >> 27) & 0x1;
1007 fBypass = (*fDataWord >> 26) & 0x1;
1009 fCommonAdditive = (*fDataWord >> 20) & 0x3f;
1011 AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d"
1012 , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive));
1018 //____________________________________________________________________________
1019 void AliTRDRawStream::DecodeMCMheader()
1023 // Decode the MCM header
1026 if ( fRawVersion < 1 || fRawVersion > 3 )
1028 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1031 fMCM = (*fDataWord & 0xff000000) >> 24;
1032 fEv = (*fDataWord & 0x00fffff0) >> 4;
1037 fROW = fGeo->GetPadRowFromMCM(fROB, fMCM);
1039 AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d"
1040 , *fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv));
1042 if ( fROB % 2 == 0 && fSIDE == 1 ) {
1043 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
1044 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
1045 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
1046 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
1048 if ( fROB % 2 != 0 && fSIDE == 0 ) {
1049 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
1050 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
1051 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
1052 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
1054 if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
1055 (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
1056 AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1057 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
1058 fRawReader->AddMajorErrorLog(kWrongPadrow,Form("SM%d L%dS%d: Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1059 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
1065 // AdcMask for Zero supressed data
1066 if ( fRawVersion == 3 ) {
1067 // read one more word
1068 if (NextData() != fkWordOK)
1070 AliWarning("MCM ADC mask missing");
1071 fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1072 fNextStatus = fkNextHC;
1075 if ( (*fDataWord & 0x000007ff) == 0xC ) { // at the moment bits 4-10 are empty
1077 for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
1078 if ( (*fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
1079 else fADCmask[ctr] = kFALSE;
1082 AliDebug(4, Form("0x%08x: ADC mask", *fDataWord));
1086 AliWarning("Expected ADC mask but did not find one!");
1087 fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Decode error");
1094 //____________________________________________________________________________
1095 void AliTRDRawStream::DecodeTracklet()
1099 // Decode the Tracklet
1101 // this function is not tested yet on real tracklets
1104 if ( fRawVersion < 1 || fRawVersion > 3 )
1106 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1109 fTracklPID = (*fDataWord >> 24) & 0xff;
1110 fTracklPadRow = (*fDataWord >> 20) & 0xf; // 0:15
1111 fTracklDefL = (*fDataWord >> 13) & 0x7f;
1112 fTracklPadPos = (*fDataWord) & 0x1fff;
1114 fTracklPID /= (Float_t)((1<<8) - 1); // 0:1 (steps of 0.39%)
1115 fTracklDefL = (fTracklDefL - ((1<< 7)-1)/2.) * 140.e-4; // -0.889:0.889cm
1116 fTracklPadPos = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm
1118 //AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f"
1119 // , *fDataWord, fSM, fLAYER, fSTACK, fSIDE+10
1120 // , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID));
1122 if( (fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0()) ||
1123 (fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1()) ) {
1124 AliWarning(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow));
1125 fRawReader->AddMajorErrorLog(kTrackletRowMismatch,Form("Word: %d", fTracklPadRow));
1130 //____________________________________________________________________________
1131 void AliTRDRawStream::DecodeGTUlinkMask()
1135 // Decode the link masks sent by the GTU. These marke the active optical links
1136 // between GTU and Super Module. Up to now only fully active links are found
1137 // (0xfff = 12 active links).
1140 if ( fRawVersion < 1 || fRawVersion > 3 )
1142 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1145 if ( fGTUctr1 == -1 ) fGTUctr2++;
1148 if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) ) {
1149 fGTUlinkMask[fGTUctr2][fGTUctr1] = (*fDataWord & 0xfff);
1154 //____________________________________________________________________________
1155 Int_t AliTRDRawStream::DecodeDataWord()
1162 if ( fRawVersion >= 1 && fRawVersion <= 2 ) {
1163 return DecodeDataWordV1V2();
1165 else if ( fRawVersion >= 3 && fRawVersion <= 3 ) {
1166 return DecodeDataWordV3();
1169 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1174 //____________________________________________________________________________
1175 Int_t AliTRDRawStream::DecodeDataWordV1V2()
1179 // Decode the Data (full raw data. No zero suppression. 21 adc channels)
1181 // return 0 means continue to next data word
1182 // return -1 means break data loop
1185 // // check the content first! - something wrong with that...
1186 // // Decode 32 bit data words with information from 3 time bins and copy the data
1187 // fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
1188 // fSig[1] = (*fDataWord & 0x003ff000) >> 12;
1189 // fSig[2] = (*fDataWord & 0xffc00000) >> 22;
1190 // if (fSig[0] <= 0 && fSig[1] <= 0 && fSig[2] <= 0)
1193 if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
1194 //AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
1195 fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
1199 if ( (*fDataWord & 0x00000003) != fTbSwitch ) { // Next ADC channel found
1200 fTbSwitch = (fTbSwitch & 2) | !(fTbSwitch & 1); // 0x3 <--> 0x2
1206 fTbSwitchCtr++; // Just read one word
1208 // We have only timeTotal time bins
1209 if ( fTbSwitchCtr > fTimeWords ) {
1210 //AliWarning(Form("Data is strange. Already found %d words for this ADC channel", (Int_t)fTbSwitchCtr));
1211 fRawReader->AddMinorErrorLog(kADCNumberOverflow,Form("%d words", (Int_t)fTbSwitchCtr));
1215 // We have only 21 ADC channels.
1216 if ( fADC > (Int_t)fGeo->ADCmax()-1 ) {
1217 //AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
1218 fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
1222 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
1223 // MCMs and are good for online tracking in the MCM.
1224 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 ) {
1227 fCOL = fGeo->GetPadColFromADC(fROB, fMCM, fADC);
1229 // We have only 144 Pad Columns
1230 //if ( fCOL > fColMax-1 || fCOL < 0 ) {
1231 if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax )
1233 // Decode 32 bit data words with information from 3 time bins and copy the data
1234 fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
1235 fSig[1] = (*fDataWord & 0x003ff000) >> 12;
1236 fSig[2] = (*fDataWord & 0xffc00000) >> 22;
1238 if (fSig[0] > 0 || fSig[1] > 0 || fSig[2] > 0)
1245 // AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
1246 // fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
1247 fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
1248 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
1251 // Print data to screen:
1252 // Do NOT switch on for default production, it is VERY slow
1253 // AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
1254 // fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
1267 //____________________________________________________________________________
1268 Int_t AliTRDRawStream::DecodeDataWordV3()
1272 // Decode the data (Zero suppresses data. 21 adc channels)
1274 // return 0 means continue to next data word
1275 // return -1 means break data loop
1277 // NOT TESTED YET!!!!!!!!
1280 if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
1281 AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
1282 fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
1286 if ( (*fDataWord & 0x00000003) != fTbSwitch ) { // Next ADC channel found
1287 fTbSwitch = (fTbSwitch & 2) | !(fTbSwitch & 1); // 0x3 <--> 0x2
1290 // Jump to next ADC channel that is not masked
1293 } while ( ((fADC < fGeo->ADCmax()) && (fADCmask[fADC] == kFALSE)) || (fADC >= fGeo->ADCmax()) );
1297 fTbSwitchCtr++; // Just read one word
1299 // We have only timeTotal time bins
1300 if ( fTbSwitchCtr > fTimeWords ) {
1301 AliWarning(Form("Data is strange. Already found %d words for this ADC channel", (Int_t)fTbSwitchCtr));
1302 fRawReader->AddMinorErrorLog(kADCNumberOverflow,Form("%d words", (Int_t)fTbSwitchCtr));
1306 // We have only 21 ADC channels.
1307 if ( fADC > (Int_t)fGeo->ADCmax()-1 ) {
1308 AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
1309 fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
1313 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
1314 // MCMs and are good for online tracking in the MCM.
1315 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 ) {
1318 fCOL = fGeo->GetPadColFromADC(fROB, fMCM, fADC);
1320 // We have only 144 Pad Columns
1321 if ( fCOL > fColMax-1 || fCOL < 0 ) {
1322 AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
1323 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
1324 fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
1325 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
1328 // Decode 32 bit data words with information from 3 time bins and copy the data
1329 fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
1330 fSig[1] = (*fDataWord & 0x003ff000) >> 12;
1331 fSig[2] = (*fDataWord & 0xffc00000) >> 22;
1333 // Print data to screen:
1334 AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
1335 fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));