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 "AliTRDdataArrayI.h"
40 #include "AliTRDSignalIndex.h"
43 #include "AliRawReader.h"
45 #define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa
46 #define END_OF_TRACKLET_MARKERNEW 0x10001000
47 #define ENDOFRAWDATAMARKER 0x00000000
48 #define WORD_SIZE sizeof(UInt_t) // size of a word in bytes
49 #define EXTRA_LEAD_WORDS 24
52 #define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w
53 #define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m
55 // SM index word masks:
56 #define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
57 #define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)
58 #define STACK_MASK(w) ((w) & 0x1f)
61 #define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
62 #define STACK_LINK_WORD(w) ((w) & 0xfff)
65 //#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!!
66 #define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK!!!
69 #define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)
70 #define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)
71 #define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)
72 #define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)
73 #define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)
74 #define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)
75 #define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)
76 #define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)
77 #define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)
80 #define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)
81 #define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)
82 #define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)
83 #define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,6)
85 //--------------------------------------------------------
87 // MCM word and ADC mask
88 #define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
89 #define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
90 #define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)
91 #define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)
92 #define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)
93 #define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)
95 //this should give 0x1fffff as a mask
96 #define MCM_DUMMY_ADCMASK_VAL 0x001fffffc
97 //--------------------------------------------------------
99 #define MAX_TRACKLETS_PERHC 256 // max number of tracklets per HC - large number for now
101 //--------------------------------------------------------
102 #define ADC_WORD_MASK(w) ((w) & 0x3)
103 //--------------------------------------------------------
104 ClassImp(AliTRDrawStreamTB)
106 Bool_t AliTRDrawStreamTB::fgExtraSkip = kFALSE;
107 Bool_t AliTRDrawStreamTB::fgSkipCDH = kFALSE;
108 Bool_t AliTRDrawStreamTB::fgWarnError = kTRUE;
109 Bool_t AliTRDrawStreamTB::fgCleanDataOnly = kTRUE;
110 Bool_t AliTRDrawStreamTB::fgDebugFlag = kTRUE;
111 Bool_t AliTRDrawStreamTB::fgDebugStreamFlag = kFALSE;
112 TTreeSRedirector *AliTRDrawStreamTB::fgDebugStreamer = 0;
113 UInt_t AliTRDrawStreamTB::fgStreamEventCounter = 0;
114 UInt_t AliTRDrawStreamTB::fgDumpHead = 0;
115 Int_t AliTRDrawStreamTB::fgCommonAdditive = 0;
116 Int_t AliTRDrawStreamTB::fgEmptySignals[] =
118 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
119 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
122 AliTRDrawStreamTB::AliTRDrawStreamTB()
134 , fStackLinkNumber(-1)
137 , fLinkTrackletCounter(-1)
138 , fEndOfTrackletCount(-1)
143 , fLastEventCounter(0)
144 , fSharedPadsOn(kFALSE)
149 , fDebugStreamOwned(kFALSE)
152 // default constructor
155 if (Init() == kFALSE)
157 AliWarning("Unable to Init.");
161 //--------------------------------------------------------
162 AliTRDrawStreamTB::AliTRDrawStreamTB(AliRawReader *rawReader)
174 , fStackLinkNumber(-1)
177 , fLinkTrackletCounter(-1)
178 , fEndOfTrackletCount(-1)
183 , fLastEventCounter(0)
184 , fSharedPadsOn(kFALSE)
187 , fRawReader(rawReader)
189 , fDebugStreamOwned(kFALSE)
192 // default constructor
196 if (Init() == kFALSE)
198 AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
203 AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
207 //------------------------------------------------------------
209 AliTRDrawStreamTB::AliTRDrawStreamTB(const AliTRDrawStreamTB& /*st*/)
221 , fStackLinkNumber(-1)
224 , fLinkTrackletCounter(-1)
225 , fEndOfTrackletCount(-1)
230 , fLastEventCounter(0)
231 , fSharedPadsOn(kFALSE)
236 , fDebugStreamOwned(kFALSE)
241 AliError("Not implemeneted.");
244 //------------------------------------------------------------
245 void AliTRDrawStreamTB::SetRawVersion(Int_t fraw)
248 // function provided for backward compatibility
250 AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");
251 fraw = 0; // avoid warnings
254 //------------------------------------------------------------
255 AliTRDrawStreamTB::~AliTRDrawStreamTB()
262 if (fDebugStreamOwned == kTRUE)
266 delete fgDebugStreamer;
272 //------------------------------------------------------------
275 AliTRDrawStreamTB::operator=(const AliTRDrawStreamTB &)
278 // we are not using this functionality
280 AliFatal("May not use.");
284 //------------------------------------------------------------
287 AliTRDrawStreamTB::EnableDebug(TTreeSRedirector *debugStream)
290 // replace the current debug streamer or create a new one if owned
293 if (debugStream == 0)
295 if (fDebugStreamOwned == kTRUE)
298 delete fgDebugStreamer;
301 fDebugStreamOwned = kTRUE;
302 fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root");
303 fgStreamEventCounter = 0;
308 if (fDebugStreamOwned == kTRUE)
311 delete fgDebugStreamer;
314 fgDebugStreamer = debugStream;
315 fDebugStreamOwned = kFALSE;
319 //___________________________________________________________
321 AliTRDrawStreamTB::SwapOnEndian()
324 // Check the endian and swap if needed
328 char* ptemp = (char*) &itemp;
332 if (fgDebugFlag) AliDebug(8, "Swapping.");
336 while (fpPos < fpEnd)
339 iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
340 ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
341 // here we override the value in the buffer!
348 //------------------------------------------------------------
350 AliTRDrawStreamTB::DumpErrorCount()
353 // print the error statistics into the stdout
357 // AliInfo(Form("Error counts: HC0 %d HC1 %d MCM %d ADCmask %d ADC %d",
358 // fHC->fH0ErrorCounter, fHC->fH1ErrorCounter, fMCM->fErrorCounter, fMCM->fMaskErrorCounter, adc.fErrorCounter));
361 //------------------------------------------------------------
363 AliTRDrawStreamTB::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
367 // note: can be made faster
370 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
371 for (UInt_t i = 0; i < iw; i++)
373 if (px + iw >= fpEnd)
378 if (marker != 0 && marker == px[i])
379 tsreturn += Form(" *>0x%08x<* ", px[i]);
381 tsreturn += Form("0x%08x ", px[i]);
385 AliInfo(tsreturn.Data());
390 //------------------------------------------------------------
392 AliTRDrawStreamTB::SkipWords(UInt_t iw)
396 // note: can be made faster
399 if ( fpPos + iw < fpEnd )
406 if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
409 TTreeSRedirector &cstream = *fgDebugStreamer;
410 cstream << "SkipWords"
411 << "Event=" << fgStreamEventCounter
413 // << ".read=" << (Char_t*)(fpPos - fpBegin)
414 // << ".togo=" << (Char_t*)(fpEnd - fpPos)
415 // << ".length=" << (Char_t*)(fpEnd - fpBegin)
424 //------------------------------------------------------------
426 AliTRDrawStreamTB::SetReader(AliRawReader *reader)
441 AliWarning("Unable to setup reader.");
447 AliWarning("AliRawReader argument is 0.");
454 //------------------------------------------------------------
456 AliTRDrawStreamTB::NextBuffer()
459 // return -1 if no more buffers available
460 // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come
461 // return 1 DecodeSM OK
468 Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
469 if (kBufferSet == kTRUE)
471 if (fgDebugFlag) AliDebug(9, "Buffer is set.");
472 length = fRawReader->GetDataSize();
473 if (fgExtraSkip == kTRUE)
475 buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
476 length -= EXTRA_LEAD_WORDS * WORD_SIZE;
479 if (fgSkipCDH == kTRUE)
481 buffer += CDH_WORDS * WORD_SIZE;
482 length -= CDH_WORDS * WORD_SIZE;
487 if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
488 //return InitBuffer((void*)buffer, length);
489 if (DecodeSM((void*)buffer, length) == kTRUE)
504 //------------------------------------------------------------
506 AliTRDrawStreamTB::ResetCounters()
509 // reset some global counters
513 fStackLinkNumber = 0;
517 fSM.fActiveStacks = 0;
518 fSM.fNexpectedHalfChambers = 0;
520 fLinkTrackletCounter = 0;
522 fLastEventCounter = 0;
526 //------------------------------------------------------------
528 AliTRDrawStreamTB::ResetIterators()
531 // reset the data iterators used in the Next()
534 fStackLinkNumber = 0;
539 //------------------------------------------------------------
542 AliTRDrawStreamTB::Next()
545 // returns with true on next adc read
546 // returns false on errors and end of buffer
549 while (fStackNumber < 5 && fSM.fActiveStacks > 0)
551 if(fSM.fStackActive[fStackNumber] == kTRUE)
553 fStack = &fSM.fStacks[fStackNumber];
554 while (fStackLinkNumber < 12)
556 if (fStack->fLinksActive[fStackLinkNumber] == kTRUE)
558 fHC = &fStack->fHalfChambers[fStackLinkNumber];
561 AliError(Form("Super Strange. HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
564 //if (fgDebugFlag) AliDebug(2, DumpHCinfoH0(fHC));
565 if (fHC->fCorrupted == 0)
567 while (fhcMCMcounter < fHC->fMCMmax)
569 fMCM = &fHC->fMCMs[fhcMCMcounter];
570 //if (fgDebugFlag) AliDebug(2, DumpMCMinfo(fMCM));
573 AliError(Form("Super Strange. HC missing at stack %d link %d atMCMslot %d",
574 fStackNumber, fStackLinkNumber, fhcMCMcounter));
577 while(fmcmADCcounter < fMCM->fADCmax)
579 //printf("%d %d %d %d\n", fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter);
580 fADC = &fMCM->fADCs[fmcmADCcounter];
583 AliError(Form("Super Strange. ADC missing at stack %d link %d MCMslot %d ADCslot %d",
584 fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));
588 //printf("ADC count %d \n", fmcmADCcounter);
595 if (fADC->fIsShared == kFALSE)
599 //printf("MCM count %d \n", fhcMCMcounter);
601 // next MCM should go through all active ADCs
607 // next stack link (HC) should go through all active MCMs
612 // next stack should go through all links - start from 0
613 fStackLinkNumber = 0;
616 // in case rawreader manages the mem buffers
617 // lets go for the next buffer
620 Int_t nextBuff = NextBuffer();
621 while (nextBuff != -1)
625 nextBuff = NextBuffer();
632 //------------------------------------------------------------
635 AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager)
638 // Fills single chamber digit array
639 // Return value is the detector number
642 AliTRDdataArrayI *digits = 0;
643 AliTRDdataArrayI *track0 = 0;
644 AliTRDdataArrayI *track1 = 0;
645 AliTRDdataArrayI *track2 = 0;
646 AliTRDSignalIndex *indexes = 0;
648 // Loop through the digits
651 // Int_t returnDet = -1;
659 // If new detector found
669 // Add a container for the digits of this detector
670 digits = digitsManager->GetDigits(det);
671 track0 = digitsManager->GetDictionary(det,0);
672 track1 = digitsManager->GetDictionary(det,1);
673 track2 = digitsManager->GetDictionary(det,2);
675 Int_t rowMax = GetRowMax();
676 Int_t colMax = GetColMax();
677 Int_t ntbins = GetNumberOfTimeBins();
679 // Allocate memory space for the digits buffer
680 if (digits->GetNtime() == 0)
682 digits->Allocate(rowMax, colMax, ntbins);
683 track0->Allocate(rowMax, colMax, ntbins);
684 track1->Allocate(rowMax, colMax, ntbins);
685 track2->Allocate(rowMax, colMax, ntbins);
688 indexes = digitsManager->GetIndexes(det);
689 indexes->SetSM(GetSM());
690 indexes->SetStack(GetStack());
691 indexes->SetLayer(GetLayer());
692 indexes->SetDetNumber(det);
693 if (indexes->IsAllocated() == kFALSE)
694 indexes->Allocate(rowMax, colMax, ntbins);
697 // ntimebins data are ready to read
698 for (it = 0; it < GetNumberOfTimeBins(); it++)
700 if (GetSignals()[it] > 0)
702 digits->SetDataUnchecked(GetRow(), GetCol(), it, GetSignals()[it]);
704 indexes->AddIndexTBin(GetRow(), GetCol(), it);
705 track0->SetDataUnchecked(GetRow(), GetCol(), it, 0);
706 track1->SetDataUnchecked(GetRow(), GetCol(), it, 0);
707 track2->SetDataUnchecked(GetRow(), GetCol(), it, 0);
712 // what happens if the last HC is turned off?
717 //------------------------------------------------------------
719 AliTRDrawStreamTB::Init()
725 TDirectory *saveDir = gDirectory;
729 fGeometry = new AliTRDgeometry();
734 AliError("Geometry FAILED!");
738 fTRDfeeParam = AliTRDfeeParam::Instance();
741 AliError("AliTRDfeeParam FAILED!");
745 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
747 // common additive is moved to be static for temp solution
748 // common additive should be delivered in the HC word 2 (3rd word)
749 //fCommonAdditive = 10;
753 // in case rawreader manages the mem buffers
754 // lets go for the next buffer
757 Int_t nextBuff = NextBuffer();
758 while (nextBuff != -1)
762 nextBuff = NextBuffer();
766 if (fgDebugStreamFlag == kTRUE)
768 if (!fgDebugStreamer)
770 fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root");
771 fgStreamEventCounter = 0;
775 AliInfo(Form("Debug Streamer Initialized! Remember to delete! %s::DeleteDebugStream()", this->IsA()->GetName()));
776 //fDebugStreamOwned = kTRUE;
780 AliError("Unable to init debug stream");
790 void AliTRDrawStreamTB::DeleteDebugStream()
793 // static helper function
798 delete fgDebugStreamer;
804 //------------------------------------------------------------
806 AliTRDrawStreamTB::InitBuffer(void *buffer, UInt_t length)
809 // init the class before reading from the buffer
810 // and read SM heading info:
811 // -- super module header
812 // -- stack headers + link status words
815 // not in the pre scan mode
816 fgStreamEventCounter++;
820 fpBegin = (UInt_t *)buffer;
824 AliFatal("Strange! Size of UInt_t == 0");
828 fWordLength = length/WORD_SIZE;
829 fpEnd = fpBegin + fWordLength;
832 if (fpBegin == 0 || length <= 0)
834 AliError(Form("This will not work! Pointer to the buffer is 0x%08x of size %d", fpBegin, length));
842 AliInfo("------------------------------------------------");
843 if (DumpWords(fpBegin, fgDumpHead) == kFALSE)
845 AliError("Dump failed. Not enough data.");
847 AliInfo("------------------------------------------------");
851 DecodeSMInfo(fpPos, &fSM);
853 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
858 if (SkipWords(fSM.fHeaderSize) == kTRUE)
861 //for (Int_t istack = 0; istack < fSM.fActiveStacks; istack++)
862 for (Int_t istack = 0; istack < 5; istack++)
864 if (fSM.fStackActive[istack] == kFALSE)
867 fStack = &fSM.fStacks[istack];
868 DecodeStackInfo(fpPos, fStack);
871 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
873 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
875 if (SkipWords(fStack->fHeaderSize) == kFALSE)
877 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack head words missing");
889 if (fgWarnError) AliWarning("No Stack info present. Strange.");
890 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
894 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers : %d", fSM.fNexpectedHalfChambers));
899 if (fgDebugFlag) AliDebug(5, "Init OK.");
903 if (fgWarnError) AliWarning("No data just after init. Strange.");
904 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing data");
911 //------------------------------------------------------------
913 AliTRDrawStreamTB::DecodeSM(void *buffer, UInt_t length)
916 // decode all sm at once
917 // still here for devel and debug
920 //memset(&fSM, 0, sizeof(fSM));
925 if (InitBuffer(buffer, length) == kTRUE)
927 // no we are already set!
932 if (fgWarnError) AliError("--- INIT failed. ---------------");
939 for (Int_t istack = 0; istack < 5; istack++)
941 fStackNumber = istack;
942 if (fSM.fStackActive[istack] == kFALSE)
945 fStack = &fSM.fStacks[istack];
947 //fStack[istack].fActiveLinks // max is 12
948 for (Int_t ilink = 0; ilink < 12; ilink++)
950 fStackLinkNumber = ilink;
951 if (fStack->fLinksActive[ilink] == kFALSE)
956 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
961 fHC = &fStack->fHalfChambers[ilink];
963 if (fSM.fTrackletEnable == kTRUE)
965 if (DecodeTracklets() == kFALSE)
967 // if (fgWarnError) AliError(Form("--- Decode Tracklets failed. --------------- Link %d of %d",
968 // ilink + 1, fStack->fActiveLinks));
971 TTreeSRedirector &cstream = *fgDebugStreamer;
972 cstream << "TrackletDecodeError"
973 << "Event=" << fgStreamEventCounter
974 << ".Stack=" << fStackNumber
975 << ".Link=" << fStackLinkNumber
976 << ".EndOfTrackletCount=" << fEndOfTrackletCount
985 AliError(Form("Failed stack %d link %d", fStackNumber, fStackLinkNumber));
986 AliError(Form("Debug Event Counter : %d", fgStreamEventCounter));
995 if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
1000 if (DecodeHC() == kFALSE)
1002 // if (fgWarnError) AliError(Form("--- Decode HC failed. --------------- Link %d of %d",
1003 // ilink + 1, fStack->fActiveLinks));
1004 fSM.fClean = kFALSE;
1005 fHC->fCorrupted += 100;
1010 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
1011 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
1012 AliError(Form("Debug Event Counter : %d", fgStreamEventCounter));
1014 // let us assume that we have the HC data although link mask says different
1016 if (fStackLinkNumber == -1)
1018 if (fgWarnError) AliWarning("Trying to recover to the right Link Mask.");
1027 // just finish off with the end of data markers
1031 //if (fgDebugFlag) AliDebug(5, Form("++++ Done with link %d of %d", ilink + 1, fStack->fActiveLinks));
1039 if (fSM.fClean == kTRUE)
1042 if (fgCleanDataOnly && (fSM.fClean == kFALSE))
1046 AliWarning("Buffer with errors. Returning FALSE.");
1047 AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
1049 fSM.fActiveStacks = 0; // Next will not give data
1056 //------------------------------------------------------------
1058 AliTRDrawStreamTB::DecodeSM()
1061 // decode SM data in case AliRawReader is in use
1065 Int_t nextBuff = NextBuffer();
1066 while (nextBuff != -1)
1070 nextBuff = NextBuffer();
1076 AliWarning("AliRawReader not set.");
1081 //------------------------------------------------------------
1083 AliTRDrawStreamTB::DecodeSM(AliRawReader *reader)
1086 // decode SM with the AliRawReader
1090 fRawReader = reader;
1095 AliWarning("Argument AliRawReader is 0.");
1100 //------------------------------------------------------------
1102 AliTRDrawStreamTB::SeekEndOfData()
1105 // go to end of data marker
1107 Int_t fEndOfDataCount = 0;
1109 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1114 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd )
1120 // if (fEndOfDataCount == 0)
1122 // if (fgWarnError) AliWarning("End of buffer reached first. No end of data marker?");
1129 //------------------------------------------------------------
1131 AliTRDrawStreamTB::SeekNextMCMheader()
1137 // move back to the mcm pos
1138 fpPos = fMCM->fPos + 1;
1140 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1142 //if (CheckMCMMask(fpPos) == 0)
1143 if (MCM_HEADER_MASK_ERR(*fpPos) == 0)
1145 if (fgWarnError) AliWarning(Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1155 //------------------------------------------------------------
1158 AliTRDrawStreamTB::DecodeTracklets()
1164 fLinkTrackletCounter = 0;
1165 fEndOfTrackletCount = 0;
1167 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
1168 //cout << Form("Decode tracklets..") << endl;;
1169 //printf("[I] Tracklet... ? \n");
1171 while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd )
1174 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
1176 //decode tracklets here...
1177 fLinkTrackletCounter++;
1179 if (fLinkTrackletCounter > MAX_TRACKLETS_PERHC)
1181 if (fgWarnError) AliWarning(Form("Max number of tracklets exceeded %d > %d. Something is wrong with the input data!",
1182 fLinkTrackletCounter, MAX_TRACKLETS_PERHC));
1184 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
1188 if (fgDebugStreamer)
1204 row = (val >> 20) & 0xF;
1205 defl = (val >> 13) & 0x7F;
1206 defl = defl << 25 >> 25;
1207 ypos = val & 0x1FFF;
1208 ypos = ypos << 19 >> 19;
1210 deflm = defl * 140.0e-6; /* m */
1211 yposm = ypos * 160.0e-6; /* m */
1213 TTreeSRedirector &cstream = *fgDebugStreamer;
1214 cstream << "MCMtracklets"
1215 << "Event=" << fgStreamEventCounter
1216 << ".stack=" << fStackNumber
1217 << ".link=" << fStackLinkNumber
1222 << ".deflm=" << deflm
1223 << ".yposm=" << yposm
1229 while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd )
1231 //seek non end of tracklets
1232 //printf("[I] End of tracklets. \n");
1233 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1235 fEndOfTrackletCount++;
1239 if ( fEndOfTrackletCount < 2 )
1241 //if (fgWarnError) AliWarning(Form("End of tracklet marker words missing %d", 2 - fEndOfTrackletCount));
1242 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1249 //------------------------------------------------------------
1251 AliTRDrawStreamTB::IsRowValid()
1254 if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||
1255 (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 )
1257 if (fgWarnError) AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1258 , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));
1259 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadrow, "Wrong Row");
1265 //------------------------------------------------------------
1267 AliTRDrawStreamTB::IsMCMheaderOK()
1270 // check the mcm header
1273 if ( fMCM->fCorrupted > 10 )
1275 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"ADC mask Corrupted");
1276 if (fgWarnError) AliWarning(Form("Wrong ADC Mask word 0x%08x %s. Error : %d", *fMCM->fPos, DumpMCMadcMask(fMCM), fMCM->fCorrupted));
1280 if ( fMCM->fCorrupted > 0 )
1282 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"Corrupted");
1283 if (fgWarnError) AliWarning(Form("Wrong MCM word 0x%08x %s. Error : %d", *fMCM->fPos, DumpMCMinfo(fMCM), fMCM->fCorrupted));
1287 if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 )
1289 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongMCMorROB,"Wrong ROB or MCM");
1290 if (fgWarnError) AliWarning(Form("Wrong fMCM or fROB. %s Skip this data.", DumpMCMinfo(fMCM)));
1294 if (IsRowValid() == kFALSE)
1299 //------------------------------------------------------------
1301 AliTRDrawStreamTB::DecodeMCMheader()
1304 // decode the mcm header
1307 DecodeMCMheader(fpPos, fMCM);
1309 fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
1311 if (fHC->fRawVMajor > 2)
1314 if ( fpPos < fpEnd )
1316 DecodeMask(fpPos, fMCM);
1317 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1318 fMCM->fAdcDataPos = fpPos + 1;
1322 if (fgWarnError) AliWarning("Expected ADC mask word. Fail due to buffer END.");
1323 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1329 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
1330 DecodeMask(&dummyMask, fMCM);
1331 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1332 fMCM->fAdcDataPos = fpPos + 1;
1337 AliDebug(6, DumpMCMinfo(fMCM));
1338 AliDebug(7, DumpMCMadcMask(fMCM));
1341 if (IsMCMheaderOK() == kFALSE)
1346 if (fEventCounter == 0)
1348 fEventCounter = fMCM->fEvCounter;
1351 if (fEventCounter < fLastEventCounter)
1353 if (fgWarnError) AliWarning(Form("Weird. Event from the past? Current %d Last %d %s", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM)));
1354 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ? Past-Future");
1358 if (fEventCounter != fMCM->fEvCounter)
1360 if (fgWarnError) AliWarning(Form("Weird. Event missmatch? %d %s", fEventCounter, DumpMCMinfo(fMCM)));
1361 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ?");
1365 //fLastEventCounter = fEventCounter;
1366 //AliInfo(Form("Current MCM %s", DumpMCMinfo(fMCM)));
1369 //return IsMCMheaderOK();
1372 //------------------------------------------------------------
1374 AliTRDrawStreamTB::IsHCheaderOK()
1377 // check the half chamber header
1380 if (fHC->fCorrupted > 0)
1382 if (fgWarnError) AliWarning(Form("Wrong HC Header word. Word 0x%08x Error : %d", *fHC->fPos, fHC->fCorrupted));
1383 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "Corrupted");
1388 if (fHC->fStack < 0 || fHC->fStack > 4)
1390 if (fgWarnError) AliWarning(Form("Wrong Stack %d", fHC->fStack));
1391 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Wrong Stack");
1395 if (fHC->fStack != fStackNumber)
1397 if (fgWarnError) AliWarning(Form("Missmatch: Stack in HC header %d HW-stack %d",
1398 fHC->fStack, fStackNumber));
1399 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Stack-HWstack");
1400 // Try this for recovery in DecodeSM(void*,UInt_t) after DecodeHC failed
1401 // buffer will still will be marked as NOT clean
1406 if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNplan)
1408 if (fgWarnError) AliWarning(Form("Wrong plane(layer) %d", fHC->fLayer));
1409 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Wrong Plane");
1413 if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1))
1415 if (fgWarnError) AliWarning(Form("Missmatch: plane(layer) in HCheader %d HW-Link %d | %s",
1416 fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));
1417 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Plane-Link missmatch");
1418 // Try this for recovery in DecodeSM(void*,UInt_t) after DecodeHC failed
1419 // buffer will still will be marked as NOT clean
1420 fStackLinkNumber = -1;
1424 if (fHC->fSide < 0 || fHC->fSide > 1)
1426 if (fgWarnError) AliWarning(Form("Wrong Side %d", fHC->fSide));
1427 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSide, "Wrong Side");
1432 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
1433 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet)
1435 if (fgWarnError) AliWarning(Form("Wrong detector %d", fHC->fDET));
1436 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1441 // this check fails - raw data inconsistent with geometry?
1442 if (fHC->fSM != fGeometry->GetSector(fHC->fDET)
1443 || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsect)
1445 if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1446 fHC->fSM, fGeometry->GetSector(fHC->fDET),
1447 fHC->fStack, fHC->fLayer, fHC->fDET));
1448 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1454 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
1457 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1461 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
1462 if (fHC->fRowMax < 1)
1464 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1468 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
1469 if (fHC->fColMax < 1)
1471 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1474 // extra - not needed
1475 // if (fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsect)
1477 // if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d",
1478 // fHC->fSM, fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack),
1479 // fHC->fStack, fHC->fLayer));
1486 //------------------------------------------------------------
1488 AliTRDrawStreamTB::DecodeHCheader()
1491 // decode the half chamber header
1494 DecodeHCwordH0(fpPos, fHC);
1496 if (fHC->fNExtraWords > 0)
1501 DecodeHCwordH1(fpPos, fHC);
1505 if (fgWarnError) AliWarning("Expected HC header word 1. Fail due to buffer END.");
1506 if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing");
1511 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1512 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1515 if (IsHCheaderOK() == kFALSE)
1523 //------------------------------------------------------------
1525 AliTRDrawStreamTB::DecodeHC()
1528 // decode the hc data
1529 // function for devel & debug
1532 if (DecodeHCheader() == kFALSE)
1534 if (fgDebugStreamer)
1536 TTreeSRedirector &cstream = *fgDebugStreamer;
1537 cstream << "HCDecodeError"
1538 << "Event=" << fgStreamEventCounter
1539 << ".stack=" << fStackNumber
1540 << ".link=" << fStackLinkNumber
1541 << ".hcCorrupted" << fHC->fCorrupted
1542 << ".hcRVmajor=" << fHC->fRawVMajor
1543 << ".hcDCSboard=" << fHC->fDCSboard
1544 << ".hcSM=" << fHC->fSM
1545 << ".hcStack=" << fHC->fStack
1546 << ".hcLayer=" << fHC->fLayer
1547 << ".hcSide=" << fHC->fSide
1548 << ".hcTbins=" << fHC->fTimeBins
1549 << ".hcBunchCross=" << fHC->fBunchCrossCounter
1550 << ".hcPreTrig=" << fHC->fPreTriggerCounter
1551 << ".hcPreTrigPh=" << fHC->fPreTriggerPhase
1552 << ".hcDet=" << fHC->fDET
1553 << ".hcROC=" << fHC->fROC
1554 << ".hc=RowMax" << fHC->fRowMax
1555 << ".hc=ColMax" << fHC->fColMax
1559 if (fgWarnError) AliWarning("Header decode failed.");
1567 if (fgWarnError) AliWarning("No MCM data? Not enough data in the buffer.");
1568 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing");
1574 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd)
1576 if (fHC->fMCMmax > TRD_MAX_MCM)
1578 if (fgWarnError) AliWarning("More mcm data than expected!");
1579 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!");
1583 fMCM = &fHC->fMCMs[fHC->fMCMmax];
1585 if (DecodeMCMheader() == kFALSE)
1587 if (fgDebugStreamer)
1589 TTreeSRedirector &cstream = *fgDebugStreamer;
1590 cstream << "MCMDecodeError"
1591 << "Event=" << fgStreamEventCounter
1592 << ".stack=" << fStackNumber
1593 << ".link=" << fStackLinkNumber
1594 << ".hcDCSboard=" << fHC->fDCSboard
1595 << ".hcSM=" << fHC->fSM
1596 << ".hcStack=" << fHC->fStack
1597 << ".hcLayer=" << fHC->fLayer
1598 << ".hcSide=" << fHC->fSide
1599 << ".hcBunchCross=" << fHC->fBunchCrossCounter
1600 << ".hcPreTrig=" << fHC->fPreTriggerCounter
1601 << ".hcPreTrigPh=" << fHC->fPreTriggerPhase
1602 << ".hcDet=" << fHC->fDET
1604 << ".mcmCorrupted=" << fMCM->fCorrupted
1605 << ".mcmROB=" << fMCM->fROB
1606 << ".mcmMCM=" << fMCM->fMCM
1607 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1608 << ".mcmEventCounter=" << fMCM->fEvCounter
1610 << ".fEventCounter=" << fEventCounter
1611 << ".fLastEventCounter=" << fLastEventCounter
1620 if (fMCM->fADCmax > 0)
1625 if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected."));
1626 if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing");
1629 // for (Int_t iadc = 0; iadc < TRD_MAX_ADC; iadc++)
1630 for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++)
1632 fADC = &fMCM->fADCs[iadc];
1633 fADC->fADCnumber = fMCM->fADCchannel[iadc];
1635 if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.",
1636 iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1638 if (fpPos + fMCM->fSingleADCwords >= fpEnd)
1640 if (fgDebugStreamer)
1642 TTreeSRedirector &cstream = *fgDebugStreamer;
1643 // means no data read
1645 cstream << "ADCDecodeError"
1646 << "Event=" << fgStreamEventCounter
1647 << ".hcSM=" << fHC->fSM
1648 << ".hcStack=" << fHC->fStack
1649 << ".hcLayer=" << fHC->fLayer
1650 << ".mcmROB=" << fMCM->fROB
1651 << ".mcmMCM=" << fMCM->fMCM
1652 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1653 << ".adcErr=" << ierr
1654 << ".adcNumber=" << ierr
1658 if (fgWarnError) AliWarning(Form("This is ADC %d of %d. ADC number is %d.", iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1659 if (fgWarnError) AliWarning("--> ADC (10 words) expected. Not enough data in the buffer.");
1660 if (fgWarnError) AliWarning(Form("--> ADC mask : %s", DumpMCMadcMask(fMCM)));
1662 if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing - less than expected");
1666 //DECODE the data here
1667 if (DecodeADC() == kFALSE)
1669 // check if we are out of the det when the pad is shared
1670 if (fADC->fIsShared && fADC->fCorrupted == 111)
1673 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1677 if (fgWarnError) AliWarning(Form("ADC decode failed."));
1678 //fpPos = fMCM->fPpos + fMCMADCWords;
1680 if (fgDebugStreamer)
1682 TTreeSRedirector &cstream = *fgDebugStreamer;
1683 cstream << "ADCDecodeError"
1684 << "Event=" << fgStreamEventCounter
1685 << ".hcSM=" << fHC->fSM
1686 << ".hcStack=" << fHC->fStack
1687 << ".hcLayer=" << fHC->fLayer
1688 << ".mcmROB=" << fMCM->fROB
1689 << ".mcmMCM=" << fMCM->fMCM
1690 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1691 << ".adcErr=" << fADC->fCorrupted
1692 << ".adcNumber=" << fADC->fADCnumber
1696 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1700 //decode the ADC words here
1702 } //mcm data present
1711 if (fgWarnError) AliWarning("We are at the end of buffer. There should be one more word left.");
1719 //------------------------------------------------------------
1721 AliTRDrawStreamTB::DecodeADC()
1724 // decode single ADC channel
1727 fADC->fCorrupted = 0;
1728 fMaskADCword = ADC_WORD_MASK(*fpPos);
1733 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
1734 fADC->fSignals[i] = 0;
1736 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
1738 if (fMaskADCword != ADC_WORD_MASK(*fpPos))
1740 //this is corrupted data
1741 fADC->fCorrupted += 1;
1742 if (fgWarnError) AliWarning(Form("Mask Change in ADC data Previous word (%d) : 0x%08x Previous mask : 0x%08x Current word(%d) : 0x%08x Current mask : 0x%08x",
1743 iw - 1, *(fpPos-1), fMaskADCword, iw, *fpPos, ADC_WORD_MASK(*fpPos)));
1744 if (fRawReader) fRawReader->AddMajorErrorLog(kADCmaskMissmatch, "Mask change inside single channel");
1749 // here we subtract the baseline ( == common additive)
1750 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1751 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1752 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1758 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
1760 fADC->fIsShared = kTRUE;
1764 fADC->fIsShared = kFALSE;
1767 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
1769 // let us guess the Column
1770 // take the one before last ADC and shift by one column
1771 // later we check if we are inside the limits of the chamber
1772 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
1777 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1780 if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0)
1782 if (fADC->fIsShared == kFALSE)
1784 fADC->fCorrupted += 100;
1786 if (fgWarnError) AliWarning(Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1787 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1788 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadcolumn, "Wrong column");
1792 // flag it - we are out of the det when the pad is shared
1793 if (fgDebugFlag) AliDebug(10, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1794 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1795 fADC->fCorrupted += 111;
1799 if (fADC->fCorrupted > 0)
1808 //--------------------------------------------------------
1809 void AliTRDrawStreamTB::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
1812 // Decode the data *word into SM info structure
1815 sm->fPos = (UInt_t*)word;
1818 UInt_t vword = *word;
1819 sm->fHeaderSize = SM_HEADER_SIZE(vword);
1821 if (TRACKLETS_ENABLED(vword) > 0)
1822 sm->fTrackletEnable = kTRUE;
1824 sm->fTrackletEnable = kFALSE;
1826 UInt_t stackMask = STACK_MASK(vword);
1827 sm->fActiveStacks = 0;
1828 for (Int_t i = 0; i < 5; i++)
1830 //if ((stackMask >> i) & 0x1 > 0)
1831 if (IS_BIT_SET(stackMask,i) > 0)
1833 sm->fStackActive[i] = kTRUE;
1834 sm->fActiveStacks++;
1838 sm->fStackActive[i] = kFALSE;
1843 //--------------------------------------------------------
1844 const char *AliTRDrawStreamTB::DumpSMInfo(const struct AliTRDrawSM *sm)
1847 // Get SM structure into a const char
1850 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
1852 sm->fHeaderSize, sm->fTrackletEnable,
1853 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
1854 sm->fStackActive[3], sm->fStackActive[4]);
1857 //--------------------------------------------------------
1858 void AliTRDrawStreamTB::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
1861 // Decode stack info - active links
1864 st->fPos = (UInt_t*)word;
1867 UInt_t vword = *word;
1868 st->fHeaderSize = STACK_HEADER_SIZE(vword);
1870 UInt_t linkMask = STACK_LINK_WORD(vword);
1871 st->fActiveLinks = 0;
1872 for (Int_t i = 0; i < 12; i++)
1874 //if (linkMask & (0x1 << i) > 0)
1875 if (IS_BIT_SET(linkMask,i) > 0)
1877 st->fLinksActive[i] = kTRUE;
1878 st->fTrackletDecode[i] = kTRUE;
1879 st->fHCDecode[i] = kTRUE;
1884 st->fTrackletDecode[i] = kFALSE;
1885 st->fLinksActive[i] = kFALSE;
1886 st->fHCDecode[i] = kFALSE;
1891 //--------------------------------------------------------
1892 const char *AliTRDrawStreamTB::DumpStackInfo(const struct AliTRDrawStack *st)
1895 // format the string with the stack info
1897 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
1900 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
1901 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
1902 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
1905 //--------------------------------------------------------
1906 void AliTRDrawStreamTB::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
1909 // decode the hc header word 0
1913 UInt_t vword = *word;
1915 hc->fCorrupted = HC_HEADER_MASK_ERR(vword);
1916 if (hc->fCorrupted > 0)
1918 hc->fH0ErrorCounter++;
1921 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
1922 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
1923 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
1924 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
1925 hc->fDCSboard = HC_DCS_BOARD(vword);
1926 hc->fSM = HC_SM_NUMBER(vword);
1927 hc->fStack = HC_STACK_NUMBER(vword);
1928 hc->fLayer = HC_LAYER_NUMBER(vword);
1929 hc->fSide = HC_SIDE_NUMBER(vword);
1931 hc->fPos[0] = (UInt_t*)word;
1935 //--------------------------------------------------------
1936 void AliTRDrawStreamTB::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
1943 UInt_t vword = *word;
1945 hc->fCorrupted += 10 * HC_HEADER_MASK_ERR(vword);
1946 if (hc->fCorrupted > 10)
1948 hc->fH1ErrorCounter++;
1951 hc->fTimeBins = HC_NTIMEBINS(vword);
1952 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
1953 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
1954 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
1956 hc->fPos[1] = (UInt_t*)word;
1959 //--------------------------------------------------------
1960 const char *AliTRDrawStreamTB::DumpHCinfoH0(const struct AliTRDrawHC *hc)
1966 return Form("Unable to dump. Null received as parameter!?!");
1968 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
1969 hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
1972 //--------------------------------------------------------
1973 const char *AliTRDrawStreamTB::DumpHCinfoH1(const struct AliTRDrawHC *hc)
1979 return Form("Unable to dump. Null received as parameter!?!");
1981 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
1982 hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
1985 //--------------------------------------------------------
1986 void AliTRDrawStreamTB::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1989 // decode the mcm header
1993 UInt_t vword = *word;
1995 mcm->fCorrupted = MCM_HEADER_MASK_ERR(vword);
1996 //printf("0x%08x %d\n", word, MCM_HEADER_MASK_ERR(word));
1997 if (mcm->fCorrupted)
1998 mcm->fErrorCounter++;
1999 mcm->fROB = MCM_ROB_NUMBER(vword);
2000 mcm->fMCM = MCM_MCM_NUMBER(vword);
2001 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
2003 mcm->fPos = (UInt_t*)word;
2006 //--------------------------------------------------------
2007 UInt_t AliTRDrawStreamTB::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2014 UInt_t vword = *word;
2019 mcm->fADCMaskWord = vword;
2020 //memset(mcm->fADCchannel, 0, sizeof(UInt_t) * 30);
2021 //if ((word & 0x0000000F) == 0x0000000C)
2022 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 )
2024 //mcm->fADCMask = (word >> 4) & skADCmaskBits;
2025 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
2029 mcm->fADCMask = 0xffffffff;
2030 mcm->fCorrupted += 10;
2031 mcm->fMaskErrorCounter++;
2034 return mcm->fADCMask;
2037 //--------------------------------------------------------
2038 void AliTRDrawStreamTB::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2041 // decode the adc mask - adcs to be read out
2044 mcm->fMCMADCWords = 0;
2045 mcm->fSingleADCwords = 0;
2047 mcm->fADCMask = GetMCMadcMask(word, mcm);
2048 if (mcm->fADCMask > 0)
2050 for (Int_t i = 0; i < TRD_MAX_ADC; i++)
2052 mcm->fADCchannel[mcm->fADCmax] = 0;
2053 if( IS_BIT_SET(mcm->fADCMask,i) )
2055 mcm->fADCchannel[mcm->fADCmax] = i;
2062 //--------------------------------------------------------
2063 void AliTRDrawStreamTB::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
2066 // count the expected mcm words for a given tbins
2068 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
2069 mcm->fSingleADCwords = 0;
2070 if (mcm->fADCmax > 0)
2072 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
2076 //--------------------------------------------------------
2077 const char *AliTRDrawStreamTB::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
2080 // mcm info in a string
2083 return Form("Unable to dump. Null received as parameter!?!");
2085 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
2088 //--------------------------------------------------------
2089 //TString DumpMCMadcMask(const struct AliTRDrawMCMInfo *mcm)
2090 const char *AliTRDrawStreamTB::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 < 21; i++)
2101 tsreturn += Form("%d ", mcm->fADCchannel[i]);
2104 return tsreturn.Data();