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 void AliTRDRawStreamV2::SwapOnEndian()
425 // Check the endian and swap if needed
429 char* ptemp = (char*) &itemp;
433 // assume we are at the begining of the buffer!
434 //AliDebug(5, "Swapping.");
435 UInt_t *pbegin = (UInt_t*)fPos;
437 for (UInt_t i = 0; i < fBufSize / fgkSizeWord; i++)
439 fDataWord = pbegin + i;
440 iutmp = (((*fDataWord & 0x000000ffU) << 24) | ((*fDataWord & 0x0000ff00U) << 8) |
441 ((*fDataWord & 0x00ff0000U) >> 8) | ((*fDataWord & 0xff000000U) >> 24));
442 // here we override the value in the buffer!
448 //____________________________________________________________________________
449 Int_t AliTRDRawStreamV2::NextData()
452 // Updates the next data word pointer
455 if (fCountBytes + fgkSizeWord >= fBufSize)
457 fkBufferSet = fRawReader->ReadNextData(fPos);
458 if (fkBufferSet == kTRUE)
460 fBufSize = fRawReader->GetDataSize();
462 fDataWord = (UInt_t*)fPos;
464 ChangeStatus(kNextSM);
477 fCountBytes += fgkSizeWord;
478 fDataWord = (UInt_t*)fPos;
484 //============================================================================
485 // Decoding functions
486 //============================================================================
488 //____________________________________________________________________________
489 void AliTRDRawStreamV2::DecodeHCheader(Int_t timeBins)
492 // Decode the HC header (fRawVersion == 2, 3, 4, ???)
495 fRVmajor = (*fDataWord >> 24) & 0x7f;
496 fRVminor = (*fDataWord >> 17) & 0x7f;
498 if (fRVmajor < 2 || fRVmajor > 4)
499 AliError(Form(" Unsupported raw version: %d", fRawVersion))
501 if ( fRawVersion != fRVmajor ) {
503 AliWarning("===============================================================================");
504 AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)"
505 ,fRawVersion,fRVmajor));
506 AliWarning(Form("Setting fRawVersion to %d", fRVmajor));
507 AliWarning("===============================================================================");
508 fRawVersion = fRVmajor;
513 // check for zero suppression
514 if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
515 else fZeroSuppressed = kFALSE;
518 if ( (*fDataWord & 0x3) == 1 ) {
520 fHCHWords = (*fDataWord >> 14) & 0x7;
521 fSM = (*fDataWord >> 9) & 0x1f;
522 fLAYER = (*fDataWord >> 6) & 0x7;
523 fSTACK = (*fDataWord >> 3) & 0x7;
524 fSIDE = (*fDataWord >> 2) & 0x1;
526 fROC = fGeo->GetDetectorSec(fLAYER, fSTACK);
528 //AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", *fDataWord, fSM, fROC, fSIDE+10));
529 //AliDebug(5, Form("0x%08x: HC header: expecting %d HC words", *fDataWord, fHCHWords));
540 AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
541 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
542 fRawReader->AddMajorErrorLog(kHCHeaderCorrupt,Form("0x%08x:dcs=%d; sm=%d; layer=%d; stack=%d.",
543 *fDataWord, fDCS, fSM, fLAYER, fSTACK));
553 AliWarning(Form("0x%08x: No HC header when it was expected.", *fDataWord));
554 fRawReader->AddMajorErrorLog(kHCHeaderMissing,Form("0x%08x", *fDataWord));
558 if ( fHCHWords >= 1 )
560 // read one more word
561 if (NextData() != kWordOK)
563 AliWarning("Next HC word missing");
564 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
565 fNextStatus = kNextHC;
569 if ( (*fDataWord & 0x3) == 1 )
572 fBCctr = (*fDataWord >> 16);
573 fPTctr = (*fDataWord >> 12) & 0xf;
574 fPTphase = (*fDataWord >> 8) & 0xf;
575 fTBins = ((*fDataWord >> 2) & 0x3f) + 1;
576 fTimeWords = (fTBins - 1)/3 + 1;
578 // AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
579 // , *fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
581 if( fTBins != timeBins )
583 AliWarning("===============================================================================");
584 AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)"
585 , timeBins, fTBins));
586 AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins));
587 AliWarning("===============================================================================");
589 fTimeWords = (fTBins - 1)/3 + 1;
595 if ( fHCHWords >= 2 ) {
596 // read one more word
597 if (NextData() != kWordOK)
599 AliWarning("Next HC word missing");
600 fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing");
601 fNextStatus = kNextHC;
604 if ( (*fDataWord & 0x3) == 1 ) {
606 fTCon = (*fDataWord >> 29) & 0x1;
607 fPEDon = (*fDataWord >> 31) & 0x1;
608 fGAINon = (*fDataWord >> 30) & 0x1;
609 fXTon = (*fDataWord >> 28) & 0x1;
610 fNonLinOn = (*fDataWord >> 27) & 0x1;
611 fBypass = (*fDataWord >> 26) & 0x1;
613 fCommonAdditive = (*fDataWord >> 20) & 0x3f;
615 // AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d"
616 // , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive));
622 //____________________________________________________________________________
623 Int_t AliTRDRawStreamV2::ChannelsToRead(Int_t ADCmask)
626 // Return the channels to read
629 memset(fADClookup, -1, 32 * sizeof(Int_t));
630 fADClookup[0] = 0; // count entries
631 fADClookup[1] = 2; // index - data start at 2
633 for (Int_t i = 0; i < 30; i++)
636 if ((ADCmask & mask))
638 //AliDebug(9, Form("fDataWord=0x%08x mask=0x%08x i=%d", *fDataWord, mask, i));
639 fADClookup[fADClookup[1]] = i;
645 // test the iteration - comment out for production
646 // begin of comment out section
648 sprintf(schannels, "ADC Channels to read: ");
650 while(fADClookup[1] - 2 < fADClookup[0])
652 //AliDebug(9, Form("max=%d index=%d adc=%d", fADClookup[0], fADClookup[1], fADClookup[fADClookup[1]]));
653 strcat(schannels, Form("%d ", fADClookup[fADClookup[1]]));
656 //AliDebug(9, Form("%s", schannels));
657 //AliDebug(9, Form("ADC channels = %d", fADClookup[0]));
658 // end of comment out section
661 return fADClookup[0];
664 //____________________________________________________________________________
665 void AliTRDRawStreamV2::DecodeTracklet()
668 // Decode the Tracklet
670 // this function is not tested yet on real tracklets
673 if ( fRawVersion < 1 || fRawVersion > 3 )
675 AliError(Form(" Unsupported raw version: %d", fRawVersion));
678 fTracklPID = (*fDataWord >> 24) & 0xff;
679 fTracklPadRow = (*fDataWord >> 20) & 0xf; // 0:15
680 fTracklDefL = (*fDataWord >> 13) & 0x7f;
681 fTracklPadPos = (*fDataWord) & 0x1fff;
683 fTracklPID /= (Float_t)((1<<8) - 1); // 0:1 (steps of 0.39%)
684 fTracklDefL = (fTracklDefL - ((1<< 7)-1)/2.) * 140.e-4; // -0.889:0.889cm
685 fTracklPadPos = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm
687 //AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f"
688 // , *fDataWord, fSM, fLAYER, fSTACK, fSIDE+10
689 // , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID));
691 if( (fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0()) ||
692 (fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1()) ) {
693 AliWarning(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow));
694 fRawReader->AddMajorErrorLog(kTrackletRowMismatch,Form("Word: %d", fTracklPadRow));
699 //____________________________________________________________________________
700 void AliTRDRawStreamV2::DecodeMCMheader()
703 // Decode the MCM header
706 if ( fRawVersion < 1 || fRawVersion > 3 )
708 AliError(Form(" Unsupported raw version: %d", fRawVersion));
711 fMCM = (*fDataWord & 0xff000000) >> 24;
712 fEv = (*fDataWord & 0x00fffff0) >> 4;
717 fROW = AliTRDfeeParam::Instance()->GetPadRowFromMCM(fROB, fMCM);
719 // AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d"
720 // , *fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv));
722 if ( fROB % 2 == 0 && fSIDE == 1 ) {
723 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
724 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
725 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
726 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
728 if ( fROB % 2 != 0 && fSIDE == 0 ) {
729 AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
730 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
731 fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
732 , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
734 if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
735 (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
736 AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
737 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
738 fRawReader->AddMajorErrorLog(kWrongPadrow,Form("SM%d L%dS%d: Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
739 , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
745 fMCMWordCrt = 1; // MCM header
747 // AdcMask for Zero supressed data
748 if ( fRawVersion == 3 )
750 // read one more word
751 if (NextData() != kWordOK)
753 AliWarning("MCM ADC mask missing");
754 fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
755 fNextStatus = kNextHC;
762 for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
763 if ( (*fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
764 else fADCmask[ctr] = kFALSE;
767 //AliDebug(4, Form("0x%08x: ADC mask", *fDataWord));
768 fNActiveADCs = ChannelsToRead(*fDataWord);
772 if (fRawVersion <= 2)
774 // no zero suppression
776 // 1 MCM header + 21 * ( Ntimebin/3)
777 // If NTimebin = 30, it is 211 words.
778 //fMCMWordsExpected = 1 + 21 * (fTBins / 3);
780 fNActiveADCs = ChannelsToRead(0x1fffff); // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
781 //fMCMWordsExpected = 1 + fNActiveADCs * ((fTBins-1) / 3. + 1.);
782 //directly get it like that:
783 fMCMWordsExpected = 1 + fNActiveADCs * fTBins / 3;
786 if (fRawVersion >= 3)
789 // 1 MCM header + 1 ADC mask + NofActiveADCs * ( Ntimebin/3 )
790 //directly get it like that:
791 fMCMWordsExpected = 1 + 1 + (fTBins * fNActiveADCs) / 3;
794 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
796 //____________________________________________________________________________
797 Bool_t AliTRDRawStreamV2::DecodeNextRawWord()
800 // Decode the next raw data word
803 //AliDebug(8, Form("-----------------------------------------"));
804 //AliDebug(8, Form("DATA IS 0x%x", *fDataWord));
806 if (fADClookup[1] - 2 > fADClookup[0])
808 // 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?",
809 // fADClookup[1] - 2, fADClookup[0], fADClookup[fADClookup[1]], *fDataWord));
811 fMCMWordsExpected = 0;
812 AliWarning("Trying to recover. Fall back to DecodeMCM.");
814 //ChangeStatus(kNextMCM);
818 if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
819 AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
820 fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
821 fMCMWordsExpected = 0;
822 AliWarning("Trying to recover. Fall back to DecodeMCM.");
824 //ChangeStatus(kNextMCM);
828 if ( (*fDataWord & 0x3) != fLastADCmask || fTbSwitchCtr > fTimeWords)
830 fADC = fADClookup[fADClookup[1]];
831 // AliDebug(8, Form("Next fADC = %d at index = %d MCM Word Number: %d Max MCM Words is %d",
832 // fADC, fADClookup[1] - 2, fMCMWordCrt, fMCMWordsExpected));
836 fLastStatus = kNextData;
837 fLastADCmask = (*fDataWord) & 0x3;
843 Bool_t kIsDataOK = kFALSE;
845 // We have only 21 ADC channels.
846 if ( fADC > (Int_t)fGeo->ADCmax() - 1 )
848 AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
849 fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
853 // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
854 // MCMs and are good for online tracking in the MCM.
855 if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax() - 1 )
859 // fCOL = fFee->GetPadColFromADC(fROB, fMCM, fADC);
860 fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fROB, fMCM, fADC);
862 // We have only 144 Pad Columns
863 //if ( fCOL > fColMax-1 || fCOL < 0 )
864 if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax )
866 // Decode 32 bit data words with information from 3 time bins and copy the data
867 fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
868 fSig[1] = (*fDataWord & 0x003ff000) >> 12;
869 fSig[2] = (*fDataWord & 0xffc00000) >> 22;
871 // Print data to screen:
872 //AliDebug(5, Form("DATA : 0x%x", *fDataWord));
873 // AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
874 // fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));
879 AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
880 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
881 fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
882 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
888 //AliDebug(5, Form("fADC not accepted %d - DATA : 0x%x", fADC, *fDataWord));
895 //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
897 // all mcm data processed go to next one
898 if ( fMCMWordCrt >= fMCMWordsExpected)
900 ChangeStatus(kNextMCM);
906 //____________________________________________________________________________
907 Bool_t AliTRDRawStreamV2::DecodeMCM()
910 // Decode a single MCM
913 if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) )
916 if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 )
918 AliWarning("Wrong fMCM or fROB. Skip this data");
919 fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB));
920 ChangeStatus(kNextHC);
924 fTbSwitch = 3; // For first adc channel we expect: (*fDataWord & 3) = 3
926 fADC = fTB = 0; // Reset Counter
927 fLastADCmask = 0; // Reset
929 if (fMCMWordCrt < fMCMWordsExpected)
931 ChangeStatus(kNextData);
935 ChangeStatus(kNextMCM);
940 if ( *fDataWord == fgkEndofrawdatamarker )
941 { // End of half-chamber data, finished
943 ChangeStatus(kNextHC);
944 fEndOfDataFlag = kTRUE;
945 //AliDebug(5, "Expecting MCM header but got End-Of-Raw-Data Marker");
946 if (fMCMWordsExpected == 0 || fMCMWordsExpected == fMCMWordCrt)
950 //AliDebug(5, Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
951 //AliWarning(Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));
956 //AliDebug(3, Form("Expecting MCM header but got 0x%x. Going to Next MCM header.", *fDataWord));
957 AliWarning(Form("Expecting MCM header but got 0x%x. Fall back: Next MCM header.", *fDataWord));
958 ChangeStatus(kNextMCM);
963 //____________________________________________________________________________
964 Bool_t AliTRDRawStreamV2::DecodeHC()
967 // Decode a half chamber
970 if ( fNextStatus == kNextHC )
972 //AliDebug(5, "kNextHC");
974 // 1) Find end_of_tracklet_marker
977 if (DecodeGTUlinkMask())
982 // endoftrackletmarker?
983 if ( *fDataWord == fgkEndoftrackletmarker )
985 //AliDebug(3, "End-of-tracklet-marker found");
986 //AliDebug(5, Form("Data 0x%x", *fDataWord));
987 ChangeStatus(kSeekNonEoTracklet);
993 //AliDebug(3, "Tracklet found");
994 //AliDebug(5, Form("Tracklet data 0x%x", *fDataWord));
1000 if (fNextStatus == kSeekNonEoTracklet)
1002 //AliDebug(5, "kSeekNonEoTracklet");
1005 // 2) Look for non-end_of_tracklet_marker
1007 //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord);
1009 if ( *fDataWord != fgkEndoftrackletmarker )
1011 ChangeStatus(kDecodeHC);
1012 //AliDebug(3, "NON end-of-tracklet-marker found");
1013 //AliDebug(5, Form("Data 0x%x", *fDataWord));
1014 //// no do not continue - this should be the hcheader
1018 //just go on and find the non-end_of_tracklet_marker
1023 if ( fNextStatus == kDecodeHC )
1025 //AliDebug(5, "kDecodeHC");
1028 // 3) This Word must be Half Chamber Header
1030 if ( (*fDataWord & 0x00000003) == 1 )
1032 DecodeHCheader(fTimeBinsCalib); // This is the new header!
1034 fDET = fGeo->GetDetector(fLAYER, fSTACK, fSM);
1035 fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM);
1036 fColMax = fGeo->GetColMax(fROC);
1040 fChamberDone[fDET]++;
1041 //AliDebug(6, Form("-------------- DET %d fChamberDone[fDET]=%d", fDET, fChamberDone[fDET]));
1043 ChangeStatus(kNextMCM);
1048 AliWarning(Form("Expecting HC header mask but got 0x%x. Fall back: Next HC.", *fDataWord));
1049 ChangeStatus(kNextHC);
1050 // before we went to //ChangeStatus(kNextSM);
1057 //____________________________________________________________________________
1058 Bool_t AliTRDRawStreamV2::DecodeGTUlinkMask()
1061 // Decode the link masks sent by the GTU. These marke the active optical links
1062 // between GTU and Super Module. Up to now only fully active links are found
1063 // (0xfff = 12 active links).
1066 if ( (*fDataWord & 0xfffff000) == 0xe0000000 )
1068 if ( fRawVersion < 1 || fRawVersion > 3 )
1070 AliError(Form(" Unsupported raw version: %d", fRawVersion));
1073 if ( fGTUctr1 == -1 ) fGTUctr2++;
1076 if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) )
1078 fGTUlinkMask[fGTUctr2][fGTUctr1] = (*fDataWord & 0xfff);
1081 //AliDebug(5, Form("GTU link mask 0x%x decoded 0x%x", *fDataWord, fGTUlinkMask[fGTUctr2][fGTUctr1]));
1088 //____________________________________________________________________________
1089 void AliTRDRawStreamV2::ChangeStatus(Int_t kstat)
1092 // Change the status
1095 fLastStatus = fNextStatus;
1096 fNextStatus = kstat;
1099 //____________________________________________________________________________
1100 Bool_t AliTRDRawStreamV2::DecodeSM()
1103 // Decode a supermodule
1112 // After reading the first word check for size of this data and get Eq. ID
1113 if ( fWordCtr == 1 )
1115 fDataSize = fRawReader->GetDataSize()/4; // Size of this payload in 32bit words
1116 fEqID = fRawReader->GetEquipmentId(); // Get Equipment ID
1117 if ( fDataSize > 0 ) fSizeOK = kTRUE;
1118 //AliDebug(3, Form("fDataSize=%d fEqID=%d", fDataSize, fEqID));
1122 if ( DecodeGTUlinkMask() )
1124 ChangeStatus(kNextHC);
1129 AliWarning(Form("Equipment %d: First data word is not GTU Link Mask! Fall back: None. Stop.", fEqID));
1130 fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID));
1131 ChangeStatus(kStop);
1137 //____________________________________________________________________________
1138 Bool_t AliTRDRawStreamV2::Next()
1141 // Updates the next data word pointer
1144 if (fNextStatus == kStart)
1149 while (fNextStatus != kStop)
1153 switch (fNextStatus)
1157 if (DecodeNextRawWord() == kTRUE)
1160 if (fSig[0] > fRawDigitThreshold || fSig[1] > fRawDigitThreshold || fSig[2] > fRawDigitThreshold)
1166 if (DecodeMCM() == kFALSE)
1167 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1170 case kSeekNonEoTracklet:
1173 if (DecodeHC() == kFALSE)
1175 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1179 //the hc header should be decoded by now
1180 if (fLastStatus == kDecodeHC)
1183 fChamberDone[fDET]++;
1189 if (DecodeSM() == kFALSE)
1190 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1195 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1196 ChangeStatus(kStop);
1201 //AliDebug(1, Form("That's all folks! %d", fSM));
1205 //____________________________________________________________________________
1206 Int_t AliTRDRawStreamV2::NextChamber(AliTRDdigitsManager *man)
1209 // Fills single chamber digit array
1210 // Return value is the detector number
1213 AliTRDdataArrayI *digits = 0;
1214 AliTRDdataArrayI *track0 = 0;
1215 AliTRDdataArrayI *track1 = 0;
1216 AliTRDdataArrayI *track2 = 0;
1217 AliTRDSignalIndex *indexes = 0;
1219 if (fNextStatus == kStart)
1224 // while (fNextStatus != kStop)
1227 // // catch 3 things
1228 // // 1) if end of raw data - if chamber complete return
1229 // // 2) fill the data with signals if data decoded ok
1230 // // 3) initialize (destroy old) after the det has changed -> just after HC header decoding
1233 while (fNextStatus != kStop)
1237 switch (fNextStatus)
1242 if (DecodeNextRawWord() == kTRUE)
1244 for (Int_t it = 0; it < 3; it++)
1246 if ( fTB + it < fTBins )
1248 if ( fSig[it] > fRawDigitThreshold )
1250 digits->SetDataUnchecked(fROW, fCOL, fTB + it, fSig[it]);
1251 indexes->AddIndexTBin(fROW, fCOL, fTB + it);
1252 if (man->UsesDictionaries())
1254 track0->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1255 track1->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1256 track2->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1257 } // if dictionaries
1258 } // signal above zero
1259 } // check the tbins range
1260 } // for each tbin of current 3
1265 // can be here as a fall back from decode raw data calling decodemcm
1266 if (fEndOfDataFlag == kTRUE)
1268 if (fChamberDone[fDET] == 2)
1272 fEndOfDataFlag = kFALSE;
1279 if (DecodeMCM() == kFALSE)
1281 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1283 // default place for end of raw data...
1284 if (fEndOfDataFlag == kTRUE)
1286 if (fChamberDone[fDET] == 2)
1290 fEndOfDataFlag = kFALSE;
1295 case kSeekNonEoTracklet:
1298 if (DecodeHC() == kFALSE)
1300 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1304 //the hc header should be decoded by now
1305 if (fLastStatus == kDecodeHC)
1307 // AliDebug(4, Form("???? New DET ???? %d last %d", fDET, fLastDET));
1308 // allocate stuff for the new det
1309 //man->ResetArrays();
1310 digits = man->GetDigits(fDET);
1311 track0 = man->GetDictionary(fDET,0);
1312 track1 = man->GetDictionary(fDET,1);
1313 track2 = man->GetDictionary(fDET,2);
1315 // Allocate memory space for the digits buffer
1316 if (digits->GetNtime() == 0)
1318 // AliDebug(5, Form("Alloc digits for det %d rows %d cols %d tbins %d", fDET, fRowMax, fColMax, fTBins));
1319 digits->Allocate(fRowMax, fColMax, fTBins);
1320 if (man->UsesDictionaries())
1322 track0->Allocate(fRowMax, fColMax, fTBins);
1323 track1->Allocate(fRowMax, fColMax, fTBins);
1324 track2->Allocate(fRowMax, fColMax, fTBins);
1328 indexes = man->GetIndexes(fDET);
1329 indexes->SetSM(fSM);
1330 indexes->SetStack(fSTACK);
1331 indexes->SetLayer(fLAYER);
1332 indexes->SetDetNumber(fDET);
1334 if (indexes->IsAllocated() == kFALSE)
1336 // AliDebug(4, "Allocating indexes");
1337 indexes->Allocate(fRowMax, fColMax, fTBins);
1339 } // is the HC header already decoded?
1345 if (DecodeSM() == kFALSE)
1346 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));
1353 AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));
1354 ChangeStatus(kStop);
1359 // we do not return chambers for which the end-of-data was not received twice (for each HC)
1361 //AliDebug(1, Form("That's all folks! %d", fSM));