54 lines
2.1 KiB
C++
54 lines
2.1 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "HDF5DataFilePluginAzInt.h"
|
|
|
|
#define RESERVE_IMAGES 1000
|
|
|
|
HDF5DataFilePluginAzInt::HDF5DataFilePluginAzInt(const StartMessage &message) :
|
|
az_int_bin_to_q(message.az_int_bin_to_q),
|
|
az_int_bin_to_two_theta(message.az_int_bin_to_two_theta),
|
|
az_int_bin_to_phi(message.az_int_bin_to_phi),
|
|
azimuthal_bins(message.az_int_phi_bin_count.value_or(1)),
|
|
q_bins(message.az_int_q_bin_count.value_or(1)){
|
|
}
|
|
|
|
void HDF5DataFilePluginAzInt::OpenFile(HDF5File &data_file, const DataMessage &msg) {
|
|
if (az_int_bin_to_q.empty() || q_bins <= 0 || azimuthal_bins <= 0)
|
|
return;
|
|
|
|
std::vector<hsize_t> dim = {azimuthal_bins, q_bins};
|
|
|
|
HDF5Group(data_file, "/entry/azint").NXClass("NXcollection");
|
|
data_file.SaveVector("/entry/azint/bin_to_q", az_int_bin_to_q, dim);
|
|
if (!az_int_bin_to_two_theta.empty())
|
|
data_file.SaveVector("/entry/azint/bin_to_two_theta", az_int_bin_to_two_theta, dim);
|
|
if (!az_int_bin_to_phi.empty())
|
|
data_file.SaveVector("/entry/azint/bin_to_phi", az_int_bin_to_phi, dim);
|
|
|
|
HDF5DataType data_type(0.0f);
|
|
HDF5DataSpace data_space = HDF5DataSpace({1, azimuthal_bins, q_bins},
|
|
{H5S_UNLIMITED, azimuthal_bins, q_bins});
|
|
HDF5Dcpl dcpl;
|
|
dcpl.SetChunking({1, azimuthal_bins, q_bins});
|
|
dataset = std::make_unique<HDF5DataSet>(data_file, "/entry/azint/image", data_type, data_space, dcpl);
|
|
}
|
|
|
|
void HDF5DataFilePluginAzInt::Write(const DataMessage &msg, uint64_t image_number) {
|
|
if (az_int_bin_to_q.empty() || q_bins <= 0 || azimuthal_bins <= 0)
|
|
return;
|
|
|
|
if (image_number > max_image_number)
|
|
max_image_number = image_number;
|
|
|
|
if (!msg.az_int_profile.empty() && (msg.az_int_profile.size() == az_int_bin_to_q.size())) {
|
|
if (azimuthal_bins > 1) {
|
|
dataset->SetExtent({max_image_number+1, azimuthal_bins, q_bins});
|
|
dataset->WriteVec(msg.az_int_profile, {image_number, 0, 0}, {1, azimuthal_bins, q_bins});
|
|
}
|
|
}
|
|
}
|
|
|
|
void HDF5DataFilePluginAzInt::WriteFinal(HDF5File &data_file) {
|
|
}
|