paradiseo/trunk/paradiseo-eo/doc/html/eo_file_snapshot_8h-source.html
legrand c3aec878e5 Paradiseo-eo sources added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
2006-12-12 14:49:08 +00:00

176 lines
13 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>EO: eoFileSnapshot.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"> <form class="search" action="search.php" method="get">
<a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a> | <span class="search"><u>S</u>earch&nbsp;for&nbsp;<input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
<div class="nav">
<a class="el" href="dir_000000.html">src</a>&nbsp;/&nbsp;<a class="el" href="dir_000011.html">utils</a></div>
<h1>eoFileSnapshot.h</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-</span>
00002
00003 <span class="comment">//-----------------------------------------------------------------------------</span>
00004 <span class="comment">// eoFileSnapshot.h</span>
00005 <span class="comment">// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2001</span>
00006 <span class="comment">/*</span>
00007 <span class="comment"> This library is free software; you can redistribute it and/or</span>
00008 <span class="comment"> modify it under the terms of the GNU Lesser General Public</span>
00009 <span class="comment"> License as published by the Free Software Foundation; either</span>
00010 <span class="comment"> version 2 of the License, or (at your option) any later version.</span>
00011 <span class="comment"></span>
00012 <span class="comment"> This library is distributed in the hope that it will be useful,</span>
00013 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
00014 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
00015 <span class="comment"> Lesser General Public License for more details.</span>
00016 <span class="comment"></span>
00017 <span class="comment"> You should have received a copy of the GNU Lesser General Public</span>
00018 <span class="comment"> License along with this library; if not, write to the Free Software</span>
00019 <span class="comment"> Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
00020 <span class="comment"></span>
00021 <span class="comment"> Contact: todos@geneura.ugr.es, http://geneura.ugr.es</span>
00022 <span class="comment"> Marc.Schoenauer@polytechnique.fr</span>
00023 <span class="comment"> mkeijzer@dhi.dk</span>
00024 <span class="comment"> */</span>
00025 <span class="comment">//-----------------------------------------------------------------------------</span>
00026
00027 <span class="preprocessor">#ifndef _eoFileSnapshot_h</span>
00028 <span class="preprocessor"></span><span class="preprocessor">#define _eoFileSnapshot_h</span>
00029 <span class="preprocessor"></span>
00030 <span class="preprocessor">#include &lt;string&gt;</span>
00031 <span class="preprocessor">#include &lt;fstream&gt;</span>
00032 <span class="preprocessor">#include &lt;utils/eoParam.h&gt;</span>
00033 <span class="preprocessor">#include &lt;utils/eoMonitor.h&gt;</span>
00034 <span class="preprocessor">#include &lt;eoObject.h&gt;</span>
00035
00036
<a name="l00053"></a><a class="code" href="classeo_file_snapshot.html">00053</a> <span class="keyword">class </span><a class="code" href="classeo_file_snapshot.html">eoFileSnapshot</a> : <span class="keyword">public</span> <a class="code" href="classeo_monitor.html">eoMonitor</a>
00054 {
00055 <span class="keyword">public</span> :
00056 <span class="keyword">typedef</span> std::vector&lt;double&gt; vDouble;
00057 <span class="keyword">typedef</span> <a class="code" href="classeo_value_param.html">eoValueParam&lt;std::vector&lt;double&gt;</a> &gt; <a class="code" href="classeo_value_param.html">vDoubleParam</a>;
00058
00059 <a class="code" href="classeo_file_snapshot.html">eoFileSnapshot</a>(std::string _dirname, <span class="keywordtype">unsigned</span> _frequency = 1, std::string _filename = <span class="stringliteral">"gen"</span>,
00060 std::string _delim = <span class="stringliteral">" "</span>, <span class="keywordtype">unsigned</span> _counter = 0, <span class="keywordtype">bool</span> _rmFiles = <span class="keyword">true</span>):
00061 dirname(_dirname), frequency(_frequency),
00062 filename(_filename), delim(_delim), counter(_counter), boolChanged(<span class="keyword">true</span>)
00063 {
00064 std::string s = <span class="stringliteral">"test -d "</span> + dirname;
00065
00066 <span class="keywordtype">int</span> res = system(s.c_str());
00067 <span class="comment">// test for (unlikely) errors</span>
00068 <span class="keywordflow">if</span> ( (res==-1) || (res==127) )
00069 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Problem executing test of dir in eoFileSnapshot"</span>);
00070 <span class="comment">// now make sure there is a dir without any genXXX file in it</span>
00071 <span class="keywordflow">if</span> (res) <span class="comment">// no dir present</span>
00072 {
00073 s = std::string(<span class="stringliteral">"mkdir "</span>)+dirname;
00074 }
00075 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!res &amp;&amp; _rmFiles)
00076 {
00077 s = std::string(<span class="stringliteral">"/bin/rm "</span>)+dirname+ <span class="stringliteral">"/"</span> + filename + <span class="stringliteral">"*"</span>;
00078 }
00079 <span class="keywordflow">else</span>
00080 s = <span class="stringliteral">" "</span>;
00081
00082 system(s.c_str());
00083 <span class="comment">// all done</span>
00084 }
00085
<a name="l00088"></a><a class="code" href="classeo_file_snapshot.html#a1">00088</a> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classeo_file_snapshot.html#a1">hasChanged</a>() {<span class="keywordflow">return</span> boolChanged;}
00089
<a name="l00092"></a><a class="code" href="classeo_file_snapshot.html#a2">00092</a> <span class="keywordtype">unsigned</span> <a class="code" href="classeo_file_snapshot.html#a2">getCounter</a>() {<span class="keywordflow">return</span> counter;}
00093
<a name="l00096"></a><a class="code" href="classeo_file_snapshot.html#a3">00096</a> std::string <a class="code" href="classeo_file_snapshot.html#a3">getFileName</a>() {<span class="keywordflow">return</span> currentFileName;}
00097
<a name="l00100"></a><a class="code" href="classeo_file_snapshot.html#a4">00100</a> <span class="keywordtype">void</span> <a class="code" href="classeo_file_snapshot.html#a4">setCurrentFileName</a>()
00101 {
00102 std::ostringstream oscount;
00103 oscount &lt;&lt; counter;
00104 currentFileName = dirname + <span class="stringliteral">"/"</span> + filename + oscount.str();
00105 }
00106
<a name="l00109"></a><a class="code" href="classeo_file_snapshot.html#a5">00109</a> <a class="code" href="classeo_monitor.html">eoMonitor</a>&amp; <a class="code" href="classeo_file_snapshot.html#a5">operator()</a>(<span class="keywordtype">void</span>)
00110 {
00111 <span class="keywordflow">if</span> (counter % frequency)
00112 {
00113 boolChanged = <span class="keyword">false</span>; <span class="comment">// subclass with gnuplot will do nothing</span>
00114 counter++;
00115 <span class="keywordflow">return</span> (*this);
00116 }
00117 counter++;
00118 boolChanged = <span class="keyword">true</span>;
00119 <a class="code" href="classeo_file_snapshot.html#a4">setCurrentFileName</a>();
00120 std::ofstream os(currentFileName.c_str());
00121
00122 <span class="keywordflow">if</span> (!os)
00123 {
00124 std::string str = <span class="stringliteral">"eoFileSnapshot: Could not open "</span> + currentFileName;
00125 <span class="keywordflow">throw</span> std::runtime_error(str);
00126 }
00127
00128 <span class="keywordflow">return</span> <a class="code" href="classeo_file_snapshot.html#a5">operator()</a>(os);
00129 }
00130
<a name="l00133"></a><a class="code" href="classeo_file_snapshot.html#a6">00133</a> <a class="code" href="classeo_monitor.html">eoMonitor</a>&amp; <a class="code" href="classeo_file_snapshot.html#a5">operator()</a>(std::ostream&amp; _os)
00134 {
00135 <span class="keyword">const</span> <a class="code" href="classeo_value_param.html">eoValueParam&lt;std::vector&lt;double&gt;</a> &gt; * ptParam =
00136 static_cast&lt;const eoValueParam&lt;std::vector&lt;double&gt; &gt;* &gt;(vec[0]);
00137
00138 <span class="keyword">const</span> std::vector&lt;double&gt; v = ptParam-&gt;<a class="code" href="classeo_value_param.html#a2">value</a>();
00139 <span class="keywordflow">if</span> (vec.size() == 1) <span class="comment">// only one std::vector: -&gt; add number in front</span>
00140 {
00141 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> k=0; k&lt;v.size(); k++)
00142 _os &lt;&lt; k &lt;&lt; <span class="stringliteral">" "</span> &lt;&lt; v[k] &lt;&lt; <span class="stringliteral">"\n"</span> ;
00143 }
00144 <span class="keywordflow">else</span> <span class="comment">// need to get all other std::vectors</span>
00145 {
00146 std::vector&lt;std::vector&lt;double&gt; &gt; vv(vec.size());
00147 vv[0]=v;
00148 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=1; i&lt;vec.size(); i++)
00149 {
00150 ptParam = static_cast&lt;const eoValueParam&lt;std::vector&lt;double&gt; &gt;* &gt;(vec[1]);
00151 vv[i] = ptParam-&gt;<a class="code" href="classeo_value_param.html#a2">value</a>();
00152 <span class="keywordflow">if</span> (vv[i].size() != v.size())
00153 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Dimension error in eoSnapshotMonitor"</span>);
00154 }
00155 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> k=0; k&lt;v.size(); k++)
00156 {
00157 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=0; i&lt;vec.size(); i++)
00158 _os &lt;&lt; vv[i][k] &lt;&lt; <span class="stringliteral">" "</span> ;
00159 _os &lt;&lt; <span class="stringliteral">"\n"</span>;
00160 }
00161 }
00162 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
00163 }
00164
00165 <span class="keyword">virtual</span> <span class="keyword">const</span> std::string getDirName() <span class="comment">// for eoGnuPlot</span>
00166 { <span class="keywordflow">return</span> dirname;}
00167 <span class="keyword">virtual</span> <span class="keyword">const</span> std::string baseFileName() <span class="comment">// the title for eoGnuPlot</span>
00168 { <span class="keywordflow">return</span> filename;}
00169
<a name="l00171"></a><a class="code" href="classeo_file_snapshot.html#a9">00171</a> <span class="keywordtype">void</span> <a class="code" href="classeo_file_snapshot.html#a9">add</a>(<span class="keyword">const</span> <a class="code" href="classeo_param.html">eoParam</a>&amp; _param)
00172 {
00173 <span class="keywordflow">if</span> (!dynamic_cast&lt;const eoValueParam&lt;std::vector&lt;double&gt; &gt;*&gt;(&amp;_param))
00174 {
00175 <span class="keywordflow">throw</span> std::logic_error(std::string(<span class="stringliteral">"eoFileSnapshot: I can only monitor std::vectors of doubles, sorry. The offending parameter name = "</span>) + _param.<a class="code" href="classeo_param.html#a6">longName</a>());
00176 }
00177 <a class="code" href="classeo_monitor.html#a1">eoMonitor::add</a>(_param);
00178 }
00179
00180 <span class="keyword">private</span> :
00181 std::string dirname;
00182 <span class="keywordtype">unsigned</span> frequency;
00183 std::string filename;
00184 std::string delim;
00185 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> counter;
00186 std::string currentFileName;
00187 <span class="keywordtype">bool</span> boolChanged;
00188 };
00189
00190 <span class="preprocessor">#endif</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:35 2006 for EO by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
</body>
</html>