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 **************************************************************************/
16 /* $Id: AliTRDrawFastStream.cxx 27797 2008-08-05 14:37:22Z cblume $ */
18 ////////////////////////////////////////////////////////////////////////////////
20 // This class provides access to TRD digits in raw data in a way of streaming //
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: M. Ploskon (ploskon@ikf.uni-frankfurt.de) //
28 // Author: MinJung Kweon (minjung@physi.uni-heidelberg.de) //
30 ////////////////////////////////////////////////////////////////////////////////
34 #include "TTreeStream.h"
36 #include "AliTRDrawFastStream.h"
37 #include "AliTRDgeometry.h"
38 #include "AliTRDfeeParam.h"
39 #include "AliTRDdigitsManager.h"
40 #include "AliTRDarrayDictionary.h"
41 #include "AliTRDarrayADC.h"
42 #include "AliTRDSignalIndex.h"
43 #include "AliTRDdigitsParam.h"
44 #include "AliTRDrawTPStream.h"
47 #include "AliRawReader.h"
49 #define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa
50 #define END_OF_TRACKLET_MARKERNEW 0x10001000
51 #define ENDOFRAWDATAMARKER 0x00000000
52 #define WORD_SIZE sizeof(UInt_t) // size of a word in bytes
53 #define EXTRA_LEAD_WORDS 24
56 #define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w
57 #define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m
59 // SM index word masks:
60 #define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
61 #define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)
62 #define STACK_MASK(w) ((w) & 0x1f)
65 #define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
66 #define STACK_LINK_WORD(w) ((w) & 0xfff)
67 #define LINK0_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,4) == (0x0) ? 0 : 1) // 0 if physics data
68 #define LINK1_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,20) == (0x0) ? 0 : 1) // 0 if physics data
69 #define LINK0_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,0) == (0x0) ? 0 : 1) // 0 if OK
70 #define LINK1_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,16) == (0x0) ? 0 : 1) // 0 if OK
73 //#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!!
74 #define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK!!!
77 #define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)
78 #define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)
79 #define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24)
80 #define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)
81 #define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)
82 #define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)
83 #define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)
84 #define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)
85 #define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)
86 #define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)
89 #define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)
90 #define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)
91 #define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)
92 #define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,6)
94 // MCM word and ADC mask
95 #define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
96 #define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
97 #define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)
98 #define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)
99 #define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)
100 #define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)
101 #define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25)
103 #define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated
104 #define ADCDATA_VAL1 0x2 // updated
105 #define ADCDATA_VAL2 0x3 // updated
107 //--------------------------------------------------------
108 #define ADC_WORD_MASK(w) ((w) & 0x3)
109 //--------------------------------------------------------
110 ClassImp(AliTRDrawFastStream)
112 Bool_t AliTRDrawFastStream::fgExtraSkip = kFALSE;
113 Bool_t AliTRDrawFastStream::fgSkipCDH = kFALSE;
114 Bool_t AliTRDrawFastStream::fgWarnError = kTRUE;
115 Bool_t AliTRDrawFastStream::fgCleanDataOnly = kFALSE;
116 Bool_t AliTRDrawFastStream::fgDebugFlag = kTRUE;
117 Bool_t AliTRDrawFastStream::fgEnableMemoryReset = kTRUE;
118 Bool_t AliTRDrawFastStream::fgStackNumberChecker = kTRUE;
119 Bool_t AliTRDrawFastStream::fgStackLinkNumberChecker = kFALSE;
120 Bool_t AliTRDrawFastStream::fgSkipData = kTRUE;
121 Bool_t AliTRDrawFastStream::fgEnableDecodeConfigData = kFALSE;
122 Int_t AliTRDrawFastStream::fgDumpHead = -1;
123 Short_t AliTRDrawFastStream::fgMCMordering[] =
125 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3
127 Short_t AliTRDrawFastStream::fgROBordering[] =
131 Bool_t AliTRDrawFastStream::fDumpingEnable = kFALSE;
132 Int_t AliTRDrawFastStream::fDumpingSM = -1;
133 Int_t AliTRDrawFastStream::fDumpingStack = -1;
134 Int_t AliTRDrawFastStream::fDumpingLayer = -1;
135 Int_t AliTRDrawFastStream::fDumpingROB = -1;
136 Int_t AliTRDrawFastStream::fDumpingMCM = -1;
138 Int_t AliTRDrawFastStream::fgLastHC = -1;
139 Int_t AliTRDrawFastStream::fgLastROB = -1;
140 Int_t AliTRDrawFastStream::fgLastIndex = -1;
142 //--------------------------------------------------------
143 AliTRDrawFastStream::AliTRDrawFastStream()
144 : AliTRDrawStreamBase()
155 , fGlobalNTimeBins(0)
156 , fIsTimeBinSet(kFALSE)
157 , fIsGlobalDigitsParamSet(kFALSE)
159 , fStackLinkNumber(-1)
160 , fLinkTrackletCounter(-1)
161 , fEndOfTrackletCount(-1)
166 , fLastEventCounter(0)
167 , fSharedPadsOn(kTRUE)
179 // default constructor
182 if (Init() == kFALSE) {
183 AliWarning("Unable to Init.");
187 //--------------------------------------------------------
188 AliTRDrawFastStream::AliTRDrawFastStream(AliRawReader *rawReader)
189 : AliTRDrawStreamBase(rawReader)
200 , fGlobalNTimeBins(0)
201 , fIsTimeBinSet(kFALSE)
202 , fIsGlobalDigitsParamSet(kFALSE)
204 , fStackLinkNumber(-1)
205 , fLinkTrackletCounter(-1)
206 , fEndOfTrackletCount(-1)
211 , fLastEventCounter(0)
212 , fSharedPadsOn(kTRUE)
220 , fRawReader(rawReader)
224 // default constructor
227 if (Init() == kFALSE) {
228 AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
232 AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
236 //------------------------------------------------------------
237 AliTRDrawFastStream::AliTRDrawFastStream(const AliTRDrawFastStream& /*st*/)
238 : AliTRDrawStreamBase()
249 , fGlobalNTimeBins(0)
250 , fIsTimeBinSet(kFALSE)
251 , fIsGlobalDigitsParamSet(kFALSE)
253 , fStackLinkNumber(-1)
254 , fLinkTrackletCounter(-1)
255 , fEndOfTrackletCount(-1)
260 , fLastEventCounter(0)
261 , fSharedPadsOn(kTRUE)
275 AliError("Not implemeneted.");
278 //------------------------------------------------------------
279 Bool_t AliTRDrawFastStream::SetRawVersion(Int_t fraw)
282 // function provided for backward compatibility
284 AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");
285 fraw = 0; // avoid warnings
289 //------------------------------------------------------------
290 AliTRDrawFastStream::~AliTRDrawFastStream()
298 //------------------------------------------------------------
300 AliTRDrawFastStream &
301 AliTRDrawFastStream::operator=(const AliTRDrawFastStream &)
304 // we are not using this functionality
306 AliFatal("May not use.");
310 //___________________________________________________________
311 void AliTRDrawFastStream::SwapOnEndian()
314 // Check the endian and swap if needed
317 char* ptemp = (char*) &itemp;
320 if (fgDebugFlag) AliDebug(8, "Swapping.");
324 while (fpPos < fpEnd)
327 iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
328 ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
329 // here we override the value in the buffer!
336 //------------------------------------------------------------
337 Bool_t AliTRDrawFastStream::SkipWords(UInt_t iw)
340 // Skip words corresponding to iw
342 if ( fpPos + iw < fpEnd ) {
347 if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
354 //------------------------------------------------------------
355 Bool_t AliTRDrawFastStream::SetReader(AliRawReader *reader)
364 AliWarning("Unable to setup reader.");
369 AliWarning("AliRawReader argument is 0.");
376 //------------------------------------------------------------
377 Int_t AliTRDrawFastStream::NextBuffer()
380 // return -1 if no more buffers available
381 // return 0 if SMHeader decoding failed
382 // return 1 if SMHeader dedoding is OK
384 if (fRawReader != 0) {
387 Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
388 if (kBufferSet == kTRUE) {
389 if (fgDebugFlag) AliDebug(9, "Buffer is set.");
390 length = fRawReader->GetDataSize();
391 if (fgExtraSkip == kTRUE) {
392 buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
393 length -= EXTRA_LEAD_WORDS * WORD_SIZE;
396 if (fgSkipCDH == kTRUE) {
397 buffer += CDH_WORDS * WORD_SIZE;
398 length -= CDH_WORDS * WORD_SIZE;
402 if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
403 if (fgEnableMemoryReset) ResetMemory();
404 if (DecodeSMHeader((void*)buffer, length) == kTRUE)
418 //------------------------------------------------------------
419 void AliTRDrawFastStream::ResetCounters()
422 // reset some global counters
424 fBufferRead = kFALSE; // kFALSE if no buffer read
426 fSM.fActiveStacks = 0;
427 fSM.fNexpectedHalfChambers = 0;
429 fLastEventCounter = 0;
435 //------------------------------------------------------------
436 void AliTRDrawFastStream::ResetIterators()
439 // reset data which should be reset every sm
442 fStackLinkNumber = 0;
445 //------------------------------------------------------------
446 void AliTRDrawFastStream::ResetPerSM()
452 fSM.fTrackletEnable = kFALSE;
454 fSM.fNexpectedHalfChambers = 0;
455 fSM.fNexpectedHalfChambers = 0;
457 for (Int_t i=0; i<5; i++) {
458 fSM.fStackActive[i] = kFALSE;
462 //------------------------------------------------------------
463 void AliTRDrawFastStream::ResetPerStack()
468 fStack->fHeaderSize = 0;
469 fStack->fActiveLinks = 0;
471 for (Int_t i=0; i<12; i++) {
472 fStack->fLinksActive[i] = kFALSE;
473 fStack->fLinksDataType[i] = 0;
474 fStack->fLinksMonitor[i] = 0;
475 fStack->fLinkMonitorError[i] = 0;
479 //------------------------------------------------------------
480 void AliTRDrawFastStream::ResetPerHC()
486 fHC->fNTracklets = 0;
487 fHC->fSpecialRawV = 0;
489 fHC->fRawVMajorOpt = 0;
491 fHC->fNExtraWords = 0;
494 fHC->fBunchCrossCounter = 0;
495 fHC->fPreTriggerCounter = 0;
496 fHC->fPreTriggerPhase = 0;
501 fHC->fStackHCheader = 0;
503 fHC->fLayerHCheader = 0;
505 fHC->fSideHCheader = 0;
511 fHC->fH0Corrupted = 0;
512 fHC->fH1Corrupted = 0;
514 fHC->fEOTECorrupted = kFALSE;
515 fHC->fBufferCorrupted = kFALSE;
516 fHC->fDataCorrupted = kFALSE;
519 memset(fHC->fErrorCodes, 0, 1411*sizeof(UShort_t)); // initialize error container
520 memset(fHC->fTrackletWords, 0, MAXTRACKLETSPERHC*sizeof(UInt_t)); // initialize tracklet container
523 //------------------------------------------------------------
524 void AliTRDrawFastStream::ResetPerMCM()
534 fMCM.fADCMaskWord = 0;
537 fMCM.fMCMADCWords = 0;
538 fMCM.fSingleADCwords = 0;
539 fMCM.fMCMhdCorrupted = 0;
540 fMCM.fADCmaskCorrupted = 0;
541 fMCM.fDataCorrupted = kFALSE;
543 fMCM.fAdcDataPos = NULL;
544 fMCM.fADCcounter = 0;
546 memset(fMCM.fADCchannel, 0, TRDMAXADC*sizeof(UInt_t));
549 //------------------------------------------------------------
550 void AliTRDrawFastStream::ResetMemory()
553 // initialize all the data members to prevent read data
554 // from previous buffer
557 for (Int_t istack=0; istack<5; istack++) {
558 fStack = &fSM.fStacks[istack];
560 for (Int_t ilink=0; ilink<12; ilink++) {
561 fHC = &fStack->fHalfChambers[ilink];
567 //------------------------------------------------------------
568 Bool_t AliTRDrawFastStream::Next()
571 // returns with true on next adc read, returns false on errors and end of buffer
574 while (fStackNumber < 5 && fSM.fActiveStacks > 0) {
575 if (fSM.fStackActive[fStackNumber] == kTRUE) {
576 fStack = &fSM.fStacks[fStackNumber];
577 while (fStackLinkNumber < 12) {
578 if (fStack->fLinksActive[fStackLinkNumber] == kTRUE) {
579 //if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0)
580 fHC = &fStack->fHalfChambers[fStackLinkNumber];
581 //ResetPerHC(); // [mj - you don't need to do? ]
583 AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
589 else fStackLinkNumber++;
590 } //stack link number loop
593 fStackLinkNumber = 0;
594 } //stack number loop
597 // go for the next buffer
599 Int_t nextBuff = NextBuffer();
600 while (nextBuff != -1) {
605 nextBuff = NextBuffer();
612 //------------------------------------------------------------
613 Int_t AliTRDrawFastStream::NextChamber(AliTRDdigitsManager *digitsManager, UInt_t **trackletContainer, UShort_t **errorCodeContainer)
617 // Fills single chamber digit array
618 // Return value is the detector number
620 // first of all, you do the SM header decoding only at the beginning of the SM data reading
621 // then, every HC, you call Next() which points next HC. then, there you decode the given HC
622 // and at the same time, put the digit into digitmanager
624 AliTRDarrayADC *digits = 0;
625 AliTRDarrayDictionary *track0 = 0;
626 AliTRDarrayDictionary *track1 = 0;
627 AliTRDarrayDictionary *track2 = 0;
628 AliTRDSignalIndex *indexes = 0;
629 AliTRDdigitsParam *digitsparam = 0;
635 Int_t ntracklets = 0;
638 if (trackletContainer){
639 for (Int_t i = 0; i < 2; i++)
640 memset(trackletContainer[i], 0, MAXTRACKLETSPERHC*sizeof(UInt_t));
643 if (errorCodeContainer){
644 for (Int_t i = 0; i < 2; i++)
645 memset(errorCodeContainer[i], 0, 1411*sizeof(UShort_t));
648 while ( Next() ) { // loop over HC
650 // get this information from the GTU header
654 if (det != lastdet) {
655 // If new detector found
656 if (lastdet == -1) {lastdet = det; fLastHC = fHC;}
657 else {fStackLinkNumber--; fHC = fLastHC ; return lastdet;}
659 if (det < 0 || det >= AliTRDgeometry::kNdet) continue;
661 // Add a container for the digits of this detector
662 digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);
664 if (digitsManager->UsesDictionaries()) {
665 track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);
666 track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);
667 track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);
670 if (!digits) return -1;
672 Int_t rowMax = GetRowMax();
673 Int_t colMax = GetColMax();
674 Int_t ntbins = GetGlobalNTimeBins();
676 // Set number of timebin into digitparam
677 if (!fIsGlobalDigitsParamSet){
678 digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();
679 digitsparam->SetCheckOCDB(kFALSE);
680 digitsparam->SetNTimeBins(ntbins);
681 digitsparam->SetADCbaseline(10);
682 digitsparam->SetPretiggerPhase(det,GetPreTriggerPhase());
\r\r
683 fIsGlobalDigitsParamSet = kTRUE;
685 if(!digitsparam){
\r\r
686 digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();
\r\r
687 digitsparam->SetPretiggerPhase(det,GetPreTriggerPhase());
\r\r
690 // Allocate memory space for the digits buffer
691 if (digits->GetNtime() == 0) {
692 digits->Allocate(rowMax, colMax, ntbins);
693 if (digitsManager->UsesDictionaries()) {
694 track0->Allocate(rowMax, colMax, ntbins);
695 track1->Allocate(rowMax, colMax, ntbins);
696 track2->Allocate(rowMax, colMax, ntbins);
700 indexes = digitsManager->GetIndexes(det);
701 indexes->SetSM(GetSM());
702 indexes->SetStack(GetStack());
703 indexes->SetLayer(GetLayer());
704 indexes->SetDetNumber(det);
705 if (indexes->IsAllocated() == kFALSE)
706 indexes->Allocate(rowMax, colMax, ntbins);
709 if (fSM.fTrackletEnable == kTRUE) {
710 if (DecodeTracklets() == kFALSE) {
713 if (fgWarnError) AliError(Form("Tracklet decoding failed stack %d link %d", GetStack(), fStackLinkNumber));
715 // copy error codes in memory into error container
716 if (errorCodeContainer) {
717 nErrors = GetNErrors();
718 if(nErrors > 0) memcpy(errorCodeContainer[side], GetErrorCodes(), sizeof(UShort_t) * 1411); // [mj temp - optimize]
721 continue; // if it fails to decode tracklets of this HC, it skips further decoding and goes to next HC
726 fgLastROB = -1; // to check mcm number odering
727 fgLastIndex = -1 ; // to check mcm number odering
728 if (DecodeHC(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {
729 // encode HC error code
730 fHC->fErrorCodes[2] += fHC->fH0Corrupted;
731 fHC->fErrorCodes[2] += (fHC->fH1Corrupted << 2);
732 fHC->fErrorCodes[2] += (fHC->fCorrupted << 3);
733 fHC->fErrorCodes[2] += ((fHC->fBufferCorrupted & 1) << 6);
734 fHC->fErrorCodes[2] += ((fHC->fEOTECorrupted & 1) << 7);
735 fHC->fErrorCodes[2] += ((fHC->fDataCorrupted & 1) << 8);
737 if (fHC->fEOTECorrupted != kTRUE) SeekEndOfData();
741 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
742 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
746 else SeekEndOfData(); // make sure that finish off with the end of data markers
748 // copy tracklets in memory into tracklet container
749 if (trackletContainer) {
750 ntracklets = GetNTracklets();
751 // copy tracklet words to trackletContainer array
752 if(ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets);
755 // copy error codes in memory into error container
756 if (errorCodeContainer) {
757 nErrors = GetNErrors();
758 if(nErrors > 0) memcpy(errorCodeContainer[side], GetErrorCodes(), sizeof(UShort_t) * 1411);
766 //------------------------------------------------------------
767 Bool_t AliTRDrawFastStream::Init()
770 // Initialize geometry and fee parameters
772 TDirectory *saveDir = gDirectory;
775 fGeometry = new AliTRDgeometry();
779 AliError("Geometry FAILED!");
783 fTRDfeeParam = AliTRDfeeParam::Instance();
785 AliError("AliTRDfeeParam FAILED!");
789 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
791 ResetCounters(); // fBufferRead is set to kFALSE - important
798 //------------------------------------------------------------
799 Bool_t AliTRDrawFastStream::InitBuffer(void *buffer, UInt_t length)
802 // set initial information about the buffer
804 if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));
805 if (fRawReader->GetEquipmentId()<1024 || fRawReader->GetEquipmentId()>1041)
810 fpBegin = (UInt_t *)buffer;
812 if (WORD_SIZE == 0) {
813 AliFatal("Strange word size. size of UInt_t == 0");
817 fWordLength = length/WORD_SIZE;
818 fpEnd = fpBegin + fWordLength;
821 if (fpBegin == 0 || length <= 0) {
822 AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%08x of size %d", fpBegin, length));
828 if (fgDumpHead >= 0) {
829 if ( fgDumpHead == 0 ) { // dump all words
830 AliInfo(Form("---------- Dumping all words from the beginnig of the buffer ----------"));
831 if (DumpWords(fpBegin, fWordLength) == kFALSE) AliError("Dump failed. Not enough data.");
834 AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));
835 if (DumpWords(fpBegin, fgDumpHead) == kFALSE) AliError("Dump failed. Not enough data.");
837 AliInfo(Form("---------- Dumping ended ----------------------------------------------"));
843 //------------------------------------------------------------
844 Bool_t AliTRDrawFastStream::DecodeSMHeader(void *buffer, UInt_t length)
847 // decode one sm data in buffer
851 if (InitBuffer(buffer, length) == kFALSE) {
852 if (fgWarnError) AliError("InitBuffer failed.");
856 if (DecodeGTUheader()== kFALSE)
859 for (Int_t istack = 0; istack < 5; istack++) {
860 fStackNumber = istack;
861 if (fSM.fStackActive[istack] == kFALSE) continue;
863 fStack = &fSM.fStacks[istack];
865 fgLastHC = -1; // to check rob number odering
866 for (Int_t ilink = 0; ilink < 12; ilink++) {
867 fStackLinkNumber = ilink;
868 if (fStack->fLinksActive[ilink] == kFALSE) continue;
870 // check GTU link monitor
871 if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0)) {
872 fStack->fLinkMonitorError[ilink] = 1;
873 fStack->fLinkMonitorError[ilink] += fNWordsCounter; // counts words of given hc having link monitor error
877 if (fpPos >= fpEnd) {
878 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
879 if (fgWarnError) AliError("Link data missing.");
883 // HLT streamer set det number using SM header
884 fHC = &fStack->fHalfChambers[ilink];
885 fHC->fSM = fRawReader->GetEquipmentId() - 1024;
886 fHC->fStack = fStackNumber;
887 fHC->fLayer = Int_t(fStackLinkNumber/2.);
888 fHC->fSide = fStackLinkNumber%2;
889 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
890 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
891 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
892 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
896 // set number of timebin to be used in the digit container
897 if (!fIsTimeBinSet) {
899 SetGlobalNTimebins();
900 fIsTimeBinSet = kTRUE;
903 ResetIterators(); // need to do it again for Next() function
908 //------------------------------------------------------------
909 Bool_t AliTRDrawFastStream::DecodeGTUheader()
912 // decode Supermodule Index Word
914 DecodeSMInfo(fpPos, &fSM);
916 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
920 // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design.
921 // For the moment, we skip decoding these words
922 if (SkipWords(fSM.fHeaderSize) == kTRUE) {
923 for (Int_t istack = 0; istack < 5; istack++) {
924 if (fSM.fStackActive[istack] == kFALSE)
927 fStack = &fSM.fStacks[istack];
929 // Decode Stack Index Word of given stack
930 DecodeStackInfo(fpPos, fStack);
933 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
935 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
937 if (SkipWords(fStack->fHeaderSize-6) == kFALSE) { // 6 is the 6 stack header words for 12 links
938 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing");
941 for (Int_t iword=0; iword<6; iword++) { // decode 6 stack header words
942 // Decode Stack Header Word of given stack
943 DecodeStackHeader(fpPos, fStack, iword);
953 if (fgWarnError) AliWarning("No additional sm headers and stack index words present.");
954 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
959 if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");
962 if (fgWarnError) AliWarning("No data just after GTU headers.");
963 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");
967 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));
972 //--------------------------------------------------------
973 void AliTRDrawFastStream::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
976 // decode Stack #i Index Word
977 // The Stack #i Index Word is a 32-Bit word with following structure
978 // ssssssss ssssssss vvvv mmmm mmmmmmmm
979 // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask
981 st->fPos = (UInt_t*)word;
983 UInt_t vword = *word;
984 st->fHeaderSize = STACK_HEADER_SIZE(vword);
986 UInt_t linkMask = STACK_LINK_WORD(vword);
987 st->fActiveLinks = 0;
988 for (Int_t i = 0; i < 12; i++) {
989 if (IS_BIT_SET(linkMask,i) > 0) {
990 st->fLinksActive[i] = kTRUE;
994 st->fLinksActive[i] = kFALSE;
999 //--------------------------------------------------------
1000 void AliTRDrawFastStream::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const
1003 // decode stack header
1005 st->fPos = (UInt_t*)word;
1007 UInt_t vword = *word;
1008 st->fLinksDataType[2*iword] = LINK0_DATA_TYPE_FLAG(vword);
1009 st->fLinksMonitor[2*iword] = LINK0_MONITOR_FLAG(vword);
1010 st->fLinksDataType[2*iword+1] = LINK1_DATA_TYPE_FLAG(vword);
1011 st->fLinksMonitor[2*iword+1] = LINK1_MONITOR_FLAG(vword);
1014 //------------------------------------------------------------
1015 Bool_t AliTRDrawFastStream::DecodeTracklets()
1020 fLinkTrackletCounter = 0; // tracklet counter of this link
1021 fEndOfTrackletCount = 0; // tracklet endmarker counter of this link
1022 fHC->fNTracklets = 0; // number of tracklet of this link, should be less than 256
1024 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
1026 while (!(*fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW) && fpPos < fpEnd) {
1027 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
1029 fLinkTrackletCounter++;
1031 if (fLinkTrackletCounter > MAXTRACKLETSPERHC) {
1032 if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d. Tracklets are wrong either GTU header has problem",
1033 fLinkTrackletCounter, MAXTRACKLETSPERHC));
1034 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
1035 fHC->fErrorCodes[1] = 1;
1039 fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into memory
1043 fHC->fNTracklets = fLinkTrackletCounter;
1045 while ((*fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW) && fpPos < fpEnd) {
1046 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1048 fEndOfTrackletCount++;
1052 if (fEndOfTrackletCount < 2) {
1053 if (fgDebugFlag) AliDebug(11,"End of tracklets word missing");
1054 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1055 fHC->fErrorCodes[1] += 2;
1062 //--------------------------------------------------------
1063 void AliTRDrawFastStream::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
1066 // decode Supermodule Index Word
1067 // The Supermodule Index Word is a 32-Bit word wit following structure
1068 // ssssssss ssssssss vvvv rrrr r d t mmmm
1069 // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use
1070 // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask
1072 sm->fPos = (UInt_t*)word;
1074 UInt_t vword = *word;
1075 sm->fHeaderSize = SM_HEADER_SIZE(vword);
1077 if (TRACKLETS_ENABLED(vword) > 0)
1078 sm->fTrackletEnable = kTRUE;
1080 sm->fTrackletEnable = kFALSE;
1082 UInt_t stackMask = STACK_MASK(vword);
1083 sm->fActiveStacks = 0;
1084 for (Int_t i = 0; i < 5; i++)
1086 if (IS_BIT_SET(stackMask,i) > 0)
1088 sm->fStackActive[i] = kTRUE;
1089 sm->fActiveStacks++;
1093 sm->fStackActive[i] = kFALSE;
1098 //------------------------------------------------------------
1099 Bool_t AliTRDrawFastStream::DecodeHC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits,
1100 AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2,
1101 AliTRDSignalIndex *indexes)
1104 // decode hc header and data
1106 if (fpPos >= fpEnd) {
1107 fHC->fCorrupted += 1;
1108 if (fgWarnError) AliError("No data(including HC header) in the buffer");
1112 if (DecodeHCheader() == kFALSE) {
1113 if (fgWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));
1118 if (fpPos >= fpEnd) {
1119 fHC->fCorrupted += 2;
1120 if (fgWarnError) AliError("No data right after HC header in the buffer");
1125 if ((fHC->fRawVMajor & 64) == 64) { // test pattern data
1126 AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos);
1127 if (tpStream->DecodeTPdata() == kFALSE) {
1128 if (fgWarnError) AliError("Failed to decode test pattern data");
1134 fHC->fMCMmax = 0; // count number of mcms in a hc
1135 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd) {
1137 ResetPerMCM(); // reset for every mcm
1139 if (fHC->fMCMmax > TRDMAXMCM) {
1140 fHC->fCorrupted += 4;
1141 if (fgDebugFlag) AliDebug(11,"More mcm data than expected");
1145 if (DecodeMCMheader() == kFALSE) {
1147 // encode mcm level error codes
1148 fHC->fErrorCodes[fHC->fMCMmax+2] += fMCM.fMCMhdCorrupted;
1149 fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fADCmaskCorrupted << 4);
1150 fHC->fErrorCodes[fHC->fMCMmax+2] += ((fMCM.fDataCorrupted & 1) << 6);
1151 fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fMCM << 7); // encode MCM number
1152 fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fROB << 11); // encode ROB number
1154 fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number
1156 // in case we decide to keep reading data, skip this mcm data and find next mcm header
1157 if (fMCM.fADCmaskCorrupted < 2) {
1158 if (SkipMCMdata(fMCM.fADCcount*fMCM.fSingleADCwords) == kFALSE)
1163 if (SeekNextMCMheader() == kFALSE)
1171 if (fMCM.fADCmax > 0) {
1173 if (fpPos >= fpEnd) {
1174 fHC->fBufferCorrupted = kTRUE;
1175 if (fgDebugFlag) AliDebug(11, Form("Buffer ends in the middle of data"));
1180 for (Int_t iadc = 0; iadc < fMCM.fADCmax; iadc++) {
1181 fADCnumber = fMCM.fADCchannel[iadc];
1182 fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber);
1183 fCOL = fTRDfeeParam->GetPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber);
1185 if (fADCnumber <= 1 || fADCnumber == fMaxADCgeom - 1) // if adc number = 0, 1, 20
1190 if (fpPos + fMCM.fSingleADCwords >= fpEnd) {
1191 fHC->fBufferCorrupted = kTRUE;
1192 if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");
1196 //if (GetGlobalNTimeBins() < 31){
1197 if (fHC->fTimeBins < 31){
1198 if (DecodeADC(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {
1202 //else if (GetGlobalNTimeBins() > 32) {
1203 else if (fHC->fTimeBins > 32) {
1204 if (DecodeADCExtended(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {
1208 else { // nsamples = 31, 32 are not implemented in the TRAP and should never happen
1209 if (fgWarnError) AliError("nsamples are 31 or 32. These are not implemented in the TRAP and should never happen!");
1214 else { // if there is no adc activated
1219 if (fpPos >= fpEnd) {
1220 fHC->fBufferCorrupted = kTRUE;
1221 if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. Not enough data in the buffer.");
1228 //------------------------------------------------------------
1229 Bool_t AliTRDrawFastStream::DecodeHCheader()
1232 // decode the half chamber header
1233 // if it fails to decode HC header for both H0 and H1, return kFALSE
1235 if (DecodeHCwordH0(fpPos, fHC) == kFALSE)
1238 if (fHC->fNExtraWords > 0) {
1240 if (fpPos < fpEnd) {
1241 if (DecodeHCwordH1(fpPos, fHC) == kFALSE)
1245 fHC->fBufferCorrupted = kTRUE;
1246 if (fgDebugFlag) AliDebug(11,"Expected HC header word H1. Fail due to buffer END.");
1251 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1252 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1254 if (IsHCheaderOK() == kFALSE) {
1255 fHC->fH0Corrupted += 2;
1256 if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));
1263 //--------------------------------------------------------
1264 Bool_t AliTRDrawFastStream::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
1267 // decode the hc header word 0
1269 UInt_t vword = *word;
1270 hc->fPos[0] = (UInt_t*)word;
1272 hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword);
1273 if (hc->fH0Corrupted > 0) {
1274 if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%08x",*fHC->fPos ));
1277 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
1278 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
1279 hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword);
1280 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
1281 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
1282 hc->fDCSboard = HC_DCS_BOARD(vword);
1283 hc->fSMHCheader = HC_SM_NUMBER(vword);
1284 hc->fStackHCheader = HC_STACK_NUMBER(vword);
1285 hc->fLayerHCheader = HC_LAYER_NUMBER(vword);
1286 hc->fSideHCheader = HC_SIDE_NUMBER(vword);
1291 //--------------------------------------------------------
1292 Bool_t AliTRDrawFastStream::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
1295 // decode the hc header word 1
1297 UInt_t vword = *word;
1298 hc->fPos[1] = (UInt_t*)word;
1300 hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword);
1301 if (hc->fH1Corrupted > 0) {
1302 if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%08x", *(fHC->fPos+1) ));
1305 hc->fTimeBins = HC_NTIMEBINS(vword);
1306 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
1307 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
1308 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
1313 //------------------------------------------------------------
1314 Bool_t AliTRDrawFastStream::IsHCheaderOK()
1317 // check insanity of half chamber header
1319 if (fHC->fStackHCheader < 0 || fHC->fStackHCheader > 4) {
1320 if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStackHCheader));
1324 if (fHC->fLayerHCheader < 0 || fHC->fLayerHCheader >= AliTRDgeometry::kNlayer) {
1325 if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayerHCheader));
1329 if (fHC->fSideHCheader < 0 || fHC->fSideHCheader > 1) {
1330 if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSideHCheader));
1334 if (fHC->fSMHCheader != fHC->fSM) {
1335 if (fgDebugFlag) AliDebug(11,Form("Missmatch: SM number between HC header %d and GTU link mask %d",
1336 fHC->fSMHCheader, fHC->fSM));
1340 if (fgStackNumberChecker) {
1341 if (fHC->fStackHCheader != fHC->fStack) {
1342 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d",
1343 fHC->fStackHCheader, fHC->fStack));
1348 if (fgStackLinkNumberChecker) {
1349 if (fHC->fLayerHCheader * 2 + fHC->fSideHCheader != fHC->fLayer * 2 + fHC->fSide) {
1350 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s",
1351 fHC->fLayerHCheader, fHC->fLayer, DumpStackInfo(fStack)));
1356 // SLOW GEOM : consistancy check with geometry
1357 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet) {
1358 if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET));
1359 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1363 if (fHC->fSM != fGeometry->GetSector(fHC->fDET) || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector) {
1364 if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1365 fHC->fSM, fGeometry->GetSector(fHC->fDET), fHC->fStack, fHC->fLayer, fHC->fDET));
1366 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1370 if (fHC->fROC < 0) {
1371 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1375 if (fHC->fRowMax < 1) {
1376 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1380 if (fHC->fColMax < 1) {
1381 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1388 //------------------------------------------------------------
1389 Bool_t AliTRDrawFastStream::DecodeMCMheader()
1392 // decode the mcm header
1394 DecodeMCMheader(fpPos, &fMCM);
1396 if (fHC->fEOTECorrupted == kTRUE) {
1401 fMCM.fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM.fROB, fMCM.fMCM);
1403 if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || ((fHC->fRawVMajor & 32) == 32)) { //cover old and new version definition of ZS data
1405 if ( fpPos < fpEnd ) {
1406 DecodeMask(fpPos, &fMCM);
1407 if (fHC->fEOTECorrupted == kTRUE) {
1411 MCMADCwordsWithTbins(fHC->fTimeBins, &fMCM);
1412 fMCM.fAdcDataPos = fpPos + 1;
1415 if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END.");
1416 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1417 fHC->fBufferCorrupted = kTRUE;
1422 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
1423 DecodeMask(&dummyMask, &fMCM);
1424 MCMADCwordsWithTbins(fHC->fTimeBins, &fMCM);
1425 fMCM.fAdcDataPos = fpPos + 1;
1427 if (IsMCMheaderOK() == kFALSE)
1433 //--------------------------------------------------------
1434 void AliTRDrawFastStream::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1437 // decode the mcm header
1439 UInt_t vword = *word;
1441 if (vword == END_OF_TRACKLET_MARKERNEW) {
1442 if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
1443 fHC->fEOTECorrupted = kTRUE; //to finish data reading of this HC
1446 mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error
1447 if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) {
1448 fHC->fDataCorrupted = kTRUE;
1449 AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));
1452 mcm->fROB = MCM_ROB_NUMBER(vword);
1453 mcm->fMCM = MCM_MCM_NUMBER(vword);
1454 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
1455 mcm->fPos = (UInt_t*)word;
1458 //--------------------------------------------------------
1459 UInt_t AliTRDrawFastStream::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1464 UInt_t vword = *word;
1468 mcm->fADCMaskWord = vword;
1470 if (vword == END_OF_TRACKLET_MARKERNEW) {
1471 if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
1472 fHC->fEOTECorrupted = kTRUE; //to finish data reading of this HC
1475 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) {
1476 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
1477 mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
1480 mcm->fADCMask = 0xffffffff;
1481 mcm->fADCmaskCorrupted = 1; // mcm adc mask error
1482 fHC->fDataCorrupted = kTRUE;
1483 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));
1486 return mcm->fADCMask;
1489 //--------------------------------------------------------
1490 void AliTRDrawFastStream::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1493 // decode the adc mask - adcs to be read out
1495 mcm->fMCMADCWords = 0;
1496 mcm->fSingleADCwords = 0;
1498 mcm->fADCMask = GetMCMadcMask(word, mcm);
1500 if (mcm->fADCMask > 0) {
1501 for (Int_t i = 0; i < TRDMAXADC; i++) {
1502 mcm->fADCchannel[mcm->fADCmax] = 0;
1503 if ( IS_BIT_SET(mcm->fADCMask,i) ) {
1504 mcm->fADCchannel[mcm->fADCmax] = i;
1509 if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) { // backward compatibility
1510 mcm->fADCmaskCorrupted += 2;
1511 fHC->fDataCorrupted = kTRUE;
1512 if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n",
1513 mcm->fADCcount, mcm->fADCmax, *fMCM.fPos));
1517 //--------------------------------------------------------
1518 void AliTRDrawFastStream::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
1521 // count the expected mcm words for a given tbins
1523 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
1524 mcm->fSingleADCwords = 0;
1525 if (mcm->fADCmax > 0) {
1526 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
1528 if (fTbins > 32) mcm->fSingleADCwords = 10; // if the timebin is more than 30, then fix the number of adc words to 10
1531 //------------------------------------------------------------
1532 Bool_t AliTRDrawFastStream::IsMCMheaderOK()
1535 // check the mcm header
1537 if (fgLastROB != fMCM.fROB) {
1539 if (fgLastROB== -1) fgLastROB = fMCM.fROB;
1542 Int_t matchingcounter = 0;
1543 for (Int_t i=fgLastIndex+1; i<16; i++) {
1544 if ( fMCM.fMCM == fgMCMordering[i] ) {
1550 if (matchingcounter == 0) {
1551 fMCM.fMCMhdCorrupted += 2;
1552 AliDebug(11,Form("MCM number from last MCM is larger: MCM # from current MCM %d \n", fMCM.fMCM));
1556 if ( fgLastHC == fHC->fLayer*2 + fHC->fSide ) {
1557 if ( fMCM.fROB < fgLastROB ) {
1558 if((fMCM.fMCMhdCorrupted & 2) == 0) fMCM.fMCMhdCorrupted += 2;
1559 AliDebug(11,Form("ROB number from last MCM is larger: ROB # from current MCM %d \n", fMCM.fROB));
1561 else fgLastROB = fMCM.fROB;
1564 fgLastHC = fHC->fLayer*2 + fHC->fSide;
1566 if (fEventCounter == 0) {
1567 fEventCounter = fMCM.fEvCounter;
1570 if (fEventCounter != fMCM.fEvCounter) {
1571 fMCM.fMCMhdCorrupted += 4;
1572 if (fgDebugFlag) AliDebug(11,Form("Event number(%d) of current MCM is different from that(%d) of reference MCM %s.\n"
1573 , fMCM.fEvCounter, fEventCounter, DumpMCMinfo(&fMCM)));
1576 if (fEventCounter < fLastEventCounter) {
1577 fMCM.fMCMhdCorrupted += 8;
1578 if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(&fMCM)));
1581 if ( fMCM.fADCmaskCorrupted > 0 )
1584 if ( fMCM.fMCMhdCorrupted > 0 )
1590 //------------------------------------------------------------
1591 Bool_t AliTRDrawFastStream::DecodeADC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits,
1592 AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2,
1593 AliTRDSignalIndex *indexes)
1596 // decode single ADC channel
1598 if(fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
1599 if(fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
1602 Bool_t isWritten = kFALSE;
1604 for (Int_t iw = 0; iw < fMCM.fSingleADCwords; iw++) {
1605 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {
1606 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1607 fHC->fEOTECorrupted = kTRUE;
1611 if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {
1612 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! [Expected mask: 0x%08x Current mask: 0x%08x] ADC channel number: %02d MCM= %s ",
1613 fMaskADCword, ADC_WORD_MASK(*fpPos), fADCnumber, DumpMCMinfo(&fMCM)));
1614 // encode adc level error codes
1615 Int_t index = 21*(fMCM.fMCM + 16*int(fMCM.fROB/2)) + fADCnumber;
1616 fHC->fErrorCodes[index+66] += 1;
1618 fHC->fErrorCodes[index+66] += (fADCnumber << 4);;
1619 fHC->fErrorCodes[index+66] += (fMCM.fMCM << 9);;
1620 fHC->fErrorCodes[index+66] += (fMCM.fROB << 13);;
1623 fMCM.fDataCorrupted = kTRUE;
1624 fHC->fDataCorrupted = kTRUE;
1628 // decode and put into the digit container
1629 Int_t adcSignals[3];
1630 adcSignals[0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1631 adcSignals[1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1632 adcSignals[2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1634 if(GetCol() < 0 || (!fSharedPadsOn & fIsShared)) {fpPos++; continue;};
1635 for (Int_t i = 0; i < 3; i++) {
1636 if (adcSignals[i] > 0) {
1638 digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcSignals[i]);
1640 digits->SetData(GetRow(), GetCol(), fTbinADC + i, adcSignals[i]);
1641 indexes->AddIndexRC(GetRow(), GetCol());
1643 if (digitsManager->UsesDictionaries()) {
1644 track0->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
1645 track1->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
1646 track2->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
1656 //------------------------------------------------------------
1657 Bool_t AliTRDrawFastStream::DecodeADCExtended(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits,
1658 AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2,
1659 AliTRDSignalIndex *indexes)
1662 // decode single ADC channel
1664 if(fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
1665 if(fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
1667 Bool_t isWritten = kFALSE; //for error code recording
1669 fTbinADC = ((*fpPos & 0x000000fc) >> 2);
1670 fMCM.fSingleADCwords = ((*fpPos & 0x00000f00) >> 8);
1672 Int_t adcFirst2Signals[2];
1673 adcFirst2Signals[0] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1674 adcFirst2Signals[1] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1676 for (Int_t i = 0; i < 2; i++) {
1677 if (adcFirst2Signals[i] > 0) {
1679 digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcFirst2Signals[i]);
1681 digits->SetData(GetRow(), GetCol(), fTbinADC + i, adcFirst2Signals[i]);
1682 indexes->AddIndexRC(GetRow(), GetCol());
1684 if (digitsManager->UsesDictionaries()) {
1685 track0->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
1686 track1->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
1687 track2->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
1692 for (Int_t iw = 0; iw < fMCM.fSingleADCwords-1; iw++) {
1693 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {
1694 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1695 fHC->fEOTECorrupted = kTRUE;
1699 if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {
1700 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! [Expected mask: 0x%08x Current mask: 0x%08x] ADC channel number: %02d MCM= %s ",
1701 fMaskADCword, ADC_WORD_MASK(*fpPos), fADCnumber, DumpMCMinfo(&fMCM)));
1702 // encode adc level error codes
1703 Int_t index = 21*(fMCM.fMCM + 16*int(fMCM.fROB/2)) + fADCnumber;
1704 fHC->fErrorCodes[index+66] += 1;
1706 fHC->fErrorCodes[index+66] += (fADCnumber << 4);;
1707 fHC->fErrorCodes[index+66] += (fMCM.fMCM << 9);;
1708 fHC->fErrorCodes[index+66] += (fMCM.fROB << 13);;
1711 fMCM.fDataCorrupted = kTRUE;
1712 fHC->fDataCorrupted = kTRUE;
1716 // decode and put into the digit container
1717 Int_t adcSignals[3];
1718 adcSignals[0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1719 adcSignals[1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1720 adcSignals[2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1722 if(GetCol() < 0 || (!fSharedPadsOn & fIsShared)) {fpPos++; continue;};
1723 for (Int_t i = 0; i < 3; i++) {
1724 if (adcSignals[i] > 0) {
1726 digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + 2 + i, adcSignals[i]);
1728 digits->SetData(GetRow(), GetCol(), fTbinADC + 2 + i, adcSignals[i]);
1729 indexes->AddIndexRC(GetRow(), GetCol());
1731 if (digitsManager->UsesDictionaries()) {
1732 track0->SetData(GetRow(), GetCol(), fTbinADC + 2 + i, 0);
1733 track1->SetData(GetRow(), GetCol(), fTbinADC + 2 + i, 0);
1734 track2->SetData(GetRow(), GetCol(), fTbinADC + 2 + i, 0);
1744 //------------------------------------------------------------
1745 Bool_t AliTRDrawFastStream::SeekEndOfData()
1748 // go to end of data marker
1750 Int_t fEndOfDataCount = 0;
1753 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
1757 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
1765 //------------------------------------------------------------
1766 Bool_t AliTRDrawFastStream::SeekNextMCMheader()
1773 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
1774 if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0) {
1775 if (fgDebugFlag) AliDebug(11,Form("Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1778 if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {
1779 fHC->fEOTECorrupted = kTRUE;
1789 //------------------------------------------------------------
1790 Bool_t AliTRDrawFastStream::SkipMCMdata(UInt_t iw)
1793 // skip mcm data words due to corruption
1795 if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw));
1796 UInt_t iwcounter = 0;
1797 while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw) {
1798 if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {
1799 if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW");
1800 fHC->fEOTECorrupted = kTRUE;
1807 if (iwcounter == iw) {
1812 if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");
1816 //------------------------------------------------------------
1817 Bool_t AliTRDrawFastStream::SetGlobalNTimebins()
1820 while (SetNTimebins()==kFALSE){
1821 if (fgDebugFlag) AliDebug(11,Form("Failed to get number of time bin information from the %sth HC",nHCs));
1828 //------------------------------------------------------------
1829 Bool_t AliTRDrawFastStream::SetNTimebins()
1831 // goes to the HC header position
1832 while (!(*fpPosTemp == END_OF_TRACKLET_MARKERNEW) && fpPosTemp < fpEnd) {
1835 while (*fpPosTemp == END_OF_TRACKLET_MARKERNEW) {
1841 UInt_t vword = *fpPosTemp;
1843 // get the number of time bins
1844 if (HC_HEADER_MASK_ERR(vword) == 0) {
1845 fGlobalNTimeBins = HC_NTIMEBINS(vword);
1846 if (fGlobalNTimeBins > 64 || fGlobalNTimeBins < 10) return kFALSE; // minimal protection
1854 //------------------------------------------------------------
1855 Bool_t AliTRDrawFastStream::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
1858 // dump given number of words for debugging
1860 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
1861 for (UInt_t i = 0; i < iw; i++) {
1862 if ( iw != 0 && px + iw > fpEnd)
1864 if (i % 8 == 0) tsreturn += "\n ";
1865 if (marker != 0 && marker == px[i]) tsreturn += Form(" *>0x%08x<* ", px[i]);
1866 else tsreturn += Form("0x%08x ", px[i]);
1870 AliInfo(tsreturn.Data());
1875 //--------------------------------------------------------
1876 const char *AliTRDrawFastStream::DumpSMInfo(const struct AliTRDrawSM *sm)
1879 // format the string with the sm info
1881 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
1882 *sm->fPos, sm->fHeaderSize, sm->fTrackletEnable,
1883 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
1884 sm->fStackActive[3], sm->fStackActive[4]);
1887 //--------------------------------------------------------
1888 const char *AliTRDrawFastStream::DumpStackInfo(const struct AliTRDrawStack *st)
1891 // format the string with the stack info
1893 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
1894 *st->fPos, st->fHeaderSize,
1895 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
1896 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
1897 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
1900 //--------------------------------------------------------
1901 const char *AliTRDrawFastStream::DumpHCinfoH0(const struct AliTRDrawHC *hc)
1904 // dump the hc header word 0 in strings
1907 return Form("Unable to dump. Null received as parameter!?!");
1909 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
1910 hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
1913 //--------------------------------------------------------
1914 const char *AliTRDrawFastStream::DumpHCinfoH1(const struct AliTRDrawHC *hc)
1917 // dump the hc header word 1 in strings
1920 return Form("Unable to dump. Null received as parameter!?!");
1922 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
1923 hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
1926 //--------------------------------------------------------
1927 const char *AliTRDrawFastStream::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
1930 // dump mcm info in strings
1933 return Form("Unable to dump. Null received as parameter!?!");
1935 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
1938 //--------------------------------------------------------
1939 const char *AliTRDrawFastStream::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
1942 // mcm adc mask in strings
1945 return Form("Unable to dump. Null received as parameter!?!");
1947 TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
1948 for (Int_t i = 0; i < TRDMAXADC; i++) {
1949 tsreturn += Form("%d ", mcm->fADCchannel[i]);
1952 return tsreturn.Data();