mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-01 15:32:22 +02:00
Add H5Format class
This commit is contained in:
+7
-8
@@ -296,17 +296,16 @@ void H5FormatUtils::write_format_data(H5::Group& file_node, const h5_parent& for
|
||||
}
|
||||
}
|
||||
|
||||
void H5FormatUtils::write_format(H5::H5File& file, const std::map<std::string, h5_value>& input_values,
|
||||
const string& raw_frames_dataset_name, const string& frames_dataset_name)
|
||||
void H5FormatUtils::write_format(H5::H5File& file, const H5Format& format, const std::map<std::string, h5_value>& input_values)
|
||||
{
|
||||
|
||||
auto format = get_format_definition();
|
||||
auto values = get_default_values();
|
||||
auto format_definition = format.get_format_definition();
|
||||
auto values = format.get_default_values();
|
||||
|
||||
add_input_values(*values, input_values);
|
||||
add_calculated_values(*values);
|
||||
format.add_input_values(*values, input_values);
|
||||
format.add_calculated_values(*values);
|
||||
|
||||
write_format_data(file, *format, *values);
|
||||
write_format_data(file, *format_definition, *values);
|
||||
|
||||
file.move(raw_frames_dataset_name.c_str(), frames_dataset_name.c_str());
|
||||
file.move(format.get_raw_frames_dataset_name().c_str(), format.get_frames_dataset_name().c_str());
|
||||
}
|
||||
+16
-9
@@ -75,6 +75,21 @@ struct h5_attr : public h5_base, public h5_data_base
|
||||
h5_value value;
|
||||
};
|
||||
|
||||
class H5Format
|
||||
{
|
||||
public:
|
||||
virtual ~H5Format(){};
|
||||
|
||||
virtual const std::map<std::string, DATA_TYPE>* get_input_value_type() const = 0;
|
||||
virtual std::map<std::string, boost::any>* get_default_values() const = 0;
|
||||
virtual const h5_group* get_format_definition() const = 0;
|
||||
virtual void add_calculated_values(std::map<std::string, boost::any>& values) const = 0;
|
||||
virtual void add_input_values(std::map<std::string, boost::any>& values, const std::map<std::string, boost::any>& input_values) const = 0;
|
||||
|
||||
virtual std::string get_raw_frames_dataset_name() const = 0;
|
||||
virtual std::string get_frames_dataset_name() const = 0;
|
||||
};
|
||||
|
||||
namespace H5FormatUtils
|
||||
{
|
||||
hsize_t expand_dataset(H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step);
|
||||
@@ -95,15 +110,7 @@ namespace H5FormatUtils
|
||||
const boost::any& get_value_from_reference(const std::string& dataset_name, const boost::any& value_reference, const std::map<std::string, boost::any>& values);
|
||||
|
||||
void write_format_data(H5::Group& file_node, const h5_parent& format_node, const std::map<std::string, h5_value>& values);
|
||||
void write_format(H5::H5File& file, const std::map<std::string, h5_value>& input_values, const std::string& raw_frames_dataset_name, const std::string& frames_dataset_name);
|
||||
void write_format(H5::H5File& file, const H5Format& format, const std::map<std::string, h5_value>& input_values);
|
||||
};
|
||||
|
||||
// Move this somewhere else.
|
||||
const std::map<std::string, DATA_TYPE>* get_input_value_type();
|
||||
std::map<std::string, boost::any>* get_default_values();
|
||||
const h5_group* get_format_definition();
|
||||
void add_calculated_values(std::map<std::string, boost::any>& values);
|
||||
void add_input_values(std::map<std::string, boost::any>& values, const std::map<std::string, boost::any>& input_values);
|
||||
std::string get_frames_dataset_name();
|
||||
|
||||
#endif
|
||||
+1045
File diff suppressed because it is too large
Load Diff
@@ -15,12 +15,14 @@
|
||||
#include "rest_interface.hpp"
|
||||
#include "H5Format.hpp"
|
||||
|
||||
#include "NXmxFormat.cpp"
|
||||
|
||||
using namespace std;
|
||||
namespace pt = boost::property_tree;
|
||||
|
||||
void write_h5(WriterManager& manager, RingBuffer& ring_buffer, string output_file)
|
||||
void write_h5(WriterManager& manager, H5Format& format, RingBuffer& ring_buffer, string output_file)
|
||||
{
|
||||
H5Writer writer(output_file, config::raw_dataset_name);
|
||||
H5Writer writer(output_file, format.get_raw_frames_dataset_name());
|
||||
|
||||
// Run until the running flag is set or the ring_buffer is empty.
|
||||
while(manager.is_running() || !ring_buffer.is_empty()) {
|
||||
@@ -65,7 +67,7 @@ void write_h5(WriterManager& manager, RingBuffer& ring_buffer, string output_fil
|
||||
|
||||
// Even if we can't write the format, lets try to preserve the data.
|
||||
try {
|
||||
H5FormatUtils::write_format(writer.get_h5_file(), parameters, config::raw_dataset_name, get_frames_dataset_name());
|
||||
H5FormatUtils::write_format(writer.get_h5_file(), format, parameters);
|
||||
} catch (const runtime_error& ex) {
|
||||
cerr << "[h5_zmq_writer::write] Error while trying to write file format: "<< ex.what() << endl;
|
||||
}
|
||||
@@ -165,7 +167,8 @@ void run_writer(string connect_address, string output_file, uint64_t n_frames, u
|
||||
int n_io_threads = config::zmq_n_io_threads;
|
||||
int receive_timeout = config::zmq_receive_timeout;
|
||||
|
||||
WriterManager manager(get_input_value_type(), n_frames);
|
||||
NXmxFormat format;
|
||||
WriterManager manager(format.get_input_value_type(), n_frames);
|
||||
RingBuffer ring_buffer(n_slots);
|
||||
|
||||
#ifdef DEBUG_OUTPUT
|
||||
@@ -179,7 +182,7 @@ void run_writer(string connect_address, string output_file, uint64_t n_frames, u
|
||||
#endif
|
||||
|
||||
boost::thread receiver_thread(receive_zmq, boost::ref(manager), boost::ref(ring_buffer), connect_address, n_io_threads, receive_timeout);
|
||||
boost::thread writer_thread(write_h5, boost::ref(manager), boost::ref(ring_buffer), output_file);
|
||||
boost::thread writer_thread(write_h5, boost::ref(manager), boost::ref(format), boost::ref(ring_buffer), output_file);
|
||||
|
||||
start_rest_api(manager, rest_port);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user