// read a mini header at the current position
// returns kFALSE if the mini header could not be read
+ fErrorCode = 0;
+
#ifdef ALI_DATE
if (!fEvent) return kFALSE;
+ // check whether there are sub events
+ if (fEvent->eventSize <= fEvent->eventHeadSize) return kFALSE;
+
do {
- if (fCount > 0) fPosition += fCount; // skip payload if event was not selected
- if (!fSubEvent || (fPosition >= fEnd)) { // new sub event
- if (fPosition >= ((UChar_t*)fEvent)+fEvent->eventSize) return kFALSE; // end of data
+ // skip payload (if event was not selected)
+ if (fCount > 0) fPosition += fCount;
+
+ // get the first or the next sub event if at the end of a sub event
+ if (!fSubEvent || (fPosition >= fEnd)) {
+
+ // check for end of event data
+ if (fPosition >= ((UChar_t*)fEvent)+fEvent->eventSize) return kFALSE;
if (fSubEvent) {
fSubEvent = (eventHeaderStruct*) (((UChar_t*)fSubEvent) +
fSubEvent->eventSize);
} else {
- if (fEvent->eventSize <= fEvent->eventHeadSize) return kFALSE; // no sub events
fSubEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) +
fEvent->eventHeadSize);
}
+
+ // check the magic word of the sub event
+ if (fSubEvent->eventMagic != EVENT_MAGIC_NUMBER) {
+ Error("ReadMiniHeader", "wrong magic number in sub event!\n"
+ " run: %d event: %d %d LDC: %d GDC: %d\n",
+ fSubEvent->eventRunNb,
+ fSubEvent->eventId[0], fSubEvent->eventId[1],
+ fSubEvent->eventLdcId, fSubEvent->eventGdcId);
+ fErrorCode = kErrMagic;
+ return kFALSE;
+ }
+
fCount = 0;
fPosition = ((UChar_t*)fSubEvent) + fSubEvent->eventHeadSize +
sizeof(equipmentHeaderStruct);
fEnd = ((UChar_t*)fSubEvent) + fSubEvent->eventSize;
}
- if (fPosition >= fEnd) continue; // no data left in the payload
+
+ // continue with the next sub event if no data left in the payload
+ if (fPosition >= fEnd) continue;
+
+ // check that there are enough bytes left for the mini header
if (fPosition + sizeof(AliMiniHeader) > fEnd) {
- Error("ReadMiniHeader", "could not read data!");
- return kFALSE;
+ Error("ReadMiniHeader", "could not read mini header data!");
+ Warning("ReadMiniHeader", "skipping %d bytes\n"
+ " run: %d event: %d %d LDC: %d GDC: %d\n",
+ fEnd - fPosition, fSubEvent->eventRunNb,
+ fSubEvent->eventId[0], fSubEvent->eventId[1],
+ fSubEvent->eventLdcId, fSubEvent->eventGdcId);
+ fCount = 0;
+ fPosition = fEnd;
+ fErrorCode = kErrNoMiniHeader;
+ continue;
}
+
+ // "read" and check the mini header
fMiniHeader = (AliMiniHeader*) fPosition;
fPosition += sizeof(AliMiniHeader);
- CheckMiniHeader();
+ if (!CheckMiniHeader()) {
+ Error("ReadMiniHeader", "wrong magic word in mini header!");
+ Warning("ReadMiniHeader", "skipping %d bytes\n"
+ " run: %d event: %d %d LDC: %d GDC: %d\n",
+ fEnd - fPosition, fSubEvent->eventRunNb,
+ fSubEvent->eventId[0], fSubEvent->eventId[1],
+ fSubEvent->eventLdcId, fSubEvent->eventGdcId);
+ fCount = 0;
+ fPosition = fEnd;
+ fErrorCode = kErrMiniMagic;
+ continue;
+ }
fCount = fMiniHeader->fSize;
- if (fPosition + fCount > fEnd) { // check data size in mini header and sub event
+
+ // check consistency of data size in the mini header and in the sub event
+ if (fPosition + fCount > fEnd) {
Error("ReadMiniHeader", "size in mini header exceeds event size!");
- fMiniHeader->fSize = fCount = fEnd - fPosition;
+ Warning("ReadMiniHeader", "skipping %d bytes\n"
+ " run: %d event: %d %d LDC: %d GDC: %d\n",
+ fEnd - fPosition, fSubEvent->eventRunNb,
+ fSubEvent->eventId[0], fSubEvent->eventId[1],
+ fSubEvent->eventLdcId, fSubEvent->eventGdcId);
+ fCount = 0;
+ fPosition = fEnd;
+ fErrorCode = kErrSize;
+ continue;
}
+
} while (!IsSelected());
+
return kTRUE;
#else
return kFALSE;
// reads the next payload at the current position
// returns kFALSE if the data could not be read
+ fErrorCode = 0;
while (fCount == 0) {
if (!ReadMiniHeader()) return kFALSE;
}
// reads the next block of data at the current position
// returns kFALSE if the data could not be read
+ fErrorCode = 0;
if (fPosition + size > fEnd) {
Error("ReadNext", "could not read data!");
+ fErrorCode = kErrOutOfBounds;
return kFALSE;
}
memcpy(data, fPosition, size);
fPosition = fEnd = NULL;
return kTRUE;
}
+
+
+Int_t AliRawReaderDate::CheckData() const
+{
+// check the consistency of the data
+
+#ifdef ALI_DATE
+ if (!fEvent) return 0;
+ // check whether there are sub events
+ if (fEvent->eventSize <= fEvent->eventHeadSize) return 0;
+
+ eventHeaderStruct* subEvent = NULL;
+ UChar_t* position = 0;
+ UChar_t* end = 0;
+ Int_t result = 0;
+
+ while (kTRUE) {
+ // get the first or the next sub event if at the end of a sub event
+ if (!subEvent || (position >= end)) {
+
+ // check for end of event data
+ if (position >= ((UChar_t*)fEvent)+fEvent->eventSize) return result;
+ if (subEvent) {
+ subEvent = (eventHeaderStruct*) (((UChar_t*)subEvent) +
+ subEvent->eventSize);
+ } else {
+ subEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) +
+ fEvent->eventHeadSize);
+ }
+
+ // check the magic word of the sub event
+ if (subEvent->eventMagic != EVENT_MAGIC_NUMBER) {
+ result |= kErrMagic;
+ return result;
+ }
+
+ position = ((UChar_t*)subEvent) + subEvent->eventHeadSize +
+ sizeof(equipmentHeaderStruct);
+ end = ((UChar_t*)subEvent) + subEvent->eventSize;
+ }
+
+ // continue with the next sub event if no data left in the payload
+ if (position >= end) continue;
+
+ // check that there are enough bytes left for the mini header
+ if (position + sizeof(AliMiniHeader) > end) {
+ result |= kErrNoMiniHeader;
+ position = end;
+ continue;
+ }
+
+ // "read" and check the mini header
+ AliMiniHeader* miniHeader = (AliMiniHeader*) position;
+ position += sizeof(AliMiniHeader);
+ if (!CheckMiniHeader(miniHeader)){
+ result |= kErrMiniMagic;
+ position = end;
+ continue;
+ }
+
+ // check consistency of data size in the mini header and in the sub event
+ if (position + miniHeader->fSize > end) result |= kErrSize;
+ position += miniHeader->fSize;
+ };
+
+#endif
+ return 0;
+}