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 "AliTRDdataArrayS.h"
41 #include "AliTRDSignalIndex.h"
43 ClassImp(AliTRDRawStreamV2)
45 //_____________________________________________________________________________
46 AliTRDRawStreamV2::AliTRDRawStreamV2()
96 ,fRawDigitThreshold(0)
120 ,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)
209 // Create an object to read TRD raw digits
212 fRawReader->Select("TRD");
214 for (Int_t i = 0; i < 540; i++) {
220 //_____________________________________________________________________________
221 AliTRDRawStreamV2::AliTRDRawStreamV2(const AliTRDRawStreamV2& stream)
268 ,fMCMWordsExpected(0)
271 ,fRawDigitThreshold(0)
295 ,fEndOfDataFlag(kFALSE)
301 AliFatal("Copy constructor not implemented");
305 //_____________________________________________________________________________
306 AliTRDRawStreamV2& AliTRDRawStreamV2::operator = (const AliTRDRawStreamV2&
310 // Assigment operator
313 Fatal("operator =", "assignment operator not implemented");
318 //_____________________________________________________________________________
319 AliTRDRawStreamV2::~AliTRDRawStreamV2()
331 //_____________________________________________________________________________
332 void AliTRDRawStreamV2::SetRawReader(AliRawReader *rawReader)
340 fRawReader = rawReader;
344 //_____________________________________________________________________________
345 Bool_t AliTRDRawStreamV2::SetRawVersion(Int_t rv)
348 // Set the raw data version
351 if ( rv >= 0 && rv <= 3 ) {
360 //____________________________________________________________________________
361 Int_t AliTRDRawStreamV2::Init()
367 if (!AliTRDcalibDB::Instance()) {
368 AliError("Could not get calibration object");
373 fGeo = new AliTRDgeometry();
376 fTimeBinsCalib = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
377 //AliDebug(2, Form("Number of Timebins read from CDB: %d", fTimeBinsCalib));
379 // The number of data words needed for this number of time bins (there
380 // are 3 time bins in one word)
381 fTimeWords = (fTimeBinsCalib-1)/3 + 1;
386 fHCHctr1 = fHCHctr2 = 0;
387 fGTUctr1 = fGTUctr2 = -1;
399 fLastStatus = kStart;
400 fNextStatus = kStart;
407 fkBufferSet = kFALSE;
410 fMCMWordsExpected = 0;
412 fEndOfDataFlag = kFALSE;
413 // set all ADC active
414 // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
415 fNActiveADCs = ChannelsToRead(0x1fffff);
422 //____________________________________________________________________________
423 void AliTRDRawStreamV2::SwapOnEndian()
426 // Check the endian and swap if needed
430 char* ptemp = (char*) &itemp;
434 // assume we are at the begining of the buffer!
435 //AliDebug(5, "Swapping.");
436 UInt_t *pbegin = (UInt_t*)fPos;
438 for (UInt_t i = 0; i < fBufSize / fgkSizeWord; i++)
440 fDataWord = pbegin + i;
441 iutmp = (((*fDataWord & 0x000000ffU) << 24) | ((*fDataWord & 0x0000ff00U) << 8) |
442 ((*fDataWord & 0x00ff0000U) >> 8) | ((*fDataWord & 0xff000000U) >> 24));
443 // here we override the value in the buffer!
449 //____________________________________________________________________________
450 Int_t AliTRDRawStreamV2::NextData()
453 // Updates the next data word pointer
456 if (fCountBytes + fgkSizeWord >= fBufSize)
458 fkBufferSet = fRawReader->ReadNextData(fPos);
459 if (fkBufferSet == kTRUE)
461 fBufSize = fRawReader->GetDataSize();
463 fDataWord = (UInt_t*)fPos;
465 ChangeStatus(kNextSM);
478 fCountBytes += fgkSizeWord;
479 fDataWord = (UInt_t*)fPos;
485 //============================================================================
486 // Decoding functions
487 //============================================================================
489 //____________________________________________________________________________
490 void AliTRDRawStreamV2::DecodeHCheader(Int_t timeBins)
493 // Decode the HC header (fRawVersion == 2, 3, 4, ???)
496 fRVmajor = (*fDataWord >> 24) & 0x7f;
497 fRVminor = (*fDataWord >> 17) & 0x7f;
499 if (fRVmajor < 2 || fRVmajor > 4)
500 AliError(Form(" Unsupported raw version: %d", fRawVersion))
502 if ( fRawVersion != fRVmajor ) {
504 AliWarning("===============================================================================");
505 AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)"
506 ,fRawVersion,fRVmajor));
507 AliWarning(Form("Setting fRawVersion to %d", fRVmajor));
508 AliWarning("===============================================================================");
509 fRawVersion = fRVmajor;
514 // check for zero suppression
515 if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
516 else fZeroSuppressed = kFALSE;
519 if ( (*fDataWord & 0x3) == 1 ) {
521 fHCHWords = (*fDataWord >> 14) & 0x7;
522 fSM = (*fDataWord >> 9) & 0x1f;
523 fLAYER = (*fDataWord >> 6) & 0x7;
524 fSTACK = (*fDataWord >> 3) & 0x7;
525 fSIDE = (*fDataWord >> 2) & 0x1;
527 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
529 //AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", *fDataWord, fSM, fROC, fSIDE+10));
530 //AliDebug(5, Form("0x%08x: HC header: expecting %d HC words", *fDataWord, fHCHWords));
541 AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
542 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
543 fRawReader->AddMajorErrorLog(kHCHeaderCorrupt,Form("0x%08x:dcs=%d; sm=%d; layer=%d; stack=%d.",
544 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
554 AliWarning(Form("0x%08x: No HC header when it was expected.", *fDataWord));
555 fRawReader->AddMajorErrorLog(kHCHeaderMissing,Form("0x%08x", *fDataWord));
559 if ( fHCHWords >= 1 )
561 // read one more word
562 if (NextData() != kWordOK)
564 AliWarning("Next HC word missing");
565 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
566 fNextStatus = kNextHC;
570 if ( (*fDataWord & 0x3) == 1 )
573 fBCctr = (*fDataWord >> 16);
574 fPTctr = (*fDataWord >> 12) & 0xf;
575 fPTphase = (*fDataWord >> 8) & 0xf;
576 fTBins = ((*fDataWord >> 2) & 0x3f) + 1;
577 fTimeWords = (fTBins - 1)/3 + 1;
579 // AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
580 // , *fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
582 if( fTBins != timeBins )
584 AliWarning("===============================================================================");
585 AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)"
586 , timeBins, fTBins));
587 AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins));
588 AliWarning("===============================================================================");
590 fTimeWords = (fTBins - 1)/3 + 1;
596 if ( fHCHWords >= 2 ) {
597 // read one more word
598 if (NextData() != kWordOK)
600 AliWarning("Next HC word missing");
601 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
602 fNextStatus = kNextHC;
605 if ( (*fDataWord & 0x3) == 1 ) {
607 fTCon = (*fDataWord >> 29) & 0x1;
608 fPEDon = (*fDataWord >> 31) & 0x1;
609 fGAINon = (*fDataWord >> 30) & 0x1;
610 fXTon = (*fDataWord >> 28) & 0x1;
611 fNonLinOn = (*fDataWord >> 27) & 0x1;
612 fBypass = (*fDataWord >> 26) & 0x1;
614 fCommonAdditive = (*fDataWord >> 20) & 0x3f;
616 // AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d"
617 // , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive));
623 //____________________________________________________________________________
624 Int_t AliTRDRawStreamV2::ChannelsToRead(Int_t ADCmask)
627 // Return the channels to read
630 memset(fADClookup, -1, 32 * sizeof(Int_t));
631 fADClookup[0] = 0; // count entries
632 fADClookup[1] = 2; // index - data start at 2
634 for (Int_t i = 0; i < 30; i++)
637 if ((ADCmask & mask))
639 //AliDebug(9, Form("fDataWord=0x%08x mask=0x%08x i=%d", *fDataWord, mask, i));
640 fADClookup[fADClookup[1]] = i;
646 // test the iteration - comment out for production
647 // begin of comment out section
649 sprintf(schannels, "ADC Channels to read: ");
651 while(fADClookup[1] - 2 < fADClookup[0])
653 //AliDebug(9, Form("max=%d index=%d adc=%d", fADClookup[0], fADClookup[1], fADClookup[fADClookup[1]]));
654 strcat(schannels, Form("%d ", fADClookup[fADClookup[1]]));
657 //AliDebug(9, Form("%s", schannels));
658 //AliDebug(9, Form("ADC channels = %d", fADClookup[0]));
659 // end of comment out section
662 return fADClookup[0];
665 //____________________________________________________________________________
666 void AliTRDRawStreamV2::DecodeTracklet()
669 // Decode the Tracklet
671 // this function is not tested yet on real tracklets
674 if ( fRawVersion < 1 || fRawVersion > 3 )
676 AliError(Form(" Unsupported raw version: %d", fRawVersion));
679 fTracklPID = (*fDataWord >> 24) & 0xff;
680 fTracklPadRow = (*fDataWord >> 20) & 0xf; // 0:15
681 fTracklDefL = (*fDataWord >> 13) & 0x7f;
682 fTracklPadPos = (*fDataWord) & 0x1fff;
684 fTracklPID /= (Float_t)((1<<8) - 1); // 0:1 (steps of 0.39%)
685 fTracklDefL = (fTracklDefL - ((1<< 7)-1)/2.) * 140.e-4; // -0.889:0.889cm
686 fTracklPadPos = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm
688 //AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f"
689 // , *fDataWord, fSM, fLAYER, fSTACK, fSIDE+10
690 // , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID));
692 if( (fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0()) ||
693 (fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1()) ) {
694 AliWarning(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow));
695 fRawReader->AddMajorErrorLog(kTrackletRowMismatch,Form("Word: %d", fTracklPadRow));
700 //____________________________________________________________________________
701 void AliTRDRawStreamV2::DecodeMCMheader()
704 // Decode the MCM header
707 if ( fRawVersion < 1 || fRawVersion > 3 )
709 AliError(Form(" Unsupported raw version: %d", fRawVersion));
712 fMCM = (*fDataWord & 0xff000000) >> 24;
713 fEv = (*fDataWord & 0x00fffff0) >> 4;
718 fROW = AliTRDfeeParam::Instance()->GetPadRowFromMCM(fROB, fMCM);
720 // AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d"
721 // , *fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv));
723 if ( fROB % 2 == 0 && fSIDE == 1 ) {
724 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
725 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
726 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
727 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
729 if ( fROB % 2 != 0 && fSIDE == 0 ) {
730 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
731 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
732 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
733 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
735 if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
736 (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
737 AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
738 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
739 fRawReader->AddMajorErrorLog(kWrongPadrow,Form("SM%d L%dS%d: Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
740 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
746 fMCMWordCrt = 1; // MCM header
748 // AdcMask for Zero supressed data
749 if ( fRawVersion == 3 )
751 // read one more word
752 if (NextData() != kWordOK)
754 AliWarning("MCM ADC mask missing");
755 fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
756 fNextStatus = kNextHC;
763 for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
764 if ( (*fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
765 else fADCmask[ctr] = kFALSE;
768 //AliDebug(4, Form("0x%08x: ADC mask", *fDataWord));
769 fNActiveADCs = ChannelsToRead(*fDataWord);
773 if (fRawVersion <= 2)
775 // no zero suppression
777 // 1 MCM header + 21 * ( Ntimebin/3)
778 // If NTimebin = 30, it is 211 words.
779 //fMCMWordsExpected = 1 + 21 * (fTBins / 3);
781 fNActiveADCs = ChannelsToRead(0x1fffff); // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
782 //fMCMWordsExpected = 1 + fNActiveADCs * ((fTBins-1) / 3. + 1.);
783 //directly get it like that:
784 fMCMWordsExpected = 1 + fNActiveADCs * fTBins / 3;
787 if (fRawVersion >= 3)
790 // 1 MCM header + 1 ADC mask + NofActiveADCs * ( Ntimebin/3 )
791 //directly get it like that:
792 fMCMWordsExpected = 1 + 1 + (fTBins * fNActiveADCs) / 3;
795 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
797 //____________________________________________________________________________
798 Bool_t AliTRDRawStreamV2::DecodeNextRawWord()
801 // Decode the next raw data word
804 //AliDebug(8, Form("-----------------------------------------"));
805 //AliDebug(8, Form("DATA IS 0x%x", *fDataWord));
807 if (fADClookup[1] - 2 > fADClookup[0])
809 // 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?",
810 // fADClookup[1] - 2, fADClookup[0], fADClookup[fADClookup[1]], *fDataWord));
812 fMCMWordsExpected = 0;
813 AliWarning("Trying to recover. Fall back to DecodeMCM.");
815 //ChangeStatus(kNextMCM);
819 if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
820 AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
821 fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
822 fMCMWordsExpected = 0;
823 AliWarning("Trying to recover. Fall back to DecodeMCM.");
825 //ChangeStatus(kNextMCM);
829 if ( (*fDataWord & 0x3) != fLastADCmask || fTbSwitchCtr > fTimeWords)
831 fADC = fADClookup[fADClookup[1]];
832 // AliDebug(8, Form("Next fADC = %d at index = %d MCM Word Number: %d Max MCM Words is %d",
833 // fADC, fADClookup[1] - 2, fMCMWordCrt, fMCMWordsExpected));
837 fLastStatus = kNextData;
838 fLastADCmask = (*fDataWord) & 0x3;
844 Bool_t kIsDataOK = kFALSE;
846 // We have only 21 ADC channels.
847 if ( fADC > (Int_t)fGeo->ADCmax() - 1 )
849 AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
850 fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
854 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
855 // MCMs and are good for online tracking in the MCM.
856 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax() - 1 )
860 // fCOL = fFee->GetPadColFromADC(fROB, fMCM, fADC);
861 fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fROB, fMCM, fADC);
863 // We have only 144 Pad Columns
864 //if ( fCOL > fColMax-1 || fCOL < 0 )
865 if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax )
867 // Decode 32 bit data words with information from 3 time bins and copy the data
868 fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
869 fSig[1] = (*fDataWord & 0x003ff000) >> 12;
870 fSig[2] = (*fDataWord & 0xffc00000) >> 22;
872 // Print data to screen:
873 //AliDebug(5, Form("DATA : 0x%x", *fDataWord));
874 // AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
875 // fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
880 AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
881 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
882 fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
883 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
889 //AliDebug(5, Form("fADC not accepted %d - DATA : 0x%x", fADC, *fDataWord));
896 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
898 // all mcm data processed go to next one
899 if ( fMCMWordCrt >= fMCMWordsExpected)
901 ChangeStatus(kNextMCM);
907 //____________________________________________________________________________
908 Bool_t AliTRDRawStreamV2::DecodeMCM()
911 // Decode a single MCM
914 if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) )
917 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 )
919 AliWarning("Wrong fMCM or fROB. Skip this data");
920 fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB));
921 ChangeStatus(kNextHC);
925 fTbSwitch = 3; // For first adc channel we expect: (*fDataWord & 3) = 3
927 fADC = fTB = 0; // Reset Counter
928 fLastADCmask = 0; // Reset
930 if (fMCMWordCrt < fMCMWordsExpected)
932 ChangeStatus(kNextData);
936 ChangeStatus(kNextMCM);
941 if ( *fDataWord == fgkEndofrawdatamarker )
942 { // End of half-chamber data, finished
944 ChangeStatus(kNextHC);
945 fEndOfDataFlag = kTRUE;
946 //AliDebug(5, "Expecting MCM header but got End-Of-Raw-Data Marker");
947 if (fMCMWordsExpected == 0 || fMCMWordsExpected == fMCMWordCrt)
951 //AliDebug(5, Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
952 //AliWarning(Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
957 //AliDebug(3, Form("Expecting MCM header but got 0x%x. Going to Next MCM header.", *fDataWord));
958 AliWarning(Form("Expecting MCM header but got 0x%x. Fall back: Next MCM header.", *fDataWord));
959 ChangeStatus(kNextMCM);
964 //____________________________________________________________________________
965 Bool_t AliTRDRawStreamV2::DecodeHC()
968 // Decode a half chamber
971 if ( fNextStatus == kNextHC )
973 //AliDebug(5, "kNextHC");
975 // 1) Find end_of_tracklet_marker
978 if (DecodeGTUlinkMask())
983 // endoftrackletmarker?
984 if ( *fDataWord == fgkEndoftrackletmarker )
986 //AliDebug(3, "End-of-tracklet-marker found");
987 //AliDebug(5, Form("Data 0x%x", *fDataWord));
988 ChangeStatus(kSeekNonEoTracklet);
994 //AliDebug(3, "Tracklet found");
995 //AliDebug(5, Form("Tracklet data 0x%x", *fDataWord));
1001 if (fNextStatus == kSeekNonEoTracklet)
1003 //AliDebug(5, "kSeekNonEoTracklet");
1006 // 2) Look for non-end_of_tracklet_marker
1008 //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord);
1010 if ( *fDataWord != fgkEndoftrackletmarker )
1012 ChangeStatus(kDecodeHC);
1013 //AliDebug(3, "NON end-of-tracklet-marker found");
1014 //AliDebug(5, Form("Data 0x%x", *fDataWord));
1015 //// no do not continue - this should be the hcheader
1019 //just go on and find the non-end_of_tracklet_marker
1024 if ( fNextStatus == kDecodeHC )
1026 //AliDebug(5, "kDecodeHC");
1029 // 3) This Word must be Half Chamber Header
1031 if ( (*fDataWord & 0x00000003) == 1 )
1033 DecodeHCheader(fTimeBinsCalib); // This is the new header!
1035 fDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
1036 fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM);
1037 fColMax = fGeo->GetColMax(fROC);
1041 fChamberDone[fDET]++;
1042 //AliDebug(6, Form("-------------- DET %d fChamberDone[fDET]=%d", fDET, fChamberDone[fDET]));
1044 ChangeStatus(kNextMCM);
1049 AliWarning(Form("Expecting HC header mask but got 0x%x. Fall back: Next HC.", *fDataWord));
1050 ChangeStatus(kNextHC);
1051 // before we went to //ChangeStatus(kNextSM);
1058 //____________________________________________________________________________
1059 Bool_t AliTRDRawStreamV2::DecodeGTUlinkMask()
1062 // Decode the link masks sent by the GTU. These marke the active optical links
1063 // between GTU and Super Module. Up to now only fully active links are found
1064 // (0xfff = 12 active links).
1067 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
1069 if ( fRawVersion < 1 || fRawVersion > 3 )
1071 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1074 if ( fGTUctr1 == -1 ) fGTUctr2++;
1077 if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) )
1079 fGTUlinkMask[fGTUctr2][fGTUctr1] = (*fDataWord & 0xfff);
1082 //AliDebug(5, Form("GTU link mask 0x%x decoded 0x%x", *fDataWord, fGTUlinkMask[fGTUctr2][fGTUctr1]));
1089 //____________________________________________________________________________
1090 void AliTRDRawStreamV2::ChangeStatus(Int_t kstat)
1093 // Change the status
1096 fLastStatus = fNextStatus;
1097 fNextStatus = kstat;
1100 //____________________________________________________________________________
1101 Bool_t AliTRDRawStreamV2::DecodeSM()
1104 // Decode a supermodule
1113 // After reading the first word check for size of this data and get Eq. ID
1114 if ( fWordCtr == 1 )
1116 fDataSize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
1117 fEqID = fRawReader->GetEquipmentId(); // Get Equipment ID
1118 if ( fDataSize > 0 ) fSizeOK = kTRUE;
1119 //AliDebug(3, Form("fDataSize=%d fEqID=%d", fDataSize, fEqID));
1123 if ( DecodeGTUlinkMask() )
1125 ChangeStatus(kNextHC);
1130 AliWarning(Form("Equipment %d: First data word is not GTU Link Mask! Fall back: None. Stop.", fEqID));
1131 fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID));
1132 ChangeStatus(kStop);
1138 //____________________________________________________________________________
1139 Bool_t AliTRDRawStreamV2::Next()
1142 // Updates the next data word pointer
1145 if (fNextStatus == kStart)
1150 while (fNextStatus != kStop)
1154 switch (fNextStatus)
1158 if (DecodeNextRawWord() == kTRUE)
1161 if (fSig[0] > fRawDigitThreshold || fSig[1] > fRawDigitThreshold || fSig[2] > fRawDigitThreshold)
1167 if (DecodeMCM() == kFALSE)
1168 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1171 case kSeekNonEoTracklet:
1174 if (DecodeHC() == kFALSE)
1176 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1180 //the hc header should be decoded by now
1181 if (fLastStatus == kDecodeHC)
1184 fChamberDone[fDET]++;
1190 if (DecodeSM() == kFALSE)
1191 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1196 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1197 ChangeStatus(kStop);
1202 //AliDebug(1, Form("That's all folks! %d", fSM));
1206 //____________________________________________________________________________
1207 Int_t AliTRDRawStreamV2::NextChamber(AliTRDdigitsManager *man)
1210 // Fills single chamber digit array
1211 // Return value is the detector number
1214 AliTRDdataArrayS *digits = 0;
1215 AliTRDdataArrayI *track0 = 0;
1216 AliTRDdataArrayI *track1 = 0;
1217 AliTRDdataArrayI *track2 = 0;
1218 AliTRDSignalIndex *indexes = 0;
1220 if (fNextStatus == kStart)
1225 // while (fNextStatus != kStop)
1228 // // catch 3 things
1229 // // 1) if end of raw data - if chamber complete return
1230 // // 2) fill the data with signals if data decoded ok
1231 // // 3) initialize (destroy old) after the det has changed -> just after HC header decoding
1234 while (fNextStatus != kStop)
1238 switch (fNextStatus)
1243 if (DecodeNextRawWord() == kTRUE)
1245 for (Int_t it = 0; it < 3; it++)
1247 if ( fTB + it < fTBins )
1249 if ( fSig[it] > fRawDigitThreshold )
1251 digits->SetDataUnchecked(fROW, fCOL, fTB + it, fSig[it]);
1252 indexes->AddIndexTBin(fROW, fCOL, fTB + it);
1253 if (man->UsesDictionaries())
1255 track0->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1256 track1->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1257 track2->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1258 } // if dictionaries
1259 } // signal above zero
1260 } // check the tbins range
1261 } // for each tbin of current 3
1266 // can be here as a fall back from decode raw data calling decodemcm
1267 if (fEndOfDataFlag == kTRUE)
1269 if (fChamberDone[fDET] == 2)
1273 fEndOfDataFlag = kFALSE;
1280 if (DecodeMCM() == kFALSE)
1282 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1284 // default place for end of raw data...
1285 if (fEndOfDataFlag == kTRUE)
1287 if (fChamberDone[fDET] == 2)
1291 fEndOfDataFlag = kFALSE;
1296 case kSeekNonEoTracklet:
1299 if (DecodeHC() == kFALSE)
1301 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1305 //the hc header should be decoded by now
1306 if (fLastStatus == kDecodeHC)
1308 // AliDebug(4, Form("???? New DET ???? %d last %d", fDET, fLastDET));
1309 // allocate stuff for the new det
1310 //man->ResetArrays();
1311 digits = (AliTRDdataArrayS *) man->GetDigits(fDET);
1312 track0 = (AliTRDdataArrayI *) man->GetDictionary(fDET,0);
1313 track1 = (AliTRDdataArrayI *) man->GetDictionary(fDET,1);
1314 track2 = (AliTRDdataArrayI *) man->GetDictionary(fDET,2);
1316 // Allocate memory space for the digits buffer
1317 if (digits->GetNtime() == 0)
1319 // AliDebug(5, Form("Alloc digits for det %d rows %d cols %d tbins %d", fDET, fRowMax, fColMax, fTBins));
1320 digits->Allocate(fRowMax, fColMax, fTBins);
1321 if (man->UsesDictionaries())
1323 track0->Allocate(fRowMax, fColMax, fTBins);
1324 track1->Allocate(fRowMax, fColMax, fTBins);
1325 track2->Allocate(fRowMax, fColMax, fTBins);
1329 indexes = man->GetIndexes(fDET);
1330 indexes->SetSM(fSM);
1331 indexes->SetStack(fSTACK);
1332 indexes->SetLayer(fLAYER);
1333 indexes->SetDetNumber(fDET);
1335 if (indexes->IsAllocated() == kFALSE)
1337 // AliDebug(4, "Allocating indexes");
1338 indexes->Allocate(fRowMax, fColMax, fTBins);
1340 } // is the HC header already decoded?
1346 if (DecodeSM() == kFALSE)
1347 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1354 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1355 ChangeStatus(kStop);
1360 // we do not return chambers for which the end-of-data was not received twice (for each HC)
1362 //AliDebug(1, Form("That's all folks! %d", fSM));