| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

RootOutputStream Class Reference

A generalized stream of output data. More...

#include <RootOutputStream.h>

Inheritance diagram for RootOutputStream:

[legend]
Collaboration diagram for RootOutputStream:
[legend]
List of all members.

Public Member Functions

 RootOutputStream (void *addr, const std::string &classname, const std::string &treepath="", const std::string &branchname="")
 Create a root output stream with the address of a pointer to an object.
virtual ~RootOutputStream ()
std::string path ()
 RootIOStream interface.
bool write ()
 Write current state of addr to disk.
bool close ()
 Write tree to file and close file.
bool newFile (const std::string &filename, const std::string &treepath="", const std::string &branchname="")
 Start a new output file.
int entries ()
 Return the number of entries in the output stream.
int fileEntries ()
 Return the number of entries in the current output file.
RootIOBaseObjectobj ()
 Return the pointer that m_addr points to assuming it points to a RootIOBaseObject.

Protected Attributes

void * m_addr

Private Member Functions

bool handle_user_data ()

Private Attributes

TFile * m_file
TTree * m_tree
TDirectory * m_dir
std::string m_classname
std::string m_treepath
std::string m_branchname
int m_entries
Dyb::MsgStreamMember log

Detailed Description

A generalized stream of output data.

This allows writing data out to file. The output stream can be broken up in to multiple files.

bv@bnl.gov Sun Jun 29 10:13:17 2008

Definition at line 26 of file RootOutputStream.h.


Constructor & Destructor Documentation

RootOutputStream::RootOutputStream ( void *  addr,
const std::string &  classname,
const std::string &  treepath = "",
const std::string &  branchname = "" 
)

Create a root output stream with the address of a pointer to an object.

Optionally specify the treepath and branchname

RootOutputStream::~RootOutputStream (  )  [virtual]

Definition at line 39 of file RootOutputStream.cc.

00040 {
00041     this->close();
00042 }


Member Function Documentation

string RootOutputStream::path (  )  [virtual]

RootIOStream interface.

Implements RootIOStream.

Definition at line 44 of file RootOutputStream.cc.

00045 {
00046     return m_treepath;
00047 }

bool RootOutputStream::write (  ) 

Write current state of addr to disk.

Definition at line 51 of file RootOutputStream.cc.

00052 {
00053     if (!m_tree) {
00054         log << MSG::ERROR << "write(): no tree" 
00055             << endreq;
00056         return false;
00057     }
00058 
00059     int nbytes = m_tree->Fill();
00060     log << MSG::DEBUG << "Wrote " << nbytes
00061         << " bytes to entry " << m_entries
00062         << " of tree " << m_treepath
00063         << endreq;
00064 
00065     // Debugging #445.
00066     //TObject* dir = m_file->Get("Event/Sim");
00067     //if (dir) dir->ls();
00068 
00069     ++m_entries;
00070     return nbytes > 0;    
00071 }

bool RootOutputStream::close (  ) 

Write tree to file and close file.

Definition at line 83 of file RootOutputStream.cc.

00084 {
00085     if (!m_file) return true;
00086     if (!m_tree) return true;
00087     
00088     log << MSG::DEBUG << "Closing file " << m_file->GetName() << endreq;
00089 
00090     m_dir->cd();
00091     m_tree->Write(NULL,TObject::kOverwrite); // for kOverwrite see #445
00092     RootOutputFileManager::get().close_file(m_file);
00093     m_file = 0;
00094     m_tree = 0;
00095     m_dir = 0;
00096     return true;
00097 }

bool RootOutputStream::newFile ( const std::string &  filename,
const std::string &  treepath = "",
const std::string &  branchname = "" 
)

Start a new output file.

int RootOutputStream::entries (  ) 

Return the number of entries in the output stream.

Definition at line 73 of file RootOutputStream.cc.

00074 {
00075     return m_entries;
00076 }

int RootOutputStream::fileEntries (  ) 

Return the number of entries in the current output file.

Definition at line 78 of file RootOutputStream.cc.

00079 {
00080     return m_tree->GetEntries();
00081 }

bool RootOutputStream::handle_user_data (  )  [private]

Definition at line 160 of file RootOutputStream.cc.

00161 {
00162     RootIOUserData ud;
00163     RootIOUserData::ProxyCollection& proxies = ud.output(m_treepath);
00164     RootIOUserData::ProxyCollection::iterator it, done = proxies.end();
00165 
00166     log << MSG::DEBUG << "newFile(): handling user data with " 
00167         << proxies.size() << " proxies at treepath=" << m_treepath
00168         << " (one of " << ud.outputMap().size() << ")"
00169         << endreq;
00170 
00171     bool ret = true;
00172     
00173     for (it = proxies.begin(); it != done; ++it) {
00174         RootIOUserDataProxy* udp = it->second;
00175         bool ok = udp->branch(m_tree);
00176         if (ok) {
00177             log << MSG::DEBUG << "newFile(): initiated user data type: "
00178                 << udp->cppType() << " name: " << udp->varName() << endreq;
00179         }
00180         else {
00181             log << MSG::ERROR << "newFile(): failed to initiate user data type: "
00182                 << udp->cppType() << " name: " << udp->varName() << endreq;
00183             ret = false;
00184         }
00185     }
00186     return ret;
00187 }

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 }


Member Data Documentation

TFile* RootOutputStream::m_file [private]

Definition at line 28 of file RootOutputStream.h.

TTree* RootOutputStream::m_tree [private]

Definition at line 29 of file RootOutputStream.h.

TDirectory* RootOutputStream::m_dir [private]

Definition at line 30 of file RootOutputStream.h.

std::string RootOutputStream::m_classname [private]

Definition at line 32 of file RootOutputStream.h.

std::string RootOutputStream::m_treepath [private]

Definition at line 32 of file RootOutputStream.h.

std::string RootOutputStream::m_branchname [private]

Definition at line 32 of file RootOutputStream.h.

int RootOutputStream::m_entries [private]

Definition at line 34 of file RootOutputStream.h.

Dyb::MsgStreamMember RootOutputStream::log [private]

Definition at line 36 of file RootOutputStream.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 Mon Apr 11 20:18:22 2011 for RootIOSvc by doxygen 1.4.7