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