Skip to content

Commit

Permalink
Podio event source: Use new, exception-free Emit() callback
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei authored and veprbl committed Nov 20, 2024
1 parent bfeecb7 commit 8384afe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/services/io/podio/JEventSourcePODIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -185,7 +186,7 @@ void JEventSourcePODIO::Close() {
///
/// \param event
//------------------------------------------------------------------------------
void JEventSourcePODIO::GetEvent(std::shared_ptr<JEvent> 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.
Expand All @@ -194,10 +195,9 @@ 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.
throw RETURN_STATUS::kNO_MORE_EVENTS;
}
else{
return Result::FailureFinished;
}
}

Expand All @@ -208,19 +208,20 @@ 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;
return Result::Success;
}

//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/services/io/podio/JEventSourcePODIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class JEventSourcePODIO : public JEventSource {

void Close() override;

void GetEvent(std::shared_ptr<JEvent>) override;
Result Emit(JEvent& event) override;

static std::string GetDescription();

Expand Down

0 comments on commit 8384afe

Please sign in to comment.