#include <RootInputStream.h>
Inheritance diagram for RootInputStream:
Public Member Functions | |
RootInputStream (void *addr, const std::string &treepath, const std::string &branchname) | |
Create stream attached to the pointer at address addr. | |
virtual | ~RootInputStream () |
std::string | path () |
RootIOStream interface:. | |
std::string | filename () |
int | fileNumber () |
int | clID () |
int | getEntry () |
RootInputFileList | getFiles () |
bool | append (const std::string &filename) |
Add another input filename, take treepath from prior files. | |
bool | append (const std::string &filename, const std::string &treepath, const std::string &branchname) |
Add another input filename and treepath with different treepath and branchname. | |
bool | read () |
Read in current entry. | |
bool | setEntry (int entry, bool read=true) |
Set the absolute entry to read. | |
bool | setFileEntry (int file, int entry, bool read=true) |
Set absolute entry in specific file number. | |
bool | next (int steps=1, bool read=true) |
Set entry to entry + steps. | |
bool | prev (int nsteps=1, bool read=true) |
Set entry to entry - steps. | |
bool | first (bool read=true) |
Go to the very first entry. | |
bool | last (bool read=true) |
Go to the very last entry. | |
int | entries () |
Return total number of entries. | |
RootIOBaseObject * | obj () |
Return the pointer that m_addr points to assuming it points to a RootIOBaseObject. | |
Protected Attributes | |
void * | m_addr |
Private Attributes | |
RootInputFileList | m_files |
int | m_entry |
int | m_clid |
int | m_entries |
std::string | m_treepath |
std::string | m_branchname |
Dyb::MsgStreamMember | log |
This allows multiple input files to be chained together for serial reading. The input stream generalized this reading providing linear forward and backward navigation as well as random access.
bv@bnl.gov Sun Jun 29 10:13:17 2008
Definition at line 25 of file RootInputStream.h.
RootInputStream::RootInputStream | ( | void * | addr, | |
const std::string & | treepath, | |||
const std::string & | branchname | |||
) |
Create stream attached to the pointer at address addr.
Definition at line 4 of file RootInputStream.cc.
00007 : RootIOStream(addr) 00008 , m_files() 00009 , m_entry(-1) 00010 , m_clid(0) 00011 , m_entries(-1) 00012 , m_treepath(treepath) 00013 , m_branchname(branchname) 00014 , log("RootInputStream") 00015 { 00016 }
RootInputStream::~RootInputStream | ( | ) | [virtual] |
std::string RootInputStream::path | ( | ) | [virtual] |
RootIOStream interface:.
Implements RootIOStream.
Definition at line 29 of file RootInputStream.cc.
00030 { 00031 return m_treepath; 00032 }
std::string RootInputStream::filename | ( | ) |
Definition at line 34 of file RootInputStream.cc.
00035 { 00036 RootInputFile* rif = m_files.current(); 00037 if (rif) return rif->filename(); 00038 return ""; 00039 }
int RootInputStream::fileNumber | ( | ) |
int RootInputStream::clID | ( | ) |
int RootInputStream::getEntry | ( | ) | [inline] |
RootInputFileList RootInputStream::getFiles | ( | ) | [inline] |
bool RootInputStream::append | ( | const std::string & | filename | ) |
Add another input filename, take treepath from prior files.
Definition at line 46 of file RootInputStream.cc.
00047 { 00048 if ("" == m_treepath || "" == m_branchname) { 00049 log << MSG::ERROR << "Can not guess tree path or branch name for " 00050 << filename << endreq; 00051 return false; 00052 } 00053 00054 int clid = RootInputFile::TestForObject(filename,m_treepath,m_branchname); 00055 if (!clid || (m_clid && clid != m_clid)) { 00056 log << MSG::ERROR << "Bad class ID from new file " << filename 00057 << " got " << clid << " (had " << m_clid << ")" 00058 << endreq; 00059 return false; 00060 } 00061 m_clid = clid; 00062 00063 m_files.push_back(new RootInputFile(filename,m_treepath,m_branchname)); 00064 if (1 == m_files.size()) { 00065 m_files.next(); 00066 } 00067 return true; 00068 }
bool RootInputStream::append | ( | const std::string & | filename, | |
const std::string & | treepath, | |||
const std::string & | branchname | |||
) |
Add another input filename and treepath with different treepath and branchname.
Definition at line 70 of file RootInputStream.cc.
00073 { 00074 if ("" != m_treepath) m_treepath = treepath; 00075 if ("" != m_branchname) m_branchname = branchname; 00076 00077 return append(filename); 00078 }
bool RootInputStream::read | ( | ) |
Read in current entry.
Definition at line 81 of file RootInputStream.cc.
00082 { 00083 RootInputFile* rif = m_files.current(); 00084 if (!rif) { 00085 log << MSG::ERROR << "No current file" << endreq; 00086 return false; 00087 } 00088 00089 int nbytes = 0; 00090 bool ok = rif->read(m_addr,nbytes); 00091 log << MSG::DEBUG << "read() " << nbytes 00092 << " bytes at entry " << m_entry 00093 << " from file \"" << rif->filename() 00094 << "\" to path \"" << this->path() 00095 << endreq; 00096 return ok; 00097 }
bool RootInputStream::setEntry | ( | int | entry, | |
bool | read = true | |||
) |
Set the absolute entry to read.
If read is true read() the entry.
Definition at line 99 of file RootInputStream.cc.
00100 { 00101 int steps = entry - m_entry; 00102 log << MSG::DEBUG << "setEntry(entry="<<entry<<",read="<<read<<") steps = " << steps 00103 << " (stream=\"" << this->path() << "\")" 00104 << endreq; 00105 if (steps < 0) return prev(-steps, read); 00106 if (steps > 0) return next(steps, read); 00107 return true; // no change 00108 }
bool RootInputStream::setFileEntry | ( | int | file, | |
int | entry, | |||
bool | read = true | |||
) |
Set absolute entry in specific file number.
Typically this is not needed but is useful in the case that the file/entry number has been stored for later reference.
book keep to let relative movement still work
Definition at line 110 of file RootInputStream.cc.
00111 { 00112 if (!m_files.jump(file)) { 00113 log << MSG::ERROR 00114 << "jump("<<file<<"): failed" 00115 << endreq; 00116 return false; 00117 } 00118 RootInputFile* rif = m_files.current(); 00119 if (!rif) { 00120 log << MSG::ERROR << "Failed to get current file #" << file << endreq; 00121 return false; 00122 } 00123 if (!rif->setEntry(entry)) { 00124 log << MSG::ERROR << "Failed to set entry " << entry << " on file #" << file << endreq; 00125 return false; 00126 } 00127 00129 int totEntries = m_files.entriesBefore(file); 00130 if (totEntries < 0) { 00131 log << MSG::ERROR << "Failed to get sane number of entries before file#" << file << endreq; 00132 return false; 00133 } 00134 m_entry = totEntries + entry; 00135 log << MSG::DEBUG << "setFileEntry(file="<<file<<",entry="<<entry<<",read="<<read<<") " 00136 << "totEntries=" << totEntries <<" m_entry=" << m_entry 00137 << " (stream=\"" << this->path() 00138 << "\", filename=\"" << rif->filename() << "\")" 00139 << endreq; 00140 00141 if (read) return this->read(); 00142 return true; 00143 00144 }
bool RootInputStream::next | ( | int | steps = 1 , |
|
bool | read = true | |||
) |
Set entry to entry + steps.
If read is true read the resulting entry.
Definition at line 146 of file RootInputStream.cc.
00147 { 00148 RootInputFile* rif = m_files.current(); 00149 00150 if (!rif) { 00151 log << MSG::ERROR << "No files" << endreq; 00152 return false; 00153 } 00154 00155 log << MSG::DEBUG << "next(nsteps="<<nsteps<<",read="<<read<<")" 00156 << " (stream=\"" << this->path() << "\")" 00157 << endreq; 00158 00159 while (nsteps) { 00160 00161 // must leave current file? 00162 if (rif->entry() + nsteps >= rif->entries()) { 00163 00164 // burn what steps current file provides 00165 int jump = rif->entries() - (rif->entry() + 1); 00166 nsteps -= jump; 00167 m_entry += jump; 00168 if (!m_files.next()) { 00169 log << MSG::INFO 00170 << "next(): no more files to go to next:" 00171 << " jump = " << jump 00172 << " nsteps = " << nsteps 00173 << " entry = " << m_entry 00174 << " tentries=" << rif->entries() << endreq; 00175 return false; 00176 } 00177 rif = m_files.current(); 00178 continue; 00179 } 00180 00181 // Current file has enough entries left 00182 rif->next(nsteps); 00183 m_entry += nsteps; 00184 nsteps = 0; 00185 break; 00186 } 00187 log << MSG::DEBUG << "next(): at stream entry " << m_entry 00188 << " (file: " << rif->filename() << " file entry: " << rif->entry() << ")" 00189 << " (stream=\"" << this->path() << "\")" 00190 << endreq; 00191 if (read) return this->read(); 00192 return true; 00193 }
bool RootInputStream::prev | ( | int | nsteps = 1 , |
|
bool | read = true | |||
) |
Set entry to entry - steps.
If read is true read the resulting entry.
Definition at line 195 of file RootInputStream.cc.
00196 { 00197 RootInputFile* rif = m_files.current(); 00198 if (!rif) { 00199 log << MSG::ERROR << "No files yet, cannot go prev" << endreq; 00200 return false; 00201 } 00202 00203 log << MSG::DEBUG << "prev(nsteps="<<nsteps<<",read="<<read<<")" 00204 << " (stream=\"" << this->path() << "\")" 00205 << endreq; 00206 00207 while (nsteps) { 00208 00209 // must leave current file? 00210 if (rif->entry()-nsteps < 0) { 00211 00212 // Burn what steps this file provides 00213 int jump = 1 + rif->entry(); 00214 nsteps -= jump; 00215 m_entry -= jump; 00216 if (!m_files.prev()) { 00217 log << MSG::ERROR << "Already at first file, cannot go prev" 00218 << endreq; 00219 return false; 00220 } 00221 rif = m_files.current(); 00222 rif->ending(); // position file entry at end 00223 continue; 00224 } 00225 00226 // Can stay in current file 00227 rif->prev(nsteps); 00228 m_entry -= nsteps; 00229 nsteps = 0; 00230 break; 00231 } 00232 00233 log << MSG::DEBUG << "prev(): at stream entry " << m_entry 00234 << " (file: " << rif->filename() << " file entry: " << rif->entry() << ")" 00235 << " (stream=\"" << this->path() << "\")" 00236 << endreq; 00237 00238 if (read) return this->read(); 00239 return true; 00240 }
bool RootInputStream::first | ( | bool | read = true |
) |
Go to the very first entry.
Definition at line 243 of file RootInputStream.cc.
00244 { 00245 bool okay = m_files.first(); 00246 if (!okay) { 00247 log << MSG::ERROR << "first(): failed to go to first file in stream" 00248 << endreq; 00249 return false; 00250 } 00251 00252 RootInputFile* rif = m_files.current(); 00253 if (!rif) { 00254 log << MSG::ERROR << "first(): failed to get current file in stream" 00255 << endreq; 00256 return false; 00257 } 00258 00259 okay = rif->beginning(); 00260 if (!okay) return false; 00261 00262 if (read) return this->read(); 00263 return true; 00264 }
bool RootInputStream::last | ( | bool | read = true |
) |
Go to the very last entry.
Definition at line 267 of file RootInputStream.cc.
00268 { 00269 bool okay = m_files.last(); 00270 if (!okay) { 00271 log << MSG::ERROR << "last(): failed to go to last file in stream" 00272 << endreq; 00273 return false; 00274 } 00275 00276 RootInputFile* rif = m_files.current(); 00277 if (!rif) { 00278 log << MSG::ERROR << "last(): failed to get current file in stream" 00279 << endreq; 00280 return false; 00281 } 00282 00283 okay = rif->ending(); 00284 if (!okay) return false; 00285 00286 if (read) return this->read(); 00287 return true; 00288 }
int RootInputStream::entries | ( | ) |
Return total number of entries.
Definition at line 290 of file RootInputStream.cc.
00291 { 00292 if( m_entries>=0 ) { 00293 return m_entries; 00294 } else { 00295 m_entries=0; 00296 RootInputFileList::iterator it,itend = m_files.end(); 00297 for( it=m_files.begin(); it!=itend; it++ ) { 00298 m_entries+= (*it)->entries(); 00299 } 00300 return m_entries; 00301 } 00302 }
RootIOBaseObject * RootIOStream::obj | ( | ) | [inherited] |
Return the pointer that m_addr points to assuming it points to a RootIOBaseObject.
Definition at line 13 of file RootIOStream.cc.
00014 { 00015 return *(RootIOBaseObject**)m_addr; 00016 }
RootInputFileList RootInputStream::m_files [private] |
Definition at line 27 of file RootInputStream.h.
int RootInputStream::m_entry [private] |
Definition at line 28 of file RootInputStream.h.
int RootInputStream::m_clid [private] |
Definition at line 29 of file RootInputStream.h.
int RootInputStream::m_entries [private] |
Definition at line 30 of file RootInputStream.h.
std::string RootInputStream::m_treepath [private] |
Definition at line 32 of file RootInputStream.h.
std::string RootInputStream::m_branchname [private] |
Definition at line 32 of file RootInputStream.h.
Dyb::MsgStreamMember RootInputStream::log [private] |
Definition at line 34 of file RootInputStream.h.
void* RootIOStream::m_addr [protected, inherited] |
Definition at line 10 of file RootIOStream.h.