]>
Commit | Line | Data |
---|---|---|
5396a6ba | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* $Id: AliTRDrawFastStream.cxx 27797 2008-08-05 14:37:22Z cblume $ */ | |
17 | ||
18 | //////////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // This class provides access to TRD digits in raw data in a way of streaming // | |
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 | // Author: MinJung Kweon (minjung@physi.uni-heidelberg.de) // | |
29 | // // | |
30 | //////////////////////////////////////////////////////////////////////////////// | |
31 | ||
32 | #include "TString.h" | |
33 | #include "TFile.h" | |
34 | #include "TTreeStream.h" | |
35 | ||
36 | #include "AliTRDrawFastStream.h" | |
37 | #include "AliTRDgeometry.h" | |
38 | #include "AliTRDfeeParam.h" | |
39 | #include "AliTRDdigitsManager.h" | |
40 | #include "AliTRDarrayDictionary.h" | |
41 | #include "AliTRDarrayADC.h" | |
42 | #include "AliTRDSignalIndex.h" | |
43 | #include "AliTRDrawTPStream.h" | |
44 | ||
45 | #include "AliLog.h" | |
46 | #include "AliRawReader.h" | |
47 | ||
48 | #define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa | |
49 | #define END_OF_TRACKLET_MARKERNEW 0x10001000 | |
50 | #define ENDOFRAWDATAMARKER 0x00000000 | |
51 | #define WORD_SIZE sizeof(UInt_t) // size of a word in bytes | |
52 | #define EXTRA_LEAD_WORDS 24 | |
53 | #define CDH_WORDS 8 | |
54 | ||
55 | #define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w | |
56 | #define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m | |
57 | ||
58 | // SM index word masks: | |
59 | #define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16) | |
60 | #define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5) | |
61 | #define STACK_MASK(w) ((w) & 0x1f) | |
62 | ||
63 | // Stack word masks | |
64 | #define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16) | |
65 | #define STACK_LINK_WORD(w) ((w) & 0xfff) | |
66 | #define LINK0_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,4) == (0x0) ? 0 : 1) // 0 if physics data | |
67 | #define LINK1_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,20) == (0x0) ? 0 : 1) // 0 if physics data | |
68 | #define LINK0_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,0) == (0x0) ? 0 : 1) // 0 if OK | |
69 | #define LINK1_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,16) == (0x0) ? 0 : 1) // 0 if OK | |
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) | |
78 | #define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24) | |
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 | // MCM word and ADC mask | |
94 | #define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!! | |
95 | #define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!! | |
96 | #define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24) | |
97 | #define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28) | |
98 | #define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4) | |
99 | #define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4) | |
100 | #define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25) | |
101 | ||
102 | #define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated | |
103 | #define ADCDATA_VAL1 0x2 // updated | |
104 | #define ADCDATA_VAL2 0x3 // updated | |
105 | ||
106 | //-------------------------------------------------------- | |
107 | #define ADC_WORD_MASK(w) ((w) & 0x3) | |
108 | //-------------------------------------------------------- | |
109 | ClassImp(AliTRDrawFastStream) | |
110 | ||
111 | Bool_t AliTRDrawFastStream::fgExtraSkip = kFALSE; | |
112 | Bool_t AliTRDrawFastStream::fgSkipCDH = kFALSE; | |
113 | Bool_t AliTRDrawFastStream::fgWarnError = kTRUE; | |
114 | Bool_t AliTRDrawFastStream::fgCleanDataOnly = kFALSE; | |
115 | Bool_t AliTRDrawFastStream::fgDebugFlag = kTRUE; | |
116 | Bool_t AliTRDrawFastStream::fgEnableMemoryReset = kTRUE; | |
117 | Bool_t AliTRDrawFastStream::fgStackNumberChecker = kTRUE; | |
118 | Bool_t AliTRDrawFastStream::fgStackLinkNumberChecker = kTRUE; | |
119 | Bool_t AliTRDrawFastStream::fgSkipData = kTRUE; | |
120 | Bool_t AliTRDrawFastStream::fgEnableDecodeConfigData = kFALSE; | |
121 | Int_t AliTRDrawFastStream::fgDumpHead = -1; | |
122 | Int_t AliTRDrawFastStream::fgCommonAdditive = 0; | |
123 | Short_t AliTRDrawFastStream::fgMCMordering[] = | |
124 | { | |
125 | 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 | |
126 | }; | |
127 | Short_t AliTRDrawFastStream::fgROBordering[] = | |
128 | { | |
129 | 0, 1, 2, 3 | |
130 | }; | |
131 | Bool_t AliTRDrawFastStream::fDumpingEnable = kFALSE; | |
132 | Int_t AliTRDrawFastStream::fDumpingSM = -1; | |
133 | Int_t AliTRDrawFastStream::fDumpingStack = -1; | |
134 | Int_t AliTRDrawFastStream::fDumpingLayer = -1; | |
135 | Int_t AliTRDrawFastStream::fDumpingROB = -1; | |
136 | Int_t AliTRDrawFastStream::fDumpingMCM = -1; | |
137 | ||
138 | Int_t AliTRDrawFastStream::fgLastHC = -1; | |
139 | Int_t AliTRDrawFastStream::fgLastROB = -1; | |
140 | Int_t AliTRDrawFastStream::fgLastIndex = -1; | |
141 | ||
142 | //-------------------------------------------------------- | |
143 | AliTRDrawFastStream::AliTRDrawFastStream() | |
144 | : AliTRDrawStreamBase() | |
145 | , fSM() | |
146 | , fStack(0) | |
147 | , fHC(0) | |
148 | , fMCM() | |
149 | , fpPos(0) | |
150 | , fpBegin(0) | |
151 | , fpEnd(0) | |
152 | , fWordLength(0) | |
153 | , fStackNumber(-1) | |
154 | , fStackLinkNumber(-1) | |
155 | , fLinkTrackletCounter(-1) | |
156 | , fEndOfTrackletCount(-1) | |
157 | , fNWordsCounter(-1) | |
158 | , fMaskADCword(0) | |
159 | , fTbinADC(0) | |
160 | , fEventCounter(0) | |
161 | , fLastEventCounter(0) | |
162 | , fSharedPadsOn(kTRUE) | |
163 | , fMaxADCgeom(0) | |
164 | , fADCnumber(0) | |
165 | , fCOL(0) | |
166 | , fExtendedCOL(0) | |
167 | , fIsShared(0) | |
168 | , fBufferRead(0) | |
169 | , fGeometry(0) | |
170 | , fRawReader(0) | |
171 | , fTRDfeeParam(0) | |
172 | { | |
173 | // | |
174 | // default constructor | |
175 | // | |
176 | ||
177 | if (Init() == kFALSE) { | |
178 | AliWarning("Unable to Init."); | |
179 | } | |
180 | } | |
181 | ||
182 | //-------------------------------------------------------- | |
183 | AliTRDrawFastStream::AliTRDrawFastStream(AliRawReader *rawReader) | |
184 | : AliTRDrawStreamBase(rawReader) | |
185 | , fSM() | |
186 | , fStack(0) | |
187 | , fHC(0) | |
188 | , fMCM() | |
189 | , fpPos(0) | |
190 | , fpBegin(0) | |
191 | , fpEnd(0) | |
192 | , fWordLength(0) | |
193 | , fStackNumber(-1) | |
194 | , fStackLinkNumber(-1) | |
195 | , fLinkTrackletCounter(-1) | |
196 | , fEndOfTrackletCount(-1) | |
197 | , fNWordsCounter(-1) | |
198 | , fMaskADCword(0) | |
199 | , fTbinADC(0) | |
200 | , fEventCounter(0) | |
201 | , fLastEventCounter(0) | |
202 | , fSharedPadsOn(kTRUE) | |
203 | , fMaxADCgeom(0) | |
204 | , fADCnumber(0) | |
205 | , fCOL(0) | |
206 | , fExtendedCOL(0) | |
207 | , fIsShared(0) | |
208 | , fBufferRead(0) | |
209 | , fGeometry(0) | |
210 | , fRawReader(rawReader) | |
211 | , fTRDfeeParam(0) | |
212 | { | |
213 | // | |
214 | // default constructor | |
215 | // | |
216 | if (fRawReader) { | |
217 | if (Init() == kFALSE) { | |
218 | AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )"); | |
219 | } | |
220 | } | |
221 | else { | |
222 | AliWarning("Unable to setup reader. Use SetReader(AliRawReader*)."); | |
223 | } | |
224 | } | |
225 | ||
226 | //------------------------------------------------------------ | |
227 | AliTRDrawFastStream::AliTRDrawFastStream(const AliTRDrawFastStream& /*st*/) | |
228 | : AliTRDrawStreamBase() | |
229 | , fSM() | |
230 | , fStack(0) | |
231 | , fHC(0) | |
232 | , fMCM() | |
233 | , fpPos(0) | |
234 | , fpBegin(0) | |
235 | , fpEnd(0) | |
236 | , fWordLength(0) | |
237 | , fStackNumber(-1) | |
238 | , fStackLinkNumber(-1) | |
239 | , fLinkTrackletCounter(-1) | |
240 | , fEndOfTrackletCount(-1) | |
241 | , fNWordsCounter(-1) | |
242 | , fMaskADCword(0) | |
243 | , fTbinADC(0) | |
244 | , fEventCounter(0) | |
245 | , fLastEventCounter(0) | |
246 | , fSharedPadsOn(kTRUE) | |
247 | , fMaxADCgeom(0) | |
248 | , fADCnumber(0) | |
249 | , fCOL(0) | |
250 | , fExtendedCOL(0) | |
251 | , fIsShared(0) | |
252 | , fBufferRead(0) | |
253 | , fGeometry(0) | |
254 | , fRawReader(0) | |
255 | , fTRDfeeParam(0) | |
256 | { | |
257 | // | |
258 | // Copy constructor | |
259 | // | |
260 | AliError("Not implemeneted."); | |
261 | } | |
262 | ||
263 | //------------------------------------------------------------ | |
264 | Bool_t AliTRDrawFastStream::SetRawVersion(Int_t fraw) | |
265 | { | |
266 | // | |
267 | // function provided for backward compatibility | |
268 | // | |
269 | AliWarning("Raw data version is read from raw data stream! No point of setting it in here."); | |
270 | fraw = 0; // avoid warnings | |
271 | return kFALSE; | |
272 | } | |
273 | ||
274 | //------------------------------------------------------------ | |
275 | AliTRDrawFastStream::~AliTRDrawFastStream() | |
276 | { | |
277 | // | |
278 | // destructor | |
279 | // | |
280 | delete fGeometry; | |
281 | } | |
282 | ||
283 | //------------------------------------------------------------ | |
284 | ||
285 | AliTRDrawFastStream & | |
286 | AliTRDrawFastStream::operator=(const AliTRDrawFastStream &) | |
287 | { | |
288 | // | |
289 | // we are not using this functionality | |
290 | // | |
291 | AliFatal("May not use."); | |
292 | return *this; | |
293 | } | |
294 | ||
295 | //___________________________________________________________ | |
296 | void AliTRDrawFastStream::SwapOnEndian() | |
297 | { | |
298 | // | |
299 | // Check the endian and swap if needed | |
300 | // | |
301 | int itemp = 1; | |
302 | char* ptemp = (char*) &itemp; | |
303 | if (ptemp[0] != 1) | |
304 | { | |
305 | if (fgDebugFlag) AliDebug(8, "Swapping."); | |
306 | ||
307 | fpPos = fpBegin; | |
308 | UInt_t iutmp = 0; | |
309 | while (fpPos < fpEnd) | |
310 | { | |
311 | fpPos += 1; | |
312 | iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) | | |
313 | ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24)); | |
314 | // here we override the value in the buffer! | |
315 | *fpPos = iutmp; | |
316 | } | |
317 | fpPos = fpBegin; | |
318 | } | |
319 | } | |
320 | ||
321 | //------------------------------------------------------------ | |
322 | Bool_t AliTRDrawFastStream::SkipWords(UInt_t iw) | |
323 | { | |
324 | // | |
325 | // Skip words corresponding to iw | |
326 | // | |
327 | if ( fpPos + iw < fpEnd ) { | |
328 | fpPos += iw; | |
329 | return kTRUE; | |
330 | } | |
331 | else { | |
332 | if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1)); | |
333 | return kFALSE; | |
334 | } | |
335 | ||
336 | return kTRUE; | |
337 | } | |
338 | ||
339 | //------------------------------------------------------------ | |
340 | Bool_t AliTRDrawFastStream::SetReader(AliRawReader *reader) | |
341 | { | |
342 | ||
343 | if (reader != 0) { | |
344 | fRawReader = reader; | |
345 | if (fRawReader) { | |
346 | return Init(); | |
347 | } | |
348 | else { | |
349 | AliWarning("Unable to setup reader."); | |
350 | return kFALSE; | |
351 | } | |
352 | } | |
353 | else { | |
354 | AliWarning("AliRawReader argument is 0."); | |
355 | fRawReader = 0; | |
356 | } | |
357 | ||
358 | return kFALSE; | |
359 | } | |
360 | ||
361 | //------------------------------------------------------------ | |
362 | Int_t AliTRDrawFastStream::NextBuffer() | |
363 | { | |
364 | // | |
365 | // return -1 if no more buffers available | |
366 | // return 0 if SMHeader decoding failed | |
367 | // return 1 if SMHeader dedoding is OK | |
368 | // | |
369 | if (fRawReader != 0) { | |
370 | UChar_t *buffer = 0; | |
371 | UInt_t length = 0; | |
372 | Bool_t kBufferSet = fRawReader->ReadNextData(buffer); | |
373 | if (kBufferSet == kTRUE) { | |
374 | if (fgDebugFlag) AliDebug(9, "Buffer is set."); | |
375 | length = fRawReader->GetDataSize(); | |
376 | if (fgExtraSkip == kTRUE) { | |
377 | buffer += EXTRA_LEAD_WORDS * WORD_SIZE; | |
378 | length -= EXTRA_LEAD_WORDS * WORD_SIZE; | |
379 | } | |
380 | ||
381 | if (fgSkipCDH == kTRUE) { | |
382 | buffer += CDH_WORDS * WORD_SIZE; | |
383 | length -= CDH_WORDS * WORD_SIZE; | |
384 | } | |
385 | ||
386 | if (length > 0) { | |
387 | if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length)); | |
388 | if (fgEnableMemoryReset) ResetMemory(); | |
389 | if (DecodeSMHeader((void*)buffer, length) == kTRUE) | |
390 | return 1; | |
391 | else | |
392 | return 0; | |
393 | } | |
394 | } | |
395 | else { | |
396 | return -1; | |
397 | } | |
398 | } | |
399 | ||
400 | return -1; | |
401 | } | |
402 | ||
403 | //------------------------------------------------------------ | |
404 | void AliTRDrawFastStream::ResetCounters() | |
405 | { | |
406 | // | |
407 | // reset some global counters | |
408 | // | |
409 | fBufferRead = kFALSE; // kFALSE if no buffer read | |
410 | ||
411 | fSM.fActiveStacks = 0; | |
412 | fSM.fNexpectedHalfChambers = 0; | |
413 | ||
414 | fLastEventCounter = 0; | |
415 | fEventCounter = 0; | |
416 | ||
417 | ResetIterators(); | |
418 | } | |
419 | ||
420 | //------------------------------------------------------------ | |
421 | void AliTRDrawFastStream::ResetIterators() | |
422 | { | |
423 | // | |
424 | // reset data which should be reset every sm | |
425 | // | |
426 | fStackNumber = 0; | |
427 | fStackLinkNumber = 0; | |
428 | } | |
429 | ||
430 | //------------------------------------------------------------ | |
431 | void AliTRDrawFastStream::ResetPerSM() | |
432 | { | |
433 | // | |
434 | // reset every SM | |
435 | // | |
436 | fSM.fHeaderSize = 0; | |
437 | fSM.fTrackletEnable = kFALSE; | |
438 | fSM.fCorrupted = 0; | |
439 | fSM.fNexpectedHalfChambers = 0; | |
440 | fSM.fNexpectedHalfChambers = 0; | |
441 | fSM.fPos = NULL; | |
442 | for (Int_t i=0; i<5; i++) { | |
443 | fSM.fStackActive[i] = kFALSE; | |
444 | } | |
445 | } | |
446 | ||
447 | //------------------------------------------------------------ | |
448 | void AliTRDrawFastStream::ResetPerStack() | |
449 | { | |
450 | // | |
451 | // reset every Stack | |
452 | // | |
453 | fStack->fHeaderSize = 0; | |
454 | fStack->fActiveLinks = 0; | |
455 | fStack->fPos = NULL; | |
456 | for (Int_t i=0; i<12; i++) { | |
457 | fStack->fLinksActive[i] = kFALSE; | |
458 | fStack->fLinksDataType[i] = 0; | |
459 | fStack->fLinksMonitor[i] = 0; | |
460 | fStack->fLinkMonitorError[i] = 0; | |
461 | } | |
462 | } | |
463 | ||
464 | //------------------------------------------------------------ | |
465 | void AliTRDrawFastStream::ResetPerHC() | |
466 | { | |
467 | // | |
468 | // reset every HC | |
469 | // | |
470 | fEventCounter = 0; | |
471 | fHC->fNTracklets = 0; | |
472 | fHC->fSpecialRawV = 0; | |
473 | fHC->fRawVMajor = 0; | |
474 | fHC->fRawVMajorOpt = 0; | |
475 | fHC->fRawVMinor = 0; | |
476 | fHC->fNExtraWords = 0; | |
477 | fHC->fDCSboard = 0; | |
478 | fHC->fTimeBins = 0; | |
479 | fHC->fBunchCrossCounter = 0; | |
480 | fHC->fPreTriggerCounter = 0; | |
481 | fHC->fPreTriggerPhase = 0; | |
482 | fHC->fMCMmax = 0; | |
483 | ||
484 | fHC->fSM = 0; | |
485 | fHC->fStack = 0; | |
486 | fHC->fStackHCheader = 0; | |
487 | fHC->fLayer = 0; | |
488 | fHC->fLayerHCheader = 0; | |
489 | fHC->fSide = 0; | |
490 | fHC->fSideHCheader = 0; | |
491 | fHC->fDET = 0; | |
492 | fHC->fROC = 0; | |
493 | fHC->fRowMax = 0; | |
494 | fHC->fColMax = 0; | |
495 | ||
496 | fHC->fH0Corrupted = 0; | |
497 | fHC->fH1Corrupted = 0; | |
498 | fHC->fCorrupted = 0; | |
499 | fHC->fEOTECorrupted = kFALSE; | |
500 | fHC->fBufferCorrupted = kFALSE; | |
501 | fHC->fDataCorrupted = kFALSE; | |
502 | ||
503 | fHC->fNErrors= 0; | |
504 | memset(fHC->fErrorCodes, 0, 1411*sizeof(UShort_t)); // initialize error container | |
505 | memset(fHC->fTrackletWords, 0, MAXTRACKLETSPERHC*sizeof(UInt_t)); // initialize tracklet container | |
506 | } | |
507 | ||
508 | //------------------------------------------------------------ | |
509 | void AliTRDrawFastStream::ResetPerMCM() | |
510 | { | |
511 | // | |
512 | // reset every MCM | |
513 | // | |
514 | fMCM.fROB = 0; | |
515 | fMCM.fMCM = 0; | |
516 | fMCM.fROW = 0; | |
517 | fMCM.fEvCounter = 0; | |
518 | fMCM.fADCMask = 0; | |
519 | fMCM.fADCMaskWord = 0; | |
520 | fMCM.fADCmax = 0; | |
521 | fMCM.fADCcount = 0; | |
522 | fMCM.fMCMADCWords = 0; | |
523 | fMCM.fSingleADCwords = 0; | |
524 | fMCM.fMCMhdCorrupted = 0; | |
525 | fMCM.fADCmaskCorrupted = 0; | |
526 | fMCM.fDataCorrupted = kFALSE; | |
527 | fMCM.fPos = NULL; | |
528 | fMCM.fAdcDataPos = NULL; | |
529 | fMCM.fADCcounter = 0; | |
530 | ||
531 | memset(fMCM.fADCchannel, 0, TRDMAXADC*sizeof(UInt_t)); | |
532 | } | |
533 | ||
534 | //------------------------------------------------------------ | |
535 | void AliTRDrawFastStream::ResetMemory() | |
536 | { | |
537 | // | |
538 | // initialize all the data members to prevent read data | |
539 | // from previous buffer | |
540 | // | |
541 | ResetPerSM(); | |
542 | for (Int_t istack=0; istack<5; istack++) { | |
543 | fStack = &fSM.fStacks[istack]; | |
544 | ResetPerStack(); | |
545 | for (Int_t ilink=0; ilink<12; ilink++) { | |
546 | fHC = &fStack->fHalfChambers[ilink]; | |
547 | ResetPerHC(); | |
548 | } | |
549 | } | |
550 | } | |
551 | ||
552 | //------------------------------------------------------------ | |
553 | Bool_t AliTRDrawFastStream::Next() | |
554 | { | |
555 | // | |
556 | // returns with true on next adc read, returns false on errors and end of buffer | |
557 | // | |
558 | if (fBufferRead) { | |
559 | while (fStackNumber < 5 && fSM.fActiveStacks > 0) { | |
560 | if (fSM.fStackActive[fStackNumber] == kTRUE) { | |
561 | fStack = &fSM.fStacks[fStackNumber]; | |
562 | while (fStackLinkNumber < 12) { | |
563 | if (fStack->fLinksActive[fStackLinkNumber] == kTRUE) { | |
564 | //if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0) | |
565 | fHC = &fStack->fHalfChambers[fStackLinkNumber]; | |
566 | //ResetPerHC(); // [mj - you don't need to do? ] | |
567 | if (!fHC) { | |
568 | AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber)); | |
569 | return kFALSE; | |
570 | } | |
571 | fStackLinkNumber++; | |
572 | return kTRUE; | |
573 | } //link active ? | |
574 | else fStackLinkNumber++; | |
575 | } //stack link number loop | |
576 | } //stack active ? | |
577 | fStackNumber++; | |
578 | fStackLinkNumber = 0; | |
579 | } //stack number loop | |
580 | } //fBufferRead | |
581 | ||
582 | // go for the next buffer | |
583 | if (fRawReader) { | |
584 | Int_t nextBuff = NextBuffer(); | |
585 | while (nextBuff != -1) { | |
586 | if (nextBuff > 0) { | |
587 | fBufferRead = kTRUE; | |
588 | return Next(); | |
589 | } | |
590 | nextBuff = NextBuffer(); | |
591 | } | |
592 | } | |
593 | ||
594 | return kFALSE; | |
595 | } | |
596 | ||
597 | //------------------------------------------------------------ | |
598 | Int_t AliTRDrawFastStream::NextChamber(AliTRDdigitsManager *digitsManager, UInt_t **trackletContainer, UShort_t **errorCodeContainer) | |
599 | { | |
600 | ||
601 | // | |
602 | // Fills single chamber digit array | |
603 | // Return value is the detector number | |
604 | // | |
605 | // first of all, you do the SM header decoding only at the beginning of the SM data reading | |
606 | // then, every HC, you call Next() which points next HC. then, there you decode the given HC | |
607 | // and at the same time, put the digit into digitmanager | |
608 | // | |
609 | AliTRDarrayADC *digits = 0; | |
610 | AliTRDarrayDictionary *track0 = 0; | |
611 | AliTRDarrayDictionary *track1 = 0; | |
612 | AliTRDarrayDictionary *track2 = 0; | |
613 | AliTRDSignalIndex *indexes = 0; | |
614 | ||
615 | Int_t lastdet = -1; | |
616 | Int_t det = -1; | |
617 | Int_t side = -1; | |
618 | //Int_t it = 0; | |
619 | Int_t ntracklets = 0; | |
620 | Int_t nErrors = 0; | |
621 | ||
622 | if (trackletContainer){ | |
623 | for (Int_t i = 0; i < 2; i++) | |
624 | memset(trackletContainer[i], 0, MAXTRACKLETSPERHC*sizeof(UInt_t)); | |
625 | } | |
626 | ||
627 | if (errorCodeContainer){ | |
628 | for (Int_t i = 0; i < 2; i++) | |
629 | memset(errorCodeContainer[i], 0, 1411*sizeof(UShort_t)); | |
630 | } | |
631 | ||
632 | while ( Next() ) { // loop over HC | |
633 | ||
634 | // get this information from the GTU header | |
635 | det = GetDet(); | |
636 | side = GetSide(); | |
637 | ||
638 | if (det != lastdet) { | |
639 | // If new detector found | |
640 | if (lastdet == -1) lastdet = det; | |
641 | else {fStackLinkNumber--; return lastdet;} | |
642 | ||
643 | if (det < 0 || det >= AliTRDgeometry::kNdet) continue; | |
644 | ||
645 | // Add a container for the digits of this detector | |
646 | digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); | |
647 | ||
648 | if (digitsManager->UsesDictionaries()) { | |
649 | track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0); | |
650 | track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1); | |
651 | track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2); | |
652 | } | |
653 | ||
654 | if (!digits) return -1; | |
655 | ||
656 | Int_t rowMax = GetRowMax(); | |
657 | Int_t colMax = GetColMax(); | |
658 | //Int_t ntbins = GetNumberOfTimeBins(); | |
659 | Int_t ntbins = 30; //[mj temp] | |
660 | ||
661 | // Allocate memory space for the digits buffer | |
662 | if (digits->GetNtime() == 0) { | |
663 | digits->Allocate(rowMax, colMax, ntbins); | |
664 | if (digitsManager->UsesDictionaries()) { | |
665 | track0->Allocate(rowMax, colMax, ntbins); | |
666 | track1->Allocate(rowMax, colMax, ntbins); | |
667 | track2->Allocate(rowMax, colMax, ntbins); | |
668 | } | |
669 | } | |
670 | ||
671 | indexes = digitsManager->GetIndexes(det); | |
672 | indexes->SetSM(GetSM()); | |
673 | indexes->SetStack(GetStack()); | |
674 | indexes->SetLayer(GetLayer()); | |
675 | indexes->SetDetNumber(det); | |
676 | if (indexes->IsAllocated() == kFALSE) | |
677 | indexes->Allocate(rowMax, colMax, ntbins); | |
678 | } | |
679 | ||
680 | if (fSM.fTrackletEnable == kTRUE) { | |
681 | if (DecodeTracklets() == kFALSE) { | |
682 | SeekEndOfData(); | |
683 | ||
684 | if (fgWarnError) AliError(Form("Tracklet decoding failed stack %d link %d", GetStack(), fStackLinkNumber)); | |
685 | ||
686 | // copy error codes in memory into error container | |
687 | if (errorCodeContainer) { | |
688 | nErrors = GetNErrors(); | |
689 | if(nErrors > 0) memcpy(errorCodeContainer[side], GetErrorCodes(), sizeof(UShort_t) * 1411); // [mj temp - optimize] | |
690 | } | |
691 | ||
692 | continue; // if it fails to decode tracklets of this HC, it skips further decoding and goes to next HC | |
693 | } | |
694 | } | |
695 | ||
696 | // decode hc data | |
697 | fgLastROB = -1; // to check mcm number odering | |
698 | fgLastIndex = -1 ; // to check mcm number odering | |
699 | if (DecodeHC(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) { | |
700 | // encode HC error code | |
701 | fHC->fErrorCodes[2] += fHC->fH0Corrupted; | |
702 | fHC->fErrorCodes[2] += (fHC->fH1Corrupted << 2); | |
703 | fHC->fErrorCodes[2] += (fHC->fCorrupted << 3); | |
704 | fHC->fErrorCodes[2] += ((fHC->fBufferCorrupted & 1) << 6); | |
705 | fHC->fErrorCodes[2] += ((fHC->fEOTECorrupted & 1) << 7); | |
706 | fHC->fErrorCodes[2] += ((fHC->fDataCorrupted & 1) << 8); | |
707 | ||
708 | if (fHC->fEOTECorrupted != kTRUE) SeekEndOfData(); | |
709 | ||
710 | /* | |
711 | if (fgWarnError) { | |
712 | AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC))); | |
713 | AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC))); | |
714 | } | |
715 | */ // [mj temp] | |
716 | } | |
717 | else SeekEndOfData(); // make sure that finish off with the end of data markers | |
718 | ||
719 | // copy tracklets in memory into tracklet container | |
720 | if (trackletContainer) { | |
721 | ntracklets = GetNTracklets(); | |
722 | // copy tracklet words to trackletContainer array | |
723 | if(ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets); | |
724 | } | |
725 | ||
726 | // copy error codes in memory into error container | |
727 | if (errorCodeContainer) { | |
728 | nErrors = GetNErrors(); | |
729 | if(nErrors > 0) memcpy(errorCodeContainer[side], GetErrorCodes(), sizeof(UShort_t) * 1411); | |
730 | } | |
731 | ||
732 | }// end of while | |
733 | ||
734 | return det; | |
735 | } | |
736 | ||
737 | //------------------------------------------------------------ | |
738 | Bool_t AliTRDrawFastStream::Init() | |
739 | { | |
740 | // | |
741 | // Initialize geometry and fee parameters | |
742 | // | |
743 | TDirectory *saveDir = gDirectory; | |
744 | ||
745 | if (!fGeometry) { | |
746 | fGeometry = new AliTRDgeometry(); | |
747 | } | |
748 | ||
749 | if (!fGeometry) { | |
750 | AliError("Geometry FAILED!"); | |
751 | return kFALSE; | |
752 | } | |
753 | ||
754 | fTRDfeeParam = AliTRDfeeParam::Instance(); | |
755 | if (!fTRDfeeParam) { | |
756 | AliError("AliTRDfeeParam FAILED!"); | |
757 | return kFALSE; | |
758 | } | |
759 | ||
760 | fMaxADCgeom = (Int_t)fGeometry->ADCmax(); | |
761 | ||
762 | ResetCounters(); // fBufferRead is set to kFALSE - important | |
763 | ||
764 | saveDir->cd(); | |
765 | ||
766 | return kTRUE; | |
767 | } | |
768 | ||
769 | //------------------------------------------------------------ | |
770 | Bool_t AliTRDrawFastStream::InitBuffer(void *buffer, UInt_t length) | |
771 | { | |
772 | // | |
773 | // set initial information about the buffer | |
774 | // | |
775 | if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId())); | |
776 | if (fRawReader->GetEquipmentId()<1024 || fRawReader->GetEquipmentId()>1041) | |
777 | return kFALSE; | |
778 | ||
779 | ResetCounters(); | |
780 | ||
781 | fpBegin = (UInt_t *)buffer; | |
782 | ||
783 | if (WORD_SIZE == 0) { | |
784 | AliFatal("Strange word size. size of UInt_t == 0"); | |
785 | return kFALSE; | |
786 | } | |
787 | ||
788 | fWordLength = length/WORD_SIZE; | |
789 | fpEnd = fpBegin + fWordLength; | |
790 | fpPos = fpBegin; | |
791 | ||
792 | if (fpBegin == 0 || length <= 0) { | |
793 | AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%08x of size %d", fpBegin, length)); | |
794 | return kFALSE; | |
795 | } | |
796 | ||
797 | SwapOnEndian(); | |
798 | ||
799 | if (fgDumpHead >= 0) { | |
800 | if ( fgDumpHead == 0 ) { // dump all words | |
801 | AliInfo(Form("---------- Dumping all words from the beginnig of the buffer ----------")); | |
802 | if (DumpWords(fpBegin, fWordLength) == kFALSE) AliError("Dump failed. Not enough data."); | |
803 | } | |
804 | else { | |
805 | AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead)); | |
806 | if (DumpWords(fpBegin, fgDumpHead) == kFALSE) AliError("Dump failed. Not enough data."); | |
807 | } | |
808 | AliInfo(Form("---------- Dumping ended ----------------------------------------------")); | |
809 | } | |
810 | ||
811 | return kTRUE; | |
812 | } | |
813 | ||
814 | //------------------------------------------------------------ | |
815 | Bool_t AliTRDrawFastStream::DecodeSMHeader(void *buffer, UInt_t length) | |
816 | { | |
817 | // | |
818 | // decode one sm data in buffer | |
819 | // | |
820 | ResetIterators(); | |
821 | ||
822 | if (InitBuffer(buffer, length) == kFALSE) { | |
823 | if (fgWarnError) AliError("InitBuffer failed."); | |
824 | return kFALSE; | |
825 | } | |
826 | ||
827 | if (DecodeGTUheader()== kFALSE) | |
828 | return kFALSE; | |
829 | ||
830 | for (Int_t istack = 0; istack < 5; istack++) { | |
831 | fStackNumber = istack; | |
832 | if (fSM.fStackActive[istack] == kFALSE) continue; | |
833 | ||
834 | fStack = &fSM.fStacks[istack]; | |
835 | ||
836 | fgLastHC = -1; // to check rob number odering | |
837 | for (Int_t ilink = 0; ilink < 12; ilink++) { | |
838 | fStackLinkNumber = ilink; | |
839 | if (fStack->fLinksActive[ilink] == kFALSE) continue; | |
840 | ||
841 | // check GTU link monitor | |
842 | if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0)) { | |
843 | fStack->fLinkMonitorError[ilink] = 1; | |
844 | fStack->fLinkMonitorError[ilink] += fNWordsCounter; // counts words of given hc having link monitor error | |
845 | //continue; | |
846 | } | |
847 | ||
848 | if (fpPos >= fpEnd) { | |
849 | if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing"); | |
850 | if (fgWarnError) AliError("Link data missing."); | |
851 | break; | |
852 | } | |
853 | ||
854 | // HLT streamer set det number using SM header | |
855 | fHC = &fStack->fHalfChambers[ilink]; | |
856 | fHC->fSM = fRawReader->GetEquipmentId() - 1024; | |
857 | fHC->fStack = fStackNumber; | |
858 | fHC->fLayer = Int_t(fStackLinkNumber/2.); | |
859 | fHC->fSide = fStackLinkNumber%2; | |
860 | fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM); | |
861 | fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM); | |
862 | fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack); | |
863 | fHC->fColMax = fGeometry->GetColMax(fHC->fROC); | |
864 | } | |
865 | } | |
866 | ||
867 | ResetIterators(); // need to do it again for Next() function | |
868 | ||
869 | return kTRUE; | |
870 | } | |
871 | ||
872 | //------------------------------------------------------------ | |
873 | Bool_t AliTRDrawFastStream::DecodeGTUheader() | |
874 | { | |
875 | // | |
876 | // decode Supermodule Index Word | |
877 | // | |
878 | DecodeSMInfo(fpPos, &fSM); | |
879 | ||
880 | if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM)); | |
881 | ||
882 | fpPos++; | |
883 | if (fpPos < fpEnd) { | |
884 | // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design. | |
885 | // For the moment, we skip decoding these words | |
886 | if (SkipWords(fSM.fHeaderSize) == kTRUE) { | |
887 | for (Int_t istack = 0; istack < 5; istack++) { | |
888 | if (fSM.fStackActive[istack] == kFALSE) | |
889 | continue; | |
890 | ||
891 | fStack = &fSM.fStacks[istack]; | |
892 | ||
893 | // Decode Stack Index Word of given stack | |
894 | DecodeStackInfo(fpPos, fStack); | |
895 | fpPos++; | |
896 | ||
897 | fSM.fNexpectedHalfChambers += fStack->fActiveLinks; | |
898 | ||
899 | if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack)); | |
900 | ||
901 | if (SkipWords(fStack->fHeaderSize-6) == kFALSE) { // 6 is the 6 stack header words for 12 links | |
902 | if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing"); | |
903 | return kFALSE; | |
904 | } | |
905 | for (Int_t iword=0; iword<6; iword++) { // decode 6 stack header words | |
906 | // Decode Stack Header Word of given stack | |
907 | DecodeStackHeader(fpPos, fStack, iword); | |
908 | fpPos++; | |
909 | } // iword | |
910 | } // istack | |
911 | } | |
912 | else { | |
913 | return kFALSE; | |
914 | } | |
915 | } | |
916 | else { | |
917 | if (fgWarnError) AliWarning("No additional sm headers and stack index words present."); | |
918 | if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing"); | |
919 | return kFALSE; | |
920 | } | |
921 | ||
922 | if (fpPos < fpEnd) { | |
923 | if (fgDebugFlag) AliDebug(5, "GTU headers are OK."); | |
924 | } | |
925 | else { | |
926 | if (fgWarnError) AliWarning("No data just after GTU headers."); | |
927 | if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data"); | |
928 | return kFALSE; | |
929 | } | |
930 | ||
931 | if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers)); | |
932 | ||
933 | return kTRUE; | |
934 | } | |
935 | ||
936 | //-------------------------------------------------------- | |
937 | void AliTRDrawFastStream::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const | |
938 | { | |
939 | // | |
940 | // decode Stack #i Index Word | |
941 | // The Stack #i Index Word is a 32-Bit word with following structure | |
942 | // ssssssss ssssssss vvvv mmmm mmmmmmmm | |
943 | // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask | |
944 | // | |
945 | st->fPos = (UInt_t*)word; | |
946 | ||
947 | UInt_t vword = *word; | |
948 | st->fHeaderSize = STACK_HEADER_SIZE(vword); | |
949 | ||
950 | UInt_t linkMask = STACK_LINK_WORD(vword); | |
951 | st->fActiveLinks = 0; | |
952 | for (Int_t i = 0; i < 12; i++) { | |
953 | if (IS_BIT_SET(linkMask,i) > 0) { | |
954 | st->fLinksActive[i] = kTRUE; | |
955 | st->fActiveLinks++; | |
956 | } | |
957 | else { | |
958 | st->fLinksActive[i] = kFALSE; | |
959 | } | |
960 | } | |
961 | } | |
962 | ||
963 | //-------------------------------------------------------- | |
964 | void AliTRDrawFastStream::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const | |
965 | { | |
966 | // | |
967 | // decode stack header | |
968 | // | |
969 | st->fPos = (UInt_t*)word; | |
970 | ||
971 | UInt_t vword = *word; | |
972 | st->fLinksDataType[2*iword] = LINK0_DATA_TYPE_FLAG(vword); | |
973 | st->fLinksMonitor[2*iword] = LINK0_MONITOR_FLAG(vword); | |
974 | st->fLinksDataType[2*iword+1] = LINK1_DATA_TYPE_FLAG(vword); | |
975 | st->fLinksMonitor[2*iword+1] = LINK1_MONITOR_FLAG(vword); | |
976 | } | |
977 | ||
978 | //------------------------------------------------------------ | |
979 | Bool_t AliTRDrawFastStream::DecodeTracklets() | |
980 | { | |
981 | // | |
982 | // decode tracklets | |
983 | // | |
984 | fLinkTrackletCounter = 0; // tracklet counter of this link | |
985 | fEndOfTrackletCount = 0; // tracklet endmarker counter of this link | |
986 | fHC->fNTracklets = 0; // number of tracklet of this link, should be less than 256 | |
987 | ||
988 | if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos)); | |
989 | ||
990 | while (!(*fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW) && fpPos < fpEnd) { | |
991 | if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos)); | |
992 | ||
993 | fLinkTrackletCounter++; | |
994 | ||
995 | if (fLinkTrackletCounter > MAXTRACKLETSPERHC) { | |
996 | if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d. Tracklets are wrong either GTU header has problem", | |
997 | fLinkTrackletCounter, MAXTRACKLETSPERHC)); | |
998 | if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets"); | |
999 | fHC->fErrorCodes[1] = 1; | |
1000 | return kFALSE; | |
1001 | } | |
1002 | ||
1003 | fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into memory | |
1004 | fpPos++; | |
1005 | } | |
1006 | ||
1007 | fHC->fNTracklets = fLinkTrackletCounter; | |
1008 | ||
1009 | while ((*fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW) && fpPos < fpEnd) { | |
1010 | if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos)); | |
1011 | ||
1012 | fEndOfTrackletCount++; | |
1013 | fpPos++; | |
1014 | } | |
1015 | ||
1016 | if (fEndOfTrackletCount < 2) { | |
1017 | if (fgDebugFlag) AliDebug(11,"End of tracklets word missing"); | |
1018 | if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing"); | |
1019 | fHC->fErrorCodes[1] += 2; | |
1020 | return kFALSE; | |
1021 | } | |
1022 | ||
1023 | return kTRUE; | |
1024 | } | |
1025 | ||
1026 | //-------------------------------------------------------- | |
1027 | void AliTRDrawFastStream::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const | |
1028 | { | |
1029 | // | |
1030 | // decode Supermodule Index Word | |
1031 | // The Supermodule Index Word is a 32-Bit word wit following structure | |
1032 | // ssssssss ssssssss vvvv rrrr r d t mmmm | |
1033 | // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use | |
1034 | // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask | |
1035 | // | |
1036 | sm->fPos = (UInt_t*)word; | |
1037 | ||
1038 | UInt_t vword = *word; | |
1039 | sm->fHeaderSize = SM_HEADER_SIZE(vword); | |
1040 | ||
1041 | if (TRACKLETS_ENABLED(vword) > 0) | |
1042 | sm->fTrackletEnable = kTRUE; | |
1043 | else | |
1044 | sm->fTrackletEnable = kFALSE; | |
1045 | ||
1046 | UInt_t stackMask = STACK_MASK(vword); | |
1047 | sm->fActiveStacks = 0; | |
1048 | for (Int_t i = 0; i < 5; i++) | |
1049 | { | |
1050 | if (IS_BIT_SET(stackMask,i) > 0) | |
1051 | { | |
1052 | sm->fStackActive[i] = kTRUE; | |
1053 | sm->fActiveStacks++; | |
1054 | } | |
1055 | else | |
1056 | { | |
1057 | sm->fStackActive[i] = kFALSE; | |
1058 | } | |
1059 | } | |
1060 | } | |
1061 | ||
1062 | //------------------------------------------------------------ | |
1063 | Bool_t AliTRDrawFastStream::DecodeHC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, | |
1064 | AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, | |
1065 | AliTRDSignalIndex *indexes) | |
1066 | { | |
1067 | // | |
1068 | // decode hc header and data | |
1069 | // | |
1070 | if (fpPos >= fpEnd) { | |
1071 | fHC->fCorrupted += 1; | |
1072 | if (fgWarnError) AliError("No data(including HC header) in the buffer"); | |
1073 | return kFALSE;; | |
1074 | } | |
1075 | ||
1076 | if (DecodeHCheader() == kFALSE) { | |
1077 | if (fgWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted)); | |
1078 | return kFALSE; | |
1079 | } | |
1080 | else { | |
1081 | fpPos++; | |
1082 | if (fpPos >= fpEnd) { | |
1083 | fHC->fCorrupted += 2; | |
1084 | if (fgWarnError) AliError("No data right after HC header in the buffer"); | |
1085 | return kFALSE; | |
1086 | } | |
1087 | } | |
1088 | ||
1089 | if ((fHC->fRawVMajor & 64) == 64) { // test pattern data | |
1090 | AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos); | |
1091 | if (tpStream->DecodeTPdata() == kFALSE) { | |
1092 | if (fgWarnError) AliError("Failed to decode test pattern data"); | |
1093 | return kFALSE; | |
1094 | } | |
1095 | return kTRUE; | |
1096 | } | |
1097 | ||
1098 | fHC->fMCMmax = 0; // count number of mcms in a hc | |
1099 | while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd) { | |
1100 | ||
1101 | ResetPerMCM(); // reset for every mcm | |
1102 | ||
1103 | if (fHC->fMCMmax > TRDMAXMCM) { | |
1104 | fHC->fCorrupted += 4; | |
1105 | if (fgDebugFlag) AliDebug(11,"More mcm data than expected"); | |
1106 | return kFALSE; | |
1107 | } | |
1108 | ||
1109 | if (DecodeMCMheader() == kFALSE) { | |
1110 | ||
1111 | // encode mcm level error codes | |
1112 | fHC->fErrorCodes[fHC->fMCMmax+2] += fMCM.fMCMhdCorrupted; | |
1113 | fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fADCmaskCorrupted << 4); | |
1114 | fHC->fErrorCodes[fHC->fMCMmax+2] += ((fMCM.fDataCorrupted & 1) << 6); | |
1115 | fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fMCM << 7); // encode MCM number | |
1116 | fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fROB << 11); // encode ROB number | |
1117 | ||
1118 | fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number | |
1119 | ||
1120 | // in case we decide to keep reading data, skip this mcm data and find next mcm header | |
1121 | if (fMCM.fADCmaskCorrupted < 2) { | |
1122 | if (SkipMCMdata(fMCM.fADCcount*fMCM.fSingleADCwords) == kFALSE) | |
1123 | return kFALSE; | |
1124 | continue; | |
1125 | } | |
1126 | else { | |
1127 | if (SeekNextMCMheader() == kFALSE) | |
1128 | return kFALSE; | |
1129 | continue; | |
1130 | } | |
1131 | } | |
1132 | ||
1133 | fHC->fMCMmax++; | |
1134 | ||
1135 | if (fMCM.fADCmax > 0) { | |
1136 | fpPos++; | |
1137 | if (fpPos >= fpEnd) { | |
1138 | fHC->fBufferCorrupted = kTRUE; | |
1139 | if (fgDebugFlag) AliDebug(11, Form("Buffer ends in the middle of data")); | |
1140 | return kFALSE; | |
1141 | } | |
1142 | ||
1143 | fADCnumber = 0; | |
1144 | for (Int_t iadc = 0; iadc < fMCM.fADCmax; iadc++) { | |
1145 | fADCnumber = fMCM.fADCchannel[iadc]; | |
1146 | ||
1147 | if ( fADCnumber >= fMaxADCgeom - 1) { | |
1148 | fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber-1); | |
1149 | fExtendedCOL--; | |
1150 | fCOL = fTRDfeeParam->GetPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber-1); | |
1151 | fCOL--; | |
1152 | } | |
1153 | else { | |
1154 | fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber); | |
1155 | fCOL = fTRDfeeParam->GetPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber); | |
1156 | } | |
1157 | ||
1158 | if (fADCnumber <= 1 || fADCnumber == fMaxADCgeom - 1) // if adc number = 0, 1, 20 | |
1159 | fIsShared = kTRUE; | |
1160 | else | |
1161 | fIsShared = kFALSE; | |
1162 | ||
1163 | if (fpPos + fMCM.fSingleADCwords >= fpEnd) { | |
1164 | fHC->fBufferCorrupted = kTRUE; | |
1165 | if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer."); | |
1166 | return kFALSE; | |
1167 | } | |
1168 | ||
1169 | if (DecodeADC(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) { | |
1170 | return kFALSE; | |
1171 | } | |
1172 | } // iadc | |
1173 | } | |
1174 | else { // if there is no adc activated | |
1175 | fpPos++; | |
1176 | } | |
1177 | } // mcm loop | |
1178 | ||
1179 | if (fpPos >= fpEnd) { | |
1180 | fHC->fBufferCorrupted = kTRUE; | |
1181 | if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. Not enough data in the buffer."); | |
1182 | return kFALSE; | |
1183 | } | |
1184 | ||
1185 | return kTRUE; | |
1186 | } | |
1187 | ||
1188 | //------------------------------------------------------------ | |
1189 | Bool_t AliTRDrawFastStream::DecodeHCheader() | |
1190 | { | |
1191 | // | |
1192 | // decode the half chamber header | |
1193 | // if it fails to decode HC header for both H0 and H1, return kFALSE | |
1194 | // | |
1195 | if (DecodeHCwordH0(fpPos, fHC) == kFALSE) | |
1196 | return kFALSE; | |
1197 | ||
1198 | if (fHC->fNExtraWords > 0) { | |
1199 | fpPos++; | |
1200 | if (fpPos < fpEnd) { | |
1201 | if (DecodeHCwordH1(fpPos, fHC) == kFALSE) | |
1202 | return kFALSE; | |
1203 | } | |
1204 | else { | |
1205 | fHC->fBufferCorrupted = kTRUE; | |
1206 | if (fgDebugFlag) AliDebug(11,"Expected HC header word H1. Fail due to buffer END."); | |
1207 | return kFALSE; | |
1208 | } | |
1209 | } | |
1210 | ||
1211 | if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC)); | |
1212 | if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC)); | |
1213 | ||
1214 | if (IsHCheaderOK() == kFALSE) { | |
1215 | fHC->fH0Corrupted += 2; | |
1216 | if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos)); | |
1217 | return kFALSE; | |
1218 | } | |
1219 | ||
1220 | return kTRUE; | |
1221 | } | |
1222 | ||
1223 | //-------------------------------------------------------- | |
1224 | Bool_t AliTRDrawFastStream::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const | |
1225 | { | |
1226 | // | |
1227 | // decode the hc header word 0 | |
1228 | // | |
1229 | UInt_t vword = *word; | |
1230 | hc->fPos[0] = (UInt_t*)word; | |
1231 | ||
1232 | hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword); | |
1233 | if (hc->fH0Corrupted > 0) { | |
1234 | if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%08x",*fHC->fPos )); | |
1235 | return kFALSE; | |
1236 | } | |
1237 | hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword); | |
1238 | hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword); | |
1239 | hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword); | |
1240 | hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword); | |
1241 | hc->fNExtraWords = HC_EXTRA_WORDS(vword); | |
1242 | hc->fDCSboard = HC_DCS_BOARD(vword); | |
1243 | hc->fSMHCheader = HC_SM_NUMBER(vword); | |
1244 | hc->fStackHCheader = HC_STACK_NUMBER(vword); | |
1245 | hc->fLayerHCheader = HC_LAYER_NUMBER(vword); | |
1246 | hc->fSideHCheader = HC_SIDE_NUMBER(vword); | |
1247 | ||
1248 | return kTRUE; | |
1249 | } | |
1250 | ||
1251 | //-------------------------------------------------------- | |
1252 | Bool_t AliTRDrawFastStream::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const | |
1253 | { | |
1254 | // | |
1255 | // decode the hc header word 1 | |
1256 | // | |
1257 | UInt_t vword = *word; | |
1258 | hc->fPos[1] = (UInt_t*)word; | |
1259 | ||
1260 | hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword); | |
1261 | if (hc->fH1Corrupted > 0) { | |
1262 | if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%08x", *(fHC->fPos+1) )); | |
1263 | return kFALSE; | |
1264 | } | |
1265 | hc->fTimeBins = HC_NTIMEBINS(vword); | |
1266 | hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword); | |
1267 | hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword); | |
1268 | hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword); | |
1269 | ||
1270 | return kTRUE; | |
1271 | } | |
1272 | ||
1273 | //------------------------------------------------------------ | |
1274 | Bool_t AliTRDrawFastStream::IsHCheaderOK() | |
1275 | { | |
1276 | // | |
1277 | // check insanity of half chamber header | |
1278 | // | |
1279 | if (fHC->fStackHCheader < 0 || fHC->fStackHCheader > 4) { | |
1280 | if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStackHCheader)); | |
1281 | return kFALSE; | |
1282 | } | |
1283 | ||
1284 | if (fHC->fLayerHCheader < 0 || fHC->fLayerHCheader >= AliTRDgeometry::kNlayer) { | |
1285 | if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayerHCheader)); | |
1286 | return kFALSE; | |
1287 | } | |
1288 | ||
1289 | if (fHC->fSideHCheader < 0 || fHC->fSideHCheader > 1) { | |
1290 | if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSideHCheader)); | |
1291 | return kFALSE; | |
1292 | } | |
1293 | ||
1294 | if (fHC->fSMHCheader != fHC->fSM) { | |
1295 | if (fgDebugFlag) AliDebug(11,Form("Missmatch: SM number between HC header %d and GTU link mask %d", | |
1296 | fHC->fSMHCheader, fHC->fSM)); | |
1297 | return kFALSE; | |
1298 | } | |
1299 | ||
1300 | if (fgStackNumberChecker) { | |
1301 | if (fHC->fStackHCheader != fHC->fStack) { | |
1302 | if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d", | |
1303 | fHC->fStackHCheader, fHC->fStack)); | |
1304 | return kFALSE; | |
1305 | } | |
1306 | } | |
1307 | ||
1308 | if (fgStackLinkNumberChecker) { | |
1309 | if (fHC->fLayerHCheader != fHC->fLayer) { | |
1310 | if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s", | |
1311 | fHC->fLayerHCheader, fHC->fLayer, DumpStackInfo(fStack))); | |
1312 | return kFALSE; | |
1313 | } | |
1314 | } | |
1315 | ||
1316 | // SLOW GEOM : consistancy check with geometry | |
1317 | if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet) { | |
1318 | if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET)); | |
1319 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det"); | |
1320 | return kFALSE; | |
1321 | } | |
1322 | ||
1323 | if (fHC->fSM != fGeometry->GetSector(fHC->fDET) || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector) { | |
1324 | if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d", | |
1325 | fHC->fSM, fGeometry->GetSector(fHC->fDET), fHC->fStack, fHC->fLayer, fHC->fDET)); | |
1326 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM"); | |
1327 | return kFALSE; | |
1328 | } | |
1329 | ||
1330 | if (fHC->fROC < 0) { | |
1331 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC"); | |
1332 | return kFALSE; | |
1333 | } | |
1334 | ||
1335 | if (fHC->fRowMax < 1) { | |
1336 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max"); | |
1337 | return kFALSE; | |
1338 | } | |
1339 | ||
1340 | if (fHC->fColMax < 1) { | |
1341 | if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max"); | |
1342 | return kFALSE; | |
1343 | } | |
1344 | ||
1345 | return kTRUE; | |
1346 | } | |
1347 | ||
1348 | //------------------------------------------------------------ | |
1349 | Bool_t AliTRDrawFastStream::DecodeMCMheader() | |
1350 | { | |
1351 | // | |
1352 | // decode the mcm header | |
1353 | // | |
1354 | DecodeMCMheader(fpPos, &fMCM); | |
1355 | ||
1356 | if (fHC->fEOTECorrupted == kTRUE) { | |
1357 | fpPos--; | |
1358 | return kFALSE; | |
1359 | } | |
1360 | ||
1361 | fMCM.fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM.fROB, fMCM.fMCM); | |
1362 | ||
1363 | if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || ((fHC->fRawVMajor & 32) == 32)) { //cover old and new version definition of ZS data | |
1364 | fpPos++; | |
1365 | if ( fpPos < fpEnd ) { | |
1366 | DecodeMask(fpPos, &fMCM); | |
1367 | if (fHC->fEOTECorrupted == kTRUE) { | |
1368 | fpPos--; | |
1369 | return kFALSE; | |
1370 | } | |
1371 | MCMADCwordsWithTbins(fHC->fTimeBins, &fMCM); | |
1372 | fMCM.fAdcDataPos = fpPos + 1; | |
1373 | } | |
1374 | else { | |
1375 | if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END."); | |
1376 | if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing"); | |
1377 | fHC->fBufferCorrupted = kTRUE; | |
1378 | return kFALSE; | |
1379 | } | |
1380 | } | |
1381 | else { | |
1382 | UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL; | |
1383 | DecodeMask(&dummyMask, &fMCM); | |
1384 | MCMADCwordsWithTbins(fHC->fTimeBins, &fMCM); | |
1385 | fMCM.fAdcDataPos = fpPos + 1; | |
1386 | } | |
1387 | if (IsMCMheaderOK() == kFALSE) | |
1388 | return kFALSE; | |
1389 | ||
1390 | return kTRUE; | |
1391 | } | |
1392 | ||
1393 | //-------------------------------------------------------- | |
1394 | void AliTRDrawFastStream::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const | |
1395 | { | |
1396 | // | |
1397 | // decode the mcm header | |
1398 | // | |
1399 | UInt_t vword = *word; | |
1400 | ||
1401 | if (vword == END_OF_TRACKLET_MARKERNEW) { | |
1402 | if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword)); | |
1403 | fHC->fEOTECorrupted = kTRUE; //to finish data reading of this HC | |
1404 | } | |
1405 | ||
1406 | mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error | |
1407 | if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) { | |
1408 | fHC->fDataCorrupted = kTRUE; | |
1409 | AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos)); | |
1410 | } | |
1411 | ||
1412 | mcm->fROB = MCM_ROB_NUMBER(vword); | |
1413 | mcm->fMCM = MCM_MCM_NUMBER(vword); | |
1414 | mcm->fEvCounter = MCM_EVENT_COUNTER(vword); | |
1415 | mcm->fPos = (UInt_t*)word; | |
1416 | } | |
1417 | ||
1418 | //-------------------------------------------------------- | |
1419 | UInt_t AliTRDrawFastStream::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const | |
1420 | { | |
1421 | // | |
1422 | // get the adc mask | |
1423 | // | |
1424 | UInt_t vword = *word; | |
1425 | ||
1426 | mcm->fADCMask = 0; | |
1427 | mcm->fADCcount = 0; | |
1428 | mcm->fADCMaskWord = vword; | |
1429 | ||
1430 | if (vword == END_OF_TRACKLET_MARKERNEW) { | |
1431 | if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword)); | |
1432 | fHC->fEOTECorrupted = kTRUE; //to finish data reading of this HC | |
1433 | } | |
1434 | ||
1435 | if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) { | |
1436 | mcm->fADCMask = MCM_ADCMASK_VAL(vword); | |
1437 | mcm->fADCcount = MCM_ADCMASK_NADC(~vword); | |
1438 | } | |
1439 | else { | |
1440 | mcm->fADCMask = 0xffffffff; | |
1441 | mcm->fADCmaskCorrupted = 1; // mcm adc mask error | |
1442 | fHC->fDataCorrupted = kTRUE; | |
1443 | if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos)); | |
1444 | } | |
1445 | ||
1446 | return mcm->fADCMask; | |
1447 | } | |
1448 | ||
1449 | //-------------------------------------------------------- | |
1450 | void AliTRDrawFastStream::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const | |
1451 | { | |
1452 | // | |
1453 | // decode the adc mask - adcs to be read out | |
1454 | // | |
1455 | mcm->fMCMADCWords = 0; | |
1456 | mcm->fSingleADCwords = 0; | |
1457 | mcm->fADCmax = 0; | |
1458 | mcm->fADCMask = GetMCMadcMask(word, mcm); | |
1459 | ||
1460 | if (mcm->fADCMask > 0) { | |
1461 | for (Int_t i = 0; i < TRDMAXADC; i++) { | |
1462 | mcm->fADCchannel[mcm->fADCmax] = 0; | |
1463 | if ( IS_BIT_SET(mcm->fADCMask,i) ) { | |
1464 | mcm->fADCchannel[mcm->fADCmax] = i; | |
1465 | mcm->fADCmax++; | |
1466 | } | |
1467 | } | |
1468 | } | |
1469 | if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) { // backward compatibility | |
1470 | mcm->fADCmaskCorrupted += 2; | |
1471 | fHC->fDataCorrupted = kTRUE; | |
1472 | if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n", | |
1473 | mcm->fADCcount, mcm->fADCmax, *fMCM.fPos)); | |
1474 | } | |
1475 | } | |
1476 | ||
1477 | //-------------------------------------------------------- | |
1478 | void AliTRDrawFastStream::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const | |
1479 | { | |
1480 | // | |
1481 | // count the expected mcm words for a given tbins | |
1482 | // | |
1483 | mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 ); | |
1484 | mcm->fSingleADCwords = 0; | |
1485 | if (mcm->fADCmax > 0) { | |
1486 | mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax; | |
1487 | } | |
1488 | } | |
1489 | ||
1490 | //------------------------------------------------------------ | |
1491 | Bool_t AliTRDrawFastStream::IsMCMheaderOK() | |
1492 | { | |
1493 | // | |
1494 | // check the mcm header | |
1495 | // | |
1496 | if (fgLastROB != fMCM.fROB) { | |
1497 | fgLastIndex = 0; | |
1498 | if (fgLastROB== -1) fgLastROB = fMCM.fROB; | |
1499 | } | |
1500 | else { | |
1501 | Int_t matchingcounter = 0; | |
1502 | for (Int_t i=fgLastIndex+1; i<16; i++) { | |
1503 | if ( fMCM.fMCM == fgMCMordering[i] ) { | |
1504 | fgLastIndex = i; | |
1505 | matchingcounter++; | |
1506 | break; | |
1507 | } | |
1508 | } | |
1509 | if (matchingcounter == 0) { | |
1510 | fMCM.fMCMhdCorrupted += 2; | |
1511 | AliDebug(11,Form("MCM number from last MCM is larger: MCM # from current MCM %d \n", fMCM.fMCM)); | |
1512 | } | |
1513 | } | |
1514 | ||
1515 | if ( fgLastHC == fHC->fLayer*2 + fHC->fSide ) { | |
1516 | if ( fMCM.fROB < fgLastROB ) { | |
1517 | if((fMCM.fMCMhdCorrupted & 2) == 0) fMCM.fMCMhdCorrupted += 2; | |
1518 | AliDebug(11,Form("ROB number from last MCM is larger: ROB # from current MCM %d \n", fMCM.fROB)); | |
1519 | } | |
1520 | else fgLastROB = fMCM.fROB; | |
1521 | } | |
1522 | ||
1523 | fgLastHC = fHC->fLayer*2 + fHC->fSide; | |
1524 | ||
1525 | if (fEventCounter == 0) { | |
1526 | fEventCounter = fMCM.fEvCounter; | |
1527 | } | |
1528 | ||
1529 | if (fEventCounter != fMCM.fEvCounter) { | |
1530 | fMCM.fMCMhdCorrupted += 4; | |
1531 | if (fgDebugFlag) AliDebug(11,Form("Event number(%d) of current MCM is different from that(%d) of reference MCM %s.\n" | |
1532 | , fMCM.fEvCounter, fEventCounter, DumpMCMinfo(&fMCM))); | |
1533 | } | |
1534 | ||
1535 | if (fEventCounter < fLastEventCounter) { | |
1536 | fMCM.fMCMhdCorrupted += 8; | |
1537 | if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(&fMCM))); | |
1538 | } | |
1539 | ||
1540 | if ( fMCM.fADCmaskCorrupted > 0 ) | |
1541 | return kFALSE; | |
1542 | ||
1543 | if ( fMCM.fMCMhdCorrupted > 0 ) | |
1544 | return kFALSE; | |
1545 | ||
1546 | return kTRUE; | |
1547 | } | |
1548 | ||
1549 | //------------------------------------------------------------ | |
1550 | Bool_t AliTRDrawFastStream::DecodeADC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, | |
1551 | AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, | |
1552 | AliTRDSignalIndex *indexes) | |
1553 | { | |
1554 | // | |
1555 | // decode single ADC channel | |
1556 | // | |
1557 | if(fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1); | |
1558 | if(fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2); | |
1559 | ||
1560 | fTbinADC = 0; | |
1561 | Bool_t isWritten = kFALSE; | |
1562 | ||
1563 | for (Int_t iw = 0; iw < fMCM.fSingleADCwords; iw++) { | |
1564 | if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) { | |
1565 | if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos)); | |
1566 | fHC->fEOTECorrupted = kTRUE; | |
1567 | fpPos--; | |
1568 | return kFALSE; | |
1569 | } | |
1570 | if (fMaskADCword != ADC_WORD_MASK(*fpPos)) { | |
1571 | if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! [Expected mask: 0x%08x Current mask: 0x%08x] ADC channel number: %02d MCM= %s ", | |
1572 | fMaskADCword, ADC_WORD_MASK(*fpPos), fADCnumber, DumpMCMinfo(&fMCM))); | |
1573 | // encode adc level error codes | |
1574 | Int_t index = 21*(fMCM.fMCM + 16*int(fMCM.fROB/2)) + fADCnumber; | |
1575 | fHC->fErrorCodes[index+66] += 1; | |
1576 | if (!isWritten) { | |
1577 | fHC->fErrorCodes[index+66] += (fADCnumber << 4);; | |
1578 | fHC->fErrorCodes[index+66] += (fMCM.fMCM << 9);; | |
1579 | fHC->fErrorCodes[index+66] += (fMCM.fROB << 13);; | |
1580 | isWritten = kTRUE; | |
1581 | } | |
1582 | fMCM.fDataCorrupted = kTRUE; | |
1583 | fHC->fDataCorrupted = kTRUE; | |
1584 | fpPos++; | |
1585 | continue; | |
1586 | } | |
1587 | // decode and put into the digit container | |
1588 | Int_t adcSignals[3]; | |
1589 | adcSignals[0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive; | |
1590 | adcSignals[1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive; | |
1591 | adcSignals[2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive; | |
1592 | ||
1593 | if(GetCol() < 0 || (!fSharedPadsOn & fIsShared)) {fpPos++; continue;}; | |
1594 | for (Int_t i = 0; i < 3; i++) { | |
1595 | if (adcSignals[i] > 0) { | |
1596 | if (fSharedPadsOn) | |
1597 | digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcSignals[i]); | |
1598 | else | |
1599 | digits->SetData(GetRow(), GetCol(), fTbinADC + i, adcSignals[i]); | |
1600 | indexes->AddIndexRC(GetRow(), GetCol()); | |
1601 | } | |
1602 | if (digitsManager->UsesDictionaries()) { | |
1603 | track0->SetData(GetRow(), GetCol(), fTbinADC + i, 0); | |
1604 | track1->SetData(GetRow(), GetCol(), fTbinADC + i, 0); | |
1605 | track2->SetData(GetRow(), GetCol(), fTbinADC + i, 0); | |
1606 | } | |
1607 | } // i | |
1608 | fTbinADC += 3; | |
1609 | fpPos++; | |
1610 | } // iw | |
1611 | ||
1612 | return kTRUE; | |
1613 | } | |
1614 | ||
1615 | //------------------------------------------------------------ | |
1616 | Bool_t AliTRDrawFastStream::SeekEndOfData() | |
1617 | { | |
1618 | // | |
1619 | // go to end of data marker | |
1620 | // | |
1621 | Int_t fEndOfDataCount = 0; | |
1622 | fNWordsCounter = 0; | |
1623 | ||
1624 | while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) { | |
1625 | fpPos++; | |
1626 | fNWordsCounter++; | |
1627 | } | |
1628 | while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd ) { | |
1629 | fEndOfDataCount++; | |
1630 | fpPos++; | |
1631 | } | |
1632 | ||
1633 | return kTRUE; | |
1634 | } | |
1635 | ||
1636 | //------------------------------------------------------------ | |
1637 | Bool_t AliTRDrawFastStream::SeekNextMCMheader() | |
1638 | { | |
1639 | // | |
1640 | // go to mcm marker | |
1641 | // | |
1642 | fpPos++; | |
1643 | ||
1644 | while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) { | |
1645 | if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0) { | |
1646 | if (fgDebugFlag) AliDebug(11,Form("Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos)); | |
1647 | return kTRUE; | |
1648 | } | |
1649 | if ( *fpPos == END_OF_TRACKLET_MARKERNEW) { | |
1650 | fHC->fEOTECorrupted = kTRUE; | |
1651 | return kFALSE; | |
1652 | } | |
1653 | fpPos++; | |
1654 | } | |
1655 | ||
1656 | SeekEndOfData(); | |
1657 | return kFALSE; | |
1658 | } | |
1659 | ||
1660 | //------------------------------------------------------------ | |
1661 | Bool_t AliTRDrawFastStream::SkipMCMdata(UInt_t iw) | |
1662 | { | |
1663 | // | |
1664 | // skip mcm data words due to corruption | |
1665 | // | |
1666 | if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw)); | |
1667 | UInt_t iwcounter = 0; | |
1668 | while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw) { | |
1669 | if ( *fpPos == END_OF_TRACKLET_MARKERNEW) { | |
1670 | if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW"); | |
1671 | fHC->fEOTECorrupted = kTRUE; | |
1672 | return kFALSE; | |
1673 | } | |
1674 | fpPos++; | |
1675 | iwcounter++; | |
1676 | } // while | |
1677 | ||
1678 | if (iwcounter == iw) { | |
1679 | fpPos++; | |
1680 | return kTRUE; | |
1681 | } | |
1682 | ||
1683 | if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER"); | |
1684 | return kFALSE; | |
1685 | } | |
1686 | ||
1687 | //------------------------------------------------------------ | |
1688 | Bool_t AliTRDrawFastStream::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker) | |
1689 | { | |
1690 | // | |
1691 | // dump given number of words for debugging | |
1692 | // | |
1693 | TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px); | |
1694 | for (UInt_t i = 0; i < iw; i++) { | |
1695 | if ( iw != 0 && px + iw > fpEnd) | |
1696 | return kFALSE; | |
1697 | if (i % 8 == 0) tsreturn += "\n "; | |
1698 | if (marker != 0 && marker == px[i]) tsreturn += Form(" *>0x%08x<* ", px[i]); | |
1699 | else tsreturn += Form("0x%08x ", px[i]); | |
1700 | } | |
1701 | tsreturn += "\n"; | |
1702 | ||
1703 | AliInfo(tsreturn.Data()); | |
1704 | ||
1705 | return kTRUE; | |
1706 | } | |
1707 | ||
1708 | //-------------------------------------------------------- | |
1709 | const char *AliTRDrawFastStream::DumpSMInfo(const struct AliTRDrawSM *sm) | |
1710 | { | |
1711 | // | |
1712 | // format the string with the sm info | |
1713 | // | |
1714 | return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d", | |
1715 | *sm->fPos, sm->fHeaderSize, sm->fTrackletEnable, | |
1716 | sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2], | |
1717 | sm->fStackActive[3], sm->fStackActive[4]); | |
1718 | } | |
1719 | ||
1720 | //-------------------------------------------------------- | |
1721 | const char *AliTRDrawFastStream::DumpStackInfo(const struct AliTRDrawStack *st) | |
1722 | { | |
1723 | // | |
1724 | // format the string with the stack info | |
1725 | // | |
1726 | return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d", | |
1727 | *st->fPos, st->fHeaderSize, | |
1728 | st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3], | |
1729 | st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7], | |
1730 | st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]); | |
1731 | ||
1732 | } | |
1733 | //-------------------------------------------------------- | |
1734 | const char *AliTRDrawFastStream::DumpHCinfoH0(const struct AliTRDrawHC *hc) | |
1735 | { | |
1736 | // | |
1737 | // dump the hc header word 0 in strings | |
1738 | // | |
1739 | if (!hc) | |
1740 | return Form("Unable to dump. Null received as parameter!?!"); | |
1741 | else | |
1742 | return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d", | |
1743 | hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard); | |
1744 | } | |
1745 | ||
1746 | //-------------------------------------------------------- | |
1747 | const char *AliTRDrawFastStream::DumpHCinfoH1(const struct AliTRDrawHC *hc) | |
1748 | { | |
1749 | // | |
1750 | // dump the hc header word 1 in strings | |
1751 | // | |
1752 | if (!hc) | |
1753 | return Form("Unable to dump. Null received as parameter!?!"); | |
1754 | else | |
1755 | return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d", | |
1756 | hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase); | |
1757 | } | |
1758 | ||
1759 | //-------------------------------------------------------- | |
1760 | const char *AliTRDrawFastStream::DumpMCMinfo(const struct AliTRDrawMCM *mcm) | |
1761 | { | |
1762 | // | |
1763 | // dump mcm info in strings | |
1764 | // | |
1765 | if (!mcm) | |
1766 | return Form("Unable to dump. Null received as parameter!?!"); | |
1767 | else | |
1768 | return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter); | |
1769 | } | |
1770 | ||
1771 | //-------------------------------------------------------- | |
1772 | const char *AliTRDrawFastStream::DumpMCMadcMask(const struct AliTRDrawMCM *mcm) | |
1773 | { | |
1774 | // | |
1775 | // mcm adc mask in strings | |
1776 | // | |
1777 | if (!mcm) | |
1778 | return Form("Unable to dump. Null received as parameter!?!"); | |
1779 | ||
1780 | TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask); | |
1781 | for (Int_t i = 0; i < TRDMAXADC; i++) { | |
1782 | tsreturn += Form("%d ", mcm->fADCchannel[i]); | |
1783 | } | |
1784 | tsreturn += ""; | |
1785 | return tsreturn.Data(); | |
1786 | } | |
1787 |