From 30599e28587266542949377b85fdcd4c5e148689 Mon Sep 17 00:00:00 2001 From: leonarski_f Date: Sat, 23 Mar 2024 04:07:12 +0100 Subject: [PATCH] Fix bug in detector initialize --- common/Definitions.h | 2 ++ common/DiffractionExperiment.cpp | 2 +- common/DiffractionExperiment.h | 1 - detector_control/DetectorWrapper.cpp | 42 +++++++++++++++++----------- image_analysis/IndexerWrapper.cpp | 2 +- image_analysis/IndexerWrapper.h | 6 ++-- image_analysis/fast-feedback-indexer | 2 +- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/common/Definitions.h b/common/Definitions.h index 0655bc32..1dd8ae25 100644 --- a/common/Definitions.h +++ b/common/Definitions.h @@ -29,4 +29,6 @@ #define DEFAULT_G2_FACTOR (-0.1145) #define DEFAULT_HG0_FACTOR (100.0) +#define MAX_SPOT_COUNT (100) + #endif //DEFINITIONS_H diff --git a/common/DiffractionExperiment.cpp b/common/DiffractionExperiment.cpp index 94c0ea7c..7d4bdf1c 100644 --- a/common/DiffractionExperiment.cpp +++ b/common/DiffractionExperiment.cpp @@ -643,7 +643,7 @@ float DiffractionExperiment::GetQSpacingForAzimInt_recipA() const { } int64_t DiffractionExperiment::GetMaxSpotCount() const { - return max_spot_count; + return MAX_SPOT_COUNT; } std::string DiffractionExperiment::GetSampleName() const { diff --git a/common/DiffractionExperiment.h b/common/DiffractionExperiment.h index 4c503c99..a76d0bef 100644 --- a/common/DiffractionExperiment.h +++ b/common/DiffractionExperiment.h @@ -100,7 +100,6 @@ class DiffractionExperiment { // Dataset settings DatasetSettings dataset; - constexpr static const int64_t max_spot_count = 100; public: // Public methods are atomic DiffractionExperiment(); diff --git a/detector_control/DetectorWrapper.cpp b/detector_control/DetectorWrapper.cpp index c2f4af06..0babc17a 100644 --- a/detector_control/DetectorWrapper.cpp +++ b/detector_control/DetectorWrapper.cpp @@ -10,31 +10,37 @@ void DetectorWrapper::Initialize(const DiffractionExperiment& experiment, const std::vector& net_config) { logger.Info("Initialize detector"); try { - if (det.size() > 0) { - // Only if the detector is already defined + auto module_hostname = experiment.GetDetectorModuleHostname(); + if (det.empty()) { + if (!module_hostname.empty()) + det.setHostname(module_hostname); + else + throw JFJochException(JFJochExceptionCategory::Detector, + "Detector not configured and hostname not provided"); + } else { // Stop the detector InternalStop(); // Clear synchronization prior to reconfiguring the detector det.setMaster(false, 0); det.setSynchronization(false); - } - auto module_hostname = experiment.GetDetectorModuleHostname(); - auto det_module_hostname = det.getHostname(); - if (!module_hostname.empty()) { - bool reset = true; - if (module_hostname.size() == det_module_hostname.size()) { - reset = false; - for (int i = 0; i < module_hostname.size(); i++) { - if (module_hostname[i] != det_module_hostname[i]) - reset = true; + if (!module_hostname.empty()) { + bool reset = true; + auto det_module_hostname = det.getHostname(); + + if (module_hostname.size() == det_module_hostname.size()) { + reset = false; + for (int i = 0; i < module_hostname.size(); i++) { + if (module_hostname[i] != det_module_hostname[i]) + reset = true; + } + } + if (reset) { + logger.Info("Resetting detector module host names"); + det.setHostname(module_hostname); } - } - if (reset) { - logger.Info("Resetting detector module host names"); - det.setHostname(module_hostname); } } @@ -161,6 +167,10 @@ void DetectorWrapper::Deactivate() { det.setHighVoltage(0); std::this_thread::sleep_for(std::chrono::seconds(5)); det.setPowerChip(false); + + det.setMaster(false, 0); + det.setSynchronization(false); + det.freeSharedMemory(); } catch (std::exception &e) { logger.ErrorException(e); diff --git a/image_analysis/IndexerWrapper.cpp b/image_analysis/IndexerWrapper.cpp index 50692dac..3fc930d6 100644 --- a/image_analysis/IndexerWrapper.cpp +++ b/image_analysis/IndexerWrapper.cpp @@ -15,7 +15,7 @@ std::vector IndexerWrapper::Run(const std::vector &coord) if (coord.size() <= min_spots) return ret; - size_t nspots = std::min(MAX_SPOTS_TO_INDEX, coord.size()); + size_t nspots = std::min(MAX_SPOT_COUNT, coord.size()); for (int i = 0; i < nspots; i++) { indexer.spotX(i) = coord[i].x; diff --git a/image_analysis/IndexerWrapper.h b/image_analysis/IndexerWrapper.h index cf0096f5..9a689473 100644 --- a/image_analysis/IndexerWrapper.h +++ b/image_analysis/IndexerWrapper.h @@ -7,14 +7,12 @@ #include "../common/Coord.h" #include "CrystalLattice.h" +#include "../common/Definitions.h" #ifdef JFJOCH_USE_CUDA #include #endif -#define MIN_SPOTS_TO_INDEX (10) -#define MAX_SPOTS_TO_INDEX (100) - struct IndexingResult { CrystalLattice l; std::vector indexed_spots; @@ -27,7 +25,7 @@ class IndexerWrapper { fast_feedback::config_persistent cpers{ .max_output_cells = 4, .max_input_cells = 1, - .max_spots = MAX_SPOTS_TO_INDEX + .max_spots = MAX_SPOT_COUNT }; // default persistent config fast_feedback::refine::config_ifss conf_ifss{}; fast_feedback::refine::indexer_ifss indexer{cpers, crt, conf_ifss}; diff --git a/image_analysis/fast-feedback-indexer b/image_analysis/fast-feedback-indexer index 1ab12c5e..7c178484 160000 --- a/image_analysis/fast-feedback-indexer +++ b/image_analysis/fast-feedback-indexer @@ -1 +1 @@ -Subproject commit 1ab12c5e59e85c0f83620df16d4e7c28ed7058fe +Subproject commit 7c178484cd2b6ce29941429e5ba7c313cf61be8c