<!DOCTYPE HTML PUBLIC "-// IETF/DTD HTML 2.0// EN">
<html>
<!--                                             -->
<!-- Author: ROOT team (rootdev@hpsalo.cern.ch)  -->
<!--                                             -->
<!--   Date: Tue Apr  6 15:52:05 1999            -->
<!--                                             -->
<head>
<title>FastMC - 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>
#include "<a href="../FastMC.h">FastMC.h</a>"
#include "TCollection.h"
#include "TObjArray.h"
#include "<a href="../Event.h">Event.h</a>"
#include &lt;stdio.h&gt;
#include "<a href="../GetParameters.h">GetParameters.h</a>"


<b>//______________________________________________________________________</b>
<b>//</b>
<b>//     <a href=".././FastMC.html">FastMC</a></b>
<b>//</b>
<b>//     Manager class for Fast MC.  Creates instances of specific</b>
<b>//     modules (processors) at constructor time.  Then may fetch</b>
<b>//     events one at a time from event source and invoke the modules</b>

ClassImp(<a href=".././FastMC.html">FastMC</a>)
<a name="FastMC:FastMC"> </a><a href=".././FastMC.html#FastMC:FastMC">FastMC::FastMC</a>(<a href="http://root.cern.ch/root/html/EventSource.html">EventSource</a>* eventSource,
	       <a href="../ListOfTypes.html#char">char</a>* parameterFileName,
	       <a href="../ListOfTypes.html#char">char</a>* outputFileName
	       ) {
<b>  // Constructor for <a href=".././FastMC.html">FastMC</a>.  Modules can use parameterFile</b>
<b>  // to set up and will write to outputFile (if non-null outputFileName</b>
<b>  // has been supplied.)</b>

<b>  // If running interactively in Root, may not have an output file</b>
<b>  // so do something sensible whether or not there is one.</b>
  <a href=".././FastMC.html#FastMC:m_ofile">m_ofile</a> = 0;
  if (outputFileName)  <a href=".././FastMC.html#FastMC:m_ofile">m_ofile</a> =  fopen(outputFileName,"w");
  
   <a href=".././FastMC.html#FastMC:m_parfile">m_parfile</a> =  fopen(parameterFileName,"r");

   <a href="http://root.cern.ch/root/html/GetParameters.html">GetParameters</a>* gp = new <a href="http://root.cern.ch/root/html/GetParameters.html">GetParameters</a>(<a href=".././FastMC.html#FastMC:m_parfile">m_parfile</a>);

<b>   // create list of modules to run</b>

<b>   // add modules to list. They inherit from <a href="http://root.cern.ch/root/html/RecModule.html">RecModule</a> and must have </b>
<b>   // doit, cleanup and spew functions defined.</b>

    <a href=".././FastMC.html#FastMC:m_eventMarker">m_eventMarker</a> = new <a href="http://root.cern.ch/root/html/EventMarker.html">EventMarker</a>(0,0);
    <a href=".././FastMC.html#FastMC:m_ModuleList">m_ModuleList</a>.<a href="http://root.cern.ch/root/html/TObjArray.html#TObjArray:Add">Add</a>(<a href=".././FastMC.html#FastMC:m_eventMarker">m_eventMarker</a>);

    <a href=".././FastMC.html#FastMC:m_mcPartPrint">m_mcPartPrint</a> = new <a href="http://root.cern.ch/root/html/MCPartPrint.html">MCPartPrint</a>();
    <a href=".././FastMC.html#FastMC:m_ModuleList">m_ModuleList</a>.<a href="http://root.cern.ch/root/html/TObjArray.html#TObjArray:Add">Add</a>(<a href=".././FastMC.html#FastMC:m_mcPartPrint">m_mcPartPrint</a>); 

    <a href=".././FastMC.html#FastMC:m_trackFullSmear">m_trackFullSmear</a> = new <a href=".././TrackFullSmear.html">TrackFullSmear</a>(gp);
    <a href=".././FastMC.html#FastMC:m_ModuleList">m_ModuleList</a>.<a href="http://root.cern.ch/root/html/TObjArray.html#TObjArray:Add">Add</a>(<a href=".././FastMC.html#FastMC:m_trackFullSmear">m_trackFullSmear</a>); 

    <a href=".././FastMC.html#FastMC:m_calRecon">m_calRecon</a> = new <a href=".././CalRecon.html">CalRecon</a>(*(gp-&gt;getDetectorName()));
    <a href=".././FastMC.html#FastMC:m_ModuleList">m_ModuleList</a>.<a href="http://root.cern.ch/root/html/TObjArray.html#TObjArray:Add">Add</a>(<a href=".././FastMC.html#FastMC:m_calRecon">m_calRecon</a>);

    <a href=".././FastMC.html#FastMC:m_iter">m_iter</a> = new <a href="http://root.cern.ch/root/html/TObjArrayIter.html">TObjArrayIter</a>(&amp;<a href=".././FastMC.html#FastMC:m_ModuleList">m_ModuleList</a>);

    <a href=".././FastMC.html#FastMC:m_source">m_source</a> = eventSource;

};

<a name="FastMC:~FastMC"> </a><a href=".././FastMC.html">FastMC</a>::~<a href=".././FastMC.html">FastMC</a>() {
<b>  // Destructor (but there is almost nothing to do)</b>

  <a href="../ListOfTypes.html#int">int</a> parfileStatus = fclose(<a href=".././FastMC.html#FastMC:m_parfile">m_parfile</a>);
  <a href="../ListOfTypes.html#int">int</a> ofileStatus;
  
  if (<a href=".././FastMC.html#FastMC:m_ofile">m_ofile</a>) ofileStatus = fclose(<a href=".././FastMC.html#FastMC:m_ofile">m_ofile</a>);

};

<a name="FastMC:DoEventBatch"> </a><a href="../ListOfTypes.html#Int_t">Int_t</a> <a href=".././FastMC.html#FastMC:DoEventBatch">FastMC::DoEventBatch</a>() {
<b>  // Full batch-like processing for a single event.</b>

  <a href="http://root.cern.ch/root/html/Event.html">Event</a>* event = 0;

<b>  // translate to Root event format</b>

  event = new <a href="http://root.cern.ch/root/html/Event.html">Event</a>();
  event-&gt;Create();

  <a href="../ListOfTypes.html#int">int</a> ierr = <a href=".././FastMC.html#FastMC:m_source">m_source</a>-&gt;<a href="http://root.cern.ch/root/html/EventSource.html#EventSource:getEvent">getEvent</a>(event);
  if (!ierr) return ierr;
  

  <a href="#FastMC:Cleanup">Cleanup</a>();        // All modules get ready
  <a href="#FastMC:Doit">Doit</a>(event);      // All modules process
  <a href="#FastMC:Spew">Spew</a>();           // All modules output
  
<b>  // clean up event</b>
  event-&gt;Clear();
  delete event;
  event = 0;
  
  return 1;
} 

<a name="FastMC:FetchEvent"> </a><a href="../ListOfTypes.html#Int_t">Int_t</a> <a href=".././FastMC.html#FastMC:FetchEvent">FastMC::FetchEvent</a>(<a href="http://root.cern.ch/root/html/Event.html">Event</a> *evt) {
<b>  // Get single event from source</b>
  return <a href=".././FastMC.html#FastMC:m_source">m_source</a>-&gt;<a href="http://root.cern.ch/root/html/EventSource.html#EventSource:getEvent">getEvent</a>(evt);
}

<a name="FastMC:Doit"> </a><a href="../ListOfTypes.html#void">void</a> <a href=".././FastMC.html#FastMC:Doit">FastMC::Doit</a>(<a href="http://root.cern.ch/root/html/Event.html">Event</a> *event) {
<b>  // Invoke each module to process event</b>

  <a href=".././FastMC.html#FastMC:m_iter">m_iter</a>-&gt;<a href="http://root.cern.ch/root/html/TObjArrayIter.html#TObjArrayIter:Reset">Reset</a>();
  
  while (<a href=".././FastMC.html#FastMC:m_module">m_module</a> = (<a href="http://root.cern.ch/root/html/RecModule.html">RecModule</a>*) (*<a href=".././FastMC.html#FastMC:m_iter">m_iter</a>)()) {

    <a href=".././FastMC.html#FastMC:m_module">m_module</a>-&gt;<a href="http://root.cern.ch/root/html/RecModule.html#RecModule:doit">doit</a>(event);
  }
}

<a name="FastMC:Spew"> </a><a href="../ListOfTypes.html#void">void</a>  <a href=".././FastMC.html#FastMC:Spew">FastMC::Spew</a>() {
<b>  // Invoke each module to do its spew (if have an output file to spew to)</b>

  if (<a href=".././FastMC.html#FastMC:m_ofile">m_ofile</a>) {
    <a href=".././FastMC.html#FastMC:m_iter">m_iter</a>-&gt;<a href="http://root.cern.ch/root/html/TObjArrayIter.html#TObjArrayIter:Reset">Reset</a>();

    while (<a href=".././FastMC.html#FastMC:m_module">m_module</a> = (<a href="http://root.cern.ch/root/html/RecModule.html">RecModule</a>*)(*<a href=".././FastMC.html#FastMC:m_iter">m_iter</a>)()) {
      <a href=".././FastMC.html#FastMC:m_module">m_module</a>-&gt;<a href="http://root.cern.ch/root/html/RecModule.html#RecModule:spew">spew</a>(<a href=".././FastMC.html#FastMC:m_ofile">m_ofile</a>);
    }
  }
}


<a name="FastMC:Cleanup"> </a><a href="../ListOfTypes.html#void">void</a>  <a href=".././FastMC.html#FastMC:Cleanup">FastMC::Cleanup</a>() {
<b>  // Invoke each module's cleanup method</b>

  <a href=".././FastMC.html#FastMC:m_iter">m_iter</a>-&gt;<a href="http://root.cern.ch/root/html/TObjArrayIter.html#TObjArrayIter:Reset">Reset</a>();

  while (<a href=".././FastMC.html#FastMC:m_module">m_module</a> = (<a href="http://root.cern.ch/root/html/RecModule.html">RecModule</a>*) (*<a href=".././FastMC.html#FastMC:m_iter">m_iter</a>)()) {

    <a href=".././FastMC.html#FastMC:m_module">m_module</a>-&gt;<a href="http://root.cern.ch/root/html/RecModule.html#RecModule:cleanup">cleanup</a>();
  }
}
</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>
