]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDrawStreamTB.cxx
Replace plane by layer and chamber by stack
[u/mrichter/AliRoot.git] / TRD / AliTRDrawStreamTB.cxx
CommitLineData
fa7427d0 1#/**************************************************************************
d4232bb6 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$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// This class provides access to TRD digits in raw data. //
21// //
22// It loops over all TRD digits in the raw data given by the AliRawReader. //
23// The Next method goes to the next digit. If there are no digits left //
24// it returns kFALSE. //
25// Several getters provide information about the current digit. //
26// //
27// Author: M. Ploskon (ploskon@ikf.uni-frankfurt.de) //
28// //
29///////////////////////////////////////////////////////////////////////////////
30
31#include "TString.h"
32#include "TFile.h"
33#include "TTreeStream.h"
34
35#include "AliTRDrawStreamTB.h"
36#include "AliTRDgeometry.h"
37#include "AliTRDfeeParam.h"
38#include "AliTRDdigitsManager.h"
625f5260 39#include "AliTRDdataArrayS.h"
6bd744d3 40#include "AliTRDdataArrayI.h"
fb44eb8e 41#include "AliTRDdataArrayDigits.h"
d4232bb6 42#include "AliTRDSignalIndex.h"
74d2e0c7 43// #include "AliTRDReconstructor.h"
0e09df31 44#include "AliTRDrecoParam.h"
fa7427d0 45#include "AliTRDcalibDB.h"
46#include "Cal/AliTRDCalPadStatus.h"
d4232bb6 47
48#include "AliLog.h"
49#include "AliRawReader.h"
50
51#define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa
52#define END_OF_TRACKLET_MARKERNEW 0x10001000
53#define ENDOFRAWDATAMARKER 0x00000000
bb1009bf 54#define ENDBITS 0x03
d4232bb6 55#define WORD_SIZE sizeof(UInt_t) // size of a word in bytes
56#define EXTRA_LEAD_WORDS 24
57#define CDH_WORDS 8
58
59#define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w
60#define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m
61
62// SM index word masks:
63#define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
64#define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)
65#define STACK_MASK(w) ((w) & 0x1f)
66
67// Stack word masks
68#define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
69#define STACK_LINK_WORD(w) ((w) & 0xfff)
70
71// HC word masks
72//#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!!
73#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK!!!
74
75// HC word 0
76#define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)
77#define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)
dc25a859 78#define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24)
d4232bb6 79#define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)
80#define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)
81#define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)
82#define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)
83#define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)
84#define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)
85#define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)
86
87// HC word 1
88#define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)
89#define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)
90#define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)
91#define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,6)
92
93//--------------------------------------------------------
94
95// MCM word and ADC mask
96#define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
97#define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!
98#define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)
99#define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)
100#define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)
101#define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)
bb1009bf 102#define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25)
d4232bb6 103
bb1009bf 104#define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated
105//#define MCM_DUMMY_ADCMASK_VAL 0x001fffffc
2e2bc4a1 106#define ADCDATA_VAL1 0x2 // updated
107#define ADCDATA_VAL2 0x3 // updated
108
d4232bb6 109//--------------------------------------------------------
110
111#define MAX_TRACKLETS_PERHC 256 // max number of tracklets per HC - large number for now
112
113//--------------------------------------------------------
114#define ADC_WORD_MASK(w) ((w) & 0x3)
115//--------------------------------------------------------
dc25a859 116
117
d4232bb6 118ClassImp(AliTRDrawStreamTB)
119
120Bool_t AliTRDrawStreamTB::fgExtraSkip = kFALSE;
121Bool_t AliTRDrawStreamTB::fgSkipCDH = kFALSE;
122Bool_t AliTRDrawStreamTB::fgWarnError = kTRUE;
123Bool_t AliTRDrawStreamTB::fgCleanDataOnly = kTRUE;
124Bool_t AliTRDrawStreamTB::fgDebugFlag = kTRUE;
125Bool_t AliTRDrawStreamTB::fgDebugStreamFlag = kFALSE;
6bd744d3 126Bool_t AliTRDrawStreamTB::fgStackNumberChecker = kTRUE;
7e8f4d17 127Bool_t AliTRDrawStreamTB::fgStackLinkNumberChecker = kTRUE;
bb1009bf 128Bool_t AliTRDrawStreamTB::fgSkipData = kTRUE;
d4232bb6 129TTreeSRedirector *AliTRDrawStreamTB::fgDebugStreamer = 0;
130UInt_t AliTRDrawStreamTB::fgStreamEventCounter = 0;
7e8f4d17 131UInt_t AliTRDrawStreamTB::fgFirstEquipmentID = 0;
d4232bb6 132UInt_t AliTRDrawStreamTB::fgDumpHead = 0;
1ced3838 133Int_t AliTRDrawStreamTB::fgCommonAdditive = 0;
d4232bb6 134Int_t AliTRDrawStreamTB::fgEmptySignals[] =
135 {
136 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
137 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
138 };
139
140AliTRDrawStreamTB::AliTRDrawStreamTB()
dfbb4bb9 141 : AliTRDrawStreamBase()
142//: TObject()
d4232bb6 143 , fSM()
144 , fStack(0)
145 , fHC(0)
146 , fMCM(0)
147 , fADC(0)
148 , fpPos(0)
149 , fpBegin(0)
150 , fpEnd(0)
151 , fWordLength(0)
7e8f4d17 152 , fEquipmentID(0)
d4232bb6 153 , fStackNumber(-1)
154 , fStackLinkNumber(-1)
155 , fhcMCMcounter(0)
156 , fmcmADCcounter(0)
157 , fLinkTrackletCounter(-1)
158 , fEndOfTrackletCount(-1)
159 , fMaskADCword(0)
160 , fTbinADC(0)
161 , fDecodedADCs(-1)
162 , fEventCounter(0)
163 , fLastEventCounter(0)
d4232bb6 164 , fSharedPadsOn(kFALSE)
165 , fMaxADCgeom(0)
166 , fGeometry(0)
167 , fRawReader(0)
168 , fTRDfeeParam(0)
169 , fDebugStreamOwned(kFALSE)
170{
171 //
172 // default constructor
173 //
174
175 if (Init() == kFALSE)
176 {
177 AliWarning("Unable to Init.");
178 }
179}
180
181//--------------------------------------------------------
182AliTRDrawStreamTB::AliTRDrawStreamTB(AliRawReader *rawReader)
dfbb4bb9 183 : AliTRDrawStreamBase(rawReader)
184//: TObject()
d4232bb6 185 , fSM()
186 , fStack(0)
187 , fHC(0)
188 , fMCM(0)
189 , fADC(0)
190 , fpPos(0)
191 , fpBegin(0)
192 , fpEnd(0)
193 , fWordLength(0)
7e8f4d17 194 , fEquipmentID(0)
d4232bb6 195 , fStackNumber(-1)
196 , fStackLinkNumber(-1)
197 , fhcMCMcounter(0)
198 , fmcmADCcounter(0)
199 , fLinkTrackletCounter(-1)
200 , fEndOfTrackletCount(-1)
201 , fMaskADCword(0)
202 , fTbinADC(0)
203 , fDecodedADCs(-1)
204 , fEventCounter(0)
205 , fLastEventCounter(0)
d4232bb6 206 , fSharedPadsOn(kFALSE)
207 , fMaxADCgeom(0)
208 , fGeometry(0)
209 , fRawReader(rawReader)
210 , fTRDfeeParam(0)
211 , fDebugStreamOwned(kFALSE)
212{
213 //
214 // default constructor
215 //
216 if (fRawReader)
217 {
218 if (Init() == kFALSE)
219 {
220 AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
221 }
222 }
223 else
224 {
225 AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
226 }
227}
228
229//------------------------------------------------------------
230
231AliTRDrawStreamTB::AliTRDrawStreamTB(const AliTRDrawStreamTB& /*st*/)
dfbb4bb9 232 : AliTRDrawStreamBase()
233//: TObject()
d4232bb6 234 , fSM()
235 , fStack(0)
236 , fHC(0)
237 , fMCM(0)
238 , fADC(0)
239 , fpPos(0)
240 , fpBegin(0)
241 , fpEnd(0)
242 , fWordLength(0)
7e8f4d17 243 , fEquipmentID(0)
d4232bb6 244 , fStackNumber(-1)
245 , fStackLinkNumber(-1)
246 , fhcMCMcounter(0)
247 , fmcmADCcounter(0)
248 , fLinkTrackletCounter(-1)
249 , fEndOfTrackletCount(-1)
250 , fMaskADCword(0)
251 , fTbinADC(0)
252 , fDecodedADCs(-1)
253 , fEventCounter(0)
254 , fLastEventCounter(0)
d4232bb6 255 , fSharedPadsOn(kFALSE)
256 , fMaxADCgeom(0)
257 , fGeometry(0)
258 , fRawReader(0)
259 , fTRDfeeParam(0)
260 , fDebugStreamOwned(kFALSE)
261{
262 //
263 // Copy constructor
264 //
265 AliError("Not implemeneted.");
266}
267
268//------------------------------------------------------------
dfbb4bb9 269Bool_t AliTRDrawStreamTB::SetRawVersion(Int_t fraw)
d4232bb6 270{
271 //
272 // function provided for backward compatibility
273 //
274 AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");
275 fraw = 0; // avoid warnings
dfbb4bb9 276 return kFALSE;
d4232bb6 277}
278
279//------------------------------------------------------------
280AliTRDrawStreamTB::~AliTRDrawStreamTB()
281{
282 //
283 // destructor
284 //
285 delete fGeometry;
286
287 if (fDebugStreamOwned == kTRUE)
288 {
289 if (fgDebugStreamer)
290 {
291 delete fgDebugStreamer;
292 fgDebugStreamer = 0;
293 }
294 }
295}
296
297//------------------------------------------------------------
298
299AliTRDrawStreamTB &
300AliTRDrawStreamTB::operator=(const AliTRDrawStreamTB &)
301{
302 //
303 // we are not using this functionality
304 //
305 AliFatal("May not use.");
306 return *this;
307}
308
309//------------------------------------------------------------
310
311void
312AliTRDrawStreamTB::EnableDebug(TTreeSRedirector *debugStream)
313{
314 //
315 // replace the current debug streamer or create a new one if owned
316 //
317
318 if (debugStream == 0)
319 {
320 if (fDebugStreamOwned == kTRUE)
321 {
322 if (fgDebugStreamer)
323 delete fgDebugStreamer;
324 }
325
326 fDebugStreamOwned = kTRUE;
327 fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root");
328 fgStreamEventCounter = 0;
329
330 }
331 else
332 {
333 if (fDebugStreamOwned == kTRUE)
334 {
335 if (fgDebugStreamer)
336 delete fgDebugStreamer;
337 }
338
339 fgDebugStreamer = debugStream;
340 fDebugStreamOwned = kFALSE;
341 }
342}
343
344//___________________________________________________________
345void
346AliTRDrawStreamTB::SwapOnEndian()
347{
348 //
349 // Check the endian and swap if needed
350 //
351
352 int itemp = 1;
353 char* ptemp = (char*) &itemp;
354 if (ptemp[0] != 1)
355 {
356 // need to swap...
357 if (fgDebugFlag) AliDebug(8, "Swapping.");
358
359 fpPos = fpBegin;
360 UInt_t iutmp = 0;
361 while (fpPos < fpEnd)
362 {
363 fpPos += 1;
364 iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
365 ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
366 // here we override the value in the buffer!
367 *fpPos = iutmp;
368 }
369 fpPos = fpBegin;
370 }
371}
372
373//------------------------------------------------------------
374void
375AliTRDrawStreamTB::DumpErrorCount()
376{
377 //
378 // print the error statistics into the stdout
379 //
380
381 ;
382 // AliInfo(Form("Error counts: HC0 %d HC1 %d MCM %d ADCmask %d ADC %d",
383 // fHC->fH0ErrorCounter, fHC->fH1ErrorCounter, fMCM->fErrorCounter, fMCM->fMaskErrorCounter, adc.fErrorCounter));
384}
385
386//------------------------------------------------------------
387Bool_t
388AliTRDrawStreamTB::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
389{
390 //
391 // skip few words
392 // note: can be made faster
393 //
394
395 TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
396 for (UInt_t i = 0; i < iw; i++)
397 {
398 if (px + iw >= fpEnd)
399 return kFALSE;
400
401 if (i % 8 == 0)
402 tsreturn += "\n ";
403 if (marker != 0 && marker == px[i])
404 tsreturn += Form(" *>0x%08x<* ", px[i]);
405 else
406 tsreturn += Form("0x%08x ", px[i]);
407 }
408 tsreturn += "\n";
409
410 AliInfo(tsreturn.Data());
411
412 return kTRUE;
413}
414
415//------------------------------------------------------------
416Bool_t
417AliTRDrawStreamTB::SkipWords(UInt_t iw)
418{
419 //
420 // skip few words
421 // note: can be made faster
422 //
423
424 if ( fpPos + iw < fpEnd )
425 {
426 fpPos += iw;
427 return kTRUE;
428 }
429 else
430 {
431 if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
432 if (fgDebugStreamer)
433 {
434 TTreeSRedirector &cstream = *fgDebugStreamer;
435 cstream << "SkipWords"
436 << "Event=" << fgStreamEventCounter
437 << ".nwords=" << iw
438// << ".read=" << (Char_t*)(fpPos - fpBegin)
439// << ".togo=" << (Char_t*)(fpEnd - fpPos)
440// << ".length=" << (Char_t*)(fpEnd - fpBegin)
441 << "\n";
442 }
443 return kFALSE;
444 }
445
446 return kTRUE;
447}
448
449//------------------------------------------------------------
450Bool_t
451AliTRDrawStreamTB::SetReader(AliRawReader *reader)
452{
453 //
454 //
455 //
456
457 if (reader != 0)
458 {
459 fRawReader = reader;
460 if (fRawReader)
461 {
462 return Init();
463 }
464 else
465 {
466 AliWarning("Unable to setup reader.");
467 return kFALSE;
468 }
469 }
470 else
471 {
472 AliWarning("AliRawReader argument is 0.");
473 fRawReader = 0;
474 }
475
476 return kFALSE;
477}
478
479//------------------------------------------------------------
480Int_t
481AliTRDrawStreamTB::NextBuffer()
482{
483 //
484 // return -1 if no more buffers available
485 // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come
486 // return 1 DecodeSM OK
487 //
488
489 if (fRawReader != 0)
490 {
491 UChar_t *buffer = 0;
492 UInt_t length = 0;
493 Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
494 if (kBufferSet == kTRUE)
495 {
496 if (fgDebugFlag) AliDebug(9, "Buffer is set.");
497 length = fRawReader->GetDataSize();
498 if (fgExtraSkip == kTRUE)
499 {
500 buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
501 length -= EXTRA_LEAD_WORDS * WORD_SIZE;
502 }
503
504 if (fgSkipCDH == kTRUE)
505 {
506 buffer += CDH_WORDS * WORD_SIZE;
507 length -= CDH_WORDS * WORD_SIZE;
508 }
509
510 if (length > 0)
511 {
512 if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
513 //return InitBuffer((void*)buffer, length);
514 if (DecodeSM((void*)buffer, length) == kTRUE)
515 return 1;
516 else
517 return 0;
518 }
519 }
520 else
521 {
522 return -1;
523 }
524 }
525
526 return -1;
527}
528
529//------------------------------------------------------------
530void
531AliTRDrawStreamTB::ResetCounters()
532{
533 //
534 // reset some global counters
535 //
536
537 fStackNumber = 0;
538 fStackLinkNumber = 0;
539
540 fDecodedADCs = 0;
541
542 fSM.fActiveStacks = 0;
543 fSM.fNexpectedHalfChambers = 0;
544
545 fLinkTrackletCounter = 0;
546
547 fLastEventCounter = 0;
548 fEventCounter = 0;
549}
550
551//------------------------------------------------------------
552void
553AliTRDrawStreamTB::ResetIterators()
554{
555 //
556 // reset the data iterators used in the Next()
557 //
558 fStackNumber = 0;
559 fStackLinkNumber = 0;
560 fhcMCMcounter = 0;
561 fmcmADCcounter = 0;
562}
563
564//------------------------------------------------------------
565
566Bool_t
567AliTRDrawStreamTB::Next()
568{
569 //
570 // returns with true on next adc read
571 // returns false on errors and end of buffer
572 //
573
574 while (fStackNumber < 5 && fSM.fActiveStacks > 0)
575 {
576 if(fSM.fStackActive[fStackNumber] == kTRUE)
577 {
578 fStack = &fSM.fStacks[fStackNumber];
579 while (fStackLinkNumber < 12)
580 {
581 if (fStack->fLinksActive[fStackLinkNumber] == kTRUE)
582 {
583 fHC = &fStack->fHalfChambers[fStackLinkNumber];
584 if (!fHC)
585 {
586 AliError(Form("Super Strange. HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
587 return kFALSE;
588 }
d4232bb6 589 if (fHC->fCorrupted == 0)
590 {
591 while (fhcMCMcounter < fHC->fMCMmax)
592 {
593 fMCM = &fHC->fMCMs[fhcMCMcounter];
d4232bb6 594 if (!fMCM)
595 {
596 AliError(Form("Super Strange. HC missing at stack %d link %d atMCMslot %d",
597 fStackNumber, fStackLinkNumber, fhcMCMcounter));
598 return kFALSE;
599 }
600 while(fmcmADCcounter < fMCM->fADCmax)
601 {
d4232bb6 602 fADC = &fMCM->fADCs[fmcmADCcounter];
603 if (!fADC)
604 {
605 AliError(Form("Super Strange. ADC missing at stack %d link %d MCMslot %d ADCslot %d",
606 fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));
607 return kFALSE;
608 }
609 fmcmADCcounter++;
d4232bb6 610 if (fSharedPadsOn)
611 {
612 return kTRUE;
613 }
614 else
615 {
616 if (fADC->fIsShared == kFALSE)
617 return kTRUE;
618 }
619 } //while adc in MCM
d4232bb6 620 fhcMCMcounter++;
621 // next MCM should go through all active ADCs
622 fmcmADCcounter = 0;
623 } // while mcm
624 } // if HC OK
625 }// if link active
626 fStackLinkNumber++;
627 // next stack link (HC) should go through all active MCMs
628 fhcMCMcounter = 0;
629 }// while links
630 }// if stack active
631 fStackNumber++;
632 // next stack should go through all links - start from 0
633 fStackLinkNumber = 0;
634 }
635
636 // in case rawreader manages the mem buffers
637 // lets go for the next buffer
638 if (fRawReader)
639 {
640 Int_t nextBuff = NextBuffer();
641 while (nextBuff != -1)
642 {
643 if (nextBuff > 0)
644 return Next();
645 nextBuff = NextBuffer();
646 }
647 }
648
649 return kFALSE;
650}
651
652//------------------------------------------------------------
653
654Int_t
655AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager)
656{
657 //
658 // Fills single chamber digit array
659 // Return value is the detector number
660 //
661
fa7427d0 662 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
fb44eb8e 663 AliTRDdataArrayDigits *digits = 0;
d4232bb6 664 AliTRDdataArrayI *track0 = 0;
665 AliTRDdataArrayI *track1 = 0;
666 AliTRDdataArrayI *track2 = 0;
667 AliTRDSignalIndex *indexes = 0;
668
0e09df31 669 // Get the ADC baseline
670 Int_t adcBaseline = 0;
74d2e0c7 671// if (!AliTRDReconstructor::RecoParam())
672// {
673// AliError("RecoParam does not exist\n");
674// return 0;
675// }
676// else
677// {
678// adcBaseline = ((Int_t) AliTRDReconstructor::RecoParam()->GetADCbaseline());
679// }
680
681 static AliTRDrecoParam * par = AliTRDrecoParam::GetLowFluxParam();
682 adcBaseline = par->GetADCbaseline();
d4232bb6 683 // Loop through the digits
684 Int_t lastdet = -1;
c5f589b9 685 Int_t det = -1;
d4232bb6 686 // Int_t returnDet = -1;
687 Int_t it = 0;
688 while (Next())
689 {
690 det = GetDet();
691
692 if (det != lastdet)
693 {
694 // If new detector found
695 if (lastdet == -1)
696 {
697 lastdet = det;
698 }
699 else
700 {
701 return lastdet;
702 }
dad68eff 703
704 if (det < 0 || det >= AliTRDgeometry::kNdet)
705 {
706 if (fSM.fClean == kTRUE)
707 {
708 AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));
709 }
710 else
711 {
712 AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));
713 }
714 continue;
715 }
716
d4232bb6 717 // Add a container for the digits of this detector
fb44eb8e 718 digits = (AliTRDdataArrayDigits *) digitsManager->GetDigits(det);
fa7427d0 719
c5f589b9 720 if (digitsManager->UsesDictionaries())
721 {
722 track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0);
723 track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1);
724 track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2);
725 }
d4232bb6 726
dad68eff 727 if (!digits)
728 {
729 if (fSM.fClean == kTRUE)
730 {
731 AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));
732 }
733 else
734 {
735 AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));
736 }
737 return -1;
738 //continue;
739 }
740
d4232bb6 741 Int_t rowMax = GetRowMax();
742 Int_t colMax = GetColMax();
743 Int_t ntbins = GetNumberOfTimeBins();
744
745 // Allocate memory space for the digits buffer
746 if (digits->GetNtime() == 0)
747 {
748 digits->Allocate(rowMax, colMax, ntbins);
c5f589b9 749 if (digitsManager->UsesDictionaries())
750 {
751 track0->Allocate(rowMax, colMax, ntbins);
752 track1->Allocate(rowMax, colMax, ntbins);
753 track2->Allocate(rowMax, colMax, ntbins);
754 }
d4232bb6 755 }
756
757 indexes = digitsManager->GetIndexes(det);
758 indexes->SetSM(GetSM());
759 indexes->SetStack(GetStack());
760 indexes->SetLayer(GetLayer());
761 indexes->SetDetNumber(det);
762 if (indexes->IsAllocated() == kFALSE)
763 indexes->Allocate(rowMax, colMax, ntbins);
764 }
fa7427d0 765
766 Char_t padStatus = cal->GetPadStatus(det, GetCol(), GetRow());
767
d4232bb6 768 // ntimebins data are ready to read
769 for (it = 0; it < GetNumberOfTimeBins(); it++)
770 {
0e09df31 771 if ((GetSignals()[it] - adcBaseline) > 0)
d4232bb6 772 {
fb44eb8e 773 digits->SetDataUnchecked(GetRow(), GetCol(), it, GetSignals()[it] - adcBaseline);
f5375dcb 774 if(padStatus)
775 digits->SetPadStatus(GetRow(), GetCol(), it, padStatus);
fb44eb8e 776
d4232bb6 777 indexes->AddIndexTBin(GetRow(), GetCol(), it);
c5f589b9 778 if (digitsManager->UsesDictionaries())
779 {
780 track0->SetDataUnchecked(GetRow(), GetCol(), it, 0);
781 track1->SetDataUnchecked(GetRow(), GetCol(), it, 0);
782 track2->SetDataUnchecked(GetRow(), GetCol(), it, 0);
783 }
d4232bb6 784 }
785 } // tbins
786 }// while Next()
787
788 // what happens if the last HC is turned off?
789 return det;
790 //return -1;
791}
792
793//------------------------------------------------------------
794Bool_t
795AliTRDrawStreamTB::Init()
796{
797 //
798 // general init
799 //
800
801 TDirectory *saveDir = gDirectory;
802
803 if (!fGeometry)
804 {
805 fGeometry = new AliTRDgeometry();
806 }
807
808 if (!fGeometry)
809 {
810 AliError("Geometry FAILED!");
811 return kFALSE;
812 }
813
814 fTRDfeeParam = AliTRDfeeParam::Instance();
815 if (!fTRDfeeParam)
816 {
817 AliError("AliTRDfeeParam FAILED!");
818 return kFALSE;
819 }
820
821 fMaxADCgeom = (Int_t)fGeometry->ADCmax();
822
1ced3838 823 // common additive is moved to be static for temp solution
824 // common additive should be delivered in the HC word 2 (3rd word)
825 //fCommonAdditive = 10;
d4232bb6 826
827 ResetCounters();
828
d4232bb6 829 if (fgDebugStreamFlag == kTRUE)
830 {
831 if (!fgDebugStreamer)
832 {
833 fgDebugStreamer = new TTreeSRedirector("TRDrawDataDebug.root");
834 fgStreamEventCounter = 0;
835
836 if (fgDebugStreamer)
837 {
838 AliInfo(Form("Debug Streamer Initialized! Remember to delete! %s::DeleteDebugStream()", this->IsA()->GetName()));
839 //fDebugStreamOwned = kTRUE;
840 }
841 else
842 {
843 AliError("Unable to init debug stream");
844 }
845 }
846 }
847
bb1009bf 848 // in case rawreader manages the mem buffers
849 // lets go for the next buffer
850 if (fRawReader)
851 {
852 Int_t nextBuff = NextBuffer();
853 while (nextBuff != -1)
854 {
855 if (nextBuff > 0)
856 return kTRUE;
857 nextBuff = NextBuffer();
858 }
859 }
860
d4232bb6 861 saveDir->cd();
862
863 return kTRUE;
864}
865
866void AliTRDrawStreamTB::DeleteDebugStream()
867{
868 //
869 // static helper function
870 //
871
872 if (fgDebugStreamer)
873 {
874 delete fgDebugStreamer;
875 fgDebugStreamer = 0;
876 }
877
878}
879
880//------------------------------------------------------------
881Bool_t
882AliTRDrawStreamTB::InitBuffer(void *buffer, UInt_t length)
883{
884 //
885 // init the class before reading from the buffer
886 // and read SM heading info:
887 // -- super module header
888 // -- stack headers + link status words
889 //
890
891 // not in the pre scan mode
7e8f4d17 892 //get Equipment ID
893 if(fgStreamEventCounter == 0) fgFirstEquipmentID = fRawReader->GetEquipmentId();
894 fEquipmentID = fRawReader->GetEquipmentId();
895 //fgStreamEventCounter++;
896 if(fEquipmentID == fgFirstEquipmentID) fgStreamEventCounter++;
897
d4232bb6 898
899 ResetCounters();
900
901 fpBegin = (UInt_t *)buffer;
902
903 if (WORD_SIZE == 0)
904 {
905 AliFatal("Strange! Size of UInt_t == 0");
906 return kFALSE;
907 }
908
909 fWordLength = length/WORD_SIZE;
910 fpEnd = fpBegin + fWordLength;
911 fpPos = fpBegin;
912
913 if (fpBegin == 0 || length <= 0)
914 {
915 AliError(Form("This will not work! Pointer to the buffer is 0x%08x of size %d", fpBegin, length));
916 return kFALSE;
917 }
918
919 SwapOnEndian();
920
921 if (fgDumpHead > 0)
922 {
923 AliInfo("------------------------------------------------");
924 if (DumpWords(fpBegin, fgDumpHead) == kFALSE)
925 {
926 AliError("Dump failed. Not enough data.");
927 }
928 AliInfo("------------------------------------------------");
929 }
930
931 //decode SM
932 DecodeSMInfo(fpPos, &fSM);
933
934 if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
935
936 fpPos++;
937 if (fpPos < fpEnd)
938 {
939 if (SkipWords(fSM.fHeaderSize) == kTRUE)
940 {
941 //decode stacks info
942 //for (Int_t istack = 0; istack < fSM.fActiveStacks; istack++)
943 for (Int_t istack = 0; istack < 5; istack++)
944 {
945 if (fSM.fStackActive[istack] == kFALSE)
946 continue;
947
948 fStack = &fSM.fStacks[istack];
949 DecodeStackInfo(fpPos, fStack);
950 fpPos++;
951
952 fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
953
954 if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
955
956 if (SkipWords(fStack->fHeaderSize) == kFALSE)
957 {
958 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack head words missing");
959 return kFALSE;
960 }
961 }
962 }
963 else
964 {
965 return kFALSE;
966 }
967 }
968 else
969 {
970 if (fgWarnError) AliWarning("No Stack info present. Strange.");
971 if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
972 return kFALSE;
973 }
974
975 if (fgDebugFlag) AliDebug(5, Form("Expected half chambers : %d", fSM.fNexpectedHalfChambers));
976
977 //fpPos++;
978 if (fpPos < fpEnd)
979 {
980 if (fgDebugFlag) AliDebug(5, "Init OK.");
981 }
982 else
983 {
984 if (fgWarnError) AliWarning("No data just after init. Strange.");
985 if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing data");
986 return kFALSE;
987 }
988
989 return kTRUE;
990}
991
992//------------------------------------------------------------
993Bool_t
994AliTRDrawStreamTB::DecodeSM(void *buffer, UInt_t length)
995{
996 //
997 // decode all sm at once
998 // still here for devel and debug
999 //
1000
1001 //memset(&fSM, 0, sizeof(fSM));
1002
1003 ResetIterators();
1004
1005 fSM.fClean = kTRUE;
1006 if (InitBuffer(buffer, length) == kTRUE)
1007 {
1008 // no we are already set!
1009 // fpPos++;
1010 }
1011 else
1012 {
1013 if (fgWarnError) AliError("--- INIT failed. ---------------");
1014 fSM.fClean = kFALSE;
1015 return kFALSE;
1016 }
1017
1018 //decode data here
1019 //fSM.fActiveStacks
1020 for (Int_t istack = 0; istack < 5; istack++)
1021 {
1022 fStackNumber = istack;
1023 if (fSM.fStackActive[istack] == kFALSE)
1024 continue;
1025
1026 fStack = &fSM.fStacks[istack];
1027
1028 //fStack[istack].fActiveLinks // max is 12
1029 for (Int_t ilink = 0; ilink < 12; ilink++)
1030 {
1031 fStackLinkNumber = ilink;
1032 if (fStack->fLinksActive[ilink] == kFALSE)
1033 continue;
1034
1035 if (fpPos >= fpEnd)
1036 {
1037 if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
1038 fSM.fClean = kFALSE;
1039 break;
1040 }
1041
1042 fHC = &fStack->fHalfChambers[ilink];
1043
7e8f4d17 1044 if (fgDebugStreamer)
1045 {
1046 TTreeSRedirector &cstream = *fgDebugStreamer;
1047 cstream << "LINKDataStream"
1048 << "Event=" << fgStreamEventCounter
1049 << ".equipID=" << fEquipmentID
1050 << ".stack=" << fStackNumber
1051 << ".link=" << fStackLinkNumber
1052 << "\n";
1053 }
1054
1055
d4232bb6 1056 if (fSM.fTrackletEnable == kTRUE)
1057 {
1058 if (DecodeTracklets() == kFALSE)
1059 {
d4232bb6 1060 if (fgDebugStreamer)
1061 {
1062 TTreeSRedirector &cstream = *fgDebugStreamer;
1063 cstream << "TrackletDecodeError"
1064 << "Event=" << fgStreamEventCounter
1065 << ".Stack=" << fStackNumber
1066 << ".Link=" << fStackLinkNumber
1067 << ".EndOfTrackletCount=" << fEndOfTrackletCount
1068 << "\n";
1069 }
1070
1071 fSM.fClean = kFALSE;
1072 SeekEndOfData();
1073
1074 if (fgWarnError)
1075 {
1076 AliError(Form("Failed stack %d link %d", fStackNumber, fStackLinkNumber));
1077 AliError(Form("Debug Event Counter : %d", fgStreamEventCounter));
1078 }
1079 continue;
1080 //return kFALSE;
1081 }
1082 }
1083
1084 if (fpPos >= fpEnd)
1085 {
1086 if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
1087 fSM.fClean = kFALSE;
1088 break;
1089 }
1090
1091 if (DecodeHC() == kFALSE)
1092 {
d4232bb6 1093 fSM.fClean = kFALSE;
bb1009bf 1094 if (fgWarnError)
1095 {
1096 AliError(Form("Dumping Words for Debugging Purpose =========================>"));
1097 DumpWords(fpPos-8, 16);
1098 AliError(Form("Dumping Done!"));
1099 }
1100 if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW during ADC data decoding or MCM header decoding
1101 // we don't seek ENDOFRAWDATAMARKER
d4232bb6 1102
1103 if (fgWarnError)
1104 {
1105 AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
1106 AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
bb1009bf 1107 AliError(Form("Debug Event Counter : %d\n\n\n", fgStreamEventCounter));
d4232bb6 1108 }
d4232bb6 1109
1110 continue;
1111 //return kFALSE;
1112 }
1113 else
1114 {
bb1009bf 1115 SeekEndOfData(); // make sure that finish off with the end of data markers
d4232bb6 1116 }
1117
d4232bb6 1118 } // ilink
1119 } // istack
1120
1121 // for next()
1122 ResetIterators();
1123
1124 if (fSM.fClean == kTRUE)
1125 return kTRUE;
1126
1127 if (fgCleanDataOnly && (fSM.fClean == kFALSE))
1128 {
1ced3838 1129 if (fgWarnError)
1130 {
1131 AliWarning("Buffer with errors. Returning FALSE.");
1132 AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
1133 }
d4232bb6 1134 fSM.fActiveStacks = 0; // Next will not give data
1135 return kFALSE;
1136 }
1137
1138 return kTRUE;
1139}
1140
1141//------------------------------------------------------------
1142Int_t
1143AliTRDrawStreamTB::DecodeSM()
1144{
1145 //
1146 // decode SM data in case AliRawReader is in use
1147
1148 if (fRawReader)
1149 {
1150 Int_t nextBuff = NextBuffer();
1151 while (nextBuff != -1)
1152 {
1153 if (nextBuff > 0)
1154 return nextBuff;
1155 nextBuff = NextBuffer();
1156 }
1157 return -1;
1158 }
1159 else
1160 {
1161 AliWarning("AliRawReader not set.");
1162 }
1163 return kFALSE;
1164}
1165
1166//------------------------------------------------------------
1167Int_t
1168AliTRDrawStreamTB::DecodeSM(AliRawReader *reader)
1169{
1170 //
1171 // decode SM with the AliRawReader
1172 //
1173 if (reader != 0)
1174 {
1175 fRawReader = reader;
1176 return DecodeSM();
1177 }
1178 else
1179 {
1180 AliWarning("Argument AliRawReader is 0.");
1181 }
1182 return kFALSE;
1183}
1184
1185//------------------------------------------------------------
1186Bool_t
1187AliTRDrawStreamTB::SeekEndOfData()
1188{
1189 //
1190 // go to end of data marker
1191 //
1192 Int_t fEndOfDataCount = 0;
1193
1194 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1195 {
1196 fpPos++;
1197 }
1198
1199 while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd )
1200 {
1201 fEndOfDataCount++;
1202 fpPos++;
1203 }
1204
1205// if (fEndOfDataCount == 0)
1206// {
1207// if (fgWarnError) AliWarning("End of buffer reached first. No end of data marker?");
1208// return kFALSE;
1209// }
1210
1211 return kTRUE;
1212}
1213
1214//------------------------------------------------------------
1215Bool_t
1216AliTRDrawStreamTB::SeekNextMCMheader()
1217{
1218 //
1219 // go to mcm marker
1220 //
1221
1222 // move back to the mcm pos
1223 fpPos = fMCM->fPos + 1;
1224
1225 while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd )
1226 {
d4232bb6 1227 if (MCM_HEADER_MASK_ERR(*fpPos) == 0)
1228 {
1229 if (fgWarnError) AliWarning(Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
1230 return kTRUE;
1231 }
1232 fpPos++;
1233 }
1234
1235 SeekEndOfData();
1236 return kFALSE;
1237}
1238
1239//------------------------------------------------------------
1240
1241Bool_t
1242AliTRDrawStreamTB::DecodeTracklets()
1243{
1244 //
1245 // decode tracklets
1246 //
1247
1248 fLinkTrackletCounter = 0;
1249 fEndOfTrackletCount = 0;
1250
1251 if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
d4232bb6 1252
1253 while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd )
1254 {
1255
1256 if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
1257
d4232bb6 1258 fLinkTrackletCounter++;
1259
1260 if (fLinkTrackletCounter > MAX_TRACKLETS_PERHC)
1261 {
1262 if (fgWarnError) AliWarning(Form("Max number of tracklets exceeded %d > %d. Something is wrong with the input data!",
1263 fLinkTrackletCounter, MAX_TRACKLETS_PERHC));
bb1009bf 1264 /*
1265 if (fgWarnError)
1266 {
1267 AliError(Form("Dumping Words for Debugging Purpose =========================>"));
1268 DumpWords(fpPos-300, 320);
1269 AliError(Form("Dumping Done!"));
1270 }
1271 */
d4232bb6 1272
1273 if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
1274 return kFALSE;
1275 }
1276
1277 if (fgDebugStreamer)
1278 {
1279 // jan!
1280 unsigned pid;
1281 unsigned row;
1282 signed defl;
1283 signed ypos;
1284
1285 double deflm;
1286 double yposm;
1287
1288 unsigned long val;
1289
1290 val = *fpPos;
1291
1292 pid = val >> 24;
1293 row = (val >> 20) & 0xF;
1294 defl = (val >> 13) & 0x7F;
1295 defl = defl << 25 >> 25;
1296 ypos = val & 0x1FFF;
1297 ypos = ypos << 19 >> 19;
1298
1299 deflm = defl * 140.0e-6; /* m */
1300 yposm = ypos * 160.0e-6; /* m */
1301
1302 TTreeSRedirector &cstream = *fgDebugStreamer;
1303 cstream << "MCMtracklets"
1304 << "Event=" << fgStreamEventCounter
1305 << ".stack=" << fStackNumber
1306 << ".link=" << fStackLinkNumber
1307 << ".pid=" << pid
1308 << ".row=" << row
1309 << ".defl=" << defl
1310 << ".ypos=" << ypos
1311 << ".deflm=" << deflm
1312 << ".yposm=" << yposm
1313 << "\n";
1314 }
1315 fpPos++;
1316 }
1317
1318 while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd )
1319 {
d4232bb6 1320 if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
1321
1322 fEndOfTrackletCount++;
1323 fpPos++;
1324 }
1325
1326 if ( fEndOfTrackletCount < 2 )
1327 {
d4232bb6 1328 if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
1329 return kFALSE;
1330 }
1331
1332 return kTRUE;
1333}
1334
1335//------------------------------------------------------------
1336Bool_t
1337AliTRDrawStreamTB::IsRowValid()
1338{
1339 //SLOW GEOM
1340 if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||
1341 (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 )
1342 {
1343 if (fgWarnError) AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
1344 , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));
1345 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadrow, "Wrong Row");
1346 return kFALSE;
1347 }
1348 return kTRUE;
1349}
1350
1351//------------------------------------------------------------
1352Bool_t
1353AliTRDrawStreamTB::IsMCMheaderOK()
1354{
1355 //
1356 // check the mcm header
1357 //
1358
bb1009bf 1359 if ( fMCM->fCorrupted > 1 )
d4232bb6 1360 {
1361 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"ADC mask Corrupted");
bb1009bf 1362 if (fgWarnError) AliWarning(Form("Wrong ADC Mask word 0x%08x %s. Error : %d\n", *fMCM->fPos, DumpMCMadcMask(fMCM), fMCM->fCorrupted));
d4232bb6 1363 return kFALSE;
1364 }
1365
1366 if ( fMCM->fCorrupted > 0 )
1367 {
1368 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMheaderCorrupted,"Corrupted");
bb1009bf 1369 if (fgWarnError) AliWarning(Form("Wrong MCM word 0x%08x %s. Error : %d\n", *fMCM->fPos, DumpMCMinfo(fMCM), fMCM->fCorrupted));
d4232bb6 1370 return kFALSE;
1371 }
1372
1373 if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 )
1374 {
1375 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongMCMorROB,"Wrong ROB or MCM");
bb1009bf 1376 if (fgWarnError) AliWarning(Form("Wrong fMCM or fROB. %s\n", DumpMCMinfo(fMCM)));
d4232bb6 1377 return kFALSE;
1378 }
1379
1380 if (IsRowValid() == kFALSE)
1381 return kFALSE;
1382
1383 return kTRUE;
1384}
bb1009bf 1385
1386//------------------------------------------------------------
1387Bool_t
1388AliTRDrawStreamTB::IsMCMevCounterOK()
1389{
1390 //
1391 // Check the MCM event counter
1392 //
1393
1394 if (fEventCounter == 0)
1395 {
1396 fEventCounter = fMCM->fEvCounter;
1397 }
1398
1399 if (fEventCounter < fLastEventCounter)
1400 {
2e2bc4a1 1401 fMCM->fCorrupted += 2;
bb1009bf 1402 if (fgWarnError) AliWarning(Form("Event from the past? Current %d Last %d %s. Error : %d\n", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM), fMCM->fCorrupted));
1403 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ? Past-Future");
1404 return kFALSE;
1405 }
1406
1407 if (fEventCounter != fMCM->fEvCounter)
1408 {
2e2bc4a1 1409 fMCM->fCorrupted += 2;
bb1009bf 1410 if (fgWarnError) AliWarning(Form("Event missmatch? FirstMCMs %d ThisMCMs %d %s. Error : %d\n", fEventCounter, fMCM->fEvCounter, DumpMCMinfo(fMCM), fMCM->fCorrupted));
1411 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMeventMissmatch, "Wrong MCM event counter ?");
1412 return kFALSE;
1413 }
1414
1415 return kTRUE;
1416}
1417
d4232bb6 1418//------------------------------------------------------------
1419Bool_t
1420AliTRDrawStreamTB::DecodeMCMheader()
1421{
1422 //
1423 // decode the mcm header
1424 //
1425
bb1009bf 1426 DecodeMCMheader(fpPos, fMCM);
1427 if (fHC->fCorrupted >= 16)
1428 {
1429 fpPos--;
1430 return kFALSE;
1431 }
d4232bb6 1432
bb1009bf 1433 fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
d4232bb6 1434
bb1009bf 1435 if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || (fHC->fRawVMajor > 31 && fHC->fRawVMajor < 64)) //cover old and new version definition of ZS data
d4232bb6 1436 {
1437 fpPos++;
1438 if ( fpPos < fpEnd )
1439 {
bb1009bf 1440 DecodeMask(fpPos, fMCM);
1441 if (fHC->fCorrupted >= 16)
1442 {
1443 fpPos--;
1444 return kFALSE;
1445 }
d4232bb6 1446 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1447 fMCM->fAdcDataPos = fpPos + 1;
1448 }
1449 else
1450 {
1451 if (fgWarnError) AliWarning("Expected ADC mask word. Fail due to buffer END.");
1452 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
1453 return kFALSE;
1454 }
1455 }
1456 else
1457 {
1458 UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
bb1009bf 1459 DecodeMask(&dummyMask, fMCM);
d4232bb6 1460 MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
1461 fMCM->fAdcDataPos = fpPos + 1;
1462 }
1463
1464 if (fgDebugFlag)
1465 {
1466 AliDebug(6, DumpMCMinfo(fMCM));
1467 AliDebug(7, DumpMCMadcMask(fMCM));
1468 }
1469
1470 if (IsMCMheaderOK() == kFALSE)
d4232bb6 1471 return kFALSE;
d4232bb6 1472
bb1009bf 1473 if (IsMCMevCounterOK() == kFALSE)
d4232bb6 1474 return kFALSE;
d4232bb6 1475
1476 return kTRUE;
d4232bb6 1477}
1478
1479//------------------------------------------------------------
1480Bool_t
1481AliTRDrawStreamTB::IsHCheaderOK()
1482{
1483 //
1484 // check the half chamber header
1485 //
1486
1487 if (fHC->fCorrupted > 0)
1488 {
1489 if (fgWarnError) AliWarning(Form("Wrong HC Header word. Word 0x%08x Error : %d", *fHC->fPos, fHC->fCorrupted));
1490 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "Corrupted");
1491
1492 return kFALSE;
1493 }
1494
1495 if (fHC->fStack < 0 || fHC->fStack > 4)
1496 {
1497 if (fgWarnError) AliWarning(Form("Wrong Stack %d", fHC->fStack));
1498 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Wrong Stack");
1499 return kFALSE;
1500 }
1501
6bd744d3 1502 if (fgStackNumberChecker)
d4232bb6 1503 {
6bd744d3 1504 if (fHC->fStack != fStackNumber)
1505 {
1506 if (fgWarnError) AliWarning(Form("Missmatch: Stack in HC header %d HW-stack %d",
d4232bb6 1507 fHC->fStack, fStackNumber));
6bd744d3 1508 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongStack, "Stack-HWstack");
6bd744d3 1509 fStackNumber = -1;
1510 return kFALSE;
1511 }
d4232bb6 1512 }
1513
053767a4 1514 if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNlayer)
d4232bb6 1515 {
053767a4 1516 if (fgWarnError) AliWarning(Form("Wrong layer %d", fHC->fLayer));
1517 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Wrong layer");
d4232bb6 1518 return kFALSE;
1519 }
1520
7e8f4d17 1521 if (fgStackLinkNumberChecker)
d4232bb6 1522 {
7e8f4d17 1523
1524 if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1))
1525 {
053767a4 1526 if (fgWarnError) AliWarning(Form("Missmatch: layer in HCheader %d HW-Link %d | %s",
7e8f4d17 1527 fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));
053767a4 1528 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongLayer, "Layer-Link missmatch");
7e8f4d17 1529 fStackLinkNumber = -1;
1530 return kFALSE;
1531 }
d4232bb6 1532 }
1533
1534 if (fHC->fSide < 0 || fHC->fSide > 1)
1535 {
1536 if (fgWarnError) AliWarning(Form("Wrong Side %d", fHC->fSide));
1537 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSide, "Wrong Side");
1538 return kFALSE;
1539 }
1540
1541 // SLOW GEOM
1542 fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
1543 if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet)
1544 {
1545 if (fgWarnError) AliWarning(Form("Wrong detector %d", fHC->fDET));
1546 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
1547 return kFALSE;
1548 }
1549
1550 // SLOW GEOM
1551 // this check fails - raw data inconsistent with geometry?
1552 if (fHC->fSM != fGeometry->GetSector(fHC->fDET)
053767a4 1553 || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector)
d4232bb6 1554 {
1555 if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
1556 fHC->fSM, fGeometry->GetSector(fHC->fDET),
1557 fHC->fStack, fHC->fLayer, fHC->fDET));
1558 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
1559 return kFALSE;
1560 }
1561
1562 // SLOW GEOM
1563 // CPU EXPENSIVE!!!
1564 fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
1565 if (fHC->fROC < 0)
1566 {
1567 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
1568 return kFALSE;
1569 }
1570
1571 fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
1572 if (fHC->fRowMax < 1)
1573 {
1574 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
1575 return kFALSE;
1576 }
1577
1578 fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
1579 if (fHC->fColMax < 1)
1580 {
1581 if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
1582 return kFALSE;
1583 }
1584 // extra - not needed
053767a4 1585 // if (fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector)
d4232bb6 1586 // {
1587 // if (fgWarnError) AliWarning(Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d",
1588 // fHC->fSM, fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack),
1589 // fHC->fStack, fHC->fLayer));
1590 // return kFALSE;
1591 // }
1592
1593 return kTRUE;
1594}
1595
1596//------------------------------------------------------------
1597Bool_t
1598AliTRDrawStreamTB::DecodeHCheader()
1599{
1600 //
1601 // decode the half chamber header
1602 //
1603
1604 DecodeHCwordH0(fpPos, fHC);
1605
1606 if (fHC->fNExtraWords > 0)
1607 {
1608 fpPos++;
1609 if (fpPos < fpEnd)
1610 {
1611 DecodeHCwordH1(fpPos, fHC);
1612 }
1613 else
1614 {
1615 if (fgWarnError) AliWarning("Expected HC header word 1. Fail due to buffer END.");
1616 if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing");
1617 return kFALSE;
1618 }
1619 }
1620
1621 if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
1622 if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
1623
1624 fHC->fDET = -1;
1625 if (IsHCheaderOK() == kFALSE)
1626 {
2e2bc4a1 1627 if(fHC->fCorrupted < 1) fHC->fCorrupted +=4;
d4232bb6 1628 return kFALSE;
1629 }
1630
1631 return kTRUE;
1632}
1633
1634//------------------------------------------------------------
1635Bool_t
1636AliTRDrawStreamTB::DecodeHC()
1637{
1638 //
1639 // decode the hc data
1640 // function for devel & debug
1641 //
1642
1643 if (DecodeHCheader() == kFALSE)
1644 {
1645 if (fgDebugStreamer)
1646 {
1647 TTreeSRedirector &cstream = *fgDebugStreamer;
1648 cstream << "HCDecodeError"
1649 << "Event=" << fgStreamEventCounter
1650 << ".stack=" << fStackNumber
1651 << ".link=" << fStackLinkNumber
7e8f4d17 1652 << ".hcCorrupted=" << fHC->fCorrupted
d4232bb6 1653 << ".hcRVmajor=" << fHC->fRawVMajor
1654 << ".hcDCSboard=" << fHC->fDCSboard
1655 << ".hcSM=" << fHC->fSM
1656 << ".hcStack=" << fHC->fStack
1657 << ".hcLayer=" << fHC->fLayer
1658 << ".hcSide=" << fHC->fSide
1659 << ".hcTbins=" << fHC->fTimeBins
1660 << ".hcBunchCross=" << fHC->fBunchCrossCounter
1661 << ".hcPreTrig=" << fHC->fPreTriggerCounter
1662 << ".hcPreTrigPh=" << fHC->fPreTriggerPhase
1663 << ".hcDet=" << fHC->fDET
1664 << ".hcROC=" << fHC->fROC
7e8f4d17 1665 << ".hcRowMax=" << fHC->fRowMax
1666 << ".hcColMax=" << fHC->fColMax
d4232bb6 1667 << "\n";
1668 }
1669
1670 if (fgWarnError) AliWarning("Header decode failed.");
1671 return kFALSE;
1672 }
1673 else
1674 {
1675 fpPos++;
1676 if (fpPos >= fpEnd)
1677 {
1678 if (fgWarnError) AliWarning("No MCM data? Not enough data in the buffer.");
1679 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing");
1680 return kFALSE;
1681 }
1682 }
1683
1684 fHC->fMCMmax = 0;
1685 while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd)
1686 {
1687 if (fHC->fMCMmax > TRD_MAX_MCM)
1688 {
1689 if (fgWarnError) AliWarning("More mcm data than expected!");
1690 if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!");
1691 return kFALSE;
1692 }
1693
1694 fMCM = &fHC->fMCMs[fHC->fMCMmax];
1695
1696 if (DecodeMCMheader() == kFALSE)
1697 {
1698 if (fgDebugStreamer)
1699 {
1700 TTreeSRedirector &cstream = *fgDebugStreamer;
1701 cstream << "MCMDecodeError"
1702 << "Event=" << fgStreamEventCounter
1703 << ".stack=" << fStackNumber
1704 << ".link=" << fStackLinkNumber
1705 << ".hcDCSboard=" << fHC->fDCSboard
1706 << ".hcSM=" << fHC->fSM
1707 << ".hcStack=" << fHC->fStack
1708 << ".hcLayer=" << fHC->fLayer
1709 << ".hcSide=" << fHC->fSide
1710 << ".hcBunchCross=" << fHC->fBunchCrossCounter
1711 << ".hcPreTrig=" << fHC->fPreTriggerCounter
1712 << ".hcPreTrigPh=" << fHC->fPreTriggerPhase
1713 << ".hcDet=" << fHC->fDET
1714
1715 << ".mcmCorrupted=" << fMCM->fCorrupted
1716 << ".mcmROB=" << fMCM->fROB
1717 << ".mcmMCM=" << fMCM->fMCM
1718 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1719 << ".mcmEventCounter=" << fMCM->fEvCounter
1720
1721 << ".fEventCounter=" << fEventCounter
1722 << ".fLastEventCounter=" << fLastEventCounter
1723 << "\n";
1724 }
1725
bb1009bf 1726 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1727 return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose
d4232bb6 1728 }
1729
1730 fHC->fMCMmax++;
1731
1732 if (fMCM->fADCmax > 0)
1733 {
1734 fpPos++;
1735 if (fpPos >= fpEnd)
1736 {
1737 if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected."));
1738 if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing");
1739 }
dc25a859 1740
bb1009bf 1741 unsigned long randVal, iniVal, expectedVal;
1742 Int_t endbits = ENDBITS;
1743
d4232bb6 1744 for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++)
1745 {
1746 fADC = &fMCM->fADCs[iadc];
1747 fADC->fADCnumber = fMCM->fADCchannel[iadc];
1748
1749 if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.",
1750 iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1751
1752 if (fpPos + fMCM->fSingleADCwords >= fpEnd)
1753 {
1754 if (fgDebugStreamer)
1755 {
1756 TTreeSRedirector &cstream = *fgDebugStreamer;
1ced3838 1757 Int_t ierr = -99;
d4232bb6 1758 cstream << "ADCDecodeError"
1759 << "Event=" << fgStreamEventCounter
1760 << ".hcSM=" << fHC->fSM
1761 << ".hcStack=" << fHC->fStack
1762 << ".hcLayer=" << fHC->fLayer
7e8f4d17 1763 << ".hcSide=" << fHC->fSide
1764 << ".hcDet=" << fHC->fDET
d4232bb6 1765 << ".mcmROB=" << fMCM->fROB
1766 << ".mcmMCM=" << fMCM->fMCM
1767 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1ced3838 1768 << ".adcErr=" << ierr
1769 << ".adcNumber=" << ierr
d4232bb6 1770 << "\n";
1771 }
1772
1773 if (fgWarnError) AliWarning(Form("This is ADC %d of %d. ADC number is %d.", iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
1774 if (fgWarnError) AliWarning("--> ADC (10 words) expected. Not enough data in the buffer.");
1775 if (fgWarnError) AliWarning(Form("--> ADC mask : %s", DumpMCMadcMask(fMCM)));
1776
1777 if (fRawReader) fRawReader->AddMajorErrorLog(kADCdataMissing, "ADC data missing - less than expected");
1778 return kFALSE;
1779 }
1780
bb1009bf 1781 if (fHC->fRawVMajor < 64) // normal(real) ADC data
1782 {
1783 if (DecodeADC() == kFALSE)
1784 {
1785 // check if we are out of the det when the pad is shared
1786 if (fADC->fIsShared && fADC->fCorrupted == 4)
1787 {
1788 fADC->fCOL = -1;
1789 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1790 }
1791 else
1792 {
1793 if (fgWarnError) AliWarning(Form("ADC decode failed."));
1794
1795 if (fgDebugStreamer)
1796 {
1797 TTreeSRedirector &cstream = *fgDebugStreamer;
1798 cstream << "ADCDecodeError"
1799 << "Event=" << fgStreamEventCounter
1800 << ".hcSM=" << fHC->fSM
1801 << ".hcStack=" << fHC->fStack
1802 << ".hcLayer=" << fHC->fLayer
1803 << ".hcSide=" << fHC->fSide
1804 << ".hcDet=" << fHC->fDET
1805 << ".mcmROB=" << fMCM->fROB
1806 << ".mcmMCM=" << fMCM->fMCM
1807 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1808 << ".adcErr=" << fADC->fCorrupted
1809 << ".adcNumber=" << fADC->fADCnumber
1810 << "\n";
1811 }
1812 if (fHC->fCorrupted < 16)
1813 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1814
1815 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1816 return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose
1817 }
1818 }
1819 }
1820 else // test pattern data
dc25a859 1821 {
dc25a859 1822 if (fHC->fRawVMajorOpt == 1) //test pattern 1
1823 {
bb1009bf 1824 Int_t iCpu = iadc/5;
1825 if(iadc==20) iCpu = 3;
1826 if(iadc%5==0 && iadc!=20) randVal = (1 << 9) | (fMCM->fROB << 6) | (fMCM->fMCM << 2) | iCpu;
dc25a859 1827 if (DecodeADCTP1(&randVal,&endbits) == kFALSE)
1828 {
bb1009bf 1829 if (fgWarnError) AliWarning(Form("Summary: Test Pattern ADC data are corrupted in channel %d %s\n", iadc, DumpMCMinfo(fMCM)));
dc25a859 1830 if (fgDebugStreamer)
1831 {
1832 TTreeSRedirector &cstream = *fgDebugStreamer;
1833 cstream << "ADCDecodeError"
1834 << "Event=" << fgStreamEventCounter
1835 << ".hcSM=" << fHC->fSM
1836 << ".hcStack=" << fHC->fStack
1837 << ".hcLayer=" << fHC->fLayer
1838 << ".hcSide=" << fHC->fSide
1839 << ".hcDet=" << fHC->fDET
1840 << ".mcmROB=" << fMCM->fROB
1841 << ".mcmMCM=" << fMCM->fMCM
1842 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1843 << ".adcErr=" << fADC->fCorrupted
1844 << ".adcNumber=" << fADC->fADCnumber
1845 << "\n";
1846 }
bb1009bf 1847 if (fHC->fCorrupted < 16)
1848 fpPos = fADC->fPos + fMCM->fSingleADCwords;
dc25a859 1849
bb1009bf 1850 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1851 return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose
dc25a859 1852 }
1853 }
bb1009bf 1854
1855 if (fHC->fRawVMajorOpt == 2 || fHC->fRawVMajorOpt == 3) //test pattern 2 or 3
dc25a859 1856 {
bb1009bf 1857 iniVal = (fHC->fSM << 6) | (fHC->fStack << 0) | (fHC->fLayer << 3);
1858 iniVal = iniVal + 0x49;
1859 iniVal = (iniVal << 9) | (fMCM->fROB << 6) | (fMCM->fMCM << 2) | (fMCM->fEvCounter << 20);
1860 Int_t iCpu = iadc/5;
1861 if (iadc==20) iCpu = 3;
1862 if (iadc%5==0 && iadc!=20)
1863 {
1864 if (fHC->fRawVMajorOpt == 2) { expectedVal = ((iniVal | iCpu) << 6) + 1; };
1865 if (fHC->fRawVMajorOpt == 3) { expectedVal = iniVal | iCpu; };
1866 }
1867 if (DecodeADCTP23(&expectedVal) == kFALSE)
1868 {
1869 if (fgWarnError) AliWarning(Form("Summary: Test Pattern ADC data are corrupted in channel %d %s\n", iadc, DumpMCMinfo(fMCM)));
1870 if (fgDebugStreamer)
1871 {
1872 TTreeSRedirector &cstream = *fgDebugStreamer;
1873 cstream << "ADCDecodeError"
1874 << "Event=" << fgStreamEventCounter
1875 << ".hcSM=" << fHC->fSM
1876 << ".hcStack=" << fHC->fStack
1877 << ".hcLayer=" << fHC->fLayer
7e8f4d17 1878 << ".hcSide=" << fHC->fSide
1879 << ".hcDet=" << fHC->fDET
bb1009bf 1880 << ".mcmROB=" << fMCM->fROB
1881 << ".mcmMCM=" << fMCM->fMCM
1882 << ".mcmADCMaskWord=" << fMCM->fADCMaskWord
1883 << ".adcErr=" << fADC->fCorrupted
1884 << ".adcNumber=" << fADC->fADCnumber
1885 << "\n";
1886 }
1887 if (fHC->fCorrupted < 16)
1888 fpPos = fADC->fPos + fMCM->fSingleADCwords;
1889
1890 if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
1891 return kFALSE; //if(true), keep reading next words even previous words were corrupted - debugging purpose
1892 }
1893 }
1894 }
1895 }
1896 }
d4232bb6 1897 else
1898 {
1899 fpPos++;
1900 }
1901 }//while eof data
1902
1903 if (fpPos >= fpEnd)
1904 {
1905 if (fgWarnError) AliWarning("We are at the end of buffer. There should be one more word left.");
d4232bb6 1906 return kFALSE;
1907 }
1908
1909 return kTRUE;
1910}
d4232bb6 1911//------------------------------------------------------------
dc25a859 1912
d4232bb6 1913Bool_t
1914AliTRDrawStreamTB::DecodeADC()
1915{
1916 //
1917 // decode single ADC channel
1918 //
1919
1920 fADC->fCorrupted = 0;
2e2bc4a1 1921 //fMaskADCword = ADC_WORD_MASK(*fpPos);
1922 if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
1923 if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
1924
d4232bb6 1925 fADC->fPos = fpPos;
d4232bb6 1926 fTbinADC = 0;
1927
1928 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
1929 fADC->fSignals[i] = 0;
1930
1931 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
1932 {
bb1009bf 1933 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW)
1934 {
1935 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
1936 fADC->fCorrupted += 16;
1937 fHC->fCorrupted += 16;
1938 fpPos--;
1939
1940 return kFALSE;
1941 }
d4232bb6 1942 if (fMaskADCword != ADC_WORD_MASK(*fpPos))
1943 {
d4232bb6 1944 fADC->fCorrupted += 1;
2e2bc4a1 1945 if (fgWarnError) AliWarning(Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x Current mask: 0x%08x] MCM= %s Error : %d",
1946 fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));
1947 //if (fgWarnError) AliWarning(Form("Mask Change in ADC data Previous word (%d) : 0x%08x Previous mask : 0x%08x Current word(%d) : 0x%08x Current mask : 0x%08x",
1948 // iw - 1, *(fpPos-1), fMaskADCword, iw, *fpPos, ADC_WORD_MASK(*fpPos)));
d4232bb6 1949 if (fRawReader) fRawReader->AddMajorErrorLog(kADCmaskMissmatch, "Mask change inside single channel");
d4232bb6 1950 break;
1951 }
1ced3838 1952
1953 // here we subtract the baseline ( == common additive)
1954 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - fgCommonAdditive;
1955 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive;
1956 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive;
d4232bb6 1957
1958 fTbinADC += 3;
1959 fpPos++;
1960 }
1961
1962 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
1963 {
1964 fADC->fIsShared = kTRUE;
1965 }
1966 else
1967 {
1968 fADC->fIsShared = kFALSE;
1969 }
1970
1971 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
1972 {
1973 // let us guess the Column
1974 // take the one before last ADC and shift by one column
1975 // later we check if we are inside the limits of the chamber
1976 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
1977 fADC->fCOL--;
1978 }
1979 else
1980 {
1981 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
1982 }
1983
1984 if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0)
1985 {
1986 if (fADC->fIsShared == kFALSE)
1987 {
7e8f4d17 1988 fADC->fCorrupted += 2;
d4232bb6 1989 if (fgWarnError) AliWarning(Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1990 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
1991 if (fRawReader) fRawReader->AddMajorErrorLog(kWrongPadcolumn, "Wrong column");
1992 }
1993 else
1994 {
1995 // flag it - we are out of the det when the pad is shared
1996 if (fgDebugFlag) AliDebug(10, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
1997 fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
7e8f4d17 1998 fADC->fCorrupted += 4;
d4232bb6 1999 }
2000 }
2001
2002 if (fADC->fCorrupted > 0)
2003 {
2004 return kFALSE;
2005 }
2006
2007 fDecodedADCs++;
2008 return kTRUE;
2009}
dc25a859 2010//------------------------------------------------------------
2011
2012Bool_t
bb1009bf 2013AliTRDrawStreamTB::DecodeADCTP1(unsigned long *randVal, Int_t *endbits)
dc25a859 2014{
2015 //
2016 // decode test pattern ADC channel
2017 //
2018
2019 unsigned long expected;
2020
2021 fADC->fCorrupted = 0;
2022 fADC->fPos = fpPos;
dc25a859 2023 fTbinADC = 0;
2024
2025 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
2026 fADC->fSignals[i] = 0;
2027
2028 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
2029 {
bb1009bf 2030 if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW)
dc25a859 2031 {
bb1009bf 2032 if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
2033 fADC->fCorrupted += 16;
2034 fHC->fCorrupted += 16;
2035 fpPos--;
2036
dc25a859 2037 return kFALSE;
2038 }
2039 expected = (AdvancePseudoRandom(randVal) << 2) | *endbits;
2040 expected |= AdvancePseudoRandom(randVal) << 12;
2041 expected |= AdvancePseudoRandom(randVal) << 22;
dc25a859 2042 if (*fpPos != expected)
2043 {
bb1009bf 2044 if (fgWarnError) AliError(Form("Error: fpPos=%d, size=%d, found=0x%08lx, expected=0x%08lx",iw, fMCM->fSingleADCwords, *fpPos, expected));
2045 fADC->fCorrupted += 32; //test pattern corrupted
dc25a859 2046 }
2047 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2);
2048 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12);
2049 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22);
2050
2051 fTbinADC += 3;
2052 fpPos++;
2053 }
2054 *endbits = *endbits ^ 0x01;
2055
2056 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
2057 {
2058 fADC->fIsShared = kTRUE;
2059 }
2060 else
2061 {
2062 fADC->fIsShared = kFALSE;
2063 }
2064
2065 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
2066 {
dc25a859 2067 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
2068 fADC->fCOL--;
2069 }
2070 else
2071 {
2072 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
2073 }
2074
bb1009bf 2075 if (fADC->fCorrupted > 0)
dc25a859 2076 {
bb1009bf 2077 return kFALSE;
2078 }
d4232bb6 2079
bb1009bf 2080 fDecodedADCs++;
2081 return kTRUE;
2082}
2083//--------------------------------------------------------
2084
2085Bool_t
2086AliTRDrawStreamTB::DecodeADCTP23(unsigned long *expected)
2087{
2088 //
2089 // decode test pattern ADC channel
2090 //
2091
2092 fADC->fCorrupted = 0;
2093 fADC->fPos = fpPos;
2094 fTbinADC = 0;
2095
2096 for (Int_t i = 0; i < TRD_MAX_TBINS; i++)
2097 fADC->fSignals[i] = 0;
2098
2099 for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++)
2100 {
2101 if (*fpPos == END_OF_TRACKLET_MARKERNEW)
2102 {
2103 if (fgWarnError) AliError(Form("There should be ADC data. We meet END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
2104 fADC->fCorrupted += 16;
2105 fHC->fCorrupted += 16;
2106 fpPos--;
2107
2108 return kFALSE;
2109 }
2110 if (*fpPos != *expected)
2111 {
2112 if (fgWarnError)
2113 {
2114 if (fHC->fRawVMajorOpt == 2)
2115 {
2116 AliError(Form("Error: fpPos=%d, size=%d, found=0x%08lx, expected=0x%08lx",iw, fMCM->fSingleADCwords, *fpPos, *expected));
2117 AliError(Form("Found ev.cnt. %ld, expected %ld", (*fpPos >> 26), (*expected >> 26)));
2118 AliError(Form("Found sector %ld, expected %ld", (*fpPos >> 21) & 0x1f - 1, (*expected >> 21) & 0x1f - 1));
2119 AliError(Form("Found layer %ld, expected %ld", (*fpPos >> 18) & 0x07 - 1, (*expected >> 18) & 0x07 - 1));
2120 AliError(Form("Found chamber %ld, expected %ld", (*fpPos >> 15) & 0x07 - 1, (*expected >> 15) & 0x07 - 1));
2121 AliError(Form("Found ROB %ld, expected %ld", (*fpPos >> 12) & 0x07, (*expected >> 12) & 0x07));
2122 AliError(Form("Found MCM %ld, expected %ld", (*fpPos >> 8) & 0x0f, (*expected >> 8) & 0x0f));
2123 AliError(Form("Found CPU %ld, expected %ld", (*fpPos >> 6) & 0x03, (*expected >> 6) & 0x03));
2124 AliError(Form("Found counter %ld, expected %ld\n", (*fpPos >> 0) & 0x3f, (*expected >> 0) & 0xf));
2125 }
2126 if (fHC->fRawVMajorOpt == 3)
2127 {
2128 AliError(Form("Error: fpPos=%d, size=%d, found=0x%08lx, expected=0x%08lx",iw, fMCM->fSingleADCwords, *fpPos, *expected));
2129 AliError(Form("Found ev.cnt. %ld, expected %ld", (*fpPos >> 20), (*expected >> 20)));
2130 AliError(Form("Found sector %ld, expected %ld", (*fpPos >> 15) & 0x1f - 1, (*expected >> 15) & 0x1f - 1));
2131 AliError(Form("Found layer %ld, expected %ld", (*fpPos >> 12) & 0x07 - 1, (*expected >> 12) & 0x07 - 1));
2132 AliError(Form("Found chamber %ld, expected %ld", (*fpPos >> 9) & 0x07 - 1, (*expected >> 9) & 0x07 - 1));
2133 AliError(Form("Found ROB %ld, expected %ld", (*fpPos >> 6) & 0x07, (*expected >> 6) & 0x07));
2134 AliError(Form("Found MCM %ld, expected %ld", (*fpPos >> 2) & 0x0f, (*expected >> 2) & 0x0f));
2135 AliError(Form("Found CPU %ld, expected %ld\n", (*fpPos >> 0) & 0x03, (*expected >> 0) & 0x03));
2136 }
2137
2138 }
2139 fADC->fCorrupted += 32; //test pattern corrupted
2140 }
2141 fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2);
2142 fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12);
2143 fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22);
2144
2145 fTbinADC += 3;
2146 fpPos++;
2147 if (fHC->fRawVMajorOpt == 2) (*expected)++;
2148 }
2149
2150 if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1)
2151 {
2152 fADC->fIsShared = kTRUE;
2153 }
2154 else
2155 {
2156 fADC->fIsShared = kFALSE;
2157 }
2158
2159 if ( fADC->fADCnumber >= fMaxADCgeom - 1)
2160 {
2161 fADC->fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber - 1);
2162 fADC->fCOL--;
2163 }
2164 else
2165 {
2166 fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
dc25a859 2167 }
dc25a859 2168
2169 if (fADC->fCorrupted > 0)
2170 {
2171 return kFALSE;
2172 }
2173
2174 fDecodedADCs++;
2175 return kTRUE;
2176}
d4232bb6 2177//--------------------------------------------------------
dc25a859 2178
bb1009bf 2179
d4232bb6 2180void AliTRDrawStreamTB::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
2181{
2182 //
2183 // Decode the data *word into SM info structure
2184 //
2185
2186 sm->fPos = (UInt_t*)word;
2187
2188 // do it once here
2189 UInt_t vword = *word;
2190 sm->fHeaderSize = SM_HEADER_SIZE(vword);
2191
2192 if (TRACKLETS_ENABLED(vword) > 0)
2193 sm->fTrackletEnable = kTRUE;
2194 else
2195 sm->fTrackletEnable = kFALSE;
2196
2197 UInt_t stackMask = STACK_MASK(vword);
2198 sm->fActiveStacks = 0;
2199 for (Int_t i = 0; i < 5; i++)
2200 {
2201 //if ((stackMask >> i) & 0x1 > 0)
2202 if (IS_BIT_SET(stackMask,i) > 0)
2203 {
2204 sm->fStackActive[i] = kTRUE;
2205 sm->fActiveStacks++;
2206 }
2207 else
2208 {
2209 sm->fStackActive[i] = kFALSE;
2210 }
2211 }
2212}
2213
2214//--------------------------------------------------------
2215const char *AliTRDrawStreamTB::DumpSMInfo(const struct AliTRDrawSM *sm)
2216{
2217 //
2218 // Get SM structure into a const char
2219 //
2220
2221 return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
2222 *sm->fPos,
2223 sm->fHeaderSize, sm->fTrackletEnable,
2224 sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
2225 sm->fStackActive[3], sm->fStackActive[4]);
2226}
2227
2228//--------------------------------------------------------
2229void AliTRDrawStreamTB::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
2230{
2231 //
2232 // Decode stack info - active links
2233 //
2234
2235 st->fPos = (UInt_t*)word;
2236
2237 // do it once here
2238 UInt_t vword = *word;
2239 st->fHeaderSize = STACK_HEADER_SIZE(vword);
2240
2241 UInt_t linkMask = STACK_LINK_WORD(vword);
2242 st->fActiveLinks = 0;
2243 for (Int_t i = 0; i < 12; i++)
2244 {
2245 //if (linkMask & (0x1 << i) > 0)
2246 if (IS_BIT_SET(linkMask,i) > 0)
2247 {
2248 st->fLinksActive[i] = kTRUE;
2249 st->fTrackletDecode[i] = kTRUE;
2250 st->fHCDecode[i] = kTRUE;
2251 st->fActiveLinks++;
2252 }
2253 else
2254 {
2255 st->fTrackletDecode[i] = kFALSE;
2256 st->fLinksActive[i] = kFALSE;
2257 st->fHCDecode[i] = kFALSE;
2258 }
2259 }
2260}
2261
2262//--------------------------------------------------------
2263const char *AliTRDrawStreamTB::DumpStackInfo(const struct AliTRDrawStack *st)
2264{
2265 //
2266 // format the string with the stack info
2267 //
2268 return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
2269 *st->fPos,
2270 st->fHeaderSize,
2271 st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
2272 st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
2273 st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
2274}
2275
2276//--------------------------------------------------------
2277void AliTRDrawStreamTB::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
2278{
2279 //
2280 // decode the hc header word 0
2281 //
2282
2283 // do it once here
2284 UInt_t vword = *word;
2285
2286 hc->fCorrupted = HC_HEADER_MASK_ERR(vword);
2287 if (hc->fCorrupted > 0)
2288 {
2289 hc->fH0ErrorCounter++;
2290 }
2291
2292 hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
2293 hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
dc25a859 2294 hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword);
d4232bb6 2295 hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
2296 hc->fNExtraWords = HC_EXTRA_WORDS(vword);
2297 hc->fDCSboard = HC_DCS_BOARD(vword);
2298 hc->fSM = HC_SM_NUMBER(vword);
2299 hc->fStack = HC_STACK_NUMBER(vword);
2300 hc->fLayer = HC_LAYER_NUMBER(vword);
2301 hc->fSide = HC_SIDE_NUMBER(vword);
2302
2303 hc->fPos[0] = (UInt_t*)word;
2304
2305}
2306
2307//--------------------------------------------------------
2308void AliTRDrawStreamTB::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
2309{
2310 //
2311 //
2312 //
2313
2314 // do it once here
2315 UInt_t vword = *word;
2316
7e8f4d17 2317 hc->fCorrupted += 2 * HC_HEADER_MASK_ERR(vword);
2318 if (hc->fCorrupted >= 2)
d4232bb6 2319 {
2320 hc->fH1ErrorCounter++;
2321 }
2322
2323 hc->fTimeBins = HC_NTIMEBINS(vword);
2324 hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
2325 hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
2326 hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
2327
2328 hc->fPos[1] = (UInt_t*)word;
2329}
2330
2331//--------------------------------------------------------
2332const char *AliTRDrawStreamTB::DumpHCinfoH0(const struct AliTRDrawHC *hc)
2333{
2334 //
2335 //
2336 //
2337 if (!hc)
2338 return Form("Unable to dump. Null received as parameter!?!");
2339 else
2340 return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
2341 hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
2342}
2343
2344//--------------------------------------------------------
2345const char *AliTRDrawStreamTB::DumpHCinfoH1(const struct AliTRDrawHC *hc)
2346{
2347 //
2348 //
2349 //
2350 if (!hc)
2351 return Form("Unable to dump. Null received as parameter!?!");
2352 else
2353 return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
2354 hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
2355}
2356
2357//--------------------------------------------------------
2358void AliTRDrawStreamTB::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2359{
2360 //
2361 // decode the mcm header
2362 //
2363
d4232bb6 2364 UInt_t vword = *word;
2365
bb1009bf 2366 if (vword == END_OF_TRACKLET_MARKERNEW)
6bd744d3 2367 {
bb1009bf 2368 if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
2369 mcm->fCorrupted += 16;
2370 fHC->fCorrupted += 16; //to finish data reading of this HC
6bd744d3 2371 }
bb1009bf 2372 mcm->fCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error, set mcm->fCorrupted = 1
d4232bb6 2373 if (mcm->fCorrupted)
2374 mcm->fErrorCounter++;
2375 mcm->fROB = MCM_ROB_NUMBER(vword);
2376 mcm->fMCM = MCM_MCM_NUMBER(vword);
2377 mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
d4232bb6 2378 mcm->fPos = (UInt_t*)word;
2379}
2380
2381//--------------------------------------------------------
2382UInt_t AliTRDrawStreamTB::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2383{
2384 //
2385 // get the adc mask
2386 //
2387
d4232bb6 2388 UInt_t vword = *word;
2389
bb1009bf 2390 mcm->fADCindex = 0;
2391 mcm->fADCmax = 0;
2392 mcm->fADCMask = 0;
2393 mcm->fADCcount = 0;
d4232bb6 2394 mcm->fADCMaskWord = vword;
bb1009bf 2395
2396 if (vword == END_OF_TRACKLET_MARKERNEW)
2397 {
2398 if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
2399 mcm->fCorrupted += 16;
2400 fHC->fCorrupted += 16; //to finish data reading of this HC
2401 }
2402
d4232bb6 2403 if ( MCM_ADCMASK_MASK_ERR(vword) == 0 )
2404 {
bb1009bf 2405 mcm->fADCMask = MCM_ADCMASK_VAL(vword);
2406 mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
d4232bb6 2407 }
2408 else
2409 {
2410 mcm->fADCMask = 0xffffffff;
2e2bc4a1 2411 mcm->fCorrupted += 4;
d4232bb6 2412 mcm->fMaskErrorCounter++;
2413 }
2414
2415 return mcm->fADCMask;
2416}
2417
2418//--------------------------------------------------------
2419void AliTRDrawStreamTB::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
2420{
2421 //
2422 // decode the adc mask - adcs to be read out
2423 //
2424
2425 mcm->fMCMADCWords = 0;
2426 mcm->fSingleADCwords = 0;
2427 mcm->fADCmax = 0;
2428 mcm->fADCMask = GetMCMadcMask(word, mcm);
bb1009bf 2429
d4232bb6 2430 if (mcm->fADCMask > 0)
2431 {
2432 for (Int_t i = 0; i < TRD_MAX_ADC; i++)
2433 {
2434 mcm->fADCchannel[mcm->fADCmax] = 0;
2435 if( IS_BIT_SET(mcm->fADCMask,i) )
2436 {
2437 mcm->fADCchannel[mcm->fADCmax] = i;
2438 mcm->fADCmax++;
2439 }
2440 }
2441 }
bb1009bf 2442 if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) // backward compatibility
2443 {
2444 mcm->fCorrupted += 8;
2445 }
d4232bb6 2446}
2447
2448//--------------------------------------------------------
2449void AliTRDrawStreamTB::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
2450{
2451 //
2452 // count the expected mcm words for a given tbins
2453 //
2454 mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
2455 mcm->fSingleADCwords = 0;
2456 if (mcm->fADCmax > 0)
2457 {
2458 mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
2459 }
2460}
2461
dc25a859 2462//--------------------------------------------------------
bb1009bf 2463const unsigned long AliTRDrawStreamTB::AdvancePseudoRandom(unsigned long *val) const
dc25a859 2464{
2465 //
2466 // pseudo random number generator for test pattern data
2467 //
2468 unsigned long currentVal = *val;
2469
2470 *val = ( (*val << 1) | (((*val >> 9) ^ (*val >> 6)) & 1) ) & 0x3FF;
2471 return currentVal;
2472}
2473
d4232bb6 2474//--------------------------------------------------------
2475const char *AliTRDrawStreamTB::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
2476{
2477 //
2478 // mcm info in a string
2479 //
2480 if (!mcm)
2481 return Form("Unable to dump. Null received as parameter!?!");
2482 else
2483 return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
2484}
2485
2486//--------------------------------------------------------
2487//TString DumpMCMadcMask(const struct AliTRDrawMCMInfo *mcm)
2488const char *AliTRDrawStreamTB::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
2489{
2490 //
2491 // mcm adc mask in a string
2492 //
2493 if (!mcm)
2494 return Form("Unable to dump. Null received as parameter!?!");
2495
2496 TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
2497 for (Int_t i = 0; i < 21; i++)
2498 {
2499 tsreturn += Form("%d ", mcm->fADCchannel[i]);
2500 }
2501 tsreturn += "";
2502 return tsreturn.Data();
2503}