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