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: AliTRDrawStream.cxx 27797 2008-08-05 14:37:22Z cblume $ */
18 ///////////////////////////////////////////////////////////////////////////////
20 // This class provides access to TRD digits in raw data. //
22 // It loops over all TRD digits in the raw data given by the AliRawReader. //
23 // The Next method goes to the next digit. If there are no digits left //
24 // it returns kFALSE. //
25 // Several getters provide information about the current digit. //
27 // Author: M. Ploskon (ploskon@ikf.uni-frankfurt.de) //
28 // Author: MinJung Kweon (minjung@physi.uni-heidelberg.de) //
30 ///////////////////////////////////////////////////////////////////////////////
34 //#include "TTreeStream.h"
36 #include "AliTRDrawStream.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) & (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,2)
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 #define ADC_WORD_MASK(w) ((w) & 0x3)
108 //--------------------------------------------------------
109 ClassImp(AliTRDrawStream)
111 Bool_t AliTRDrawStream::fgExtraSkip = kFALSE;
112 Bool_t AliTRDrawStream::fgSkipCDH = kFALSE;
113 Bool_t AliTRDrawStream::fgWarnError = kTRUE;
114 Bool_t AliTRDrawStream::fgCleanDataOnly = kFALSE;
115 Bool_t AliTRDrawStream::fgDebugFlag = kTRUE;
116 Bool_t AliTRDrawStream::fgEnableMemoryReset = kTRUE;
117 Bool_t AliTRDrawStream::fgStackNumberChecker = kTRUE;
118 Bool_t AliTRDrawStream::fgStackLinkNumberChecker = kFALSE;
119 Bool_t AliTRDrawStream::fgSkipData = kTRUE;
120 Bool_t AliTRDrawStream::fgEnableDecodeConfigData = kFALSE;
121 Int_t AliTRDrawStream::fgDumpHead = -1;
122 Int_t AliTRDrawStream::fgEmptySignals[] =
124 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
125 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
127 Short_t AliTRDrawStream::fgMCMordering[] =
129 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3
131 Short_t AliTRDrawStream::fgROBordering[] =
135 Int_t AliTRDrawStream::fgLastHC = -1;
136 Int_t AliTRDrawStream::fgLastROB = -1;
137 Int_t AliTRDrawStream::fgLastIndex = -1;
138 Int_t AliTRDrawStream::fgDumpingSM = -1;
139 Int_t AliTRDrawStream::fgDumpingStack = -1;
140 Int_t AliTRDrawStream::fgDumpingLayer = -1;
141 Int_t AliTRDrawStream::fgDumpingROB = -1;
142 Int_t AliTRDrawStream::fgDumpingMCM = -1;
143 Bool_t AliTRDrawStream::fgDumpingEnable = kFALSE;
146 AliTRDrawStream::AliTRDrawStream()
147 : AliTRDrawStreamBase()
158 , fIsGlobalDigitsParamSet(kFALSE)
160 , fStackLinkNumber(-1)
163 , fLinkTrackletCounter(-1)
164 , fEndOfTrackletCount(-1)
170 , fLastEventCounter(0)
171 , fSharedPadsOn(kTRUE)
179 // default constructor
181 if (Init() == kFALSE) {
182 AliWarning("Unable to Init.");
186 //--------------------------------------------------------
187 AliTRDrawStream::AliTRDrawStream(AliRawReader *rawReader)
188 : AliTRDrawStreamBase(rawReader)
199 , fIsGlobalDigitsParamSet(kFALSE)
201 , fStackLinkNumber(-1)
204 , fLinkTrackletCounter(-1)
205 , fEndOfTrackletCount(-1)
211 , fLastEventCounter(0)
212 , fSharedPadsOn(kTRUE)
216 , fRawReader(rawReader)
220 // default constructor
223 if (Init() == kFALSE) {
224 AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
228 AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
232 //------------------------------------------------------------
234 AliTRDrawStream::AliTRDrawStream(const AliTRDrawStream& /*st*/)
235 : AliTRDrawStreamBase()
246 , fIsGlobalDigitsParamSet(kFALSE)
248 , fStackLinkNumber(-1)
251 , fLinkTrackletCounter(-1)
252 , fEndOfTrackletCount(-1)
258 , fLastEventCounter(0)
259 , fSharedPadsOn(kTRUE)
269 AliError("Not implemeneted.");
272 //------------------------------------------------------------
273 Bool_t AliTRDrawStream::SetRawVersion(Int_t fraw)
276 // function provided for backward compatibility
278 AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");
279 fraw = 0; // avoid warnings
284 //------------------------------------------------------------
285 AliTRDrawStream::~AliTRDrawStream()
293 //------------------------------------------------------------
294 AliTRDrawStream & AliTRDrawStream::operator=(const AliTRDrawStream &)
297 // we are not using this functionality
299 AliFatal("May not use.");
304 //___________________________________________________________
305 void AliTRDrawStream::SwapOnEndian()
308 // Check the endian and swap if needed
311 char* ptemp = (char*) &itemp;
313 if (fgDebugFlag) AliDebug(8, "Swapping.");
317 while (fpPos < fpEnd) {
319 iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
320 ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
321 // here we override the value in the buffer!
328 //------------------------------------------------------------
329 Bool_t AliTRDrawStream::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
332 // dump given number of words for debugging
334 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
335 for (UInt_t i = 0; i < iw; i++) {
336 if ( iw != 0 && px + iw > fpEnd) return kFALSE;
338 if (i % 8 == 0) tsreturn += "\n ";
339 if (marker != 0 && marker == px[i]) tsreturn += Form(" *>0x%08x<* ", px[i]);
340 else tsreturn += Form("0x%08x ", px[i]);
344 AliInfo(tsreturn.Data());
349 //------------------------------------------------------------
350 Bool_t AliTRDrawStream::SkipWords(UInt_t iw)
353 // Skip words corresponding to iw
355 if ( fpPos + iw < fpEnd ) {
360 if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
367 //------------------------------------------------------------
368 Bool_t AliTRDrawStream::SetReader(AliRawReader * reader)
371 // Set reader pointer
379 AliWarning("Unable to setup reader.");
384 AliWarning("AliRawReader argument is 0.");
391 //------------------------------------------------------------
392 Int_t AliTRDrawStream::NextBuffer()
395 // return -1 if no more buffers available
396 // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come
397 // return 1 DecodeSM OK
399 if (fRawReader != 0) {
402 Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
403 if (kBufferSet == kTRUE) {
404 if (fgDebugFlag) AliDebug(9, "Buffer is set.");
405 length = fRawReader->GetDataSize();
406 if (fgExtraSkip == kTRUE) {
407 buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
408 length -= EXTRA_LEAD_WORDS * WORD_SIZE;
411 if (fgSkipCDH == kTRUE) {
412 buffer += CDH_WORDS * WORD_SIZE;
413 length -= CDH_WORDS * WORD_SIZE;
417 if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
418 if (fgEnableMemoryReset) ResetMemory(); //[mj]
419 if (DecodeSM((void*)buffer, length) == kTRUE)
433 //------------------------------------------------------------
434 void AliTRDrawStream::ResetCounters()
437 // reset some global counters
439 fBufferRead = kFALSE; // read buffer if it is false (important to read buffer)
442 fStackLinkNumber = 0;
445 fSM.fActiveStacks = 0;
446 fSM.fNexpectedHalfChambers = 0;
448 fLinkTrackletCounter = 0;
449 fLastEventCounter = 0;
453 //------------------------------------------------------------
454 void AliTRDrawStream::ResetIterators()
457 // reset data which should be reset every sm
459 fStackNumber = 0; // reset for Next() function
460 fStackLinkNumber = 0; // reset for Next() function
465 //------------------------------------------------------------
466 void AliTRDrawStream::ResetPerSM()
472 fSM.fTrackletEnable = kFALSE;
474 fSM.fNexpectedHalfChambers = 0;
475 fSM.fNexpectedHalfChambers = 0;
478 for (Int_t i=0; i<5; i++){
479 fSM.fStackActive[i] = kFALSE;
483 //------------------------------------------------------------
484 void AliTRDrawStream::ResetPerStack()
489 fStack->fHeaderSize = 0;
490 fStack->fActiveLinks = 0;
492 for (Int_t i=0; i<12; i++){
493 fStack->fLinksActive[i] = kFALSE;
494 fStack->fLinksDataType[i] = 0;
495 fStack->fLinksMonitor[i] = 0;
496 fStack->fLinkMonitorError[i] = 0;
500 //------------------------------------------------------------
501 void AliTRDrawStream::ResetPerHC()
507 fHC->fTrackletError = 0;
508 fHC->fNTracklets = 0;
509 fHC->fSpecialRawV = 0;
511 fHC->fRawVMajorOpt = 0;
513 fHC->fNExtraWords = 0;
520 fHC->fBunchCrossCounter = 0;
521 fHC->fPreTriggerCounter = 0;
522 fHC->fPreTriggerPhase = 0;
528 fHC->fH0Corrupted = 0;
529 fHC->fH1Corrupted = 0;
533 //------------------------------------------------------------
534 void AliTRDrawStream::ResetPerMCM()
542 fMCM->fEvCounter = 0;
544 fMCM->fADCMaskWord = 0;
547 fMCM->fMCMADCWords = 0;
548 fMCM->fSingleADCwords = 0;
549 fMCM->fMCMhdCorrupted = 0;
550 fMCM->fADCmaskCorrupted = 0;
551 fMCM->fCorrupted = 0;
553 fMCM->fAdcDataPos = NULL;
554 fMCM->fADCcounter = 0;
556 memset(fMCM->fADCchannel, 0, TRDMAXADC*sizeof(UInt_t));
559 //------------------------------------------------------------
560 void AliTRDrawStream::ResetPerADC()
566 fADC->fADCnumber = 0;
567 fADC->fExtendedCOL = 0;
569 fADC->fIsShared = kTRUE;
570 fADC->fCorrupted = 0;
572 //memset(fADC->fSignals, 0, GetNumberOfTimeBins()*sizeof(Int_t));
573 memset(fADC->fSignals, 0, TRDMAXTBINS*sizeof(Int_t));
576 //------------------------------------------------------------
577 void AliTRDrawStream::ResetMemory()
580 // initialize all the data members to prevent read data from memory for previous buffer
583 for (Int_t istack=0; istack<5; istack++){
584 fStack = &fSM.fStacks[istack];
586 for (Int_t ilink=0; ilink<12; ilink++){
587 fHC = &fStack->fHalfChambers[ilink];
589 for (Int_t imcm=0; imcm<TRDMAXMCM; imcm++){
590 fMCM = &fHC->fMCMs[imcm];
592 for (Int_t iadc=0; iadc<TRDMAXADC; iadc++){
593 fADC = &fMCM->fADCs[iadc];
601 //------------------------------------------------------------
602 Bool_t AliTRDrawStream::Next()
605 // returns with true on next adc read
606 // returns false on errors and end of buffer
609 while (fStackNumber < 5 && fSM.fActiveStacks > 0) {
610 if (fSM.fStackActive[fStackNumber] == kTRUE) {
611 fStack = &fSM.fStacks[fStackNumber];
612 while (fStackLinkNumber < 12) {
613 if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0) {
614 fHC = &fStack->fHalfChambers[fStackLinkNumber];
616 AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
619 if (fHC->fCorrupted == 0 && (fHC->fH0Corrupted == 0 && fHC->fH1Corrupted == 0) | !fgSkipData) { // if HC data corrupted(in any case), we don't read data at all from this HC
620 while (fhcMCMcounter < fHC->fMCMmax) {
621 fMCM = &fHC->fMCMs[fhcMCMcounter];
623 AliError(Form("HC missing at stack %d link %d atMCMslot %d",
624 fStackNumber, fStackLinkNumber, fhcMCMcounter));
627 while(fmcmADCcounter < fMCM->fADCmax) {
628 fADC = &fMCM->fADCs[fmcmADCcounter];
630 AliError(Form("ADC missing at stack %d link %d MCMslot %d ADCslot %d",
631 fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));
639 if (fADC->fIsShared == kFALSE)
642 } // while fmcmADCcounter
644 fmcmADCcounter = 0; // next MCM should go through all active ADCs - start from 0
645 } // while fhcMCMcounter
649 fhcMCMcounter = 0; // next stack link (HC) should go through all active MCMs - start from 0
650 } // while fStackLinkNumber
653 fStackLinkNumber = 0; // next stack should go through all links - start from 0
654 } // while fStackNumber
657 // in case rawreader manages the mem buffers, go for the next buffer
659 Int_t nextBuff = NextBuffer();
660 while (nextBuff != -1) {
665 nextBuff = NextBuffer();
672 //------------------------------------------------------------
673 Int_t AliTRDrawStream::NextChamber(AliTRDdigitsManager *const digitsManager, UInt_t **trackletContainer, UShort_t **errorCodeContainer)
676 // Fills single chamber digit array
677 // Return value is the detector number
679 AliTRDarrayADC *digits = 0;
680 AliTRDarrayDictionary *track0 = 0;
681 AliTRDarrayDictionary *track1 = 0;
682 AliTRDarrayDictionary *track2 = 0;
683 AliTRDSignalIndex *indexes = 0;
684 AliTRDdigitsParam *digitsparam = 0;
686 // Loop through the digits
692 Int_t ntracklets = 0;
694 if (trackletContainer) {
695 for (Int_t i = 0; i < 2; i++)
696 for (Int_t j = 0; j < MAXTRACKLETSPERHC; j++)
697 trackletContainer[i][j] = 0;
704 if (trackletContainer) {
705 if ((det + side*AliTRDgeometry::kNdet) != (lastdet + lastside*AliTRDgeometry::kNdet)) {
706 if (det != lastdet) {
712 ntracklets = GetNTracklets();
713 if (ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets); //copy tracklet words to trackletContainer array
718 if (det != lastdet) {
719 // If new detector found
730 if (det < 0 || det >= AliTRDgeometry::kNdet) {
731 if (fSM.fClean == kTRUE) {
732 AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));
735 AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));
740 // Add a container for the digits of this detector
741 digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);
743 if (digitsManager->UsesDictionaries()) {
744 track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);
745 track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);
746 track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);
750 if (fSM.fClean == kTRUE) {
751 AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));
754 AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));
759 Int_t rowMax = GetRowMax();
760 Int_t colMax = GetColMax();
761 Int_t ntbins = GetNumberOfTimeBins();
763 // Set number of timebin into digitparam
764 if (!fIsGlobalDigitsParamSet){
765 digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();
766 digitsparam->SetCheckOCDB(kFALSE);
767 digitsparam->SetNTimeBins(ntbins);
768 digitsparam->SetADCbaseline(10);
\r\r
769 digitsparam->SetPretiggerPhase(det,GetPreTriggerPhase());
\r\r
770 fIsGlobalDigitsParamSet = kTRUE;
772 if(!digitsparam){
\r\r
773 digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();
774 digitsparam->SetPretiggerPhase(det,GetPreTriggerPhase());
\r\r
777 // Allocate memory space for the digits buffer
778 if (digits->GetNtime() == 0) {
779 digits->Allocate(rowMax, colMax, ntbins);
780 if (digitsManager->UsesDictionaries()) {
781 track0->Allocate(rowMax, colMax, ntbins);
782 track1->Allocate(rowMax, colMax, ntbins);
783 track2->Allocate(rowMax, colMax, ntbins);
787 indexes = digitsManager->GetIndexes(det);
788 indexes->SetSM(GetSM());
789 indexes->SetStack(GetStack());
790 indexes->SetLayer(GetLayer());
791 indexes->SetDetNumber(det);
792 if (indexes->IsAllocated() == kFALSE)
793 indexes->Allocate(rowMax, colMax, ntbins);
796 // ntimebins data are ready to read
797 for (it = 0; it < GetNumberOfTimeBins(); it++) {
798 if (GetSignals()[it] > 0) {
801 digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), it, GetSignals()[it]);
803 digits->SetData(GetRow(), GetCol(), it, GetSignals()[it]);
805 indexes->AddIndexRC(GetRow(), GetCol());
806 if (digitsManager->UsesDictionaries()) {
807 track0->SetData(GetRow(), GetCol(), it, 0);
808 track1->SetData(GetRow(), GetCol(), it, 0);
809 track2->SetData(GetRow(), GetCol(), it, 0);
818 //------------------------------------------------------------
819 Bool_t AliTRDrawStream::Init()
822 // Initialize geometry and fee parameters
824 TDirectory *saveDir = gDirectory;
827 fGeometry = new AliTRDgeometry();
829 AliError("Geometry FAILED!");
834 fTRDfeeParam = AliTRDfeeParam::Instance();
836 AliError("AliTRDfeeParam FAILED!");
840 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
842 ResetCounters(); // fBufferRead is set to kFALSE - important
849 //------------------------------------------------------------
850 Bool_t AliTRDrawStream::InitBuffer(void * const buffer, UInt_t length)
853 // set initial information about the buffer
855 if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));
856 if (fRawReader->GetEquipmentId()<1024 || fRawReader->GetEquipmentId()>1041) // tmp protection
859 if (WORD_SIZE == 0) {
860 AliFatal("Strange word size. size of UInt_t == 0");
866 fpBegin = (UInt_t *)buffer;
867 fWordLength = length/WORD_SIZE;
868 fpEnd = fpBegin + fWordLength;
871 if (fpBegin == 0 || length <= 0) {
872 AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%08x of size %d", fpBegin, length));
878 if (fgDumpHead >= 0) {
879 if ( fgDumpHead == 0 ) { // dump all words
880 AliInfo(Form("---------- Dumping all words from the beginnig of the buffer ----------"));
881 if (DumpWords(fpBegin, fWordLength) == kFALSE) AliError("Dump failed. Not enough data.");
884 AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));
885 if (DumpWords(fpBegin, fgDumpHead) == kFALSE) AliError("Dump failed. Not enough data.");
887 AliInfo(Form("---------- Dumping ended ----------------------------------------------"));
893 //------------------------------------------------------------
894 Bool_t AliTRDrawStream::DecodeGTUheader()
896 // Decode Supermodule Index Word
897 DecodeSMInfo(fpPos, &fSM);
899 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
903 // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design.
904 // For the moment, we skip decoding these words
905 if (SkipWords(fSM.fHeaderSize) == kTRUE) {
906 for (Int_t istack = 0; istack < 5; istack++) {
907 if (fSM.fStackActive[istack] == kFALSE)
910 fStack = &fSM.fStacks[istack];
912 // Decode Stack Index Word of given stack
913 DecodeStackInfo(fpPos, fStack);
916 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
918 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
920 if (SkipWords(fStack->fHeaderSize-6) == kFALSE) { // 6 is the 6 stack header words for 12 links
921 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing");
924 for (Int_t iword=0; iword<6; iword++) { // decode 6 stack header words
925 // Decode Stack Header Word of given stack
926 DecodeStackHeader(fpPos, fStack, iword);
936 if (fgWarnError) AliWarning("No additional sm headers and stack index words present.");
937 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
942 if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");
945 if (fgWarnError) AliWarning("No data just after GTU headers.");
946 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");
950 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));
955 //------------------------------------------------------------
956 Bool_t AliTRDrawStream::DecodeSM(void * const buffer, UInt_t length)
959 // decode one sm data in buffer
964 if (InitBuffer(buffer, length) == kFALSE) {
965 if (fgWarnError) AliError("InitBuffer failed.");
970 if (DecodeGTUheader()== kFALSE)
973 for (Int_t istack = 0; istack < 5; istack++) {
974 fStackNumber = istack;
975 if (fSM.fStackActive[istack] == kFALSE)
978 fStack = &fSM.fStacks[istack];
980 fgLastHC = -1; // to check rob number odering
981 for (Int_t ilink = 0; ilink < 12; ilink++) {
982 fStackLinkNumber = ilink;
983 if (fStack->fLinksActive[ilink] == kFALSE)
986 // check GTU link monitor
987 if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0)) {
988 fStack->fLinkMonitorError[ilink] = 1;
989 SeekEndOfData(); // skip this HC data if GTU link monitor report error
990 fStack->fLinkMonitorError[ilink] += fNWordsCounter; // counts words of given hc having link monitor error
994 if (fpPos >= fpEnd) {
995 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
996 if (fgWarnError) AliError("Link data missing.");
1001 fHC = &fStack->fHalfChambers[ilink];
1004 if (fSM.fTrackletEnable == kTRUE) {
1005 if (DecodeTracklets() == kFALSE) {
1006 fSM.fClean = kFALSE;
1010 AliError(Form("Tracklet decoding failed stack %d link %d", fStackNumber, fStackLinkNumber));
1016 if (fpPos >= fpEnd) {
1017 if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
1018 if (fgWarnError) AliError("HC data missing.");
1019 fSM.fClean = kFALSE;
1023 fgLastROB = -1; // to check mcm number odering
1024 fgLastIndex = -1 ; // to check mcm number odering
1025 if (DecodeHC() == kFALSE) {
1026 fSM.fClean = kFALSE;
1027 if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW
1028 // during ADC data decoding or MCM header decoding
1029 // we don't seek ENDOFRAWDATAMARKER
1031 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
1032 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
1038 SeekEndOfData(); // make sure that finish off with the end of data markers
1043 ResetIterators(); // need to do it again for Next() function
1045 if (fSM.fClean == kTRUE)
1048 if (fgCleanDataOnly && (fSM.fClean == kFALSE)) {
1050 AliWarning("Buffer with errors. Returning FALSE.");
1051 AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
1053 fSM.fActiveStacks = 0; // Next() will not give data
1060 //------------------------------------------------------------
1061 Int_t AliTRDrawStream::DecodeSM()
1064 // decode SM data in case AliRawReader is in use
1067 Int_t nextBuff = NextBuffer();
1068 while (nextBuff != -1) {
1071 nextBuff = NextBuffer();
1076 AliWarning("AliRawReader not set.");
1082 //------------------------------------------------------------
1083 Int_t AliTRDrawStream::DecodeSM(AliRawReader *reader)
1086 // decode SM with the AliRawReader
1089 fRawReader = reader;
1093 AliWarning("Argument AliRawReader is 0.");
1099 //------------------------------------------------------------
1100 Bool_t AliTRDrawStream::SeekEndOfData()
1103 // go to end of data marker
1105 Int_t fEndOfDataCount = 0;
1108 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
1112 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
1120 //------------------------------------------------------------
1121 Bool_t AliTRDrawStream::SkipMCMdata(UInt_t iw)
1124 // skip mcm data words due to corruption
1126 if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw));
1127 UInt_t iwcounter = 0;
1128 while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw) {
1129 if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {
1130 if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW");
1131 fMCM->fCorrupted += 16;
1132 fHC->fCorrupted += 16;
1139 if (iwcounter == iw) {
1144 if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");
1149 //------------------------------------------------------------
1150 Bool_t AliTRDrawStream::SeekNextMCMheader()
1157 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
1158 if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0) {
1159 if (fgDebugFlag) AliDebug(11,Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1162 if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {
1163 fMCM->fCorrupted += 16;
1164 fHC->fCorrupted += 16;
1175 //------------------------------------------------------------
1176 Bool_t AliTRDrawStream::DecodeTracklets()
1181 fLinkTrackletCounter = 0;
1182 fEndOfTrackletCount = 0;
1183 fHC->fNTracklets = 0;
1185 for (Int_t i = 0; i < MAXTRACKLETSPERHC; i++)
1186 fHC->fTrackletWords[i] = 0;
1188 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
1190 while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd ) {
1191 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
1193 fLinkTrackletCounter++;
1195 if (fLinkTrackletCounter > MAXTRACKLETSPERHC) {
1196 if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d.",
1197 fLinkTrackletCounter, MAXTRACKLETSPERHC));
1198 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
1199 fHC->fTrackletError = 1;
1203 fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into array
1204 fHC->fNTracklets = fLinkTrackletCounter;
1208 while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd ) {
1209 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1211 fEndOfTrackletCount++;
1215 if ( fEndOfTrackletCount < 2 ) {
1216 if (fgDebugFlag) AliDebug(11,"End of tracklets word missing");
1217 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1218 fHC->fTrackletError += 2;
1225 //------------------------------------------------------------
1226 Bool_t AliTRDrawStream::IsRowValid()
1229 // check if the row number is in valid range
1231 if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||
1232 (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 ) {
1233 if (fgDebugFlag) AliDebug(11,Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1234 , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));
1241 //------------------------------------------------------------
1242 Bool_t AliTRDrawStream::IsMCMheaderOK()
1245 // check the mcm header
1247 if (fgLastROB != fMCM->fROB) {
1249 if (fgLastROB== -1) fgLastROB = fMCM->fROB;
1252 Int_t matchingcounter = 0;
1253 for (Int_t i=fgLastIndex+1; i<16; i++) {
1254 if ( fMCM->fMCM == fgMCMordering[i] ) {
1260 if (matchingcounter == 0) {
1261 fMCM->fMCMhdCorrupted += 2;
1262 AliDebug(11,Form("MCM number from last MCM is larger: MCM # from last MCM %d, MCM # from current MCM %d \n",(fMCM-1)->fMCM, fMCM->fMCM));
1266 if ( fgLastHC == fHC->fLayer*2 + fHC->fSide ) {
1267 if ( fMCM->fROB < (fMCM-1)->fROB ) {
1268 fMCM->fMCMhdCorrupted += 2;
1269 AliDebug(11,Form("ROB number from last MCM is larger: ROB # from last MCM %d, ROB # from current MCM %d \n",(fMCM-1)->fROB, fMCM->fROB));
1271 else fgLastROB = fMCM->fROB;
1274 fgLastHC = fHC->fLayer*2 + fHC->fSide;
1277 // this check will come back later again when we have "patched MCM map"
1278 int expectedROB = -1;
1279 if(!fHC->fSide) expectedROB = int(fHC->fMCMmax/16)*2;
1280 else expectedROB = int(fHC->fMCMmax/16)*2 + 1;
1281 int expectedMCM = 4*(3-int((fHC->fMCMmax%16)/4)) + fHC->fMCMmax%4;
1283 if ( expectedROB != fMCM->fROB || expectedMCM != fMCM->fMCM)
1285 fMCM->fMCMhdCorrupted += 2;
1286 AliDebug(11,Form("ROB expected %d ROB read %d, MCM expected %d MCM read %d\n",expectedROB, fMCM->fROB, expectedMCM, fMCM->fMCM));
1290 // below two conditions are redundant
1292 if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 )
1294 fMCM->fMCMhdCorrupted += 8; // need to assign new number
1295 if (fgDebugFlag) AliDebug(11,Form("ROB or MCM number is out of range. %s\n", DumpMCMinfo(fMCM)));
1297 if (IsRowValid() == kFALSE)
1299 fMCM->fMCMhdCorrupted += 16; // need to assign new number
1303 if (fEventCounter == 0) {
1304 fEventCounter = fMCM->fEvCounter;
1307 if (fEventCounter != fMCM->fEvCounter) {
1308 fMCM->fMCMhdCorrupted += 4;
1309 if (fgDebugFlag) AliDebug(11,Form("Event number(%d) of current MCM is different from that(%d) of reference MCM %s.\n"
1310 , fMCM->fEvCounter, fEventCounter, DumpMCMinfo(fMCM)));
1313 if (fEventCounter < fLastEventCounter) {
1314 fMCM->fMCMhdCorrupted += 8;
1315 if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM)));
1318 if ( fMCM->fADCmaskCorrupted > 0 )
1321 if ( fMCM->fMCMhdCorrupted > 0 )
1327 //------------------------------------------------------------
1328 Bool_t AliTRDrawStream::DecodeMCMheader()
1331 // decode the mcm header
1333 DecodeMCMheader(fpPos, fMCM);
1335 if (fgDumpingEnable) {
1336 if (fMCM->fMCM == fgDumpingMCM) {
1337 if (fMCM->fROB == fgDumpingROB && fHC->fLayer == fgDumpingLayer) {
1338 if (fHC->fSM == fgDumpingSM && fHC->fStack == fgDumpingStack) {
1340 AliDebug(5,DumpHCinfoH0(fHC));
1341 AliDebug(5,DumpMCMinfo(fMCM));
1343 DumpWords(fpPos, 212);
1349 if (fHC->fCorrupted >= 16) {
1354 fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
1356 if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || ((fHC->fRawVMajor & 32) == 32)) { //cover old and new version definition of ZS data
1358 if ( fpPos < fpEnd ) {
1359 DecodeMask(fpPos, fMCM);
1360 if (fHC->fCorrupted >= 16) {
1364 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1365 fMCM->fAdcDataPos = fpPos + 1;
1368 if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END.");
1369 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1370 fHC->fCorrupted += 32;
1375 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
1376 DecodeMask(&dummyMask, fMCM);
1377 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1378 fMCM->fAdcDataPos = fpPos + 1;
1382 AliDebug(6, DumpMCMinfo(fMCM));
1383 AliDebug(7, DumpMCMadcMask(fMCM));
1386 if (IsMCMheaderOK() == kFALSE)
1392 //------------------------------------------------------------
1393 Bool_t AliTRDrawStream::IsHCheaderOK()
1396 // check insanity of half chamber header
1398 if (fHC->fStack < 0 || fHC->fStack > 4) {
1399 if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStack));
1403 if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNlayer) {
1404 if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayer));
1408 if (fHC->fSide < 0 || fHC->fSide > 1) {
1409 if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSide));
1413 if (fgStackNumberChecker) {
1414 if (fHC->fStack != fStackNumber) {
1415 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d",
1416 fHC->fStack, fStackNumber));
1422 if (fgStackLinkNumberChecker) {
1423 if (fHC->fLayer * 2 + fHC->fSide != fStackLinkNumber) {
1424 // let it make flexible to consider known fiber swapping
1425 //if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1)) {
1426 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s",
1427 fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));
1428 fStackLinkNumber = -1;
1433 // SLOW GEOM : consistancy check with geometry
1434 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
1435 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet) {
1436 if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET));
1437 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1441 if (fHC->fSM != fGeometry->GetSector(fHC->fDET) || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector) {
1442 if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1443 fHC->fSM, fGeometry->GetSector(fHC->fDET), fHC->fStack, fHC->fLayer, fHC->fDET));
1444 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1448 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
1449 if (fHC->fROC < 0) {
1450 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1454 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
1455 if (fHC->fRowMax < 1) {
1456 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1460 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
1461 if (fHC->fColMax < 1) {
1462 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1469 //------------------------------------------------------------
1470 Bool_t AliTRDrawStream::DecodeHCheader()
1473 // decode the half chamber header
1475 if (DecodeHCwordH0(fpPos, fHC) == kFALSE)
1478 if (fHC->fNExtraWords > 0) {
1480 if (fpPos < fpEnd) {
1481 if (DecodeHCwordH1(fpPos, fHC) == kFALSE)
1485 if (fgDebugFlag) AliDebug(11,"Expected HC header word 1. Fail due to buffer END.");
1486 if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing");
1491 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1492 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1495 if (IsHCheaderOK() == kFALSE) {
1496 fHC->fH0Corrupted += 2;
1497 if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));
1504 //------------------------------------------------------------
1505 Bool_t AliTRDrawStream::DecodeHC()
1508 // decode hc header and data
1510 if (DecodeHCheader() == kFALSE) {
1511 if (fgWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));
1512 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "HC header corrupted");
1517 if (fpPos >= fpEnd) {
1518 fHC->fCorrupted += 1;
1519 if (fgDebugFlag) AliDebug(11,"No MCM data? Not enough data in the buffer.");
1520 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing");
1525 if ((fHC->fRawVMajor & 64) == 64) { // test pattern data
1526 AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos);
1527 if (tpStream->DecodeTPdata() == kFALSE) {
1528 if (fgWarnError) AliError("failed to decode test pattern data");
1535 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd) {
1536 if (fHC->fMCMmax > TRDMAXMCM) {
1537 fHC->fCorrupted += 2;
1538 if (fgDebugFlag) AliDebug(11,"More mcm data than expected!");
1539 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!");
1543 fMCM = &fHC->fMCMs[fHC->fMCMmax];
1545 if (DecodeMCMheader() == kFALSE) {
1546 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1548 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16) { // stop HC data reading
1553 fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number
1555 // in case we decide to keep reading data, skip this mcm data and find next mcm header
1556 if (fMCM->fADCmaskCorrupted < 2) {
1557 if (SkipMCMdata(fMCM->fADCcount*fMCM->fSingleADCwords) == kFALSE)
1562 if (SeekNextMCMheader() == kFALSE)
1570 if (fMCM->fADCmax > 0) {
1572 if (fpPos >= fpEnd) {
1573 fMCM->fCorrupted += 1;
1574 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1575 if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected."));
1579 for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++) {
1580 fADC = &fMCM->fADCs[iadc];
1581 fADC->fADCnumber = fMCM->fADCchannel[iadc];
1582 if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.",
1583 iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1584 if (fpPos + fMCM->fSingleADCwords >= fpEnd) {
1585 fMCM->fCorrupted += 2;
1586 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1587 if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");
1591 if (fHC->fRawVMajor < 64) { // normal(real) ADC data
1592 if (fHC->fTimeBins < 31) {
1593 if (DecodeADC() == kFALSE) {
1594 if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4
1595 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1596 if (fADC->fIsShared && fADC->fCorrupted == 32) { // check if we are out of the det when the pad is shared
1597 fADC->fExtendedCOL = -1;
1599 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1602 if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));
1603 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1604 return kFALSE; // stop HC data reading
1608 else if (fHC->fTimeBins > 32) {
1609 if (DecodeADCExtended() == kFALSE) { // decoding TRAP data with ZS and more than 32 samples
1610 if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4
1611 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1612 if (fADC->fIsShared && fADC->fCorrupted == 32) { // check if we are out of the det when the pad is shared
1613 fADC->fExtendedCOL = -1;
1615 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1618 if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));
1619 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1620 return kFALSE; // stop HC data reading
1624 else { // nsamples = 31, 32 are not implemented in the TRAP and should never happen
1625 if (fgWarnError) AliError("nsamples are 31 or 32. These are not implemented in the TRAP and should never happen!");
1627 } // if fHC->fRawVMajor
1628 else { // test pattern data
1629 if (fgWarnError) AliError("These are test pattern data. You need other reader"); // will be served in other class
1632 } // if fMCM->fADCmax
1638 if (fpPos >= fpEnd) {
1639 if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. There should be one more word left.");
1646 //------------------------------------------------------------
1647 Bool_t AliTRDrawStream::DecodeADC()
1650 // decode single ADC channel
1653 UInt_t commonAdditive = AliTRDrawStreamBase::fgCommonAdditive;
1655 fADC->fCorrupted = 0;
1656 if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
1657 if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
1662 for (Int_t i = 0; i < GetNumberOfTimeBins(); i++)
1663 //for (Int_t i = 0; i < TRDMAXTBINS; i++)
1664 fADC->fSignals[i] = 0;
1666 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++) {
1667 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {
1668 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1669 fADC->fCorrupted += 16;
1670 fHC->fCorrupted += 16;
1674 if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {
1675 fADC->fCorrupted += 1;
1676 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x Current mask: 0x%08x] MCM= %s Error : %d",
1677 fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));
1682 // here we subtract the baseline ( == common additive)
1683 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - commonAdditive;
1684 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - commonAdditive;
1685 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - commonAdditive;
1691 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) {
1692 fADC->fIsShared = kTRUE;
1695 fADC->fIsShared = kFALSE;
1698 fADC->fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1699 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1701 if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0) {
1702 if (fADC->fIsShared == kFALSE) {
1703 fADC->fCorrupted += 32;
1704 if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1705 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1708 // we are out of the det when the pad is shared
1709 //if (fgDebugFlag) AliDebug(11, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1710 // fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1711 //fADC->fCorrupted += 32;
1715 if (fADC->fCorrupted > 0) {
1724 //------------------------------------------------------------
1725 Bool_t AliTRDrawStream::DecodeADCExtended()
1728 // decode single ADC channel
1731 UInt_t commonAdditive = AliTRDrawStreamBase::fgCommonAdditive;
1733 fADC->fCorrupted = 0;
1734 if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
1735 if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
1739 fTbinADC = ((*fpPos & 0x000000fc) >> 2);
1740 fMCM->fSingleADCwords = ((*fpPos & 0x00000f00) >> 8);
1741 fADC->fSignals[fTbinADC] = ((*fpPos & 0x003ff000) >> 12) - commonAdditive;
1742 fADC->fSignals[fTbinADC+1] = ((*fpPos & 0xffc00000) >> 22) - commonAdditive;
1745 for (Int_t iw = 0; iw < fMCM->fSingleADCwords-1; iw++) { // it goes up to fMCM->fSingleADCwords-1 since the first word was already decoded above
1746 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {
1747 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1748 fADC->fCorrupted += 16;
1749 fHC->fCorrupted += 16;
1753 if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {
1754 fADC->fCorrupted += 1;
1755 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x Current mask: 0x%08x] MCM= %s Error : %d",
1756 fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));
1761 // here we subtract the baseline ( == common additive)
1762 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0x00000ffc) >> 2) - commonAdditive;
1763 fADC->fSignals[fTbinADC + 3] = ((*fpPos & 0x003ff000) >> 12) - commonAdditive;
1764 fADC->fSignals[fTbinADC + 4] = ((*fpPos & 0xffc00000) >> 22) - commonAdditive;
1774 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) {
1775 fADC->fIsShared = kTRUE;
1778 fADC->fIsShared = kFALSE;
1781 fADC->fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1782 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1784 if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0) {
1785 if (fADC->fIsShared == kFALSE) {
1786 fADC->fCorrupted += 32;
1787 if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1788 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1792 if (fADC->fCorrupted > 0) {
1801 //--------------------------------------------------------
1802 void AliTRDrawStream::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
1805 // Decode Supermodule Index Word
1806 // The Supermodule Index Word is a 32-Bit word wit following structure
1807 // ssssssss ssssssss vvvv rrrr r d t mmmm
1808 // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use
1809 // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask
1811 sm->fPos = (UInt_t*)word;
1813 UInt_t vword = *word;
1814 sm->fHeaderSize = SM_HEADER_SIZE(vword);
1816 if (TRACKLETS_ENABLED(vword) > 0)
1817 sm->fTrackletEnable = kTRUE;
1819 sm->fTrackletEnable = kFALSE;
1821 UInt_t stackMask = STACK_MASK(vword);
1822 sm->fActiveStacks = 0;
1823 for (Int_t i = 0; i < 5; i++) {
1824 if (IS_BIT_SET(stackMask,i) > 0) {
1825 sm->fStackActive[i] = kTRUE;
1826 sm->fActiveStacks++;
1829 sm->fStackActive[i] = kFALSE;
1834 //--------------------------------------------------------
1835 const char *AliTRDrawStream::DumpSMInfo(const struct AliTRDrawSM *sm)
1838 // Get SM structure into a const char
1840 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
1841 *sm->fPos, sm->fHeaderSize, sm->fTrackletEnable,
1842 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
1843 sm->fStackActive[3], sm->fStackActive[4]);
1846 //--------------------------------------------------------
1847 void AliTRDrawStream::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
1850 // Decode Stack #i Index Word
1851 // The Stack #i Index Word is a 32-Bit word wit following structure
1852 // ssssssss ssssssss vvvv mmmm mmmmmmmm
1853 // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask
1855 st->fPos = (UInt_t*)word;
1857 UInt_t vword = *word;
1858 st->fHeaderSize = STACK_HEADER_SIZE(vword);
1860 UInt_t linkMask = STACK_LINK_WORD(vword);
1861 st->fActiveLinks = 0;
1862 for (Int_t i = 0; i < 12; i++) {
1863 if (IS_BIT_SET(linkMask,i) > 0) {
1864 st->fLinksActive[i] = kTRUE;
1868 st->fLinksActive[i] = kFALSE;
1873 //--------------------------------------------------------
1874 void AliTRDrawStream::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const
1877 // decode gtu header for stack info
1879 st->fPos = (UInt_t*)word;
1881 UInt_t vword = *word;
1882 st->fLinksDataType[2*iword] = LINK0_DATA_TYPE_FLAG(vword);
1883 st->fLinksMonitor[2*iword] = LINK0_MONITOR_FLAG(vword);
1884 st->fLinksDataType[2*iword+1] = LINK1_DATA_TYPE_FLAG(vword);
1885 st->fLinksMonitor[2*iword+1] = LINK1_MONITOR_FLAG(vword);
1888 //--------------------------------------------------------
1889 const char *AliTRDrawStream::DumpStackInfo(const struct AliTRDrawStack *st)
1892 // format the string with the stack info
1895 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
1896 *st->fPos, st->fHeaderSize,
1897 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
1898 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
1899 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
1902 //--------------------------------------------------------
1903 Bool_t AliTRDrawStream::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
1906 // decode the hc header word 0
1908 UInt_t vword = *word;
1909 hc->fPos[0] = (UInt_t*)word;
1911 hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword);
1912 if (hc->fH0Corrupted > 0) {
1913 if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%08x", *fHC->fPos));
1917 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
1918 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
1919 hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword);
1920 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
1921 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
1922 hc->fDCSboard = HC_DCS_BOARD(vword);
1923 hc->fSM = HC_SM_NUMBER(vword);
1924 hc->fStack = HC_STACK_NUMBER(vword);
1925 hc->fLayer = HC_LAYER_NUMBER(vword);
1926 hc->fSide = HC_SIDE_NUMBER(vword);
1932 //--------------------------------------------------------
1933 Bool_t AliTRDrawStream::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
1936 // decode the hc header word 1
1938 UInt_t vword = *word;
1940 hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword);
1941 if (hc->fH1Corrupted > 0) {
1942 if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%08x", *fHC->fPos));
1946 hc->fTimeBins = HC_NTIMEBINS(vword);
1947 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
1948 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
1949 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
1951 hc->fPos[1] = (UInt_t*)word;
1956 //--------------------------------------------------------
1957 const char *AliTRDrawStream::DumpHCinfoH0(const struct AliTRDrawHC *hc)
1960 // dump the hc header word 0
1963 return Form("Unable to dump. Null received as parameter!?!");
1965 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
1966 hc->fPos[0], (hc->fPos[0]) ? *(hc->fPos[0]) : 0, hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
1969 //--------------------------------------------------------
1970 const char *AliTRDrawStream::DumpHCinfoH1(const struct AliTRDrawHC *hc)
1973 // dump the hc header word 1
1976 return Form("Unable to dump. Null received as parameter!?!");
1978 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
1979 hc->fPos[1], (hc->fPos[1]) ? *(hc->fPos[1]) : 0, hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
1982 //--------------------------------------------------------
1983 void AliTRDrawStream::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1986 // decode the mcm header
1988 UInt_t vword = *word;
1990 if (vword == END_OF_TRACKLET_MARKERNEW) {
1991 if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
1992 mcm->fMCMhdCorrupted += 16;
1993 fHC->fCorrupted += 16; //to finish data reading of this HC
1996 mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error
1997 if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));
1999 mcm->fROB = MCM_ROB_NUMBER(vword);
2000 mcm->fMCM = MCM_MCM_NUMBER(vword);
2001 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
2002 mcm->fPos = (UInt_t*)word;
2005 //--------------------------------------------------------
2006 UInt_t AliTRDrawStream::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2011 UInt_t vword = *word;
2016 mcm->fADCMaskWord = vword;
2018 if (vword == END_OF_TRACKLET_MARKERNEW) {
2019 if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
2020 mcm->fADCmaskCorrupted += 16;
2021 fHC->fCorrupted += 16; //to finish data reading of this HC
2024 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) {
2025 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
2026 mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
2029 mcm->fADCMask = 0xffffffff;
2030 mcm->fADCmaskCorrupted = 1; // mcm adc mask error
2031 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));
2034 return mcm->fADCMask;
2037 //--------------------------------------------------------
2038 void AliTRDrawStream::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2041 // decode the adc mask - adcs to be read out
2043 mcm->fMCMADCWords = 0;
2044 mcm->fSingleADCwords = 0;
2046 mcm->fADCMask = GetMCMadcMask(word, mcm);
2048 if (mcm->fADCMask > 0) {
2049 for (Int_t i = 0; i < TRDMAXADC; i++) {
2050 mcm->fADCchannel[mcm->fADCmax] = 0;
2051 if ( IS_BIT_SET(mcm->fADCMask,i) ) {
2052 mcm->fADCchannel[mcm->fADCmax] = i;
2057 if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) { // backward compatibility
2058 mcm->fADCmaskCorrupted += 2;
2059 if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n", mcm->fADCcount, mcm->fADCmax, *fMCM->fPos));
2063 //--------------------------------------------------------
2064 void AliTRDrawStream::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
2067 // count the expected mcm words for a given tbins
2069 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
2070 mcm->fSingleADCwords = 0;
2071 if (mcm->fADCmax > 0) {
2072 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
2074 if (fTbins > 32) mcm->fSingleADCwords = 10; // if the timebin is more than 30, then fix the number of adc words to 10
2077 //--------------------------------------------------------
2078 const char *AliTRDrawStream::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
2081 // mcm info in a string
2084 return Form("Unable to dump. Null received as parameter!?!");
2086 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
2089 //--------------------------------------------------------
2090 const char *AliTRDrawStream::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
2093 // mcm adc mask in a string
2096 return Form("Unable to dump. Null received as parameter!?!");
2098 TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
2099 for (Int_t i = 0; i < TRDMAXADC; i++) {
2100 tsreturn += Form("%d ", mcm->fADCchannel[i]);
2103 return tsreturn.Data();