//----------------------------------------------------------------------------- // May 2006 T.Kuhr: SAM STNTUPLE input module //----------------------------------------------------------------------------- #include "TChain.h" #include "TFile.h" #include "diskcache_i/TSam.hh" #include "Stntuple/obj/TStnEvent.hh" #include "Stntuple/loop/TStnSamInputModule.hh" ClassImp(TStnSamInputModule) //_____________________________________________________________________________ TStnSamInputModule::TStnSamInputModule(const char* dataset): TStnRun2InputModule(), fSam(new TSam(dataset)), fOffset(-1) { SetName("SamInputModule"); SetTitle("SAM Input module"); fChain = new TChain("STNTUPLE"); } //_____________________________________________________________________________ TStnSamInputModule::~TStnSamInputModule() { delete fSam; delete fChain; } //_____________________________________________________________________________ Int_t TStnSamInputModule::RegisterInputBranches(TStnEvent* Event) { if (!OpenNextFile()) return -1; return TStnRun2InputModule::RegisterInputBranches(Event); } //_____________________________________________________________________________ Double_t TStnSamInputModule::GetEntries() { Warning("GetEntries", "The total number of entries in unknown because of sequential file access"); return 99999999; } //_____________________________________________________________________________ Int_t TStnSamInputModule::NextEvent(Int_t IEntry) { if (!fSam || !fChain) return -5; if (fOffset < 0) { SetBranches(); fOffset = 0; } Int_t entry = IEntry - fOffset; if (entry < 0) { Error("NextEvent", "Can not go back in sequential file access"); return -5; } while (entry >= fChain->GetEntries()) { fOffset += (Int_t)fChain->GetEntries(); entry = IEntry - fOffset; if (!OpenNextFile()) return -5; } fChain->LoadTree(entry); GetEvent()->SetCurrentEntry(IEntry); GetEvent()->SetCurrentTreeEntry(entry); return entry; } //_____________________________________________________________________________ Bool_t TStnSamInputModule::OpenNextFile() { delete fChain; fChain = new TChain("STNTUPLE"); if (!fSam) return false; TFile* file = fSam->OpenNextFile(); if (!file) return false; fChain->Add(file->GetName()); if (fOffset >= 0) SetBranches(); return true; }