Apparently DAQ changed raw-data filenames conventions. Technical fix, should go also...
[u/mrichter/AliRoot.git] / RAW / AliRawReaderRoot.cxx
CommitLineData
04fa961a 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
bea6b2a4 16/* $Id$ */
17
04fa961a 18///////////////////////////////////////////////////////////////////////////////
bea6b2a4 19///
20/// This is a class for reading raw data from a root file.
21///
22/// The root file is expected to contain a tree of name "RAW" with
23/// a branch of name "rawevent" which contains objects of type
33314186 24/// AliRawVEvent.
bea6b2a4 25///
26/// The file name and the event number are arguments of the constructor
27/// of AliRawReaderRoot.
28///
04fa961a 29///////////////////////////////////////////////////////////////////////////////
30
a197a4ce 31#include <TFile.h>
32#include <TTree.h>
04fa961a 33#include "AliRawReaderRoot.h"
33314186 34#include "AliRawVEvent.h"
f2dc6b20 35#include "AliRawEventHeaderBase.h"
33314186 36#include "AliRawVEquipment.h"
a197a4ce 37#include "AliRawEquipmentHeader.h"
38#include "AliRawData.h"
04fa961a 39
40
41ClassImp(AliRawReaderRoot)
42
6923e953 43AliRawReaderRoot::AliRawReaderRoot() :
44 fFile(NULL),
45 fBranch(NULL),
46 fEventIndex(-1),
47 fEvent(NULL),
33314186 48 fEventHeader(NULL),
6923e953 49 fSubEventIndex(0),
50 fSubEvent(NULL),
51 fEquipmentIndex(0),
52 fEquipment(NULL),
53 fRawData(NULL),
54 fPosition(NULL),
55 fEnd(NULL)
56{
57// default constructor
58
59}
04fa961a 60
dd9a70fe 61AliRawReaderRoot::AliRawReaderRoot(const char* fileName, Int_t eventNumber) :
62 fFile(NULL),
63 fBranch(NULL),
64 fEventIndex(eventNumber),
65 fEvent(NULL),
33314186 66 fEventHeader(NULL),
dd9a70fe 67 fSubEventIndex(0),
68 fSubEvent(NULL),
94d918a7 69 fEquipmentIndex(0),
70 fEquipment(NULL),
dd9a70fe 71 fRawData(NULL),
72 fPosition(NULL),
73 fEnd(NULL)
04fa961a 74{
75// create an object to read digits from the given input file for the
76// event with the given number
77
03c6d9a3 78 TDirectory* dir = gDirectory;
04fa961a 79 fFile = TFile::Open(fileName);
03c6d9a3 80 dir->cd();
04fa961a 81 if (!fFile || !fFile->IsOpen()) {
82 Error("AliRawReaderRoot", "could not open file %s", fileName);
a97af23d 83 fIsValid = kFALSE;
04fa961a 84 return;
85 }
86 TTree* tree = (TTree*) fFile->Get("RAW");
87 if (!tree) {
88 Error("AliRawReaderRoot", "no raw data tree found");
a97af23d 89 fIsValid = kFALSE;
04fa961a 90 return;
91 }
dd9a70fe 92 fBranch = tree->GetBranch("rawevent");
93 if (!fBranch) {
04fa961a 94 Error("AliRawReaderRoot", "no raw data branch found");
a97af23d 95 fIsValid = kFALSE;
04fa961a 96 return;
97 }
98
dd9a70fe 99 fBranch->SetAddress(&fEvent);
100 if (fEventIndex >= 0) {
101 if (fBranch->GetEntry(fEventIndex) <= 0) {
102 Error("AliRawReaderRoot", "no event with number %d found", fEventIndex);
a97af23d 103 fIsValid = kFALSE;
dd9a70fe 104 return;
105 }
33314186 106 fEventHeader = fEvent->GetHeader();
04fa961a 107 }
04fa961a 108}
109
33314186 110AliRawReaderRoot::AliRawReaderRoot(AliRawVEvent* event) :
dd9a70fe 111 fFile(NULL),
112 fBranch(NULL),
113 fEventIndex(-1),
114 fEvent(event),
33314186 115 fEventHeader(event->GetHeader()),
dd9a70fe 116 fSubEventIndex(0),
117 fSubEvent(NULL),
94d918a7 118 fEquipmentIndex(0),
119 fEquipment(NULL),
dd9a70fe 120 fRawData(NULL),
121 fPosition(NULL),
122 fEnd(NULL)
04fa961a 123{
124// create an object to read digits from the given raw event
a97af23d 125 if (!fEvent) fIsValid = kFALSE;
04fa961a 126}
127
42d20574 128AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
dd9a70fe 129 AliRawReader(rawReader),
130 fFile(NULL),
131 fBranch(NULL),
132 fEventIndex(rawReader.fEventIndex),
133 fEvent(NULL),
33314186 134 fEventHeader(NULL),
dd9a70fe 135 fSubEventIndex(rawReader.fSubEventIndex),
136 fSubEvent(NULL),
94d918a7 137 fEquipmentIndex(rawReader.fEquipmentIndex),
138 fEquipment(NULL),
dd9a70fe 139 fRawData(NULL),
140 fPosition(NULL),
141 fEnd(NULL)
42d20574 142{
143// copy constructor
144
dd9a70fe 145 if (rawReader.fFile) {
146 TDirectory* dir = gDirectory;
147 fFile = TFile::Open(rawReader.fFile->GetName());
148 dir->cd();
149 if (!fFile || !fFile->IsOpen()) {
150 Error("AliRawReaderRoot", "could not open file %s",
151 rawReader.fFile->GetName());
a97af23d 152 fIsValid = kFALSE;
dd9a70fe 153 return;
154 }
155 TTree* tree = (TTree*) fFile->Get("RAW");
156 if (!tree) {
157 Error("AliRawReaderRoot", "no raw data tree found");
a97af23d 158 fIsValid = kFALSE;
dd9a70fe 159 return;
160 }
161 fBranch = tree->GetBranch("rawevent");
162 if (!fBranch) {
163 Error("AliRawReaderRoot", "no raw data branch found");
a97af23d 164 fIsValid = kFALSE;
dd9a70fe 165 return;
166 }
167
dd9a70fe 168 fBranch->SetAddress(&fEvent);
169 if (fEventIndex >= 0) {
170 if (fBranch->GetEntry(fEventIndex) <= 0) {
171 Error("AliRawReaderRoot", "no event with number %d found",
172 fEventIndex);
a97af23d 173 fIsValid = kFALSE;
dd9a70fe 174 return;
175 }
33314186 176 fEventHeader = fEvent->GetHeader();
dd9a70fe 177 }
178 } else {
179 fEvent = rawReader.fEvent;
33314186 180 fEventHeader = rawReader.fEventHeader;
dd9a70fe 181 }
182
183 if (fSubEventIndex > 0) {
184 fSubEvent = fEvent->GetSubEvent(fSubEventIndex-1);
94d918a7 185 fEquipment = fSubEvent->GetEquipment(fEquipmentIndex);
186 fRawData = fEquipment->GetRawData();
dd9a70fe 187 fCount = 0;
188 fHeader = (AliRawDataHeader*) ((UChar_t*) fRawData->GetBuffer() +
189 ((UChar_t*) rawReader.fHeader -
190 (UChar_t*) rawReader.fRawData->GetBuffer()));
191 fPosition = (UChar_t*) fRawData->GetBuffer() +
192 (rawReader.fPosition - (UChar_t*) rawReader.fRawData->GetBuffer());
193 fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
194 }
42d20574 195}
196
197AliRawReaderRoot& AliRawReaderRoot::operator = (const AliRawReaderRoot&
198 rawReader)
199{
200// assignment operator
201
202 this->~AliRawReaderRoot();
203 new(this) AliRawReaderRoot(rawReader);
204 return *this;
205}
206
04fa961a 207AliRawReaderRoot::~AliRawReaderRoot()
208{
209// delete objects and close root file
210
211 if (fFile) {
212 if (fEvent) delete fEvent;
213 fFile->Close();
214 delete fFile;
215 }
216}
217
1fb5b4a8 218const AliRawEventHeaderBase* AliRawReaderRoot::GetEventHeader() const
219{
220 // Get the even header
221 // Return NULL in case of failure
33314186 222 return fEventHeader;
1fb5b4a8 223}
04fa961a 224
42d20574 225UInt_t AliRawReaderRoot::GetType() const
04fa961a 226{
227// get the type from the event header
228
33314186 229 if (!fEventHeader) return 0;
230 return fEventHeader->Get("Type");
04fa961a 231}
232
42d20574 233UInt_t AliRawReaderRoot::GetRunNumber() const
04fa961a 234{
235// get the run number from the event header
236
33314186 237 if (!fEventHeader) return 0;
238 return fEventHeader->Get("RunNb");
04fa961a 239}
240
42d20574 241const UInt_t* AliRawReaderRoot::GetEventId() const
04fa961a 242{
243// get the event id from the event header
244
33314186 245 if (!fEventHeader) return NULL;
246 return fEventHeader->GetP("Id");
04fa961a 247}
248
42d20574 249const UInt_t* AliRawReaderRoot::GetTriggerPattern() const
04fa961a 250{
251// get the trigger pattern from the event header
252
33314186 253 if (!fEventHeader) return NULL;
254 return fEventHeader->GetP("TriggerPattern");
04fa961a 255}
256
42d20574 257const UInt_t* AliRawReaderRoot::GetDetectorPattern() const
04fa961a 258{
259// get the detector pattern from the event header
260
33314186 261 if (!fEventHeader) return NULL;
262 return fEventHeader->GetP("DetectorPattern");
04fa961a 263}
264
42d20574 265const UInt_t* AliRawReaderRoot::GetAttributes() const
04fa961a 266{
267// get the type attributes from the event header
268
33314186 269 if (!fEventHeader) return NULL;
270 return fEventHeader->GetP("TypeAttribute");
04fa961a 271}
272
e94ad92c 273const UInt_t* AliRawReaderRoot::GetSubEventAttributes() const
274{
275// get the type attributes from the sub event header
276
277 if (!fSubEvent) return NULL;
f2dc6b20 278 return fSubEvent->GetHeader()->GetP("TypeAttribute");
e94ad92c 279}
280
c946ab02 281UInt_t AliRawReaderRoot::GetLDCId() const
282{
283// get the LDC Id from the event header
284
94d918a7 285 if (!fEvent || !fSubEvent) return 0;
f2dc6b20 286 return fSubEvent->GetHeader()->Get("LdcId");
c946ab02 287}
288
42d20574 289UInt_t AliRawReaderRoot::GetGDCId() const
04fa961a 290{
291// get the GDC Id from the event header
292
33314186 293 if (!fEventHeader) return 0;
294 return fEventHeader->Get("GdcId");
04fa961a 295}
296
741c154c 297UInt_t AliRawReaderRoot::GetTimestamp() const
298{
33314186 299 if (!fEventHeader) return 0;
300 return fEventHeader->Get("Timestamp");
741c154c 301}
04fa961a 302
c946ab02 303Int_t AliRawReaderRoot::GetEquipmentSize() const
304{
305// get the size of the equipment
306
94d918a7 307 if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return 0;
308 return fEquipment->GetEquipmentHeader()->GetEquipmentSize();
c946ab02 309}
310
311Int_t AliRawReaderRoot::GetEquipmentType() const
312{
313// get the type from the equipment header
314
94d918a7 315 if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return -1;
316 return fEquipment->GetEquipmentHeader()->GetEquipmentType();
c946ab02 317}
318
319Int_t AliRawReaderRoot::GetEquipmentId() const
320{
321// get the ID from the equipment header
322
94d918a7 323 if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return -1;
324 return fEquipment->GetEquipmentHeader()->GetId();
c946ab02 325}
326
327const UInt_t* AliRawReaderRoot::GetEquipmentAttributes() const
328{
329// get the attributes from the equipment header
330
94d918a7 331 if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return NULL;
332 return fEquipment->GetEquipmentHeader()->GetTypeAttribute();
c946ab02 333}
334
335Int_t AliRawReaderRoot::GetEquipmentElementSize() const
336{
337// get the basic element size from the equipment header
338
94d918a7 339 if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return 0;
340 return fEquipment->GetEquipmentHeader()->GetBasicSizeType();
c946ab02 341}
342
299738b9 343Int_t AliRawReaderRoot::GetEquipmentHeaderSize() const
344{
345// get the size of the equipment header (28 bytes by default)
346
347 if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return 0;
348 return fEquipment->GetEquipmentHeader()->HeaderSize();
349}
350
edd06192 351// _________________________________________________________________________
edd06192 352void AliRawReaderRoot::SwapData(const void* inbuf, const void* outbuf, UInt_t size) {
353 // The method swaps the contents of the
354 // raw-data event header
91f76e9b 355 UInt_t intCount = (size+3)/sizeof(UInt_t);
edd06192 356
357 UInt_t* buf = (UInt_t*) inbuf; // temporary integers buffer
358 for (UInt_t i=0; i<intCount; i++, buf++) {
359 UInt_t value = SwapWord(*buf);
dae3f0d9 360 if (i==(intCount-1))
361 memcpy((UInt_t*)outbuf+i, &value, size%sizeof(UInt_t));
362 else
363 memcpy((UInt_t*)outbuf+i, &value, sizeof(UInt_t));
edd06192 364 }
365}
366// _________________________________________________________________________
c946ab02 367
368Bool_t AliRawReaderRoot::ReadHeader()
04fa961a 369{
39f9963f 370// read a data header at the current position
371// returns kFALSE if the data header could not be read
04fa961a 372
b4857df7 373 fErrorCode = 0;
04fa961a 374 if (!fEvent) return kFALSE;
b4857df7 375
04fa961a 376 do {
b4857df7 377 // skip payload (if event was not selected)
378 if (fCount > 0) fPosition += fCount;
379
94d918a7 380 // get the first or the next equipment if at the end of an equipment
381 if (!fEquipment || (fPosition >= fEnd)) {
b4857df7 382
94d918a7 383 // get the first or the next sub event if at the end of a sub event
384 if (!fSubEvent || (fEquipmentIndex >= fSubEvent->GetNEquipments())) {
b4857df7 385
94d918a7 386 // check for end of event data
387 if (fSubEventIndex >= fEvent->GetNSubEvents()) return kFALSE;
388 fSubEvent = fEvent->GetSubEvent(fSubEventIndex++);
389
390 // check the magic word of the sub event
391 if (!fSubEvent->GetHeader()->IsValid()) {
392 Error("ReadHeader", "wrong magic number in sub event!");
393 fSubEvent->GetHeader()->Dump();
394 fErrorCode = kErrMagic;
395 return kFALSE;
396 }
397
398 fEquipmentIndex = 0;
399 fEquipment = NULL;
400 fRawData = NULL;
b4857df7 401 }
402
94d918a7 403 // get the next equipment and raw data
04fa961a 404 fCount = 0;
f49c01bc 405 if (fEquipmentIndex >= fSubEvent->GetNEquipments()) {
406 fEquipment = NULL;
407 continue;
408 }
94d918a7 409 fEquipment = fSubEvent->GetEquipment(fEquipmentIndex++);
410 if (!fEquipment) continue;
3d65cc80 411 if (!IsSelected()) {
412 fPosition = fEnd;
413 continue;
414 }
94d918a7 415 fRawData = fEquipment->GetRawData();
416 if (!fRawData) {
417 fPosition = fEnd;
418 continue;
419 }
04fa961a 420 fPosition = (UChar_t*) fRawData->GetBuffer();
421 fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
422 }
b4857df7 423
94d918a7 424 // continue with the next equipment if no data left in the payload
b4857df7 425 if (fPosition >= fEnd) continue;
426
18882b3b 427 if (fRequireHeader) {
428 // check that there are enough bytes left for the data header
429 if (fPosition + sizeof(AliRawDataHeader) > fEnd) {
430 Error("ReadHeader", "could not read data header!");
6c12d59f 431 Warning("ReadHeader", "skipping %ld bytes", fEnd - fPosition);
18882b3b 432 fEquipment->GetEquipmentHeader()->Dump();
433 fCount = 0;
434 fPosition = fEnd;
435 fErrorCode = kErrNoDataHeader;
436 continue;
437 }
438
439 // "read" the data header
440 fHeader = (AliRawDataHeader*) fPosition;
edd06192 441#ifndef R__BYTESWAP
442 SwapData((void*) fHeader, (void*) fHeaderSwapped, sizeof(AliRawDataHeader));
443 fHeader=fHeaderSwapped;
444#endif
299738b9 445 if ((fPosition + fHeader->fSize) != fEnd) {
806e573c 446 if (fHeader->fSize != 0xFFFFFFFF)
447 Warning("ReadHeader",
6c12d59f 448 "Equipment %d : raw data size found in the header is wrong (%d != %ld)! Using the equipment size instead !",
806e573c 449 fEquipment->GetEquipmentHeader()->GetId(),fHeader->fSize, fEnd - fPosition);
299738b9 450 fHeader->fSize = fEnd - fPosition;
451 }
18882b3b 452 fPosition += sizeof(AliRawDataHeader);
04fa961a 453 }
b4857df7 454
7c726b91 455 if (fHeader && (fHeader->fSize != 0xFFFFFFFF)) {
39f9963f 456 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
7c726b91 457
458 // check consistency of data size in the header and in the sub event
459 if (fPosition + fCount > fEnd) {
460 Error("ReadHeader", "size in data header exceeds event size!");
6c12d59f 461 Warning("ReadHeader", "skipping %ld bytes", fEnd - fPosition);
7c726b91 462 fEquipment->GetEquipmentHeader()->Dump();
463 fCount = 0;
464 fPosition = fEnd;
465 fErrorCode = kErrSize;
466 continue;
467 }
468
39f9963f 469 } else {
470 fCount = fEnd - fPosition;
72dd1d4f 471 }
b4857df7 472
04fa961a 473 } while (!IsSelected());
b4857df7 474
04fa961a 475 return kTRUE;
476}
477
478Bool_t AliRawReaderRoot::ReadNextData(UChar_t*& data)
479{
480// reads the next payload at the current position
481// returns kFALSE if the data could not be read
482
b4857df7 483 fErrorCode = 0;
04fa961a 484 while (fCount == 0) {
c946ab02 485 if (!ReadHeader()) return kFALSE;
04fa961a 486 }
487 data = fPosition;
488 fPosition += fCount;
489 fCount = 0;
490 return kTRUE;
491}
492
493Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size)
494{
495// reads the next block of data at the current position
496// returns kFALSE if the data could not be read
497
b4857df7 498 fErrorCode = 0;
04fa961a 499 if (fPosition + size > fEnd) {
500 Error("ReadNext", "could not read data!");
b4857df7 501 fErrorCode = kErrOutOfBounds;
04fa961a 502 return kFALSE;
503 }
504 memcpy(data, fPosition, size);
dae3f0d9 505
04fa961a 506 fPosition += size;
507 fCount -= size;
508 return kTRUE;
509}
510
511
512Bool_t AliRawReaderRoot::Reset()
513{
514// reset the current position to the beginning of the event
515
516 fSubEventIndex = 0;
517 fSubEvent = NULL;
94d918a7 518 fEquipmentIndex = 0;
519 fEquipment = NULL;
04fa961a 520 fRawData = NULL;
39f9963f 521 fHeader = NULL;
04fa961a 522
523 fCount = 0;
524 fPosition = fEnd = NULL;
525 return kTRUE;
526}
527
b4857df7 528
dd9a70fe 529Bool_t AliRawReaderRoot::NextEvent()
530{
531// go to the next event in the root file
532
2da4ef20 533 if (!fBranch) return kFALSE;
dd9a70fe 534
535 do {
d41ecdd0 536 delete fEvent;
33314186 537 fEvent = NULL;
538 fEventHeader = NULL;
d41ecdd0 539 fBranch->SetAddress(&fEvent);
540 if (fBranch->GetEntry(fEventIndex+1) <= 0)
dd9a70fe 541 return kFALSE;
33314186 542 fEventHeader = fEvent->GetHeader();
dd9a70fe 543 fEventIndex++;
544 } while (!IsEventSelected());
38cf12f3 545 fEventNumber++;
dd9a70fe 546 return Reset();
547}
548
549Bool_t AliRawReaderRoot::RewindEvents()
550{
551// go back to the beginning of the root file
552
2da4ef20 553 if (!fBranch) return kFALSE;
dd9a70fe 554
555 fEventIndex = -1;
556 delete fEvent;
33314186 557 fEvent = NULL;
558 fEventHeader = NULL;
dd9a70fe 559 fBranch->SetAddress(&fEvent);
38cf12f3 560 fEventNumber = -1;
dd9a70fe 561 return Reset();
562}
563
636c1780 564Bool_t AliRawReaderRoot::GotoEvent(Int_t event)
565{
566 // go to a particular event
567 // Uses the absolute event index inside the
568 // raw-data file
569
570 if (!fBranch) return kFALSE;
571
572 delete fEvent;
33314186 573 fEvent = NULL;
574 fEventHeader = NULL;
636c1780 575 fBranch->SetAddress(&fEvent);
576 if (fBranch->GetEntry(event) <= 0)
577 return kFALSE;
33314186 578 fEventHeader = fEvent->GetHeader();
636c1780 579 fEventIndex = event;
580 fEventNumber++;
581 return Reset();
582}
dd9a70fe 583
25e82ff5 584Int_t AliRawReaderRoot::GetNumberOfEvents() const
585{
586 // Get the total number of events in
587 // the raw-data tree
588
589 if (!fBranch) return -1;
590
591 return fBranch->GetEntries();
592}
593
b4857df7 594Int_t AliRawReaderRoot::CheckData() const
595{
596// check the consistency of the data
597
598 if (!fEvent) return 0;
599
33314186 600 AliRawVEvent* subEvent = NULL;
b4857df7 601 Int_t subEventIndex = 0;
33314186 602 AliRawVEquipment* equipment = NULL;
94d918a7 603 Int_t equipmentIndex = 0;
b4857df7 604 UChar_t* position = 0;
605 UChar_t* end = 0;
be50fca2 606 Int_t result = 0;
b4857df7 607
608 while (kTRUE) {
94d918a7 609 // get the first or the next sub event if at the end of an equipment
610 if (!subEvent || (equipmentIndex >= subEvent->GetNEquipments())) {
b4857df7 611
612 // check for end of event data
be50fca2 613 if (subEventIndex >= fEvent->GetNSubEvents()) return result;
b4857df7 614 subEvent = fEvent->GetSubEvent(subEventIndex++);
615
616 // check the magic word of the sub event
be50fca2 617 if (!fSubEvent->GetHeader()->IsValid()) {
618 result |= kErrMagic;
619 return result;
620 }
b4857df7 621
94d918a7 622 equipmentIndex = 0;
b4857df7 623 }
624
94d918a7 625 // get the next equipment and raw data
f49c01bc 626 if (equipmentIndex >= subEvent->GetNEquipments()) {
627 equipment = NULL;
628 continue;
629 }
94d918a7 630 equipment = subEvent->GetEquipment(equipmentIndex++);
631 if (!equipment) continue;
632 AliRawData* rawData = equipment->GetRawData();
633 if (!rawData) continue;
634 position = (UChar_t*) rawData->GetBuffer();
635 end = ((UChar_t*) rawData->GetBuffer()) + rawData->GetSize();
636
b4857df7 637 // continue with the next sub event if no data left in the payload
638 if (position >= end) continue;
639
18882b3b 640 if (fRequireHeader) {
39f9963f 641 // check that there are enough bytes left for the data header
18882b3b 642 if (position + sizeof(AliRawDataHeader) > end) {
643 result |= kErrNoDataHeader;
644 continue;
645 }
b4857df7 646
18882b3b 647 // check consistency of data size in the header and in the equipment
648 AliRawDataHeader* header = (AliRawDataHeader*) position;
299738b9 649 if ((position + header->fSize) != end) {
806e573c 650 if (header->fSize != 0xFFFFFFFF)
651 Warning("ReadHeader",
6c12d59f 652 "Equipment %d : raw data size found in the header is wrong (%d != %ld)! Using the equipment size instead !",
806e573c 653 equipment->GetEquipmentHeader()->GetId(),header->fSize, end - position);
299738b9 654 header->fSize = end - position;
655 result |= kErrSize;
39f9963f 656 }
be50fca2 657 }
299738b9 658 position = end;
b4857df7 659 };
fd0de2e2 660
661 return result;
b4857df7 662}
b900a426 663
664AliRawReader* AliRawReaderRoot::CloneSingleEvent() const
665{
666 // Clones the current event and
667 // creates raw-reader for the cloned event
668 // Can be used in order to make asynchronious
669 // access to the current raw data within
670 // several threads (online event display/reco)
671
243e7b72 672 if (fEvent) {
b900a426 673 // Root formatted raw data
243e7b72 674 AliRawVEvent *gdcRootEvent = (AliRawVEvent*)fEvent->Clone();
b900a426 675 for (Int_t ldcCounter=0; ldcCounter < gdcRootEvent->GetNSubEvents(); ldcCounter++) {
676 AliRawVEvent *ldcRootEvent = gdcRootEvent->GetSubEvent(ldcCounter);
243e7b72 677 AliRawVEvent *subEvent = fEvent->GetSubEvent(ldcCounter);
b900a426 678 for (Int_t eqCounter=0; eqCounter < ldcRootEvent->GetNEquipments(); eqCounter++) {
679 AliRawVEquipment *equipment=ldcRootEvent->GetEquipment(eqCounter);
243e7b72 680 AliRawVEquipment *eq = subEvent->GetEquipment(eqCounter);
681 equipment->CloneRawData(eq->GetRawData());
b900a426 682 }
683 }
243e7b72 684 // Reset original event and newly
685 // produced one
686 gdcRootEvent->GetSubEvent(-1);
687 fEvent->GetSubEvent(-1);
b900a426 688 return new AliRawReaderRoot(gdcRootEvent);
689 }
690 return NULL;
691}