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 "AliTRDrawTPStream.h"
46 #include "AliRawReader.h"
48 #define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa
49 #define END_OF_TRACKLET_MARKERNEW 0x10001000
50 #define ENDOFRAWDATAMARKER 0x00000000
51 #define WORD_SIZE sizeof(UInt_t) // size of a word in bytes
52 #define EXTRA_LEAD_WORDS 24
55 #define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w
56 #define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m
58 // SM index word masks:
59 #define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
60 #define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)
61 #define STACK_MASK(w) ((w) & 0x1f)
64 #define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
65 #define STACK_LINK_WORD(w) ((w) & 0xfff)
66 #define LINK0_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,4) == (0x0) ? 0 : 1) // 0 if physics data
67 #define LINK1_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,20) == (0x0) ? 0 : 1) // 0 if physics data
68 #define LINK0_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,0) == (0x0) ? 0 : 1) // 0 if OK
69 #define LINK1_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,16) == (0x0) ? 0 : 1) // 0 if OK
72 //#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!!
73 #define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK!!!
76 #define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)
77 #define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)
78 #define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24)
79 #define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)
80 #define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)
81 #define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)
82 #define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)
83 #define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)
84 #define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)
85 #define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)
88 #define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)
89 #define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)
90 #define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)
91 #define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,6)
93 // MCM word and ADC mask
94 #define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
95 #define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
96 #define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)
97 #define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)
98 #define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)
99 #define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)
100 #define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25)
102 #define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated
103 #define ADCDATA_VAL1 0x2 // updated
104 #define ADCDATA_VAL2 0x3 // updated
106 //--------------------------------------------------------
107 #define ADC_WORD_MASK(w) ((w) & 0x3)
108 //--------------------------------------------------------
109 ClassImp(AliTRDrawFastStream)
111 Bool_t AliTRDrawFastStream::fgExtraSkip = kFALSE;
112 Bool_t AliTRDrawFastStream::fgSkipCDH = kFALSE;
113 Bool_t AliTRDrawFastStream::fgWarnError = kTRUE;
114 Bool_t AliTRDrawFastStream::fgCleanDataOnly = kFALSE;
115 Bool_t AliTRDrawFastStream::fgDebugFlag = kTRUE;
116 Bool_t AliTRDrawFastStream::fgEnableMemoryReset = kTRUE;
117 Bool_t AliTRDrawFastStream::fgStackNumberChecker = kTRUE;
118 Bool_t AliTRDrawFastStream::fgStackLinkNumberChecker = kTRUE;
119 Bool_t AliTRDrawFastStream::fgSkipData = kTRUE;
120 Bool_t AliTRDrawFastStream::fgEnableDecodeConfigData = kFALSE;
121 Int_t AliTRDrawFastStream::fgDumpHead = -1;
122 Int_t AliTRDrawFastStream::fgCommonAdditive = 0;
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()
154 , fStackLinkNumber(-1)
155 , fLinkTrackletCounter(-1)
156 , fEndOfTrackletCount(-1)
161 , fLastEventCounter(0)
162 , fSharedPadsOn(kTRUE)
174 // default constructor
177 if (Init() == kFALSE) {
178 AliWarning("Unable to Init.");
182 //--------------------------------------------------------
183 AliTRDrawFastStream::AliTRDrawFastStream(AliRawReader *rawReader)
184 : AliTRDrawStreamBase(rawReader)
194 , fStackLinkNumber(-1)
195 , fLinkTrackletCounter(-1)
196 , fEndOfTrackletCount(-1)
201 , fLastEventCounter(0)
202 , fSharedPadsOn(kTRUE)
210 , fRawReader(rawReader)
214 // default constructor
217 if (Init() == kFALSE) {
218 AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
222 AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
226 //------------------------------------------------------------
227 AliTRDrawFastStream::AliTRDrawFastStream(const AliTRDrawFastStream& /*st*/)
228 : AliTRDrawStreamBase()
238 , fStackLinkNumber(-1)
239 , fLinkTrackletCounter(-1)
240 , fEndOfTrackletCount(-1)
245 , fLastEventCounter(0)
246 , fSharedPadsOn(kTRUE)
260 AliError("Not implemeneted.");
263 //------------------------------------------------------------
264 Bool_t AliTRDrawFastStream::SetRawVersion(Int_t fraw)
267 // function provided for backward compatibility
269 AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");
270 fraw = 0; // avoid warnings
274 //------------------------------------------------------------
275 AliTRDrawFastStream::~AliTRDrawFastStream()
283 //------------------------------------------------------------
285 AliTRDrawFastStream &
286 AliTRDrawFastStream::operator=(const AliTRDrawFastStream &)
289 // we are not using this functionality
291 AliFatal("May not use.");
295 //___________________________________________________________
296 void AliTRDrawFastStream::SwapOnEndian()
299 // Check the endian and swap if needed
302 char* ptemp = (char*) &itemp;
305 if (fgDebugFlag) AliDebug(8, "Swapping.");
309 while (fpPos < fpEnd)
312 iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
313 ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
314 // here we override the value in the buffer!
321 //------------------------------------------------------------
322 Bool_t AliTRDrawFastStream::SkipWords(UInt_t iw)
325 // Skip words corresponding to iw
327 if ( fpPos + iw < fpEnd ) {
332 if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
339 //------------------------------------------------------------
340 Bool_t AliTRDrawFastStream::SetReader(AliRawReader *reader)
349 AliWarning("Unable to setup reader.");
354 AliWarning("AliRawReader argument is 0.");
361 //------------------------------------------------------------
362 Int_t AliTRDrawFastStream::NextBuffer()
365 // return -1 if no more buffers available
366 // return 0 if SMHeader decoding failed
367 // return 1 if SMHeader dedoding is OK
369 if (fRawReader != 0) {
372 Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
373 if (kBufferSet == kTRUE) {
374 if (fgDebugFlag) AliDebug(9, "Buffer is set.");
375 length = fRawReader->GetDataSize();
376 if (fgExtraSkip == kTRUE) {
377 buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
378 length -= EXTRA_LEAD_WORDS * WORD_SIZE;
381 if (fgSkipCDH == kTRUE) {
382 buffer += CDH_WORDS * WORD_SIZE;
383 length -= CDH_WORDS * WORD_SIZE;
387 if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
388 if (fgEnableMemoryReset) ResetMemory();
389 if (DecodeSMHeader((void*)buffer, length) == kTRUE)
403 //------------------------------------------------------------
404 void AliTRDrawFastStream::ResetCounters()
407 // reset some global counters
409 fBufferRead = kFALSE; // kFALSE if no buffer read
411 fSM.fActiveStacks = 0;
412 fSM.fNexpectedHalfChambers = 0;
414 fLastEventCounter = 0;
420 //------------------------------------------------------------
421 void AliTRDrawFastStream::ResetIterators()
424 // reset data which should be reset every sm
427 fStackLinkNumber = 0;
430 //------------------------------------------------------------
431 void AliTRDrawFastStream::ResetPerSM()
437 fSM.fTrackletEnable = kFALSE;
439 fSM.fNexpectedHalfChambers = 0;
440 fSM.fNexpectedHalfChambers = 0;
442 for (Int_t i=0; i<5; i++) {
443 fSM.fStackActive[i] = kFALSE;
447 //------------------------------------------------------------
448 void AliTRDrawFastStream::ResetPerStack()
453 fStack->fHeaderSize = 0;
454 fStack->fActiveLinks = 0;
456 for (Int_t i=0; i<12; i++) {
457 fStack->fLinksActive[i] = kFALSE;
458 fStack->fLinksDataType[i] = 0;
459 fStack->fLinksMonitor[i] = 0;
460 fStack->fLinkMonitorError[i] = 0;
464 //------------------------------------------------------------
465 void AliTRDrawFastStream::ResetPerHC()
471 fHC->fNTracklets = 0;
472 fHC->fSpecialRawV = 0;
474 fHC->fRawVMajorOpt = 0;
476 fHC->fNExtraWords = 0;
479 fHC->fBunchCrossCounter = 0;
480 fHC->fPreTriggerCounter = 0;
481 fHC->fPreTriggerPhase = 0;
486 fHC->fStackHCheader = 0;
488 fHC->fLayerHCheader = 0;
490 fHC->fSideHCheader = 0;
496 fHC->fH0Corrupted = 0;
497 fHC->fH1Corrupted = 0;
499 fHC->fEOTECorrupted = kFALSE;
500 fHC->fBufferCorrupted = kFALSE;
501 fHC->fDataCorrupted = kFALSE;
504 memset(fHC->fErrorCodes, 0, 1411*sizeof(UShort_t)); // initialize error container
505 memset(fHC->fTrackletWords, 0, MAXTRACKLETSPERHC*sizeof(UInt_t)); // initialize tracklet container
508 //------------------------------------------------------------
509 void AliTRDrawFastStream::ResetPerMCM()
519 fMCM.fADCMaskWord = 0;
522 fMCM.fMCMADCWords = 0;
523 fMCM.fSingleADCwords = 0;
524 fMCM.fMCMhdCorrupted = 0;
525 fMCM.fADCmaskCorrupted = 0;
526 fMCM.fDataCorrupted = kFALSE;
528 fMCM.fAdcDataPos = NULL;
529 fMCM.fADCcounter = 0;
531 memset(fMCM.fADCchannel, 0, TRDMAXADC*sizeof(UInt_t));
534 //------------------------------------------------------------
535 void AliTRDrawFastStream::ResetMemory()
538 // initialize all the data members to prevent read data
539 // from previous buffer
542 for (Int_t istack=0; istack<5; istack++) {
543 fStack = &fSM.fStacks[istack];
545 for (Int_t ilink=0; ilink<12; ilink++) {
546 fHC = &fStack->fHalfChambers[ilink];
552 //------------------------------------------------------------
553 Bool_t AliTRDrawFastStream::Next()
556 // returns with true on next adc read, returns false on errors and end of buffer
559 while (fStackNumber < 5 && fSM.fActiveStacks > 0) {
560 if (fSM.fStackActive[fStackNumber] == kTRUE) {
561 fStack = &fSM.fStacks[fStackNumber];
562 while (fStackLinkNumber < 12) {
563 if (fStack->fLinksActive[fStackLinkNumber] == kTRUE) {
564 //if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0)
565 fHC = &fStack->fHalfChambers[fStackLinkNumber];
566 //ResetPerHC(); // [mj - you don't need to do? ]
568 AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
574 else fStackLinkNumber++;
575 } //stack link number loop
578 fStackLinkNumber = 0;
579 } //stack number loop
582 // go for the next buffer
584 Int_t nextBuff = NextBuffer();
585 while (nextBuff != -1) {
590 nextBuff = NextBuffer();
597 //------------------------------------------------------------
598 Int_t AliTRDrawFastStream::NextChamber(AliTRDdigitsManager *digitsManager, UInt_t **trackletContainer, UShort_t **errorCodeContainer)
602 // Fills single chamber digit array
603 // Return value is the detector number
605 // first of all, you do the SM header decoding only at the beginning of the SM data reading
606 // then, every HC, you call Next() which points next HC. then, there you decode the given HC
607 // and at the same time, put the digit into digitmanager
609 AliTRDarrayADC *digits = 0;
610 AliTRDarrayDictionary *track0 = 0;
611 AliTRDarrayDictionary *track1 = 0;
612 AliTRDarrayDictionary *track2 = 0;
613 AliTRDSignalIndex *indexes = 0;
619 Int_t ntracklets = 0;
622 if (trackletContainer){
623 for (Int_t i = 0; i < 2; i++)
624 memset(trackletContainer[i], 0, MAXTRACKLETSPERHC*sizeof(UInt_t));
627 if (errorCodeContainer){
628 for (Int_t i = 0; i < 2; i++)
629 memset(errorCodeContainer[i], 0, 1411*sizeof(UShort_t));
632 while ( Next() ) { // loop over HC
634 // get this information from the GTU header
638 if (det != lastdet) {
639 // If new detector found
640 if (lastdet == -1) lastdet = det;
641 else {fStackLinkNumber--; return lastdet;}
643 if (det < 0 || det >= AliTRDgeometry::kNdet) continue;
645 // Add a container for the digits of this detector
646 digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);
648 if (digitsManager->UsesDictionaries()) {
649 track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);
650 track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);
651 track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);
654 if (!digits) return -1;
656 Int_t rowMax = GetRowMax();
657 Int_t colMax = GetColMax();
658 //Int_t ntbins = GetNumberOfTimeBins();
659 Int_t ntbins = 30; //[mj temp]
661 // Allocate memory space for the digits buffer
662 if (digits->GetNtime() == 0) {
663 digits->Allocate(rowMax, colMax, ntbins);
664 if (digitsManager->UsesDictionaries()) {
665 track0->Allocate(rowMax, colMax, ntbins);
666 track1->Allocate(rowMax, colMax, ntbins);
667 track2->Allocate(rowMax, colMax, ntbins);
671 indexes = digitsManager->GetIndexes(det);
672 indexes->SetSM(GetSM());
673 indexes->SetStack(GetStack());
674 indexes->SetLayer(GetLayer());
675 indexes->SetDetNumber(det);
676 if (indexes->IsAllocated() == kFALSE)
677 indexes->Allocate(rowMax, colMax, ntbins);
680 if (fSM.fTrackletEnable == kTRUE) {
681 if (DecodeTracklets() == kFALSE) {
684 if (fgWarnError) AliError(Form("Tracklet decoding failed stack %d link %d", GetStack(), fStackLinkNumber));
686 // copy error codes in memory into error container
687 if (errorCodeContainer) {
688 nErrors = GetNErrors();
689 if(nErrors > 0) memcpy(errorCodeContainer[side], GetErrorCodes(), sizeof(UShort_t) * 1411); // [mj temp - optimize]
692 continue; // if it fails to decode tracklets of this HC, it skips further decoding and goes to next HC
697 fgLastROB = -1; // to check mcm number odering
698 fgLastIndex = -1 ; // to check mcm number odering
699 if (DecodeHC(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {
700 // encode HC error code
701 fHC->fErrorCodes[2] += fHC->fH0Corrupted;
702 fHC->fErrorCodes[2] += (fHC->fH1Corrupted << 2);
703 fHC->fErrorCodes[2] += (fHC->fCorrupted << 3);
704 fHC->fErrorCodes[2] += ((fHC->fBufferCorrupted & 1) << 6);
705 fHC->fErrorCodes[2] += ((fHC->fEOTECorrupted & 1) << 7);
706 fHC->fErrorCodes[2] += ((fHC->fDataCorrupted & 1) << 8);
708 if (fHC->fEOTECorrupted != kTRUE) SeekEndOfData();
712 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
713 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
717 else SeekEndOfData(); // make sure that finish off with the end of data markers
719 // copy tracklets in memory into tracklet container
720 if (trackletContainer) {
721 ntracklets = GetNTracklets();
722 // copy tracklet words to trackletContainer array
723 if(ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets);
726 // copy error codes in memory into error container
727 if (errorCodeContainer) {
728 nErrors = GetNErrors();
729 if(nErrors > 0) memcpy(errorCodeContainer[side], GetErrorCodes(), sizeof(UShort_t) * 1411);
737 //------------------------------------------------------------
738 Bool_t AliTRDrawFastStream::Init()
741 // Initialize geometry and fee parameters
743 TDirectory *saveDir = gDirectory;
746 fGeometry = new AliTRDgeometry();
750 AliError("Geometry FAILED!");
754 fTRDfeeParam = AliTRDfeeParam::Instance();
756 AliError("AliTRDfeeParam FAILED!");
760 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
762 ResetCounters(); // fBufferRead is set to kFALSE - important
769 //------------------------------------------------------------
770 Bool_t AliTRDrawFastStream::InitBuffer(void *buffer, UInt_t length)
773 // set initial information about the buffer
775 if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));
776 if (fRawReader->GetEquipmentId()<1024 || fRawReader->GetEquipmentId()>1041)
781 fpBegin = (UInt_t *)buffer;
783 if (WORD_SIZE == 0) {
784 AliFatal("Strange word size. size of UInt_t == 0");
788 fWordLength = length/WORD_SIZE;
789 fpEnd = fpBegin + fWordLength;
792 if (fpBegin == 0 || length <= 0) {
793 AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%08x of size %d", fpBegin, length));
799 if (fgDumpHead >= 0) {
800 if ( fgDumpHead == 0 ) { // dump all words
801 AliInfo(Form("---------- Dumping all words from the beginnig of the buffer ----------"));
802 if (DumpWords(fpBegin, fWordLength) == kFALSE) AliError("Dump failed. Not enough data.");
805 AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));
806 if (DumpWords(fpBegin, fgDumpHead) == kFALSE) AliError("Dump failed. Not enough data.");
808 AliInfo(Form("---------- Dumping ended ----------------------------------------------"));
814 //------------------------------------------------------------
815 Bool_t AliTRDrawFastStream::DecodeSMHeader(void *buffer, UInt_t length)
818 // decode one sm data in buffer
822 if (InitBuffer(buffer, length) == kFALSE) {
823 if (fgWarnError) AliError("InitBuffer failed.");
827 if (DecodeGTUheader()== kFALSE)
830 for (Int_t istack = 0; istack < 5; istack++) {
831 fStackNumber = istack;
832 if (fSM.fStackActive[istack] == kFALSE) continue;
834 fStack = &fSM.fStacks[istack];
836 fgLastHC = -1; // to check rob number odering
837 for (Int_t ilink = 0; ilink < 12; ilink++) {
838 fStackLinkNumber = ilink;
839 if (fStack->fLinksActive[ilink] == kFALSE) continue;
841 // check GTU link monitor
842 if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0)) {
843 fStack->fLinkMonitorError[ilink] = 1;
844 fStack->fLinkMonitorError[ilink] += fNWordsCounter; // counts words of given hc having link monitor error
848 if (fpPos >= fpEnd) {
849 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
850 if (fgWarnError) AliError("Link data missing.");
854 // HLT streamer set det number using SM header
855 fHC = &fStack->fHalfChambers[ilink];
856 fHC->fSM = fRawReader->GetEquipmentId() - 1024;
857 fHC->fStack = fStackNumber;
858 fHC->fLayer = Int_t(fStackLinkNumber/2.);
859 fHC->fSide = fStackLinkNumber%2;
860 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
861 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
862 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
863 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
867 ResetIterators(); // need to do it again for Next() function
872 //------------------------------------------------------------
873 Bool_t AliTRDrawFastStream::DecodeGTUheader()
876 // decode Supermodule Index Word
878 DecodeSMInfo(fpPos, &fSM);
880 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
884 // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design.
885 // For the moment, we skip decoding these words
886 if (SkipWords(fSM.fHeaderSize) == kTRUE) {
887 for (Int_t istack = 0; istack < 5; istack++) {
888 if (fSM.fStackActive[istack] == kFALSE)
891 fStack = &fSM.fStacks[istack];
893 // Decode Stack Index Word of given stack
894 DecodeStackInfo(fpPos, fStack);
897 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
899 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
901 if (SkipWords(fStack->fHeaderSize-6) == kFALSE) { // 6 is the 6 stack header words for 12 links
902 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing");
905 for (Int_t iword=0; iword<6; iword++) { // decode 6 stack header words
906 // Decode Stack Header Word of given stack
907 DecodeStackHeader(fpPos, fStack, iword);
917 if (fgWarnError) AliWarning("No additional sm headers and stack index words present.");
918 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
923 if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");
926 if (fgWarnError) AliWarning("No data just after GTU headers.");
927 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");
931 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));
936 //--------------------------------------------------------
937 void AliTRDrawFastStream::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
940 // decode Stack #i Index Word
941 // The Stack #i Index Word is a 32-Bit word with following structure
942 // ssssssss ssssssss vvvv mmmm mmmmmmmm
943 // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask
945 st->fPos = (UInt_t*)word;
947 UInt_t vword = *word;
948 st->fHeaderSize = STACK_HEADER_SIZE(vword);
950 UInt_t linkMask = STACK_LINK_WORD(vword);
951 st->fActiveLinks = 0;
952 for (Int_t i = 0; i < 12; i++) {
953 if (IS_BIT_SET(linkMask,i) > 0) {
954 st->fLinksActive[i] = kTRUE;
958 st->fLinksActive[i] = kFALSE;
963 //--------------------------------------------------------
964 void AliTRDrawFastStream::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const
967 // decode stack header
969 st->fPos = (UInt_t*)word;
971 UInt_t vword = *word;
972 st->fLinksDataType[2*iword] = LINK0_DATA_TYPE_FLAG(vword);
973 st->fLinksMonitor[2*iword] = LINK0_MONITOR_FLAG(vword);
974 st->fLinksDataType[2*iword+1] = LINK1_DATA_TYPE_FLAG(vword);
975 st->fLinksMonitor[2*iword+1] = LINK1_MONITOR_FLAG(vword);
978 //------------------------------------------------------------
979 Bool_t AliTRDrawFastStream::DecodeTracklets()
984 fLinkTrackletCounter = 0; // tracklet counter of this link
985 fEndOfTrackletCount = 0; // tracklet endmarker counter of this link
986 fHC->fNTracklets = 0; // number of tracklet of this link, should be less than 256
988 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
990 while (!(*fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW) && fpPos < fpEnd) {
991 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
993 fLinkTrackletCounter++;
995 if (fLinkTrackletCounter > MAXTRACKLETSPERHC) {
996 if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d. Tracklets are wrong either GTU header has problem",
997 fLinkTrackletCounter, MAXTRACKLETSPERHC));
998 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
999 fHC->fErrorCodes[1] = 1;
1003 fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into memory
1007 fHC->fNTracklets = fLinkTrackletCounter;
1009 while ((*fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW) && fpPos < fpEnd) {
1010 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1012 fEndOfTrackletCount++;
1016 if (fEndOfTrackletCount < 2) {
1017 if (fgDebugFlag) AliDebug(11,"End of tracklets word missing");
1018 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1019 fHC->fErrorCodes[1] += 2;
1026 //--------------------------------------------------------
1027 void AliTRDrawFastStream::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
1030 // decode Supermodule Index Word
1031 // The Supermodule Index Word is a 32-Bit word wit following structure
1032 // ssssssss ssssssss vvvv rrrr r d t mmmm
1033 // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use
1034 // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask
1036 sm->fPos = (UInt_t*)word;
1038 UInt_t vword = *word;
1039 sm->fHeaderSize = SM_HEADER_SIZE(vword);
1041 if (TRACKLETS_ENABLED(vword) > 0)
1042 sm->fTrackletEnable = kTRUE;
1044 sm->fTrackletEnable = kFALSE;
1046 UInt_t stackMask = STACK_MASK(vword);
1047 sm->fActiveStacks = 0;
1048 for (Int_t i = 0; i < 5; i++)
1050 if (IS_BIT_SET(stackMask,i) > 0)
1052 sm->fStackActive[i] = kTRUE;
1053 sm->fActiveStacks++;
1057 sm->fStackActive[i] = kFALSE;
1062 //------------------------------------------------------------
1063 Bool_t AliTRDrawFastStream::DecodeHC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits,
1064 AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2,
1065 AliTRDSignalIndex *indexes)
1068 // decode hc header and data
1070 if (fpPos >= fpEnd) {
1071 fHC->fCorrupted += 1;
1072 if (fgWarnError) AliError("No data(including HC header) in the buffer");
1076 if (DecodeHCheader() == kFALSE) {
1077 if (fgWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));
1082 if (fpPos >= fpEnd) {
1083 fHC->fCorrupted += 2;
1084 if (fgWarnError) AliError("No data right after HC header in the buffer");
1089 if ((fHC->fRawVMajor & 64) == 64) { // test pattern data
1090 AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos);
1091 if (tpStream->DecodeTPdata() == kFALSE) {
1092 if (fgWarnError) AliError("Failed to decode test pattern data");
1098 fHC->fMCMmax = 0; // count number of mcms in a hc
1099 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd) {
1101 ResetPerMCM(); // reset for every mcm
1103 if (fHC->fMCMmax > TRDMAXMCM) {
1104 fHC->fCorrupted += 4;
1105 if (fgDebugFlag) AliDebug(11,"More mcm data than expected");
1109 if (DecodeMCMheader() == kFALSE) {
1111 // encode mcm level error codes
1112 fHC->fErrorCodes[fHC->fMCMmax+2] += fMCM.fMCMhdCorrupted;
1113 fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fADCmaskCorrupted << 4);
1114 fHC->fErrorCodes[fHC->fMCMmax+2] += ((fMCM.fDataCorrupted & 1) << 6);
1115 fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fMCM << 7); // encode MCM number
1116 fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fROB << 11); // encode ROB number
1118 fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number
1120 // in case we decide to keep reading data, skip this mcm data and find next mcm header
1121 if (fMCM.fADCmaskCorrupted < 2) {
1122 if (SkipMCMdata(fMCM.fADCcount*fMCM.fSingleADCwords) == kFALSE)
1127 if (SeekNextMCMheader() == kFALSE)
1135 if (fMCM.fADCmax > 0) {
1137 if (fpPos >= fpEnd) {
1138 fHC->fBufferCorrupted = kTRUE;
1139 if (fgDebugFlag) AliDebug(11, Form("Buffer ends in the middle of data"));
1144 for (Int_t iadc = 0; iadc < fMCM.fADCmax; iadc++) {
1145 fADCnumber = fMCM.fADCchannel[iadc];
1147 if ( fADCnumber >= fMaxADCgeom - 1) {
1148 fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber-1);
1150 fCOL = fTRDfeeParam->GetPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber-1);
1154 fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber);
1155 fCOL = fTRDfeeParam->GetPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber);
1158 if (fADCnumber <= 1 || fADCnumber == fMaxADCgeom - 1) // if adc number = 0, 1, 20
1163 if (fpPos + fMCM.fSingleADCwords >= fpEnd) {
1164 fHC->fBufferCorrupted = kTRUE;
1165 if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");
1169 if (DecodeADC(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {
1174 else { // if there is no adc activated
1179 if (fpPos >= fpEnd) {
1180 fHC->fBufferCorrupted = kTRUE;
1181 if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. Not enough data in the buffer.");
1188 //------------------------------------------------------------
1189 Bool_t AliTRDrawFastStream::DecodeHCheader()
1192 // decode the half chamber header
1193 // if it fails to decode HC header for both H0 and H1, return kFALSE
1195 if (DecodeHCwordH0(fpPos, fHC) == kFALSE)
1198 if (fHC->fNExtraWords > 0) {
1200 if (fpPos < fpEnd) {
1201 if (DecodeHCwordH1(fpPos, fHC) == kFALSE)
1205 fHC->fBufferCorrupted = kTRUE;
1206 if (fgDebugFlag) AliDebug(11,"Expected HC header word H1. Fail due to buffer END.");
1211 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1212 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1214 if (IsHCheaderOK() == kFALSE) {
1215 fHC->fH0Corrupted += 2;
1216 if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));
1223 //--------------------------------------------------------
1224 Bool_t AliTRDrawFastStream::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
1227 // decode the hc header word 0
1229 UInt_t vword = *word;
1230 hc->fPos[0] = (UInt_t*)word;
1232 hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword);
1233 if (hc->fH0Corrupted > 0) {
1234 if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%08x",*fHC->fPos ));
1237 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
1238 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
1239 hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword);
1240 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
1241 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
1242 hc->fDCSboard = HC_DCS_BOARD(vword);
1243 hc->fSMHCheader = HC_SM_NUMBER(vword);
1244 hc->fStackHCheader = HC_STACK_NUMBER(vword);
1245 hc->fLayerHCheader = HC_LAYER_NUMBER(vword);
1246 hc->fSideHCheader = HC_SIDE_NUMBER(vword);
1251 //--------------------------------------------------------
1252 Bool_t AliTRDrawFastStream::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
1255 // decode the hc header word 1
1257 UInt_t vword = *word;
1258 hc->fPos[1] = (UInt_t*)word;
1260 hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword);
1261 if (hc->fH1Corrupted > 0) {
1262 if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%08x", *(fHC->fPos+1) ));
1265 hc->fTimeBins = HC_NTIMEBINS(vword);
1266 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
1267 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
1268 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
1273 //------------------------------------------------------------
1274 Bool_t AliTRDrawFastStream::IsHCheaderOK()
1277 // check insanity of half chamber header
1279 if (fHC->fStackHCheader < 0 || fHC->fStackHCheader > 4) {
1280 if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStackHCheader));
1284 if (fHC->fLayerHCheader < 0 || fHC->fLayerHCheader >= AliTRDgeometry::kNlayer) {
1285 if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayerHCheader));
1289 if (fHC->fSideHCheader < 0 || fHC->fSideHCheader > 1) {
1290 if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSideHCheader));
1294 if (fHC->fSMHCheader != fHC->fSM) {
1295 if (fgDebugFlag) AliDebug(11,Form("Missmatch: SM number between HC header %d and GTU link mask %d",
1296 fHC->fSMHCheader, fHC->fSM));
1300 if (fgStackNumberChecker) {
1301 if (fHC->fStackHCheader != fHC->fStack) {
1302 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d",
1303 fHC->fStackHCheader, fHC->fStack));
1308 if (fgStackLinkNumberChecker) {
1309 if (fHC->fLayerHCheader != fHC->fLayer) {
1310 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s",
1311 fHC->fLayerHCheader, fHC->fLayer, DumpStackInfo(fStack)));
1316 // SLOW GEOM : consistancy check with geometry
1317 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet) {
1318 if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET));
1319 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1323 if (fHC->fSM != fGeometry->GetSector(fHC->fDET) || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector) {
1324 if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1325 fHC->fSM, fGeometry->GetSector(fHC->fDET), fHC->fStack, fHC->fLayer, fHC->fDET));
1326 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1330 if (fHC->fROC < 0) {
1331 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1335 if (fHC->fRowMax < 1) {
1336 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1340 if (fHC->fColMax < 1) {
1341 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1348 //------------------------------------------------------------
1349 Bool_t AliTRDrawFastStream::DecodeMCMheader()
1352 // decode the mcm header
1354 DecodeMCMheader(fpPos, &fMCM);
1356 if (fHC->fEOTECorrupted == kTRUE) {
1361 fMCM.fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM.fROB, fMCM.fMCM);
1363 if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || ((fHC->fRawVMajor & 32) == 32)) { //cover old and new version definition of ZS data
1365 if ( fpPos < fpEnd ) {
1366 DecodeMask(fpPos, &fMCM);
1367 if (fHC->fEOTECorrupted == kTRUE) {
1371 MCMADCwordsWithTbins(fHC->fTimeBins, &fMCM);
1372 fMCM.fAdcDataPos = fpPos + 1;
1375 if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END.");
1376 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1377 fHC->fBufferCorrupted = kTRUE;
1382 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
1383 DecodeMask(&dummyMask, &fMCM);
1384 MCMADCwordsWithTbins(fHC->fTimeBins, &fMCM);
1385 fMCM.fAdcDataPos = fpPos + 1;
1387 if (IsMCMheaderOK() == kFALSE)
1393 //--------------------------------------------------------
1394 void AliTRDrawFastStream::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1397 // decode the mcm header
1399 UInt_t vword = *word;
1401 if (vword == END_OF_TRACKLET_MARKERNEW) {
1402 if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
1403 fHC->fEOTECorrupted = kTRUE; //to finish data reading of this HC
1406 mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error
1407 if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) {
1408 fHC->fDataCorrupted = kTRUE;
1409 AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));
1412 mcm->fROB = MCM_ROB_NUMBER(vword);
1413 mcm->fMCM = MCM_MCM_NUMBER(vword);
1414 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
1415 mcm->fPos = (UInt_t*)word;
1418 //--------------------------------------------------------
1419 UInt_t AliTRDrawFastStream::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1424 UInt_t vword = *word;
1428 mcm->fADCMaskWord = vword;
1430 if (vword == END_OF_TRACKLET_MARKERNEW) {
1431 if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
1432 fHC->fEOTECorrupted = kTRUE; //to finish data reading of this HC
1435 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) {
1436 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
1437 mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
1440 mcm->fADCMask = 0xffffffff;
1441 mcm->fADCmaskCorrupted = 1; // mcm adc mask error
1442 fHC->fDataCorrupted = kTRUE;
1443 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));
1446 return mcm->fADCMask;
1449 //--------------------------------------------------------
1450 void AliTRDrawFastStream::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1453 // decode the adc mask - adcs to be read out
1455 mcm->fMCMADCWords = 0;
1456 mcm->fSingleADCwords = 0;
1458 mcm->fADCMask = GetMCMadcMask(word, mcm);
1460 if (mcm->fADCMask > 0) {
1461 for (Int_t i = 0; i < TRDMAXADC; i++) {
1462 mcm->fADCchannel[mcm->fADCmax] = 0;
1463 if ( IS_BIT_SET(mcm->fADCMask,i) ) {
1464 mcm->fADCchannel[mcm->fADCmax] = i;
1469 if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) { // backward compatibility
1470 mcm->fADCmaskCorrupted += 2;
1471 fHC->fDataCorrupted = kTRUE;
1472 if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n",
1473 mcm->fADCcount, mcm->fADCmax, *fMCM.fPos));
1477 //--------------------------------------------------------
1478 void AliTRDrawFastStream::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
1481 // count the expected mcm words for a given tbins
1483 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
1484 mcm->fSingleADCwords = 0;
1485 if (mcm->fADCmax > 0) {
1486 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
1490 //------------------------------------------------------------
1491 Bool_t AliTRDrawFastStream::IsMCMheaderOK()
1494 // check the mcm header
1496 if (fgLastROB != fMCM.fROB) {
1498 if (fgLastROB== -1) fgLastROB = fMCM.fROB;
1501 Int_t matchingcounter = 0;
1502 for (Int_t i=fgLastIndex+1; i<16; i++) {
1503 if ( fMCM.fMCM == fgMCMordering[i] ) {
1509 if (matchingcounter == 0) {
1510 fMCM.fMCMhdCorrupted += 2;
1511 AliDebug(11,Form("MCM number from last MCM is larger: MCM # from current MCM %d \n", fMCM.fMCM));
1515 if ( fgLastHC == fHC->fLayer*2 + fHC->fSide ) {
1516 if ( fMCM.fROB < fgLastROB ) {
1517 if((fMCM.fMCMhdCorrupted & 2) == 0) fMCM.fMCMhdCorrupted += 2;
1518 AliDebug(11,Form("ROB number from last MCM is larger: ROB # from current MCM %d \n", fMCM.fROB));
1520 else fgLastROB = fMCM.fROB;
1523 fgLastHC = fHC->fLayer*2 + fHC->fSide;
1525 if (fEventCounter == 0) {
1526 fEventCounter = fMCM.fEvCounter;
1529 if (fEventCounter != fMCM.fEvCounter) {
1530 fMCM.fMCMhdCorrupted += 4;
1531 if (fgDebugFlag) AliDebug(11,Form("Event number(%d) of current MCM is different from that(%d) of reference MCM %s.\n"
1532 , fMCM.fEvCounter, fEventCounter, DumpMCMinfo(&fMCM)));
1535 if (fEventCounter < fLastEventCounter) {
1536 fMCM.fMCMhdCorrupted += 8;
1537 if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(&fMCM)));
1540 if ( fMCM.fADCmaskCorrupted > 0 )
1543 if ( fMCM.fMCMhdCorrupted > 0 )
1549 //------------------------------------------------------------
1550 Bool_t AliTRDrawFastStream::DecodeADC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits,
1551 AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2,
1552 AliTRDSignalIndex *indexes)
1555 // decode single ADC channel
1557 if(fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
1558 if(fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
1561 Bool_t isWritten = kFALSE;
1563 for (Int_t iw = 0; iw < fMCM.fSingleADCwords; iw++) {
1564 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {
1565 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1566 fHC->fEOTECorrupted = kTRUE;
1570 if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {
1571 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! [Expected mask: 0x%08x Current mask: 0x%08x] ADC channel number: %02d MCM= %s ",
1572 fMaskADCword, ADC_WORD_MASK(*fpPos), fADCnumber, DumpMCMinfo(&fMCM)));
1573 // encode adc level error codes
1574 Int_t index = 21*(fMCM.fMCM + 16*int(fMCM.fROB/2)) + fADCnumber;
1575 fHC->fErrorCodes[index+66] += 1;
1577 fHC->fErrorCodes[index+66] += (fADCnumber << 4);;
1578 fHC->fErrorCodes[index+66] += (fMCM.fMCM << 9);;
1579 fHC->fErrorCodes[index+66] += (fMCM.fROB << 13);;
1582 fMCM.fDataCorrupted = kTRUE;
1583 fHC->fDataCorrupted = kTRUE;
1587 // decode and put into the digit container
1588 Int_t adcSignals[3];
1589 adcSignals[0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1590 adcSignals[1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1591 adcSignals[2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1593 if(GetCol() < 0 || (!fSharedPadsOn & fIsShared)) {fpPos++; continue;};
1594 for (Int_t i = 0; i < 3; i++) {
1595 if (adcSignals[i] > 0) {
1597 digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcSignals[i]);
1599 digits->SetData(GetRow(), GetCol(), fTbinADC + i, adcSignals[i]);
1600 indexes->AddIndexRC(GetRow(), GetCol());
1602 if (digitsManager->UsesDictionaries()) {
1603 track0->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
1604 track1->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
1605 track2->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
1615 //------------------------------------------------------------
1616 Bool_t AliTRDrawFastStream::SeekEndOfData()
1619 // go to end of data marker
1621 Int_t fEndOfDataCount = 0;
1624 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
1628 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
1636 //------------------------------------------------------------
1637 Bool_t AliTRDrawFastStream::SeekNextMCMheader()
1644 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
1645 if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0) {
1646 if (fgDebugFlag) AliDebug(11,Form("Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1649 if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {
1650 fHC->fEOTECorrupted = kTRUE;
1660 //------------------------------------------------------------
1661 Bool_t AliTRDrawFastStream::SkipMCMdata(UInt_t iw)
1664 // skip mcm data words due to corruption
1666 if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw));
1667 UInt_t iwcounter = 0;
1668 while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw) {
1669 if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {
1670 if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW");
1671 fHC->fEOTECorrupted = kTRUE;
1678 if (iwcounter == iw) {
1683 if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");
1687 //------------------------------------------------------------
1688 Bool_t AliTRDrawFastStream::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
1691 // dump given number of words for debugging
1693 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
1694 for (UInt_t i = 0; i < iw; i++) {
1695 if ( iw != 0 && px + iw > fpEnd)
1697 if (i % 8 == 0) tsreturn += "\n ";
1698 if (marker != 0 && marker == px[i]) tsreturn += Form(" *>0x%08x<* ", px[i]);
1699 else tsreturn += Form("0x%08x ", px[i]);
1703 AliInfo(tsreturn.Data());
1708 //--------------------------------------------------------
1709 const char *AliTRDrawFastStream::DumpSMInfo(const struct AliTRDrawSM *sm)
1712 // format the string with the sm info
1714 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
1715 *sm->fPos, sm->fHeaderSize, sm->fTrackletEnable,
1716 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
1717 sm->fStackActive[3], sm->fStackActive[4]);
1720 //--------------------------------------------------------
1721 const char *AliTRDrawFastStream::DumpStackInfo(const struct AliTRDrawStack *st)
1724 // format the string with the stack info
1726 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
1727 *st->fPos, st->fHeaderSize,
1728 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
1729 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
1730 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
1733 //--------------------------------------------------------
1734 const char *AliTRDrawFastStream::DumpHCinfoH0(const struct AliTRDrawHC *hc)
1737 // dump the hc header word 0 in strings
1740 return Form("Unable to dump. Null received as parameter!?!");
1742 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
1743 hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
1746 //--------------------------------------------------------
1747 const char *AliTRDrawFastStream::DumpHCinfoH1(const struct AliTRDrawHC *hc)
1750 // dump the hc header word 1 in strings
1753 return Form("Unable to dump. Null received as parameter!?!");
1755 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
1756 hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
1759 //--------------------------------------------------------
1760 const char *AliTRDrawFastStream::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
1763 // dump mcm info in strings
1766 return Form("Unable to dump. Null received as parameter!?!");
1768 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
1771 //--------------------------------------------------------
1772 const char *AliTRDrawFastStream::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
1775 // mcm adc mask in strings
1778 return Form("Unable to dump. Null received as parameter!?!");
1780 TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
1781 for (Int_t i = 0; i < TRDMAXADC; i++) {
1782 tsreturn += Form("%d ", mcm->fADCchannel[i]);
1785 return tsreturn.Data();