+
+Int_t AliRawReaderRoot::CheckData() const
+{
+// check the consistency of the data
+
+ if (!fEvent) return 0;
+
+ AliRawEvent* subEvent = NULL;
+ Int_t subEventIndex = 0;
+ 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 (subEventIndex >= fEvent->GetNSubEvents()) return result;
+ subEvent = fEvent->GetSubEvent(subEventIndex++);
+
+ // check the magic word of the sub event
+ if (!fSubEvent->GetHeader()->IsValid()) {
+ result |= kErrMagic;
+ return result;
+ }
+
+ AliRawData* rawData = subEvent->GetRawData();
+ position = (UChar_t*) rawData->GetBuffer();
+ end = ((UChar_t*) rawData->GetBuffer()) + rawData->GetSize();
+ }
+
+ // 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;
+ };
+}