JFJochReceiver: Plot is C++ struct
This commit is contained in:
@@ -16,11 +16,13 @@ const std::vector<uint64_t> &ADUHistogram::GetHistogram() const {
|
||||
return histogram;
|
||||
}
|
||||
|
||||
void ADUHistogram::GetPlot(JFJochProtoBuf::Plot &plot) const {
|
||||
Plot ADUHistogram::GetPlot() const {
|
||||
std::unique_lock<std::mutex> ul(m);
|
||||
|
||||
Plot ret;
|
||||
ret.x.resize(ADU_HISTO_BIN_COUNT);
|
||||
ret.y.resize(ADU_HISTO_BIN_COUNT);
|
||||
for (int i = 0; i < ADU_HISTO_BIN_COUNT; i++) {
|
||||
plot.add_x(ADU_HISTO_BIN_WIDTH * i + ADU_HISTO_BIN_WIDTH / 2);
|
||||
plot.add_y(histogram[i]);
|
||||
ret.x[i] = ADU_HISTO_BIN_WIDTH * i + ADU_HISTO_BIN_WIDTH / 2;
|
||||
ret.y[i] = histogram[i];
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
#define JUNGFRAUJOCH_ADUHISTOGRAM_H
|
||||
|
||||
#include <mutex>
|
||||
#include <jfjoch.pb.h>
|
||||
#include "Plot.h"
|
||||
#include "../acquisition_device/AcquisitionDevice.h"
|
||||
|
||||
class ADUHistogram {
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
explicit ADUHistogram();
|
||||
void Add(const DeviceOutput &output);
|
||||
const std::vector<uint64_t>& GetHistogram() const;
|
||||
void GetPlot(JFJochProtoBuf::Plot &plot) const;
|
||||
Plot GetPlot() const;
|
||||
};
|
||||
|
||||
#endif //JUNGFRAUJOCH_ADUHISTOGRAM_H
|
||||
|
||||
@@ -50,7 +50,8 @@ ADD_LIBRARY( CommonFunctions STATIC
|
||||
NUMAHWPolicy.h
|
||||
ADUHistogram.cpp
|
||||
ADUHistogram.h
|
||||
RawToConvertedGeometryCore.h)
|
||||
RawToConvertedGeometryCore.h
|
||||
Plot.h)
|
||||
|
||||
TARGET_LINK_LIBRARIES(CommonFunctions Compression FrameSerialize libzmq JFCalibration JFJochProtoBuf -lrt)
|
||||
|
||||
|
||||
+9
-5
@@ -7,7 +7,7 @@
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <jfjoch.pb.h>
|
||||
#include "Plot.h"
|
||||
|
||||
template <class T>
|
||||
class Histogram {
|
||||
@@ -25,16 +25,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void GetPlot(JFJochProtoBuf::Plot &plot) {
|
||||
Plot GetPlot() {
|
||||
std::unique_lock<std::mutex> ul(m);
|
||||
|
||||
Plot ret;
|
||||
ret.x.resize(sum.size());
|
||||
ret.y.resize(sum.size());
|
||||
for (int i = 0; i < sum.size(); i++) {
|
||||
plot.add_x(static_cast<float>(i));
|
||||
ret.x[i] = static_cast<float>(i);
|
||||
if (count[i] > 0)
|
||||
plot.add_y(static_cast<float>(sum[i]) / count[i]);
|
||||
ret.y[i] = static_cast<float>(sum[i]) / count[i];
|
||||
else
|
||||
plot.add_y(0);
|
||||
ret.y[i] = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright (2019-2023) Paul Scherrer Institute
|
||||
|
||||
#ifndef JUNGFRAUJOCH_PLOT_H
|
||||
#define JUNGFRAUJOCH_PLOT_H
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
enum class PlotType {BkgEstimate, RadInt, SpotCount, IndexingRate, IndexingRatePerFile, ADUHistorgram};
|
||||
|
||||
struct PlotRequest {
|
||||
PlotType type;
|
||||
uint64_t binning;
|
||||
};
|
||||
|
||||
struct Plot {
|
||||
std::vector<float> x;
|
||||
std::vector<float> y;
|
||||
};
|
||||
|
||||
struct RadialIntegrationProfileStruct {
|
||||
std::string title;
|
||||
Plot plot;
|
||||
};
|
||||
|
||||
struct RadialIntegrationProfiles {
|
||||
std::vector<RadialIntegrationProfileStruct> profiles;
|
||||
};
|
||||
|
||||
#endif //JUNGFRAUJOCH_PLOT_H
|
||||
+11
-8
@@ -7,7 +7,7 @@
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include <jfjoch.pb.h>
|
||||
#include "Plot.h"
|
||||
|
||||
#include "JFJochException.h"
|
||||
#include <iostream>
|
||||
@@ -72,18 +72,21 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void GetPlot(JFJochProtoBuf::Plot& plot, int32_t bin_size) const {
|
||||
Plot GetPlot(int64_t bin_size) const {
|
||||
// GetStatus has mutex, no need to lock again
|
||||
auto status = GetStatus(bin_size);
|
||||
if (status.size() == 1) {
|
||||
plot.add_x(max_id / 2.0);
|
||||
plot.add_y(status[0]);
|
||||
} else if (!status.empty()) {
|
||||
*plot.mutable_y() = {status.begin(), status.end()};
|
||||
|
||||
Plot ret;
|
||||
if (status.size() == 1) {
|
||||
ret.x = {max_id / 2.0f};
|
||||
ret.y = {status[0]};
|
||||
} else if (!status.empty()) {
|
||||
ret.y = status;
|
||||
ret.x.resize(status.size());
|
||||
for (int i = 0; i < status.size(); i++)
|
||||
plot.add_x(bin_size * (i + 0.5));
|
||||
ret.x[i] = bin_size * (i + 0.5f);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -36,13 +36,13 @@ std::vector<float> RadialIntegrationProfile::GetResult() const {
|
||||
return rad_int_profile;
|
||||
}
|
||||
|
||||
void RadialIntegrationProfile::GetPlot(JFJochProtoBuf::Plot &plot) const {
|
||||
Plot RadialIntegrationProfile::GetPlot() const {
|
||||
std::unique_lock<std::mutex> ul(m);
|
||||
|
||||
std::vector<float> rad_int_profile = GetResult();
|
||||
|
||||
*plot.mutable_x() = {bin_to_q.begin(), bin_to_q.end()};
|
||||
*plot.mutable_y() = {rad_int_profile.begin(), rad_int_profile.end()};
|
||||
Plot ret;
|
||||
ret.x = bin_to_q;
|
||||
ret.y = GetResult();
|
||||
return ret;
|
||||
}
|
||||
|
||||
float RadialIntegrationProfile::GetMeanValueOfBins(uint16_t min_bin, uint16_t max_bin) const {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <jfjoch.pb.h>
|
||||
#include "../common/Plot.h"
|
||||
|
||||
#include "RadialIntegrationMapping.h"
|
||||
#include "../acquisition_device/AcquisitionDevice.h"
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
void Add(const std::vector<int64_t> &sum, const std::vector<uint64_t> &count);
|
||||
std::vector<float> GetResult() const;
|
||||
float GetMeanValueOfBins(uint16_t min_bin, uint16_t max_bin) const;
|
||||
void GetPlot(JFJochProtoBuf::Plot &plot) const;
|
||||
Plot GetPlot() const;
|
||||
RadialIntegrationProfile& operator+=(const RadialIntegrationProfile& profile);
|
||||
};
|
||||
|
||||
|
||||
+27
-30
@@ -660,31 +660,28 @@ JFJochProtoBuf::DataProcessingSettings JFJochReceiver::GetDataProcessingSettings
|
||||
return data_processing_settings;
|
||||
}
|
||||
|
||||
JFJochProtoBuf::Plot JFJochReceiver::GetPlots(const JFJochProtoBuf::PlotRequest &request) {
|
||||
JFJochProtoBuf::Plot ret;
|
||||
Plot JFJochReceiver::GetPlots(const PlotRequest &request) {
|
||||
Plot ret;
|
||||
auto nbins = experiment.GetSpotFindingBin();
|
||||
if (request.binning() > 0)
|
||||
nbins = request.binning();
|
||||
if (request.binning > 0)
|
||||
nbins = request.binning;
|
||||
|
||||
switch (request.type()) {
|
||||
case JFJochProtoBuf::RAD_INT:
|
||||
switch (request.type) {
|
||||
case PlotType::RadInt:
|
||||
if (rad_int_profile)
|
||||
rad_int_profile->GetPlot(ret);
|
||||
break;
|
||||
case JFJochProtoBuf::SPOT_COUNT:
|
||||
spot_count.GetPlot(ret, nbins);
|
||||
break;
|
||||
case JFJochProtoBuf::INDEXING_RATE:
|
||||
indexing_solution.GetPlot(ret, nbins);
|
||||
break;
|
||||
case JFJochProtoBuf::BKG_ESTIMATE:
|
||||
bkg_estimate.GetPlot(ret, nbins);
|
||||
break;
|
||||
case JFJochProtoBuf::INDEXING_RATE_PER_FILE:
|
||||
indexing_solution_per_file.GetPlot(ret);
|
||||
break;
|
||||
case JFJochProtoBuf::ADU_HISTOGRAM:
|
||||
adu_histogram_total.GetPlot(ret);
|
||||
return rad_int_profile->GetPlot();
|
||||
else
|
||||
return {};
|
||||
case PlotType::SpotCount:
|
||||
return spot_count.GetPlot(nbins);
|
||||
case PlotType::IndexingRate:
|
||||
return indexing_solution.GetPlot(nbins);
|
||||
case PlotType::BkgEstimate:
|
||||
return bkg_estimate.GetPlot(nbins);
|
||||
case PlotType::IndexingRatePerFile:
|
||||
return indexing_solution_per_file.GetPlot();
|
||||
case PlotType::ADUHistorgram:
|
||||
return adu_histogram_total.GetPlot();
|
||||
break;
|
||||
default:
|
||||
// Do nothing
|
||||
@@ -693,19 +690,19 @@ JFJochProtoBuf::Plot JFJochReceiver::GetPlots(const JFJochProtoBuf::PlotRequest
|
||||
return ret;
|
||||
}
|
||||
|
||||
JFJochProtoBuf::RadialIntegrationProfiles JFJochReceiver::GetRadialIntegrationProfiles() {
|
||||
JFJochProtoBuf::RadialIntegrationProfiles ret;
|
||||
RadialIntegrationProfiles JFJochReceiver::GetRadialIntegrationProfiles() {
|
||||
RadialIntegrationProfiles ret;
|
||||
|
||||
if (rad_int_profile) {
|
||||
auto p = ret.add_profiles();
|
||||
p->set_title("dataset");
|
||||
rad_int_profile->GetPlot(*p->mutable_plot());
|
||||
ret.profiles.emplace_back(RadialIntegrationProfileStruct{
|
||||
.title = "dataset" ,
|
||||
.plot = rad_int_profile->GetPlot()});
|
||||
}
|
||||
|
||||
for (int i = 0; i < rad_int_profile_per_file.size(); i++) {
|
||||
auto p = ret.add_profiles();
|
||||
p->set_title("file" + std::to_string(i));
|
||||
rad_int_profile_per_file[i]->GetPlot(*p->mutable_plot());
|
||||
ret.profiles.emplace_back(RadialIntegrationProfileStruct{
|
||||
.title = "file" + std::to_string(i),
|
||||
.plot = rad_int_profile_per_file[i]->GetPlot()});
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "../jungfrau/JFCalibration.h"
|
||||
#include "../common/ADUHistogram.h"
|
||||
#include "../common/Plot.h"
|
||||
|
||||
struct JFJochReceiverOutput {
|
||||
std::vector<JFModulePedestal> pedestal_result;
|
||||
@@ -151,8 +152,8 @@ public:
|
||||
void SetDataProcessingSettings(const JFJochProtoBuf::DataProcessingSettings &data_processing_settings);
|
||||
|
||||
float GetAvailableSendBuffers() const;
|
||||
JFJochProtoBuf::Plot GetPlots(const JFJochProtoBuf::PlotRequest& request);
|
||||
JFJochProtoBuf::RadialIntegrationProfiles GetRadialIntegrationProfiles();
|
||||
Plot GetPlots(const PlotRequest& request);
|
||||
RadialIntegrationProfiles GetRadialIntegrationProfiles();
|
||||
};
|
||||
|
||||
#endif //JUNGFRAUJOCH_JFJOCHRECEIVER_H
|
||||
|
||||
@@ -2,6 +2,49 @@
|
||||
|
||||
#include "JFJochReceiverService.h"
|
||||
|
||||
PlotRequest Convert(const JFJochProtoBuf::PlotRequest& request) {
|
||||
PlotRequest ret;
|
||||
ret.binning = request.binning();
|
||||
switch (request.type()) {
|
||||
case JFJochProtoBuf::BKG_ESTIMATE:
|
||||
ret.type = PlotType::BkgEstimate;
|
||||
break;
|
||||
case JFJochProtoBuf::RAD_INT:
|
||||
ret.type = PlotType::RadInt;
|
||||
break;
|
||||
case JFJochProtoBuf::SPOT_COUNT:
|
||||
ret.type = PlotType::SpotCount;
|
||||
break;
|
||||
case JFJochProtoBuf::INDEXING_RATE:
|
||||
ret.type = PlotType::IndexingRate;
|
||||
break;
|
||||
case JFJochProtoBuf::INDEXING_RATE_PER_FILE:
|
||||
ret.type = PlotType::IndexingRatePerFile;
|
||||
break;
|
||||
default:
|
||||
case JFJochProtoBuf::ADU_HISTOGRAM:
|
||||
ret.type = PlotType::ADUHistorgram;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Convert(const Plot& input, JFJochProtoBuf::Plot &output) {
|
||||
if (!input.x.empty())
|
||||
*output.mutable_x() = {input.x.begin(), input.x.end()};
|
||||
if (!input.y.empty())
|
||||
*output.mutable_y() = {input.y.begin(), input.y.end()};
|
||||
|
||||
}
|
||||
|
||||
void Convert(const RadialIntegrationProfiles& input, JFJochProtoBuf::RadialIntegrationProfiles& output) {
|
||||
for (const auto &i: input.profiles) {
|
||||
auto tmp = output.add_profiles();
|
||||
tmp->set_title(i.title);
|
||||
Convert(i.plot, *tmp->mutable_plot());
|
||||
}
|
||||
}
|
||||
|
||||
JFJochReceiverService::JFJochReceiverService(std::vector<AcquisitionDevice *> &open_capi_device,
|
||||
Logger &in_logger, ImagePusher &pusher) :
|
||||
logger(in_logger), aq_devices(open_capi_device),
|
||||
@@ -175,7 +218,7 @@ grpc::Status JFJochReceiverService::GetDataProcessingPlots(grpc::ServerContext *
|
||||
// Need to hold mutex, as receiver might not exist here, if state is idle
|
||||
std::unique_lock<std::mutex> ul(state_mutex);
|
||||
if (receiver)
|
||||
*response = receiver->GetPlots(*request);
|
||||
Convert(receiver->GetPlots(Convert(*request)), *response);
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
|
||||
@@ -185,7 +228,7 @@ grpc::Status JFJochReceiverService::GetRadialIntegrationProfiles(grpc::ServerCon
|
||||
// Need to hold mutex, as receiver might not exist here, if state is idle
|
||||
std::unique_lock<std::mutex> ul(state_mutex);
|
||||
if (receiver)
|
||||
*response = receiver->GetRadialIntegrationProfiles();
|
||||
Convert(receiver->GetRadialIntegrationProfiles(), *response);
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,14 +79,13 @@ TEST_CASE("RadialIntegrationProfile","[RadialIntegration]") {
|
||||
std::vector<int64_t> sum_wr(mapping.GetBinNumber() - 1);
|
||||
REQUIRE_THROWS(profile.Add(sum_wr, count));
|
||||
|
||||
JFJochProtoBuf::Plot plot;
|
||||
profile.GetPlot(plot);
|
||||
Plot plot = profile.GetPlot();
|
||||
|
||||
REQUIRE(plot.x_size() == mapping.GetBinNumber());
|
||||
REQUIRE(plot.y_size() == mapping.GetBinNumber());
|
||||
REQUIRE(plot.x.size() == mapping.GetBinNumber());
|
||||
REQUIRE(plot.y.size() == mapping.GetBinNumber());
|
||||
for (int i = 0; i < mapping.GetBinNumber(); i++) {
|
||||
REQUIRE(plot.x(i) == Approx(mapping.GetBinToQ()[i]));
|
||||
REQUIRE(plot.y(i) == Approx(i * 4));
|
||||
REQUIRE(plot.x[i] == Approx(mapping.GetBinToQ()[i]));
|
||||
REQUIRE(plot.y[i] == Approx(i * 4));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,14 +108,13 @@ TEST_CASE("RadialIntegrationProfile_operatorAdd","[RadialIntegration]") {
|
||||
REQUIRE_NOTHROW(profile0.Add(sum, count));
|
||||
REQUIRE_NOTHROW(profile1 += profile0);
|
||||
|
||||
JFJochProtoBuf::Plot plot;
|
||||
profile1.GetPlot(plot);
|
||||
auto plot = profile1.GetPlot();
|
||||
|
||||
REQUIRE(plot.x_size() == mapping.GetBinNumber());
|
||||
REQUIRE(plot.y_size() == mapping.GetBinNumber());
|
||||
REQUIRE(plot.x.size() == mapping.GetBinNumber());
|
||||
REQUIRE(plot.y.size() == mapping.GetBinNumber());
|
||||
for (int i = 0; i < mapping.GetBinNumber(); i++) {
|
||||
REQUIRE(plot.x(i) == Approx(mapping.GetBinToQ()[i]));
|
||||
REQUIRE(plot.y(i) == Approx(i * 4));
|
||||
REQUIRE(plot.x[i] == Approx(mapping.GetBinToQ()[i]));
|
||||
REQUIRE(plot.y[i] == Approx(i * 4));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-14
@@ -45,24 +45,22 @@ TEST_CASE("StatusVector_Plot","[StatusVector]") {
|
||||
status_vector.AddElement(2543, 44);
|
||||
status_vector.AddElement(2600, 41);
|
||||
|
||||
JFJochProtoBuf::Plot plot_out;
|
||||
status_vector.GetPlot(plot_out, 1000);
|
||||
REQUIRE(plot_out.x_size() == 3);
|
||||
REQUIRE(plot_out.y_size() == 3);
|
||||
REQUIRE(plot_out.x(0) == Approx(500));
|
||||
REQUIRE(plot_out.y(0) == Approx(11));
|
||||
REQUIRE(plot_out.x(2) == Approx(2500));
|
||||
REQUIRE(plot_out.y(2) == Approx((45 + 44 + 41) / 3.0));
|
||||
Plot plot_out = status_vector.GetPlot(1000);
|
||||
REQUIRE(plot_out.x.size() == 3);
|
||||
REQUIRE(plot_out.y.size() == 3);
|
||||
REQUIRE(plot_out.x[0] == Approx(500));
|
||||
REQUIRE(plot_out.y[0] == Approx(11));
|
||||
REQUIRE(plot_out.x[2] == Approx(2500));
|
||||
REQUIRE(plot_out.y[2] == Approx((45 + 44 + 41) / 3.0));
|
||||
}
|
||||
|
||||
TEST_CASE("StatusVector_Plot_OneBin","[StatusVector]") {
|
||||
StatusVector<uint64_t> status_vector;
|
||||
status_vector.AddElement(5, 11);
|
||||
|
||||
JFJochProtoBuf::Plot plot_out;
|
||||
status_vector.GetPlot(plot_out, 1000);
|
||||
REQUIRE(plot_out.x_size() == 1);
|
||||
REQUIRE(plot_out.y_size() == 1);
|
||||
REQUIRE(plot_out.x(0) == Approx(2.5));
|
||||
REQUIRE(plot_out.y(0) == Approx(11));
|
||||
auto plot_out = status_vector.GetPlot(1000);
|
||||
REQUIRE(plot_out.x.size() == 1);
|
||||
REQUIRE(plot_out.y.size() == 1);
|
||||
REQUIRE(plot_out.x[0] == Approx(2.5));
|
||||
REQUIRE(plot_out.y[0] == Approx(11));
|
||||
}
|
||||
Reference in New Issue
Block a user