The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
IncidentAsyncTestSvc.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 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
17
19
24
26
27#define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
28#define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
29
30#define DEBMSG ON_DEBUG debug()
31#define VERMSG ON_VERBOSE verbose()
32
34 auto sc = Service::initialize();
35 if ( sc.isFailure() ) return sc;
36 m_incSvc = service( "IncidentSvc", true );
37 if ( !m_incSvc ) throw GaudiException( "Cannot find IncidentSvc", name(), StatusCode::FAILURE );
38 m_msgSvc = msgSvc();
39 if ( m_incidentNames.empty() ) {
40 std::vector<std::string> incNames;
41 incNames.push_back( IncidentType::BeginEvent );
42 incNames.push_back( IncidentType::EndEvent );
43 m_incidentNames.setValue( incNames );
44 }
45 auto& incNames = m_incidentNames.value();
46 for ( auto& i : incNames ) { m_incSvc->addListener( this, i, m_prio ); }
47 return sc;
48}
49
51
52//=============================================================================
53void IncidentAsyncTestSvc::handle( const Incident& incident ) {
54 if ( incident.type() == IncidentType::BeginEvent ) {
55 auto res = m_ctxData.insert(
56 std::make_pair( incident.context(), incident.context().evt() * m_eventMultiplier + m_fileOffset ) );
57 if ( !res.second ) {
58 warning() << " Context already exists for '" << incident.type() << "' event=" << incident.context().evt()
59 << endmsg;
60 }
61 } else if ( incident.type() == IncidentType::EndEvent ) {
62 {
63 auto g = std::scoped_lock{ m_eraseMutex };
64 auto res = m_ctxData.unsafe_erase( incident.context() );
65 if ( res == 0 ) {
66 warning() << " Context is missing for '" << incident.type() << "' event=" << incident.context().evt() << endmsg;
67 }
68 }
69 info() << " Cleaned up context store for event =" << incident.context().evt() << " for incident='"
70 << incident.type() << "'" << endmsg;
71 }
72 info() << " Handling incident '" << incident.type() << "' at ctx=" << incident.context() << endmsg;
73}
74
75void IncidentAsyncTestSvc::getData( uint64_t* data, EventContext* ctx ) const {
76 if ( ctx ) {
77 debug() << "Asked for data with context " << *ctx << endmsg;
78 auto cit = m_ctxData.find( *ctx );
79 if ( cit == m_ctxData.end() ) {
80 fatal() << " data for event " << ctx->evt() << " is not initialized yet!. This shouldn't happen!" << endmsg;
81 return;
82 }
83 *data = cit->second;
84 } else {
85 const auto& ct = Gaudi::Hive::currentContext();
86 auto cit = m_ctxData.find( ct );
87 if ( cit == m_ctxData.end() ) {
88 fatal() << " data for event " << ct.evt() << " is not initialized yet!. This shouldn't happen!" << endmsg;
89 return;
90 }
91 *data = cit->second;
92 }
93}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
This class represents an entry point to all the event specific data.
ContextEvt_t evt() const
Define general base for Gaudi exception.
Gaudi::Property< long > m_prio
SmartIF< IIncidentSvc > m_incSvc
Gaudi::Property< uint64_t > m_fileOffset
StatusCode finalize() override
tbb::concurrent_unordered_map< EventContext, uint64_t, EventContextHash, EventContextHash > m_ctxData
Gaudi::Property< std::vector< std::string > > m_incidentNames
void getData(uint64_t *data, EventContext *ctx=0) const override
Gaudi::Property< uint64_t > m_eventMultiplier
void handle(const Incident &incident) override
Reimplements from IIncidentListener.
StatusCode initialize() override
SmartIF< IMessageSvc > m_msgSvc
Base class for all Incidents (computing events).
Definition Incident.h:24
EventContext context() const
Access to the EventContext of the source of the incident.
Definition Incident.h:55
const std::string & type() const
Access to the incident type.
Definition Incident.h:43
StatusCode finalize() override
Definition Service.cpp:223
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
Definition Service.h:79
StatusCode initialize() override
Definition Service.cpp:118
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto FAILURE
Definition StatusCode.h:100
GAUDI_API const EventContext & currentContext()