| The Gaudi Framework v32r1 (f65d50dc)

ContextEventCounter.cpp
Go to the documentation of this file.
1 #include "ContextEventCounter.h"
2
3 // ----------------------------------------------------------------------------
4 // Implementation file for class: ContextEventCounterPtr
5 //
6 // 27/10/2013: Marco Clemencic
7 // ----------------------------------------------------------------------------
8 DECLARE_COMPONENT( ContextEventCounterPtr )
9 DECLARE_COMPONENT( ContextEventCounterData )
10
11 // ============================================================================
12 // Main execution
13 // ============================================================================
14 StatusCode ContextEventCounterPtr::execute() {
15 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
16
17 if ( !m_ctxtSpecCounter ) {
18 m_ctxtSpecCounter = new int( 1 );
19 } else {
20 ++( *m_ctxtSpecCounter );
21 }
22 debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter.get() << " -> "
23 << *m_ctxtSpecCounter << endmsg;
24
25 return StatusCode::SUCCESS;
26 }
27
28 // ============================================================================
29 // Finalize
30 // ============================================================================
31 StatusCode ContextEventCounterPtr::finalize() {
32 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
33
34 debug() << "Partial counts:" << endmsg;
35
36 info() << "Total count of events: "
37 << m_ctxtSpecCounter.accumulate(
38 [this]( const int* p ) {
39 const int r = ( p ? *p : 0 );
40 // print partial counts
41 this->debug() << " " << p << " -> " << r << endmsg;
42 return r;
43 },
44 0 )
45 << endmsg;
46
47 m_ctxtSpecCounter.deleteAll();
48
49 return Algorithm::finalize(); // must be called after all other actions
50 }
51
52 // ============================================================================
53 // Main execution
54 // ============================================================================
55 StatusCode ContextEventCounterData::execute() {
56 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
57
58 ++m_ctxtSpecCounter;
59 debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter << endmsg;
60
61 return StatusCode::SUCCESS;
62 }
63
64 // ============================================================================
65 // Finalize
66 // ============================================================================
67 StatusCode ContextEventCounterData::finalize() {
68 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
69
70 if ( msgLevel( MSG::DEBUG ) ) {
71 debug() << "Partial counts:" << endmsg;
72 m_ctxtSpecCounter.for_each( [this]( const int i ) { this->debug() << " " << i << endmsg; } );
73 }
74
75 info() << "Total count of events: " << m_ctxtSpecCounter.accumulate( 0 ) << endmsg;
76
77 return Algorithm::finalize(); // must be called after all other actions
78 }
79
80 // ============================================================================
Gaudi::Hive::currentContextId
GAUDI_API ContextIdType currentContextId()
Return the current context id.
Definition: ThreadLocalContext.cpp:18
ContextEventCounterPtr::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: ContextEventCounter.cpp:31
ContextEventCounterData::m_ctxtSpecCounter
Gaudi::Hive::ContextSpecificData< int > m_ctxtSpecCounter
Definition: ContextEventCounter.h:29
MSG::DEBUG
Definition: IMessageSvc.h:15
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
ContextEventCounterData::execute
StatusCode execute() override
Standard constructor.
Definition: ContextEventCounter.cpp:55
ContextEventCounterPtr
Definition: ContextEventCounter.h:14
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:104
ContextEventCounterPtr::m_ctxtSpecCounter
Gaudi::Hive::ContextSpecificPtr< int > m_ctxtSpecCounter
Definition: ContextEventCounter.h:20
CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:138
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
ContextEventCounterData
Definition: ContextEventCounter.h:23
ContextEventCounter.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:186
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:107
ContextEventCounterData::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: ContextEventCounter.cpp:67
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192