DetectorSimplonClient: Rearrange logic to achieve shorter setup time
This commit is contained in:
@@ -84,9 +84,14 @@ void DectrisSimplonClient::SetConfig(SimplonModule element, const std::string &k
|
||||
}
|
||||
}
|
||||
|
||||
std::string DectrisSimplonClient::GenAddr(DectrisSimplonClient::SimplonModule element,
|
||||
DectrisSimplonClient::SimplonTask task,
|
||||
const std::string& key) {
|
||||
void DectrisSimplonClient::SetConfigIfDifferent(SimplonModule element, const std::string &key, float value, float tolerance) {
|
||||
auto curr_val = GetConfig(element, key).val.get<float>();
|
||||
|
||||
if (std::abs(curr_val - value) > tolerance)
|
||||
SetConfig(element, key, value);
|
||||
}
|
||||
|
||||
std::string DectrisSimplonClient::GenAddr(SimplonModule element, SimplonTask task, const std::string& key) {
|
||||
std::string addr;
|
||||
switch (element) {
|
||||
case SimplonModule::Detector:
|
||||
@@ -120,9 +125,7 @@ std::string DectrisSimplonClient::GenAddr(DectrisSimplonClient::SimplonModule el
|
||||
}
|
||||
|
||||
SimplonConfig
|
||||
DectrisSimplonClient::GetConfig(DectrisSimplonClient::SimplonModule element,
|
||||
DectrisSimplonClient::SimplonTask task,
|
||||
const std::string &key) {
|
||||
DectrisSimplonClient::GetConfig(SimplonModule element, SimplonTask task, const std::string &key) {
|
||||
httplib::Client cli_simple(hostname, port);
|
||||
cli_simple.set_connection_timeout(std::chrono::milliseconds(500));
|
||||
cli_simple.set_read_timeout(std::chrono::seconds(1));
|
||||
@@ -162,7 +165,7 @@ SimplonConfig DectrisSimplonClient::GetDetCfg(const std::string &key) {
|
||||
return GetConfig(SimplonModule::Detector, key);
|
||||
}
|
||||
|
||||
nlohmann::json DectrisSimplonClient::GetStatus(DectrisSimplonClient::SimplonModule element, const std::string &key) {
|
||||
nlohmann::json DectrisSimplonClient::GetStatus(SimplonModule element, const std::string &key) {
|
||||
return GetConfig(element, SimplonTask::Status, key).val;
|
||||
}
|
||||
|
||||
@@ -207,6 +210,11 @@ void DectrisSimplonClient::InitializeDetector(DetectorSetup& setup) {
|
||||
"Initialize unsuccessful");
|
||||
|
||||
SetConfig(SimplonModule::Detector, "roi_mode", setup.GetDECTRISROI());
|
||||
// Configure streaming, disable file writer and monitor
|
||||
SetConfig(SimplonModule::Stream, "format", "cbor");
|
||||
SetConfig(SimplonModule::Stream, "mode", "enabled");
|
||||
SetConfig(SimplonModule::Filewriter, "mode", "disabled");
|
||||
SetConfig(SimplonModule::Monitor, "mode", "disabled");
|
||||
ReadDetectorConfig(setup);
|
||||
}
|
||||
|
||||
@@ -222,24 +230,34 @@ void DectrisSimplonClient::EndAcquisitionFinished() {
|
||||
SendDetectorCommand(SimplonDetectorCommand::Disarm);
|
||||
}
|
||||
|
||||
void DectrisSimplonClient::StartAcquisition() {
|
||||
void DectrisSimplonClient::StartAcquisition(const DiffractionExperiment& experiment) {
|
||||
// For DECTRIS detectors we assume frame_time == count_time
|
||||
if (experiment.GetFrameCountTimeAuto())
|
||||
SetConfig(SimplonModule::Detector, "count_time", experiment.GetFrameTime().count() / 1e6f);
|
||||
else
|
||||
SetConfig(SimplonModule::Detector, "count_time", experiment.GetFrameCountTime().count() / 1e6f);
|
||||
|
||||
SetConfig(SimplonModule::Detector, "frame_time", experiment.GetFrameTime().count() / 1e6f);
|
||||
SetConfig(SimplonModule::Detector, "nimages", experiment.GetFrameNumPerTrigger());
|
||||
SetConfig(SimplonModule::Detector, "ntrigger", experiment.GetNumTriggers());
|
||||
|
||||
SetConfig(SimplonModule::Detector, "beam_center_x", experiment.GetBeamX_pxl());
|
||||
SetConfig(SimplonModule::Detector, "beam_center_y", experiment.GetBeamY_pxl());
|
||||
SetConfig(SimplonModule::Detector, "detector_distance", experiment.GetDetectorDistance_mm() / 1e3f);
|
||||
|
||||
SendDetectorCommand(SimplonDetectorCommand::Arm);
|
||||
}
|
||||
|
||||
void DectrisSimplonClient::ConfigureDetector(const DiffractionExperiment &experiment) {
|
||||
SetConfig(SimplonModule::Stream, "format", "cbor");
|
||||
SetConfig(SimplonModule::Stream, "mode", "enabled");
|
||||
SetConfig(SimplonModule::Filewriter, "mode", "disabled");
|
||||
SetConfig(SimplonModule::Monitor, "mode", "disabled");
|
||||
|
||||
// TODO: Check if counting_mode retrigger is available
|
||||
if (experiment.GetDetectorMode() == DetectorMode::DarkMask)
|
||||
SetConfig(SimplonModule::Detector, "counting_mode", "normal");
|
||||
else
|
||||
SetConfig(SimplonModule::Detector, "counting_mode", "retrigger");
|
||||
SetConfig(SimplonModule::Detector, "photon_energy", experiment.GetIncidentEnergy_keV() * 1e3f);
|
||||
|
||||
SetConfigIfDifferent(SimplonModule::Detector, "photon_energy", experiment.GetIncidentEnergy_keV() * 1e3f, 0.01f);
|
||||
auto thr = experiment.GetEigerThreshold_keV();
|
||||
SetConfig(SimplonModule::Detector, "threshold_energy", thr * 1e3f);
|
||||
SetConfigIfDifferent(SimplonModule::Detector, "threshold_energy", thr * 1e3f, 0.01);
|
||||
|
||||
switch (experiment.GetDetectorTiming()) {
|
||||
case DetectorTiming::Auto:
|
||||
@@ -256,19 +274,6 @@ void DectrisSimplonClient::ConfigureDetector(const DiffractionExperiment &experi
|
||||
"Burst mode not supported with DECTRIS sytems");
|
||||
}
|
||||
|
||||
// For DECTRIS detectors we assume frame_time == count_time
|
||||
if (experiment.GetFrameCountTimeAuto())
|
||||
SetConfig(SimplonModule::Detector, "count_time", experiment.GetFrameTime().count() / 1e6f);
|
||||
else
|
||||
SetConfig(SimplonModule::Detector, "count_time", experiment.GetFrameCountTime().count() / 1e6f);
|
||||
|
||||
SetConfig(SimplonModule::Detector, "frame_time", experiment.GetFrameTime().count() / 1e6f);
|
||||
SetConfig(SimplonModule::Detector, "nimages", experiment.GetFrameNumPerTrigger());
|
||||
SetConfig(SimplonModule::Detector, "ntrigger", experiment.GetNumTriggers());
|
||||
|
||||
SetConfig(SimplonModule::Detector, "beam_center_x", experiment.GetBeamX_pxl());
|
||||
SetConfig(SimplonModule::Detector, "beam_center_y", experiment.GetBeamY_pxl());
|
||||
SetConfig(SimplonModule::Detector, "detector_distance", experiment.GetDetectorDistance_mm() / 1e3f);
|
||||
SetConfig(SimplonModule::Detector, "trigger_start_delay", experiment.GetDetectorDelay().count() / 1e9);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user