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"
34 #include "AliTRDRawStreamV2.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDcalibDB.h"
37 #include "AliTRDfeeParam.h"
38 #include "AliTRDdigitsManager.h"
39 #include "AliTRDdataArrayI.h"
40 #include "AliTRDSignalIndex.h"
42 ClassImp(AliTRDRawStreamV2)
44 //_____________________________________________________________________________
45 AliTRDRawStreamV2::AliTRDRawStreamV2()
95 ,fRawDigitThreshold(0)
119 ,fEndOfDataFlag(kFALSE)
122 // Default constructor
125 for (Int_t i = 0; i < 540; i++) {
131 //_____________________________________________________________________________
132 AliTRDRawStreamV2::AliTRDRawStreamV2(AliRawReader *rawReader)
178 ,fMCMWordsExpected(0)
179 ,fRawReader(rawReader)
181 ,fRawDigitThreshold(0)
205 ,fEndOfDataFlag(kFALSE)
208 // Create an object to read TRD raw digits
211 fRawReader->Select("TRD");
213 for (Int_t i = 0; i < 540; i++) {
219 //_____________________________________________________________________________
220 AliTRDRawStreamV2::AliTRDRawStreamV2(const AliTRDRawStreamV2& stream)
267 ,fMCMWordsExpected(0)
270 ,fRawDigitThreshold(0)
294 ,fEndOfDataFlag(kFALSE)
300 AliFatal("Copy constructor not implemented");
304 //_____________________________________________________________________________
305 AliTRDRawStreamV2& AliTRDRawStreamV2::operator = (const AliTRDRawStreamV2&
309 // Assigment operator
312 Fatal("operator =", "assignment operator not implemented");
317 //_____________________________________________________________________________
318 AliTRDRawStreamV2::~AliTRDRawStreamV2()
330 //_____________________________________________________________________________
331 void AliTRDRawStreamV2::SetRawReader(AliRawReader *rawReader)
339 fRawReader = rawReader;
343 //_____________________________________________________________________________
344 Bool_t AliTRDRawStreamV2::SetRawVersion(Int_t rv)
347 // Set the raw data version
350 if ( rv >= 0 && rv <= 3 ) {
359 //____________________________________________________________________________
360 Int_t AliTRDRawStreamV2::Init()
366 if (!AliTRDcalibDB::Instance()) {
367 AliError("Could not get calibration object");
372 fGeo = new AliTRDgeometry();
375 fTimeBinsCalib = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
376 //AliDebug(2, Form("Number of Timebins read from CDB: %d", fTimeBinsCalib));
378 // The number of data words needed for this number of time bins (there
379 // are 3 time bins in one word)
380 fTimeWords = (fTimeBinsCalib-1)/3 + 1;
385 fHCHctr1 = fHCHctr2 = 0;
386 fGTUctr1 = fGTUctr2 = -1;
398 fLastStatus = kStart;
399 fNextStatus = kStart;
406 fkBufferSet = kFALSE;
409 fMCMWordsExpected = 0;
411 fEndOfDataFlag = kFALSE;
412 // set all ADC active
413 // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
414 fNActiveADCs = ChannelsToRead(0x1fffff);
421 //____________________________________________________________________________
422 Int_t AliTRDRawStreamV2::NextData()
425 // Updates the next data word pointer
428 if (fCountBytes + fgkSizeWord >= fBufSize)
430 fkBufferSet = fRawReader->ReadNextData(fPos);
431 if (fkBufferSet == kTRUE)
433 fBufSize = fRawReader->GetDataSize();
435 fDataWord = (UInt_t*)fPos;
436 ChangeStatus(kNextSM);
449 fCountBytes += fgkSizeWord;
450 fDataWord = (UInt_t*)fPos;
456 //============================================================================
457 // Decoding functions
458 //============================================================================
460 //____________________________________________________________________________
461 void AliTRDRawStreamV2::DecodeHCheader(Int_t timeBins)
464 // Decode the HC header (fRawVersion == 2, 3, 4, ???)
467 fRVmajor = (*fDataWord >> 24) & 0x7f;
468 fRVminor = (*fDataWord >> 17) & 0x7f;
470 if (fRVmajor < 2 || fRVmajor > 4)
471 AliError(Form(" Unsupported raw version: %d", fRawVersion))
473 if ( fRawVersion != fRVmajor ) {
475 AliWarning("===============================================================================");
476 AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)"
477 ,fRawVersion,fRVmajor));
478 AliWarning(Form("Setting fRawVersion to %d", fRVmajor));
479 AliWarning("===============================================================================");
480 fRawVersion = fRVmajor;
485 // check for zero suppression
486 if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
487 else fZeroSuppressed = kFALSE;
490 if ( (*fDataWord & 0x3) == 1 ) {
492 fHCHWords = (*fDataWord >> 14) & 0x7;
493 fSM = (*fDataWord >> 9) & 0x1f;
494 fLAYER = (*fDataWord >> 6) & 0x7;
495 fSTACK = (*fDataWord >> 3) & 0x7;
496 fSIDE = (*fDataWord >> 2) & 0x1;
498 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
500 //AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", *fDataWord, fSM, fROC, fSIDE+10));
501 //AliDebug(5, Form("0x%08x: HC header: expecting %d HC words", *fDataWord, fHCHWords));
512 AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
513 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
514 fRawReader->AddMajorErrorLog(kHCHeaderCorrupt,Form("0x%08x:dcs=%d; sm=%d; layer=%d; stack=%d.",
515 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
525 AliWarning(Form("0x%08x: No HC header when it was expected.", *fDataWord));
526 fRawReader->AddMajorErrorLog(kHCHeaderMissing,Form("0x%08x", *fDataWord));
530 if ( fHCHWords >= 1 )
532 // read one more word
533 if (NextData() != kWordOK)
535 AliWarning("Next HC word missing");
536 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
537 fNextStatus = kNextHC;
541 if ( (*fDataWord & 0x3) == 1 )
544 fBCctr = (*fDataWord >> 16);
545 fPTctr = (*fDataWord >> 12) & 0xf;
546 fPTphase = (*fDataWord >> 8) & 0xf;
547 fTBins = ((*fDataWord >> 2) & 0x3f) + 1;
548 fTimeWords = (fTBins - 1)/3 + 1;
550 // AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
551 // , *fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
553 if( fTBins != timeBins )
555 AliWarning("===============================================================================");
556 AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)"
557 , timeBins, fTBins));
558 AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins));
559 AliWarning("===============================================================================");
561 fTimeWords = (fTBins - 1)/3 + 1;
567 if ( fHCHWords >= 2 ) {
568 // read one more word
569 if (NextData() != kWordOK)
571 AliWarning("Next HC word missing");
572 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
573 fNextStatus = kNextHC;
576 if ( (*fDataWord & 0x3) == 1 ) {
578 fTCon = (*fDataWord >> 29) & 0x1;
579 fPEDon = (*fDataWord >> 31) & 0x1;
580 fGAINon = (*fDataWord >> 30) & 0x1;
581 fXTon = (*fDataWord >> 28) & 0x1;
582 fNonLinOn = (*fDataWord >> 27) & 0x1;
583 fBypass = (*fDataWord >> 26) & 0x1;
585 fCommonAdditive = (*fDataWord >> 20) & 0x3f;
587 // AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d"
588 // , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive));
594 //____________________________________________________________________________
595 Int_t AliTRDRawStreamV2::ChannelsToRead(Int_t ADCmask)
598 // Return the channels to read
601 memset(fADClookup, -1, 32 * sizeof(Int_t));
602 fADClookup[0] = 0; // count entries
603 fADClookup[1] = 2; // index - data start at 2
605 for (Int_t i = 0; i < 30; i++)
608 if ((ADCmask & mask))
610 //AliDebug(9, Form("fDataWord=0x%08x mask=0x%08x i=%d", *fDataWord, mask, i));
611 fADClookup[fADClookup[1]] = i;
617 // test the iteration - comment out for production
618 // begin of comment out section
620 sprintf(schannels, "ADC Channels to read: ");
622 while(fADClookup[1] - 2 < fADClookup[0])
624 //AliDebug(9, Form("max=%d index=%d adc=%d", fADClookup[0], fADClookup[1], fADClookup[fADClookup[1]]));
625 strcat(schannels, Form("%d ", fADClookup[fADClookup[1]]));
628 //AliDebug(9, Form("%s", schannels));
629 //AliDebug(9, Form("ADC channels = %d", fADClookup[0]));
630 // end of comment out section
633 return fADClookup[0];
636 //____________________________________________________________________________
637 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()
675 // Decode the MCM header
678 if ( fRawVersion < 1 || fRawVersion > 3 )
680 AliError(Form(" Unsupported raw version: %d", fRawVersion));
683 fMCM = (*fDataWord & 0xff000000) >> 24;
684 fEv = (*fDataWord & 0x00fffff0) >> 4;
689 fROW = AliTRDfeeParam::Instance()->GetPadRowFromMCM(fROB, fMCM);
691 // AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d"
692 // , *fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv));
694 if ( fROB % 2 == 0 && fSIDE == 1 ) {
695 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
696 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
697 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
698 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
700 if ( fROB % 2 != 0 && fSIDE == 0 ) {
701 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
702 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
703 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
704 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
706 if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
707 (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
708 AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
709 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
710 fRawReader->AddMajorErrorLog(kWrongPadrow,Form("SM%d L%dS%d: Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
711 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
717 fMCMWordCrt = 1; // MCM header
719 // AdcMask for Zero supressed data
720 if ( fRawVersion == 3 )
722 // read one more word
723 if (NextData() != kWordOK)
725 AliWarning("MCM ADC mask missing");
726 fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
727 fNextStatus = kNextHC;
734 for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
735 if ( (*fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
736 else fADCmask[ctr] = kFALSE;
739 //AliDebug(4, Form("0x%08x: ADC mask", *fDataWord));
740 fNActiveADCs = ChannelsToRead(*fDataWord);
744 if (fRawVersion <= 2)
746 // no zero suppression
748 // 1 MCM header + 21 * ( Ntimebin/3)
749 // If NTimebin = 30, it is 211 words.
750 //fMCMWordsExpected = 1 + 21 * (fTBins / 3);
752 fNActiveADCs = ChannelsToRead(0x1fffff); // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
753 //fMCMWordsExpected = 1 + fNActiveADCs * ((fTBins-1) / 3. + 1.);
754 //directly get it like that:
755 fMCMWordsExpected = 1 + fNActiveADCs * fTBins / 3;
758 if (fRawVersion >= 3)
761 // 1 MCM header + 1 ADC mask + NofActiveADCs * ( Ntimebin/3 )
762 //directly get it like that:
763 fMCMWordsExpected = 1 + 1 + (fTBins * fNActiveADCs) / 3;
766 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
768 //____________________________________________________________________________
769 Bool_t AliTRDRawStreamV2::DecodeNextRawWord()
772 // Decode the next raw data word
775 //AliDebug(8, Form("-----------------------------------------"));
776 //AliDebug(8, Form("DATA IS 0x%x", *fDataWord));
778 if (fADClookup[1] - 2 > fADClookup[0])
780 // 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?",
781 // fADClookup[1] - 2, fADClookup[0], fADClookup[fADClookup[1]], *fDataWord));
783 fMCMWordsExpected = 0;
784 AliWarning("Trying to recover. Fall back to DecodeMCM.");
786 //ChangeStatus(kNextMCM);
790 if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
791 AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
792 fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
793 fMCMWordsExpected = 0;
794 AliWarning("Trying to recover. Fall back to DecodeMCM.");
796 //ChangeStatus(kNextMCM);
800 if ( (*fDataWord & 0x3) != fLastADCmask || fTbSwitchCtr > fTimeWords)
802 fADC = fADClookup[fADClookup[1]];
803 // AliDebug(8, Form("Next fADC = %d at index = %d MCM Word Number: %d Max MCM Words is %d",
804 // fADC, fADClookup[1] - 2, fMCMWordCrt, fMCMWordsExpected));
808 fLastStatus = kNextData;
809 fLastADCmask = (*fDataWord) & 0x3;
815 Bool_t kIsDataOK = kFALSE;
817 // We have only 21 ADC channels.
818 if ( fADC > (Int_t)fGeo->ADCmax() - 1 )
820 AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
821 fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
825 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
826 // MCMs and are good for online tracking in the MCM.
827 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax() - 1 )
831 // fCOL = fFee->GetPadColFromADC(fROB, fMCM, fADC);
832 fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fROB, fMCM, fADC);
834 // We have only 144 Pad Columns
835 //if ( fCOL > fColMax-1 || fCOL < 0 )
836 if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax )
838 // Decode 32 bit data words with information from 3 time bins and copy the data
839 fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
840 fSig[1] = (*fDataWord & 0x003ff000) >> 12;
841 fSig[2] = (*fDataWord & 0xffc00000) >> 22;
843 // Print data to screen:
844 //AliDebug(5, Form("DATA : 0x%x", *fDataWord));
845 // AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
846 // fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
851 AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
852 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
853 fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
854 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
860 //AliDebug(5, Form("fADC not accepted %d - DATA : 0x%x", fADC, *fDataWord));
867 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
869 // all mcm data processed go to next one
870 if ( fMCMWordCrt >= fMCMWordsExpected)
872 ChangeStatus(kNextMCM);
878 //____________________________________________________________________________
879 Bool_t AliTRDRawStreamV2::DecodeMCM()
882 // Decode a single MCM
885 if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) )
888 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 )
890 AliWarning("Wrong fMCM or fROB. Skip this data");
891 fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB));
892 ChangeStatus(kNextHC);
896 fTbSwitch = 3; // For first adc channel we expect: (*fDataWord & 3) = 3
898 fADC = fTB = 0; // Reset Counter
899 fLastADCmask = 0; // Reset
901 if (fMCMWordCrt < fMCMWordsExpected)
903 ChangeStatus(kNextData);
907 ChangeStatus(kNextMCM);
912 if ( *fDataWord == fgkEndofrawdatamarker )
913 { // End of half-chamber data, finished
915 ChangeStatus(kNextHC);
916 fEndOfDataFlag = kTRUE;
917 //AliDebug(5, "Expecting MCM header but got End-Of-Raw-Data Marker");
918 if (fMCMWordsExpected == 0 || fMCMWordsExpected == fMCMWordCrt)
922 //AliDebug(5, Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
923 //AliWarning(Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
928 //AliDebug(3, Form("Expecting MCM header but got 0x%x. Going to Next MCM header.", *fDataWord));
929 AliWarning(Form("Expecting MCM header but got 0x%x. Fall back: Next MCM header.", *fDataWord));
930 ChangeStatus(kNextMCM);
935 //____________________________________________________________________________
936 Bool_t AliTRDRawStreamV2::DecodeHC()
939 // Decode a half chamber
942 if ( fNextStatus == kNextHC )
944 //AliDebug(5, "kNextHC");
946 // 1) Find end_of_tracklet_marker
949 if (DecodeGTUlinkMask())
954 // endoftrackletmarker?
955 if ( *fDataWord == fgkEndoftrackletmarker )
957 //AliDebug(3, "End-of-tracklet-marker found");
958 //AliDebug(5, Form("Data 0x%x", *fDataWord));
959 ChangeStatus(kSeekNonEoTracklet);
965 //AliDebug(3, "Tracklet found");
966 //AliDebug(5, Form("Tracklet data 0x%x", *fDataWord));
972 if (fNextStatus == kSeekNonEoTracklet)
974 //AliDebug(5, "kSeekNonEoTracklet");
977 // 2) Look for non-end_of_tracklet_marker
979 //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord);
981 if ( *fDataWord != fgkEndoftrackletmarker )
983 ChangeStatus(kDecodeHC);
984 //AliDebug(3, "NON end-of-tracklet-marker found");
985 //AliDebug(5, Form("Data 0x%x", *fDataWord));
986 //// no do not continue - this should be the hcheader
990 //just go on and find the non-end_of_tracklet_marker
995 if ( fNextStatus == kDecodeHC )
997 //AliDebug(5, "kDecodeHC");
1000 // 3) This Word must be Half Chamber Header
1002 if ( (*fDataWord & 0x00000003) == 1 )
1004 DecodeHCheader(fTimeBinsCalib); // This is the new header!
1006 fDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
1007 fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM);
1008 fColMax = fGeo->GetColMax(fROC);
1012 fChamberDone[fDET]++;
1013 //AliDebug(6, Form("-------------- DET %d fChamberDone[fDET]=%d", fDET, fChamberDone[fDET]));
1015 ChangeStatus(kNextMCM);
1020 AliWarning(Form("Expecting HC header mask but got 0x%x. Fall back: Next HC.", *fDataWord));
1021 ChangeStatus(kNextHC);
1022 // before we went to //ChangeStatus(kNextSM);
1029 //____________________________________________________________________________
1030 Bool_t AliTRDRawStreamV2::DecodeGTUlinkMask()
1033 // Decode the link masks sent by the GTU. These marke the active optical links
1034 // between GTU and Super Module. Up to now only fully active links are found
1035 // (0xfff = 12 active links).
1038 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
1040 if ( fRawVersion < 1 || fRawVersion > 3 )
1042 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1045 if ( fGTUctr1 == -1 ) fGTUctr2++;
1048 if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) )
1050 fGTUlinkMask[fGTUctr2][fGTUctr1] = (*fDataWord & 0xfff);
1053 //AliDebug(5, Form("GTU link mask 0x%x decoded 0x%x", *fDataWord, fGTUlinkMask[fGTUctr2][fGTUctr1]));
1060 //____________________________________________________________________________
1061 void AliTRDRawStreamV2::ChangeStatus(Int_t kstat)
1064 // Change the status
1067 fLastStatus = fNextStatus;
1068 fNextStatus = kstat;
1071 //____________________________________________________________________________
1072 Bool_t AliTRDRawStreamV2::DecodeSM()
1075 // Decode a supermodule
1084 // After reading the first word check for size of this data and get Eq. ID
1085 if ( fWordCtr == 1 )
1087 fDataSize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
1088 fEqID = fRawReader->GetEquipmentId(); // Get Equipment ID
1089 if ( fDataSize > 0 ) fSizeOK = kTRUE;
1090 //AliDebug(3, Form("fDataSize=%d fEqID=%d", fDataSize, fEqID));
1094 if ( DecodeGTUlinkMask() )
1096 ChangeStatus(kNextHC);
1101 AliWarning(Form("Equipment %d: First data word is not GTU Link Mask! Fall back: None. Stop.", fEqID));
1102 fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID));
1103 ChangeStatus(kStop);
1109 //____________________________________________________________________________
1110 Bool_t AliTRDRawStreamV2::Next()
1113 // Updates the next data word pointer
1116 if (fNextStatus == kStart)
1121 while (fNextStatus != kStop)
1125 switch (fNextStatus)
1129 if (DecodeNextRawWord() == kTRUE)
1132 if (fSig[0] > fRawDigitThreshold || fSig[1] > fRawDigitThreshold || fSig[2] > fRawDigitThreshold)
1138 if (DecodeMCM() == kFALSE)
1139 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1142 case kSeekNonEoTracklet:
1145 if (DecodeHC() == kFALSE)
1147 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1151 //the hc header should be decoded by now
1152 if (fLastStatus == kDecodeHC)
1155 fChamberDone[fDET]++;
1161 if (DecodeSM() == kFALSE)
1162 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1167 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1168 ChangeStatus(kStop);
1173 //AliDebug(1, Form("That's all folks! %d", fSM));
1177 //____________________________________________________________________________
1178 Int_t AliTRDRawStreamV2::NextChamber(AliTRDdigitsManager *man)
1181 // Fills single chamber digit array
1182 // Return value is the detector number
1185 AliTRDdataArrayI *digits = 0;
1186 AliTRDdataArrayI *track0 = 0;
1187 AliTRDdataArrayI *track1 = 0;
1188 AliTRDdataArrayI *track2 = 0;
1189 AliTRDSignalIndex *indexes = 0;
1191 if (fNextStatus == kStart)
1196 // while (fNextStatus != kStop)
1199 // // catch 3 things
1200 // // 1) if end of raw data - if chamber complete return
1201 // // 2) fill the data with signals if data decoded ok
1202 // // 3) initialize (destroy old) after the det has changed -> just after HC header decoding
1205 while (fNextStatus != kStop)
1209 switch (fNextStatus)
1214 if (DecodeNextRawWord() == kTRUE)
1216 for (Int_t it = 0; it < 3; it++)
1218 if ( fTB + it < fTBins )
1220 if ( fSig[it] > fRawDigitThreshold )
1222 digits->SetDataUnchecked(fROW, fCOL, fTB + it, fSig[it]);
1223 indexes->AddIndexTBin(fROW, fCOL, fTB + it);
1224 if (man->UsesDictionaries())
1226 track0->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1227 track1->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1228 track2->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1229 } // if dictionaries
1230 } // signal above zero
1231 } // check the tbins range
1232 } // for each tbin of current 3
1237 // can be here as a fall back from decode raw data calling decodemcm
1238 if (fEndOfDataFlag == kTRUE)
1240 if (fChamberDone[fDET] == 2)
1244 fEndOfDataFlag = kFALSE;
1251 if (DecodeMCM() == kFALSE)
1253 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1255 // default place for end of raw data...
1256 if (fEndOfDataFlag == kTRUE)
1258 if (fChamberDone[fDET] == 2)
1262 fEndOfDataFlag = kFALSE;
1267 case kSeekNonEoTracklet:
1270 if (DecodeHC() == kFALSE)
1272 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1276 //the hc header should be decoded by now
1277 if (fLastStatus == kDecodeHC)
1279 // AliDebug(4, Form("???? New DET ???? %d last %d", fDET, fLastDET));
1280 // allocate stuff for the new det
1281 //man->ResetArrays();
1282 digits = man->GetDigits(fDET);
1283 track0 = man->GetDictionary(fDET,0);
1284 track1 = man->GetDictionary(fDET,1);
1285 track2 = man->GetDictionary(fDET,2);
1287 // Allocate memory space for the digits buffer
1288 if (digits->GetNtime() == 0)
1290 // AliDebug(5, Form("Alloc digits for det %d rows %d cols %d tbins %d", fDET, fRowMax, fColMax, fTBins));
1291 digits->Allocate(fRowMax, fColMax, fTBins);
1292 if (man->UsesDictionaries())
1294 track0->Allocate(fRowMax, fColMax, fTBins);
1295 track1->Allocate(fRowMax, fColMax, fTBins);
1296 track2->Allocate(fRowMax, fColMax, fTBins);
1300 indexes = man->GetIndexes(fDET);
1301 indexes->SetSM(fSM);
1302 indexes->SetStack(fSTACK);
1303 indexes->SetLayer(fLAYER);
1304 indexes->SetDetNumber(fDET);
1306 if (indexes->IsAllocated() == kFALSE)
1308 // AliDebug(4, "Allocating indexes");
1309 indexes->Allocate(fRowMax, fColMax, fTBins);
1311 } // is the HC header already decoded?
1317 if (DecodeSM() == kFALSE)
1318 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1325 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1326 ChangeStatus(kStop);
1331 // we do not return chambers for which the end-of-data was not received twice (for each HC)
1333 //AliDebug(1, Form("That's all folks! %d", fSM));