/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Protected Attributes | Private Attributes
RootInputStream Class Reference

A generalized stream of input data. More...

#include <RootInputStream.h>

Inheritance diagram for RootInputStream:
Inheritance graph
[legend]
Collaboration diagram for RootInputStream:
Collaboration graph
[legend]

List of all members.

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 ()
RootInputFileListgetFiles ()
bool append (const std::string &filename, bool ignore_missing=false)
 Add another input filename, take treepath from prior files.
bool append (const std::string &filename, const std::string &treepath, const std::string &branchname, bool ignore_missing=false)
 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.
RootIOBaseObjectobj ()
 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

Detailed Description

A generalized stream of input data.

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.


Constructor & Destructor Documentation

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.

    : RootIOStream(addr)
    , m_files()
    , m_entry(-1)
    , m_clid(0)
    , m_entries(-1)
    , m_treepath(treepath)
    , m_branchname(branchname)
    , log("RootInputStream")
{
}
RootInputStream::~RootInputStream ( ) [virtual]

Definition at line 19 of file RootInputStream.cc.

{
    // close file if needed
}

Member Function Documentation

std::string RootInputStream::path ( ) [virtual]

RootIOStream interface:

Implements RootIOStream.

Definition at line 29 of file RootInputStream.cc.

{
    return m_treepath;
}
std::string RootInputStream::filename ( )

Definition at line 34 of file RootInputStream.cc.

{
    RootInputFile* rif = m_files.current();
    if (rif) return rif->filename();
    return "";
}
int RootInputStream::fileNumber ( )

Definition at line 41 of file RootInputStream.cc.

{
    return m_files.index();
}
int RootInputStream::clID ( )

Definition at line 24 of file RootInputStream.cc.

{
    return m_clid;
}
int RootInputStream::getEntry ( ) [inline]

Definition at line 50 of file RootInputStream.h.

{ return m_entry; }
RootInputFileList& RootInputStream::getFiles ( ) [inline]

Definition at line 51 of file RootInputStream.h.

{ return m_files; }
bool RootInputStream::append ( const std::string &  filename,
bool  ignore_missing = false 
)

Add another input filename, take treepath from prior files.

Definition at line 46 of file RootInputStream.cc.

{
    if ("" == m_treepath || "" == m_branchname) {
        log << MSG::ERROR << "Can not guess tree path or branch name for "
            << filename << endreq;
        return false;
    }

    int clid = RootInputFile::TestForObject(filename,m_treepath,m_branchname, true);
    if (m_clid && clid && clid != m_clid) {
        log << MSG::ERROR << "Bad class ID from new file " << filename
            << " for " << m_treepath
            << "; got " << clid << " (had " << m_clid << ")"
            << endreq;
        return false;
    } else if (!clid) {         // not present
        if (ignore_missing) {
            // Even if this file is missing the path, we still need to add a
            // dummy entry to the input stream, since all input streams must
            // have the same number of files.
            m_files.push_back(new RootInputFile("","",""));
        } else {
            log << MSG::ERROR << "Missing class ID " << m_clid
                << " for " << m_treepath
                << " in file " << filename << endreq;
            return false;
        }
    } else {                    // we found it
        m_clid = clid;
        m_files.push_back(new RootInputFile(filename,m_treepath,m_branchname));
    }

    if (1 == m_files.size()) {
        m_files.next();
    }
    return true;
}
bool RootInputStream::append ( const std::string &  filename,
const std::string &  treepath,
const std::string &  branchname,
bool  ignore_missing = false 
)

Add another input filename and treepath with different treepath and branchname.

Definition at line 84 of file RootInputStream.cc.

{
    if ("" != m_treepath) m_treepath = treepath;
    if ("" != m_branchname) m_branchname = branchname;

    return append(filename, ignore_missing);
}
bool RootInputStream::read ( )

Read in current entry.

Definition at line 96 of file RootInputStream.cc.

{
    RootInputFile* rif = m_files.current();
    if (!rif) {
        log << MSG::ERROR << "No current file" << endreq;
        return false;
    }

    int nbytes = 0;
    bool ok = rif->read(m_addr,nbytes);
    log << MSG::DEBUG << "read() " << nbytes
        << " bytes at entry " << m_entry
        << " from file \"" << rif->filename() 
        << "\" to path \"" <<  this->path() 
        << endreq;
    return ok;
}
bool RootInputStream::setEntry ( int  entry,
bool  read = true 
)

Set the absolute entry to read.

If read is true read() the entry.

Definition at line 114 of file RootInputStream.cc.

{
    int steps = entry - m_entry;
    log << MSG::DEBUG << "setEntry(entry="<<entry<<",read="<<read<<") steps = " << steps
        << " (stream=\"" << this->path() << "\")"
        << endreq;
    if (steps < 0) return prev(-steps, read);
    if (steps > 0) return next(steps, read);
    return true;                // no change
}
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 125 of file RootInputStream.cc.

{
    if (!m_files.jump(file)) {
        log << MSG::ERROR
            << "jump("<<file<<"): failed"
            << endreq;
        return false;
    }
    RootInputFile* rif = m_files.current();
    if (!rif) {
        log << MSG::ERROR << "Failed to get current file #" << file << endreq;
        return false;
    }
    if (!rif->setEntry(entry)) {
        log << MSG::ERROR << "Failed to set entry " << entry << " on file #" << file << endreq;
        return false;
    }

    int totEntries = m_files.entriesBefore(file);
    if (totEntries < 0) {
        log << MSG::ERROR << "Failed to get sane number of entries before file#" << file << endreq;
        return false;
    }
    m_entry = totEntries + entry;
    log << MSG::DEBUG << "setFileEntry(file="<<file<<",entry="<<entry<<",read="<<read<<") "
        << "totEntries=" << totEntries <<" m_entry=" << m_entry 
        << " (stream=\"" << this->path() 
        << "\", filename=\"" << rif->filename() << "\")"
        << endreq;
    
    if (read) return this->read();
    return true;

}
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 161 of file RootInputStream.cc.

{
    RootInputFile* rif = m_files.current();

    if (!rif) {
        log << MSG::ERROR << "No files" << endreq;
        return false;
    }

    log << MSG::DEBUG << "next(nsteps="<<nsteps<<",read="<<read<<")" 
        << " (stream=\"" << this->path() << "\")"
        << endreq;

    while (nsteps) {

        // must leave current file?
        if (rif->entry() + nsteps >= rif->entries()) {

            // burn what steps current file provides
            int jump = rif->entries() - (rif->entry() + 1); 
            nsteps -= jump;
            m_entry += jump;
            if (!m_files.next()) {
                log << MSG::INFO
                    << "next(): no more files to go to next:"
                    << " jump = " << jump
                    << " nsteps = " << nsteps 
                    << " entry = " << m_entry
                    << " tentries=" << rif->entries() << endreq;
                return false;
            }
            rif = m_files.current();
            continue;
        }

        // Current file has enough entries left
        rif->next(nsteps);
        m_entry += nsteps;
        nsteps = 0;
        break;        
    }
    log << MSG::DEBUG << "next(): at stream entry " << m_entry
        << " (file: " << rif->filename() << " file entry: " << rif->entry() << ")"
        << " (stream=\"" << this->path() << "\")"
        << endreq;
    if (read) return this->read();
    return true;
}
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 210 of file RootInputStream.cc.

{
    RootInputFile* rif = m_files.current();
    if (!rif) {
        log << MSG::ERROR << "No files yet, cannot go prev" << endreq;
        return false;
    }

    log << MSG::DEBUG << "prev(nsteps="<<nsteps<<",read="<<read<<")"
        << " (stream=\"" << this->path() << "\")"
        << endreq;

    while (nsteps) {

        // must leave current file?
        if (rif->entry()-nsteps < 0) { 

            // Burn what steps this file provides
            int jump = 1 + rif->entry();
            nsteps -= jump;
            m_entry -= jump;
            if (!m_files.prev()) {
                log << MSG::ERROR << "Already at first file, cannot go prev"
                    << endreq;
                return false;
            }
            rif = m_files.current();
            rif->ending();      // position file entry at end
            continue;
        }

        // Can stay in current file
        rif->prev(nsteps);
        m_entry -= nsteps;
        nsteps = 0;
        break;
    }

    log << MSG::DEBUG << "prev(): at stream entry " << m_entry
        << " (file: " << rif->filename() << " file entry: " << rif->entry() << ")"
        << " (stream=\"" << this->path() << "\")"
        << endreq;

    if (read) return this->read();
    return true;
}
bool RootInputStream::first ( bool  read = true)

Go to the very first entry.

Definition at line 258 of file RootInputStream.cc.

{
    bool okay = m_files.first();
    if (!okay) {
        log << MSG::ERROR << "first(): failed to go to first file in stream" 
            << endreq;
        return false;
    }

    RootInputFile* rif = m_files.current();
    if (!rif) {
        log << MSG::ERROR << "first(): failed to get current file in stream" 
            << endreq;
        return false;
    }

    okay = rif->beginning();
    if (!okay) return false;

    if (read) return this->read();
    return true;    
}
bool RootInputStream::last ( bool  read = true)

Go to the very last entry.

Definition at line 282 of file RootInputStream.cc.

{
    bool okay = m_files.last();
    if (!okay) {
        log << MSG::ERROR << "last(): failed to go to last file in stream" 
            << endreq;
        return false;
    }

    RootInputFile* rif = m_files.current();
    if (!rif) {
        log << MSG::ERROR << "last(): failed to get current file in stream" 
            << endreq;
        return false;
    }

    okay = rif->ending();
    if (!okay) return false;

    if (read) return this->read();
    return true;
}
int RootInputStream::entries ( )

Return total number of entries.

Definition at line 305 of file RootInputStream.cc.

{
  if( m_entries>=0 ) {
    return m_entries;
  } else {
    m_entries=0;
    RootInputFileList::iterator it,itend = m_files.end();
    for( it=m_files.begin(); it!=itend; it++ ) {
      m_entries+= (*it)->entries();
    }
    return m_entries;
  }
}
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.

{
    return *(RootIOBaseObject**)m_addr;
}

Member Data Documentation

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.

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.

Definition at line 34 of file RootInputStream.h.

void* RootIOStream::m_addr [protected, inherited]

Definition at line 10 of file RootIOStream.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:58:18 for RootIOSvc by doxygen 1.7.4