Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > eebc325dc36bd6e3b09b9b45133e42f8 > files > 1411

HippoDraw-devel-docs-1.21.1-10.fc13.i686.rpm

<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>HippoDraw Class Library</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="hippoApp.ico">
</head><body>
<!-- Generated by Doxygen 1.6.2 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_81660c05fb6bfb5c6c7ef0fee605ba15.html">datasrcs</a>
  </div>
</div>
<div class="contents">
<h1>NTupleController.cxx</h1><a href="NTupleController_8cxx.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00012"></a>00012 <span class="comment">// for truncation warning in debug mode</span>
<a name="l00013"></a>00013 <span class="preprocessor">#ifdef _MSC_VER</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#include &quot;msdevstudio/MSconfig.h&quot;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#endif</span>
<a name="l00016"></a>00016 <span class="preprocessor"></span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;<a class="code" href="NTupleController_8h.html" title="hippodraw::NTupleController class interface">NTupleController.h</a>&quot;</span>
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="CircularBuffer_8h.html" title="CircularBuffer class interface.">CircularBuffer.h</a>&quot;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &quot;<a class="code" href="DataSourceController_8h.html" title="DataSourceController class interface.">DataSourceController.h</a>&quot;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;<a class="code" href="TupleCut_8h.html" title="hippodraw::TupleCut class interface">TupleCut.h</a>&quot;</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="preprocessor">#include &quot;<a class="code" href="string__convert_8h.html" title="The namespace for conversion to string.">pattern/string_convert.h</a>&quot;</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;algorithm&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;stdexcept&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;fstream&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;utility&gt;</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="keyword">using</span> std::endl;
<a name="l00035"></a>00035 <span class="keyword">using</span> std::ofstream;
<a name="l00036"></a>00036 <span class="keyword">using</span> std::runtime_error;
<a name="l00037"></a>00037 <span class="keyword">using</span> std::string;
<a name="l00038"></a>00038 <span class="keyword">using</span> std::vector;
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="keyword">using namespace </span>hippodraw;
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 <a class="code" href="classhippodraw_1_1NTupleController.html" title="A singleton class that is the interface between GUI and the NTuple objects.">NTupleController</a> * NTupleController::s_instance = 0;
<a name="l00043"></a>00043 
<a name="l00044"></a><a class="code" href="classhippodraw_1_1NTupleController.html#acd72446c2516587975bf6669fcc0213d">00044</a> NTupleController::NTupleController ()
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 
<a name="l00050"></a><a class="code" href="classhippodraw_1_1NTupleController.html#aec20826712f556d32fdc8868b7d246e6">00050</a> <a class="code" href="classhippodraw_1_1NTupleController.html#acd72446c2516587975bf6669fcc0213d" title="A default constructor for avoiding creation except by itself.">NTupleController::NTupleController</a> ( <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1NTupleController.html" title="A singleton class that is the interface between GUI and the NTuple objects.">NTupleController</a> &amp; )
<a name="l00051"></a>00051 {
<a name="l00052"></a>00052   assert ( <span class="keyword">false</span> );
<a name="l00053"></a>00053 }
<a name="l00054"></a>00054 
<a name="l00055"></a><a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a">00055</a> <a class="code" href="classhippodraw_1_1NTupleController.html" title="A singleton class that is the interface between GUI and the NTuple objects.">NTupleController</a> * <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">NTupleController::instance</a> ( )
<a name="l00056"></a>00056 {
<a name="l00057"></a>00057   <span class="keywordflow">if</span> ( <a class="code" href="classhippodraw_1_1NTupleController.html#ac1a4247ea82561923c1f6807c5cfe02f" title="The pointer to the singleton object.">s_instance</a> == 0 ) {
<a name="l00058"></a>00058     <a class="code" href="classhippodraw_1_1NTupleController.html#ac1a4247ea82561923c1f6807c5cfe02f" title="The pointer to the singleton object.">s_instance</a> = <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1NTupleController.html#acd72446c2516587975bf6669fcc0213d" title="A default constructor for avoiding creation except by itself.">NTupleController</a> ( );
<a name="l00059"></a>00059   }
<a name="l00060"></a>00060   <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1NTupleController.html#ac1a4247ea82561923c1f6807c5cfe02f" title="The pointer to the singleton object.">s_instance</a>;
<a name="l00061"></a>00061 }
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 string::size_type
<a name="l00064"></a>00064 <a class="code" href="classhippodraw_1_1NTupleController.html#ab07b1cf83749e0ed0b5fd5d4c01b4221" title="Find and return position of white space.">NTupleController::</a>
<a name="l00065"></a><a class="code" href="classhippodraw_1_1NTupleController.html#ab07b1cf83749e0ed0b5fd5d4c01b4221">00065</a> <a class="code" href="classhippodraw_1_1NTupleController.html#ab07b1cf83749e0ed0b5fd5d4c01b4221" title="Find and return position of white space.">findWhite</a> ( <span class="keyword">const</span> std::string &amp; line, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> left, <span class="keywordtype">bool</span> tabs_only )
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067   string::size_type right = line.find( <span class="charliteral">&#39;\t&#39;</span>, left );
<a name="l00068"></a>00068 
<a name="l00069"></a>00069   <span class="keywordflow">if</span>( line.find( <span class="charliteral">&#39;\n&#39;</span>, left ) &lt; right ) right = line.find( <span class="charliteral">&#39;\n&#39;</span>, left );
<a name="l00070"></a>00070 
<a name="l00071"></a>00071   <span class="keywordflow">if</span> ( tabs_only == <span class="keyword">false</span> ) { 
<a name="l00072"></a>00072     <span class="keywordflow">if</span>( line.find( <span class="charliteral">&#39; &#39;</span>, left ) &lt; right ) right = line.find( <span class="charliteral">&#39; &#39;</span>, left );
<a name="l00073"></a>00073   }
<a name="l00074"></a>00074 
<a name="l00075"></a>00075   <span class="keywordflow">return</span> right;
<a name="l00076"></a>00076 }
<a name="l00077"></a>00077 
<a name="l00078"></a>00078 <span class="keywordtype">void</span>
<a name="l00079"></a>00079 <a class="code" href="classhippodraw_1_1NTupleController.html#ad8be2b0e20b7cfefe6bdc7452d442c03" title="Splits the line at white space and fills values with strings found.">NTupleController::</a>
<a name="l00080"></a><a class="code" href="classhippodraw_1_1NTupleController.html#ad8be2b0e20b7cfefe6bdc7452d442c03">00080</a> <a class="code" href="classhippodraw_1_1NTupleController.html#ad8be2b0e20b7cfefe6bdc7452d442c03" title="Splits the line at white space and fills values with strings found.">splitAndFill</a> ( <span class="keyword">const</span> std::string &amp; line,
<a name="l00081"></a>00081                std::vector &lt; std::string &gt; &amp; values )
<a name="l00082"></a>00082 {
<a name="l00083"></a>00083   <span class="keyword">static</span> <span class="keywordtype">string</span>  white ( <span class="stringliteral">&quot; \n\r\t&quot;</span> );
<a name="l00084"></a>00084   values.clear ();
<a name="l00085"></a>00085 
<a name="l00086"></a>00086   string::size_type start = line.find_first_not_of ( white, 0 );
<a name="l00087"></a>00087   <span class="keywordflow">while</span> ( start != string::npos ) {
<a name="l00088"></a>00088     string::size_type end = line.find_first_of ( white, start );
<a name="l00089"></a>00089     <span class="keywordflow">if</span> ( end != string::npos ) {
<a name="l00090"></a>00090       values.push_back ( <span class="keywordtype">string</span> ( line, start, end - start ) );
<a name="l00091"></a>00091       start = line.find_first_not_of ( white, end );
<a name="l00092"></a>00092     }
<a name="l00093"></a>00093     <span class="keywordflow">else</span> {
<a name="l00094"></a>00094       values.push_back ( <span class="keywordtype">string</span> ( line, start ) ); <span class="comment">// to end</span>
<a name="l00095"></a>00095       <span class="keywordflow">break</span>;
<a name="l00096"></a>00096     }
<a name="l00097"></a>00097   }
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099 
<a name="l00112"></a>00112 <span class="keywordtype">int</span>
<a name="l00113"></a>00113 <a class="code" href="classhippodraw_1_1NTupleController.html#a6753b631926a447634c24086de4a3fab" title="Reads ASCII formatted file and fills the NTuple.">NTupleController::</a>
<a name="l00114"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a6753b631926a447634c24086de4a3fab">00114</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a6753b631926a447634c24086de4a3fab" title="Reads ASCII formatted file and fills the NTuple.">readAsciiNTuple</a> ( <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> * ntuple, <span class="keyword">const</span> std::string &amp; filename )
<a name="l00115"></a>00115 {
<a name="l00116"></a>00116   <span class="comment">// Two local flags to define if name or labels are missing</span>
<a name="l00117"></a>00117   <span class="keywordtype">bool</span> hasTitle = <span class="keyword">true</span>;
<a name="l00118"></a>00118   <span class="keywordtype">bool</span> hasLabel = <span class="keyword">true</span>;
<a name="l00119"></a>00119 
<a name="l00120"></a>00120   <span class="keywordtype">string</span> dir_name = filename;
<a name="l00121"></a>00121 
<a name="l00122"></a>00122   string::size_type pos = dir_name.find_last_of( <span class="charliteral">&#39;/&#39;</span> );
<a name="l00123"></a>00123   <span class="keywordflow">if</span> ( pos == string::npos ) {
<a name="l00124"></a>00124     dir_name = <span class="stringliteral">&quot;.&quot;</span>;
<a name="l00125"></a>00125   } <span class="keywordflow">else</span> {
<a name="l00126"></a>00126     dir_name.erase( pos );
<a name="l00127"></a>00127   }
<a name="l00128"></a>00128   dir_name += <span class="stringliteral">&quot;/&quot;</span>;
<a name="l00129"></a>00129 
<a name="l00130"></a>00130   std::ifstream infile( filename.c_str() );
<a name="l00131"></a>00131   <span class="keywordflow">if</span>( !infile.is_open() ) {
<a name="l00132"></a>00132     <span class="keywordtype">string</span> what ( <span class="stringliteral">&quot;NTupleController: Could not open file\n`&quot;</span> );
<a name="l00133"></a>00133     what += filename.c_str();
<a name="l00134"></a>00134     what += <span class="stringliteral">&quot;&#39;\n&quot;</span>;
<a name="l00135"></a>00135     what += <span class="stringliteral">&quot;Files doesn&#39;t exist or is not readable.&quot;</span>;
<a name="l00136"></a>00136     <span class="keywordflow">throw</span> runtime_error ( what );
<a name="l00137"></a>00137   }
<a name="l00138"></a>00138   <span class="keywordtype">string</span> line;
<a name="l00139"></a>00139   <span class="keywordflow">if</span>( !std::getline( infile, line ) ) {
<a name="l00140"></a>00140     <span class="keywordflow">return</span> -2;
<a name="l00141"></a>00141   }
<a name="l00142"></a>00142 
<a name="l00143"></a>00143   <span class="comment">// ignore spaces at the beginning of the line</span>
<a name="l00144"></a>00144   <span class="keywordflow">while</span>( <a class="code" href="classhippodraw_1_1NTupleController.html#ab07b1cf83749e0ed0b5fd5d4c01b4221" title="Find and return position of white space.">findWhite</a>( line, 0, <span class="keyword">false</span> ) == 0 ) line = line.substr( 1 );
<a name="l00145"></a>00145   string::size_type firstTab = line.find( <span class="charliteral">&#39;\t&#39;</span>, 0 );
<a name="l00146"></a>00146 
<a name="l00147"></a>00147   <span class="comment">// fist line with tab, no name</span>
<a name="l00148"></a>00148   <span class="keywordflow">if</span> ( firstTab != line.npos ) { 
<a name="l00149"></a>00149     hasTitle = <span class="keyword">false</span>;
<a name="l00150"></a>00150     ntuple-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#abc79cf0667bbb5c93fca3f01b52c7b57" title="Sets the title of the data source to title.">setTitle</a> (<span class="stringliteral">&quot;&lt;none&gt;&quot;</span>);
<a name="l00151"></a>00151     <span class="keywordtype">string</span> firstword = line.substr ( 0, firstTab );
<a name="l00152"></a>00152     
<a name="l00153"></a>00153     <span class="comment">// first line are numbers, no labels</span>
<a name="l00154"></a>00154     <span class="keywordflow">if</span> ( std::atof ( firstword.c_str() ) != 0.0 ) { 
<a name="l00155"></a>00155       hasLabel = <span class="keyword">false</span>;
<a name="l00156"></a>00156     }
<a name="l00157"></a>00157   }
<a name="l00158"></a>00158   <span class="keywordflow">else</span> {
<a name="l00159"></a>00159     <span class="comment">// first line is a single number, no name, no labels</span>
<a name="l00160"></a>00160     <span class="keywordflow">if</span> ( std::atof ( line.c_str() ) != 0.0 ) {
<a name="l00161"></a>00161       hasTitle = <span class="keyword">false</span>;
<a name="l00162"></a>00162       ntuple-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#abc79cf0667bbb5c93fca3f01b52c7b57" title="Sets the title of the data source to title.">setTitle</a>(<span class="stringliteral">&quot;&lt;none&gt;&quot;</span>);
<a name="l00163"></a>00163       hasLabel = <span class="keyword">false</span>;
<a name="l00164"></a>00164     }
<a name="l00165"></a>00165     <span class="comment">// name exist</span>
<a name="l00166"></a>00166     <span class="keywordflow">else</span> ntuple-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#abc79cf0667bbb5c93fca3f01b52c7b57" title="Sets the title of the data source to title.">setTitle</a> ( line );
<a name="l00167"></a>00167   }
<a name="l00168"></a>00168 
<a name="l00169"></a>00169   <span class="comment">// second line missing</span>
<a name="l00170"></a>00170   <span class="keywordflow">if</span> ( hasTitle ){
<a name="l00171"></a>00171     <span class="keywordflow">if</span> ( !std::getline( infile, line ) ) 
<a name="l00172"></a>00172     <span class="keywordflow">return</span> -2;
<a name="l00173"></a>00173   }
<a name="l00174"></a>00174 
<a name="l00175"></a>00175   string::size_type <a class="code" href="namespacenum__util.html#a137f48a49d12a7dae8ba7c86db2a0c01">size</a> = line.size ();
<a name="l00176"></a>00176   <span class="keywordflow">if</span> ( line[size-1] == <span class="charliteral">&#39;\r&#39;</span> ) { <span class="comment">// CR on Windows written file</span>
<a name="l00177"></a>00177     line.erase ( size-1 );
<a name="l00178"></a>00178   }
<a name="l00179"></a>00179   line += <span class="stringliteral">&quot;\n&quot;</span>;
<a name="l00180"></a>00180   string::size_type right = <a class="code" href="classhippodraw_1_1NTupleController.html#ab07b1cf83749e0ed0b5fd5d4c01b4221" title="Find and return position of white space.">findWhite</a>( line, 0, <span class="keyword">true</span> );
<a name="l00181"></a>00181   <span class="keywordtype">string</span> firstlabel = line.substr( 0, right );
<a name="l00182"></a>00182   <span class="comment">// current line start with number, no labels</span>
<a name="l00183"></a>00183   <span class="keywordflow">if</span> ( std::atof ( firstlabel.c_str() ) != 0.0 ) hasLabel=<span class="keyword">false</span>;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185   vector&lt; string &gt; labels;
<a name="l00186"></a>00186   string::size_type left = 0;
<a name="l00187"></a>00187   <span class="comment">// label index, used when labels in the file are missing</span>
<a name="l00188"></a>00188   <span class="keywordtype">int</span> i=0; 
<a name="l00189"></a>00189 
<a name="l00190"></a>00190   <span class="keywordflow">while</span>( right != line.npos ){
<a name="l00191"></a>00191     <span class="keywordflow">if</span>( right == left ){
<a name="l00192"></a>00192       left++;
<a name="l00193"></a>00193       right = <a class="code" href="classhippodraw_1_1NTupleController.html#ab07b1cf83749e0ed0b5fd5d4c01b4221" title="Find and return position of white space.">findWhite</a>( line, left, <span class="keyword">true</span> );
<a name="l00194"></a>00194       <span class="keywordflow">continue</span>;
<a name="l00195"></a>00195     }
<a name="l00196"></a>00196 
<a name="l00197"></a>00197     <span class="keywordtype">string</span> label;
<a name="l00198"></a>00198     <span class="keywordflow">if</span> (!hasLabel) { 
<a name="l00199"></a>00199       <span class="comment">// make a label name when label name is missing </span>
<a name="l00200"></a>00200       label=<span class="stringliteral">&quot;Column&quot;</span>+<a class="code" href="namespacehippodraw_1_1Axes.html#ae2337bddf33bc8b17dd5c08e665422cd" title="Converts from string representation ot Axes::Type representation.">String::convert</a>(i); 
<a name="l00201"></a>00201       i++;
<a name="l00202"></a>00202     }
<a name="l00203"></a>00203     <span class="comment">// read label name from the file</span>
<a name="l00204"></a>00204     <span class="keywordflow">else</span> label = line.substr( left, right - left );
<a name="l00205"></a>00205     labels.push_back ( label );
<a name="l00206"></a>00206     left = right + 1;
<a name="l00207"></a>00207     right = <a class="code" href="classhippodraw_1_1NTupleController.html#ab07b1cf83749e0ed0b5fd5d4c01b4221" title="Find and return position of white space.">findWhite</a>( line, left, <span class="keyword">true</span> );
<a name="l00208"></a>00208   }
<a name="l00209"></a>00209   <span class="keywordflow">if</span> ( labels.size () == 0 ) {
<a name="l00210"></a>00210     <span class="keywordflow">return</span> -2;
<a name="l00211"></a>00211   }
<a name="l00212"></a>00212 
<a name="l00213"></a>00213   ntuple-&gt;<a class="code" href="classhippodraw_1_1NTuple.html#a4d4664fa50e3299863ecba81e224aaa6" title="Assigns the label to each column from the vector of strings.">setLabels</a> ( labels );
<a name="l00214"></a>00214 
<a name="l00215"></a>00215   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> columns = labels.size ();
<a name="l00216"></a>00216   vector &lt; double &gt; vals ( columns );
<a name="l00217"></a>00217 
<a name="l00218"></a>00218   <span class="keywordflow">if</span> ( hasLabel ) {
<a name="l00219"></a>00219     std::getline ( infile, line );
<a name="l00220"></a>00220   }
<a name="l00221"></a>00221 
<a name="l00222"></a>00222   <span class="keywordflow">do</span> {
<a name="l00223"></a>00223     <span class="comment">// else use current line</span>
<a name="l00224"></a>00224     vector &lt; string &gt; values;
<a name="l00225"></a>00225     <a class="code" href="classhippodraw_1_1NTupleController.html#ad8be2b0e20b7cfefe6bdc7452d442c03" title="Splits the line at white space and fills values with strings found.">splitAndFill</a> ( line, values );
<a name="l00226"></a>00226 
<a name="l00227"></a>00227     <span class="keywordflow">if</span> ( values.size() != columns ) {
<a name="l00228"></a>00228       <span class="keywordflow">return</span> -2;
<a name="l00229"></a>00229     }
<a name="l00230"></a>00230     <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; columns; i++ ) {
<a name="l00231"></a>00231       vals[i] = atof ( values[i].c_str() );
<a name="l00232"></a>00232     }
<a name="l00233"></a>00233     ntuple -&gt; addRow ( vals );
<a name="l00234"></a>00234 
<a name="l00235"></a>00235   } <span class="keywordflow">while</span> ( std::getline ( infile, line ) );
<a name="l00236"></a>00236 
<a name="l00237"></a>00237   vector &lt; unsigned int &gt; <a class="code" href="namespacenum__util.html#a8570d9b34e8e9d714823c1b1986764f7">shape</a> ( 2 );
<a name="l00238"></a>00238   shape[0] = ntuple -&gt; rows();
<a name="l00239"></a>00239   shape[1] = ntuple -&gt; columns ();
<a name="l00240"></a>00240   ntuple -&gt; setShape ( shape );
<a name="l00241"></a>00241 
<a name="l00242"></a>00242   <span class="keywordflow">return</span> 0;
<a name="l00243"></a>00243 }
<a name="l00244"></a>00244 
<a name="l00245"></a>00245 <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * 
<a name="l00246"></a>00246 <a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f" title="Creates and registers an empty NTuple.">NTupleController::</a>
<a name="l00247"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a367a0129829b506b44f415cad946db40">00247</a> <a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f" title="Creates and registers an empty NTuple.">createNTuple</a> ( <span class="keyword">const</span> std::string &amp; filename )
<a name="l00248"></a>00248 {
<a name="l00249"></a>00249   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> columns = 0;
<a name="l00250"></a>00250   <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> * nt = <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> ( columns );
<a name="l00251"></a>00251   <span class="keywordflow">try</span> {
<a name="l00252"></a>00252     <a class="code" href="classhippodraw_1_1NTupleController.html#ae7fd3d3f39d6fbeb16d3ef1f5db7fdf1" title="Fills the empty NTuple source from reading data from the file.">fillFromFile</a> ( filename, nt );
<a name="l00253"></a>00253   }
<a name="l00254"></a>00254   <span class="keywordflow">catch</span> ( <span class="keyword">const</span> runtime_error &amp; e ) {
<a name="l00255"></a>00255     <span class="keyword">delete</span> nt;
<a name="l00256"></a>00256     <span class="keywordflow">throw</span> e;
<a name="l00257"></a>00257   }
<a name="l00258"></a>00258 
<a name="l00259"></a>00259   <span class="keywordflow">return</span> nt;
<a name="l00260"></a>00260 }
<a name="l00261"></a>00261 
<a name="l00262"></a>00262 <span class="keywordtype">void</span>
<a name="l00263"></a>00263 <a class="code" href="classhippodraw_1_1NTupleController.html#ae7fd3d3f39d6fbeb16d3ef1f5db7fdf1" title="Fills the empty NTuple source from reading data from the file.">NTupleController::</a>
<a name="l00264"></a><a class="code" href="classhippodraw_1_1NTupleController.html#ae7fd3d3f39d6fbeb16d3ef1f5db7fdf1">00264</a> <a class="code" href="classhippodraw_1_1NTupleController.html#ae7fd3d3f39d6fbeb16d3ef1f5db7fdf1" title="Fills the empty NTuple source from reading data from the file.">fillFromFile</a> ( <span class="keyword">const</span> std::string &amp; filename, <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> * nt )
<a name="l00265"></a>00265 {
<a name="l00266"></a>00266   <span class="keywordtype">int</span> retval = <a class="code" href="classhippodraw_1_1NTupleController.html#a6753b631926a447634c24086de4a3fab" title="Reads ASCII formatted file and fills the NTuple.">readAsciiNTuple</a> ( nt, filename );
<a name="l00267"></a>00267 
<a name="l00268"></a>00268   <span class="keywordflow">if</span> ( retval &lt; 0 ) {
<a name="l00269"></a>00269     std::string what ( <span class="stringliteral">&quot;NTupleController: File:\n `&quot;</span> );
<a name="l00270"></a>00270     what += filename;
<a name="l00271"></a>00271     what += <span class="stringliteral">&quot;&#39;\n &quot;</span>;
<a name="l00272"></a>00272     <span class="keywordflow">if</span> ( retval == -1 ) {
<a name="l00273"></a>00273       what += <span class="stringliteral">&quot;could not be found.&quot;</span>;
<a name="l00274"></a>00274     }
<a name="l00275"></a>00275     <span class="keywordflow">else</span> {
<a name="l00276"></a>00276       what += <span class="stringliteral">&quot;had bad format.&quot;</span>;
<a name="l00277"></a>00277     }
<a name="l00278"></a>00278     <span class="keywordflow">throw</span> std::runtime_error ( what );
<a name="l00279"></a>00279   }
<a name="l00280"></a>00280 
<a name="l00281"></a>00281   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00282"></a>00282   <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * ds = controller -&gt; getDataSource ( filename );
<a name="l00283"></a>00283 
<a name="l00284"></a>00284   <span class="comment">// Register the NTuple name if it&#39;s not in memory.</span>
<a name="l00285"></a>00285   <span class="comment">// Alway register that it came from a file.</span>
<a name="l00286"></a>00286   nt -&gt; setName ( filename ); <span class="comment">// before registering.</span>
<a name="l00287"></a>00287   <span class="keywordflow">if</span> ( ds == 0 ) controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( filename, nt );
<a name="l00288"></a>00288   controller -&gt; registerDataSourceFile ( nt );
<a name="l00289"></a>00289 }
<a name="l00290"></a>00290 
<a name="l00291"></a>00291 <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> * 
<a name="l00292"></a>00292 <a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f" title="Creates and registers an empty NTuple.">NTupleController::</a>
<a name="l00293"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a7ff0f5af26427ca8492dccf6c6062824">00293</a> <a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f" title="Creates and registers an empty NTuple.">createNTuple</a> ( <span class="keyword">const</span> std::vector &lt; std::string &gt; &amp; labels )
<a name="l00294"></a>00294 {
<a name="l00295"></a>00295   <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> * nt = <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> ( labels );
<a name="l00296"></a>00296   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00297"></a>00297   controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( nt );
<a name="l00298"></a>00298 
<a name="l00299"></a>00299   <span class="keywordflow">return</span> nt;
<a name="l00300"></a>00300 }
<a name="l00301"></a>00301 
<a name="l00302"></a>00302 <a class="code" href="classhippodraw_1_1CircularBuffer.html" title="CircularBuffer manager.">CircularBuffer</a> * 
<a name="l00303"></a>00303 <a class="code" href="classhippodraw_1_1NTupleController.html#a6d52a03fe6dd8b53c0d4a81b9f67b583" title="Creates and registers an empty CircularBuffer.">NTupleController::</a>
<a name="l00304"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a75c48e1f54dc722b15f792afa607ebb8">00304</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a6d52a03fe6dd8b53c0d4a81b9f67b583" title="Creates and registers an empty CircularBuffer.">createCircularBuffer</a> ( <span class="keyword">const</span> std::vector &lt; std::string &gt; &amp; labels )
<a name="l00305"></a>00305 {
<a name="l00306"></a>00306   <a class="code" href="classhippodraw_1_1CircularBuffer.html" title="CircularBuffer manager.">CircularBuffer</a> * nt = <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1CircularBuffer.html" title="CircularBuffer manager.">CircularBuffer</a> ( labels );
<a name="l00307"></a>00307   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00308"></a>00308   controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( nt );
<a name="l00309"></a>00309 
<a name="l00310"></a>00310   <span class="keywordflow">return</span> nt;
<a name="l00311"></a>00311 }
<a name="l00312"></a>00312 
<a name="l00313"></a>00313 <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> * 
<a name="l00314"></a>00314 <a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f" title="Creates and registers an empty NTuple.">NTupleController::</a>
<a name="l00315"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a2fc0175526e6aadab484ae95d032325b">00315</a> <a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f" title="Creates and registers an empty NTuple.">createNTuple</a> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> columns )
<a name="l00316"></a>00316 {
<a name="l00317"></a>00317   <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> * nt = <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> ( columns );
<a name="l00318"></a>00318   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00319"></a>00319   controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( nt );
<a name="l00320"></a>00320 
<a name="l00321"></a>00321   <span class="keywordflow">return</span> nt;
<a name="l00322"></a>00322 }
<a name="l00323"></a>00323 
<a name="l00324"></a>00324 <a class="code" href="classhippodraw_1_1CircularBuffer.html" title="CircularBuffer manager.">CircularBuffer</a> * 
<a name="l00325"></a>00325 <a class="code" href="classhippodraw_1_1NTupleController.html#a6d52a03fe6dd8b53c0d4a81b9f67b583" title="Creates and registers an empty CircularBuffer.">NTupleController::</a>
<a name="l00326"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a51bdd27469e51745782f0d9f9f5a74d4">00326</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a6d52a03fe6dd8b53c0d4a81b9f67b583" title="Creates and registers an empty CircularBuffer.">createCircularBuffer</a> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> columns )
<a name="l00327"></a>00327 {
<a name="l00328"></a>00328   <a class="code" href="classhippodraw_1_1CircularBuffer.html" title="CircularBuffer manager.">CircularBuffer</a> * nt = <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1CircularBuffer.html" title="CircularBuffer manager.">CircularBuffer</a> ( columns );
<a name="l00329"></a>00329   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00330"></a>00330   controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( nt );
<a name="l00331"></a>00331 
<a name="l00332"></a>00332   <span class="keywordflow">return</span> nt;
<a name="l00333"></a>00333 }
<a name="l00334"></a>00334 
<a name="l00335"></a>00335 <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> * 
<a name="l00336"></a>00336 <a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f" title="Creates and registers an empty NTuple.">NTupleController::</a>
<a name="l00337"></a><a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f">00337</a> <a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f" title="Creates and registers an empty NTuple.">createNTuple</a> ( )
<a name="l00338"></a>00338 {
<a name="l00339"></a>00339   <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> * nt = <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> ();
<a name="l00340"></a>00340   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00341"></a>00341   controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( nt );
<a name="l00342"></a>00342 
<a name="l00343"></a>00343   <span class="keywordflow">return</span> nt;
<a name="l00344"></a>00344 }
<a name="l00345"></a>00345 
<a name="l00346"></a>00346 <a class="code" href="classhippodraw_1_1CircularBuffer.html" title="CircularBuffer manager.">CircularBuffer</a> * 
<a name="l00347"></a>00347 <a class="code" href="classhippodraw_1_1NTupleController.html#a6d52a03fe6dd8b53c0d4a81b9f67b583" title="Creates and registers an empty CircularBuffer.">NTupleController::</a>
<a name="l00348"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a6d52a03fe6dd8b53c0d4a81b9f67b583">00348</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a6d52a03fe6dd8b53c0d4a81b9f67b583" title="Creates and registers an empty CircularBuffer.">createCircularBuffer</a> ( )
<a name="l00349"></a>00349 {
<a name="l00350"></a>00350   <a class="code" href="classhippodraw_1_1CircularBuffer.html" title="CircularBuffer manager.">CircularBuffer</a> * nt = <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1CircularBuffer.html" title="CircularBuffer manager.">CircularBuffer</a> ();
<a name="l00351"></a>00351   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00352"></a>00352   controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( nt );
<a name="l00353"></a>00353 
<a name="l00354"></a>00354   <span class="keywordflow">return</span> nt;
<a name="l00355"></a>00355 }
<a name="l00356"></a>00356 
<a name="l00357"></a>00357 <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * 
<a name="l00358"></a>00358 <a class="code" href="classhippodraw_1_1NTupleController.html#a12d64d4bd97d8216595ba5a405e4399b" title="Returns the DataSource object with name name.">NTupleController::</a>
<a name="l00359"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a12d64d4bd97d8216595ba5a405e4399b">00359</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a12d64d4bd97d8216595ba5a405e4399b" title="Returns the DataSource object with name name.">findDataSource</a> ( <span class="keyword">const</span> std::string &amp; name )<span class="keyword"> const</span>
<a name="l00360"></a>00360 <span class="keyword"></span>{
<a name="l00361"></a>00361   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00362"></a>00362 
<a name="l00363"></a>00363   <span class="keywordflow">return</span> controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a12d64d4bd97d8216595ba5a405e4399b" title="Returns the DataSource object with name name.">findDataSource</a> ( name );
<a name="l00364"></a>00364 }
<a name="l00365"></a>00365 
<a name="l00366"></a>00366 <span class="keywordtype">void</span>
<a name="l00367"></a>00367 <a class="code" href="classhippodraw_1_1NTupleController.html#ac4fe98a25c8e5e8dd66c7a2fd0cb2a17" title="Changes the name of the DataSource object.">NTupleController::</a>
<a name="l00368"></a><a class="code" href="classhippodraw_1_1NTupleController.html#ac4fe98a25c8e5e8dd66c7a2fd0cb2a17">00368</a> <a class="code" href="classhippodraw_1_1NTupleController.html#ac4fe98a25c8e5e8dd66c7a2fd0cb2a17" title="Changes the name of the DataSource object.">changeName</a> ( <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * ntuple, <span class="keyword">const</span> std::string &amp; new_name )
<a name="l00369"></a>00369 {
<a name="l00370"></a>00370   ntuple -&gt; setName ( new_name );
<a name="l00371"></a>00371 }
<a name="l00372"></a>00372 
<a name="l00373"></a>00373 <span class="keywordtype">int</span> 
<a name="l00374"></a>00374 <a class="code" href="classhippodraw_1_1NTupleController.html#a66b12b1d426bb84b3511ebbec62ad6aa" title="Writes the DataSource source to a file given by filename.">NTupleController::</a>
<a name="l00375"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a3a23b2dd32d9dd4b9ff1db6cd5e952a9">00375</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a66b12b1d426bb84b3511ebbec62ad6aa" title="Writes the DataSource source to a file given by filename.">writeNTupleToFile</a> ( <span class="keyword">const</span> std::string &amp; name,
<a name="l00376"></a>00376                     <span class="keyword">const</span> std::string &amp; filename )
<a name="l00377"></a>00377 {
<a name="l00378"></a>00378   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00379"></a>00379   <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * ntuple 
<a name="l00380"></a>00380     = controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a12d64d4bd97d8216595ba5a405e4399b" title="Returns the DataSource object with name name.">findDataSource</a> ( name );
<a name="l00381"></a>00381   <span class="comment">// throws exception if not found</span>
<a name="l00382"></a>00382   <span class="keywordflow">if</span> ( ntuple == 0 ) <span class="keywordflow">return</span> -1;
<a name="l00383"></a>00383 
<a name="l00384"></a>00384   <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1NTupleController.html#a66b12b1d426bb84b3511ebbec62ad6aa" title="Writes the DataSource source to a file given by filename.">writeNTupleToFile</a> ( ntuple, filename );
<a name="l00385"></a>00385 }
<a name="l00386"></a>00386 
<a name="l00388"></a>00388 <span class="keywordtype">int</span> 
<a name="l00389"></a>00389 <a class="code" href="classhippodraw_1_1NTupleController.html#a66b12b1d426bb84b3511ebbec62ad6aa" title="Writes the DataSource source to a file given by filename.">NTupleController::</a>
<a name="l00390"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a66b12b1d426bb84b3511ebbec62ad6aa">00390</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a66b12b1d426bb84b3511ebbec62ad6aa" title="Writes the DataSource source to a file given by filename.">writeNTupleToFile</a> ( <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * ntuple, 
<a name="l00391"></a>00391                     <span class="keyword">const</span> std::string &amp; filename )
<a name="l00392"></a>00392 {
<a name="l00393"></a>00393   ofstream file ( filename.c_str() );
<a name="l00394"></a>00394   <span class="keywordflow">if</span> ( file.is_open () == false ) {
<a name="l00395"></a>00395     <span class="keywordflow">return</span> 1;
<a name="l00396"></a>00396   }
<a name="l00397"></a>00397   file &lt;&lt; ntuple-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#afea7e0d9518a202a10d7a14222d7ca13" title="Returns a const reference to the title of the data source.">title</a>() &lt;&lt; endl;
<a name="l00398"></a>00398 
<a name="l00399"></a>00399   <span class="keyword">const</span> vector &lt; string &gt; &amp; labels = ntuple-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#a5f883b623617dd5f66e2fa57216c9397" title="Returns the list of available labels.">getLabels</a> ();
<a name="l00400"></a>00400 <span class="preprocessor">#ifdef ITERATOR_MEMBER_DEFECT</span>
<a name="l00401"></a>00401 <span class="preprocessor"></span>  std::
<a name="l00402"></a>00402 <span class="preprocessor">#endif</span>
<a name="l00403"></a>00403 <span class="preprocessor"></span>  vector &lt; string &gt; ::const_iterator first = labels.begin ();
<a name="l00404"></a>00404   <span class="keywordtype">string</span> label = *first++;
<a name="l00405"></a>00405   file &lt;&lt; label;
<a name="l00406"></a>00406   <span class="keywordflow">while</span> (  first != labels.end() ) {
<a name="l00407"></a>00407     label = *first++;
<a name="l00408"></a>00408     file &lt;&lt; <span class="stringliteral">&quot;\t&quot;</span> &lt;&lt; label;
<a name="l00409"></a>00409   }
<a name="l00410"></a>00410   file &lt;&lt; endl;
<a name="l00411"></a>00411 
<a name="l00412"></a>00412   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> rows = ntuple-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#a1d2abe9c739bf78a94515f803cf926e7" title="Returns the number of rows.">rows</a> ();
<a name="l00413"></a>00413   <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; rows; i++ ) {
<a name="l00414"></a>00414     <span class="keyword">const</span> vector &lt; double &gt; &amp; row = ntuple-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#a2fb1dfa7e0d38e58516ab80dc4713a42" title="Returns a const reference to slice along the axis known as a row.">getRow</a> ( i );
<a name="l00415"></a>00415 
<a name="l00416"></a>00416 <span class="preprocessor">#ifdef ITERATOR_MEMBER_DEFECT</span>
<a name="l00417"></a>00417 <span class="preprocessor"></span>    std::
<a name="l00418"></a>00418 <span class="preprocessor">#endif</span>
<a name="l00419"></a>00419 <span class="preprocessor"></span>      vector &lt; double &gt; ::const_iterator first = row.begin();
<a name="l00420"></a>00420     <span class="keywordflow">while</span> ( first != row.end() ) {
<a name="l00421"></a>00421       file &lt;&lt; <span class="stringliteral">&quot;\t&quot;</span> &lt;&lt; *first++;
<a name="l00422"></a>00422     }
<a name="l00423"></a>00423     file &lt;&lt; endl;
<a name="l00424"></a>00424   }
<a name="l00425"></a>00425 
<a name="l00426"></a>00426   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00427"></a>00427   controller -&gt; registerDataSourceFile ( ntuple );
<a name="l00428"></a>00428 
<a name="l00429"></a>00429   <span class="keywordflow">return</span> 0;
<a name="l00430"></a>00430 }
<a name="l00431"></a>00431 
<a name="l00435"></a>00435 <span class="keywordtype">void</span>
<a name="l00436"></a>00436 <a class="code" href="classhippodraw_1_1NTupleController.html#a1972284caeded9ca4ab75f6920b93a22" title="Saves all the NTuple.">NTupleController::</a>
<a name="l00437"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a1972284caeded9ca4ab75f6920b93a22">00437</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a1972284caeded9ca4ab75f6920b93a22" title="Saves all the NTuple.">saveNTuples</a> ( <span class="keyword">const</span> std::string &amp; fileprefix, <span class="keyword">const</span> std::string &amp; filesuffix )
<a name="l00438"></a>00438 {
<a name="l00439"></a>00439   string::size_type pos = fileprefix.find_last_of ( <span class="charliteral">&#39;/&#39;</span> );
<a name="l00440"></a>00440   <span class="keyword">const</span> <span class="keywordtype">string</span> path = fileprefix.substr ( 0, pos + 1 );
<a name="l00441"></a>00441   <span class="keyword">const</span> <span class="keywordtype">string</span> basename = fileprefix.substr ( pos + 1 );
<a name="l00442"></a>00442 
<a name="l00443"></a>00443   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00444"></a>00444   vector &lt; DataSource * &gt; tuples;
<a name="l00445"></a>00445   controller-&gt;<a class="code" href="classhippodraw_1_1DataSourceController.html#a3fe8b75e838aa54efb5e63433c19e1c5" title="Clears and fills the vector with the registered DataSource objects.">getDataSources</a> ( tuples, <span class="keyword">false</span> ); <span class="comment">// only non files</span>
<a name="l00446"></a>00446   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>  <a class="code" href="namespacenum__util.html#a137f48a49d12a7dae8ba7c86db2a0c01">size</a> = tuples.size();
<a name="l00447"></a>00447 
<a name="l00448"></a>00448   <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; size; i++ ) {
<a name="l00449"></a>00449     <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * ntuple = tuples[i];
<a name="l00450"></a>00450     <span class="keyword">const</span> <span class="keywordtype">string</span> &amp; tuple_name = ntuple-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#a8cf4db36c9f3123506d73e98c4a93464" title="Returns the name of the data source.">getName</a> ();
<a name="l00451"></a>00451 
<a name="l00452"></a>00452     <span class="keywordtype">string</span> filename ( basename );
<a name="l00453"></a>00453     filename += <a class="code" href="namespacehippodraw_1_1Axes.html#ae2337bddf33bc8b17dd5c08e665422cd" title="Converts from string representation ot Axes::Type representation.">String::convert</a> ( i );
<a name="l00454"></a>00454     filename += filesuffix;
<a name="l00455"></a>00455 
<a name="l00456"></a>00456     <span class="keywordtype">string</span> tuple_file ( path );
<a name="l00457"></a>00457     tuple_file += filename;
<a name="l00458"></a>00458 
<a name="l00459"></a>00459     <a class="code" href="classhippodraw_1_1NTupleController.html#a66b12b1d426bb84b3511ebbec62ad6aa" title="Writes the DataSource source to a file given by filename.">writeNTupleToFile</a> ( tuple_name, tuple_file );
<a name="l00460"></a>00460     controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#ac4fe98a25c8e5e8dd66c7a2fd0cb2a17" title="Changes the name of the DataSource object.">changeName</a> ( tuple_name, filename );
<a name="l00461"></a>00461   }
<a name="l00462"></a>00462 }
<a name="l00463"></a>00463 
<a name="l00464"></a>00464 <span class="keywordtype">string</span>
<a name="l00465"></a>00465 <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">NTupleController::</a>
<a name="l00466"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283">00466</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * ds )
<a name="l00467"></a>00467 {
<a name="l00468"></a>00468   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00469"></a>00469   controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( ds );
<a name="l00470"></a>00470 
<a name="l00471"></a>00471   <span class="keywordflow">return</span> ds -&gt; getName ();
<a name="l00472"></a>00472 }
<a name="l00473"></a>00473 
<a name="l00474"></a>00474 <span class="keywordtype">void</span>
<a name="l00475"></a>00475 <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">NTupleController::</a>
<a name="l00476"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a94d7461b01e694bea2b253ef14cd0ebe">00476</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( <span class="keyword">const</span> std::string &amp; key, <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * ntuple )
<a name="l00477"></a>00477 {
<a name="l00478"></a>00478   <a class="code" href="classhippodraw_1_1DataSourceController.html" title="A singleton class that is the interface between GUI and the DataSource objects.">DataSourceController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">DataSourceController::instance</a> ();
<a name="l00479"></a>00479   controller -&gt; <a class="code" href="classhippodraw_1_1NTupleController.html#a36f566288e01236f92e4430a26c91283" title="Register a NTuple.">registerNTuple</a> ( key, ntuple );
<a name="l00480"></a>00480 }
<a name="l00481"></a>00481 
<a name="l00482"></a>00482 
<a name="l00483"></a>00483 <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> *
<a name="l00484"></a>00484 <a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f" title="Creates and registers an empty NTuple.">NTupleController::</a>
<a name="l00485"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a60966c14d0feefec24d825ab82d37e4f">00485</a> <a class="code" href="classhippodraw_1_1NTupleController.html#acb491d08abb6c7ddc23c3fee5f09094f" title="Creates and registers an empty NTuple.">createNTuple</a>( <span class="keyword">const</span> std::vector &lt; std::string &gt; &amp; column_list,
<a name="l00486"></a>00486               <span class="keyword">const</span> std::vector &lt; const TupleCut * &gt; &amp; cut_list, 
<a name="l00487"></a>00487               <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * ds )
<a name="l00488"></a>00488 {
<a name="l00489"></a>00489   <span class="keywordflow">if</span> ( column_list.empty() ) <span class="keywordflow">return</span> NULL;
<a name="l00490"></a>00490 
<a name="l00491"></a>00491   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> columnNumber = column_list.size();
<a name="l00492"></a>00492   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cutNumber = cut_list.size();
<a name="l00493"></a>00493   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="namespacenum__util.html#a137f48a49d12a7dae8ba7c86db2a0c01">size</a> = ds-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#a1d2abe9c739bf78a94515f803cf926e7" title="Returns the number of rows.">rows</a>();
<a name="l00494"></a>00494 
<a name="l00495"></a>00495   <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a> * nt = <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1NTuple.html" title="A DataSource class implemented with std::vector&amp;lt;double&amp;gt; to store the column...">NTuple</a>( column_list );
<a name="l00496"></a>00496  
<a name="l00497"></a>00497   <span class="comment">// Check all the rows.</span>
<a name="l00498"></a>00498   <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; size; i++ )
<a name="l00499"></a>00499     {
<a name="l00500"></a>00500       <span class="comment">// If cut is not selected, default is accept.</span>
<a name="l00501"></a>00501       <span class="keywordtype">bool</span> accept = <span class="keyword">true</span>;
<a name="l00502"></a>00502 
<a name="l00503"></a>00503       <span class="comment">// Check all the cuts.</span>
<a name="l00504"></a>00504       <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> j = 0; j &lt; cutNumber; j++ ) 
<a name="l00505"></a>00505         {
<a name="l00506"></a>00506           <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1TupleCut.html" title="The class expresses a cut on a DataSource, i.e.">TupleCut</a> * tc = cut_list[j];
<a name="l00507"></a>00507           accept = tc -&gt; acceptRow ( ds, i );
<a name="l00508"></a>00508           <span class="keywordflow">if</span> (!accept) <span class="keywordflow">break</span>;
<a name="l00509"></a>00509         }
<a name="l00510"></a>00510       
<a name="l00511"></a>00511       <span class="comment">// Add the row when all cuts accept the row.</span>
<a name="l00512"></a>00512       <span class="keywordflow">if</span> (accept) {
<a name="l00513"></a>00513         vector &lt;double&gt; row;
<a name="l00514"></a>00514         <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> k = 0; k &lt; columnNumber; k++ ) 
<a name="l00515"></a>00515           {
<a name="l00516"></a>00516             row.push_back(ds-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#a1fdd1df8df0a21efbfb26e8c47c675b9" title="Returns the value in the table in position given by the row and column indexes without...">valueAtNoCache</a>(i,ds-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#aa26d6f6aa00fc1486dd69069f5f9d90b" title="Returns true if the specified column labeled label has been filled.">indexOf</a>(column_list[k])));
<a name="l00517"></a>00517           }
<a name="l00518"></a>00518         nt-&gt;<a class="code" href="classhippodraw_1_1NTuple.html#a9fca4555396ff541ebe4a7120d5ef8a0" title="Adds a row to the end of the ntuple.">addRow</a>(row);
<a name="l00519"></a>00519       }
<a name="l00520"></a>00520     }
<a name="l00521"></a>00521 
<a name="l00522"></a>00522   <span class="keywordflow">return</span> nt;
<a name="l00523"></a>00523 
<a name="l00524"></a>00524 }
<a name="l00525"></a>00525 
<a name="l00526"></a>00526 <span class="keywordtype">int</span>
<a name="l00527"></a>00527 <a class="code" href="classhippodraw_1_1NTupleController.html#a582456bed2f3f7ad2359150575a48f1b" title="Create NTuple with column list and cut list and save to a file.">NTupleController::</a>
<a name="l00528"></a><a class="code" href="classhippodraw_1_1NTupleController.html#a582456bed2f3f7ad2359150575a48f1b">00528</a> <a class="code" href="classhippodraw_1_1NTupleController.html#a582456bed2f3f7ad2359150575a48f1b" title="Create NTuple with column list and cut list and save to a file.">createNTupleToFile</a>( <span class="keyword">const</span> std::vector &lt; std::string &gt; &amp; column_list,
<a name="l00529"></a>00529                     <span class="keyword">const</span> std::vector &lt; const TupleCut * &gt; &amp; cut_list, 
<a name="l00530"></a>00530                     <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * ds,
<a name="l00531"></a>00531                     <span class="keyword">const</span> std::string &amp; filename,
<a name="l00532"></a>00532                     <span class="keyword">const</span> std::string &amp; dsname)
<a name="l00533"></a>00533 {
<a name="l00534"></a>00534   <span class="keywordflow">if</span> ( column_list.empty() ) <span class="keywordflow">return</span> 1;
<a name="l00535"></a>00535 
<a name="l00536"></a>00536   ofstream file ( filename.c_str() );
<a name="l00537"></a>00537   <span class="keywordflow">if</span> ( file.is_open () == false ) {
<a name="l00538"></a>00538     <span class="keywordflow">return</span> 1;
<a name="l00539"></a>00539   }
<a name="l00540"></a>00540   <span class="comment">// Check the column list and create indices for inner loop</span>
<a name="l00541"></a>00541   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> columnNumber = column_list.size();
<a name="l00542"></a>00542   vector &lt; int &gt; col_indices ( columnNumber );
<a name="l00543"></a>00543   
<a name="l00544"></a>00544   <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; columnNumber; i++ ) {
<a name="l00545"></a>00545     <span class="keyword">const</span> <span class="keywordtype">string</span> &amp; label = column_list [ i ];
<a name="l00546"></a>00546     <span class="keywordtype">int</span> index = ds -&gt; indexOf ( label );
<a name="l00547"></a>00547     <span class="keywordflow">if</span> ( index &lt; 0 ) { 
<a name="l00548"></a>00548      ds -&gt; throwIfInvalidLabel ( label );
<a name="l00549"></a>00549     }
<a name="l00550"></a>00550     col_indices [i] = index;
<a name="l00551"></a>00551   }
<a name="l00552"></a>00552 
<a name="l00553"></a>00553   file &lt;&lt; dsname &lt;&lt; endl;
<a name="l00554"></a>00554 
<a name="l00555"></a>00555 <span class="preprocessor">#ifdef ITERATOR_MEMBER_DEFECT</span>
<a name="l00556"></a>00556 <span class="preprocessor"></span>  std::
<a name="l00557"></a>00557 <span class="preprocessor">#endif</span>
<a name="l00558"></a>00558 <span class="preprocessor"></span>  vector &lt; string &gt; ::const_iterator first = column_list.begin ();
<a name="l00559"></a>00559   <span class="keywordtype">string</span> label = *first++;
<a name="l00560"></a>00560   file &lt;&lt; label;
<a name="l00561"></a>00561   <span class="keywordflow">while</span> (  first != column_list.end() ) {
<a name="l00562"></a>00562     label = *first++;
<a name="l00563"></a>00563     file &lt;&lt; <span class="stringliteral">&quot;\t&quot;</span> &lt;&lt; label;
<a name="l00564"></a>00564   }
<a name="l00565"></a>00565   file &lt;&lt; endl;
<a name="l00566"></a>00566 
<a name="l00567"></a>00567   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cutNumber = cut_list.size();
<a name="l00568"></a>00568   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="namespacenum__util.html#a137f48a49d12a7dae8ba7c86db2a0c01">size</a> = ds-&gt;<a class="code" href="classhippodraw_1_1DataSource.html#a1d2abe9c739bf78a94515f803cf926e7" title="Returns the number of rows.">rows</a>();
<a name="l00569"></a>00569 
<a name="l00570"></a>00570    <span class="comment">// Check all the rows.</span>
<a name="l00571"></a>00571   <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; size; i++ )
<a name="l00572"></a>00572     {
<a name="l00573"></a>00573       <span class="comment">// If cut is not selected, default is accept.</span>
<a name="l00574"></a>00574       <span class="keywordtype">bool</span> accept = <span class="keyword">true</span>;
<a name="l00575"></a>00575 
<a name="l00576"></a>00576       <span class="comment">// Check all the cuts.</span>
<a name="l00577"></a>00577       <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> j = 0; j &lt; cutNumber; j++ ) 
<a name="l00578"></a>00578         {
<a name="l00579"></a>00579           <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1TupleCut.html" title="The class expresses a cut on a DataSource, i.e.">TupleCut</a> * tc = cut_list[j];
<a name="l00580"></a>00580           accept = tc -&gt; acceptRow ( ds, i );
<a name="l00581"></a>00581           <span class="keywordflow">if</span> (!accept) <span class="keywordflow">break</span>;
<a name="l00582"></a>00582         }
<a name="l00583"></a>00583       
<a name="l00584"></a>00584       <span class="comment">// Add the row to the file when all cuts accept the row.</span>
<a name="l00585"></a>00585       <span class="keywordflow">if</span> (accept) {
<a name="l00586"></a>00586         
<a name="l00587"></a>00587         <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> k = 0; k &lt; columnNumber; k++ ) 
<a name="l00588"></a>00588           {
<a name="l00589"></a>00589             <span class="keywordtype">int</span> index = col_indices [ k ];
<a name="l00590"></a>00590             file &lt;&lt; <span class="stringliteral">&quot;\t&quot;</span> &lt;&lt; ds -&gt; valueAtNoCache (i, index );       
<a name="l00591"></a>00591           }
<a name="l00592"></a>00592         file &lt;&lt; endl;
<a name="l00593"></a>00593       }
<a name="l00594"></a>00594     }
<a name="l00595"></a>00595   <span class="keywordflow">return</span> 0; 
<a name="l00596"></a>00596 }
</pre></div></div>
<hr size="1"><address style="align: right;"><small>
Generated for HippoDraw Class Library by <a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0>
</a> </small></address>
</body>
</html>