Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  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 // ============================================================================
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 // ============================================================================
56  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
57 
59  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter << endmsg;
60 
61  return StatusCode::SUCCESS;
62 }
63 
64 // ============================================================================
65 // Finalize
66 // ============================================================================
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_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.
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
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:50
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:186
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:192
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)