From e589e5645d0f6acc02fd3b60a76b833c92422f46 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Mon, 20 Feb 2023 10:36:41 -0800 Subject: [PATCH 01/16] Default to C++17 (necessitated by new ROOT used by Katydid; not ideal, but an ok fix given that we just need old Nymph to work for now) --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a39f45b..64c6981b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,8 +25,8 @@ include( Nymph ) # Nymph options # ################# -# require C++11 -set_option( USE_CPP11 TRUE ) +# require C++17 +set_option( USE_CPP17 TRUE ) # Build the Nymph executable (also requires Nymph_ENABLE_EXECUTABLES) option( Nymph_BUILD_NYMPH_EXE "Flag to build the Nymph executable; also requires Nymph_ENABLE_EXECUTABLES" ON ) From 81ad3f773c0f2ee63fcfa6653cdaad200f0a9ca7 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Mon, 20 Feb 2023 10:37:18 -0800 Subject: [PATCH 02/16] Updating Scarab to hotfix branch for C++17 use and logger.hh macro deconflicting --- Scarab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scarab b/Scarab index ef2af248..c728b2fe 160000 --- a/Scarab +++ b/Scarab @@ -1 +1 @@ -Subproject commit ef2af248c5db7c92c84952a57759ba0f145f6cd4 +Subproject commit c728b2fecf7187fb01a1ef7d4189821f9406d32d From 2723d4119989b626942ed3dade284cf4556b7752 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Fri, 15 Sep 2023 15:38:32 -0700 Subject: [PATCH 03/16] Updated scarab (still on hotfix branch) --- Scarab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scarab b/Scarab index c728b2fe..bcf0dd86 160000 --- a/Scarab +++ b/Scarab @@ -1 +1 @@ -Subproject commit c728b2fecf7187fb01a1ef7d4189821f9406d32d +Subproject commit bcf0dd86f104197ba9b8b2cbc474948706cbda8f From 382c6d83fb838371c2c0651644acfdb7f23b41a2 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Fri, 15 Sep 2023 15:38:50 -0700 Subject: [PATCH 04/16] Updated KTLogger to use snprintf instead of sprintf --- Library/Utility/KTLogger.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Utility/KTLogger.cc b/Library/Utility/KTLogger.cc index 7cc87190..3cfff8ce 100644 --- a/Library/Utility/KTLogger.cc +++ b/Library/Utility/KTLogger.cc @@ -147,7 +147,7 @@ namespace Nymph fPrivate->fLogger = logName; } fPrivate->fColored = true; - sprintf(KTLogger::Private::sDateTimeFormat, "%%T"); + snprintf(KTLogger::Private::sDateTimeFormat, 16, "%%T"); SetLevel(eDebug); } @@ -155,7 +155,7 @@ namespace Nymph { fPrivate->fLogger = name.c_str(); fPrivate->fColored = true; - sprintf(KTLogger::Private::sDateTimeFormat, "%%T"); + snprintf(KTLogger::Private::sDateTimeFormat, 16, "%%T"); SetLevel(eDebug); } From b794568f3b75e9e500c0e3cfbde4c8bda322410e Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Wed, 20 Sep 2023 10:13:52 -0700 Subject: [PATCH 05/16] Updated Scarab to v1.6.8 --- Scarab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scarab b/Scarab index bcf0dd86..3c2b0bfe 160000 --- a/Scarab +++ b/Scarab @@ -1 +1 @@ -Subproject commit bcf0dd86f104197ba9b8b2cbc474948706cbda8f +Subproject commit 3c2b0bfe132b5ae4e3ff41f5db7d2744fcb9a0a2 From b39932f61954e2b5f407944a1f4162212f3cf628 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Wed, 20 Sep 2023 10:14:59 -0700 Subject: [PATCH 06/16] Bumped version to v1.4.8 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64c6981b..cfad2cd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ cmake_minimum_required (VERSION 3.1) ######### cmake_policy( SET CMP0048 NEW ) # version in project() -project( Nymph VERSION 1.4.7 ) +project( Nymph VERSION 1.4.8 ) list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/Scarab/cmake ) include( PackageBuilder ) From b3e019a3993411139a3f35deb4b1814121470395 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Sat, 7 Oct 2023 00:19:47 -0700 Subject: [PATCH 07/16] Updated Scarab to v1.6.9 --- Scarab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scarab b/Scarab index 3c2b0bfe..5cba1faa 160000 --- a/Scarab +++ b/Scarab @@ -1 +1 @@ -Subproject commit 3c2b0bfe132b5ae4e3ff41f5db7d2744fcb9a0a2 +Subproject commit 5cba1faaffb047d01c951b5756e072a11132d1e5 From f2a9754e9d681478fb671f9b2d0401c240fbeaf2 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Sat, 7 Oct 2023 00:20:13 -0700 Subject: [PATCH 08/16] Bumped version to v1.4.9 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfad2cd4..6b074616 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ cmake_minimum_required (VERSION 3.1) ######### cmake_policy( SET CMP0048 NEW ) # version in project() -project( Nymph VERSION 1.4.8 ) +project( Nymph VERSION 1.4.9 ) list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/Scarab/cmake ) include( PackageBuilder ) From 2c4ff286d870ef354031db16bf323b9eca54b251 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Thu, 21 Dec 2023 17:00:02 -0800 Subject: [PATCH 09/16] Updated Scarab to v1.6.10 --- Scarab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scarab b/Scarab index 5cba1faa..f6b2c613 160000 --- a/Scarab +++ b/Scarab @@ -1 +1 @@ -Subproject commit 5cba1faaffb047d01c951b5756e072a11132d1e5 +Subproject commit f6b2c613653584c9c5b0327bbe18302c2fef37a9 From 141a21e6453725bc65aab85274d8b7ff2688e97f Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Thu, 21 Dec 2023 17:01:16 -0800 Subject: [PATCH 10/16] Bumped version to 1.4.10 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b074616..b2ce1c7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ cmake_minimum_required (VERSION 3.1) ######### cmake_policy( SET CMP0048 NEW ) # version in project() -project( Nymph VERSION 1.4.9 ) +project( Nymph VERSION 1.4.10 ) list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/Scarab/cmake ) include( PackageBuilder ) From 6293cce361972f72cc8bd0760aaa16cc23e97406 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Thu, 8 Aug 2024 16:33:53 -0700 Subject: [PATCH 11/16] New class KTContext and associated changes to integrate the context with KTProcessor and distribute it with KTProcessorToolbox --- Library/Application/KTProcessorToolbox.cc | 6 +++- Library/Application/KTProcessorToolbox.hh | 16 +++++++++ Library/CMakeLists.txt | 2 ++ Library/Processor/KTContext.cc | 42 +++++++++++++++++++++++ Library/Processor/KTContext.hh | 34 ++++++++++++++++++ Library/Processor/KTProcessor.cc | 7 ++-- Library/Processor/KTProcessor.hh | 29 ++++++++++++++++ 7 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 Library/Processor/KTContext.cc create mode 100644 Library/Processor/KTContext.hh diff --git a/Library/Application/KTProcessorToolbox.cc b/Library/Application/KTProcessorToolbox.cc index 1623e2b8..933e27ea 100644 --- a/Library/Application/KTProcessorToolbox.cc +++ b/Library/Application/KTProcessorToolbox.cc @@ -7,6 +7,7 @@ #include "KTProcessorToolbox.hh" +#include "KTContext.hh" #include "KTLogger.hh" #include "KTPrimaryProcessor.hh" @@ -33,7 +34,8 @@ namespace Nymph KTConfigurable(name), fProcFactory(scarab::factory< KTProcessor, const std::string& >::get_instance()), fRunQueue(), - fProcMap() + fProcMap(), + fContext(std::make_shared< KTContext >()) { } @@ -85,6 +87,8 @@ namespace Nymph KTERROR(proclog, "Unable to create processor of type <" << procType << ">"); return false; } + // seed with shared context + newProc->SetContext(fContext); if (! AddProcessor(procName, newProc)) { diff --git a/Library/Application/KTProcessorToolbox.hh b/Library/Application/KTProcessorToolbox.hh index 555b2162..e65602fc 100644 --- a/Library/Application/KTProcessorToolbox.hh +++ b/Library/Application/KTProcessorToolbox.hh @@ -21,6 +21,7 @@ namespace Nymph { + class KTContext; class KTPrimaryProcessor; class KTProcessor; @@ -185,6 +186,13 @@ namespace Nymph RunQueue fRunQueue; + public: + KTContext& Context(); + const KTContext& Context() const; + + private: + std::shared_ptr< KTContext > fContext; + }; inline void KTProcessorToolbox::PopBackOfRunQueue() @@ -199,7 +207,15 @@ namespace Nymph return; } + inline KTContext& KTProcessorToolbox::Context() + { + return *fContext; + } + inline const KTContext& KTProcessorToolbox::Context() const + { + return *fContext; + } } /* namespace Nymph */ #endif /* KTPROCESSORTOOLBOX_HH_ */ diff --git a/Library/CMakeLists.txt b/Library/CMakeLists.txt index c7d0c0d5..a88501c1 100644 --- a/Library/CMakeLists.txt +++ b/Library/CMakeLists.txt @@ -29,6 +29,7 @@ set( NYMPH_HEADERFILES ${DATA_DIR}/KTCutStatus.hh ${DATA_DIR}/KTData.hh ${PROC_DIR}/KTConnection.hh + ${PROC_DIR}/KTContext.hh ${PROC_DIR}/KTPrimaryProcessor.hh ${PROC_DIR}/KTProcessor.hh ${PROC_DIR}/KTSignal.hh @@ -62,6 +63,7 @@ set( NYMPH_SOURCEFILES ${DATA_DIR}/KTCutFilter.cc ${DATA_DIR}/KTCutStatus.cc ${DATA_DIR}/KTData.cc + ${PROC_DIR}/KTContext.cc ${PROC_DIR}/KTPrimaryProcessor.cc ${PROC_DIR}/KTProcessor.cc ${PROC_DIR}/KTSignal.cc diff --git a/Library/Processor/KTContext.cc b/Library/Processor/KTContext.cc new file mode 100644 index 00000000..cada7abe --- /dev/null +++ b/Library/Processor/KTContext.cc @@ -0,0 +1,42 @@ +/* + * KTContext.cc + * + * Created on: Aug 7, 2024 + * Author: N.S. Oblath + */ + +#include "KTContext.hh" + +#include "KTLogger.hh" + + +namespace Nymph +{ + + KTLOGGER(proclog, "KTContext.hh"); + + KTContext::KTContext() : + fData() + {} + + KTContext::~KTContext() + {} + + scarab::param& KTContext::Get(const std::string& name) + { + return fData[name]; + } + + const scarab::param& KTContext::Get(const std::string& name) const + { + return fData[name]; + } + + void KTContext::Add(const std::string& name, const scarab::param& data) + { + fData.add(name, data); + return; + } + + +} /* namespace Nymph */ diff --git a/Library/Processor/KTContext.hh b/Library/Processor/KTContext.hh new file mode 100644 index 00000000..da6ad1ec --- /dev/null +++ b/Library/Processor/KTContext.hh @@ -0,0 +1,34 @@ +/** + @file KTContext.hh + @brief Contains KTContext + @details KTContext contains the run context that's available to all processors + @author: N. S. Oblath + @date: Aug 7, 2024 + */ + +#ifndef KTCONTEXT_HH_ +#define KTCONTEXT_HH_ + +#include "param.hh" + +namespace Nymph +{ + + class KTContext + { + public: + KTContext(); + virtual ~KTContext(); + + scarab::param& Get(const std::string& name); + const scarab::param& Get(const std::string& name) const; + + void Add(const std::string& name, const scarab::param& data); + + protected: + scarab::param_node fData; + }; + +} /* namespace Nymph */ + +#endif /* KTCONTEXT_HH_ */ diff --git a/Library/Processor/KTProcessor.cc b/Library/Processor/KTProcessor.cc index 72a717d6..3b4c3768 100644 --- a/Library/Processor/KTProcessor.cc +++ b/Library/Processor/KTProcessor.cc @@ -7,6 +7,7 @@ #include "KTProcessor.hh" +#include "KTContext.hh" //#include "KTLogger.hh" #include @@ -27,9 +28,9 @@ namespace Nymph KTProcessor::KTProcessor(const string& name) : KTConfigurable(name), fSignalMap(), - fSlotMap() - { - } + fSlotMap(), + fContext(std::make_shared< KTContext >()) + {} KTProcessor::~KTProcessor() { diff --git a/Library/Processor/KTProcessor.hh b/Library/Processor/KTProcessor.hh index 7aa8e6c2..71ac3e45 100644 --- a/Library/Processor/KTProcessor.hh +++ b/Library/Processor/KTProcessor.hh @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -31,6 +32,8 @@ namespace Nymph { KTLOGGER(processorlog, "KTProcessor.hh"); + class KTContext; + class ProcessorException : public std::logic_error { public: @@ -80,6 +83,16 @@ namespace Nymph SlotMap fSlotMap; + public: + + KTContext& Context(); + const KTContext& Context() const; + + void SetContext(const std::shared_ptr< KTContext > context); + + protected: + + std::shared_ptr< KTContext > fContext; }; @@ -134,6 +147,22 @@ namespace Nymph return; } + inline KTContext& KTProcessor::Context() + { + return *fContext; + } + + inline const KTContext& KTProcessor::Context() const + { + return *fContext; + } + + inline void KTProcessor::SetContext(std::shared_ptr< KTContext > context) + { + fContext = context; + return; + } + #define KT_REGISTER_PROCESSOR(proc_class, proc_name) \ static ::scarab::registrar< ::Nymph::KTProcessor, proc_class, const std::string& > sProc##proc_class##Registrar( proc_name ); From a4fbd4f35f718d1cc06d2ad9ac012aace3289ed4 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Fri, 9 Aug 2024 13:56:15 -0700 Subject: [PATCH 12/16] Register the test processors so we can access them from the Proc toolbox --- Executables/Validation/KTTestProcessor.cc | 10 +++++++--- Executables/Validation/KTTestProcessor.hh | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Executables/Validation/KTTestProcessor.cc b/Executables/Validation/KTTestProcessor.cc index ad14cdf0..36ef014f 100644 --- a/Executables/Validation/KTTestProcessor.cc +++ b/Executables/Validation/KTTestProcessor.cc @@ -13,7 +13,10 @@ namespace Nymph { KTLOGGER(testsiglog, "KTTestProcessor") - KTTestProcessorA::KTTestProcessorA() : + KT_REGISTER_PROCESSOR(KTTestProcessorA, "test-proc-a"); + + KTTestProcessorA::KTTestProcessorA(const std::string& name) : + KTProcessor(name), fTheSignal() { RegisterSignal("the_signal", &fTheSignal); @@ -35,9 +38,10 @@ namespace Nymph } + KT_REGISTER_PROCESSOR(KTTestProcessorB, "test-proc-b"); - - KTTestProcessorB::KTTestProcessorB() + KTTestProcessorB::KTTestProcessorB(const std::string& name) : + KTProcessor(name) { RegisterSlot("first_slot", this, &KTTestProcessorB::Slot1); RegisterSlot("second_slot", this, &KTTestProcessorB::Slot2); diff --git a/Executables/Validation/KTTestProcessor.hh b/Executables/Validation/KTTestProcessor.hh index 77560935..eb6df849 100644 --- a/Executables/Validation/KTTestProcessor.hh +++ b/Executables/Validation/KTTestProcessor.hh @@ -19,7 +19,7 @@ namespace Nymph typedef KTSignalConcept< void (int) >::signal TheSignal; public: - KTTestProcessorA(); + KTTestProcessorA(const std::string& name = "test-proc-a"); virtual ~KTTestProcessorA(); bool Configure(const scarab::param_node* node); @@ -34,7 +34,7 @@ namespace Nymph class KTTestProcessorB : public KTProcessor { public: - KTTestProcessorB(); + KTTestProcessorB(const std::string& name = "test-proc-b"); virtual ~KTTestProcessorB(); bool Configure(const scarab::param_node* node); From 927d6d98afc21be472682c336dddfff8b34beba1 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Fri, 9 Aug 2024 13:57:07 -0700 Subject: [PATCH 13/16] Fix proc toolbox so it shares its context in a location where it gets shared no matter how the processor is added to the toolbox --- Library/Application/KTProcessorToolbox.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Application/KTProcessorToolbox.cc b/Library/Application/KTProcessorToolbox.cc index 933e27ea..67f89a96 100644 --- a/Library/Application/KTProcessorToolbox.cc +++ b/Library/Application/KTProcessorToolbox.cc @@ -87,8 +87,6 @@ namespace Nymph KTERROR(proclog, "Unable to create processor of type <" << procType << ">"); return false; } - // seed with shared context - newProc->SetContext(fContext); if (! AddProcessor(procName, newProc)) { @@ -322,6 +320,9 @@ namespace Nymph ProcMapIt it = fProcMap.find(procName); if (it == fProcMap.end()) { + // share the context + proc->SetContext(fContext); + ProcessorInfo pInfo; pInfo.fProc = proc; fProcMap.insert(ProcMapValue(procName, pInfo)); From cec72823f5d5405a1152cf25059c369e6873539f Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Fri, 9 Aug 2024 13:57:20 -0700 Subject: [PATCH 14/16] Add a Has() function to KTContext --- Library/Processor/KTContext.cc | 5 +++++ Library/Processor/KTContext.hh | 2 ++ 2 files changed, 7 insertions(+) diff --git a/Library/Processor/KTContext.cc b/Library/Processor/KTContext.cc index cada7abe..b0b0cc93 100644 --- a/Library/Processor/KTContext.cc +++ b/Library/Processor/KTContext.cc @@ -22,6 +22,11 @@ namespace Nymph KTContext::~KTContext() {} + bool KTContext::Has(const std::string& name) const + { + return fData.has(name); + } + scarab::param& KTContext::Get(const std::string& name) { return fData[name]; diff --git a/Library/Processor/KTContext.hh b/Library/Processor/KTContext.hh index da6ad1ec..ab63f071 100644 --- a/Library/Processor/KTContext.hh +++ b/Library/Processor/KTContext.hh @@ -20,6 +20,8 @@ namespace Nymph KTContext(); virtual ~KTContext(); + bool Has(const std::string& name) const; + scarab::param& Get(const std::string& name); const scarab::param& Get(const std::string& name) const; From f6912c95a98c33a912b8ddf21e8d6a2b98db308d Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Fri, 9 Aug 2024 13:57:37 -0700 Subject: [PATCH 15/16] Add test executable TestContext.cc --- Executables/Validation/CMakeLists.txt | 1 + Executables/Validation/TestContext.cc | 55 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Executables/Validation/TestContext.cc diff --git a/Executables/Validation/CMakeLists.txt b/Executables/Validation/CMakeLists.txt index 5e5f9cf7..b04fab12 100644 --- a/Executables/Validation/CMakeLists.txt +++ b/Executables/Validation/CMakeLists.txt @@ -44,6 +44,7 @@ if (Nymph_ENABLE_TESTING) TestApplication TestApplyCut TestCacheDirectory + TestContext TestCut TestCutFilter TestLogger diff --git a/Executables/Validation/TestContext.cc b/Executables/Validation/TestContext.cc new file mode 100644 index 00000000..b8e9448d --- /dev/null +++ b/Executables/Validation/TestContext.cc @@ -0,0 +1,55 @@ +/* + * TestContext.cc + * + * Created on: Aug 9, 2024 + * Author: N.S. Oblath + * + * Usage: > ./TestContext + * + * Purpose: Test access to context from multiple processors + * + */ + +#include "KTTestProcessor.hh" + +#include "KTContext.hh" +#include "KTLogger.hh" +#include "KTProcessorToolbox.hh" + +using namespace Nymph; + +KTLOGGER(testlog, "TestContext"); + +int main() +{ + KTTestProcessorA procA; + KTTestProcessorB procB; + + KTINFO(testlog, "Contexts belonging to procA and procB should be independent\n&procA.Context() == &procB.Context(): " << (&procA.Context() == &procB.Context())); + + KTProcessorToolbox toolbox; + + if (! toolbox.AddProcessor("test-proc-a", "tpa")) + { + KTERROR(testlog, "Unable to create test proc A with the Processor Toolbox"); + return 1; + } + if (! toolbox.AddProcessor("test-proc-b", "tpb")) + { + KTERROR(testlog, "Unable to create test proc B with the Processor Toolbox"); + return 1; + } + + KTProcessor& procAtb = *toolbox.GetProcessor("tpa"); + KTProcessor& procBtb = *toolbox.GetProcessor("tpb"); + + KTINFO(testlog, "Contexts belonging to procAtb and procBtb should be identical\n&procAtb.Context() == &procBtb.Context(): " << (&procAtb.Context() == &procBtb.Context())); + + toolbox.Context().Add("test", scarab::param_value(5)); + KTINFO(testlog, "toolbox has context \"test\"? (expect \"1\") " << toolbox.Context().Has("test")); + KTINFO(testlog, "procAtb has context \"test\"? (expect \"1\") " << procAtb.Context().Has("test")); + KTINFO(testlog, "procBtb has context \"test\"? (expect \"1\") " << procBtb.Context().Has("test")); + KTINFO(testlog, "Values are all equal? (expect \"1 1\") " << (toolbox.Context().Get("test")().as_int() == procAtb.Context().Get("test")().as_int()) << " " << (toolbox.Context().Get("test")().as_int() == procBtb.Context().Get("test")().as_int())); + + return 0; +} From cab1fdc7239fbaf4f3ce6402779a1fa5bfd88549 Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Fri, 9 Aug 2024 14:15:21 -0700 Subject: [PATCH 16/16] Moved the characteristic of having context to a base class, and inherited KTProcessor and KTProcessorToolbox from it --- Library/Application/KTProcessorToolbox.cc | 5 ++-- Library/Application/KTProcessorToolbox.hh | 21 ++------------- Library/Processor/KTContext.cc | 7 +++++ Library/Processor/KTContext.hh | 32 +++++++++++++++++++++++ Library/Processor/KTProcessor.cc | 4 +-- Library/Processor/KTProcessor.hh | 30 ++------------------- 6 files changed, 47 insertions(+), 52 deletions(-) diff --git a/Library/Application/KTProcessorToolbox.cc b/Library/Application/KTProcessorToolbox.cc index 67f89a96..705a5e94 100644 --- a/Library/Application/KTProcessorToolbox.cc +++ b/Library/Application/KTProcessorToolbox.cc @@ -7,7 +7,6 @@ #include "KTProcessorToolbox.hh" -#include "KTContext.hh" #include "KTLogger.hh" #include "KTPrimaryProcessor.hh" @@ -32,10 +31,10 @@ namespace Nymph KTProcessorToolbox::KTProcessorToolbox(const std::string& name) : KTConfigurable(name), + KTHasContext(), fProcFactory(scarab::factory< KTProcessor, const std::string& >::get_instance()), fRunQueue(), - fProcMap(), - fContext(std::make_shared< KTContext >()) + fProcMap() { } diff --git a/Library/Application/KTProcessorToolbox.hh b/Library/Application/KTProcessorToolbox.hh index e65602fc..517d49cf 100644 --- a/Library/Application/KTProcessorToolbox.hh +++ b/Library/Application/KTProcessorToolbox.hh @@ -10,6 +10,7 @@ #define KTPROCESSORTOOLBOX_HH_ #include "KTConfigurable.hh" +#include "KTContext.hh" //#include "KTNOFactory.hh" #include "factory.hh" @@ -21,7 +22,6 @@ namespace Nymph { - class KTContext; class KTPrimaryProcessor; class KTProcessor; @@ -72,7 +72,7 @@ namespace Nymph */ - class KTProcessorToolbox : public KTConfigurable + class KTProcessorToolbox : public KTConfigurable, public KTHasContext { public: KTProcessorToolbox(const std::string& name = "processor-toolbox"); @@ -186,13 +186,6 @@ namespace Nymph RunQueue fRunQueue; - public: - KTContext& Context(); - const KTContext& Context() const; - - private: - std::shared_ptr< KTContext > fContext; - }; inline void KTProcessorToolbox::PopBackOfRunQueue() @@ -207,15 +200,5 @@ namespace Nymph return; } - inline KTContext& KTProcessorToolbox::Context() - { - return *fContext; - } - - inline const KTContext& KTProcessorToolbox::Context() const - { - return *fContext; - } - } /* namespace Nymph */ #endif /* KTPROCESSORTOOLBOX_HH_ */ diff --git a/Library/Processor/KTContext.cc b/Library/Processor/KTContext.cc index b0b0cc93..cd83d080 100644 --- a/Library/Processor/KTContext.cc +++ b/Library/Processor/KTContext.cc @@ -9,6 +9,7 @@ #include "KTLogger.hh" +#include namespace Nymph { @@ -44,4 +45,10 @@ namespace Nymph } + KTHasContext::KTHasContext() : + fContext(std::make_shared< KTContext >()) + {} + + KTHasContext::~KTHasContext() + {} } /* namespace Nymph */ diff --git a/Library/Processor/KTContext.hh b/Library/Processor/KTContext.hh index ab63f071..2d1ca311 100644 --- a/Library/Processor/KTContext.hh +++ b/Library/Processor/KTContext.hh @@ -31,6 +31,38 @@ namespace Nymph scarab::param_node fData; }; + class KTHasContext + { + public: + KTHasContext(); + virtual ~KTHasContext(); + + KTContext& Context(); + const KTContext& Context() const; + + void SetContext(const std::shared_ptr< KTContext > context); + + protected: + std::shared_ptr< KTContext > fContext; + + }; + + inline KTContext& KTHasContext::Context() + { + return *fContext; + } + + inline const KTContext& KTHasContext::Context() const + { + return *fContext; + } + + inline void KTHasContext::SetContext(std::shared_ptr< KTContext > context) + { + fContext = context; + return; + } + } /* namespace Nymph */ #endif /* KTCONTEXT_HH_ */ diff --git a/Library/Processor/KTProcessor.cc b/Library/Processor/KTProcessor.cc index 3b4c3768..66a6d868 100644 --- a/Library/Processor/KTProcessor.cc +++ b/Library/Processor/KTProcessor.cc @@ -27,9 +27,9 @@ namespace Nymph KTProcessor::KTProcessor(const string& name) : KTConfigurable(name), + KTHasContext(), fSignalMap(), - fSlotMap(), - fContext(std::make_shared< KTContext >()) + fSlotMap() {} KTProcessor::~KTProcessor() diff --git a/Library/Processor/KTProcessor.hh b/Library/Processor/KTProcessor.hh index 71ac3e45..0ae1b0cc 100644 --- a/Library/Processor/KTProcessor.hh +++ b/Library/Processor/KTProcessor.hh @@ -10,6 +10,7 @@ #define KTPROCESSOR_HH_ #include "KTConfigurable.hh" +#include "KTContext.hh" #include "KTConnection.hh" #include "KTLogger.hh" @@ -32,7 +33,6 @@ namespace Nymph { KTLOGGER(processorlog, "KTProcessor.hh"); - class KTContext; class ProcessorException : public std::logic_error { @@ -40,7 +40,7 @@ namespace Nymph ProcessorException(std::string const& why); }; - class KTProcessor : public KTConfigurable + class KTProcessor : public KTConfigurable, public KTHasContext { protected: typedef std::map< std::string, KTSignalWrapper* > SignalMap; @@ -83,16 +83,6 @@ namespace Nymph SlotMap fSlotMap; - public: - - KTContext& Context(); - const KTContext& Context() const; - - void SetContext(const std::shared_ptr< KTContext > context); - - protected: - - std::shared_ptr< KTContext > fContext; }; @@ -147,22 +137,6 @@ namespace Nymph return; } - inline KTContext& KTProcessor::Context() - { - return *fContext; - } - - inline const KTContext& KTProcessor::Context() const - { - return *fContext; - } - - inline void KTProcessor::SetContext(std::shared_ptr< KTContext > context) - { - fContext = context; - return; - } - #define KT_REGISTER_PROCESSOR(proc_class, proc_name) \ static ::scarab::registrar< ::Nymph::KTProcessor, proc_class, const std::string& > sProc##proc_class##Registrar( proc_name );