From 3054328a404cf3d6a21d5a5261037d0fe5b0a9ed Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Wed, 31 Jan 2018 15:48:08 +0100 Subject: [PATCH] Rename H5FormatUtils namespace --- src/H5Format.cpp | 60 +++++++++++++++++++++---------------------- src/H5Format.hpp | 3 ++- src/H5Writer.cpp | 10 ++++---- src/h5_zmq_writer.cpp | 2 +- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/H5Format.cpp b/src/H5Format.cpp index aaeb84d..71f4332 100644 --- a/src/H5Format.cpp +++ b/src/H5Format.cpp @@ -7,7 +7,7 @@ using namespace std; -hsize_t H5Format::expand_dataset(H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step) +hsize_t H5FormatUtils::expand_dataset(H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step) { hsize_t dataset_rank = 3; hsize_t dataset_dimension[dataset_rank]; @@ -16,7 +16,7 @@ hsize_t H5Format::expand_dataset(H5::DataSet& dataset, hsize_t frame_index, hsiz dataset_dimension[0] = frame_index + dataset_increase_step; #ifdef DEBUG_OUTPUT - cout << "[H5Format::expand_dataset] Expanding dataspace to size ("; + cout << "[H5FormatUtils::expand_dataset] Expanding dataspace to size ("; for (hsize_t i=0; i& values) +const boost::any& H5FormatUtils::get_value_from_reference(const string& dataset_name, const boost::any& value_reference, const map& values) { try { auto reference_string = boost::any_cast(value_reference); @@ -72,10 +72,10 @@ const boost::any& H5Format::get_value_from_reference(const string& dataset_name, } } -H5::PredType H5Format::get_dataset_data_type(const string& type){ +H5::PredType H5FormatUtils::get_dataset_data_type(const string& type){ #ifdef DEBUG_OUTPUT - cout << "[H5Format::get_dataset_data_type] Getting dataset type for received frame type " << type << endl; + cout << "[H5FormatUtils::get_dataset_data_type] Getting dataset type for received frame type " << type << endl; #endif if (type == "uint8") { @@ -105,7 +105,7 @@ H5::PredType H5Format::get_dataset_data_type(const string& type){ } } -H5::DataSet H5Format::write_dataset(H5::Group& target, const h5_dataset& dataset, const map& values){ +H5::DataSet H5FormatUtils::write_dataset(H5::Group& target, const h5_dataset& dataset, const map& values){ string name = dataset.name; boost::any value; @@ -114,18 +114,18 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, const h5_dataset& dataset value = dataset.value; // Value in struct is just a string reference to into the values map. } else { - value = H5Format::get_value_from_reference(name, dataset.value, values); + value = H5FormatUtils::get_value_from_reference(name, dataset.value, values); } if (dataset.data_type == NX_CHAR || dataset.data_type == NX_DATE_TIME || dataset.data_type == NXnote) { // Attempt to convert to const char * (string "literals" cause that). try { - return H5Format::write_dataset(target, name, string(boost::any_cast(value))); + return H5FormatUtils::write_dataset(target, name, string(boost::any_cast(value))); } catch (const boost::bad_any_cast& exception) {} // Atempt to convert to string. try { - return H5Format::write_dataset(target, name, boost::any_cast(value)); + return H5FormatUtils::write_dataset(target, name, boost::any_cast(value)); } catch (const boost::bad_any_cast& exception) {} // We cannot really convert this attribute. @@ -136,7 +136,7 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, const h5_dataset& dataset } else if (dataset.data_type == NX_INT) { try { - return H5Format::write_dataset(target, name, boost::any_cast(value)); + return H5FormatUtils::write_dataset(target, name, boost::any_cast(value)); } catch (const boost::bad_any_cast& exception) {} // We cannot really convert this attribute. @@ -146,7 +146,7 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, const h5_dataset& dataset throw runtime_error(error_message.str()); } else if (dataset.data_type == NX_FLOAT || dataset.data_type == NX_NUMBER) { try { - return H5Format::write_dataset(target, name, boost::any_cast(value)); + return H5FormatUtils::write_dataset(target, name, boost::any_cast(value)); } catch (const boost::bad_any_cast& exception) {} // We cannot really convert this attribute. @@ -162,7 +162,7 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, const h5_dataset& dataset } } -H5::DataSet H5Format::write_dataset(H5::Group& target, const string& name, double value) +H5::DataSet H5FormatUtils::write_dataset(H5::Group& target, const string& name, double value) { H5::DataSpace att_space(H5S_SCALAR); auto data_type = H5::PredType::NATIVE_DOUBLE; @@ -173,7 +173,7 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, const string& name, doubl return dataset; } -H5::DataSet H5Format::write_dataset(H5::Group& target, const string& name, int value) +H5::DataSet H5FormatUtils::write_dataset(H5::Group& target, const string& name, int value) { H5::DataSpace att_space(H5S_SCALAR); auto data_type = H5::PredType::NATIVE_INT; @@ -184,7 +184,7 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, const string& name, int v return dataset; } -H5::DataSet H5Format::write_dataset(H5::Group& target, const string& name, const string& value) +H5::DataSet H5FormatUtils::write_dataset(H5::Group& target, const string& name, const string& value) { H5::DataSpace att_space(H5S_SCALAR); H5::DataType data_type = H5::StrType(0, H5T_VARIABLE); @@ -195,7 +195,7 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, const string& name, const return dataset; } -void H5Format::write_attribute(H5::H5Object& target, const string& name, const string& value) +void H5FormatUtils::write_attribute(H5::H5Object& target, const string& name, const string& value) { H5::DataSpace att_space(H5S_SCALAR); H5::DataType data_type = H5::StrType(H5::PredType::C_S1, H5T_VARIABLE); @@ -204,7 +204,7 @@ void H5Format::write_attribute(H5::H5Object& target, const string& name, const s h5_attribute.write(data_type, &value); } -void H5Format::write_attribute(H5::H5Object& target, const string& name, int value) +void H5FormatUtils::write_attribute(H5::H5Object& target, const string& name, int value) { H5::DataSpace att_space(H5S_SCALAR); auto data_type = H5::PredType::NATIVE_INT; @@ -213,7 +213,7 @@ void H5Format::write_attribute(H5::H5Object& target, const string& name, int val h5_attribute.write(data_type, &value); } -void H5Format::write_attribute(H5::H5Object& target, const h5_attr& attribute, const map& values) +void H5FormatUtils::write_attribute(H5::H5Object& target, const h5_attr& attribute, const map& values) { string name = attribute.name; boost::any value; @@ -223,19 +223,19 @@ void H5Format::write_attribute(H5::H5Object& target, const h5_attr& attribute, c value = attribute.value; // Value in struct is just a string reference to into the values map. } else { - value = H5Format::get_value_from_reference(name, attribute.value, values); + value = H5FormatUtils::get_value_from_reference(name, attribute.value, values); } if (attribute.data_type == NX_CHAR) { // Attempt to convert to const char * (string "literals" cause that). try { - H5Format::write_attribute(target, name, string(boost::any_cast(value))); + H5FormatUtils::write_attribute(target, name, string(boost::any_cast(value))); return; } catch (const boost::bad_any_cast& exception) {} // Atempt to convert to string. try { - H5Format::write_attribute(target, name, boost::any_cast(value)); + H5FormatUtils::write_attribute(target, name, boost::any_cast(value)); return; } catch (const boost::bad_any_cast& exception) {} @@ -247,7 +247,7 @@ void H5Format::write_attribute(H5::H5Object& target, const h5_attr& attribute, c } else if (attribute.data_type == NX_INT) { try { - H5Format::write_attribute(target, name, boost::any_cast(value)); + H5FormatUtils::write_attribute(target, name, boost::any_cast(value)); return; } catch (const boost::bad_any_cast& exception) {} @@ -259,8 +259,8 @@ void H5Format::write_attribute(H5::H5Object& target, const h5_attr& attribute, c } } -void H5Format::write_format_data(H5::Group& file_node, const h5_parent& format_node, const std::map& values) { - auto node_group = H5Format::create_group(file_node, format_node.name); +void H5FormatUtils::write_format_data(H5::Group& file_node, const h5_parent& format_node, const std::map& values) { + auto node_group = H5FormatUtils::create_group(file_node, format_node.name); for (const auto item : format_node.items) { @@ -271,10 +271,10 @@ void H5Format::write_format_data(H5::Group& file_node, const h5_parent& format_n } else if (item->node_type == ATTRIBUTE) { auto sub_attribute = dynamic_cast(item); - H5Format::write_attribute(node_group, *sub_attribute, values); + H5FormatUtils::write_attribute(node_group, *sub_attribute, values); } else if (item->node_type == DATASET) { auto sub_dataset = dynamic_cast(item); - auto current_dataset = H5Format::write_dataset(node_group, *sub_dataset, values); + auto current_dataset = H5FormatUtils::write_dataset(node_group, *sub_dataset, values); for (const auto dataset_attr : sub_dataset->items) { @@ -288,13 +288,13 @@ void H5Format::write_format_data(H5::Group& file_node, const h5_parent& format_n auto sub_attribute = dynamic_cast(dataset_attr); - H5Format::write_attribute(current_dataset, *sub_attribute, values); + H5FormatUtils::write_attribute(current_dataset, *sub_attribute, values); } } } } -void H5Format::write_format(H5::H5File& file, const std::map& input_values, const string& raw_frames_dataset_name, const string& frames_dataset_name){ +void H5FormatUtils::write_format(H5::H5File& file, const std::map& input_values, const string& raw_frames_dataset_name, const string& frames_dataset_name){ auto format = get_format_definition(); auto values = get_default_values(); diff --git a/src/H5Format.hpp b/src/H5Format.hpp index 8285a06..4f3d066 100644 --- a/src/H5Format.hpp +++ b/src/H5Format.hpp @@ -66,7 +66,7 @@ struct h5_attr : public h5_base, public h5_data_base { h5_value value; }; -namespace H5Format { +namespace H5FormatUtils { hsize_t expand_dataset(H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step); void compact_dataset(H5::DataSet& dataset, hsize_t max_frame_index); @@ -88,6 +88,7 @@ namespace H5Format { void write_format(H5::H5File& file, const std::map& input_values, const std::string& raw_frames_dataset_name, const std::string& frames_dataset_name); }; + // Move this somewhere else. const std::map* get_input_value_type(); std::map* get_default_values(); diff --git a/src/H5Writer.cpp b/src/H5Writer.cpp index 5d3fe4a..dda4c98 100644 --- a/src/H5Writer.cpp +++ b/src/H5Writer.cpp @@ -46,7 +46,7 @@ void H5Writer::close_file() cout << "[H5Writer::close_file] Closing file." << endl; #endif - H5Format::compact_dataset(dataset, max_frame_index); + H5FormatUtils::compact_dataset(dataset, max_frame_index); hsize_t min_frame_in_dataset = 0; if (frames_per_file) { @@ -64,8 +64,8 @@ void H5Writer::close_file() cout << "[H5Writer::close_file] Setting dataset attribute image_nr_low=" << image_nr_low << " and image_nr_high=" << image_nr_high << endl; #endif - H5Format::write_attribute(dataset, "image_nr_low", image_nr_low); - H5Format::write_attribute(dataset, "image_nr_high", image_nr_high); + H5FormatUtils::write_attribute(dataset, "image_nr_low", image_nr_low); + H5FormatUtils::write_attribute(dataset, "image_nr_high", image_nr_high); // Cleanup. file.close(); @@ -140,7 +140,7 @@ void H5Writer::create_file(const size_t* frame_shape, hsize_t frame_chunk, const const hsize_t dataset_chunking[] = {1, frame_shape[0], frame_shape[1]}; dataset_properties.setChunk(dataset_rank, dataset_chunking); - H5::AtomType data_type(H5Format::get_dataset_data_type(type)); + H5::AtomType data_type(H5FormatUtils::get_dataset_data_type(type)); if (endianness == "big") { data_type.setOrder(H5T_ORDER_BE); @@ -191,7 +191,7 @@ hsize_t H5Writer::prepare_storage_for_frame(size_t frame_index, const size_t* fr // Expand the dataset if needed. if (relative_frame_index > current_dataset_size) { - current_dataset_size = H5Format::expand_dataset(dataset, relative_frame_index, dataset_increase_step); + current_dataset_size = H5FormatUtils::expand_dataset(dataset, relative_frame_index, dataset_increase_step); } // Keep track of the max index in this file - needed for shrinking the dataset at the end. diff --git a/src/h5_zmq_writer.cpp b/src/h5_zmq_writer.cpp index d46afb1..55484e8 100644 --- a/src/h5_zmq_writer.cpp +++ b/src/h5_zmq_writer.cpp @@ -65,7 +65,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 { - H5Format::write_format(writer.get_h5_file(), parameters, config::raw_dataset_name, get_frames_dataset_name()); + H5FormatUtils::write_format(writer.get_h5_file(), parameters, config::raw_dataset_name, get_frames_dataset_name()); } catch (const runtime_error& ex) { cerr << "[h5_zmq_writer::write] Error while trying to write file format: "<< ex.what() << endl; }