1 #/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // This class provides access to TRD digits in raw data. //
22 // It loops over all TRD digits in the raw data given by the AliRawReader. //
23 // The Next method goes to the next digit. If there are no digits left //
24 // it returns kFALSE. //
25 // Several getters provide information about the current digit. //
27 // Author: M. Ploskon (ploskon@ikf.uni-frankfurt.de) //
29 ///////////////////////////////////////////////////////////////////////////////
33 #include "TTreeStream.h"
35 #include "AliTRDrawStreamTB.h"
36 #include "AliTRDgeometry.h"
37 #include "AliTRDfeeParam.h"
38 #include "AliTRDdigitsManager.h"
39 #include "AliTRDdataArrayS.h"
40 #include "AliTRDdataArrayI.h"
41 #include "AliTRDdataArrayDigits.h"
42 #include "AliTRDSignalIndex.h"
43 #include "AliTRDrecoParam.h"
44 #include "AliTRDcalibDB.h"
45 #include "Cal/AliTRDCalPadStatus.h"
47 //[mj tracklet writing] #include "AliTRDrawTracklet.h"
50 #include "AliRawReader.h"
52 #define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa
53 #define END_OF_TRACKLET_MARKERNEW 0x10001000
54 #define ENDOFRAWDATAMARKER 0x00000000
55 #define WORD_SIZE sizeof(UInt_t) // size of a word in bytes
56 #define EXTRA_LEAD_WORDS 24
59 #define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w
60 #define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m
62 // SM index word masks:
63 #define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
64 #define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)
65 #define STACK_MASK(w) ((w) & 0x1f)
68 #define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
69 #define STACK_LINK_WORD(w) ((w) & 0xfff)
70 #define LINK0_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,4) == (0x0) ? 0 : 1) // 0 if physics data
71 #define LINK1_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,20) == (0x0) ? 0 : 1) // 0 if physics data
72 #define LINK0_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,0) == (0x0) ? 0 : 1) // 0 if OK
73 #define LINK1_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,16) == (0x0) ? 0 : 1) // 0 if OK
76 //#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!!
77 #define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK!!!
80 #define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)
81 #define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)
82 #define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24)
83 #define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)
84 #define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)
85 #define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)
86 #define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)
87 #define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)
88 #define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)
89 #define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)
92 #define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)
93 #define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)
94 #define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)
95 #define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,6)
97 // MCM word and ADC mask
98 #define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
99 #define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
100 #define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)
101 #define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)
102 #define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)
103 #define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)
104 #define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25)
106 #define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated
107 #define ADCDATA_VAL1 0x2 // updated
108 #define ADCDATA_VAL2 0x3 // updated
110 //--------------------------------------------------------
111 #define ADC_WORD_MASK(w) ((w) & 0x3)
112 //--------------------------------------------------------
115 ClassImp(AliTRDrawStreamTB)
117 Bool_t AliTRDrawStreamTB::fgExtraSkip = kFALSE;
118 Bool_t AliTRDrawStreamTB::fgSkipCDH = kFALSE;
119 Bool_t AliTRDrawStreamTB::fgWarnError = kTRUE;
120 Bool_t AliTRDrawStreamTB::fgCleanDataOnly = kFALSE;
121 Bool_t AliTRDrawStreamTB::fgDebugFlag = kTRUE;
122 Bool_t AliTRDrawStreamTB::fgStackNumberChecker = kTRUE;
123 Bool_t AliTRDrawStreamTB::fgStackLinkNumberChecker = kTRUE;
124 Bool_t AliTRDrawStreamTB::fgSkipData = kTRUE;
125 UInt_t AliTRDrawStreamTB::fgStreamEventCounter = 0;
126 UInt_t AliTRDrawStreamTB::fgFirstEquipmentID = 0;
127 UInt_t AliTRDrawStreamTB::fgDumpHead = 0;
128 Int_t AliTRDrawStreamTB::fgCommonAdditive = 0;
129 Int_t AliTRDrawStreamTB::fgEmptySignals[] =
131 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
132 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
135 AliTRDrawStreamTB::AliTRDrawStreamTB()
136 : AliTRDrawStreamBase()
148 , fStackLinkNumber(-1)
151 , fLinkTrackletCounter(-1)
152 , fEndOfTrackletCount(-1)
157 , fLastEventCounter(0)
158 , fSharedPadsOn(kFALSE)
166 // default constructor
169 if (Init() == kFALSE)
171 AliWarning("Unable to Init.");
175 //--------------------------------------------------------
176 AliTRDrawStreamTB::AliTRDrawStreamTB(AliRawReader *rawReader)
177 : AliTRDrawStreamBase(rawReader)
189 , fStackLinkNumber(-1)
192 , fLinkTrackletCounter(-1)
193 , fEndOfTrackletCount(-1)
198 , fLastEventCounter(0)
199 , fSharedPadsOn(kFALSE)
203 , fRawReader(rawReader)
207 // default constructor
211 if (Init() == kFALSE)
213 AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
218 AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
222 //------------------------------------------------------------
224 AliTRDrawStreamTB::AliTRDrawStreamTB(const AliTRDrawStreamTB& /*st*/)
225 : AliTRDrawStreamBase()
237 , fStackLinkNumber(-1)
240 , fLinkTrackletCounter(-1)
241 , fEndOfTrackletCount(-1)
246 , fLastEventCounter(0)
247 , fSharedPadsOn(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()
280 //------------------------------------------------------------
283 AliTRDrawStreamTB::operator=(const AliTRDrawStreamTB &)
286 // we are not using this functionality
288 AliFatal("May not use.");
292 //___________________________________________________________
294 AliTRDrawStreamTB::SwapOnEndian()
297 // Check the endian and swap if needed
300 char* ptemp = (char*) &itemp;
303 if (fgDebugFlag) AliDebug(8, "Swapping.");
307 while (fpPos < fpEnd)
310 iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
311 ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
312 // here we override the value in the buffer!
319 //------------------------------------------------------------
321 AliTRDrawStreamTB::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
324 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
325 for (UInt_t i = 0; i < iw; i++)
327 if (px + iw >= fpEnd)
332 if (marker != 0 && marker == px[i])
333 tsreturn += Form(" *>0x%08x<* ", px[i]);
335 tsreturn += Form("0x%08x ", px[i]);
339 AliInfo(tsreturn.Data());
344 //------------------------------------------------------------
346 AliTRDrawStreamTB::SkipWords(UInt_t iw)
349 // Skip words corresponding to iw
351 if ( fpPos + iw < fpEnd )
358 if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
365 //------------------------------------------------------------
367 AliTRDrawStreamTB::SetReader(AliRawReader *reader)
379 AliWarning("Unable to setup reader.");
385 AliWarning("AliRawReader argument is 0.");
392 //------------------------------------------------------------
394 AliTRDrawStreamTB::NextBuffer()
397 // return -1 if no more buffers available
398 // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come
399 // return 1 DecodeSM OK
406 Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
407 if (kBufferSet == kTRUE)
409 if (fgDebugFlag) AliDebug(9, "Buffer is set.");
410 length = fRawReader->GetDataSize();
411 if (fgExtraSkip == kTRUE)
413 buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
414 length -= EXTRA_LEAD_WORDS * WORD_SIZE;
417 if (fgSkipCDH == kTRUE)
419 buffer += CDH_WORDS * WORD_SIZE;
420 length -= CDH_WORDS * WORD_SIZE;
425 if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
426 if (DecodeSM((void*)buffer, length) == kTRUE)
441 //------------------------------------------------------------
443 AliTRDrawStreamTB::ResetCounters()
446 // reset some global counters
448 fBufferRead = kFALSE; // important to read buffer
452 fStackLinkNumber = 0;
455 fSM.fActiveStacks = 0;
456 fSM.fNexpectedHalfChambers = 0;
458 fLinkTrackletCounter = 0;
459 fLastEventCounter = 0;
463 //------------------------------------------------------------
465 AliTRDrawStreamTB::ResetIterators()
468 // reset data which should be reset every sm
470 fStackNumber = 0; // reset for Next() function
471 fStackLinkNumber = 0; // reset for Next() function
476 //------------------------------------------------------------
478 AliTRDrawStreamTB::ResetPerHC()
486 //------------------------------------------------------------
489 AliTRDrawStreamTB::Next()
492 // returns with true on next adc read
493 // returns false on errors and end of buffer
498 while (fStackNumber < 5 && fSM.fActiveStacks > 0)
500 if(fSM.fStackActive[fStackNumber] == kTRUE)
502 fStack = &fSM.fStacks[fStackNumber];
503 while (fStackLinkNumber < 12)
505 if (fStack->fLinksActive[fStackLinkNumber] == kTRUE)
507 fHC = &fStack->fHalfChambers[fStackLinkNumber];
510 AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
513 if (fHC->fCorrupted == 0)
515 while (fhcMCMcounter < fHC->fMCMmax)
517 fMCM = &fHC->fMCMs[fhcMCMcounter];
520 AliError(Form("HC missing at stack %d link %d atMCMslot %d",
521 fStackNumber, fStackLinkNumber, fhcMCMcounter));
524 while(fmcmADCcounter < fMCM->fADCmax)
526 fADC = &fMCM->fADCs[fmcmADCcounter];
529 AliError(Form("ADC missing at stack %d link %d MCMslot %d ADCslot %d",
530 fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));
540 if (fADC->fIsShared == kFALSE)
545 // next MCM should go through all active ADCs
551 // next stack link (HC) should go through all active MCMs
556 // next stack should go through all links - start from 0
557 fStackLinkNumber = 0;
561 // in case rawreader manages the mem buffers, go for the next buffer
564 Int_t nextBuff = NextBuffer();
565 while (nextBuff != -1)
572 nextBuff = NextBuffer();
579 //------------------------------------------------------------
581 AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager)
582 //[mj tracklet writing] AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager, TObjArray *trackletContainer)
585 // Fills single chamber digit array
586 // Return value is the detector number
589 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
590 AliTRDdataArrayDigits *digits = 0;
591 AliTRDdataArrayI *track0 = 0;
592 AliTRDdataArrayI *track1 = 0;
593 AliTRDdataArrayI *track2 = 0;
594 AliTRDSignalIndex *indexes = 0;
596 // Get the ADC baseline
597 Int_t adcBaseline = 0;
598 // if (!AliTRDReconstructor::RecoParam())
600 // AliError("RecoParam does not exist\n");
605 // adcBaseline = ((Int_t) AliTRDReconstructor::RecoParam()->GetADCbaseline());
608 static AliTRDrecoParam * par = AliTRDrecoParam::GetLowFluxParam();
609 adcBaseline = par->GetADCbaseline();
610 // Loop through the digits
613 // Int_t returnDet = -1;
614 //[mj tracklet writing] Int_t lastside = -1;
615 //[mj tracklet writing] Int_t side = -1;
620 //[mj tracklet writing]
623 if (trackletContainer)
625 if ((det + side*AliTRDgeometry::kNdet) != (lastdet + lastside*AliTRDgeometry::kNdet))
635 UInt_t *trackletwords = GetTrackletWords();
636 AliTRDrawTracklet *tracklets = new AliTRDrawTracklet();
637 tracklets->SetDet(det);
638 tracklets->SetSide(side);
640 tracklets->SetTracklets(trackletwords);
641 trackletContainer->Add(tracklets);
648 // If new detector found
658 if (det < 0 || det >= AliTRDgeometry::kNdet)
660 if (fSM.fClean == kTRUE)
662 AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));
666 AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));
671 // Add a container for the digits of this detector
672 digits = (AliTRDdataArrayDigits *) digitsManager->GetDigits(det);
674 if (digitsManager->UsesDictionaries())
676 track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0);
677 track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1);
678 track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2);
683 if (fSM.fClean == kTRUE)
685 AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));
689 AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));
694 Int_t rowMax = GetRowMax();
695 Int_t colMax = GetColMax();
696 Int_t ntbins = GetNumberOfTimeBins();
698 // Allocate memory space for the digits buffer
699 if (digits->GetNtime() == 0)
701 digits->Allocate(rowMax, colMax, ntbins);
702 if (digitsManager->UsesDictionaries())
704 track0->Allocate(rowMax, colMax, ntbins);
705 track1->Allocate(rowMax, colMax, ntbins);
706 track2->Allocate(rowMax, colMax, ntbins);
710 indexes = digitsManager->GetIndexes(det);
711 indexes->SetSM(GetSM());
712 indexes->SetStack(GetStack());
713 indexes->SetLayer(GetLayer());
714 indexes->SetDetNumber(det);
715 if (indexes->IsAllocated() == kFALSE)
716 indexes->Allocate(rowMax, colMax, ntbins);
719 Char_t padStatus = cal->GetPadStatus(det, GetCol(), GetRow());
721 // ntimebins data are ready to read
722 for (it = 0; it < GetNumberOfTimeBins(); it++)
724 if ((GetSignals()[it] - adcBaseline) > 0)
726 digits->SetDataUnchecked(GetRow(), GetCol(), it, GetSignals()[it] - adcBaseline);
728 digits->SetPadStatus(GetRow(), GetCol(), it, padStatus);
730 indexes->AddIndexTBin(GetRow(), GetCol(), it);
731 if (digitsManager->UsesDictionaries())
733 track0->SetDataUnchecked(GetRow(), GetCol(), it, 0);
734 track1->SetDataUnchecked(GetRow(), GetCol(), it, 0);
735 track2->SetDataUnchecked(GetRow(), GetCol(), it, 0);
744 //------------------------------------------------------------
746 AliTRDrawStreamTB::Init()
749 // Initialize geometry and fee parameters
752 TDirectory *saveDir = gDirectory;
756 fGeometry = new AliTRDgeometry();
761 AliError("Geometry FAILED!");
765 fTRDfeeParam = AliTRDfeeParam::Instance();
768 AliError("AliTRDfeeParam FAILED!");
772 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
774 ResetCounters(); // fBufferRead is set to kFALSE - important
777 // in case rawreader manages the mem buffers
778 // lets go for the next buffer
781 Int_t nextBuff = NextBuffer();
782 while (nextBuff != -1)
786 nextBuff = NextBuffer();
795 //------------------------------------------------------------
797 AliTRDrawStreamTB::InitBuffer(void *buffer, UInt_t length)
800 // set initial information about the buffer
803 if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));
805 if(fgStreamEventCounter == 0) fgFirstEquipmentID = fRawReader->GetEquipmentId();
806 fEquipmentID = fRawReader->GetEquipmentId();
807 if(fEquipmentID == fgFirstEquipmentID) fgStreamEventCounter++; // [mj] risky if the order of sm in data changed
808 // since it is still for debug event counter, doesn't give an effect on decoded data
811 fpBegin = (UInt_t *)buffer;
815 AliFatal("Strange word size. size of UInt_t == 0");
819 fWordLength = length/WORD_SIZE;
820 fpEnd = fpBegin + fWordLength;
823 if (fpBegin == 0 || length <= 0)
825 AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%08x of size %d", fpBegin, length));
833 AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));
834 if (DumpWords(fpBegin, fgDumpHead) == kFALSE)
836 AliError("Dump failed. Not enough data.");
838 AliInfo(Form("---------- Dumping ended ----------------------------------------------"));
844 //------------------------------------------------------------
846 AliTRDrawStreamTB::DecodeGTUheader()
848 // Decode Supermodule Index Word
849 DecodeSMInfo(fpPos, &fSM);
851 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
856 // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design.
857 // For the moment, we skip decoding these words
858 if (SkipWords(fSM.fHeaderSize) == kTRUE)
860 for (Int_t istack = 0; istack < 5; istack++)
862 if (fSM.fStackActive[istack] == kFALSE)
865 fStack = &fSM.fStacks[istack];
867 // Decode Stack Index Word of given stack
868 DecodeStackInfo(fpPos, fStack);
871 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
873 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
875 if (SkipWords(fStack->fHeaderSize-6) == kFALSE) // 6 is the 6 stack header words for 12 links
877 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing");
880 for (Int_t iword=0; iword<6; iword++) // decode 6 stack header words
882 // Decode Stack Header Word of given stack
883 DecodeStackHeader(fpPos, fStack, iword);
895 if (fgWarnError) AliWarning("No additional sm headers and stack index words present.");
896 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
902 if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");
906 if (fgWarnError) AliWarning("No data just after GTU headers.");
907 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");
911 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));
916 //------------------------------------------------------------
918 AliTRDrawStreamTB::DecodeSM(void *buffer, UInt_t length)
921 // decode one sm data in buffer
927 if (InitBuffer(buffer, length) == kFALSE)
929 if (fgWarnError) AliError("InitBuffer failed.");
934 if (DecodeGTUheader()== kFALSE)
937 for (Int_t istack = 0; istack < 5; istack++)
939 fStackNumber = istack;
940 if (fSM.fStackActive[istack] == kFALSE)
943 fStack = &fSM.fStacks[istack];
945 for (Int_t ilink = 0; ilink < 12; ilink++)
947 fStackLinkNumber = ilink;
948 if (fStack->fLinksActive[ilink] == kFALSE)
951 // check GTU link monitor
952 if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0))
954 fStack->fLinkMonitorError[ilink] = 1;
955 SeekEndOfData(); // skip this HC data if GTU link monitor report error
961 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
966 fHC = &fStack->fHalfChambers[ilink];
969 if (fSM.fTrackletEnable == kTRUE)
971 if (DecodeTracklets() == kFALSE)
979 AliError(Form("Failed stack %d link %d", fStackNumber, fStackLinkNumber));
980 AliError(Form("Debug Event Counter : %d", fgStreamEventCounter));
988 if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
993 if (DecodeHC() == kFALSE)
996 if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW
997 // during ADC data decoding or MCM header decoding
998 // we don't seek ENDOFRAWDATAMARKER
1002 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
1003 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
1004 AliError(Form("Debug Event Counter : %d\n\n\n", fgStreamEventCounter));
1011 SeekEndOfData(); // make sure that finish off with the end of data markers
1017 ResetIterators(); // need to do it again for Next() function
1019 if (fSM.fClean == kTRUE)
1022 if (fgCleanDataOnly && (fSM.fClean == kFALSE))
1026 AliWarning("Buffer with errors. Returning FALSE.");
1027 AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
1029 fSM.fActiveStacks = 0; // Next() will not give data
1036 //------------------------------------------------------------
1038 AliTRDrawStreamTB::DecodeSM()
1041 // decode SM data in case AliRawReader is in use
1045 Int_t nextBuff = NextBuffer();
1046 while (nextBuff != -1)
1050 nextBuff = NextBuffer();
1056 AliWarning("AliRawReader not set.");
1061 //------------------------------------------------------------
1063 AliTRDrawStreamTB::DecodeSM(AliRawReader *reader)
1066 // decode SM with the AliRawReader
1070 fRawReader = reader;
1075 AliWarning("Argument AliRawReader is 0.");
1080 //------------------------------------------------------------
1082 AliTRDrawStreamTB::SeekEndOfData()
1085 // go to end of data marker
1087 Int_t fEndOfDataCount = 0;
1089 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1094 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd )
1103 //------------------------------------------------------------
1105 AliTRDrawStreamTB::SkipMCMdata(UInt_t iw)
1108 if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw));
1109 UInt_t iwcounter = 0;
1110 while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw)
1112 if ( *fpPos == END_OF_TRACKLET_MARKERNEW)
1114 if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW");
1115 fMCM->fCorrupted += 16;
1116 fHC->fCorrupted += 16;
1123 if (iwcounter == iw)
1129 if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");
1133 //------------------------------------------------------------
1135 AliTRDrawStreamTB::SeekNextMCMheader()
1143 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1145 if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0)
1147 if (fgDebugFlag) AliDebug(11,Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1150 if ( *fpPos == END_OF_TRACKLET_MARKERNEW)
1152 fMCM->fCorrupted += 16;
1153 fHC->fCorrupted += 16;
1163 //------------------------------------------------------------
1166 AliTRDrawStreamTB::DecodeTracklets()
1172 fLinkTrackletCounter = 0;
1173 fEndOfTrackletCount = 0;
1175 //[mj tracklet writing] for (Int_t i = 0; i < MAX_TRACKLETS_PERHC; i++)
1176 //[mj tracklet writing] fHC->fTrackletWords[i] = 0;
1178 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
1180 while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd )
1182 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
1184 fLinkTrackletCounter++;
1186 if (fLinkTrackletCounter > MAX_TRACKLETS_PERHC)
1188 if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d.",
1189 fLinkTrackletCounter, MAX_TRACKLETS_PERHC));
1190 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
1191 fHC->fTrackletError = 1;
1195 //[mj tracklet writing] fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into array
1199 while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd )
1201 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1203 fEndOfTrackletCount++;
1207 if ( fEndOfTrackletCount < 2 )
1209 if (fgDebugFlag) AliDebug(11,"End of tracklets word missing");
1210 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1211 fHC->fTrackletError += 2;
1218 //------------------------------------------------------------
1220 AliTRDrawStreamTB::IsRowValid()
1222 if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||
1223 (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 )
1225 if (fgDebugFlag) AliDebug(11,Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1226 , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));
1232 //------------------------------------------------------------
1234 AliTRDrawStreamTB::IsMCMheaderOK()
1237 // check the mcm header
1240 int expectedROB = -1;
1241 if(!fHC->fSide) expectedROB = int(fHC->fMCMmax/16)*2;
1242 else expectedROB = int(fHC->fMCMmax/16)*2 + 1;
1243 int expectedMCM = 4*(3-int((fHC->fMCMmax%16)/4)) + fHC->fMCMmax%4;
1245 if ( expectedROB != fMCM->fROB || expectedMCM != fMCM->fMCM)
1247 fMCM->fMCMhdCorrupted += 2;
1248 AliDebug(11,Form("ROB expected %d ROB read %d, MCM expected %d MCM read %d\n",expectedROB, fMCM->fROB, expectedMCM, fMCM->fMCM));
1251 // below two conditions are redundant
1253 if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 )
1255 fMCM->fMCMhdCorrupted += 8; // need to assign new number
1256 if (fgDebugFlag) AliDebug(11,Form("ROB or MCM number is out of range. %s\n", DumpMCMinfo(fMCM)));
1258 if (IsRowValid() == kFALSE)
1260 fMCM->fMCMhdCorrupted += 16; // need to assign new number
1264 if (fEventCounter == 0)
1266 fEventCounter = fMCM->fEvCounter;
1269 if (fEventCounter != fMCM->fEvCounter)
1271 fMCM->fMCMhdCorrupted += 4; if (fgDebugFlag) AliDebug(11,Form("Event number(%d) of current MCM is different from that(%d) of reference MCM %s.\n", fMCM->fEvCounter, fEventCounter, DumpMCMinfo(fMCM)));
1274 if (fEventCounter < fLastEventCounter)
1276 fMCM->fMCMhdCorrupted += 8; if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM)));
1279 if ( fMCM->fADCmaskCorrupted > 0 )
1282 if ( fMCM->fMCMhdCorrupted > 0 )
1288 //------------------------------------------------------------
1290 AliTRDrawStreamTB::DecodeMCMheader()
1293 // decode the mcm header
1296 DecodeMCMheader(fpPos, fMCM);
1297 if (fHC->fCorrupted >= 16)
1303 fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
1305 if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || (fHC->fRawVMajor > 31 && fHC->fRawVMajor < 64)) //cover old and new version definition of ZS data
1308 if ( fpPos < fpEnd )
1310 DecodeMask(fpPos, fMCM);
1311 if (fHC->fCorrupted >= 16)
1316 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1317 fMCM->fAdcDataPos = fpPos + 1;
1321 if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END.");
1322 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1323 fHC->fCorrupted += 32;
1329 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
1330 DecodeMask(&dummyMask, fMCM);
1331 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1332 fMCM->fAdcDataPos = fpPos + 1;
1337 AliDebug(6, DumpMCMinfo(fMCM));
1338 AliDebug(7, DumpMCMadcMask(fMCM));
1341 if (IsMCMheaderOK() == kFALSE)
1347 //------------------------------------------------------------
1349 AliTRDrawStreamTB::IsHCheaderOK()
1352 // check insanity of half chamber header
1355 if (fHC->fStack < 0 || fHC->fStack > 4)
1357 if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStack));
1361 if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNlayer)
1363 if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayer));
1367 if (fHC->fSide < 0 || fHC->fSide > 1)
1369 if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSide));
1373 if (fgStackNumberChecker)
1375 if (fHC->fStack != fStackNumber)
1377 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d",
1378 fHC->fStack, fStackNumber));
1384 if (fgStackLinkNumberChecker)
1386 //if (fHC->fLayer * 2 + fHC->fSide != fStackLinkNumber)
1387 // let it make flexible to consider known fiber swapping
1388 if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1))
1390 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s",
1391 fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));
1392 fStackLinkNumber = -1;
1397 // SLOW GEOM : consistancy check with geometry
1398 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
1399 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet)
1401 if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET));
1402 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1406 if (fHC->fSM != fGeometry->GetSector(fHC->fDET)
1407 || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector)
1409 if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1410 fHC->fSM, fGeometry->GetSector(fHC->fDET),
1411 fHC->fStack, fHC->fLayer, fHC->fDET));
1412 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1416 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
1419 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1423 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
1424 if (fHC->fRowMax < 1)
1426 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1430 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
1431 if (fHC->fColMax < 1)
1433 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1440 //------------------------------------------------------------
1442 AliTRDrawStreamTB::DecodeHCheader()
1445 // decode the half chamber header
1448 if (DecodeHCwordH0(fpPos, fHC) == kFALSE)
1451 if (fHC->fNExtraWords > 0)
1456 if (DecodeHCwordH1(fpPos, fHC) == kFALSE)
1461 if (fgDebugFlag) AliDebug(11,"Expected HC header word 1. Fail due to buffer END.");
1462 if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing");
1467 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1468 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1471 if (IsHCheaderOK() == kFALSE)
1473 fHC->fH0Corrupted += 2;
1474 if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));
1481 //------------------------------------------------------------
1483 AliTRDrawStreamTB::DecodeHC()
1486 // decode hc header and data
1489 if (DecodeHCheader() == kFALSE)
1491 if (fgWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));
1492 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "HC header corrupted");
1500 fHC->fCorrupted += 1;
1501 if (fgDebugFlag) AliDebug(11,"No MCM data? Not enough data in the buffer.");
1502 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing");
1508 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd)
1510 if (fHC->fMCMmax > TRD_MAX_MCM)
1512 fHC->fCorrupted += 2;
1513 if (fgDebugFlag) AliDebug(11,"More mcm data than expected!");
1514 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!");
1518 fMCM = &fHC->fMCMs[fHC->fMCMmax];
1520 if (DecodeMCMheader() == kFALSE)
1522 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1524 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1525 return kFALSE; // stop HC data reading
1527 fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number
1529 // in case we decide to keep reading data, skip this mcm data and find next mcm header
1530 if (fMCM->fADCmaskCorrupted < 2)
1532 if (SkipMCMdata(fMCM->fADCcount*fMCM->fSingleADCwords) == kFALSE)
1538 if (SeekNextMCMheader() == kFALSE)
1546 if (fMCM->fADCmax > 0)
1551 fMCM->fCorrupted += 1;
1552 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1553 if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected."));
1557 for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++)
1559 fADC = &fMCM->fADCs[iadc];
1560 fADC->fADCnumber = fMCM->fADCchannel[iadc];
1562 if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.",
1563 iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1565 if (fpPos + fMCM->fSingleADCwords >= fpEnd)
1568 fMCM->fCorrupted += 2;
1569 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1570 if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");
1574 if (fHC->fRawVMajor < 64) // normal(real) ADC data
1576 if (DecodeADC() == kFALSE)
1578 if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4
1579 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1580 if (fADC->fIsShared && fADC->fCorrupted == 16) // check if we are out of the det when the pad is shared
1583 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1587 if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));
1588 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1589 return kFALSE; // stop HC data reading
1593 else // test pattern data
1595 if (fgWarnError) AliError("These are test pattern data. You need other reader"); // will be served in other class
1607 if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. There should be one more word left.");
1613 //------------------------------------------------------------
1616 AliTRDrawStreamTB::DecodeADC()
1619 // decode single ADC channel
1622 fADC->fCorrupted = 0;
1623 if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
1624 if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
1629 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
1630 fADC->fSignals[i] = 0;
1632 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
1634 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW)
1636 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1637 fADC->fCorrupted += 16;
1638 fHC->fCorrupted += 16;
1643 if (fMaskADCword != ADC_WORD_MASK(*fpPos))
1645 fADC->fCorrupted += 1;
1646 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x Current mask: 0x%08x] MCM= %s Error : %d",
1647 fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));
1652 // here we subtract the baseline ( == common additive)
1653 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1654 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1655 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1661 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
1663 fADC->fIsShared = kTRUE;
1667 fADC->fIsShared = kFALSE;
1670 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
1672 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
1677 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1680 if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0)
1682 if (fADC->fIsShared == kFALSE)
1684 fADC->fCorrupted += 32;
1685 if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1686 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1690 // we are out of the det when the pad is shared
1691 if (fgDebugFlag) AliDebug(11, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1692 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1693 fADC->fCorrupted += 32;
1697 if (fADC->fCorrupted > 0)
1706 //--------------------------------------------------------
1709 void AliTRDrawStreamTB::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
1712 // Decode Supermodule Index Word
1713 // The Supermodule Index Word is a 32-Bit word wit following structure
1714 // ssssssss ssssssss vvvv rrrr r d t mmmm
1715 // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use
1716 // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask
1718 sm->fPos = (UInt_t*)word;
1720 UInt_t vword = *word;
1721 sm->fHeaderSize = SM_HEADER_SIZE(vword);
1723 if (TRACKLETS_ENABLED(vword) > 0)
1724 sm->fTrackletEnable = kTRUE;
1726 sm->fTrackletEnable = kFALSE;
1728 UInt_t stackMask = STACK_MASK(vword);
1729 sm->fActiveStacks = 0;
1730 for (Int_t i = 0; i < 5; i++)
1732 if (IS_BIT_SET(stackMask,i) > 0)
1734 sm->fStackActive[i] = kTRUE;
1735 sm->fActiveStacks++;
1739 sm->fStackActive[i] = kFALSE;
1744 //--------------------------------------------------------
1745 const char *AliTRDrawStreamTB::DumpSMInfo(const struct AliTRDrawSM *sm)
1748 // Get SM structure into a const char
1750 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
1752 sm->fHeaderSize, sm->fTrackletEnable,
1753 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
1754 sm->fStackActive[3], sm->fStackActive[4]);
1757 //--------------------------------------------------------
1758 void AliTRDrawStreamTB::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
1761 // Decode Stack #i Index Word
1762 // The Stack #i Index Word is a 32-Bit word wit following structure
1763 // ssssssss ssssssss vvvv mmmm mmmmmmmm
1764 // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask
1766 st->fPos = (UInt_t*)word;
1768 UInt_t vword = *word;
1769 st->fHeaderSize = STACK_HEADER_SIZE(vword);
1771 UInt_t linkMask = STACK_LINK_WORD(vword);
1772 st->fActiveLinks = 0;
1773 for (Int_t i = 0; i < 12; i++)
1775 if (IS_BIT_SET(linkMask,i) > 0)
1777 st->fLinksActive[i] = kTRUE;
1782 st->fLinksActive[i] = kFALSE;
1787 //--------------------------------------------------------
1788 void AliTRDrawStreamTB::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const
1790 st->fPos = (UInt_t*)word;
1792 UInt_t vword = *word;
1793 st->fLinksDataType[2*iword] = LINK0_DATA_TYPE_FLAG(vword);
1794 st->fLinksMonitor[2*iword] = LINK0_MONITOR_FLAG(vword);
1795 st->fLinksDataType[2*iword+1] = LINK1_DATA_TYPE_FLAG(vword);
1796 st->fLinksMonitor[2*iword+1] = LINK1_MONITOR_FLAG(vword);
1799 //--------------------------------------------------------
1800 const char *AliTRDrawStreamTB::DumpStackInfo(const struct AliTRDrawStack *st)
1803 // format the string with the stack info
1806 return "Dupa Blada";
1808 static char text[1000];
1810 "[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
1813 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
1814 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
1815 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]
1821 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
1824 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
1825 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
1826 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
1831 //--------------------------------------------------------
1832 Bool_t AliTRDrawStreamTB::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
1835 // decode the hc header word 0
1837 UInt_t vword = *word;
1839 hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword);
1840 if (hc->fH0Corrupted > 0)
1842 if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%08x", *fHC->fPos));
1846 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
1847 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
1848 hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword);
1849 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
1850 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
1851 hc->fDCSboard = HC_DCS_BOARD(vword);
1852 hc->fSM = HC_SM_NUMBER(vword);
1853 hc->fStack = HC_STACK_NUMBER(vword);
1854 hc->fLayer = HC_LAYER_NUMBER(vword);
1855 hc->fSide = HC_SIDE_NUMBER(vword);
1857 hc->fPos[0] = (UInt_t*)word;
1862 //--------------------------------------------------------
1863 Bool_t AliTRDrawStreamTB::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
1866 // decode the hc header word 1
1869 UInt_t vword = *word;
1871 hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword);
1872 if (hc->fH1Corrupted > 0)
1874 if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%08x", *fHC->fPos));
1878 hc->fTimeBins = HC_NTIMEBINS(vword);
1879 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
1880 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
1881 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
1883 hc->fPos[1] = (UInt_t*)word;
1888 //--------------------------------------------------------
1889 const char *AliTRDrawStreamTB::DumpHCinfoH0(const struct AliTRDrawHC *hc)
1892 // dump the hc header word 0
1895 return Form("Unable to dump. Null received as parameter!?!");
1897 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
1898 hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
1901 //--------------------------------------------------------
1902 const char *AliTRDrawStreamTB::DumpHCinfoH1(const struct AliTRDrawHC *hc)
1905 // dump the hc header word 1
1908 return Form("Unable to dump. Null received as parameter!?!");
1910 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
1911 hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
1914 //--------------------------------------------------------
1915 void AliTRDrawStreamTB::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1918 // decode the mcm header
1920 UInt_t vword = *word;
1922 if (vword == END_OF_TRACKLET_MARKERNEW)
1924 if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
1925 mcm->fMCMhdCorrupted += 16;
1926 fHC->fCorrupted += 16; //to finish data reading of this HC
1929 mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error
1930 if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));
1932 mcm->fROB = MCM_ROB_NUMBER(vword);
1933 mcm->fMCM = MCM_MCM_NUMBER(vword);
1934 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
1935 mcm->fPos = (UInt_t*)word;
1938 //--------------------------------------------------------
1939 UInt_t AliTRDrawStreamTB::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1944 UInt_t vword = *word;
1949 mcm->fADCMaskWord = vword;
1951 if (vword == END_OF_TRACKLET_MARKERNEW)
1953 if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
1954 mcm->fADCmaskCorrupted += 16;
1955 fHC->fCorrupted += 16; //to finish data reading of this HC
1958 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 )
1960 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
1961 mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
1965 mcm->fADCMask = 0xffffffff;
1966 mcm->fADCmaskCorrupted = 1; // mcm adc mask error
1967 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));
1970 return mcm->fADCMask;
1973 //--------------------------------------------------------
1974 void AliTRDrawStreamTB::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1977 // decode the adc mask - adcs to be read out
1979 mcm->fMCMADCWords = 0;
1980 mcm->fSingleADCwords = 0;
1982 mcm->fADCMask = GetMCMadcMask(word, mcm);
1984 if (mcm->fADCMask > 0)
1986 for (Int_t i = 0; i < TRD_MAX_ADC; i++)
1988 mcm->fADCchannel[mcm->fADCmax] = 0;
1989 if( IS_BIT_SET(mcm->fADCMask,i) )
1991 mcm->fADCchannel[mcm->fADCmax] = i;
1996 if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) // backward compatibility
1998 mcm->fADCmaskCorrupted += 2;
1999 if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n", mcm->fADCcount, mcm->fADCmax, *fMCM->fPos));
2003 //--------------------------------------------------------
2004 void AliTRDrawStreamTB::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
2007 // count the expected mcm words for a given tbins
2009 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
2010 mcm->fSingleADCwords = 0;
2011 if (mcm->fADCmax > 0)
2013 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
2017 //--------------------------------------------------------
2018 const char *AliTRDrawStreamTB::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
2021 // mcm info in a string
2024 return Form("Unable to dump. Null received as parameter!?!");
2026 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
2029 //--------------------------------------------------------
2030 const char *AliTRDrawStreamTB::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
2033 // mcm adc mask in a string
2036 return Form("Unable to dump. Null received as parameter!?!");
2038 TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
2039 for (Int_t i = 0; i < 21; i++)
2041 tsreturn += Form("%d ", mcm->fADCchannel[i]);
2044 return tsreturn.Data();