1 |
#define _LARGEFILE_SOURCE64 |
2 |
#define _FILE_OFFSET_BITS 64 |
3 |
|
4 |
#include "io/StatWriter.hpp" |
5 |
#include "utils/simError.h" |
6 |
|
7 |
namespace oopse { |
8 |
StatWriter::StatWriter( const std::string& filename, const StatsBitSet& mask) : mask_(mask){ |
9 |
|
10 |
#ifdef IS_MPI |
11 |
if(worldRank == 0 ){ |
12 |
#endif // is_mpi |
13 |
|
14 |
statfile_.open(filename.c_str(), std::ios::out | std::ios::trunc ); |
15 |
|
16 |
if( !statfile_ ){ |
17 |
|
18 |
sprintf( painCave.errMsg, |
19 |
"Could not open \"%s\" for stat output.\n", |
20 |
filename.c_str()); |
21 |
painCave.isFatal = 1; |
22 |
simError(); |
23 |
} |
24 |
|
25 |
writeTitle(); |
26 |
|
27 |
#ifdef IS_MPI |
28 |
} |
29 |
|
30 |
sprintf( checkPointMsg, |
31 |
"Sucessfully opened output file for stating.\n"); |
32 |
MPIcheckPoint(); |
33 |
#endif // is_mpi |
34 |
|
35 |
} |
36 |
|
37 |
StatWriter::~StatWriter( ){ |
38 |
|
39 |
#ifdef IS_MPI |
40 |
if(worldRank == 0 ){ |
41 |
#endif // is_mpi |
42 |
|
43 |
statfile_.close(); |
44 |
|
45 |
#ifdef IS_MPI |
46 |
} |
47 |
#endif // is_mpi |
48 |
} |
49 |
|
50 |
void StatWriter::writeTitle() { |
51 |
|
52 |
|
53 |
#ifdef IS_MPI |
54 |
if(worldRank == 0 ){ |
55 |
#endif // is_mpi |
56 |
|
57 |
//write title |
58 |
statfile_ << "#"; |
59 |
for (int i =0; i < mask_.size(); ++i) { |
60 |
if (mask_[i]) { |
61 |
statfile_ << "\t" << Stats::getTitle(i) << "(" << Stats::getUnits(i) << ")"; |
62 |
} |
63 |
} |
64 |
statfile_ << std::endl; |
65 |
|
66 |
#ifdef IS_MPI |
67 |
} |
68 |
#endif // is_mpi |
69 |
} |
70 |
|
71 |
void StatWriter::writeStat(const Stats& s){ |
72 |
|
73 |
#ifdef IS_MPI |
74 |
if(worldRank == 0 ){ |
75 |
#endif // is_mpi |
76 |
|
77 |
statfile_.precision(8); |
78 |
|
79 |
for (int i =0; i < mask_.size(); ++i) { |
80 |
if (mask_[i]) { |
81 |
statfile_ << "\t" << s[i]; |
82 |
} |
83 |
} |
84 |
statfile_ << std::endl; |
85 |
|
86 |
statfile_.flush(); |
87 |
|
88 |
#ifdef IS_MPI |
89 |
} |
90 |
#endif // is_mpi |
91 |
} |
92 |
|
93 |
} |