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
134 Short_t AliTRDrawStreamTB::fgMCMordering[] =
136 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3
138 Short_t AliTRDrawStreamTB::fgROBordering[] =
142 Int_t AliTRDrawStreamTB::fgLastHC = -1;
143 Int_t AliTRDrawStreamTB::fgLastROB = -1;
144 Int_t AliTRDrawStreamTB::fgLastIndex = -1;
146 AliTRDrawStreamTB::AliTRDrawStreamTB()
147 : AliTRDrawStreamBase()
159 , fStackLinkNumber(-1)
162 , fLinkTrackletCounter(-1)
163 , fEndOfTrackletCount(-1)
168 , fLastEventCounter(0)
169 , fSharedPadsOn(kFALSE)
177 // default constructor
180 if (Init() == kFALSE)
182 AliWarning("Unable to Init.");
186 //--------------------------------------------------------
187 AliTRDrawStreamTB::AliTRDrawStreamTB(AliRawReader *rawReader)
188 : AliTRDrawStreamBase(rawReader)
200 , fStackLinkNumber(-1)
203 , fLinkTrackletCounter(-1)
204 , fEndOfTrackletCount(-1)
209 , fLastEventCounter(0)
210 , fSharedPadsOn(kFALSE)
214 , fRawReader(rawReader)
218 // default constructor
222 if (Init() == kFALSE)
224 AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
229 AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
233 //------------------------------------------------------------
235 AliTRDrawStreamTB::AliTRDrawStreamTB(const AliTRDrawStreamTB& /*st*/)
236 : AliTRDrawStreamBase()
248 , fStackLinkNumber(-1)
251 , fLinkTrackletCounter(-1)
252 , fEndOfTrackletCount(-1)
257 , fLastEventCounter(0)
258 , fSharedPadsOn(kFALSE)
268 AliError("Not implemeneted.");
271 //------------------------------------------------------------
272 Bool_t AliTRDrawStreamTB::SetRawVersion(Int_t fraw)
275 // function provided for backward compatibility
277 AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");
278 fraw = 0; // avoid warnings
282 //------------------------------------------------------------
283 AliTRDrawStreamTB::~AliTRDrawStreamTB()
291 //------------------------------------------------------------
294 AliTRDrawStreamTB::operator=(const AliTRDrawStreamTB &)
297 // we are not using this functionality
299 AliFatal("May not use.");
303 //___________________________________________________________
305 AliTRDrawStreamTB::SwapOnEndian()
308 // Check the endian and swap if needed
311 char* ptemp = (char*) &itemp;
314 if (fgDebugFlag) AliDebug(8, "Swapping.");
318 while (fpPos < fpEnd)
321 iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
322 ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
323 // here we override the value in the buffer!
330 //------------------------------------------------------------
332 AliTRDrawStreamTB::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
335 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
336 for (UInt_t i = 0; i < iw; i++)
338 if (px + iw >= fpEnd)
343 if (marker != 0 && marker == px[i])
344 tsreturn += Form(" *>0x%08x<* ", px[i]);
346 tsreturn += Form("0x%08x ", px[i]);
350 AliInfo(tsreturn.Data());
355 //------------------------------------------------------------
357 AliTRDrawStreamTB::SkipWords(UInt_t iw)
360 // Skip words corresponding to iw
362 if ( fpPos + iw < fpEnd )
369 if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
376 //------------------------------------------------------------
378 AliTRDrawStreamTB::SetReader(AliRawReader *reader)
390 AliWarning("Unable to setup reader.");
396 AliWarning("AliRawReader argument is 0.");
403 //------------------------------------------------------------
405 AliTRDrawStreamTB::NextBuffer()
408 // return -1 if no more buffers available
409 // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come
410 // return 1 DecodeSM OK
417 Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
418 if (kBufferSet == kTRUE)
420 if (fgDebugFlag) AliDebug(9, "Buffer is set.");
421 length = fRawReader->GetDataSize();
422 if (fgExtraSkip == kTRUE)
424 buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
425 length -= EXTRA_LEAD_WORDS * WORD_SIZE;
428 if (fgSkipCDH == kTRUE)
430 buffer += CDH_WORDS * WORD_SIZE;
431 length -= CDH_WORDS * WORD_SIZE;
436 if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
437 if (DecodeSM((void*)buffer, length) == kTRUE)
452 //------------------------------------------------------------
454 AliTRDrawStreamTB::ResetCounters()
457 // reset some global counters
459 fBufferRead = kFALSE; // important to read buffer
463 fStackLinkNumber = 0;
466 fSM.fActiveStacks = 0;
467 fSM.fNexpectedHalfChambers = 0;
469 fLinkTrackletCounter = 0;
470 fLastEventCounter = 0;
474 //------------------------------------------------------------
476 AliTRDrawStreamTB::ResetIterators()
479 // reset data which should be reset every sm
481 fStackNumber = 0; // reset for Next() function
482 fStackLinkNumber = 0; // reset for Next() function
487 //------------------------------------------------------------
489 AliTRDrawStreamTB::ResetPerHC()
497 //------------------------------------------------------------
500 AliTRDrawStreamTB::Next()
503 // returns with true on next adc read
504 // returns false on errors and end of buffer
509 while (fStackNumber < 5 && fSM.fActiveStacks > 0)
511 if(fSM.fStackActive[fStackNumber] == kTRUE)
513 fStack = &fSM.fStacks[fStackNumber];
514 while (fStackLinkNumber < 12)
516 if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0)
518 fHC = &fStack->fHalfChambers[fStackLinkNumber];
521 AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
524 if (fHC->fCorrupted == 0 && (fHC->fH0Corrupted == 0 && fHC->fH1Corrupted == 0)) // if HC data corrupted(in any case), we don't read data at all from this HC
526 while (fhcMCMcounter < fHC->fMCMmax)
528 fMCM = &fHC->fMCMs[fhcMCMcounter];
531 AliError(Form("HC missing at stack %d link %d atMCMslot %d",
532 fStackNumber, fStackLinkNumber, fhcMCMcounter));
535 while(fmcmADCcounter < fMCM->fADCmax)
537 fADC = &fMCM->fADCs[fmcmADCcounter];
540 AliError(Form("ADC missing at stack %d link %d MCMslot %d ADCslot %d",
541 fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));
551 if (fADC->fIsShared == kFALSE)
556 // next MCM should go through all active ADCs
562 // next stack link (HC) should go through all active MCMs
567 // next stack should go through all links - start from 0
568 fStackLinkNumber = 0;
572 // in case rawreader manages the mem buffers, go for the next buffer
575 Int_t nextBuff = NextBuffer();
576 while (nextBuff != -1)
583 nextBuff = NextBuffer();
590 //------------------------------------------------------------
592 //AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager)
593 AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager, UInt_t **trackletContainer) //[mj]
596 // Fills single chamber digit array
597 // Return value is the detector number
600 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
601 AliTRDdataArrayDigits *digits = 0;
602 AliTRDdataArrayI *track0 = 0;
603 AliTRDdataArrayI *track1 = 0;
604 AliTRDdataArrayI *track2 = 0;
605 AliTRDSignalIndex *indexes = 0;
607 // Get the ADC baseline
608 Int_t adcBaseline = 0;
609 // if (!AliTRDReconstructor::RecoParam())
611 // AliError("RecoParam does not exist\n");
616 // adcBaseline = ((Int_t) AliTRDReconstructor::RecoParam()->GetADCbaseline());
619 static AliTRDrecoParam * par = AliTRDrecoParam::GetLowFluxParam();
620 adcBaseline = par->GetADCbaseline();
621 // Loop through the digits
624 // Int_t returnDet = -1;
625 Int_t lastside = -1; //[mj]
626 Int_t side = -1; //[mj]
628 Int_t ntracklets = 0;
630 if (trackletContainer){
631 for (Int_t i = 0; i < 2; i++) //[mj]
632 for (Int_t j = 0; j < MAX_TRACKLETS_PERHC; j++) //[mj]
633 trackletContainer[i][j] = 0; //[mj]
639 //[mj tracklet writing]
641 //printf("det= %d lastdet= %d side= %d lastside= %d\n",det,lastdet,side,lastside);
643 if (trackletContainer)
645 if ((det + side*AliTRDgeometry::kNdet) != (lastdet + lastside*AliTRDgeometry::kNdet))
655 //if(GetTrackletWords()) trackletContainer[side] = GetTrackletWords();
656 //printf("test= %u \n",*(trackletContainer[side]));
659 ntracklets = GetNTracklets();
660 if(ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets); //copy tracklet words to trackletContainer array [mj]
661 //memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * MAX_TRACKLETS_PERHC); //copy tracklet words to trackletContainer array [mj]
662 //if(ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * MAX_TRACKLETS_PERHC); //copy tracklet words to trackletContainer array [mj]
669 // If new detector found
679 if (det < 0 || det >= AliTRDgeometry::kNdet)
681 if (fSM.fClean == kTRUE)
683 AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));
687 AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));
692 // Add a container for the digits of this detector
693 digits = (AliTRDdataArrayDigits *) digitsManager->GetDigits(det);
695 if (digitsManager->UsesDictionaries())
697 track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0);
698 track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1);
699 track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2);
704 if (fSM.fClean == kTRUE)
706 AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));
710 AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));
715 Int_t rowMax = GetRowMax();
716 Int_t colMax = GetColMax();
717 Int_t ntbins = GetNumberOfTimeBins();
719 // Allocate memory space for the digits buffer
720 if (digits->GetNtime() == 0)
722 digits->Allocate(rowMax, colMax, ntbins);
723 if (digitsManager->UsesDictionaries())
725 track0->Allocate(rowMax, colMax, ntbins);
726 track1->Allocate(rowMax, colMax, ntbins);
727 track2->Allocate(rowMax, colMax, ntbins);
731 indexes = digitsManager->GetIndexes(det);
732 indexes->SetSM(GetSM());
733 indexes->SetStack(GetStack());
734 indexes->SetLayer(GetLayer());
735 indexes->SetDetNumber(det);
736 if (indexes->IsAllocated() == kFALSE)
737 indexes->Allocate(rowMax, colMax, ntbins);
740 Char_t padStatus = cal->GetPadStatus(det, GetCol(), GetRow());
742 // ntimebins data are ready to read
743 for (it = 0; it < GetNumberOfTimeBins(); it++)
745 if ((GetSignals()[it] - adcBaseline) > 0)
747 digits->SetDataUnchecked(GetRow(), GetCol(), it, GetSignals()[it] - adcBaseline);
749 digits->SetPadStatus(GetRow(), GetCol(), it, padStatus);
751 indexes->AddIndexTBin(GetRow(), GetCol(), it);
752 if (digitsManager->UsesDictionaries())
754 track0->SetDataUnchecked(GetRow(), GetCol(), it, 0);
755 track1->SetDataUnchecked(GetRow(), GetCol(), it, 0);
756 track2->SetDataUnchecked(GetRow(), GetCol(), it, 0);
765 //------------------------------------------------------------
767 AliTRDrawStreamTB::Init()
770 // Initialize geometry and fee parameters
773 TDirectory *saveDir = gDirectory;
777 fGeometry = new AliTRDgeometry();
782 AliError("Geometry FAILED!");
786 fTRDfeeParam = AliTRDfeeParam::Instance();
789 AliError("AliTRDfeeParam FAILED!");
793 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
795 ResetCounters(); // fBufferRead is set to kFALSE - important
798 // in case rawreader manages the mem buffers
799 // lets go for the next buffer
802 Int_t nextBuff = NextBuffer();
803 while (nextBuff != -1)
807 nextBuff = NextBuffer();
816 //------------------------------------------------------------
818 AliTRDrawStreamTB::InitBuffer(void *buffer, UInt_t length)
821 // set initial information about the buffer
824 if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));
826 if(fgStreamEventCounter == 0) fgFirstEquipmentID = fRawReader->GetEquipmentId();
827 fEquipmentID = fRawReader->GetEquipmentId();
828 if(fEquipmentID == fgFirstEquipmentID) fgStreamEventCounter++; // [mj] risky if the order of sm in data changed
829 // since it is still for debug event counter, doesn't give an effect on decoded data
832 fpBegin = (UInt_t *)buffer;
836 AliFatal("Strange word size. size of UInt_t == 0");
840 fWordLength = length/WORD_SIZE;
841 fpEnd = fpBegin + fWordLength;
844 if (fpBegin == 0 || length <= 0)
846 AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%08x of size %d", fpBegin, length));
854 AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));
855 if (DumpWords(fpBegin, fgDumpHead) == kFALSE)
857 AliError("Dump failed. Not enough data.");
859 AliInfo(Form("---------- Dumping ended ----------------------------------------------"));
865 //------------------------------------------------------------
867 AliTRDrawStreamTB::DecodeGTUheader()
869 // Decode Supermodule Index Word
870 DecodeSMInfo(fpPos, &fSM);
872 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
877 // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design.
878 // For the moment, we skip decoding these words
879 if (SkipWords(fSM.fHeaderSize) == kTRUE)
881 for (Int_t istack = 0; istack < 5; istack++)
883 if (fSM.fStackActive[istack] == kFALSE)
886 fStack = &fSM.fStacks[istack];
888 // Decode Stack Index Word of given stack
889 DecodeStackInfo(fpPos, fStack);
892 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
894 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
896 if (SkipWords(fStack->fHeaderSize-6) == kFALSE) // 6 is the 6 stack header words for 12 links
898 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing");
901 for (Int_t iword=0; iword<6; iword++) // decode 6 stack header words
903 // Decode Stack Header Word of given stack
904 DecodeStackHeader(fpPos, fStack, iword);
916 if (fgWarnError) AliWarning("No additional sm headers and stack index words present.");
917 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
923 if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");
927 if (fgWarnError) AliWarning("No data just after GTU headers.");
928 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");
932 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));
937 //------------------------------------------------------------
939 AliTRDrawStreamTB::DecodeSM(void *buffer, UInt_t length)
942 // decode one sm data in buffer
948 if (InitBuffer(buffer, length) == kFALSE)
950 if (fgWarnError) AliError("InitBuffer failed.");
955 if (DecodeGTUheader()== kFALSE)
958 for (Int_t istack = 0; istack < 5; istack++)
960 fStackNumber = istack;
961 if (fSM.fStackActive[istack] == kFALSE)
964 fStack = &fSM.fStacks[istack];
966 fgLastHC = -1; // to check rob number odering
967 for (Int_t ilink = 0; ilink < 12; ilink++)
969 fStackLinkNumber = ilink;
970 if (fStack->fLinksActive[ilink] == kFALSE)
973 // check GTU link monitor
974 if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0))
976 fStack->fLinkMonitorError[ilink] = 1;
977 SeekEndOfData(); // skip this HC data if GTU link monitor report error
983 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
988 fHC = &fStack->fHalfChambers[ilink];
991 if (fSM.fTrackletEnable == kTRUE)
993 if (DecodeTracklets() == kFALSE)
1001 AliError(Form("Failed stack %d link %d", fStackNumber, fStackLinkNumber));
1002 AliError(Form("Debug Event Counter : %d", fgStreamEventCounter));
1010 if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
1011 fSM.fClean = kFALSE;
1015 fgLastROB = -1; // to check mcm number odering
1016 fgLastIndex = -1 ; // to check mcm number odering
1017 if (DecodeHC() == kFALSE)
1019 fSM.fClean = kFALSE;
1020 if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW
1021 // during ADC data decoding or MCM header decoding
1022 // we don't seek ENDOFRAWDATAMARKER
1026 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
1027 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
1028 AliError(Form("Debug Event Counter : %d\n\n\n", fgStreamEventCounter));
1035 SeekEndOfData(); // make sure that finish off with the end of data markers
1041 ResetIterators(); // need to do it again for Next() function
1043 if (fSM.fClean == kTRUE)
1046 if (fgCleanDataOnly && (fSM.fClean == kFALSE))
1050 AliWarning("Buffer with errors. Returning FALSE.");
1051 AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
1053 fSM.fActiveStacks = 0; // Next() will not give data
1060 //------------------------------------------------------------
1062 AliTRDrawStreamTB::DecodeSM()
1065 // decode SM data in case AliRawReader is in use
1069 Int_t nextBuff = NextBuffer();
1070 while (nextBuff != -1)
1074 nextBuff = NextBuffer();
1080 AliWarning("AliRawReader not set.");
1085 //------------------------------------------------------------
1087 AliTRDrawStreamTB::DecodeSM(AliRawReader *reader)
1090 // decode SM with the AliRawReader
1094 fRawReader = reader;
1099 AliWarning("Argument AliRawReader is 0.");
1104 //------------------------------------------------------------
1106 AliTRDrawStreamTB::SeekEndOfData()
1109 // go to end of data marker
1111 Int_t fEndOfDataCount = 0;
1113 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1118 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd )
1127 //------------------------------------------------------------
1129 AliTRDrawStreamTB::SkipMCMdata(UInt_t iw)
1132 if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw));
1133 UInt_t iwcounter = 0;
1134 while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw)
1136 if ( *fpPos == END_OF_TRACKLET_MARKERNEW)
1138 if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW");
1139 fMCM->fCorrupted += 16;
1140 fHC->fCorrupted += 16;
1147 if (iwcounter == iw)
1153 if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");
1157 //------------------------------------------------------------
1159 AliTRDrawStreamTB::SeekNextMCMheader()
1167 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1169 if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0)
1171 if (fgDebugFlag) AliDebug(11,Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1174 if ( *fpPos == END_OF_TRACKLET_MARKERNEW)
1176 fMCM->fCorrupted += 16;
1177 fHC->fCorrupted += 16;
1187 //------------------------------------------------------------
1190 AliTRDrawStreamTB::DecodeTracklets()
1196 fLinkTrackletCounter = 0;
1197 fEndOfTrackletCount = 0;
1199 for (Int_t i = 0; i < MAX_TRACKLETS_PERHC; i++) //[mj]
1200 fHC->fTrackletWords[i] = 0; //[mj]
1202 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
1204 while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd )
1206 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
1208 fLinkTrackletCounter++;
1210 if (fLinkTrackletCounter > MAX_TRACKLETS_PERHC)
1212 if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d.",
1213 fLinkTrackletCounter, MAX_TRACKLETS_PERHC));
1214 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
1215 fHC->fTrackletError = 1;
1219 fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into array //[mj]
1220 fHC->fNTracklets = fLinkTrackletCounter;
1224 while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd )
1226 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1228 fEndOfTrackletCount++;
1232 if ( fEndOfTrackletCount < 2 )
1234 if (fgDebugFlag) AliDebug(11,"End of tracklets word missing");
1235 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1236 fHC->fTrackletError += 2;
1243 //------------------------------------------------------------
1245 AliTRDrawStreamTB::IsRowValid()
1247 if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||
1248 (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 )
1250 if (fgDebugFlag) AliDebug(11,Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1251 , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));
1257 //------------------------------------------------------------
1259 AliTRDrawStreamTB::IsMCMheaderOK()
1262 // check the mcm header
1265 if (fgLastROB != fMCM->fROB)
1268 if (fgLastROB== -1) fgLastROB = fMCM->fROB;
1272 Int_t matchingcounter = 0;
1273 for (Int_t i=fgLastIndex+1; i<16; i++)
1275 if ( fMCM->fMCM == fgMCMordering[i] )
1282 if (matchingcounter == 0)
1284 fMCM->fMCMhdCorrupted += 2;
1285 AliDebug(11,Form("MCM number from last MCM is larger: MCM # from last MCM %d, MCM # from current MCM %d \n",(fMCM-1)->fMCM, fMCM->fMCM));
1289 if ( fgLastHC == fHC->fLayer*2 + fHC->fSide )
1291 if ( fMCM->fROB < (fMCM-1)->fROB )
1293 fMCM->fMCMhdCorrupted += 2;
1294 AliDebug(11,Form("ROB number from last MCM is larger: ROB # from last MCM %d, ROB # from current MCM %d \n",(fMCM-1)->fROB, fMCM->fROB));
1296 else fgLastROB = fMCM->fROB;
1299 fgLastHC = fHC->fLayer*2 + fHC->fSide;
1302 // this check will come back later again when we have "patched MCM map"
1303 int expectedROB = -1;
1304 if(!fHC->fSide) expectedROB = int(fHC->fMCMmax/16)*2;
1305 else expectedROB = int(fHC->fMCMmax/16)*2 + 1;
1306 int expectedMCM = 4*(3-int((fHC->fMCMmax%16)/4)) + fHC->fMCMmax%4;
1308 if ( expectedROB != fMCM->fROB || expectedMCM != fMCM->fMCM)
1310 fMCM->fMCMhdCorrupted += 2;
1311 AliDebug(11,Form("ROB expected %d ROB read %d, MCM expected %d MCM read %d\n",expectedROB, fMCM->fROB, expectedMCM, fMCM->fMCM));
1315 // below two conditions are redundant
1317 if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 )
1319 fMCM->fMCMhdCorrupted += 8; // need to assign new number
1320 if (fgDebugFlag) AliDebug(11,Form("ROB or MCM number is out of range. %s\n", DumpMCMinfo(fMCM)));
1322 if (IsRowValid() == kFALSE)
1324 fMCM->fMCMhdCorrupted += 16; // need to assign new number
1328 if (fEventCounter == 0)
1330 fEventCounter = fMCM->fEvCounter;
1333 if (fEventCounter != fMCM->fEvCounter)
1335 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)));
1338 if (fEventCounter < fLastEventCounter)
1340 fMCM->fMCMhdCorrupted += 8; if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM)));
1343 if ( fMCM->fADCmaskCorrupted > 0 )
1346 if ( fMCM->fMCMhdCorrupted > 0 )
1352 //------------------------------------------------------------
1354 AliTRDrawStreamTB::DecodeMCMheader()
1357 // decode the mcm header
1360 DecodeMCMheader(fpPos, fMCM);
1361 if (fHC->fCorrupted >= 16)
1367 fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
1369 if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || (fHC->fRawVMajor > 31 && fHC->fRawVMajor < 64)) //cover old and new version definition of ZS data
1372 if ( fpPos < fpEnd )
1374 DecodeMask(fpPos, fMCM);
1375 if (fHC->fCorrupted >= 16)
1380 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1381 fMCM->fAdcDataPos = fpPos + 1;
1385 if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END.");
1386 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1387 fHC->fCorrupted += 32;
1393 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
1394 DecodeMask(&dummyMask, fMCM);
1395 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1396 fMCM->fAdcDataPos = fpPos + 1;
1401 AliDebug(6, DumpMCMinfo(fMCM));
1402 AliDebug(7, DumpMCMadcMask(fMCM));
1405 if (IsMCMheaderOK() == kFALSE)
1411 //------------------------------------------------------------
1413 AliTRDrawStreamTB::IsHCheaderOK()
1416 // check insanity of half chamber header
1419 if (fHC->fStack < 0 || fHC->fStack > 4)
1421 if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStack));
1425 if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNlayer)
1427 if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayer));
1431 if (fHC->fSide < 0 || fHC->fSide > 1)
1433 if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSide));
1437 if (fgStackNumberChecker)
1439 if (fHC->fStack != fStackNumber)
1441 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d",
1442 fHC->fStack, fStackNumber));
1448 if (fgStackLinkNumberChecker)
1450 //if (fHC->fLayer * 2 + fHC->fSide != fStackLinkNumber)
1451 // let it make flexible to consider known fiber swapping
1452 if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1))
1454 if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s",
1455 fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));
1456 fStackLinkNumber = -1;
1461 // SLOW GEOM : consistancy check with geometry
1462 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
1463 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet)
1465 if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET));
1466 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1470 if (fHC->fSM != fGeometry->GetSector(fHC->fDET)
1471 || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector)
1473 if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1474 fHC->fSM, fGeometry->GetSector(fHC->fDET),
1475 fHC->fStack, fHC->fLayer, fHC->fDET));
1476 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1480 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
1483 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1487 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
1488 if (fHC->fRowMax < 1)
1490 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1494 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
1495 if (fHC->fColMax < 1)
1497 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1504 //------------------------------------------------------------
1506 AliTRDrawStreamTB::DecodeHCheader()
1509 // decode the half chamber header
1512 if (DecodeHCwordH0(fpPos, fHC) == kFALSE)
1515 if (fHC->fNExtraWords > 0)
1520 if (DecodeHCwordH1(fpPos, fHC) == kFALSE)
1525 if (fgDebugFlag) AliDebug(11,"Expected HC header word 1. Fail due to buffer END.");
1526 if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing");
1531 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1532 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1535 if (IsHCheaderOK() == kFALSE)
1537 fHC->fH0Corrupted += 2;
1538 if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));
1545 //------------------------------------------------------------
1547 AliTRDrawStreamTB::DecodeHC()
1550 // decode hc header and data
1553 if (DecodeHCheader() == kFALSE)
1555 if (fgWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));
1556 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "HC header corrupted");
1564 fHC->fCorrupted += 1;
1565 if (fgDebugFlag) AliDebug(11,"No MCM data? Not enough data in the buffer.");
1566 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing");
1572 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd)
1574 if (fHC->fMCMmax > TRD_MAX_MCM)
1576 fHC->fCorrupted += 2;
1577 if (fgDebugFlag) AliDebug(11,"More mcm data than expected!");
1578 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!");
1582 fMCM = &fHC->fMCMs[fHC->fMCMmax];
1584 if (DecodeMCMheader() == kFALSE)
1586 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1588 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1589 return kFALSE; // stop HC data reading
1591 fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number
1593 // in case we decide to keep reading data, skip this mcm data and find next mcm header
1594 if (fMCM->fADCmaskCorrupted < 2)
1596 if (SkipMCMdata(fMCM->fADCcount*fMCM->fSingleADCwords) == kFALSE)
1602 if (SeekNextMCMheader() == kFALSE)
1610 if (fMCM->fADCmax > 0)
1615 fMCM->fCorrupted += 1;
1616 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1617 if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected."));
1621 for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++)
1623 fADC = &fMCM->fADCs[iadc];
1624 fADC->fADCnumber = fMCM->fADCchannel[iadc];
1626 if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.",
1627 iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1629 if (fpPos + fMCM->fSingleADCwords >= fpEnd)
1632 fMCM->fCorrupted += 2;
1633 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1634 if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");
1638 if (fHC->fRawVMajor < 64) // normal(real) ADC data
1640 if (DecodeADC() == kFALSE)
1642 if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4
1643 if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
1644 if (fADC->fIsShared && fADC->fCorrupted == 16) // check if we are out of the det when the pad is shared
1647 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1651 if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));
1652 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1653 return kFALSE; // stop HC data reading
1657 else // test pattern data
1659 if (fgWarnError) AliError("These are test pattern data. You need other reader"); // will be served in other class
1671 if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. There should be one more word left.");
1677 //------------------------------------------------------------
1680 AliTRDrawStreamTB::DecodeADC()
1683 // decode single ADC channel
1686 fADC->fCorrupted = 0;
1687 if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
1688 if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
1693 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
1694 fADC->fSignals[i] = 0;
1696 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
1698 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW)
1700 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1701 fADC->fCorrupted += 16;
1702 fHC->fCorrupted += 16;
1707 if (fMaskADCword != ADC_WORD_MASK(*fpPos))
1709 fADC->fCorrupted += 1;
1710 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",
1711 fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));
1716 // here we subtract the baseline ( == common additive)
1717 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1718 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1719 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
1725 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
1727 fADC->fIsShared = kTRUE;
1731 fADC->fIsShared = kFALSE;
1734 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
1736 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
1741 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1744 if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0)
1746 if (fADC->fIsShared == kFALSE)
1748 fADC->fCorrupted += 32;
1749 if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1750 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1754 // we are out of the det when the pad is shared
1755 if (fgDebugFlag) AliDebug(11, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1756 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1757 fADC->fCorrupted += 32;
1761 if (fADC->fCorrupted > 0)
1770 //--------------------------------------------------------
1773 void AliTRDrawStreamTB::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
1776 // Decode Supermodule Index Word
1777 // The Supermodule Index Word is a 32-Bit word wit following structure
1778 // ssssssss ssssssss vvvv rrrr r d t mmmm
1779 // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use
1780 // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask
1782 sm->fPos = (UInt_t*)word;
1784 UInt_t vword = *word;
1785 sm->fHeaderSize = SM_HEADER_SIZE(vword);
1787 if (TRACKLETS_ENABLED(vword) > 0)
1788 sm->fTrackletEnable = kTRUE;
1790 sm->fTrackletEnable = kFALSE;
1792 UInt_t stackMask = STACK_MASK(vword);
1793 sm->fActiveStacks = 0;
1794 for (Int_t i = 0; i < 5; i++)
1796 if (IS_BIT_SET(stackMask,i) > 0)
1798 sm->fStackActive[i] = kTRUE;
1799 sm->fActiveStacks++;
1803 sm->fStackActive[i] = kFALSE;
1808 //--------------------------------------------------------
1809 const char *AliTRDrawStreamTB::DumpSMInfo(const struct AliTRDrawSM *sm)
1812 // Get SM structure into a const char
1814 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
1816 sm->fHeaderSize, sm->fTrackletEnable,
1817 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
1818 sm->fStackActive[3], sm->fStackActive[4]);
1821 //--------------------------------------------------------
1822 void AliTRDrawStreamTB::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
1825 // Decode Stack #i Index Word
1826 // The Stack #i Index Word is a 32-Bit word wit following structure
1827 // ssssssss ssssssss vvvv mmmm mmmmmmmm
1828 // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask
1830 st->fPos = (UInt_t*)word;
1832 UInt_t vword = *word;
1833 st->fHeaderSize = STACK_HEADER_SIZE(vword);
1835 UInt_t linkMask = STACK_LINK_WORD(vword);
1836 st->fActiveLinks = 0;
1837 for (Int_t i = 0; i < 12; i++)
1839 if (IS_BIT_SET(linkMask,i) > 0)
1841 st->fLinksActive[i] = kTRUE;
1846 st->fLinksActive[i] = kFALSE;
1851 //--------------------------------------------------------
1852 void AliTRDrawStreamTB::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const
1854 st->fPos = (UInt_t*)word;
1856 UInt_t vword = *word;
1857 st->fLinksDataType[2*iword] = LINK0_DATA_TYPE_FLAG(vword);
1858 st->fLinksMonitor[2*iword] = LINK0_MONITOR_FLAG(vword);
1859 st->fLinksDataType[2*iword+1] = LINK1_DATA_TYPE_FLAG(vword);
1860 st->fLinksMonitor[2*iword+1] = LINK1_MONITOR_FLAG(vword);
1863 //--------------------------------------------------------
1864 const char *AliTRDrawStreamTB::DumpStackInfo(const struct AliTRDrawStack *st)
1867 // format the string with the stack info
1870 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
1873 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
1874 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
1875 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
1879 //--------------------------------------------------------
1880 Bool_t AliTRDrawStreamTB::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
1883 // decode the hc header word 0
1885 UInt_t vword = *word;
1887 hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword);
1888 if (hc->fH0Corrupted > 0)
1890 if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%08x", *fHC->fPos));
1894 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
1895 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
1896 hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword);
1897 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
1898 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
1899 hc->fDCSboard = HC_DCS_BOARD(vword);
1900 hc->fSM = HC_SM_NUMBER(vword);
1901 hc->fStack = HC_STACK_NUMBER(vword);
1902 hc->fLayer = HC_LAYER_NUMBER(vword);
1903 hc->fSide = HC_SIDE_NUMBER(vword);
1905 hc->fPos[0] = (UInt_t*)word;
1910 //--------------------------------------------------------
1911 Bool_t AliTRDrawStreamTB::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
1914 // decode the hc header word 1
1917 UInt_t vword = *word;
1919 hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword);
1920 if (hc->fH1Corrupted > 0)
1922 if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%08x", *fHC->fPos));
1926 hc->fTimeBins = HC_NTIMEBINS(vword);
1927 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
1928 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
1929 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
1931 hc->fPos[1] = (UInt_t*)word;
1936 //--------------------------------------------------------
1937 const char *AliTRDrawStreamTB::DumpHCinfoH0(const struct AliTRDrawHC *hc)
1940 // dump the hc header word 0
1943 return Form("Unable to dump. Null received as parameter!?!");
1945 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
1946 hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
1949 //--------------------------------------------------------
1950 const char *AliTRDrawStreamTB::DumpHCinfoH1(const struct AliTRDrawHC *hc)
1953 // dump the hc header word 1
1956 return Form("Unable to dump. Null received as parameter!?!");
1958 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
1959 hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
1962 //--------------------------------------------------------
1963 void AliTRDrawStreamTB::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1966 // decode the mcm header
1968 UInt_t vword = *word;
1970 if (vword == END_OF_TRACKLET_MARKERNEW)
1972 if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
1973 mcm->fMCMhdCorrupted += 16;
1974 fHC->fCorrupted += 16; //to finish data reading of this HC
1977 mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error
1978 if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));
1980 mcm->fROB = MCM_ROB_NUMBER(vword);
1981 mcm->fMCM = MCM_MCM_NUMBER(vword);
1982 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
1983 mcm->fPos = (UInt_t*)word;
1986 //--------------------------------------------------------
1987 UInt_t AliTRDrawStreamTB::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
1992 UInt_t vword = *word;
1997 mcm->fADCMaskWord = vword;
1999 if (vword == END_OF_TRACKLET_MARKERNEW)
2001 if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
2002 mcm->fADCmaskCorrupted += 16;
2003 fHC->fCorrupted += 16; //to finish data reading of this HC
2006 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 )
2008 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
2009 mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
2013 mcm->fADCMask = 0xffffffff;
2014 mcm->fADCmaskCorrupted = 1; // mcm adc mask error
2015 if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));
2018 return mcm->fADCMask;
2021 //--------------------------------------------------------
2022 void AliTRDrawStreamTB::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2025 // decode the adc mask - adcs to be read out
2027 mcm->fMCMADCWords = 0;
2028 mcm->fSingleADCwords = 0;
2030 mcm->fADCMask = GetMCMadcMask(word, mcm);
2032 if (mcm->fADCMask > 0)
2034 for (Int_t i = 0; i < TRD_MAX_ADC; i++)
2036 mcm->fADCchannel[mcm->fADCmax] = 0;
2037 if( IS_BIT_SET(mcm->fADCMask,i) )
2039 mcm->fADCchannel[mcm->fADCmax] = i;
2044 if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) // backward compatibility
2046 mcm->fADCmaskCorrupted += 2;
2047 if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n", mcm->fADCcount, mcm->fADCmax, *fMCM->fPos));
2051 //--------------------------------------------------------
2052 void AliTRDrawStreamTB::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
2055 // count the expected mcm words for a given tbins
2057 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
2058 mcm->fSingleADCwords = 0;
2059 if (mcm->fADCmax > 0)
2061 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
2065 //--------------------------------------------------------
2066 const char *AliTRDrawStreamTB::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
2069 // mcm info in a string
2072 return Form("Unable to dump. Null received as parameter!?!");
2074 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
2077 //--------------------------------------------------------
2078 const char *AliTRDrawStreamTB::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
2081 // mcm adc mask in a string
2084 return Form("Unable to dump. Null received as parameter!?!");
2086 TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
2087 for (Int_t i = 0; i < 21; i++)
2089 tsreturn += Form("%d ", mcm->fADCchannel[i]);
2092 return tsreturn.Data();