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