]>
Commit | Line | Data |
---|---|---|
d4232bb6 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | /* $Id$ */ | |
17 | ||
18 | /////////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // This class provides access to TRD digits in raw data. // | |
21 | // // | |
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. // | |
26 | // // | |
27 | // Author: M. Ploskon (ploskon@ikf.uni-frankfurt.de) // | |
28 | // // | |
29 | /////////////////////////////////////////////////////////////////////////////// | |
30 | ||
31 | #include "TString.h" | |
32 | #include "TFile.h" | |
33 | #include "TTreeStream.h" | |
34 | ||
35 | #include "AliTRDrawStreamTB.h" | |
36 | #include "AliTRDgeometry.h" | |
37 | #include "AliTRDfeeParam.h" | |
38 | #include "AliTRDdigitsManager.h" | |
625f5260 | 39 | #include "AliTRDdataArrayS.h" |
6bd744d3 | 40 | #include "AliTRDdataArrayI.h" |
d4232bb6 | 41 | #include "AliTRDSignalIndex.h" |
42 | ||
43 | #include "AliLog.h" | |
44 | #include "AliRawReader.h" | |
45 | ||
46 | #define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa | |
47 | #define END_OF_TRACKLET_MARKERNEW 0x10001000 | |
48 | #define ENDOFRAWDATAMARKER 0x00000000 | |
bb1009bf | 49 | #define ENDBITS 0x03 |
d4232bb6 | 50 | #define WORD_SIZE sizeof(UInt_t) // size of a word in bytes |
51 | #define EXTRA_LEAD_WORDS 24 | |
52 | #define CDH_WORDS 8 | |
53 | ||
54 | #define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w | |
55 | #define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m | |
56 | ||
57 | // SM index word masks: | |
58 | #define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16) | |
59 | #define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5) | |
60 | #define STACK_MASK(w) ((w) & 0x1f) | |
61 | ||
62 | // Stack word masks | |
63 | #define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16) | |
64 | #define STACK_LINK_WORD(w) ((w) & 0xfff) | |
65 | ||
66 | // HC word masks | |
67 | //#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!! | |
68 | #define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK!!! | |
69 | ||
70 | // HC word 0 | |
71 | #define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31) | |
72 | #define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24) | |
dc25a859 | 73 | #define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24) |
d4232bb6 | 74 | #define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17) |
75 | #define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14) | |
76 | #define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20) | |
77 | #define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9) | |
78 | #define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6) | |
79 | #define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3) | |
80 | #define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2) | |
81 | ||
82 | // HC word 1 | |
83 | #define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26) | |
84 | #define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10) | |
85 | #define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6) | |
86 | #define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,6) | |
87 | ||
88 | //-------------------------------------------------------- | |
89 | ||
90 | // MCM word and ADC mask | |
91 | #define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!! | |
92 | #define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!! | |
93 | #define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24) | |
94 | #define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28) | |
95 | #define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4) | |
96 | #define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4) | |
bb1009bf | 97 | #define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25) |
d4232bb6 | 98 | |
bb1009bf | 99 | #define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated |
100 | //#define MCM_DUMMY_ADCMASK_VAL 0x001fffffc | |
d4232bb6 | 101 | //-------------------------------------------------------- |
102 | ||
103 | #define MAX_TRACKLETS_PERHC 256 // max number of tracklets per HC - large number for now | |
104 | ||
105 | //-------------------------------------------------------- | |
106 | #define ADC_WORD_MASK(w) ((w) & 0x3) | |
107 | //-------------------------------------------------------- | |
dc25a859 | 108 | |
109 | ||
d4232bb6 | 110 | ClassImp(AliTRDrawStreamTB) |
111 | ||
112 | Bool_t AliTRDrawStreamTB::fgExtraSkip = kFALSE; | |
113 | Bool_t AliTRDrawStreamTB::fgSkipCDH = kFALSE; | |
114 | Bool_t AliTRDrawStreamTB::fgWarnError = kTRUE; | |
115 | Bool_t AliTRDrawStreamTB::fgCleanDataOnly = kTRUE; | |
116 | Bool_t AliTRDrawStreamTB::fgDebugFlag = kTRUE; | |
117 | Bool_t AliTRDrawStreamTB::fgDebugStreamFlag = kFALSE; | |
6bd744d3 | 118 | Bool_t AliTRDrawStreamTB::fgStackNumberChecker = kTRUE; |
7e8f4d17 | 119 | Bool_t AliTRDrawStreamTB::fgStackLinkNumberChecker = kTRUE; |
bb1009bf | 120 | Bool_t AliTRDrawStreamTB::fgSkipData = kTRUE; |
d4232bb6 | 121 | TTreeSRedirector *AliTRDrawStreamTB::fgDebugStreamer = 0; |
122 | UInt_t AliTRDrawStreamTB::fgStreamEventCounter = 0; | |
7e8f4d17 | 123 | UInt_t AliTRDrawStreamTB::fgFirstEquipmentID = 0; |
d4232bb6 | 124 | UInt_t AliTRDrawStreamTB::fgDumpHead = 0; |
1ced3838 | 125 | Int_t AliTRDrawStreamTB::fgCommonAdditive = 0; |
d4232bb6 | 126 | Int_t AliTRDrawStreamTB::fgEmptySignals[] = |
127 | { | |
128 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 | |
129 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 | |
130 | }; | |
131 | ||
132 | AliTRDrawStreamTB::AliTRDrawStreamTB() | |
dfbb4bb9 | 133 | : AliTRDrawStreamBase() |
134 | //: TObject() | |
d4232bb6 | 135 | , fSM() |
136 | , fStack(0) | |
137 | , fHC(0) | |
138 | , fMCM(0) | |
139 | , fADC(0) | |
140 | , fpPos(0) | |
141 | , fpBegin(0) | |
142 | , fpEnd(0) | |
143 | , fWordLength(0) | |
7e8f4d17 | 144 | , fEquipmentID(0) |
d4232bb6 | 145 | , fStackNumber(-1) |
146 | , fStackLinkNumber(-1) | |
147 | , fhcMCMcounter(0) | |
148 | , fmcmADCcounter(0) | |
149 | , fLinkTrackletCounter(-1) | |
150 | , fEndOfTrackletCount(-1) | |
151 | , fMaskADCword(0) | |
152 | , fTbinADC(0) | |
153 | , fDecodedADCs(-1) | |
154 | , fEventCounter(0) | |
155 | , fLastEventCounter(0) | |
d4232bb6 | 156 | , fSharedPadsOn(kFALSE) |
157 | , fMaxADCgeom(0) | |
158 | , fGeometry(0) | |
159 | , fRawReader(0) | |
160 | , fTRDfeeParam(0) | |
161 | , fDebugStreamOwned(kFALSE) | |
162 | { | |
163 | // | |
164 | // default constructor | |
165 | // | |
166 | ||
167 | if (Init() == kFALSE) | |
168 | { | |
169 | AliWarning("Unable to Init."); | |
170 | } | |
171 | } | |
172 | ||
173 | //-------------------------------------------------------- | |
174 | AliTRDrawStreamTB::AliTRDrawStreamTB(AliRawReader *rawReader) | |
dfbb4bb9 | 175 | : AliTRDrawStreamBase(rawReader) |
176 | //: TObject() | |
d4232bb6 | 177 | , fSM() |
178 | , fStack(0) | |
179 | , fHC(0) | |
180 | , fMCM(0) | |
181 | , fADC(0) | |
182 | , fpPos(0) | |
183 | , fpBegin(0) | |
184 | , fpEnd(0) | |
185 | , fWordLength(0) | |
7e8f4d17 | 186 | , fEquipmentID(0) |
d4232bb6 | 187 | , fStackNumber(-1) |
188 | , fStackLinkNumber(-1) | |
189 | , fhcMCMcounter(0) | |
190 | , fmcmADCcounter(0) | |
191 | , fLinkTrackletCounter(-1) | |
192 | , fEndOfTrackletCount(-1) | |
193 | , fMaskADCword(0) | |
194 | , fTbinADC(0) | |
195 | , fDecodedADCs(-1) | |
196 | , fEventCounter(0) | |
197 | , fLastEventCounter(0) | |
d4232bb6 | 198 | , fSharedPadsOn(kFALSE) |
199 | , fMaxADCgeom(0) | |
200 | , fGeometry(0) | |
201 | , fRawReader(rawReader) | |
202 | , fTRDfeeParam(0) | |
203 | , fDebugStreamOwned(kFALSE) | |
204 | { | |
205 | // | |
206 | // default constructor | |
207 | // | |
208 | if (fRawReader) | |
209 | { | |
210 | if (Init() == kFALSE) | |
211 | { | |
212 | AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )"); | |
213 | } | |
214 | } | |
215 | else | |
216 | { | |
217 | AliWarning("Unable to setup reader. Use SetReader(AliRawReader*)."); | |
218 | } | |
219 | } | |
220 | ||
221 | //------------------------------------------------------------ | |
222 | ||
223 | AliTRDrawStreamTB::AliTRDrawStreamTB(const AliTRDrawStreamTB& /*st*/) | |
dfbb4bb9 | 224 | : AliTRDrawStreamBase() |
225 | //: TObject() | |
d4232bb6 | 226 | , fSM() |
227 | , fStack(0) | |
228 | , fHC(0) | |
229 | , fMCM(0) | |
230 | , fADC(0) | |
231 | , fpPos(0) | |
232 | , fpBegin(0) | |
233 | , fpEnd(0) | |
234 | , fWordLength(0) | |
7e8f4d17 | 235 | , fEquipmentID(0) |
d4232bb6 | 236 | , fStackNumber(-1) |
237 | , fStackLinkNumber(-1) | |
238 | , fhcMCMcounter(0) | |
239 | , fmcmADCcounter(0) | |
240 | , fLinkTrackletCounter(-1) | |
241 | , fEndOfTrackletCount(-1) | |
242 | , fMaskADCword(0) | |
243 | , fTbinADC(0) | |
244 | , fDecodedADCs(-1) | |
245 | , fEventCounter(0) | |
246 | , fLastEventCounter(0) | |
d4232bb6 | 247 | , fSharedPadsOn(kFALSE) |
248 | , fMaxADCgeom(0) | |
249 | , fGeometry(0) | |
250 | , fRawReader(0) | |
251 | , fTRDfeeParam(0) | |
252 | , fDebugStreamOwned(kFALSE) | |
253 | { | |
254 | // | |
255 | // Copy constructor | |
256 | // | |
257 | AliError("Not implemeneted."); | |
258 | } | |
259 | ||
260 | //------------------------------------------------------------ | |
dfbb4bb9 | 261 | Bool_t AliTRDrawStreamTB::SetRawVersion(Int_t fraw) |
d4232bb6 | 262 | { |
263 | // | |
264 | // function provided for backward compatibility | |
265 | // | |
266 | AliWarning("Raw data version is read from raw data stream! No point of setting it in here."); | |
267 | fraw = 0; // avoid warnings | |
dfbb4bb9 | 268 | return kFALSE; |
d4232bb6 | 269 | } |
270 | ||
271 | //------------------------------------------------------------ | |
272 | AliTRDrawStreamTB::~AliTRDrawStreamTB() | |
273 | { | |
274 | // | |
275 | // destructor | |
276 | // | |
277 | delete fGeometry; | |
278 | ||
279 | if (fDebugStreamOwned == kTRUE) | |
280 | { | |
281 | if (fgDebugStreamer) | |
282 | { | |
283 | delete fgDebugStreamer; | |
284 | fgDebugStreamer = 0; | |
285 | } | |
286 | } | |
287 | } | |
288 | ||
289 | //------------------------------------------------------------ | |
290 | ||
291 | AliTRDrawStreamTB & | |
292 | AliTRDrawStreamTB::operator=(const AliTRDrawStreamTB &) | |
293 | { | |
294 | // | |
295 | // we are not using this functionality | |
296 | // | |
297 | AliFatal("May not use."); | |
298 | return *this; | |
299 | } | |
300 | ||
301 | //------------------------------------------------------------ | |
302 | ||
303 | void | |
304 | AliTRDrawStreamTB::EnableDebug(TTreeSRedirector *debugStream) | |
305 | { | |
306 | // | |
307 | // replace the current debug streamer or create a new one if owned | |
308 | // | |
309 | ||
310 | if (debugStream == 0) | |
311 | { | |
312 | if (fDebugStreamOwned == kTRUE) | |
313 | { | |
314 | if (fgDebugStreamer) | |
315 | delete fgDebugStreamer; | |
316 | } | |
317 | ||
318 | fDebugStreamOwned = kTRUE; | |
319 | fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root"); | |
320 | fgStreamEventCounter = 0; | |
321 | ||
322 | } | |
323 | else | |
324 | { | |
325 | if (fDebugStreamOwned == kTRUE) | |
326 | { | |
327 | if (fgDebugStreamer) | |
328 | delete fgDebugStreamer; | |
329 | } | |
330 | ||
331 | fgDebugStreamer = debugStream; | |
332 | fDebugStreamOwned = kFALSE; | |
333 | } | |
334 | } | |
335 | ||
336 | //___________________________________________________________ | |
337 | void | |
338 | AliTRDrawStreamTB::SwapOnEndian() | |
339 | { | |
340 | // | |
341 | // Check the endian and swap if needed | |
342 | // | |
343 | ||
344 | int itemp = 1; | |
345 | char* ptemp = (char*) &itemp; | |
346 | if (ptemp[0] != 1) | |
347 | { | |
348 | // need to swap... | |
349 | if (fgDebugFlag) AliDebug(8, "Swapping."); | |
350 | ||
351 | fpPos = fpBegin; | |
352 | UInt_t iutmp = 0; | |
353 | while (fpPos < fpEnd) | |
354 | { | |
355 | fpPos += 1; | |
356 | iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) | | |
357 | ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24)); | |
358 | // here we override the value in the buffer! | |
359 | *fpPos = iutmp; | |
360 | } | |
361 | fpPos = fpBegin; | |
362 | } | |
363 | } | |
364 | ||
365 | //------------------------------------------------------------ | |
366 | void | |
367 | AliTRDrawStreamTB::DumpErrorCount() | |
368 | { | |
369 | // | |
370 | // print the error statistics into the stdout | |
371 | // | |
372 | ||
373 | ; | |
374 | // AliInfo(Form("Error counts: HC0 %d HC1 %d MCM %d ADCmask %d ADC %d", | |
375 | // fHC->fH0ErrorCounter, fHC->fH1ErrorCounter, fMCM->fErrorCounter, fMCM->fMaskErrorCounter, adc.fErrorCounter)); | |
376 | } | |
377 | ||
378 | //------------------------------------------------------------ | |
379 | Bool_t | |
380 | AliTRDrawStreamTB::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker) | |
381 | { | |
382 | // | |
383 | // skip few words | |
384 | // note: can be made faster | |
385 | // | |
386 | ||
387 | TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px); | |
388 | for (UInt_t i = 0; i < iw; i++) | |
389 | { | |
390 | if (px + iw >= fpEnd) | |
391 | return kFALSE; | |
392 | ||
393 | if (i % 8 == 0) | |
394 | tsreturn += "\n "; | |
395 | if (marker != 0 && marker == px[i]) | |
396 | tsreturn += Form(" *>0x%08x<* ", px[i]); | |
397 | else | |
398 | tsreturn += Form("0x%08x ", px[i]); | |
399 | } | |
400 | tsreturn += "\n"; | |
401 | ||
402 | AliInfo(tsreturn.Data()); | |
403 | ||
404 | return kTRUE; | |
405 | } | |
406 | ||
407 | //------------------------------------------------------------ | |
408 | Bool_t | |
409 | AliTRDrawStreamTB::SkipWords(UInt_t iw) | |
410 | { | |
411 | // | |
412 | // skip few words | |
413 | // note: can be made faster | |
414 | // | |
415 | ||
416 | if ( fpPos + iw < fpEnd ) | |
417 | { | |
418 | fpPos += iw; | |
419 | return kTRUE; | |
420 | } | |
421 | else | |
422 | { | |
423 | if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1)); | |
424 | if (fgDebugStreamer) | |
425 | { | |
426 | TTreeSRedirector &cstream = *fgDebugStreamer; | |
427 | cstream << "SkipWords" | |
428 | << "Event=" << fgStreamEventCounter | |
429 | << ".nwords=" << iw | |
430 | // << ".read=" << (Char_t*)(fpPos - fpBegin) | |
431 | // << ".togo=" << (Char_t*)(fpEnd - fpPos) | |
432 | // << ".length=" << (Char_t*)(fpEnd - fpBegin) | |
433 | << "\n"; | |
434 | } | |
435 | return kFALSE; | |
436 | } | |
437 | ||
438 | return kTRUE; | |
439 | } | |
440 | ||
441 | //------------------------------------------------------------ | |
442 | Bool_t | |
443 | AliTRDrawStreamTB::SetReader(AliRawReader *reader) | |
444 | { | |
445 | // | |
446 | // | |
447 | // | |
448 | ||
449 | if (reader != 0) | |
450 | { | |
451 | fRawReader = reader; | |
452 | if (fRawReader) | |
453 | { | |
454 | return Init(); | |
455 | } | |
456 | else | |
457 | { | |
458 | AliWarning("Unable to setup reader."); | |
459 | return kFALSE; | |
460 | } | |
461 | } | |
462 | else | |
463 | { | |
464 | AliWarning("AliRawReader argument is 0."); | |
465 | fRawReader = 0; | |
466 | } | |
467 | ||
468 | return kFALSE; | |
469 | } | |
470 | ||
471 | //------------------------------------------------------------ | |
472 | Int_t | |
473 | AliTRDrawStreamTB::NextBuffer() | |
474 | { | |
475 | // | |
476 | // return -1 if no more buffers available | |
477 | // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come | |
478 | // return 1 DecodeSM OK | |
479 | // | |
480 | ||
481 | if (fRawReader != 0) | |
482 | { | |
483 | UChar_t *buffer = 0; | |
484 | UInt_t length = 0; | |
485 | Bool_t kBufferSet = fRawReader->ReadNextData(buffer); | |
486 | if (kBufferSet == kTRUE) | |
487 | { | |
488 | if (fgDebugFlag) AliDebug(9, "Buffer is set."); | |
489 | length = fRawReader->GetDataSize(); | |
490 | if (fgExtraSkip == kTRUE) | |
491 | { | |
492 | buffer += EXTRA_LEAD_WORDS * WORD_SIZE; | |
493 | length -= EXTRA_LEAD_WORDS * WORD_SIZE; | |
494 | } | |
495 | ||
496 | if (fgSkipCDH == kTRUE) | |
497 | { | |
498 | buffer += CDH_WORDS * WORD_SIZE; | |
499 | length -= CDH_WORDS * WORD_SIZE; | |
500 | } | |
501 | ||
502 | if (length > 0) | |
503 | { | |
504 | if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length)); | |
505 | //return InitBuffer((void*)buffer, length); | |
506 | if (DecodeSM((void*)buffer, length) == kTRUE) | |
507 | return 1; | |
508 | else | |
509 | return 0; | |
510 | } | |
511 | } | |
512 | else | |
513 | { | |
514 | return -1; | |
515 | } | |
516 | } | |
517 | ||
518 | return -1; | |
519 | } | |
520 | ||
521 | //------------------------------------------------------------ | |
522 | void | |
523 | AliTRDrawStreamTB::ResetCounters() | |
524 | { | |
525 | // | |
526 | // reset some global counters | |
527 | // | |
528 | ||
529 | fStackNumber = 0; | |
530 | fStackLinkNumber = 0; | |
531 | ||
532 | fDecodedADCs = 0; | |
533 | ||
534 | fSM.fActiveStacks = 0; | |
535 | fSM.fNexpectedHalfChambers = 0; | |
536 | ||
537 | fLinkTrackletCounter = 0; | |
538 | ||
539 | fLastEventCounter = 0; | |
540 | fEventCounter = 0; | |
541 | } | |
542 | ||
543 | //------------------------------------------------------------ | |
544 | void | |
545 | AliTRDrawStreamTB::ResetIterators() | |
546 | { | |
547 | // | |
548 | // reset the data iterators used in the Next() | |
549 | // | |
550 | fStackNumber = 0; | |
551 | fStackLinkNumber = 0; | |
552 | fhcMCMcounter = 0; | |
553 | fmcmADCcounter = 0; | |
554 | } | |
555 | ||
556 | //------------------------------------------------------------ | |
557 | ||
558 | Bool_t | |
559 | AliTRDrawStreamTB::Next() | |
560 | { | |
561 | // | |
562 | // returns with true on next adc read | |
563 | // returns false on errors and end of buffer | |
564 | // | |
565 | ||
566 | while (fStackNumber < 5 && fSM.fActiveStacks > 0) | |
567 | { | |
568 | if(fSM.fStackActive[fStackNumber] == kTRUE) | |
569 | { | |
570 | fStack = &fSM.fStacks[fStackNumber]; | |
571 | while (fStackLinkNumber < 12) | |
572 | { | |
573 | if (fStack->fLinksActive[fStackLinkNumber] == kTRUE) | |
574 | { | |
575 | fHC = &fStack->fHalfChambers[fStackLinkNumber]; | |
576 | if (!fHC) | |
577 | { | |
578 | AliError(Form("Super Strange. HC missing at stack %d link %d", fStackNumber, fStackLinkNumber)); | |
579 | return kFALSE; | |
580 | } | |
d4232bb6 | 581 | if (fHC->fCorrupted == 0) |
582 | { | |
583 | while (fhcMCMcounter < fHC->fMCMmax) | |
584 | { | |
585 | fMCM = &fHC->fMCMs[fhcMCMcounter]; | |
d4232bb6 | 586 | if (!fMCM) |
587 | { | |
588 | AliError(Form("Super Strange. HC missing at stack %d link %d atMCMslot %d", | |
589 | fStackNumber, fStackLinkNumber, fhcMCMcounter)); | |
590 | return kFALSE; | |
591 | } | |
592 | while(fmcmADCcounter < fMCM->fADCmax) | |
593 | { | |
d4232bb6 | 594 | fADC = &fMCM->fADCs[fmcmADCcounter]; |
595 | if (!fADC) | |
596 | { | |
597 | AliError(Form("Super Strange. ADC missing at stack %d link %d MCMslot %d ADCslot %d", | |
598 | fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter)); | |
599 | return kFALSE; | |
600 | } | |
601 | fmcmADCcounter++; | |
d4232bb6 | 602 | if (fSharedPadsOn) |
603 | { | |
604 | return kTRUE; | |
605 | } | |
606 | else | |
607 | { | |
608 | if (fADC->fIsShared == kFALSE) | |
609 | return kTRUE; | |
610 | } | |
611 | } //while adc in MCM | |
d4232bb6 | 612 | fhcMCMcounter++; |
613 | // next MCM should go through all active ADCs | |
614 | fmcmADCcounter = 0; | |
615 | } // while mcm | |
616 | } // if HC OK | |
617 | }// if link active | |
618 | fStackLinkNumber++; | |
619 | // next stack link (HC) should go through all active MCMs | |
620 | fhcMCMcounter = 0; | |
621 | }// while links | |
622 | }// if stack active | |
623 | fStackNumber++; | |
624 | // next stack should go through all links - start from 0 | |
625 | fStackLinkNumber = 0; | |
626 | } | |
627 | ||
628 | // in case rawreader manages the mem buffers | |
629 | // lets go for the next buffer | |
630 | if (fRawReader) | |
631 | { | |
632 | Int_t nextBuff = NextBuffer(); | |
633 | while (nextBuff != -1) | |
634 | { | |
635 | if (nextBuff > 0) | |
636 | return Next(); | |
637 | nextBuff = NextBuffer(); | |
638 | } | |
639 | } | |
640 | ||
641 | return kFALSE; | |
642 | } | |
643 | ||
644 | //------------------------------------------------------------ | |
645 | ||
646 | Int_t | |
647 | AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager) | |
648 | { | |
649 | // | |
650 | // Fills single chamber digit array | |
651 | // Return value is the detector number | |
652 | // | |
653 | ||
625f5260 | 654 | AliTRDdataArrayS *digits = 0; |
d4232bb6 | 655 | AliTRDdataArrayI *track0 = 0; |
656 | AliTRDdataArrayI *track1 = 0; | |
657 | AliTRDdataArrayI *track2 = 0; | |
658 | AliTRDSignalIndex *indexes = 0; | |
659 | ||
660 | // Loop through the digits | |
661 | Int_t lastdet = -1; | |
662 | Int_t det = -1; | |
663 | // Int_t returnDet = -1; | |
664 | Int_t it = 0; | |
665 | while (Next()) | |
666 | { | |
667 | det = GetDet(); | |
668 | ||
669 | if (det != lastdet) | |
670 | { | |
671 | // If new detector found | |
672 | if (lastdet == -1) | |
673 | { | |
674 | lastdet = det; | |
675 | } | |
676 | else | |
677 | { | |
678 | return lastdet; | |
679 | } | |
dad68eff | 680 | |
681 | if (det < 0 || det >= AliTRDgeometry::kNdet) | |
682 | { | |
683 | if (fSM.fClean == kTRUE) | |
684 | { | |
685 | AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det)); | |
686 | } | |
687 | else | |
688 | { | |
689 | AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det)); | |
690 | } | |
691 | continue; | |
692 | } | |
693 | ||
d4232bb6 | 694 | // Add a container for the digits of this detector |
625f5260 | 695 | digits = (AliTRDdataArrayS *) digitsManager->GetDigits(det); |
696 | track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0); | |
697 | track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1); | |
698 | track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2); | |
d4232bb6 | 699 | |
dad68eff | 700 | if (!digits) |
701 | { | |
702 | if (fSM.fClean == kTRUE) | |
703 | { | |
704 | AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det)); | |
705 | } | |
706 | else | |
707 | { | |
708 | AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det)); | |
709 | } | |
710 | return -1; | |
711 | //continue; | |
712 | } | |
713 | ||
d4232bb6 | 714 | Int_t rowMax = GetRowMax(); |
715 | Int_t colMax = GetColMax(); | |
716 | Int_t ntbins = GetNumberOfTimeBins(); | |
717 | ||
718 | // Allocate memory space for the digits buffer | |
719 | if (digits->GetNtime() == 0) | |
720 | { | |
721 | digits->Allocate(rowMax, colMax, ntbins); | |
722 | track0->Allocate(rowMax, colMax, ntbins); | |
723 | track1->Allocate(rowMax, colMax, ntbins); | |
724 | track2->Allocate(rowMax, colMax, ntbins); | |
725 | } | |
726 | ||
727 | indexes = digitsManager->GetIndexes(det); | |
728 | indexes->SetSM(GetSM()); | |
729 | indexes->SetStack(GetStack()); | |
730 | indexes->SetLayer(GetLayer()); | |
731 | indexes->SetDetNumber(det); | |
732 | if (indexes->IsAllocated() == kFALSE) | |
733 | indexes->Allocate(rowMax, colMax, ntbins); | |
734 | } | |
735 | ||
736 | // ntimebins data are ready to read | |
737 | for (it = 0; it < GetNumberOfTimeBins(); it++) | |
738 | { | |
739 | if (GetSignals()[it] > 0) | |
740 | { | |
741 | digits->SetDataUnchecked(GetRow(), GetCol(), it, GetSignals()[it]); | |
742 | ||
743 | indexes->AddIndexTBin(GetRow(), GetCol(), it); | |
744 | track0->SetDataUnchecked(GetRow(), GetCol(), it, 0); | |
745 | track1->SetDataUnchecked(GetRow(), GetCol(), it, 0); | |
746 | track2->SetDataUnchecked(GetRow(), GetCol(), it, 0); | |
747 | } | |
748 | } // tbins | |
749 | }// while Next() | |
750 | ||
751 | // what happens if the last HC is turned off? | |
752 | return det; | |
753 | //return -1; | |
754 | } | |
755 | ||
756 | //------------------------------------------------------------ | |
757 | Bool_t | |
758 | AliTRDrawStreamTB::Init() | |
759 | { | |
760 | // | |
761 | // general init | |
762 | // | |
763 | ||
764 | TDirectory *saveDir = gDirectory; | |
765 | ||
766 | if (!fGeometry) | |
767 | { | |
768 | fGeometry = new AliTRDgeometry(); | |
769 | } | |
770 | ||
771 | if (!fGeometry) | |
772 | { | |
773 | AliError("Geometry FAILED!"); | |
774 | return kFALSE; | |
775 | } | |
776 | ||
777 | fTRDfeeParam = AliTRDfeeParam::Instance(); | |
778 | if (!fTRDfeeParam) | |
779 | { | |
780 | AliError("AliTRDfeeParam FAILED!"); | |
781 | return kFALSE; | |
782 | } | |
783 | ||
784 | fMaxADCgeom = (Int_t)fGeometry->ADCmax(); | |
785 | ||
1ced3838 | 786 | // common additive is moved to be static for temp solution |
787 | // common additive should be delivered in the HC word 2 (3rd word) | |
788 | //fCommonAdditive = 10; | |
d4232bb6 | 789 | |
790 | ResetCounters(); | |
791 | ||
d4232bb6 | 792 | if (fgDebugStreamFlag == kTRUE) |
793 | { | |
794 | if (!fgDebugStreamer) | |
795 | { | |
796 | fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root"); | |
797 | fgStreamEventCounter = 0; | |
798 | ||
799 | if (fgDebugStreamer) | |
800 | { | |
801 | AliInfo(Form("Debug Streamer Initialized! Remember to delete! %s::DeleteDebugStream()", this->IsA()->GetName())); | |
802 | //fDebugStreamOwned = kTRUE; | |
803 | } | |
804 | else | |
805 | { | |
806 | AliError("Unable to init debug stream"); | |
807 | } | |
808 | } | |
809 | } | |
810 | ||
bb1009bf | 811 | // in case rawreader manages the mem buffers |
812 | // lets go for the next buffer | |
813 | if (fRawReader) | |
814 | { | |
815 | Int_t nextBuff = NextBuffer(); | |
816 | while (nextBuff != -1) | |
817 | { | |
818 | if (nextBuff > 0) | |
819 | return kTRUE; | |
820 | nextBuff = NextBuffer(); | |
821 | } | |
822 | } | |
823 | ||
d4232bb6 | 824 | saveDir->cd(); |
825 | ||
826 | return kTRUE; | |
827 | } | |
828 | ||
829 | void AliTRDrawStreamTB::DeleteDebugStream() | |
830 | { | |
831 | // | |
832 | // static helper function | |
833 | // | |
834 | ||
835 | if (fgDebugStreamer) | |
836 | { | |
837 | delete fgDebugStreamer; | |
838 | fgDebugStreamer = 0; | |
839 | } | |
840 | ||
841 | } | |
842 | ||
843 | //------------------------------------------------------------ | |
844 | Bool_t | |
845 | AliTRDrawStreamTB::InitBuffer(void *buffer, UInt_t length) | |
846 | { | |
847 | // | |
848 | // init the class before reading from the buffer | |
849 | // and read SM heading info: | |
850 | // -- super module header | |
851 | // -- stack headers + link status words | |
852 | // | |
853 | ||
854 | // not in the pre scan mode | |
7e8f4d17 | 855 | //get Equipment ID |
856 | if(fgStreamEventCounter == 0) fgFirstEquipmentID = fRawReader->GetEquipmentId(); | |
857 | fEquipmentID = fRawReader->GetEquipmentId(); | |
858 | //fgStreamEventCounter++; | |
859 | if(fEquipmentID == fgFirstEquipmentID) fgStreamEventCounter++; | |
860 | ||
d4232bb6 | 861 | |
862 | ResetCounters(); | |
863 | ||
864 | fpBegin = (UInt_t *)buffer; | |
865 | ||
866 | if (WORD_SIZE == 0) | |
867 | { | |
868 | AliFatal("Strange! Size of UInt_t == 0"); | |
869 | return kFALSE; | |
870 | } | |
871 | ||
872 | fWordLength = length/WORD_SIZE; | |
873 | fpEnd = fpBegin + fWordLength; | |
874 | fpPos = fpBegin; | |
875 | ||
876 | if (fpBegin == 0 || length <= 0) | |
877 | { | |
878 | AliError(Form("This will not work! Pointer to the buffer is 0x%08x of size %d", fpBegin, length)); | |
879 | return kFALSE; | |
880 | } | |
881 | ||
882 | SwapOnEndian(); | |
883 | ||
884 | if (fgDumpHead > 0) | |
885 | { | |
886 | AliInfo("------------------------------------------------"); | |
887 | if (DumpWords(fpBegin, fgDumpHead) == kFALSE) | |
888 | { | |
889 | AliError("Dump failed. Not enough data."); | |
890 | } | |
891 | AliInfo("------------------------------------------------"); | |
892 | } | |
893 | ||
894 | //decode SM | |
895 | DecodeSMInfo(fpPos, &fSM); | |
896 | ||
897 | if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM)); | |
898 | ||
899 | fpPos++; | |
900 | if (fpPos < fpEnd) | |
901 | { | |
902 | if (SkipWords(fSM.fHeaderSize) == kTRUE) | |
903 | { | |
904 | //decode stacks info | |
905 | //for (Int_t istack = 0; istack < fSM.fActiveStacks; istack++) | |
906 | for (Int_t istack = 0; istack < 5; istack++) | |
907 | { | |
908 | if (fSM.fStackActive[istack] == kFALSE) | |
909 | continue; | |
910 | ||
911 | fStack = &fSM.fStacks[istack]; | |
912 | DecodeStackInfo(fpPos, fStack); | |
913 | fpPos++; | |
914 | ||
915 | fSM.fNexpectedHalfChambers += fStack->fActiveLinks; | |
916 | ||
917 | if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack)); | |
918 | ||
919 | if (SkipWords(fStack->fHeaderSize) == kFALSE) | |
920 | { | |
921 | if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack head words missing"); | |
922 | return kFALSE; | |
923 | } | |
924 | } | |
925 | } | |
926 | else | |
927 | { | |
928 | return kFALSE; | |
929 | } | |
930 | } | |
931 | else | |
932 | { | |
933 | if (fgWarnError) AliWarning("No Stack info present. Strange."); | |
934 | if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing"); | |
935 | return kFALSE; | |
936 | } | |
937 | ||
938 | if (fgDebugFlag) AliDebug(5, Form("Expected half chambers : %d", fSM.fNexpectedHalfChambers)); | |
939 | ||
940 | //fpPos++; | |
941 | if (fpPos < fpEnd) | |
942 | { | |
943 | if (fgDebugFlag) AliDebug(5, "Init OK."); | |
944 | } | |
945 | else | |
946 | { | |
947 | if (fgWarnError) AliWarning("No data just after init. Strange."); | |
948 | if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing data"); | |
949 | return kFALSE; | |
950 | } | |
951 | ||
952 | return kTRUE; | |
953 | } | |
954 | ||
955 | //------------------------------------------------------------ | |
956 | Bool_t | |
957 | AliTRDrawStreamTB::DecodeSM(void *buffer, UInt_t length) | |
958 | { | |
959 | // | |
960 | // decode all sm at once | |
961 | // still here for devel and debug | |
962 | // | |
963 | ||
964 | //memset(&fSM, 0, sizeof(fSM)); | |
965 | ||
966 | ResetIterators(); | |
967 | ||
968 | fSM.fClean = kTRUE; | |
969 | if (InitBuffer(buffer, length) == kTRUE) | |
970 | { | |
971 | // no we are already set! | |
972 | // fpPos++; | |
973 | } | |
974 | else | |
975 | { | |
976 | if (fgWarnError) AliError("--- INIT failed. ---------------"); | |
977 | fSM.fClean = kFALSE; | |
978 | return kFALSE; | |
979 | } | |
980 | ||
981 | //decode data here | |
982 | //fSM.fActiveStacks | |
983 | for (Int_t istack = 0; istack < 5; istack++) | |
984 | { | |
985 | fStackNumber = istack; | |
986 | if (fSM.fStackActive[istack] == kFALSE) | |
987 | continue; | |
988 | ||
989 | fStack = &fSM.fStacks[istack]; | |
990 | ||
991 | //fStack[istack].fActiveLinks // max is 12 | |
992 | for (Int_t ilink = 0; ilink < 12; ilink++) | |
993 | { | |
994 | fStackLinkNumber = ilink; | |
995 | if (fStack->fLinksActive[ilink] == kFALSE) | |
996 | continue; | |
997 | ||
998 | if (fpPos >= fpEnd) | |
999 | { | |
1000 | if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing"); | |
1001 | fSM.fClean = kFALSE; | |
1002 | break; | |
1003 | } | |
1004 | ||
1005 | fHC = &fStack->fHalfChambers[ilink]; | |
1006 | ||
7e8f4d17 | 1007 | if (fgDebugStreamer) |
1008 | { | |
1009 | TTreeSRedirector &cstream = *fgDebugStreamer; | |
1010 | cstream << "LINKDataStream" | |
1011 | << "Event=" << fgStreamEventCounter | |
1012 | << ".equipID=" << fEquipmentID | |
1013 | << ".stack=" << fStackNumber | |
1014 | << ".link=" << fStackLinkNumber | |
1015 | << "\n"; | |
1016 | } | |
1017 | ||
1018 | ||
d4232bb6 | 1019 | if (fSM.fTrackletEnable == kTRUE) |
1020 | { | |
1021 | if (DecodeTracklets() == kFALSE) | |
1022 | { | |
d4232bb6 | 1023 | if (fgDebugStreamer) |
1024 | { | |
1025 | TTreeSRedirector &cstream = *fgDebugStreamer; | |
1026 | cstream << "TrackletDecodeError" | |
1027 | << "Event=" << fgStreamEventCounter | |
1028 | << ".Stack=" << fStackNumber | |
1029 | << ".Link=" << fStackLinkNumber | |
1030 | << ".EndOfTrackletCount=" << fEndOfTrackletCount | |
1031 | << "\n"; | |
1032 | } | |
1033 | ||
1034 | fSM.fClean = kFALSE; | |
1035 | SeekEndOfData(); | |
1036 | ||
1037 | if (fgWarnError) | |
1038 | { | |
1039 | AliError(Form("Failed stack %d link %d", fStackNumber, fStackLinkNumber)); | |
1040 | AliError(Form("Debug Event Counter : %d", fgStreamEventCounter)); | |
1041 | } | |
1042 | continue; | |
1043 | //return kFALSE; | |
1044 | } | |
1045 | } | |
1046 | ||
1047 | if (fpPos >= fpEnd) | |
1048 | { | |
1049 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing"); | |
1050 | fSM.fClean = kFALSE; | |
1051 | break; | |
1052 | } | |
1053 | ||
1054 | if (DecodeHC() == kFALSE) | |
1055 | { | |
d4232bb6 | 1056 | fSM.fClean = kFALSE; |
bb1009bf | 1057 | if (fgWarnError) |
1058 | { | |
1059 | AliError(Form("Dumping Words for Debugging Purpose =========================>")); | |
1060 | DumpWords(fpPos-8, 16); | |
1061 | AliError(Form("Dumping Done!")); | |
1062 | } | |
1063 | if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW during ADC data decoding or MCM header decoding | |
1064 | // we don't seek ENDOFRAWDATAMARKER | |
d4232bb6 | 1065 | |
1066 | if (fgWarnError) | |
1067 | { | |
1068 | AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC))); | |
1069 | AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC))); | |
bb1009bf | 1070 | AliError(Form("Debug Event Counter : %d\n\n\n", fgStreamEventCounter)); |
d4232bb6 | 1071 | } |
d4232bb6 | 1072 | |
1073 | continue; | |
1074 | //return kFALSE; | |
1075 | } | |
1076 | else | |
1077 | { | |
bb1009bf | 1078 | SeekEndOfData(); // make sure that finish off with the end of data markers |
d4232bb6 | 1079 | } |
1080 | ||
d4232bb6 | 1081 | } // ilink |
1082 | } // istack | |
1083 | ||
1084 | // for next() | |
1085 | ResetIterators(); | |
1086 | ||
1087 | if (fSM.fClean == kTRUE) | |
1088 | return kTRUE; | |
1089 | ||
1090 | if (fgCleanDataOnly && (fSM.fClean == kFALSE)) | |
1091 | { | |
1ced3838 | 1092 | if (fgWarnError) |
1093 | { | |
1094 | AliWarning("Buffer with errors. Returning FALSE."); | |
1095 | AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM))); | |
1096 | } | |
d4232bb6 | 1097 | fSM.fActiveStacks = 0; // Next will not give data |
1098 | return kFALSE; | |
1099 | } | |
1100 | ||
1101 | return kTRUE; | |
1102 | } | |
1103 | ||
1104 | //------------------------------------------------------------ | |
1105 | Int_t | |
1106 | AliTRDrawStreamTB::DecodeSM() | |
1107 | { | |
1108 | // | |
1109 | // decode SM data in case AliRawReader is in use | |
1110 | ||
1111 | if (fRawReader) | |
1112 | { | |
1113 | Int_t nextBuff = NextBuffer(); | |
1114 | while (nextBuff != -1) | |
1115 | { | |
1116 | if (nextBuff > 0) | |
1117 | return nextBuff; | |
1118 | nextBuff = NextBuffer(); | |
1119 | } | |
1120 | return -1; | |
1121 | } | |
1122 | else | |
1123 | { | |
1124 | AliWarning("AliRawReader not set."); | |
1125 | } | |
1126 | return kFALSE; | |
1127 | } | |
1128 | ||
1129 | //------------------------------------------------------------ | |
1130 | Int_t | |
1131 | AliTRDrawStreamTB::DecodeSM(AliRawReader *reader) | |
1132 | { | |
1133 | // | |
1134 | // decode SM with the AliRawReader | |
1135 | // | |
1136 | if (reader != 0) | |
1137 | { | |
1138 | fRawReader = reader; | |
1139 | return DecodeSM(); | |
1140 | } | |
1141 | else | |
1142 | { | |
1143 | AliWarning("Argument AliRawReader is 0."); | |
1144 | } | |
1145 | return kFALSE; | |
1146 | } | |
1147 | ||
1148 | //------------------------------------------------------------ | |
1149 | Bool_t | |
1150 | AliTRDrawStreamTB::SeekEndOfData() | |
1151 | { | |
1152 | // | |
1153 | // go to end of data marker | |
1154 | // | |
1155 | Int_t fEndOfDataCount = 0; | |
1156 | ||
1157 | while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) | |
1158 | { | |
1159 | fpPos++; | |
1160 | } | |
1161 | ||
1162 | while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd ) | |
1163 | { | |
1164 | fEndOfDataCount++; | |
1165 | fpPos++; | |
1166 | } | |
1167 | ||
1168 | // if (fEndOfDataCount == 0) | |
1169 | // { | |
1170 | // if (fgWarnError) AliWarning("End of buffer reached first. No end of data marker?"); | |
1171 | // return kFALSE; | |
1172 | // } | |
1173 | ||
1174 | return kTRUE; | |
1175 | } | |
1176 | ||
1177 | //------------------------------------------------------------ | |
1178 | Bool_t | |
1179 | AliTRDrawStreamTB::SeekNextMCMheader() | |
1180 | { | |
1181 | // | |
1182 | // go to mcm marker | |
1183 | // | |
1184 | ||
1185 | // move back to the mcm pos | |
1186 | fpPos = fMCM->fPos + 1; | |
1187 | ||
1188 | while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) | |
1189 | { | |
d4232bb6 | 1190 | if (MCM_HEADER_MASK_ERR(*fpPos) == 0) |
1191 | { | |
1192 | if (fgWarnError) AliWarning(Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos)); | |
1193 | return kTRUE; | |
1194 | } | |
1195 | fpPos++; | |
1196 | } | |
1197 | ||
1198 | SeekEndOfData(); | |
1199 | return kFALSE; | |
1200 | } | |
1201 | ||
1202 | //------------------------------------------------------------ | |
1203 | ||
1204 | Bool_t | |
1205 | AliTRDrawStreamTB::DecodeTracklets() | |
1206 | { | |
1207 | // | |
1208 | // decode tracklets | |
1209 | // | |
1210 | ||
1211 | fLinkTrackletCounter = 0; | |
1212 | fEndOfTrackletCount = 0; | |
1213 | ||
1214 | if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos)); | |
d4232bb6 | 1215 | |
1216 | while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd ) | |
1217 | { | |
1218 | ||
1219 | if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos)); | |
1220 | ||
d4232bb6 | 1221 | fLinkTrackletCounter++; |
1222 | ||
1223 | if (fLinkTrackletCounter > MAX_TRACKLETS_PERHC) | |
1224 | { | |
1225 | if (fgWarnError) AliWarning(Form("Max number of tracklets exceeded %d > %d. Something is wrong with the input data!", | |
1226 | fLinkTrackletCounter, MAX_TRACKLETS_PERHC)); | |
bb1009bf | 1227 | /* |
1228 | if (fgWarnError) | |
1229 | { | |
1230 | AliError(Form("Dumping Words for Debugging Purpose =========================>")); | |
1231 | DumpWords(fpPos-300, 320); | |
1232 | AliError(Form("Dumping Done!")); | |
1233 | } | |
1234 | */ | |
d4232bb6 | 1235 | |
1236 | if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets"); | |
1237 | return kFALSE; | |
1238 | } | |
1239 | ||
1240 | if (fgDebugStreamer) | |
1241 | { | |
1242 | // jan! | |
1243 | unsigned pid; | |
1244 | unsigned row; | |
1245 | signed defl; | |
1246 | signed ypos; | |
1247 | ||
1248 | double deflm; | |
1249 | double yposm; | |
1250 | ||
1251 | unsigned long val; | |
1252 | ||
1253 | val = *fpPos; | |
1254 | ||
1255 | pid = val >> 24; | |
1256 | row = (val >> 20) & 0xF; | |
1257 | defl = (val >> 13) & 0x7F; | |
1258 | defl = defl << 25 >> 25; | |
1259 | ypos = val & 0x1FFF; | |
1260 | ypos = ypos << 19 >> 19; | |
1261 | ||
1262 | deflm = defl * 140.0e-6; /* m */ | |
1263 | yposm = ypos * 160.0e-6; /* m */ | |
1264 | ||
1265 | TTreeSRedirector &cstream = *fgDebugStreamer; | |
1266 | cstream << "MCMtracklets" | |
1267 | << "Event=" << fgStreamEventCounter | |
1268 | << ".stack=" << fStackNumber | |
1269 | << ".link=" << fStackLinkNumber | |
1270 | << ".pid=" << pid | |
1271 | << ".row=" << row | |
1272 | << ".defl=" << defl | |
1273 | << ".ypos=" << ypos | |
1274 | << ".deflm=" << deflm | |
1275 | << ".yposm=" << yposm | |
1276 | << "\n"; | |
1277 | } | |
1278 | fpPos++; | |
1279 | } | |
1280 | ||
1281 | while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd ) | |
1282 | { | |
d4232bb6 | 1283 | if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos)); |
1284 | ||
1285 | fEndOfTrackletCount++; | |
1286 | fpPos++; | |
1287 | } | |
1288 | ||
1289 | if ( fEndOfTrackletCount < 2 ) | |
1290 | { | |
d4232bb6 | 1291 | if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing"); |
1292 | return kFALSE; | |
1293 | } | |
1294 | ||
1295 | return kTRUE; | |
1296 | } | |
1297 | ||
1298 | //------------------------------------------------------------ | |
1299 | Bool_t | |
1300 | AliTRDrawStreamTB::IsRowValid() | |
1301 | { | |
1302 | //SLOW GEOM | |
1303 | if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) || | |
1304 | (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 ) | |
1305 | { | |
1306 | if (fgWarnError) AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d" | |
1307 | , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM )); | |
1308 | if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadrow, "Wrong Row"); | |
1309 | return kFALSE; | |
1310 | } | |
1311 | return kTRUE; | |
1312 | } | |
1313 | ||
1314 | //------------------------------------------------------------ | |
1315 | Bool_t | |
1316 | AliTRDrawStreamTB::IsMCMheaderOK() | |
1317 | { | |
1318 | // | |
1319 | // check the mcm header | |
1320 | // | |
1321 | ||
bb1009bf | 1322 | if ( fMCM->fCorrupted > 1 ) |
d4232bb6 | 1323 | { |
1324 | if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"ADC mask Corrupted"); | |
bb1009bf | 1325 | if (fgWarnError) AliWarning(Form("Wrong ADC Mask word 0x%08x %s. Error : %d\n", *fMCM->fPos, DumpMCMadcMask(fMCM), fMCM->fCorrupted)); |
d4232bb6 | 1326 | return kFALSE; |
1327 | } | |
1328 | ||
1329 | if ( fMCM->fCorrupted > 0 ) | |
1330 | { | |
1331 | if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"Corrupted"); | |
bb1009bf | 1332 | if (fgWarnError) AliWarning(Form("Wrong MCM word 0x%08x %s. Error : %d\n", *fMCM->fPos, DumpMCMinfo(fMCM), fMCM->fCorrupted)); |
d4232bb6 | 1333 | return kFALSE; |
1334 | } | |
1335 | ||
1336 | if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 ) | |
1337 | { | |
1338 | if (fRawReader) fRawReader->AddMajorErrorLog(kWrongMCMorROB,"Wrong ROB or MCM"); | |
bb1009bf | 1339 | if (fgWarnError) AliWarning(Form("Wrong fMCM or fROB. %s\n", DumpMCMinfo(fMCM))); |
d4232bb6 | 1340 | return kFALSE; |
1341 | } | |
1342 | ||
1343 | if (IsRowValid() == kFALSE) | |
1344 | return kFALSE; | |
1345 | ||
1346 | return kTRUE; | |
1347 | } | |
bb1009bf | 1348 | |
1349 | //------------------------------------------------------------ | |
1350 | Bool_t | |
1351 | AliTRDrawStreamTB::IsMCMevCounterOK() | |
1352 | { | |
1353 | // | |
1354 | // Check the MCM event counter | |
1355 | // | |
1356 | ||
1357 | if (fEventCounter == 0) | |
1358 | { | |
1359 | fEventCounter = fMCM->fEvCounter; | |
1360 | } | |
1361 | ||
1362 | if (fEventCounter < fLastEventCounter) | |
1363 | { | |
1364 | fMCM->fCorrupted += 4; | |
1365 | if (fgWarnError) AliWarning(Form("Event from the past? Current %d Last %d %s. Error : %d\n", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM), fMCM->fCorrupted)); | |
1366 | if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ? Past-Future"); | |
1367 | return kFALSE; | |
1368 | } | |
1369 | ||
1370 | if (fEventCounter != fMCM->fEvCounter) | |
1371 | { | |
1372 | fMCM->fCorrupted += 4; | |
1373 | if (fgWarnError) AliWarning(Form("Event missmatch? FirstMCMs %d ThisMCMs %d %s. Error : %d\n", fEventCounter, fMCM->fEvCounter, DumpMCMinfo(fMCM), fMCM->fCorrupted)); | |
1374 | if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ?"); | |
1375 | return kFALSE; | |
1376 | } | |
1377 | ||
1378 | return kTRUE; | |
1379 | } | |
1380 | ||
d4232bb6 | 1381 | //------------------------------------------------------------ |
1382 | Bool_t | |
1383 | AliTRDrawStreamTB::DecodeMCMheader() | |
1384 | { | |
1385 | // | |
1386 | // decode the mcm header | |
1387 | // | |
1388 | ||
bb1009bf | 1389 | DecodeMCMheader(fpPos, fMCM); |
1390 | if (fHC->fCorrupted >= 16) | |
1391 | { | |
1392 | fpPos--; | |
1393 | return kFALSE; | |
1394 | } | |
d4232bb6 | 1395 | |
bb1009bf | 1396 | fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM); |
d4232bb6 | 1397 | |
bb1009bf | 1398 | if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || (fHC->fRawVMajor > 31 && fHC->fRawVMajor < 64)) //cover old and new version definition of ZS data |
d4232bb6 | 1399 | { |
1400 | fpPos++; | |
1401 | if ( fpPos < fpEnd ) | |
1402 | { | |
bb1009bf | 1403 | DecodeMask(fpPos, fMCM); |
1404 | if (fHC->fCorrupted >= 16) | |
1405 | { | |
1406 | fpPos--; | |
1407 | return kFALSE; | |
1408 | } | |
d4232bb6 | 1409 | MCMADCwordsWithTbins(fHC->fTimeBins, fMCM); |
1410 | fMCM->fAdcDataPos = fpPos + 1; | |
1411 | } | |
1412 | else | |
1413 | { | |
1414 | if (fgWarnError) AliWarning("Expected ADC mask word. Fail due to buffer END."); | |
1415 | if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing"); | |
1416 | return kFALSE; | |
1417 | } | |
1418 | } | |
1419 | else | |
1420 | { | |
1421 | UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL; | |
bb1009bf | 1422 | DecodeMask(&dummyMask, fMCM); |
d4232bb6 | 1423 | MCMADCwordsWithTbins(fHC->fTimeBins, fMCM); |
1424 | fMCM->fAdcDataPos = fpPos + 1; | |
1425 | } | |
1426 | ||
1427 | if (fgDebugFlag) | |
1428 | { | |
1429 | AliDebug(6, DumpMCMinfo(fMCM)); | |
1430 | AliDebug(7, DumpMCMadcMask(fMCM)); | |
1431 | } | |
1432 | ||
1433 | if (IsMCMheaderOK() == kFALSE) | |
d4232bb6 | 1434 | return kFALSE; |
d4232bb6 | 1435 | |
bb1009bf | 1436 | if (IsMCMevCounterOK() == kFALSE) |
d4232bb6 | 1437 | return kFALSE; |
d4232bb6 | 1438 | |
1439 | return kTRUE; | |
d4232bb6 | 1440 | } |
1441 | ||
1442 | //------------------------------------------------------------ | |
1443 | Bool_t | |
1444 | AliTRDrawStreamTB::IsHCheaderOK() | |
1445 | { | |
1446 | // | |
1447 | // check the half chamber header | |
1448 | // | |
1449 | ||
1450 | if (fHC->fCorrupted > 0) | |
1451 | { | |
1452 | if (fgWarnError) AliWarning(Form("Wrong HC Header word. Word 0x%08x Error : %d", *fHC->fPos, fHC->fCorrupted)); | |
1453 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "Corrupted"); | |
1454 | ||
1455 | return kFALSE; | |
1456 | } | |
1457 | ||
1458 | if (fHC->fStack < 0 || fHC->fStack > 4) | |
1459 | { | |
1460 | if (fgWarnError) AliWarning(Form("Wrong Stack %d", fHC->fStack)); | |
1461 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Wrong Stack"); | |
1462 | return kFALSE; | |
1463 | } | |
1464 | ||
6bd744d3 | 1465 | if (fgStackNumberChecker) |
d4232bb6 | 1466 | { |
6bd744d3 | 1467 | if (fHC->fStack != fStackNumber) |
1468 | { | |
1469 | if (fgWarnError) AliWarning(Form("Missmatch: Stack in HC header %d HW-stack %d", | |
d4232bb6 | 1470 | fHC->fStack, fStackNumber)); |
6bd744d3 | 1471 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Stack-HWstack"); |
6bd744d3 | 1472 | fStackNumber = -1; |
1473 | return kFALSE; | |
1474 | } | |
d4232bb6 | 1475 | } |
1476 | ||
1477 | if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNplan) | |
1478 | { | |
1479 | if (fgWarnError) AliWarning(Form("Wrong plane(layer) %d", fHC->fLayer)); | |
1480 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Wrong Plane"); | |
1481 | return kFALSE; | |
1482 | } | |
1483 | ||
7e8f4d17 | 1484 | if (fgStackLinkNumberChecker) |
d4232bb6 | 1485 | { |
7e8f4d17 | 1486 | |
1487 | if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1)) | |
1488 | { | |
1489 | if (fgWarnError) AliWarning(Form("Missmatch: plane(layer) in HCheader %d HW-Link %d | %s", | |
1490 | fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack))); | |
1491 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Plane-Link missmatch"); | |
7e8f4d17 | 1492 | fStackLinkNumber = -1; |
1493 | return kFALSE; | |
1494 | } | |
d4232bb6 | 1495 | } |
1496 | ||
1497 | if (fHC->fSide < 0 || fHC->fSide > 1) | |
1498 | { | |
1499 | if (fgWarnError) AliWarning(Form("Wrong Side %d", fHC->fSide)); | |
1500 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSide, "Wrong Side"); | |
1501 | return kFALSE; | |
1502 | } | |
1503 | ||
1504 | // SLOW GEOM | |
1505 | fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM); | |
1506 | if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet) | |
1507 | { | |
1508 | if (fgWarnError) AliWarning(Form("Wrong detector %d", fHC->fDET)); | |
1509 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det"); | |
1510 | return kFALSE; | |
1511 | } | |
1512 | ||
1513 | // SLOW GEOM | |
1514 | // this check fails - raw data inconsistent with geometry? | |
1515 | if (fHC->fSM != fGeometry->GetSector(fHC->fDET) | |
1516 | || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsect) | |
1517 | { | |
1518 | if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d", | |
1519 | fHC->fSM, fGeometry->GetSector(fHC->fDET), | |
1520 | fHC->fStack, fHC->fLayer, fHC->fDET)); | |
1521 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM"); | |
1522 | return kFALSE; | |
1523 | } | |
1524 | ||
1525 | // SLOW GEOM | |
1526 | // CPU EXPENSIVE!!! | |
1527 | fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack); | |
1528 | if (fHC->fROC < 0) | |
1529 | { | |
1530 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC"); | |
1531 | return kFALSE; | |
1532 | } | |
1533 | ||
1534 | fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM); | |
1535 | if (fHC->fRowMax < 1) | |
1536 | { | |
1537 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max"); | |
1538 | return kFALSE; | |
1539 | } | |
1540 | ||
1541 | fHC->fColMax = fGeometry->GetColMax(fHC->fROC); | |
1542 | if (fHC->fColMax < 1) | |
1543 | { | |
1544 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max"); | |
1545 | return kFALSE; | |
1546 | } | |
1547 | // extra - not needed | |
1548 | // if (fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsect) | |
1549 | // { | |
1550 | // if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d", | |
1551 | // fHC->fSM, fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack), | |
1552 | // fHC->fStack, fHC->fLayer)); | |
1553 | // return kFALSE; | |
1554 | // } | |
1555 | ||
1556 | return kTRUE; | |
1557 | } | |
1558 | ||
1559 | //------------------------------------------------------------ | |
1560 | Bool_t | |
1561 | AliTRDrawStreamTB::DecodeHCheader() | |
1562 | { | |
1563 | // | |
1564 | // decode the half chamber header | |
1565 | // | |
1566 | ||
1567 | DecodeHCwordH0(fpPos, fHC); | |
1568 | ||
1569 | if (fHC->fNExtraWords > 0) | |
1570 | { | |
1571 | fpPos++; | |
1572 | if (fpPos < fpEnd) | |
1573 | { | |
1574 | DecodeHCwordH1(fpPos, fHC); | |
1575 | } | |
1576 | else | |
1577 | { | |
1578 | if (fgWarnError) AliWarning("Expected HC header word 1. Fail due to buffer END."); | |
1579 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing"); | |
1580 | return kFALSE; | |
1581 | } | |
1582 | } | |
1583 | ||
1584 | if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC)); | |
1585 | if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC)); | |
1586 | ||
1587 | fHC->fDET = -1; | |
1588 | if (IsHCheaderOK() == kFALSE) | |
1589 | { | |
bb1009bf | 1590 | fHC->fCorrupted +=4; |
d4232bb6 | 1591 | return kFALSE; |
1592 | } | |
1593 | ||
1594 | return kTRUE; | |
1595 | } | |
1596 | ||
1597 | //------------------------------------------------------------ | |
1598 | Bool_t | |
1599 | AliTRDrawStreamTB::DecodeHC() | |
1600 | { | |
1601 | // | |
1602 | // decode the hc data | |
1603 | // function for devel & debug | |
1604 | // | |
1605 | ||
1606 | if (DecodeHCheader() == kFALSE) | |
1607 | { | |
1608 | if (fgDebugStreamer) | |
1609 | { | |
1610 | TTreeSRedirector &cstream = *fgDebugStreamer; | |
1611 | cstream << "HCDecodeError" | |
1612 | << "Event=" << fgStreamEventCounter | |
1613 | << ".stack=" << fStackNumber | |
1614 | << ".link=" << fStackLinkNumber | |
7e8f4d17 | 1615 | << ".hcCorrupted=" << fHC->fCorrupted |
d4232bb6 | 1616 | << ".hcRVmajor=" << fHC->fRawVMajor |
1617 | << ".hcDCSboard=" << fHC->fDCSboard | |
1618 | << ".hcSM=" << fHC->fSM | |
1619 | << ".hcStack=" << fHC->fStack | |
1620 | << ".hcLayer=" << fHC->fLayer | |
1621 | << ".hcSide=" << fHC->fSide | |
1622 | << ".hcTbins=" << fHC->fTimeBins | |
1623 | << ".hcBunchCross=" << fHC->fBunchCrossCounter | |
1624 | << ".hcPreTrig=" << fHC->fPreTriggerCounter | |
1625 | << ".hcPreTrigPh=" << fHC->fPreTriggerPhase | |
1626 | << ".hcDet=" << fHC->fDET | |
1627 | << ".hcROC=" << fHC->fROC | |
7e8f4d17 | 1628 | << ".hcRowMax=" << fHC->fRowMax |
1629 | << ".hcColMax=" << fHC->fColMax | |
d4232bb6 | 1630 | << "\n"; |
1631 | } | |
1632 | ||
1633 | if (fgWarnError) AliWarning("Header decode failed."); | |
1634 | return kFALSE; | |
1635 | } | |
1636 | else | |
1637 | { | |
1638 | fpPos++; | |
1639 | if (fpPos >= fpEnd) | |
1640 | { | |
1641 | if (fgWarnError) AliWarning("No MCM data? Not enough data in the buffer."); | |
1642 | if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing"); | |
1643 | return kFALSE; | |
1644 | } | |
1645 | } | |
1646 | ||
1647 | fHC->fMCMmax = 0; | |
1648 | while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd) | |
1649 | { | |
1650 | if (fHC->fMCMmax > TRD_MAX_MCM) | |
1651 | { | |
1652 | if (fgWarnError) AliWarning("More mcm data than expected!"); | |
1653 | if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!"); | |
1654 | return kFALSE; | |
1655 | } | |
1656 | ||
1657 | fMCM = &fHC->fMCMs[fHC->fMCMmax]; | |
1658 | ||
1659 | if (DecodeMCMheader() == kFALSE) | |
1660 | { | |
1661 | if (fgDebugStreamer) | |
1662 | { | |
1663 | TTreeSRedirector &cstream = *fgDebugStreamer; | |
1664 | cstream << "MCMDecodeError" | |
1665 | << "Event=" << fgStreamEventCounter | |
1666 | << ".stack=" << fStackNumber | |
1667 | << ".link=" << fStackLinkNumber | |
1668 | << ".hcDCSboard=" << fHC->fDCSboard | |
1669 | << ".hcSM=" << fHC->fSM | |
1670 | << ".hcStack=" << fHC->fStack | |
1671 | << ".hcLayer=" << fHC->fLayer | |
1672 | << ".hcSide=" << fHC->fSide | |
1673 | << ".hcBunchCross=" << fHC->fBunchCrossCounter | |
1674 | << ".hcPreTrig=" << fHC->fPreTriggerCounter | |
1675 | << ".hcPreTrigPh=" << fHC->fPreTriggerPhase | |
1676 | << ".hcDet=" << fHC->fDET | |
1677 | ||
1678 | << ".mcmCorrupted=" << fMCM->fCorrupted | |
1679 | << ".mcmROB=" << fMCM->fROB | |
1680 | << ".mcmMCM=" << fMCM->fMCM | |
1681 | << ".mcmADCMaskWord=" << fMCM->fADCMaskWord | |
1682 | << ".mcmEventCounter=" << fMCM->fEvCounter | |
1683 | ||
1684 | << ".fEventCounter=" << fEventCounter | |
1685 | << ".fLastEventCounter=" << fLastEventCounter | |
1686 | << "\n"; | |
1687 | } | |
1688 | ||
bb1009bf | 1689 | if (fgSkipData == kTRUE || fHC->fCorrupted >= 16) |
1690 | return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose | |
d4232bb6 | 1691 | } |
1692 | ||
1693 | fHC->fMCMmax++; | |
1694 | ||
1695 | if (fMCM->fADCmax > 0) | |
1696 | { | |
1697 | fpPos++; | |
1698 | if (fpPos >= fpEnd) | |
1699 | { | |
1700 | if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected.")); | |
1701 | if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing"); | |
1702 | } | |
dc25a859 | 1703 | |
bb1009bf | 1704 | unsigned long randVal, iniVal, expectedVal; |
1705 | Int_t endbits = ENDBITS; | |
1706 | ||
d4232bb6 | 1707 | for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++) |
1708 | { | |
1709 | fADC = &fMCM->fADCs[iadc]; | |
1710 | fADC->fADCnumber = fMCM->fADCchannel[iadc]; | |
1711 | ||
1712 | if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.", | |
1713 | iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc])); | |
1714 | ||
1715 | if (fpPos + fMCM->fSingleADCwords >= fpEnd) | |
1716 | { | |
1717 | if (fgDebugStreamer) | |
1718 | { | |
1719 | TTreeSRedirector &cstream = *fgDebugStreamer; | |
1ced3838 | 1720 | Int_t ierr = -99; |
d4232bb6 | 1721 | cstream << "ADCDecodeError" |
1722 | << "Event=" << fgStreamEventCounter | |
1723 | << ".hcSM=" << fHC->fSM | |
1724 | << ".hcStack=" << fHC->fStack | |
1725 | << ".hcLayer=" << fHC->fLayer | |
7e8f4d17 | 1726 | << ".hcSide=" << fHC->fSide |
1727 | << ".hcDet=" << fHC->fDET | |
d4232bb6 | 1728 | << ".mcmROB=" << fMCM->fROB |
1729 | << ".mcmMCM=" << fMCM->fMCM | |
1730 | << ".mcmADCMaskWord=" << fMCM->fADCMaskWord | |
1ced3838 | 1731 | << ".adcErr=" << ierr |
1732 | << ".adcNumber=" << ierr | |
d4232bb6 | 1733 | << "\n"; |
1734 | } | |
1735 | ||
1736 | if (fgWarnError) AliWarning(Form("This is ADC %d of %d. ADC number is %d.", iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc])); | |
1737 | if (fgWarnError) AliWarning("--> ADC (10 words) expected. Not enough data in the buffer."); | |
1738 | if (fgWarnError) AliWarning(Form("--> ADC mask : %s", DumpMCMadcMask(fMCM))); | |
1739 | ||
1740 | if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing - less than expected"); | |
1741 | return kFALSE; | |
1742 | } | |
1743 | ||
bb1009bf | 1744 | if (fHC->fRawVMajor < 64) // normal(real) ADC data |
1745 | { | |
1746 | if (DecodeADC() == kFALSE) | |
1747 | { | |
1748 | // check if we are out of the det when the pad is shared | |
1749 | if (fADC->fIsShared && fADC->fCorrupted == 4) | |
1750 | { | |
1751 | fADC->fCOL = -1; | |
1752 | fpPos = fADC->fPos + fMCM->fSingleADCwords; | |
1753 | } | |
1754 | else | |
1755 | { | |
1756 | if (fgWarnError) AliWarning(Form("ADC decode failed.")); | |
1757 | ||
1758 | if (fgDebugStreamer) | |
1759 | { | |
1760 | TTreeSRedirector &cstream = *fgDebugStreamer; | |
1761 | cstream << "ADCDecodeError" | |
1762 | << "Event=" << fgStreamEventCounter | |
1763 | << ".hcSM=" << fHC->fSM | |
1764 | << ".hcStack=" << fHC->fStack | |
1765 | << ".hcLayer=" << fHC->fLayer | |
1766 | << ".hcSide=" << fHC->fSide | |
1767 | << ".hcDet=" << fHC->fDET | |
1768 | << ".mcmROB=" << fMCM->fROB | |
1769 | << ".mcmMCM=" << fMCM->fMCM | |
1770 | << ".mcmADCMaskWord=" << fMCM->fADCMaskWord | |
1771 | << ".adcErr=" << fADC->fCorrupted | |
1772 | << ".adcNumber=" << fADC->fADCnumber | |
1773 | << "\n"; | |
1774 | } | |
1775 | if (fHC->fCorrupted < 16) | |
1776 | fpPos = fADC->fPos + fMCM->fSingleADCwords; | |
1777 | ||
1778 | if (fgSkipData == kTRUE || fHC->fCorrupted >= 16) | |
1779 | return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose | |
1780 | } | |
1781 | } | |
1782 | } | |
1783 | else // test pattern data | |
dc25a859 | 1784 | { |
dc25a859 | 1785 | if (fHC->fRawVMajorOpt == 1) //test pattern 1 |
1786 | { | |
bb1009bf | 1787 | Int_t iCpu = iadc/5; |
1788 | if(iadc==20) iCpu = 3; | |
1789 | if(iadc%5==0 && iadc!=20) randVal = (1 << 9) | (fMCM->fROB << 6) | (fMCM->fMCM << 2) | iCpu; | |
dc25a859 | 1790 | if (DecodeADCTP1(&randVal,&endbits) == kFALSE) |
1791 | { | |
bb1009bf | 1792 | if (fgWarnError) AliWarning(Form("Summary: Test Pattern ADC data are corrupted in channel %d %s\n", iadc, DumpMCMinfo(fMCM))); |
dc25a859 | 1793 | if (fgDebugStreamer) |
1794 | { | |
1795 | TTreeSRedirector &cstream = *fgDebugStreamer; | |
1796 | cstream << "ADCDecodeError" | |
1797 | << "Event=" << fgStreamEventCounter | |
1798 | << ".hcSM=" << fHC->fSM | |
1799 | << ".hcStack=" << fHC->fStack | |
1800 | << ".hcLayer=" << fHC->fLayer | |
1801 | << ".hcSide=" << fHC->fSide | |
1802 | << ".hcDet=" << fHC->fDET | |
1803 | << ".mcmROB=" << fMCM->fROB | |
1804 | << ".mcmMCM=" << fMCM->fMCM | |
1805 | << ".mcmADCMaskWord=" << fMCM->fADCMaskWord | |
1806 | << ".adcErr=" << fADC->fCorrupted | |
1807 | << ".adcNumber=" << fADC->fADCnumber | |
1808 | << "\n"; | |
1809 | } | |
bb1009bf | 1810 | if (fHC->fCorrupted < 16) |
1811 | fpPos = fADC->fPos + fMCM->fSingleADCwords; | |
dc25a859 | 1812 | |
bb1009bf | 1813 | if (fgSkipData == kTRUE || fHC->fCorrupted >= 16) |
1814 | return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose | |
dc25a859 | 1815 | } |
1816 | } | |
bb1009bf | 1817 | |
1818 | if (fHC->fRawVMajorOpt == 2 || fHC->fRawVMajorOpt == 3) //test pattern 2 or 3 | |
dc25a859 | 1819 | { |
bb1009bf | 1820 | iniVal = (fHC->fSM << 6) | (fHC->fStack << 0) | (fHC->fLayer << 3); |
1821 | iniVal = iniVal + 0x49; | |
1822 | iniVal = (iniVal << 9) | (fMCM->fROB << 6) | (fMCM->fMCM << 2) | (fMCM->fEvCounter << 20); | |
1823 | Int_t iCpu = iadc/5; | |
1824 | if (iadc==20) iCpu = 3; | |
1825 | if (iadc%5==0 && iadc!=20) | |
1826 | { | |
1827 | if (fHC->fRawVMajorOpt == 2) { expectedVal = ((iniVal | iCpu) << 6) + 1; }; | |
1828 | if (fHC->fRawVMajorOpt == 3) { expectedVal = iniVal | iCpu; }; | |
1829 | } | |
1830 | if (DecodeADCTP23(&expectedVal) == kFALSE) | |
1831 | { | |
1832 | if (fgWarnError) AliWarning(Form("Summary: Test Pattern ADC data are corrupted in channel %d %s\n", iadc, DumpMCMinfo(fMCM))); | |
1833 | if (fgDebugStreamer) | |
1834 | { | |
1835 | TTreeSRedirector &cstream = *fgDebugStreamer; | |
1836 | cstream << "ADCDecodeError" | |
1837 | << "Event=" << fgStreamEventCounter | |
1838 | << ".hcSM=" << fHC->fSM | |
1839 | << ".hcStack=" << fHC->fStack | |
1840 | << ".hcLayer=" << fHC->fLayer | |
7e8f4d17 | 1841 | << ".hcSide=" << fHC->fSide |
1842 | << ".hcDet=" << fHC->fDET | |
bb1009bf | 1843 | << ".mcmROB=" << fMCM->fROB |
1844 | << ".mcmMCM=" << fMCM->fMCM | |
1845 | << ".mcmADCMaskWord=" << fMCM->fADCMaskWord | |
1846 | << ".adcErr=" << fADC->fCorrupted | |
1847 | << ".adcNumber=" << fADC->fADCnumber | |
1848 | << "\n"; | |
1849 | } | |
1850 | if (fHC->fCorrupted < 16) | |
1851 | fpPos = fADC->fPos + fMCM->fSingleADCwords; | |
1852 | ||
1853 | if (fgSkipData == kTRUE || fHC->fCorrupted >= 16) | |
1854 | return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose | |
1855 | } | |
1856 | } | |
1857 | } | |
1858 | } | |
1859 | } | |
d4232bb6 | 1860 | else |
1861 | { | |
1862 | fpPos++; | |
1863 | } | |
1864 | }//while eof data | |
1865 | ||
1866 | if (fpPos >= fpEnd) | |
1867 | { | |
1868 | if (fgWarnError) AliWarning("We are at the end of buffer. There should be one more word left."); | |
d4232bb6 | 1869 | return kFALSE; |
1870 | } | |
1871 | ||
1872 | return kTRUE; | |
1873 | } | |
d4232bb6 | 1874 | //------------------------------------------------------------ |
dc25a859 | 1875 | |
d4232bb6 | 1876 | Bool_t |
1877 | AliTRDrawStreamTB::DecodeADC() | |
1878 | { | |
1879 | // | |
1880 | // decode single ADC channel | |
1881 | // | |
1882 | ||
1883 | fADC->fCorrupted = 0; | |
1884 | fMaskADCword = ADC_WORD_MASK(*fpPos); | |
1885 | fADC->fPos = fpPos; | |
d4232bb6 | 1886 | fTbinADC = 0; |
1887 | ||
1888 | for (Int_t i = 0; i < TRD_MAX_TBINS; i++) | |
1889 | fADC->fSignals[i] = 0; | |
1890 | ||
1891 | for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++) | |
1892 | { | |
bb1009bf | 1893 | if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) |
1894 | { | |
1895 | if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos)); | |
1896 | fADC->fCorrupted += 16; | |
1897 | fHC->fCorrupted += 16; | |
1898 | fpPos--; | |
1899 | ||
1900 | return kFALSE; | |
1901 | } | |
d4232bb6 | 1902 | if (fMaskADCword != ADC_WORD_MASK(*fpPos)) |
1903 | { | |
d4232bb6 | 1904 | fADC->fCorrupted += 1; |
1ced3838 | 1905 | if (fgWarnError) AliWarning(Form("Mask Change in ADC data Previous word (%d) : 0x%08x Previous mask : 0x%08x Current word(%d) : 0x%08x Current mask : 0x%08x", |
1906 | iw - 1, *(fpPos-1), fMaskADCword, iw, *fpPos, ADC_WORD_MASK(*fpPos))); | |
d4232bb6 | 1907 | if (fRawReader) fRawReader->AddMajorErrorLog(kADCmaskMissmatch, "Mask change inside single channel"); |
d4232bb6 | 1908 | break; |
1909 | } | |
1ced3838 | 1910 | |
1911 | // here we subtract the baseline ( == common additive) | |
1912 | fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive; | |
1913 | fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive; | |
1914 | fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive; | |
d4232bb6 | 1915 | |
1916 | fTbinADC += 3; | |
1917 | fpPos++; | |
1918 | } | |
1919 | ||
1920 | if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) | |
1921 | { | |
1922 | fADC->fIsShared = kTRUE; | |
1923 | } | |
1924 | else | |
1925 | { | |
1926 | fADC->fIsShared = kFALSE; | |
1927 | } | |
1928 | ||
1929 | if ( fADC->fADCnumber >= fMaxADCgeom - 1) | |
1930 | { | |
1931 | // let us guess the Column | |
1932 | // take the one before last ADC and shift by one column | |
1933 | // later we check if we are inside the limits of the chamber | |
1934 | fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1); | |
1935 | fADC->fCOL--; | |
1936 | } | |
1937 | else | |
1938 | { | |
1939 | fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber); | |
1940 | } | |
1941 | ||
1942 | if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0) | |
1943 | { | |
1944 | if (fADC->fIsShared == kFALSE) | |
1945 | { | |
7e8f4d17 | 1946 | fADC->fCorrupted += 2; |
d4232bb6 | 1947 | if (fgWarnError) AliWarning(Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s", |
1948 | fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM))); | |
1949 | if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadcolumn, "Wrong column"); | |
1950 | } | |
1951 | else | |
1952 | { | |
1953 | // flag it - we are out of the det when the pad is shared | |
1954 | if (fgDebugFlag) AliDebug(10, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s", | |
1955 | fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM))); | |
7e8f4d17 | 1956 | fADC->fCorrupted += 4; |
d4232bb6 | 1957 | } |
1958 | } | |
1959 | ||
1960 | if (fADC->fCorrupted > 0) | |
1961 | { | |
1962 | return kFALSE; | |
1963 | } | |
1964 | ||
1965 | fDecodedADCs++; | |
1966 | return kTRUE; | |
1967 | } | |
dc25a859 | 1968 | //------------------------------------------------------------ |
1969 | ||
1970 | Bool_t | |
bb1009bf | 1971 | AliTRDrawStreamTB::DecodeADCTP1(unsigned long *randVal, Int_t *endbits) |
dc25a859 | 1972 | { |
1973 | // | |
1974 | // decode test pattern ADC channel | |
1975 | // | |
1976 | ||
1977 | unsigned long expected; | |
1978 | ||
1979 | fADC->fCorrupted = 0; | |
1980 | fADC->fPos = fpPos; | |
dc25a859 | 1981 | fTbinADC = 0; |
1982 | ||
1983 | for (Int_t i = 0; i < TRD_MAX_TBINS; i++) | |
1984 | fADC->fSignals[i] = 0; | |
1985 | ||
1986 | for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++) | |
1987 | { | |
bb1009bf | 1988 | if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) |
dc25a859 | 1989 | { |
bb1009bf | 1990 | if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos)); |
1991 | fADC->fCorrupted += 16; | |
1992 | fHC->fCorrupted += 16; | |
1993 | fpPos--; | |
1994 | ||
dc25a859 | 1995 | return kFALSE; |
1996 | } | |
1997 | expected = (AdvancePseudoRandom(randVal) << 2) | *endbits; | |
1998 | expected |= AdvancePseudoRandom(randVal) << 12; | |
1999 | expected |= AdvancePseudoRandom(randVal) << 22; | |
dc25a859 | 2000 | if (*fpPos != expected) |
2001 | { | |
bb1009bf | 2002 | if (fgWarnError) AliError(Form("Error: fpPos=%d, size=%d, found=0x%08lx, expected=0x%08lx",iw, fMCM->fSingleADCwords, *fpPos, expected)); |
2003 | fADC->fCorrupted += 32; //test pattern corrupted | |
dc25a859 | 2004 | } |
2005 | fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2); | |
2006 | fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12); | |
2007 | fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22); | |
2008 | ||
2009 | fTbinADC += 3; | |
2010 | fpPos++; | |
2011 | } | |
2012 | *endbits = *endbits ^ 0x01; | |
2013 | ||
2014 | if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) | |
2015 | { | |
2016 | fADC->fIsShared = kTRUE; | |
2017 | } | |
2018 | else | |
2019 | { | |
2020 | fADC->fIsShared = kFALSE; | |
2021 | } | |
2022 | ||
2023 | if ( fADC->fADCnumber >= fMaxADCgeom - 1) | |
2024 | { | |
dc25a859 | 2025 | fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1); |
2026 | fADC->fCOL--; | |
2027 | } | |
2028 | else | |
2029 | { | |
2030 | fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber); | |
2031 | } | |
2032 | ||
bb1009bf | 2033 | if (fADC->fCorrupted > 0) |
dc25a859 | 2034 | { |
bb1009bf | 2035 | return kFALSE; |
2036 | } | |
d4232bb6 | 2037 | |
bb1009bf | 2038 | fDecodedADCs++; |
2039 | return kTRUE; | |
2040 | } | |
2041 | //-------------------------------------------------------- | |
2042 | ||
2043 | Bool_t | |
2044 | AliTRDrawStreamTB::DecodeADCTP23(unsigned long *expected) | |
2045 | { | |
2046 | // | |
2047 | // decode test pattern ADC channel | |
2048 | // | |
2049 | ||
2050 | fADC->fCorrupted = 0; | |
2051 | fADC->fPos = fpPos; | |
2052 | fTbinADC = 0; | |
2053 | ||
2054 | for (Int_t i = 0; i < TRD_MAX_TBINS; i++) | |
2055 | fADC->fSignals[i] = 0; | |
2056 | ||
2057 | for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++) | |
2058 | { | |
2059 | if (*fpPos == END_OF_TRACKLET_MARKERNEW) | |
2060 | { | |
2061 | if (fgWarnError) AliError(Form("There should be ADC data. We meet END_OF_TRACKLET_MARKER 0x%08x",*fpPos)); | |
2062 | fADC->fCorrupted += 16; | |
2063 | fHC->fCorrupted += 16; | |
2064 | fpPos--; | |
2065 | ||
2066 | return kFALSE; | |
2067 | } | |
2068 | if (*fpPos != *expected) | |
2069 | { | |
2070 | if (fgWarnError) | |
2071 | { | |
2072 | if (fHC->fRawVMajorOpt == 2) | |
2073 | { | |
2074 | AliError(Form("Error: fpPos=%d, size=%d, found=0x%08lx, expected=0x%08lx",iw, fMCM->fSingleADCwords, *fpPos, *expected)); | |
2075 | AliError(Form("Found ev.cnt. %ld, expected %ld", (*fpPos >> 26), (*expected >> 26))); | |
2076 | AliError(Form("Found sector %ld, expected %ld", (*fpPos >> 21) & 0x1f - 1, (*expected >> 21) & 0x1f - 1)); | |
2077 | AliError(Form("Found layer %ld, expected %ld", (*fpPos >> 18) & 0x07 - 1, (*expected >> 18) & 0x07 - 1)); | |
2078 | AliError(Form("Found chamber %ld, expected %ld", (*fpPos >> 15) & 0x07 - 1, (*expected >> 15) & 0x07 - 1)); | |
2079 | AliError(Form("Found ROB %ld, expected %ld", (*fpPos >> 12) & 0x07, (*expected >> 12) & 0x07)); | |
2080 | AliError(Form("Found MCM %ld, expected %ld", (*fpPos >> 8) & 0x0f, (*expected >> 8) & 0x0f)); | |
2081 | AliError(Form("Found CPU %ld, expected %ld", (*fpPos >> 6) & 0x03, (*expected >> 6) & 0x03)); | |
2082 | AliError(Form("Found counter %ld, expected %ld\n", (*fpPos >> 0) & 0x3f, (*expected >> 0) & 0xf)); | |
2083 | } | |
2084 | if (fHC->fRawVMajorOpt == 3) | |
2085 | { | |
2086 | AliError(Form("Error: fpPos=%d, size=%d, found=0x%08lx, expected=0x%08lx",iw, fMCM->fSingleADCwords, *fpPos, *expected)); | |
2087 | AliError(Form("Found ev.cnt. %ld, expected %ld", (*fpPos >> 20), (*expected >> 20))); | |
2088 | AliError(Form("Found sector %ld, expected %ld", (*fpPos >> 15) & 0x1f - 1, (*expected >> 15) & 0x1f - 1)); | |
2089 | AliError(Form("Found layer %ld, expected %ld", (*fpPos >> 12) & 0x07 - 1, (*expected >> 12) & 0x07 - 1)); | |
2090 | AliError(Form("Found chamber %ld, expected %ld", (*fpPos >> 9) & 0x07 - 1, (*expected >> 9) & 0x07 - 1)); | |
2091 | AliError(Form("Found ROB %ld, expected %ld", (*fpPos >> 6) & 0x07, (*expected >> 6) & 0x07)); | |
2092 | AliError(Form("Found MCM %ld, expected %ld", (*fpPos >> 2) & 0x0f, (*expected >> 2) & 0x0f)); | |
2093 | AliError(Form("Found CPU %ld, expected %ld\n", (*fpPos >> 0) & 0x03, (*expected >> 0) & 0x03)); | |
2094 | } | |
2095 | ||
2096 | } | |
2097 | fADC->fCorrupted += 32; //test pattern corrupted | |
2098 | } | |
2099 | fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2); | |
2100 | fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12); | |
2101 | fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22); | |
2102 | ||
2103 | fTbinADC += 3; | |
2104 | fpPos++; | |
2105 | if (fHC->fRawVMajorOpt == 2) (*expected)++; | |
2106 | } | |
2107 | ||
2108 | if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) | |
2109 | { | |
2110 | fADC->fIsShared = kTRUE; | |
2111 | } | |
2112 | else | |
2113 | { | |
2114 | fADC->fIsShared = kFALSE; | |
2115 | } | |
2116 | ||
2117 | if ( fADC->fADCnumber >= fMaxADCgeom - 1) | |
2118 | { | |
2119 | fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1); | |
2120 | fADC->fCOL--; | |
2121 | } | |
2122 | else | |
2123 | { | |
2124 | fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber); | |
dc25a859 | 2125 | } |
dc25a859 | 2126 | |
2127 | if (fADC->fCorrupted > 0) | |
2128 | { | |
2129 | return kFALSE; | |
2130 | } | |
2131 | ||
2132 | fDecodedADCs++; | |
2133 | return kTRUE; | |
2134 | } | |
d4232bb6 | 2135 | //-------------------------------------------------------- |
dc25a859 | 2136 | |
bb1009bf | 2137 | |
d4232bb6 | 2138 | void AliTRDrawStreamTB::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const |
2139 | { | |
2140 | // | |
2141 | // Decode the data *word into SM info structure | |
2142 | // | |
2143 | ||
2144 | sm->fPos = (UInt_t*)word; | |
2145 | ||
2146 | // do it once here | |
2147 | UInt_t vword = *word; | |
2148 | sm->fHeaderSize = SM_HEADER_SIZE(vword); | |
2149 | ||
2150 | if (TRACKLETS_ENABLED(vword) > 0) | |
2151 | sm->fTrackletEnable = kTRUE; | |
2152 | else | |
2153 | sm->fTrackletEnable = kFALSE; | |
2154 | ||
2155 | UInt_t stackMask = STACK_MASK(vword); | |
2156 | sm->fActiveStacks = 0; | |
2157 | for (Int_t i = 0; i < 5; i++) | |
2158 | { | |
2159 | //if ((stackMask >> i) & 0x1 > 0) | |
2160 | if (IS_BIT_SET(stackMask,i) > 0) | |
2161 | { | |
2162 | sm->fStackActive[i] = kTRUE; | |
2163 | sm->fActiveStacks++; | |
2164 | } | |
2165 | else | |
2166 | { | |
2167 | sm->fStackActive[i] = kFALSE; | |
2168 | } | |
2169 | } | |
2170 | } | |
2171 | ||
2172 | //-------------------------------------------------------- | |
2173 | const char *AliTRDrawStreamTB::DumpSMInfo(const struct AliTRDrawSM *sm) | |
2174 | { | |
2175 | // | |
2176 | // Get SM structure into a const char | |
2177 | // | |
2178 | ||
2179 | return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d", | |
2180 | *sm->fPos, | |
2181 | sm->fHeaderSize, sm->fTrackletEnable, | |
2182 | sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2], | |
2183 | sm->fStackActive[3], sm->fStackActive[4]); | |
2184 | } | |
2185 | ||
2186 | //-------------------------------------------------------- | |
2187 | void AliTRDrawStreamTB::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const | |
2188 | { | |
2189 | // | |
2190 | // Decode stack info - active links | |
2191 | // | |
2192 | ||
2193 | st->fPos = (UInt_t*)word; | |
2194 | ||
2195 | // do it once here | |
2196 | UInt_t vword = *word; | |
2197 | st->fHeaderSize = STACK_HEADER_SIZE(vword); | |
2198 | ||
2199 | UInt_t linkMask = STACK_LINK_WORD(vword); | |
2200 | st->fActiveLinks = 0; | |
2201 | for (Int_t i = 0; i < 12; i++) | |
2202 | { | |
2203 | //if (linkMask & (0x1 << i) > 0) | |
2204 | if (IS_BIT_SET(linkMask,i) > 0) | |
2205 | { | |
2206 | st->fLinksActive[i] = kTRUE; | |
2207 | st->fTrackletDecode[i] = kTRUE; | |
2208 | st->fHCDecode[i] = kTRUE; | |
2209 | st->fActiveLinks++; | |
2210 | } | |
2211 | else | |
2212 | { | |
2213 | st->fTrackletDecode[i] = kFALSE; | |
2214 | st->fLinksActive[i] = kFALSE; | |
2215 | st->fHCDecode[i] = kFALSE; | |
2216 | } | |
2217 | } | |
2218 | } | |
2219 | ||
2220 | //-------------------------------------------------------- | |
2221 | const char *AliTRDrawStreamTB::DumpStackInfo(const struct AliTRDrawStack *st) | |
2222 | { | |
2223 | // | |
2224 | // format the string with the stack info | |
2225 | // | |
2226 | return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d", | |
2227 | *st->fPos, | |
2228 | st->fHeaderSize, | |
2229 | st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3], | |
2230 | st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7], | |
2231 | st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]); | |
2232 | } | |
2233 | ||
2234 | //-------------------------------------------------------- | |
2235 | void AliTRDrawStreamTB::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const | |
2236 | { | |
2237 | // | |
2238 | // decode the hc header word 0 | |
2239 | // | |
2240 | ||
2241 | // do it once here | |
2242 | UInt_t vword = *word; | |
2243 | ||
2244 | hc->fCorrupted = HC_HEADER_MASK_ERR(vword); | |
2245 | if (hc->fCorrupted > 0) | |
2246 | { | |
2247 | hc->fH0ErrorCounter++; | |
2248 | } | |
2249 | ||
2250 | hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword); | |
2251 | hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword); | |
dc25a859 | 2252 | hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword); |
d4232bb6 | 2253 | hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword); |
2254 | hc->fNExtraWords = HC_EXTRA_WORDS(vword); | |
2255 | hc->fDCSboard = HC_DCS_BOARD(vword); | |
2256 | hc->fSM = HC_SM_NUMBER(vword); | |
2257 | hc->fStack = HC_STACK_NUMBER(vword); | |
2258 | hc->fLayer = HC_LAYER_NUMBER(vword); | |
2259 | hc->fSide = HC_SIDE_NUMBER(vword); | |
2260 | ||
2261 | hc->fPos[0] = (UInt_t*)word; | |
2262 | ||
2263 | } | |
2264 | ||
2265 | //-------------------------------------------------------- | |
2266 | void AliTRDrawStreamTB::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const | |
2267 | { | |
2268 | // | |
2269 | // | |
2270 | // | |
2271 | ||
2272 | // do it once here | |
2273 | UInt_t vword = *word; | |
2274 | ||
7e8f4d17 | 2275 | hc->fCorrupted += 2 * HC_HEADER_MASK_ERR(vword); |
2276 | if (hc->fCorrupted >= 2) | |
d4232bb6 | 2277 | { |
2278 | hc->fH1ErrorCounter++; | |
2279 | } | |
2280 | ||
2281 | hc->fTimeBins = HC_NTIMEBINS(vword); | |
2282 | hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword); | |
2283 | hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword); | |
2284 | hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword); | |
2285 | ||
2286 | hc->fPos[1] = (UInt_t*)word; | |
2287 | } | |
2288 | ||
2289 | //-------------------------------------------------------- | |
2290 | const char *AliTRDrawStreamTB::DumpHCinfoH0(const struct AliTRDrawHC *hc) | |
2291 | { | |
2292 | // | |
2293 | // | |
2294 | // | |
2295 | if (!hc) | |
2296 | return Form("Unable to dump. Null received as parameter!?!"); | |
2297 | else | |
2298 | return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d", | |
2299 | hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard); | |
2300 | } | |
2301 | ||
2302 | //-------------------------------------------------------- | |
2303 | const char *AliTRDrawStreamTB::DumpHCinfoH1(const struct AliTRDrawHC *hc) | |
2304 | { | |
2305 | // | |
2306 | // | |
2307 | // | |
2308 | if (!hc) | |
2309 | return Form("Unable to dump. Null received as parameter!?!"); | |
2310 | else | |
2311 | return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d", | |
2312 | hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase); | |
2313 | } | |
2314 | ||
2315 | //-------------------------------------------------------- | |
2316 | void AliTRDrawStreamTB::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const | |
2317 | { | |
2318 | // | |
2319 | // decode the mcm header | |
2320 | // | |
2321 | ||
d4232bb6 | 2322 | UInt_t vword = *word; |
2323 | ||
bb1009bf | 2324 | if (vword == END_OF_TRACKLET_MARKERNEW) |
6bd744d3 | 2325 | { |
bb1009bf | 2326 | if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword)); |
2327 | mcm->fCorrupted += 16; | |
2328 | fHC->fCorrupted += 16; //to finish data reading of this HC | |
6bd744d3 | 2329 | } |
bb1009bf | 2330 | mcm->fCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error, set mcm->fCorrupted = 1 |
d4232bb6 | 2331 | if (mcm->fCorrupted) |
2332 | mcm->fErrorCounter++; | |
2333 | mcm->fROB = MCM_ROB_NUMBER(vword); | |
2334 | mcm->fMCM = MCM_MCM_NUMBER(vword); | |
2335 | mcm->fEvCounter = MCM_EVENT_COUNTER(vword); | |
d4232bb6 | 2336 | mcm->fPos = (UInt_t*)word; |
2337 | } | |
2338 | ||
2339 | //-------------------------------------------------------- | |
2340 | UInt_t AliTRDrawStreamTB::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const | |
2341 | { | |
2342 | // | |
2343 | // get the adc mask | |
2344 | // | |
2345 | ||
d4232bb6 | 2346 | UInt_t vword = *word; |
2347 | ||
bb1009bf | 2348 | mcm->fADCindex = 0; |
2349 | mcm->fADCmax = 0; | |
2350 | mcm->fADCMask = 0; | |
2351 | mcm->fADCcount = 0; | |
d4232bb6 | 2352 | mcm->fADCMaskWord = vword; |
bb1009bf | 2353 | |
2354 | if (vword == END_OF_TRACKLET_MARKERNEW) | |
2355 | { | |
2356 | if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword)); | |
2357 | mcm->fCorrupted += 16; | |
2358 | fHC->fCorrupted += 16; //to finish data reading of this HC | |
2359 | } | |
2360 | ||
d4232bb6 | 2361 | if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) |
2362 | { | |
bb1009bf | 2363 | mcm->fADCMask = MCM_ADCMASK_VAL(vword); |
2364 | mcm->fADCcount = MCM_ADCMASK_NADC(~vword); | |
d4232bb6 | 2365 | } |
2366 | else | |
2367 | { | |
2368 | mcm->fADCMask = 0xffffffff; | |
7e8f4d17 | 2369 | mcm->fCorrupted += 2; |
d4232bb6 | 2370 | mcm->fMaskErrorCounter++; |
2371 | } | |
2372 | ||
2373 | return mcm->fADCMask; | |
2374 | } | |
2375 | ||
2376 | //-------------------------------------------------------- | |
2377 | void AliTRDrawStreamTB::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const | |
2378 | { | |
2379 | // | |
2380 | // decode the adc mask - adcs to be read out | |
2381 | // | |
2382 | ||
2383 | mcm->fMCMADCWords = 0; | |
2384 | mcm->fSingleADCwords = 0; | |
2385 | mcm->fADCmax = 0; | |
2386 | mcm->fADCMask = GetMCMadcMask(word, mcm); | |
bb1009bf | 2387 | |
d4232bb6 | 2388 | if (mcm->fADCMask > 0) |
2389 | { | |
2390 | for (Int_t i = 0; i < TRD_MAX_ADC; i++) | |
2391 | { | |
2392 | mcm->fADCchannel[mcm->fADCmax] = 0; | |
2393 | if( IS_BIT_SET(mcm->fADCMask,i) ) | |
2394 | { | |
2395 | mcm->fADCchannel[mcm->fADCmax] = i; | |
2396 | mcm->fADCmax++; | |
2397 | } | |
2398 | } | |
2399 | } | |
bb1009bf | 2400 | if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) // backward compatibility |
2401 | { | |
2402 | mcm->fCorrupted += 8; | |
2403 | } | |
d4232bb6 | 2404 | } |
2405 | ||
2406 | //-------------------------------------------------------- | |
2407 | void AliTRDrawStreamTB::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const | |
2408 | { | |
2409 | // | |
2410 | // count the expected mcm words for a given tbins | |
2411 | // | |
2412 | mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 ); | |
2413 | mcm->fSingleADCwords = 0; | |
2414 | if (mcm->fADCmax > 0) | |
2415 | { | |
2416 | mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax; | |
2417 | } | |
2418 | } | |
2419 | ||
dc25a859 | 2420 | //-------------------------------------------------------- |
bb1009bf | 2421 | const unsigned long AliTRDrawStreamTB::AdvancePseudoRandom(unsigned long *val) const |
dc25a859 | 2422 | { |
2423 | // | |
2424 | // pseudo random number generator for test pattern data | |
2425 | // | |
2426 | unsigned long currentVal = *val; | |
2427 | ||
2428 | *val = ( (*val << 1) | (((*val >> 9) ^ (*val >> 6)) & 1) ) & 0x3FF; | |
2429 | return currentVal; | |
2430 | } | |
2431 | ||
d4232bb6 | 2432 | //-------------------------------------------------------- |
2433 | const char *AliTRDrawStreamTB::DumpMCMinfo(const struct AliTRDrawMCM *mcm) | |
2434 | { | |
2435 | // | |
2436 | // mcm info in a string | |
2437 | // | |
2438 | if (!mcm) | |
2439 | return Form("Unable to dump. Null received as parameter!?!"); | |
2440 | else | |
2441 | return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter); | |
2442 | } | |
2443 | ||
2444 | //-------------------------------------------------------- | |
2445 | //TString DumpMCMadcMask(const struct AliTRDrawMCMInfo *mcm) | |
2446 | const char *AliTRDrawStreamTB::DumpMCMadcMask(const struct AliTRDrawMCM *mcm) | |
2447 | { | |
2448 | // | |
2449 | // mcm adc mask in a string | |
2450 | // | |
2451 | if (!mcm) | |
2452 | return Form("Unable to dump. Null received as parameter!?!"); | |
2453 | ||
2454 | TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask); | |
2455 | for (Int_t i = 0; i < 21; i++) | |
2456 | { | |
2457 | tsreturn += Form("%d ", mcm->fADCchannel[i]); | |
2458 | } | |
2459 | tsreturn += ""; | |
2460 | return tsreturn.Data(); | |
2461 | } |