43 |
|
#include "primitives/Molecule.hpp" |
44 |
|
#include "utils/simError.h" |
45 |
|
#include "io/basic_teebuf.hpp" |
46 |
+ |
#include "io/gzstream.hpp" |
47 |
+ |
#include "io/Globals.hpp" |
48 |
+ |
|
49 |
|
#ifdef IS_MPI |
50 |
|
#include <mpi.h> |
51 |
|
#endif //is_mpi |
54 |
|
|
55 |
|
DumpWriter::DumpWriter(SimInfo* info) |
56 |
|
: info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ |
57 |
+ |
|
58 |
+ |
Globals* simParams = info->getSimParams(); |
59 |
+ |
needCompression_ = simParams->getCompressDumpFile(); |
60 |
+ |
|
61 |
+ |
#ifdef HAVE_LIBZ |
62 |
+ |
if (needCompression_) { |
63 |
+ |
filename_ += ".gz"; |
64 |
+ |
eorFilename_ += ".gz"; |
65 |
+ |
} |
66 |
+ |
#endif |
67 |
+ |
|
68 |
|
#ifdef IS_MPI |
69 |
|
|
70 |
|
if (worldRank == 0) { |
71 |
|
#endif // is_mpi |
72 |
|
|
59 |
– |
dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
73 |
|
|
74 |
+ |
dumpFile_ = createOStream(filename_); |
75 |
+ |
|
76 |
|
if (!dumpFile_) { |
77 |
|
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
78 |
|
filename_.c_str()); |
94 |
|
|
95 |
|
DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) |
96 |
|
: info_(info), filename_(filename){ |
97 |
+ |
|
98 |
+ |
Globals* simParams = info->getSimParams(); |
99 |
+ |
eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
100 |
+ |
|
101 |
+ |
needCompression_ = simParams->getCompressDumpFile(); |
102 |
+ |
|
103 |
+ |
#ifdef HAVE_LIBZ |
104 |
+ |
if (needCompression_) { |
105 |
+ |
filename_ += ".gz"; |
106 |
+ |
eorFilename_ += ".gz"; |
107 |
+ |
} |
108 |
+ |
#endif |
109 |
+ |
|
110 |
|
#ifdef IS_MPI |
111 |
|
|
112 |
|
if (worldRank == 0) { |
113 |
|
#endif // is_mpi |
114 |
|
|
87 |
– |
eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
88 |
– |
dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
115 |
|
|
116 |
+ |
dumpFile_ = createOStream(filename_); |
117 |
+ |
|
118 |
|
if (!dumpFile_) { |
119 |
|
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
120 |
|
filename_.c_str()); |
140 |
|
if (worldRank == 0) { |
141 |
|
#endif // is_mpi |
142 |
|
|
143 |
< |
dumpFile_.close(); |
143 |
> |
delete dumpFile_; |
144 |
|
|
145 |
|
#ifdef IS_MPI |
146 |
|
|
600 |
|
} |
601 |
|
|
602 |
|
void DumpWriter::writeDump() { |
603 |
< |
writeFrame(dumpFile_); |
576 |
< |
|
603 |
> |
writeFrame(*dumpFile_); |
604 |
|
} |
605 |
|
|
606 |
|
void DumpWriter::writeEor() { |
607 |
< |
std::ofstream eorStream; |
607 |
> |
std::ostream* eorStream; |
608 |
|
|
609 |
|
#ifdef IS_MPI |
610 |
|
if (worldRank == 0) { |
611 |
|
#endif // is_mpi |
612 |
|
|
613 |
< |
eorStream.open(eorFilename_.c_str()); |
587 |
< |
if (!eorStream.is_open()) { |
588 |
< |
sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n", |
589 |
< |
eorFilename_.c_str()); |
590 |
< |
painCave.isFatal = 1; |
591 |
< |
simError(); |
592 |
< |
} |
613 |
> |
eorStream = createOStream(eorFilename_); |
614 |
|
|
615 |
|
#ifdef IS_MPI |
616 |
|
} |
617 |
|
#endif // is_mpi |
618 |
|
|
619 |
< |
writeFrame(eorStream); |
619 |
> |
writeFrame(*eorStream); |
620 |
> |
|
621 |
> |
#ifdef IS_MPI |
622 |
> |
if (worldRank == 0) { |
623 |
> |
#endif // is_mpi |
624 |
> |
delete eorStream; |
625 |
> |
|
626 |
> |
#ifdef IS_MPI |
627 |
> |
} |
628 |
> |
#endif // is_mpi |
629 |
> |
|
630 |
|
} |
631 |
|
|
632 |
|
|
633 |
|
void DumpWriter::writeDumpAndEor() { |
603 |
– |
std::ofstream eorStream; |
634 |
|
std::vector<std::streambuf*> buffers; |
635 |
+ |
std::ostream* eorStream; |
636 |
|
#ifdef IS_MPI |
637 |
|
if (worldRank == 0) { |
638 |
|
#endif // is_mpi |
639 |
|
|
640 |
< |
buffers.push_back(dumpFile_.rdbuf()); |
640 |
> |
buffers.push_back(dumpFile_->rdbuf()); |
641 |
|
|
642 |
< |
eorStream.open(eorFilename_.c_str()); |
612 |
< |
if (!eorStream.is_open()) { |
613 |
< |
sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n", |
614 |
< |
eorFilename_.c_str()); |
615 |
< |
painCave.isFatal = 1; |
616 |
< |
simError(); |
617 |
< |
} |
642 |
> |
eorStream = createOStream(eorFilename_); |
643 |
|
|
644 |
< |
buffers.push_back(eorStream.rdbuf()); |
644 |
> |
buffers.push_back(eorStream->rdbuf()); |
645 |
|
|
646 |
|
#ifdef IS_MPI |
647 |
|
} |
651 |
|
std::ostream os(&tbuf); |
652 |
|
|
653 |
|
writeFrame(os); |
654 |
+ |
|
655 |
+ |
#ifdef IS_MPI |
656 |
+ |
if (worldRank == 0) { |
657 |
+ |
#endif // is_mpi |
658 |
+ |
delete eorStream; |
659 |
+ |
|
660 |
+ |
#ifdef IS_MPI |
661 |
+ |
} |
662 |
+ |
#endif // is_mpi |
663 |
|
|
664 |
|
} |
665 |
|
|
666 |
+ |
std::ostream* DumpWriter::createOStream(const std::string& filename) { |
667 |
|
|
668 |
+ |
std::ostream* newOStream; |
669 |
+ |
#ifdef HAVE_LIBZ |
670 |
+ |
if (needCompression_) { |
671 |
+ |
newOStream = new ogzstream(filename.c_str()); |
672 |
+ |
} else { |
673 |
+ |
newOStream = new std::ofstream(filename.c_str()); |
674 |
+ |
} |
675 |
+ |
#else |
676 |
+ |
newOStream = new std::ofstream(filename.c_str()); |
677 |
+ |
#endif |
678 |
+ |
return newOStream; |
679 |
+ |
} |
680 |
|
|
681 |
|
}//end namespace oopse |