]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDrawStreamTB.h
SDD gain DA updated with ECS run information and link to est file. Added protections...
[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
265 Int_t GetCommonAdditive() const {return fCommonAdditive;} // return the common additive
266 Bool_t IsCurrentPadShared() const {return fADC->fIsShared;} // is current pad shared between mcms
267 void SetSharedPadReadout(Bool_t fv) {fSharedPadsOn = fv;} // set the flag on if the reader should return the shared pads
268 Bool_t IsDataZeroSuppressed() const {return (fHC->fRawVMajor > 2) ? kTRUE : kFALSE;} // check the version and tell if ZS is on
269
270 Bool_t DecodeSM(void *buffer, UInt_t length); //decode a buffer
271 Int_t DecodeSM(); // used with raw reader
272 Int_t DecodeSM(AliRawReader *reader); // used with raw reader
273
274 Bool_t SetReader(AliRawReader *reader); // set the raw reader to use
275
276 Bool_t IsTrackletEnableBitSet() const {return fSM.fTrackletEnable;} // get status of the tracklets enable bit
277 Bool_t IsStackActive(Int_t is) const {return fSM.fStackActive[is];} // get status of a stack
278 Int_t GetNofActiveStacks() const {return fSM.fActiveStacks;} // get number of active stacks
279 UInt_t *GetSMstreamPosition() const {return fSM.fPos;} // get position of the SM index word in the buffer
280
281 Bool_t IsSMbufferClean() const {return fSM.fClean;} // is data clean
282
283 Bool_t IsLinkActiveInStack(Int_t is, Int_t il) const {return fSM.fStacks[is].fLinksActive[il];} // check whether the link is active
284 Int_t GetActiveLinksInStack(Int_t is) const {return fSM.fStacks[is].fActiveLinks;} //get active links in a stack
285
286 Int_t GetSpecialRawVersion() const {return fHC ? fHC->fSpecialRawV : -1;} // return special raw version
287 Int_t GetMajorRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // major raw version getter
288 Int_t GetRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // compatibility see funtion above
289 Int_t GetMinorRawVersion() const {return fHC ? fHC->fRawVMinor : -1;} // minor raw version
290
291 Int_t GetSM() const {return fHC ? fHC->fSM : -1;} // Position of CURRENT half chamber in full TRD
292 Int_t GetLayer() const {return fHC ? fHC->fLayer : -1;} // PLANE = Position of CURRENT half chamber in full TRD
293 Int_t GetStack() const {return fHC ? fHC->fStack : -1;} // CHAMBER = Position of CURRENT half chamber in full TRD
294 Int_t GetSide() const {return fHC ? fHC->fSide : -1;} // get side
295 Int_t GetDCS() const { return fHC ? fHC->fDCSboard : -1;} // DCS board number read from data (HC header)
296 //Int_t GetDCSboard() {return fHC ? fHC->fDCSboard : -1;} // DCS board number read from data (HC header)
297 Int_t GetROC() const { return fHC ? fHC->fROC : -1;} // Position of CURRENT half chamber in full TRD
298 Int_t GetNumberOfTimeBins() const { return fHC ? fHC->fTimeBins : 0;} // Get Ntime bins
299 UInt_t GetBunchCrossCounter() const {return fHC ? fHC->fBunchCrossCounter : 0;} // get bunch cross counter
300 UInt_t GetPreTriggerCounter() const {return fHC ? fHC->fPreTriggerCounter : 0;} // get pre trigger info
301 UInt_t GetPreTriggerPhase() const {return fHC ? fHC->fPreTriggerPhase : 0;} // get trigger phase
302
303 Int_t GetRow() const {return fMCM ? fMCM->fROW : -1;} // get current row number
304 Int_t GetCol() const {return fADC ? fADC->fCOL : -1;} // get current column number
305 Int_t GetRowMax() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC
306 Int_t GetColMax() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC
307 // compatibility
308 Int_t GetMaxRow() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC
309 Int_t GetMaxCol() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC
310
311 UInt_t GetHCword0() const {return fHC ? *fHC->fPos[0] : 0;} // get the HC word 0
312 UInt_t GetHCword1() const {return fHC ? *fHC->fPos[1] : 0;} // get the HC word 1
313
314 Int_t GetDET() const {return fHC ? fHC->fDET : -1;} // get current det number
315 Int_t GetDet() const {return fHC ? fHC->fDET : -1;} // get current det number
316
317 Int_t GetROB() const {return fMCM ? fMCM->fROB : -1;} // get current ROB number
318 Int_t GetMCM() const {return fMCM ? fMCM->fMCM : -1;} // get current MCM number
319 Int_t GetEventNumber() const { return fMCM->fEvCounter;} // MCM Event number and position of current MCM on TRD chamber
320
321 Int_t IsMCMcorrupted() const {return fMCM ? fMCM->fCorrupted : -1;} // is current MCM header corrupted
322
323 Int_t *GetSignals() const { return fADC ? fADC->fSignals : (Int_t *)fgEmptySignals;}//Signals in the n-time bins from Data Word
324 Int_t GetADC() const { return fADC ? fADC->fADCnumber : -1 ;} // MCM ADC channel and Time Bin of word 1
325 Int_t GetTimeBin() const { return 0;} // MCM ADC channel and Time Bin of word 1
326
327 //----------------------------------------------------------
328
329 static void SetNoDebug() {fgDebugFlag = kFALSE;} // allow debug info
330 static void SetNoErrorWarning() {fgWarnError = kFALSE;} // disable warning and error info
331 static void SetForceCleanDataOnly() {fgCleanDataOnly = kTRUE;} // clean data only
332 static void AllowCorruptedData() {fgCleanDataOnly = kFALSE;} // accept corrupted data
333
334 static void SetExtraWordsFix() {fgExtraSkip = kTRUE;} // extra skip of 24 32-bit words
335 static void SetSkipCDH() {fgSkipCDH = kTRUE;} // skip of 8 32-bit words
336 void EnableDebug(TTreeSRedirector *debugStream = 0); // enable the debug stream - use the paramter if non zero
337 static void EnableDebugStream() {fgDebugStreamFlag = kTRUE;} //global enable of the dbug stream
338 static void DeleteDebugStream(); // helper function to delete the debug streamer
339 static void SetDumpHead(UInt_t iv) {fgDumpHead = iv;}
340
341 void DumpErrorCount();
342 void ReSetStreamEventCounter(Int_t ival = 0) {fgStreamEventCounter = ival;} // reset the event counter for the debug streamer
343
344 //--------------------------------------------------------
345 // Decoding functions
346 //--------------------------------------------------------
347
348 void DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const ;
349 const char *DumpSMInfo(const struct AliTRDrawSM *sm);
350 void DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const;
351 const char *DumpStackInfo(const struct AliTRDrawStack *st);
352 void DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const;
353 void DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const;
354 const char *DumpHCinfoH0(const struct AliTRDrawHC *hc);
355 const char *DumpHCinfoH1(const struct AliTRDrawHC *hc);
356 void DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const;
357 UInt_t GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const;
358 void DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const;
359 void MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const;
360 const char *DumpMCMinfo(const struct AliTRDrawMCM *mcm);
361 const char *DumpMCMadcMask(const struct AliTRDrawMCM *mcm);
362
363 protected:
364
365 private:
366
367 Bool_t InitBuffer(void *buffer, UInt_t length); // init the buffer - called by DecodeSM(void*, UInt_t)
368 Bool_t DumpWords(UInt_t *px, UInt_t iw, UInt_t marker = 0); // dump some words onto the screen
369
370 Int_t NextBuffer(); // go and init next buffer if available - check the implementation file for return values
371
372 void SwapOnEndian(); // swap if endian is BIG
373 Bool_t SkipWords(UInt_t iw); // skip number of words
374 Bool_t DecodeTracklets(); // decode tracklets
375 Bool_t DecodeHC(); // decode data in HC
376
377 Bool_t DecodeADC(); // decode 10 ADC words
378
379 Bool_t DecodeHCheader(); // decode HC header
380 Bool_t SeekEndOfData(); // go to next end of raw data marker (actually 1 word after)
381 Bool_t SeekNextMCMheader(); // go to next mcm header
382 Bool_t DecodeMCMheader(); // decode mcm header
383
384 Bool_t IsRowValid(); // check if row within the range
385 Bool_t IsHCheaderOK(); // check if current hc header data make sense
386 Bool_t IsMCMheaderOK(); // check if current mcm header data make sense
387
388 void ResetCounters(); // reset some counters
389 void ResetIterators(); // needed for Next()
390 AliTRDrawStreamTB(const AliTRDrawStreamTB& st);
391 AliTRDrawStreamTB &operator=(const AliTRDrawStreamTB &);
392
393 // ----------------- DATA MEMBERS START
394
395 struct AliTRDrawSM fSM; // one SM per buffer
396 struct AliTRDrawStack *fStack; //! pointer to the current stack
397 struct AliTRDrawHC *fHC; //! current HC
398 struct AliTRDrawMCM *fMCM; //! current MCM
399 struct AliTRDrawADC *fADC; //! current ADC
400
401 UInt_t *fpPos; // current position in the buffer
402 UInt_t *fpBegin; // begin - pointer to the buffer word 0
403 UInt_t *fpEnd; // end of the buffer
404
405 UInt_t fWordLength; // length of the buffer in 32bit words
406
407 Int_t fStackNumber; // current stack number
408 Int_t fStackLinkNumber; // current link in the stack
409
410 Int_t fhcMCMcounter; // mcm counter inside single hc - used in Next()
411 Int_t fmcmADCcounter; // adc counrer inside single adc - used in Next()
412
413 Int_t fLinkTrackletCounter; // count the tracklets in the current HC
414 Int_t fEndOfTrackletCount; // count link by link (hc by hc) used for debug
415
416 UInt_t fMaskADCword; // temp mask when decoding adcs
417 UInt_t fTbinADC; // temp adc
418 Int_t fDecodedADCs; // counter of decoded adcs
419
420 UInt_t fEventCounter; // stores the valid/current MCM event counter
421 UInt_t fLastEventCounter; // last known event counter of MCM
422
423 Int_t fCommonAdditive; // common additive - should be decoded! from HC word2
424 Bool_t fSharedPadsOn; // do we want to output shared pads - default is off
425 Int_t fMaxADCgeom; // maximum ADC channels per mcm
426
427 AliTRDgeometry *fGeometry; //! TRD geometry
428 AliRawReader *fRawReader; //! raw reader
429
430 AliTRDfeeParam *fTRDfeeParam; // pointer to the fee params
431
432 Bool_t fDebugStreamOwned; // created in this case by this - allowed to delete?
433
434 // STATIC
435
436 static Bool_t fgExtraSkip; // whether we should skip the leading 24 words
437 static Bool_t fgSkipCDH; // whether we should skip CDH (8 words)
438 static Bool_t fgWarnError; // no errors no warnings
439 static Bool_t fgCleanDataOnly; // release only clean events = no errors
440 static Bool_t fgDebugFlag; // allow debugging info
441 static Bool_t fgDebugStreamFlag; // set on debug streamer
442 static TTreeSRedirector *fgDebugStreamer; //!Debug streamer
443 static UInt_t fgStreamEventCounter; // event counter for debug streamer
444 static UInt_t fgDumpHead; // number of words to dump (from the start of the buffer) on each Init
445 static Int_t fgEmptySignals[30]; // empty signals in case of ADC pointer = NULL
446
447
448 // ----------------- DATA MEMBERS STOP
449
450 enum ETRDzRawStreamError
451 {
452 kDecodeStackInfo = 1 //
453 , kMissingData = 2 //
454 , kLinkDataMissing = 3 //
455 , kHCdataMissing = 4 //
456 , kTrackletOverflow = 5 //
457 , kEOTrackeltsMissing = 6 //
458 , kWrongPadrow = 7 //
459 , kMCMheaderCorrupted = 8 //
460 , kWrongMCMorROB = 9 //
461 , kMCMeventMissmatch = 10 //
462 , kMCMADCMaskMissing = 11 //
463 , kHCHeaderCorrupt = 12 //
464 , kHCHeaderWrongStack = 13 //
465 , kHCHeaderWrongLayer = 14 //
466 , kHCHeaderWrongSide = 15 //
467 , kHCHeaderWrongSM = 16 //
468 , kHCHeaderWrongDet = 17 //
469 , kHCHeaderWrongROC = 18 //
470 , kHCWordMissing = 19 //
471 , kMCMdataMissing = 20 //
472 , kMCMoverflow = 21 //
473 , kADCdataMissing = 22 //
474 , kADCmaskMissmatch = 23 //
475 , kWrongPadcolumn = 24 //
476 };
477
478 ClassDef(AliTRDrawStreamTB, 0)
479}; //clas def end
480
481#endif
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505