DiffractionExperiment: Add option to save calibration
This commit is contained in:
@@ -52,6 +52,7 @@ DiffractionExperiment::DiffractionExperiment(const DetectorSetup& det_setup) {
|
||||
|
||||
dataset.set_rad_int_polarization_corr(false);
|
||||
dataset.set_rad_int_solid_angle_corr(false);
|
||||
dataset.set_save_calibration(false);
|
||||
|
||||
internal.set_ndatastreams(1);
|
||||
|
||||
@@ -1230,3 +1231,12 @@ void DiffractionExperiment::SetupROIFilter(ROIFilter &filter) {
|
||||
filter.SetRectangle(i.x0(), i.y0(), i.width(), i.height());
|
||||
}
|
||||
|
||||
DiffractionExperiment &DiffractionExperiment::SaveCalibration(bool input) {
|
||||
dataset.set_save_calibration(input);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool DiffractionExperiment::GetSaveCalibration() const {
|
||||
return dataset.save_calibration();
|
||||
}
|
||||
|
||||
|
||||
@@ -228,6 +228,9 @@ public:
|
||||
DiffractionExperiment& ClearROI();
|
||||
bool GetApplyROI() const;
|
||||
void SetupROIFilter(ROIFilter& filter);
|
||||
|
||||
DiffractionExperiment& SaveCalibration(bool input);
|
||||
bool GetSaveCalibration() const;
|
||||
};
|
||||
|
||||
inline int64_t CalculateStride(const std::chrono::microseconds &frame_time, const std::chrono::microseconds &preview_time) {
|
||||
|
||||
@@ -111,6 +111,8 @@ message DatasetSettings {
|
||||
bool rad_int_solid_angle_corr = 18;
|
||||
bool rad_int_polarization_corr = 19;
|
||||
float rad_int_polarization_factor = 20;
|
||||
|
||||
bool save_calibration = 21;
|
||||
}
|
||||
|
||||
message DetectorSettings {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -173,24 +173,30 @@ JFJochReceiver::JFJochReceiver(const JFJochProtoBuf::ReceiverInput &settings,
|
||||
.algorithm = CompressionAlgorithm::BSHUF_LZ4,
|
||||
.channel = "sc0"
|
||||
});
|
||||
for (int sc = 0; sc < experiment.GetStorageCellNumber(); sc++) {
|
||||
for (int gain = 0; gain < 3; gain++) {
|
||||
auto tmp = compressor.Compress(calib->GetPedestal(gain, sc));
|
||||
pedestal.emplace_back(tmp);
|
||||
std::string channel = "pedestal_G" + std::to_string(gain)+ "_sc" + std::to_string(sc);
|
||||
if (experiment.GetSaveCalibration()) {
|
||||
for (int sc = 0; sc < experiment.GetStorageCellNumber(); sc++) {
|
||||
for (int gain = 0; gain < 3; gain++) {
|
||||
auto tmp = compressor.Compress(calib->GetPedestal(gain, sc));
|
||||
pedestal.emplace_back(tmp);
|
||||
std::string channel = "pedestal_G" + std::to_string(gain);
|
||||
|
||||
CBORImage image{
|
||||
.data = pedestal.at(pedestal.size()-1).data(),
|
||||
.size = pedestal.at(pedestal.size()-1).size(),
|
||||
.xpixel = (size_t) xpixel,
|
||||
.ypixel = (size_t) ypixel,
|
||||
.pixel_depth_bytes = 2,
|
||||
.pixel_is_signed = false,
|
||||
.pixel_is_float = false,
|
||||
.algorithm = CompressionAlgorithm::BSHUF_LZ4,
|
||||
.channel = channel
|
||||
};
|
||||
message.AddCalibration(image);
|
||||
if (experiment.GetStorageCellNumber() > 1)
|
||||
channel += "_sc" + std::to_string(sc);
|
||||
|
||||
CBORImage image{
|
||||
.data = pedestal.at(pedestal.size() - 1).data(),
|
||||
.size = pedestal.at(pedestal.size() - 1).size(),
|
||||
.xpixel = (size_t) xpixel,
|
||||
.ypixel = (size_t) ypixel,
|
||||
.pixel_depth_bytes = 2,
|
||||
.pixel_is_signed = false,
|
||||
.pixel_is_float = false,
|
||||
.algorithm = CompressionAlgorithm::BSHUF_LZ4,
|
||||
.channel = channel
|
||||
};
|
||||
|
||||
message.AddCalibration(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,103 @@ TEST_CASE("JFJochIntegrationTest_ZMQ", "[JFJochReceiver]") {
|
||||
writer_server->Shutdown();
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("JFJochIntegrationTest_ZMQ_save_calibration", "[JFJochReceiver]") {
|
||||
Logger logger("JFJochIntegrationTest_ZMQ_save_calibration");
|
||||
ZMQContext zmq_context;
|
||||
|
||||
RegisterHDF5Filter();
|
||||
|
||||
int64_t nimages = 5;
|
||||
int64_t ndatastream = 2;
|
||||
int64_t nmodules = 4;
|
||||
|
||||
JFJochServices services(logger);
|
||||
JFJochStateMachine state_machine(services, logger);
|
||||
|
||||
REQUIRE(!state_machine.GetMeasurementStatistics().has_value());
|
||||
state_machine.AddDetectorSetup(DetectorGeometry(ndatastream * nmodules, 2, 8, 36));
|
||||
|
||||
state_machine.NotThreadSafe_Experiment().DataStreams(ndatastream);
|
||||
state_machine.NotThreadSafe_Experiment().PedestalG0Frames(0).PedestalG1Frames(0).PedestalG2Frames(0);
|
||||
services.Writer("unix:writer_test", "inproc://#1").Receiver("unix:fpga_receiver_test");
|
||||
|
||||
logger.Verbose(true);
|
||||
|
||||
std::vector<uint16_t> image(RAW_MODULE_SIZE);
|
||||
|
||||
std::vector<std::unique_ptr<MockAcquisitionDevice>> aq_devices;
|
||||
|
||||
for (int i = 0; i < ndatastream; i++) {
|
||||
auto *test = new MockAcquisitionDevice(i, 256);
|
||||
aq_devices.emplace_back(test);
|
||||
}
|
||||
|
||||
std::vector<AcquisitionDevice *> tmp_devices;
|
||||
for (const auto &i: aq_devices)
|
||||
tmp_devices.emplace_back(i.get());
|
||||
|
||||
ZMQImagePusher pusher(zmq_context, {"inproc://#1"});
|
||||
JFJochReceiverService fpga_receiver(tmp_devices, logger, pusher);
|
||||
|
||||
JFJochWriterService writer(zmq_context, logger);
|
||||
|
||||
auto fpga_receiver_server = gRPCServer("unix:fpga_receiver_test", fpga_receiver);
|
||||
auto writer_server = gRPCServer("unix:writer_test", writer);
|
||||
|
||||
REQUIRE_NOTHROW(state_machine.Initialize());
|
||||
logger.Info("Initialized");
|
||||
|
||||
JFJochProtoBuf::DatasetSettings setup;
|
||||
setup.set_ntrigger(1);
|
||||
setup.set_images_per_trigger(5);
|
||||
setup.set_detector_distance_mm(100);
|
||||
setup.set_file_prefix("integration_test_with_calibration");
|
||||
setup.set_photon_energy_kev(12.4);
|
||||
setup.set_data_file_count(2);
|
||||
setup.set_summation(1);
|
||||
setup.set_save_calibration(true);
|
||||
|
||||
REQUIRE_NOTHROW(state_machine.Start(setup));
|
||||
logger.Info("Started measurement");
|
||||
|
||||
JFJochProtoBuf::BrokerStatus status;
|
||||
status = state_machine.GetStatus();
|
||||
REQUIRE(status.progress() == Approx(0.0));
|
||||
REQUIRE(status.broker_state() == JFJochProtoBuf::DATA_COLLECTION);
|
||||
|
||||
for (int i = 0; i < ndatastream; i++) {
|
||||
for (int m = 0; m < state_machine.NotThreadSafe_Experiment().GetModulesNum(i); m++) {
|
||||
for (int image_num = 1; image_num <= nimages; image_num++)
|
||||
aq_devices[i]->AddModule(image_num, m, image.data());
|
||||
}
|
||||
aq_devices[i]->Terminate();
|
||||
}
|
||||
|
||||
REQUIRE_NOTHROW(state_machine.Stop());
|
||||
logger.Info("Stopped measurement");
|
||||
|
||||
status = state_machine.GetStatus();
|
||||
REQUIRE(status.broker_state() == JFJochProtoBuf::IDLE);
|
||||
|
||||
auto tmp = state_machine.GetMeasurementStatistics();
|
||||
REQUIRE(tmp.has_value());
|
||||
auto statistics = tmp.value();
|
||||
|
||||
REQUIRE(statistics.collection_efficiency() == 1.0);
|
||||
REQUIRE(statistics.images_collected() == 5);
|
||||
REQUIRE(statistics.images_written() == 5);
|
||||
REQUIRE(statistics.max_image_number_sent() == 4);
|
||||
REQUIRE(!statistics.cancelled());
|
||||
REQUIRE(statistics.file_prefix() == "integration_test_with_calibration");
|
||||
REQUIRE(statistics.detector_width() == 2068);
|
||||
REQUIRE(statistics.detector_height() == 2164);
|
||||
REQUIRE(statistics.detector_pixel_depth() == 2);
|
||||
REQUIRE(statistics.file_statistics_size() == 2);
|
||||
fpga_receiver_server->Shutdown();
|
||||
writer_server->Shutdown();
|
||||
}
|
||||
|
||||
TEST_CASE("JFJochIntegrationTest_ZMQ_2DataStreams_4Devices", "[JFJochReceiver]") {
|
||||
Logger logger("JFJochIntegrationTest_ZMQ_2DataStreams_4Devices");
|
||||
ZMQContext zmq_context;
|
||||
|
||||
Reference in New Issue
Block a user