| The Gaudi Framework v27r1

- 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 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 // ============================================================================
44 StatusCode ContextEventCounterPtr::execute() {
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 // ============================================================================
61 StatusCode ContextEventCounterPtr::finalize() {
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 // ============================================================================
83 ContextEventCounterData::ContextEventCounterData(const std::string& name, ISvcLocator* pSvcLocator)
84 : GaudiAlgorithm(name, pSvcLocator)
85 {
86 }
87
88 // ============================================================================
89 // Destructor
90 // ============================================================================
91 ContextEventCounterData::~ContextEventCounterData() {}
92
93 // ============================================================================
94 // Initialization
95 // ============================================================================
96 StatusCode ContextEventCounterData::initialize() {
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 // ============================================================================
108 StatusCode ContextEventCounterData::execute() {
109 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
110
111 ++m_ctxtSpecCounter;
112 debug() << "Context " << Gaudi::Hive::currentContextId() << " "
113 << m_ctxtSpecCounter << endmsg;
114
115 return StatusCode::SUCCESS;
116 }
117
118 // ============================================================================
119 // Finalize
120 // ============================================================================
121 StatusCode ContextEventCounterData::finalize() {
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::ContextEventCounterData
ContextEventCounterData(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition: ContextEventCounter.cpp:83
Gaudi::Hive::currentContextId
GAUDI_API ContextIdType currentContextId()
Return the current context id.
Definition: ThreadLocalContext.cpp:8
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:48
ContextEventCounterData::m_ctxtSpecCounter
Gaudi::Hive::ContextSpecificData< int > m_ctxtSpecCounter
Definition: ContextEventCounter.h:42
ContextEventCounterData::~ContextEventCounterData
virtual ~ContextEventCounterData()
Destructor.
Definition: ContextEventCounter.cpp:91
MSG::DEBUG
Definition: IMessageSvc.h:18
ContextEventCounterPtr::~ContextEventCounterPtr
virtual ~ContextEventCounterPtr()
Destructor.
Definition: ContextEventCounter.cpp:27
std
STL namespace.
ContextEventCounterPtr
Definition: ContextEventCounter.h:15
ContextEventCounterData::finalize
virtual StatusCode finalize()
Algorithm finalization.
Definition: ContextEventCounter.cpp:121
merge_files.sc
int sc
Definition: merge_files.py:167
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
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:62
DECLARE_ALGORITHM_FACTORY
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:777
GaudiAlgorithm
The useful base class for data processing algorithms.
Definition: GaudiAlgorithm.h:93
ContextEventCounterData::initialize
virtual StatusCode initialize()
Algorithm initialization.
Definition: ContextEventCounter.cpp:96
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
ContextEventCounterPtr::initialize
virtual StatusCode initialize()
Algorithm initialization.
Definition: ContextEventCounter.cpp:32
ContextEventCounterPtr::finalize
virtual StatusCode finalize()
Algorithm finalization.
Definition: ContextEventCounter.cpp:61
AlgFactory.h
ContextEventCounterPtr::execute
virtual StatusCode execute()
Algorithm execution.
Definition: ContextEventCounter.cpp:44
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
ana.i
list i
Definition: ana.py:128
ContextEventCounterData::execute
virtual StatusCode execute()
Algorithm execution.
Definition: ContextEventCounter.cpp:108
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244