The Gaudi Framework  v30r1 (5d4f4ae2)
ContextEventCounter.cpp
Go to the documentation of this file.
1 // Include files
2 
3 // local
4 #include "ContextEventCounter.h"
5 
6 // ----------------------------------------------------------------------------
7 // Implementation file for class: ContextEventCounterPtr
8 //
9 // 27/10/2013: Marco Clemencic
10 // ----------------------------------------------------------------------------
13 
14 // ============================================================================
15 // Main execution
16 // ============================================================================
18 {
19  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
20 
21  if ( !m_ctxtSpecCounter ) {
22  m_ctxtSpecCounter = new int( 1 );
23  } else {
24  ++( *m_ctxtSpecCounter );
25  }
26  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter.get() << " -> "
27  << *m_ctxtSpecCounter << endmsg;
28 
29  return StatusCode::SUCCESS;
30 }
31 
32 // ============================================================================
33 // Finalize
34 // ============================================================================
36 {
37  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
38 
39  debug() << "Partial counts:" << endmsg;
40 
41  info() << "Total count of events: "
42  << m_ctxtSpecCounter.accumulate(
43  [this]( const int* p ) {
44  const int r = ( p ? *p : 0 );
45  // print partial counts
46  this->debug() << " " << p << " -> " << r << endmsg;
47  return r;
48  },
49  0 )
50  << endmsg;
51 
52  m_ctxtSpecCounter.deleteAll();
53 
54  return Algorithm::finalize(); // must be called after all other actions
55 }
56 
57 // ============================================================================
58 // Main execution
59 // ============================================================================
61 {
62  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
63 
65  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter << endmsg;
66 
67  return StatusCode::SUCCESS;
68 }
69 
70 // ============================================================================
71 // Finalize
72 // ============================================================================
74 {
75  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
76 
77  if ( msgLevel( MSG::DEBUG ) ) {
78  debug() << "Partial counts:" << endmsg;
79  m_ctxtSpecCounter.for_each( [this]( const int i ) { this->debug() << " " << i << endmsg; } );
80  }
81 
82  info() << "Total count of events: " << m_ctxtSpecCounter.accumulate( 0 ) << endmsg;
83 
84  return Algorithm::finalize(); // must be called after all other actions
85 }
86 
87 // ============================================================================
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:186
StatusCode execute() override
Standard constructor.
Gaudi::Hive::ContextSpecificPtr< int > m_ctxtSpecCounter
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:633
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode finalize() override
Algorithm finalization.
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209