1 #ifndef ALITRDRAWSTREAMTB_H
2 #define ALITRDRAWSTREAMTB_H
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
9 ///////////////////////////////////////////////////////////////////////////////
11 // This class provides access to TRD digits in raw data. //
13 ///////////////////////////////////////////////////////////////////////////////
20 class AliTRDdigitsManager;
21 class TTreeSRedirector;
24 #define TRD_MAX_TBINS 30
25 #define TRD_MAX_ADC 21
26 #define TRD_MAX_MCM 4 * 16
28 class AliTRDrawStreamTB : public TObject
33 //--------------------------------------------------------
37 //--------------------------------------------------------
42 UInt_t *fPos; //! position of ADC 1st word in the buffer
43 Short_t fADCnumber; // number of the ADC 0 .. 20
44 Short_t fCOL; // column - row from MCM
45 Int_t fSignals[TRD_MAX_TBINS]; // signals for this adc
46 Bool_t fIsShared; // is pad chared between MCMs
47 Short_t fCorrupted; // is adc word corrupted
57 // default constructor
61 AliTRDrawADC(const AliTRDrawADC& p):
63 , fADCnumber(p.fADCnumber)
66 , fIsShared(p.fIsShared)
67 , fCorrupted(p.fCorrupted)
73 AliTRDrawADC &operator=(const AliTRDrawADC &)
75 // assignment operator
83 //--------------------------------------------------------
87 Int_t fROB; // ROB number
88 Int_t fMCM; // MCM number
89 Int_t fROW; //filed during decoding!
91 UInt_t fEvCounter; // MCM event counter
92 UInt_t fADCMask; // ADC mask
93 UInt_t fADCMaskWord; // word with ADC mask in
94 UInt_t fADCchannel[30]; // channels to be decoded accrording to ADC mask
96 Int_t fADCindex; // index of current ADC (comment: 1 ADC is 1 pad)
97 Int_t fADCmax; // number of ADCs fired
98 Int_t fMCMADCWords; // mcm words to expect
99 Int_t fSingleADCwords; // n of words per ADC
101 Int_t fCorrupted; // is mcm word corrupted
103 UInt_t fErrorCounter; // count the mcm header errors
104 UInt_t fMaskErrorCounter; // count the adc mask errors
106 UInt_t *fPos; //! position of mcm header in the buffer
107 UInt_t *fAdcDataPos; //! start of ADC data for this mcm
109 Int_t fADCcounter; // count the adcs decoded
110 AliTRDrawADC fADCs[TRD_MAX_ADC]; // 21 adcs
126 , fMaskErrorCounter(0)
132 // default constructor
133 /* the following violates coding conventions */
134 //for (Int_t i = 0; i < 30; i++) fADCchannel[i] = 0;
137 AliTRDrawMCM(const AliTRDrawMCM & p):
141 , fEvCounter(p.fEvCounter)
142 , fADCMask(p.fADCMask)
143 , fADCMaskWord(p.fADCMaskWord)
145 , fADCindex(p.fADCindex)
147 , fMCMADCWords(p.fMCMADCWords)
148 , fSingleADCwords(p.fSingleADCwords)
149 , fCorrupted(p.fCorrupted)
150 , fErrorCounter(p.fErrorCounter)
151 , fMaskErrorCounter(p.fMaskErrorCounter)
153 , fAdcDataPos(p.fAdcDataPos)
154 , fADCcounter(p.fADCcounter)
161 AliTRDrawMCM &operator=(const AliTRDrawMCM &)
163 // assignment operator
170 //--------------------------------------------------------
175 Int_t fCorrupted; // Zero if not corrupted
177 UInt_t fH0ErrorCounter; // Count the H0 word errors
178 UInt_t fH1ErrorCounter; // Count the H1 word errors
181 Int_t fSpecialRawV; // Raw data version
182 Int_t fRawVMajor; // Raw data version
183 Int_t fRawVMinor; // Raw data version
184 Int_t fNExtraWords; // N extra HC header words
185 Int_t fDCSboard; // DCS board number
186 Int_t fSM; // Super Module number
187 Int_t fStack; // Stack number (some people might call it a chamber)
188 Int_t fLayer; // Layer number (some people might call it a plane)
189 Int_t fSide; // Side of HC
192 Int_t fTimeBins; // N of t bins
193 UInt_t fBunchCrossCounter; // Bunch crossing counter
194 UInt_t fPreTriggerCounter; // Pre Trigger counter
195 UInt_t fPreTriggerPhase; // Pre Trigger phase
197 UInt_t *fPos[2]; //! position of the header words in buffer
199 Int_t fDET; // filled while decoding
200 Int_t fROC; // filled while decoding
201 Int_t fRowMax; // filled while decoding
202 Int_t fColMax; // filled while decoding
204 //AliTRDrawMCM fMCMs[4][16]; // 4 ROBS 16 each - that is max!
205 Int_t fMCMmax; // number of mcm found
206 AliTRDrawMCM fMCMs[TRD_MAX_MCM]; // 4 ROBS 16 each - that is max!
222 , fBunchCrossCounter(0)
223 , fPreTriggerCounter(0)
224 , fPreTriggerPhase(0)
233 // default constructor hc info
234 /* the following violates coding conventions */
235 //fPos[0] = fPos[0] = 0;
238 AliTRDrawHC(const AliTRDrawHC & p):
239 fCorrupted(p.fCorrupted)
240 , fH0ErrorCounter(p.fH0ErrorCounter)
241 , fH1ErrorCounter(p.fH1ErrorCounter)
242 , fSpecialRawV(p.fSpecialRawV)
243 , fRawVMajor(p.fRawVMajor)
244 , fRawVMinor(p.fRawVMinor)
245 , fNExtraWords(p.fNExtraWords)
246 , fDCSboard(p.fDCSboard)
251 , fTimeBins(p.fTimeBins)
252 , fBunchCrossCounter(p.fBunchCrossCounter)
253 , fPreTriggerCounter(p.fPreTriggerCounter)
254 , fPreTriggerPhase(p.fPreTriggerPhase)
267 AliTRDrawHC &operator=(const AliTRDrawHC &)
269 // assignment operator
276 //--------------------------------------------------------
278 struct AliTRDrawStack
280 UInt_t fHeaderSize; // header size of the stack info
281 Bool_t fLinksActive[12]; // data links active - 1 per half chamber
282 Bool_t fTrackletDecode[12]; // book keeping while decoding - set false after decoding
283 Bool_t fHCDecode[12]; // book keeping while decoding - set false after HC header decoding
284 Int_t fActiveLinks; // number of active links
285 UInt_t *fPos; //! position in the buffer
287 AliTRDrawHC fHalfChambers[12]; // 6 chambers in a stack
292 , fTrackletDecode() //book keeping while decoding - set false after decoding
293 , fHCDecode() //book keeping while decoding - set false after HC header decoding
298 // default constructor
301 AliTRDrawStack(const AliTRDrawStack & p):
302 fHeaderSize(p.fHeaderSize)
304 , fTrackletDecode() //book keeping while decoding - set false after decoding
305 , fHCDecode() //book keeping while decoding - set false after HC header decoding
306 , fActiveLinks(p.fActiveLinks)
314 AliTRDrawStack &operator=(const AliTRDrawStack &)
316 // assignment operator
323 /* the following violates coding conventions */
324 /* for (Int_t i = 0; i < 12; i++) */
326 /* fLinksActive[i] = fTrackletDecode[i] = fHCDecode[i] = kFALSE; */
329 //--------------------------------------------------------
333 UInt_t fHeaderSize; // size of the header in words
334 Bool_t fTrackletEnable; // tracklet enable bit
335 Bool_t fStackActive[5]; // map of active/expected stacks
336 Int_t fActiveStacks; // number of active stacks
337 Int_t fCorrupted; // is sm info corrupted
338 Int_t fNexpectedHalfChambers; // number of half chambers to be read out
339 Bool_t fClean; // true if everything went OK - false is some error occured
340 UInt_t *fPos; //! location of the sm info - should be the first word (after CDH if not DDL buffer)
342 AliTRDrawStack fStacks[5]; // we do have only five stacks ;)
350 , fNexpectedHalfChambers(0)
355 // Default constructor
356 // coding rule violation in the next line
357 //for (Int_t i = 0; i < 5; i++) fStackActive[i] = kFALSE;
360 AliTRDrawSM(const AliTRDrawSM & p):
361 fHeaderSize(p.fHeaderSize)
362 , fTrackletEnable(p.fTrackletEnable)
364 , fActiveStacks(p.fActiveStacks)
365 , fCorrupted(p.fCorrupted)
366 , fNexpectedHalfChambers(p.fNexpectedHalfChambers)
375 AliTRDrawSM &operator=(const AliTRDrawSM &)
377 // assignment operator
384 //--------------------------------------------------------
387 AliTRDrawStreamTB(AliRawReader *rawReader);
388 virtual ~AliTRDrawStreamTB();
390 //--------------------------------------------------------
392 virtual Bool_t Next(); // Read the next data
393 virtual Int_t NextChamber(AliTRDdigitsManager *man); // read next chamber data
394 virtual Bool_t Init(); // Init some internal variables
396 void SetRawVersion(Int_t fraw); // set the raw version - used for backward compat.
398 Bool_t IsCurrentPadShared() const {return fADC->fIsShared;} // is current pad shared between mcms
399 void SetSharedPadReadout(Bool_t fv) {fSharedPadsOn = fv;} // set the flag on if the reader should return the shared pads
400 Bool_t IsDataZeroSuppressed() const {return (fHC->fRawVMajor > 2) ? kTRUE : kFALSE;} // check the version and tell if ZS is on
402 Bool_t DecodeSM(void *buffer, UInt_t length); //decode a buffer
403 Int_t DecodeSM(); // used with raw reader
404 Int_t DecodeSM(AliRawReader *reader); // used with raw reader
406 Bool_t SetReader(AliRawReader *reader); // set the raw reader to use
408 Bool_t IsTrackletEnableBitSet() const {return fSM.fTrackletEnable;} // get status of the tracklets enable bit
409 Bool_t IsStackActive(Int_t is) const {return fSM.fStackActive[is];} // get status of a stack
410 Int_t GetNofActiveStacks() const {return fSM.fActiveStacks;} // get number of active stacks
411 UInt_t *GetSMstreamPosition() const {return fSM.fPos;} // get position of the SM index word in the buffer
413 Bool_t IsSMbufferClean() const {return fSM.fClean;} // is data clean
415 Bool_t IsLinkActiveInStack(Int_t is, Int_t il) const {return fSM.fStacks[is].fLinksActive[il];} // check whether the link is active
416 Int_t GetActiveLinksInStack(Int_t is) const {return fSM.fStacks[is].fActiveLinks;} //get active links in a stack
418 Int_t GetSpecialRawVersion() const {return fHC ? fHC->fSpecialRawV : -1;} // return special raw version
419 Int_t GetMajorRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // major raw version getter
420 Int_t GetRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // compatibility see funtion above
421 Int_t GetMinorRawVersion() const {return fHC ? fHC->fRawVMinor : -1;} // minor raw version
423 Int_t GetSM() const {return fHC ? fHC->fSM : -1;} // Position of CURRENT half chamber in full TRD
424 Int_t GetLayer() const {return fHC ? fHC->fLayer : -1;} // PLANE = Position of CURRENT half chamber in full TRD
425 Int_t GetStack() const {return fHC ? fHC->fStack : -1;} // CHAMBER = Position of CURRENT half chamber in full TRD
426 Int_t GetSide() const {return fHC ? fHC->fSide : -1;} // get side
427 Int_t GetDCS() const { return fHC ? fHC->fDCSboard : -1;} // DCS board number read from data (HC header)
428 //Int_t GetDCSboard() {return fHC ? fHC->fDCSboard : -1;} // DCS board number read from data (HC header)
429 Int_t GetROC() const { return fHC ? fHC->fROC : -1;} // Position of CURRENT half chamber in full TRD
430 Int_t GetNumberOfTimeBins() const { return fHC ? fHC->fTimeBins : 0;} // Get Ntime bins
431 UInt_t GetBunchCrossCounter() const {return fHC ? fHC->fBunchCrossCounter : 0;} // get bunch cross counter
432 UInt_t GetPreTriggerCounter() const {return fHC ? fHC->fPreTriggerCounter : 0;} // get pre trigger info
433 UInt_t GetPreTriggerPhase() const {return fHC ? fHC->fPreTriggerPhase : 0;} // get trigger phase
435 Int_t GetRow() const {return fMCM ? fMCM->fROW : -1;} // get current row number
436 Int_t GetCol() const {return fADC ? fADC->fCOL : -1;} // get current column number
437 Int_t GetRowMax() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC
438 Int_t GetColMax() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC
440 Int_t GetMaxRow() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC
441 Int_t GetMaxCol() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC
443 UInt_t GetHCword0() const {return fHC ? *fHC->fPos[0] : 0;} // get the HC word 0
444 UInt_t GetHCword1() const {return fHC ? *fHC->fPos[1] : 0;} // get the HC word 1
446 Int_t GetDET() const {return fHC ? fHC->fDET : -1;} // get current det number
447 Int_t GetDet() const {return fHC ? fHC->fDET : -1;} // get current det number
449 Int_t GetROB() const {return fMCM ? fMCM->fROB : -1;} // get current ROB number
450 Int_t GetMCM() const {return fMCM ? fMCM->fMCM : -1;} // get current MCM number
451 Int_t GetEventNumber() const { return fMCM->fEvCounter;} // MCM Event number and position of current MCM on TRD chamber
453 Int_t IsMCMcorrupted() const {return fMCM ? fMCM->fCorrupted : -1;} // is current MCM header corrupted
455 Int_t *GetSignals() const { return fADC ? fADC->fSignals : (Int_t *)fgEmptySignals;}//Signals in the n-time bins from Data Word
456 Int_t GetADC() const { return fADC ? fADC->fADCnumber : -1 ;} // MCM ADC channel and Time Bin of word 1
457 Int_t GetTimeBin() const { return 0;} // MCM ADC channel and Time Bin of word 1
459 //----------------------------------------------------------
461 static void SetNoDebug() {fgDebugFlag = kFALSE;} // allow debug info
462 static void SetNoErrorWarning() {fgWarnError = kFALSE;} // disable warning and error info
463 static void SetForceCleanDataOnly() {fgCleanDataOnly = kTRUE;} // clean data only
464 static void AllowCorruptedData() {fgCleanDataOnly = kFALSE;} // accept corrupted data
466 static void SetExtraWordsFix() {fgExtraSkip = kTRUE;} // extra skip of 24 32-bit words
467 static void SetSkipCDH() {fgSkipCDH = kTRUE;} // skip of 8 32-bit words
468 void EnableDebug(TTreeSRedirector *debugStream = 0); // enable the debug stream - use the paramter if non zero
469 static void EnableDebugStream() {fgDebugStreamFlag = kTRUE;} //global enable of the dbug stream
470 static void DeleteDebugStream(); // helper function to delete the debug streamer
471 static void SetDumpHead(UInt_t iv) {fgDumpHead = iv;}
472 static void DisableStackNumberChecker() {fgStackNumberChecker = kFALSE;} // set false to cleanroom data
474 // this is a temporary solution!
475 // baseline should come with the HC header word 2 (count from 0!)
476 static void SetSubtractBaseline(Int_t baseline) {fgCommonAdditive = baseline;}
477 Int_t GetCommonAdditive() const {return fgCommonAdditive;} // return the common additive
479 void DumpErrorCount();
480 void ReSetStreamEventCounter(Int_t ival = 0) {fgStreamEventCounter = ival;} // reset the event counter for the debug streamer
482 //--------------------------------------------------------
483 // Decoding functions
484 //--------------------------------------------------------
486 void DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const ;
487 const char *DumpSMInfo(const struct AliTRDrawSM *sm);
488 void DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const;
489 const char *DumpStackInfo(const struct AliTRDrawStack *st);
490 void DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const;
491 void DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const;
492 const char *DumpHCinfoH0(const struct AliTRDrawHC *hc);
493 const char *DumpHCinfoH1(const struct AliTRDrawHC *hc);
494 void DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const;
495 UInt_t GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const;
496 void DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const;
497 void MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const;
498 const char *DumpMCMinfo(const struct AliTRDrawMCM *mcm);
499 const char *DumpMCMadcMask(const struct AliTRDrawMCM *mcm);
505 Bool_t InitBuffer(void *buffer, UInt_t length); // init the buffer - called by DecodeSM(void*, UInt_t)
506 Bool_t DumpWords(UInt_t *px, UInt_t iw, UInt_t marker = 0); // dump some words onto the screen
508 Int_t NextBuffer(); // go and init next buffer if available - check the implementation file for return values
510 void SwapOnEndian(); // swap if endian is BIG
511 Bool_t SkipWords(UInt_t iw); // skip number of words
512 Bool_t DecodeTracklets(); // decode tracklets
513 Bool_t DecodeHC(); // decode data in HC
515 Bool_t DecodeADC(); // decode 10 ADC words
517 Bool_t DecodeHCheader(); // decode HC header
518 Bool_t SeekEndOfData(); // go to next end of raw data marker (actually 1 word after)
519 Bool_t SeekNextMCMheader(); // go to next mcm header
520 Bool_t DecodeMCMheader(); // decode mcm header
522 Bool_t IsRowValid(); // check if row within the range
523 Bool_t IsHCheaderOK(); // check if current hc header data make sense
524 Bool_t IsMCMheaderOK(); // check if current mcm header data make sense
526 void ResetCounters(); // reset some counters
527 void ResetIterators(); // needed for Next()
528 AliTRDrawStreamTB(const AliTRDrawStreamTB& st);
529 AliTRDrawStreamTB &operator=(const AliTRDrawStreamTB &);
531 // ----------------- DATA MEMBERS START
533 struct AliTRDrawSM fSM; // one SM per buffer
534 struct AliTRDrawStack *fStack; //! pointer to the current stack
535 struct AliTRDrawHC *fHC; //! current HC
536 struct AliTRDrawMCM *fMCM; //! current MCM
537 struct AliTRDrawADC *fADC; //! current ADC
539 UInt_t *fpPos; // current position in the buffer
540 UInt_t *fpBegin; // begin - pointer to the buffer word 0
541 UInt_t *fpEnd; // end of the buffer
543 UInt_t fWordLength; // length of the buffer in 32bit words
545 Int_t fStackNumber; // current stack number
546 Int_t fStackLinkNumber; // current link in the stack
548 Int_t fhcMCMcounter; // mcm counter inside single hc - used in Next()
549 Int_t fmcmADCcounter; // adc counrer inside single adc - used in Next()
551 Int_t fLinkTrackletCounter; // count the tracklets in the current HC
552 Int_t fEndOfTrackletCount; // count link by link (hc by hc) used for debug
554 UInt_t fMaskADCword; // temp mask when decoding adcs
555 UInt_t fTbinADC; // temp adc
556 Int_t fDecodedADCs; // counter of decoded adcs
558 UInt_t fEventCounter; // stores the valid/current MCM event counter
559 UInt_t fLastEventCounter; // last known event counter of MCM
561 Bool_t fSharedPadsOn; // do we want to output shared pads - default is off
562 Int_t fMaxADCgeom; // maximum ADC channels per mcm
564 AliTRDgeometry *fGeometry; //! TRD geometry
565 AliRawReader *fRawReader; //! raw reader
567 AliTRDfeeParam *fTRDfeeParam; // pointer to the fee params
569 Bool_t fDebugStreamOwned; // created in this case by this - allowed to delete?
573 static Bool_t fgExtraSkip; // whether we should skip the leading 24 words
574 static Bool_t fgSkipCDH; // whether we should skip CDH (8 words)
575 static Bool_t fgWarnError; // no errors no warnings
576 static Bool_t fgCleanDataOnly; // release only clean events = no errors
577 static Bool_t fgDebugFlag; // allow debugging info
578 static Bool_t fgDebugStreamFlag; // set on debug streamer
579 static Bool_t fgStackNumberChecker; // decide if we check stack number insanity - set false to cleanroom data
580 static TTreeSRedirector *fgDebugStreamer; //!Debug streamer
581 static UInt_t fgStreamEventCounter; // event counter for debug streamer
582 static UInt_t fgDumpHead; // number of words to dump (from the start of the buffer) on each Init
583 static Int_t fgEmptySignals[30]; // empty signals in case of ADC pointer = NULL
586 // this is a temporary solution!
587 // baseline should come with the HC header word 2 (count from 0!)
588 static Int_t fgCommonAdditive; // common additive - should be decoded! from HC word2
590 // ----------------- DATA MEMBERS STOP
592 enum ETRDzRawStreamError
594 kDecodeStackInfo = 1 //
595 , kMissingData = 2 //
596 , kLinkDataMissing = 3 //
597 , kHCdataMissing = 4 //
598 , kTrackletOverflow = 5 //
599 , kEOTrackeltsMissing = 6 //
600 , kWrongPadrow = 7 //
601 , kMCMheaderCorrupted = 8 //
602 , kWrongMCMorROB = 9 //
603 , kMCMeventMissmatch = 10 //
604 , kMCMADCMaskMissing = 11 //
605 , kHCHeaderCorrupt = 12 //
606 , kHCHeaderWrongStack = 13 //
607 , kHCHeaderWrongLayer = 14 //
608 , kHCHeaderWrongSide = 15 //
609 , kHCHeaderWrongSM = 16 //
610 , kHCHeaderWrongDet = 17 //
611 , kHCHeaderWrongROC = 18 //
612 , kHCWordMissing = 19 //
613 , kMCMdataMissing = 20 //
614 , kMCMoverflow = 21 //
615 , kADCdataMissing = 22 //
616 , kADCmaskMissmatch = 23 //
617 , kWrongPadcolumn = 24 //
620 ClassDef(AliTRDrawStreamTB, 0)