// create an object to read digits from the given input file for the
// event with the given number
+ fEvent = NULL;
TDirectory* dir = gDirectory;
fFile = TFile::Open(fileName);
dir->cd();
fSubEventIndex = 0;
fSubEvent = NULL;
fRawData = NULL;
- fMiniHeader = NULL;
+ fHeader = NULL;
fCount = 0;
fPosition = fEnd = NULL;
fSubEventIndex = 0;
fSubEvent = NULL;
fRawData = NULL;
- fMiniHeader = NULL;
+ fHeader = NULL;
fCount = 0;
fPosition = fEnd = NULL;
fSubEventIndex = rawReader.fSubEventIndex;
fSubEvent = rawReader.fSubEvent;
fRawData = rawReader.fRawData;
- fMiniHeader = rawReader.fMiniHeader;
+ fHeader = rawReader.fHeader;
fCount = rawReader.fCount;
fPosition = rawReader.fPosition;
return fEvent->GetHeader()->GetTypeAttribute();
}
+UInt_t AliRawReaderRoot::GetLDCId() const
+{
+// get the LDC Id from the event header
+
+ if (!fEvent || !fEvent->GetSubEvent(fSubEventIndex)) return 0;
+ return fEvent->GetSubEvent(fSubEventIndex)->GetHeader()->GetLDCId();
+}
+
UInt_t AliRawReaderRoot::GetGDCId() const
{
// get the GDC Id from the event header
}
-Bool_t AliRawReaderRoot::ReadMiniHeader()
+Int_t AliRawReaderRoot::GetEquipmentSize() const
+{
+// get the size of the equipment
+
+ if (!fEvent || !fEvent->GetEquipmentHeader()) return 0;
+ return fEvent->GetEquipmentHeader()->GetEquipmentSize();
+}
+
+Int_t AliRawReaderRoot::GetEquipmentType() const
+{
+// get the type from the equipment header
+
+ if (!fEvent || !fEvent->GetEquipmentHeader()) return -1;
+ return fEvent->GetEquipmentHeader()->GetEquipmentType();
+}
+
+Int_t AliRawReaderRoot::GetEquipmentId() const
+{
+// get the ID from the equipment header
+
+ if (!fEvent || !fEvent->GetEquipmentHeader()) return -1;
+ return fEvent->GetEquipmentHeader()->GetId();
+}
+
+const UInt_t* AliRawReaderRoot::GetEquipmentAttributes() const
+{
+// get the attributes from the equipment header
+
+ if (!fEvent || !fEvent->GetEquipmentHeader()) return NULL;
+ return fEvent->GetEquipmentHeader()->GetTypeAttribute();
+}
+
+Int_t AliRawReaderRoot::GetEquipmentElementSize() const
{
-// read a mini header at the current position
-// returns kFALSE if the mini header could not be read
+// get the basic element size from the equipment header
+ if (!fEvent || !fEvent->GetEquipmentHeader()) return 0;
+ return fEvent->GetEquipmentHeader()->GetBasicSizeType();
+}
+
+
+Bool_t AliRawReaderRoot::ReadHeader()
+{
+// read a data header at the current position
+// returns kFALSE if the data header could not be read
+
+ fErrorCode = 0;
if (!fEvent) return kFALSE;
+
do {
- if (fCount > 0) fPosition += fCount; // skip payload if event was not selected
- if (!fSubEvent || (fPosition >= fEnd)) { // new sub event
+ // 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 (fSubEventIndex >= fEvent->GetNSubEvents()) return kFALSE;
fSubEvent = fEvent->GetSubEvent(fSubEventIndex++);
+
+ // check the magic word of the sub event
+ if (!fSubEvent->GetHeader()->IsValid()) {
+ Error("ReadHeader", "wrong magic number in sub event!");
+ fSubEvent->GetHeader()->Dump();
+ fErrorCode = kErrMagic;
+ return kFALSE;
+ }
+
fRawData = fSubEvent->GetRawData();
fCount = 0;
fPosition = (UChar_t*) fRawData->GetBuffer();
fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
}
- if (fPosition >= fEnd) continue; // no data left in the payload
- if (fPosition + sizeof(AliMiniHeader) > fEnd) {
- Error("ReadMiniHeader", "could not read data!");
- return kFALSE;
- }
- fMiniHeader = (AliMiniHeader*) fPosition;
- fPosition += sizeof(AliMiniHeader);
- if (!CheckMiniHeader()) {
- Warning("ReadMiniHeader", "skipping %d bytes", fEnd - fPosition);
+
+ // 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 data header
+ if (fPosition + sizeof(AliRawDataHeader) > fEnd) {
+ Error("ReadHeader", "could not read data header!");
+ Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
fSubEvent->GetHeader()->Dump();
fCount = 0;
fPosition = fEnd;
+ fErrorCode = kErrNoDataHeader;
continue;
}
- fCount = fMiniHeader->fSize;
- if (fPosition + fCount > fEnd) { // check data size in mini header and sub event
- Error("ReadMiniHeader", "size in mini header exceeds event size!");
- Warning("ReadMiniHeader", "skipping %d bytes", fEnd - fPosition);
+
+ // "read" the data header
+ fHeader = (AliRawDataHeader*) fPosition;
+ fPosition += sizeof(AliRawDataHeader);
+ if (fHeader->fSize != 0xFFFFFFFF) {
+ fCount = fHeader->fSize - sizeof(AliRawDataHeader);
+ } else {
+ fCount = fEnd - fPosition;
+ }
+
+ // check consistency of data size in the header and in the sub event
+ if (fPosition + fCount > fEnd) {
+ Error("ReadHeader", "size in data header exceeds event size!");
+ Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
fSubEvent->GetHeader()->Dump();
fCount = 0;
fPosition = fEnd;
+ fErrorCode = kErrSize;
continue;
}
+
} while (!IsSelected());
+
return kTRUE;
}
// 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;
+ if (!ReadHeader()) return kFALSE;
}
data = fPosition;
fPosition += fCount;
// 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);
fSubEventIndex = 0;
fSubEvent = NULL;
fRawData = NULL;
- fMiniHeader = NULL;
+ fHeader = NULL;
fCount = 0;
fPosition = fEnd = NULL;
return kTRUE;
}
+
+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;
+}