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