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