The Gaudi Framework  v29r0 (ff2e7097)
ContextEventCounter.cpp
Go to the documentation of this file.
1 // Include files
2 
3 // From Gaudi
5 // local
6 #include "ContextEventCounter.h"
7 
8 // ----------------------------------------------------------------------------
9 // Implementation file for class: ContextEventCounterPtr
10 //
11 // 27/10/2013: Marco Clemencic
12 // ----------------------------------------------------------------------------
15 
16 // ============================================================================
17 // Standard constructor, initializes variables
18 // ============================================================================
20  : GaudiAlgorithm( name, pSvcLocator )
21 {
22 }
23 
24 // ============================================================================
25 // Destructor
26 // ============================================================================
28 
29 // ============================================================================
30 // Initialization
31 // ============================================================================
33 {
34  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
35  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
36 
37  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
38 
39  return StatusCode::SUCCESS;
40 }
41 
42 // ============================================================================
43 // Main execution
44 // ============================================================================
46 {
47  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
48 
49  if ( !m_ctxtSpecCounter ) {
50  m_ctxtSpecCounter = new int( 1 );
51  } else {
52  ++( *m_ctxtSpecCounter );
53  }
54  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter.get() << " -> "
56 
57  return StatusCode::SUCCESS;
58 }
59 
60 // ============================================================================
61 // Finalize
62 // ============================================================================
64 {
65  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
66 
67  debug() << "Partial counts:" << endmsg;
68 
69  info() << "Total count of events: "
70  << m_ctxtSpecCounter.accumulate(
71  [this]( const int* p ) -> int {
72  const int r = ( p ) ? *p : 0;
73  // print partial counts
74  this->debug() << " " << p << " -> " << r << endmsg;
75  return r;
76  },
77  0 )
78  << endmsg;
79 
80  m_ctxtSpecCounter.deleteAll();
81 
82  return GaudiAlgorithm::finalize(); // must be called after all other actions
83 }
84 
85 // ============================================================================
86 // Standard constructor, initializes variables
87 // ============================================================================
89  : GaudiAlgorithm( name, pSvcLocator )
90 {
91 }
92 
93 // ============================================================================
94 // Destructor
95 // ============================================================================
97 
98 // ============================================================================
99 // Initialization
100 // ============================================================================
102 {
103  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
104  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
105 
106  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
107 
108  return StatusCode::SUCCESS;
109 }
110 
111 // ============================================================================
112 // Main execution
113 // ============================================================================
115 {
116  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
117 
119  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter << endmsg;
120 
121  return StatusCode::SUCCESS;
122 }
123 
124 // ============================================================================
125 // Finalize
126 // ============================================================================
128 {
129  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
130 
131  if ( msgLevel( MSG::DEBUG ) ) {
132  debug() << "Partial counts:" << endmsg;
133  m_ctxtSpecCounter.for_each( [this]( const int i ) { this->debug() << " " << i << endmsg; } );
134  }
135 
136  info() << "Total count of events: " << m_ctxtSpecCounter.accumulate( 0 ) << endmsg;
137 
138  return GaudiAlgorithm::finalize(); // must be called after all other actions
139 }
140 
141 // ============================================================================
ContextEventCounterData(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
GAUDI_API ContextIdType currentContextId()
Return the current context id.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:731
~ContextEventCounterPtr() override
Destructor.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode initialize() override
standard initialization method
StatusCode finalize() override
Algorithm finalization.
Gaudi::Hive::ContextSpecificData< int > m_ctxtSpecCounter
STL namespace.
StatusCode execute() override
Algorithm execution.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
Gaudi::Hive::ContextSpecificPtr< int > m_ctxtSpecCounter
STL class.
StatusCode initialize() override
Algorithm initialization.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
StatusCode execute() override
Algorithm execution.
StatusCode finalize() override
standard finalization method
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:629
The useful base class for data processing algorithms.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
~ContextEventCounterData() override
Destructor.
StatusCode finalize() override
Algorithm finalization.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode initialize() override
Algorithm initialization.