]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderRoot.cxx
Delete AliRawEvent before taking the next one. The problem caused huge memory leak...
[u/mrichter/AliRoot.git] / RAW / AliRawReaderRoot.cxx
index c963e33b851f90b930b9436624721eafc73beb31..71aabc0b3f4cb4ab74781d85a19760f499d16bfa 100644 (file)
@@ -32,7 +32,8 @@
 #include <TTree.h>
 #include "AliRawReaderRoot.h"
 #include "AliRawEvent.h"
-#include "AliRawEventHeader.h"
+#include "AliRawEventHeaderBase.h"
+#include "AliRawEquipment.h"
 #include "AliRawEquipmentHeader.h"
 #include "AliRawData.h"
 
@@ -47,6 +48,8 @@ AliRawReaderRoot::AliRawReaderRoot(const char* fileName, Int_t eventNumber) :
   fEvent(NULL),
   fSubEventIndex(0),
   fSubEvent(NULL),
+  fEquipmentIndex(0),
+  fEquipment(NULL),
   fRawData(NULL),
   fPosition(NULL),
   fEnd(NULL)
@@ -89,6 +92,8 @@ AliRawReaderRoot::AliRawReaderRoot(AliRawEvent* event) :
   fEvent(event),
   fSubEventIndex(0),
   fSubEvent(NULL),
+  fEquipmentIndex(0),
+  fEquipment(NULL),
   fRawData(NULL),
   fPosition(NULL),
   fEnd(NULL)
@@ -105,6 +110,8 @@ AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
   fEvent(NULL),
   fSubEventIndex(rawReader.fSubEventIndex),
   fSubEvent(NULL),
+  fEquipmentIndex(rawReader.fEquipmentIndex),
+  fEquipment(NULL),
   fRawData(NULL),
   fPosition(NULL),
   fEnd(NULL)
@@ -146,7 +153,8 @@ AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
 
   if (fSubEventIndex > 0) {
     fSubEvent = fEvent->GetSubEvent(fSubEventIndex-1);
-    fRawData = fSubEvent->GetRawData();
+    fEquipment = fSubEvent->GetEquipment(fEquipmentIndex);
+    fRawData = fEquipment->GetRawData();
       fCount = 0;
     fHeader = (AliRawDataHeader*) ((UChar_t*) fRawData->GetBuffer() + 
       ((UChar_t*) rawReader.fHeader - 
@@ -184,7 +192,7 @@ UInt_t AliRawReaderRoot::GetType() const
 // get the type from the event header
 
   if (!fEvent) return 0;
-  return fEvent->GetHeader()->GetType();
+  return fEvent->GetHeader()->Get("Type");
 }
 
 UInt_t AliRawReaderRoot::GetRunNumber() const
@@ -192,7 +200,7 @@ UInt_t AliRawReaderRoot::GetRunNumber() const
 // get the run number from the event header
 
   if (!fEvent) return 0;
-  return fEvent->GetHeader()->GetRunNumber();
+  return fEvent->GetHeader()->Get("RunNb");
 }
 
 const UInt_t* AliRawReaderRoot::GetEventId() const
@@ -200,7 +208,7 @@ const UInt_t* AliRawReaderRoot::GetEventId() const
 // get the event id from the event header
 
   if (!fEvent) return NULL;
-  return fEvent->GetHeader()->GetId();
+  return fEvent->GetHeader()->GetP("Id");
 }
 
 const UInt_t* AliRawReaderRoot::GetTriggerPattern() const
@@ -208,7 +216,7 @@ const UInt_t* AliRawReaderRoot::GetTriggerPattern() const
 // get the trigger pattern from the event header
 
   if (!fEvent) return NULL;
-  return fEvent->GetHeader()->GetTriggerPattern();
+  return fEvent->GetHeader()->GetP("TriggerPattern");
 }
 
 const UInt_t* AliRawReaderRoot::GetDetectorPattern() const
@@ -216,7 +224,7 @@ const UInt_t* AliRawReaderRoot::GetDetectorPattern() const
 // get the detector pattern from the event header
 
   if (!fEvent) return NULL;
-  return fEvent->GetHeader()->GetDetectorPattern();
+  return fEvent->GetHeader()->GetP("DetectorPattern");
 }
 
 const UInt_t* AliRawReaderRoot::GetAttributes() const
@@ -224,15 +232,23 @@ const UInt_t* AliRawReaderRoot::GetAttributes() const
 // get the type attributes from the event header
 
   if (!fEvent) return NULL;
-  return fEvent->GetHeader()->GetTypeAttribute();
+  return fEvent->GetHeader()->GetP("TypeAttribute");
+}
+
+const UInt_t* AliRawReaderRoot::GetSubEventAttributes() const
+{
+// get the type attributes from the sub event header
+
+  if (!fSubEvent) return NULL;
+  return fSubEvent->GetHeader()->GetP("TypeAttribute");
 }
 
 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();
+  if (!fEvent || !fSubEvent) return 0;
+  return fSubEvent->GetHeader()->Get("LdcId");
 }
 
 UInt_t AliRawReaderRoot::GetGDCId() const
@@ -240,7 +256,7 @@ UInt_t AliRawReaderRoot::GetGDCId() const
 // get the GDC Id from the event header
 
   if (!fEvent) return 0;
-  return fEvent->GetHeader()->GetGDCId();
+  return fEvent->GetHeader()->Get("GdcId");
 }
 
 
@@ -248,40 +264,48 @@ Int_t AliRawReaderRoot::GetEquipmentSize() const
 {
 // get the size of the equipment
 
-  if (!fEvent || !fEvent->GetEquipmentHeader()) return 0;
-  return fEvent->GetEquipmentHeader()->GetEquipmentSize();
+  if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return 0;
+  return fEquipment->GetEquipmentHeader()->GetEquipmentSize();
 }
 
 Int_t AliRawReaderRoot::GetEquipmentType() const
 {
 // get the type from the equipment header
 
-  if (!fEvent || !fEvent->GetEquipmentHeader()) return -1;
-  return fEvent->GetEquipmentHeader()->GetEquipmentType();
+  if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return -1;
+  return fEquipment->GetEquipmentHeader()->GetEquipmentType();
 }
 
 Int_t AliRawReaderRoot::GetEquipmentId() const
 {
 // get the ID from the equipment header
 
-  if (!fEvent || !fEvent->GetEquipmentHeader()) return -1;
-  return fEvent->GetEquipmentHeader()->GetId();
+  if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return -1;
+  return fEquipment->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();
+  if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return NULL;
+  return fEquipment->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();
+  if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return 0;
+  return fEquipment->GetEquipmentHeader()->GetBasicSizeType();
+}
+
+Int_t AliRawReaderRoot::GetEquipmentHeaderSize() const
+{
+// get the size of the equipment header (28 bytes by default)
+
+  if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return 0;
+  return fEquipment->GetEquipmentHeader()->HeaderSize();
 }
 
 
@@ -297,61 +321,86 @@ Bool_t AliRawReaderRoot::ReadHeader()
     // 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)) {
 
-      // check for end of event data
-      if (fSubEventIndex >= fEvent->GetNSubEvents()) return kFALSE;
-      fSubEvent = fEvent->GetSubEvent(fSubEventIndex++);
+      // get the first or the next sub event if at the end of a sub event
+      if (!fSubEvent || (fEquipmentIndex >= fSubEvent->GetNEquipments())) {
 
-      // 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;
+       // 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;
+       }
+
+       fEquipmentIndex = 0;
+       fEquipment = NULL;
+       fRawData = NULL;
       }
 
-      fRawData = fSubEvent->GetRawData();
+      // get the next equipment and raw data
       fCount = 0;
+      fEquipment = fSubEvent->GetEquipment(fEquipmentIndex++);
+      if (!fEquipment) continue;
+      fRawData = fEquipment->GetRawData();
+      if (!fRawData) {
+       fPosition = fEnd;
+       continue;
+      }
       fPosition = (UChar_t*) fRawData->GetBuffer();
       fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
     }
 
-    // continue with the next sub event if no data left in the payload
+    // continue with the next equipment 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;
+    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!");
+       Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
+       fEquipment->GetEquipmentHeader()->Dump();
+       fCount = 0;
+       fPosition = fEnd;
+       fErrorCode = kErrNoDataHeader;
+       continue;
+      }
+
+      // "read" the data header
+      fHeader = (AliRawDataHeader*) fPosition;
+      if ((fPosition + fHeader->fSize) != fEnd) {
+       Warning("ReadHeader",
+               "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
+               fHeader->fSize, fEnd - fPosition);
+       fHeader->fSize = fEnd - fPosition;
+      }
+      fPosition += sizeof(AliRawDataHeader);
     }
 
-    // "read" the data header
-    fHeader = (AliRawDataHeader*) fPosition;
-    fPosition += sizeof(AliRawDataHeader);
-    if (fHeader->fSize != 0xFFFFFFFF) {
+    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", fEnd - fPosition);
+       fEquipment->GetEquipmentHeader()->Dump();
+       fCount = 0;
+       fPosition = fEnd;
+       fErrorCode = kErrSize;
+       continue;
+      }
+
     } 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;
@@ -396,6 +445,8 @@ Bool_t AliRawReaderRoot::Reset()
 
   fSubEventIndex = 0;
   fSubEvent = NULL;
+  fEquipmentIndex = 0;
+  fEquipment = NULL;
   fRawData = NULL;
   fHeader = NULL;
 
@@ -412,12 +463,11 @@ Bool_t AliRawReaderRoot::NextEvent()
   if (!fFile) return kFALSE;
 
   do {
-    if (fBranch->GetEntry(fEventIndex+1) <= 0) {
-      delete fEvent;
-      fEvent = new AliRawEvent;
-      fBranch->SetAddress(&fEvent);
+    delete fEvent;
+    fEvent = new AliRawEvent;
+    fBranch->SetAddress(&fEvent);
+    if (fBranch->GetEntry(fEventIndex+1) <= 0)
       return kFALSE;
-    }
     fEventIndex++;
   } while (!IsEventSelected());
   return Reset();
@@ -445,13 +495,15 @@ Int_t AliRawReaderRoot::CheckData() const
 
   AliRawEvent* subEvent = NULL;
   Int_t subEventIndex = 0;
+  AliRawEquipment* equipment = NULL;
+  Int_t equipmentIndex = 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)) {
+    // get the first or the next sub event if at the end of an equipment
+    if (!subEvent || (equipmentIndex >= subEvent->GetNEquipments())) {
 
       // check for end of event data
       if (subEventIndex >= fEvent->GetNSubEvents()) return result;
@@ -463,33 +515,38 @@ Int_t AliRawReaderRoot::CheckData() const
        return result;
       }
 
-      AliRawData* rawData = subEvent->GetRawData();
-      position = (UChar_t*) rawData->GetBuffer();
-      end = ((UChar_t*) rawData->GetBuffer()) + rawData->GetSize();
+      equipmentIndex = 0;
     }
 
+    // get the next equipment and raw data
+    equipment = subEvent->GetEquipment(equipmentIndex++);
+    if (!equipment) continue;
+    AliRawData* rawData = equipment->GetRawData();
+    if (!rawData) continue;
+    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;
 
+    if (fRequireHeader) {
     // check that there are enough bytes left for the data header
-    if (position + sizeof(AliRawDataHeader) > end) {
-      result |= kErrNoDataHeader;
-      position = end;
-      continue;
-    }
+      if (position + sizeof(AliRawDataHeader) > end) {
+       result |= kErrNoDataHeader;
+       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) {
+      // check consistency of data size in the header and in the equipment
+      AliRawDataHeader* header = (AliRawDataHeader*) position;
+      if ((position + header->fSize) != end) {
+       Warning("ReadHeader",
+               "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
+               header->fSize, end - position);
+       header->fSize = end - position;
        result |= kErrSize;
-       position = end;
-      } else {
-       position += header->fSize;
       }
-    } else {
-      position = end;
     }
+    position = end;
   };
 
   return result;