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
49 #define WORD_SIZE sizeof(UInt_t) // size of a word in bytes
50 #define EXTRA_LEAD_WORDS 24
53 #define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w
54 #define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m
56 // SM index word masks:
57 #define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
58 #define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)
59 #define STACK_MASK(w) ((w) & 0x1f)
62 #define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
63 #define STACK_LINK_WORD(w) ((w) & 0xfff)
66 //#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!!
67 #define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK!!!
70 #define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)
71 #define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)
72 #define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)
73 #define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)
74 #define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)
75 #define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)
76 #define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)
77 #define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)
78 #define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)
81 #define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)
82 #define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)
83 #define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)
84 #define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,6)
86 //--------------------------------------------------------
88 // MCM word and ADC mask
89 #define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
90 #define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
91 #define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)
92 #define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)
93 #define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)
94 #define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)
96 //this should give 0x1fffff as a mask
97 #define MCM_DUMMY_ADCMASK_VAL 0x001fffffc
98 //--------------------------------------------------------
100 #define MAX_TRACKLETS_PERHC 256 // max number of tracklets per HC - large number for now
102 //--------------------------------------------------------
103 #define ADC_WORD_MASK(w) ((w) & 0x3)
104 //--------------------------------------------------------
105 ClassImp(AliTRDrawStreamTB)
107 Bool_t AliTRDrawStreamTB::fgExtraSkip = kFALSE;
108 Bool_t AliTRDrawStreamTB::fgSkipCDH = kFALSE;
109 Bool_t AliTRDrawStreamTB::fgWarnError = kTRUE;
110 Bool_t AliTRDrawStreamTB::fgCleanDataOnly = kTRUE;
111 Bool_t AliTRDrawStreamTB::fgDebugFlag = kTRUE;
112 Bool_t AliTRDrawStreamTB::fgDebugStreamFlag = kFALSE;
113 Bool_t AliTRDrawStreamTB::fgStackNumberChecker = kTRUE;
114 Bool_t AliTRDrawStreamTB::fgStackLinkNumberChecker = kTRUE;
115 TTreeSRedirector *AliTRDrawStreamTB::fgDebugStreamer = 0;
116 UInt_t AliTRDrawStreamTB::fgStreamEventCounter = 0;
117 UInt_t AliTRDrawStreamTB::fgFirstEquipmentID = 0;
118 UInt_t AliTRDrawStreamTB::fgDumpHead = 0;
119 Int_t AliTRDrawStreamTB::fgCommonAdditive = 0;
120 Int_t AliTRDrawStreamTB::fgEmptySignals[] =
122 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
123 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
126 AliTRDrawStreamTB::AliTRDrawStreamTB()
127 : AliTRDrawStreamBase()
140 , fStackLinkNumber(-1)
143 , fLinkTrackletCounter(-1)
144 , fEndOfTrackletCount(-1)
149 , fLastEventCounter(0)
150 , fSharedPadsOn(kFALSE)
155 , fDebugStreamOwned(kFALSE)
158 // default constructor
161 if (Init() == kFALSE)
163 AliWarning("Unable to Init.");
167 //--------------------------------------------------------
168 AliTRDrawStreamTB::AliTRDrawStreamTB(AliRawReader *rawReader)
169 : AliTRDrawStreamBase(rawReader)
182 , fStackLinkNumber(-1)
185 , fLinkTrackletCounter(-1)
186 , fEndOfTrackletCount(-1)
191 , fLastEventCounter(0)
192 , fSharedPadsOn(kFALSE)
195 , fRawReader(rawReader)
197 , fDebugStreamOwned(kFALSE)
200 // default constructor
204 if (Init() == kFALSE)
206 AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
211 AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
215 //------------------------------------------------------------
217 AliTRDrawStreamTB::AliTRDrawStreamTB(const AliTRDrawStreamTB& /*st*/)
218 : AliTRDrawStreamBase()
231 , fStackLinkNumber(-1)
234 , fLinkTrackletCounter(-1)
235 , fEndOfTrackletCount(-1)
240 , fLastEventCounter(0)
241 , fSharedPadsOn(kFALSE)
246 , fDebugStreamOwned(kFALSE)
251 AliError("Not implemeneted.");
254 //------------------------------------------------------------
255 Bool_t AliTRDrawStreamTB::SetRawVersion(Int_t fraw)
258 // function provided for backward compatibility
260 AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");
261 fraw = 0; // avoid warnings
265 //------------------------------------------------------------
266 AliTRDrawStreamTB::~AliTRDrawStreamTB()
273 if (fDebugStreamOwned == kTRUE)
277 delete fgDebugStreamer;
283 //------------------------------------------------------------
286 AliTRDrawStreamTB::operator=(const AliTRDrawStreamTB &)
289 // we are not using this functionality
291 AliFatal("May not use.");
295 //------------------------------------------------------------
298 AliTRDrawStreamTB::EnableDebug(TTreeSRedirector *debugStream)
301 // replace the current debug streamer or create a new one if owned
304 if (debugStream == 0)
306 if (fDebugStreamOwned == kTRUE)
309 delete fgDebugStreamer;
312 fDebugStreamOwned = kTRUE;
313 fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root");
314 fgStreamEventCounter = 0;
319 if (fDebugStreamOwned == kTRUE)
322 delete fgDebugStreamer;
325 fgDebugStreamer = debugStream;
326 fDebugStreamOwned = kFALSE;
330 //___________________________________________________________
332 AliTRDrawStreamTB::SwapOnEndian()
335 // Check the endian and swap if needed
339 char* ptemp = (char*) &itemp;
343 if (fgDebugFlag) AliDebug(8, "Swapping.");
347 while (fpPos < fpEnd)
350 iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
351 ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
352 // here we override the value in the buffer!
359 //------------------------------------------------------------
361 AliTRDrawStreamTB::DumpErrorCount()
364 // print the error statistics into the stdout
368 // AliInfo(Form("Error counts: HC0 %d HC1 %d MCM %d ADCmask %d ADC %d",
369 // fHC->fH0ErrorCounter, fHC->fH1ErrorCounter, fMCM->fErrorCounter, fMCM->fMaskErrorCounter, adc.fErrorCounter));
372 //------------------------------------------------------------
374 AliTRDrawStreamTB::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
378 // note: can be made faster
381 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
382 for (UInt_t i = 0; i < iw; i++)
384 if (px + iw >= fpEnd)
389 if (marker != 0 && marker == px[i])
390 tsreturn += Form(" *>0x%08x<* ", px[i]);
392 tsreturn += Form("0x%08x ", px[i]);
396 AliInfo(tsreturn.Data());
401 //------------------------------------------------------------
403 AliTRDrawStreamTB::SkipWords(UInt_t iw)
407 // note: can be made faster
410 if ( fpPos + iw < fpEnd )
417 if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
420 TTreeSRedirector &cstream = *fgDebugStreamer;
421 cstream << "SkipWords"
422 << "Event=" << fgStreamEventCounter
424 // << ".read=" << (Char_t*)(fpPos - fpBegin)
425 // << ".togo=" << (Char_t*)(fpEnd - fpPos)
426 // << ".length=" << (Char_t*)(fpEnd - fpBegin)
435 //------------------------------------------------------------
437 AliTRDrawStreamTB::SetReader(AliRawReader *reader)
452 AliWarning("Unable to setup reader.");
458 AliWarning("AliRawReader argument is 0.");
465 //------------------------------------------------------------
467 AliTRDrawStreamTB::NextBuffer()
470 // return -1 if no more buffers available
471 // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come
472 // return 1 DecodeSM OK
479 Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
480 if (kBufferSet == kTRUE)
482 if (fgDebugFlag) AliDebug(9, "Buffer is set.");
483 length = fRawReader->GetDataSize();
484 if (fgExtraSkip == kTRUE)
486 buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
487 length -= EXTRA_LEAD_WORDS * WORD_SIZE;
490 if (fgSkipCDH == kTRUE)
492 buffer += CDH_WORDS * WORD_SIZE;
493 length -= CDH_WORDS * WORD_SIZE;
498 if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
499 //return InitBuffer((void*)buffer, length);
500 if (DecodeSM((void*)buffer, length) == kTRUE)
515 //------------------------------------------------------------
517 AliTRDrawStreamTB::ResetCounters()
520 // reset some global counters
524 fStackLinkNumber = 0;
528 fSM.fActiveStacks = 0;
529 fSM.fNexpectedHalfChambers = 0;
531 fLinkTrackletCounter = 0;
533 fLastEventCounter = 0;
537 //------------------------------------------------------------
539 AliTRDrawStreamTB::ResetIterators()
542 // reset the data iterators used in the Next()
545 fStackLinkNumber = 0;
550 //------------------------------------------------------------
553 AliTRDrawStreamTB::Next()
556 // returns with true on next adc read
557 // returns false on errors and end of buffer
560 while (fStackNumber < 5 && fSM.fActiveStacks > 0)
562 if(fSM.fStackActive[fStackNumber] == kTRUE)
564 fStack = &fSM.fStacks[fStackNumber];
565 while (fStackLinkNumber < 12)
567 if (fStack->fLinksActive[fStackLinkNumber] == kTRUE)
569 fHC = &fStack->fHalfChambers[fStackLinkNumber];
572 AliError(Form("Super Strange. HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
575 //if (fgDebugFlag) AliDebug(2, DumpHCinfoH0(fHC));
576 if (fHC->fCorrupted == 0)
578 while (fhcMCMcounter < fHC->fMCMmax)
580 fMCM = &fHC->fMCMs[fhcMCMcounter];
581 //if (fgDebugFlag) AliDebug(2, DumpMCMinfo(fMCM));
584 AliError(Form("Super Strange. HC missing at stack %d link %d atMCMslot %d",
585 fStackNumber, fStackLinkNumber, fhcMCMcounter));
588 while(fmcmADCcounter < fMCM->fADCmax)
590 //printf("%d %d %d %d\n", fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter);
591 fADC = &fMCM->fADCs[fmcmADCcounter];
594 AliError(Form("Super Strange. ADC missing at stack %d link %d MCMslot %d ADCslot %d",
595 fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));
599 //printf("ADC count %d \n", fmcmADCcounter);
606 if (fADC->fIsShared == kFALSE)
610 //printf("MCM count %d \n", fhcMCMcounter);
612 // next MCM should go through all active ADCs
618 // next stack link (HC) should go through all active MCMs
623 // next stack should go through all links - start from 0
624 fStackLinkNumber = 0;
627 // in case rawreader manages the mem buffers
628 // lets go for the next buffer
631 Int_t nextBuff = NextBuffer();
632 while (nextBuff != -1)
636 nextBuff = NextBuffer();
643 //------------------------------------------------------------
646 AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager)
649 // Fills single chamber digit array
650 // Return value is the detector number
653 AliTRDdataArrayS *digits = 0;
654 AliTRDdataArrayI *track0 = 0;
655 AliTRDdataArrayI *track1 = 0;
656 AliTRDdataArrayI *track2 = 0;
657 AliTRDSignalIndex *indexes = 0;
659 // Loop through the digits
662 // Int_t returnDet = -1;
670 // If new detector found
680 if (det < 0 || det >= AliTRDgeometry::kNdet)
682 if (fSM.fClean == kTRUE)
684 AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));
688 AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));
693 // Add a container for the digits of this detector
694 digits = (AliTRDdataArrayS *) digitsManager->GetDigits(det);
695 track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0);
696 track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1);
697 track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2);
701 if (fSM.fClean == kTRUE)
703 AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));
707 AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));
713 Int_t rowMax = GetRowMax();
714 Int_t colMax = GetColMax();
715 Int_t ntbins = GetNumberOfTimeBins();
717 // Allocate memory space for the digits buffer
718 if (digits->GetNtime() == 0)
720 digits->Allocate(rowMax, colMax, ntbins);
721 track0->Allocate(rowMax, colMax, ntbins);
722 track1->Allocate(rowMax, colMax, ntbins);
723 track2->Allocate(rowMax, colMax, ntbins);
726 indexes = digitsManager->GetIndexes(det);
727 indexes->SetSM(GetSM());
728 indexes->SetStack(GetStack());
729 indexes->SetLayer(GetLayer());
730 indexes->SetDetNumber(det);
731 if (indexes->IsAllocated() == kFALSE)
732 indexes->Allocate(rowMax, colMax, ntbins);
735 // ntimebins data are ready to read
736 for (it = 0; it < GetNumberOfTimeBins(); it++)
738 if (GetSignals()[it] > 0)
740 digits->SetDataUnchecked(GetRow(), GetCol(), it, GetSignals()[it]);
742 indexes->AddIndexTBin(GetRow(), GetCol(), it);
743 track0->SetDataUnchecked(GetRow(), GetCol(), it, 0);
744 track1->SetDataUnchecked(GetRow(), GetCol(), it, 0);
745 track2->SetDataUnchecked(GetRow(), GetCol(), it, 0);
750 // what happens if the last HC is turned off?
755 //------------------------------------------------------------
757 AliTRDrawStreamTB::Init()
763 TDirectory *saveDir = gDirectory;
767 fGeometry = new AliTRDgeometry();
772 AliError("Geometry FAILED!");
776 fTRDfeeParam = AliTRDfeeParam::Instance();
779 AliError("AliTRDfeeParam FAILED!");
783 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
785 // common additive is moved to be static for temp solution
786 // common additive should be delivered in the HC word 2 (3rd word)
787 //fCommonAdditive = 10;
791 // in case rawreader manages the mem buffers
792 // lets go for the next buffer
795 Int_t nextBuff = NextBuffer();
796 while (nextBuff != -1)
800 nextBuff = NextBuffer();
804 if (fgDebugStreamFlag == kTRUE)
806 if (!fgDebugStreamer)
808 fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root");
809 fgStreamEventCounter = 0;
813 AliInfo(Form("Debug Streamer Initialized! Remember to delete! %s::DeleteDebugStream()", this->IsA()->GetName()));
814 //fDebugStreamOwned = kTRUE;
818 AliError("Unable to init debug stream");
828 void AliTRDrawStreamTB::DeleteDebugStream()
831 // static helper function
836 delete fgDebugStreamer;
842 //------------------------------------------------------------
844 AliTRDrawStreamTB::InitBuffer(void *buffer, UInt_t length)
847 // init the class before reading from the buffer
848 // and read SM heading info:
849 // -- super module header
850 // -- stack headers + link status words
853 // not in the pre scan mode
855 if(fgStreamEventCounter == 0) fgFirstEquipmentID = fRawReader->GetEquipmentId();
856 fEquipmentID = fRawReader->GetEquipmentId();
857 //fgStreamEventCounter++;
858 if(fEquipmentID == fgFirstEquipmentID) fgStreamEventCounter++;
863 fpBegin = (UInt_t *)buffer;
867 AliFatal("Strange! Size of UInt_t == 0");
871 fWordLength = length/WORD_SIZE;
872 fpEnd = fpBegin + fWordLength;
875 if (fpBegin == 0 || length <= 0)
877 AliError(Form("This will not work! Pointer to the buffer is 0x%08x of size %d", fpBegin, length));
885 AliInfo("------------------------------------------------");
886 if (DumpWords(fpBegin, fgDumpHead) == kFALSE)
888 AliError("Dump failed. Not enough data.");
890 AliInfo("------------------------------------------------");
894 DecodeSMInfo(fpPos, &fSM);
896 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
901 if (SkipWords(fSM.fHeaderSize) == kTRUE)
904 //for (Int_t istack = 0; istack < fSM.fActiveStacks; istack++)
905 for (Int_t istack = 0; istack < 5; istack++)
907 if (fSM.fStackActive[istack] == kFALSE)
910 fStack = &fSM.fStacks[istack];
911 DecodeStackInfo(fpPos, fStack);
914 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
916 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
918 if (SkipWords(fStack->fHeaderSize) == kFALSE)
920 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack head words missing");
932 if (fgWarnError) AliWarning("No Stack info present. Strange.");
933 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
937 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers : %d", fSM.fNexpectedHalfChambers));
942 if (fgDebugFlag) AliDebug(5, "Init OK.");
946 if (fgWarnError) AliWarning("No data just after init. Strange.");
947 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing data");
954 //------------------------------------------------------------
956 AliTRDrawStreamTB::DecodeSM(void *buffer, UInt_t length)
959 // decode all sm at once
960 // still here for devel and debug
963 //memset(&fSM, 0, sizeof(fSM));
968 if (InitBuffer(buffer, length) == kTRUE)
970 // no we are already set!
975 if (fgWarnError) AliError("--- INIT failed. ---------------");
982 for (Int_t istack = 0; istack < 5; istack++)
984 fStackNumber = istack;
985 if (fSM.fStackActive[istack] == kFALSE)
988 fStack = &fSM.fStacks[istack];
990 //fStack[istack].fActiveLinks // max is 12
991 for (Int_t ilink = 0; ilink < 12; ilink++)
993 fStackLinkNumber = ilink;
994 if (fStack->fLinksActive[ilink] == kFALSE)
999 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
1000 fSM.fClean = kFALSE;
1004 fHC = &fStack->fHalfChambers[ilink];
1006 if (fgDebugStreamer)
1008 TTreeSRedirector &cstream = *fgDebugStreamer;
1009 cstream << "LINKDataStream"
1010 << "Event=" << fgStreamEventCounter
1011 << ".equipID=" << fEquipmentID
1012 << ".stack=" << fStackNumber
1013 << ".link=" << fStackLinkNumber
1018 if (fSM.fTrackletEnable == kTRUE)
1020 if (DecodeTracklets() == kFALSE)
1022 // if (fgWarnError) AliError(Form("--- Decode Tracklets failed. --------------- Link %d of %d",
1023 // ilink + 1, fStack->fActiveLinks));
1024 if (fgDebugStreamer)
1026 TTreeSRedirector &cstream = *fgDebugStreamer;
1027 cstream << "TrackletDecodeError"
1028 << "Event=" << fgStreamEventCounter
1029 << ".Stack=" << fStackNumber
1030 << ".Link=" << fStackLinkNumber
1031 << ".EndOfTrackletCount=" << fEndOfTrackletCount
1035 fSM.fClean = kFALSE;
1040 AliError(Form("Failed stack %d link %d", fStackNumber, fStackLinkNumber));
1041 AliError(Form("Debug Event Counter : %d", fgStreamEventCounter));
1050 if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
1051 fSM.fClean = kFALSE;
1055 if (DecodeHC() == kFALSE)
1057 // if (fgWarnError) AliError(Form("--- Decode HC failed. --------------- Link %d of %d",
1058 // ilink + 1, fStack->fActiveLinks));
1059 fSM.fClean = kFALSE;
1060 //fHC->fCorrupted += 100;
1061 // mj -> need to look at
1062 if (fHC->fCorrupted < 8) SeekEndOfData(); // In case that we met END_OF_TRACKLET_MARKERNEW during DecodeADC() & DecodeMCMheader()
1063 // we don't seek ENDOFRAWDATAMARKER
1067 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
1068 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
1069 AliError(Form("Debug Event Counter : %d", fgStreamEventCounter));
1071 // let us assume that we have the HC data although link mask says different
1073 /* //we don't need to do
1074 if (fStackLinkNumber == -1)
1076 if (fgWarnError) AliWarning("Trying to recover to the right Link Mask.");
1086 // just finish off with the end of data markers
1090 //if (fgDebugFlag) AliDebug(5, Form("++++ Done with link %d of %d", ilink + 1, fStack->fActiveLinks));
1098 if (fSM.fClean == kTRUE)
1101 if (fgCleanDataOnly && (fSM.fClean == kFALSE))
1105 AliWarning("Buffer with errors. Returning FALSE.");
1106 AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
1108 fSM.fActiveStacks = 0; // Next will not give data
1115 //------------------------------------------------------------
1117 AliTRDrawStreamTB::DecodeSM()
1120 // decode SM data in case AliRawReader is in use
1124 Int_t nextBuff = NextBuffer();
1125 while (nextBuff != -1)
1129 nextBuff = NextBuffer();
1135 AliWarning("AliRawReader not set.");
1140 //------------------------------------------------------------
1142 AliTRDrawStreamTB::DecodeSM(AliRawReader *reader)
1145 // decode SM with the AliRawReader
1149 fRawReader = reader;
1154 AliWarning("Argument AliRawReader is 0.");
1159 //------------------------------------------------------------
1161 AliTRDrawStreamTB::SeekEndOfData()
1164 // go to end of data marker
1166 Int_t fEndOfDataCount = 0;
1168 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1173 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd )
1179 // if (fEndOfDataCount == 0)
1181 // if (fgWarnError) AliWarning("End of buffer reached first. No end of data marker?");
1188 //------------------------------------------------------------
1190 AliTRDrawStreamTB::SeekNextMCMheader()
1196 // move back to the mcm pos
1197 fpPos = fMCM->fPos + 1;
1199 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1201 //if (CheckMCMMask(fpPos) == 0)
1202 if (MCM_HEADER_MASK_ERR(*fpPos) == 0)
1204 if (fgWarnError) AliWarning(Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1214 //------------------------------------------------------------
1217 AliTRDrawStreamTB::DecodeTracklets()
1223 fLinkTrackletCounter = 0;
1224 fEndOfTrackletCount = 0;
1226 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
1227 //cout << Form("Decode tracklets..") << endl;;
1228 //printf("[I] Tracklet... ? \n");
1230 while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd )
1233 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
1235 //decode tracklets here...
1236 fLinkTrackletCounter++;
1238 if (fLinkTrackletCounter > MAX_TRACKLETS_PERHC)
1240 if (fgWarnError) AliWarning(Form("Max number of tracklets exceeded %d > %d. Something is wrong with the input data!",
1241 fLinkTrackletCounter, MAX_TRACKLETS_PERHC));
1243 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
1247 if (fgDebugStreamer)
1263 row = (val >> 20) & 0xF;
1264 defl = (val >> 13) & 0x7F;
1265 defl = defl << 25 >> 25;
1266 ypos = val & 0x1FFF;
1267 ypos = ypos << 19 >> 19;
1269 deflm = defl * 140.0e-6; /* m */
1270 yposm = ypos * 160.0e-6; /* m */
1272 TTreeSRedirector &cstream = *fgDebugStreamer;
1273 cstream << "MCMtracklets"
1274 << "Event=" << fgStreamEventCounter
1275 << ".stack=" << fStackNumber
1276 << ".link=" << fStackLinkNumber
1281 << ".deflm=" << deflm
1282 << ".yposm=" << yposm
1288 while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd )
1290 //seek non end of tracklets
1291 //printf("[I] End of tracklets. \n");
1292 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1294 fEndOfTrackletCount++;
1298 if ( fEndOfTrackletCount < 2 )
1300 //if (fgWarnError) AliWarning(Form("End of tracklet marker words missing %d", 2 - fEndOfTrackletCount));
1301 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1308 //------------------------------------------------------------
1310 AliTRDrawStreamTB::IsRowValid()
1313 if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||
1314 (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 )
1316 if (fgWarnError) AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1317 , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));
1318 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadrow, "Wrong Row");
1324 //------------------------------------------------------------
1326 AliTRDrawStreamTB::IsMCMheaderOK()
1329 // check the mcm header
1332 if ( fMCM->fCorrupted > 2 )
1334 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"ADC mask Corrupted");
1335 if (fgWarnError) AliWarning(Form("Wrong ADC Mask word 0x%08x %s. Error : %d", *fMCM->fPos, DumpMCMadcMask(fMCM), fMCM->fCorrupted));
1339 if ( fMCM->fCorrupted > 0 )
1341 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"Corrupted");
1342 if (fgWarnError) AliWarning(Form("Wrong MCM word 0x%08x %s. Error : %d", *fMCM->fPos, DumpMCMinfo(fMCM), fMCM->fCorrupted));
1346 if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 )
1348 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongMCMorROB,"Wrong ROB or MCM");
1349 if (fgWarnError) AliWarning(Form("Wrong fMCM or fROB. %s Skip this data.", DumpMCMinfo(fMCM)));
1353 if (IsRowValid() == kFALSE)
1358 //------------------------------------------------------------
1360 AliTRDrawStreamTB::DecodeMCMheader()
1363 // decode the mcm header
1366 DecodeMCMheader(fpPos, fMCM);
1368 fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
1370 if (fHC->fRawVMajor > 2)
1373 if ( fpPos < fpEnd )
1375 DecodeMask(fpPos, fMCM);
1376 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1377 fMCM->fAdcDataPos = fpPos + 1;
1381 if (fgWarnError) AliWarning("Expected ADC mask word. Fail due to buffer END.");
1382 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1388 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
1389 DecodeMask(&dummyMask, fMCM);
1390 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1391 fMCM->fAdcDataPos = fpPos + 1;
1396 AliDebug(6, DumpMCMinfo(fMCM));
1397 AliDebug(7, DumpMCMadcMask(fMCM));
1400 if (IsMCMheaderOK() == kFALSE)
1402 if (fMCM->fCorrupted >= 8)
1404 fpPos--; // to prevent DecodeTracklets() fault due to previous fpPos++
1405 fHC->fCorrupted += 8;
1410 if (fEventCounter == 0)
1412 fEventCounter = fMCM->fEvCounter;
1415 if (fEventCounter < fLastEventCounter)
1417 if (fgWarnError) AliWarning(Form("Weird. Event from the past? Current %d Last %d %s", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM)));
1418 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ? Past-Future");
1422 if (fEventCounter != fMCM->fEvCounter)
1424 if (fgWarnError) AliWarning(Form("Weird. Event missmatch? %d %s", fEventCounter, DumpMCMinfo(fMCM)));
1425 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ?");
1429 //fLastEventCounter = fEventCounter;
1430 //AliInfo(Form("Current MCM %s", DumpMCMinfo(fMCM)));
1433 //return IsMCMheaderOK();
1436 //------------------------------------------------------------
1438 AliTRDrawStreamTB::IsHCheaderOK()
1441 // check the half chamber header
1444 if (fHC->fCorrupted > 0)
1446 if (fgWarnError) AliWarning(Form("Wrong HC Header word. Word 0x%08x Error : %d", *fHC->fPos, fHC->fCorrupted));
1447 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "Corrupted");
1452 if (fHC->fStack < 0 || fHC->fStack > 4)
1454 if (fgWarnError) AliWarning(Form("Wrong Stack %d", fHC->fStack));
1455 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Wrong Stack");
1459 if (fgStackNumberChecker)
1461 if (fHC->fStack != fStackNumber)
1463 if (fgWarnError) AliWarning(Form("Missmatch: Stack in HC header %d HW-stack %d",
1464 fHC->fStack, fStackNumber));
1465 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Stack-HWstack");
1466 // Try this for recovery in DecodeSM(void*,UInt_t) after DecodeHC failed
1467 // buffer will still will be marked as NOT clean
1473 if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNplan)
1475 if (fgWarnError) AliWarning(Form("Wrong plane(layer) %d", fHC->fLayer));
1476 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Wrong Plane");
1480 if (fgStackLinkNumberChecker)
1483 if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1))
1485 if (fgWarnError) AliWarning(Form("Missmatch: plane(layer) in HCheader %d HW-Link %d | %s",
1486 fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));
1487 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Plane-Link missmatch");
1488 // Try this for recovery in DecodeSM(void*,UInt_t) after DecodeHC failed
1489 // buffer will still will be marked as NOT clean
1490 fStackLinkNumber = -1;
1495 if (fHC->fSide < 0 || fHC->fSide > 1)
1497 if (fgWarnError) AliWarning(Form("Wrong Side %d", fHC->fSide));
1498 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSide, "Wrong Side");
1503 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
1504 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet)
1506 if (fgWarnError) AliWarning(Form("Wrong detector %d", fHC->fDET));
1507 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1512 // this check fails - raw data inconsistent with geometry?
1513 if (fHC->fSM != fGeometry->GetSector(fHC->fDET)
1514 || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsect)
1516 if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1517 fHC->fSM, fGeometry->GetSector(fHC->fDET),
1518 fHC->fStack, fHC->fLayer, fHC->fDET));
1519 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1525 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
1528 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1532 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
1533 if (fHC->fRowMax < 1)
1535 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1539 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
1540 if (fHC->fColMax < 1)
1542 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1545 // extra - not needed
1546 // if (fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsect)
1548 // if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d",
1549 // fHC->fSM, fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack),
1550 // fHC->fStack, fHC->fLayer));
1557 //------------------------------------------------------------
1559 AliTRDrawStreamTB::DecodeHCheader()
1562 // decode the half chamber header
1565 DecodeHCwordH0(fpPos, fHC);
1567 if (fHC->fNExtraWords > 0)
1572 DecodeHCwordH1(fpPos, fHC);
1576 if (fgWarnError) AliWarning("Expected HC header word 1. Fail due to buffer END.");
1577 if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing");
1582 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1583 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1586 if (IsHCheaderOK() == kFALSE)
1594 //------------------------------------------------------------
1596 AliTRDrawStreamTB::DecodeHC()
1599 // decode the hc data
1600 // function for devel & debug
1603 if (DecodeHCheader() == kFALSE)
1605 if (fgDebugStreamer)
1607 TTreeSRedirector &cstream = *fgDebugStreamer;
1608 cstream << "HCDecodeError"
1609 << "Event=" << fgStreamEventCounter
1610 << ".stack=" << fStackNumber
1611 << ".link=" << fStackLinkNumber
1612 << ".hcCorrupted=" << fHC->fCorrupted
1613 << ".hcRVmajor=" << fHC->fRawVMajor
1614 << ".hcDCSboard=" << fHC->fDCSboard
1615 << ".hcSM=" << fHC->fSM
1616 << ".hcStack=" << fHC->fStack
1617 << ".hcLayer=" << fHC->fLayer
1618 << ".hcSide=" << fHC->fSide
1619 << ".hcTbins=" << fHC->fTimeBins
1620 << ".hcBunchCross=" << fHC->fBunchCrossCounter
1621 << ".hcPreTrig=" << fHC->fPreTriggerCounter
1622 << ".hcPreTrigPh=" << fHC->fPreTriggerPhase
1623 << ".hcDet=" << fHC->fDET
1624 << ".hcROC=" << fHC->fROC
1625 << ".hcRowMax=" << fHC->fRowMax
1626 << ".hcColMax=" << fHC->fColMax
1630 if (fgWarnError) AliWarning("Header decode failed.");
1638 if (fgWarnError) AliWarning("No MCM data? Not enough data in the buffer.");
1639 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing");
1645 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd)
1647 if (fHC->fMCMmax > TRD_MAX_MCM)
1649 if (fgWarnError) AliWarning("More mcm data than expected!");
1650 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!");
1654 fMCM = &fHC->fMCMs[fHC->fMCMmax];
1656 if (DecodeMCMheader() == kFALSE)
1658 if (fgDebugStreamer)
1660 TTreeSRedirector &cstream = *fgDebugStreamer;
1661 cstream << "MCMDecodeError"
1662 << "Event=" << fgStreamEventCounter
1663 << ".stack=" << fStackNumber
1664 << ".link=" << fStackLinkNumber
1665 << ".hcDCSboard=" << fHC->fDCSboard
1666 << ".hcSM=" << fHC->fSM
1667 << ".hcStack=" << fHC->fStack
1668 << ".hcLayer=" << fHC->fLayer
1669 << ".hcSide=" << fHC->fSide
1670 << ".hcBunchCross=" << fHC->fBunchCrossCounter
1671 << ".hcPreTrig=" << fHC->fPreTriggerCounter
1672 << ".hcPreTrigPh=" << fHC->fPreTriggerPhase
1673 << ".hcDet=" << fHC->fDET
1675 << ".mcmCorrupted=" << fMCM->fCorrupted
1676 << ".mcmROB=" << fMCM->fROB
1677 << ".mcmMCM=" << fMCM->fMCM
1678 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1679 << ".mcmEventCounter=" << fMCM->fEvCounter
1681 << ".fEventCounter=" << fEventCounter
1682 << ".fLastEventCounter=" << fLastEventCounter
1691 if (fMCM->fADCmax > 0)
1696 if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected."));
1697 if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing");
1700 // for (Int_t iadc = 0; iadc < TRD_MAX_ADC; iadc++)
1701 for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++)
1703 fADC = &fMCM->fADCs[iadc];
1704 fADC->fADCnumber = fMCM->fADCchannel[iadc];
1706 if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.",
1707 iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1709 if (fpPos + fMCM->fSingleADCwords >= fpEnd)
1711 if (fgDebugStreamer)
1713 TTreeSRedirector &cstream = *fgDebugStreamer;
1714 // means no data read
1716 cstream << "ADCDecodeError"
1717 << "Event=" << fgStreamEventCounter
1718 << ".hcSM=" << fHC->fSM
1719 << ".hcStack=" << fHC->fStack
1720 << ".hcLayer=" << fHC->fLayer
1721 << ".hcSide=" << fHC->fSide
1722 << ".hcDet=" << fHC->fDET
1723 << ".mcmROB=" << fMCM->fROB
1724 << ".mcmMCM=" << fMCM->fMCM
1725 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1726 << ".adcErr=" << ierr
1727 << ".adcNumber=" << ierr
1731 if (fgWarnError) AliWarning(Form("This is ADC %d of %d. ADC number is %d.", iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1732 if (fgWarnError) AliWarning("--> ADC (10 words) expected. Not enough data in the buffer.");
1733 if (fgWarnError) AliWarning(Form("--> ADC mask : %s", DumpMCMadcMask(fMCM)));
1735 if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing - less than expected");
1739 //DECODE the data here
1740 if (DecodeADC() == kFALSE)
1742 // check if we are out of the det when the pad is shared
1743 if (fADC->fIsShared && fADC->fCorrupted == 4)
1746 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1750 if (fgWarnError) AliWarning(Form("ADC decode failed."));
1751 //fpPos = fMCM->fPpos + fMCMADCWords;
1753 if (fgDebugStreamer)
1755 TTreeSRedirector &cstream = *fgDebugStreamer;
1756 cstream << "ADCDecodeError"
1757 << "Event=" << fgStreamEventCounter
1758 << ".hcSM=" << fHC->fSM
1759 << ".hcStack=" << fHC->fStack
1760 << ".hcLayer=" << fHC->fLayer
1761 << ".hcSide=" << fHC->fSide
1762 << ".hcDet=" << fHC->fDET
1763 << ".mcmROB=" << fMCM->fROB
1764 << ".mcmMCM=" << fMCM->fMCM
1765 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1766 << ".adcErr=" << fADC->fCorrupted
1767 << ".adcNumber=" << fADC->fADCnumber
1770 if (fADC->fCorrupted >= 8) fHC->fCorrupted += 8;
1771 else fpPos = fADC->fPos + fMCM->fSingleADCwords;
1776 //decode the ADC words here
1778 } //mcm data present
1787 if (fgWarnError) AliWarning("We are at the end of buffer. There should be one more word left.");
1795 //------------------------------------------------------------
1797 AliTRDrawStreamTB::DecodeADC()
1800 // decode single ADC channel
1803 fADC->fCorrupted = 0;
1804 fMaskADCword = ADC_WORD_MASK(*fpPos);
1807 if (*fpPos == END_OF_TRACKLET_MARKERNEW) // To read properly ZS data corrupted in this way
1809 if (fgWarnError) AliError(Form("There should be ADC data. We met END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1810 fADC->fCorrupted += 8;
1816 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
1817 fADC->fSignals[i] = 0;
1819 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
1821 if (fMaskADCword != ADC_WORD_MASK(*fpPos))
1823 //this is corrupted data
1824 fADC->fCorrupted += 1;
1825 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",
1826 iw - 1, *(fpPos-1), fMaskADCword, iw, *fpPos, ADC_WORD_MASK(*fpPos)));
1827 if (fRawReader) fRawReader->AddMajorErrorLog(kADCmaskMissmatch, "Mask change inside single channel");
1828 if (HC_HEADER_MASK_ERR(*fpPos) == 0)
1830 if (fgWarnError) AliError(Form("There should be ADC data. We met HC header 0x%08x",*fpPos));
1831 fADC->fCorrupted += 16; //if we meet half chamber header in adc expected place
1837 // here we subtract the baseline ( == common additive)
1838 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1839 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1840 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1846 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
1848 fADC->fIsShared = kTRUE;
1852 fADC->fIsShared = kFALSE;
1855 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
1857 // let us guess the Column
1858 // take the one before last ADC and shift by one column
1859 // later we check if we are inside the limits of the chamber
1860 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
1865 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1868 if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0)
1870 if (fADC->fIsShared == kFALSE)
1872 fADC->fCorrupted += 2;
1874 if (fgWarnError) AliWarning(Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1875 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1876 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadcolumn, "Wrong column");
1880 // flag it - we are out of the det when the pad is shared
1881 if (fgDebugFlag) AliDebug(10, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1882 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1883 fADC->fCorrupted += 4;
1887 if (fADC->fCorrupted > 0)
1896 //--------------------------------------------------------
1897 void AliTRDrawStreamTB::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
1900 // Decode the data *word into SM info structure
1903 sm->fPos = (UInt_t*)word;
1906 UInt_t vword = *word;
1907 sm->fHeaderSize = SM_HEADER_SIZE(vword);
1909 if (TRACKLETS_ENABLED(vword) > 0)
1910 sm->fTrackletEnable = kTRUE;
1912 sm->fTrackletEnable = kFALSE;
1914 UInt_t stackMask = STACK_MASK(vword);
1915 sm->fActiveStacks = 0;
1916 for (Int_t i = 0; i < 5; i++)
1918 //if ((stackMask >> i) & 0x1 > 0)
1919 if (IS_BIT_SET(stackMask,i) > 0)
1921 sm->fStackActive[i] = kTRUE;
1922 sm->fActiveStacks++;
1926 sm->fStackActive[i] = kFALSE;
1931 //--------------------------------------------------------
1932 const char *AliTRDrawStreamTB::DumpSMInfo(const struct AliTRDrawSM *sm)
1935 // Get SM structure into a const char
1938 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
1940 sm->fHeaderSize, sm->fTrackletEnable,
1941 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
1942 sm->fStackActive[3], sm->fStackActive[4]);
1945 //--------------------------------------------------------
1946 void AliTRDrawStreamTB::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
1949 // Decode stack info - active links
1952 st->fPos = (UInt_t*)word;
1955 UInt_t vword = *word;
1956 st->fHeaderSize = STACK_HEADER_SIZE(vword);
1958 UInt_t linkMask = STACK_LINK_WORD(vword);
1959 st->fActiveLinks = 0;
1960 for (Int_t i = 0; i < 12; i++)
1962 //if (linkMask & (0x1 << i) > 0)
1963 if (IS_BIT_SET(linkMask,i) > 0)
1965 st->fLinksActive[i] = kTRUE;
1966 st->fTrackletDecode[i] = kTRUE;
1967 st->fHCDecode[i] = kTRUE;
1972 st->fTrackletDecode[i] = kFALSE;
1973 st->fLinksActive[i] = kFALSE;
1974 st->fHCDecode[i] = kFALSE;
1979 //--------------------------------------------------------
1980 const char *AliTRDrawStreamTB::DumpStackInfo(const struct AliTRDrawStack *st)
1983 // format the string with the stack info
1985 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
1988 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
1989 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
1990 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
1993 //--------------------------------------------------------
1994 void AliTRDrawStreamTB::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
1997 // decode the hc header word 0
2001 UInt_t vword = *word;
2003 hc->fCorrupted = HC_HEADER_MASK_ERR(vword);
2004 if (hc->fCorrupted > 0)
2006 hc->fH0ErrorCounter++;
2009 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
2010 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
2011 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
2012 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
2013 hc->fDCSboard = HC_DCS_BOARD(vword);
2014 hc->fSM = HC_SM_NUMBER(vword);
2015 hc->fStack = HC_STACK_NUMBER(vword);
2016 hc->fLayer = HC_LAYER_NUMBER(vword);
2017 hc->fSide = HC_SIDE_NUMBER(vword);
2019 hc->fPos[0] = (UInt_t*)word;
2023 //--------------------------------------------------------
2024 void AliTRDrawStreamTB::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
2031 UInt_t vword = *word;
2033 hc->fCorrupted += 2 * HC_HEADER_MASK_ERR(vword);
2034 if (hc->fCorrupted >= 2)
2036 hc->fH1ErrorCounter++;
2039 hc->fTimeBins = HC_NTIMEBINS(vword);
2040 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
2041 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
2042 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
2044 hc->fPos[1] = (UInt_t*)word;
2047 //--------------------------------------------------------
2048 const char *AliTRDrawStreamTB::DumpHCinfoH0(const struct AliTRDrawHC *hc)
2054 return Form("Unable to dump. Null received as parameter!?!");
2056 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
2057 hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
2060 //--------------------------------------------------------
2061 const char *AliTRDrawStreamTB::DumpHCinfoH1(const struct AliTRDrawHC *hc)
2067 return Form("Unable to dump. Null received as parameter!?!");
2069 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
2070 hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
2073 //--------------------------------------------------------
2074 void AliTRDrawStreamTB::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2077 // decode the mcm header
2081 UInt_t vword = *word;
2083 mcm->fCorrupted = MCM_HEADER_MASK_ERR(vword);
2084 //printf("0x%08x %d\n", word, MCM_HEADER_MASK_ERR(vword));
2085 if (vword == END_OF_TRACKLET_MARKERNEW) // To read properly ZS data corrupted in this way
2087 if (fgWarnError) AliError(Form("There should be MCM header. We met END_OF_TRACKLET_MARKER 0x%08x",vword));
2088 mcm->fCorrupted += 8;
2090 if (mcm->fCorrupted)
2091 mcm->fErrorCounter++;
2092 mcm->fROB = MCM_ROB_NUMBER(vword);
2093 mcm->fMCM = MCM_MCM_NUMBER(vword);
2094 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
2096 mcm->fPos = (UInt_t*)word;
2099 //--------------------------------------------------------
2100 UInt_t AliTRDrawStreamTB::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2107 UInt_t vword = *word;
2112 mcm->fADCMaskWord = vword;
2113 //memset(mcm->fADCchannel, 0, sizeof(UInt_t) * 30);
2114 //if ((word & 0x0000000F) == 0x0000000C)
2115 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 )
2117 //mcm->fADCMask = (word >> 4) & skADCmaskBits;
2118 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
2122 mcm->fADCMask = 0xffffffff;
2123 mcm->fCorrupted += 2;
2124 mcm->fMaskErrorCounter++;
2127 return mcm->fADCMask;
2130 //--------------------------------------------------------
2131 void AliTRDrawStreamTB::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2134 // decode the adc mask - adcs to be read out
2137 mcm->fMCMADCWords = 0;
2138 mcm->fSingleADCwords = 0;
2140 mcm->fADCMask = GetMCMadcMask(word, mcm);
2141 if (mcm->fADCMask > 0)
2143 for (Int_t i = 0; i < TRD_MAX_ADC; i++)
2145 mcm->fADCchannel[mcm->fADCmax] = 0;
2146 if( IS_BIT_SET(mcm->fADCMask,i) )
2148 mcm->fADCchannel[mcm->fADCmax] = i;
2155 //--------------------------------------------------------
2156 void AliTRDrawStreamTB::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
2159 // count the expected mcm words for a given tbins
2161 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
2162 mcm->fSingleADCwords = 0;
2163 if (mcm->fADCmax > 0)
2165 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
2169 //--------------------------------------------------------
2170 const char *AliTRDrawStreamTB::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
2173 // mcm info in a string
2176 return Form("Unable to dump. Null received as parameter!?!");
2178 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
2181 //--------------------------------------------------------
2182 //TString DumpMCMadcMask(const struct AliTRDrawMCMInfo *mcm)
2183 const char *AliTRDrawStreamTB::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
2186 // mcm adc mask in a string
2189 return Form("Unable to dump. Null received as parameter!?!");
2191 TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
2192 for (Int_t i = 0; i < 21; i++)
2194 tsreturn += Form("%d ", mcm->fADCchannel[i]);
2197 return tsreturn.Data();