From 6d12773b2837c1b33bb6af86bc86fc5dd2939ca2 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sat, 6 Dec 2025 22:14:41 +0100 Subject: [PATCH] jfjoch_broker: Add binary plot option --- broker/JFJochBrokerHttp.cpp | 22 ++++++ broker/JFJochBrokerHttp.h | 1 + broker/gen/api/DefaultApi.cpp | 30 +++++++++ broker/gen/api/DefaultApi.h | 9 +++ broker/jfjoch_api.yaml | 23 +++++++ broker/redoc-static.html | 35 +++++++--- docs/python_client/README.md | 1 + docs/python_client/docs/DefaultApi.md | 67 +++++++++++++++++++ frontend/package-lock.json | 4 +- .../src/openapi/services/DefaultService.ts | 24 +++++++ 10 files changed, 205 insertions(+), 11 deletions(-) diff --git a/broker/JFJochBrokerHttp.cpp b/broker/JFJochBrokerHttp.cpp index a5bc603e..5e336f0f 100644 --- a/broker/JFJochBrokerHttp.cpp +++ b/broker/JFJochBrokerHttp.cpp @@ -579,6 +579,28 @@ void JFJochBrokerHttp::preview_plot_get(const std::optional &type, ProcessOutput(Convert(plot), response, compression.value_or(false)); } +void JFJochBrokerHttp::preview_plot_bin_get(const std::optional &type, + Pistache::Http::ResponseWriter &response) { + PlotRequest req{ + .type = ConvertPlotType(type), + .binning = 1, + .experimental_coord = false, + .azint_unit = PlotAzintUnit::Q_recipA, + .fill_value = NAN + }; + + auto plots_container = state_machine.GetPlots(req); + const auto &plots = plots_container.GetPlots(); + + if (plots.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), + Pistache::Http::Mime::MediaType::fromString("application/octet-stream")); +} + void JFJochBrokerHttp::config_indexing_get(Pistache::Http::ResponseWriter &response) { ProcessOutput(Convert(state_machine.GetIndexingSettings()), response); } diff --git a/broker/JFJochBrokerHttp.h b/broker/JFJochBrokerHttp.h index ca8bfd96..d98e2148 100644 --- a/broker/JFJochBrokerHttp.h +++ b/broker/JFJochBrokerHttp.h @@ -169,6 +169,7 @@ 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, Pistache::Http::ResponseWriter &response) override; void config_indexing_get(Pistache::Http::ResponseWriter &response) override; diff --git a/broker/gen/api/DefaultApi.cpp b/broker/gen/api/DefaultApi.cpp index 25d0c8e5..6d68b9dc 100644 --- a/broker/gen/api/DefaultApi.cpp +++ b/broker/gen/api/DefaultApi.cpp @@ -80,6 +80,7 @@ void DefaultApi::setupRoutes() { Routes::Post(*router, base + "/initialize", Routes::bind(&DefaultApi::initialize_post_handler, this)); Routes::Post(*router, base + "/pedestal", Routes::bind(&DefaultApi::pedestal_post_handler, this)); Routes::Get(*router, base + "/preview/pedestal.tiff", Routes::bind(&DefaultApi::preview_pedestal_tiff_get_handler, this)); + Routes::Get(*router, base + "/preview/plot.bin", Routes::bind(&DefaultApi::preview_plot_bin_get_handler, this)); Routes::Get(*router, base + "/preview/plot", Routes::bind(&DefaultApi::preview_plot_get_handler, this)); Routes::Get(*router, base + "/result/scan", Routes::bind(&DefaultApi::result_scan_get_handler, this)); Routes::Post(*router, base + "/start", Routes::bind(&DefaultApi::start_post_handler, this)); @@ -1279,6 +1280,35 @@ void DefaultApi::preview_pedestal_tiff_get_handler(const Pistache::Rest::Request response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +} +void DefaultApi::preview_plot_bin_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) { + try { + + + // Getting the query params + auto typeQuery = request.query().get("type"); + std::optional type; + if(typeQuery.has_value()){ + std::string valueQuery_instance; + if(fromStringValue(typeQuery.value(), valueQuery_instance)){ + type = valueQuery_instance; + } + } + + try { + this->preview_plot_bin_get(type, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } + + } catch (std::exception &e) { + response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); + } + } void DefaultApi::preview_plot_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) { try { diff --git a/broker/gen/api/DefaultApi.h b/broker/gen/api/DefaultApi.h index 6c4137ca..88b5bda7 100644 --- a/broker/gen/api/DefaultApi.h +++ b/broker/gen/api/DefaultApi.h @@ -116,6 +116,7 @@ private: void initialize_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); void pedestal_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); void preview_pedestal_tiff_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); + void preview_plot_bin_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); void preview_plot_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); void result_scan_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); void start_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); @@ -514,6 +515,14 @@ private: /// Storage cell number (optional, default to 0) virtual void preview_pedestal_tiff_get(const std::optional &gainLevel, const std::optional &sc, Pistache::Http::ResponseWriter &response) = 0; /// + /// Generate 1D plot from Jungfraujoch and send in binary format. This format is unsuitable for azimuthal integration plots, only to per image plots for a dataset. No binning is available. + /// + /// + /// + /// + /// Type of requested plot + virtual void preview_plot_bin_get(const std::optional &type, Pistache::Http::ResponseWriter &response) = 0; + /// /// Generate 1D plot from Jungfraujoch /// /// diff --git a/broker/jfjoch_api.yaml b/broker/jfjoch_api.yaml index 97a1f1a9..f0f559d9 100644 --- a/broker/jfjoch_api.yaml +++ b/broker/jfjoch_api.yaml @@ -3136,6 +3136,29 @@ paths: schema: type: string description: Exception error + /preview/plot.bin: + get: + summary: | + Generate 1D plot from Jungfraujoch and send in binary format. + This format is unsuitable for azimuthal integration plots, only to per image plots for a dataset. + No binning is available. + parameters: + - $ref: "#/components/parameters/plot_type" + responses: + "200": + description: Everything OK. + content: + application/octet-stream: + schema: + type: string + format: binary + "400": + description: Input parsing or validation error + content: + text/plain: + schema: + type: string + description: Exception error /result/scan: get: summary: Get full scan result diff --git a/broker/redoc-static.html b/broker/redoc-static.html index dad78159..0c9bcab7 100644 --- a/broker/redoc-static.html +++ b/broker/redoc-static.html @@ -387,7 +387,13 @@ Get user mask of the detector (binary) Get user mask of the detector (TIFF) " aria-expanded="false" class="sc-cgHfjM ixknQI">
putUpload user mask of the detector

Input parsing or validation error

Response samples

Content type
application/json
{
  • "title": "string",
  • "unit_x": "image_number",
  • "size_x": 0.1,
  • "size_y": 0.1,
  • "plot": [
    ]
}

Get full scan result

Responses

Response samples

Content type
application/json
{
  • "title": "string",
  • "unit_x": "image_number",
  • "size_x": 0.1,
  • "size_y": 0.1,
  • "plot": [
    ]
}

Generate 1D plot from Jungfraujoch and send in binary format. +This format is unsuitable for azimuthal integration plots, only to per image plots for a dataset. +No binning is available. +

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

+

Responses

Get full scan result

Responses

Response samples

Content type
application/json
{
  • "file_prefix": "string",
  • "rotation_unit_cell": {
    },
  • "rotation_crystal_lattice": [
    ],
  • "images": [
    ]
}

Get Start message in CBOR format

http://localhost:5232/result/scan

Response samples

Content type
application/json
{
  • "file_prefix": "string",
  • "rotation_unit_cell": {
    },
  • "rotation_crystal_lattice": [
    ],
  • "images": [
    ]
}

Get Start message in CBOR format

Contains metadata for a dataset (e.g., experimental geometry)

Responses

Response samples

Content type
application/json
{
  • "msg": "Detector in wrong state",
  • "reason": "WrongDAQState"
}

Get image message in CBOR format

http://localhost:5232/image_buffer/start.cbor

Response samples

Content type
application/json
{
  • "msg": "Detector in wrong state",
  • "reason": "WrongDAQState"
}

Get image message in CBOR format

Contains full image data and metadata. The image must come from the latest data collection.

query Parameters
id
integer <int64> >= -2
Default: -1

Image ID in the image buffer. Special values: -1 - last image in the buffer, -2: last indexed image in the buffer

@@ -1341,7 +1358,7 @@ For still measurement the number is ignored

" class="sc-eVqvcJ sc-fszimp sc-etsjJW kIppRw jnwENr ljKHqG">

Error within Jungfraujoch code - see output message.

Response samples

Content type
application/json
{
  • "msg": "Detector in wrong state",
  • "reason": "WrongDAQState"
}

Get preview image in JPEG format using custom settings

query Parameters
id
integer <int64> >= -2
Default: -1
http://localhost:5232/image_buffer/image.cbor

Response samples

Content type
application/json
{
  • "msg": "Detector in wrong state",
  • "reason": "WrongDAQState"
}

Get preview image in JPEG format using custom settings

query Parameters
id
integer <int64> >= -2
Default: -1

Image ID in the image buffer. Special values: -1 - last image in the buffer, -2: last indexed image in the buffer

show_user_mask
boolean
Default: false

Show user mask

@@ -1371,7 +1388,7 @@ For still measurement the number is ignored

" class="sc-eVqvcJ sc-fszimp sc-etsjJW kIppRw jnwENr ljKHqG">

Error within Jungfraujoch code - see output message.

Response samples

Content type
application/json
{
  • "msg": "Detector in wrong state",
  • "reason": "WrongDAQState"
}

Get preview image in TIFF format

query Parameters
id
integer <int64> >= -2
Default: -1
http://localhost:5232/image_buffer/image.jpeg

Response samples

Content type
application/json
{
  • "msg": "Detector in wrong state",
  • "reason": "WrongDAQState"
}

Get preview image in TIFF format

query Parameters
id
integer <int64> >= -2
Default: -1

Image ID in the image buffer. Special values: -1 - last image in the buffer, -2: last indexed image in the buffer

Responses

Response samples

Content type
application/json
{
  • "msg": "Detector in wrong state",
  • "reason": "WrongDAQState"
}

Get status of the image buffers

http://localhost:5232/image_buffer/clear

Response samples

Content type
application/json
{
  • "msg": "Detector in wrong state",
  • "reason": "WrongDAQState"
}

Get status of the image buffers

Can be run at any stage of Jungfraujoch operation, including during data collection. @@ -1399,13 +1416,13 @@ then image might be replaced in the buffer between calling /images and /image.cb " class="sc-eVqvcJ sc-fszimp sc-etsjJW kIppRw jnwENr ljKHqG">

Error within Jungfraujoch code - see output message.

Response samples

Content type
application/json
{
  • "min_image_number": 0,
  • "max_image_number": 0,
  • "image_numbers": [
    ],
  • "total_slots": 0,
  • "available_slots": 0
}

Get Jungfraujoch version of jfjoch_broker

Responses

Response samples

Content type
application/json
{
  • "min_image_number": 0,
  • "max_image_number": 0,
  • "image_numbers": [
    ],
  • "total_slots": 0,
  • "available_slots": 0
}

Get Jungfraujoch version of jfjoch_broker

Responses