127 lines
3.9 KiB
C++
127 lines
3.9 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 JFJochException(JFJochExceptionCategory::Detector,
|
|
"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->ConfigureDetector(experiment);
|
|
simplon->StartAcquisition();
|
|
}
|
|
}
|
|
|
|
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());
|
|
}
|