Cambridge SMT System
task.stats.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, AdriĆ  de Gispert, William Byrne
14 
15 #ifndef STATSOUTPUTTASK_HPP
16 #define STATSOUTPUTTASK_HPP
17 
24 namespace ucam {
25 namespace fsttools {
26 
28 template <class Data>
30  private:
32 
35 
37  Data *d_;
38 
39  public:
40 
43  d_ ( NULL ),
44  statsoutput_ ( rg.get<std::string> ( HifstConstants::kStatsWrite ) ) {
45  };
46 
51  bool run ( Data& d ) {
52  if ( statsoutput_() == "" ) return false;
53  d_ = &d;
54  FORCELINFO ( "Writing stats to " << statsoutput_ ( d.sidx ) );
55  oszfstream o ( statsoutput_ ( d.sidx ) );
56  o << "=================================================================" <<
57  endl;
58  o << "Sentence " << d.sidx << ": Time (ms):" << endl;
59  writeSpeedStats ( o );
60  o << "-----------------------------------------------------------------" <<
61  endl;
62  o << "Other:" << endl;
63  o << d_->stats->message << endl;
64  o << "=================================================================" <<
65  endl;
66  o.close();
67  return false;
68  };
69 
70  private:
71 
79  void writeSpeedStats ( oszfstream& o ) {
80  d_->stats->write ( o );
81  }
82 };
83 
84 }
85 } // end namespaces
86 #endif
Wrapper stream class that writes to pipes, text files or gzipped files.
Definition: szfstream.hpp:200
class that expands a wildcard into its actual value. This is useful e.g. for filenames ranging severa...
#define FORCELINFO(msg)
Templated (hybrid) Interface for Task classes.
Task that reads stats from data object and writes them to a [file].
Definition: task.stats.hpp:29
SpeedStatsTask(const ucam::util::RegistryPO &rg)
Constructor with RegistryPO object.
Definition: task.stats.hpp:42
bool run(Data &d)
General run method from TaskInterface. Dumps all stats to a file.
Definition: task.stats.hpp:51
std::string const kStatsWrite
Definition: bleu.hpp:14
void close()
Closes the file.
Definition: szfstream.hpp:323