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