X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=RAW%2FAliRawReaderDate.cxx;h=88c3e6515b2be04d3aba741c3dfbc427cc6f0879;hb=817c796a9eb59ded9e54f612f16730dff5a8155f;hp=d459352fef5f4f42685697548eafe0da53205df4;hpb=bea6b2a48b987c82a6e6c8efd8bc0ac1cac9aa0a;p=u%2Fmrichter%2FAliRoot.git diff --git a/RAW/AliRawReaderDate.cxx b/RAW/AliRawReaderDate.cxx index d459352fef5..88c3e6515b2 100644 --- a/RAW/AliRawReaderDate.cxx +++ b/RAW/AliRawReaderDate.cxx @@ -39,11 +39,10 @@ AliRawReaderDate::AliRawReaderDate( void* /* event */ #endif ) : - fRequireHeader(kTRUE), + fFile(NULL), fEvent(NULL), fSubEvent(NULL), fEquipment(NULL), - fIsOwner(kFALSE), fPosition(NULL), fEnd(NULL) { @@ -64,37 +63,36 @@ AliRawReaderDate::AliRawReaderDate( Int_t /*eventNumber*/ #endif ) : - fRequireHeader(kTRUE), + fFile(NULL), fEvent(NULL), fSubEvent(NULL), fEquipment(NULL), - fIsOwner(kFALSE), fPosition(NULL), fEnd(NULL) { // create an object to read digits from the given date event #ifdef ALI_DATE - FILE* file = fopen(fileName, "rb"); - if (!file) { + fFile = fopen(fileName, "rb"); + if (!fFile) { Error("AliRawReaderDate", "could not open file %s", fileName); return; } + if (eventNumber < 0) return; + eventHeaderStruct header; UInt_t headerSize = sizeof(eventHeaderStruct); - while (fread(&header, 1, headerSize, file) == headerSize) { + while (fread(&header, 1, headerSize, fFile) == headerSize) { if (eventNumber == 0) { UChar_t* buffer = new UChar_t[header.eventSize]; - fseek(file, -headerSize, SEEK_CUR); - if (fread(buffer, 1, header.eventSize, file) != header.eventSize) break; + fseek(fFile, -(long)headerSize, SEEK_CUR); + if (fread(buffer, 1, header.eventSize, fFile) != header.eventSize) break; fEvent = (eventHeaderStruct*) buffer; - fIsOwner = kTRUE; break; } - fseek(file, header.eventSize-headerSize, SEEK_CUR); + fseek(fFile, header.eventSize-headerSize, SEEK_CUR); eventNumber--; } - fclose(file); #else Fatal("AliRawReaderDate", "this class was compiled without DATE"); @@ -103,26 +101,25 @@ AliRawReaderDate::AliRawReaderDate( AliRawReaderDate::AliRawReaderDate(const AliRawReaderDate& rawReader) : AliRawReader(rawReader), - fRequireHeader(rawReader.fRequireHeader), + fFile(rawReader.fFile), fEvent(rawReader.fEvent), fSubEvent(rawReader.fSubEvent), fEquipment(rawReader.fEquipment), - fIsOwner(kFALSE), fPosition(rawReader.fPosition), fEnd(rawReader.fEnd) { // copy constructor + Fatal("AliRawReaderDate", "copy constructor not implemented"); } AliRawReaderDate& AliRawReaderDate::operator = (const AliRawReaderDate& - rawReader) + /*rawReader*/) { // assignment operator - this->~AliRawReaderDate(); - new(this) AliRawReaderDate(rawReader); + Fatal("operator =", "assignment operator not implemented"); return *this; } @@ -131,7 +128,10 @@ AliRawReaderDate::~AliRawReaderDate() // destructor #ifdef ALI_DATE - if (fIsOwner) delete[] fEvent; + if (fFile) { + delete[] fEvent; + fclose(fFile); + } #endif } @@ -208,6 +208,18 @@ const UInt_t* AliRawReaderDate::GetAttributes() const #endif } +const UInt_t* AliRawReaderDate::GetSubEventAttributes() const +{ +// get the type attributes from the sub event header + +#ifdef ALI_DATE + if (!fSubEvent) return NULL; + return fSubEvent->eventTypeAttribute; +#else + return NULL; +#endif +} + UInt_t AliRawReaderDate::GetLDCId() const { // get the LDC Id from the event header @@ -232,14 +244,29 @@ UInt_t AliRawReaderDate::GetGDCId() const #endif } +UInt_t AliRawReaderDate::GetTimestamp() const +{ +// get the timestamp from the event header + +#ifdef ALI_DATE + if (!fEvent) return 0; + return fEvent->eventTimestamp; +#else + return 0; +#endif +} Int_t AliRawReaderDate::GetEquipmentSize() const { -// get the size of the equipment +// get the size of the equipment (including the header) #ifdef ALI_DATE if (!fEquipment) return 0; - return fEquipment->equipmentSize; + if (fSubEvent->eventVersion <= 0x00030001) { + return fEquipment->equipmentSize + sizeof(equipmentHeaderStruct); + } else { + return fEquipment->equipmentSize; + } #else return 0; #endif @@ -293,6 +320,16 @@ Int_t AliRawReaderDate::GetEquipmentElementSize() const #endif } +Int_t AliRawReaderDate::GetEquipmentHeaderSize() const +{ + // Get the equipment header size + // 28 bytes by default +#ifdef ALI_DATE + return sizeof(equipmentHeaderStruct); +#else + return 0; +#endif +} Bool_t AliRawReaderDate::ReadHeader() { @@ -302,6 +339,7 @@ Bool_t AliRawReaderDate::ReadHeader() fErrorCode = 0; #ifdef ALI_DATE + fHeader = NULL; if (!fEvent) return kFALSE; // check whether there are sub events if (fEvent->eventSize <= fEvent->eventHeadSize) return kFALSE; @@ -312,6 +350,7 @@ Bool_t AliRawReaderDate::ReadHeader() // get the first or the next equipment if at the end of an equipment if (!fEquipment || (fPosition >= fEnd)) { + fEquipment = NULL; // get the first or the next sub event if at the end of a sub event if (!fSubEvent || @@ -319,7 +358,10 @@ Bool_t AliRawReaderDate::ReadHeader() // check for end of event data if (fPosition >= ((UChar_t*)fEvent)+fEvent->eventSize) return kFALSE; - if (fSubEvent) { + if (!TEST_SYSTEM_ATTRIBUTE(fEvent->eventTypeAttribute, + ATTR_SUPER_EVENT)) { + fSubEvent = fEvent; // no super event + } else if (fSubEvent) { fSubEvent = (eventHeaderStruct*) (((UChar_t*)fSubEvent) + fSubEvent->eventSize); } else { @@ -338,6 +380,13 @@ Bool_t AliRawReaderDate::ReadHeader() return kFALSE; } + // continue if no data in the subevent + if (fSubEvent->eventSize == fSubEvent->eventHeadSize) { + fPosition = fEnd = ((UChar_t*)fSubEvent) + fSubEvent->eventSize; + fCount = 0; + continue; + } + fEquipment = (equipmentHeaderStruct*) (((UChar_t*)fSubEvent) + fSubEvent->eventHeadSize); @@ -347,13 +396,16 @@ Bool_t AliRawReaderDate::ReadHeader() fCount = 0; fPosition = ((UChar_t*)fEquipment) + sizeof(equipmentHeaderStruct); - fEnd = fPosition + fEquipment->equipmentSize; + if (fSubEvent->eventVersion <= 0x00030001) { + fEnd = fPosition + fEquipment->equipmentSize; + } else { + fEnd = ((UChar_t*)fEquipment) + fEquipment->equipmentSize; + } } // continue with the next sub event if no data left in the payload if (fPosition >= fEnd) continue; - fHeader = NULL; if (fRequireHeader) { // check that there are enough bytes left for the data header if (fPosition + sizeof(AliRawDataHeader) > fEnd) { @@ -371,6 +423,13 @@ Bool_t AliRawReaderDate::ReadHeader() // "read" the data header fHeader = (AliRawDataHeader*) fPosition; + if ((fPosition + fHeader->fSize) != fEnd) { + if (fHeader->fSize != 0xFFFFFFFF) + Warning("ReadHeader", + "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !", + fHeader->fSize, fEnd - fPosition); + fHeader->fSize = fEnd - fPosition; + } fPosition += sizeof(AliRawDataHeader); } @@ -395,7 +454,7 @@ Bool_t AliRawReaderDate::ReadHeader() fCount = fEnd - fPosition; } - } while (!IsSelected()); + } while (!fEquipment || !IsSelected()); return kTRUE; #else @@ -442,6 +501,7 @@ Bool_t AliRawReaderDate::Reset() #ifdef ALI_DATE fSubEvent = NULL; + fEquipment = NULL; #endif fCount = 0; fPosition = fEnd = NULL; @@ -449,6 +509,61 @@ Bool_t AliRawReaderDate::Reset() } +Bool_t AliRawReaderDate::NextEvent() +{ +// go to the next event in the date file + +#ifdef ALI_DATE + if (!fFile) { + if (fEventNumber < 0 && fEvent) { + fEventNumber++; + return kTRUE; + } + else + return kFALSE; + } + + Reset(); + eventHeaderStruct header; + UInt_t headerSize = sizeof(eventHeaderStruct); + if (fEvent) delete[] fEvent; + fEvent = &header; + + while (fread(&header, 1, headerSize, fFile) == headerSize) { + if (!IsEventSelected()) { + fseek(fFile, header.eventSize-headerSize, SEEK_CUR); + continue; + } + UChar_t* buffer = new UChar_t[header.eventSize]; + fseek(fFile, -(long)headerSize, SEEK_CUR); + if (fread(buffer, 1, header.eventSize, fFile) != header.eventSize) { + Error("NextEvent", "could not read event from file"); + delete[] buffer; + break; + } + fEvent = (eventHeaderStruct*) buffer; + fEventNumber++; + return kTRUE; + }; + + fEvent = NULL; +#endif + + return kFALSE; +} + +Bool_t AliRawReaderDate::RewindEvents() +{ +// go back to the beginning of the date file + + if (fFile) + fseek(fFile, 0, SEEK_SET); + + fEventNumber = -1; + return Reset(); +} + + Int_t AliRawReaderDate::CheckData() const { // check the consistency of the data @@ -469,7 +584,10 @@ Int_t AliRawReaderDate::CheckData() const // check for end of event data if (position >= ((UChar_t*)fEvent)+fEvent->eventSize) return result; - if (subEvent) { + if (!TEST_SYSTEM_ATTRIBUTE(fEvent->eventTypeAttribute, + ATTR_SUPER_EVENT)) { + subEvent = fEvent; // no super event + } else if (subEvent) { subEvent = (eventHeaderStruct*) (((UChar_t*)subEvent) + subEvent->eventSize); } else { @@ -491,25 +609,26 @@ Int_t AliRawReaderDate::CheckData() const // continue with the next sub event if no data left in the payload if (position >= end) continue; + if (fRequireHeader) { // check that there are enough bytes left for the data header - if (position + sizeof(AliRawDataHeader) > end) { - result |= kErrNoDataHeader; - position = end; - continue; - } + if (position + sizeof(AliRawDataHeader) > end) { + result |= kErrNoDataHeader; + position = end; + continue; + } - // check consistency of data size in the data header and in the sub event - AliRawDataHeader* header = (AliRawDataHeader*) position; - if (fHeader->fSize != 0xFFFFFFFF) { - if (position + header->fSize > end) { + // check consistency of data size in the data header and in the sub event + AliRawDataHeader* header = (AliRawDataHeader*) position; + if ((position + header->fSize) != end) { + if (header->fSize != 0xFFFFFFFF) + Warning("ReadHeader", + "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !", + header->fSize, end - position); + header->fSize = end - position; result |= kErrSize; - position = end; - } else { - position += header->fSize; } - } else { - position = end; } + position = end; }; #endif