From 2cfa896ffdc2f8e49f5de1efbe37a086c33cec30 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Sat, 27 Apr 2024 18:43:34 -0400 Subject: [PATCH] Migrate JTestRoot to new event source API --- src/plugins/JTestRoot/JTestRoot.cc | 2 +- src/plugins/JTestRoot/JTestRootEventSource.cc | 13 ++++++++----- src/plugins/JTestRoot/JTestRootEventSource.h | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/plugins/JTestRoot/JTestRoot.cc b/src/plugins/JTestRoot/JTestRoot.cc index 9bf090f19..d60bfbfcd 100644 --- a/src/plugins/JTestRoot/JTestRoot.cc +++ b/src/plugins/JTestRoot/JTestRoot.cc @@ -19,7 +19,7 @@ void InitPlugin(JApplication* app) { InitJANAPlugin(app); LOG << "Loading JTestRoot" << LOG_END; - app->Add(new JTestRootEventSource("dummy_root_object_source", app)); + app->Add(new JTestRootEventSource); app->Add(new JTestRootProcessor); app->Add(new JFactoryGeneratorT); } diff --git a/src/plugins/JTestRoot/JTestRootEventSource.cc b/src/plugins/JTestRoot/JTestRootEventSource.cc index 15ce74c01..02760b6f5 100644 --- a/src/plugins/JTestRoot/JTestRootEventSource.cc +++ b/src/plugins/JTestRoot/JTestRootEventSource.cc @@ -15,11 +15,12 @@ #include #include -JTestRootEventSource::JTestRootEventSource(std::string resource_name, JApplication* app) : JEventSource(resource_name, app) { +JTestRootEventSource::JTestRootEventSource() { SetTypeName(NAME_OF_THIS); // Provide JANA with class name + SetCallbackStyle(CallbackStyle::ExpertMode); } -void JTestRootEventSource::GetEvent(std::shared_ptr event) { +JEventSource::Result JTestRootEventSource::Emit(JEvent& event) { /// Generate an event by inserting objects into "event". /// (n.b. a normal event source would read these from a file or stream) @@ -28,8 +29,8 @@ void JTestRootEventSource::GetEvent(std::shared_ptr event) { // Configure event and run numbers static size_t current_event_number = 1; - event->SetEventNumber(current_event_number++); - event->SetRunNumber(222); + event.SetEventNumber(current_event_number++); + event.SetRunNumber(222); // Generate hit objects. We use random numbers to give some variation // and make things look a little more realistic @@ -44,5 +45,7 @@ void JTestRootEventSource::GetEvent(std::shared_ptr event) { } // Add Hit objects to event - event->Insert(hits); + event.Insert(hits); + return Result::Success; } + diff --git a/src/plugins/JTestRoot/JTestRootEventSource.h b/src/plugins/JTestRoot/JTestRootEventSource.h index f2c6ea3df..1a41f3930 100644 --- a/src/plugins/JTestRoot/JTestRootEventSource.h +++ b/src/plugins/JTestRoot/JTestRootEventSource.h @@ -15,7 +15,7 @@ class JTestRootEventSource : public JEventSource { JTestRootEventSource(std::string resource_name, JApplication* app); virtual ~JTestRootEventSource() = default; - void GetEvent(std::shared_ptr) override; + Result Emit(JEvent& event) override; protected: std::default_random_engine generator;