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 "AliTRDRawStreamV2.h"
34 #include "AliTRDgeometry.h"
35 #include "AliTRDcalibDB.h"
36 #include "AliTRDfeeParam.h"
38 #include "AliTRDdigitsManager.h"
39 #include "AliTRDdataArrayI.h"
40 #include "AliTRDSignalIndex.h"
43 ClassImp(AliTRDRawStreamV2)
45 //_____________________________________________________________________________
46 AliTRDRawStreamV2::AliTRDRawStreamV2()
95 ,fRawDigitThreshold(0)
119 ,fEndOfDataFlag(kFALSE)
123 // Default constructor
126 for (Int_t i = 0; i < 540; i++) {
132 //_____________________________________________________________________________
133 AliTRDRawStreamV2::AliTRDRawStreamV2(AliRawReader *rawReader)
179 ,fMCMWordsExpected(0)
180 ,fRawReader(rawReader)
182 ,fRawDigitThreshold(0)
206 ,fEndOfDataFlag(kFALSE)
210 // Create an object to read TRD raw digits
213 fRawReader->Select("TRD");
215 for (Int_t i = 0; i < 540; i++) {
221 //_____________________________________________________________________________
222 AliTRDRawStreamV2::AliTRDRawStreamV2(const AliTRDRawStreamV2& stream)
268 ,fMCMWordsExpected(0)
271 ,fRawDigitThreshold(0)
295 ,fEndOfDataFlag(kFALSE)
302 AliFatal("Copy constructor not implemented");
306 //_____________________________________________________________________________
307 AliTRDRawStreamV2& AliTRDRawStreamV2::operator = (const AliTRDRawStreamV2&
311 // Assigment operator
314 Fatal("operator =", "assignment operator not implemented");
319 //_____________________________________________________________________________
320 AliTRDRawStreamV2::~AliTRDRawStreamV2()
332 //_____________________________________________________________________________
333 void AliTRDRawStreamV2::SetRawReader(AliRawReader *rawReader)
341 fRawReader = rawReader;
345 //_____________________________________________________________________________
346 Bool_t AliTRDRawStreamV2::SetRawVersion(Int_t rv)
349 // Set the raw data version
352 if ( rv >= 0 && rv <= 3 ) {
362 //____________________________________________________________________________
363 Int_t AliTRDRawStreamV2::Init()
369 if (!AliTRDcalibDB::Instance()) {
370 AliError("Could not get calibration object");
375 fGeo = new AliTRDgeometry();
378 fTimeBinsCalib = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
379 //AliDebug(2, Form("Number of Timebins read from CDB: %d", fTimeBinsCalib));
381 // The number of data words needed for this number of time bins (there
382 // are 3 time bins in one word)
383 fTimeWords = (fTimeBinsCalib-1)/3 + 1;
388 fHCHctr1 = fHCHctr2 = 0;
389 fGTUctr1 = fGTUctr2 = -1;
401 fLastStatus = fkStart;
402 fNextStatus = fkStart;
409 fkBufferSet = kFALSE;
412 fMCMWordsExpected = 0;
414 fEndOfDataFlag = kFALSE;
415 // set all ADC active
416 fNActiveADCs = ChannelsToRead(0x1fffff); // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
423 //____________________________________________________________________________
424 Int_t AliTRDRawStreamV2::NextData()
427 // Updates the next data word pointer
430 if (fCountBytes + kSizeWord >= fBufSize)
432 fkBufferSet = fRawReader->ReadNextData(fPos);
433 if (fkBufferSet == kTRUE)
435 fBufSize = fRawReader->GetDataSize();
437 fDataWord = (UInt_t*)fPos;
438 ChangeStatus(fkNextSM);
444 ChangeStatus(fkStop);
451 fCountBytes += kSizeWord;
452 fDataWord = (UInt_t*)fPos;
458 //============================================================================
459 // Decoding functions
460 //============================================================================
463 //____________________________________________________________________________
464 void AliTRDRawStreamV2::DecodeHCheader(Int_t timeBins)
467 // Decode the HC header (fRawVersion == 2, 3, 4, ???)
470 fRVmajor = (*fDataWord >> 24) & 0x7f;
471 fRVminor = (*fDataWord >> 17) & 0x7f;
473 if (fRVmajor < 2 || fRVmajor > 4)
474 AliError(Form(" Unsupported raw version: %d", fRawVersion))
476 if ( fRawVersion != fRVmajor ) {
478 AliWarning("===============================================================================");
479 AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)"
480 ,fRawVersion,fRVmajor));
481 AliWarning(Form("Setting fRawVersion to %d", fRVmajor));
482 AliWarning("===============================================================================");
483 fRawVersion = fRVmajor;
488 // check for zero suppression
489 if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
490 else fZeroSuppressed = kFALSE;
493 if ( (*fDataWord & 0x3) == 1 ) {
495 fHCHWords = (*fDataWord >> 14) & 0x7;
496 fSM = (*fDataWord >> 9) & 0x1f;
497 fLAYER = (*fDataWord >> 6) & 0x7;
498 fSTACK = (*fDataWord >> 3) & 0x7;
499 fSIDE = (*fDataWord >> 2) & 0x1;
501 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
503 //AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", *fDataWord, fSM, fROC, fSIDE+10));
504 //AliDebug(5, Form("0x%08x: HC header: expecting %d HC words", *fDataWord, fHCHWords));
515 AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
516 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
517 fRawReader->AddMajorErrorLog(kHCHeaderCorrupt,Form("0x%08x:dcs=%d; sm=%d; layer=%d; stack=%d.",
518 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
528 AliWarning(Form("0x%08x: No HC header when it was expected.", *fDataWord));
529 fRawReader->AddMajorErrorLog(kHCHeaderMissing,Form("0x%08x", *fDataWord));
533 if ( fHCHWords >= 1 )
535 // read one more word
536 if (NextData() != fkWordOK)
538 AliWarning("Next HC word missing");
539 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
540 fNextStatus = fkNextHC;
544 if ( (*fDataWord & 0x3) == 1 )
547 fBCctr = (*fDataWord >> 16);
548 fPTctr = (*fDataWord >> 12) & 0xf;
549 fPTphase = (*fDataWord >> 8) & 0xf;
550 fTBins = ((*fDataWord >> 2) & 0x3f) + 1;
551 fTimeWords = (fTBins - 1)/3 + 1;
553 // AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
554 // , *fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
556 if( fTBins != timeBins )
558 AliWarning("===============================================================================");
559 AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)"
560 , timeBins, fTBins));
561 AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins));
562 AliWarning("===============================================================================");
564 fTimeWords = (fTBins - 1)/3 + 1;
570 if ( fHCHWords >= 2 ) {
571 // read one more word
572 if (NextData() != fkWordOK)
574 AliWarning("Next HC word missing");
575 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
576 fNextStatus = fkNextHC;
579 if ( (*fDataWord & 0x3) == 1 ) {
581 fTCon = (*fDataWord >> 29) & 0x1;
582 fPEDon = (*fDataWord >> 31) & 0x1;
583 fGAINon = (*fDataWord >> 30) & 0x1;
584 fXTon = (*fDataWord >> 28) & 0x1;
585 fNonLinOn = (*fDataWord >> 27) & 0x1;
586 fBypass = (*fDataWord >> 26) & 0x1;
588 fCommonAdditive = (*fDataWord >> 20) & 0x3f;
590 // AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d"
591 // , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive));
597 //____________________________________________________________________________
598 Int_t AliTRDRawStreamV2::ChannelsToRead(Int_t ADCmask)
600 memset(fADClookup, -1, 32 * sizeof(Int_t));
601 fADClookup[0] = 0; // count entries
602 fADClookup[1] = 2; // index - data start at 2
604 for (Int_t i = 0; i < 30; i++)
607 if ((ADCmask & mask))
609 //AliDebug(9, Form("fDataWord=0x%08x mask=0x%08x i=%d", *fDataWord, mask, i));
610 fADClookup[fADClookup[1]] = i;
616 // test the iteration - comment out for production
617 // begin of comment out section
619 sprintf(schannels, "ADC Channels to read: ");
621 while(fADClookup[1] - 2 < fADClookup[0])
623 //AliDebug(9, Form("max=%d index=%d adc=%d", fADClookup[0], fADClookup[1], fADClookup[fADClookup[1]]));
624 strcat(schannels, Form("%d ", fADClookup[fADClookup[1]]));
627 //AliDebug(9, Form("%s", schannels));
628 //AliDebug(9, Form("ADC channels = %d", fADClookup[0]));
629 // end of comment out section
632 return fADClookup[0];
635 //____________________________________________________________________________
636 void AliTRDRawStreamV2::DecodeTracklet()
640 // Decode the Tracklet
642 // this function is not tested yet on real tracklets
645 if ( fRawVersion < 1 || fRawVersion > 3 )
647 AliError(Form(" Unsupported raw version: %d", fRawVersion));
650 fTracklPID = (*fDataWord >> 24) & 0xff;
651 fTracklPadRow = (*fDataWord >> 20) & 0xf; // 0:15
652 fTracklDefL = (*fDataWord >> 13) & 0x7f;
653 fTracklPadPos = (*fDataWord) & 0x1fff;
655 fTracklPID /= (Float_t)((1<<8) - 1); // 0:1 (steps of 0.39%)
656 fTracklDefL = (fTracklDefL - ((1<< 7)-1)/2.) * 140.e-4; // -0.889:0.889cm
657 fTracklPadPos = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm
659 //AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f"
660 // , *fDataWord, fSM, fLAYER, fSTACK, fSIDE+10
661 // , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID));
663 if( (fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0()) ||
664 (fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1()) ) {
665 AliWarning(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow));
666 fRawReader->AddMajorErrorLog(kTrackletRowMismatch,Form("Word: %d", fTracklPadRow));
671 //____________________________________________________________________________
672 void AliTRDRawStreamV2::DecodeMCMheader()
676 // Decode the MCM header
679 if ( fRawVersion < 1 || fRawVersion > 3 )
681 AliError(Form(" Unsupported raw version: %d", fRawVersion));
684 fMCM = (*fDataWord & 0xff000000) >> 24;
685 fEv = (*fDataWord & 0x00fffff0) >> 4;
690 fROW = AliTRDfeeParam::Instance()->GetPadRowFromMCM(fROB, fMCM);
692 // AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d"
693 // , *fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv));
695 if ( fROB % 2 == 0 && fSIDE == 1 ) {
696 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
697 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
698 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
699 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
701 if ( fROB % 2 != 0 && fSIDE == 0 ) {
702 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
703 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
704 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
705 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
707 if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
708 (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
709 AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
710 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
711 fRawReader->AddMajorErrorLog(kWrongPadrow,Form("SM%d L%dS%d: Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
712 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
718 fMCMWordCrt = 1; // MCM header
720 // AdcMask for Zero supressed data
721 if ( fRawVersion == 3 )
723 // read one more word
724 if (NextData() != fkWordOK)
726 AliWarning("MCM ADC mask missing");
727 fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
728 fNextStatus = fkNextHC;
735 for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
736 if ( (*fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
737 else fADCmask[ctr] = kFALSE;
740 //AliDebug(4, Form("0x%08x: ADC mask", *fDataWord));
741 fNActiveADCs = ChannelsToRead(*fDataWord);
745 if (fRawVersion <= 2)
747 // no zero suppression
749 // 1 MCM header + 21 * ( Ntimebin/3)
750 // If NTimebin = 30, it is 211 words.
751 //fMCMWordsExpected = 1 + 21 * (fTBins / 3);
753 fNActiveADCs = ChannelsToRead(0x1fffff); // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
754 //fMCMWordsExpected = 1 + fNActiveADCs * ((fTBins-1) / 3. + 1.);
755 //directly get it like that:
756 fMCMWordsExpected = 1 + fNActiveADCs * fTBins / 3;
759 if (fRawVersion >= 3)
762 // 1 MCM header + 1 ADC mask + NofActiveADCs * ( Ntimebin/3 )
763 //directly get it like that:
764 fMCMWordsExpected = 1 + 1 + (fTBins * fNActiveADCs) / 3;
767 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
769 //____________________________________________________________________________
770 Bool_t AliTRDRawStreamV2::DecodeNextRawWord()
772 //AliDebug(8, Form("-----------------------------------------"));
773 //AliDebug(8, Form("DATA IS 0x%x", *fDataWord));
775 if (fADClookup[1] - 2 > fADClookup[0])
777 // AliDebug(8, Form("Overflow Index ADC = %d Max Index = %d Value = %d. Done with ADCs in this MCM. Is this already MCM header 0x%x?",
778 // fADClookup[1] - 2, fADClookup[0], fADClookup[fADClookup[1]], *fDataWord));
780 fMCMWordsExpected = 0;
781 AliWarning("Trying to recover. Fall back to DecodeMCM.");
783 //ChangeStatus(fkNextMCM);
787 if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
788 AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
789 fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
790 fMCMWordsExpected = 0;
791 AliWarning("Trying to recover. Fall back to DecodeMCM.");
793 //ChangeStatus(fkNextMCM);
797 if ( (*fDataWord & 0x3) != fLastADCmask || fTbSwitchCtr > fTimeWords)
799 fADC = fADClookup[fADClookup[1]];
800 // AliDebug(8, Form("Next fADC = %d at index = %d MCM Word Number: %d Max MCM Words is %d",
801 // fADC, fADClookup[1] - 2, fMCMWordCrt, fMCMWordsExpected));
805 fLastStatus = fkNextData;
806 fLastADCmask = (*fDataWord) & 0x3;
812 Bool_t kIsDataOK = kFALSE;
814 // We have only 21 ADC channels.
815 if ( fADC > (Int_t)fGeo->ADCmax() - 1 )
817 AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
818 fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
822 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
823 // MCMs and are good for online tracking in the MCM.
824 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax() - 1 )
828 // fCOL = fFee->GetPadColFromADC(fROB, fMCM, fADC);
829 fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fROB, fMCM, fADC);
831 // We have only 144 Pad Columns
832 //if ( fCOL > fColMax-1 || fCOL < 0 )
833 if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax )
835 // Decode 32 bit data words with information from 3 time bins and copy the data
836 fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
837 fSig[1] = (*fDataWord & 0x003ff000) >> 12;
838 fSig[2] = (*fDataWord & 0xffc00000) >> 22;
840 // Print data to screen:
841 //AliDebug(5, Form("DATA : 0x%x", *fDataWord));
842 // AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
843 // fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
848 AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
849 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
850 fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
851 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
857 //AliDebug(5, Form("fADC not accepted %d - DATA : 0x%x", fADC, *fDataWord));
864 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
866 // all mcm data processed go to next one
867 if ( fMCMWordCrt >= fMCMWordsExpected)
869 ChangeStatus(fkNextMCM);
875 //____________________________________________________________________________
876 Bool_t AliTRDRawStreamV2::DecodeMCM()
878 if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) )
881 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 )
883 AliWarning("Wrong fMCM or fROB. Skip this data");
884 fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB));
885 ChangeStatus(fkNextHC);
889 fTbSwitch = 3; // For first adc channel we expect: (*fDataWord & 3) = 3
891 fADC = fTB = 0; // Reset Counter
892 fLastADCmask = 0; // Reset
894 if (fMCMWordCrt < fMCMWordsExpected)
896 ChangeStatus(fkNextData);
900 ChangeStatus(fkNextMCM);
905 if ( *fDataWord == kEndofrawdatamarker )
906 { // End of half-chamber data, finished
908 ChangeStatus(fkNextHC);
909 fEndOfDataFlag = kTRUE;
910 //AliDebug(5, "Expecting MCM header but got End-Of-Raw-Data Marker");
911 if (fMCMWordsExpected == 0 || fMCMWordsExpected == fMCMWordCrt)
915 //AliDebug(5, Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
916 //AliWarning(Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
921 //AliDebug(3, Form("Expecting MCM header but got 0x%x. Going to Next MCM header.", *fDataWord));
922 AliWarning(Form("Expecting MCM header but got 0x%x. Fall back: Next MCM header.", *fDataWord));
923 ChangeStatus(fkNextMCM);
928 //____________________________________________________________________________
929 Bool_t AliTRDRawStreamV2::DecodeHC()
931 if ( fNextStatus == fkNextHC )
933 //AliDebug(5, "fkNextHC");
935 // 1) Find end_of_tracklet_marker
938 if (DecodeGTUlinkMask())
943 // endoftrackletmarker?
944 if ( *fDataWord == kEndoftrackletmarker )
946 //AliDebug(3, "End-of-tracklet-marker found");
947 //AliDebug(5, Form("Data 0x%x", *fDataWord));
948 ChangeStatus(fkSeekNonEoTracklet);
954 //AliDebug(3, "Tracklet found");
955 //AliDebug(5, Form("Tracklet data 0x%x", *fDataWord));
961 if (fNextStatus == fkSeekNonEoTracklet)
963 //AliDebug(5, "fkSeekNonEoTracklet");
966 // 2) Look for non-end_of_tracklet_marker
968 //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord);
970 if ( *fDataWord != kEndoftrackletmarker )
972 ChangeStatus(fkDecodeHC);
973 //AliDebug(3, "NON end-of-tracklet-marker found");
974 //AliDebug(5, Form("Data 0x%x", *fDataWord));
975 //// no do not continue - this should be the hcheader
979 //just go on and find the non-end_of_tracklet_marker
984 if ( fNextStatus == fkDecodeHC )
986 //AliDebug(5, "fkDecodeHC");
989 // 3) This Word must be Half Chamber Header
991 if ( (*fDataWord & 0x00000003) == 1 )
993 DecodeHCheader(fTimeBinsCalib); // This is the new header!
995 fDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
996 fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM);
997 fColMax = fGeo->GetColMax(fROC);
1001 fChamberDone[fDET]++;
1002 //AliDebug(6, Form("-------------- DET %d fChamberDone[fDET]=%d", fDET, fChamberDone[fDET]));
1004 ChangeStatus(fkNextMCM);
1009 AliWarning(Form("Expecting HC header mask but got 0x%x. Fall back: Next HC.", *fDataWord));
1010 ChangeStatus(fkNextHC);
1011 // before we went to //ChangeStatus(fkNextSM);
1017 //____________________________________________________________________________
1018 Bool_t AliTRDRawStreamV2::DecodeGTUlinkMask()
1021 // Decode the link masks sent by the GTU. These marke the active optical links
1022 // between GTU and Super Module. Up to now only fully active links are found
1023 // (0xfff = 12 active links).
1026 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
1028 if ( fRawVersion < 1 || fRawVersion > 3 )
1030 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1033 if ( fGTUctr1 == -1 ) fGTUctr2++;
1036 if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) )
1038 fGTUlinkMask[fGTUctr2][fGTUctr1] = (*fDataWord & 0xfff);
1041 //AliDebug(5, Form("GTU link mask 0x%x decoded 0x%x", *fDataWord, fGTUlinkMask[fGTUctr2][fGTUctr1]));
1048 // //____________________________________________________________________________
1049 void AliTRDRawStreamV2::ChangeStatus(Int_t kstat)
1051 fLastStatus = fNextStatus;
1052 fNextStatus = kstat;
1055 //____________________________________________________________________________
1056 Bool_t AliTRDRawStreamV2::DecodeSM()
1064 // After reading the first word check for size of this data and get Eq. ID
1065 if ( fWordCtr == 1 )
1067 fDataSize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
1068 fEqID = fRawReader->GetEquipmentId(); // Get Equipment ID
1069 if ( fDataSize > 0 ) fSizeOK = kTRUE;
1070 //AliDebug(3, Form("fDataSize=%d fEqID=%d", fDataSize, fEqID));
1074 if ( DecodeGTUlinkMask() )
1076 ChangeStatus(fkNextHC);
1081 AliWarning(Form("Equipment %d: First data word is not GTU Link Mask! Fall back: None. Stop.", fEqID));
1082 fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID));
1083 ChangeStatus(fkStop);
1089 //____________________________________________________________________________
1090 Bool_t AliTRDRawStreamV2::Next()
1093 // Updates the next data word pointer
1096 if (fNextStatus == fkStart)
1101 while (fNextStatus != fkStop)
1105 switch (fNextStatus)
1109 if (DecodeNextRawWord() == kTRUE)
1112 if (fSig[0] > fRawDigitThreshold || fSig[1] > fRawDigitThreshold || fSig[2] > fRawDigitThreshold)
1118 if (DecodeMCM() == kFALSE)
1119 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1122 case fkSeekNonEoTracklet:
1125 if (DecodeHC() == kFALSE)
1127 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1131 //the hc header should be decoded by now
1132 if (fLastStatus == fkDecodeHC)
1135 fChamberDone[fDET]++;
1141 if (DecodeSM() == kFALSE)
1142 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1147 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1148 ChangeStatus(fkStop);
1153 //AliDebug(1, Form("That's all folks! %d", fSM));
1157 //____________________________________________________________________________
1158 Int_t AliTRDRawStreamV2::NextChamber(AliTRDdigitsManager *man)
1161 // Fills single chamber digit array
1162 // Return value is the detector number
1165 AliTRDdataArrayI *digits = 0;
1166 AliTRDdataArrayI *track0 = 0;
1167 AliTRDdataArrayI *track1 = 0;
1168 AliTRDdataArrayI *track2 = 0;
1169 AliTRDSignalIndex *indexes = 0;
1171 if (fNextStatus == fkStart)
1176 // while (fNextStatus != fkStop)
1179 // // catch 3 things
1180 // // 1) if end of raw data - if chamber complete return
1181 // // 2) fill the data with signals if data decoded ok
1182 // // 3) initialize (destroy old) after the det has changed -> just after HC header decoding
1185 while (fNextStatus != fkStop)
1189 switch (fNextStatus)
1194 if (DecodeNextRawWord() == kTRUE)
1196 for (Int_t it = 0; it < 3; it++)
1198 if ( fTB + it < fTBins )
1200 if ( fSig[it] > fRawDigitThreshold )
1202 digits->SetDataUnchecked(fROW, fCOL, fTB + it, fSig[it]);
1203 indexes->AddIndexTBin(fROW, fCOL, fTB + it);
1204 if (man->UsesDictionaries())
1206 track0->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1207 track1->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1208 track2->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1209 } // if dictionaries
1210 } // signal above zero
1211 } // check the tbins range
1212 } // for each tbin of current 3
1217 // can be here as a fall back from decode raw data calling decodemcm
1218 if (fEndOfDataFlag == kTRUE)
1220 if (fChamberDone[fDET] == 2)
1224 fEndOfDataFlag = kFALSE;
1231 if (DecodeMCM() == kFALSE)
1233 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1235 // default place for end of raw data...
1236 if (fEndOfDataFlag == kTRUE)
1238 if (fChamberDone[fDET] == 2)
1242 fEndOfDataFlag = kFALSE;
1247 case fkSeekNonEoTracklet:
1250 if (DecodeHC() == kFALSE)
1252 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1256 //the hc header should be decoded by now
1257 if (fLastStatus == fkDecodeHC)
1259 // AliDebug(4, Form("???? New DET ???? %d last %d", fDET, fLastDET));
1260 // allocate stuff for the new det
1261 //man->ResetArrays();
1262 digits = man->GetDigits(fDET);
1263 track0 = man->GetDictionary(fDET,0);
1264 track1 = man->GetDictionary(fDET,1);
1265 track2 = man->GetDictionary(fDET,2);
1267 // Allocate memory space for the digits buffer
1268 if (digits->GetNtime() == 0)
1270 // AliDebug(5, Form("Alloc digits for det %d rows %d cols %d tbins %d", fDET, fRowMax, fColMax, fTBins));
1271 digits->Allocate(fRowMax, fColMax, fTBins);
1272 if (man->UsesDictionaries())
1274 track0->Allocate(fRowMax, fColMax, fTBins);
1275 track1->Allocate(fRowMax, fColMax, fTBins);
1276 track2->Allocate(fRowMax, fColMax, fTBins);
1280 indexes = man->GetIndexes(fDET);
1281 indexes->SetSM(fSM);
1282 indexes->SetStack(fSTACK);
1283 indexes->SetLayer(fLAYER);
1284 indexes->SetDetNumber(fDET);
1286 if (indexes->IsAllocated() == kFALSE)
1288 // AliDebug(4, "Allocating indexes");
1289 indexes->Allocate(fRowMax, fColMax, fTBins);
1291 } // is the HC header already decoded?
1297 if (DecodeSM() == kFALSE)
1298 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1305 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1306 ChangeStatus(fkStop);
1311 // we do not return chambers for which the end-of-data was not received twice (for each HC)
1313 //AliDebug(1, Form("That's all folks! %d", fSM));