+
+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 data header
+ if (position + sizeof(AliRawDataHeader) > end) {
+ result |= kErrNoDataHeader;
+ position = end;
+ continue;
+ }
+
+ // check consistency of data size in the header and in the sub event
+ AliRawDataHeader* header = (AliRawDataHeader*) position;
+ if (fHeader->fSize != 0xFFFFFFFF) {
+ if (position + header->fSize > end) {
+ result |= kErrSize;
+ position = end;
+ } else {
+ position += header->fSize;
+ }
+ } else {
+ position = end;
+ }
+ };
+
+ return result;
+}