X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=RAW%2FAliRawReaderChain.cxx;h=33b6953f84b3d0bbe6c0c68a3ae7952e40737f37;hb=5b2e5faeb0218a2fa5ac178e2a61ac6d56cab371;hp=da665f24f126d925997768f75bb516b69aef3d4e;hpb=25e82ff56cdbe602c28052ed1f9844e086d6468e;p=u%2Fmrichter%2FAliRoot.git diff --git a/RAW/AliRawReaderChain.cxx b/RAW/AliRawReaderChain.cxx index da665f24f12..33b6953f84b 100644 --- a/RAW/AliRawReaderChain.cxx +++ b/RAW/AliRawReaderChain.cxx @@ -26,9 +26,18 @@ #include #include +#include +#include "TGridCollection.h" +#include +#include +#include +#include +#include +#include +#include #include "AliRawReaderChain.h" -#include "AliRawEvent.h" +#include "AliRawVEvent.h" ClassImp(AliRawReaderChain) @@ -39,27 +48,106 @@ 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"); - 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 { - fChain->SetBranchStatus("*",1); + TFileCollection collection("RAW", + "Collection with raw-data files", + fileNameStr.Data()); - fEvent = new AliRawEvent; - fChain->SetBranchAddress("rawevent", &fEvent); + if (!fChain->AddFileInfoList((TCollection*)(collection.GetList()))) { + Error("AliRawReaderChain","Bad file list in collection, the chain is empty"); + fIsValid = kFALSE; + return; + } + } + + fChain->SetBranchStatus("*",1); + fChain->SetBranchAddress("rawevent",&fEvent,&fBranch); } AliRawReaderChain::AliRawReaderChain(TFileCollection *collection) : @@ -72,13 +160,12 @@ AliRawReaderChain::AliRawReaderChain(TFileCollection *collection) : fChain = new TChain("RAW"); if (!fChain->AddFileInfoList((TCollection*)(collection->GetList()))) { Error("AliRawReaderChain","Bad file list in collection, the chain is empty"); + fIsValid = kFALSE; return; } fChain->SetBranchStatus("*",1); - - fEvent = new AliRawEvent; - fChain->SetBranchAddress("rawevent", &fEvent); + fChain->SetBranchAddress("rawevent",&fEvent,&fBranch); } AliRawReaderChain::AliRawReaderChain(TChain *chain) : @@ -88,12 +175,77 @@ 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; + + 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; + + 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; + } - fEvent = new AliRawEvent; - fChain->SetBranchAddress("rawevent", &fEvent); + 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) @@ -129,12 +281,14 @@ Bool_t AliRawReaderChain::NextEvent() do { delete fEvent; - fEvent = new AliRawEvent; - TBranch *branch = fChain->GetBranch("rawevent"); - if (!branch) + fEvent = NULL; + fEventHeader = NULL; + Long64_t treeEntry = fChain->LoadTree(fEventIndex+1); + if (!fBranch) return kFALSE; - if (branch->GetEntry(fEventIndex+1) <= 0) + if (fBranch->GetEntry(treeEntry) <= 0) return kFALSE; + fEventHeader = fEvent->GetHeader(); fEventIndex++; } while (!IsEventSelected()); fEventNumber++; @@ -147,7 +301,8 @@ Bool_t AliRawReaderChain::RewindEvents() fEventIndex = -1; delete fEvent; - fEvent = new AliRawEvent; + fEvent = NULL; + fEventHeader = NULL; fEventNumber = -1; return Reset(); } @@ -161,12 +316,14 @@ Bool_t AliRawReaderChain::GotoEvent(Int_t event) if (!fChain || !fChain->GetListOfFiles()->GetEntriesFast()) return kFALSE; delete fEvent; - fEvent = new AliRawEvent; - TBranch *branch = fChain->GetBranch("rawevent"); - if (!branch) + fEvent = NULL; + fEventHeader = NULL; + Long64_t treeEntry = fChain->LoadTree(event); + if (!fBranch) return kFALSE; - if (branch->GetEntry(event) <= 0) + if (fBranch->GetEntry(treeEntry) <= 0) return kFALSE; + fEventHeader = fEvent->GetHeader(); fEventIndex = event; fEventNumber++; return Reset();