//
// The derived classes, which operate on concrete raw data formats,
// should implement
-// - ReadMiniHeader to read the next mini header
+// - ReadHeader to read the next (mini or equipment) header
// - ReadNextData to read the next raw data block (=1 DDL)
// - ReadNext to read a given number of bytes
// - several getters like GetType
//
// Sequential access to the raw data is provided by the methods
-// ReadMiniHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
+// ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
//
// If only data from a specific detector (and a given range of DDL numbers)
// should be read, this can be achieved by the Select method.
ClassImp(AliRawReader)
-AliRawReader::AliRawReader()
+AliRawReader::AliRawReader() :
+ fMiniHeader(NULL),
+ fCount(0),
+ fSelectDetectorID(-1),
+ fSelectMinDDLID(-1),
+ fSelectMaxDDLID(-1),
+ fErrorCode(0)
{
// default constructor: initialize data members
- fMiniHeader = NULL;
- fCount = 0;
-
- fSelectDetectorID = -1;
- fSelectMinDDLID = -1;
- fSelectMaxDDLID = -1;
-
- fErrorCode = 0;
}
AliRawReader::AliRawReader(const AliRawReader& rawReader) :
- TObject(rawReader)
+ TObject(rawReader),
+ fMiniHeader(rawReader.fMiniHeader),
+ fCount(rawReader.fCount),
+ fSelectDetectorID(rawReader.fSelectDetectorID),
+ fSelectMinDDLID(rawReader.fSelectMinDDLID),
+ fSelectMaxDDLID(rawReader.fSelectMaxDDLID),
+ fErrorCode(0)
{
// copy constructor
- fMiniHeader = rawReader.fMiniHeader;
- fCount = rawReader.fCount;
-
- fSelectDetectorID = rawReader.fSelectDetectorID;
- fSelectMinDDLID = rawReader.fSelectMinDDLID;
- fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
-
- fErrorCode = 0;
}
AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
// apply the selection (if any)
if (fSelectDetectorID >= 0) {
+ if (!fMiniHeader) return kFALSE;
if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
return kFALSE;
// check the magic number of the mini header
if (!miniHeader) miniHeader = fMiniHeader;
+ if (!miniHeader) return kFALSE;
if ((miniHeader->fMagicWord[2] != 0x12) ||
(miniHeader->fMagicWord[1] != 0x34) ||
(miniHeader->fMagicWord[0] != 0x56)) {
// returns kFALSE if the data could not be read
while (fCount == 0) {
- if (!ReadMiniHeader()) return kFALSE;
+ if (!ReadHeader()) return kFALSE;
}
if (fCount < (Int_t) sizeof(data)) {
Error("ReadNextInt",
// returns kFALSE if the data could not be read
while (fCount == 0) {
- if (!ReadMiniHeader()) return kFALSE;
+ if (!ReadHeader()) return kFALSE;
}
if (fCount < (Int_t) sizeof(data)) {
Error("ReadNextShort",
// returns kFALSE if the data could not be read
while (fCount == 0) {
- if (!ReadMiniHeader()) return kFALSE;
+ if (!ReadHeader()) return kFALSE;
}
if (!ReadNext((UChar_t*) &data, sizeof(data))) {
Error("ReadNextChar", "could not read data!");
#else
void* /* event */
#endif
-)
+ ) :
+ fRequireMiniHeader(kTRUE),
+ 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
fEvent = (eventHeaderStruct*) event;
- fSubEvent = NULL;
- fPosition = fEnd = NULL;
+#else
+ Fatal("AliRawReaderDate", "this class was compiled without DATE");
+#endif
+}
+
+AliRawReaderDate::AliRawReaderDate(
+#ifdef ALI_DATE
+ const char* fileName, Int_t eventNumber
+#else
+ const char* /*fileName*/,
+ Int_t /*eventNumber*/
+#endif
+ ) :
+ fRequireMiniHeader(kTRUE),
+ 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) {
+ Error("AliRawReaderDate", "could not open file %s", fileName);
+ return;
+ }
+ eventHeaderStruct header;
+ UInt_t headerSize = sizeof(eventHeaderStruct);
+ while (fread(&header, 1, headerSize, file) == 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;
+ fEvent = (eventHeaderStruct*) buffer;
+ fIsOwner = kTRUE;
+ break;
+ }
+ fseek(file, header.eventSize-headerSize, SEEK_CUR);
+ eventNumber--;
+ }
+ fclose(file);
+
#else
Fatal("AliRawReaderDate", "this class was compiled without DATE");
#endif
}
AliRawReaderDate::AliRawReaderDate(const AliRawReaderDate& rawReader) :
- AliRawReader(rawReader)
+ AliRawReader(rawReader),
+ fRequireMiniHeader(rawReader.fRequireMiniHeader),
+ fEvent(rawReader.fEvent),
+ fSubEvent(rawReader.fSubEvent),
+ fEquipment(rawReader.fEquipment),
+ fIsOwner(kFALSE),
+ fPosition(rawReader.fPosition),
+ fEnd(rawReader.fEnd)
+
{
// copy constructor
- fEvent = rawReader.fEvent;
- fSubEvent = rawReader.fSubEvent;
- fPosition = rawReader.fPosition;
- fEnd = rawReader.fEnd;
}
AliRawReaderDate& AliRawReaderDate::operator = (const AliRawReaderDate&
return *this;
}
+AliRawReaderDate::~AliRawReaderDate()
+{
+// destructor
+
+#ifdef ALI_DATE
+ if (fIsOwner) delete[] fEvent;
+#endif
+}
+
UInt_t AliRawReaderDate::GetType() const
{
#endif
}
+UInt_t AliRawReaderDate::GetLDCId() const
+{
+// get the LDC Id from the event header
+
+#ifdef ALI_DATE
+ if (!fSubEvent) return 0;
+ return fSubEvent->eventLdcId;
+#else
+ return 0;
+#endif
+}
+
UInt_t AliRawReaderDate::GetGDCId() const
{
// get the GDC Id from the event header
}
-Bool_t AliRawReaderDate::ReadMiniHeader()
+Int_t AliRawReaderDate::GetEquipmentSize() const
+{
+// get the size of the equipment
+
+#ifdef ALI_DATE
+ if (!fEquipment) return 0;
+ return fEquipment->equipmentSize;
+#else
+ return 0;
+#endif
+}
+
+Int_t AliRawReaderDate::GetEquipmentType() const
+{
+// get the type from the equipment header
+
+#ifdef ALI_DATE
+ if (!fEquipment) return -1;
+ return fEquipment->equipmentType;
+#else
+ return 0;
+#endif
+}
+
+Int_t AliRawReaderDate::GetEquipmentId() const
+{
+// get the ID from the equipment header
+
+#ifdef ALI_DATE
+ if (!fEquipment) return -1;
+ return fEquipment->equipmentId;
+#else
+ return 0;
+#endif
+}
+
+const UInt_t* AliRawReaderDate::GetEquipmentAttributes() const
+{
+// get the attributes from the equipment header
+
+#ifdef ALI_DATE
+ if (!fEquipment) return NULL;
+ return fEquipment->equipmentTypeAttribute;
+#else
+ return 0;
+#endif
+}
+
+Int_t AliRawReaderDate::GetEquipmentElementSize() const
+{
+// get the basic element size from the equipment header
+
+#ifdef ALI_DATE
+ if (!fEquipment) return 0;
+ return fEquipment->equipmentBasicElementSize;
+#else
+ return 0;
+#endif
+}
+
+
+Bool_t AliRawReaderDate::ReadHeader()
{
// read a mini header at the current position
// returns kFALSE if the mini header could not be read
// 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)) {
+ // get the first or the next equipment if at the end of an equipment
+ if (!fEquipment || (fPosition >= fEnd)) {
+
+ // get the first or the next sub event if at the end of a sub event
+ if (!fSubEvent ||
+ (fPosition >= ((UChar_t*)fSubEvent) + fSubEvent->eventSize)) {
+
+ // 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 {
+ fSubEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) +
+ fEvent->eventHeadSize);
+ }
+
+ // check the magic word of the sub event
+ if (fSubEvent->eventMagic != EVENT_MAGIC_NUMBER) {
+ Error("ReadHeader", "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;
+ }
+
+ fEquipment = (equipmentHeaderStruct*)
+ (((UChar_t*)fSubEvent) + fSubEvent->eventHeadSize);
- // 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 {
- 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;
+ fEquipment = (equipmentHeaderStruct*) fEnd;
}
fCount = 0;
- fPosition = ((UChar_t*)fSubEvent) + fSubEvent->eventHeadSize +
- sizeof(equipmentHeaderStruct);
- fEnd = ((UChar_t*)fSubEvent) + fSubEvent->eventSize;
+ fPosition = ((UChar_t*)fEquipment) + sizeof(equipmentHeaderStruct);
+ fEnd = fPosition + fEquipment->equipmentSize;
}
// 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 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;
- }
+ fMiniHeader = NULL;
+ if (fRequireMiniHeader) {
+ // check that there are enough bytes left for the mini header
+ if (fPosition + sizeof(AliMiniHeader) > fEnd) {
+ Error("ReadHeader", "could not read mini header data!");
+ Warning("ReadHeader", "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);
- 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;
+ // "read" and check the mini header
+ fMiniHeader = (AliMiniHeader*) fPosition;
+ fPosition += sizeof(AliMiniHeader);
+ if (!CheckMiniHeader()) {
+ Error("ReadHeader", "wrong magic word in mini header!");
+ Warning("ReadHeader", "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;
+ }
+
+ } else { // if mini header not required
+ // assume there is a mini header if the magic word is correct
+ if ((fPosition + sizeof(AliMiniHeader) <= fEnd) &&
+ CheckMiniHeader((AliMiniHeader*) fPosition)) {
+ fMiniHeader = (AliMiniHeader*) fPosition;
+ fPosition += sizeof(AliMiniHeader);
+ }
}
- fCount = fMiniHeader->fSize;
- // 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!");
- 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;
+ if (fMiniHeader) {
+ fCount = fMiniHeader->fSize;
+
+ // check consistency of data size in the mini header and in the sub event
+ if (fPosition + fCount > fEnd) {
+ Error("ReadHeader", "size in mini header exceeds event size!");
+ Warning("ReadHeader", "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;
+ }
+
+ } else {
+ fCount = fEnd - fPosition;
}
} while (!IsSelected());
fErrorCode = 0;
while (fCount == 0) {
- if (!ReadMiniHeader()) return kFALSE;
+ if (!ReadHeader()) return kFALSE;
}
data = fPosition;
fPosition += fCount;
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
+{
+// 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 mini header at the current position
// returns kFALSE if the mini header could not be read
// check the magic word of the sub event
if (!fSubEvent->GetHeader()->IsValid()) {
- Error("ReadMiniHeader", "wrong magic number in sub event!");
+ Error("ReadHeader", "wrong magic number in sub event!");
fSubEvent->GetHeader()->Dump();
fErrorCode = kErrMagic;
return kFALSE;
// check that there are enough bytes left for the mini header
if (fPosition + sizeof(AliMiniHeader) > fEnd) {
- Error("ReadMiniHeader", "could not read mini header data!");
- Warning("ReadMiniHeader", "skipping %d bytes", fEnd - fPosition);
+ Error("ReadHeader", "could not read mini header data!");
+ Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
fSubEvent->GetHeader()->Dump();
fCount = 0;
fPosition = fEnd;
fMiniHeader = (AliMiniHeader*) fPosition;
fPosition += sizeof(AliMiniHeader);
if (!CheckMiniHeader()) {
- Error("ReadMiniHeader", "wrong magic word in mini header!");
- Warning("ReadMiniHeader", "skipping %d bytes", fEnd - fPosition);
+ Error("ReadHeader", "wrong magic word in mini header!");
+ Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
fSubEvent->GetHeader()->Dump();
fCount = 0;
fPosition = fEnd;
// 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!");
- Warning("ReadMiniHeader", "skipping %d bytes", fEnd - fPosition);
+ Error("ReadHeader", "size in mini header exceeds event size!");
+ Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
fSubEvent->GetHeader()->Dump();
fCount = 0;
fPosition = fEnd;
fErrorCode = 0;
while (fCount == 0) {
- if (!ReadMiniHeader()) return kFALSE;
+ if (!ReadHeader()) return kFALSE;
}
data = fPosition;
fPosition += fCount;