<!DOCTYPE HTML PUBLIC "-// IETF/DTD HTML 2.0// EN">
<html>
<!--                                             -->
<!-- Author: ROOT team (rootdev@hpsalo.cern.ch)  -->
<!--                                             -->
<!--   Date: Tue Apr  6 15:50:18 1999            -->
<!--                                             -->
<head>
<title>readRootFile - source file</title>
<link rev=made href="mailto:rootdev@root.cern.ch">
<meta name="rating" content="General">
<meta name="objecttype" content="Manual">
<meta name="keywords" content="software development, oo, object oriented, unix, x11, motif, windows nt, c++, html, rene brun, fons rademakers">
<meta name="description" content="ROOT - An Object Oriented Framework For Large Scale Data Analysis.">
</head>
<body BGCOLOR="#ffffff" LINK="#0000ff" VLINK="#551a8b" ALINK="#ff0000" TEXT="#000000">
<a name="TopOfPage"></a>
<pre>
<b>//  Get input from root file.</b>

<b>// Version 0.00 18-Nov-1998 RXD Creation</b>
<b>//              31-Mar-1999 jrb Move to Util (libRootAppsUtil)</b>


#include "<a href="../readRootFile.h">readRootFile.h</a>"
#include "TBranch.h"

ClassImp(readRootFile)

<b>//______________________________________________________________________</b>
<b>// <a href=".././readRootFile.html">readRootFile</a> </b>
<b>//</b>
<b>// <a href=".././EventSource.html">EventSource</a> reading from root file</b>

<a name="readRootFile:readRootFile"> </a><a href=".././readRootFile.html#readRootFile:readRootFile">readRootFile::readRootFile</a>(<a href="../ListOfTypes.html#Char_t">Char_t</a>* rootFileName) {
<b>  // constructor</b>

   FILE* parFile;
   if(!(parFile = fopen(rootFileName,"r"))){
     printf("Root file %s could not be openedn", rootFileName);
     return;
   };

   <a href="../ListOfTypes.html#int">int</a> parfileStatus = fclose(parFile);
      
<b>   // set up root</b>

   <a href=".././readRootFile.html#readRootFile:m_event">m_event</a> = new <a href="http://root.cern.ch/root/html/Event.html">Event</a>();

   <a href=".././readRootFile.html#readRootFile:m_rootFile">m_rootFile</a> = new <a href="http://root.cern.ch/root/html/TFile.html">TFile</a>(rootFileName);
   <a href=".././readRootFile.html#readRootFile:T">T</a> = (<a href="http://root.cern.ch/root/html/TTree.html">TTree</a>*)(<a href=".././readRootFile.html#readRootFile:m_rootFile">m_rootFile</a>-&gt;Get("<a href=".././readRootFile.html#readRootFile:T">T</a>"));

   <a href=".././readRootFile.html#readRootFile:T">T</a>-&gt;<a href="http://root.cern.ch/root/html/TTree.html#TTree:SetBranchAddress">SetBranchAddress</a>("<a href="http://root.cern.ch/root/html/Event.html">Event</a>",&amp;<a href=".././readRootFile.html#readRootFile:m_event">m_event</a>);

   <a href="../ListOfTypes.html#Int_t">Int_t</a> nEntries = <a href=".././readRootFile.html#readRootFile:T">T</a>-&gt;<a href="http://root.cern.ch/root/html/TTree.html#TTree:GetEntries">GetEntries</a>();

   printf("Using Root file %s with %i entries n",
	  rootFileName,nEntries);
   
   <a href=".././readRootFile.html#readRootFile:m_nEvent">m_nEvent</a> = 0;
}

<a name="readRootFile:~readRootFile"> </a><a href=".././readRootFile.html">readRootFile</a>::~<a href=".././readRootFile.html">readRootFile</a>() {};

<a name="readRootFile:getEvent"> </a><a href="../ListOfTypes.html#Int_t">Int_t</a> <a href=".././readRootFile.html#readRootFile:getEvent">readRootFile::getEvent</a>(<a href="http://root.cern.ch/root/html/Event.html">Event</a>* event) {
<b>  // get next event</b>

   <a href="../ListOfTypes.html#Int_t">Int_t</a> nBytes = <a href=".././readRootFile.html#readRootFile:T">T</a>-&gt;<a href="http://root.cern.ch/root/html/TTree.html#TTree:GetEvent">GetEvent</a>(<a href=".././readRootFile.html#readRootFile:m_nEvent">m_nEvent</a>);

   <a href=".././readRootFile.html#readRootFile:m_nEvent">m_nEvent</a>++;

   return nBytes;
};
</pre>

<!--SIGNATURE-->
<br>
<address>
<hr>
<center>
<a href="http://root.cern.ch/root/Welcome.html">ROOT page</a> - <a href="../ClassIndex.html">Class index</a> - <a href="#TopOfPage">Top of the page</a><br>
</center>
<hr>This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to <a href="mailto:rootdev@root.cern.ch">ROOT support</a>, or contact <a href="mailto:rootdev@root.cern.ch">the developers</a> with any questions or problems regarding ROOT.
</address>
</body>
</html>
