The Gaudi Framework  v30r3 (a5ef0a68)
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 // ----------------------------------------------------------------------------
10 
11 // ============================================================================
12 // Main execution
13 // ============================================================================
15 {
16  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
17 
18  if ( !m_ctxtSpecCounter ) {
19  m_ctxtSpecCounter = new int( 1 );
20  } else {
21  ++( *m_ctxtSpecCounter );
22  }
23  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter.get() << " -> "
24  << *m_ctxtSpecCounter << endmsg;
25 
26  return StatusCode::SUCCESS;
27 }
28 
29 // ============================================================================
30 // Finalize
31 // ============================================================================
33 {
34  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
35 
36  debug() << "Partial counts:" << endmsg;
37 
38  info() << "Total count of events: "
39  << m_ctxtSpecCounter.accumulate(
40  [this]( const int* p ) {
41  const int r = ( p ? *p : 0 );
42  // print partial counts
43  this->debug() << " " << p << " -> " << r << endmsg;
44  return r;
45  },
46  0 )
47  << endmsg;
48 
49  m_ctxtSpecCounter.deleteAll();
50 
51  return Algorithm::finalize(); // must be called after all other actions
52 }
53 
54 // ============================================================================
55 // Main execution
56 // ============================================================================
58 {
59  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
60 
62  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter << endmsg;
63 
64  return StatusCode::SUCCESS;
65 }
66 
67 // ============================================================================
68 // Finalize
69 // ============================================================================
71 {
72  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
73 
74  if ( msgLevel( MSG::DEBUG ) ) {
75  debug() << "Partial counts:" << endmsg;
76  m_ctxtSpecCounter.for_each( [this]( const int i ) { this->debug() << " " << i << endmsg; } );
77  }
78 
79  info() << "Total count of events: " << m_ctxtSpecCounter.accumulate( 0 ) << endmsg;
80 
81  return Algorithm::finalize(); // must be called after all other actions
82 }
83 
84 // ============================================================================
GAUDI_API ContextIdType currentContextId()
Return the current context id.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode execute() override final
StatusCode finalize() override
Algorithm finalization.
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:185
StatusCode execute() override
Standard constructor.
Gaudi::Hive::ContextSpecificPtr< int > m_ctxtSpecCounter
#define DECLARE_COMPONENT(type)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode finalize() override
Algorithm finalization.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)