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