1 #ifndef ALITRDRAWSTREAMTB_H
2 #define ALITRDRAWSTREAMTB_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
8 ///////////////////////////////////////////////////////////////////////////////
10 // This class provides access to TRD digits in raw data. //
12 ///////////////////////////////////////////////////////////////////////////////
18 class AliTRDdigitsManager;
20 namespace AliTRDrawDataUtilsTB
22 //--------------------------------------------------------
24 //static const UInt_t kEndoftrackletmarker = 0xAAAAAAAA; /*This marks the end of tracklet data words*/
25 //static const UInt_t kEndOfTrackletMarker = 0x10001000; /*This marks the end of tracklet data words*/
26 static const UInt_t kEndOfTrackletMarker = 0xaaaaaaaa; /*This marks the end of tracklet data words*/
27 //static const UInt_t kEndofrawdatamarker = 0x00000000; /*This marks the end of half-chamber-data*/
28 static const UInt_t kEndOfRawDataMarker = 0x00000000; /*This marks the end of half-chamber-data*/
29 static const UInt_t kSizeWord = sizeof(UInt_t); // size of a word in bytes
31 //--------------------------------------------------------
32 // SM index word masks
33 static const UInt_t skSMheaderSizeBits = 0xffff0000;
34 static const UInt_t skTrackletsEnableBits = 0x1 << 5;
35 static const UInt_t skStackMasksBits = 0x1f;
37 static UInt_t GetSMheaderSize(UInt_t *word)
39 return (*word & skSMheaderSizeBits) >> 16;
42 static UInt_t GetTrackletEnable(UInt_t *word)
44 return (*word & skTrackletsEnableBits) >> 5;
47 static UInt_t GetStackMask(UInt_t *word)
49 return (*word & skStackMasksBits);
52 /* static UInt_t GetStackStatus(UInt_t *word, Int_t istack) */
54 /* return (*word & (0x1 << istack)); */
57 //--------------------------------------------------------
58 struct AliTRDrawSMinfo
61 Bool_t fTrackletEnable;
62 Bool_t fStackActive[5];
65 void Decode(UInt_t *word)
67 fHeaderSize = GetSMheaderSize(word);
69 if (GetTrackletEnable(word) > 0)
70 fTrackletEnable = kTRUE;
72 fTrackletEnable = kFALSE;
74 UInt_t stackMask = GetStackMask(word);
76 for (Int_t i = 0; i < 5; i++)
78 //if (stackMask & (0x1 << i) > 0)
79 if ((stackMask >> i) & 0x1 > 0)
81 fStackActive[i] = kTRUE;
86 fStackActive[i] = kFALSE;
93 printf("[I] SM Info is : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d\n",
94 fHeaderSize, fTrackletEnable,
95 fStackActive[0], fStackActive[1], fStackActive[2],
96 fStackActive[3], fStackActive[4]);
101 //--------------------------------------------------------
103 static const UInt_t skStackHeaderSizeBits = 0xffff0000;
104 static const UInt_t skStackLinkMaskBits = 0xfff;
106 static UInt_t GetStackHeaderSize(UInt_t *word)
108 return (*word & skStackHeaderSizeBits) >> 16;
111 static UInt_t GetStackLinkWord(UInt_t *word)
113 return (*word & skStackLinkMaskBits);
116 static UInt_t GetStackHeaderSizeBug(UInt_t *word)
118 return (*word & 0x0000ffff);
121 static UInt_t GetStackLinkWordBug(UInt_t *word)
123 return (*word & 0x0fff) >> 16;
126 struct AliTRDrawStackInfo
129 Bool_t fLinksActive[12];
132 void Decode(UInt_t *word)
134 fHeaderSize = GetStackHeaderSize(word);
136 UInt_t linkMask = GetStackLinkWord(word);
138 for (Int_t i = 0; i < 12; i++)
140 if (linkMask & (0x1 << i) > 0)
142 fLinksActive[i] = kTRUE;
147 fLinksActive[i] = kFALSE;
152 void DecodeBug(UInt_t *word)
154 fHeaderSize = GetStackHeaderSizeBug(word);
156 UInt_t linkMask = GetStackLinkWordBug(word);
157 for (Int_t i = 0; i < 12; i++)
159 if (linkMask & (0x1 << i) > 0)
160 fLinksActive[i] = kTRUE;
162 fLinksActive[i] = kFALSE;
168 printf("[I] Stack Info is : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d\n",
170 fLinksActive[0], fLinksActive[1], fLinksActive[2], fLinksActive[3],
171 fLinksActive[4], fLinksActive[5], fLinksActive[6], fLinksActive[7],
172 fLinksActive[8], fLinksActive[9], fLinksActive[10], fLinksActive[11]);
176 //--------------------------------------------------------
179 static const UInt_t skSpecialRawVBits = 0x1 << 31;
180 static const UInt_t skRawVMajorBits = 0x7f << 24;
181 static const UInt_t skRawVMinorBits = 0x7f << 17;
182 static const UInt_t skHCExtraWordsBits = 0x7 << 14;
183 static const UInt_t skHCSMBits = 0x1f << 9;
184 static const UInt_t skHCLayerBits = 0x7 << 6;
185 static const UInt_t skHCStackBits = 0x7 << 3;
186 static const UInt_t skHCSideBits = 0x1 << 2;
188 static const UInt_t skDCSBoardBits = 0xfff << 20;
190 static UInt_t GetSpecialRawV(UInt_t *word)
192 return (*word & skSpecialRawVBits) >> 31;
195 static UInt_t GetRawVMajor(UInt_t *word)
197 return (*word & skRawVMajorBits) >> 24;
200 static UInt_t GetRawVMinor(UInt_t *word)
202 return (*word & skRawVMinorBits) >> 31;
205 static UInt_t GetDCSBoard(UInt_t *word)
207 return (*word & skDCSBoardBits) >> 20;
210 static UInt_t GetSM(UInt_t *word)
212 return (*word & skHCSMBits) >> 9;
215 static UInt_t GetStack(UInt_t *word)
217 return (*word & skHCStackBits) >> 3;
220 static UInt_t GetLayer(UInt_t *word)
222 return (*word & skHCLayerBits) >> 6;
225 static UInt_t GetSide(UInt_t *word)
227 return (*word & skHCSideBits) >> 2;
230 static UInt_t GetExtraWords(UInt_t *word)
232 return (*word & skHCExtraWordsBits) >> 14;
233 //fHCHWords = (*fDataWord >> 14) & 0x7;
237 //static const UInt_t skTimeBinsBits = 0xfc << 26;
238 static const UInt_t skTimeBinsBits = 0x3f << 26;
239 static const UInt_t skBunchCrossCounterBits = 0xffff << 10;
240 static const UInt_t skPreTriggerCounterBits = 0xf << 6;
241 static const UInt_t skPreTriggerPhase = 0xf << 2;
243 static UInt_t GetTimeBins(UInt_t *word)
245 return (*word & skTimeBinsBits) >> 26;
248 static UInt_t GetBunchCrossCounter(UInt_t *word)
250 return (*word & skBunchCrossCounterBits) >> 10;
253 static UInt_t GetPreTriggerCounter(UInt_t *word)
255 return (*word & skPreTriggerCounterBits) >> 6;
258 static UInt_t GetPreTriggerPhase(UInt_t *word)
260 return (*word & skPreTriggerPhase) >> 2;
263 struct AliTRDrawHCInfo
275 /* fBCctr = (*fDataWord >> 16); */
276 /* fPTctr = (*fDataWord >> 12) & 0xf; */
277 /* fPTphase = (*fDataWord >> 8) & 0xf; */
278 /* fTBins = ((*fDataWord >> 2) & 0x3f) + 1; */
279 /* fTimeWords = (fTBins - 1)/3 + 1; */
282 UInt_t fBunchCrossCounter;
283 UInt_t fPreTriggerCounter;
284 UInt_t fPreTriggerPhase;
286 void DecodeH0(UInt_t *word)
288 fSpecialRawV = GetSpecialRawV(word);
289 fRawVMajor = GetRawVMajor(word);
290 fRawVMinor = GetRawVMinor(word);
291 fNExtraWords = GetExtraWords(word);
292 fDCSboard = GetDCSBoard(word);
294 fStack = GetStack(word);
295 fLayer = GetLayer(word);
296 fSide = GetSide(word);
299 void DecodeH1(UInt_t *word)
301 fTimeBins = GetTimeBins(word);
302 fBunchCrossCounter = GetBunchCrossCounter(word);
303 fPreTriggerCounter = GetPreTriggerCounter(word);
304 fPreTriggerPhase = GetPreTriggerPhase(word);
309 /* printf("[I] HC Info is : DCSboard %d SM %d Stack %d Layer %d Side %d \n", */
310 /* fDCSboard, fSM, fStack, fLayer, fSide); */
311 printf("[I] HC Info is : RawV %d SM %d Stack %d Layer %d Side %d \n",
312 fRawVMajor, fSM, fStack, fLayer, fSide);
316 //--------------------------------------------------------
318 static const UInt_t skROBBits = 0x70000000; // 0x7 << 28
319 static const UInt_t skMCMBits = 0x0f000000; // 0xf << 24
320 static const UInt_t skHCEvCounterBits = 0x00fffff0; //0x00fffff << 4
322 static UInt_t GetROB(UInt_t *word)
324 return (*word & skROBBits) >> 28;
327 static UInt_t GetMCM(UInt_t *word)
329 return (*word & skMCMBits) >> 24;
332 static UInt_t GetEvCounter(UInt_t *word)
334 return (*word & skHCEvCounterBits) >> 4;
337 struct AliTRDrawMCMInfo
343 void Decode(UInt_t *word)
347 fEvCounter = GetEvCounter(word);
352 printf("[I] MCM Info is : ROB %d MCM %d EvCounter %d\n", fROB, fMCM, fEvCounter);
358 class AliTRDRawStreamTB: public TObject {
363 AliTRDRawStreamTB(AliRawReader *rawReader);
364 virtual ~AliTRDRawStreamTB();
366 virtual Bool_t Next(); // Read the next data
367 virtual Int_t NextChamber(AliTRDdigitsManager *man); // read next chamber data
368 virtual Int_t Init(); // Init for the fRawVersion > 1
370 enum { kDDLOffset = 0x400 }; // Offset for DDL numbers
372 Bool_t SetRawVersion(Int_t rv);
373 Int_t GetRawVersion() const { return fRawVersion; };
374 void SetRawReader(AliRawReader *rawReader);
376 // Get Filter settings (does not make a lot of sense):
377 Int_t TRAPfilterTCon() const { return fTCon; };
378 Int_t TRAPfilterPEDon() const { return fPEDon; };
379 Int_t TRAPfilterGAINon() const { return fGAINon; };
380 Int_t TRAPsendsUnfilteredData() const { return fBypass; };
382 // Get Tracklet parameters (does not make a lot of sense):
383 Float_t GetTrackletPID() const { return fTracklPID; };
384 Float_t GetTrackletDeflLength() const { return fTracklDefL; };
385 Float_t GetTrackletPadPos() const { return fTracklPadPos; };
386 Int_t GetTrackletPadRow() const { return fTracklPadRow; };
388 // Check if the link has optical power (HC sends data)
389 Bool_t IsGTULinkActive(Int_t sm, Int_t la, Int_t sta, Int_t side)
390 { return ( ((fGTUlinkMask[sm][sta]) >> (2*la+side)) & 0x1 ); };
392 static void SetStackIndexBug(Bool_t val) {fgStackIndexBug = val;}
393 static void SetForceRawVersion(Int_t val) {fgForceRawVersion = val;}
394 static void SupressWarnings(Bool_t val) {fgSupressWarnings = val;}
395 static void ExtraDebug(Bool_t val) {fgExtraDebug = val;}
396 static void RawBufferMissAligned(Bool_t val) {fgRawDataHack = val;}
398 Int_t *GetSignals() { return fSig;} // Signals in the three time bins from Data Word
399 Int_t GetADC() const { return fADC;} // MCM ADC channel and Time Bin of word 1
400 Int_t GetTimeBin() const { return fTB - 3;} // MCM ADC channel and Time Bin of word 1
401 Int_t GetEventNumber() const { return fEv;} // MCM Event number and position of current MCM on TRD chamber
402 Int_t GetROB() const { return fROB;} // MCM Event number and position of current MCM on TRD chamber
403 Int_t GetMCM() const { return fMCM;} // MCM Event number and position of current MCM on TRD chamber
404 Int_t GetSM() const { return fSM;} // Position of CURRENT half chamber in full TRD
405 Int_t GetLayer() const { return fLAYER;} // PLANE = Position of CURRENT half chamber in full TRD
406 Int_t GetStack() const { return fSTACK;} // CHAMBER = Position of CURRENT half chamber in full TRD
407 Int_t GetROC() const { return fROC;} // Position of CURRENT half chamber in full TRD
408 Int_t GetSide() const { return fSIDE;} // Position of CURRENT half chamber in full TRD
409 Int_t GetDCS() const { return fDCS;} // DCS board number read from data (HC header)
410 Int_t GetRow() const { return fROW;}
411 Int_t GetCol() const { return fCOL;} // Detector Pad coordinates
412 Int_t GetDet() const { return fDET;} // helper
413 Int_t GetLastDet() const { return fLastDET;} // helper
414 Int_t GetMaxRow() const { return fRowMax;}
415 Int_t GetMaxCol() const { return fColMax;}
416 Int_t GetNumberOfTimeBins() const {return fTBins;}
418 Int_t GetCommonAdditive() const {return fCommonAdditive;}
419 Bool_t IsCurrentPadShared() const {return fIsPadShared;}
420 void SetSharedPadReadout(Bool_t fv) {fSharedPadsOn = fv;}
421 Bool_t IsDataZeroSuppressed() const {return fZeroSuppressed;}
425 Int_t fSig[3]; // Signals in the three time bins from Data Word
426 Int_t fADC; // MCM ADC channel and Time Bin of word 1
427 Int_t fMaxADCgeom; // Max ADC number as returned by AliTRDgeometry::ADCmax()
428 Int_t fTB; // MCM ADC channel and Time Bin of word 1
429 Int_t fEv; // MCM Event number and position of current MCM on TRD chamber
430 Int_t fROB; // MCM Event number and position of current MCM on TRD chamber
431 Int_t fMCM; // MCM Event number and position of current MCM on TRD chamber
432 Int_t fSM; // Position of CURRENT half chamber in full TRD
433 Int_t fLAYER; // Position of CURRENT half chamber in full TRD
434 Int_t fSTACK; // Position of CURRENT half chamber in full TRD
435 Int_t fROC; // Position of CURRENT half chamber in full TRD
436 Int_t fSIDE; // Position of CURRENT half chamber in full TRD
437 Int_t fDCS; // DCS board number read from data (HC header)
438 Int_t fROW; // Detector Row coordinates
439 Int_t fCOL; // Detector Pad coordinates
440 Int_t fDET; // Current detector - version > 1
441 Int_t fLastDET; // Previous detector - version > 1
443 Int_t fBCctr; // Counters from HC header (>=V2)
444 Int_t fPTctr; // Counters from HC header (>=V2)
445 Int_t fPTphase; // Counters from HC header (>=V2)
446 Int_t fRVmajor; // Raw version numbers and number of additional HC headerwords (>=V2)
447 Int_t fRVminor; // Raw version numbers and number of additional HC headerwords (>=V2)
448 Int_t fHCHWords; // Raw version numbers and number of additional HC headerwords (>=V2)
449 Int_t fTBins; // Number of time bins read from HC header (>=V2)
450 Bool_t fTCon; // Filter settings read from HC header (>=V2)
451 Bool_t fPEDon; // Filter settings read from HC header (>=V2)
452 Bool_t fGAINon; // Filter settings read from HC header (>=V2)
453 Bool_t fXTon; // Filter settings read from HC header (>=V2)
454 Bool_t fNonLinOn; // Filter settings read from HC header (>=V2)
455 Bool_t fBypass; // Filter settings read from HC header (>=V2)
456 Int_t fCommonAdditive; // Common baseline additive read from HC header (>=V2)
458 Bool_t fZeroSuppressed; // Data is zero suppressed
460 Int_t fHCHctr1; // HC and MCM Header counter
461 Int_t fHCHctr2; // HC and MCM Header counter
462 Int_t fMCMHctr1; // HC and MCM Header counter
463 Int_t fMCMHctr2; // HC and MCM Header counter
464 Int_t fGTUctr1; // GTU LinkMask Counter
465 Int_t fGTUctr2; // GTU LinkMask Counter
466 Int_t fHCdataCtr; // Data Counter for half chamber
468 Float_t fTracklPID; // Tracklet parameters
469 Float_t fTracklDefL; // Tracklet parameters
470 Float_t fTracklPadPos; // Tracklet parameters
471 Int_t fTracklPadRow; // Tracklet parameters
473 UShort_t fGTUlinkMask[18][5]; // Mask with active links
475 Int_t fMCMWordCrt; // Word Counter for a single MCM
476 Int_t fMCMWordsExpected; // Expected Words from MCM
478 AliTRDRawStreamTB(const AliTRDRawStreamTB &stream);
479 AliTRDRawStreamTB &operator=(const AliTRDRawStreamTB &stream);
482 AliRawReader *fRawReader; // Object for reading the raw data
484 Int_t fRawVersion; // Which version of raw data decoding is used
485 Int_t fRawDigitThreshold; // Naive "zero"(threshold) supression. Usefull for Raw Data ver 2.
487 Int_t fNextStatus; // Navigation in raw versions > 1
488 Int_t fLastStatus; // Navigation in raw versions > 1
489 UInt_t fTbSwitch; // Time Bin Switch for internal use
490 UInt_t fTbSwitchCtr; // Counter for internal use
491 UInt_t fTimeWords; // Number of Words needed to store the data of 1 ADC ch.
492 UInt_t fWordCtr; // Word Counter
494 Int_t fRowMax; // Maximum number of pad rows and columns
495 Int_t fColMax; // Maximum number of pad rows and columns
497 Bool_t fADCmask[21]; // Mask of active ADCs for zero suppression
498 UInt_t fLastADCmask; // Last ADC read out
500 Int_t fChamberDone[540]; // Chamber was processed already (1=1HC, 2=full chamber)
502 Int_t fRetVal; // Datadecode return
503 Int_t fEqID; // Equipment id
504 UInt_t fDataSize; // Size of the data available in the current buffer
505 Bool_t fSizeOK; // Did we read anything
506 UInt_t fCountBytes; // Bytes traversed in the buffer
507 UInt_t fBufSize; // Size of the current RawReader buffer
508 Bool_t fkBufferSet; // Is the RawReader buffer available
509 UChar_t *fPos; // Position in the buffer of the RawReader
510 UInt_t *fDataWord; // The pointer to the current 32 bit data word
511 UInt_t fTimeBinsCalib; // N of time bins retrieved from calibration
513 Int_t fADClookup[32]; // Lookup for version 3 (1[entries]+1[index]+30[fADC channels] = 32)
514 Int_t fNActiveADCs; // Number of active ADC channels
515 Bool_t fEndOfDataFlag; // End of data flag
517 AliTRDrawDataUtilsTB::AliTRDrawSMinfo fSMinfo[18]; // Super module info
518 AliTRDrawDataUtilsTB::AliTRDrawStackInfo fStackInfo[18][5]; // Stack info
519 AliTRDrawDataUtilsTB::AliTRDrawHCInfo fHCInfo; // Half chamber info
520 AliTRDrawDataUtilsTB::AliTRDrawMCMInfo fMCMInfo; // MCM info
522 Int_t fiSMx; // Position of CURRENT half chamber in full TRD
523 static Bool_t fgStackIndexBug; // Buggy index word flag
525 Bool_t fSharedPadsOn; // Should we return on shared pad readout
526 Bool_t fIsPadShared; // Set if the current pad is shared
527 static Int_t fgForceRawVersion; // Force the raw version specified
528 static Bool_t fgSupressWarnings; // Superss warnings (raw data version and TB missmatch)
529 static Bool_t fgExtraDebug; // Extra info on the screen
530 static Bool_t fgRawDataHack; // skip 23 words - a hack for the DATE raw format
531 enum ETRDzRawStreamError {
532 kHCWordMissing = 1 //
533 ,kMCMADCMaskMissing = 2 //
534 ,kWrongMCMorROB = 3 //
535 ,kGTULinkMaskMissing = 4 //
536 ,kHCHeaderCorrupt = 5 //
537 ,kHCHeaderMissing = 6 //
538 ,kROBSideMismatch = 7 //
540 ,kWrongPadcolumn = 9 //
541 ,kTrackletRowMismatch = 10 //
542 ,kDataMaskError = 11 //
543 ,kADCNumberOverflow = 12 //
544 ,kADCChannelOverflow = 13 //
549 AliTRDgeometry *fGeo; // TRD geometry
551 Bool_t DecodeGTUlinkMask();
552 Bool_t DecodeADCWord();
553 Bool_t DecodeNextRawWord();
557 inline void ChangeStatus(Int_t kstat);
559 void DecodeHCheader(Int_t timeBins = 0);
560 void DecodeMCMheader();
561 void DecodeTracklet();
563 void SetRawDigitThreshold (Int_t ith) {fRawDigitThreshold = ith;} // set the naive zero suppression threshold
565 Int_t NextData(); // get the next piece of memory
566 Int_t RewindWord(); //go back one word
568 Int_t ChannelsToRead(Int_t ADCmask); // Get the active ADC channels from the mask (V3 and 2)
570 Int_t SkipWords(UInt_t iw);
571 Int_t DecodeHeadingInfo();
585 ClassDef(AliTRDRawStreamTB, 1) // Class for reading TRD raw digits