Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Podio event source: Use new, exception-free Emit() callback #1624

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmake/jana_plugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
29 changes: 21 additions & 8 deletions src/services/io/podio/JEventSourcePODIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +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();
Expand Down Expand Up @@ -185,7 +188,12 @@ void JEventSourcePODIO::Close() {
///
/// \param event
//------------------------------------------------------------------------------
void JEventSourcePODIO::GetEvent(std::shared_ptr<JEvent> event) {
#if JANA_NEW_CALLBACK_STYLE
JEventSourcePODIO::Result JEventSourcePODIO::Emit(JEvent& event) {
#else
void JEventSourcePODIO::GetEvent(std::shared_ptr<JEvent> _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.
Expand All @@ -194,10 +202,12 @@ void JEventSourcePODIO::GetEvent(std::shared_ptr<JEvent> 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.
wdconinc marked this conversation as resolved.
Show resolved Hide resolved
} else {
#if JANA_NEW_CALLBACK_STYLE
return Result::FailureFinished;
#else
throw RETURN_STATUS::kNO_MORE_EVENTS;
#endif
}
}

Expand All @@ -208,19 +218,22 @@ void JEventSourcePODIO::GetEvent(std::shared_ptr<JEvent> 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<InsertingVisitor> 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<podio::Frame>
event.Insert(frame.release()); // Transfer ownership from unique_ptr to JFactoryT<podio::Frame>
Nevents_read += 1;
#if JANA_NEW_CALLBACK_STYLE
return Result::Success;
#endif
}

//------------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions src/services/io/podio/JEventSourcePODIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
#include <set>
#include <string>

#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:
Expand All @@ -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<JEvent>) override;
#endif

static std::string GetDescription();

Expand Down
Loading