The Gaudi Framework  v30r0 (c919700c)
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 // Standard constructor, initializes variables
16 // ============================================================================
18  : GaudiAlgorithm( name, pSvcLocator )
19 {
20 }
21 
22 // ============================================================================
23 // Destructor
24 // ============================================================================
26 
27 // ============================================================================
28 // Initialization
29 // ============================================================================
31 {
32  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
33  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
34 
35  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
36 
37  return StatusCode::SUCCESS;
38 }
39 
40 // ============================================================================
41 // Main execution
42 // ============================================================================
44 {
45  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
46 
47  if ( !m_ctxtSpecCounter ) {
48  m_ctxtSpecCounter = new int( 1 );
49  } else {
50  ++( *m_ctxtSpecCounter );
51  }
52  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter.get() << " -> "
54 
55  return StatusCode::SUCCESS;
56 }
57 
58 // ============================================================================
59 // Finalize
60 // ============================================================================
62 {
63  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
64 
65  debug() << "Partial counts:" << endmsg;
66 
67  info() << "Total count of events: "
68  << m_ctxtSpecCounter.accumulate(
69  [this]( const int* p ) -> int {
70  const int r = ( p ) ? *p : 0;
71  // print partial counts
72  this->debug() << " " << p << " -> " << r << endmsg;
73  return r;
74  },
75  0 )
76  << endmsg;
77 
78  m_ctxtSpecCounter.deleteAll();
79 
80  return GaudiAlgorithm::finalize(); // must be called after all other actions
81 }
82 
83 // ============================================================================
84 // Standard constructor, initializes variables
85 // ============================================================================
87  : GaudiAlgorithm( name, pSvcLocator )
88 {
89 }
90 
91 // ============================================================================
92 // Destructor
93 // ============================================================================
95 
96 // ============================================================================
97 // Initialization
98 // ============================================================================
100 {
101  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
102  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
103 
104  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
105 
106  return StatusCode::SUCCESS;
107 }
108 
109 // ============================================================================
110 // Main execution
111 // ============================================================================
113 {
114  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
115 
117  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter << endmsg;
118 
119  return StatusCode::SUCCESS;
120 }
121 
122 // ============================================================================
123 // Finalize
124 // ============================================================================
126 {
127  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
128 
129  if ( msgLevel( MSG::DEBUG ) ) {
130  debug() << "Partial counts:" << endmsg;
131  m_ctxtSpecCounter.for_each( [this]( const int i ) { this->debug() << " " << i << endmsg; } );
132  }
133 
134  info() << "Total count of events: " << m_ctxtSpecCounter.accumulate( 0 ) << endmsg;
135 
136  return GaudiAlgorithm::finalize(); // must be called after all other actions
137 }
138 
139 // ============================================================================
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:737
~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:61
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:26
StatusCode execute() override
Algorithm execution.
StatusCode finalize() override
standard finalization method
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:631
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 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
StatusCode initialize() override
Algorithm initialization.