37 #include <boost/archive/text_oarchive.hpp>
38 #include <boost/archive/text_iarchive.hpp>
43 #include "ArchiveOpener.hpp"
44 #include "ArchiveLocationInfo.hpp"
45 #include "ProcessSpecificArchive.hpp"
47 #include "OutputFileHandler.hpp"
58 const std::string& rFileNameBase,
60 : mpCommonStream(nullptr),
61 mpPrivateStream(nullptr),
62 mpCommonArchive(nullptr),
63 mpPrivateArchive(nullptr)
68 std::stringstream common_path;
72 mpCommonStream =
new std::ifstream(common_path.str().c_str(), std::ios::binary);
76 EXCEPTION(
"Cannot load main archive file: " + common_path.str());
83 catch (boost::archive::archive_exception& boost_exception)
85 if (boost_exception.code == boost::archive::archive_exception::unsupported_version)
90 EXCEPTION(
"Could not open Boost archive '" + common_path.str() +
"' because it was written by a more recent Boost. Check process-specific archives too");
95 throw boost_exception;
100 mpPrivateStream =
new std::ifstream(private_path.c_str(), std::ios::binary);
106 EXCEPTION(
"Cannot load secondary archive file: " + private_path);
116 delete mpPrivateArchive;
117 delete mpPrivateStream;
118 delete mpCommonArchive;
119 delete mpCommonStream;
131 const std::string& rFileNameBase,
133 : mpCommonStream(nullptr),
134 mpPrivateStream(nullptr),
135 mpCommonArchive(nullptr),
136 mpPrivateArchive(nullptr)
141 EXCEPTION(
"Specifying the secondary archive file ID doesn't make sense when writing.");
152 std::stringstream common_path;
158 mpCommonStream =
new std::ofstream(common_path.str().c_str(), std::ios::binary | std::ios::trunc);
162 EXCEPTION(
"Failed to open main archive file for writing: " + common_path.str());
169 mpCommonStream =
new std::ofstream(
"NUL", std::ios::binary | std::ios::trunc);
171 mpCommonStream =
new std::ofstream(
"/dev/null", std::ios::binary | std::ios::trunc);
177 EXCEPTION(
"Failed to open dummy archive file '/dev/null' for writing");
184 mpPrivateStream =
new std::ofstream(private_path.c_str(), std::ios::binary | std::ios::trunc);
190 EXCEPTION(
"Failed to open secondary archive file for writing: " + private_path);
200 delete mpPrivateArchive;
201 delete mpPrivateStream;
202 delete mpCommonArchive;
203 delete mpCommonStream;
static std::string GetProcessUniqueFilePath(const std::string &rFileName, unsigned procId=PetscTools::GetMyRank())
ArchiveOpener(const FileFinder &rDirectory, const std::string &rFileNameBase, unsigned procId=PetscTools::GetMyRank())
static bool GetIsDirRelativeToChasteTestOutput()
#define EXCEPTION(message)
Archive * mpPrivateArchive
static std::string GetArchiveDirectory()
static std::string GetArchiveRelativePath()
static void SetArchiveDirectory(const FileFinder &rDirectory)
Archive * mpCommonArchive
static void Set(Archive *pArchive)