Skip to content

Commit

Permalink
support previous JANA2 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
veprbl committed Nov 20, 2024
1 parent 8258c3d commit 8e7a0d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/services/io/podio/JEventSourcePODIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<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 @@ -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
}
}

Expand All @@ -221,7 +231,9 @@ JEventSourcePODIO::Result JEventSourcePODIO::Emit(JEvent& event) {

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

0 comments on commit 8e7a0d5

Please sign in to comment.