From 93b32611e9df822b3414ac7b7be8fa7f281a9128 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Wed, 17 Apr 2024 15:16:20 -0400 Subject: [PATCH] Improve JAutoActivator One of the use cases for AutoActivator is debugging factories that might be excepting, but the exceptions are being swallowed by the caller. --- src/libraries/JANA/Services/JComponentManager.cc | 5 +++-- src/libraries/JANA/Services/JComponentManager.h | 1 + src/libraries/JANA/Utils/JAutoActivator.cc | 10 ++++------ src/libraries/JANA/Utils/JAutoActivator.h | 1 - 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libraries/JANA/Services/JComponentManager.cc b/src/libraries/JANA/Services/JComponentManager.cc index 548e03656..becab3ed1 100644 --- a/src/libraries/JANA/Services/JComponentManager.cc +++ b/src/libraries/JANA/Services/JComponentManager.cc @@ -38,12 +38,13 @@ void JComponentManager::InitPhase2() { m_params().SetDefaultParameter("record_call_stack", m_enable_call_graph_recording, "Records a trace of who called each factory. Reduces performance but necessary for plugins such as janadot."); m_params().SetDefaultParameter("jana:nevents", m_nevents, "Max number of events that sources can emit"); m_params().SetDefaultParameter("jana:nskip", m_nskip, "Number of events that sources should skip before starting emitting"); + m_params().SetDefaultParameter("autoactivate", m_autoactivate, "List of factories to activate regardless of what the event processors request. Format is typename:tag,typename:tag"); m_params().FilterParameters(m_default_tags, "DEFTAG:"); // Look for factories to auto-activate - // Right now AutoActivator parameter won't show up in parameters list. Reconsider this. - if (JAutoActivator::IsRequested(m_params())) { + if (!m_autoactivate.empty()) { add(new JAutoActivator); + // JAutoActivator will re-parse the autoactivate list by itself } } diff --git a/src/libraries/JANA/Services/JComponentManager.h b/src/libraries/JANA/Services/JComponentManager.h index ff5c4b6f5..c264462d3 100644 --- a/src/libraries/JANA/Services/JComponentManager.h +++ b/src/libraries/JANA/Services/JComponentManager.h @@ -64,6 +64,7 @@ class JComponentManager : public JService { std::map m_default_tags; bool m_enable_call_graph_recording = false; + std::string m_autoactivate; uint64_t m_nskip=0; uint64_t m_nevents=0; diff --git a/src/libraries/JANA/Utils/JAutoActivator.cc b/src/libraries/JANA/Utils/JAutoActivator.cc index c4497d2ac..a2d199204 100644 --- a/src/libraries/JANA/Utils/JAutoActivator.cc +++ b/src/libraries/JANA/Utils/JAutoActivator.cc @@ -9,10 +9,6 @@ JAutoActivator::JAutoActivator() { SetTypeName("JAutoActivator"); } -bool JAutoActivator::IsRequested(JParameterManager& params) { - return params.Exists("autoactivate") && (!params.GetParameterValue("autoactivate").empty()); -} - void JAutoActivator::AddAutoActivatedFactory(string factory_name, string factory_tag) { m_auto_activated_factories.push_back({std::move(factory_name), std::move(factory_tag)}); } @@ -67,7 +63,8 @@ void JAutoActivator::Init() { } } catch (...) { - LOG << "Error parsing AUTOACTIVATE=" << autoactivate_conf << LOG_END; + LOG_ERROR(GetLogger()) << "Error parsing parameter 'autoactivate'. Found: " << autoactivate_conf << LOG_END; + throw JException("AutoActivator could not parse parameter 'autoactivate'"); } } } @@ -81,7 +78,8 @@ void JAutoActivator::Process(const std::shared_ptr &event) { factory->Create(event); // This will do nothing if factory is already created } else { - LOG << "Warning: Could not find factory with name=" << name << ", tag=" << tag << LOG_END; + LOG_ERROR(GetLogger()) << "Could not find factory with typename=" << name << ", tag=" << tag << LOG_END; + throw JException("AutoActivator could not find factory with typename=%s, tag=%s", name.c_str(), tag.c_str()); } } } diff --git a/src/libraries/JANA/Utils/JAutoActivator.h b/src/libraries/JANA/Utils/JAutoActivator.h index 695a6d958..35d7eb410 100644 --- a/src/libraries/JANA/Utils/JAutoActivator.h +++ b/src/libraries/JANA/Utils/JAutoActivator.h @@ -16,7 +16,6 @@ class JAutoActivator : public JEventProcessor { public: JAutoActivator(); - static bool IsRequested(JParameterManager& params); static std::pair Split(std::string factory_name); void AddAutoActivatedFactory(string factory_name, string factory_tag); void Init() override;