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 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  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
34  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
35 
36  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
37 
38  return StatusCode::SUCCESS;
39 }
40 
41 // ============================================================================
42 // Main execution
43 // ============================================================================
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() << " "
53  << m_ctxtSpecCounter.get() << " -> " << *m_ctxtSpecCounter << endmsg;
54 
55  return StatusCode::SUCCESS;
56 }
57 
58 // ============================================================================
59 // Finalize
60 // ============================================================================
62  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
63 
64  debug() << "Partial counts:" << endmsg;
65 
66  info() << "Total count of events: " << m_ctxtSpecCounter.accumulate(
67  [this] (const int* p) -> int {
68  const int r = (p) ? *p : 0;
69  // print partial counts
70  this->debug() << " " << p << " -> " << r << endmsg;
71  return r;
72  }
73  , 0) << endmsg;
74 
75  m_ctxtSpecCounter.deleteAll();
76 
77  return GaudiAlgorithm::finalize(); // must be called after all other actions
78 }
79 
80 // ============================================================================
81 // Standard constructor, initializes variables
82 // ============================================================================
84  : GaudiAlgorithm(name, pSvcLocator)
85 {
86 }
87 
88 // ============================================================================
89 // Destructor
90 // ============================================================================
92 
93 // ============================================================================
94 // Initialization
95 // ============================================================================
97  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
98  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
99 
100  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
101 
102  return StatusCode::SUCCESS;
103 }
104 
105 // ============================================================================
106 // Main execution
107 // ============================================================================
109  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
110 
112  debug() << "Context " << Gaudi::Hive::currentContextId() << " "
114 
115  return StatusCode::SUCCESS;
116 }
117 
118 // ============================================================================
119 // Finalize
120 // ============================================================================
122  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
123 
124  if ( msgLevel(MSG::DEBUG) ) {
125  debug() << "Partial counts:" << endmsg;
126  m_ctxtSpecCounter.for_each([this] (const int i) {
127  this->debug() << " " << i << endmsg;
128  });
129  }
130 
131  info() << "Total count of events: " << m_ctxtSpecCounter.accumulate(0) << endmsg;
132 
133  return GaudiAlgorithm::finalize(); // must be called after all other actions
134 }
135 
136 // ============================================================================
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:725
~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:84
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:644
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:244
StatusCode initialize() override
Algorithm initialization.