26 void initialize()
override {
27 const std::string & path = getPath();
28 const std::string & subpath = getSubpath();
29 createArchiveDirectory_(path, subpath);
30 openBinaryArchiveFile_(path, subpath);
39 serializeArchiveTree_(*root, path, subpath);
48 const std::string & source_path = stream->getPath();
49 const std::string & source_subpath = stream->getSubpath();
50 const std::string source_full_path = source_path +
"/" + source_subpath;
52 const std::string source_tree_filename = source_full_path +
"/archive_tree.bin";
53 if (!std::filesystem::exists(source_tree_filename)) {
55 "Metadata file not available for read: ") << source_tree_filename;
58 const std::string & dest_path = getPath();
59 const std::string & dest_subpath = getSubpath();
60 const std::string dest_full_path = dest_path +
"/" + dest_subpath;
62 const std::string dest_tree_filename = dest_full_path +
"/archive_tree.bin";
63 if (std::filesystem::exists(dest_tree_filename)) {
64 std::filesystem::remove(dest_tree_filename);
67 std::filesystem::copy_file(source_tree_filename, dest_tree_filename);
71 void sendToSink(
const std::vector<double> & values)
override {
72 if (!values.empty()) {
73 binary_fout_.write(
reinterpret_cast<const char*
>(
74 &values[0]), values.size() *
sizeof(
double));
82 void flush()
override {
87 void createArchiveDirectory_(
const std::string & path,
88 const std::string & subpath)
const
90 std::filesystem::create_directories(path +
"/" + subpath);
93 void openBinaryArchiveFile_(
const std::string & path,
94 const std::string & subpath)
96 const std::string binary_filename = path +
"/" + subpath +
"/values.bin";
97 if (std::filesystem::exists(binary_filename)) {
98 std::filesystem::remove(binary_filename);
101 binary_fout_.open(binary_filename, std::ios::binary);
104 "Unable to open archive file for write: ") << binary_filename;
107 auto root = getRoot_();
109 root->setMetadataValue(
"output_filename", binary_filename);
119 const std::string & path,
120 const std::string & subpath)
const
122 const std::string filename = path +
"/" + subpath +
"/archive_tree.bin";
123 if (std::filesystem::exists(filename)) {
124 std::filesystem::remove(filename);
127 std::ofstream fout(filename, std::ios::binary);
130 "Unable to open archive file for write: ") << filename;
133 boost::archive::binary_oarchive oa(fout);
137 std::ofstream binary_fout_;