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