mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-03 01:44:12 +02:00
File format refactoring
This commit is contained in:
+1
-36
@@ -187,41 +187,6 @@ hsize_t HDF5ChunkedWriter::prepare_storage_for_frame(size_t frame_index, size_t*
|
||||
return relative_frame_index;
|
||||
}
|
||||
|
||||
void HDF5ChunkedWriter::write_format_data(H5::CommonFG& file_node, h5_parent& format_node, std::map<std::string, h5_value>& values){
|
||||
auto node_group = h5_utils::create_group(file_node, format_node.name);
|
||||
|
||||
for (auto item : format_node.items) {
|
||||
|
||||
if (item->node_type == GROUP) {
|
||||
auto sub_group = dynamic_cast<h5_group*>(item);
|
||||
|
||||
write_format_data(node_group, *sub_group, values);
|
||||
} else if (item->node_type == ATTRIBUTE) {
|
||||
auto sub_attribute = dynamic_cast<h5_attr*>(item);
|
||||
|
||||
h5_utils::write_attribute(node_group, *sub_attribute, values);
|
||||
} else if (item->node_type == DATASET) {
|
||||
auto sub_dataset = dynamic_cast<h5_dataset*>(item);
|
||||
|
||||
auto current_dataset = h5_utils::write_dataset(node_group, *sub_dataset, values);
|
||||
|
||||
for (auto dataset_attr : sub_dataset->items) {
|
||||
// You can specify only attributes inside a dataset.
|
||||
if (dataset_attr->node_type != ATTRIBUTE) {
|
||||
stringstream error_message;
|
||||
error_message << "Invalid element " << dataset_attr->name << " on dataset " << sub_dataset->name << ". Only attributes allowd.";
|
||||
|
||||
throw invalid_argument( error_message.str() );
|
||||
}
|
||||
|
||||
auto sub_attribute = dynamic_cast<h5_attr*>(item);
|
||||
|
||||
h5_utils::write_attribute(current_dataset, *sub_attribute, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HDF5ChunkedWriter::write_format(h5_group& format_root, std::map<std::string, h5_value>& values) {
|
||||
write_format_data(file, format_root, values);
|
||||
h5_utils::write_format_data(file, format_root, values);
|
||||
}
|
||||
@@ -31,8 +31,6 @@ class HDF5ChunkedWriter
|
||||
hsize_t prepare_storage_for_frame(size_t frame_index, size_t* frame_shape);
|
||||
void create_file(size_t* frame_shape, hsize_t frame_chunk=0);
|
||||
|
||||
void write_format_data(H5::CommonFG& file_node, h5_parent& format_node, std::map<std::string, h5_value>& values);
|
||||
|
||||
public:
|
||||
HDF5ChunkedWriter(const std::string filename, const std::string dataset_name, hsize_t frames_per_file=0, hsize_t initial_dataset_size=config::initial_dataset_size);
|
||||
~HDF5ChunkedWriter();
|
||||
|
||||
@@ -224,4 +224,39 @@ void h5_utils::write_attribute(H5::H5Object& target, h5_attr& attribute, map<str
|
||||
|
||||
throw runtime_error(error_message.str());
|
||||
}
|
||||
}
|
||||
|
||||
void h5_utils::write_format_data(H5::CommonFG& file_node, h5_parent& format_node, std::map<std::string, h5_value>& values){
|
||||
auto node_group = h5_utils::create_group(file_node, format_node.name);
|
||||
|
||||
for (auto item : format_node.items) {
|
||||
|
||||
if (item->node_type == GROUP) {
|
||||
auto sub_group = dynamic_cast<h5_group*>(item);
|
||||
|
||||
write_format_data(node_group, *sub_group, values);
|
||||
} else if (item->node_type == ATTRIBUTE) {
|
||||
auto sub_attribute = dynamic_cast<h5_attr*>(item);
|
||||
|
||||
h5_utils::write_attribute(node_group, *sub_attribute, values);
|
||||
} else if (item->node_type == DATASET) {
|
||||
auto sub_dataset = dynamic_cast<h5_dataset*>(item);
|
||||
|
||||
auto current_dataset = h5_utils::write_dataset(node_group, *sub_dataset, values);
|
||||
|
||||
for (auto dataset_attr : sub_dataset->items) {
|
||||
// You can specify only attributes inside a dataset.
|
||||
if (dataset_attr->node_type != ATTRIBUTE) {
|
||||
stringstream error_message;
|
||||
error_message << "Invalid element " << dataset_attr->name << " on dataset " << sub_dataset->name << ". Only attributes allowd.";
|
||||
|
||||
throw invalid_argument( error_message.str() );
|
||||
}
|
||||
|
||||
auto sub_attribute = dynamic_cast<h5_attr*>(item);
|
||||
|
||||
h5_utils::write_attribute(current_dataset, *sub_attribute, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -3,9 +3,10 @@
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <H5Cpp.h>
|
||||
#include <map>
|
||||
|
||||
typedef boost::any h5_value;
|
||||
|
||||
@@ -81,6 +82,8 @@ namespace h5_utils{
|
||||
void write_attribute(H5::H5Object& target, std::string name, int value);
|
||||
|
||||
boost::any get_value_from_reference(std::string& dataset_name, boost::any value_reference, std::map<std::string, boost::any>& values);
|
||||
|
||||
void write_format_data(H5::CommonFG& file_node, h5_parent& format_node, std::map<std::string, h5_value>& values);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user