The Gaudi Framework
master (c53a8715)
Toggle main menu visibility
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
13
#include <
GaudiKernel/Algorithm.h
>
14
#include <
GaudiKernel/ContextSpecificPtr.h
>
15
22
class
ContextEventCounterPtr
final :
public
Algorithm
{
23
public
:
24
using
Algorithm::Algorithm
;
25
StatusCode
execute
()
override
;
26
StatusCode
finalize
()
override
;
27
private
:
28
Gaudi::Hive::ContextSpecificPtr<int>
m_ctxtSpecCounter
;
29
};
30
31
class
ContextEventCounterData
final :
public
Algorithm
{
32
public
:
33
using
Algorithm::Algorithm
;
34
StatusCode
execute
()
override
;
35
StatusCode
finalize
()
override
;
36
private
:
37
Gaudi::Hive::ContextSpecificData<int>
m_ctxtSpecCounter
;
38
};
39
40
// ----------------------------------------------------------------------------
41
// Implementation file for class: ContextEventCounterPtr
42
//
43
// 27/10/2013: Marco Clemencic
44
// ----------------------------------------------------------------------------
45
DECLARE_COMPONENT
(
ContextEventCounterPtr
)
46
DECLARE_COMPONENT
(
ContextEventCounterData
)
47
48
// ============================================================================
49
// Main execution
50
// ============================================================================
51
StatusCode
ContextEventCounterPtr
::
execute
() {
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() <<
" -> "
60
<< *
m_ctxtSpecCounter
<<
endmsg
;
61
62
return
StatusCode::SUCCESS
;
63
}
64
65
// ============================================================================
66
// Finalize
67
// ============================================================================
68
StatusCode
ContextEventCounterPtr::finalize
() {
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
// ============================================================================
92
StatusCode
ContextEventCounterData::execute
() {
93
if
(
msgLevel
(
MSG::DEBUG
) )
debug
() <<
"==> Execute"
<<
endmsg
;
94
95
++
m_ctxtSpecCounter
;
96
debug
() <<
"Context "
<<
Gaudi::Hive::currentContextId
() <<
" "
<<
m_ctxtSpecCounter
<<
endmsg
;
97
98
return
StatusCode::SUCCESS
;
99
}
100
101
// ============================================================================
102
// Finalize
103
// ============================================================================
104
StatusCode
ContextEventCounterData::finalize
() {
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
// ============================================================================
ContextSpecificPtr.h
Algorithm.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition
CommonMessaging.h:118
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:115
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition
CommonMessaging.h:127
ContextEventCounterData
Definition
ContextEventCounter.cpp:31
ContextEventCounterData::m_ctxtSpecCounter
Gaudi::Hive::ContextSpecificData< int > m_ctxtSpecCounter
Definition
ContextEventCounter.cpp:37
ContextEventCounterData::finalize
StatusCode finalize() override
Algorithm finalization.
Definition
ContextEventCounter.cpp:104
ContextEventCounterData::execute
StatusCode execute() override
Standard constructor.
Definition
ContextEventCounter.cpp:92
ContextEventCounterPtr
Definition
ContextEventCounter.cpp:22
ContextEventCounterPtr::finalize
StatusCode finalize() override
Algorithm finalization.
Definition
ContextEventCounter.cpp:68
ContextEventCounterPtr::execute
StatusCode execute() override
Standard constructor.
Definition
ContextEventCounter.cpp:51
ContextEventCounterPtr::m_ctxtSpecCounter
Gaudi::Hive::ContextSpecificPtr< int > m_ctxtSpecCounter
Definition
ContextEventCounter.cpp:28
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition
Algorithm.h:98
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition
Algorithm.h:181
Gaudi::Hive::ContextSpecificData
Implementation of a context specific storage accessible as a sort of smart reference class.
Definition
ContextSpecificPtr.h:147
Gaudi::Hive::ContextSpecificPtr
Simple implementation of a smart pointer with different values for different event contexts (slots).
Definition
ContextSpecificPtr.h:39
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
Gaudi::Hive::currentContextId
GAUDI_API ContextIdType currentContextId()
Return the current context id.
Definition
ThreadLocalContext.cpp:28
MSG::DEBUG
@ DEBUG
Definition
IMessageSvc.h:22
GaudiHive
src
ContextEventCounter.cpp
Generated on
for The Gaudi Framework by
1.17.0