diff --git a/src/h5_utils.cpp b/src/H5Format.cpp similarity index 81% rename from src/h5_utils.cpp rename to src/H5Format.cpp index 7762146..c3f3faf 100644 --- a/src/h5_utils.cpp +++ b/src/H5Format.cpp @@ -3,12 +3,11 @@ #include #include -#include "h5_utils.hpp" -#include "config.hpp" +#include "H5Format.hpp" using namespace std; -hsize_t h5_utils::expand_dataset(const H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step) +hsize_t H5Format::expand_dataset(const H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step) { hsize_t dataset_rank = 3; hsize_t dataset_dimension[dataset_rank]; @@ -17,7 +16,7 @@ hsize_t h5_utils::expand_dataset(const H5::DataSet& dataset, hsize_t frame_index dataset_dimension[0] = frame_index + dataset_increase_step; #ifdef DEBUG_OUTPUT - cout << "[h5_utils::expand_dataset] Expanding dataspace to size ("; + cout << "[H5Format::expand_dataset] Expanding dataspace to size ("; for (hsize_t i=0; i& values) +boost::any H5Format::get_value_from_reference(string& dataset_name, boost::any value_reference, map& values) { try { auto reference_string = boost::any_cast(value_reference); @@ -73,10 +72,10 @@ boost::any h5_utils::get_value_from_reference(string& dataset_name, boost::any v } } -H5::PredType h5_utils::get_dataset_data_type(string& type){ +H5::PredType H5Format::get_dataset_data_type(string& type){ #ifdef DEBUG_OUTPUT - cout << "[h5_utils::get_dataset_data_type] Getting dataset type for received frame type " << type << endl; + cout << "[H5Format::get_dataset_data_type] Getting dataset type for received frame type " << type << endl; #endif if (type == "uint8") { @@ -106,7 +105,7 @@ H5::PredType h5_utils::get_dataset_data_type(string& type){ } } -H5::DataSet h5_utils::write_dataset(H5::Group& target, h5_dataset& dataset, map& values){ +H5::DataSet H5Format::write_dataset(H5::Group& target, h5_dataset& dataset, map& values){ string name = dataset.name; boost::any value; @@ -115,18 +114,18 @@ H5::DataSet h5_utils::write_dataset(H5::Group& target, h5_dataset& dataset, map< value = dataset.value; // Value in struct is just a string reference to into the values map. } else { - value = h5_utils::get_value_from_reference(name, dataset.value, values); + value = H5Format::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 h5_utils::write_dataset(target, name, string(boost::any_cast(value))); + return H5Format::write_dataset(target, name, string(boost::any_cast(value))); } catch (const boost::bad_any_cast& exception) {} // Atempt to convert to string. try { - return h5_utils::write_dataset(target, name, boost::any_cast(value)); + return H5Format::write_dataset(target, name, boost::any_cast(value)); } catch (const boost::bad_any_cast& exception) {} // We cannot really convert this attribute. @@ -137,7 +136,7 @@ H5::DataSet h5_utils::write_dataset(H5::Group& target, h5_dataset& dataset, map< } else if (dataset.data_type == NX_INT) { try { - return h5_utils::write_dataset(target, name, boost::any_cast(value)); + return H5Format::write_dataset(target, name, boost::any_cast(value)); } catch (const boost::bad_any_cast& exception) {} // We cannot really convert this attribute. @@ -147,7 +146,7 @@ H5::DataSet h5_utils::write_dataset(H5::Group& target, h5_dataset& dataset, map< throw runtime_error(error_message.str()); } else if (dataset.data_type == NX_FLOAT || dataset.data_type == NX_NUMBER) { try { - return h5_utils::write_dataset(target, name, boost::any_cast(value)); + return H5Format::write_dataset(target, name, boost::any_cast(value)); } catch (const boost::bad_any_cast& exception) {} // We cannot really convert this attribute. @@ -163,7 +162,7 @@ H5::DataSet h5_utils::write_dataset(H5::Group& target, h5_dataset& dataset, map< } } -H5::DataSet h5_utils::write_dataset(H5::Group& target, string name, double value) +H5::DataSet H5Format::write_dataset(H5::Group& target, string name, double value) { H5::DataSpace att_space(H5S_SCALAR); auto data_type = H5::PredType::NATIVE_DOUBLE; @@ -174,7 +173,7 @@ H5::DataSet h5_utils::write_dataset(H5::Group& target, string name, double value return dataset; } -H5::DataSet h5_utils::write_dataset(H5::Group& target, string name, int value) +H5::DataSet H5Format::write_dataset(H5::Group& target, string name, int value) { H5::DataSpace att_space(H5S_SCALAR); auto data_type = H5::PredType::NATIVE_INT; @@ -185,7 +184,7 @@ H5::DataSet h5_utils::write_dataset(H5::Group& target, string name, int value) return dataset; } -H5::DataSet h5_utils::write_dataset(H5::Group& target, string name, string value) +H5::DataSet H5Format::write_dataset(H5::Group& target, string name, string value) { H5::DataSpace att_space(H5S_SCALAR); H5::DataType data_type = H5::StrType(0, H5T_VARIABLE); @@ -196,7 +195,7 @@ H5::DataSet h5_utils::write_dataset(H5::Group& target, string name, string value return dataset; } -void h5_utils::write_attribute(H5::H5Object& target, string name, string value) +void H5Format::write_attribute(H5::H5Object& target, string name, string value) { H5::DataSpace att_space(H5S_SCALAR); H5::DataType data_type = H5::StrType(0, H5T_VARIABLE); @@ -205,7 +204,7 @@ void h5_utils::write_attribute(H5::H5Object& target, string name, string value) h5_attribute.write(data_type, value); } -void h5_utils::write_attribute(H5::H5Object& target, string name, int value) +void H5Format::write_attribute(H5::H5Object& target, string name, int value) { H5::DataSpace att_space(H5S_SCALAR); auto data_type = H5::PredType::NATIVE_INT; @@ -214,7 +213,7 @@ void h5_utils::write_attribute(H5::H5Object& target, string name, int value) h5_attribute.write(data_type, &value); } -void h5_utils::write_attribute(H5::H5Object& target, h5_attr& attribute, map& values) +void H5Format::write_attribute(H5::H5Object& target, h5_attr& attribute, map& values) { string name = attribute.name; boost::any value; @@ -224,19 +223,19 @@ void h5_utils::write_attribute(H5::H5Object& target, h5_attr& attribute, map(value))); + H5Format::write_attribute(target, name, string(boost::any_cast(value))); return; } catch (const boost::bad_any_cast& exception) {} // Atempt to convert to string. try { - h5_utils::write_attribute(target, name, boost::any_cast(value)); + H5Format::write_attribute(target, name, boost::any_cast(value)); return; } catch (const boost::bad_any_cast& exception) {} @@ -248,7 +247,7 @@ void h5_utils::write_attribute(H5::H5Object& target, h5_attr& attribute, map(value)); + H5Format::write_attribute(target, name, boost::any_cast(value)); return; } catch (const boost::bad_any_cast& exception) {} @@ -260,8 +259,8 @@ void h5_utils::write_attribute(H5::H5Object& target, h5_attr& attribute, map& values) { - auto node_group = h5_utils::create_group(file_node, format_node.name); +void H5Format::write_format_data(H5::CommonFG& file_node, h5_parent& format_node, std::map& values) { + auto node_group = H5Format::create_group(file_node, format_node.name); for (auto item : format_node.items) { @@ -272,10 +271,10 @@ void h5_utils::write_format_data(H5::CommonFG& file_node, h5_parent& format_node } else if (item->node_type == ATTRIBUTE) { auto sub_attribute = dynamic_cast(item); - h5_utils::write_attribute(node_group, *sub_attribute, values); + H5Format::write_attribute(node_group, *sub_attribute, values); } else if (item->node_type == DATASET) { auto sub_dataset = dynamic_cast(item); - auto current_dataset = h5_utils::write_dataset(node_group, *sub_dataset, values); + auto current_dataset = H5Format::write_dataset(node_group, *sub_dataset, values); for (auto dataset_attr : sub_dataset->items) { @@ -289,13 +288,13 @@ void h5_utils::write_format_data(H5::CommonFG& file_node, h5_parent& format_node auto sub_attribute = dynamic_cast(dataset_attr); - h5_utils::write_attribute(current_dataset, *sub_attribute, values); + H5Format::write_attribute(current_dataset, *sub_attribute, values); } } } } -void h5_utils::write_format(H5::H5File& file, std::map& input_values){ +void H5Format::write_format(H5::H5File& file, std::map& input_values){ auto format = get_format_definition(); auto values = get_default_values(); diff --git a/src/h5_utils.hpp b/src/H5Format.hpp similarity index 98% rename from src/h5_utils.hpp rename to src/H5Format.hpp index c5d89a5..9e4084e 100644 --- a/src/h5_utils.hpp +++ b/src/H5Format.hpp @@ -4,9 +4,8 @@ #include #include #include - -#include #include +#include typedef boost::any h5_value; @@ -67,7 +66,7 @@ struct h5_attr : public h5_base, public h5_data_base { h5_value value; }; -namespace h5_utils{ +namespace H5Format { hsize_t expand_dataset(const H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step); void compact_dataset(const H5::DataSet& dataset, hsize_t max_frame_index); @@ -89,6 +88,7 @@ namespace h5_utils{ void write_format(H5::H5File& file, std::map& input_values); }; +// Move this somewhere else. std::map* get_input_value_type(); std::map* get_default_values(); h5_group* get_format_definition(); @@ -96,5 +96,4 @@ void add_calculated_values(std::map& values); void add_input_values(std::map& values, std::map& input_values); - #endif \ No newline at end of file diff --git a/src/H5Writer.cpp b/src/H5Writer.cpp index 579363e..0bf6cca 100644 --- a/src/H5Writer.cpp +++ b/src/H5Writer.cpp @@ -1,8 +1,9 @@ -#include "h5_utils.hpp" #include #include #include + #include "H5Writer.hpp" +#include "H5Format.hpp" extern "C" { @@ -45,7 +46,7 @@ void H5Writer::close_file() cout << "[H5Writer::close_file] Closing file." << endl; #endif - h5_utils::compact_dataset(dataset, max_frame_index); + H5Format::compact_dataset(dataset, max_frame_index); hsize_t min_frame_in_dataset = 0; if (frames_per_file) { @@ -63,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 - h5_utils::write_attribute(dataset, "image_nr_low", image_nr_low); - h5_utils::write_attribute(dataset, "image_nr_high", image_nr_high); + H5Format::write_attribute(dataset, "image_nr_low", image_nr_low); + H5Format::write_attribute(dataset, "image_nr_high", image_nr_high); // Cleanup. file.close(); @@ -139,7 +140,7 @@ void H5Writer::create_file(size_t* frame_shape, hsize_t frame_chunk, string& typ const hsize_t dataset_chunking[] = {1, frame_shape[0], frame_shape[1]}; dataset_properties.setChunk(dataset_rank, dataset_chunking); - H5::AtomType data_type(h5_utils::get_dataset_data_type(type)); + H5::AtomType data_type(H5Format::get_dataset_data_type(type)); if (endianness == "big") { data_type.setOrder(H5T_ORDER_BE); @@ -190,7 +191,7 @@ hsize_t H5Writer::prepare_storage_for_frame(size_t frame_index, size_t* frame_sh // Expand the dataset if needed. if (relative_frame_index > current_dataset_size) { - current_dataset_size = h5_utils::expand_dataset(dataset, relative_frame_index, dataset_increase_step); + current_dataset_size = H5Format::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 c08406c..682f501 100644 --- a/src/h5_zmq_writer.cpp +++ b/src/h5_zmq_writer.cpp @@ -11,7 +11,7 @@ #include "H5Writer.hpp" #include "RingBuffer.hpp" #include "rest_interface.hpp" -#include "h5_utils.hpp" +#include "H5Format.hpp" using namespace std; namespace pt = boost::property_tree; @@ -52,7 +52,7 @@ void write_h5(WriterManager *manager, RingBuffer *ring_buffer, string output_fil cout << "[h5_zmq_writer::write] Writing file format." << endl; #endif - h5_utils::write_format(writer.get_h5_file(), manager->get_parameters()); + H5Format::write_format(writer.get_h5_file(), manager->get_parameters()); } #ifdef DEBUG_OUTPUT diff --git a/src/nxsas_format.cpp b/src/nxsas_format.cpp index ea0f21e..80a8194 100644 --- a/src/nxsas_format.cpp +++ b/src/nxsas_format.cpp @@ -1,9 +1,10 @@ -#include "h5_utils.hpp" #include #include #include #include +#include "H5Format.hpp" + using namespace std; h5_group* get_format_definition(){ diff --git a/src/rest_interface.cpp b/src/rest_interface.cpp index a6f314d..e234778 100644 --- a/src/rest_interface.cpp +++ b/src/rest_interface.cpp @@ -1,9 +1,8 @@ #include #include -#include "rest_interface.hpp" #include "crow_all.h" -#include "h5_utils.hpp" +#include "rest_interface.hpp" using namespace std; diff --git a/src/rest_interface.hpp b/src/rest_interface.hpp index e579e22..b737e59 100644 --- a/src/rest_interface.hpp +++ b/src/rest_interface.hpp @@ -2,7 +2,7 @@ #define REST_INTERFACE_H #include "WriterManager.hpp" -#include "h5_utils.hpp" +#include "H5Format.hpp" void start_rest_api(WriterManager& writer_manager, uint16_t port, std::map* input_value_type);