From ce8753ab009e19080576af508335c588e18fdf5c Mon Sep 17 00:00:00 2001 From: Babicaa Date: Thu, 25 Apr 2019 14:21:40 +0200 Subject: [PATCH] Add header types to PSIWriter --- lib/src/PSIWriter.cpp | 55 ++++++++++++++++++++++++++----------------- lib/src/PSIWriter.hpp | 7 ++++++ 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/lib/src/PSIWriter.cpp b/lib/src/PSIWriter.cpp index ad50b82..237e9fa 100644 --- a/lib/src/PSIWriter.cpp +++ b/lib/src/PSIWriter.cpp @@ -1,10 +1,9 @@ #include "PSIWriter.hpp" +#include "config.hpp" +#include "BufferedWriter.hpp" using namespace std; -void PSIWriter::join_writer(){ - writing_thread.join(); -} void PSIWriter::run_writer(WriterManager& writer_manager, string output_file, @@ -12,11 +11,15 @@ void PSIWriter::run_writer(WriterManager& writer_manager, { writing_thread = boost::thread(&PSIWriter::write_h5, this, - &writer_manager, + boost::ref(writer_manager), output_file, n_frames); } +void PSIWriter::join_writer(){ + writing_thread.join(); +} + void PSIWriter::write_h5(WriterManager& writer_manager, string output_file, uint64_t n_frames) @@ -28,7 +31,7 @@ void PSIWriter::write_h5(WriterManager& writer_manager, auto metadata_buffer = unique_ptr( new MetadataBuffer(metadata_buffer_size, - receiver.get_header_values_type())); + header_values_type)); auto writer = get_buffered_writer( output_file, @@ -71,7 +74,9 @@ void PSIWriter::write_h5(WriterManager& writer_manager, #ifdef DEBUG_OUTPUT using namespace date; - cout << "[" << chrono::system_clock::now() << "]"; + using namespace chrono; + + cout << "[" << system_clock::now() << "]"; cout << "[PSIWriter::write_h5] Frame index "; cout << received_data.first->frame_index; cout << " does not belong to current file. "; @@ -85,7 +90,9 @@ void PSIWriter::write_h5(WriterManager& writer_manager, #ifdef PERF_OUTPUT using namespace date; - auto start_time_frame = chrono::system_clock::now(); + using namespace chrono; + + auto start_time_frame = system_clock::now(); #endif // Write image data. @@ -101,13 +108,12 @@ void PSIWriter::write_h5(WriterManager& writer_manager, using namespace date; using namespace chrono; - auto frame_time_difference = - chrono::system_clock::now() - start_time_frame; + auto frame_time_difference = system_clock::now() - start_time_frame; auto frame_diff_ms = duration(frame_time_difference).count(); - cout << "[" << chrono::system_clock::now() << "]"; + cout << "[" << system_clock::now() << "]"; cout << "[PSIWriter::write_h5] Frame index "; cout << received_data.first->frame_index; cout << " written in " << frame_diff_ms << " ms." << endl; @@ -117,11 +123,12 @@ void PSIWriter::write_h5(WriterManager& writer_manager, #ifdef PERF_OUTPUT using namespace date; - auto start_time_metadata = chrono::system_clock::now(); + using namespace chrono; + + auto start_time_metadata = system_clock::now(); #endif // Write image metadata if mapping specified. - auto header_values_type = receiver.get_header_values_type(); if (header_values_type) { for (const auto& header_type : *header_values_type) { @@ -147,10 +154,10 @@ void PSIWriter::write_h5(WriterManager& writer_manager, using namespace date; using namespace chrono; - auto metadata_time_difference = chrono::system_clock::now() - start_time_metadata; + auto metadata_time_difference = system_clock::now() - start_time_metadata; auto metadata_diff_ms = duration(metadata_time_difference).count(); - cout << "[" << chrono::system_clock::now() << "]"; + cout << "[" << system_clock::now() << "]"; cout << "[ProcessManager::write_h5] Frame metadata index "; cout << received_data.first->frame_index << " written in " << metadata_diff_ms << " ms." << endl; #endif @@ -164,7 +171,9 @@ void PSIWriter::write_h5(WriterManager& writer_manager, if (writer->is_file_open()) { #ifdef DEBUG_OUTPUT using namespace date; - cout << "[" << chrono::system_clock::now() << "]"; + using namespace chrono; + + cout << "[" << system_clock::now() << "]"; cout << "[ProcessManager::write] Writing file format." << endl; #endif @@ -175,7 +184,9 @@ void PSIWriter::write_h5(WriterManager& writer_manager, #ifdef DEBUG_OUTPUT using namespace date; - cout << "[" << chrono::system_clock::now() << "]"; + using namespace chrono; + + cout << "[" << system_clock::now() << "]"; cout << "[ProcessManager::write] Closing file " << writer_manager.get_output_file() << endl; #endif @@ -183,7 +194,9 @@ void PSIWriter::write_h5(WriterManager& writer_manager, #ifdef DEBUG_OUTPUT using namespace date; - cout << "[" << chrono::system_clock::now() << "]"; + using namespace chrono; + + cout << "[" << system_clock::now() << "]"; cout << "[ProcessManager::write] Writer thread stopped." << endl; #endif @@ -196,13 +209,13 @@ void PSIWriter::write_h5(WriterManager& writer_manager, void PSIWriter::write_h5_format(H5::H5File& file) { - const auto parameters = writer_manager.get_parameters(); - try { - H5FormatUtils::write_format(file, format, parameters); + H5FormatUtils::write_format(file, format, {}); } catch (const runtime_error& ex) { using namespace date; - cout << "[" << chrono::system_clock::now() << "]"; + using namespace chrono; + + cout << "[" << system_clock::now() << "]"; cout << "[ProcessManager::write_h5_format] Error while"; cout << " trying to write file format: "<< ex.what() << endl; } diff --git a/lib/src/PSIWriter.hpp b/lib/src/PSIWriter.hpp index 7d59b84..da9a0b8 100644 --- a/lib/src/PSIWriter.hpp +++ b/lib/src/PSIWriter.hpp @@ -10,25 +10,32 @@ #include "H5Format.hpp" #include "RingBuffer.hpp" #include "MetadataBuffer.hpp" +#include "ZmqReceiver.hpp" class PSIWriter { + RingBuffer& ring_buffer; const H5Format& format; hsize_t frames_per_file; + typedef std::unordered_map header_map; + std::shared_ptr header_values_type = NULL; + protected: boost::thread writing_thread; void write_h5(WriterManager& writer_manager, std::string output_file, uint64_t n_frames); + void write_h5_format(H5::H5File& file); public: PSIWriter(RingBuffer& ring_buffer, const H5Format& format, + std::shared_ptr header_values_type, hsize_t frames_per_file=0); void run_writer(WriterManager& writer_manager,