///////////////////////////////////////////////////////////////////////////////
//
-// This is the base class for reading a raw data file and providing
+// This is the base class for reading raw data and providing
// information about digits
//
///////////////////////////////////////////////////////////////////////////////
#include "AliRawReader.h"
+
ClassImp(AliRawReader)
-AliRawReader::AliRawReader(const char* fileName, Bool_t addNumber)
+AliRawReader::AliRawReader()
{
-// create an object to read digits from the given input file(s)
-// if addNumber is true, a number starting at 1 is appended to the file name
-
- fFileName = fileName;
- if (!addNumber) {
- fFileNumber = -1;
-#ifndef __DECCXX
- fStream = new fstream(fileName, ios::binary|ios::in);
-#else
- fStream = new fstream(fileName, ios::in);
-#endif
- } else {
- fFileNumber = 0;
- fStream = NULL;
- OpenNextFile();
- }
+ fMiniHeader = NULL;
fCount = 0;
+
+ fSelectDetectorID = -1;
+ fSelectMinDDLID = -1;
+ fSelectMaxDDLID = -1;
}
-AliRawReader::~AliRawReader()
+
+void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
{
-// close the input file
-
- if (fStream) {
-#if defined(__HP_aCC) || defined(__DECCXX)
- if (fStream->rdbuf()->is_open()) fStream->close();
-#else
- if (fStream->is_open()) fStream->close();
-#endif
- delete fStream;
- }
-}
+// read only data of the detector with the given ID and in the given
+// range of DDLs (minDDLID <= DDLID < maxDDLID).
+// no selection is applied if a value < 0 is used.
+ fSelectDetectorID = detectorID;
+ fSelectMinDDLID = minDDLID;
+ fSelectMaxDDLID = maxDDLID;
+}
-Bool_t AliRawReader::OpenNextFile()
+Bool_t AliRawReader::IsSelected()
{
- if (fStream) {
-#if defined(__HP_aCC) || defined(__DECCXX)
- if (fStream->rdbuf()->is_open()) fStream->close();
-#else
- if (fStream->is_open()) fStream->close();
-#endif
- delete fStream;
- fStream = NULL;
+// apply the selection (if any)
+
+ if (fSelectDetectorID >= 0) {
+ if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
+ if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
+ return kFALSE;
+ if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID >= fSelectMaxDDLID))
+ return kFALSE;
}
- if (fFileNumber < 0) return kFALSE;
-
- fFileNumber++;
- char fileName[256];
- sprintf(fileName, "%s%d", fFileName, fFileNumber);
-#ifndef __DECCXX
- fStream = new fstream(fileName, ios::binary|ios::in);
-#else
- fStream = new fstream(fileName, ios::in);
-#endif
-#if defined(__HP_aCC) || defined(__DECCXX)
- return (fStream->rdbuf()->is_open());
-#else
- return (fStream->is_open());
-#endif
+ return kTRUE;
}
-Bool_t AliRawReader::ReadMiniHeader()
+Bool_t AliRawReader::CheckMiniHeader()
{
-// read a mini header at the current stream position
-// returns kFALSE if the mini header could not be read
+// check the magic number of the mini header
- if (!fStream) return kFALSE;
- while (!fStream->read((char*) &fMiniHeader, sizeof(fMiniHeader))) {
- if (!OpenNextFile()) return kFALSE;
+ if ((fMiniHeader->fMagicWord[2] != 0x12) ||
+ (fMiniHeader->fMagicWord[1] != 0x34) ||
+ (fMiniHeader->fMagicWord[0] != 0x56)) {
+ Error("CheckMiniHeader", "wrong magic word!");
+ return kFALSE;
}
- if ((fMiniHeader.fMagicWord[2] != 0x12) ||
- (fMiniHeader.fMagicWord[1] != 0x34) ||
- (fMiniHeader.fMagicWord[0] != 0x56))
- Error("ReadMiniHeader", "wrong magic word!");
- fCount = fMiniHeader.fSize;
return kTRUE;
}
Bool_t AliRawReader::ReadNextInt(UInt_t& data)
{
-// reads the next 4 bytes at the current stream position
-// returns kFALSE if the data not be read
+// reads the next 4 bytes at the current position
+// returns kFALSE if the data could not be read
while (fCount == 0) {
if (!ReadMiniHeader()) return kFALSE;
}
- if (!fStream->read((char*) &data, sizeof(data))) {
+ if (fCount < (Int_t) sizeof(data)) {
+ Error("ReadNextInt",
+ "too few data left (%d bytes) to read an UInt_t!", fCount);
+ return kFALSE;
+ }
+ if (!ReadNext((UChar_t*) &data, sizeof(data))) {
Error("ReadNextInt", "could not read data!");
return kFALSE;
}
- fCount -= sizeof(data);
return kTRUE;
}
Bool_t AliRawReader::ReadNextShort(UShort_t& data)
{
-// reads the next 2 bytes at the current stream position
-// returns kFALSE if the data not be read
+// reads the next 2 bytes at the current position
+// returns kFALSE if the data could not be read
while (fCount == 0) {
if (!ReadMiniHeader()) return kFALSE;
}
- if (!fStream->read((char*) &data, sizeof(data))) {
+ if (fCount < (Int_t) sizeof(data)) {
+ Error("ReadNextShort",
+ "too few data left (%d bytes) to read an UShort_t!", fCount);
+ return kFALSE;
+ }
+ if (!ReadNext((UChar_t*) &data, sizeof(data))) {
Error("ReadNextShort", "could not read data!");
return kFALSE;
}
- fCount -= sizeof(data);
return kTRUE;
}
Bool_t AliRawReader::ReadNextChar(UChar_t& data)
{
// reads the next 1 byte at the current stream position
-// returns kFALSE if the data not be read
+// returns kFALSE if the data could not be read
while (fCount == 0) {
if (!ReadMiniHeader()) return kFALSE;
}
- if (!fStream->read((char*) &data, sizeof(data))) {
+ if (!ReadNext((UChar_t*) &data, sizeof(data))) {
Error("ReadNextChar", "could not read data!");
return kFALSE;
}
- fCount -= sizeof(data);
return kTRUE;
}