| The Gaudi Framework v30r0 (c919700c)

- 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 // local
4 #include "ContextEventCounter.h"
5
6 // ----------------------------------------------------------------------------
7 // Implementation file for class: ContextEventCounterPtr
8 //
9 // 27/10/2013: Marco Clemencic
10 // ----------------------------------------------------------------------------
11 DECLARE_ALGORITHM_FACTORY( ContextEventCounterPtr )
12 DECLARE_ALGORITHM_FACTORY( ContextEventCounterData )
13
14 // ============================================================================
15 // Standard constructor, initializes variables
16 // ============================================================================
17 ContextEventCounterPtr::ContextEventCounterPtr( const std::string& name, ISvcLocator* pSvcLocator )
18 : GaudiAlgorithm( name, pSvcLocator )
19 {
20 }
21
22 // ============================================================================
23 // Destructor
24 // ============================================================================
25 ContextEventCounterPtr::~ContextEventCounterPtr() {}
26
27 // ============================================================================
28 // Initialization
29 // ============================================================================
30 StatusCode ContextEventCounterPtr::initialize()
31 {
32 StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
33 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
34
35 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
36
37 return StatusCode::SUCCESS;
38 }
39
40 // ============================================================================
41 // Main execution
42 // ============================================================================
43 StatusCode ContextEventCounterPtr::execute()
44 {
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() << " " << m_ctxtSpecCounter.get() << " -> "
53 << *m_ctxtSpecCounter << endmsg;
54
55 return StatusCode::SUCCESS;
56 }
57
58 // ============================================================================
59 // Finalize
60 // ============================================================================
61 StatusCode ContextEventCounterPtr::finalize()
62 {
63 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
64
65 debug() << "Partial counts:" << endmsg;
66
67 info() << "Total count of events: "
68 << m_ctxtSpecCounter.accumulate(
69 [this]( const int* p ) -> int {
70 const int r = ( p ) ? *p : 0;
71 // print partial counts
72 this->debug() << " " << p << " -> " << r << endmsg;
73 return r;
74 },
75 0 )
76 << endmsg;
77
78 m_ctxtSpecCounter.deleteAll();
79
80 return GaudiAlgorithm::finalize(); // must be called after all other actions
81 }
82
83 // ============================================================================
84 // Standard constructor, initializes variables
85 // ============================================================================
86 ContextEventCounterData::ContextEventCounterData( const std::string& name, ISvcLocator* pSvcLocator )
87 : GaudiAlgorithm( name, pSvcLocator )
88 {
89 }
90
91 // ============================================================================
92 // Destructor
93 // ============================================================================
94 ContextEventCounterData::~ContextEventCounterData() {}
95
96 // ============================================================================
97 // Initialization
98 // ============================================================================
99 StatusCode ContextEventCounterData::initialize()
100 {
101 StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
102 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
103
104 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
105
106 return StatusCode::SUCCESS;
107 }
108
109 // ============================================================================
110 // Main execution
111 // ============================================================================
112 StatusCode ContextEventCounterData::execute()
113 {
114 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
115
116 ++m_ctxtSpecCounter;
117 debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter << endmsg;
118
119 return StatusCode::SUCCESS;
120 }
121
122 // ============================================================================
123 // Finalize
124 // ============================================================================
125 StatusCode ContextEventCounterData::finalize()
126 {
127 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
128
129 if ( msgLevel( MSG::DEBUG ) ) {
130 debug() << "Partial counts:" << endmsg;
131 m_ctxtSpecCounter.for_each( [this]( const int i ) { this->debug() << " " << i << endmsg; } );
132 }
133
134 info() << "Total count of events: " << m_ctxtSpecCounter.accumulate( 0 ) << endmsg;
135
136 return GaudiAlgorithm::finalize(); // must be called after all other actions
137 }
138
139 // ============================================================================
ContextEventCounterData::ContextEventCounterData
ContextEventCounterData(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition: ContextEventCounter.cpp:86
StatusCode::SUCCESS
Definition: StatusCode.h:29
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:737
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
ContextEventCounterPtr::~ContextEventCounterPtr
~ContextEventCounterPtr() override
Destructor.
Definition: ContextEventCounter.cpp:25
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:112
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:43
ContextEventCounterPtr::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: ContextEventCounter.cpp:61
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:112
ContextEventCounterPtr
Definition: ContextEventCounter.h:15
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:61
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:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
ContextEventCounterPtr::execute
StatusCode execute() override
Algorithm execution.
Definition: ContextEventCounter.cpp:43
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:59
DECLARE_ALGORITHM_FACTORY
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:631
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:115
ContextEventCounterData::~ContextEventCounterData
~ContextEventCounterData() override
Destructor.
Definition: ContextEventCounter.cpp:94
ContextEventCounterData::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: ContextEventCounter.cpp:125
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:124
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:99