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

Handle exceptions coming from Marlin #58

Merged
merged 1 commit into from
Dec 6, 2021
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
2 changes: 2 additions & 0 deletions k4MarlinWrapper/k4MarlinWrapper/MarlinProcessorWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

// Gaudi
#include <GaudiAlg/GaudiAlgorithm.h>
#include <GaudiKernel/IEventProcessor.h>
#include <GaudiKernel/MsgStream.h>
#include <GaudiKernel/ToolHandle.h>

Expand All @@ -37,6 +38,7 @@

// Marlin
#include <marlin/EventModifier.h>
#include <marlin/Exceptions.h>
#include <marlin/Global.h>
#include <marlin/ProcessorEventSeeder.h>
#include <marlin/ProcessorMgr.h>
Expand Down
3 changes: 1 addition & 2 deletions k4MarlinWrapper/src/components/LcioEventAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ StatusCode LcioEvent::execute() {

if (theEvent == nullptr) {
// Store flag to indicate there was NOT a LCEvent
auto pStatus = std::make_unique<LCEventWrapperStatus>(false);
std::cout << "Saving status: " << pStatus->hasLCEvent << std::endl;
auto pStatus = std::make_unique<LCEventWrapperStatus>(false);
const StatusCode scStatus = eventSvc()->registerObject("/Event/LCEventStatus", pStatus.release());
if (scStatus.isFailure()) {
error() << "Failed to store flag for underlying LCEvent: MarlinProcessorWrapper may try to run over non existing "
Expand Down
65 changes: 52 additions & 13 deletions k4MarlinWrapper/src/components/MarlinProcessorWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ StatusCode MarlinProcessorWrapper::execute() {
the_event = dynamic_cast<IMPL::LCEventImpl*>(static_cast<LCEventWrapper*>(pObject)->getEvent());
}

// Found EDM Conversion tool
// EDM4hep->LCIO conversion
if (!m_edm_conversionTool.empty()) {
StatusCode edm_sc = m_edm_conversionTool->convertCollections(the_event);
if (edm_sc.isFailure()) {
Expand All @@ -226,22 +226,61 @@ StatusCode MarlinProcessorWrapper::execute() {
// FIXME: this is an overkill, but we need to call this once per event, not
// once for each execute call
// how can this be done more efficiently?
auto* procMgr = marlin::ProcessorMgr::instance();
procMgr->modifyEvent(the_event);
try {
auto* procMgr = marlin::ProcessorMgr::instance();
procMgr->modifyEvent(the_event);

streamlog::logscope scope(streamlog::out);
scope.setName(name());
scope.setLevel(m_verbosity);
streamlog::logscope scope(streamlog::out);
scope.setName(name());
scope.setLevel(m_verbosity);

// process the event in the processor
auto modifier = dynamic_cast<marlin::EventModifier*>(m_processor);
if (modifier) {
modifier->modifyEvent(the_event);
} else {
m_processor->processEvent(the_event);
// process the event in the processor
auto modifier = dynamic_cast<marlin::EventModifier*>(m_processor);
if (modifier) {
modifier->modifyEvent(the_event);
} else {
m_processor->processEvent(the_event);
}
}
// Handle exceptions that may come from Marlin
catch (marlin::SkipEventException& e) {
// Store flag to prevent the rest of the event from processing
auto pStatus = std::make_unique<LCEventWrapperStatus>(false);
const StatusCode scStatus = eventSvc()->registerObject("/Event/LCEventStatus", pStatus.release());
if (scStatus.isFailure()) {
error() << "Failed to store flag to skip event on Marlin marlin::SkipEventException" << endmsg;
return scStatus;
}

error() << e.what() << endmsg;
return StatusCode::FAILURE;
} catch (marlin::StopProcessingException& e) {
// Store flag to prevent the rest of the event from processing
auto pStatus = std::make_unique<LCEventWrapperStatus>(false);
const StatusCode scStatus = eventSvc()->registerObject("/Event/LCEventStatus", pStatus.release());
if (scStatus.isFailure()) {
error() << "Failed to store flag to skip event on Marlin marlin::StopProcessingException" << endmsg;
return scStatus;
}

error() << e.what() << endmsg;

// Send stop to EventProcessor
IEventProcessor* evt = nullptr;
if (service("ApplicationMgr", evt, true).isSuccess()) {
evt->stopRun().ignore();
evt->release();
} else {
abort();
}

return StatusCode::FAILURE;
} catch (lcio::Exception& e) {
error() << "There was an exception while processing " << m_processor->name() << ": " << e.what() << endmsg;
return StatusCode::FAILURE;
}

// Found LCIO Conversion tool
// LCIO->EDM4hep conversion
if (!m_lcio_conversionTool.empty()) {
StatusCode lcio_sc = m_lcio_conversionTool->convertCollections(the_event);
if (lcio_sc.isFailure()) {
Expand Down