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()
47 :AliTRDrawStreamBase()
97 ,fRawDigitThreshold(0)
121 ,fEndOfDataFlag(kFALSE)
124 // Default constructor
127 for (Int_t i = 0; i < 540; i++) {
133 //_____________________________________________________________________________
134 AliTRDRawStreamV2::AliTRDRawStreamV2(AliRawReader *rawReader)
135 :AliTRDrawStreamBase(rawReader)
181 ,fMCMWordsExpected(0)
182 ,fRawReader(rawReader)
184 ,fRawDigitThreshold(0)
208 ,fEndOfDataFlag(kFALSE)
211 // Create an object to read TRD raw digits
214 fRawReader->Select("TRD");
216 for (Int_t i = 0; i < 540; i++) {
222 //_____________________________________________________________________________
223 AliTRDRawStreamV2::AliTRDRawStreamV2(const AliTRDRawStreamV2& stream)
224 :AliTRDrawStreamBase(stream)
271 ,fMCMWordsExpected(0)
274 ,fRawDigitThreshold(0)
298 ,fEndOfDataFlag(kFALSE)
304 AliFatal("Copy constructor not implemented");
308 //_____________________________________________________________________________
309 AliTRDRawStreamV2& AliTRDRawStreamV2::operator = (const AliTRDRawStreamV2&
313 // Assigment operator
316 Fatal("operator =", "assignment operator not implemented");
321 //_____________________________________________________________________________
322 AliTRDRawStreamV2::~AliTRDRawStreamV2()
334 //_____________________________________________________________________________
335 void AliTRDRawStreamV2::SetRawReader(AliRawReader *rawReader)
343 fRawReader = rawReader;
347 //_____________________________________________________________________________
348 Bool_t AliTRDRawStreamV2::SetRawVersion(Int_t rv)
351 // Set the raw data version
354 if ( rv >= 0 && rv <= 3 ) {
363 //____________________________________________________________________________
364 Bool_t AliTRDRawStreamV2::Init()
370 if (!AliTRDcalibDB::Instance()) {
371 AliError("Could not get calibration object");
376 fGeo = new AliTRDgeometry();
379 fTimeBinsCalib = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
380 //AliDebug(2, Form("Number of Timebins read from CDB: %d", fTimeBinsCalib));
382 // The number of data words needed for this number of time bins (there
383 // are 3 time bins in one word)
384 fTimeWords = (fTimeBinsCalib-1)/3 + 1;
389 fHCHctr1 = fHCHctr2 = 0;
390 fGTUctr1 = fGTUctr2 = -1;
402 fLastStatus = kStart;
403 fNextStatus = kStart;
410 fkBufferSet = kFALSE;
413 fMCMWordsExpected = 0;
415 fEndOfDataFlag = kFALSE;
416 // set all ADC active
417 // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
418 fNActiveADCs = ChannelsToRead(0x1fffff);
425 //____________________________________________________________________________
426 void AliTRDRawStreamV2::SwapOnEndian()
429 // Check the endian and swap if needed
433 char* ptemp = (char*) &itemp;
437 // assume we are at the begining of the buffer!
438 //AliDebug(5, "Swapping.");
439 UInt_t *pbegin = (UInt_t*)fPos;
441 for (UInt_t i = 0; i < fBufSize / fgkSizeWord; i++)
443 fDataWord = pbegin + i;
444 iutmp = (((*fDataWord & 0x000000ffU) << 24) | ((*fDataWord & 0x0000ff00U) << 8) |
445 ((*fDataWord & 0x00ff0000U) >> 8) | ((*fDataWord & 0xff000000U) >> 24));
446 // here we override the value in the buffer!
452 //____________________________________________________________________________
453 Int_t AliTRDRawStreamV2::NextData()
456 // Updates the next data word pointer
459 if (fCountBytes + fgkSizeWord >= fBufSize)
461 fkBufferSet = fRawReader->ReadNextData(fPos);
462 if (fkBufferSet == kTRUE)
464 fBufSize = fRawReader->GetDataSize();
466 fDataWord = (UInt_t*)fPos;
468 ChangeStatus(kNextSM);
481 fCountBytes += fgkSizeWord;
482 fDataWord = (UInt_t*)fPos;
488 //============================================================================
489 // Decoding functions
490 //============================================================================
492 //____________________________________________________________________________
493 void AliTRDRawStreamV2::DecodeHCheader(Int_t timeBins)
496 // Decode the HC header (fRawVersion == 2, 3, 4, ???)
499 fRVmajor = (*fDataWord >> 24) & 0x7f;
500 fRVminor = (*fDataWord >> 17) & 0x7f;
502 if (fRVmajor < 2 || fRVmajor > 4)
503 AliError(Form(" Unsupported raw version: %d", fRawVersion))
505 if ( fRawVersion != fRVmajor ) {
507 AliWarning("===============================================================================");
508 AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)"
509 ,fRawVersion,fRVmajor));
510 AliWarning(Form("Setting fRawVersion to %d", fRVmajor));
511 AliWarning("===============================================================================");
512 fRawVersion = fRVmajor;
517 // check for zero suppression
518 if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
519 else fZeroSuppressed = kFALSE;
522 if ( (*fDataWord & 0x3) == 1 ) {
524 fHCHWords = (*fDataWord >> 14) & 0x7;
525 fSM = (*fDataWord >> 9) & 0x1f;
526 fLAYER = (*fDataWord >> 6) & 0x7;
527 fSTACK = (*fDataWord >> 3) & 0x7;
528 fSIDE = (*fDataWord >> 2) & 0x1;
530 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
532 //AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", *fDataWord, fSM, fROC, fSIDE+10));
533 //AliDebug(5, Form("0x%08x: HC header: expecting %d HC words", *fDataWord, fHCHWords));
544 AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
545 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
546 fRawReader->AddMajorErrorLog(kHCHeaderCorrupt,Form("0x%08x:dcs=%d; sm=%d; layer=%d; stack=%d.",
547 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
557 AliWarning(Form("0x%08x: No HC header when it was expected.", *fDataWord));
558 fRawReader->AddMajorErrorLog(kHCHeaderMissing,Form("0x%08x", *fDataWord));
562 if ( fHCHWords >= 1 )
564 // read one more word
565 if (NextData() != kWordOK)
567 AliWarning("Next HC word missing");
568 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
569 fNextStatus = kNextHC;
573 if ( (*fDataWord & 0x3) == 1 )
576 fBCctr = (*fDataWord >> 16);
577 fPTctr = (*fDataWord >> 12) & 0xf;
578 fPTphase = (*fDataWord >> 8) & 0xf;
579 fTBins = ((*fDataWord >> 2) & 0x3f) + 1;
580 fTimeWords = (fTBins - 1)/3 + 1;
582 // AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
583 // , *fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
585 if( fTBins != timeBins )
587 AliWarning("===============================================================================");
588 AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)"
589 , timeBins, fTBins));
590 AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins));
591 AliWarning("===============================================================================");
593 fTimeWords = (fTBins - 1)/3 + 1;
599 if ( fHCHWords >= 2 ) {
600 // read one more word
601 if (NextData() != kWordOK)
603 AliWarning("Next HC word missing");
604 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
605 fNextStatus = kNextHC;
608 if ( (*fDataWord & 0x3) == 1 ) {
610 fTCon = (*fDataWord >> 29) & 0x1;
611 fPEDon = (*fDataWord >> 31) & 0x1;
612 fGAINon = (*fDataWord >> 30) & 0x1;
613 fXTon = (*fDataWord >> 28) & 0x1;
614 fNonLinOn = (*fDataWord >> 27) & 0x1;
615 fBypass = (*fDataWord >> 26) & 0x1;
617 fCommonAdditive = (*fDataWord >> 20) & 0x3f;
619 // AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d"
620 // , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive));
626 //____________________________________________________________________________
627 Int_t AliTRDRawStreamV2::ChannelsToRead(Int_t ADCmask)
630 // Return the channels to read
633 memset(fADClookup, -1, 32 * sizeof(Int_t));
634 fADClookup[0] = 0; // count entries
635 fADClookup[1] = 2; // index - data start at 2
637 for (Int_t i = 0; i < 30; i++)
640 if ((ADCmask & mask))
642 //AliDebug(9, Form("fDataWord=0x%08x mask=0x%08x i=%d", *fDataWord, mask, i));
643 fADClookup[fADClookup[1]] = i;
649 // test the iteration - comment out for production
650 // begin of comment out section
652 sprintf(schannels, "ADC Channels to read: ");
654 while(fADClookup[1] - 2 < fADClookup[0])
656 //AliDebug(9, Form("max=%d index=%d adc=%d", fADClookup[0], fADClookup[1], fADClookup[fADClookup[1]]));
657 strcat(schannels, Form("%d ", fADClookup[fADClookup[1]]));
660 //AliDebug(9, Form("%s", schannels));
661 //AliDebug(9, Form("ADC channels = %d", fADClookup[0]));
662 // end of comment out section
665 return fADClookup[0];
668 //____________________________________________________________________________
669 void AliTRDRawStreamV2::DecodeTracklet()
672 // Decode the Tracklet
674 // this function is not tested yet on real tracklets
677 if ( fRawVersion < 1 || fRawVersion > 3 )
679 AliError(Form(" Unsupported raw version: %d", fRawVersion));
682 fTracklPID = (*fDataWord >> 24) & 0xff;
683 fTracklPadRow = (*fDataWord >> 20) & 0xf; // 0:15
684 fTracklDefL = (*fDataWord >> 13) & 0x7f;
685 fTracklPadPos = (*fDataWord) & 0x1fff;
687 fTracklPID /= (Float_t)((1<<8) - 1); // 0:1 (steps of 0.39%)
688 fTracklDefL = (fTracklDefL - ((1<< 7)-1)/2.) * 140.e-4; // -0.889:0.889cm
689 fTracklPadPos = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm
691 //AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f"
692 // , *fDataWord, fSM, fLAYER, fSTACK, fSIDE+10
693 // , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID));
695 if( (fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0()) ||
696 (fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1()) ) {
697 AliWarning(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow));
698 fRawReader->AddMajorErrorLog(kTrackletRowMismatch,Form("Word: %d", fTracklPadRow));
703 //____________________________________________________________________________
704 void AliTRDRawStreamV2::DecodeMCMheader()
707 // Decode the MCM header
710 if ( fRawVersion < 1 || fRawVersion > 3 )
712 AliError(Form(" Unsupported raw version: %d", fRawVersion));
715 fMCM = (*fDataWord & 0xff000000) >> 24;
716 fEv = (*fDataWord & 0x00fffff0) >> 4;
721 fROW = AliTRDfeeParam::Instance()->GetPadRowFromMCM(fROB, fMCM);
723 // AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d"
724 // , *fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv));
726 if ( fROB % 2 == 0 && fSIDE == 1 ) {
727 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
728 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
729 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
730 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
732 if ( fROB % 2 != 0 && fSIDE == 0 ) {
733 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
734 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
735 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
736 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
738 if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
739 (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
740 AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
741 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
742 fRawReader->AddMajorErrorLog(kWrongPadrow,Form("SM%d L%dS%d: Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
743 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
749 fMCMWordCrt = 1; // MCM header
751 // AdcMask for Zero supressed data
752 if ( fRawVersion == 3 )
754 // read one more word
755 if (NextData() != kWordOK)
757 AliWarning("MCM ADC mask missing");
758 fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
759 fNextStatus = kNextHC;
766 for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
767 if ( (*fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
768 else fADCmask[ctr] = kFALSE;
771 //AliDebug(4, Form("0x%08x: ADC mask", *fDataWord));
772 fNActiveADCs = ChannelsToRead(*fDataWord);
776 if (fRawVersion <= 2)
778 // no zero suppression
780 // 1 MCM header + 21 * ( Ntimebin/3)
781 // If NTimebin = 30, it is 211 words.
782 //fMCMWordsExpected = 1 + 21 * (fTBins / 3);
784 fNActiveADCs = ChannelsToRead(0x1fffff); // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
785 //fMCMWordsExpected = 1 + fNActiveADCs * ((fTBins-1) / 3. + 1.);
786 //directly get it like that:
787 fMCMWordsExpected = 1 + fNActiveADCs * fTBins / 3;
790 if (fRawVersion >= 3)
793 // 1 MCM header + 1 ADC mask + NofActiveADCs * ( Ntimebin/3 )
794 //directly get it like that:
795 fMCMWordsExpected = 1 + 1 + (fTBins * fNActiveADCs) / 3;
798 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
800 //____________________________________________________________________________
801 Bool_t AliTRDRawStreamV2::DecodeNextRawWord()
804 // Decode the next raw data word
807 //AliDebug(8, Form("-----------------------------------------"));
808 //AliDebug(8, Form("DATA IS 0x%x", *fDataWord));
810 if (fADClookup[1] - 2 > fADClookup[0])
812 // 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?",
813 // fADClookup[1] - 2, fADClookup[0], fADClookup[fADClookup[1]], *fDataWord));
815 fMCMWordsExpected = 0;
816 AliWarning("Trying to recover. Fall back to DecodeMCM.");
818 //ChangeStatus(kNextMCM);
822 if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
823 AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
824 fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
825 fMCMWordsExpected = 0;
826 AliWarning("Trying to recover. Fall back to DecodeMCM.");
828 //ChangeStatus(kNextMCM);
832 if ( (*fDataWord & 0x3) != fLastADCmask || fTbSwitchCtr > fTimeWords)
834 fADC = fADClookup[fADClookup[1]];
835 // AliDebug(8, Form("Next fADC = %d at index = %d MCM Word Number: %d Max MCM Words is %d",
836 // fADC, fADClookup[1] - 2, fMCMWordCrt, fMCMWordsExpected));
840 fLastStatus = kNextData;
841 fLastADCmask = (*fDataWord) & 0x3;
847 Bool_t kIsDataOK = kFALSE;
849 // We have only 21 ADC channels.
850 if ( fADC > (Int_t)fGeo->ADCmax() - 1 )
852 AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
853 fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
857 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
858 // MCMs and are good for online tracking in the MCM.
859 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax() - 1 )
863 // fCOL = fFee->GetPadColFromADC(fROB, fMCM, fADC);
864 fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fROB, fMCM, fADC);
866 // We have only 144 Pad Columns
867 //if ( fCOL > fColMax-1 || fCOL < 0 )
868 if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax )
870 // Decode 32 bit data words with information from 3 time bins and copy the data
871 fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
872 fSig[1] = (*fDataWord & 0x003ff000) >> 12;
873 fSig[2] = (*fDataWord & 0xffc00000) >> 22;
875 // Print data to screen:
876 //AliDebug(5, Form("DATA : 0x%x", *fDataWord));
877 // AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
878 // fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
883 AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
884 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
885 fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
886 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
892 //AliDebug(5, Form("fADC not accepted %d - DATA : 0x%x", fADC, *fDataWord));
899 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
901 // all mcm data processed go to next one
902 if ( fMCMWordCrt >= fMCMWordsExpected)
904 ChangeStatus(kNextMCM);
910 //____________________________________________________________________________
911 Bool_t AliTRDRawStreamV2::DecodeMCM()
914 // Decode a single MCM
917 if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) )
920 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 )
922 AliWarning("Wrong fMCM or fROB. Skip this data");
923 fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB));
924 ChangeStatus(kNextHC);
928 fTbSwitch = 3; // For first adc channel we expect: (*fDataWord & 3) = 3
930 fADC = fTB = 0; // Reset Counter
931 fLastADCmask = 0; // Reset
933 if (fMCMWordCrt < fMCMWordsExpected)
935 ChangeStatus(kNextData);
939 ChangeStatus(kNextMCM);
944 if ( *fDataWord == fgkEndofrawdatamarker )
945 { // End of half-chamber data, finished
947 ChangeStatus(kNextHC);
948 fEndOfDataFlag = kTRUE;
949 //AliDebug(5, "Expecting MCM header but got End-Of-Raw-Data Marker");
950 if (fMCMWordsExpected == 0 || fMCMWordsExpected == fMCMWordCrt)
954 //AliDebug(5, Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
955 //AliWarning(Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
960 //AliDebug(3, Form("Expecting MCM header but got 0x%x. Going to Next MCM header.", *fDataWord));
961 AliWarning(Form("Expecting MCM header but got 0x%x. Fall back: Next MCM header.", *fDataWord));
962 ChangeStatus(kNextMCM);
967 //____________________________________________________________________________
968 Bool_t AliTRDRawStreamV2::DecodeHC()
971 // Decode a half chamber
974 if ( fNextStatus == kNextHC )
976 //AliDebug(5, "kNextHC");
978 // 1) Find end_of_tracklet_marker
981 if (DecodeGTUlinkMask())
986 // endoftrackletmarker?
987 if ( *fDataWord == fgkEndoftrackletmarker )
989 //AliDebug(3, "End-of-tracklet-marker found");
990 //AliDebug(5, Form("Data 0x%x", *fDataWord));
991 ChangeStatus(kSeekNonEoTracklet);
997 //AliDebug(3, "Tracklet found");
998 //AliDebug(5, Form("Tracklet data 0x%x", *fDataWord));
1004 if (fNextStatus == kSeekNonEoTracklet)
1006 //AliDebug(5, "kSeekNonEoTracklet");
1009 // 2) Look for non-end_of_tracklet_marker
1011 //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord);
1013 if ( *fDataWord != fgkEndoftrackletmarker )
1015 ChangeStatus(kDecodeHC);
1016 //AliDebug(3, "NON end-of-tracklet-marker found");
1017 //AliDebug(5, Form("Data 0x%x", *fDataWord));
1018 //// no do not continue - this should be the hcheader
1022 //just go on and find the non-end_of_tracklet_marker
1027 if ( fNextStatus == kDecodeHC )
1029 //AliDebug(5, "kDecodeHC");
1032 // 3) This Word must be Half Chamber Header
1034 if ( (*fDataWord & 0x00000003) == 1 )
1036 DecodeHCheader(fTimeBinsCalib); // This is the new header!
1038 fDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
1039 fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM);
1040 fColMax = fGeo->GetColMax(fROC);
1044 fChamberDone[fDET]++;
1045 //AliDebug(6, Form("-------------- DET %d fChamberDone[fDET]=%d", fDET, fChamberDone[fDET]));
1047 ChangeStatus(kNextMCM);
1052 AliWarning(Form("Expecting HC header mask but got 0x%x. Fall back: Next HC.", *fDataWord));
1053 ChangeStatus(kNextHC);
1054 // before we went to //ChangeStatus(kNextSM);
1061 //____________________________________________________________________________
1062 Bool_t AliTRDRawStreamV2::DecodeGTUlinkMask()
1065 // Decode the link masks sent by the GTU. These marke the active optical links
1066 // between GTU and Super Module. Up to now only fully active links are found
1067 // (0xfff = 12 active links).
1070 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
1072 if ( fRawVersion < 1 || fRawVersion > 3 )
1074 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1077 if ( fGTUctr1 == -1 ) fGTUctr2++;
1080 if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) )
1082 fGTUlinkMask[fGTUctr2][fGTUctr1] = (*fDataWord & 0xfff);
1085 //AliDebug(5, Form("GTU link mask 0x%x decoded 0x%x", *fDataWord, fGTUlinkMask[fGTUctr2][fGTUctr1]));
1092 //____________________________________________________________________________
1093 void AliTRDRawStreamV2::ChangeStatus(Int_t kstat)
1096 // Change the status
1099 fLastStatus = fNextStatus;
1100 fNextStatus = kstat;
1103 //____________________________________________________________________________
1104 Bool_t AliTRDRawStreamV2::DecodeSM()
1107 // Decode a supermodule
1116 // After reading the first word check for size of this data and get Eq. ID
1117 if ( fWordCtr == 1 )
1119 fDataSize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
1120 fEqID = fRawReader->GetEquipmentId(); // Get Equipment ID
1121 if ( fDataSize > 0 ) fSizeOK = kTRUE;
1122 //AliDebug(3, Form("fDataSize=%d fEqID=%d", fDataSize, fEqID));
1126 if ( DecodeGTUlinkMask() )
1128 ChangeStatus(kNextHC);
1133 AliWarning(Form("Equipment %d: First data word is not GTU Link Mask! Fall back: None. Stop.", fEqID));
1134 fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID));
1135 ChangeStatus(kStop);
1141 //____________________________________________________________________________
1142 Bool_t AliTRDRawStreamV2::Next()
1145 // Updates the next data word pointer
1148 if (fNextStatus == kStart)
1153 while (fNextStatus != kStop)
1157 switch (fNextStatus)
1161 if (DecodeNextRawWord() == kTRUE)
1164 if (fSig[0] > fRawDigitThreshold || fSig[1] > fRawDigitThreshold || fSig[2] > fRawDigitThreshold)
1170 if (DecodeMCM() == kFALSE)
1171 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1174 case kSeekNonEoTracklet:
1177 if (DecodeHC() == kFALSE)
1179 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1183 //the hc header should be decoded by now
1184 if (fLastStatus == kDecodeHC)
1187 fChamberDone[fDET]++;
1193 if (DecodeSM() == kFALSE)
1194 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1199 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1200 ChangeStatus(kStop);
1205 //AliDebug(1, Form("That's all folks! %d", fSM));
1209 //____________________________________________________________________________
1210 Int_t AliTRDRawStreamV2::NextChamber(AliTRDdigitsManager *man)
1213 // Fills single chamber digit array
1214 // Return value is the detector number
1217 AliTRDdataArrayS *digits = 0;
1218 AliTRDdataArrayI *track0 = 0;
1219 AliTRDdataArrayI *track1 = 0;
1220 AliTRDdataArrayI *track2 = 0;
1221 AliTRDSignalIndex *indexes = 0;
1223 if (fNextStatus == kStart)
1228 // while (fNextStatus != kStop)
1231 // // catch 3 things
1232 // // 1) if end of raw data - if chamber complete return
1233 // // 2) fill the data with signals if data decoded ok
1234 // // 3) initialize (destroy old) after the det has changed -> just after HC header decoding
1237 while (fNextStatus != kStop)
1241 switch (fNextStatus)
1246 if (DecodeNextRawWord() == kTRUE)
1248 for (Int_t it = 0; it < 3; it++)
1250 if ( fTB + it < fTBins )
1252 if ( fSig[it] > fRawDigitThreshold )
1254 digits->SetDataUnchecked(fROW, fCOL, fTB + it, fSig[it]);
1255 indexes->AddIndexTBin(fROW, fCOL, fTB + it);
1256 if (man->UsesDictionaries())
1258 track0->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1259 track1->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1260 track2->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1261 } // if dictionaries
1262 } // signal above zero
1263 } // check the tbins range
1264 } // for each tbin of current 3
1269 // can be here as a fall back from decode raw data calling decodemcm
1270 if (fEndOfDataFlag == kTRUE)
1272 if (fChamberDone[fDET] == 2)
1276 fEndOfDataFlag = kFALSE;
1283 if (DecodeMCM() == kFALSE)
1285 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1287 // default place for end of raw data...
1288 if (fEndOfDataFlag == kTRUE)
1290 if (fChamberDone[fDET] == 2)
1294 fEndOfDataFlag = kFALSE;
1299 case kSeekNonEoTracklet:
1302 if (DecodeHC() == kFALSE)
1304 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1308 //the hc header should be decoded by now
1309 if (fLastStatus == kDecodeHC)
1311 // AliDebug(4, Form("???? New DET ???? %d last %d", fDET, fLastDET));
1312 // allocate stuff for the new det
1313 //man->ResetArrays();
1314 digits = (AliTRDdataArrayS *) man->GetDigits(fDET);
1315 track0 = (AliTRDdataArrayI *) man->GetDictionary(fDET,0);
1316 track1 = (AliTRDdataArrayI *) man->GetDictionary(fDET,1);
1317 track2 = (AliTRDdataArrayI *) man->GetDictionary(fDET,2);
1319 // Allocate memory space for the digits buffer
1320 if (digits->GetNtime() == 0)
1322 // AliDebug(5, Form("Alloc digits for det %d rows %d cols %d tbins %d", fDET, fRowMax, fColMax, fTBins));
1323 digits->Allocate(fRowMax, fColMax, fTBins);
1324 if (man->UsesDictionaries())
1326 track0->Allocate(fRowMax, fColMax, fTBins);
1327 track1->Allocate(fRowMax, fColMax, fTBins);
1328 track2->Allocate(fRowMax, fColMax, fTBins);
1332 indexes = man->GetIndexes(fDET);
1333 indexes->SetSM(fSM);
1334 indexes->SetStack(fSTACK);
1335 indexes->SetLayer(fLAYER);
1336 indexes->SetDetNumber(fDET);
1338 if (indexes->IsAllocated() == kFALSE)
1340 // AliDebug(4, "Allocating indexes");
1341 indexes->Allocate(fRowMax, fColMax, fTBins);
1343 } // is the HC header already decoded?
1349 if (DecodeSM() == kFALSE)
1350 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1357 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1358 ChangeStatus(kStop);
1363 // we do not return chambers for which the end-of-data was not received twice (for each HC)
1365 //AliDebug(1, Form("That's all folks! %d", fSM));