The Gaudi Framework  master (bdbe7744)
Loading...
Searching...
No Matches
AsynchronousAlgorithm.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 2024-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
12#include <Gaudi/IAuditor.h>
14
16 setAsynchronous( true );
17 debug() << "Starting sysInitialize for AsynchronousAlgorithm" << endmsg;
18 // Disable synchronous timeline recording and enable asynchronous timeline recording if synchronous was enabled before
20
22}
23
25 debug() << "Starting sysExecute for AsynchronousAlgorithm for event " << ctx << endmsg;
26
27 s_ctx.reset( new EventContext( ctx ) );
28
29 if ( m_doAsyncTimeline ) {
30 s_timelineRecorder.reset( new ITimelineSvc::TimelineRecorder( timelineSvc()->getRecorder( name(), ctx ) ) );
31 }
32
33 auto sc = Gaudi::Algorithm::sysExecute( ctx );
34
35 if ( m_doAsyncTimeline ) { s_timelineRecorder.reset( nullptr ); }
36
37 return sc;
38} catch ( const GaudiException& e ) {
39 error() << "EXCEPTION MESSAGE IS: " << e.what() << endmsg;
40 if ( m_doAsyncTimeline ) { s_timelineRecorder.reset( nullptr ); } // still need to reset the timeline recorder
41 throw;
42}
43
45 if ( !whiteboard()->selectStore( s_ctx->slot() ).isSuccess() ) {
46 error() << "Resetting slot from fiber_specific_ptr failed" << endmsg;
48 }
50}
51
60
62 if ( !whiteboard()->selectStore( s_ctx->slot() ).isSuccess() ) {
63 error() << "Resetting slot from fiber_specific_ptr failed" << endmsg;
65 }
68 }
69 if ( m_doAsyncTimeline ) {
70 s_timelineRecorder.reset( new ITimelineSvc::TimelineRecorder( timelineSvc()->getRecorder( name(), *s_ctx ) ) );
71 }
73}
74
76 // preSuspension
77 try {
78 if ( auto sc = preSuspension(); !sc.isSuccess() ) { return sc; }
79 } catch ( const GaudiException& e ) {
80 error() << "Exception in preSuspension(): " << e.what() << endmsg;
82 }
83
84 // Callable
86 try {
87 fsc = std::invoke( std::move( f ) );
88 } catch ( const GaudiException& e ) {
89 error() << "Exception in decorated callable: " << e.what() << endmsg;
91 }
92
93 // postResumption happen happen even if callable failed/threw
95 try {
96 psc = postResumption();
97 } catch ( const GaudiException& e ) {
98 error() << "Exception in postResumption(): " << e.what() << endmsg;
100 }
101
102 // Preserve the original callable failure over a postResumption failure.
103 if ( !fsc.isSuccess() ) { return fsc; }
104
105 return psc;
106}
107
109 return decorateSuspension( []() -> StatusCode {
110 boost::this_fiber::yield();
111 return StatusCode::SUCCESS;
112 } );
113}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
This class represents an entry point to all the event specific data.
SmartIF< IAuditorSvc > & auditorSvc() const
The standard auditor service.May not be invoked before sysInitialize() has been invoked.
bool setAsynchronousTimeline()
Definition Algorithm.h:382
StatusCode sysExecute(const EventContext &ctx) override
The actions to be performed by the algorithm on an event.
void setAsynchronous(bool value)
Definition Algorithm.h:378
SmartIF< ITimelineSvc > & timelineSvc() const
const std::string & name() const override
The identifying name of the algorithm object.
SmartIF< IHiveWhiteBoard > & whiteboard() const
bool isEnabled() const override
Is this algorithm enabled or disabled?
bool isInitialized() const override
Has the Algorithm already been initialized?
Definition Algorithm.h:404
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition Algorithm.cpp:53
virtual StatusCode preSuspension() const
Gaudi::Property< bool > m_auditorSuspension
boost::fibers::fiber_specific_ptr< EventContext > s_ctx
Contains current slot.
StatusCode sysExecute(const EventContext &ctx) override
virtual StatusCode restoreAfterSuspend() const
Restore after suspend.
StatusCode yield() const
Forwards to boost::this_fiber::yield.
virtual StatusCode postResumption() const
StatusCode decorateSuspension(std::function< StatusCode()> f) const
Decorate a direct call to a suspending (or possibly suspending) function with the necessary pre- and ...
boost::fibers::fiber_specific_ptr< ITimelineSvc::TimelineRecorder > s_timelineRecorder
static const std::string Suspension
Definition IAuditor.h:55
Define general base for Gaudi exception.
const char * what() const override
method from std::exception
RAII helper to record timeline events.
virtual bool isEnabled() const =0
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isSuccess() const
Definition StatusCode.h:302
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100