]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReader.cxx
"Version
[u/mrichter/AliRoot.git] / RAW / AliRawReader.cxx
index e830b260882e5a1e5232ce211215d862918bcb6b..7d91bc13bc80dc1621054a28bf6e66fc8058578d 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+/* $Id$ */
+
 ///////////////////////////////////////////////////////////////////////////////
-//
-// This is the base class for reading raw data and providing
-// information about digits
-//
-// The derived classes, which operate on concrete raw data formats,
-// should implement
-// - ReadMiniHeader to read the next mini 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
-//
-// 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.
-// Several getter provide information about the current event and the
-// current type of raw data.
-//
+///
+/// This is the base class for reading raw data.
+///
+/// The derived classes, which operate on concrete raw data formats,
+/// should implement
+/// - ReadHeader to read the next (data/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
+/// 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.
+/// Several getters provide information about the current event and the
+/// current type of raw data.
+///
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "AliRawReader.h"
 ClassImp(AliRawReader)
 
 
-AliRawReader::AliRawReader()
+AliRawReader::AliRawReader() :
+  fRequireHeader(kTRUE),
+  fHeader(NULL),
+  fCount(0),
+  fSelectEquipmentType(-1),
+  fSelectMinEquipmentId(-1),
+  fSelectMaxEquipmentId(-1),
+  fSkipInvalid(kFALSE),
+  fSelectEventType(-1),
+  fErrorCode(0)
 {
 // default constructor: initialize data members
 
-  fMiniHeader = NULL;
-  fCount = 0;
-
-  fSelectDetectorID = -1;
-  fSelectMinDDLID = -1;
-  fSelectMaxDDLID = -1;
 }
 
 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
-  TObject(rawReader)
+  TObject(rawReader),
+  fRequireHeader(rawReader.fRequireHeader),
+  fHeader(rawReader.fHeader),
+  fCount(rawReader.fCount),
+  fSelectEquipmentType(rawReader.fSelectEquipmentType),
+  fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
+  fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
+  fSkipInvalid(rawReader.fSkipInvalid),
+  fSelectEventType(rawReader.fSelectEventType),
+  fErrorCode(0)
 {
 // copy constructor
 
-  fMiniHeader = rawReader.fMiniHeader;
-  fCount = rawReader.fCount;
-
-  fSelectDetectorID = rawReader.fSelectDetectorID;
-  fSelectMinDDLID = rawReader.fSelectMinDDLID;
-  fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
 }
 
 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
 {
 // assignment operator
 
-  fMiniHeader = rawReader.fMiniHeader;
+  fHeader = rawReader.fHeader;
   fCount = rawReader.fCount;
 
-  fSelectDetectorID = rawReader.fSelectDetectorID;
-  fSelectMinDDLID = rawReader.fSelectMinDDLID;
-  fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
+  fSelectEquipmentType = rawReader.fSelectEquipmentType;
+  fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
+  fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
+  fSkipInvalid = rawReader.fSkipInvalid;
+  fSelectEventType = rawReader.fSelectEventType;
+
+  fErrorCode = rawReader.fErrorCode;
 
   return *this;
 }
@@ -84,49 +95,74 @@ AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
 {
 // read only data of the detector with the given ID and in the given
-// range of DDLs (minDDLID <= DDLID < maxDDLID).
+// range of DDLs (minDDLID <= DDLID <= maxDDLID).
 // no selection is applied if a value < 0 is used.
 
-  fSelectDetectorID = detectorID;
-  fSelectMinDDLID = minDDLID;
-  fSelectMaxDDLID = maxDDLID;
+  fSelectEquipmentType = 0;
+  if (minDDLID < 0) minDDLID = 0;
+  fSelectMinEquipmentId = (detectorID << 8) + minDDLID;
+  if (maxDDLID < 0) maxDDLID = 0xFF;
+  fSelectMaxEquipmentId = (detectorID << 8) + maxDDLID;
+}
+
+void AliRawReader::SelectEquipment(Int_t equipmentType, 
+                                  Int_t minEquipmentId, Int_t maxEquipmentId)
+{
+// read only data of the equipment with the given type and in the given
+// range of IDs (minEquipmentId <= EquipmentId <= maxEquipmentId).
+// no selection is applied if a value < 0 is used.
+
+  fSelectEquipmentType = equipmentType;
+  fSelectMinEquipmentId = minEquipmentId;
+  fSelectMaxEquipmentId = maxEquipmentId;
+}
+
+void AliRawReader::SelectEvents(Int_t type)
+{
+// read only events with the given type.
+// no selection is applied if a value < 0 is used.
+
+  fSelectEventType = type;
 }
 
 Bool_t AliRawReader::IsSelected() const
 {
 // apply the selection (if any)
 
-  if (fSelectDetectorID >= 0) {
-    if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
-    if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
+  if (fSkipInvalid && !IsValid()) return kFALSE;
+
+  if (fSelectEquipmentType >= 0) {
+    if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
+    if ((fSelectMinEquipmentId >= 0) && 
+       (GetEquipmentId() < fSelectMinEquipmentId))
       return kFALSE;
-    if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID >= fSelectMaxDDLID))
+    if ((fSelectMaxEquipmentId >= 0) && 
+       (GetEquipmentId() > fSelectMaxEquipmentId))
       return kFALSE;
   }
+
   return kTRUE;
 }
 
-
-Bool_t AliRawReader::CheckMiniHeader() const
+Bool_t AliRawReader::IsEventSelected() const
 {
-// check the magic number of the mini header
+// apply the event selection (if any)
 
-  if ((fMiniHeader->fMagicWord[2] != 0x12) ||
-      (fMiniHeader->fMagicWord[1] != 0x34) ||
-      (fMiniHeader->fMagicWord[0] != 0x56)) {
-    Error("CheckMiniHeader", "wrong magic word!");
-    return kFALSE;
+  if (fSelectEventType >= 0) {
+    if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
   }
+
   return kTRUE;
 }
 
+
 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
 {
 // 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 (!ReadHeader()) return kFALSE;
   }
   if (fCount < (Int_t) sizeof(data)) {
     Error("ReadNextInt", 
@@ -146,7 +182,7 @@ Bool_t AliRawReader::ReadNextShort(UShort_t& data)
 // 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", 
@@ -166,7 +202,7 @@ Bool_t AliRawReader::ReadNextChar(UChar_t& data)
 // 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!");
@@ -175,3 +211,118 @@ Bool_t AliRawReader::ReadNextChar(UChar_t& data)
   return kTRUE;
 }
 
+
+Int_t AliRawReader::CheckData() const
+{
+// check the consistency of the data
+// derived classes should overwrite the default method which returns 0 (no err)
+
+  return 0;
+}
+
+
+void AliRawReader::DumpData(Int_t limit)
+{
+// print the raw data
+// if limit is not negative, only the first and last "limit" lines of raw data
+// are printed
+
+  Reset();
+  if (!ReadHeader()) {
+    Error("DumpData", "no header");
+    return;
+  }
+  printf("header:\n"
+        " type = %d  run = %d  ", GetType(), GetRunNumber());
+  if (GetEventId()) {
+    printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
+  } else {
+    printf("event = -------- --------\n");
+  }
+  if (GetTriggerPattern()) {
+    printf(" trigger = %8.8x %8.8x  ",
+          GetTriggerPattern()[1], GetTriggerPattern()[0]);
+  } else {
+    printf(" trigger = -------- --------  ");
+  }
+  if (GetDetectorPattern()) {
+    printf("detector = %8.8x\n", GetDetectorPattern()[0]);
+  } else {
+    printf("detector = --------\n");
+  }
+  if (GetAttributes()) {
+    printf(" attributes = %8.8x %8.8x %8.8x  ",
+          GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
+  } else {
+    printf(" attributes = -------- -------- --------  ");
+  }
+  printf("GDC = %d\n", GetGDCId());
+  printf("\n");
+
+  do {
+    printf("-------------------------------------------------------------------------------\n");
+    printf("LDC = %d\n", GetLDCId());
+
+    printf("equipment:\n"
+          " size = %d  type = %d  id = %d\n",
+          GetEquipmentSize(), GetEquipmentType(), GetEquipmentId());
+    if (GetEquipmentAttributes()) {
+      printf(" attributes = %8.8x %8.8x %8.8x  ", GetEquipmentAttributes()[2],
+            GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]);
+    } else {
+      printf(" attributes = -------- -------- --------  ");
+    }
+    printf("element size = %d\n", GetEquipmentElementSize());
+
+    printf("data header:\n"
+          " size = %d  version = %d  valid = %d  compression = %d\n",
+          GetDataSize(), GetVersion(), IsValid(), IsCompressed());
+
+    printf("\n");
+    if (limit == 0) continue;
+
+    Int_t size = GetDataSize();
+    char line[70];
+    for (Int_t i = 0; i < 70; i++) line[i] = ' ';
+    line[69] = '\0';
+    Int_t pos = 0;
+    Int_t max = 16;
+    UChar_t byte;
+
+    for (Int_t n = 0; n < size; n++) {
+      if (!ReadNextChar(byte)) {
+       Error("DumpData", "couldn't read byte number %d\n", n);
+       break;
+      }
+      if (pos >= max) {
+       printf("%8.8x  %s\n", n-pos, line);
+       for (Int_t i = 0; i < 70; i++) line[i] = ' ';
+       line[69] = '\0';
+       pos = 0;
+       if ((limit > 0) && (n/max == limit)) {
+         Int_t nContinue = ((size-1)/max+1-limit) * max;
+         if (nContinue > n) {
+           printf(" [skipping %d bytes]\n", nContinue-n);
+           n = nContinue-1;
+           continue;
+         }
+       }
+      }
+      Int_t offset = pos/4;
+      if ((byte > 0x20) && (byte < 0x7f)) {
+       line[pos+offset] = byte;
+      } else {
+       line[pos+offset] = '.';
+      }
+      char hex[3];
+      sprintf(hex, "%2.2x", byte);
+      line[max+max/4+3+2*pos+offset] = hex[0];
+      line[max+max/4+4+2*pos+offset] = hex[1];
+      pos++;
+    }
+
+    if (pos > 0) printf("%8.8x  %s\n", size-pos, line);
+    printf("\n");
+          
+  } while (ReadHeader());
+}