# | Line 43 | Line 43 | |
---|---|---|
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 | |
# | Line 51 | Line 54 | namespace oopse { | |
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 | + | if (needCompression_) { |
62 | + | filename_ += ".gz"; |
63 | + | eorFilename_ += ".gz"; |
64 | + | } |
65 | + | |
66 | #ifdef IS_MPI | |
67 | ||
68 | if (worldRank == 0) { | |
69 | #endif // is_mpi | |
70 | ||
59 | – | dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
71 | ||
72 | + | dumpFile_ = createOStream(filename_); |
73 | + | |
74 | if (!dumpFile_) { | |
75 | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", | |
76 | filename_.c_str()); | |
# | Line 79 | Line 92 | namespace oopse { | |
92 | ||
93 | DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) | |
94 | : info_(info), filename_(filename){ | |
95 | + | |
96 | + | Globals* simParams = info->getSimParams(); |
97 | + | eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
98 | + | |
99 | + | needCompression_ = simParams->getCompressDumpFile(); |
100 | + | if (needCompression_) { |
101 | + | filename_ += ".gz"; |
102 | + | eorFilename_ += ".gz"; |
103 | + | } |
104 | + | |
105 | #ifdef IS_MPI | |
106 | ||
107 | if (worldRank == 0) { | |
108 | #endif // is_mpi | |
109 | ||
87 | – | eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
88 | – | dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
110 | ||
111 | + | dumpFile_ = createOStream(filename_); |
112 | + | |
113 | if (!dumpFile_) { | |
114 | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", | |
115 | filename_.c_str()); | |
# | Line 112 | Line 135 | namespace oopse { | |
135 | if (worldRank == 0) { | |
136 | #endif // is_mpi | |
137 | ||
138 | < | dumpFile_.close(); |
138 | > | delete dumpFile_; |
139 | ||
140 | #ifdef IS_MPI | |
141 | ||
# | Line 572 | Line 595 | namespace oopse { | |
595 | } | |
596 | ||
597 | void DumpWriter::writeDump() { | |
598 | < | writeFrame(dumpFile_); |
576 | < | |
598 | > | writeFrame(*dumpFile_); |
599 | } | |
600 | ||
601 | void DumpWriter::writeEor() { | |
602 | < | std::ofstream eorStream; |
602 | > | std::ostream* eorStream; |
603 | ||
604 | #ifdef IS_MPI | |
605 | if (worldRank == 0) { | |
606 | #endif // is_mpi | |
607 | ||
608 | < | 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 | < | } |
608 | > | eorStream = createOStream(eorFilename_); |
609 | ||
610 | #ifdef IS_MPI | |
611 | } | |
612 | #endif // is_mpi | |
613 | ||
614 | < | writeFrame(eorStream); |
614 | > | writeFrame(*eorStream); |
615 | > | |
616 | > | #ifdef IS_MPI |
617 | > | if (worldRank == 0) { |
618 | > | #endif // is_mpi |
619 | > | delete eorStream; |
620 | > | |
621 | > | #ifdef IS_MPI |
622 | > | } |
623 | > | #endif // is_mpi |
624 | > | |
625 | } | |
626 | ||
627 | ||
628 | void DumpWriter::writeDumpAndEor() { | |
603 | – | std::ofstream eorStream; |
629 | std::vector<std::streambuf*> buffers; | |
630 | + | std::ostream* eorStream; |
631 | #ifdef IS_MPI | |
632 | if (worldRank == 0) { | |
633 | #endif // is_mpi | |
634 | ||
635 | < | buffers.push_back(dumpFile_.rdbuf()); |
635 | > | buffers.push_back(dumpFile_->rdbuf()); |
636 | ||
637 | < | 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 | < | } |
637 | > | eorStream = createOStream(eorFilename_); |
638 | ||
639 | < | buffers.push_back(eorStream.rdbuf()); |
639 | > | buffers.push_back(eorStream->rdbuf()); |
640 | ||
641 | #ifdef IS_MPI | |
642 | } | |
# | Line 626 | Line 646 | namespace oopse { | |
646 | std::ostream os(&tbuf); | |
647 | ||
648 | writeFrame(os); | |
649 | + | |
650 | + | #ifdef IS_MPI |
651 | + | if (worldRank == 0) { |
652 | + | #endif // is_mpi |
653 | + | delete eorStream; |
654 | + | |
655 | + | #ifdef IS_MPI |
656 | + | } |
657 | + | #endif // is_mpi |
658 | ||
659 | } | |
660 | ||
661 | + | std::ostream* DumpWriter::createOStream(const std::string& filename) { |
662 | + | std::ostream* newOStream; |
663 | + | if (needCompression_) { |
664 | + | newOStream = new ogzstream(filename.c_str()); |
665 | + | } else { |
666 | + | newOStream = new std::ofstream(filename.c_str()); |
667 | + | } |
668 | + | return newOStream; |
669 | + | } |
670 | ||
633 | – | |
671 | }//end namespace oopse |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |