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 "AliTRDarrayDictionary.h"
40 #include "AliTRDarrayADC.h"
41 #include "AliTRDSignalIndex.h"
43 ClassImp(AliTRDRawStreamV2)
45 UInt_t AliTRDRawStreamV2::fgDumpHead = 0;
47 //_____________________________________________________________________________
48 AliTRDRawStreamV2::AliTRDRawStreamV2()
49 :AliTRDrawStreamBase()
99 ,fRawDigitThreshold(0)
125 ,fEndOfDataFlag(kFALSE)
128 // Default constructor
131 for (Int_t i = 0; i < 540; i++) {
137 //_____________________________________________________________________________
138 AliTRDRawStreamV2::AliTRDRawStreamV2(AliRawReader *rawReader)
139 :AliTRDrawStreamBase(rawReader)
185 ,fMCMWordsExpected(0)
186 ,fRawReader(rawReader)
188 ,fRawDigitThreshold(0)
214 ,fEndOfDataFlag(kFALSE)
217 // Create an object to read TRD raw digits
220 fRawReader->Select("TRD");
222 for (Int_t i = 0; i < 540; i++) {
228 //_____________________________________________________________________________
229 AliTRDRawStreamV2::AliTRDRawStreamV2(const AliTRDRawStreamV2& stream)
230 :AliTRDrawStreamBase(stream)
277 ,fMCMWordsExpected(0)
280 ,fRawDigitThreshold(0)
306 ,fEndOfDataFlag(kFALSE)
312 AliFatal("Copy constructor not implemented");
316 //_____________________________________________________________________________
317 AliTRDRawStreamV2& AliTRDRawStreamV2::operator = (const AliTRDRawStreamV2&
321 // Assigment operator
324 Fatal("operator =", "assignment operator not implemented");
329 //_____________________________________________________________________________
330 AliTRDRawStreamV2::~AliTRDRawStreamV2()
342 //_____________________________________________________________________________
343 void AliTRDRawStreamV2::SetRawReader(AliRawReader *rawReader)
351 fRawReader = rawReader;
355 //_____________________________________________________________________________
356 Bool_t AliTRDRawStreamV2::SetRawVersion(Int_t rv)
359 // Set the raw data version
362 if ( rv >= 0 && rv <= 3 ) {
371 //____________________________________________________________________________
372 Bool_t AliTRDRawStreamV2::Init()
378 if (!AliTRDcalibDB::Instance()) {
379 AliError("Could not get calibration object");
384 fGeo = new AliTRDgeometry();
387 fTimeBinsCalib = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
388 //AliDebug(2, Form("Number of Timebins read from CDB: %d", fTimeBinsCalib));
390 // The number of data words needed for this number of time bins (there
391 // are 3 time bins in one word)
392 fTimeWords = (fTimeBinsCalib-1)/3 + 1;
397 fHCHctr1 = fHCHctr2 = 0;
398 fGTUctr1 = fGTUctr2 = -1;
410 fLastStatus = kStart;
411 fNextStatus = kStart;
420 fkBufferSet = kFALSE;
423 fMCMWordsExpected = 0;
425 fEndOfDataFlag = kFALSE;
426 // set all ADC active
427 // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
428 fNActiveADCs = ChannelsToRead(0x1fffff);
435 //____________________________________________________________________________
436 void AliTRDRawStreamV2::SwapOnEndian()
439 // Check the endian and swap if needed
443 char* ptemp = (char*) &itemp;
444 fpBegin = (UInt_t*)fPos;
445 fpEnd = fpBegin + (fBufSize/sizeof(UInt_t));
449 // assume we are at the begining of the buffer!
450 //AliDebug(5, "Swapping.");
451 //UInt_t *pbegin = (UInt_t*)fPos;
453 for (UInt_t i = 0; i < fBufSize / fgkSizeWord; i++)
455 fDataWord = fpBegin + i;
456 iutmp = (((*fDataWord & 0x000000ffU) << 24) | ((*fDataWord & 0x0000ff00U) << 8) |
457 ((*fDataWord & 0x00ff0000U) >> 8) | ((*fDataWord & 0xff000000U) >> 24));
458 // here we override the value in the buffer!
464 // dump words - debugging perpose
466 AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));
467 if (DumpWords(fpBegin, fgDumpHead) == kFALSE){AliError("Dump failed. Not enough data.");}
468 AliInfo(Form("---------- Dumping ended ----------------------------------------------"));
472 //____________________________________________________________________________
473 Int_t AliTRDRawStreamV2::NextData()
476 // Updates the next data word pointer
479 if (fCountBytes + fgkSizeWord >= fBufSize)
481 fkBufferSet = fRawReader->ReadNextData(fPos);
482 if (fkBufferSet == kTRUE)
484 fBufSize = fRawReader->GetDataSize();
486 fDataWord = (UInt_t*)fPos;
488 ChangeStatus(kNextSM);
501 fCountBytes += fgkSizeWord;
502 fDataWord = (UInt_t*)fPos;
508 //============================================================================
509 // Decoding functions
510 //============================================================================
512 //____________________________________________________________________________
513 void AliTRDRawStreamV2::DecodeHCheader(Int_t timeBins)
516 // Decode the HC header (fRawVersion == 2, 3, 4, ???)
519 fRVmajor = (*fDataWord >> 24) & 0x7f;
520 fRVminor = (*fDataWord >> 17) & 0x7f;
522 if (fRVmajor < 2 || fRVmajor > 4)
523 AliError(Form(" Unsupported raw version: %d", fRawVersion))
525 if ( fRawVersion != fRVmajor ) {
527 AliWarning("===============================================================================");
528 AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)"
529 ,fRawVersion,fRVmajor));
530 AliWarning(Form("Setting fRawVersion to %d", fRVmajor));
531 AliWarning("===============================================================================");
532 fRawVersion = fRVmajor;
537 // check for zero suppression
538 if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
539 else fZeroSuppressed = kFALSE;
542 if ( (*fDataWord & 0x3) == 1 ) {
544 fHCHWords = (*fDataWord >> 14) & 0x7;
545 fSM = (*fDataWord >> 9) & 0x1f;
546 fLAYER = (*fDataWord >> 6) & 0x7;
547 fSTACK = (*fDataWord >> 3) & 0x7;
548 fSIDE = (*fDataWord >> 2) & 0x1;
550 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
552 //AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", *fDataWord, fSM, fROC, fSIDE+10));
553 //AliDebug(5, Form("0x%08x: HC header: expecting %d HC words", *fDataWord, fHCHWords));
564 AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
565 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
566 fRawReader->AddMajorErrorLog(kHCHeaderCorrupt,Form("0x%08x:dcs=%d; sm=%d; layer=%d; stack=%d.",
567 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
577 AliWarning(Form("0x%08x: No HC header when it was expected.", *fDataWord));
578 fRawReader->AddMajorErrorLog(kHCHeaderMissing,Form("0x%08x", *fDataWord));
582 if ( fHCHWords >= 1 )
584 // read one more word
585 if (NextData() != kWordOK)
587 AliWarning("Next HC word missing");
588 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
589 fNextStatus = kNextHC;
593 if ( (*fDataWord & 0x3) == 1 )
596 fBCctr = (*fDataWord >> 16);
597 fPTctr = (*fDataWord >> 12) & 0xf;
598 fPTphase = (*fDataWord >> 8) & 0xf;
599 fTBins = ((*fDataWord >> 2) & 0x3f) + 1;
600 fTimeWords = (fTBins - 1)/3 + 1;
602 // AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
603 // , *fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
605 if( fTBins != timeBins )
607 AliWarning("===============================================================================");
608 AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)"
609 , timeBins, fTBins));
610 AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins));
611 AliWarning("===============================================================================");
613 fTimeWords = (fTBins - 1)/3 + 1;
619 if ( fHCHWords >= 2 ) {
620 // read one more word
621 if (NextData() != kWordOK)
623 AliWarning("Next HC word missing");
624 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
625 fNextStatus = kNextHC;
628 if ( (*fDataWord & 0x3) == 1 ) {
630 fTCon = (*fDataWord >> 29) & 0x1;
631 fPEDon = (*fDataWord >> 31) & 0x1;
632 fGAINon = (*fDataWord >> 30) & 0x1;
633 fXTon = (*fDataWord >> 28) & 0x1;
634 fNonLinOn = (*fDataWord >> 27) & 0x1;
635 fBypass = (*fDataWord >> 26) & 0x1;
637 fCommonAdditive = (*fDataWord >> 20) & 0x3f;
639 // AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d"
640 // , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive));
646 //____________________________________________________________________________
647 Int_t AliTRDRawStreamV2::ChannelsToRead(Int_t ADCmask)
650 // Return the channels to read
653 memset(fADClookup, -1, 32 * sizeof(Int_t));
654 fADClookup[0] = 0; // count entries
655 fADClookup[1] = 2; // index - data start at 2
657 for (Int_t i = 0; i < 30; i++)
660 if ((ADCmask & mask))
662 //AliDebug(9, Form("fDataWord=0x%08x mask=0x%08x i=%d", *fDataWord, mask, i));
663 fADClookup[fADClookup[1]] = i;
669 // test the iteration - comment out for production
670 // begin of comment out section
672 sprintf(schannels, "ADC Channels to read: ");
674 while(fADClookup[1] - 2 < fADClookup[0])
676 //AliDebug(9, Form("max=%d index=%d adc=%d", fADClookup[0], fADClookup[1], fADClookup[fADClookup[1]]));
677 strcat(schannels, Form("%d ", fADClookup[fADClookup[1]]));
680 //AliDebug(9, Form("%s", schannels));
681 //AliDebug(9, Form("ADC channels = %d", fADClookup[0]));
682 // end of comment out section
685 return fADClookup[0];
688 //____________________________________________________________________________
689 void AliTRDRawStreamV2::DecodeTracklet()
692 // Decode the Tracklet
694 // this function is not tested yet on real tracklets
697 if ( fRawVersion < 1 || fRawVersion > 3 )
699 AliError(Form(" Unsupported raw version: %d", fRawVersion));
702 fTracklPID = (*fDataWord >> 24) & 0xff;
703 fTracklPadRow = (*fDataWord >> 20) & 0xf; // 0:15
704 fTracklDefL = (*fDataWord >> 13) & 0x7f;
705 fTracklPadPos = (*fDataWord) & 0x1fff;
707 fTracklPID /= (Float_t)((1<<8) - 1); // 0:1 (steps of 0.39%)
708 fTracklDefL = (fTracklDefL - ((1<< 7)-1)/2.) * 140.e-4; // -0.889:0.889cm
709 fTracklPadPos = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm
711 //AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f"
712 // , *fDataWord, fSM, fLAYER, fSTACK, fSIDE+10
713 // , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID));
715 if( ((fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0())) ||
716 ((fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1())) ) {
717 AliWarning(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow));
718 fRawReader->AddMajorErrorLog(kTrackletRowMismatch,Form("Word: %d", fTracklPadRow));
723 //____________________________________________________________________________
724 void AliTRDRawStreamV2::DecodeMCMheader()
727 // Decode the MCM header
730 if ( fRawVersion < 1 || fRawVersion > 3 )
732 AliError(Form(" Unsupported raw version: %d", fRawVersion));
735 fMCM = (*fDataWord & 0xff000000) >> 24;
736 fEv = (*fDataWord & 0x00fffff0) >> 4;
741 fROW = AliTRDfeeParam::Instance()->GetPadRowFromMCM(fROB, fMCM);
743 // AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d"
744 // , *fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv));
746 if ( fROB % 2 == 0 && fSIDE == 1 ) {
747 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
748 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
749 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
750 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
752 if ( fROB % 2 != 0 && fSIDE == 0 ) {
753 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
754 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
755 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
756 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
758 if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
759 (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
760 AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
761 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
762 fRawReader->AddMajorErrorLog(kWrongPadrow,Form("SM%d L%dS%d: Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
763 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
769 fMCMWordCrt = 1; // MCM header
771 // AdcMask for Zero supressed data
772 if ( fRawVersion == 3 )
774 // read one more word
775 if (NextData() != kWordOK)
777 AliWarning("MCM ADC mask missing");
778 fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
779 fNextStatus = kNextHC;
786 for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
787 if ( (*fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
788 else fADCmask[ctr] = kFALSE;
791 //AliDebug(4, Form("0x%08x: ADC mask", *fDataWord));
792 fNActiveADCs = ChannelsToRead(*fDataWord);
796 if (fRawVersion <= 2)
798 // no zero suppression
800 // 1 MCM header + 21 * ( Ntimebin/3)
801 // If NTimebin = 30, it is 211 words.
802 //fMCMWordsExpected = 1 + 21 * (fTBins / 3);
804 fNActiveADCs = ChannelsToRead(0x1fffff); // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
805 //fMCMWordsExpected = 1 + fNActiveADCs * ((fTBins-1) / 3. + 1.);
806 //directly get it like that:
807 fMCMWordsExpected = 1 + fNActiveADCs * fTBins / 3;
810 if (fRawVersion >= 3)
813 // 1 MCM header + 1 ADC mask + NofActiveADCs * ( Ntimebin/3 )
814 //directly get it like that:
815 fMCMWordsExpected = 1 + 1 + (fTBins * fNActiveADCs) / 3;
818 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
820 //____________________________________________________________________________
821 Bool_t AliTRDRawStreamV2::DecodeNextRawWord()
824 // Decode the next raw data word
827 //AliDebug(8, Form("-----------------------------------------"));
828 //AliDebug(8, Form("DATA IS 0x%x", *fDataWord));
830 if (fADClookup[1] - 2 > fADClookup[0])
832 // 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?",
833 // fADClookup[1] - 2, fADClookup[0], fADClookup[fADClookup[1]], *fDataWord));
835 fMCMWordsExpected = 0;
836 AliWarning("Trying to recover. Fall back to DecodeMCM.");
838 //ChangeStatus(kNextMCM);
842 if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
843 AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
844 fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
845 fMCMWordsExpected = 0;
846 AliWarning("Trying to recover. Fall back to DecodeMCM.");
848 //ChangeStatus(kNextMCM);
852 if ( (*fDataWord & 0x3) != fLastADCmask || fTbSwitchCtr > fTimeWords)
854 fADC = fADClookup[fADClookup[1]];
855 // AliDebug(8, Form("Next fADC = %d at index = %d MCM Word Number: %d Max MCM Words is %d",
856 // fADC, fADClookup[1] - 2, fMCMWordCrt, fMCMWordsExpected));
860 fLastStatus = kNextData;
861 fLastADCmask = (*fDataWord) & 0x3;
867 Bool_t kIsDataOK = kFALSE;
869 // We have only 21 ADC channels.
870 if ( fADC > (Int_t)fGeo->ADCmax() - 1 )
872 AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
873 fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
877 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
878 // MCMs and are good for online tracking in the MCM.
879 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax() - 1 )
883 // fCOL = fFee->GetPadColFromADC(fROB, fMCM, fADC);
884 fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fROB, fMCM, fADC);
886 // We have only 144 Pad Columns
887 //if ( fCOL > fColMax-1 || fCOL < 0 )
888 if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax )
890 // Decode 32 bit data words with information from 3 time bins and copy the data
891 fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
892 fSig[1] = (*fDataWord & 0x003ff000) >> 12;
893 fSig[2] = (*fDataWord & 0xffc00000) >> 22;
895 // Print data to screen:
896 //AliDebug(5, Form("DATA : 0x%x", *fDataWord));
897 // AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
898 // fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
903 AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
904 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
905 fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
906 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
912 //AliDebug(5, Form("fADC not accepted %d - DATA : 0x%x", fADC, *fDataWord));
919 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
921 // all mcm data processed go to next one
922 if ( fMCMWordCrt >= fMCMWordsExpected)
924 ChangeStatus(kNextMCM);
930 //____________________________________________________________________________
931 Bool_t AliTRDRawStreamV2::DecodeMCM()
934 // Decode a single MCM
937 if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) )
940 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 )
942 AliWarning("Wrong fMCM or fROB. Skip this data");
943 fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB));
944 ChangeStatus(kNextHC);
948 fTbSwitch = 3; // For first adc channel we expect: (*fDataWord & 3) = 3
950 fADC = fTB = 0; // Reset Counter
951 fLastADCmask = 0; // Reset
953 if (fMCMWordCrt < fMCMWordsExpected)
955 ChangeStatus(kNextData);
959 ChangeStatus(kNextMCM);
964 if ( *fDataWord == fgkEndofrawdatamarker )
965 { // End of half-chamber data, finished
967 ChangeStatus(kNextHC);
968 fEndOfDataFlag = kTRUE;
969 //AliDebug(5, "Expecting MCM header but got End-Of-Raw-Data Marker");
970 if (fMCMWordsExpected == 0 || fMCMWordsExpected == fMCMWordCrt)
974 //AliDebug(5, Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
975 //AliWarning(Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
980 //AliDebug(3, Form("Expecting MCM header but got 0x%x. Going to Next MCM header.", *fDataWord));
981 AliWarning(Form("Expecting MCM header but got 0x%x. Fall back: Next MCM header.", *fDataWord));
982 ChangeStatus(kNextMCM);
987 //____________________________________________________________________________
988 Bool_t AliTRDRawStreamV2::DecodeHC()
991 // Decode a half chamber
994 if ( fNextStatus == kNextHC )
996 //AliDebug(5, "kNextHC");
998 // 1) Find end_of_tracklet_marker
1001 if (DecodeGTUlinkMask())
1006 // endoftrackletmarker?
1007 if ( *fDataWord == fgkEndoftrackletmarker )
1009 //AliDebug(3, "End-of-tracklet-marker found");
1010 //AliDebug(5, Form("Data 0x%x", *fDataWord));
1011 ChangeStatus(kSeekNonEoTracklet);
1017 //AliDebug(3, "Tracklet found");
1018 //AliDebug(5, Form("Tracklet data 0x%x", *fDataWord));
1024 if (fNextStatus == kSeekNonEoTracklet)
1026 //AliDebug(5, "kSeekNonEoTracklet");
1029 // 2) Look for non-end_of_tracklet_marker
1031 //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord);
1033 if ( *fDataWord != fgkEndoftrackletmarker )
1035 ChangeStatus(kDecodeHC);
1036 //AliDebug(3, "NON end-of-tracklet-marker found");
1037 //AliDebug(5, Form("Data 0x%x", *fDataWord));
1038 //// no do not continue - this should be the hcheader
1042 //just go on and find the non-end_of_tracklet_marker
1047 if ( fNextStatus == kDecodeHC )
1049 //AliDebug(5, "kDecodeHC");
1052 // 3) This Word must be Half Chamber Header
1054 if ( (*fDataWord & 0x00000003) == 1 )
1056 DecodeHCheader(fTimeBinsCalib); // This is the new header!
1058 fDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
1059 fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM);
1060 fColMax = fGeo->GetColMax(fROC);
1064 fChamberDone[fDET]++;
1065 //AliDebug(6, Form("-------------- DET %d fChamberDone[fDET]=%d", fDET, fChamberDone[fDET]));
1067 ChangeStatus(kNextMCM);
1072 AliWarning(Form("Expecting HC header mask but got 0x%x. Fall back: Next HC.", *fDataWord));
1073 ChangeStatus(kNextHC);
1074 // before we went to //ChangeStatus(kNextSM);
1081 //____________________________________________________________________________
1082 Bool_t AliTRDRawStreamV2::DecodeGTUlinkMask()
1085 // Decode the link masks sent by the GTU. These marke the active optical links
1086 // between GTU and Super Module. Up to now only fully active links are found
1087 // (0xfff = 12 active links).
1090 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
1092 if ( fRawVersion < 1 || fRawVersion > 3 )
1094 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1097 if ( fGTUctr1 == -1 ) fGTUctr2++;
1100 if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) )
1102 fGTUlinkMask[fGTUctr2][fGTUctr1] = (*fDataWord & 0xfff);
1105 //AliDebug(5, Form("GTU link mask 0x%x decoded 0x%x", *fDataWord, fGTUlinkMask[fGTUctr2][fGTUctr1]));
1112 //____________________________________________________________________________
1113 void AliTRDRawStreamV2::ChangeStatus(Int_t kstat)
1116 // Change the status
1119 fLastStatus = fNextStatus;
1120 fNextStatus = kstat;
1123 //____________________________________________________________________________
1124 Bool_t AliTRDRawStreamV2::DecodeSM()
1127 // Decode a supermodule
1136 // After reading the first word check for size of this data and get Eq. ID
1137 if ( fWordCtr == 1 )
1139 fDataSize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
1140 fEqID = fRawReader->GetEquipmentId(); // Get Equipment ID
1141 if ( fDataSize > 0 ) fSizeOK = kTRUE;
1142 //AliDebug(3, Form("fDataSize=%d fEqID=%d", fDataSize, fEqID));
1146 if ( DecodeGTUlinkMask() )
1148 ChangeStatus(kNextHC);
1153 AliWarning(Form("Equipment %d: First data word is not GTU Link Mask! Fall back: None. Stop.", fEqID));
1154 fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID));
1155 ChangeStatus(kStop);
1161 //____________________________________________________________________________
1162 Bool_t AliTRDRawStreamV2::Next()
1165 // Updates the next data word pointer
1168 if (fNextStatus == kStart)
1173 while (fNextStatus != kStop)
1177 switch (fNextStatus)
1181 if (DecodeNextRawWord() == kTRUE)
1184 if (fSig[0] > fRawDigitThreshold || fSig[1] > fRawDigitThreshold || fSig[2] > fRawDigitThreshold)
1190 if (DecodeMCM() == kFALSE)
1191 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1194 case kSeekNonEoTracklet:
1197 if (DecodeHC() == kFALSE)
1199 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1203 //the hc header should be decoded by now
1204 if (fLastStatus == kDecodeHC)
1207 fChamberDone[fDET]++;
1213 if (DecodeSM() == kFALSE)
1214 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1219 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1220 ChangeStatus(kStop);
1225 //AliDebug(1, Form("That's all folks! %d", fSM));
1229 //____________________________________________________________________________
1230 Int_t AliTRDRawStreamV2::NextChamber(AliTRDdigitsManager *man, UInt_t** /*trackletContainer*/)
1233 // Fills single chamber digit array
1234 // Return value is the detector number
1237 AliTRDarrayADC *digits = 0;
1238 AliTRDarrayDictionary *track0 = 0;
1239 AliTRDarrayDictionary *track1 = 0;
1240 AliTRDarrayDictionary *track2 = 0;
1241 AliTRDSignalIndex *indexes = 0;
1243 if (fNextStatus == kStart)
1248 // while (fNextStatus != kStop)
1251 // // catch 3 things
1252 // // 1) if end of raw data - if chamber complete return
1253 // // 2) fill the data with signals if data decoded ok
1254 // // 3) initialize (destroy old) after the det has changed -> just after HC header decoding
1257 while (fNextStatus != kStop)
1261 switch (fNextStatus)
1266 if (DecodeNextRawWord() == kTRUE)
1268 for (Int_t it = 0; it < 3; it++)
1270 if ( fTB + it < fTBins )
1272 if ( fSig[it] > fRawDigitThreshold )
1274 digits->SetData(fROW, fCOL, fTB + it, fSig[it]);
1275 indexes->AddIndexRC(fROW, fCOL);
1276 if (man->UsesDictionaries())
1278 track0->SetData(fROW, fCOL, fTB + it, 0);
1279 track1->SetData(fROW, fCOL, fTB + it, 0);
1280 track2->SetData(fROW, fCOL, fTB + it, 0);
1281 } // if dictionaries
1282 } // signal above zero
1283 } // check the tbins range
1284 } // for each tbin of current 3
1289 // can be here as a fall back from decode raw data calling decodemcm
1290 if (fEndOfDataFlag == kTRUE)
1292 if (fChamberDone[fDET] == 2)
1296 fEndOfDataFlag = kFALSE;
1303 if (DecodeMCM() == kFALSE)
1305 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1307 // default place for end of raw data...
1308 if (fEndOfDataFlag == kTRUE)
1310 if (fChamberDone[fDET] == 2)
1314 fEndOfDataFlag = kFALSE;
1319 case kSeekNonEoTracklet:
1322 if (DecodeHC() == kFALSE)
1324 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1328 //the hc header should be decoded by now
1329 if (fLastStatus == kDecodeHC)
1331 // AliDebug(4, Form("???? New DET ???? %d last %d", fDET, fLastDET));
1332 // allocate stuff for the new det
1333 //man->ResetArrays();
1334 digits = (AliTRDarrayADC *) man->GetDigits(fDET);
1335 track0 = (AliTRDarrayDictionary *) man->GetDictionary(fDET,0);
1336 track1 = (AliTRDarrayDictionary *) man->GetDictionary(fDET,1);
1337 track2 = (AliTRDarrayDictionary *) man->GetDictionary(fDET,2);
1339 // Allocate memory space for the digits buffer
1340 if (digits->GetNtime() == 0)
1342 // AliDebug(5, Form("Alloc digits for det %d rows %d cols %d tbins %d", fDET, fRowMax, fColMax, fTBins));
1343 digits->Allocate(fRowMax, fColMax, fTBins);
1344 if (man->UsesDictionaries())
1346 track0->Allocate(fRowMax, fColMax, fTBins);
1347 track1->Allocate(fRowMax, fColMax, fTBins);
1348 track2->Allocate(fRowMax, fColMax, fTBins);
1352 indexes = man->GetIndexes(fDET);
1353 indexes->SetSM(fSM);
1354 indexes->SetStack(fSTACK);
1355 indexes->SetLayer(fLAYER);
1356 indexes->SetDetNumber(fDET);
1358 if (indexes->IsAllocated() == kFALSE)
1360 // AliDebug(4, "Allocating indexes");
1361 indexes->Allocate(fRowMax, fColMax, fTBins);
1363 } // is the HC header already decoded?
1369 if (DecodeSM() == kFALSE)
1370 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1377 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1378 ChangeStatus(kStop);
1383 // we do not return chambers for which the end-of-data was not received twice (for each HC)
1385 //AliDebug(1, Form("That's all folks! %d", fSM));
1390 //____________________________________________________________________________
1392 AliTRDRawStreamV2::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
1395 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
1396 for (UInt_t i = 0; i < iw; i++)
1398 if (px + iw >= fpEnd)
1403 if (marker != 0 && marker == px[i])
1404 tsreturn += Form(" *>0x%08x<* ", px[i]);
1406 tsreturn += Form("0x%08x ", px[i]);
1410 AliInfo(tsreturn.Data());