]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDrawStream.cxx
- update AliTRDtrackletMCM to carry 3 labels and assign them in AliTRDmcmSim
[u/mrichter/AliRoot.git] / TRD / AliTRDrawStream.cxx
CommitLineData
0508ca31 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16////////////////////////////////////////////////////////////////////////////
17// //
18// Decoding data from the TRD raw stream //
19// and translation into ADC values //
20// //
21// Author: J. Klein (jochen.klein@cern.ch) //
22// //
23////////////////////////////////////////////////////////////////////////////
24
92223bf6 25#include <cstdio>
26#include <cstdarg>
27
d60fe037 28#include "TClonesArray.h"
29#include "TTree.h"
30
31#include "AliLog.h"
32#include "AliRawReader.h"
33#include "AliTRDdigitsManager.h"
34#include "AliTRDdigitsParam.h"
35#include "AliTRDtrapConfig.h"
36#include "AliTRDarrayADC.h"
37#include "AliTRDarrayDictionary.h"
38#include "AliTRDSignalIndex.h"
39#include "AliTRDtrackletWord.h"
cc26f39c 40#include "AliTreeLoader.h"
d60fe037 41
42#include "AliTRDrawStream.h"
43
44// temporary
45#include "AliRunLoader.h"
46
47ClassImp(AliTRDrawStream)
48
49// some static information
50const Int_t AliTRDrawStream::fgkMcmOrder[] = {12, 13, 14, 15,
cc26f39c 51 8, 9, 10, 11,
52 4, 5, 6, 7,
53 0, 1, 2, 3};
d60fe037 54const Int_t AliTRDrawStream::fgkRobOrder [] = {0, 1, 2, 3};
55const Int_t AliTRDrawStream::fgkNlinks = 12;
56const Int_t AliTRDrawStream::fgkNstacks = 5;
57const UInt_t AliTRDrawStream::fgkDataEndmarker = 0x00000000;
58const UInt_t AliTRDrawStream::fgkTrackletEndmarker = 0x10001000;
59
cc26f39c 60const char* AliTRDrawStream::fgErrorMessages[] = {
d60fe037 61 "Unknown error",
62 "Link monitor active",
63 "Pretrigger counter mismatch",
64 "not a TRD equipment (1024-1041)",
65 "Invalid Stack header",
66 "Invalid detector number",
67 "No digits could be retrieved from the digitsmanager",
68 "HC header mismatch",
69 "HC check bits wrong",
70 "Unexpected position in readout stream",
71 "Invalid testpattern mode",
72 "Testpattern mismatch",
73 "Number of timebins changed",
74 "ADC mask inconsistent",
75 "ADC check bits invalid",
76 "Missing ADC data",
77 "Missing expected ADC channels",
78 "Missing MCM headers"
79};
80
92223bf6 81const Int_t AliTRDrawStream::fgErrorDebugLevel[] = {
82 0,
83 0,
84 2,
85 1,
86 0,
87 1,
88 1,
89 1,
90 1,
91 2,
92 1,
93 1,
94 1,
95 1,
96 2,
97 1,
98 1,
99 1
100};
101
102AliTRDrawStream::ErrorBehav_t AliTRDrawStream::fgErrorBehav[] = {
103 AliTRDrawStream::kTolerate,
104 AliTRDrawStream::kDiscardHC,
105 AliTRDrawStream::kTolerate,
106 AliTRDrawStream::kAbort,
107 AliTRDrawStream::kAbort,
108 AliTRDrawStream::kAbort,
109 AliTRDrawStream::kAbort,
110 AliTRDrawStream::kDiscardHC,
111 AliTRDrawStream::kDiscardHC,
112 AliTRDrawStream::kTolerate,
113 AliTRDrawStream::kTolerate,
114 AliTRDrawStream::kTolerate,
115 AliTRDrawStream::kTolerate,
116 AliTRDrawStream::kTolerate,
117 AliTRDrawStream::kTolerate,
118 AliTRDrawStream::kTolerate,
119 AliTRDrawStream::kTolerate,
120 AliTRDrawStream::kTolerate
121};
122
d60fe037 123AliTRDrawStream::AliTRDrawStream(AliRawReader *rawReader) :
cc26f39c 124 fStats(),
f4b3235e 125 fStoreError(&AliTRDrawStream::StoreErrorTree),
d60fe037 126 fRawReader(rawReader),
127 fDigitsManager(0x0),
128 fDigitsParam(0x0),
129 fErrors(0x0),
130 fLastError(),
92223bf6 131 fErrorFlags(0),
d60fe037 132 fPayloadStart(0x0),
133 fPayloadCurr(0x0),
134 fPayloadSize(0),
135 fNtimebins(-1),
136 fLastEvId(-1),
137 fCurrSlot(-1),
138 fCurrLink(-1),
139 fCurrRobPos(-1),
140 fCurrMcmPos(-1),
141 fCurrEquipmentId(0),
142 fCurrSmuIndexHeaderSize(0),
143 fCurrSmuIndexHeaderVersion(0),
144 fCurrTrackEnable(0),
145 fCurrTrackletEnable(0),
146 fCurrStackMask(0),
147 fCurrStackIndexWord(0x0),
148 fCurrStackHeaderSize(0x0),
149 fCurrStackHeaderVersion(0x0),
150 fCurrLinkMask(0x0),
151 fCurrCleanCheckout(0x0),
152 fCurrBoardId(0x0),
153 fCurrHwRev(0x0),
154 fCurrLinkMonitorFlags(0x0),
155 fCurrLinkDataTypeFlags(0x0),
156 fCurrLinkDebugFlags(0x0),
157 fCurrSpecial(-1),
158 fCurrMajor(-1),
159 fCurrMinor(-1),
160 fCurrAddHcWords(-1),
161 fCurrSm(-1),
162 fCurrStack(-1),
163 fCurrLayer(-1),
164 fCurrSide(-1),
165 fCurrHC(-1),
166 fCurrCheck(-1),
167 fCurrNtimebins(-1),
168 fCurrBC(-1),
169 fCurrPtrgCnt(-1),
170 fCurrPtrgPhase(-1),
cc26f39c 171 fNDumpMCMs(0),
d60fe037 172 fTrackletArray(0x0),
173 fAdcArray(0x0),
174 fSignalIndex(0x0),
175 fTrackletTree(0x0)
176{
177 // default constructor
178
179 fCurrStackIndexWord = new UInt_t[fgkNstacks];
180 fCurrStackHeaderSize = new UInt_t[fgkNstacks];
181 fCurrStackHeaderVersion = new UInt_t[fgkNstacks];
182 fCurrLinkMask = new UInt_t[fgkNstacks];
183 fCurrCleanCheckout = new UInt_t[fgkNstacks];
184 fCurrBoardId = new UInt_t[fgkNstacks];
185 fCurrHwRev = new UInt_t[fgkNstacks];
186 fCurrLinkMonitorFlags = new UInt_t[fgkNstacks * fgkNlinks];
187 fCurrLinkDataTypeFlags = new UInt_t[fgkNstacks * fgkNlinks];
188 fCurrLinkDebugFlags = new UInt_t[fgkNstacks * fgkNlinks];
189
190 // preparing TClonesArray
191 fTrackletArray = new TClonesArray("AliTRDtrackletWord", 256);
192
193 // setting up the error tree
194 fErrors = new TTree("errorStats", "Error statistics");
195 fErrors->SetDirectory(0x0);
196 fErrors->Branch("error", &fLastError, "sector/I:stack:link:error:rob:mcm");
197 fErrors->SetCircular(1000);
198}
199
200AliTRDrawStream::~AliTRDrawStream()
201{
202 // destructor
203
204 delete fErrors;
205
206 delete [] fCurrStackIndexWord;
207 delete [] fCurrStackHeaderSize;
208 delete [] fCurrStackHeaderVersion;
209 delete [] fCurrLinkMask;
210 delete [] fCurrCleanCheckout;
211 delete [] fCurrBoardId;
212 delete [] fCurrHwRev;
213 delete [] fCurrLinkMonitorFlags;
214 delete [] fCurrLinkDataTypeFlags;
215 delete [] fCurrLinkDebugFlags;
216}
217
218Bool_t AliTRDrawStream::ReadEvent(TTree *trackletTree)
219{
220 // read the current event from the raw reader and fill it to the digits manager
221
222 if (!fRawReader) {
223 AliError("No raw reader available");
224 return kFALSE;
225 }
226
227 // tracklet output
67271412 228 ConnectTracklets(trackletTree);
d60fe037 229
230 // some preparations
231 fDigitsParam = 0x0;
232
233 // loop over all DDLs
234 // data starts with GTU payload, i.e. SMU index word
235 UChar_t *buffer = 0x0;
236
237 while (fRawReader->ReadNextData(buffer)) {
238
239 fCurrEquipmentId = fRawReader->GetEquipmentId();
240 AliDebug(2, Form("equipment: %i", fCurrEquipmentId));
241
242 if (fCurrEquipmentId < 1024 || fCurrEquipmentId > 1041) {
92223bf6 243 EquipmentError(kNonTrdEq, "Skipping");
d60fe037 244 continue;
245 }
246
247 // setting the pointer to data and current reading position
248 fPayloadCurr = fPayloadStart = (UInt_t*) (buffer);
249 fPayloadSize = fRawReader->GetDataSize() / sizeof(UInt_t);
cc26f39c 250 fStats.fStatsSector[fCurrEquipmentId - 1024].fBytes = fRawReader->GetDataSize();
d60fe037 251 AliDebug(2, Form("Read buffer of size: %i", fRawReader->GetDataSize()));
252
253 // read SMU index header
254 if (ReadSmHeader() < 0) {
255 AliError(Form("Reading SMU header failed, skipping this DDL %i", fCurrEquipmentId));
256 continue;
257 }
258
259 // read stack index header
260 for (Int_t iStack = 0; iStack < 5; iStack++) {
67271412 261 if ((fCurrStackMask & (1 << iStack)) != 0)
d60fe037 262 ReadStackIndexHeader(iStack);
263 }
264
265 for (Int_t iStack = 0; iStack < 5; iStack++) {
266 fCurrSlot = iStack;
67271412 267 if ((fCurrStackMask & (1 << fCurrSlot)) == 0)
d60fe037 268 continue;
269
270 AliDebug(2, Form("Stack %i, Link mask: 0x%02x", fCurrSlot, fCurrLinkMask[fCurrSlot]));
271 for (Int_t iLink = 0; iLink < 12; iLink++) {
272 fCurrLink = iLink;
273 fCurrHC = fCurrSm * 60 + fCurrSlot * 12 + iLink;
274 if ((fCurrLinkMask[fCurrSlot] & (1 << fCurrLink)) == 0)
275 continue;
276
92223bf6 277 fErrorFlags = 0;
278 // check for link monitor error flag
d60fe037 279 if (fCurrLinkMonitorFlags[fCurrSlot*fgkNlinks + fCurrLink] != 0)
280 LinkError(kLinkMonitor);
d60fe037 281
282 // read the data from one HC
283 ReadLinkData();
284
285 // read all data endmarkers
92223bf6 286 SeekNextLink();
d60fe037 287 }
288 }
289 }
290 return kTRUE;
291}
292
293
294Bool_t AliTRDrawStream::NextDDL()
295{
0508ca31 296 // continue reading with the next equipment
297
d60fe037 298 if (!fRawReader)
299 return kFALSE;
300
301 fCurrEquipmentId = 0;
302 fCurrSlot = 0;
303 fCurrLink = 0;
304
305 UChar_t *buffer = 0x0;
306
307 while (fRawReader->ReadNextData(buffer)) {
308
309 fCurrEquipmentId = fRawReader->GetEquipmentId();
310 AliDebug(2, Form("equipment: %i", fCurrEquipmentId));
311
312 if (fCurrEquipmentId < 1024 || fCurrEquipmentId > 1041) {
92223bf6 313 EquipmentError(kNonTrdEq, "Skipping");
d60fe037 314 continue;
315 }
316
317 // setting the pointer to data and current reading position
318 fPayloadCurr = fPayloadStart = (UInt_t*) (buffer);
319 fPayloadSize = fRawReader->GetDataSize() / sizeof(UInt_t);
320 AliDebug(2, Form("Read buffer of size: %i", fRawReader->GetDataSize()));
321
322 // read SMU index header
323 if (ReadSmHeader() < 0) {
324 AliError(Form("Reading SMU header failed, skipping this DDL %i", fCurrEquipmentId));
325 continue;
326 }
327
328 // read stack index header
329 for (Int_t iStack = 0; iStack < 5; iStack++) {
67271412 330 if ((fCurrStackMask & (1 << iStack)) != 0) {
d60fe037 331 ReadStackIndexHeader(iStack);
332 }
333 }
334 return kTRUE;
335 }
336
337 return kFALSE;
338}
339
340
341Int_t AliTRDrawStream::NextChamber(AliTRDdigitsManager *digMgr, UInt_t ** /* trackletContainer */, UShort_t ** /* errorContainer */)
342{
0508ca31 343 // read the data for the next chamber
344 // in case you only want to read the data of a single chamber
345 // to read all data ReadEvent(...) is recommended
346
d60fe037 347 fDigitsManager = digMgr;
348 fDigitsParam = 0x0;
349
92223bf6 350 fErrorFlags = 0;
351
d60fe037 352 // tracklet output preparation
67271412 353 TTree *trklTree = 0x0;
354 AliRunLoader *rl = AliRunLoader::Instance();
44ac5cbf 355 AliLoader* trdLoader = rl ? rl->GetLoader("TRDLoader") : NULL;
356 AliDataLoader *trklLoader = trdLoader ? trdLoader->GetDataLoader("tracklets") : NULL;
357 if (trklLoader) {
cc26f39c 358 AliTreeLoader *trklTreeLoader = (AliTreeLoader*) trklLoader->GetBaseLoader("tracklets-raw");
359 if (trklTreeLoader)
360 trklTree = trklTreeLoader->Tree();
361 else
362 trklTree = trklLoader->Tree();
67271412 363 }
364
365 if (fTrackletTree != trklTree)
366 ConnectTracklets(trklTree);
d60fe037 367
368 if (!fRawReader) {
369 AliError("No raw reader available");
370 return -1;
371 }
372
373 if (fCurrSlot < 0 || fCurrSlot >= 5) {
374 if (!NextDDL()) {
375 fCurrSlot = -1;
376 return -1;
377 }
378 }
379
380 AliDebug(2, Form("Stack %i, Link %i, mask: 0x%02x", fCurrSlot, fCurrLink, fCurrLinkMask[fCurrSlot]));
381 fCurrHC = (fCurrEquipmentId - 1024) * 60 + fCurrSlot * 12 + fCurrLink;
382
383 if (fCurrLinkMonitorFlags[fCurrSlot*fgkNlinks + fCurrLink] != 0)
384 LinkError(kLinkMonitor);
385
386 // read the data from one HC
387 ReadLinkData();
388
389 // read all data endmarkers
92223bf6 390 SeekNextLink();
d60fe037 391
392 if (fCurrLink % 2 == 0) {
393 // if we just read the A-side HC then also check the B-side
394 fCurrLink++;
1e7466b5 395 fCurrHC++;
d60fe037 396 if (fCurrLinkMask[fCurrSlot] & (1 << fCurrLink)) {
397 ReadLinkData();
92223bf6 398 SeekNextLink();
d60fe037 399 }
400 }
401
402 //??? to check
403 do {
404 fCurrLink++;
405 if (fCurrLink > 11) {
406 fCurrLink = 0;
407 fCurrSlot++;
408 }
409 } while ((fCurrSlot < 5) &&
67271412 410 (((fCurrStackMask & (1 << fCurrSlot)) == 0) ||
411 ((fCurrLinkMask[fCurrSlot] & (1 << fCurrLink))) == 0));
d60fe037 412
25671e69 413 // return chamber information from HC if it is valid
414 // otherwise return information from link position
415 if (fCurrSm < 0 || fCurrSm > 17 || fCurrStack < 0 || fCurrStack > 4 || fCurrLayer < 0 || fCurrLayer > 5)
416 return ((fCurrEquipmentId-1024) + fCurrSlot * 6 + fCurrLink/2);
417 else
418 return (fCurrSm * 30 + fCurrStack * 6 + fCurrLayer);
d60fe037 419}
420
421
422Int_t AliTRDrawStream::ReadSmHeader()
423{
424 // read the SMU index header at the current reading position
425 // and store the information in the corresponding variables
426
427 if (fPayloadCurr - fPayloadStart >= fPayloadSize - 1) {
92223bf6 428 EquipmentError(kUnknown, "SM Header incomplete");
d60fe037 429 return -1;
430 }
431
432 fCurrSmuIndexHeaderSize = ((*fPayloadCurr) >> 16) & 0xffff;
433 fCurrSmuIndexHeaderVersion = ((*fPayloadCurr) >> 12) & 0xf;
434 fCurrTrackEnable = ((*fPayloadCurr) >> 6) & 0x1;
435 fCurrTrackletEnable = ((*fPayloadCurr) >> 5) & 0x1;
436 fCurrStackMask = ((*fPayloadCurr) ) & 0x1f;
437
438 AliDebug(5, Form("SMU header: size: %i, version: %i, track enable: %i, tracklet enable: %i, stack mask: %2x",
439 fCurrSmuIndexHeaderSize,
440 fCurrSmuIndexHeaderVersion,
441 fCurrTrackEnable,
442 fCurrTrackletEnable,
443 fCurrStackMask));
444
445 fPayloadCurr += fCurrSmuIndexHeaderSize + 1;
446
447 return fCurrSmuIndexHeaderSize + 1;
448}
449
450Int_t AliTRDrawStream::ReadStackIndexHeader(Int_t stack)
451{
452 // read the stack index header
453 // and store the information in the corresponding variables
454
455 fCurrStackIndexWord[stack] = *fPayloadCurr;
456 fCurrStackHeaderSize[stack] = (((*fPayloadCurr) >> 16) & 0xffff) + 1;
457 fCurrStackHeaderVersion[stack] = ((*fPayloadCurr) >> 12) & 0xf;
458 fCurrLinkMask[stack] = (*fPayloadCurr) & 0xfff;
459
67271412 460 if (fPayloadCurr - fPayloadStart >= fPayloadSize - (Int_t) fCurrStackHeaderSize[stack]) {
92223bf6 461 StackError(kStackHeaderInvalid, "Stack index header aborted");
d60fe037 462 return -1;
463 }
464
465 switch (fCurrStackHeaderVersion[stack]) {
466 case 0xa:
467 if (fCurrStackHeaderSize[stack] < 8) {
92223bf6 468 StackError(kStackHeaderInvalid, "Stack header smaller than expected!");
d60fe037 469 return -1;
470 }
471
472 fCurrCleanCheckout[stack] = fPayloadCurr[1] & 0x1;
473 fCurrBoardId[stack] = (fPayloadCurr[1] >> 8) & 0xff;
474 fCurrHwRev[stack] = (fPayloadCurr[1] >> 16) & 0xffff;
475
476 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
477 // A side
478 fCurrLinkMonitorFlags [stack*fgkNlinks + iLayer*2] = fPayloadCurr[iLayer+2] & 0xf;
479 fCurrLinkDataTypeFlags [stack*fgkNlinks + iLayer*2] = (fPayloadCurr[iLayer+2] >> 4) & 0x3;
480 fCurrLinkDebugFlags [stack*fgkNlinks + iLayer*2] = (fPayloadCurr[iLayer+2] >> 12) & 0xf;
481 // B side
482 fCurrLinkMonitorFlags [stack*fgkNlinks + iLayer*2 + 1] = (fPayloadCurr[iLayer+2] >> 16) & 0xf;
483 fCurrLinkDataTypeFlags [stack*fgkNlinks + iLayer*2 + 1] = (fPayloadCurr[iLayer+2] >> 20) & 0x3;
484 fCurrLinkDebugFlags [stack*fgkNlinks + iLayer*2 + 1] = (fPayloadCurr[iLayer+2] >> 28) & 0xf;
485 }
486 break;
487
488 default:
92223bf6 489 StackError(kStackHeaderInvalid, "Invalid Stack Index Header version %x", fCurrStackHeaderVersion[stack]);
d60fe037 490 }
491
492 fPayloadCurr += fCurrStackHeaderSize[stack];
493
494 return fCurrStackHeaderSize[stack];
495}
496
497Int_t AliTRDrawStream::ReadLinkData()
498{
499 // read the data in one link (one HC) until the data endmarker is reached
cc26f39c 500 // returns the number of words read!
d60fe037 501
502 Int_t count = 0;
cc26f39c 503 UInt_t* startPosLink = fPayloadCurr;
504
505// printf("----- HC: %i -----\n", fCurrHC);
506// for (Int_t i = 0; i < 3; i++) {
507// printf("0x%08x 0x%08x 0x%08x 0x%08x\n",
508// fPayloadCurr[i*4+0], fPayloadCurr[i*4+1], fPayloadCurr[i*4+2], fPayloadCurr[i*4+3]);
509// }
d60fe037 510
92223bf6 511 if (fErrorFlags & kDiscardHC)
512 return count;
513
d60fe037 514 count += ReadTracklets();
92223bf6 515 if (fErrorFlags & kDiscardHC)
516 return count;
d60fe037 517
518 count += ReadHcHeader();
92223bf6 519 if (fErrorFlags & kDiscardHC)
520 return count;
d60fe037 521
522 Int_t det = fCurrSm * 30 + fCurrStack * 6 + fCurrLayer;
523
524 if (det > -1 && det < 540) {
525
526 if ((fAdcArray = fDigitsManager->GetDigits(det))) {
527 //fAdcArray->Expand();
528 if (fAdcArray->GetNtime() != fCurrNtimebins)
529 fAdcArray->Allocate(16, 144, fCurrNtimebins);
530 }
531 else {
92223bf6 532 LinkError(kNoDigits);
d60fe037 533 }
534
535 if (!fDigitsParam) {
536 fDigitsParam = fDigitsManager->GetDigitsParam();
537 }
538 if (fDigitsParam) {
539 fDigitsParam->SetPretriggerPhase(det, fCurrPtrgPhase);
540 fDigitsParam->SetNTimeBins(det, fCurrNtimebins);
541 fDigitsParam->SetADCbaseline(det, 10);
542 }
543
544 if (fDigitsManager->UsesDictionaries()) {
545 fDigitsManager->GetDictionary(det, 0)->Reset();
546 fDigitsManager->GetDictionary(det, 1)->Reset();
547 fDigitsManager->GetDictionary(det, 2)->Reset();
548 }
549
550 if ((fSignalIndex = fDigitsManager->GetIndexes(det))) {
551 fSignalIndex->SetSM(fCurrSm);
552 fSignalIndex->SetStack(fCurrStack);
553 fSignalIndex->SetLayer(fCurrLayer);
554 fSignalIndex->SetDetNumber(det);
555 if (!fSignalIndex->IsAllocated())
556 fSignalIndex->Allocate(16, 144, fCurrNtimebins);
557 }
558
559 // ----- check which kind of data -----
560 if (fCurrMajor & 0x40) {
561 if ((fCurrMajor & 0x7) == 0x7) {
562 AliDebug(1, "This is a config event");
563 UInt_t *startPos = fPayloadCurr;
564 while (fPayloadCurr - fPayloadStart < fPayloadSize &&
565 *fPayloadCurr != fgkDataEndmarker)
566 fPayloadCurr++;
567 count += fPayloadCurr - startPos;
568
569 // feeding TRAP config
570 AliTRDtrapConfig *trapcfg = AliTRDtrapConfig::Instance();
0508ca31 571 trapcfg->ReadPackedConfig(fCurrHC, startPos, fPayloadCurr - startPos);
d60fe037 572 }
573 else {
574 Int_t tpmode = fCurrMajor & 0x7;
575 AliDebug(1, Form("Checking testpattern (mode %i) data", tpmode));
576 ReadTPData(tpmode);
577 }
578 }
579 else if (fCurrMajor & 0x20) {
580 AliDebug(1, "This is a zs event");
581 count += ReadZSData();
582 }
583 else {
584 AliDebug(1, "This is a nozs event");
585 count += ReadNonZSData();
586 }
587 }
588 else {
92223bf6 589 LinkError(kInvalidDetector, "%i", det);
d60fe037 590 while (fPayloadCurr - fPayloadStart < fPayloadSize &&
591 *fPayloadCurr != fgkDataEndmarker)
592 fPayloadCurr++;
d60fe037 593 }
594
cc26f39c 595 fStats.fStatsSector[fCurrSm].fStatsHC[fCurrHC%60].fBytes += (fPayloadCurr - startPosLink) * sizeof(UInt_t);
596 fStats.fStatsSector[fCurrSm].fStatsHC[fCurrHC%60].fBytesRead += count * sizeof(UInt_t);
597 fStats.fStatsSector[fCurrSm].fBytesRead += count * sizeof(UInt_t);
598 fStats.fBytesRead += count * sizeof(UInt_t);
599
d60fe037 600 return count;
601}
602
603Int_t AliTRDrawStream::ReadTracklets()
604{
605 // read the tracklets from one HC
606
607 fTrackletArray->Clear();
608
609 UInt_t *start = fPayloadCurr;
610 while (*(fPayloadCurr) != fgkTrackletEndmarker &&
611 fPayloadCurr - fPayloadStart < fPayloadSize) {
612
613 new ((*fTrackletArray)[fTrackletArray->GetEntriesFast()]) AliTRDtrackletWord(*(fPayloadCurr));
614
615 fPayloadCurr++;
616 }
617
618 if (fTrackletArray->GetEntriesFast() > 0) {
619 AliDebug(1, Form("Found %i tracklets in %i %i %i (ev. %i)", fTrackletArray->GetEntriesFast(),
620 fCurrSm, fCurrSlot, fCurrLink, fRawReader->GetEventIndex()));
cc26f39c 621 fStats.fStatsSector[fCurrSm].fStatsHC[fCurrHC%60].fNTracklets += fTrackletArray->GetEntriesFast();
622 fStats.fStatsSector[fCurrSm].fNTracklets += fTrackletArray->GetEntriesFast();
d60fe037 623 if (fTrackletTree)
624 fTrackletTree->Fill();
625 }
626
627 // loop over remaining tracklet endmarkers
628 while ((*(fPayloadCurr) == fgkTrackletEndmarker &&
629 fPayloadCurr - fPayloadStart < fPayloadSize))
630 fPayloadCurr++;
631
cc26f39c 632 return fPayloadCurr - start;
d60fe037 633}
634
635Int_t AliTRDrawStream::ReadHcHeader()
636{
637 // read and parse the HC header of one HC
638 // and store the information in the corresponding variables
639
640 UInt_t *start = fPayloadCurr;
641 // check not to be at the data endmarker
642 if (*fPayloadCurr == fgkDataEndmarker)
643 return 0;
644
645 fCurrSpecial = (*fPayloadCurr >> 31) & 0x1;
646 fCurrMajor = (*fPayloadCurr >> 24) & 0x7f;
647 fCurrMinor = (*fPayloadCurr >> 17) & 0x7f;
648 fCurrAddHcWords = (*fPayloadCurr >> 14) & 0x7;
649 fCurrSm = (*fPayloadCurr >> 9) & 0x1f;
650 fCurrLayer = (*fPayloadCurr >> 6) & 0x7;
651 fCurrStack = (*fPayloadCurr >> 3) & 0x7;
652 fCurrSide = (*fPayloadCurr >> 2) & 0x1;
653 fCurrCheck = (*fPayloadCurr) & 0x3;
654
0508ca31 655 if (fCurrSm != (((Int_t) fCurrEquipmentId) - 1024) ||
d60fe037 656 fCurrStack != fCurrSlot ||
657 fCurrLayer != fCurrLink / 2 ||
658 fCurrSide != fCurrLink % 2) {
92223bf6 659 LinkError(kHCmismatch,
660 "HC: %i, %i, %i, %i\n 0x%08x 0x%08x 0x%08x 0x%08x",
661 fCurrSm, fCurrStack, fCurrLayer, fCurrSide,
662 fPayloadCurr[0], fPayloadCurr[1], fPayloadCurr[2], fPayloadCurr[3]);;
d60fe037 663 }
664 if (fCurrCheck != 0x1) {
92223bf6 665 LinkError(kHCcheckFailed);
d60fe037 666 }
667
668 if (fCurrAddHcWords > 0) {
669 fCurrNtimebins = (fPayloadCurr[1] >> 26) & 0x3f;
670 fCurrBC = (fPayloadCurr[1] >> 10) & 0xffff;
671 fCurrPtrgCnt = (fPayloadCurr[1] >> 6) & 0xf;
672 fCurrPtrgPhase = (fPayloadCurr[1] >> 2) & 0xf;
673 }
674
675 fPayloadCurr += 1 + fCurrAddHcWords;
676
677 return (fPayloadCurr - start) / sizeof(UInt_t);
678}
679
680Int_t AliTRDrawStream::ReadTPData(Int_t mode)
681{
682 // testing of testpattern 1 to 3 (hardcoded), 0 missing
683 // evcnt checking missing
684 Int_t cpu = 0;
685 Int_t cpufromchannel[] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3};
686 Int_t evcnt = 0;
687 Int_t count = 0;
688 Int_t mcmcount = -1;
689 Int_t wordcount = 0;
690 Int_t channelcount = 0;
691 UInt_t expword = 0;
692 UInt_t expadcval = 0;
693 UInt_t diff = 0;
694 Int_t lastmcmpos = -1;
695 Int_t lastrobpos = -1;
696
697 UInt_t* start = fPayloadCurr;
698
699 while (*(fPayloadCurr) != fgkDataEndmarker &&
700 fPayloadCurr - fPayloadStart < fPayloadSize - 1) {
701
702 // ----- Checking MCM Header -----
703 AliDebug(2, Form("MCM header: 0x%08x", *fPayloadCurr));
704 mcmcount++;
705
706 // ----- checking for proper readout order - ROB -----
707 if (GetROBReadoutPos(ROB(*fPayloadCurr) / 2) >= lastrobpos) {
708 lastrobpos = GetROBReadoutPos(ROB(*fPayloadCurr) / 2);
709 }
710 else {
92223bf6 711 ROBError(kPosUnexp);
d60fe037 712 }
713 fCurrRobPos = ROB(*fPayloadCurr);
714
715 // ----- checking for proper readout order - MCM -----
716 if (GetMCMReadoutPos(MCM(*fPayloadCurr)) >= (lastmcmpos + 1) % 16) {
717 lastmcmpos = GetMCMReadoutPos(MCM(*fPayloadCurr));
718 }
719 else {
92223bf6 720 MCMError(kPosUnexp);
d60fe037 721 }
722 fCurrMcmPos = MCM(*fPayloadCurr);
723
724
725 fPayloadCurr++;
726
727 evcnt = 0x3f & *fPayloadCurr >> 26;
728 cpu = -1;
729 channelcount = 0;
730 while (channelcount < 21) {
731 count = 0;
732 if (cpu != cpufromchannel[channelcount]) {
733 cpu = cpufromchannel[channelcount];
734 expadcval = (1 << 9) | (fCurrRobPos << 6) | (fCurrMcmPos << 2) | cpu;
735 wordcount = 0;
736 }
737
738 while (count < 10) {
739 if (channelcount % 2 == 0)
740 expword = 0x3;
741 else
742 expword = 0x2;
743
744 if (mode == 1) {
745 // ----- TP 1 -----
746 expword |= expadcval << 2;
747 expadcval = ( (expadcval << 1) | ( ( (expadcval >> 9) ^ (expadcval >> 6) ) & 1) ) & 0x3FF;
748 expword |= expadcval << 12;
749 expadcval = ( (expadcval << 1) | ( ( (expadcval >> 9) ^ (expadcval >> 6) ) & 1) ) & 0x3FF;
750 expword |= expadcval << 22;
751 expadcval = ( (expadcval << 1) | ( ( (expadcval >> 9) ^ (expadcval >> 6) ) & 1) ) & 0x3FF;
752 }
753 else if (mode == 2) {
754 // ----- TP 2 ------
755 expword = ((0x3f & evcnt) << 26) | ((fCurrSm + 1) << 21) | ((fCurrLayer + 1) << 18) |
756 ((fCurrStack + 1) << 15) |
757 (fCurrRobPos << 12) | (fCurrMcmPos << 8) | (cpu << 6) | (wordcount + 1);
758 }
759 else if (mode == 3) {
760 // ----- TP 3 -----
761 expword = ((0xfff & evcnt) << 20) | (fCurrSm << 15) | (fCurrLink/2 << 12) | (fCurrStack << 9) |
762 (fCurrRobPos << 6) | (fCurrMcmPos << 2) | (cpu << 0);
763 }
764 else {
765 expword = 0;
92223bf6 766 LinkError(kTPmodeInvalid, "Just reading");
d60fe037 767 }
768
769 diff = *fPayloadCurr ^ expword;
770 if (diff != 0) {
92223bf6 771 MCMError(kTPmismatch,
772 "Seen 0x%08x, expected 0x%08x, diff: 0x%08x (0x%02x)",
773 *fPayloadCurr, expword, diff, 0xff & (diff | diff >> 8 | diff >> 16 | diff >> 24));;
d60fe037 774 }
775 fPayloadCurr++;
776 count++;
777 wordcount++;
778 }
779 channelcount++;
780 }
781 // continue with next MCM
782 }
783 return fPayloadCurr - start;
784}
785
786
787Int_t AliTRDrawStream::ReadZSData()
788{
789 // read the zs data from one link from the current reading position
790
791 UInt_t *start = fPayloadCurr;
792
793 Int_t mcmcount = 0;
0508ca31 794 Int_t mcmcountExp = fCurrStack == 2 ? 48 : 64;
d60fe037 795 Int_t channelcount = 0;
0508ca31 796 Int_t channelcountExp = 0;
797 Int_t channelcountMax = 0;
d60fe037 798 Int_t timebins;
799 Int_t currentTimebin = 0;
800 Int_t adcwc = 0;
801 Int_t evno = -1;
802 Int_t lastmcmpos = -1;
803 Int_t lastrobpos = -1;
804
805 if (fCurrNtimebins != fNtimebins) {
806 if (fNtimebins > 0)
92223bf6 807 LinkError(kNtimebinsChanged,
808 "No. of timebins changed from %i to %i", fNtimebins, fCurrNtimebins);
d60fe037 809 fNtimebins = fCurrNtimebins;
810 }
811
812 timebins = fNtimebins;
813
814 while (*(fPayloadCurr) != fgkDataEndmarker &&
815 fPayloadCurr - fPayloadStart < fPayloadSize) {
816
817 // ----- Checking MCM Header -----
818 AliDebug(2, Form("MCM header: 0x%08x", *fPayloadCurr));
cc26f39c 819 UInt_t *startPosMCM = fPayloadCurr;
d60fe037 820
821 // ----- checking for proper readout order - ROB -----
822 if (GetROBReadoutPos(ROB(*fPayloadCurr) / 2) >= lastrobpos) {
823 lastrobpos = GetROBReadoutPos(ROB(*fPayloadCurr) / 2);
824 }
825 else {
92223bf6 826 ROBError(kPosUnexp);
d60fe037 827 }
828 fCurrRobPos = ROB(*fPayloadCurr);
829
830 // ----- checking for proper readout order - MCM -----
831 if (GetMCMReadoutPos(MCM(*fPayloadCurr)) > lastmcmpos) {
832 lastmcmpos = GetMCMReadoutPos(lastmcmpos);
833 }
834 else {
92223bf6 835 MCMError(kPosUnexp);
d60fe037 836 }
837 fCurrMcmPos = MCM(*fPayloadCurr);
838
839 if (EvNo(*fPayloadCurr) != evno) {
840 if (evno == -1)
841 evno = EvNo(*fPayloadCurr);
842 else {
92223bf6 843 MCMError(kPtrgCntMismatch, "%i <-> %i", evno, EvNo(*fPayloadCurr));
d60fe037 844 }
845 }
846 Int_t adccoloff = AdcColOffset(*fPayloadCurr);
847 Int_t padcoloff = PadColOffset(*fPayloadCurr);
848 Int_t row = Row(*fPayloadCurr);
849 fPayloadCurr++;
850
851 // ----- Reading ADC channels -----
852 AliDebug(2, Form("ADC mask: 0x%08x", *fPayloadCurr));
853
854 // ----- analysing the ADC mask -----
855 channelcount = 0;
0508ca31 856 channelcountExp = GetNActiveChannelsFromMask(*fPayloadCurr);
857 channelcountMax = GetNActiveChannels(*fPayloadCurr);
d60fe037 858 Int_t channelmask = GetActiveChannels(*fPayloadCurr);
859 Int_t channelno = -1;
860 fPayloadCurr++;
861
0508ca31 862 if (channelcountExp != channelcountMax) {
863 if (channelcountExp > channelcountMax) {
864 Int_t temp = channelcountExp;
865 channelcountExp = channelcountMax;
866 channelcountMax = temp;
d60fe037 867 }
0508ca31 868 while (channelcountExp < channelcountMax && channelcountExp < 21 &&
869 fPayloadCurr - fPayloadStart < fPayloadSize - 10 * channelcountExp - 1) {
92223bf6 870 MCMError(kAdcMaskInconsistent,
871 "Possible MCM-H: 0x%08x, possible ADC-mask: 0x%08x",
872 *(fPayloadCurr + 10 * channelcountExp),
873 *(fPayloadCurr + 10 * channelcountExp + 1) );
0508ca31 874 if (!CouldBeMCMhdr( *(fPayloadCurr + 10 * channelcountExp)) && !CouldBeADCmask( *(fPayloadCurr + 10 * channelcountExp + 1)))
875 channelcountExp++;
d60fe037 876 else {
877 break;
878 }
879 }
92223bf6 880 MCMError(kAdcMaskInconsistent,
881 "Inconsistency in no. of active channels: Counter: %i, Mask: %i, chosen: %i!",
882 GetNActiveChannels(fPayloadCurr[-1]), GetNActiveChannelsFromMask(fPayloadCurr[-1]), channelcountExp);
d60fe037 883 }
0508ca31 884 AliDebug(2, Form("expecting %i active channels, timebins: %i", channelcountExp, fCurrNtimebins));
d60fe037 885
886 // ----- reading marked ADC channels -----
0508ca31 887 while (channelcount < channelcountExp && *(fPayloadCurr) != fgkDataEndmarker) {
e29e514c 888 if (channelno < 20)
d60fe037 889 channelno++;
e29e514c 890 while (channelno < 20 && (channelmask & 1 << channelno) == 0)
d60fe037 891 channelno++;
892
893 if (fCurrNtimebins > 30) {
894 currentTimebin = ((*fPayloadCurr >> 2) & 0x3f);
895 timebins = ((*fPayloadCurr >> 8) & 0xf) * 3;
896 }
897 else {
898 currentTimebin = 0;
899 }
900
901 adcwc = 0;
902 AliDebug(2, Form("Now looking %i words", timebins / 3));
903 Int_t adccol = adccoloff - channelno;
904 Int_t padcol = padcoloff - channelno;
cc26f39c 905// if (adccol < 3 || adccol > 165)
906// AliInfo(Form("writing channel %i of det %3i %i:%2i to adcrow/-col: %i/%i padcol: %i",
907// channelno, fCurrHC/2, fCurrRobPos, fCurrMcmPos, row, adccol, padcol));
908
d60fe037 909 while (adcwc < timebins / 3 &&
910 *(fPayloadCurr) != fgkDataEndmarker &&
911 fPayloadCurr - fPayloadStart < fPayloadSize) {
912 int check = 0x3 & *fPayloadCurr;
913 if (channelno % 2 != 0) { // odd channel
914 if (check != 0x2 && channelno < 21) {
92223bf6 915 MCMError(kAdcCheckInvalid,
916 "%i for %2i. ADC word in odd channel %i",
917 check, adcwc+1, channelno);
d60fe037 918 }
919 }
920 else { // even channel
921 if (check != 0x3 && channelno < 21) {
92223bf6 922 MCMError(kAdcCheckInvalid,
923 "%i for %2i. ADC word in even channel %i",
924 check, adcwc+1, channelno);
d60fe037 925 }
926 }
927
928 // filling the actual timebin data
929 int tb2 = 0x3ff & *fPayloadCurr >> 22;
930 int tb1 = 0x3ff & *fPayloadCurr >> 12;
931 int tb0 = 0x3ff & *fPayloadCurr >> 2;
932 if (adcwc != 0 || fCurrNtimebins <= 30)
933 fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb0);
934 else
935 tb0 = -1;
936 fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb1);
937 fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb2);
938
939 adcwc++;
940 fPayloadCurr++;
941 }
942
943 if (adcwc != timebins / 3)
92223bf6 944 MCMError(kAdcDataAbort);
d60fe037 945
946 // adding index
947 if (padcol > 0 && padcol < 144) {
948 fSignalIndex->AddIndexRC(row, padcol);
949 }
950
951 channelcount++;
952 }
cc26f39c 953
954 fStats.fStatsSector[fCurrSm].fStatsHC[fCurrHC%60].fNChannels += channelcount;
955 fStats.fStatsSector[fCurrSm].fNChannels += channelcount;
0508ca31 956 if (channelcount != channelcountExp)
92223bf6 957 MCMError(kAdcChannelsMiss);
d60fe037 958
959 mcmcount++;
cc26f39c 960 fStats.fStatsSector[fCurrSm].fStatsHC[fCurrHC%60].fNMCMs++;
961 fStats.fStatsSector[fCurrSm].fNMCMs++;
962
963 if (IsDumping() && DumpingMCM(fCurrHC/2, fCurrRobPos, fCurrMcmPos)) {
92223bf6 964 DumpRaw(Form("Event %i: Det %3i ROB %i MCM %2i", fRawReader->GetEventIndex(), fCurrHC/2, fCurrRobPos, fCurrMcmPos),
cc26f39c 965 startPosMCM, fPayloadCurr - startPosMCM);
966 }
967
d60fe037 968 // continue with next MCM
969 }
970
971 // check for missing MCMs (if header suppression is inactive)
67271412 972 if (((fCurrMajor & 0x1) == 0) && (mcmcount != mcmcountExp)) {
92223bf6 973 LinkError(kMissMcmHeaders,
974 "No. of MCM headers %i not as expected: %i",
975 mcmcount, mcmcountExp);
d60fe037 976 }
977
978 return (fPayloadCurr - start);
979}
980
981Int_t AliTRDrawStream::ReadNonZSData()
982{
983 // read the non-zs data from one link from the current reading position
984
985 UInt_t *start = fPayloadCurr;
986
987 Int_t mcmcount = 0;
0508ca31 988 Int_t mcmcountExp = fCurrStack == 2 ? 48 : 64;
d60fe037 989 Int_t channelcount = 0;
0508ca31 990 Int_t channelcountExp = 0;
d60fe037 991 Int_t timebins;
992 Int_t currentTimebin = 0;
993 Int_t adcwc = 0;
994 Int_t evno = -1;
995 Int_t lastmcmpos = -1;
996 Int_t lastrobpos = -1;
997
998 if (fCurrNtimebins != fNtimebins) {
999 if (fNtimebins > 0)
92223bf6 1000 LinkError(kNtimebinsChanged,
1001 "No. of timebins changed from %i to %i", fNtimebins, fCurrNtimebins);
d60fe037 1002 fNtimebins = fCurrNtimebins;
1003 }
1004
1005 timebins = fNtimebins;
1006
1007 while (*(fPayloadCurr) != fgkDataEndmarker &&
1008 fPayloadCurr - fPayloadStart < fPayloadSize - 2) {
1009
1010 // ----- Checking MCM Header -----
1011 AliDebug(2, Form("MCM header: 0x%08x", *fPayloadCurr));
1012
1013 // ----- checking for proper readout order - ROB -----
1014 if (GetROBReadoutPos(ROB(*fPayloadCurr) / 2) >= lastrobpos) {
1015 lastrobpos = GetROBReadoutPos(ROB(*fPayloadCurr) / 2);
1016 }
1017 else {
92223bf6 1018 ROBError(kPosUnexp);
d60fe037 1019 }
1020 fCurrRobPos = ROB(*fPayloadCurr);
1021
1022 // ----- checking for proper readout order - MCM -----
1023 if (GetMCMReadoutPos(MCM(*fPayloadCurr)) >= (lastmcmpos + 1) % 16) {
1024 lastmcmpos = GetMCMReadoutPos(*fPayloadCurr);
1025 }
1026 else {
92223bf6 1027 MCMError(kPosUnexp);
d60fe037 1028 }
1029 fCurrMcmPos = MCM(*fPayloadCurr);
1030
1031 if (EvNo(*fPayloadCurr) != evno) {
1032 if (evno == -1)
1033 evno = EvNo(*fPayloadCurr);
1034 else {
92223bf6 1035 MCMError(kPtrgCntMismatch, "%i <-> %i", evno, EvNo(*fPayloadCurr));
d60fe037 1036 }
1037 }
1038
1039 channelcount = 0;
0508ca31 1040 channelcountExp = 21;
d60fe037 1041 int channelno = -1;
1042
1043 Int_t adccoloff = AdcColOffset(*fPayloadCurr);
1044 Int_t padcoloff = PadColOffset(*fPayloadCurr);
1045 Int_t row = Row(*fPayloadCurr);
1046
1047 fPayloadCurr++;
1048
1049 // ----- reading marked ADC channels -----
0508ca31 1050 while (channelcount < channelcountExp &&
d60fe037 1051 *(fPayloadCurr) != fgkDataEndmarker) {
e29e514c 1052 if (channelno < 20)
d60fe037 1053 channelno++;
1054
1055 currentTimebin = 0;
1056
1057 adcwc = 0;
1058 AliDebug(2, Form("Now looking %i words", timebins / 3));
1059 Int_t adccol = adccoloff - channelno;
1060 Int_t padcol = padcoloff - channelno;
1061 while (adcwc < timebins / 3 &&
1062 *(fPayloadCurr) != fgkDataEndmarker &&
1063 fPayloadCurr - fPayloadStart < fPayloadSize) {
1064 int check = 0x3 & *fPayloadCurr;
1065 if (channelno % 2 != 0) { // odd channel
1066 if (check != 0x2 && channelno < 21) {
92223bf6 1067 MCMError(kAdcCheckInvalid,
1068 "%i for %2i. ADC word in odd channel %i",
1069 check, adcwc+1, channelno);
d60fe037 1070 }
1071 }
1072 else { // even channel
1073 if (check != 0x3 && channelno < 21) {
92223bf6 1074 MCMError(kAdcCheckInvalid,
1075 "%i for %2i. ADC word in even channel %i",
1076 check, adcwc+1, channelno);
d60fe037 1077 }
1078 }
1079
1080 // filling the actual timebin data
1081 int tb2 = 0x3ff & *fPayloadCurr >> 22;
1082 int tb1 = 0x3ff & *fPayloadCurr >> 12;
1083 int tb0 = 0x3ff & *fPayloadCurr >> 2;
1084 if (adcwc != 0 || fCurrNtimebins <= 30)
1085 fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb0);
1086 else
1087 tb0 = -1;
1088 fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb1);
1089 fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb2);
1090
1091 adcwc++;
1092 fPayloadCurr++;
1093 }
1094
1095 if (adcwc != timebins / 3)
92223bf6 1096 MCMError(kAdcDataAbort);
d60fe037 1097
1098 // adding index
1099 if (padcol > 0 && padcol < 144) {
1100 fSignalIndex->AddIndexRC(row, padcol);
1101 }
1102
1103 channelcount++;
1104 }
1105
0508ca31 1106 if (channelcount != channelcountExp)
92223bf6 1107 MCMError(kAdcChannelsMiss);
d60fe037 1108 mcmcount++;
1109 // continue with next MCM
1110 }
1111
1112 // check for missing MCMs (if header suppression is inactive)
0508ca31 1113 if (mcmcount != mcmcountExp) {
92223bf6 1114 LinkError(kMissMcmHeaders,
1115 "%i not as expected: %i", mcmcount, mcmcountExp);
d60fe037 1116 }
1117
1118 return (fPayloadCurr - start);
1119}
1120
92223bf6 1121Int_t AliTRDrawStream::SeekNextLink()
1122{
1123 UInt_t *start = fPayloadCurr;
1124
1125 // read until data endmarkers
1126 while (fPayloadCurr - fPayloadStart < fPayloadSize &&
1127 *fPayloadCurr != fgkDataEndmarker)
1128 fPayloadCurr++;
1129
1130 // read all data endmarkers
1131 while (fPayloadCurr - fPayloadStart < fPayloadSize &&
1132 *fPayloadCurr == fgkDataEndmarker)
1133 fPayloadCurr++;
1134
1135 return (fPayloadCurr - start);
1136}
1137
67271412 1138Bool_t AliTRDrawStream::ConnectTracklets(TTree *trklTree)
1139{
1140 fTrackletTree = trklTree;
1141 if (!fTrackletTree)
1142 return kTRUE;
1143
cc26f39c 1144 if (!fTrackletTree->GetBranch("hc"))
67271412 1145 fTrackletTree->Branch("hc", &fCurrHC, "hc/I");
cc26f39c 1146 else
67271412 1147 fTrackletTree->SetBranchAddress("hc", &fCurrHC);
cc26f39c 1148
1149 if (!fTrackletTree->GetBranch("trkl"))
1150 fTrackletTree->Branch("trkl", &fTrackletArray);
1151 else
67271412 1152 fTrackletTree->SetBranchAddress("trkl", &fTrackletArray);
cc26f39c 1153
67271412 1154 return kTRUE;
1155}
1156
1157
1d62be37 1158void AliTRDrawStream::EquipmentError(ErrorCode_t err, const char *const msg, ...)
d60fe037 1159{
0508ca31 1160 // register error according to error code on equipment level
1161 // and return the corresponding error message
1162
d60fe037 1163 fLastError.fSector = fCurrEquipmentId - 1024;
1164 fLastError.fStack = -1;
1165 fLastError.fLink = -1;
1166 fLastError.fRob = -1;
1167 fLastError.fMcm = -1;
1168 fLastError.fError = err;
f4b3235e 1169 (this->*fStoreError)();
d60fe037 1170
92223bf6 1171 va_list ap;
1172 if (fgErrorDebugLevel[err] > 10)
1173 AliDebug(fgErrorDebugLevel[err],
1174 Form("Event %6i: Eq. %2d - %s : %s",
1175 fRawReader->GetEventIndex(), fCurrEquipmentId, fgErrorMessages[err],
1d62be37 1176 (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
92223bf6 1177 else
1178 AliError(Form("Event %6i: Eq. %2d - %s : %s",
1179 fRawReader->GetEventIndex(), fCurrEquipmentId, fgErrorMessages[err],
1d62be37 1180 (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
92223bf6 1181 fErrorFlags |= fgErrorBehav[err];
d60fe037 1182}
1183
1184
1d62be37 1185void AliTRDrawStream::StackError(ErrorCode_t err, const char *const msg, ...)
d60fe037 1186{
0508ca31 1187 // register error according to error code on stack level
1188 // and return the corresponding error message
1189
d60fe037 1190 fLastError.fSector = fCurrEquipmentId - 1024;
1191 fLastError.fStack = fCurrSlot;
1192 fLastError.fLink = -1;
1193 fLastError.fRob = -1;
1194 fLastError.fMcm = -1;
1195 fLastError.fError = err;
f4b3235e 1196 (this->*fStoreError)();
d60fe037 1197
92223bf6 1198 va_list ap;
e29e514c 1199 if (fgErrorDebugLevel[err] > 0)
92223bf6 1200 AliDebug(fgErrorDebugLevel[err],
1201 Form("Event %6i: Eq. %2d S %i - %s : %s",
1202 fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fgErrorMessages[err],
1d62be37 1203 (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
92223bf6 1204 else
1205 AliError(Form("Event %6i: Eq. %2d S %i - %s : %s",
1206 fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fgErrorMessages[err],
1d62be37 1207 (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
92223bf6 1208 fErrorFlags |= fgErrorBehav[err];
d60fe037 1209}
1210
1211
1d62be37 1212void AliTRDrawStream::LinkError(ErrorCode_t err, const char *const msg, ...)
d60fe037 1213{
0508ca31 1214 // register error according to error code on link level
1215 // and return the corresponding error message
1216
d60fe037 1217 fLastError.fSector = fCurrEquipmentId - 1024;
1218 fLastError.fStack = fCurrSlot;
1219 fLastError.fLink = fCurrLink;
1220 fLastError.fRob = -1;
1221 fLastError.fMcm = -1;
1222 fLastError.fError = err;
f4b3235e 1223 (this->*fStoreError)();
d60fe037 1224
92223bf6 1225 va_list ap;
e29e514c 1226 if (fgErrorDebugLevel[err] > 0)
92223bf6 1227 AliDebug(fgErrorDebugLevel[err],
1228 Form("Event %6i: Eq. %2d S %i l %2i - %s : %s",
1229 fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fgErrorMessages[err],
1d62be37 1230 (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
92223bf6 1231 else
1232 AliError(Form("Event %6i: Eq. %2d S %i l %2i - %s : %s",
1233 fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fgErrorMessages[err],
1d62be37 1234 (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
92223bf6 1235 fErrorFlags |= fgErrorBehav[err];
d60fe037 1236}
1237
1238
1d62be37 1239void AliTRDrawStream::ROBError(ErrorCode_t err, const char *const msg, ...)
d60fe037 1240{
0508ca31 1241 // register error according to error code on ROB level
1242 // and return the corresponding error message
1243
d60fe037 1244 fLastError.fSector = fCurrEquipmentId - 1024;
1245 fLastError.fStack = fCurrSlot;
1246 fLastError.fLink = fCurrLink;
1247 fLastError.fRob = fCurrRobPos;
1248 fLastError.fMcm = -1;
1249 fLastError.fError = err;
f4b3235e 1250 (this->*fStoreError)();
d60fe037 1251
92223bf6 1252 va_list ap;
e29e514c 1253 if (fgErrorDebugLevel[err] > 0)
92223bf6 1254 AliDebug(fgErrorDebugLevel[err],
1255 Form("Event %6i: Eq. %2d S %i l %2i ROB %i - %s : %s",
1256 fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fCurrRobPos, fgErrorMessages[err],
1d62be37 1257 (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
92223bf6 1258 else
1259 AliError(Form("Event %6i: Eq. %2d S %i l %2i ROB %i - %s : %s",
1260 fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fCurrRobPos, fgErrorMessages[err],
1d62be37 1261 (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
92223bf6 1262 fErrorFlags |= fgErrorBehav[err];
d60fe037 1263}
1264
1265
1d62be37 1266void AliTRDrawStream::MCMError(ErrorCode_t err, const char *const msg, ...)
d60fe037 1267{
0508ca31 1268 // register error according to error code on MCM level
1269 // and return the corresponding error message
1270
d60fe037 1271 fLastError.fSector = fCurrEquipmentId - 1024;
1272 fLastError.fStack = fCurrSlot;
1273 fLastError.fLink = fCurrLink;
1274 fLastError.fRob = fCurrRobPos;
1275 fLastError.fMcm = fCurrMcmPos;
1276 fLastError.fError = err;
f4b3235e 1277 (this->*fStoreError)();
d60fe037 1278
92223bf6 1279 va_list ap;
e29e514c 1280 if (fgErrorDebugLevel[err] > 0)
92223bf6 1281 AliDebug(fgErrorDebugLevel[err],
1282 Form("Event %6i: Eq. %2d S %i l %2i ROB %i MCM %2i - %s : %s",
1283 fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fCurrRobPos, fCurrMcmPos, fgErrorMessages[err],
1d62be37 1284 (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
92223bf6 1285 else
1286 AliError(Form("Event %6i: Eq. %2d S %i l %2i ROB %i MCM %2i - %s : %s",
1287 fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fCurrRobPos, fCurrMcmPos, fgErrorMessages[err],
1d62be37 1288 (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
92223bf6 1289 fErrorFlags |= fgErrorBehav[err];
d60fe037 1290}
1291
1292const char* AliTRDrawStream::GetErrorMessage(ErrorCode_t errCode)
1293{
0508ca31 1294 // return the error message for the given error code
1295
d60fe037 1296 if (errCode > 0 && errCode < kLastErrorCode)
1297 return fgErrorMessages[errCode];
1298 else
1299 return "";
1300}
cc26f39c 1301
1302void AliTRDrawStream::AliTRDrawStats::ClearStats()
1303{
1304 // clear statistics (includes clearing sector-wise statistics)
1305
1306 fBytesRead = 0;
1307 for (Int_t iSector = 0; iSector < 18; iSector++) {
1308 fStatsSector[iSector].ClearStats();
1309 }
1310
1311}
1312
1313void AliTRDrawStream::AliTRDrawStats::AliTRDrawStatsSector::ClearStats()
1314{
1315 // clear statistics (includes clearing HC-wise statistics)
1316
1317 fBytes = 0;
1318 fBytesRead = 0;
1319 fNTracklets = 0;
1320 fNMCMs = 0;
1321 fNChannels = 0;
1322
1323 for (Int_t iHC = 0; iHC < 60; iHC++) {
1324 fStatsHC[iHC].ClearStats();
1325 }
1326}
1327
1328void AliTRDrawStream::AliTRDrawStats::AliTRDrawStatsSector::AliTRDrawStatsHC::ClearStats()
1329{
1330 // clear statistics
1331
1332 fBytes = 0;
1333 fBytesRead = 0;
1334 fNTracklets = 0;
1335 fNMCMs = 0;
1336 fNChannels = 0;
1337}
1338
1339void AliTRDrawStream::SetDumpMCM(Int_t det, Int_t rob, Int_t mcm, Bool_t dump)
1340{
1341 // mark MCM for dumping of raw data
1342
1343 if (dump) {
1344 fDumpMCM[fNDumpMCMs++] = (det << 7) | (rob << 4) | mcm;
1345 }
1346 else {
1347 Int_t iMCM;
1348 for (iMCM = 0; iMCM < fNDumpMCMs; iMCM++) {
1349 if (fDumpMCM[iMCM] == ((det << 7) | (rob << 4) | mcm)) {
1350 fNDumpMCMs--;
1351 break;
1352 }
1353 }
1354 for ( ; iMCM < fNDumpMCMs; iMCM++) {
1355 fDumpMCM[iMCM] = fDumpMCM[iMCM+1];
1356 }
1357 }
1358}
1359
1360Bool_t AliTRDrawStream::DumpingMCM(Int_t det, Int_t rob, Int_t mcm)
1361{
1362 // check if MCM data should be dumped
1363
1364 for (Int_t iMCM = 0; iMCM < fNDumpMCMs; iMCM++) {
1365 if (fDumpMCM[iMCM] == ((det << 7) | (rob << 4) | mcm)) {
1366 return kTRUE;
1367 }
1368 }
1369 return kFALSE;
1370}
1371
1372void AliTRDrawStream::DumpRaw(TString title, UInt_t *start, Int_t length)
1373{
1374 // dump raw data
1375
1376 title += "\n";
1377 Int_t pos = 0;
1378 for ( ; pos+3 < length; pos += 4) {
1379 title += Form("0x%08x 0x%08x 0x%08x 0x%08x\n",
1380 start[pos+0], start[pos+1], start[pos+2], start[pos+3]);
1381 }
1382 for ( ; pos < length; pos++) {
1383 title += Form("0x%08x ", start[pos]);
1384 }
1385 AliInfo(title);
1386}
f4b3235e 1387
1388AliTRDrawStream::AliTRDrawStreamError::AliTRDrawStreamError(Int_t error, Int_t sector, Int_t stack, Int_t link, Int_t rob, Int_t mcm) :
1389 fError(error),
1390 fSector(sector),
1391 fStack(stack),
1392 fLink(link),
1393 fRob(rob),
1394 fMcm(mcm)
1395{
1396 // ctor
1397
1398}