1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// This is a class for reading raw data from a date file or event.
22 /// The AliRawReaderDate is constructed either with a pointer to a
23 /// date event or with a file name and an event number.
25 ///////////////////////////////////////////////////////////////////////////////
27 #include "AliRawReaderDate.h"
32 ClassImp(AliRawReaderDate)
35 AliRawReaderDate::AliRawReaderDate(
42 fRequireHeader(kTRUE),
50 // create an object to read digits from the given date event
53 fEvent = (eventHeaderStruct*) event;
55 Fatal("AliRawReaderDate", "this class was compiled without DATE");
59 AliRawReaderDate::AliRawReaderDate(
61 const char* fileName, Int_t eventNumber
63 const char* /*fileName*/,
67 fRequireHeader(kTRUE),
75 // create an object to read digits from the given date event
78 fFile = fopen(fileName, "rb");
80 Error("AliRawReaderDate", "could not open file %s", fileName);
83 if (eventNumber < 0) return;
85 eventHeaderStruct header;
86 UInt_t headerSize = sizeof(eventHeaderStruct);
87 while (fread(&header, 1, headerSize, fFile) == headerSize) {
88 if (eventNumber == 0) {
89 UChar_t* buffer = new UChar_t[header.eventSize];
90 fseek(fFile, -headerSize, SEEK_CUR);
91 if (fread(buffer, 1, header.eventSize, fFile) != header.eventSize) break;
92 fEvent = (eventHeaderStruct*) buffer;
95 fseek(fFile, header.eventSize-headerSize, SEEK_CUR);
100 Fatal("AliRawReaderDate", "this class was compiled without DATE");
104 AliRawReaderDate::AliRawReaderDate(const AliRawReaderDate& rawReader) :
105 AliRawReader(rawReader),
106 fRequireHeader(rawReader.fRequireHeader),
107 fFile(rawReader.fFile),
108 fEvent(rawReader.fEvent),
109 fSubEvent(rawReader.fSubEvent),
110 fEquipment(rawReader.fEquipment),
111 fPosition(rawReader.fPosition),
117 Fatal("AliRawReaderDate", "copy constructor not implemented");
120 AliRawReaderDate& AliRawReaderDate::operator = (const AliRawReaderDate&
123 // assignment operator
125 Fatal("operator =", "assignment operator not implemented");
129 AliRawReaderDate::~AliRawReaderDate()
142 UInt_t AliRawReaderDate::GetType() const
144 // get the type from the event header
147 if (!fEvent) return 0;
148 return fEvent->eventType;
154 UInt_t AliRawReaderDate::GetRunNumber() const
156 // get the run number from the event header
159 if (!fEvent) return 0;
160 return fEvent->eventRunNb;
166 const UInt_t* AliRawReaderDate::GetEventId() const
168 // get the event id from the event header
171 if (!fEvent) return NULL;
172 return fEvent->eventId;
178 const UInt_t* AliRawReaderDate::GetTriggerPattern() const
180 // get the trigger pattern from the event header
183 if (!fEvent) return NULL;
184 return fEvent->eventTriggerPattern;
190 const UInt_t* AliRawReaderDate::GetDetectorPattern() const
192 // get the detector pattern from the event header
195 if (!fEvent) return NULL;
196 return fEvent->eventDetectorPattern;
202 const UInt_t* AliRawReaderDate::GetAttributes() const
204 // get the type attributes from the event header
207 if (!fEvent) return NULL;
208 return fEvent->eventTypeAttribute;
214 UInt_t AliRawReaderDate::GetLDCId() const
216 // get the LDC Id from the event header
219 if (!fSubEvent) return 0;
220 return fSubEvent->eventLdcId;
226 UInt_t AliRawReaderDate::GetGDCId() const
228 // get the GDC Id from the event header
231 if (!fEvent) return 0;
232 return fEvent->eventGdcId;
239 Int_t AliRawReaderDate::GetEquipmentSize() const
241 // get the size of the equipment
244 if (!fEquipment) return 0;
245 return fEquipment->equipmentSize;
251 Int_t AliRawReaderDate::GetEquipmentType() const
253 // get the type from the equipment header
256 if (!fEquipment) return -1;
257 return fEquipment->equipmentType;
263 Int_t AliRawReaderDate::GetEquipmentId() const
265 // get the ID from the equipment header
268 if (!fEquipment) return -1;
269 return fEquipment->equipmentId;
275 const UInt_t* AliRawReaderDate::GetEquipmentAttributes() const
277 // get the attributes from the equipment header
280 if (!fEquipment) return NULL;
281 return fEquipment->equipmentTypeAttribute;
287 Int_t AliRawReaderDate::GetEquipmentElementSize() const
289 // get the basic element size from the equipment header
292 if (!fEquipment) return 0;
293 return fEquipment->equipmentBasicElementSize;
300 Bool_t AliRawReaderDate::ReadHeader()
302 // read a data header at the current position
303 // returns kFALSE if the data header could not be read
309 if (!fEvent) return kFALSE;
310 // check whether there are sub events
311 if (fEvent->eventSize <= fEvent->eventHeadSize) return kFALSE;
314 // skip payload (if event was not selected)
315 if (fCount > 0) fPosition += fCount;
317 // get the first or the next equipment if at the end of an equipment
318 if (!fEquipment || (fPosition >= fEnd)) {
321 // get the first or the next sub event if at the end of a sub event
323 (fPosition >= ((UChar_t*)fSubEvent) + fSubEvent->eventSize)) {
325 // check for end of event data
326 if (fPosition >= ((UChar_t*)fEvent)+fEvent->eventSize) return kFALSE;
328 fSubEvent = (eventHeaderStruct*) (((UChar_t*)fSubEvent) +
329 fSubEvent->eventSize);
331 fSubEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) +
332 fEvent->eventHeadSize);
335 // check the magic word of the sub event
336 if (fSubEvent->eventMagic != EVENT_MAGIC_NUMBER) {
337 Error("ReadHeader", "wrong magic number in sub event!\n"
338 " run: %d event: %d %d LDC: %d GDC: %d\n",
339 fSubEvent->eventRunNb,
340 fSubEvent->eventId[0], fSubEvent->eventId[1],
341 fSubEvent->eventLdcId, fSubEvent->eventGdcId);
342 fErrorCode = kErrMagic;
346 // continue if no data in the subevent
347 if (fSubEvent->eventSize == fSubEvent->eventHeadSize) {
348 fPosition = fEnd = ((UChar_t*)fSubEvent) + fSubEvent->eventSize;
353 fEquipment = (equipmentHeaderStruct*)
354 (((UChar_t*)fSubEvent) + fSubEvent->eventHeadSize);
357 fEquipment = (equipmentHeaderStruct*) fEnd;
361 fPosition = ((UChar_t*)fEquipment) + sizeof(equipmentHeaderStruct);
362 if (fSubEvent->eventVersion <= 0x00030002) {
363 fEnd = fPosition + fEquipment->equipmentSize;
365 fEnd = ((UChar_t*)fEquipment) + fEquipment->equipmentSize;
369 // continue with the next sub event if no data left in the payload
370 if (fPosition >= fEnd) continue;
372 if (fRequireHeader) {
373 // check that there are enough bytes left for the data header
374 if (fPosition + sizeof(AliRawDataHeader) > fEnd) {
375 Error("ReadHeader", "could not read data header data!");
376 Warning("ReadHeader", "skipping %d bytes\n"
377 " run: %d event: %d %d LDC: %d GDC: %d\n",
378 fEnd - fPosition, fSubEvent->eventRunNb,
379 fSubEvent->eventId[0], fSubEvent->eventId[1],
380 fSubEvent->eventLdcId, fSubEvent->eventGdcId);
383 fErrorCode = kErrNoDataHeader;
387 // "read" the data header
388 fHeader = (AliRawDataHeader*) fPosition;
389 fPosition += sizeof(AliRawDataHeader);
392 if (fHeader && (fHeader->fSize != 0xFFFFFFFF)) {
393 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
395 // check consistency of data size in the header and in the sub event
396 if (fPosition + fCount > fEnd) {
397 Error("ReadHeader", "size in data header exceeds event size!");
398 Warning("ReadHeader", "skipping %d bytes\n"
399 " run: %d event: %d %d LDC: %d GDC: %d\n",
400 fEnd - fPosition, fSubEvent->eventRunNb,
401 fSubEvent->eventId[0], fSubEvent->eventId[1],
402 fSubEvent->eventLdcId, fSubEvent->eventGdcId);
405 fErrorCode = kErrSize;
410 fCount = fEnd - fPosition;
413 } while (!fEquipment || !IsSelected());
421 Bool_t AliRawReaderDate::ReadNextData(UChar_t*& data)
423 // reads the next payload at the current position
424 // returns kFALSE if the data could not be read
427 while (fCount == 0) {
428 if (!ReadHeader()) return kFALSE;
436 Bool_t AliRawReaderDate::ReadNext(UChar_t* data, Int_t size)
438 // reads the next block of data at the current position
439 // returns kFALSE if the data could not be read
442 if (fPosition + size > fEnd) {
443 Error("ReadNext", "could not read data!");
444 fErrorCode = kErrOutOfBounds;
447 memcpy(data, fPosition, size);
454 Bool_t AliRawReaderDate::Reset()
456 // reset the current position to the beginning of the event
462 fPosition = fEnd = NULL;
467 Bool_t AliRawReaderDate::NextEvent()
469 // go to the next event in the date file
472 if (!fFile) return kFALSE;
474 eventHeaderStruct header;
475 UInt_t headerSize = sizeof(eventHeaderStruct);
476 if (fEvent) delete[] fEvent;
479 while (fread(&header, 1, headerSize, fFile) == headerSize) {
480 if (!IsEventSelected()) {
481 fseek(fFile, header.eventSize-headerSize, SEEK_CUR);
484 UChar_t* buffer = new UChar_t[header.eventSize];
485 fseek(fFile, -headerSize, SEEK_CUR);
486 if (fread(buffer, 1, header.eventSize, fFile) != header.eventSize) {
487 Error("NextEvent", "could not read event from file");
491 fEvent = (eventHeaderStruct*) buffer;
501 Bool_t AliRawReaderDate::RewindEvents()
503 // go back to the beginning of the date file
505 if (!fFile) return kFALSE;
507 fseek(fFile, 0, SEEK_SET);
512 Int_t AliRawReaderDate::CheckData() const
514 // check the consistency of the data
517 if (!fEvent) return 0;
518 // check whether there are sub events
519 if (fEvent->eventSize <= fEvent->eventHeadSize) return 0;
521 eventHeaderStruct* subEvent = NULL;
522 UChar_t* position = 0;
527 // get the first or the next sub event if at the end of a sub event
528 if (!subEvent || (position >= end)) {
530 // check for end of event data
531 if (position >= ((UChar_t*)fEvent)+fEvent->eventSize) return result;
533 subEvent = (eventHeaderStruct*) (((UChar_t*)subEvent) +
534 subEvent->eventSize);
536 subEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) +
537 fEvent->eventHeadSize);
540 // check the magic word of the sub event
541 if (subEvent->eventMagic != EVENT_MAGIC_NUMBER) {
546 position = ((UChar_t*)subEvent) + subEvent->eventHeadSize +
547 sizeof(equipmentHeaderStruct);
548 end = ((UChar_t*)subEvent) + subEvent->eventSize;
551 // continue with the next sub event if no data left in the payload
552 if (position >= end) continue;
554 // check that there are enough bytes left for the data header
555 if (position + sizeof(AliRawDataHeader) > end) {
556 result |= kErrNoDataHeader;
561 // check consistency of data size in the data header and in the sub event
562 AliRawDataHeader* header = (AliRawDataHeader*) position;
563 if (header->fSize != 0xFFFFFFFF) {
564 if (position + header->fSize > end) {
568 position += header->fSize;