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 if (det < 0 || det >= AliTRDgeometry::kNdet)
671 if (fSM.fClean == kTRUE)
673 AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));
677 AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));
682 // Add a container for the digits of this detector
683 digits = digitsManager->GetDigits(det);
684 track0 = digitsManager->GetDictionary(det,0);
685 track1 = digitsManager->GetDictionary(det,1);
686 track2 = digitsManager->GetDictionary(det,2);
690 if (fSM.fClean == kTRUE)
692 AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));
696 AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));
702 Int_t rowMax = GetRowMax();
703 Int_t colMax = GetColMax();
704 Int_t ntbins = GetNumberOfTimeBins();
706 // Allocate memory space for the digits buffer
707 if (digits->GetNtime() == 0)
709 digits->Allocate(rowMax, colMax, ntbins);
710 track0->Allocate(rowMax, colMax, ntbins);
711 track1->Allocate(rowMax, colMax, ntbins);
712 track2->Allocate(rowMax, colMax, ntbins);
715 indexes = digitsManager->GetIndexes(det);
716 indexes->SetSM(GetSM());
717 indexes->SetStack(GetStack());
718 indexes->SetLayer(GetLayer());
719 indexes->SetDetNumber(det);
720 if (indexes->IsAllocated() == kFALSE)
721 indexes->Allocate(rowMax, colMax, ntbins);
724 // ntimebins data are ready to read
725 for (it = 0; it < GetNumberOfTimeBins(); it++)
727 if (GetSignals()[it] > 0)
729 digits->SetDataUnchecked(GetRow(), GetCol(), it, GetSignals()[it]);
731 indexes->AddIndexTBin(GetRow(), GetCol(), it);
732 track0->SetDataUnchecked(GetRow(), GetCol(), it, 0);
733 track1->SetDataUnchecked(GetRow(), GetCol(), it, 0);
734 track2->SetDataUnchecked(GetRow(), GetCol(), it, 0);
739 // what happens if the last HC is turned off?
744 //------------------------------------------------------------
746 AliTRDrawStreamTB::Init()
752 TDirectory *saveDir = gDirectory;
756 fGeometry = new AliTRDgeometry();
761 AliError("Geometry FAILED!");
765 fTRDfeeParam = AliTRDfeeParam::Instance();
768 AliError("AliTRDfeeParam FAILED!");
772 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
774 // common additive is moved to be static for temp solution
775 // common additive should be delivered in the HC word 2 (3rd word)
776 //fCommonAdditive = 10;
780 // in case rawreader manages the mem buffers
781 // lets go for the next buffer
784 Int_t nextBuff = NextBuffer();
785 while (nextBuff != -1)
789 nextBuff = NextBuffer();
793 if (fgDebugStreamFlag == kTRUE)
795 if (!fgDebugStreamer)
797 fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root");
798 fgStreamEventCounter = 0;
802 AliInfo(Form("Debug Streamer Initialized! Remember to delete! %s::DeleteDebugStream()", this->IsA()->GetName()));
803 //fDebugStreamOwned = kTRUE;
807 AliError("Unable to init debug stream");
817 void AliTRDrawStreamTB::DeleteDebugStream()
820 // static helper function
825 delete fgDebugStreamer;
831 //------------------------------------------------------------
833 AliTRDrawStreamTB::InitBuffer(void *buffer, UInt_t length)
836 // init the class before reading from the buffer
837 // and read SM heading info:
838 // -- super module header
839 // -- stack headers + link status words
842 // not in the pre scan mode
843 fgStreamEventCounter++;
847 fpBegin = (UInt_t *)buffer;
851 AliFatal("Strange! Size of UInt_t == 0");
855 fWordLength = length/WORD_SIZE;
856 fpEnd = fpBegin + fWordLength;
859 if (fpBegin == 0 || length <= 0)
861 AliError(Form("This will not work! Pointer to the buffer is 0x%08x of size %d", fpBegin, length));
869 AliInfo("------------------------------------------------");
870 if (DumpWords(fpBegin, fgDumpHead) == kFALSE)
872 AliError("Dump failed. Not enough data.");
874 AliInfo("------------------------------------------------");
878 DecodeSMInfo(fpPos, &fSM);
880 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
885 if (SkipWords(fSM.fHeaderSize) == kTRUE)
888 //for (Int_t istack = 0; istack < fSM.fActiveStacks; istack++)
889 for (Int_t istack = 0; istack < 5; istack++)
891 if (fSM.fStackActive[istack] == kFALSE)
894 fStack = &fSM.fStacks[istack];
895 DecodeStackInfo(fpPos, fStack);
898 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
900 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
902 if (SkipWords(fStack->fHeaderSize) == kFALSE)
904 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack head words missing");
916 if (fgWarnError) AliWarning("No Stack info present. Strange.");
917 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
921 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers : %d", fSM.fNexpectedHalfChambers));
926 if (fgDebugFlag) AliDebug(5, "Init OK.");
930 if (fgWarnError) AliWarning("No data just after init. Strange.");
931 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing data");
938 //------------------------------------------------------------
940 AliTRDrawStreamTB::DecodeSM(void *buffer, UInt_t length)
943 // decode all sm at once
944 // still here for devel and debug
947 //memset(&fSM, 0, sizeof(fSM));
952 if (InitBuffer(buffer, length) == kTRUE)
954 // no we are already set!
959 if (fgWarnError) AliError("--- INIT failed. ---------------");
966 for (Int_t istack = 0; istack < 5; istack++)
968 fStackNumber = istack;
969 if (fSM.fStackActive[istack] == kFALSE)
972 fStack = &fSM.fStacks[istack];
974 //fStack[istack].fActiveLinks // max is 12
975 for (Int_t ilink = 0; ilink < 12; ilink++)
977 fStackLinkNumber = ilink;
978 if (fStack->fLinksActive[ilink] == kFALSE)
983 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
988 fHC = &fStack->fHalfChambers[ilink];
990 if (fSM.fTrackletEnable == kTRUE)
992 if (DecodeTracklets() == kFALSE)
994 // if (fgWarnError) AliError(Form("--- Decode Tracklets failed. --------------- Link %d of %d",
995 // ilink + 1, fStack->fActiveLinks));
998 TTreeSRedirector &cstream = *fgDebugStreamer;
999 cstream << "TrackletDecodeError"
1000 << "Event=" << fgStreamEventCounter
1001 << ".Stack=" << fStackNumber
1002 << ".Link=" << fStackLinkNumber
1003 << ".EndOfTrackletCount=" << fEndOfTrackletCount
1007 fSM.fClean = kFALSE;
1012 AliError(Form("Failed stack %d link %d", fStackNumber, fStackLinkNumber));
1013 AliError(Form("Debug Event Counter : %d", fgStreamEventCounter));
1022 if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
1023 fSM.fClean = kFALSE;
1027 if (DecodeHC() == kFALSE)
1029 // if (fgWarnError) AliError(Form("--- Decode HC failed. --------------- Link %d of %d",
1030 // ilink + 1, fStack->fActiveLinks));
1031 fSM.fClean = kFALSE;
1032 fHC->fCorrupted += 100;
1037 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
1038 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
1039 AliError(Form("Debug Event Counter : %d", fgStreamEventCounter));
1041 // let us assume that we have the HC data although link mask says different
1043 if (fStackLinkNumber == -1)
1045 if (fgWarnError) AliWarning("Trying to recover to the right Link Mask.");
1054 // just finish off with the end of data markers
1058 //if (fgDebugFlag) AliDebug(5, Form("++++ Done with link %d of %d", ilink + 1, fStack->fActiveLinks));
1066 if (fSM.fClean == kTRUE)
1069 if (fgCleanDataOnly && (fSM.fClean == kFALSE))
1073 AliWarning("Buffer with errors. Returning FALSE.");
1074 AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
1076 fSM.fActiveStacks = 0; // Next will not give data
1083 //------------------------------------------------------------
1085 AliTRDrawStreamTB::DecodeSM()
1088 // decode SM data in case AliRawReader is in use
1092 Int_t nextBuff = NextBuffer();
1093 while (nextBuff != -1)
1097 nextBuff = NextBuffer();
1103 AliWarning("AliRawReader not set.");
1108 //------------------------------------------------------------
1110 AliTRDrawStreamTB::DecodeSM(AliRawReader *reader)
1113 // decode SM with the AliRawReader
1117 fRawReader = reader;
1122 AliWarning("Argument AliRawReader is 0.");
1127 //------------------------------------------------------------
1129 AliTRDrawStreamTB::SeekEndOfData()
1132 // go to end of data marker
1134 Int_t fEndOfDataCount = 0;
1136 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1141 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd )
1147 // if (fEndOfDataCount == 0)
1149 // if (fgWarnError) AliWarning("End of buffer reached first. No end of data marker?");
1156 //------------------------------------------------------------
1158 AliTRDrawStreamTB::SeekNextMCMheader()
1164 // move back to the mcm pos
1165 fpPos = fMCM->fPos + 1;
1167 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1169 //if (CheckMCMMask(fpPos) == 0)
1170 if (MCM_HEADER_MASK_ERR(*fpPos) == 0)
1172 if (fgWarnError) AliWarning(Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1182 //------------------------------------------------------------
1185 AliTRDrawStreamTB::DecodeTracklets()
1191 fLinkTrackletCounter = 0;
1192 fEndOfTrackletCount = 0;
1194 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
1195 //cout << Form("Decode tracklets..") << endl;;
1196 //printf("[I] Tracklet... ? \n");
1198 while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd )
1201 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
1203 //decode tracklets here...
1204 fLinkTrackletCounter++;
1206 if (fLinkTrackletCounter > MAX_TRACKLETS_PERHC)
1208 if (fgWarnError) AliWarning(Form("Max number of tracklets exceeded %d > %d. Something is wrong with the input data!",
1209 fLinkTrackletCounter, MAX_TRACKLETS_PERHC));
1211 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
1215 if (fgDebugStreamer)
1231 row = (val >> 20) & 0xF;
1232 defl = (val >> 13) & 0x7F;
1233 defl = defl << 25 >> 25;
1234 ypos = val & 0x1FFF;
1235 ypos = ypos << 19 >> 19;
1237 deflm = defl * 140.0e-6; /* m */
1238 yposm = ypos * 160.0e-6; /* m */
1240 TTreeSRedirector &cstream = *fgDebugStreamer;
1241 cstream << "MCMtracklets"
1242 << "Event=" << fgStreamEventCounter
1243 << ".stack=" << fStackNumber
1244 << ".link=" << fStackLinkNumber
1249 << ".deflm=" << deflm
1250 << ".yposm=" << yposm
1256 while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd )
1258 //seek non end of tracklets
1259 //printf("[I] End of tracklets. \n");
1260 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1262 fEndOfTrackletCount++;
1266 if ( fEndOfTrackletCount < 2 )
1268 //if (fgWarnError) AliWarning(Form("End of tracklet marker words missing %d", 2 - fEndOfTrackletCount));
1269 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1276 //------------------------------------------------------------
1278 AliTRDrawStreamTB::IsRowValid()
1281 if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||
1282 (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 )
1284 if (fgWarnError) AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1285 , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));
1286 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadrow, "Wrong Row");
1292 //------------------------------------------------------------
1294 AliTRDrawStreamTB::IsMCMheaderOK()
1297 // check the mcm header
1300 if ( fMCM->fCorrupted > 10 )
1302 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"ADC mask Corrupted");
1303 if (fgWarnError) AliWarning(Form("Wrong ADC Mask word 0x%08x %s. Error : %d", *fMCM->fPos, DumpMCMadcMask(fMCM), fMCM->fCorrupted));
1307 if ( fMCM->fCorrupted > 0 )
1309 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"Corrupted");
1310 if (fgWarnError) AliWarning(Form("Wrong MCM word 0x%08x %s. Error : %d", *fMCM->fPos, DumpMCMinfo(fMCM), fMCM->fCorrupted));
1314 if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 )
1316 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongMCMorROB,"Wrong ROB or MCM");
1317 if (fgWarnError) AliWarning(Form("Wrong fMCM or fROB. %s Skip this data.", DumpMCMinfo(fMCM)));
1321 if (IsRowValid() == kFALSE)
1326 //------------------------------------------------------------
1328 AliTRDrawStreamTB::DecodeMCMheader()
1331 // decode the mcm header
1334 DecodeMCMheader(fpPos, fMCM);
1336 fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
1338 if (fHC->fRawVMajor > 2)
1341 if ( fpPos < fpEnd )
1343 DecodeMask(fpPos, fMCM);
1344 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1345 fMCM->fAdcDataPos = fpPos + 1;
1349 if (fgWarnError) AliWarning("Expected ADC mask word. Fail due to buffer END.");
1350 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1356 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
1357 DecodeMask(&dummyMask, fMCM);
1358 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1359 fMCM->fAdcDataPos = fpPos + 1;
1364 AliDebug(6, DumpMCMinfo(fMCM));
1365 AliDebug(7, DumpMCMadcMask(fMCM));
1368 if (IsMCMheaderOK() == kFALSE)
1373 if (fEventCounter == 0)
1375 fEventCounter = fMCM->fEvCounter;
1378 if (fEventCounter < fLastEventCounter)
1380 if (fgWarnError) AliWarning(Form("Weird. Event from the past? Current %d Last %d %s", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM)));
1381 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ? Past-Future");
1385 if (fEventCounter != fMCM->fEvCounter)
1387 if (fgWarnError) AliWarning(Form("Weird. Event missmatch? %d %s", fEventCounter, DumpMCMinfo(fMCM)));
1388 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ?");
1392 //fLastEventCounter = fEventCounter;
1393 //AliInfo(Form("Current MCM %s", DumpMCMinfo(fMCM)));
1396 //return IsMCMheaderOK();
1399 //------------------------------------------------------------
1401 AliTRDrawStreamTB::IsHCheaderOK()
1404 // check the half chamber header
1407 if (fHC->fCorrupted > 0)
1409 if (fgWarnError) AliWarning(Form("Wrong HC Header word. Word 0x%08x Error : %d", *fHC->fPos, fHC->fCorrupted));
1410 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "Corrupted");
1415 if (fHC->fStack < 0 || fHC->fStack > 4)
1417 if (fgWarnError) AliWarning(Form("Wrong Stack %d", fHC->fStack));
1418 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Wrong Stack");
1422 if (fHC->fStack != fStackNumber)
1424 if (fgWarnError) AliWarning(Form("Missmatch: Stack in HC header %d HW-stack %d",
1425 fHC->fStack, fStackNumber));
1426 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Stack-HWstack");
1427 // Try this for recovery in DecodeSM(void*,UInt_t) after DecodeHC failed
1428 // buffer will still will be marked as NOT clean
1433 if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNplan)
1435 if (fgWarnError) AliWarning(Form("Wrong plane(layer) %d", fHC->fLayer));
1436 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Wrong Plane");
1440 if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1))
1442 if (fgWarnError) AliWarning(Form("Missmatch: plane(layer) in HCheader %d HW-Link %d | %s",
1443 fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));
1444 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Plane-Link missmatch");
1445 // Try this for recovery in DecodeSM(void*,UInt_t) after DecodeHC failed
1446 // buffer will still will be marked as NOT clean
1447 fStackLinkNumber = -1;
1451 if (fHC->fSide < 0 || fHC->fSide > 1)
1453 if (fgWarnError) AliWarning(Form("Wrong Side %d", fHC->fSide));
1454 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSide, "Wrong Side");
1459 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
1460 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet)
1462 if (fgWarnError) AliWarning(Form("Wrong detector %d", fHC->fDET));
1463 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1468 // this check fails - raw data inconsistent with geometry?
1469 if (fHC->fSM != fGeometry->GetSector(fHC->fDET)
1470 || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsect)
1472 if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1473 fHC->fSM, fGeometry->GetSector(fHC->fDET),
1474 fHC->fStack, fHC->fLayer, fHC->fDET));
1475 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1481 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
1484 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1488 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
1489 if (fHC->fRowMax < 1)
1491 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1495 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
1496 if (fHC->fColMax < 1)
1498 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1501 // extra - not needed
1502 // if (fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsect)
1504 // if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d",
1505 // fHC->fSM, fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack),
1506 // fHC->fStack, fHC->fLayer));
1513 //------------------------------------------------------------
1515 AliTRDrawStreamTB::DecodeHCheader()
1518 // decode the half chamber header
1521 DecodeHCwordH0(fpPos, fHC);
1523 if (fHC->fNExtraWords > 0)
1528 DecodeHCwordH1(fpPos, fHC);
1532 if (fgWarnError) AliWarning("Expected HC header word 1. Fail due to buffer END.");
1533 if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing");
1538 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1539 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1542 if (IsHCheaderOK() == kFALSE)
1550 //------------------------------------------------------------
1552 AliTRDrawStreamTB::DecodeHC()
1555 // decode the hc data
1556 // function for devel & debug
1559 if (DecodeHCheader() == kFALSE)
1561 if (fgDebugStreamer)
1563 TTreeSRedirector &cstream = *fgDebugStreamer;
1564 cstream << "HCDecodeError"
1565 << "Event=" << fgStreamEventCounter
1566 << ".stack=" << fStackNumber
1567 << ".link=" << fStackLinkNumber
1568 << ".hcCorrupted" << fHC->fCorrupted
1569 << ".hcRVmajor=" << fHC->fRawVMajor
1570 << ".hcDCSboard=" << fHC->fDCSboard
1571 << ".hcSM=" << fHC->fSM
1572 << ".hcStack=" << fHC->fStack
1573 << ".hcLayer=" << fHC->fLayer
1574 << ".hcSide=" << fHC->fSide
1575 << ".hcTbins=" << fHC->fTimeBins
1576 << ".hcBunchCross=" << fHC->fBunchCrossCounter
1577 << ".hcPreTrig=" << fHC->fPreTriggerCounter
1578 << ".hcPreTrigPh=" << fHC->fPreTriggerPhase
1579 << ".hcDet=" << fHC->fDET
1580 << ".hcROC=" << fHC->fROC
1581 << ".hc=RowMax" << fHC->fRowMax
1582 << ".hc=ColMax" << fHC->fColMax
1586 if (fgWarnError) AliWarning("Header decode failed.");
1594 if (fgWarnError) AliWarning("No MCM data? Not enough data in the buffer.");
1595 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing");
1601 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd)
1603 if (fHC->fMCMmax > TRD_MAX_MCM)
1605 if (fgWarnError) AliWarning("More mcm data than expected!");
1606 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!");
1610 fMCM = &fHC->fMCMs[fHC->fMCMmax];
1612 if (DecodeMCMheader() == kFALSE)
1614 if (fgDebugStreamer)
1616 TTreeSRedirector &cstream = *fgDebugStreamer;
1617 cstream << "MCMDecodeError"
1618 << "Event=" << fgStreamEventCounter
1619 << ".stack=" << fStackNumber
1620 << ".link=" << fStackLinkNumber
1621 << ".hcDCSboard=" << fHC->fDCSboard
1622 << ".hcSM=" << fHC->fSM
1623 << ".hcStack=" << fHC->fStack
1624 << ".hcLayer=" << fHC->fLayer
1625 << ".hcSide=" << fHC->fSide
1626 << ".hcBunchCross=" << fHC->fBunchCrossCounter
1627 << ".hcPreTrig=" << fHC->fPreTriggerCounter
1628 << ".hcPreTrigPh=" << fHC->fPreTriggerPhase
1629 << ".hcDet=" << fHC->fDET
1631 << ".mcmCorrupted=" << fMCM->fCorrupted
1632 << ".mcmROB=" << fMCM->fROB
1633 << ".mcmMCM=" << fMCM->fMCM
1634 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1635 << ".mcmEventCounter=" << fMCM->fEvCounter
1637 << ".fEventCounter=" << fEventCounter
1638 << ".fLastEventCounter=" << fLastEventCounter
1647 if (fMCM->fADCmax > 0)
1652 if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected."));
1653 if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing");
1656 // for (Int_t iadc = 0; iadc < TRD_MAX_ADC; iadc++)
1657 for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++)
1659 fADC = &fMCM->fADCs[iadc];
1660 fADC->fADCnumber = fMCM->fADCchannel[iadc];
1662 if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.",
1663 iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1665 if (fpPos + fMCM->fSingleADCwords >= fpEnd)
1667 if (fgDebugStreamer)
1669 TTreeSRedirector &cstream = *fgDebugStreamer;
1670 // means no data read
1672 cstream << "ADCDecodeError"
1673 << "Event=" << fgStreamEventCounter
1674 << ".hcSM=" << fHC->fSM
1675 << ".hcStack=" << fHC->fStack
1676 << ".hcLayer=" << fHC->fLayer
1677 << ".mcmROB=" << fMCM->fROB
1678 << ".mcmMCM=" << fMCM->fMCM
1679 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1680 << ".adcErr=" << ierr
1681 << ".adcNumber=" << ierr
1685 if (fgWarnError) AliWarning(Form("This is ADC %d of %d. ADC number is %d.", iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1686 if (fgWarnError) AliWarning("--> ADC (10 words) expected. Not enough data in the buffer.");
1687 if (fgWarnError) AliWarning(Form("--> ADC mask : %s", DumpMCMadcMask(fMCM)));
1689 if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing - less than expected");
1693 //DECODE the data here
1694 if (DecodeADC() == kFALSE)
1696 // check if we are out of the det when the pad is shared
1697 if (fADC->fIsShared && fADC->fCorrupted == 111)
1700 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1704 if (fgWarnError) AliWarning(Form("ADC decode failed."));
1705 //fpPos = fMCM->fPpos + fMCMADCWords;
1707 if (fgDebugStreamer)
1709 TTreeSRedirector &cstream = *fgDebugStreamer;
1710 cstream << "ADCDecodeError"
1711 << "Event=" << fgStreamEventCounter
1712 << ".hcSM=" << fHC->fSM
1713 << ".hcStack=" << fHC->fStack
1714 << ".hcLayer=" << fHC->fLayer
1715 << ".mcmROB=" << fMCM->fROB
1716 << ".mcmMCM=" << fMCM->fMCM
1717 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1718 << ".adcErr=" << fADC->fCorrupted
1719 << ".adcNumber=" << fADC->fADCnumber
1723 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1727 //decode the ADC words here
1729 } //mcm data present
1738 if (fgWarnError) AliWarning("We are at the end of buffer. There should be one more word left.");
1746 //------------------------------------------------------------
1748 AliTRDrawStreamTB::DecodeADC()
1751 // decode single ADC channel
1754 fADC->fCorrupted = 0;
1755 fMaskADCword = ADC_WORD_MASK(*fpPos);
1760 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
1761 fADC->fSignals[i] = 0;
1763 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
1765 if (fMaskADCword != ADC_WORD_MASK(*fpPos))
1767 //this is corrupted data
1768 fADC->fCorrupted += 1;
1769 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",
1770 iw - 1, *(fpPos-1), fMaskADCword, iw, *fpPos, ADC_WORD_MASK(*fpPos)));
1771 if (fRawReader) fRawReader->AddMajorErrorLog(kADCmaskMissmatch, "Mask change inside single channel");
1776 // here we subtract the baseline ( == common additive)
1777 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1778 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1779 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1785 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
1787 fADC->fIsShared = kTRUE;
1791 fADC->fIsShared = kFALSE;
1794 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
1796 // let us guess the Column
1797 // take the one before last ADC and shift by one column
1798 // later we check if we are inside the limits of the chamber
1799 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
1804 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1807 if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0)
1809 if (fADC->fIsShared == kFALSE)
1811 fADC->fCorrupted += 100;
1813 if (fgWarnError) AliWarning(Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1814 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1815 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadcolumn, "Wrong column");
1819 // flag it - we are out of the det when the pad is shared
1820 if (fgDebugFlag) AliDebug(10, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1821 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1822 fADC->fCorrupted += 111;
1826 if (fADC->fCorrupted > 0)
1835 //--------------------------------------------------------
1836 void AliTRDrawStreamTB::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
1839 // Decode the data *word into SM info structure
1842 sm->fPos = (UInt_t*)word;
1845 UInt_t vword = *word;
1846 sm->fHeaderSize = SM_HEADER_SIZE(vword);
1848 if (TRACKLETS_ENABLED(vword) > 0)
1849 sm->fTrackletEnable = kTRUE;
1851 sm->fTrackletEnable = kFALSE;
1853 UInt_t stackMask = STACK_MASK(vword);
1854 sm->fActiveStacks = 0;
1855 for (Int_t i = 0; i < 5; i++)
1857 //if ((stackMask >> i) & 0x1 > 0)
1858 if (IS_BIT_SET(stackMask,i) > 0)
1860 sm->fStackActive[i] = kTRUE;
1861 sm->fActiveStacks++;
1865 sm->fStackActive[i] = kFALSE;
1870 //--------------------------------------------------------
1871 const char *AliTRDrawStreamTB::DumpSMInfo(const struct AliTRDrawSM *sm)
1874 // Get SM structure into a const char
1877 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
1879 sm->fHeaderSize, sm->fTrackletEnable,
1880 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
1881 sm->fStackActive[3], sm->fStackActive[4]);
1884 //--------------------------------------------------------
1885 void AliTRDrawStreamTB::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
1888 // Decode stack info - active links
1891 st->fPos = (UInt_t*)word;
1894 UInt_t vword = *word;
1895 st->fHeaderSize = STACK_HEADER_SIZE(vword);
1897 UInt_t linkMask = STACK_LINK_WORD(vword);
1898 st->fActiveLinks = 0;
1899 for (Int_t i = 0; i < 12; i++)
1901 //if (linkMask & (0x1 << i) > 0)
1902 if (IS_BIT_SET(linkMask,i) > 0)
1904 st->fLinksActive[i] = kTRUE;
1905 st->fTrackletDecode[i] = kTRUE;
1906 st->fHCDecode[i] = kTRUE;
1911 st->fTrackletDecode[i] = kFALSE;
1912 st->fLinksActive[i] = kFALSE;
1913 st->fHCDecode[i] = kFALSE;
1918 //--------------------------------------------------------
1919 const char *AliTRDrawStreamTB::DumpStackInfo(const struct AliTRDrawStack *st)
1922 // format the string with the stack info
1924 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
1927 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
1928 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
1929 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
1932 //--------------------------------------------------------
1933 void AliTRDrawStreamTB::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
1936 // decode the hc header word 0
1940 UInt_t vword = *word;
1942 hc->fCorrupted = HC_HEADER_MASK_ERR(vword);
1943 if (hc->fCorrupted > 0)
1945 hc->fH0ErrorCounter++;
1948 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
1949 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
1950 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
1951 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
1952 hc->fDCSboard = HC_DCS_BOARD(vword);
1953 hc->fSM = HC_SM_NUMBER(vword);
1954 hc->fStack = HC_STACK_NUMBER(vword);
1955 hc->fLayer = HC_LAYER_NUMBER(vword);
1956 hc->fSide = HC_SIDE_NUMBER(vword);
1958 hc->fPos[0] = (UInt_t*)word;
1962 //--------------------------------------------------------
1963 void AliTRDrawStreamTB::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
1970 UInt_t vword = *word;
1972 hc->fCorrupted += 10 * HC_HEADER_MASK_ERR(vword);
1973 if (hc->fCorrupted > 10)
1975 hc->fH1ErrorCounter++;
1978 hc->fTimeBins = HC_NTIMEBINS(vword);
1979 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
1980 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
1981 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
1983 hc->fPos[1] = (UInt_t*)word;
1986 //--------------------------------------------------------
1987 const char *AliTRDrawStreamTB::DumpHCinfoH0(const struct AliTRDrawHC *hc)
1993 return Form("Unable to dump. Null received as parameter!?!");
1995 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
1996 hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
1999 //--------------------------------------------------------
2000 const char *AliTRDrawStreamTB::DumpHCinfoH1(const struct AliTRDrawHC *hc)
2006 return Form("Unable to dump. Null received as parameter!?!");
2008 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
2009 hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
2012 //--------------------------------------------------------
2013 void AliTRDrawStreamTB::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2016 // decode the mcm header
2020 UInt_t vword = *word;
2022 mcm->fCorrupted = MCM_HEADER_MASK_ERR(vword);
2023 //printf("0x%08x %d\n", word, MCM_HEADER_MASK_ERR(word));
2024 if (mcm->fCorrupted)
2025 mcm->fErrorCounter++;
2026 mcm->fROB = MCM_ROB_NUMBER(vword);
2027 mcm->fMCM = MCM_MCM_NUMBER(vword);
2028 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
2030 mcm->fPos = (UInt_t*)word;
2033 //--------------------------------------------------------
2034 UInt_t AliTRDrawStreamTB::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2041 UInt_t vword = *word;
2046 mcm->fADCMaskWord = vword;
2047 //memset(mcm->fADCchannel, 0, sizeof(UInt_t) * 30);
2048 //if ((word & 0x0000000F) == 0x0000000C)
2049 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 )
2051 //mcm->fADCMask = (word >> 4) & skADCmaskBits;
2052 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
2056 mcm->fADCMask = 0xffffffff;
2057 mcm->fCorrupted += 10;
2058 mcm->fMaskErrorCounter++;
2061 return mcm->fADCMask;
2064 //--------------------------------------------------------
2065 void AliTRDrawStreamTB::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2068 // decode the adc mask - adcs to be read out
2071 mcm->fMCMADCWords = 0;
2072 mcm->fSingleADCwords = 0;
2074 mcm->fADCMask = GetMCMadcMask(word, mcm);
2075 if (mcm->fADCMask > 0)
2077 for (Int_t i = 0; i < TRD_MAX_ADC; i++)
2079 mcm->fADCchannel[mcm->fADCmax] = 0;
2080 if( IS_BIT_SET(mcm->fADCMask,i) )
2082 mcm->fADCchannel[mcm->fADCmax] = i;
2089 //--------------------------------------------------------
2090 void AliTRDrawStreamTB::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
2093 // count the expected mcm words for a given tbins
2095 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
2096 mcm->fSingleADCwords = 0;
2097 if (mcm->fADCmax > 0)
2099 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
2103 //--------------------------------------------------------
2104 const char *AliTRDrawStreamTB::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
2107 // mcm info in a string
2110 return Form("Unable to dump. Null received as parameter!?!");
2112 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
2115 //--------------------------------------------------------
2116 //TString DumpMCMadcMask(const struct AliTRDrawMCMInfo *mcm)
2117 const char *AliTRDrawStreamTB::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
2120 // mcm adc mask in a string
2123 return Form("Unable to dump. Null received as parameter!?!");
2125 TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
2126 for (Int_t i = 0; i < 21; i++)
2128 tsreturn += Form("%d ", mcm->fADCchannel[i]);
2131 return tsreturn.Data();