"Error in detector operation" was raised whenever the wait-for-idle loop in JFJochServices::Stop() ended in any state other than idle. For DECTRIS that includes a single failed status request (connect/read timeout, non-200), which GetState() silently turned into NOT_CONNECTED, and a cancel whose disarm failed - none of them distinguishable in the log. - DectrisDetectorWrapper::GetState() logs the failure reason before returning NOT_CONNECTED. - Stop() logs the state that ended the loop, whether the stop command failed, and what the detector reports (DetectorWrapper::GetErrorDescription(); for DECTRIS the SIMPLON state and the detector status "error" list). - Cancel() logs why the stop command failed. - A non-200 GET now reports the HTTP status and body (it printed "Success"). - DectrisSimplonClient keeps one keep-alive httplib::Client, serialised by a mutex, instead of opening a new TCP connection per request. - The wait-for-idle loop polls every 100 ms instead of every 5 ms. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
142 lines
4.4 KiB
C++
142 lines
4.4 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
#include "DectrisDetectorWrapper.h"
|
|
|
|
DetectorState DectrisDetectorWrapper::GetState() const {
|
|
if (!simplon)
|
|
return DetectorState::NOT_CONNECTED;
|
|
|
|
SimplonState simplon_state;
|
|
|
|
try {
|
|
simplon_state = simplon->GetState();
|
|
} catch (const JFJochException &e) {
|
|
logger.Warning("Cannot read detector state: {}", e.what());
|
|
return DetectorState::NOT_CONNECTED;
|
|
}
|
|
|
|
switch (simplon_state) {
|
|
case SimplonState::Ready:
|
|
return DetectorState::WAITING;
|
|
case SimplonState::Initialize:
|
|
case SimplonState::Configure:
|
|
case SimplonState::Acquire:
|
|
case SimplonState::Test:
|
|
return DetectorState::BUSY;
|
|
case SimplonState::Idle:
|
|
return DetectorState::IDLE;
|
|
default:
|
|
case SimplonState::Error:
|
|
case SimplonState::Na:
|
|
return DetectorState::ERROR;
|
|
}
|
|
}
|
|
|
|
void DectrisDetectorWrapper::CheckBusy() {
|
|
switch(GetState()) {
|
|
case DetectorState::BUSY:
|
|
case DetectorState::WAITING:
|
|
throw JFJochException(JFJochExceptionCategory::Detector,
|
|
"Detector busy");
|
|
case DetectorState::NOT_CONNECTED:
|
|
throw JFJochException(JFJochExceptionCategory::Detector,
|
|
"Detector not connected");
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void DectrisDetectorWrapper::CheckBusyOrError() {
|
|
switch(GetState()) {
|
|
case DetectorState::ERROR:
|
|
throw JFJochCriticalException("Detector in error state");
|
|
case DetectorState::BUSY:
|
|
case DetectorState::WAITING:
|
|
throw JFJochException(JFJochExceptionCategory::Detector,
|
|
"Detector busy");
|
|
case DetectorState::NOT_CONNECTED:
|
|
throw JFJochException(JFJochExceptionCategory::Detector,
|
|
"Detector not connected");
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void DectrisDetectorWrapper::Initialize(DiffractionExperiment &experiment,
|
|
const std::vector<AcquisitionDeviceNetConfig> &net_config) {
|
|
if (experiment.GetDetectorType() != DetectorType::DECTRIS)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
|
"DectrisDetectorWrapper needs DECTRIS detector");
|
|
|
|
if (experiment.GetDetectorModuleHostname().empty()) {
|
|
simplon.reset();
|
|
return;
|
|
}
|
|
|
|
if (experiment.GetDetectorModuleHostname().size() != 1)
|
|
throw JFJochException(JFJochExceptionCategory::Detector,
|
|
"DectrisDetectorWrapper needs DECTRIS detector");
|
|
|
|
simplon = std::make_unique<DectrisSimplonClient>(experiment.GetDetectorSetup().GetDetectorModuleHostname()[0]);
|
|
|
|
CheckBusy();
|
|
simplon->InitializeDetector(experiment.Detector());
|
|
}
|
|
|
|
void DectrisDetectorWrapper::Configure(const DiffractionExperiment &experiment) {
|
|
CheckBusyOrError();
|
|
if (simplon)
|
|
simplon->ConfigureDetector(experiment);
|
|
}
|
|
|
|
void DectrisDetectorWrapper::Start(const DiffractionExperiment &experiment) {
|
|
CheckBusyOrError();
|
|
if (simplon)
|
|
simplon->StartAcquisition(experiment);
|
|
}
|
|
|
|
void DectrisDetectorWrapper::Stop() {
|
|
if (simplon)
|
|
simplon->EndAcquisitionFinished();
|
|
}
|
|
|
|
void DectrisDetectorWrapper::Trigger() {
|
|
if (simplon)
|
|
simplon->TriggerAcquisition();
|
|
}
|
|
|
|
void DectrisDetectorWrapper::Deactivate() {
|
|
CheckBusyOrError();
|
|
}
|
|
|
|
DetectorStatus DectrisDetectorWrapper::GetStatus() const {
|
|
if (!simplon)
|
|
return {.detector_state = DetectorState::NOT_CONNECTED};
|
|
|
|
return {
|
|
.detector_state = GetState()
|
|
};
|
|
}
|
|
|
|
void DectrisDetectorWrapper::LoadPixelMask(PixelMask &mask) {
|
|
if (simplon)
|
|
mask.LoadDECTRISBadPixelMask(simplon->GetPixelMask());
|
|
}
|
|
|
|
std::string DectrisDetectorWrapper::GetErrorDescription() const {
|
|
if (!simplon)
|
|
return {};
|
|
std::string ret;
|
|
try {
|
|
ret = "SIMPLON state " + to_string(simplon->GetState());
|
|
} catch (const JFJochException &e) {
|
|
ret = std::string("SIMPLON state unreadable (") + e.what() + ")";
|
|
}
|
|
try {
|
|
ret += ", errors " + simplon->GetErrorStatus();
|
|
} catch (const JFJochException &e) {
|
|
ret += std::string(", errors unreadable (") + e.what() + ")";
|
|
}
|
|
return ret;
|
|
}
|