]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderChain.cxx
Bug fix in copying object and improved documentation.
[u/mrichter/AliRoot.git] / RAW / AliRawReaderChain.cxx
index 17e59f54b0e521213ee467fca3fe1e637d5e4109..33b6953f84b3d0bbe6c0c68a3ae7952e40737f37 100644 (file)
 #include <TSystem.h>
 #include <TFile.h>
 #include <TKey.h>
+#include <TGrid.h>
+#include <TGridResult.h>
 
 #include "AliRawReaderChain.h"
-#include "AliRawEvent.h"
+#include "AliRawVEvent.h"
 
 ClassImp(AliRawReaderChain)
 
@@ -202,6 +204,48 @@ AliRawReaderChain::AliRawReaderChain(TEntryList *elist) :
   fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
 }
 
+AliRawReaderChain::AliRawReaderChain(Int_t runNumber) :
+  AliRawReaderRoot(),
+  fChain(NULL)
+{
+// create raw-reader objects which takes as an input a root chain
+// with the raw-data files for a given run
+// It queries alien FC in order to do that and therefore
+// it needs alien API to be enabled
+
+  if (runNumber <= 0) {
+    Error("AliRawReaderChain","Bad run number:%d",runNumber);
+    fIsValid = kFALSE;
+  }
+
+  if (!gGrid) TGrid::Connect("alien://");
+  if (!gGrid) {
+    fIsValid = kFALSE;
+    return;
+  }
+
+  TGridResult *res = gGrid->Query("/alice/data",Form("%09d/raw/*%09d*0.root",runNumber,runNumber));
+  Int_t nFiles = res->GetEntries();
+  if (!nFiles) {
+    Error("AliRawReaderChain","No raw-data files found for run %d",runNumber);
+    fIsValid = kFALSE;
+    delete res;
+    return;
+  }
+
+  fChain = new TChain("RAW");
+  for (Int_t i = 0; i < nFiles; i++) {
+    TString filename = res->GetKey(i, "turl");
+    if(filename == "") continue;
+    fChain->Add(filename.Data());
+  }
+  delete res;
+
+  fChain->SetBranchStatus("*",1);
+  fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
+}
+
+
 AliRawReaderChain::AliRawReaderChain(const AliRawReaderChain& rawReader) :
   AliRawReaderRoot(rawReader),
   fChain(rawReader.fChain)
@@ -237,12 +281,14 @@ Bool_t AliRawReaderChain::NextEvent()
 
   do {
     delete fEvent;
-    fEvent = new AliRawEvent;
+    fEvent = NULL;
+    fEventHeader = NULL;
     Long64_t treeEntry = fChain->LoadTree(fEventIndex+1);
     if (!fBranch)
       return kFALSE;
     if (fBranch->GetEntry(treeEntry) <= 0)
       return kFALSE;
+    fEventHeader = fEvent->GetHeader();
     fEventIndex++;
   } while (!IsEventSelected());
   fEventNumber++;
@@ -255,7 +301,8 @@ Bool_t AliRawReaderChain::RewindEvents()
 
   fEventIndex = -1;
   delete fEvent;
-  fEvent = new AliRawEvent;
+  fEvent = NULL;
+  fEventHeader = NULL;
   fEventNumber = -1;
   return Reset();
 }
@@ -269,12 +316,14 @@ Bool_t  AliRawReaderChain::GotoEvent(Int_t event)
   if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE;
 
   delete fEvent;
-  fEvent = new AliRawEvent;
+  fEvent = NULL;
+  fEventHeader = NULL;
   Long64_t treeEntry = fChain->LoadTree(event);
    if (!fBranch)
     return kFALSE;
   if (fBranch->GetEntry(treeEntry) <= 0)
     return kFALSE;
+  fEventHeader = fEvent->GetHeader();
   fEventIndex = event;
   fEventNumber++;
   return Reset();