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