* provided "as is" without express or implied warranty. *
**************************************************************************/
+/* $Id$ */
+
///////////////////////////////////////////////////////////////////////////////
-//
-// This is a class for reading a raw data from a date event and providing
-// information about digits
-//
+///
+/// This is a class for reading raw data from a date file or event.
+///
+/// The AliRawReaderDate is constructed either with a pointer to a
+/// date event or with a file name and an event number.
+///
///////////////////////////////////////////////////////////////////////////////
#include "AliRawReaderDate.h"
#else
void* /* event */
#endif
-)
+ ) :
+ fRequireHeader(kTRUE),
+ fFile(NULL),
+ fEvent(NULL),
+ fSubEvent(NULL),
+ fEquipment(NULL),
+ 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
+ ) :
+ fRequireHeader(kTRUE),
+ fFile(NULL),
+ fEvent(NULL),
+ fSubEvent(NULL),
+ fEquipment(NULL),
+ fPosition(NULL),
+ fEnd(NULL)
+{
+// create an object to read digits from the given date event
+
+#ifdef ALI_DATE
+ fFile = fopen(fileName, "rb");
+ if (!fFile) {
+ Error("AliRawReaderDate", "could not open file %s", fileName);
+ return;
+ }
+ if (eventNumber < 0) return;
+
+ eventHeaderStruct header;
+ UInt_t headerSize = sizeof(eventHeaderStruct);
+ while (fread(&header, 1, headerSize, fFile) == headerSize) {
+ if (eventNumber == 0) {
+ UChar_t* buffer = new UChar_t[header.eventSize];
+ fseek(fFile, -headerSize, SEEK_CUR);
+ if (fread(buffer, 1, header.eventSize, fFile) != header.eventSize) break;
+ fEvent = (eventHeaderStruct*) buffer;
+ break;
+ }
+ fseek(fFile, header.eventSize-headerSize, SEEK_CUR);
+ eventNumber--;
+ }
+
#else
Fatal("AliRawReaderDate", "this class was compiled without DATE");
#endif
}
AliRawReaderDate::AliRawReaderDate(const AliRawReaderDate& rawReader) :
- AliRawReader(rawReader)
+ AliRawReader(rawReader),
+ fRequireHeader(rawReader.fRequireHeader),
+ fFile(rawReader.fFile),
+ fEvent(rawReader.fEvent),
+ fSubEvent(rawReader.fSubEvent),
+ fEquipment(rawReader.fEquipment),
+ fPosition(rawReader.fPosition),
+ fEnd(rawReader.fEnd)
+
{
// copy constructor
- fEvent = rawReader.fEvent;
- fSubEvent = rawReader.fSubEvent;
- fPosition = rawReader.fPosition;
- fEnd = rawReader.fEnd;
+ Fatal("AliRawReaderDate", "copy constructor not implemented");
}
AliRawReaderDate& AliRawReaderDate::operator = (const AliRawReaderDate&
- rawReader)
+ /*rawReader*/)
{
// assignment operator
- this->~AliRawReaderDate();
- new(this) AliRawReaderDate(rawReader);
+ Fatal("operator =", "assignment operator not implemented");
return *this;
}
+AliRawReaderDate::~AliRawReaderDate()
+{
+// destructor
+
+#ifdef ALI_DATE
+ if (fFile) {
+ delete[] fEvent;
+ fclose(fFile);
+ }
+#endif
+}
+
UInt_t AliRawReaderDate::GetType() const
{
#endif
}
+const UInt_t* AliRawReaderDate::GetSubEventAttributes() const
+{
+// get the type attributes from the sub event header
+
+#ifdef ALI_DATE
+ if (!fSubEvent) return NULL;
+ return fSubEvent->eventTypeAttribute;
+#else
+ return NULL;
+#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 (without header)
+
+#ifdef ALI_DATE
+ if (!fEquipment) return 0;
+ if (fSubEvent->eventVersion <= 0x00030001) {
+ return fEquipment->equipmentSize;
+ } else {
+ return fEquipment->equipmentSize - sizeof(equipmentHeaderStruct);
+ }
+#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
{
-// 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
+
+#ifdef ALI_DATE
+ if (!fEquipment) return 0;
+ return fEquipment->equipmentBasicElementSize;
+#else
+ return 0;
+#endif
+}
+
+
+Bool_t AliRawReaderDate::ReadHeader()
+{
+// read a data header at the current position
+// returns kFALSE if the data header could not be read
fErrorCode = 0;
#ifdef ALI_DATE
+ fHeader = NULL;
if (!fEvent) return kFALSE;
// check whether there are sub events
if (fEvent->eventSize <= fEvent->eventHeadSize) return kFALSE;
// 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)) {
+ fEquipment = NULL;
+
+ // 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 (!TEST_SYSTEM_ATTRIBUTE(fEvent->eventTypeAttribute,
+ ATTR_SUPER_EVENT)) {
+ fSubEvent = fEvent; // no super event
+ } else 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;
+ }
+
+ // continue if no data in the subevent
+ if (fSubEvent->eventSize == fSubEvent->eventHeadSize) {
+ fPosition = fEnd = ((UChar_t*)fSubEvent) + fSubEvent->eventSize;
+ fCount = 0;
+ continue;
+ }
+
+ 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);
+ if (fSubEvent->eventVersion <= 0x00030001) {
+ fEnd = fPosition + fEquipment->equipmentSize;
+ } else {
+ fEnd = ((UChar_t*)fEquipment) + 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;
- }
+ if (fRequireHeader) {
+ // check that there are enough bytes left for the data header
+ if (fPosition + sizeof(AliRawDataHeader) > fEnd) {
+ Error("ReadHeader", "could not read data 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 = kErrNoDataHeader;
+ 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" the data header
+ fHeader = (AliRawDataHeader*) fPosition;
+ fPosition += sizeof(AliRawDataHeader);
}
- 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 (fHeader && (fHeader->fSize != 0xFFFFFFFF)) {
+ fCount = fHeader->fSize - sizeof(AliRawDataHeader);
+
+ // 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\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());
+ } while (!fEquipment || !IsSelected());
return kTRUE;
#else
fErrorCode = 0;
while (fCount == 0) {
- if (!ReadMiniHeader()) return kFALSE;
+ if (!ReadHeader()) return kFALSE;
}
data = fPosition;
fPosition += fCount;
#ifdef ALI_DATE
fSubEvent = NULL;
+ fEquipment = NULL;
#endif
fCount = 0;
fPosition = fEnd = NULL;
}
+Bool_t AliRawReaderDate::NextEvent()
+{
+// go to the next event in the date file
+
+#ifdef ALI_DATE
+ if (!fFile) return kFALSE;
+
+ Reset();
+ eventHeaderStruct header;
+ UInt_t headerSize = sizeof(eventHeaderStruct);
+ if (fEvent) delete[] fEvent;
+ fEvent = &header;
+
+ while (fread(&header, 1, headerSize, fFile) == headerSize) {
+ if (!IsEventSelected()) {
+ fseek(fFile, header.eventSize-headerSize, SEEK_CUR);
+ continue;
+ }
+ UChar_t* buffer = new UChar_t[header.eventSize];
+ fseek(fFile, -headerSize, SEEK_CUR);
+ if (fread(buffer, 1, header.eventSize, fFile) != header.eventSize) {
+ Error("NextEvent", "could not read event from file");
+ delete[] buffer;
+ break;
+ }
+ fEvent = (eventHeaderStruct*) buffer;
+ return kTRUE;
+ };
+
+ fEvent = NULL;
+#endif
+
+ return kFALSE;
+}
+
+Bool_t AliRawReaderDate::RewindEvents()
+{
+// go back to the beginning of the date file
+
+ if (!fFile) return kFALSE;
+
+ fseek(fFile, 0, SEEK_SET);
+ return Reset();
+}
+
+
Int_t AliRawReaderDate::CheckData() const
{
// check the consistency of the data
// check for end of event data
if (position >= ((UChar_t*)fEvent)+fEvent->eventSize) return result;
- if (subEvent) {
+ if (!TEST_SYSTEM_ATTRIBUTE(fEvent->eventTypeAttribute,
+ ATTR_SUPER_EVENT)) {
+ subEvent = fEvent; // no super event
+ } else if (subEvent) {
subEvent = (eventHeaderStruct*) (((UChar_t*)subEvent) +
subEvent->eventSize);
} else {
// 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;
+ // check that there are enough bytes left for the data header
+ if (position + sizeof(AliRawDataHeader) > end) {
+ result |= kErrNoDataHeader;
position = end;
continue;
}
- // "read" and check the mini header
- AliMiniHeader* miniHeader = (AliMiniHeader*) position;
- position += sizeof(AliMiniHeader);
- if (!CheckMiniHeader(miniHeader)){
- result |= kErrMiniMagic;
+ // check consistency of data size in the data header and in the sub event
+ AliRawDataHeader* header = (AliRawDataHeader*) position;
+ if (header->fSize != 0xFFFFFFFF) {
+ if (position + header->fSize > end) {
+ result |= kErrSize;
+ position = end;
+ } else {
+ position += header->fSize;
+ }
+ } else {
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