| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 // ----------------------------------------------------------------------------
13 DECLARE_ALGORITHM_FACTORY( ContextEventCounterPtr )
14 DECLARE_ALGORITHM_FACTORY( ContextEventCounterData )
15
16 // ============================================================================
17 // Standard constructor, initializes variables
18 // ============================================================================
19 ContextEventCounterPtr::ContextEventCounterPtr( const std::string& name, ISvcLocator* pSvcLocator )
20 : GaudiAlgorithm( name, pSvcLocator )
21 {
22 }
23
24 // ============================================================================
25 // Destructor
26 // ============================================================================
27 ContextEventCounterPtr::~ContextEventCounterPtr() {}
28
29 // ============================================================================
30 // Initialization
31 // ============================================================================
32 StatusCode ContextEventCounterPtr::initialize()
33 {
34 StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
35 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
36
37 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
38
39 return StatusCode::SUCCESS;
40 }
41
42 // ============================================================================
43 // Main execution
44 // ============================================================================
45 StatusCode ContextEventCounterPtr::execute()
46 {
47 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
48
49 if ( !m_ctxtSpecCounter ) {
50 m_ctxtSpecCounter = new int( 1 );
51 } else {
52 ++( *m_ctxtSpecCounter );
53 }
54 debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter.get() << " -> "
55 << *m_ctxtSpecCounter << endmsg;
56
57 return StatusCode::SUCCESS;
58 }
59
60 // ============================================================================
61 // Finalize
62 // ============================================================================
63 StatusCode ContextEventCounterPtr::finalize()
64 {
65 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
66
67 debug() << "Partial counts:" << endmsg;
68
69 info() << "Total count of events: "
70 << m_ctxtSpecCounter.accumulate(
71 [this]( const int* p ) -> int {
72 const int r = ( p ) ? *p : 0;
73 // print partial counts
74 this->debug() << " " << p << " -> " << r << endmsg;
75 return r;
76 },
77 0 )
78 << endmsg;
79
80 m_ctxtSpecCounter.deleteAll();
81
82 return GaudiAlgorithm::finalize(); // must be called after all other actions
83 }
84
85 // ============================================================================
86 // Standard constructor, initializes variables
87 // ============================================================================
88 ContextEventCounterData::ContextEventCounterData( const std::string& name, ISvcLocator* pSvcLocator )
89 : GaudiAlgorithm( name, pSvcLocator )
90 {
91 }
92
93 // ============================================================================
94 // Destructor
95 // ============================================================================
96 ContextEventCounterData::~ContextEventCounterData() {}
97
98 // ============================================================================
99 // Initialization
100 // ============================================================================
101 StatusCode ContextEventCounterData::initialize()
102 {
103 StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
104 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
105
106 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
107
108 return StatusCode::SUCCESS;
109 }
110
111 // ============================================================================
112 // Main execution
113 // ============================================================================
114 StatusCode ContextEventCounterData::execute()
115 {
116 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
117
118 ++m_ctxtSpecCounter;
119 debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter << endmsg;
120
121 return StatusCode::SUCCESS;
122 }
123
124 // ============================================================================
125 // Finalize
126 // ============================================================================
127 StatusCode ContextEventCounterData::finalize()
128 {
129 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
130
131 if ( msgLevel( MSG::DEBUG ) ) {
132 debug() << "Partial counts:" << endmsg;
133 m_ctxtSpecCounter.for_each( [this]( const int i ) { this->debug() << " " << i << endmsg; } );
134 }
135
136 info() << "Total count of events: " << m_ctxtSpecCounter.accumulate( 0 ) << endmsg;
137
138 return GaudiAlgorithm::finalize(); // must be called after all other actions
139 }
140
141 // ============================================================================
ContextEventCounterData::ContextEventCounterData
ContextEventCounterData(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition: ContextEventCounter.cpp:88
StatusCode::SUCCESS
Definition: StatusCode.h:31
Gaudi::Hive::currentContextId
GAUDI_API ContextIdType currentContextId()
Return the current context id.
Definition: ThreadLocalContext.cpp:22
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:731
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
ContextEventCounterPtr::~ContextEventCounterPtr
~ContextEventCounterPtr() override
Destructor.
Definition: ContextEventCounter.cpp:27
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:117
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:43
ContextEventCounterPtr::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: ContextEventCounter.cpp:63
ContextEventCounterData::m_ctxtSpecCounter
Gaudi::Hive::ContextSpecificData< int > m_ctxtSpecCounter
Definition: ContextEventCounter.h:42
MSG::DEBUG
Definition: IMessageSvc.h:16
std
STL namespace.
ContextEventCounterData::execute
StatusCode execute() override
Algorithm execution.
Definition: ContextEventCounter.cpp:114
ContextEventCounterPtr
Definition: ContextEventCounter.h:15
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
ContextEventCounterPtr::m_ctxtSpecCounter
Gaudi::Hive::ContextSpecificPtr< int > m_ctxtSpecCounter
Definition: ContextEventCounter.h:27
std::string
STL class.
ContextEventCounterData
Definition: ContextEventCounter.h:30
ContextEventCounter.h
ContextEventCounterPtr::initialize
StatusCode initialize() override
Algorithm initialization.
Definition: ContextEventCounter.cpp:32
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
ContextEventCounterPtr::execute
StatusCode execute() override
Algorithm execution.
Definition: ContextEventCounter.cpp:45
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:59
DECLARE_ALGORITHM_FACTORY
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:629
GaudiAlgorithm
The useful base class for data processing algorithms.
Definition: GaudiAlgorithm.h:94
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:120
ContextEventCounterData::~ContextEventCounterData
~ContextEventCounterData() override
Destructor.
Definition: ContextEventCounter.cpp:96
AlgFactory.h
ContextEventCounterData::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: ContextEventCounter.cpp:127
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:129
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
ContextEventCounterData::initialize
StatusCode initialize() override
Algorithm initialization.
Definition: ContextEventCounter.cpp:101