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 "AliTRDSignalIndex.h"
44 #include "AliRawReader.h"
46 #define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa
47 #define END_OF_TRACKLET_MARKERNEW 0x10001000
48 #define ENDOFRAWDATAMARKER 0x00000000
50 #define WORD_SIZE sizeof(UInt_t) // size of a word in bytes
51 #define EXTRA_LEAD_WORDS 24
54 #define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w
55 #define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m
57 // SM index word masks:
58 #define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
59 #define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)
60 #define STACK_MASK(w) ((w) & 0x1f)
63 #define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
64 #define STACK_LINK_WORD(w) ((w) & 0xfff)
67 //#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!!
68 #define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK!!!
71 #define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)
72 #define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)
73 #define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24)
74 #define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)
75 #define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)
76 #define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)
77 #define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)
78 #define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)
79 #define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)
80 #define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)
83 #define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)
84 #define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)
85 #define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)
86 #define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,6)
88 //--------------------------------------------------------
90 // MCM word and ADC mask
91 #define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
92 #define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
93 #define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)
94 #define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)
95 #define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)
96 #define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)
97 #define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25)
99 #define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated
100 //#define MCM_DUMMY_ADCMASK_VAL 0x001fffffc
101 //--------------------------------------------------------
103 #define MAX_TRACKLETS_PERHC 256 // max number of tracklets per HC - large number for now
105 //--------------------------------------------------------
106 #define ADC_WORD_MASK(w) ((w) & 0x3)
107 //--------------------------------------------------------
110 ClassImp(AliTRDrawStreamTB)
112 Bool_t AliTRDrawStreamTB::fgExtraSkip = kFALSE;
113 Bool_t AliTRDrawStreamTB::fgSkipCDH = kFALSE;
114 Bool_t AliTRDrawStreamTB::fgWarnError = kTRUE;
115 Bool_t AliTRDrawStreamTB::fgCleanDataOnly = kTRUE;
116 Bool_t AliTRDrawStreamTB::fgDebugFlag = kTRUE;
117 Bool_t AliTRDrawStreamTB::fgDebugStreamFlag = kFALSE;
118 Bool_t AliTRDrawStreamTB::fgStackNumberChecker = kTRUE;
119 Bool_t AliTRDrawStreamTB::fgStackLinkNumberChecker = kTRUE;
120 Bool_t AliTRDrawStreamTB::fgSkipData = kTRUE;
121 TTreeSRedirector *AliTRDrawStreamTB::fgDebugStreamer = 0;
122 UInt_t AliTRDrawStreamTB::fgStreamEventCounter = 0;
123 UInt_t AliTRDrawStreamTB::fgFirstEquipmentID = 0;
124 UInt_t AliTRDrawStreamTB::fgDumpHead = 0;
125 Int_t AliTRDrawStreamTB::fgCommonAdditive = 0;
126 Int_t AliTRDrawStreamTB::fgEmptySignals[] =
128 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
129 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
132 AliTRDrawStreamTB::AliTRDrawStreamTB()
133 : AliTRDrawStreamBase()
146 , fStackLinkNumber(-1)
149 , fLinkTrackletCounter(-1)
150 , fEndOfTrackletCount(-1)
155 , fLastEventCounter(0)
156 , fSharedPadsOn(kFALSE)
161 , fDebugStreamOwned(kFALSE)
164 // default constructor
167 if (Init() == kFALSE)
169 AliWarning("Unable to Init.");
173 //--------------------------------------------------------
174 AliTRDrawStreamTB::AliTRDrawStreamTB(AliRawReader *rawReader)
175 : AliTRDrawStreamBase(rawReader)
188 , fStackLinkNumber(-1)
191 , fLinkTrackletCounter(-1)
192 , fEndOfTrackletCount(-1)
197 , fLastEventCounter(0)
198 , fSharedPadsOn(kFALSE)
201 , fRawReader(rawReader)
203 , fDebugStreamOwned(kFALSE)
206 // default constructor
210 if (Init() == kFALSE)
212 AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
217 AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
221 //------------------------------------------------------------
223 AliTRDrawStreamTB::AliTRDrawStreamTB(const AliTRDrawStreamTB& /*st*/)
224 : AliTRDrawStreamBase()
237 , fStackLinkNumber(-1)
240 , fLinkTrackletCounter(-1)
241 , fEndOfTrackletCount(-1)
246 , fLastEventCounter(0)
247 , fSharedPadsOn(kFALSE)
252 , fDebugStreamOwned(kFALSE)
257 AliError("Not implemeneted.");
260 //------------------------------------------------------------
261 Bool_t AliTRDrawStreamTB::SetRawVersion(Int_t fraw)
264 // function provided for backward compatibility
266 AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");
267 fraw = 0; // avoid warnings
271 //------------------------------------------------------------
272 AliTRDrawStreamTB::~AliTRDrawStreamTB()
279 if (fDebugStreamOwned == kTRUE)
283 delete fgDebugStreamer;
289 //------------------------------------------------------------
292 AliTRDrawStreamTB::operator=(const AliTRDrawStreamTB &)
295 // we are not using this functionality
297 AliFatal("May not use.");
301 //------------------------------------------------------------
304 AliTRDrawStreamTB::EnableDebug(TTreeSRedirector *debugStream)
307 // replace the current debug streamer or create a new one if owned
310 if (debugStream == 0)
312 if (fDebugStreamOwned == kTRUE)
315 delete fgDebugStreamer;
318 fDebugStreamOwned = kTRUE;
319 fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root");
320 fgStreamEventCounter = 0;
325 if (fDebugStreamOwned == kTRUE)
328 delete fgDebugStreamer;
331 fgDebugStreamer = debugStream;
332 fDebugStreamOwned = kFALSE;
336 //___________________________________________________________
338 AliTRDrawStreamTB::SwapOnEndian()
341 // Check the endian and swap if needed
345 char* ptemp = (char*) &itemp;
349 if (fgDebugFlag) AliDebug(8, "Swapping.");
353 while (fpPos < fpEnd)
356 iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
357 ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
358 // here we override the value in the buffer!
365 //------------------------------------------------------------
367 AliTRDrawStreamTB::DumpErrorCount()
370 // print the error statistics into the stdout
374 // AliInfo(Form("Error counts: HC0 %d HC1 %d MCM %d ADCmask %d ADC %d",
375 // fHC->fH0ErrorCounter, fHC->fH1ErrorCounter, fMCM->fErrorCounter, fMCM->fMaskErrorCounter, adc.fErrorCounter));
378 //------------------------------------------------------------
380 AliTRDrawStreamTB::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
384 // note: can be made faster
387 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
388 for (UInt_t i = 0; i < iw; i++)
390 if (px + iw >= fpEnd)
395 if (marker != 0 && marker == px[i])
396 tsreturn += Form(" *>0x%08x<* ", px[i]);
398 tsreturn += Form("0x%08x ", px[i]);
402 AliInfo(tsreturn.Data());
407 //------------------------------------------------------------
409 AliTRDrawStreamTB::SkipWords(UInt_t iw)
413 // note: can be made faster
416 if ( fpPos + iw < fpEnd )
423 if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
426 TTreeSRedirector &cstream = *fgDebugStreamer;
427 cstream << "SkipWords"
428 << "Event=" << fgStreamEventCounter
430 // << ".read=" << (Char_t*)(fpPos - fpBegin)
431 // << ".togo=" << (Char_t*)(fpEnd - fpPos)
432 // << ".length=" << (Char_t*)(fpEnd - fpBegin)
441 //------------------------------------------------------------
443 AliTRDrawStreamTB::SetReader(AliRawReader *reader)
458 AliWarning("Unable to setup reader.");
464 AliWarning("AliRawReader argument is 0.");
471 //------------------------------------------------------------
473 AliTRDrawStreamTB::NextBuffer()
476 // return -1 if no more buffers available
477 // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come
478 // return 1 DecodeSM OK
485 Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
486 if (kBufferSet == kTRUE)
488 if (fgDebugFlag) AliDebug(9, "Buffer is set.");
489 length = fRawReader->GetDataSize();
490 if (fgExtraSkip == kTRUE)
492 buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
493 length -= EXTRA_LEAD_WORDS * WORD_SIZE;
496 if (fgSkipCDH == kTRUE)
498 buffer += CDH_WORDS * WORD_SIZE;
499 length -= CDH_WORDS * WORD_SIZE;
504 if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
505 //return InitBuffer((void*)buffer, length);
506 if (DecodeSM((void*)buffer, length) == kTRUE)
521 //------------------------------------------------------------
523 AliTRDrawStreamTB::ResetCounters()
526 // reset some global counters
530 fStackLinkNumber = 0;
534 fSM.fActiveStacks = 0;
535 fSM.fNexpectedHalfChambers = 0;
537 fLinkTrackletCounter = 0;
539 fLastEventCounter = 0;
543 //------------------------------------------------------------
545 AliTRDrawStreamTB::ResetIterators()
548 // reset the data iterators used in the Next()
551 fStackLinkNumber = 0;
556 //------------------------------------------------------------
559 AliTRDrawStreamTB::Next()
562 // returns with true on next adc read
563 // returns false on errors and end of buffer
566 while (fStackNumber < 5 && fSM.fActiveStacks > 0)
568 if(fSM.fStackActive[fStackNumber] == kTRUE)
570 fStack = &fSM.fStacks[fStackNumber];
571 while (fStackLinkNumber < 12)
573 if (fStack->fLinksActive[fStackLinkNumber] == kTRUE)
575 fHC = &fStack->fHalfChambers[fStackLinkNumber];
578 AliError(Form("Super Strange. HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
581 if (fHC->fCorrupted == 0)
583 while (fhcMCMcounter < fHC->fMCMmax)
585 fMCM = &fHC->fMCMs[fhcMCMcounter];
588 AliError(Form("Super Strange. HC missing at stack %d link %d atMCMslot %d",
589 fStackNumber, fStackLinkNumber, fhcMCMcounter));
592 while(fmcmADCcounter < fMCM->fADCmax)
594 fADC = &fMCM->fADCs[fmcmADCcounter];
597 AliError(Form("Super Strange. ADC missing at stack %d link %d MCMslot %d ADCslot %d",
598 fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));
608 if (fADC->fIsShared == kFALSE)
613 // next MCM should go through all active ADCs
619 // next stack link (HC) should go through all active MCMs
624 // next stack should go through all links - start from 0
625 fStackLinkNumber = 0;
628 // in case rawreader manages the mem buffers
629 // lets go for the next buffer
632 Int_t nextBuff = NextBuffer();
633 while (nextBuff != -1)
637 nextBuff = NextBuffer();
644 //------------------------------------------------------------
647 AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager)
650 // Fills single chamber digit array
651 // Return value is the detector number
654 AliTRDdataArrayS *digits = 0;
655 AliTRDdataArrayI *track0 = 0;
656 AliTRDdataArrayI *track1 = 0;
657 AliTRDdataArrayI *track2 = 0;
658 AliTRDSignalIndex *indexes = 0;
660 // Loop through the digits
663 // Int_t returnDet = -1;
671 // If new detector found
681 if (det < 0 || det >= AliTRDgeometry::kNdet)
683 if (fSM.fClean == kTRUE)
685 AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));
689 AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));
694 // Add a container for the digits of this detector
695 digits = (AliTRDdataArrayS *) digitsManager->GetDigits(det);
696 if (digitsManager->UsesDictionaries())
698 track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0);
699 track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1);
700 track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2);
705 if (fSM.fClean == kTRUE)
707 AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));
711 AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));
717 Int_t rowMax = GetRowMax();
718 Int_t colMax = GetColMax();
719 Int_t ntbins = GetNumberOfTimeBins();
721 // Allocate memory space for the digits buffer
722 if (digits->GetNtime() == 0)
724 digits->Allocate(rowMax, colMax, ntbins);
725 if (digitsManager->UsesDictionaries())
727 track0->Allocate(rowMax, colMax, ntbins);
728 track1->Allocate(rowMax, colMax, ntbins);
729 track2->Allocate(rowMax, colMax, ntbins);
733 indexes = digitsManager->GetIndexes(det);
734 indexes->SetSM(GetSM());
735 indexes->SetStack(GetStack());
736 indexes->SetLayer(GetLayer());
737 indexes->SetDetNumber(det);
738 if (indexes->IsAllocated() == kFALSE)
739 indexes->Allocate(rowMax, colMax, ntbins);
742 // ntimebins data are ready to read
743 for (it = 0; it < GetNumberOfTimeBins(); it++)
745 if (GetSignals()[it] > 0)
747 digits->SetDataUnchecked(GetRow(), GetCol(), it, GetSignals()[it]);
749 indexes->AddIndexTBin(GetRow(), GetCol(), it);
750 if (digitsManager->UsesDictionaries())
752 track0->SetDataUnchecked(GetRow(), GetCol(), it, 0);
753 track1->SetDataUnchecked(GetRow(), GetCol(), it, 0);
754 track2->SetDataUnchecked(GetRow(), GetCol(), it, 0);
760 // what happens if the last HC is turned off?
765 //------------------------------------------------------------
767 AliTRDrawStreamTB::Init()
773 TDirectory *saveDir = gDirectory;
777 fGeometry = new AliTRDgeometry();
782 AliError("Geometry FAILED!");
786 fTRDfeeParam = AliTRDfeeParam::Instance();
789 AliError("AliTRDfeeParam FAILED!");
793 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
795 // common additive is moved to be static for temp solution
796 // common additive should be delivered in the HC word 2 (3rd word)
797 //fCommonAdditive = 10;
801 if (fgDebugStreamFlag == kTRUE)
803 if (!fgDebugStreamer)
805 fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root");
806 fgStreamEventCounter = 0;
810 AliInfo(Form("Debug Streamer Initialized! Remember to delete! %s::DeleteDebugStream()", this->IsA()->GetName()));
811 //fDebugStreamOwned = kTRUE;
815 AliError("Unable to init debug stream");
820 // in case rawreader manages the mem buffers
821 // lets go for the next buffer
824 Int_t nextBuff = NextBuffer();
825 while (nextBuff != -1)
829 nextBuff = NextBuffer();
838 void AliTRDrawStreamTB::DeleteDebugStream()
841 // static helper function
846 delete fgDebugStreamer;
852 //------------------------------------------------------------
854 AliTRDrawStreamTB::InitBuffer(void *buffer, UInt_t length)
857 // init the class before reading from the buffer
858 // and read SM heading info:
859 // -- super module header
860 // -- stack headers + link status words
863 // not in the pre scan mode
865 if(fgStreamEventCounter == 0) fgFirstEquipmentID = fRawReader->GetEquipmentId();
866 fEquipmentID = fRawReader->GetEquipmentId();
867 //fgStreamEventCounter++;
868 if(fEquipmentID == fgFirstEquipmentID) fgStreamEventCounter++;
873 fpBegin = (UInt_t *)buffer;
877 AliFatal("Strange! Size of UInt_t == 0");
881 fWordLength = length/WORD_SIZE;
882 fpEnd = fpBegin + fWordLength;
885 if (fpBegin == 0 || length <= 0)
887 AliError(Form("This will not work! Pointer to the buffer is 0x%08x of size %d", fpBegin, length));
895 AliInfo("------------------------------------------------");
896 if (DumpWords(fpBegin, fgDumpHead) == kFALSE)
898 AliError("Dump failed. Not enough data.");
900 AliInfo("------------------------------------------------");
904 DecodeSMInfo(fpPos, &fSM);
906 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
911 if (SkipWords(fSM.fHeaderSize) == kTRUE)
914 //for (Int_t istack = 0; istack < fSM.fActiveStacks; istack++)
915 for (Int_t istack = 0; istack < 5; istack++)
917 if (fSM.fStackActive[istack] == kFALSE)
920 fStack = &fSM.fStacks[istack];
921 DecodeStackInfo(fpPos, fStack);
924 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
926 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
928 if (SkipWords(fStack->fHeaderSize) == kFALSE)
930 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack head words missing");
942 if (fgWarnError) AliWarning("No Stack info present. Strange.");
943 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
947 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers : %d", fSM.fNexpectedHalfChambers));
952 if (fgDebugFlag) AliDebug(5, "Init OK.");
956 if (fgWarnError) AliWarning("No data just after init. Strange.");
957 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing data");
964 //------------------------------------------------------------
966 AliTRDrawStreamTB::DecodeSM(void *buffer, UInt_t length)
969 // decode all sm at once
970 // still here for devel and debug
973 //memset(&fSM, 0, sizeof(fSM));
978 if (InitBuffer(buffer, length) == kTRUE)
980 // no we are already set!
985 if (fgWarnError) AliError("--- INIT failed. ---------------");
992 for (Int_t istack = 0; istack < 5; istack++)
994 fStackNumber = istack;
995 if (fSM.fStackActive[istack] == kFALSE)
998 fStack = &fSM.fStacks[istack];
1000 //fStack[istack].fActiveLinks // max is 12
1001 for (Int_t ilink = 0; ilink < 12; ilink++)
1003 fStackLinkNumber = ilink;
1004 if (fStack->fLinksActive[ilink] == kFALSE)
1009 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
1010 fSM.fClean = kFALSE;
1014 fHC = &fStack->fHalfChambers[ilink];
1016 if (fgDebugStreamer)
1018 TTreeSRedirector &cstream = *fgDebugStreamer;
1019 cstream << "LINKDataStream"
1020 << "Event=" << fgStreamEventCounter
1021 << ".equipID=" << fEquipmentID
1022 << ".stack=" << fStackNumber
1023 << ".link=" << fStackLinkNumber
1028 if (fSM.fTrackletEnable == kTRUE)
1030 if (DecodeTracklets() == kFALSE)
1032 if (fgDebugStreamer)
1034 TTreeSRedirector &cstream = *fgDebugStreamer;
1035 cstream << "TrackletDecodeError"
1036 << "Event=" << fgStreamEventCounter
1037 << ".Stack=" << fStackNumber
1038 << ".Link=" << fStackLinkNumber
1039 << ".EndOfTrackletCount=" << fEndOfTrackletCount
1043 fSM.fClean = kFALSE;
1048 AliError(Form("Failed stack %d link %d", fStackNumber, fStackLinkNumber));
1049 AliError(Form("Debug Event Counter : %d", fgStreamEventCounter));
1058 if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
1059 fSM.fClean = kFALSE;
1063 if (DecodeHC() == kFALSE)
1065 fSM.fClean = kFALSE;
1068 AliError(Form("Dumping Words for Debugging Purpose =========================>"));
1069 DumpWords(fpPos-8, 16);
1070 AliError(Form("Dumping Done!"));
1072 if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW during ADC data decoding or MCM header decoding
1073 // we don't seek ENDOFRAWDATAMARKER
1077 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
1078 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
1079 AliError(Form("Debug Event Counter : %d\n\n\n", fgStreamEventCounter));
1087 SeekEndOfData(); // make sure that finish off with the end of data markers
1096 if (fSM.fClean == kTRUE)
1099 if (fgCleanDataOnly && (fSM.fClean == kFALSE))
1103 AliWarning("Buffer with errors. Returning FALSE.");
1104 AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
1106 fSM.fActiveStacks = 0; // Next will not give data
1113 //------------------------------------------------------------
1115 AliTRDrawStreamTB::DecodeSM()
1118 // decode SM data in case AliRawReader is in use
1122 Int_t nextBuff = NextBuffer();
1123 while (nextBuff != -1)
1127 nextBuff = NextBuffer();
1133 AliWarning("AliRawReader not set.");
1138 //------------------------------------------------------------
1140 AliTRDrawStreamTB::DecodeSM(AliRawReader *reader)
1143 // decode SM with the AliRawReader
1147 fRawReader = reader;
1152 AliWarning("Argument AliRawReader is 0.");
1157 //------------------------------------------------------------
1159 AliTRDrawStreamTB::SeekEndOfData()
1162 // go to end of data marker
1164 Int_t fEndOfDataCount = 0;
1166 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1171 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd )
1177 // if (fEndOfDataCount == 0)
1179 // if (fgWarnError) AliWarning("End of buffer reached first. No end of data marker?");
1186 //------------------------------------------------------------
1188 AliTRDrawStreamTB::SeekNextMCMheader()
1194 // move back to the mcm pos
1195 fpPos = fMCM->fPos + 1;
1197 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1199 if (MCM_HEADER_MASK_ERR(*fpPos) == 0)
1201 if (fgWarnError) AliWarning(Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1211 //------------------------------------------------------------
1214 AliTRDrawStreamTB::DecodeTracklets()
1220 fLinkTrackletCounter = 0;
1221 fEndOfTrackletCount = 0;
1223 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
1225 while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd )
1228 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
1230 fLinkTrackletCounter++;
1232 if (fLinkTrackletCounter > MAX_TRACKLETS_PERHC)
1234 if (fgWarnError) AliWarning(Form("Max number of tracklets exceeded %d > %d. Something is wrong with the input data!",
1235 fLinkTrackletCounter, MAX_TRACKLETS_PERHC));
1239 AliError(Form("Dumping Words for Debugging Purpose =========================>"));
1240 DumpWords(fpPos-300, 320);
1241 AliError(Form("Dumping Done!"));
1245 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
1249 if (fgDebugStreamer)
1265 row = (val >> 20) & 0xF;
1266 defl = (val >> 13) & 0x7F;
1267 defl = defl << 25 >> 25;
1268 ypos = val & 0x1FFF;
1269 ypos = ypos << 19 >> 19;
1271 deflm = defl * 140.0e-6; /* m */
1272 yposm = ypos * 160.0e-6; /* m */
1274 TTreeSRedirector &cstream = *fgDebugStreamer;
1275 cstream << "MCMtracklets"
1276 << "Event=" << fgStreamEventCounter
1277 << ".stack=" << fStackNumber
1278 << ".link=" << fStackLinkNumber
1283 << ".deflm=" << deflm
1284 << ".yposm=" << yposm
1290 while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd )
1292 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1294 fEndOfTrackletCount++;
1298 if ( fEndOfTrackletCount < 2 )
1300 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1307 //------------------------------------------------------------
1309 AliTRDrawStreamTB::IsRowValid()
1312 if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||
1313 (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 )
1315 if (fgWarnError) AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1316 , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));
1317 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadrow, "Wrong Row");
1323 //------------------------------------------------------------
1325 AliTRDrawStreamTB::IsMCMheaderOK()
1328 // check the mcm header
1331 if ( fMCM->fCorrupted > 1 )
1333 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"ADC mask Corrupted");
1334 if (fgWarnError) AliWarning(Form("Wrong ADC Mask word 0x%08x %s. Error : %d\n", *fMCM->fPos, DumpMCMadcMask(fMCM), fMCM->fCorrupted));
1338 if ( fMCM->fCorrupted > 0 )
1340 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"Corrupted");
1341 if (fgWarnError) AliWarning(Form("Wrong MCM word 0x%08x %s. Error : %d\n", *fMCM->fPos, DumpMCMinfo(fMCM), fMCM->fCorrupted));
1345 if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 )
1347 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongMCMorROB,"Wrong ROB or MCM");
1348 if (fgWarnError) AliWarning(Form("Wrong fMCM or fROB. %s\n", DumpMCMinfo(fMCM)));
1352 if (IsRowValid() == kFALSE)
1358 //------------------------------------------------------------
1360 AliTRDrawStreamTB::IsMCMevCounterOK()
1363 // Check the MCM event counter
1366 if (fEventCounter == 0)
1368 fEventCounter = fMCM->fEvCounter;
1371 if (fEventCounter < fLastEventCounter)
1373 fMCM->fCorrupted += 4;
1374 if (fgWarnError) AliWarning(Form("Event from the past? Current %d Last %d %s. Error : %d\n", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM), fMCM->fCorrupted));
1375 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ? Past-Future");
1379 if (fEventCounter != fMCM->fEvCounter)
1381 fMCM->fCorrupted += 4;
1382 if (fgWarnError) AliWarning(Form("Event missmatch? FirstMCMs %d ThisMCMs %d %s. Error : %d\n", fEventCounter, fMCM->fEvCounter, DumpMCMinfo(fMCM), fMCM->fCorrupted));
1383 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ?");
1390 //------------------------------------------------------------
1392 AliTRDrawStreamTB::DecodeMCMheader()
1395 // decode the mcm header
1398 DecodeMCMheader(fpPos, fMCM);
1399 if (fHC->fCorrupted >= 16)
1405 fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
1407 if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || (fHC->fRawVMajor > 31 && fHC->fRawVMajor < 64)) //cover old and new version definition of ZS data
1410 if ( fpPos < fpEnd )
1412 DecodeMask(fpPos, fMCM);
1413 if (fHC->fCorrupted >= 16)
1418 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1419 fMCM->fAdcDataPos = fpPos + 1;
1423 if (fgWarnError) AliWarning("Expected ADC mask word. Fail due to buffer END.");
1424 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1430 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
1431 DecodeMask(&dummyMask, fMCM);
1432 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1433 fMCM->fAdcDataPos = fpPos + 1;
1438 AliDebug(6, DumpMCMinfo(fMCM));
1439 AliDebug(7, DumpMCMadcMask(fMCM));
1442 if (IsMCMheaderOK() == kFALSE)
1445 if (IsMCMevCounterOK() == kFALSE)
1451 //------------------------------------------------------------
1453 AliTRDrawStreamTB::IsHCheaderOK()
1456 // check the half chamber header
1459 if (fHC->fCorrupted > 0)
1461 if (fgWarnError) AliWarning(Form("Wrong HC Header word. Word 0x%08x Error : %d", *fHC->fPos, fHC->fCorrupted));
1462 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "Corrupted");
1467 if (fHC->fStack < 0 || fHC->fStack > 4)
1469 if (fgWarnError) AliWarning(Form("Wrong Stack %d", fHC->fStack));
1470 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Wrong Stack");
1474 if (fgStackNumberChecker)
1476 if (fHC->fStack != fStackNumber)
1478 if (fgWarnError) AliWarning(Form("Missmatch: Stack in HC header %d HW-stack %d",
1479 fHC->fStack, fStackNumber));
1480 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Stack-HWstack");
1486 if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNplan)
1488 if (fgWarnError) AliWarning(Form("Wrong plane(layer) %d", fHC->fLayer));
1489 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Wrong Plane");
1493 if (fgStackLinkNumberChecker)
1496 if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1))
1498 if (fgWarnError) AliWarning(Form("Missmatch: plane(layer) in HCheader %d HW-Link %d | %s",
1499 fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));
1500 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Plane-Link missmatch");
1501 fStackLinkNumber = -1;
1506 if (fHC->fSide < 0 || fHC->fSide > 1)
1508 if (fgWarnError) AliWarning(Form("Wrong Side %d", fHC->fSide));
1509 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSide, "Wrong Side");
1514 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
1515 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet)
1517 if (fgWarnError) AliWarning(Form("Wrong detector %d", fHC->fDET));
1518 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1523 // this check fails - raw data inconsistent with geometry?
1524 if (fHC->fSM != fGeometry->GetSector(fHC->fDET)
1525 || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsect)
1527 if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1528 fHC->fSM, fGeometry->GetSector(fHC->fDET),
1529 fHC->fStack, fHC->fLayer, fHC->fDET));
1530 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1536 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
1539 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1543 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
1544 if (fHC->fRowMax < 1)
1546 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1550 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
1551 if (fHC->fColMax < 1)
1553 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1556 // extra - not needed
1557 // if (fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsect)
1559 // if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d",
1560 // fHC->fSM, fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack),
1561 // fHC->fStack, fHC->fLayer));
1568 //------------------------------------------------------------
1570 AliTRDrawStreamTB::DecodeHCheader()
1573 // decode the half chamber header
1576 DecodeHCwordH0(fpPos, fHC);
1578 if (fHC->fNExtraWords > 0)
1583 DecodeHCwordH1(fpPos, fHC);
1587 if (fgWarnError) AliWarning("Expected HC header word 1. Fail due to buffer END.");
1588 if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing");
1593 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1594 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1597 if (IsHCheaderOK() == kFALSE)
1599 fHC->fCorrupted +=4;
1606 //------------------------------------------------------------
1608 AliTRDrawStreamTB::DecodeHC()
1611 // decode the hc data
1612 // function for devel & debug
1615 if (DecodeHCheader() == kFALSE)
1617 if (fgDebugStreamer)
1619 TTreeSRedirector &cstream = *fgDebugStreamer;
1620 cstream << "HCDecodeError"
1621 << "Event=" << fgStreamEventCounter
1622 << ".stack=" << fStackNumber
1623 << ".link=" << fStackLinkNumber
1624 << ".hcCorrupted=" << fHC->fCorrupted
1625 << ".hcRVmajor=" << fHC->fRawVMajor
1626 << ".hcDCSboard=" << fHC->fDCSboard
1627 << ".hcSM=" << fHC->fSM
1628 << ".hcStack=" << fHC->fStack
1629 << ".hcLayer=" << fHC->fLayer
1630 << ".hcSide=" << fHC->fSide
1631 << ".hcTbins=" << fHC->fTimeBins
1632 << ".hcBunchCross=" << fHC->fBunchCrossCounter
1633 << ".hcPreTrig=" << fHC->fPreTriggerCounter
1634 << ".hcPreTrigPh=" << fHC->fPreTriggerPhase
1635 << ".hcDet=" << fHC->fDET
1636 << ".hcROC=" << fHC->fROC
1637 << ".hcRowMax=" << fHC->fRowMax
1638 << ".hcColMax=" << fHC->fColMax
1642 if (fgWarnError) AliWarning("Header decode failed.");
1650 if (fgWarnError) AliWarning("No MCM data? Not enough data in the buffer.");
1651 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing");
1657 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd)
1659 if (fHC->fMCMmax > TRD_MAX_MCM)
1661 if (fgWarnError) AliWarning("More mcm data than expected!");
1662 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!");
1666 fMCM = &fHC->fMCMs[fHC->fMCMmax];
1668 if (DecodeMCMheader() == kFALSE)
1670 if (fgDebugStreamer)
1672 TTreeSRedirector &cstream = *fgDebugStreamer;
1673 cstream << "MCMDecodeError"
1674 << "Event=" << fgStreamEventCounter
1675 << ".stack=" << fStackNumber
1676 << ".link=" << fStackLinkNumber
1677 << ".hcDCSboard=" << fHC->fDCSboard
1678 << ".hcSM=" << fHC->fSM
1679 << ".hcStack=" << fHC->fStack
1680 << ".hcLayer=" << fHC->fLayer
1681 << ".hcSide=" << fHC->fSide
1682 << ".hcBunchCross=" << fHC->fBunchCrossCounter
1683 << ".hcPreTrig=" << fHC->fPreTriggerCounter
1684 << ".hcPreTrigPh=" << fHC->fPreTriggerPhase
1685 << ".hcDet=" << fHC->fDET
1687 << ".mcmCorrupted=" << fMCM->fCorrupted
1688 << ".mcmROB=" << fMCM->fROB
1689 << ".mcmMCM=" << fMCM->fMCM
1690 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1691 << ".mcmEventCounter=" << fMCM->fEvCounter
1693 << ".fEventCounter=" << fEventCounter
1694 << ".fLastEventCounter=" << fLastEventCounter
1698 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1699 return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose
1704 if (fMCM->fADCmax > 0)
1709 if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected."));
1710 if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing");
1713 unsigned long randVal, iniVal, expectedVal;
1714 Int_t endbits = ENDBITS;
1716 for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++)
1718 fADC = &fMCM->fADCs[iadc];
1719 fADC->fADCnumber = fMCM->fADCchannel[iadc];
1721 if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.",
1722 iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1724 if (fpPos + fMCM->fSingleADCwords >= fpEnd)
1726 if (fgDebugStreamer)
1728 TTreeSRedirector &cstream = *fgDebugStreamer;
1730 cstream << "ADCDecodeError"
1731 << "Event=" << fgStreamEventCounter
1732 << ".hcSM=" << fHC->fSM
1733 << ".hcStack=" << fHC->fStack
1734 << ".hcLayer=" << fHC->fLayer
1735 << ".hcSide=" << fHC->fSide
1736 << ".hcDet=" << fHC->fDET
1737 << ".mcmROB=" << fMCM->fROB
1738 << ".mcmMCM=" << fMCM->fMCM
1739 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1740 << ".adcErr=" << ierr
1741 << ".adcNumber=" << ierr
1745 if (fgWarnError) AliWarning(Form("This is ADC %d of %d. ADC number is %d.", iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1746 if (fgWarnError) AliWarning("--> ADC (10 words) expected. Not enough data in the buffer.");
1747 if (fgWarnError) AliWarning(Form("--> ADC mask : %s", DumpMCMadcMask(fMCM)));
1749 if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing - less than expected");
1753 if (fHC->fRawVMajor < 64) // normal(real) ADC data
1755 if (DecodeADC() == kFALSE)
1757 // check if we are out of the det when the pad is shared
1758 if (fADC->fIsShared && fADC->fCorrupted == 4)
1761 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1765 if (fgWarnError) AliWarning(Form("ADC decode failed."));
1767 if (fgDebugStreamer)
1769 TTreeSRedirector &cstream = *fgDebugStreamer;
1770 cstream << "ADCDecodeError"
1771 << "Event=" << fgStreamEventCounter
1772 << ".hcSM=" << fHC->fSM
1773 << ".hcStack=" << fHC->fStack
1774 << ".hcLayer=" << fHC->fLayer
1775 << ".hcSide=" << fHC->fSide
1776 << ".hcDet=" << fHC->fDET
1777 << ".mcmROB=" << fMCM->fROB
1778 << ".mcmMCM=" << fMCM->fMCM
1779 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1780 << ".adcErr=" << fADC->fCorrupted
1781 << ".adcNumber=" << fADC->fADCnumber
1784 if (fHC->fCorrupted < 16)
1785 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1787 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1788 return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose
1792 else // test pattern data
1794 if (fHC->fRawVMajorOpt == 1) //test pattern 1
1796 Int_t iCpu = iadc/5;
1797 if(iadc==20) iCpu = 3;
1798 if(iadc%5==0 && iadc!=20) randVal = (1 << 9) | (fMCM->fROB << 6) | (fMCM->fMCM << 2) | iCpu;
1799 if (DecodeADCTP1(&randVal,&endbits) == kFALSE)
1801 if (fgWarnError) AliWarning(Form("Summary: Test Pattern ADC data are corrupted in channel %d %s\n", iadc, DumpMCMinfo(fMCM)));
1802 if (fgDebugStreamer)
1804 TTreeSRedirector &cstream = *fgDebugStreamer;
1805 cstream << "ADCDecodeError"
1806 << "Event=" << fgStreamEventCounter
1807 << ".hcSM=" << fHC->fSM
1808 << ".hcStack=" << fHC->fStack
1809 << ".hcLayer=" << fHC->fLayer
1810 << ".hcSide=" << fHC->fSide
1811 << ".hcDet=" << fHC->fDET
1812 << ".mcmROB=" << fMCM->fROB
1813 << ".mcmMCM=" << fMCM->fMCM
1814 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1815 << ".adcErr=" << fADC->fCorrupted
1816 << ".adcNumber=" << fADC->fADCnumber
1819 if (fHC->fCorrupted < 16)
1820 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1822 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1823 return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose
1827 if (fHC->fRawVMajorOpt == 2 || fHC->fRawVMajorOpt == 3) //test pattern 2 or 3
1829 iniVal = (fHC->fSM << 6) | (fHC->fStack << 0) | (fHC->fLayer << 3);
1830 iniVal = iniVal + 0x49;
1831 iniVal = (iniVal << 9) | (fMCM->fROB << 6) | (fMCM->fMCM << 2) | (fMCM->fEvCounter << 20);
1832 Int_t iCpu = iadc/5;
1833 if (iadc==20) iCpu = 3;
1834 if (iadc%5==0 && iadc!=20)
1836 if (fHC->fRawVMajorOpt == 2) { expectedVal = ((iniVal | iCpu) << 6) + 1; };
1837 if (fHC->fRawVMajorOpt == 3) { expectedVal = iniVal | iCpu; };
1839 if (DecodeADCTP23(&expectedVal) == kFALSE)
1841 if (fgWarnError) AliWarning(Form("Summary: Test Pattern ADC data are corrupted in channel %d %s\n", iadc, DumpMCMinfo(fMCM)));
1842 if (fgDebugStreamer)
1844 TTreeSRedirector &cstream = *fgDebugStreamer;
1845 cstream << "ADCDecodeError"
1846 << "Event=" << fgStreamEventCounter
1847 << ".hcSM=" << fHC->fSM
1848 << ".hcStack=" << fHC->fStack
1849 << ".hcLayer=" << fHC->fLayer
1850 << ".hcSide=" << fHC->fSide
1851 << ".hcDet=" << fHC->fDET
1852 << ".mcmROB=" << fMCM->fROB
1853 << ".mcmMCM=" << fMCM->fMCM
1854 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1855 << ".adcErr=" << fADC->fCorrupted
1856 << ".adcNumber=" << fADC->fADCnumber
1859 if (fHC->fCorrupted < 16)
1860 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1862 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1863 return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose
1877 if (fgWarnError) AliWarning("We are at the end of buffer. There should be one more word left.");
1883 //------------------------------------------------------------
1886 AliTRDrawStreamTB::DecodeADC()
1889 // decode single ADC channel
1892 fADC->fCorrupted = 0;
1893 fMaskADCword = ADC_WORD_MASK(*fpPos);
1897 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
1898 fADC->fSignals[i] = 0;
1900 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
1902 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW)
1904 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1905 fADC->fCorrupted += 16;
1906 fHC->fCorrupted += 16;
1911 if (fMaskADCword != ADC_WORD_MASK(*fpPos))
1913 fADC->fCorrupted += 1;
1914 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",
1915 iw - 1, *(fpPos-1), fMaskADCword, iw, *fpPos, ADC_WORD_MASK(*fpPos)));
1916 if (fRawReader) fRawReader->AddMajorErrorLog(kADCmaskMissmatch, "Mask change inside single channel");
1920 // here we subtract the baseline ( == common additive)
1921 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1922 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1923 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1929 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
1931 fADC->fIsShared = kTRUE;
1935 fADC->fIsShared = kFALSE;
1938 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
1940 // let us guess the Column
1941 // take the one before last ADC and shift by one column
1942 // later we check if we are inside the limits of the chamber
1943 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
1948 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1951 if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0)
1953 if (fADC->fIsShared == kFALSE)
1955 fADC->fCorrupted += 2;
1956 if (fgWarnError) AliWarning(Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1957 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1958 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadcolumn, "Wrong column");
1962 // flag it - we are out of the det when the pad is shared
1963 if (fgDebugFlag) AliDebug(10, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1964 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1965 fADC->fCorrupted += 4;
1969 if (fADC->fCorrupted > 0)
1977 //------------------------------------------------------------
1980 AliTRDrawStreamTB::DecodeADCTP1(unsigned long *randVal, Int_t *endbits)
1983 // decode test pattern ADC channel
1986 unsigned long expected;
1988 fADC->fCorrupted = 0;
1992 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
1993 fADC->fSignals[i] = 0;
1995 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
1997 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW)
1999 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
2000 fADC->fCorrupted += 16;
2001 fHC->fCorrupted += 16;
2006 expected = (AdvancePseudoRandom(randVal) << 2) | *endbits;
2007 expected |= AdvancePseudoRandom(randVal) << 12;
2008 expected |= AdvancePseudoRandom(randVal) << 22;
2009 if (*fpPos != expected)
2011 if (fgWarnError) AliError(Form("Error: fpPos=%d, size=%d, found=0x%08lx, expected=0x%08lx",iw, fMCM->fSingleADCwords, *fpPos, expected));
2012 fADC->fCorrupted += 32; //test pattern corrupted
2014 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2);
2015 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12);
2016 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22);
2021 *endbits = *endbits ^ 0x01;
2023 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
2025 fADC->fIsShared = kTRUE;
2029 fADC->fIsShared = kFALSE;
2032 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
2034 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
2039 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
2042 if (fADC->fCorrupted > 0)
2050 //--------------------------------------------------------
2053 AliTRDrawStreamTB::DecodeADCTP23(unsigned long *expected)
2056 // decode test pattern ADC channel
2059 fADC->fCorrupted = 0;
2063 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
2064 fADC->fSignals[i] = 0;
2066 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
2068 if (*fpPos == END_OF_TRACKLET_MARKERNEW)
2070 if (fgWarnError) AliError(Form("There should be ADC data. We meet END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
2071 fADC->fCorrupted += 16;
2072 fHC->fCorrupted += 16;
2077 if (*fpPos != *expected)
2081 if (fHC->fRawVMajorOpt == 2)
2083 AliError(Form("Error: fpPos=%d, size=%d, found=0x%08lx, expected=0x%08lx",iw, fMCM->fSingleADCwords, *fpPos, *expected));
2084 AliError(Form("Found ev.cnt. %ld, expected %ld", (*fpPos >> 26), (*expected >> 26)));
2085 AliError(Form("Found sector %ld, expected %ld", (*fpPos >> 21) & 0x1f - 1, (*expected >> 21) & 0x1f - 1));
2086 AliError(Form("Found layer %ld, expected %ld", (*fpPos >> 18) & 0x07 - 1, (*expected >> 18) & 0x07 - 1));
2087 AliError(Form("Found chamber %ld, expected %ld", (*fpPos >> 15) & 0x07 - 1, (*expected >> 15) & 0x07 - 1));
2088 AliError(Form("Found ROB %ld, expected %ld", (*fpPos >> 12) & 0x07, (*expected >> 12) & 0x07));
2089 AliError(Form("Found MCM %ld, expected %ld", (*fpPos >> 8) & 0x0f, (*expected >> 8) & 0x0f));
2090 AliError(Form("Found CPU %ld, expected %ld", (*fpPos >> 6) & 0x03, (*expected >> 6) & 0x03));
2091 AliError(Form("Found counter %ld, expected %ld\n", (*fpPos >> 0) & 0x3f, (*expected >> 0) & 0xf));
2093 if (fHC->fRawVMajorOpt == 3)
2095 AliError(Form("Error: fpPos=%d, size=%d, found=0x%08lx, expected=0x%08lx",iw, fMCM->fSingleADCwords, *fpPos, *expected));
2096 AliError(Form("Found ev.cnt. %ld, expected %ld", (*fpPos >> 20), (*expected >> 20)));
2097 AliError(Form("Found sector %ld, expected %ld", (*fpPos >> 15) & 0x1f - 1, (*expected >> 15) & 0x1f - 1));
2098 AliError(Form("Found layer %ld, expected %ld", (*fpPos >> 12) & 0x07 - 1, (*expected >> 12) & 0x07 - 1));
2099 AliError(Form("Found chamber %ld, expected %ld", (*fpPos >> 9) & 0x07 - 1, (*expected >> 9) & 0x07 - 1));
2100 AliError(Form("Found ROB %ld, expected %ld", (*fpPos >> 6) & 0x07, (*expected >> 6) & 0x07));
2101 AliError(Form("Found MCM %ld, expected %ld", (*fpPos >> 2) & 0x0f, (*expected >> 2) & 0x0f));
2102 AliError(Form("Found CPU %ld, expected %ld\n", (*fpPos >> 0) & 0x03, (*expected >> 0) & 0x03));
2106 fADC->fCorrupted += 32; //test pattern corrupted
2108 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2);
2109 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12);
2110 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22);
2114 if (fHC->fRawVMajorOpt == 2) (*expected)++;
2117 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
2119 fADC->fIsShared = kTRUE;
2123 fADC->fIsShared = kFALSE;
2126 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
2128 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
2133 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
2136 if (fADC->fCorrupted > 0)
2144 //--------------------------------------------------------
2147 void AliTRDrawStreamTB::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
2150 // Decode the data *word into SM info structure
2153 sm->fPos = (UInt_t*)word;
2156 UInt_t vword = *word;
2157 sm->fHeaderSize = SM_HEADER_SIZE(vword);
2159 if (TRACKLETS_ENABLED(vword) > 0)
2160 sm->fTrackletEnable = kTRUE;
2162 sm->fTrackletEnable = kFALSE;
2164 UInt_t stackMask = STACK_MASK(vword);
2165 sm->fActiveStacks = 0;
2166 for (Int_t i = 0; i < 5; i++)
2168 //if ((stackMask >> i) & 0x1 > 0)
2169 if (IS_BIT_SET(stackMask,i) > 0)
2171 sm->fStackActive[i] = kTRUE;
2172 sm->fActiveStacks++;
2176 sm->fStackActive[i] = kFALSE;
2181 //--------------------------------------------------------
2182 const char *AliTRDrawStreamTB::DumpSMInfo(const struct AliTRDrawSM *sm)
2185 // Get SM structure into a const char
2188 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
2190 sm->fHeaderSize, sm->fTrackletEnable,
2191 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
2192 sm->fStackActive[3], sm->fStackActive[4]);
2195 //--------------------------------------------------------
2196 void AliTRDrawStreamTB::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
2199 // Decode stack info - active links
2202 st->fPos = (UInt_t*)word;
2205 UInt_t vword = *word;
2206 st->fHeaderSize = STACK_HEADER_SIZE(vword);
2208 UInt_t linkMask = STACK_LINK_WORD(vword);
2209 st->fActiveLinks = 0;
2210 for (Int_t i = 0; i < 12; i++)
2212 //if (linkMask & (0x1 << i) > 0)
2213 if (IS_BIT_SET(linkMask,i) > 0)
2215 st->fLinksActive[i] = kTRUE;
2216 st->fTrackletDecode[i] = kTRUE;
2217 st->fHCDecode[i] = kTRUE;
2222 st->fTrackletDecode[i] = kFALSE;
2223 st->fLinksActive[i] = kFALSE;
2224 st->fHCDecode[i] = kFALSE;
2229 //--------------------------------------------------------
2230 const char *AliTRDrawStreamTB::DumpStackInfo(const struct AliTRDrawStack *st)
2233 // format the string with the stack info
2235 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
2238 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
2239 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
2240 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
2243 //--------------------------------------------------------
2244 void AliTRDrawStreamTB::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
2247 // decode the hc header word 0
2251 UInt_t vword = *word;
2253 hc->fCorrupted = HC_HEADER_MASK_ERR(vword);
2254 if (hc->fCorrupted > 0)
2256 hc->fH0ErrorCounter++;
2259 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
2260 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
2261 hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword);
2262 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
2263 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
2264 hc->fDCSboard = HC_DCS_BOARD(vword);
2265 hc->fSM = HC_SM_NUMBER(vword);
2266 hc->fStack = HC_STACK_NUMBER(vword);
2267 hc->fLayer = HC_LAYER_NUMBER(vword);
2268 hc->fSide = HC_SIDE_NUMBER(vword);
2270 hc->fPos[0] = (UInt_t*)word;
2274 //--------------------------------------------------------
2275 void AliTRDrawStreamTB::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
2282 UInt_t vword = *word;
2284 hc->fCorrupted += 2 * HC_HEADER_MASK_ERR(vword);
2285 if (hc->fCorrupted >= 2)
2287 hc->fH1ErrorCounter++;
2290 hc->fTimeBins = HC_NTIMEBINS(vword);
2291 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
2292 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
2293 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
2295 hc->fPos[1] = (UInt_t*)word;
2298 //--------------------------------------------------------
2299 const char *AliTRDrawStreamTB::DumpHCinfoH0(const struct AliTRDrawHC *hc)
2305 return Form("Unable to dump. Null received as parameter!?!");
2307 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
2308 hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
2311 //--------------------------------------------------------
2312 const char *AliTRDrawStreamTB::DumpHCinfoH1(const struct AliTRDrawHC *hc)
2318 return Form("Unable to dump. Null received as parameter!?!");
2320 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
2321 hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
2324 //--------------------------------------------------------
2325 void AliTRDrawStreamTB::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2328 // decode the mcm header
2331 UInt_t vword = *word;
2333 if (vword == END_OF_TRACKLET_MARKERNEW)
2335 if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
2336 mcm->fCorrupted += 16;
2337 fHC->fCorrupted += 16; //to finish data reading of this HC
2339 mcm->fCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error, set mcm->fCorrupted = 1
2340 if (mcm->fCorrupted)
2341 mcm->fErrorCounter++;
2342 mcm->fROB = MCM_ROB_NUMBER(vword);
2343 mcm->fMCM = MCM_MCM_NUMBER(vword);
2344 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
2345 mcm->fPos = (UInt_t*)word;
2348 //--------------------------------------------------------
2349 UInt_t AliTRDrawStreamTB::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2355 UInt_t vword = *word;
2361 mcm->fADCMaskWord = vword;
2363 if (vword == END_OF_TRACKLET_MARKERNEW)
2365 if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
2366 mcm->fCorrupted += 16;
2367 fHC->fCorrupted += 16; //to finish data reading of this HC
2370 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 )
2372 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
2373 mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
2377 mcm->fADCMask = 0xffffffff;
2378 mcm->fCorrupted += 2;
2379 mcm->fMaskErrorCounter++;
2382 return mcm->fADCMask;
2385 //--------------------------------------------------------
2386 void AliTRDrawStreamTB::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2389 // decode the adc mask - adcs to be read out
2392 mcm->fMCMADCWords = 0;
2393 mcm->fSingleADCwords = 0;
2395 mcm->fADCMask = GetMCMadcMask(word, mcm);
2397 if (mcm->fADCMask > 0)
2399 for (Int_t i = 0; i < TRD_MAX_ADC; i++)
2401 mcm->fADCchannel[mcm->fADCmax] = 0;
2402 if( IS_BIT_SET(mcm->fADCMask,i) )
2404 mcm->fADCchannel[mcm->fADCmax] = i;
2409 if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) // backward compatibility
2411 mcm->fCorrupted += 8;
2415 //--------------------------------------------------------
2416 void AliTRDrawStreamTB::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
2419 // count the expected mcm words for a given tbins
2421 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
2422 mcm->fSingleADCwords = 0;
2423 if (mcm->fADCmax > 0)
2425 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
2429 //--------------------------------------------------------
2430 const unsigned long AliTRDrawStreamTB::AdvancePseudoRandom(unsigned long *val) const
2433 // pseudo random number generator for test pattern data
2435 unsigned long currentVal = *val;
2437 *val = ( (*val << 1) | (((*val >> 9) ^ (*val >> 6)) & 1) ) & 0x3FF;
2441 //--------------------------------------------------------
2442 const char *AliTRDrawStreamTB::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
2445 // mcm info in a string
2448 return Form("Unable to dump. Null received as parameter!?!");
2450 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
2453 //--------------------------------------------------------
2454 //TString DumpMCMadcMask(const struct AliTRDrawMCMInfo *mcm)
2455 const char *AliTRDrawStreamTB::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
2458 // mcm adc mask in a string
2461 return Form("Unable to dump. Null received as parameter!?!");
2463 TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
2464 for (Int_t i = 0; i < 21; i++)
2466 tsreturn += Form("%d ", mcm->fADCchannel[i]);
2469 return tsreturn.Data();