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