From 0e2bcc5d8cbbb42f4582e6480a24cbbff65aec0f Mon Sep 17 00:00:00 2001 From: simonge Date: Tue, 13 Aug 2024 11:31:50 +0100 Subject: [PATCH 1/2] Moved exceptions from init and added debug statements to process --- .../fardetectors/FarDetectorMLReconstruction.cc | 8 +++++++- .../fardetectors/FarDetectorMLReconstruction.h | 1 + .../fardetectors/FarDetectorTrackerCluster.cc | 10 ++++++++-- .../fardetectors/FarDetectorTrackerCluster.h | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc b/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc index d92b382714..945bb5fa8d 100644 --- a/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc +++ b/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc @@ -32,10 +32,10 @@ namespace eicrecon { // Locate and load the weight file // TODO - Add functionality to select passed by configuration - bool methodFound = false; if(!m_cfg.modelPath.empty()){ try{ m_method = dynamic_cast(m_reader->BookMVA( m_cfg.methodName, m_cfg.modelPath )); + m_initialized = true; } catch(std::exception &e){ error(fmt::format("Failed to load method {} from file {}: {}", m_cfg.methodName, m_cfg.modelPath, e.what())); @@ -55,6 +55,12 @@ namespace eicrecon { const auto [inputTracks,beamElectrons] = input; auto [outputFarDetectorMLTrajectories, outputFarDetectorMLTrackParameters, outputFarDetectorMLTracks] = output; + // Check if the algorithm has been initialized properly + if(!m_initialized){ + debug("Initialization did not complete"); + return; + } + //Set beam energy from first MCBeamElectron, using std::call_once std::call_once(m_initBeamE,[&](){ // Check if beam electrons are present diff --git a/src/algorithms/fardetectors/FarDetectorMLReconstruction.h b/src/algorithms/fardetectors/FarDetectorMLReconstruction.h index a0f72141a7..b95f6be000 100644 --- a/src/algorithms/fardetectors/FarDetectorMLReconstruction.h +++ b/src/algorithms/fardetectors/FarDetectorMLReconstruction.h @@ -61,6 +61,7 @@ namespace eicrecon { float m_beamE{10.0}; std::once_flag m_initBeamE; float nnInput[4] = {0.0,0.0,0.0,0.0}; + bool m_initialized{false}; }; diff --git a/src/algorithms/fardetectors/FarDetectorTrackerCluster.cc b/src/algorithms/fardetectors/FarDetectorTrackerCluster.cc index b12a61b738..d49214eace 100644 --- a/src/algorithms/fardetectors/FarDetectorTrackerCluster.cc +++ b/src/algorithms/fardetectors/FarDetectorTrackerCluster.cc @@ -30,7 +30,7 @@ void FarDetectorTrackerCluster::init() { m_cellid_converter = algorithms::GeoSvc::instance().cellIDPositionConverter(); if (m_cfg.readout.empty()) { - throw JException("Readout is empty"); + error("Config readout field is empty"); } try { m_seg = m_detector->readout(m_cfg.readout).segmentation(); @@ -43,9 +43,9 @@ void FarDetectorTrackerCluster::init() { m_y_idx = m_id_dec->index(m_cfg.y_field); debug("Find layer field {}, index = {}", m_cfg.y_field, m_y_idx); } + m_initialized = true; } catch (...) { error("Failed to load ID decoder for {}", m_cfg.readout); - throw JException("Failed to load ID decoder"); } } @@ -55,6 +55,12 @@ void FarDetectorTrackerCluster::process(const FarDetectorTrackerCluster::Input& const auto [inputHitsCollections] = input; auto [outputClustersCollection] = output; + // Return if configurations are not set properly + if (!m_initialized) { + debug("Initialization did not complete"); + return; + } + // Loop over input and output collections - Any collection should only contain hits from a single // surface for (size_t i = 0; i < inputHitsCollections.size(); i++) { diff --git a/src/algorithms/fardetectors/FarDetectorTrackerCluster.h b/src/algorithms/fardetectors/FarDetectorTrackerCluster.h index 6ac60e5067..1849c1d107 100644 --- a/src/algorithms/fardetectors/FarDetectorTrackerCluster.h +++ b/src/algorithms/fardetectors/FarDetectorTrackerCluster.h @@ -62,6 +62,7 @@ class FarDetectorTrackerCluster : public FarDetectorTrackerClusterAlgorithm, const dd4hep::BitFieldCoder* m_id_dec{nullptr}; const dd4hep::rec::CellIDPositionConverter* m_cellid_converter{nullptr}; dd4hep::Segmentation m_seg; + bool m_initialized{false}; int m_x_idx{0}; int m_y_idx{0}; From a21ddcb706c0c226baaf7b8ef30dc6aa9ad28bb0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:44:08 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/algorithms/fardetectors/FarDetectorMLReconstruction.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc b/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc index 945bb5fa8d..296720c490 100644 --- a/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc +++ b/src/algorithms/fardetectors/FarDetectorMLReconstruction.cc @@ -59,7 +59,7 @@ namespace eicrecon { if(!m_initialized){ debug("Initialization did not complete"); return; - } + } //Set beam energy from first MCBeamElectron, using std::call_once std::call_once(m_initBeamE,[&](){