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