]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDrawStreamTB.h
Radical performance improvement
[u/mrichter/AliRoot.git] / TRD / AliTRDrawStreamTB.h
CommitLineData
d4232bb6 1#ifndef ALITRDRAWSTREAMTB_H
2#define ALITRDRAWSTREAMTB_H
3
4/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
6
7/* $Id$ */
8
9///////////////////////////////////////////////////////////////////////////////
10// //
11// This class provides access to TRD digits in raw data. //
12// //
13///////////////////////////////////////////////////////////////////////////////
14
15#include "TObject.h"
16#include "TString.h"
17
18class AliTRDgeometry;
19class AliRawReader;
20class AliTRDdigitsManager;
21class TTreeSRedirector;
22class AliTRDfeeParam;
23
24#define TRD_MAX_TBINS 30
25#define TRD_MAX_ADC 21
26#define TRD_MAX_MCM 4 * 16
27
28class AliTRDrawStreamTB : public TObject
29{ // class def begin
30
31 public:
32
33 //--------------------------------------------------------
34
35 // THE STRUCTURES
36
37 //--------------------------------------------------------
38
39 struct AliTRDrawADC
40 {//adc struct
41
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
48
49 AliTRDrawADC()
50 : fPos(0)
51 , fADCnumber(0)
52 , fCOL(0)
53 , fSignals()
54 , fIsShared(kFALSE)
55 , fCorrupted(0)
56 {
57 // default constructor
58 ;
59 }
60
61 };
62
63 //--------------------------------------------------------
64
65 struct AliTRDrawMCM
66 { // mcm struct
67 Int_t fROB; // ROB number
68 Int_t fMCM; // MCM number
69 Int_t fROW; //filed during decoding!
70
71 UInt_t fEvCounter; // MCM event counter
72 UInt_t fADCMask; // ADC mask
73 UInt_t fADCMaskWord; // word with ADC mask in
74 UInt_t fADCchannel[30]; // channels to be decoded accrording to ADC mask
75
76 Int_t fADCindex; // index of current ADC (comment: 1 ADC is 1 pad)
77 Int_t fADCmax; // number of ADCs fired
78 Int_t fMCMADCWords; // mcm words to expect
79 Int_t fSingleADCwords; // n of words per ADC
80
81 Int_t fCorrupted; // is mcm word corrupted
82
83 UInt_t fErrorCounter; // count the mcm header errors
84 UInt_t fMaskErrorCounter; // count the adc mask errors
85
86 UInt_t *fPos; //! position of mcm header in the buffer
87 UInt_t *fAdcDataPos; //! start of ADC data for this mcm
88
89 Int_t fADCcounter; // count the adcs decoded
90 AliTRDrawADC fADCs[TRD_MAX_ADC]; // 21 adcs
91
92 AliTRDrawMCM()
93 : fROB(-1)
94 , fMCM(-1)
95 , fROW(-1)
96 , fEvCounter(0)
97 , fADCMask(0)
98 , fADCMaskWord(0)
99 , fADCchannel()
100 , fADCindex(0)
101 , fADCmax(0)
102 , fMCMADCWords(0)
103 , fSingleADCwords(0)
104 , fCorrupted(0)
105 , fErrorCounter(0)
106 , fMaskErrorCounter(0)
107 , fPos(0)
108 , fAdcDataPos(0)
109 , fADCcounter(0)
110 , fADCs()
111 {
112 // default constructor
113 /* the following violates coding conventions */
114 //for (Int_t i = 0; i < 30; i++) fADCchannel[i] = 0;
115 }
116 };
117
118 //--------------------------------------------------------
119
120 struct AliTRDrawHC
121 { // hc struct
122 // global
123 Int_t fCorrupted; // Zero if not corrupted
124
125 UInt_t fH0ErrorCounter; // Count the H0 word errors
126 UInt_t fH1ErrorCounter; // Count the H1 word errors
127
128 // word 0
129 Int_t fSpecialRawV; // Raw data version
130 Int_t fRawVMajor; // Raw data version
131 Int_t fRawVMinor; // Raw data version
132 Int_t fNExtraWords; // N extra HC header words
133 Int_t fDCSboard; // DCS board number
134 Int_t fSM; // Super Module number
135 Int_t fStack; // Stack number (some people might call it a chamber)
136 Int_t fLayer; // Layer number (some people might call it a plane)
137 Int_t fSide; // Side of HC
138
139 //word 1
140 Int_t fTimeBins; // N of t bins
141 UInt_t fBunchCrossCounter; // Bunch crossing counter
142 UInt_t fPreTriggerCounter; // Pre Trigger counter
143 UInt_t fPreTriggerPhase; // Pre Trigger phase
144
145 UInt_t *fPos[2]; //! position of the header words in buffer
146
147 Int_t fDET; // filled while decoding
148 Int_t fROC; // filled while decoding
149 Int_t fRowMax; // filled while decoding
150 Int_t fColMax; // filled while decoding
151
152 //AliTRDrawMCM fMCMs[4][16]; // 4 ROBS 16 each - that is max!
153 Int_t fMCMmax; // number of mcm found
154 AliTRDrawMCM fMCMs[TRD_MAX_MCM]; // 4 ROBS 16 each - that is max!
155
156 AliTRDrawHC()
157 : fCorrupted(0)
158 , fH0ErrorCounter(0)
159 , fH1ErrorCounter(0)
160 , fSpecialRawV(0)
161 , fRawVMajor(0)
162 , fRawVMinor(0)
163 , fNExtraWords(0)
164 , fDCSboard(-1)
165 , fSM(-1)
166 , fStack(-1)
167 , fLayer(-1)
168 , fSide(-1)
169 , fTimeBins(0)
170 , fBunchCrossCounter(0)
171 , fPreTriggerCounter(0)
172 , fPreTriggerPhase(0)
173 , fPos()
174 , fDET(-1)
175 , fROC(-1)
176 , fRowMax(-1)
177 , fColMax(-1)
178 , fMCMmax(0)
179 , fMCMs()
180 {
181 // default constructor hc info
182 /* the following violates coding conventions */
183 //fPos[0] = fPos[0] = 0;
184 }
185 };
186
187 //--------------------------------------------------------
188
189 struct AliTRDrawStack
190 {
191 UInt_t fHeaderSize; // header size of the stack info
192 Bool_t fLinksActive[12]; // data links active - 1 per half chamber
193 Bool_t fTrackletDecode[12]; // book keeping while decoding - set false after decoding
194 Bool_t fHCDecode[12]; // book keeping while decoding - set false after HC header decoding
195 Int_t fActiveLinks; // number of active links
196 UInt_t *fPos; //! position in the buffer
197
198 AliTRDrawHC fHalfChambers[12]; // 6 chambers in a stack
199
200 AliTRDrawStack()
201 : fHeaderSize(0)
202 , fLinksActive()
203 , fTrackletDecode() //book keeping while decoding - set false after decoding
204 , fHCDecode() //book keeping while decoding - set false after HC header decoding
205 , fActiveLinks(0)
206 , fPos(0)
207 , fHalfChambers()
208 {
209 // default constructor
210 }
211 };
212
213 /* the following violates coding conventions */
214/* for (Int_t i = 0; i < 12; i++) */
215/* { */
216/* fLinksActive[i] = fTrackletDecode[i] = fHCDecode[i] = kFALSE; */
217/* } */
218
219 //--------------------------------------------------------
220
221 struct AliTRDrawSM
222 {
223 UInt_t fHeaderSize; // size of the header in words
224 Bool_t fTrackletEnable; // tracklet enable bit
225 Bool_t fStackActive[5]; // map of active/expected stacks
226 Int_t fActiveStacks; // number of active stacks
227 Int_t fCorrupted; // is sm info corrupted
228 Int_t fNexpectedHalfChambers; // number of half chambers to be read out
229 Bool_t fClean; // true if everything went OK - false is some error occured
230 UInt_t *fPos; //! location of the sm info - should be the first word (after CDH if not DDL buffer)
231
232 AliTRDrawStack fStacks[5]; // we do have only five stacks ;)
233
234 AliTRDrawSM()
235 : fHeaderSize(0)
236 , fTrackletEnable(0)
237 , fStackActive()
238 , fActiveStacks(0)
239 , fCorrupted(0)
240 , fNexpectedHalfChambers(0)
241 , fClean(kTRUE)
242 , fPos(0)
243 , fStacks()
244 {
245 // Default constructor
246 // coding rule violation in the next line
247 //for (Int_t i = 0; i < 5; i++) fStackActive[i] = kFALSE;
248 };
249 };
250
251 //--------------------------------------------------------
252
253 AliTRDrawStreamTB();
254 AliTRDrawStreamTB(AliRawReader *rawReader);
255 virtual ~AliTRDrawStreamTB();
256
257 //--------------------------------------------------------
258
259 virtual Bool_t Next(); // Read the next data
260 virtual Int_t NextChamber(AliTRDdigitsManager *man); // read next chamber data
261 virtual Bool_t Init(); // Init some internal variables
262
263 void SetRawVersion(Int_t fraw); // set the raw version - used for backward compat.
264
d4232bb6 265 Bool_t IsCurrentPadShared() const {return fADC->fIsShared;} // is current pad shared between mcms
266 void SetSharedPadReadout(Bool_t fv) {fSharedPadsOn = fv;} // set the flag on if the reader should return the shared pads
267 Bool_t IsDataZeroSuppressed() const {return (fHC->fRawVMajor > 2) ? kTRUE : kFALSE;} // check the version and tell if ZS is on
268
269 Bool_t DecodeSM(void *buffer, UInt_t length); //decode a buffer
270 Int_t DecodeSM(); // used with raw reader
271 Int_t DecodeSM(AliRawReader *reader); // used with raw reader
272
273 Bool_t SetReader(AliRawReader *reader); // set the raw reader to use
274
275 Bool_t IsTrackletEnableBitSet() const {return fSM.fTrackletEnable;} // get status of the tracklets enable bit
276 Bool_t IsStackActive(Int_t is) const {return fSM.fStackActive[is];} // get status of a stack
277 Int_t GetNofActiveStacks() const {return fSM.fActiveStacks;} // get number of active stacks
278 UInt_t *GetSMstreamPosition() const {return fSM.fPos;} // get position of the SM index word in the buffer
279
280 Bool_t IsSMbufferClean() const {return fSM.fClean;} // is data clean
281
282 Bool_t IsLinkActiveInStack(Int_t is, Int_t il) const {return fSM.fStacks[is].fLinksActive[il];} // check whether the link is active
283 Int_t GetActiveLinksInStack(Int_t is) const {return fSM.fStacks[is].fActiveLinks;} //get active links in a stack
284
285 Int_t GetSpecialRawVersion() const {return fHC ? fHC->fSpecialRawV : -1;} // return special raw version
286 Int_t GetMajorRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // major raw version getter
287 Int_t GetRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // compatibility see funtion above
288 Int_t GetMinorRawVersion() const {return fHC ? fHC->fRawVMinor : -1;} // minor raw version
289
290 Int_t GetSM() const {return fHC ? fHC->fSM : -1;} // Position of CURRENT half chamber in full TRD
291 Int_t GetLayer() const {return fHC ? fHC->fLayer : -1;} // PLANE = Position of CURRENT half chamber in full TRD
292 Int_t GetStack() const {return fHC ? fHC->fStack : -1;} // CHAMBER = Position of CURRENT half chamber in full TRD
293 Int_t GetSide() const {return fHC ? fHC->fSide : -1;} // get side
294 Int_t GetDCS() const { return fHC ? fHC->fDCSboard : -1;} // DCS board number read from data (HC header)
295 //Int_t GetDCSboard() {return fHC ? fHC->fDCSboard : -1;} // DCS board number read from data (HC header)
296 Int_t GetROC() const { return fHC ? fHC->fROC : -1;} // Position of CURRENT half chamber in full TRD
297 Int_t GetNumberOfTimeBins() const { return fHC ? fHC->fTimeBins : 0;} // Get Ntime bins
298 UInt_t GetBunchCrossCounter() const {return fHC ? fHC->fBunchCrossCounter : 0;} // get bunch cross counter
299 UInt_t GetPreTriggerCounter() const {return fHC ? fHC->fPreTriggerCounter : 0;} // get pre trigger info
300 UInt_t GetPreTriggerPhase() const {return fHC ? fHC->fPreTriggerPhase : 0;} // get trigger phase
301
302 Int_t GetRow() const {return fMCM ? fMCM->fROW : -1;} // get current row number
303 Int_t GetCol() const {return fADC ? fADC->fCOL : -1;} // get current column number
304 Int_t GetRowMax() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC
305 Int_t GetColMax() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC
306 // compatibility
307 Int_t GetMaxRow() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC
308 Int_t GetMaxCol() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC
309
310 UInt_t GetHCword0() const {return fHC ? *fHC->fPos[0] : 0;} // get the HC word 0
311 UInt_t GetHCword1() const {return fHC ? *fHC->fPos[1] : 0;} // get the HC word 1
312
313 Int_t GetDET() const {return fHC ? fHC->fDET : -1;} // get current det number
314 Int_t GetDet() const {return fHC ? fHC->fDET : -1;} // get current det number
315
316 Int_t GetROB() const {return fMCM ? fMCM->fROB : -1;} // get current ROB number
317 Int_t GetMCM() const {return fMCM ? fMCM->fMCM : -1;} // get current MCM number
318 Int_t GetEventNumber() const { return fMCM->fEvCounter;} // MCM Event number and position of current MCM on TRD chamber
319
320 Int_t IsMCMcorrupted() const {return fMCM ? fMCM->fCorrupted : -1;} // is current MCM header corrupted
321
322 Int_t *GetSignals() const { return fADC ? fADC->fSignals : (Int_t *)fgEmptySignals;}//Signals in the n-time bins from Data Word
323 Int_t GetADC() const { return fADC ? fADC->fADCnumber : -1 ;} // MCM ADC channel and Time Bin of word 1
324 Int_t GetTimeBin() const { return 0;} // MCM ADC channel and Time Bin of word 1
325
326 //----------------------------------------------------------
327
328 static void SetNoDebug() {fgDebugFlag = kFALSE;} // allow debug info
329 static void SetNoErrorWarning() {fgWarnError = kFALSE;} // disable warning and error info
330 static void SetForceCleanDataOnly() {fgCleanDataOnly = kTRUE;} // clean data only
331 static void AllowCorruptedData() {fgCleanDataOnly = kFALSE;} // accept corrupted data
332
333 static void SetExtraWordsFix() {fgExtraSkip = kTRUE;} // extra skip of 24 32-bit words
334 static void SetSkipCDH() {fgSkipCDH = kTRUE;} // skip of 8 32-bit words
335 void EnableDebug(TTreeSRedirector *debugStream = 0); // enable the debug stream - use the paramter if non zero
336 static void EnableDebugStream() {fgDebugStreamFlag = kTRUE;} //global enable of the dbug stream
337 static void DeleteDebugStream(); // helper function to delete the debug streamer
338 static void SetDumpHead(UInt_t iv) {fgDumpHead = iv;}
339
1ced3838 340 // this is a temporary solution!
341 // baseline should come with the HC header word 2 (count from 0!)
342 static void SetSubtractBaseline(Int_t baseline) {fgCommonAdditive = baseline;}
343 Int_t GetCommonAdditive() const {return fgCommonAdditive;} // return the common additive
344
d4232bb6 345 void DumpErrorCount();
346 void ReSetStreamEventCounter(Int_t ival = 0) {fgStreamEventCounter = ival;} // reset the event counter for the debug streamer
347
348 //--------------------------------------------------------
349 // Decoding functions
350 //--------------------------------------------------------
351
352 void DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const ;
353 const char *DumpSMInfo(const struct AliTRDrawSM *sm);
354 void DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const;
355 const char *DumpStackInfo(const struct AliTRDrawStack *st);
356 void DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const;
357 void DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const;
358 const char *DumpHCinfoH0(const struct AliTRDrawHC *hc);
359 const char *DumpHCinfoH1(const struct AliTRDrawHC *hc);
360 void DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const;
361 UInt_t GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const;
362 void DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const;
363 void MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const;
364 const char *DumpMCMinfo(const struct AliTRDrawMCM *mcm);
365 const char *DumpMCMadcMask(const struct AliTRDrawMCM *mcm);
366
367 protected:
368
369 private:
370
371 Bool_t InitBuffer(void *buffer, UInt_t length); // init the buffer - called by DecodeSM(void*, UInt_t)
372 Bool_t DumpWords(UInt_t *px, UInt_t iw, UInt_t marker = 0); // dump some words onto the screen
373
374 Int_t NextBuffer(); // go and init next buffer if available - check the implementation file for return values
375
376 void SwapOnEndian(); // swap if endian is BIG
377 Bool_t SkipWords(UInt_t iw); // skip number of words
378 Bool_t DecodeTracklets(); // decode tracklets
379 Bool_t DecodeHC(); // decode data in HC
380
381 Bool_t DecodeADC(); // decode 10 ADC words
382
383 Bool_t DecodeHCheader(); // decode HC header
384 Bool_t SeekEndOfData(); // go to next end of raw data marker (actually 1 word after)
385 Bool_t SeekNextMCMheader(); // go to next mcm header
386 Bool_t DecodeMCMheader(); // decode mcm header
387
388 Bool_t IsRowValid(); // check if row within the range
389 Bool_t IsHCheaderOK(); // check if current hc header data make sense
390 Bool_t IsMCMheaderOK(); // check if current mcm header data make sense
391
392 void ResetCounters(); // reset some counters
393 void ResetIterators(); // needed for Next()
394 AliTRDrawStreamTB(const AliTRDrawStreamTB& st);
395 AliTRDrawStreamTB &operator=(const AliTRDrawStreamTB &);
396
397 // ----------------- DATA MEMBERS START
398
399 struct AliTRDrawSM fSM; // one SM per buffer
400 struct AliTRDrawStack *fStack; //! pointer to the current stack
401 struct AliTRDrawHC *fHC; //! current HC
402 struct AliTRDrawMCM *fMCM; //! current MCM
403 struct AliTRDrawADC *fADC; //! current ADC
404
405 UInt_t *fpPos; // current position in the buffer
406 UInt_t *fpBegin; // begin - pointer to the buffer word 0
407 UInt_t *fpEnd; // end of the buffer
408
409 UInt_t fWordLength; // length of the buffer in 32bit words
410
411 Int_t fStackNumber; // current stack number
412 Int_t fStackLinkNumber; // current link in the stack
413
414 Int_t fhcMCMcounter; // mcm counter inside single hc - used in Next()
415 Int_t fmcmADCcounter; // adc counrer inside single adc - used in Next()
416
417 Int_t fLinkTrackletCounter; // count the tracklets in the current HC
418 Int_t fEndOfTrackletCount; // count link by link (hc by hc) used for debug
419
420 UInt_t fMaskADCword; // temp mask when decoding adcs
421 UInt_t fTbinADC; // temp adc
422 Int_t fDecodedADCs; // counter of decoded adcs
423
424 UInt_t fEventCounter; // stores the valid/current MCM event counter
425 UInt_t fLastEventCounter; // last known event counter of MCM
426
d4232bb6 427 Bool_t fSharedPadsOn; // do we want to output shared pads - default is off
428 Int_t fMaxADCgeom; // maximum ADC channels per mcm
429
430 AliTRDgeometry *fGeometry; //! TRD geometry
431 AliRawReader *fRawReader; //! raw reader
432
433 AliTRDfeeParam *fTRDfeeParam; // pointer to the fee params
434
435 Bool_t fDebugStreamOwned; // created in this case by this - allowed to delete?
436
437 // STATIC
438
439 static Bool_t fgExtraSkip; // whether we should skip the leading 24 words
440 static Bool_t fgSkipCDH; // whether we should skip CDH (8 words)
441 static Bool_t fgWarnError; // no errors no warnings
442 static Bool_t fgCleanDataOnly; // release only clean events = no errors
443 static Bool_t fgDebugFlag; // allow debugging info
444 static Bool_t fgDebugStreamFlag; // set on debug streamer
445 static TTreeSRedirector *fgDebugStreamer; //!Debug streamer
446 static UInt_t fgStreamEventCounter; // event counter for debug streamer
447 static UInt_t fgDumpHead; // number of words to dump (from the start of the buffer) on each Init
448 static Int_t fgEmptySignals[30]; // empty signals in case of ADC pointer = NULL
449
450
1ced3838 451 // this is a temporary solution!
452 // baseline should come with the HC header word 2 (count from 0!)
453 static Int_t fgCommonAdditive; // common additive - should be decoded! from HC word2
454
d4232bb6 455 // ----------------- DATA MEMBERS STOP
456
457 enum ETRDzRawStreamError
458 {
459 kDecodeStackInfo = 1 //
460 , kMissingData = 2 //
461 , kLinkDataMissing = 3 //
462 , kHCdataMissing = 4 //
463 , kTrackletOverflow = 5 //
464 , kEOTrackeltsMissing = 6 //
465 , kWrongPadrow = 7 //
466 , kMCMheaderCorrupted = 8 //
467 , kWrongMCMorROB = 9 //
468 , kMCMeventMissmatch = 10 //
469 , kMCMADCMaskMissing = 11 //
470 , kHCHeaderCorrupt = 12 //
471 , kHCHeaderWrongStack = 13 //
472 , kHCHeaderWrongLayer = 14 //
473 , kHCHeaderWrongSide = 15 //
474 , kHCHeaderWrongSM = 16 //
475 , kHCHeaderWrongDet = 17 //
476 , kHCHeaderWrongROC = 18 //
477 , kHCWordMissing = 19 //
478 , kMCMdataMissing = 20 //
479 , kMCMoverflow = 21 //
480 , kADCdataMissing = 22 //
481 , kADCmaskMissmatch = 23 //
482 , kWrongPadcolumn = 24 //
483 };
484
485 ClassDef(AliTRDrawStreamTB, 0)
486}; //clas def end
487
488#endif
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512