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