53 lines
2.1 KiB
C++
53 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 10000
|
|
|
|
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);
|
|
|
|
az_int_image.reserve(RESERVE_IMAGES * azimuthal_bins * q_bins);
|
|
az_int_image.resize(msg.number * azimuthal_bins * q_bins);
|
|
}
|
|
|
|
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 (static_cast<int64_t>(image_number) >= max_image_number) {
|
|
max_image_number = image_number;
|
|
az_int_image.resize((max_image_number + 1) * azimuthal_bins * q_bins);
|
|
}
|
|
|
|
if (!msg.az_int_profile.empty() && (msg.az_int_profile.size() == azimuthal_bins * q_bins)) {
|
|
for (int i = 0; i < azimuthal_bins * q_bins; i++)
|
|
az_int_image[image_number * azimuthal_bins * q_bins + i] = msg.az_int_profile[i];
|
|
}
|
|
}
|
|
|
|
void HDF5DataFilePluginAzInt::WriteFinal(HDF5File &data_file) {
|
|
if (!az_int_image.empty())
|
|
data_file.SaveVector("/entry/azint/image", az_int_image,
|
|
{(hsize_t) (max_image_number + 1), azimuthal_bins, q_bins});
|
|
}
|