Files
Jungfraujoch/reader/JFJochHDF5Reader.h
T
leonarski_fandClaude Opus 4.8 c6e7f8aa15 writer/reader: move ROI definitions to /entry/roi_defs and read them back
Relocate the ROI definitions and the roi_map bitmap from /entry/roi to a
separate /entry/roi_defs group in the master file. /entry/roi keeps its
original meaning (per-image ROI results only), so an older reader that
iterates /entry/roi is not disturbed by the bitmap/definition entries
(which would otherwise make it try to read /entry/roi/roi_map/max and
fail to open the file at all). Back-compatibility for already-deployed
viewers is the reason for the split.

JFJochHDF5Reader now reads the logical definitions into experiment.ROI()
and the roi_map bitmask (+ a name->bit index) into the dataset, for all
file formats (the master always carries them). Reading both lets a later
viewer either re-derive ROIs with the current geometry (logical) or show
the exact written footprint (bitmap).

Added a write/read round-trip test over VDS and integrated formats.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 10:35:18 +02:00

69 lines
2.5 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "JFJochReader.h"
#include "JFJochReaderSpots.h"
#include "../writer/HDF5Objects.h"
#include "../image_analysis/IntegrationOutcome.h"
class JFJochHDF5Reader : public JFJochReader {
FileWriterFormat format = FileWriterFormat::NoFile;
HDF5DataSetLayout data_layout = HDF5DataSetLayout::CONTIGUOUS;
std::shared_ptr<HDF5ReadOnlyFile> master_file;
DiffractionGeometry cached_geom;
std::vector<std::string> legacy_format_files;
std::vector<HDF5VirtualDatasetMapping> vds_data_mappings;
std::string master_file_directory;
std::string master_filename;
size_t images_per_file = 1;
size_t number_of_images = 0;
bool LoadImage_i(std::shared_ptr<JFJochReaderDataset> &dataset,
DataMessage& message,
std::vector<uint8_t> &buffer,
int64_t image_number,
bool update_dataset) override;
CompressedImage LoadImageDataset(std::vector<uint8_t> &tmp, HDF5Object &file, hsize_t number);
template <class T>
void ReadVector(std::vector<T> &v,
HDF5Object &file,
const std::string &dataset_name,
size_t image0,
size_t nimages);
std::pair<std::shared_ptr<HDF5ReadOnlyFile>, uint32_t> GetImageLocation(int64_t image_number);
std::optional<GoniometerAxis> ReadAxis(HDF5Object *file, const std::string &name);
// Read the master-file ROI definitions: logical definitions into experiment.ROI()
// and the roi_map bitmask (+ bit index) into the dataset. Present for all formats.
void ReadROIMetadata(HDF5ReadOnlyFile &file, JFJochReaderDataset &dataset) const;
public:
~JFJochHDF5Reader() override = default;
void ReadFile(const std::string& filename);
uint64_t GetNumberOfImages() const override;
void Close() override;
std::vector<HDF5DataSourceMessage> GetHDF5DataSource(
uint64_t first_image = 0,
std::optional<uint64_t> image_count = {}
) const;
std::vector<IntegrationOutcome> ReadReflections(size_t start_image = 0, std::optional<size_t> end_image = {}) const;
std::vector<SpotToSave> ReadSpots(int64_t image) const override;
CompressedImage ReadCalibration(std::vector<uint8_t> &tmp, const std::string &name) const;
std::shared_ptr<JFJochReaderRawImage> GetRawImage(int64_t image_number) override;
};