1 #/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // This class provides access to TRD digits in raw data. //
22 // It loops over all TRD digits in the raw data given by the AliRawReader. //
23 // The Next method goes to the next digit. If there are no digits left //
24 // it returns kFALSE. //
25 // Several getters provide information about the current digit. //
27 // Author: M. Ploskon (ploskon@ikf.uni-frankfurt.de) //
29 ///////////////////////////////////////////////////////////////////////////////
33 #include "TTreeStream.h"
35 #include "AliTRDrawStreamTB.h"
36 #include "AliTRDgeometry.h"
37 #include "AliTRDfeeParam.h"
38 #include "AliTRDdigitsManager.h"
39 #include "AliTRDdataArrayS.h"
40 #include "AliTRDdataArrayI.h"
41 #include "AliTRDdataArrayDigits.h"
42 #include "AliTRDSignalIndex.h"
43 #include "AliTRDrecoParam.h"
44 #include "AliTRDcalibDB.h"
45 #include "Cal/AliTRDCalPadStatus.h"
47 //[mj tracklet writing] #include "AliTRDrawTracklet.h"
50 #include "AliRawReader.h"
52 #define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa
53 #define END_OF_TRACKLET_MARKERNEW 0x10001000
54 #define ENDOFRAWDATAMARKER 0x00000000
55 #define WORD_SIZE sizeof(UInt_t) // size of a word in bytes
56 #define EXTRA_LEAD_WORDS 24
59 #define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w
60 #define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m
62 // SM index word masks:
63 #define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
64 #define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)
65 #define STACK_MASK(w) ((w) & 0x1f)
68 #define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
69 #define STACK_LINK_WORD(w) ((w) & 0xfff)
70 #define LINK0_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,4) == (0x0) ? 0 : 1) // 0 if physics data
71 #define LINK1_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,20) == (0x0) ? 0 : 1) // 0 if physics data
72 #define LINK0_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,0) == (0x0) ? 0 : 1) // 0 if OK
73 #define LINK1_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,16) == (0x0) ? 0 : 1) // 0 if OK
76 //#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!!
77 #define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK!!!
80 #define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)
81 #define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)
82 #define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24)
83 #define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)
84 #define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)
85 #define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)
86 #define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)
87 #define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)
88 #define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)
89 #define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)
92 #define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)
93 #define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)
94 #define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)
95 #define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,6)
97 // MCM word and ADC mask
98 #define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
99 #define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
100 #define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)
101 #define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)
102 #define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)
103 #define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)
104 #define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25)
106 #define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated
107 #define ADCDATA_VAL1 0x2 // updated
108 #define ADCDATA_VAL2 0x3 // updated
110 //--------------------------------------------------------
111 #define ADC_WORD_MASK(w) ((w) & 0x3)
112 //--------------------------------------------------------
115 ClassImp(AliTRDrawStreamTB)
117 Bool_t AliTRDrawStreamTB::fgExtraSkip = kFALSE;
118 Bool_t AliTRDrawStreamTB::fgSkipCDH = kFALSE;
119 Bool_t AliTRDrawStreamTB::fgWarnError = kTRUE;
120 Bool_t AliTRDrawStreamTB::fgCleanDataOnly = kFALSE;
121 Bool_t AliTRDrawStreamTB::fgDebugFlag = kTRUE;
122 Bool_t AliTRDrawStreamTB::fgEnableMemoryReset = kTRUE;
123 Bool_t AliTRDrawStreamTB::fgStackNumberChecker = kTRUE;
124 Bool_t AliTRDrawStreamTB::fgStackLinkNumberChecker = kTRUE;
125 Bool_t AliTRDrawStreamTB::fgSkipData = kTRUE;
126 UInt_t AliTRDrawStreamTB::fgDumpHead = 0;
127 Int_t AliTRDrawStreamTB::fgCommonAdditive = 0;
128 Int_t AliTRDrawStreamTB::fgEmptySignals[] =
130 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
131 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
133 Short_t AliTRDrawStreamTB::fgMCMordering[] =
135 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3
137 Short_t AliTRDrawStreamTB::fgROBordering[] =
141 Int_t AliTRDrawStreamTB::fgLastHC = -1;
142 Int_t AliTRDrawStreamTB::fgLastROB = -1;
143 Int_t AliTRDrawStreamTB::fgLastIndex = -1;
144 Bool_t AliTRDrawStreamTB::fDumpingEnable = kFALSE;
145 Int_t AliTRDrawStreamTB::fDumpingSM = -1;
146 Int_t AliTRDrawStreamTB::fDumpingStack = -1;
147 Int_t AliTRDrawStreamTB::fDumpingLayer = -1;
148 Int_t AliTRDrawStreamTB::fDumpingROB = -1;
149 Int_t AliTRDrawStreamTB::fDumpingMCM = -1;
152 AliTRDrawStreamTB::AliTRDrawStreamTB()
153 : AliTRDrawStreamBase()
164 , fStackLinkNumber(-1)
167 , fLinkTrackletCounter(-1)
168 , fEndOfTrackletCount(-1)
174 , fLastEventCounter(0)
175 , fSharedPadsOn(kFALSE)
183 // default constructor
186 if (Init() == kFALSE)
188 AliWarning("Unable to Init.");
192 //--------------------------------------------------------
193 AliTRDrawStreamTB::AliTRDrawStreamTB(AliRawReader *rawReader)
194 : AliTRDrawStreamBase(rawReader)
205 , fStackLinkNumber(-1)
208 , fLinkTrackletCounter(-1)
209 , fEndOfTrackletCount(-1)
215 , fLastEventCounter(0)
216 , fSharedPadsOn(kFALSE)
220 , fRawReader(rawReader)
224 // default constructor
228 if (Init() == kFALSE)
230 AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
235 AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
239 //------------------------------------------------------------
241 AliTRDrawStreamTB::AliTRDrawStreamTB(const AliTRDrawStreamTB& /*st*/)
242 : AliTRDrawStreamBase()
253 , fStackLinkNumber(-1)
256 , fLinkTrackletCounter(-1)
257 , fEndOfTrackletCount(-1)
263 , fLastEventCounter(0)
264 , fSharedPadsOn(kFALSE)
274 AliError("Not implemeneted.");
277 //------------------------------------------------------------
278 Bool_t AliTRDrawStreamTB::SetRawVersion(Int_t fraw)
281 // function provided for backward compatibility
283 AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");
284 fraw = 0; // avoid warnings
288 //------------------------------------------------------------
289 AliTRDrawStreamTB::~AliTRDrawStreamTB()
297 //------------------------------------------------------------
300 AliTRDrawStreamTB::operator=(const AliTRDrawStreamTB &)
303 // we are not using this functionality
305 AliFatal("May not use.");
309 //___________________________________________________________
311 AliTRDrawStreamTB::SwapOnEndian()
314 // Check the endian and swap if needed
317 char* ptemp = (char*) &itemp;
320 if (fgDebugFlag) AliDebug(8, "Swapping.");
324 while (fpPos < fpEnd)
327 iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
328 ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
329 // here we override the value in the buffer!
336 //------------------------------------------------------------
338 AliTRDrawStreamTB::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
341 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
342 for (UInt_t i = 0; i < iw; i++)
344 if (px + iw >= fpEnd)
349 if (marker != 0 && marker == px[i])
350 tsreturn += Form(" *>0x%08x<* ", px[i]);
352 tsreturn += Form("0x%08x ", px[i]);
356 AliInfo(tsreturn.Data());
361 //------------------------------------------------------------
363 AliTRDrawStreamTB::SkipWords(UInt_t iw)
366 // Skip words corresponding to iw
368 if ( fpPos + iw < fpEnd )
375 if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
382 //------------------------------------------------------------
384 AliTRDrawStreamTB::SetReader(AliRawReader *reader)
396 AliWarning("Unable to setup reader.");
402 AliWarning("AliRawReader argument is 0.");
409 //------------------------------------------------------------
411 AliTRDrawStreamTB::NextBuffer()
414 // return -1 if no more buffers available
415 // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come
416 // return 1 DecodeSM OK
423 Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
424 if (kBufferSet == kTRUE)
426 if (fgDebugFlag) AliDebug(9, "Buffer is set.");
427 length = fRawReader->GetDataSize();
428 if (fgExtraSkip == kTRUE)
430 buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
431 length -= EXTRA_LEAD_WORDS * WORD_SIZE;
434 if (fgSkipCDH == kTRUE)
436 buffer += CDH_WORDS * WORD_SIZE;
437 length -= CDH_WORDS * WORD_SIZE;
442 if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
443 if (fgEnableMemoryReset) ResetMemory(); //[mj]
444 if (DecodeSM((void*)buffer, length) == kTRUE)
459 //------------------------------------------------------------
461 AliTRDrawStreamTB::ResetCounters()
464 // reset some global counters
466 fBufferRead = kFALSE; // important to read buffer
469 fStackLinkNumber = 0;
472 fSM.fActiveStacks = 0;
473 fSM.fNexpectedHalfChambers = 0;
475 fLinkTrackletCounter = 0;
476 fLastEventCounter = 0;
480 //------------------------------------------------------------
482 AliTRDrawStreamTB::ResetIterators()
485 // reset data which should be reset every sm
487 fStackNumber = 0; // reset for Next() function
488 fStackLinkNumber = 0; // reset for Next() function
493 //------------------------------------------------------------
495 AliTRDrawStreamTB::ResetPerSM()
502 fSM.fTrackletEnable = kFALSE;
504 fSM.fNexpectedHalfChambers = 0;
505 fSM.fNexpectedHalfChambers = 0;
508 for (Int_t i=0; i<5; i++){
509 fSM.fStackActive[i] = kFALSE;
513 //------------------------------------------------------------
515 AliTRDrawStreamTB::ResetPerStack()
521 fStack->fHeaderSize = 0;
522 fStack->fActiveLinks = 0;
524 for (Int_t i=0; i<12; i++){
525 fStack->fLinksActive[i] = kFALSE;
526 fStack->fLinksDataType[i] = 0;
527 fStack->fLinksMonitor[i] = 0;
528 fStack->fLinkMonitorError[i] = 0;
532 //------------------------------------------------------------
534 AliTRDrawStreamTB::ResetPerHC()
540 fHC->fTrackletError = 0;
541 fHC->fNTracklets = 0;
542 fHC->fSpecialRawV = 0;
544 fHC->fRawVMajorOpt = 0;
546 fHC->fNExtraWords = 0;
553 fHC->fBunchCrossCounter = 0;
554 fHC->fPreTriggerCounter = 0;
555 fHC->fPreTriggerPhase = 0;
562 fHC->fH0Corrupted = 0;
563 fHC->fH1Corrupted = 0;
567 //------------------------------------------------------------
569 AliTRDrawStreamTB::ResetPerMCM()
577 fMCM->fEvCounter = 0;
579 fMCM->fADCMaskWord = 0;
582 fMCM->fMCMADCWords = 0;
583 fMCM->fSingleADCwords = 0;
584 fMCM->fMCMhdCorrupted = 0;
585 fMCM->fADCmaskCorrupted = 0;
586 fMCM->fCorrupted = 0;
588 fMCM->fAdcDataPos = NULL;
589 fMCM->fADCcounter = 0;
591 for (Int_t i=0; i<21; i++){
592 fMCM->fADCchannel[i] = 0;
596 //------------------------------------------------------------
598 AliTRDrawStreamTB::ResetPerADC()
604 fADC->fADCnumber = 0;
606 fADC->fIsShared = kTRUE;
607 fADC->fCorrupted = 0;
609 for (Int_t i=0; i<30; i++){
610 fADC->fSignals[i] = 0;
614 //------------------------------------------------------------
616 AliTRDrawStreamTB::ResetMemory()
619 // initialize all the data members to prevent read data
620 // from previous buffer
623 for (Int_t istack=0; istack<5; istack++){
624 fStack = &fSM.fStacks[istack];
626 for (Int_t ilink=0; ilink<12; ilink++){
627 fHC = &fStack->fHalfChambers[ilink];
629 for (Int_t imcm=0; imcm<12; imcm++){
630 fMCM = &fHC->fMCMs[imcm];
632 for (Int_t iadc=0; iadc<12; iadc++){
633 fADC = &fMCM->fADCs[iadc];
641 //------------------------------------------------------------
644 AliTRDrawStreamTB::Next()
647 // returns with true on next adc read
648 // returns false on errors and end of buffer
653 while (fStackNumber < 5 && fSM.fActiveStacks > 0)
655 if(fSM.fStackActive[fStackNumber] == kTRUE)
657 fStack = &fSM.fStacks[fStackNumber];
658 while (fStackLinkNumber < 12)
660 if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0)
662 fHC = &fStack->fHalfChambers[fStackLinkNumber];
665 AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
668 if (fHC->fCorrupted == 0 && (fHC->fH0Corrupted == 0 && fHC->fH1Corrupted == 0)) // if HC data corrupted(in any case), we don't read data at all from this HC
670 while (fhcMCMcounter < fHC->fMCMmax)
672 fMCM = &fHC->fMCMs[fhcMCMcounter];
675 AliError(Form("HC missing at stack %d link %d atMCMslot %d",
676 fStackNumber, fStackLinkNumber, fhcMCMcounter));
679 while(fmcmADCcounter < fMCM->fADCmax)
681 fADC = &fMCM->fADCs[fmcmADCcounter];
684 AliError(Form("ADC missing at stack %d link %d MCMslot %d ADCslot %d",
685 fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));
695 if (fADC->fIsShared == kFALSE)
700 // next MCM should go through all active ADCs
706 // next stack link (HC) should go through all active MCMs
711 // next stack should go through all links - start from 0
712 fStackLinkNumber = 0;
716 // in case rawreader manages the mem buffers, go for the next buffer
719 Int_t nextBuff = NextBuffer();
720 while (nextBuff != -1)
727 nextBuff = NextBuffer();
734 //------------------------------------------------------------
736 AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager, UInt_t **trackletContainer)
739 // Fills single chamber digit array
740 // Return value is the detector number
743 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
744 AliTRDdataArrayDigits *digits = 0;
745 AliTRDdataArrayI *track0 = 0;
746 AliTRDdataArrayI *track1 = 0;
747 AliTRDdataArrayI *track2 = 0;
748 AliTRDSignalIndex *indexes = 0;
750 // Loop through the digits
756 Int_t ntracklets = 0;
758 if (trackletContainer){
759 for (Int_t i = 0; i < 2; i++)
760 for (Int_t j = 0; j < MAX_TRACKLETS_PERHC; j++)
761 trackletContainer[i][j] = 0;
769 if (trackletContainer)
771 if ((det + side*AliTRDgeometry::kNdet) != (lastdet + lastside*AliTRDgeometry::kNdet))
780 ntracklets = GetNTracklets();
781 if(ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets); //copy tracklet words to trackletContainer array
788 // If new detector found
798 if (det < 0 || det >= AliTRDgeometry::kNdet)
800 if (fSM.fClean == kTRUE)
802 AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));
806 AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));
811 // Add a container for the digits of this detector
812 digits = (AliTRDdataArrayDigits *) digitsManager->GetDigits(det);
814 if (digitsManager->UsesDictionaries())
816 track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0);
817 track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1);
818 track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2);
823 if (fSM.fClean == kTRUE)
825 AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));
829 AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));
834 Int_t rowMax = GetRowMax();
835 Int_t colMax = GetColMax();
836 Int_t ntbins = GetNumberOfTimeBins();
838 // Allocate memory space for the digits buffer
839 if (digits->GetNtime() == 0)
841 digits->Allocate(rowMax, colMax, ntbins);
842 if (digitsManager->UsesDictionaries())
844 track0->Allocate(rowMax, colMax, ntbins);
845 track1->Allocate(rowMax, colMax, ntbins);
846 track2->Allocate(rowMax, colMax, ntbins);
850 indexes = digitsManager->GetIndexes(det);
851 indexes->SetSM(GetSM());
852 indexes->SetStack(GetStack());
853 indexes->SetLayer(GetLayer());
854 indexes->SetDetNumber(det);
855 if (indexes->IsAllocated() == kFALSE)
856 indexes->Allocate(rowMax, colMax, ntbins);
859 Char_t padStatus = cal->GetPadStatus(det, GetCol(), GetRow());
861 // ntimebins data are ready to read
862 for (it = 0; it < GetNumberOfTimeBins(); it++)
864 if (GetSignals()[it] > 0)
866 digits->SetDataUnchecked(GetRow(), GetCol(), it, GetSignals()[it]);
868 digits->SetPadStatus(GetRow(), GetCol(), it, padStatus);
870 indexes->AddIndexTBin(GetRow(), GetCol(), it);
871 if (digitsManager->UsesDictionaries())
873 track0->SetDataUnchecked(GetRow(), GetCol(), it, 0);
874 track1->SetDataUnchecked(GetRow(), GetCol(), it, 0);
875 track2->SetDataUnchecked(GetRow(), GetCol(), it, 0);
884 //------------------------------------------------------------
886 AliTRDrawStreamTB::Init()
889 // Initialize geometry and fee parameters
892 TDirectory *saveDir = gDirectory;
896 fGeometry = new AliTRDgeometry();
901 AliError("Geometry FAILED!");
905 fTRDfeeParam = AliTRDfeeParam::Instance();
908 AliError("AliTRDfeeParam FAILED!");
912 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
914 ResetCounters(); // fBufferRead is set to kFALSE - important
921 //------------------------------------------------------------
923 AliTRDrawStreamTB::InitBuffer(void *buffer, UInt_t length)
926 // set initial information about the buffer
929 if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));
930 if (fRawReader->GetEquipmentId()<1024 || fRawReader->GetEquipmentId()>1041) //tmp protection
935 fpBegin = (UInt_t *)buffer;
939 AliFatal("Strange word size. size of UInt_t == 0");
943 fWordLength = length/WORD_SIZE;
944 fpEnd = fpBegin + fWordLength;
947 if (fpBegin == 0 || length <= 0)
949 AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%08x of size %d", fpBegin, length));
957 AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));
958 if (DumpWords(fpBegin, fgDumpHead) == kFALSE)
960 AliError("Dump failed. Not enough data.");
962 AliInfo(Form("---------- Dumping ended ----------------------------------------------"));
968 //------------------------------------------------------------
970 AliTRDrawStreamTB::DecodeGTUheader()
972 // Decode Supermodule Index Word
973 DecodeSMInfo(fpPos, &fSM);
975 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
980 // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design.
981 // For the moment, we skip decoding these words
982 if (SkipWords(fSM.fHeaderSize) == kTRUE)
984 for (Int_t istack = 0; istack < 5; istack++)
986 if (fSM.fStackActive[istack] == kFALSE)
989 fStack = &fSM.fStacks[istack];
991 // Decode Stack Index Word of given stack
992 DecodeStackInfo(fpPos, fStack);
995 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
997 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
999 if (SkipWords(fStack->fHeaderSize-6) == kFALSE) // 6 is the 6 stack header words for 12 links
1001 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing");
1004 for (Int_t iword=0; iword<6; iword++) // decode 6 stack header words
1006 // Decode Stack Header Word of given stack
1007 DecodeStackHeader(fpPos, fStack, iword);
1019 if (fgWarnError) AliWarning("No additional sm headers and stack index words present.");
1020 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
1026 if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");
1030 if (fgWarnError) AliWarning("No data just after GTU headers.");
1031 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");
1035 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));
1040 //------------------------------------------------------------
1042 AliTRDrawStreamTB::DecodeSM(void *buffer, UInt_t length)
1045 // decode one sm data in buffer
1051 if (InitBuffer(buffer, length) == kFALSE)
1053 if (fgWarnError) AliError("InitBuffer failed.");
1054 fSM.fClean = kFALSE;
1058 if (DecodeGTUheader()== kFALSE)
1061 for (Int_t istack = 0; istack < 5; istack++)
1063 fStackNumber = istack;
1064 if (fSM.fStackActive[istack] == kFALSE)
1067 fStack = &fSM.fStacks[istack];
1069 fgLastHC = -1; // to check rob number odering
1070 for (Int_t ilink = 0; ilink < 12; ilink++)
1072 fStackLinkNumber = ilink;
1073 if (fStack->fLinksActive[ilink] == kFALSE)
1076 // check GTU link monitor
1077 if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0))
1079 fStack->fLinkMonitorError[ilink] = 1;
1080 SeekEndOfData(); // skip this HC data if GTU link monitor report error
1081 fStack->fLinkMonitorError[ilink] += fNWordsCounter; // counts words of given hc having link monitor error
1087 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
1088 if (fgWarnError) AliError("Link data missing.");
1089 fSM.fClean = kFALSE;
1093 fHC = &fStack->fHalfChambers[ilink];
1096 if (fSM.fTrackletEnable == kTRUE)
1098 if (DecodeTracklets() == kFALSE)
1101 fSM.fClean = kFALSE;
1106 AliError(Form("Tracklet decoding failed stack %d link %d", fStackNumber, fStackLinkNumber));
1114 if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
1115 if (fgWarnError) AliError("HC data missing.");
1116 fSM.fClean = kFALSE;
1120 fgLastROB = -1; // to check mcm number odering
1121 fgLastIndex = -1 ; // to check mcm number odering
1122 if (DecodeHC() == kFALSE)
1124 fSM.fClean = kFALSE;
1125 if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW
1126 // during ADC data decoding or MCM header decoding
1127 // we don't seek ENDOFRAWDATAMARKER
1131 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
1132 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
1139 SeekEndOfData(); // make sure that finish off with the end of data markers
1145 ResetIterators(); // need to do it again for Next() function
1147 if (fSM.fClean == kTRUE)
1150 if (fgCleanDataOnly && (fSM.fClean == kFALSE))
1154 AliWarning("Buffer with errors. Returning FALSE.");
1155 AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
1157 fSM.fActiveStacks = 0; // Next() will not give data
1164 //------------------------------------------------------------
1166 AliTRDrawStreamTB::DecodeSM()
1169 // decode SM data in case AliRawReader is in use
1173 Int_t nextBuff = NextBuffer();
1174 while (nextBuff != -1)
1178 nextBuff = NextBuffer();
1184 AliWarning("AliRawReader not set.");
1189 //------------------------------------------------------------
1191 AliTRDrawStreamTB::DecodeSM(AliRawReader *reader)
1194 // decode SM with the AliRawReader
1198 fRawReader = reader;
1203 AliWarning("Argument AliRawReader is 0.");
1208 //------------------------------------------------------------
1210 AliTRDrawStreamTB::SeekEndOfData()
1213 // go to end of data marker
1215 Int_t fEndOfDataCount = 0;
1218 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1223 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd )
1232 //------------------------------------------------------------
1234 AliTRDrawStreamTB::SkipMCMdata(UInt_t iw)
1237 if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw));
1238 UInt_t iwcounter = 0;
1239 while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw)
1241 if ( *fpPos == END_OF_TRACKLET_MARKERNEW)
1243 if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW");
1244 fMCM->fCorrupted += 16;
1245 fHC->fCorrupted += 16;
1252 if (iwcounter == iw)
1258 if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");
1262 //------------------------------------------------------------
1264 AliTRDrawStreamTB::SeekNextMCMheader()
1272 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1274 if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0)
1276 if (fgDebugFlag) AliDebug(11,Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1279 if ( *fpPos == END_OF_TRACKLET_MARKERNEW)
1281 fMCM->fCorrupted += 16;
1282 fHC->fCorrupted += 16;
1292 //------------------------------------------------------------
1295 AliTRDrawStreamTB::DecodeTracklets()
1301 fLinkTrackletCounter = 0;
1302 fEndOfTrackletCount = 0;
1303 fHC->fNTracklets = 0;
1305 for (Int_t i = 0; i < MAX_TRACKLETS_PERHC; i++)
1306 fHC->fTrackletWords[i] = 0;
1308 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
1310 while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd )
1312 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
1314 fLinkTrackletCounter++;
1316 if (fLinkTrackletCounter > MAX_TRACKLETS_PERHC)
1318 if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d.",
1319 fLinkTrackletCounter, MAX_TRACKLETS_PERHC));
1320 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
1321 fHC->fTrackletError = 1;
1325 fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into array
1326 fHC->fNTracklets = fLinkTrackletCounter;
1330 while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd )
1332 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1334 fEndOfTrackletCount++;
1338 if ( fEndOfTrackletCount < 2 )
1340 if (fgDebugFlag) AliDebug(11,"End of tracklets word missing");
1341 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1342 fHC->fTrackletError += 2;
1349 //------------------------------------------------------------
1351 AliTRDrawStreamTB::IsRowValid()
1353 if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||
1354 (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 )
1356 if (fgDebugFlag) AliDebug(11,Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1357 , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));
1363 //------------------------------------------------------------
1365 AliTRDrawStreamTB::IsMCMheaderOK()
1368 // check the mcm header
1371 if (fgLastROB != fMCM->fROB)
1374 if (fgLastROB== -1) fgLastROB = fMCM->fROB;
1378 Int_t matchingcounter = 0;
1379 for (Int_t i=fgLastIndex+1; i<16; i++)
1381 if ( fMCM->fMCM == fgMCMordering[i] )
1388 if (matchingcounter == 0)
1390 fMCM->fMCMhdCorrupted += 2;
1391 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));
1395 if ( fgLastHC == fHC->fLayer*2 + fHC->fSide )
1397 if ( fMCM->fROB < (fMCM-1)->fROB )
1399 fMCM->fMCMhdCorrupted += 2;
1400 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));
1402 else fgLastROB = fMCM->fROB;
1405 fgLastHC = fHC->fLayer*2 + fHC->fSide;
1408 // this check will come back later again when we have "patched MCM map"
1409 int expectedROB = -1;
1410 if(!fHC->fSide) expectedROB = int(fHC->fMCMmax/16)*2;
1411 else expectedROB = int(fHC->fMCMmax/16)*2 + 1;
1412 int expectedMCM = 4*(3-int((fHC->fMCMmax%16)/4)) + fHC->fMCMmax%4;
1414 if ( expectedROB != fMCM->fROB || expectedMCM != fMCM->fMCM)
1416 fMCM->fMCMhdCorrupted += 2;
1417 AliDebug(11,Form("ROB expected %d ROB read %d, MCM expected %d MCM read %d\n",expectedROB, fMCM->fROB, expectedMCM, fMCM->fMCM));
1421 // below two conditions are redundant
1423 if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 )
1425 fMCM->fMCMhdCorrupted += 8; // need to assign new number
1426 if (fgDebugFlag) AliDebug(11,Form("ROB or MCM number is out of range. %s\n", DumpMCMinfo(fMCM)));
1428 if (IsRowValid() == kFALSE)
1430 fMCM->fMCMhdCorrupted += 16; // need to assign new number
1434 if (fEventCounter == 0)
1436 fEventCounter = fMCM->fEvCounter;
1439 if (fEventCounter != fMCM->fEvCounter)
1441 fMCM->fMCMhdCorrupted += 4; if (fgDebugFlag) AliDebug(11,Form("Event number(%d) of current MCM is different from that(%d) of reference MCM %s.\n", fMCM->fEvCounter, fEventCounter, DumpMCMinfo(fMCM)));
1444 if (fEventCounter < fLastEventCounter)
1446 fMCM->fMCMhdCorrupted += 8; if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM)));
1449 if ( fMCM->fADCmaskCorrupted > 0 )
1452 if ( fMCM->fMCMhdCorrupted > 0 )
1458 //------------------------------------------------------------
1460 AliTRDrawStreamTB::DecodeMCMheader()
1463 // decode the mcm header
1466 DecodeMCMheader(fpPos, fMCM);
1470 if (fMCM->fMCM == fDumpingMCM)
1472 if (fMCM->fROB == fDumpingROB && fHC->fLayer == fDumpingLayer)
1474 if (fHC->fSM == fDumpingSM && fHC->fStack == fDumpingStack)
1477 AliDebug(5,DumpHCinfoH0(fHC));
1478 AliDebug(5,DumpMCMinfo(fMCM));
1480 DumpWords(fpPos, 212);
1486 if (fHC->fCorrupted >= 16)
1492 fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
1494 if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || (fHC->fRawVMajor > 31 && fHC->fRawVMajor < 64)) //cover old and new version definition of ZS data
1497 if ( fpPos < fpEnd )
1499 DecodeMask(fpPos, fMCM);
1500 if (fHC->fCorrupted >= 16)
1505 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1506 fMCM->fAdcDataPos = fpPos + 1;
1510 if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END.");
1511 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1512 fHC->fCorrupted += 32;
1518 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
1519 DecodeMask(&dummyMask, fMCM);
1520 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1521 fMCM->fAdcDataPos = fpPos + 1;
1526 AliDebug(6, DumpMCMinfo(fMCM));
1527 AliDebug(7, DumpMCMadcMask(fMCM));
1530 if (IsMCMheaderOK() == kFALSE)
1536 //------------------------------------------------------------
1538 AliTRDrawStreamTB::IsHCheaderOK()
1541 // check insanity of half chamber header
1544 if (fHC->fStack < 0 || fHC->fStack > 4)
1546 if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStack));
1550 if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNlayer)
1552 if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayer));
1556 if (fHC->fSide < 0 || fHC->fSide > 1)
1558 if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSide));
1562 if (fgStackNumberChecker)
1564 if (fHC->fStack != fStackNumber)
1566 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d",
1567 fHC->fStack, fStackNumber));
1573 if (fgStackLinkNumberChecker)
1575 //if (fHC->fLayer * 2 + fHC->fSide != fStackLinkNumber)
1576 // let it make flexible to consider known fiber swapping
1577 if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1))
1579 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s",
1580 fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));
1581 fStackLinkNumber = -1;
1586 // SLOW GEOM : consistancy check with geometry
1587 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
1588 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet)
1590 if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET));
1591 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1595 if (fHC->fSM != fGeometry->GetSector(fHC->fDET)
1596 || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector)
1598 if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1599 fHC->fSM, fGeometry->GetSector(fHC->fDET),
1600 fHC->fStack, fHC->fLayer, fHC->fDET));
1601 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1605 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
1608 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1612 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
1613 if (fHC->fRowMax < 1)
1615 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1619 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
1620 if (fHC->fColMax < 1)
1622 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1629 //------------------------------------------------------------
1631 AliTRDrawStreamTB::DecodeHCheader()
1634 // decode the half chamber header
1637 if (DecodeHCwordH0(fpPos, fHC) == kFALSE)
1640 if (fHC->fNExtraWords > 0)
1645 if (DecodeHCwordH1(fpPos, fHC) == kFALSE)
1650 if (fgDebugFlag) AliDebug(11,"Expected HC header word 1. Fail due to buffer END.");
1651 if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing");
1656 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1657 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1660 if (IsHCheaderOK() == kFALSE)
1662 fHC->fH0Corrupted += 2;
1663 if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));
1670 //------------------------------------------------------------
1672 AliTRDrawStreamTB::DecodeHC()
1675 // decode hc header and data
1678 if (DecodeHCheader() == kFALSE)
1680 if (fgWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));
1681 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "HC header corrupted");
1689 fHC->fCorrupted += 1;
1690 if (fgDebugFlag) AliDebug(11,"No MCM data? Not enough data in the buffer.");
1691 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing");
1697 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd)
1699 if (fHC->fMCMmax > TRD_MAX_MCM)
1701 fHC->fCorrupted += 2;
1702 if (fgDebugFlag) AliDebug(11,"More mcm data than expected!");
1703 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!");
1707 fMCM = &fHC->fMCMs[fHC->fMCMmax];
1709 if (DecodeMCMheader() == kFALSE)
1711 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1713 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1714 return kFALSE; // stop HC data reading
1716 fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number
1718 // in case we decide to keep reading data, skip this mcm data and find next mcm header
1719 if (fMCM->fADCmaskCorrupted < 2)
1721 if (SkipMCMdata(fMCM->fADCcount*fMCM->fSingleADCwords) == kFALSE)
1727 if (SeekNextMCMheader() == kFALSE)
1735 if (fMCM->fADCmax > 0)
1740 fMCM->fCorrupted += 1;
1741 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1742 if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected."));
1746 for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++)
1748 fADC = &fMCM->fADCs[iadc];
1749 fADC->fADCnumber = fMCM->fADCchannel[iadc];
1751 if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.",
1752 iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1754 if (fpPos + fMCM->fSingleADCwords >= fpEnd)
1757 fMCM->fCorrupted += 2;
1758 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1759 if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");
1763 if (fHC->fRawVMajor < 64) // normal(real) ADC data
1765 if (DecodeADC() == kFALSE)
1767 if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4
1768 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1769 if (fADC->fIsShared && fADC->fCorrupted == 16) // check if we are out of the det when the pad is shared
1772 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1776 if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));
1777 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1778 return kFALSE; // stop HC data reading
1782 else // test pattern data
1784 if (fgWarnError) AliError("These are test pattern data. You need other reader"); // will be served in other class
1796 if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. There should be one more word left.");
1802 //------------------------------------------------------------
1805 AliTRDrawStreamTB::DecodeADC()
1808 // decode single ADC channel
1811 fADC->fCorrupted = 0;
1812 if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
1813 if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
1818 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
1819 fADC->fSignals[i] = 0;
1821 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
1823 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW)
1825 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1826 fADC->fCorrupted += 16;
1827 fHC->fCorrupted += 16;
1832 if (fMaskADCword != ADC_WORD_MASK(*fpPos))
1834 fADC->fCorrupted += 1;
1835 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",
1836 fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));
1841 // here we subtract the baseline ( == common additive)
1842 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1843 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1844 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1850 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
1852 fADC->fIsShared = kTRUE;
1856 fADC->fIsShared = kFALSE;
1859 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
1861 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
1866 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1869 if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0)
1871 if (fADC->fIsShared == kFALSE)
1873 fADC->fCorrupted += 32;
1874 if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1875 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1879 // we are out of the det when the pad is shared
1880 //if (fgDebugFlag) AliDebug(11, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1881 // fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1882 //fADC->fCorrupted += 32;
1886 if (fADC->fCorrupted > 0)
1895 //--------------------------------------------------------
1898 void AliTRDrawStreamTB::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
1901 // Decode Supermodule Index Word
1902 // The Supermodule Index Word is a 32-Bit word wit following structure
1903 // ssssssss ssssssss vvvv rrrr r d t mmmm
1904 // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use
1905 // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask
1907 sm->fPos = (UInt_t*)word;
1909 UInt_t vword = *word;
1910 sm->fHeaderSize = SM_HEADER_SIZE(vword);
1912 if (TRACKLETS_ENABLED(vword) > 0)
1913 sm->fTrackletEnable = kTRUE;
1915 sm->fTrackletEnable = kFALSE;
1917 UInt_t stackMask = STACK_MASK(vword);
1918 sm->fActiveStacks = 0;
1919 for (Int_t i = 0; i < 5; i++)
1921 if (IS_BIT_SET(stackMask,i) > 0)
1923 sm->fStackActive[i] = kTRUE;
1924 sm->fActiveStacks++;
1928 sm->fStackActive[i] = kFALSE;
1933 //--------------------------------------------------------
1934 const char *AliTRDrawStreamTB::DumpSMInfo(const struct AliTRDrawSM *sm)
1937 // Get SM structure into a const char
1939 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
1941 sm->fHeaderSize, sm->fTrackletEnable,
1942 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
1943 sm->fStackActive[3], sm->fStackActive[4]);
1946 //--------------------------------------------------------
1947 void AliTRDrawStreamTB::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
1950 // Decode Stack #i Index Word
1951 // The Stack #i Index Word is a 32-Bit word wit following structure
1952 // ssssssss ssssssss vvvv mmmm mmmmmmmm
1953 // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask
1955 st->fPos = (UInt_t*)word;
1957 UInt_t vword = *word;
1958 st->fHeaderSize = STACK_HEADER_SIZE(vword);
1960 UInt_t linkMask = STACK_LINK_WORD(vword);
1961 st->fActiveLinks = 0;
1962 for (Int_t i = 0; i < 12; i++)
1964 if (IS_BIT_SET(linkMask,i) > 0)
1966 st->fLinksActive[i] = kTRUE;
1971 st->fLinksActive[i] = kFALSE;
1976 //--------------------------------------------------------
1977 void AliTRDrawStreamTB::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const
1979 st->fPos = (UInt_t*)word;
1981 UInt_t vword = *word;
1982 st->fLinksDataType[2*iword] = LINK0_DATA_TYPE_FLAG(vword);
1983 st->fLinksMonitor[2*iword] = LINK0_MONITOR_FLAG(vword);
1984 st->fLinksDataType[2*iword+1] = LINK1_DATA_TYPE_FLAG(vword);
1985 st->fLinksMonitor[2*iword+1] = LINK1_MONITOR_FLAG(vword);
1988 //--------------------------------------------------------
1989 const char *AliTRDrawStreamTB::DumpStackInfo(const struct AliTRDrawStack *st)
1992 // format the string with the stack info
1995 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
1998 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
1999 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
2000 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
2004 //--------------------------------------------------------
2005 Bool_t AliTRDrawStreamTB::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
2008 // decode the hc header word 0
2010 UInt_t vword = *word;
2012 hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword);
2013 if (hc->fH0Corrupted > 0)
2015 if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%08x", *fHC->fPos));
2019 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
2020 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
2021 hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword);
2022 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
2023 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
2024 hc->fDCSboard = HC_DCS_BOARD(vword);
2025 hc->fSM = HC_SM_NUMBER(vword);
2026 hc->fStack = HC_STACK_NUMBER(vword);
2027 hc->fLayer = HC_LAYER_NUMBER(vword);
2028 hc->fSide = HC_SIDE_NUMBER(vword);
2030 hc->fPos[0] = (UInt_t*)word;
2035 //--------------------------------------------------------
2036 Bool_t AliTRDrawStreamTB::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
2039 // decode the hc header word 1
2042 UInt_t vword = *word;
2044 hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword);
2045 if (hc->fH1Corrupted > 0)
2047 if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%08x", *fHC->fPos));
2051 hc->fTimeBins = HC_NTIMEBINS(vword);
2052 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
2053 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
2054 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
2056 hc->fPos[1] = (UInt_t*)word;
2061 //--------------------------------------------------------
2062 const char *AliTRDrawStreamTB::DumpHCinfoH0(const struct AliTRDrawHC *hc)
2065 // dump the hc header word 0
2068 return Form("Unable to dump. Null received as parameter!?!");
2070 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
2071 hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
2074 //--------------------------------------------------------
2075 const char *AliTRDrawStreamTB::DumpHCinfoH1(const struct AliTRDrawHC *hc)
2078 // dump the hc header word 1
2081 return Form("Unable to dump. Null received as parameter!?!");
2083 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
2084 hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
2087 //--------------------------------------------------------
2088 void AliTRDrawStreamTB::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2091 // decode the mcm header
2093 UInt_t vword = *word;
2095 if (vword == END_OF_TRACKLET_MARKERNEW)
2097 if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
2098 mcm->fMCMhdCorrupted += 16;
2099 fHC->fCorrupted += 16; //to finish data reading of this HC
2102 mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error
2103 if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));
2105 mcm->fROB = MCM_ROB_NUMBER(vword);
2106 mcm->fMCM = MCM_MCM_NUMBER(vword);
2107 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
2108 mcm->fPos = (UInt_t*)word;
2111 //--------------------------------------------------------
2112 UInt_t AliTRDrawStreamTB::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2117 UInt_t vword = *word;
2122 mcm->fADCMaskWord = vword;
2124 if (vword == END_OF_TRACKLET_MARKERNEW)
2126 if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
2127 mcm->fADCmaskCorrupted += 16;
2128 fHC->fCorrupted += 16; //to finish data reading of this HC
2131 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 )
2133 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
2134 mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
2138 mcm->fADCMask = 0xffffffff;
2139 mcm->fADCmaskCorrupted = 1; // mcm adc mask error
2140 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));
2143 return mcm->fADCMask;
2146 //--------------------------------------------------------
2147 void AliTRDrawStreamTB::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2150 // decode the adc mask - adcs to be read out
2152 mcm->fMCMADCWords = 0;
2153 mcm->fSingleADCwords = 0;
2155 mcm->fADCMask = GetMCMadcMask(word, mcm);
2157 if (mcm->fADCMask > 0)
2159 for (Int_t i = 0; i < TRD_MAX_ADC; i++)
2161 mcm->fADCchannel[mcm->fADCmax] = 0;
2162 if( IS_BIT_SET(mcm->fADCMask,i) )
2164 mcm->fADCchannel[mcm->fADCmax] = i;
2169 if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) // backward compatibility
2171 mcm->fADCmaskCorrupted += 2;
2172 if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n", mcm->fADCcount, mcm->fADCmax, *fMCM->fPos));
2176 //--------------------------------------------------------
2177 void AliTRDrawStreamTB::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
2180 // count the expected mcm words for a given tbins
2182 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
2183 mcm->fSingleADCwords = 0;
2184 if (mcm->fADCmax > 0)
2186 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
2190 //--------------------------------------------------------
2191 const char *AliTRDrawStreamTB::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
2194 // mcm info in a string
2197 return Form("Unable to dump. Null received as parameter!?!");
2199 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
2202 //--------------------------------------------------------
2203 const char *AliTRDrawStreamTB::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
2206 // mcm adc mask in a string
2209 return Form("Unable to dump. Null received as parameter!?!");
2211 TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
2212 for (Int_t i = 0; i < 21; i++)
2214 tsreturn += Form("%d ", mcm->fADCchannel[i]);
2217 return tsreturn.Data();