diff --git a/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamCnvSvc.cxx b/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamCnvSvc.cxx index c796ecd1de6a0e95818351c4f97efd480f63132a..f400a2ba6f252fd78ccb2c79c82475e987fb1672 100644 --- a/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamCnvSvc.cxx +++ b/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamCnvSvc.cxx @@ -158,24 +158,25 @@ StatusCode TrigByteStreamCnvSvc::commitOutput(const std::string& /*outputFile*/, } // Send output to the DataCollector + StatusCode result = StatusCode::SUCCESS; try { hltinterface::DataCollector::instance()->eventDone(std::move(rawEventPtr)); + ATH_MSG_DEBUG("Serialised FullEventFragment with HLT result was returned to DataCollector successfully"); } catch (const std::exception& e) { ATH_MSG_ERROR("Sending output to DataCollector failed, caught an unexpected std::exception " << e.what()); - return StatusCode::FAILURE; + result = StatusCode::FAILURE; } catch (...) { ATH_MSG_ERROR("Sending output to DataCollector failed, caught an unexpected exception"); - return StatusCode::FAILURE; + result = StatusCode::FAILURE; } - ATH_MSG_DEBUG("Serialised FullEventFragment with HLT result was returned to DataCollector successfully"); delete m_rawEventWrite; m_rawEventWrite = nullptr; ATH_MSG_VERBOSE("end of " << __FUNCTION__); - return StatusCode::SUCCESS; + return result; } // ============================================================================= @@ -216,7 +217,17 @@ void TrigByteStreamCnvSvc::printRawEvent() { << std::endl; std::vector<eformat::helper::StreamTag> stream_tags; - eformat::helper::decode(m_rawEventWrite->nstream_tag(), m_rawEventWrite->stream_tag(), stream_tags); + try { + eformat::helper::decode(m_rawEventWrite->nstream_tag(), m_rawEventWrite->stream_tag(), stream_tags); + } + catch (const std::exception& ex) { + ATH_MSG_ERROR("StreamTag decoding failed, caught an unexpected std::exception " << ex.what()); + return; + } + catch (...) { + ATH_MSG_ERROR("StreamTag decoding failed, caught an unexpected exception"); + return; + } ss << "--> stream_tags = "; bool first = true; for (const auto& st : stream_tags) { diff --git a/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamInputSvc.cxx b/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamInputSvc.cxx index e18de147c7f8eb8e3e71b9e449860902047dc40d..ee8ca25c9d156b4a88164c6b608c7b914df2c731 100644 --- a/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamInputSvc.cxx +++ b/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamInputSvc.cxx @@ -88,11 +88,23 @@ const RawEvent* TrigByteStreamInputSvc::nextEvent() { eformat::write::FullEventFragment l1r; using DCStatus = hltinterface::DataCollector::Status; - auto status = DCStatus::NO_EVENT; + DCStatus status = DCStatus::NO_EVENT; do { - status = hltinterface::DataCollector::instance()->getNext(l1r); - if (status == DCStatus::NO_EVENT) - ATH_MSG_ERROR("Failed to read new event, DataCollector::getNext returned Status::NO_EVENT. Trying again."); + try { + status = hltinterface::DataCollector::instance()->getNext(l1r); + if (status == DCStatus::NO_EVENT) + ATH_MSG_ERROR("Failed to read new event, DataCollector::getNext returned Status::NO_EVENT. Trying again."); + } + catch (const std::exception& ex) { + ATH_MSG_ERROR("Failed to read new event, caught an unexpected exception: " << ex.what() + << ". Throwing hltonl::Exception::EventSourceCorrupted" ); + throw hltonl::Exception::EventSourceCorrupted(); + } + catch (...) { + ATH_MSG_ERROR("Failed to read new event, caught an unexpected exception. " + << "Throwing hltonl::Exception::EventSourceCorrupted" ); + throw hltonl::Exception::EventSourceCorrupted(); + } } while (status == DCStatus::NO_EVENT); if (status == DCStatus::STOP) { diff --git a/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamInputSvc.h b/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamInputSvc.h index 66fc6e623287cb49044ce9012d07c2d5b334ad19..a0b62f2e5c2c54c72be99a989182b9326b2d1ae7 100644 --- a/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamInputSvc.h +++ b/HLT/Event/TrigByteStreamCnvSvc/src/TrigByteStreamInputSvc.h @@ -38,20 +38,19 @@ public: virtual const RawEvent* currentEvent() const override; private: - // ------------------------- service handles ---- ---------------------------- + // ------------------------- Service handles --------------------------------- ServiceHandle<IROBDataProviderSvc> m_robDataProviderSvc; ServiceHandle<StoreGateSvc> m_evtStore; - // ------------------------- private data members ---------------------------- + // ------------------------- Private data members ---------------------------- struct EventCache { ~EventCache(); - RawEvent* rawEvent = 0; //!< current event - // unsigned int eventStatus = 0; //!< status of the current event + RawEvent* rawEvent {nullptr}; //!< Current event }; - SG::SlotSpecificObj<EventCache> m_eventsCache; + SG::SlotSpecificObj<EventCache> m_eventsCache; //!< Cache of RawEvent pointer per event slot - // ------------------------- private helper methods -------------------------- + // ------------------------- Private helper methods -------------------------- /// Clean up parts of previous event and re-init them void releaseEvent(EventCache* cache); }; diff --git a/HLT/Event/TrigByteStreamCnvSvc/src/TrigEventSelectorByteStream.cxx b/HLT/Event/TrigByteStreamCnvSvc/src/TrigEventSelectorByteStream.cxx index 47ca5fead05ead24713aac0a527c54721f47d266..c63306a594957b8061f3b236a2d9e5f2fc763d45 100644 --- a/HLT/Event/TrigByteStreamCnvSvc/src/TrigEventSelectorByteStream.cxx +++ b/HLT/Event/TrigByteStreamCnvSvc/src/TrigEventSelectorByteStream.cxx @@ -14,9 +14,6 @@ #include "EventInfo/EventInfo.h" #include "StoreGate/StoreGateSvc.h" -// TDAQ includes -#include "hltinterface/DataCollector.h" - // ============================================================================= // Standard constructor // ============================================================================= @@ -78,12 +75,16 @@ StatusCode TrigEventSelectorByteStream::next(IEvtSelector::Context& /*c*/) const ATH_MSG_INFO(e.what()); throw; // rethrow NoMoreEvents } + catch (const hltonl::Exception::EventSourceCorrupted& e) { + ATH_MSG_ERROR(e.what()); + throw; // rethrow EventSourceCorrupted + } catch (const std::exception& e) { ATH_MSG_ERROR("Failed to get next event from the event source, std::exception caught: " << e.what()); return StatusCode::FAILURE; } catch (...) { - ATH_MSG_ERROR("Failed to get next event from the event source, unhandled exception caught"); + ATH_MSG_ERROR("Failed to get next event from the event source, unknown exception caught"); return StatusCode::FAILURE; } diff --git a/HLT/Trigger/TrigControl/TrigKernel/CMakeLists.txt b/HLT/Trigger/TrigControl/TrigKernel/CMakeLists.txt index 45c7995164eadbbe7eace835eb91bcf4bb47d855..27a5413feaa922d5d13f3e07b7c5789c0b1ed24e 100644 --- a/HLT/Trigger/TrigControl/TrigKernel/CMakeLists.txt +++ b/HLT/Trigger/TrigControl/TrigKernel/CMakeLists.txt @@ -11,7 +11,7 @@ atlas_depends_on_subdirs( PUBLIC # External dependencies: find_package( Boost COMPONENTS filesystem thread system ) -find_package( tdaq-common COMPONENTS eformat hltinterface ) +find_package( tdaq-common COMPONENTS eformat ) # Component(s) in the package: atlas_add_library( TrigKernel diff --git a/HLT/Trigger/TrigControl/TrigKernel/TrigKernel/HltExceptions.h b/HLT/Trigger/TrigControl/TrigKernel/TrigKernel/HltExceptions.h index 7d7ec7cbf0da711280c0db910d83c98351a4b939..f6b40e37561835756a514755528ca656614cfca2 100644 --- a/HLT/Trigger/TrigControl/TrigKernel/TrigKernel/HltExceptions.h +++ b/HLT/Trigger/TrigControl/TrigKernel/TrigKernel/HltExceptions.h @@ -11,7 +11,7 @@ namespace hltonl { namespace Exception { /** * @class NoMoreEvents - * @brief Can be thrown if all events are already read from the input and another one is requested + * @brief Thrown if all events are already read from the input and another one is requested */ class NoMoreEvents : public std::exception { public: @@ -19,6 +19,16 @@ namespace hltonl { virtual ~NoMoreEvents() {} const char* what() const noexcept override {return "No more events to be processed";} }; + /** + * @class EventSourceCorrupted + * @brief Thrown if event source keeps throwing exceptions when new event is requested + */ + class EventSourceCorrupted : public std::exception { + public: + EventSourceCorrupted() {} + virtual ~EventSourceCorrupted() {} + const char* what() const noexcept override {return "Event source corrupted and cannot provide events";} + }; } } diff --git a/HLT/Trigger/TrigControl/TrigKernel/TrigKernel/ITrigEventLoopMgr.h b/HLT/Trigger/TrigControl/TrigKernel/TrigKernel/ITrigEventLoopMgr.h index 58caf01982f52808042bcea3e112e45062dfa914..7158fce919fd21c310b35938955bf19743a6b070 100644 --- a/HLT/Trigger/TrigControl/TrigKernel/TrigKernel/ITrigEventLoopMgr.h +++ b/HLT/Trigger/TrigControl/TrigKernel/TrigKernel/ITrigEventLoopMgr.h @@ -8,12 +8,6 @@ #include "GaudiKernel/IInterface.h" #include <boost/property_tree/ptree.hpp> -namespace hltinterface -{ - struct EventId; - struct HLTResult; -} - /**@class ITrigEventLoopMgr * @brief EventLoopMgr interface implemented by the HLT event loop manager * diff --git a/HLT/Trigger/TrigControl/TrigPSC/TrigPSC/Psc.h b/HLT/Trigger/TrigControl/TrigPSC/TrigPSC/Psc.h index cce46e17c9ca8ba4817fc692dd40f6bb38386022..a4f83dd72fc611ae0a1da94474c04ab3b2ea52f9 100644 --- a/HLT/Trigger/TrigControl/TrigPSC/TrigPSC/Psc.h +++ b/HLT/Trigger/TrigControl/TrigPSC/TrigPSC/Psc.h @@ -15,10 +15,6 @@ // Package includes #include "hltinterface/HLTInterface.h" -#include "hltinterface/EventId.h" - -// to be removed together with the Psc::process method -#include "hltinterface/HLTResult.h" // Gaudi Includes #include "GaudiKernel/StatusCode.h" diff --git a/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.cxx b/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.cxx index 5366dd9905e71a977106662d96e0ac79e89d74a0..0c456e3b1a3e4f200efeede0e3091572999147c5 100644 --- a/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.cxx +++ b/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.cxx @@ -36,7 +36,6 @@ // TDAQ includes #include "eformat/StreamTag.h" -#include "hltinterface/DataCollector.h" #include "owl/time.h" // System includes @@ -696,7 +695,12 @@ StatusCode HltEventLoopMgr::nextEvent(int /*maxevt*/) } continue; } + catch (const std::exception& e) { + ATH_MSG_ERROR("Failed to get next event from the event source, std::exception caught: " << e.what()); + sc = StatusCode::FAILURE; + } catch (...) { + ATH_MSG_ERROR("Failed to get next event from the event source, unknown exception caught"); sc = StatusCode::FAILURE; } HLT_EVTLOOP_CHECK(sc, "Failed to get the next event", @@ -1055,14 +1059,14 @@ StatusCode HltEventLoopMgr::failedEvent(hltonl::PSCErrorCode errorCode, const Ev << "Failure occurred with PSCErrorCode=" << hltonl::PrintPscErrorCode(errorCode) << " meaning there was a framework error before requesting a new event. No output will be produced and all slots" << " of this HltEventLoopMgr instance will be drained before proceeding."; - return drainAllAndProceed(); + return drainAllAndProceed(); } else if (errorCode==hltonl::PSCErrorCode::AFTER_RESULT_SENT) { ATH_REPORT_MESSAGE(MSG::ERROR) << "Failure occurred with PSCErrorCode=" << hltonl::PrintPscErrorCode(errorCode) << " meaning there was a framework error after HLT result was already sent out." << " All slots of this HltEventLoopMgr instance will be drained before proceeding."; - return drainAllAndProceed(); + return drainAllAndProceed(); } else if (errorCode==hltonl::PSCErrorCode::CANNOT_ACCESS_SLOT) { ATH_REPORT_MESSAGE(MSG::ERROR) @@ -1070,14 +1074,26 @@ StatusCode HltEventLoopMgr::failedEvent(hltonl::PSCErrorCode errorCode, const Ev << hltonl::PrintPscErrorCode(errorCode) << ". All slots of this HltEventLoopMgr instance will be drained before proceeding, then either the loop will" << " exit with a failure code or the failed event will reach a hard timeout."; - return drainAllAndProceed(); + return drainAllAndProceed(); } else if (!eventContext.valid()) { ATH_REPORT_MESSAGE(MSG::ERROR) << "Failure occurred with an invalid EventContext. Likely there was a framework error before requesting a new" << " event or after sending the result of a finished event. PSCErrorCode=" << hltonl::PrintPscErrorCode(errorCode) << ". All slots of this HltEventLoopMgr instance will be drained before proceeding."; - return drainAllAndProceed(); + return drainAllAndProceed(); + } + + //---------------------------------------------------------------------------- + // In case of event source failure, drain the scheduler and break the loop + //---------------------------------------------------------------------------- + if (errorCode==hltonl::PSCErrorCode::CANNOT_RETRIEVE_EVENT) { + ATH_REPORT_MESSAGE(MSG::ERROR) + << "Failure occurred with PSCErrorCode=" << hltonl::PrintPscErrorCode(errorCode) + << " meaning a new event could not be correctly read. No output will be produced for this event. All slots of" + << " this HltEventLoopMgr instance will be drained and the loop will exit."; + ATH_CHECK(drainAllSlots()); + return StatusCode::FAILURE; } //---------------------------------------------------------------------------- @@ -1106,7 +1122,7 @@ StatusCode HltEventLoopMgr::failedEvent(hltonl::PSCErrorCode errorCode, const Ev << " event processing started or not. Current local event number is " << eventContext.evt() << ", slot " << eventContext.slot() << ". " << eventInfoString << " All slots of this HltEventLoopMgr instance will be drained before proceeding."; - return drainAllAndProceed(); + return drainAllAndProceed(); } //---------------------------------------------------------------------------- @@ -1133,7 +1149,7 @@ StatusCode HltEventLoopMgr::failedEvent(hltonl::PSCErrorCode errorCode, const Ev << " PSCErrorCode=" << hltonl::PrintPscErrorCode(errorCode) << ", local event number " << eventContext.evt() << ", slot " << eventContext.slot() << ". " << eventInfoString << " All slots of this HltEventLoopMgr instance will be drained before proceeding."; - return drainAllAndProceed(); + return drainAllAndProceed(); } //---------------------------------------------------------------------------- @@ -1153,7 +1169,7 @@ StatusCode HltEventLoopMgr::failedEvent(hltonl::PSCErrorCode errorCode, const Ev << " recorded for this event. PSCErrorCode=" << hltonl::PrintPscErrorCode(errorCode) << ", local event number " << eventContext.evt() << ", slot " << eventContext.slot() << ". " << eventInfoString << " All slots of this HltEventLoopMgr instance will be drained before proceeding."; - return drainAllAndProceed(); + return drainAllAndProceed(); } DataObject* hltResultDO = m_evtStore->accessData(hltResultWH.clid(),hltResultWH.key()); @@ -1163,7 +1179,7 @@ StatusCode HltEventLoopMgr::failedEvent(hltonl::PSCErrorCode errorCode, const Ev << " can be recorded for this event. PSCErrorCode=" << hltonl::PrintPscErrorCode(errorCode) << ", local event number " << eventContext.evt() << ", slot " << eventContext.slot() << ". " << eventInfoString << " All slots of this HltEventLoopMgr instance will be drained before proceeding."; - return drainAllAndProceed(); + return drainAllAndProceed(); } IOpaqueAddress* addr = nullptr; @@ -1173,7 +1189,7 @@ StatusCode HltEventLoopMgr::failedEvent(hltonl::PSCErrorCode errorCode, const Ev << " can be recorded for this event. PSCErrorCode=" << hltonl::PrintPscErrorCode(errorCode) << ", local event number " << eventContext.evt() << ", slot " << eventContext.slot() << ". " << eventInfoString << " All slots of this HltEventLoopMgr instance will be drained before proceeding."; - return drainAllAndProceed(); + return drainAllAndProceed(); } if (m_outputCnvSvc->commitOutput("",true).isFailure()) { @@ -1182,7 +1198,7 @@ StatusCode HltEventLoopMgr::failedEvent(hltonl::PSCErrorCode errorCode, const Ev << " recorded for this event. PSCErrorCode=" << hltonl::PrintPscErrorCode(errorCode) << ", local event number " << eventContext.evt() << ", slot " << eventContext.slot() << ". " << eventInfoString << " All slots of this HltEventLoopMgr instance will be drained before proceeding."; - return drainAllAndProceed(); + return drainAllAndProceed(); } //---------------------------------------------------------------------------- @@ -1206,8 +1222,8 @@ StatusCode HltEventLoopMgr::failedEvent(hltonl::PSCErrorCode errorCode, const Ev << m_maxFrameworkErrors.value() << ", was exceeded. Current local event number is " << eventContextCopy.evt() << ", slot " << eventContextCopy.slot() << ". " << eventInfoString << " All slots of this HltEventLoopMgr instance will be drained and the loop will exit."; - ATH_CHECK(drainAllSlots()); - return StatusCode::FAILURE; + ATH_CHECK(drainAllSlots()); + return StatusCode::FAILURE; } }