]>
Commit | Line | Data |
---|---|---|
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 | ||
41 | ClassImp(AliRawReaderRoot) | |
42 | ||
6923e953 | 43 | AliRawReaderRoot::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 | 61 | AliRawReaderRoot::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 | 110 | AliRawReaderRoot::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 | 128 | AliRawReaderRoot::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 | ||
197 | AliRawReaderRoot& 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 | 207 | AliRawReaderRoot::~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 | 218 | const 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 | 225 | UInt_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 | 233 | UInt_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 | 241 | const 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 | 249 | const 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 | 257 | const 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 | 265 | const 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 | 273 | const 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 | 281 | UInt_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 | 289 | UInt_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 | 297 | UInt_t AliRawReaderRoot::GetTimestamp() const |
298 | { | |
33314186 | 299 | if (!fEventHeader) return 0; |
300 | return fEventHeader->Get("Timestamp"); | |
741c154c | 301 | } |
04fa961a | 302 | |
c946ab02 | 303 | Int_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 | ||
311 | Int_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 | ||
319 | Int_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 | ||
327 | const 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 | ||
335 | Int_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 | 343 | Int_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 | 352 | void 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 | |
368 | Bool_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; |
94d918a7 | 405 | fEquipment = fSubEvent->GetEquipment(fEquipmentIndex++); |
406 | if (!fEquipment) continue; | |
3d65cc80 | 407 | if (!IsSelected()) { |
408 | fPosition = fEnd; | |
409 | continue; | |
410 | } | |
94d918a7 | 411 | fRawData = fEquipment->GetRawData(); |
412 | if (!fRawData) { | |
413 | fPosition = fEnd; | |
414 | continue; | |
415 | } | |
04fa961a | 416 | fPosition = (UChar_t*) fRawData->GetBuffer(); |
417 | fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize(); | |
418 | } | |
b4857df7 | 419 | |
94d918a7 | 420 | // continue with the next equipment if no data left in the payload |
b4857df7 | 421 | if (fPosition >= fEnd) continue; |
422 | ||
18882b3b | 423 | if (fRequireHeader) { |
424 | // check that there are enough bytes left for the data header | |
425 | if (fPosition + sizeof(AliRawDataHeader) > fEnd) { | |
426 | Error("ReadHeader", "could not read data header!"); | |
427 | Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition); | |
428 | fEquipment->GetEquipmentHeader()->Dump(); | |
429 | fCount = 0; | |
430 | fPosition = fEnd; | |
431 | fErrorCode = kErrNoDataHeader; | |
432 | continue; | |
433 | } | |
434 | ||
435 | // "read" the data header | |
436 | fHeader = (AliRawDataHeader*) fPosition; | |
edd06192 | 437 | #ifndef R__BYTESWAP |
438 | SwapData((void*) fHeader, (void*) fHeaderSwapped, sizeof(AliRawDataHeader)); | |
439 | fHeader=fHeaderSwapped; | |
440 | #endif | |
299738b9 | 441 | if ((fPosition + fHeader->fSize) != fEnd) { |
806e573c | 442 | if (fHeader->fSize != 0xFFFFFFFF) |
443 | Warning("ReadHeader", | |
444 | "Equipment %d : raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !", | |
445 | fEquipment->GetEquipmentHeader()->GetId(),fHeader->fSize, fEnd - fPosition); | |
299738b9 | 446 | fHeader->fSize = fEnd - fPosition; |
447 | } | |
18882b3b | 448 | fPosition += sizeof(AliRawDataHeader); |
04fa961a | 449 | } |
b4857df7 | 450 | |
7c726b91 | 451 | if (fHeader && (fHeader->fSize != 0xFFFFFFFF)) { |
39f9963f | 452 | fCount = fHeader->fSize - sizeof(AliRawDataHeader); |
7c726b91 | 453 | |
454 | // check consistency of data size in the header and in the sub event | |
455 | if (fPosition + fCount > fEnd) { | |
456 | Error("ReadHeader", "size in data header exceeds event size!"); | |
457 | Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition); | |
458 | fEquipment->GetEquipmentHeader()->Dump(); | |
459 | fCount = 0; | |
460 | fPosition = fEnd; | |
461 | fErrorCode = kErrSize; | |
462 | continue; | |
463 | } | |
464 | ||
39f9963f | 465 | } else { |
466 | fCount = fEnd - fPosition; | |
72dd1d4f | 467 | } |
b4857df7 | 468 | |
04fa961a | 469 | } while (!IsSelected()); |
b4857df7 | 470 | |
04fa961a | 471 | return kTRUE; |
472 | } | |
473 | ||
474 | Bool_t AliRawReaderRoot::ReadNextData(UChar_t*& data) | |
475 | { | |
476 | // reads the next payload at the current position | |
477 | // returns kFALSE if the data could not be read | |
478 | ||
b4857df7 | 479 | fErrorCode = 0; |
04fa961a | 480 | while (fCount == 0) { |
c946ab02 | 481 | if (!ReadHeader()) return kFALSE; |
04fa961a | 482 | } |
483 | data = fPosition; | |
484 | fPosition += fCount; | |
485 | fCount = 0; | |
486 | return kTRUE; | |
487 | } | |
488 | ||
489 | Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size) | |
490 | { | |
491 | // reads the next block of data at the current position | |
492 | // returns kFALSE if the data could not be read | |
493 | ||
b4857df7 | 494 | fErrorCode = 0; |
04fa961a | 495 | if (fPosition + size > fEnd) { |
496 | Error("ReadNext", "could not read data!"); | |
b4857df7 | 497 | fErrorCode = kErrOutOfBounds; |
04fa961a | 498 | return kFALSE; |
499 | } | |
500 | memcpy(data, fPosition, size); | |
dae3f0d9 | 501 | |
04fa961a | 502 | fPosition += size; |
503 | fCount -= size; | |
504 | return kTRUE; | |
505 | } | |
506 | ||
507 | ||
508 | Bool_t AliRawReaderRoot::Reset() | |
509 | { | |
510 | // reset the current position to the beginning of the event | |
511 | ||
512 | fSubEventIndex = 0; | |
513 | fSubEvent = NULL; | |
94d918a7 | 514 | fEquipmentIndex = 0; |
515 | fEquipment = NULL; | |
04fa961a | 516 | fRawData = NULL; |
39f9963f | 517 | fHeader = NULL; |
04fa961a | 518 | |
519 | fCount = 0; | |
520 | fPosition = fEnd = NULL; | |
521 | return kTRUE; | |
522 | } | |
523 | ||
b4857df7 | 524 | |
dd9a70fe | 525 | Bool_t AliRawReaderRoot::NextEvent() |
526 | { | |
527 | // go to the next event in the root file | |
528 | ||
2da4ef20 | 529 | if (!fBranch) return kFALSE; |
dd9a70fe | 530 | |
531 | do { | |
d41ecdd0 | 532 | delete fEvent; |
33314186 | 533 | fEvent = NULL; |
534 | fEventHeader = NULL; | |
d41ecdd0 | 535 | fBranch->SetAddress(&fEvent); |
536 | if (fBranch->GetEntry(fEventIndex+1) <= 0) | |
dd9a70fe | 537 | return kFALSE; |
33314186 | 538 | fEventHeader = fEvent->GetHeader(); |
dd9a70fe | 539 | fEventIndex++; |
540 | } while (!IsEventSelected()); | |
38cf12f3 | 541 | fEventNumber++; |
dd9a70fe | 542 | return Reset(); |
543 | } | |
544 | ||
545 | Bool_t AliRawReaderRoot::RewindEvents() | |
546 | { | |
547 | // go back to the beginning of the root file | |
548 | ||
2da4ef20 | 549 | if (!fBranch) return kFALSE; |
dd9a70fe | 550 | |
551 | fEventIndex = -1; | |
552 | delete fEvent; | |
33314186 | 553 | fEvent = NULL; |
554 | fEventHeader = NULL; | |
dd9a70fe | 555 | fBranch->SetAddress(&fEvent); |
38cf12f3 | 556 | fEventNumber = -1; |
dd9a70fe | 557 | return Reset(); |
558 | } | |
559 | ||
636c1780 | 560 | Bool_t AliRawReaderRoot::GotoEvent(Int_t event) |
561 | { | |
562 | // go to a particular event | |
563 | // Uses the absolute event index inside the | |
564 | // raw-data file | |
565 | ||
566 | if (!fBranch) return kFALSE; | |
567 | ||
568 | delete fEvent; | |
33314186 | 569 | fEvent = NULL; |
570 | fEventHeader = NULL; | |
636c1780 | 571 | fBranch->SetAddress(&fEvent); |
572 | if (fBranch->GetEntry(event) <= 0) | |
573 | return kFALSE; | |
33314186 | 574 | fEventHeader = fEvent->GetHeader(); |
636c1780 | 575 | fEventIndex = event; |
576 | fEventNumber++; | |
577 | return Reset(); | |
578 | } | |
dd9a70fe | 579 | |
25e82ff5 | 580 | Int_t AliRawReaderRoot::GetNumberOfEvents() const |
581 | { | |
582 | // Get the total number of events in | |
583 | // the raw-data tree | |
584 | ||
585 | if (!fBranch) return -1; | |
586 | ||
587 | return fBranch->GetEntries(); | |
588 | } | |
589 | ||
b4857df7 | 590 | Int_t AliRawReaderRoot::CheckData() const |
591 | { | |
592 | // check the consistency of the data | |
593 | ||
594 | if (!fEvent) return 0; | |
595 | ||
33314186 | 596 | AliRawVEvent* subEvent = NULL; |
b4857df7 | 597 | Int_t subEventIndex = 0; |
33314186 | 598 | AliRawVEquipment* equipment = NULL; |
94d918a7 | 599 | Int_t equipmentIndex = 0; |
b4857df7 | 600 | UChar_t* position = 0; |
601 | UChar_t* end = 0; | |
be50fca2 | 602 | Int_t result = 0; |
b4857df7 | 603 | |
604 | while (kTRUE) { | |
94d918a7 | 605 | // get the first or the next sub event if at the end of an equipment |
606 | if (!subEvent || (equipmentIndex >= subEvent->GetNEquipments())) { | |
b4857df7 | 607 | |
608 | // check for end of event data | |
be50fca2 | 609 | if (subEventIndex >= fEvent->GetNSubEvents()) return result; |
b4857df7 | 610 | subEvent = fEvent->GetSubEvent(subEventIndex++); |
611 | ||
612 | // check the magic word of the sub event | |
be50fca2 | 613 | if (!fSubEvent->GetHeader()->IsValid()) { |
614 | result |= kErrMagic; | |
615 | return result; | |
616 | } | |
b4857df7 | 617 | |
94d918a7 | 618 | equipmentIndex = 0; |
b4857df7 | 619 | } |
620 | ||
94d918a7 | 621 | // get the next equipment and raw data |
622 | equipment = subEvent->GetEquipment(equipmentIndex++); | |
623 | if (!equipment) continue; | |
624 | AliRawData* rawData = equipment->GetRawData(); | |
625 | if (!rawData) continue; | |
626 | position = (UChar_t*) rawData->GetBuffer(); | |
627 | end = ((UChar_t*) rawData->GetBuffer()) + rawData->GetSize(); | |
628 | ||
b4857df7 | 629 | // continue with the next sub event if no data left in the payload |
630 | if (position >= end) continue; | |
631 | ||
18882b3b | 632 | if (fRequireHeader) { |
39f9963f | 633 | // check that there are enough bytes left for the data header |
18882b3b | 634 | if (position + sizeof(AliRawDataHeader) > end) { |
635 | result |= kErrNoDataHeader; | |
636 | continue; | |
637 | } | |
b4857df7 | 638 | |
18882b3b | 639 | // check consistency of data size in the header and in the equipment |
640 | AliRawDataHeader* header = (AliRawDataHeader*) position; | |
299738b9 | 641 | if ((position + header->fSize) != end) { |
806e573c | 642 | if (header->fSize != 0xFFFFFFFF) |
643 | Warning("ReadHeader", | |
644 | "Equipment %d : raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !", | |
645 | equipment->GetEquipmentHeader()->GetId(),header->fSize, end - position); | |
299738b9 | 646 | header->fSize = end - position; |
647 | result |= kErrSize; | |
39f9963f | 648 | } |
be50fca2 | 649 | } |
299738b9 | 650 | position = end; |
b4857df7 | 651 | }; |
fd0de2e2 | 652 | |
653 | return result; | |
b4857df7 | 654 | } |