From 8384afe1824f676257f8cd848923335770818511 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Mon, 30 Sep 2024 13:05:13 -0400 Subject: [PATCH 1/3] Podio event source: Use new, exception-free Emit() callback --- src/services/io/podio/JEventSourcePODIO.cc | 19 ++++++++++--------- src/services/io/podio/JEventSourcePODIO.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/services/io/podio/JEventSourcePODIO.cc b/src/services/io/podio/JEventSourcePODIO.cc index d7260b768..781c8e8a2 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:: ROOTReader 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 ba7c45a94..fd88575eb 100644 --- a/src/services/io/podio/JEventSourcePODIO.h +++ b/src/services/io/podio/JEventSourcePODIO.h @@ -30,7 +30,7 @@ class JEventSourcePODIO : public JEventSource { void Close() override; - void GetEvent(std::shared_ptr) override; + Result Emit(JEvent& event) override; static std::string GetDescription(); From c894cc252f88cd230e08f99fb34d29fb0b4ed994 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Wed, 20 Nov 2024 16:41:18 -0500 Subject: [PATCH 2/3] propagate JANA version to CPP, like we do for Acts --- cmake/jana_plugin.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmake/jana_plugin.cmake b/cmake/jana_plugin.cmake index b2616f916..7a10eb253 100644 --- a/cmake/jana_plugin.cmake +++ b/cmake/jana_plugin.cmake @@ -57,6 +57,11 @@ macro(plugin_add _name) PROPERTIES PREFIX "" OUTPUT_NAME "${_name}" SUFFIX ".so") + target_compile_definitions( + ${PLUGIN_NAME}_plugin + PRIVATE "JANA_VERSION_MAJOR=${JANA_VERSION_MAJOR}" + "JANA_VERSION_MINOR=${JANA_VERSION_MINOR}" + "JANA_VERSION_PATCH=${JANA_VERSION_PATCH}") target_link_libraries(${_name}_plugin ${JANA_LIB} podio::podio podio::podioRootIO spdlog::spdlog fmt::fmt) target_link_libraries(${_name}_plugin Microsoft.GSL::GSL) @@ -82,6 +87,11 @@ macro(plugin_add _name) PROPERTIES PREFIX "lib" OUTPUT_NAME "${_name}" SUFFIX ${suffix}) + target_compile_definitions( + ${PLUGIN_NAME}_library + PRIVATE "JANA_VERSION_MAJOR=${JANA_VERSION_MAJOR}" + "JANA_VERSION_MINOR=${JANA_VERSION_MINOR}" + "JANA_VERSION_PATCH=${JANA_VERSION_PATCH}") target_include_directories( ${_name}_library From 5773c2e09ac66454c1bac8c70793f80a8704770a Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Wed, 20 Nov 2024 16:55:18 -0500 Subject: [PATCH 3/3] support previous JANA2 versions --- src/services/io/podio/JEventSourcePODIO.cc | 16 ++++++++++++++-- src/services/io/podio/JEventSourcePODIO.h | 10 ++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/services/io/podio/JEventSourcePODIO.cc b/src/services/io/podio/JEventSourcePODIO.cc index 781c8e8a2..faf3f4ba3 100644 --- a/src/services/io/podio/JEventSourcePODIO.cc +++ b/src/services/io/podio/JEventSourcePODIO.cc @@ -69,7 +69,9 @@ struct InsertingVisitor { //------------------------------------------------------------------------------ JEventSourcePODIO::JEventSourcePODIO(std::string resource_name, JApplication* app) : JEventSource(resource_name, app) { SetTypeName(NAME_OF_THIS); // Provide JANA with class name +#if JANA_NEW_CALLBACK_STYLE SetCallbackStyle(CallbackStyle::ExpertMode); // Use new, exception-free Emit() callback +#endif // Tell JANA that we want it to call the FinishEvent() method. // EnableFinishEvent(); @@ -186,7 +188,12 @@ void JEventSourcePODIO::Close() { /// /// \param event //------------------------------------------------------------------------------ +#if JANA_NEW_CALLBACK_STYLE JEventSourcePODIO::Result JEventSourcePODIO::Emit(JEvent& event) { +#else +void JEventSourcePODIO::GetEvent(std::shared_ptr _event) { + auto &event = *_event; +#endif /// Calls to GetEvent are synchronized with each other, which means they can /// read and write state on the JEventSource without causing race conditions. @@ -195,9 +202,12 @@ JEventSourcePODIO::Result JEventSourcePODIO::Emit(JEvent& event) { if( Nevents_read >= Nevents_in_file ) { if( m_run_forever ){ Nevents_read = 0; - } - else{ + } else { +#if JANA_NEW_CALLBACK_STYLE return Result::FailureFinished; +#else + throw RETURN_STATUS::kNO_MORE_EVENTS; +#endif } } @@ -221,7 +231,9 @@ JEventSourcePODIO::Result JEventSourcePODIO::Emit(JEvent& event) { event.Insert(frame.release()); // Transfer ownership from unique_ptr to JFactoryT Nevents_read += 1; +#if JANA_NEW_CALLBACK_STYLE return Result::Success; +#endif } //------------------------------------------------------------------------------ diff --git a/src/services/io/podio/JEventSourcePODIO.h b/src/services/io/podio/JEventSourcePODIO.h index fd88575eb..6c81ede7f 100644 --- a/src/services/io/podio/JEventSourcePODIO.h +++ b/src/services/io/podio/JEventSourcePODIO.h @@ -19,6 +19,12 @@ #include #include +#if ((JANA_VERSION_MAJOR == 2) && (JANA_VERSION_MINOR >= 3)) || (JANA_VERSION_MAJOR > 2) +#define JANA_NEW_CALLBACK_STYLE 1 +#else +#define JANA_NEW_CALLBACK_STYLE 0 +#endif + class JEventSourcePODIO : public JEventSource { public: @@ -30,7 +36,11 @@ class JEventSourcePODIO : public JEventSource { void Close() override; +#if JANA_NEW_CALLBACK_STYLE Result Emit(JEvent& event) override; +#else + void GetEvent(std::shared_ptr) override; +#endif static std::string GetDescription();