From 30e414e44072102d226d943444ef917a6f28b30c Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Wed, 16 Oct 2024 12:19:42 -0400 Subject: [PATCH 1/8] All JComponents inject parameters and services correctly --- src/libraries/JANA/JEventSource.cc | 17 +++++++++++------ src/libraries/JANA/JEventUnfolder.h | 15 +++++---------- src/libraries/JANA/JFactory.cc | 16 +++++++++++----- src/libraries/JANA/JMultifactory.cc | 15 ++++++++++----- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/libraries/JANA/JEventSource.cc b/src/libraries/JANA/JEventSource.cc index e33d397a9..62c3377e0 100644 --- a/src/libraries/JANA/JEventSource.cc +++ b/src/libraries/JANA/JEventSource.cc @@ -1,14 +1,19 @@ #include void JEventSource::DoInit() { - if (m_status == Status::Uninitialized) { - CallWithJExceptionWrapper("JEventSource::Init", [&](){ Init();}); - m_status = Status::Initialized; - LOG_INFO(GetLogger()) << "Initialized JEventSource '" << GetTypeName() << "' ('" << GetResourceName() << "')" << LOG_END; + std::lock_guard lock(m_mutex); + if (m_status != Status::Uninitialized) { + throw JException("Attempted to initialize a JEventSource that is already initialized!"); } - else { - throw JException("Attempted to initialize a JEventSource that is not uninitialized!"); + for (auto* parameter : m_parameters) { + parameter->Configure(*(m_app->GetJParameterManager()), m_prefix); + } + for (auto* service : m_services) { + service->Fetch(m_app); } + CallWithJExceptionWrapper("JEventSource::Init", [&](){ Init(); }); + m_status = Status::Initialized; + LOG_INFO(GetLogger()) << "Initialized JEventSource '" << GetTypeName() << "' ('" << GetResourceName() << "')" << LOG_END; } void JEventSource::DoInitialize() { diff --git a/src/libraries/JANA/JEventUnfolder.h b/src/libraries/JANA/JEventUnfolder.h index b57fa8b06..bd67a69f6 100644 --- a/src/libraries/JANA/JEventUnfolder.h +++ b/src/libraries/JANA/JEventUnfolder.h @@ -61,23 +61,18 @@ class JEventUnfolder : public jana::components::JComponent, void DoInit() { std::lock_guard lock(m_mutex); + if (m_status != Status::Uninitialized) { + throw JException("JEventUnfolder: Attempting to initialize twice or from an invalid state"); + } // TODO: Obtain overrides of collection names from param manager - for (auto* parameter : m_parameters) { parameter->Configure(*(m_app->GetJParameterManager()), m_prefix); } for (auto* service : m_services) { service->Fetch(m_app); } - if (m_status == Status::Uninitialized) { - CallWithJExceptionWrapper("JEventUnfolder::Init", [&](){ - Init(); - }); - m_status = Status::Initialized; - } - else { - throw JException("JEventUnfolder: Attempting to initialize twice or from an invalid state"); - } + CallWithJExceptionWrapper("JEventUnfolder::Init", [&](){Init();}); + m_status = Status::Initialized; } void DoPreprocess(const JEvent& parent) { diff --git a/src/libraries/JANA/JFactory.cc b/src/libraries/JANA/JFactory.cc index aa98d7ebe..757c01ce6 100644 --- a/src/libraries/JANA/JFactory.cc +++ b/src/libraries/JANA/JFactory.cc @@ -18,8 +18,7 @@ void JFactory::Create(const std::shared_ptr& event) { } if (mStatus == Status::Uninitialized) { - CallWithJExceptionWrapper("JFactory::Init", [&](){ Init(); }); - mStatus = Status::Unprocessed; + DoInit(); } auto src = event->GetJEventSource(); @@ -66,10 +65,17 @@ void JFactory::Create(const std::shared_ptr& event) { } void JFactory::DoInit() { - if (mStatus == Status::Uninitialized) { - CallWithJExceptionWrapper("JFactory::Init", [&](){ Init(); }); - mStatus = Status::Unprocessed; + if (mStatus != Status::Uninitialized) { + throw JException("Attempted to initialize a JFactory that has already been initialized!"); + } + for (auto* parameter : m_parameters) { + parameter->Configure(*(m_app->GetJParameterManager()), m_prefix); + } + for (auto* service : m_services) { + service->Fetch(m_app); } + CallWithJExceptionWrapper("JFactory::Init", [&](){ Init(); }); + mStatus = Status::Unprocessed; } void JFactory::Summarize(JComponentSummary& summary) const { diff --git a/src/libraries/JANA/JMultifactory.cc b/src/libraries/JANA/JMultifactory.cc index e6da04fc1..a9783f9ad 100644 --- a/src/libraries/JANA/JMultifactory.cc +++ b/src/libraries/JANA/JMultifactory.cc @@ -66,12 +66,17 @@ JFactorySet* JMultifactory::GetHelpers() { void JMultifactory::DoInit() { std::lock_guard lock(m_mutex); - if (m_status == Status::Uninitialized) { - CallWithJExceptionWrapper("JMultifactory::Init", [&](){ - Init(); - }); - m_status = Status::Initialized; + if (m_status != Status::Uninitialized) { + throw JException("Attempted to initialzie a JMultifactory that has already been initialized!"); + } + CallWithJExceptionWrapper("JMultifactory::Init", [&](){ Init(); }); + for (auto* parameter : m_parameters) { + parameter->Configure(*(m_app->GetJParameterManager()), m_prefix); + } + for (auto* service : m_services) { + service->Fetch(m_app); } + m_status = Status::Initialized; } void JMultifactory::Summarize(JComponentSummary& summary) const { From 1bebfa9bc5dc8cb6190b76f6a6855fe5a93cf6cf Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Wed, 16 Oct 2024 12:46:55 -0400 Subject: [PATCH 2/8] JTest uses injected parameters --- src/plugins/JTest/JTestCalibrationService.h | 7 ++++- src/plugins/JTest/JTestDataObjects.h | 6 ++++ src/plugins/JTest/JTestDisentangler.h | 33 ++++++++++----------- src/plugins/JTest/JTestParser.h | 23 +++++--------- src/plugins/JTest/JTestPlotter.h | 29 ++++++------------ src/plugins/JTest/JTestTracker.h | 31 +++++++------------ 6 files changed, 56 insertions(+), 73 deletions(-) diff --git a/src/plugins/JTest/JTestCalibrationService.h b/src/plugins/JTest/JTestCalibrationService.h index 76dde7251..8c70c3fb2 100644 --- a/src/plugins/JTest/JTestCalibrationService.h +++ b/src/plugins/JTest/JTestCalibrationService.h @@ -5,9 +5,14 @@ #ifndef JANA2_JTESTCALIBRATIONSERVICE_H #define JANA2_JTESTCALIBRATIONSERVICE_H +#include + struct JTestCalibrationService: JService { + + Parameter m_calibration_value{this, "calibration_value", 7.0, "Dummy calibration value"}; + double getCalibration() { - return 7.0; + return *m_calibration_value; } }; diff --git a/src/plugins/JTest/JTestDataObjects.h b/src/plugins/JTest/JTestDataObjects.h index 0bcca09b6..5cc4a3ab6 100644 --- a/src/plugins/JTest/JTestDataObjects.h +++ b/src/plugins/JTest/JTestDataObjects.h @@ -45,4 +45,10 @@ struct JTestHistogramData : public JObject { JOBJECT_PUBLIC(JTestHistogramData) }; +struct JTestTrackAuxilliaryData : public JObject { + int something = 1; + float something2 = 2; + JOBJECT_PUBLIC(JTestTrackAuxilliaryData) +}; + #endif //JANA2_JTESTEVENTCONTEXTS_H diff --git a/src/plugins/JTest/JTestDisentangler.h b/src/plugins/JTest/JTestDisentangler.h index 155245cea..9885c0f88 100644 --- a/src/plugins/JTest/JTestDisentangler.h +++ b/src/plugins/JTest/JTestDisentangler.h @@ -15,44 +15,43 @@ class JTestDisentangler : public JFactoryT { - size_t m_cputime_ms = 20; - size_t m_write_bytes = 500000; - double m_cputime_spread = 0.25; - double m_write_spread = 0.25; - JBenchUtils m_bench_utils = JBenchUtils(); + Parameter m_cputime_ms {this, "cputime_ms", 20, "Time spent during disentangling" }; + Parameter m_write_bytes {this, "bytes", 500000, "Bytes written during disentangling"}; + Parameter m_cputime_spread {this, "cputime_spread", 0.25, "Spread of time spent during disentangling"}; + Parameter m_write_spread {this, "bytes_spread", 0.25, "Spread of bytes written during disentangling"}; std::shared_ptr m_calibration_service; + JBenchUtils m_bench_utils; + public: + JTestDisentangler() { + SetPrefix("disentangler"); + SetTypeName(NAME_OF_THIS); + } + void Init() override { - auto app = GetApplication(); - assert (app != nullptr); - app->SetDefaultParameter("jtest:disentangler_ms", m_cputime_ms, "Time spent during disentangling"); - app->SetDefaultParameter("jtest:disentangler_spread", m_cputime_spread, "Spread of time spent during disentangling"); - app->SetDefaultParameter("jtest:disentangler_bytes", m_write_bytes, "Bytes written during disentangling"); - app->SetDefaultParameter("jtest:disentangler_bytes_spread", m_write_spread, "Spread of bytes written during disentangling"); - - // Retrieve calibration service from JApp - m_calibration_service = app->GetService(); + m_calibration_service = GetApplication()->GetService(); } void Process(const std::shared_ptr &aEvent) override { m_bench_utils.set_seed(aEvent->GetEventNumber(), NAME_OF_THIS); + // Read (large) entangled event data auto eed = aEvent->GetSingle(); m_bench_utils.read_memory(*eed->buffer); // Read calibration data - m_calibration_service->getCalibration(); + auto calib = m_calibration_service->getCalibration(); // Do a little bit of computation - m_bench_utils.consume_cpu_ms(m_cputime_ms, m_cputime_spread); + m_bench_utils.consume_cpu_ms(*m_cputime_ms + calib, *m_cputime_spread); // Write (large) event data auto ed = new JTestEventData; - m_bench_utils.write_memory(ed->buffer, m_write_bytes, m_write_spread); + m_bench_utils.write_memory(ed->buffer, *m_write_bytes, *m_write_spread); Insert(ed); } }; diff --git a/src/plugins/JTest/JTestParser.h b/src/plugins/JTest/JTestParser.h index 51bf6bd43..1c72a11d8 100644 --- a/src/plugins/JTest/JTestParser.h +++ b/src/plugins/JTest/JTestParser.h @@ -14,16 +14,16 @@ #include - #include "JTestDataObjects.h" class JTestParser : public JEventSource { - size_t m_cputime_ms = 0; - size_t m_write_bytes = 2000000; - double m_cputime_spread = 0.25; - double m_write_spread = 0.25; + Parameter m_cputime_ms {this, "cputime_ms", 0, "Time spent during parsing" }; + Parameter m_write_bytes {this, "bytes", 2000000, "Bytes written during parsing"}; + Parameter m_cputime_spread {this, "cputime_spread", 0.25, "Spread of time spent during parsing"}; + Parameter m_write_spread {this, "bytes_spread", 0.25, "Spread of bytes written during parsing"}; + JBenchUtils m_bench_utils = JBenchUtils(); std::shared_ptr> m_latest_entangled_buffer; @@ -32,6 +32,7 @@ class JTestParser : public JEventSource { public: JTestParser() { + SetPrefix("parser"); SetTypeName(NAME_OF_THIS); SetCallbackStyle(CallbackStyle::ExpertMode); } @@ -40,14 +41,6 @@ class JTestParser : public JEventSource { return "JTest Fake Event Source"; } - void Init() override { - auto app = GetApplication(); - app->SetDefaultParameter("jtest:parser_ms", m_cputime_ms, "Time spent during parsing"); - app->SetDefaultParameter("jtest:parser_spread", m_cputime_spread, "Spread of time spent during parsing"); - app->SetDefaultParameter("jtest:parser_bytes", m_write_bytes, "Bytes written during parsing"); - app->SetDefaultParameter("jtest:parser_bytes_spread", m_write_spread, "Spread of bytes written during parsing"); - } - void Open() override { } @@ -62,11 +55,11 @@ class JTestParser : public JEventSource { if ((prev_m_events_generated % 40) == 0) { // "Read" new entangled event every 40 events m_latest_entangled_buffer = std::shared_ptr>(new std::vector); - m_bench_utils.write_memory(*m_latest_entangled_buffer, m_write_bytes, m_write_spread); + m_bench_utils.write_memory(*m_latest_entangled_buffer, *m_write_bytes, *m_write_spread); } // Spin the CPU - m_bench_utils.consume_cpu_ms(m_cputime_ms, m_cputime_spread); + m_bench_utils.consume_cpu_ms(*m_cputime_ms, *m_cputime_spread); // Emit a shared pointer to the entangled event buffer auto eec = new JTestEntangledEventData; diff --git a/src/plugins/JTest/JTestPlotter.h b/src/plugins/JTest/JTestPlotter.h index a37928b9d..0a118953d 100644 --- a/src/plugins/JTest/JTestPlotter.h +++ b/src/plugins/JTest/JTestPlotter.h @@ -5,36 +5,25 @@ #ifndef JTestEventProcessor_h #define JTestEventProcessor_h -#include #include #include -#include "JTestTracker.h" -#include +#include "JTestDataObjects.h" class JTestPlotter : public JEventProcessor { - size_t m_cputime_ms = 0; - size_t m_write_bytes = 1000; - double m_cputime_spread = 0.25; - double m_write_spread = 0.25; + Parameter m_cputime_ms {this, "cputime_ms", 0, "Time spent during plotting" }; + Parameter m_write_bytes {this, "bytes", 1000, "Bytes written during plotting"}; + Parameter m_cputime_spread {this, "cputime_spread", 0.25, "Spread of time spent during plotting"}; + Parameter m_write_spread {this, "bytes_spread", 0.25, "Spread of bytes written during plotting"}; JBenchUtils m_bench_utils = JBenchUtils(); - std::mutex m_mutex; public: JTestPlotter() { - SetPrefix("jtest:plotter"); + SetPrefix("plotter"); SetTypeName(NAME_OF_THIS); } - void Init() override { - auto app = GetApplication(); - app->SetDefaultParameter("jtest:plotter_ms", m_cputime_ms, "Time spent during plotting"); - app->SetDefaultParameter("jtest:plotter_spread", m_cputime_spread, "Spread of time spent during plotting"); - app->SetDefaultParameter("jtest:plotter_bytes", m_write_bytes, "Bytes written during plotting"); - app->SetDefaultParameter("jtest:plotter_bytes_spread", m_write_spread, "Spread of bytes written during plotting"); - } - void Process(const std::shared_ptr& event) override { m_bench_utils.set_seed(event->GetEventNumber(), typeid(*this).name()); @@ -43,17 +32,17 @@ class JTestPlotter : public JEventProcessor { m_bench_utils.read_memory(td->buffer); // Read the extra data objects inserted by JTestTracker - event->Get(); + auto tad = event->Get(); // Everything that happens after here is in a critical section std::lock_guard lock(m_mutex); // Consume CPU - m_bench_utils.consume_cpu_ms(m_cputime_ms, m_cputime_spread); + m_bench_utils.consume_cpu_ms(*m_cputime_ms + tad.at(0)->something, *m_cputime_spread); // Write the histogram data auto hd = new JTestHistogramData; - m_bench_utils.write_memory(hd->buffer, m_write_bytes, m_write_spread); + m_bench_utils.write_memory(hd->buffer, *m_write_bytes, *m_write_spread); event->Insert(hd); } diff --git a/src/plugins/JTest/JTestTracker.h b/src/plugins/JTest/JTestTracker.h index 3438d8fdb..29967f1d0 100644 --- a/src/plugins/JTest/JTestTracker.h +++ b/src/plugins/JTest/JTestTracker.h @@ -13,26 +13,17 @@ class JTestTracker : public JFactoryT { - size_t m_cputime_ms = 200; - size_t m_write_bytes = 1000; - double m_cputime_spread = 0.25; - double m_write_spread = 0.25; - JBenchUtils m_bench_utils = JBenchUtils(); + Parameter m_cputime_ms {this, "cputime_ms", 200, "Time spent during tracking" }; + Parameter m_write_bytes {this, "bytes", 1000, "Bytes written during tracking"}; + Parameter m_cputime_spread {this, "cputime_spread", 0.25, "Spread of time spent during tracking"}; + Parameter m_write_spread {this, "bytes_spread", 0.25, "Spread of bytes written during tracking"}; -public: - - struct JTestTrackAuxilliaryData{ - int something = 1; - float something2 = 2; - }; + JBenchUtils m_bench_utils; - void Init() override { - - auto app = GetApplication(); - app->SetDefaultParameter("jtest:tracker_ms", m_cputime_ms, "Time spent during tracking"); - app->SetDefaultParameter("jtest:tracker_spread", m_cputime_spread, "Spread of time spent during tracking"); - app->SetDefaultParameter("jtest:tracker_bytes", m_write_bytes, "Bytes written during tracking"); - app->SetDefaultParameter("jtest:tracker_bytes_spread", m_write_spread, "Spread of bytes written during tracking"); +public: + JTestTracker() { + SetPrefix("tracker"); + SetTypeName(NAME_OF_THIS); } void Process(const std::shared_ptr &aEvent) override { @@ -43,11 +34,11 @@ class JTestTracker : public JFactoryT { m_bench_utils.read_memory(ed->buffer); // Do lots of computation - m_bench_utils.consume_cpu_ms(m_cputime_ms, m_cputime_spread); + m_bench_utils.consume_cpu_ms(*m_cputime_ms, *m_cputime_spread); // Write (small) track data auto td = new JTestTrackData; - m_bench_utils.write_memory(td->buffer, m_write_bytes, m_write_spread); + m_bench_utils.write_memory(td->buffer, *m_write_bytes, *m_write_spread); Insert(td); // Insert some additional objects From 8a3f4d9586c23e7201059bb32190175e82cb7dc8 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Wed, 16 Oct 2024 12:49:10 -0400 Subject: [PATCH 3/8] JHasInputs::Input provides operator*, operator-> These make it just a little bit more syntactically convenient --- src/libraries/JANA/Components/JHasInputs.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libraries/JANA/Components/JHasInputs.h b/src/libraries/JANA/Components/JHasInputs.h index ed0836abd..46ed8d360 100644 --- a/src/libraries/JANA/Components/JHasInputs.h +++ b/src/libraries/JANA/Components/JHasInputs.h @@ -96,6 +96,8 @@ struct JHasInputs { } const std::vector& operator()() { return m_data; } + const std::vector& operator*() { return m_data; } + const std::vector* operator->() { return &m_data; } private: @@ -146,6 +148,12 @@ struct JHasInputs { const typename PodioT::collection_type* operator()() { return m_data; } + const typename PodioT::collection_type& operator*() { + return *m_data; + } + const typename PodioT::collection_type* operator->() { + return m_data; + } void GetCollection(const JEvent& event) { auto& level = this->levels[0]; From 85b45cab45b478f5b3a24ebc6c74eb58522e1f26 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Wed, 16 Oct 2024 20:48:19 -0400 Subject: [PATCH 4/8] JTest uses injected services --- src/plugins/JTest/JTestDisentangler.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/plugins/JTest/JTestDisentangler.h b/src/plugins/JTest/JTestDisentangler.h index 9885c0f88..007d3976c 100644 --- a/src/plugins/JTest/JTestDisentangler.h +++ b/src/plugins/JTest/JTestDisentangler.h @@ -20,7 +20,7 @@ class JTestDisentangler : public JFactoryT { Parameter m_cputime_spread {this, "cputime_spread", 0.25, "Spread of time spent during disentangling"}; Parameter m_write_spread {this, "bytes_spread", 0.25, "Spread of bytes written during disentangling"}; - std::shared_ptr m_calibration_service; + Service m_calibration_service {this}; JBenchUtils m_bench_utils; @@ -31,10 +31,6 @@ class JTestDisentangler : public JFactoryT { SetTypeName(NAME_OF_THIS); } - void Init() override { - m_calibration_service = GetApplication()->GetService(); - } - void Process(const std::shared_ptr &aEvent) override { m_bench_utils.set_seed(aEvent->GetEventNumber(), NAME_OF_THIS); From a9df8862514ffa24d416f84cbb329524b8325e9b Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Wed, 16 Oct 2024 14:32:48 -0400 Subject: [PATCH 5/8] Move JTestPlotter track reading into critical section This is a more realistic scenario, plus it gives us an apples-to-apples comparison with CallbackStyle::ExpertMode --- src/plugins/JTest/JTestPlotter.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/JTest/JTestPlotter.h b/src/plugins/JTest/JTestPlotter.h index 0a118953d..b13772b53 100644 --- a/src/plugins/JTest/JTestPlotter.h +++ b/src/plugins/JTest/JTestPlotter.h @@ -27,16 +27,19 @@ class JTestPlotter : public JEventProcessor { void Process(const std::shared_ptr& event) override { m_bench_utils.set_seed(event->GetEventNumber(), typeid(*this).name()); - // Read the track data + + // Produce and acquire the track data auto td = event->GetSingle(); - m_bench_utils.read_memory(td->buffer); - - // Read the extra data objects inserted by JTestTracker + + // Produce and acquire the track aux data auto tad = event->Get(); // Everything that happens after here is in a critical section std::lock_guard lock(m_mutex); + // Read the track data + m_bench_utils.read_memory(td->buffer); + // Consume CPU m_bench_utils.consume_cpu_ms(*m_cputime_ms + tad.at(0)->something, *m_cputime_spread); From a1cbefcd95f3e0d131acdd94a953a6d82fd65ca4 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Wed, 16 Oct 2024 12:54:36 -0400 Subject: [PATCH 6/8] JTest uses Expert-mode JEventProcessor --- src/libraries/JANA/Components/JHasInputs.h | 5 +++++ src/plugins/JTest/JTestPlotter.h | 26 +++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/libraries/JANA/Components/JHasInputs.h b/src/libraries/JANA/Components/JHasInputs.h index 46ed8d360..3fb5e5a4f 100644 --- a/src/libraries/JANA/Components/JHasInputs.h +++ b/src/libraries/JANA/Components/JHasInputs.h @@ -87,6 +87,9 @@ struct JHasInputs { Input(JHasInputs* owner) { owner->RegisterInput(this); this->type_name = JTypeInfo::demangle(); + this->names.push_back(""); + // For non-PODIO inputs, these are technically tags for now, not names + this->levels.push_back(JEventLevel::None); } Input(JHasInputs* owner, const InputOptions& options) { @@ -137,6 +140,8 @@ struct JHasInputs { PodioInput(JHasInputs* owner) { owner->RegisterInput(this); this->type_name = JTypeInfo::demangle(); + this->names.push_back(this->type_name); + this->levels.push_back(JEventLevel::None); } PodioInput(JHasInputs* owner, const InputOptions& options) { diff --git a/src/plugins/JTest/JTestPlotter.h b/src/plugins/JTest/JTestPlotter.h index b13772b53..15a013fff 100644 --- a/src/plugins/JTest/JTestPlotter.h +++ b/src/plugins/JTest/JTestPlotter.h @@ -15,38 +15,34 @@ class JTestPlotter : public JEventProcessor { Parameter m_write_bytes {this, "bytes", 1000, "Bytes written during plotting"}; Parameter m_cputime_spread {this, "cputime_spread", 0.25, "Spread of time spent during plotting"}; Parameter m_write_spread {this, "bytes_spread", 0.25, "Spread of bytes written during plotting"}; - JBenchUtils m_bench_utils = JBenchUtils(); + + Input m_track_data {this}; + Input m_track_aux_data {this}; + + JBenchUtils m_bench_utils; public: JTestPlotter() { SetPrefix("plotter"); SetTypeName(NAME_OF_THIS); + SetCallbackStyle(CallbackStyle::ExpertMode); } - void Process(const std::shared_ptr& event) override { - - m_bench_utils.set_seed(event->GetEventNumber(), typeid(*this).name()); - - // Produce and acquire the track data - auto td = event->GetSingle(); - - // Produce and acquire the track aux data - auto tad = event->Get(); + void Process(const JEvent& event) override { - // Everything that happens after here is in a critical section - std::lock_guard lock(m_mutex); + m_bench_utils.set_seed(event.GetEventNumber(), typeid(*this).name()); // Read the track data - m_bench_utils.read_memory(td->buffer); + m_bench_utils.read_memory(m_track_data->at(0)->buffer); // Consume CPU - m_bench_utils.consume_cpu_ms(*m_cputime_ms + tad.at(0)->something, *m_cputime_spread); + m_bench_utils.consume_cpu_ms(*m_cputime_ms + m_track_aux_data->at(0)->something, *m_cputime_spread); // Write the histogram data auto hd = new JTestHistogramData; m_bench_utils.write_memory(hd->buffer, *m_write_bytes, *m_write_spread); - event->Insert(hd); + event.Insert(hd); } }; From ba2aa633d266658c31fb4f5aee15202aca3330d1 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Wed, 16 Oct 2024 15:52:22 -0400 Subject: [PATCH 7/8] Improve performance of data access via Input --- src/libraries/JANA/Components/JHasInputs.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libraries/JANA/Components/JHasInputs.h b/src/libraries/JANA/Components/JHasInputs.h index 3fb5e5a4f..c6c644cfa 100644 --- a/src/libraries/JANA/Components/JHasInputs.h +++ b/src/libraries/JANA/Components/JHasInputs.h @@ -108,23 +108,24 @@ struct JHasInputs { void GetCollection(const JEvent& event) { auto& level = this->levels[0]; + m_data.clear(); if (level == event.GetLevel() || level == JEventLevel::None) { - m_data = event.Get(this->names[0], !this->is_optional); + event.Get(m_data, this->names[0], !this->is_optional); } else { if (this->is_optional && !event.HasParent(level)) return; - m_data = event.GetParent(level).template Get(this->names[0], !this->is_optional); + event.GetParent(level).template Get(m_data, this->names[0], !this->is_optional); } } void PrefetchCollection(const JEvent& event) { auto& level = this->levels[0]; auto& name = this->names[0]; if (level == event.GetLevel() || level == JEventLevel::None) { - event.Get(name, !this->is_optional); + event.GetFactory(name, !this->is_optional)->Create(event.shared_from_this()); } else { if (this->is_optional && !event.HasParent(level)) return; - event.GetParent(level).template Get(name, !this->is_optional); + event.GetParent(level).template GetFactory(name, !this->is_optional)->Create(event.shared_from_this()); } } }; From 085f24544456de3f77c156b3ff09662f428b599b Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Thu, 17 Oct 2024 16:25:39 -0400 Subject: [PATCH 8/8] Fix JTest parameter prefixes --- docs/howto/other-howtos.md | 32 +++++++++++++-------------- src/plugins/JTest/JTestDisentangler.h | 2 +- src/plugins/JTest/JTestParser.h | 2 +- src/plugins/JTest/JTestPlotter.h | 2 +- src/plugins/JTest/JTestTracker.h | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/howto/other-howtos.md b/docs/howto/other-howtos.md index f6bfc8ec6..5da2862a8 100644 --- a/docs/howto/other-howtos.md +++ b/docs/howto/other-howtos.md @@ -89,22 +89,22 @@ The `JTest` plugin lets you test JANA's performance for different workloads. It | Name | Type | Default | Description | |:-----|:-----|:------------|:--------| -jtest:parser_ms | int | 0 | Time spent during parsing -jtest:parser_spread | int | 0.25 | Spread of time spent during parsing -jtest:parser_bytes | int | 2000000 | Bytes written during parsing -jtest:parser_bytes_spread | double | 0.25 | Spread of bytes written during parsing -jtest:disentangler_ms | int | 20 | Time spent during disentangling -jtest:disentangler_spread | double | 0.25 | Spread of time spent during disentangling -jtest:disentangler_bytes | int | 500000 | Bytes written during disentangling -jtest:disentangler_bytes_spread | double | 0.25 | Spread of bytes written during disentangling -jtest:tracker_ms | int | 200 | Time spent during tracking -jtest:tracker_spread | double | 0.25 | Spread of time spent during tracking -jtest:tracker_bytes | int | 1000 | Bytes written during tracking -jtest:tracker_bytes_spread | double | 0.25 | Spread of bytes written during tracking -jtest:plotter_ms | int | 0 | Time spent during plotting -jtest:plotter_spread | double | 0.25 | Spread of time spent during plotting -jtest:plotter_bytes | int | 1000 | Bytes written during plotting -jtest:plotter_bytes_spread | double | 0.25 | Spread of bytes written during plotting +jtest:parser:cputime_ms | int | 0 | Time spent during parsing +jtest:parser:cputime_spread | int | 0.25 | Spread of time spent during parsing +jtest:parser:bytes | int | 2000000 | Bytes written during parsing +jtest:parser:bytes_spread | double | 0.25 | Spread of bytes written during parsing +jtest:disentangler:cputime_ms | int | 20 | Time spent during disentangling +jtest:disentangler:cputime_spread | double | 0.25 | Spread of time spent during disentangling +jtest:disentangler:bytes | int | 500000 | Bytes written during disentangling +jtest:disentangler:bytes_spread | double | 0.25 | Spread of bytes written during disentangling +jtest:tracker:cputime_ms | int | 200 | Time spent during tracking +jtest:tracker:cputime_spread | double | 0.25 | Spread of time spent during tracking +jtest:tracker:bytes | int | 1000 | Bytes written during tracking +jtest:tracker:bytes_spread | double | 0.25 | Spread of bytes written during tracking +jtest:plotter:cputime_ms | int | 0 | Time spent during plotting +jtest:plotter:cputime_spread | double | 0.25 | Spread of time spent during plotting +jtest:plotter:bytes | int | 1000 | Bytes written during plotting +jtest:plotter:bytes_spread | double | 0.25 | Spread of bytes written during plotting diff --git a/src/plugins/JTest/JTestDisentangler.h b/src/plugins/JTest/JTestDisentangler.h index 007d3976c..908f99a64 100644 --- a/src/plugins/JTest/JTestDisentangler.h +++ b/src/plugins/JTest/JTestDisentangler.h @@ -27,7 +27,7 @@ class JTestDisentangler : public JFactoryT { public: JTestDisentangler() { - SetPrefix("disentangler"); + SetPrefix("jtest:disentangler"); SetTypeName(NAME_OF_THIS); } diff --git a/src/plugins/JTest/JTestParser.h b/src/plugins/JTest/JTestParser.h index 1c72a11d8..48855b7ef 100644 --- a/src/plugins/JTest/JTestParser.h +++ b/src/plugins/JTest/JTestParser.h @@ -32,7 +32,7 @@ class JTestParser : public JEventSource { public: JTestParser() { - SetPrefix("parser"); + SetPrefix("jtest:parser"); SetTypeName(NAME_OF_THIS); SetCallbackStyle(CallbackStyle::ExpertMode); } diff --git a/src/plugins/JTest/JTestPlotter.h b/src/plugins/JTest/JTestPlotter.h index 15a013fff..88f0ed929 100644 --- a/src/plugins/JTest/JTestPlotter.h +++ b/src/plugins/JTest/JTestPlotter.h @@ -24,7 +24,7 @@ class JTestPlotter : public JEventProcessor { public: JTestPlotter() { - SetPrefix("plotter"); + SetPrefix("jtest:plotter"); SetTypeName(NAME_OF_THIS); SetCallbackStyle(CallbackStyle::ExpertMode); } diff --git a/src/plugins/JTest/JTestTracker.h b/src/plugins/JTest/JTestTracker.h index 29967f1d0..98494024b 100644 --- a/src/plugins/JTest/JTestTracker.h +++ b/src/plugins/JTest/JTestTracker.h @@ -22,7 +22,7 @@ class JTestTracker : public JFactoryT { public: JTestTracker() { - SetPrefix("tracker"); + SetPrefix("jtest:tracker"); SetTypeName(NAME_OF_THIS); }