diff --git a/xds-plugin/CMakeLists.txt b/xds-plugin/CMakeLists.txt index 459367a4..8f254043 100644 --- a/xds-plugin/CMakeLists.txt +++ b/xds-plugin/CMakeLists.txt @@ -11,7 +11,7 @@ set_target_properties(jfjoch_xds_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden C_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN YES - VERSION 1.0.0 + VERSION 1.0.1 ) if(UNIX AND NOT APPLE) diff --git a/xds-plugin/plugin.cpp b/xds-plugin/plugin.cpp index a5bb92e5..699d2c97 100644 --- a/xds-plugin/plugin.cpp +++ b/xds-plugin/plugin.cpp @@ -219,50 +219,52 @@ void plugin_get_header(int *nx, int *ny, int *nbytes, float *qx, float *qy, void plugin_get_data(int *frame_number, int *nx, int *ny, int *data_array, int info[1024], int *error_flag) { std::shared_lock sl(plugin_mutex); + std::vector tmp; + CompressionAlgorithm algorithm = CompressionAlgorithm::NO_COMPRESSION; try { - if (!hdf5_file) - throw PluginError(-1, "HDF5 file not open"); + { + std::unique_lock h5l(hdf5_mutex); + if (!hdf5_file) + throw PluginError(-1, "HDF5 file not open"); - FillInfoArray(info); + FillInfoArray(info); - if (*frame_number <= 0 || *frame_number > total_image_number) - throw PluginError(-1, "Frame number out of range"); + if (*frame_number <= 0 || *frame_number > total_image_number) + throw PluginError(-1, "Frame number out of range"); - std::string dataset_name; - hsize_t image_id; + std::string dataset_name; + hsize_t image_id; - if (format == FileWriterFormat::NXmxLegacy) { - char str[256]; - size_t dataset_index = (*frame_number - 1) / images_per_file + 1; - snprintf(str, sizeof(str), "/entry/data/data_%06ld", dataset_index); - dataset_name = std::string(str); - image_id = (*frame_number - 1) % images_per_file; - } else { - dataset_name = "/entry/data/data"; - image_id = *frame_number - 1; - } + if (format == FileWriterFormat::NXmxLegacy) { + char str[256]; + size_t dataset_index = (*frame_number - 1) / images_per_file + 1; + snprintf(str, sizeof(str), "/entry/data/data_%06ld", dataset_index); + dataset_name = std::string(str); + image_id = (*frame_number - 1) % images_per_file; + } else { + dataset_name = "/entry/data/data"; + image_id = *frame_number - 1; + } - HDF5DataSet dataset(*hdf5_file, dataset_name); - HDF5Dcpl dcpl(dataset); + HDF5DataSet dataset(*hdf5_file, dataset_name); + HDF5Dcpl dcpl(dataset); - std::vector tmp; - std::vector start = {image_id, 0, 0}; + std::vector start = {image_id, 0, 0}; - CompressionAlgorithm algorithm = CompressionAlgorithm::NO_COMPRESSION; - auto chunk_size = dcpl.GetChunking(); + auto chunk_size = dcpl.GetChunking(); - if ((chunk_size.size() == 3) - && (chunk_size[0] == 1) - && (chunk_size[1] == image_size_y) - && (chunk_size[2] == image_size_x)) { - dataset.ReadDirectChunk(tmp, start); - algorithm = dcpl.GetCompression(); + if ((chunk_size.size() == 3) + && (chunk_size[0] == 1) + && (chunk_size[1] == image_size_y) + && (chunk_size[2] == image_size_x)) { + dataset.ReadDirectChunk(tmp, start); + algorithm = dcpl.GetCompression(); } else { dataset.ReadVectorToU8(tmp, start, {1, image_size_y, image_size_x}); algorithm = CompressionAlgorithm::NO_COMPRESSION; } - + } if (algorithm != CompressionAlgorithm::NO_COMPRESSION) { std::vector decompressed_image(image_size_x * image_size_y * pixel_byte_depth); JFJochDecompressPtr(decompressed_image.data(), @@ -300,4 +302,4 @@ void plugin_close(int *error_flag) { *error_flag = -1; } } -} /* extern "C" */ \ No newline at end of file +} /* extern "C" */