mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-10 05:32:03 +02:00
Implement get_relative_data_index
This commit is contained in:
+16
-5
@@ -243,6 +243,19 @@ bool H5Writer::is_file_open() const
|
||||
return (file.getId() != -1);
|
||||
}
|
||||
|
||||
inline size_t H5Writer::get_relative_data_index(const size_t data_index)
|
||||
{
|
||||
// No file roll over.
|
||||
if (frames_per_file == 0) {
|
||||
return data_index;
|
||||
}
|
||||
|
||||
size_t destination_file_index = data_index / frames_per_file;
|
||||
size_t relative_data_index = data_index - (destination_file_index * frames_per_file);
|
||||
|
||||
return relative_data_index;
|
||||
}
|
||||
|
||||
inline bool H5Writer::is_data_for_current_file(const size_t data_index)
|
||||
{
|
||||
if (frames_per_file) {
|
||||
@@ -260,15 +273,11 @@ inline bool H5Writer::is_data_for_current_file(const size_t data_index)
|
||||
hsize_t H5Writer::prepare_storage_for_data(const string& dataset_name, const size_t data_index, const std::vector<size_t>& data_shape,
|
||||
const string& data_type, const string& endianness)
|
||||
{
|
||||
hsize_t relative_data_index = data_index;
|
||||
|
||||
// Check if we have to create a new file.
|
||||
if (!is_data_for_current_file(data_index)) {
|
||||
// Calculate to which file (1 based) the data_index belongs.
|
||||
hsize_t frame_chunk = (data_index / frames_per_file) + 1;
|
||||
create_file(frame_chunk);
|
||||
|
||||
// Make the data_index relative to this chunk (file).
|
||||
relative_data_index = data_index - ((frame_chunk - 1) * frames_per_file);
|
||||
}
|
||||
|
||||
// Open the file if needed.
|
||||
@@ -283,6 +292,8 @@ hsize_t H5Writer::prepare_storage_for_data(const string& dataset_name, const siz
|
||||
|
||||
hsize_t current_dataset_size = datasets_current_size.at(dataset_name);
|
||||
|
||||
hsize_t relative_data_index = get_relative_data_index(data_index);
|
||||
|
||||
// Expand the dataset if needed.
|
||||
if (relative_data_index > current_dataset_size) {
|
||||
auto dataset = datasets.at(dataset_name);
|
||||
|
||||
@@ -30,6 +30,8 @@ class H5Writer
|
||||
|
||||
void create_dataset(const std::string& dataset_name, const std::vector<size_t>& data_shape,
|
||||
const std::string& data_type, const std::string& endianness);
|
||||
|
||||
size_t get_relative_data_index(const size_t data_index);
|
||||
|
||||
public:
|
||||
H5Writer(const std::string& filename, hsize_t frames_per_file=0, hsize_t initial_dataset_size=1000, hsize_t dataset_increase_step=1000);
|
||||
@@ -41,6 +43,7 @@ class H5Writer
|
||||
const size_t data_bytes_size, const std::string& data_type, const std::string& endianness);
|
||||
virtual H5::H5File& get_h5_file();
|
||||
virtual bool is_data_for_current_file(const size_t data_index);
|
||||
|
||||
};
|
||||
|
||||
class DummyH5Writer : public H5Writer
|
||||
|
||||
Reference in New Issue
Block a user