ContextEventCounter.cpp
Go to the documentation of this file.
1 // Include files
2 
3 // From Gaudi
4 #include "GaudiKernel/AlgFactory.h"
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.
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:946
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode initialize() override
standard initialization method
Gaudi::Hive::ContextSpecificData< int > m_ctxtSpecCounter
virtual ~ContextEventCounterData()
Destructor.
virtual ~ContextEventCounterPtr()
Destructor.
STL namespace.
virtual StatusCode finalize()
Algorithm finalization.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
Gaudi::Hive::ContextSpecificPtr< int > m_ctxtSpecCounter
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
GAUDI_API ContextIdType currentContextId()
Return the current context id.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode finalize() override
standard finalization method
The useful base class for data processing algorithms.
virtual StatusCode initialize()
Algorithm initialization.
virtual StatusCode initialize()
Algorithm initialization.
virtual StatusCode finalize()
Algorithm finalization.
virtual StatusCode execute()
Algorithm execution.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
list i
Definition: ana.py:128
virtual StatusCode execute()
Algorithm execution.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream