git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
176 lines
13 KiB
HTML
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 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 Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="pages.html">Related Pages</a> | <span class="search"><u>S</u>earch for <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> / <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 <string></span>
|
|
00031 <span class="preprocessor">#include <fstream></span>
|
|
00032 <span class="preprocessor">#include <utils/eoParam.h></span>
|
|
00033 <span class="preprocessor">#include <utils/eoMonitor.h></span>
|
|
00034 <span class="preprocessor">#include <eoObject.h></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<double> vDouble;
|
|
00057 <span class="keyword">typedef</span> <a class="code" href="classeo_value_param.html">eoValueParam<std::vector<double></a> > <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 && _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 << 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>& <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>& <a class="code" href="classeo_file_snapshot.html#a5">operator()</a>(std::ostream& _os)
|
|
00134 {
|
|
00135 <span class="keyword">const</span> <a class="code" href="classeo_value_param.html">eoValueParam<std::vector<double></a> > * ptParam =
|
|
00136 static_cast<const eoValueParam<std::vector<double> >* >(vec[0]);
|
|
00137
|
|
00138 <span class="keyword">const</span> std::vector<double> v = ptParam-><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: -> add number in front</span>
|
|
00140 {
|
|
00141 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> k=0; k<v.size(); k++)
|
|
00142 _os << k << <span class="stringliteral">" "</span> << v[k] << <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<std::vector<double> > vv(vec.size());
|
|
00147 vv[0]=v;
|
|
00148 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=1; i<vec.size(); i++)
|
|
00149 {
|
|
00150 ptParam = static_cast<const eoValueParam<std::vector<double> >* >(vec[1]);
|
|
00151 vv[i] = ptParam-><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<v.size(); k++)
|
|
00156 {
|
|
00157 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=0; i<vec.size(); i++)
|
|
00158 _os << vv[i][k] << <span class="stringliteral">" "</span> ;
|
|
00159 _os << <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>& _param)
|
|
00172 {
|
|
00173 <span class="keywordflow">if</span> (!dynamic_cast<const eoValueParam<std::vector<double> >*>(&_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
|
|
<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>
|