The Gaudi Framework  master (c53a8715)
Loading...
Searching...
No Matches
ContextEventCounter.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11
12// Framework includes
15
22class ContextEventCounterPtr final : public Algorithm {
23public:
25 StatusCode execute() override;
26 StatusCode finalize() override;
27private:
29};
30
31class ContextEventCounterData final : public Algorithm {
32public:
34 StatusCode execute() override;
35 StatusCode finalize() override;
36private:
38};
39
40// ----------------------------------------------------------------------------
41// Implementation file for class: ContextEventCounterPtr
42//
43// 27/10/2013: Marco Clemencic
44// ----------------------------------------------------------------------------
47
48// ============================================================================
49// Main execution
50// ============================================================================
52 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
53
54 if ( !m_ctxtSpecCounter ) {
55 m_ctxtSpecCounter = new int( 1 );
56 } else {
57 ++( *m_ctxtSpecCounter );
58 }
59 debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter.get() << " -> "
61
63}
64
65// ============================================================================
66// Finalize
67// ============================================================================
69 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
70
71 debug() << "Partial counts:" << endmsg;
72
73 info() << "Total count of events: "
74 << m_ctxtSpecCounter.accumulate(
75 [this]( const int* p ) {
76 const int r = ( p ? *p : 0 );
77 // print partial counts
78 this->debug() << " " << p << " -> " << r << endmsg;
79 return r;
80 },
81 0 )
82 << endmsg;
83
84 m_ctxtSpecCounter.deleteAll();
85
86 return Algorithm::finalize(); // must be called after all other actions
87}
88
89// ============================================================================
90// Main execution
91// ============================================================================
93 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
94
96 debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter << endmsg;
97
99}
100
101// ============================================================================
102// Finalize
103// ============================================================================
105 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
106
107 if ( msgLevel( MSG::DEBUG ) ) {
108 debug() << "Partial counts:" << endmsg;
109 m_ctxtSpecCounter.for_each( [this]( const int i ) { this->debug() << " " << i << endmsg; } );
110 }
111
112 info() << "Total count of events: " << m_ctxtSpecCounter.accumulate( 0 ) << endmsg;
113
114 return Algorithm::finalize(); // must be called after all other actions
115}
116
117// ============================================================================
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Gaudi::Hive::ContextSpecificData< int > m_ctxtSpecCounter
StatusCode finalize() override
Algorithm finalization.
StatusCode execute() override
Standard constructor.
StatusCode finalize() override
Algorithm finalization.
StatusCode execute() override
Standard constructor.
Gaudi::Hive::ContextSpecificPtr< int > m_ctxtSpecCounter
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition Algorithm.h:181
Implementation of a context specific storage accessible as a sort of smart reference class.
Simple implementation of a smart pointer with different values for different event contexts (slots).
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
GAUDI_API ContextIdType currentContextId()
Return the current context id.
@ DEBUG
Definition IMessageSvc.h:22