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 |
#ifdef IS_MPI |
26 |
} |
27 |
|
28 |
sprintf( checkPointMsg, |
29 |
"Sucessfully opened output file for stating.\n"); |
30 |
MPIcheckPoint(); |
31 |
#endif // is_mpi |
32 |
|
33 |
} |
34 |
|
35 |
StatWriter::~StatWriter( ){ |
36 |
|
37 |
#ifdef IS_MPI |
38 |
if(worldRank == 0 ){ |
39 |
#endif // is_mpi |
40 |
|
41 |
statfile_.close(); |
42 |
|
43 |
#ifdef IS_MPI |
44 |
} |
45 |
#endif // is_mpi |
46 |
} |
47 |
|
48 |
void StatWriter::writeTitle() { |
49 |
|
50 |
|
51 |
#ifdef IS_MPI |
52 |
if(worldRank == 0 ){ |
53 |
#endif // is_mpi |
54 |
|
55 |
//write title |
56 |
statfile_ << "#"; |
57 |
for (int i =0; i < mask_.size(); ++i) { |
58 |
if (mask_[i]) { |
59 |
statfile_ << "\t" << Stats::getTitle(i) << "(" << Stats::getUnits(i) << ")"; |
60 |
} |
61 |
} |
62 |
statfile_ << std::endl; |
63 |
|
64 |
#ifdef IS_MPI |
65 |
} |
66 |
#endif // is_mpi |
67 |
} |
68 |
|
69 |
void StatWriter::writeStat(Stats* s){ |
70 |
|
71 |
#ifdef IS_MPI |
72 |
if(worldRank == 0 ){ |
73 |
#endif // is_mpi |
74 |
|
75 |
statfile_.precision(8); |
76 |
|
77 |
for (int i =0; i < mask_.size(); ++i) { |
78 |
if (mask_[i]) { |
79 |
statfile_ << "\t" << (*s)[i]; |
80 |
} |
81 |
} |
82 |
statfile_ << std::endl; |
83 |
|
84 |
statfile_.flush(); |
85 |
|
86 |
#ifdef IS_MPI |
87 |
} |
88 |
#endif // is_mpi |
89 |
} |
90 |
|
91 |
} |