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