From c5ff6b89af58fe963e6c09f8e7515f1a02624892 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Tue, 9 Dec 2025 10:51:21 +0100 Subject: [PATCH 1/5] jfjoch_broker: Improve API to get raw plot (for viewer and other applications) --- broker/JFJochBrokerHttp.cpp | 38 ++----- broker/JFJochBrokerHttp.h | 5 +- broker/JFJochServices.cpp | 5 + broker/JFJochServices.h | 1 + broker/JFJochStateMachine.cpp | 4 + broker/JFJochStateMachine.h | 1 + broker/gen/api/DefaultApi.cpp | 20 ++-- broker/gen/api/DefaultApi.h | 5 +- broker/jfjoch_api.yaml | 3 +- broker/redoc-static.html | 8 +- common/StatusVector.cpp | 13 +-- common/StatusVector.h | 4 +- docs/python_client/docs/DefaultApi.md | 10 +- .../src/openapi/services/DefaultService.ts | 10 +- receiver/JFJochReceiverPlots.cpp | 101 ++++++++++++++++++ receiver/JFJochReceiverPlots.h | 2 + receiver/JFJochReceiverService.cpp | 5 + receiver/JFJochReceiverService.h | 1 + 18 files changed, 154 insertions(+), 82 deletions(-) diff --git a/broker/JFJochBrokerHttp.cpp b/broker/JFJochBrokerHttp.cpp index 858511d1..0e350efd 100644 --- a/broker/JFJochBrokerHttp.cpp +++ b/broker/JFJochBrokerHttp.cpp @@ -580,43 +580,17 @@ void JFJochBrokerHttp::preview_plot_get(const std::optional &type, } void JFJochBrokerHttp::preview_plot_bin_get(const std::optional &type, - const std::optional &azintUnit, - const std::optional &binning, + const std::optional &roi, Pistache::Http::ResponseWriter &response) { - PlotAzintUnit unit = PlotAzintUnit::Q_recipA; - if (azintUnit.has_value()) { - if (azintUnit == "Q_recipA" || azintUnit == "q_recipa") - unit = PlotAzintUnit::Q_recipA; - else if (azintUnit == "d_A" || azintUnit == "d_a") - unit = PlotAzintUnit::D_A; - else if (azintUnit == "two_theta_deg") - unit = PlotAzintUnit::TwoTheta_deg; - } + std::vector ret; + state_machine.GetPlotRaw(ret, ConvertPlotType(type), roi.value_or("")); - PlotRequest req{ - .type = ConvertPlotType(type), - .binning = 1, - .experimental_coord = false, - .azint_unit = unit, - .fill_value = NAN - }; - - if (binning) { - if (binning.value() < 0) - throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, - "Binning must be positive number or zero"); - req.binning = binning.value(); - } - - auto plots_container = state_machine.GetPlots(req); - const auto &plots = plots_container.GetPlots(); - - if (plots.empty()) + if (ret.empty()) response.send(Pistache::Http::Code::Ok); else response.send(Pistache::Http::Code::Ok, - reinterpret_cast(plots[0].y.data()), - plots[0].y.size() * sizeof(float), + reinterpret_cast(ret.data()), + ret.size() * sizeof(float), Pistache::Http::Mime::MediaType::fromString("application/octet-stream")); } diff --git a/broker/JFJochBrokerHttp.h b/broker/JFJochBrokerHttp.h index be9f7672..db26adf5 100644 --- a/broker/JFJochBrokerHttp.h +++ b/broker/JFJochBrokerHttp.h @@ -169,8 +169,9 @@ class JFJochBrokerHttp : public org::openapitools::server::api::DefaultApi { const std::optional &compression, const std::optional &fill, const std::optional &experimentalCoord, const std::optional &azintUnit, Pistache::Http::ResponseWriter &response) override; - void preview_plot_bin_get(const std::optional &type, const std::optional &azintUnit, - const std::optional &binning, Pistache::Http::ResponseWriter &response) override; + + void preview_plot_bin_get(const std::optional &type, const std::optional &roi, + Pistache::Http::ResponseWriter &response) override; void config_indexing_get(Pistache::Http::ResponseWriter &response) override; diff --git a/broker/JFJochServices.cpp b/broker/JFJochServices.cpp index cf0210a6..d5cd1765 100644 --- a/broker/JFJochServices.cpp +++ b/broker/JFJochServices.cpp @@ -152,6 +152,11 @@ MultiLinePlot JFJochServices::GetPlots(const PlotRequest &request) { return receiver->GetDataProcessingPlot(request); } +void JFJochServices::GetPlotRaw(std::vector &v, PlotType type, const std::string &roi) { + if (receiver != nullptr) + receiver->GetPlotRaw(v, type, roi); +} + void JFJochServices::SetSpotFindingSettings(const SpotFindingSettings &settings) { if (receiver) receiver->SetSpotFindingSettings(settings); diff --git a/broker/JFJochServices.h b/broker/JFJochServices.h index 4595fc24..6d18cad2 100644 --- a/broker/JFJochServices.h +++ b/broker/JFJochServices.h @@ -38,6 +38,7 @@ public: std::optional GetReceiverStatus() const; std::optional GetReceiverProgress() const; MultiLinePlot GetPlots(const PlotRequest &request); + void GetPlotRaw(std::vector &v, PlotType type, const std::string &roi); void SetSpotFindingSettings(const SpotFindingSettings &settings); JFJochServices& Receiver(JFJochReceiverService *input); diff --git a/broker/JFJochStateMachine.cpp b/broker/JFJochStateMachine.cpp index 185970ec..3d451aa6 100644 --- a/broker/JFJochStateMachine.cpp +++ b/broker/JFJochStateMachine.cpp @@ -571,6 +571,10 @@ MultiLinePlot JFJochStateMachine::GetPlots(const PlotRequest &request) const { return services.GetPlots(request); } +void JFJochStateMachine::GetPlotRaw(std::vector &v, PlotType type, const std::string &roi) const { + services.GetPlotRaw(v, type, roi); +} + void JFJochStateMachine::SetSpotFindingSettings(const SpotFindingSettings &settings) { std::unique_lock ul(data_processing_settings_mutex); DiffractionExperiment::CheckDataProcessingSettings(settings); diff --git a/broker/JFJochStateMachine.h b/broker/JFJochStateMachine.h index cfc79578..661bb733 100644 --- a/broker/JFJochStateMachine.h +++ b/broker/JFJochStateMachine.h @@ -189,6 +189,7 @@ public: BrokerStatus GetStatus() const; MultiLinePlot GetPlots(const PlotRequest &request) const; + void GetPlotRaw(std::vector &v,PlotType type, const std::string &roi) const; void SetSpotFindingSettings(const SpotFindingSettings& settings); SpotFindingSettings GetSpotFindingSettings() const; diff --git a/broker/gen/api/DefaultApi.cpp b/broker/gen/api/DefaultApi.cpp index 7b31572f..bc8d23f5 100644 --- a/broker/gen/api/DefaultApi.cpp +++ b/broker/gen/api/DefaultApi.cpp @@ -1294,25 +1294,17 @@ void DefaultApi::preview_plot_bin_get_handler(const Pistache::Rest::Request &req type = valueQuery_instance; } } - auto azintUnitQuery = request.query().get("azint_unit"); - std::optional azintUnit; - if(azintUnitQuery.has_value()){ + auto roiQuery = request.query().get("roi"); + std::optional roi; + if(roiQuery.has_value()){ std::string valueQuery_instance; - if(fromStringValue(azintUnitQuery.value(), valueQuery_instance)){ - azintUnit = valueQuery_instance; - } - } - auto binningQuery = request.query().get("binning"); - std::optional binning; - if(binningQuery.has_value()){ - int32_t valueQuery_instance; - if(fromStringValue(binningQuery.value(), valueQuery_instance)){ - binning = valueQuery_instance; + if(fromStringValue(roiQuery.value(), valueQuery_instance)){ + roi = valueQuery_instance; } } try { - this->preview_plot_bin_get(type, azintUnit, binning, response); + this->preview_plot_bin_get(type, roi, response); } catch (Pistache::Http::HttpError &e) { response.send(static_cast(e.code()), e.what()); return; diff --git a/broker/gen/api/DefaultApi.h b/broker/gen/api/DefaultApi.h index fabb84a5..e6e5b52f 100644 --- a/broker/gen/api/DefaultApi.h +++ b/broker/gen/api/DefaultApi.h @@ -521,9 +521,8 @@ private: /// /// /// Type of requested plot - /// Unit used for azim int. (optional, default to "Q_recipA") - /// Binning of frames for the plot (0 = default binning) (optional, default to 1) - virtual void preview_plot_bin_get(const std::optional &type, const std::optional &azintUnit, const std::optional &binning, Pistache::Http::ResponseWriter &response) = 0; + /// Name of ROI for which plot is requested (optional, default to "") + virtual void preview_plot_bin_get(const std::optional &type, const std::optional &roi, Pistache::Http::ResponseWriter &response) = 0; /// /// Generate 1D plot from Jungfraujoch /// diff --git a/broker/jfjoch_api.yaml b/broker/jfjoch_api.yaml index 55943dc4..bdfba050 100644 --- a/broker/jfjoch_api.yaml +++ b/broker/jfjoch_api.yaml @@ -3147,8 +3147,7 @@ paths: This format doesn't transmit information about X-axis, only values, so it is of limited use for azimuthal integration. parameters: - $ref: "#/components/parameters/plot_type" - - $ref: "#/components/parameters/azint_unit" - - $ref: "#/components/parameters/binning" + - $ref: "#/components/parameters/roi" responses: "200": description: Everything OK. diff --git a/broker/redoc-static.html b/broker/redoc-static.html index a52d111e..30a22ab7 100644 --- a/broker/redoc-static.html +++ b/broker/redoc-static.html @@ -1322,10 +1322,8 @@ Data are provided as (32-bit) float binary array. This format doesn't transmit information about X-axis, only values, so it is of limited use for azimuthal integration.
query Parameters
type
required
string
Enum: "bkg_estimate" "azint" "azint_1d" "spot_count" "spot_count_low_res" "spot_count_indexed" "spot_count_ice" "indexing_rate" "indexing_time" "indexing_unit_cell_length" "indexing_unit_cell_angle" "profile_radius" "b_factor" "error_pixels" "saturated_pixels" "image_collection_efficiency" "receiver_delay" "receiver_free_send_buf" "strong_pixels" "roi_sum" "roi_mean" "roi_max_count" "roi_pixels" "roi_weighted_x" "roi_weighted_y" "packets_received" "max_pixel_value" "resolution_estimate" "pixel_sum" "processing_time" "beam_center_x" "beam_center_y"

Type of requested plot

-
azint_unit
string
Default: "Q_recipA"
Enum: "Q_recipA" "d_A" "two_theta_deg"

Unit used for azim int.

-
binning
integer
Default: 1

Binning of frames for the plot (0 = default binning)

+
roi
string non-empty

Name of ROI for which plot is requested

Responses