Build Packages / build:viewer-tgz:cpu (push) Successful in 7m8s
Build Packages / build:viewer-tgz:cuda (push) Successful in 7m38s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 12m56s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 12m57s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 13m35s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 13m40s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 13m59s
Build Packages / build:windows:nocuda (push) Successful in 16m4s
Build Packages / build:windows:cuda (push) Successful in 18m16s
Build Packages / build:rpm (rocky8) (push) Successful in 11m25s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 12m34s
Build Packages / XDS test (durin plugin) (push) Successful in 7m11s
Build Packages / Generate python client (push) Successful in 34s
Build Packages / Build documentation (push) Successful in 1m4s
Build Packages / Create release (push) Skipped
Build Packages / build:rpm (ubuntu2204) (push) Successful in 11m41s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 11m44s
Build Packages / build:rpm (rocky9) (push) Successful in 13m0s
Build Packages / DIALS test (push) Successful in 13m18s
Build Packages / XDS test (neggia plugin) (push) Successful in 7m43s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 8m33s
Build Packages / Unit tests (push) Successful in 1h1m27s
Going to the Error state after any acquisition failure forced an expensive re-initialisation (reconnect + full detector config + pedestals), even when the detector was still perfectly configured and only a transient problem occurred. Split failures into two classes: - ordinary acquisition failures (receiver/writer/analysis problems, missed packets, writer disconnect) return to Idle with an Error-severity message, so the run can be retried without re-initialising; - failures that leave the detector in an undefined state throw the new JFJochCriticalException and still go to Error, forcing re-initialisation. The detector layer is the single source of truth for "detector faulted": SLSDetectorWrapper::InternalStop and DectrisDetectorWrapper::CheckBusyOrError raise JFJochCriticalException on the ERROR state, and JFJochServices::Stop raises it when the detector does not return to idle at the end of a run. MeasurementThread dispatches purely on exception type - no detector-status field checks. Also: - JFJochServices::Start now stops the receiver it launched if the detector fails to start, so the service returns to idle cleanly and the run can be retried. - A synchronous Start rethrows the failure to the caller (HTTP layer) via a stored exception_ptr, so a failed start is no longer reported as HTTP 200. - JFJochServices::Stop no longer throws on a writer error; it is reported through receiver_output.writer_err and surfaced as an Idle + Error-severity message, which makes the previously-dead writer_err branch in MeasurementThread live. Initialisation, calibration/pedestal, SelectDetector and Deactivate keep the Error-state behaviour, as those genuinely leave the system in an undefined state. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
124 lines
3.8 KiB
C++
124 lines
3.8 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) {
|
|
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());
|
|
}
|