]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderChain.cxx
Coverity fix (an obsolete constructor removed)
[u/mrichter/AliRoot.git] / RAW / AliRawReaderChain.cxx
index 0739551e8f036d1d239688be350b0bf158a9ce72..4663bd625864107bacaeb26015c2578335cfd442 100644 (file)
 
 #include <TChain.h>
 #include <TFileCollection.h>
+#include <TEntryList.h>
+#include "TGridCollection.h"
+#include <TPluginManager.h>
+#include <TROOT.h>
+#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)
 
@@ -39,22 +48,102 @@ AliRawReaderChain::AliRawReaderChain() :
   // default constructor
 }
 
-AliRawReaderChain::AliRawReaderChain(const char* listFileName) :
+AliRawReaderChain::AliRawReaderChain(const char* fileName) :
   AliRawReaderRoot(),
   fChain(NULL)
 {
 // create raw-reader objects which takes as an input a root chain
-// from the file list found in 'listFileName'
-
-  TFileCollection collection("RAW",
-                            "Collection with raw-data files",
-                            listFileName);
+// either from the file list found in 'fileName' (IsCollection = true)
+// or from entry list found in 'filename' (IsCollection = false)
+// The entry-list syntax follows root convetion: filename.root/listname
 
   fChain = new TChain("RAW");
-  if (!fChain->AddFileInfoList((TCollection*)(collection.GetList()))) {
-    Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
-    fIsValid = kFALSE;
-    return;
+
+  TString fileNameStr = fileName;
+  if (fileNameStr.EndsWith(".xml")) {
+
+    TGridCollection *collection = NULL;
+    TPluginManager* pluginManager = gROOT->GetPluginManager();
+    TPluginHandler* pluginHandler = pluginManager->FindHandler("TGridCollection", "alice");
+    if (!pluginHandler) {
+      pluginManager->AddHandler("TGridCollection", "alice", 
+                               "AliXMLCollection", "ANALYSISalice", "AliXMLCollection(const char*)");
+      pluginHandler = pluginManager->FindHandler("TGridCollection", "alice");
+    }
+    gSystem->Load("libANALYSIS");
+    if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
+      collection = (TGridCollection*)pluginHandler->ExecPlugin(1,fileNameStr.Data());
+    }
+    else {
+      fIsValid = kFALSE;
+      return;
+    }
+    collection->Reset();
+    Bool_t elistsExist = kFALSE;
+    TEntryList *elist = new TEntryList();
+    while (collection->Next()) {
+      fChain->Add(collection->GetTURL(""));
+      TEntryList *list = (TEntryList *)collection->GetEntryList("");
+      if (list) {
+       list->SetTreeName("RAW");
+       list->SetFileName(collection->GetTURL(""));
+       elist->Add(list);
+       elistsExist = kTRUE;
+      }
+    }
+    if (elistsExist) {
+      fChain->SetEntryList(elist,"ne");
+    }
+    else {
+      Info("AliRawReaderChain", "no entry lists found in %s. Using all entries", fileNameStr.Data());
+      delete elist;
+    }
+  }
+  else if (fileNameStr.EndsWith(".root")) {
+
+    TDirectory* dir = gDirectory;
+    TFile *listFile = TFile::Open(fileNameStr.Data());
+    dir->cd();
+    if (!listFile || !listFile->IsOpen()) {
+      Error("AliRawReaderChain", "could not open file %s", fileNameStr.Data());
+      fIsValid = kFALSE;
+      return;
+    }
+
+    TEntryList *elist = NULL;
+    TKey *key = NULL;
+    TIter nextkey(listFile->GetListOfKeys());
+    while ((key=(TKey*)nextkey())){
+      if (strcmp("TEntryList", key->GetClassName())==0){
+        elist = (TEntryList*)key->ReadObj();
+      }
+    }
+    if (!elist) {
+      Error("AliRawReaderChain", "no TEntryList found in %s", fileNameStr.Data());
+      fIsValid = kFALSE;
+      return;
+    }
+
+    TEntryList *templist = NULL;
+    TList *elists = elist->GetLists();
+    TIter next(elists);
+    while((templist = (TEntryList*)next())){
+      Info("AliRawReaderChain", "%s added to the chain", templist->GetFileName());
+      fChain->Add(templist->GetFileName());
+    }
+    fChain->SetEntryList(elist,"ne");
+  }
+  else {
+
+    TFileCollection collection("RAW",
+                              "Collection with raw-data files",
+                              fileNameStr.Data());
+
+    if (!fChain->AddFileInfoList((TCollection*)(collection.GetList()))) {
+      Error("AliRawReaderChain","Bad file list in collection, the chain is empty");
+      fIsValid = kFALSE;
+      return;
+    }
   }
 
   fChain->SetBranchStatus("*",1);
@@ -86,12 +175,83 @@ AliRawReaderChain::AliRawReaderChain(TChain *chain) :
 // create raw-reader objects which takes as an input a root chain
 // from a root file collection
 
-  if (!fChain) fIsValid = kFALSE;
+  if (!fChain) {
+    fIsValid = kFALSE;
+    return;
+  }
+
+  fChain->SetBranchStatus("*",1);
+  fChain->SetBranchAddress("rawevent",&fEvent,&fBranch);
+}
+
+AliRawReaderChain::AliRawReaderChain(TEntryList *elist) :
+  AliRawReaderRoot(),
+  fChain(NULL)
+{
+// create raw-reader objects which takes as an input a root chain
+// from a root file collection
+
+  if (!elist) {
+    fIsValid = kFALSE;
+    return;
+  }
+
+  fChain = new TChain("RAW");
+
+  TEntryList *templist = NULL;
+  TList *elists = elist->GetLists();
+  TIter next(elists);
+  while((templist = (TEntryList*)next())){
+    fChain->Add(templist->GetFileName());
+  }
+  fChain->SetEntryList(elist,"ne");
 
   fChain->SetBranchStatus("*",1);
   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)
@@ -127,12 +287,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++;
@@ -145,7 +307,8 @@ Bool_t AliRawReaderChain::RewindEvents()
 
   fEventIndex = -1;
   delete fEvent;
-  fEvent = new AliRawEvent;
+  fEvent = NULL;
+  fEventHeader = NULL;
   fEventNumber = -1;
   return Reset();
 }
@@ -159,12 +322,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();