From a0a19ef15c905e526825518d984077ee16f8ab66 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Mon, 30 Sep 2024 13:05:13 -0400 Subject: [PATCH] Podio event source: Use new, exception-free Emit() callback --- src/services/io/podio/JEventSourcePODIO.cc | 19 ++++++++++--------- src/services/io/podio/JEventSourcePODIO.h | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/services/io/podio/JEventSourcePODIO.cc b/src/services/io/podio/JEventSourcePODIO.cc index 1d60140ff2..3950069918 100644 --- a/src/services/io/podio/JEventSourcePODIO.cc +++ b/src/services/io/podio/JEventSourcePODIO.cc @@ -69,6 +69,7 @@ struct InsertingVisitor { //------------------------------------------------------------------------------ JEventSourcePODIO::JEventSourcePODIO(std::string resource_name, JApplication* app) : JEventSource(resource_name, app) { SetTypeName(NAME_OF_THIS); // Provide JANA with class name + SetCallbackStyle(CallbackStyle::ExpertMode); // Use new, exception-free Emit() callback // Tell JANA that we want it to call the FinishEvent() method. // EnableFinishEvent(); @@ -185,7 +186,7 @@ void JEventSourcePODIO::Close() { /// /// \param event //------------------------------------------------------------------------------ -void JEventSourcePODIO::GetEvent(std::shared_ptr event) { +JEventSourcePODIO::Result JEventSourcePODIO::Emit(JEvent& event) { /// Calls to GetEvent are synchronized with each other, which means they can /// read and write state on the JEventSource without causing race conditions. @@ -194,10 +195,9 @@ void JEventSourcePODIO::GetEvent(std::shared_ptr event) { if( Nevents_read >= Nevents_in_file ) { if( m_run_forever ){ Nevents_read = 0; - }else{ - // m_reader.close(); - // TODO:: ROOTFrameReader does not appear to have a close() method. - throw RETURN_STATUS::kNO_MORE_EVENTS; + } + else{ + return Result::FailureFinished; } } @@ -208,19 +208,20 @@ void JEventSourcePODIO::GetEvent(std::shared_ptr event) { if (event_headers.size() != 1) { throw JException("Bad event headers: Entry %d contains %d items, but 1 expected.", Nevents_read, event_headers.size()); } - event->SetEventNumber(event_headers[0].getEventNumber()); - event->SetRunNumber(event_headers[0].getRunNumber()); + event.SetEventNumber(event_headers[0].getEventNumber()); + event.SetRunNumber(event_headers[0].getRunNumber()); // Insert contents odf frame into JFactories VisitPodioCollection visit; for (const std::string& coll_name : frame->getAvailableCollections()) { const podio::CollectionBase* collection = frame->get(coll_name); - InsertingVisitor visitor(*event, coll_name); + InsertingVisitor visitor(event, coll_name); visit(visitor, *collection); } - event->Insert(frame.release()); // Transfer ownership from unique_ptr to JFactoryT + event.Insert(frame.release()); // Transfer ownership from unique_ptr to JFactoryT Nevents_read += 1; + return Result::Success; } //------------------------------------------------------------------------------ diff --git a/src/services/io/podio/JEventSourcePODIO.h b/src/services/io/podio/JEventSourcePODIO.h index 21dc45c999..8e053c49a4 100644 --- a/src/services/io/podio/JEventSourcePODIO.h +++ b/src/services/io/podio/JEventSourcePODIO.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -25,7 +25,7 @@ class JEventSourcePODIO : public JEventSource { void Close() override; - void GetEvent(std::shared_ptr) override; + Result Emit(JEvent& event) override; static std::string GetDescription();