/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 #include "RidxHandler.h" 00002 #include "TFile.h" 00003 00004 RidxHandler::RidxHandler(const std::vector<std::string>& ridxs) 00005 : m_fcount(-1), 00006 m_count(-1), 00007 m_max(0), 00008 m_entry(0) 00009 { 00010 m_chain = new TChain("EvtIdx", "EvtIdx"); 00011 for ( std::vector<std::string>::const_iterator it = ridxs.begin(); it != ridxs.end(); ++it ) { 00012 m_chain->AddFile(it->c_str()); 00013 } 00014 std::string* fname = 0; 00015 int nEvt; 00016 m_chain->SetBranchStatus("entry", 0); 00017 m_chain->SetBranchAddress("fname", &fname); 00018 m_chain->SetBranchAddress("nEvt", &nEvt); 00019 00020 Long64_t nfiles = m_chain->GetEntries(); 00021 m_offset = new Long64_t[nfiles+1]; 00022 m_offset[0] = 0; 00023 00024 for ( Long64_t i = 0; i < nfiles; ++i ) { 00025 m_chain->GetEntry(i); 00026 m_max += nEvt; 00027 m_offset[i+1] = m_max; 00028 m_roots.push_back(*fname); 00029 } 00030 00031 m_chain->SetBranchStatus("*", 0); 00032 m_chain->SetBranchStatus("entry", 1); 00033 m_chain->SetBranchAddress("entry", &m_entry); 00034 } 00035 00036 RidxHandler::~RidxHandler() 00037 { 00038 delete m_chain->GetCurrentFile(); 00039 delete [] m_offset; 00040 } 00041 00042 bool RidxHandler::seek(int n) 00043 { 00044 m_count = n; 00045 if ( m_count >= m_max ) return false; 00046 00047 bool nextfile = false; 00048 while ( m_count >= m_offset[m_fcount+1] ) { 00049 ++m_fcount; 00050 nextfile = true; 00051 } 00052 00053 if ( nextfile ) { 00054 m_chain->GetEntry(m_fcount); 00055 } 00056 00057 return true; 00058 } 00059 00060 Int_t RidxHandler::fIndex() 00061 { 00062 return m_fcount; 00063 } 00064 00065 Long64_t RidxHandler::eIndex() 00066 { 00067 return m_entry->at( m_count - m_offset[m_fcount] ); 00068 }