]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderRoot.cxx
comment printf
[u/mrichter/AliRoot.git] / RAW / AliRawReaderRoot.cxx
index 6cd69416364f7416310588ec3ea34f3902afe7df..86c9bc17139dcf0d2583e8a367a3f6453758d475 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <TFile.h>
 #include <TTree.h>
+#include <TTreeIndex.h>
 #include "AliRawReaderRoot.h"
 #include "AliRawVEvent.h"
 #include "AliRawEventHeaderBase.h"
@@ -39,6 +40,8 @@
 
 
 ClassImp(AliRawReaderRoot)
+Bool_t AliRawReaderRoot::fgUseOrder = kFALSE;
+
 
 AliRawReaderRoot::AliRawReaderRoot() :
   fFile(NULL),
@@ -52,7 +55,8 @@ AliRawReaderRoot::AliRawReaderRoot() :
   fEquipment(NULL),
   fRawData(NULL),
   fPosition(NULL),
-  fEnd(NULL)
+  fEnd(NULL),
+  fIndex(0x0)
 {
 // default constructor
 
@@ -70,7 +74,8 @@ AliRawReaderRoot::AliRawReaderRoot(const char* fileName, Int_t eventNumber) :
   fEquipment(NULL),
   fRawData(NULL),
   fPosition(NULL),
-  fEnd(NULL)
+  fEnd(NULL),
+  fIndex(0x0)
 {
 // create an object to read digits from the given input file for the
 // event with the given number
@@ -119,7 +124,8 @@ AliRawReaderRoot::AliRawReaderRoot(AliRawVEvent* event) :
   fEquipment(NULL),
   fRawData(NULL),
   fPosition(NULL),
-  fEnd(NULL)
+  fEnd(NULL),
+  fIndex(0x0)
 {
 // create an object to read digits from the given raw event
   if (!fEvent) fIsValid = kFALSE;
@@ -138,7 +144,8 @@ AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
   fEquipment(NULL),
   fRawData(NULL),
   fPosition(NULL),
-  fEnd(NULL)
+  fEnd(NULL),
+  fIndex(0x0)
 {
 // copy constructor
 
@@ -428,7 +435,7 @@ Bool_t AliRawReaderRoot::ReadHeader()
       // 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);
+       Warning("ReadHeader", "skipping %ld bytes", fEnd - fPosition);
        fEquipment->GetEquipmentHeader()->Dump();
        fCount = 0;
        fPosition = fEnd;
@@ -445,7 +452,7 @@ Bool_t AliRawReaderRoot::ReadHeader()
       if ((fPosition + fHeader->fSize) != fEnd) {
        if (fHeader->fSize != 0xFFFFFFFF)
          Warning("ReadHeader",
-                 "Equipment %d : raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
+                 "Equipment %d : raw data size found in the header is wrong (%d != %ld)! Using the equipment size instead !",
                  fEquipment->GetEquipmentHeader()->GetId(),fHeader->fSize, fEnd - fPosition);
        fHeader->fSize = fEnd - fPosition;
       }
@@ -458,7 +465,7 @@ Bool_t AliRawReaderRoot::ReadHeader()
       // 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);
+       Warning("ReadHeader", "skipping %ld bytes", fEnd - fPosition);
        fEquipment->GetEquipmentHeader()->Dump();
        fCount = 0;
        fPosition = fEnd;
@@ -532,12 +539,20 @@ Bool_t AliRawReaderRoot::NextEvent()
 
   if (!fBranch) return kFALSE;
 
+  // check if it uses order or not
+  if (fgUseOrder && !fIndex) MakeIndex();
+
   do {
     delete fEvent;
     fEvent = NULL;
     fEventHeader = NULL;
     fBranch->SetAddress(&fEvent);
-    if (fBranch->GetEntry(fEventIndex+1) <= 0)
+    Int_t entryToGet = fEventIndex + 1;
+    if (fgUseOrder 
+       && fIndex 
+       && entryToGet<fBranch->GetEntries()
+       && entryToGet>-1 ) entryToGet = fIndex[entryToGet];
+    if (fBranch->GetEntry(entryToGet) <= 0)
       return kFALSE;
     fEventHeader = fEvent->GetHeader();
     fEventIndex++;
@@ -569,11 +584,19 @@ Bool_t  AliRawReaderRoot::GotoEvent(Int_t event)
 
   if (!fBranch) return kFALSE;
 
+  // check if it uses order or not
+  if (fgUseOrder && !fIndex) MakeIndex();
+
   delete fEvent;
   fEvent = NULL;
   fEventHeader = NULL;
   fBranch->SetAddress(&fEvent);
-  if (fBranch->GetEntry(event) <= 0)
+  Int_t entryToGet = event;
+  if (fgUseOrder 
+      && fIndex 
+      && entryToGet<fBranch->GetEntries()
+      && entryToGet>-1 ) entryToGet = fIndex[entryToGet];
+  if (fBranch->GetEntry(entryToGet) <= 0)
     return kFALSE;
   fEventHeader = fEvent->GetHeader();
   fEventIndex = event;
@@ -649,7 +672,7 @@ Int_t AliRawReaderRoot::CheckData() const
       if ((position + header->fSize) != end) {
        if (header->fSize != 0xFFFFFFFF)
          Warning("ReadHeader",
-                 "Equipment %d : raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
+                 "Equipment %d : raw data size found in the header is wrong (%d != %ld)! Using the equipment size instead !",
                  equipment->GetEquipmentHeader()->GetId(),header->fSize, end - position);
        header->fSize = end - position;
        result |= kErrSize;
@@ -669,17 +692,35 @@ AliRawReader* AliRawReaderRoot::CloneSingleEvent() const
   // access to the current raw data within
   // several threads (online event display/reco)
 
-  if (GetEvent()) {
+  if (fEvent) {
     // Root formatted raw data
-    AliRawVEvent *gdcRootEvent = (AliRawVEvent*) GetEvent()->Clone();
+    AliRawVEvent *gdcRootEvent = (AliRawVEvent*)fEvent->Clone();
     for (Int_t ldcCounter=0; ldcCounter < gdcRootEvent->GetNSubEvents(); ldcCounter++) {
       AliRawVEvent *ldcRootEvent = gdcRootEvent->GetSubEvent(ldcCounter);
+      AliRawVEvent *subEvent = fEvent->GetSubEvent(ldcCounter);
       for (Int_t eqCounter=0; eqCounter < ldcRootEvent->GetNEquipments(); eqCounter++) {
        AliRawVEquipment *equipment=ldcRootEvent->GetEquipment(eqCounter);
-       equipment->CloneRawData();
+       AliRawVEquipment *eq = subEvent->GetEquipment(eqCounter);
+       equipment->CloneRawData(eq->GetRawData());
       }
     }
+    // Reset original event and newly
+    // produced one
+    gdcRootEvent->GetSubEvent(-1);
+    fEvent->GetSubEvent(-1);
     return new AliRawReaderRoot(gdcRootEvent);
   }
   return NULL;
 }
+
+void AliRawReaderRoot::MakeIndex() {
+  // Make index
+  if (fBranch) {
+    TTree * rawTree = fBranch->GetTree();
+    if (rawTree) {
+      rawTree->BuildIndex("-fEvtHdrs[0].fSize"); // Minus sign to get largest first
+      TTreeIndex * treeInd = (TTreeIndex*)rawTree->GetTreeIndex();
+      if (treeInd) fIndex = treeInd->GetIndex();
+    }
+  }
+}