JFJOchReader: Add ReadAllSpots option to handle reading just spot finding result
This commit is contained in:
@@ -8,6 +8,7 @@ ADD_LIBRARY(JFJochReader STATIC
|
||||
JFJochReaderDataset.h
|
||||
JFJochHttpReader.cpp
|
||||
JFJochHttpReader.h
|
||||
JFJochReaderSpots.h
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES(JFJochReader JFJochImageAnalysis JFJochAPI JFJochCommon JFJochZMQ JFJochLogger
|
||||
|
||||
@@ -1249,9 +1249,12 @@ std::vector<IntegrationOutcome> JFJochHDF5Reader::ReadReflections(size_t start_i
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<SpotToSave> JFJochHDF5Reader::ReadSpots(size_t image) const {
|
||||
std::vector<SpotToSave> JFJochHDF5Reader::ReadSpots(int64_t image) const {
|
||||
std::unique_lock ul(hdf5_mutex);
|
||||
|
||||
if (image < 0)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"image number must be non-negative");
|
||||
if (image >= number_of_images)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"image must be less than number_of_images");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "JFJochReader.h"
|
||||
#include "JFJochReaderSpots.h"
|
||||
#include "../writer/HDF5Objects.h"
|
||||
#include "../image_analysis/IntegrationOutcome.h"
|
||||
|
||||
@@ -56,7 +57,7 @@ public:
|
||||
|
||||
std::vector<IntegrationOutcome> ReadReflections(size_t start_image = 0, std::optional<size_t> end_image = {}) const;
|
||||
|
||||
std::vector<SpotToSave> ReadSpots(size_t image) const;
|
||||
std::vector<SpotToSave> ReadSpots(int64_t image) const override;
|
||||
|
||||
CompressedImage ReadCalibration(std::vector<uint8_t> &tmp, const std::string &name) const;
|
||||
|
||||
|
||||
@@ -374,3 +374,31 @@ void JFJochHttpReader::UploadUserMask(const std::vector<uint32_t>& mask) {
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"Server rejected user mask upload");
|
||||
}
|
||||
|
||||
std::vector<SpotToSave> JFJochHttpReader::ReadSpots(int64_t image) const {
|
||||
std::unique_lock ul(http_mutex);
|
||||
|
||||
if (image < 0)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"Image number must be non-negative");
|
||||
|
||||
if (addr.empty())
|
||||
return {};
|
||||
|
||||
httplib::Client cli_cmd(addr);
|
||||
auto res = cli_cmd.Get("/image_buffer/image.cbor?id=" + std::to_string(image));
|
||||
|
||||
if (!res || res->status != httplib::StatusCode::OK_200 || res->body.empty())
|
||||
return {};
|
||||
|
||||
try {
|
||||
auto msg = CBORStream2Deserialize(res->body);
|
||||
|
||||
if (msg->msg_type != CBORImageType::IMAGE)
|
||||
return {};
|
||||
|
||||
return msg->data_message->spots;
|
||||
} catch (std::exception &e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
BrokerStatus GetBrokerStatus() const;
|
||||
|
||||
std::shared_ptr<JFJochReaderRawImage> GetRawImage(int64_t image_number) override;
|
||||
std::vector<SpotToSave> ReadSpots(int64_t image) const override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -98,3 +98,30 @@ void JFJochReader::UpdateUserMask(const std::vector<uint32_t> &mask) {
|
||||
new_dataset->pixel_mask.LoadUserMask(dataset->experiment, mask);
|
||||
dataset = new_dataset;
|
||||
}
|
||||
|
||||
std::shared_ptr<JFJochReaderSpots> JFJochReader::ReadAllSpots(int64_t start_image, int64_t end_image,
|
||||
int64_t stride) const {
|
||||
|
||||
if (start_image < 0)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"Start image must be non-negative");
|
||||
|
||||
if (start_image > end_image)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"Start image number is greater than end image number");
|
||||
|
||||
if (stride == 0)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"Stride cannot be zero");
|
||||
|
||||
size_t nelems = (end_image - start_image) / stride + 1;
|
||||
|
||||
auto ret = std::make_shared<JFJochReaderSpots>();
|
||||
ret->start_image = static_cast<int64_t>(start_image);
|
||||
ret->stride = static_cast<int64_t>(stride);
|
||||
ret->spots.reserve(nelems);
|
||||
|
||||
for (int i = 0; i < nelems; i++)
|
||||
ret->spots.emplace_back(ReadSpots(start_image + i * stride));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "../common/DiffractionExperiment.h"
|
||||
#include "JFJochReaderDataset.h"
|
||||
#include "JFJochReaderImage.h"
|
||||
#include "JFJochReaderSpots.h"
|
||||
|
||||
class JFJochReader {
|
||||
mutable std::mutex m;
|
||||
@@ -49,6 +50,9 @@ public:
|
||||
void UpdateUserMask(const std::vector<uint32_t>& mask);
|
||||
|
||||
virtual std::shared_ptr<JFJochReaderRawImage> GetRawImage(int64_t image_number) = 0;
|
||||
|
||||
virtual std::vector<SpotToSave> ReadSpots(int64_t image) const = 0;
|
||||
std::shared_ptr<JFJochReaderSpots> ReadAllSpots(int64_t start_image, int64_t end_image, int64_t stride = 1) const;
|
||||
};
|
||||
|
||||
#endif //JFJOCHIMAGEREADER_H
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../common/SpotToSave.h"
|
||||
|
||||
struct JFJochReaderSpots {
|
||||
int64_t start_image;
|
||||
int64_t stride;
|
||||
std::vector<std::vector<SpotToSave>> spots;
|
||||
};
|
||||
Reference in New Issue
Block a user