| The Gaudi Framework v28r2-patches (bc4ad17a)

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

- File List
- File Members

ReplayOutputStream.cpp
Go to the documentation of this file.
1 // Include files
2
3 // From Gaudi
4 #include "GaudiKernel/IAlgManager.h"
5 #include "GaudiKernel/IDataManagerSvc.h"
6 #include "GaudiKernel/IDataStoreAgent.h"
7 // local
8 #include "ReplayOutputStream.h"
9 #include "RecordOutputStream.h"
10
11 #include <algorithm>
12 #include <functional>
13 #include <list>
14
15 // ----------------------------------------------------------------------------
16 // Implementation file for class: ReplayOutputStream
17 //
18 // 30/08/2013: Marco Clemencic
19 // ----------------------------------------------------------------------------
20 DECLARE_ALGORITHM_FACTORY(ReplayOutputStream)
21
22 namespace {
23
25 template <Gaudi::StateMachine::Transition TR>
26 class OutStreamTransition {
27 public:
28 typedef ReplayOutputStream::OutStreamsMapType::value_type ItemType;
29 OutStreamTransition(MsgStream &msg):
30 m_msg(msg),
31 m_code(StatusCode::SUCCESS, false)
32 {}
33
34 void operator() (ItemType &item);
35
36 StatusCode result() const { return m_code; }
37 private:
38 MsgStream &m_msg;
39 StatusCode m_code;
40 };
41
42 template <>
43 void OutStreamTransition<Gaudi::StateMachine::INITIALIZE>::operator() (ItemType &item) {
44 const StatusCode sc = item.second->sysInitialize();
45 if (sc.isFailure()) {
46 m_msg << MSG::WARNING << "Failed to initialize " << item.first << endmsg;
47 m_code = sc;
48 }
49 }
50 template <>
51 void OutStreamTransition<Gaudi::StateMachine::START>::operator() (ItemType &item) {
52 const StatusCode sc = item.second->sysStart();
53 if (sc.isFailure()) {
54 m_msg << MSG::WARNING << "Failed to start " << item.first << endmsg;
55 m_code = sc;
56 }
57 }
58 template <>
59 void OutStreamTransition<Gaudi::StateMachine::STOP>::operator() (ItemType &item) {
60 const StatusCode sc = item.second->sysStop();
61 if (sc.isFailure()) {
62 m_msg << MSG::WARNING << "Failed to stop " << item.first << endmsg;
63 m_code = sc;
64 }
65 }
66 template <>
67 void OutStreamTransition<Gaudi::StateMachine::FINALIZE>::operator() (ItemType &item) {
68 const StatusCode sc = item.second->sysFinalize();
69 if (sc.isFailure()) {
70 m_msg << MSG::WARNING << "Failed to finalize " << item.first << endmsg;
71 m_code = sc;
72 }
73 }
74
75 }
76
77 template <Gaudi::StateMachine::Transition TR>
78 StatusCode ReplayOutputStream::i_outStreamTransition() {
79 OutStreamTransition<TR> trans(msg());
80 std::for_each(m_outputStreams.begin(), m_outputStreams.end(), trans);
81 return trans.result();
82 }
83
84 // ============================================================================
85 // Initialization
86 // ============================================================================
87 StatusCode ReplayOutputStream::initialize() {
88 StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
89 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
90
91 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
92
93 m_algMgr = service("ApplicationMgr");
94 if (UNLIKELY(!m_algMgr)) return Error("cannot retrieve IAlgManager");
95
96 m_evtMgr = evtSvc();
97 if (UNLIKELY(!m_evtMgr)) return Error("cannot retrieve IDataManagerSvc ");
98
99 std::for_each(m_outputStreamNames.begin(), m_outputStreamNames.end(),
100 OutStreamAdder(this));
101
102 return i_outStreamTransition<Gaudi::StateMachine::INITIALIZE>();
103 }
104
105 StatusCode ReplayOutputStream::start() {
106 StatusCode sc = GaudiAlgorithm::start(); // must be executed first
107 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
108
109 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Start" << endmsg;
110
111 return i_outStreamTransition<Gaudi::StateMachine::START>();
112 }
113
114
115 namespace {
118 struct OutputStreamsCollector: public IDataStoreAgent {
119 std::list<std::string> names;
120 bool analyse(IRegistry* pRegistry, int lvl) override {
121 if (lvl > 0)
122 names.push_back(pRegistry->name());
123 return true;
124 }
125 };
126 }
127
128 // ============================================================================
129 // Main execution
130 // ============================================================================
131 StatusCode ReplayOutputStream::execute() {
132 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
133
134 OutputStreamsCollector collector;
135 m_evtMgr->traverseSubTree(RecordOutputStream::locationRoot(), &collector);
136
137 std::for_each(collector.names.begin(), collector.names.end(),
138 OutStreamTrigger(this));
139
140 return StatusCode::SUCCESS;
141 }
142
143 // ============================================================================
144 // Finalize
145 // ============================================================================
146 StatusCode ReplayOutputStream::finalize() {
147 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
148
149 StatusCode sc = i_outStreamTransition<Gaudi::StateMachine::FINALIZE>();
150
151 // release interfaces
152 m_outputStreams.clear();
153 m_algMgr.reset();
154 m_evtMgr.reset();
155
156 StatusCode fsc = GaudiAlgorithm::finalize(); // must be called after all other actions
157 if (sc.isSuccess()) sc = fsc;
158 return sc;
159 }
160
161 StatusCode ReplayOutputStream::stop() {
162 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Stop" << endmsg;
163
164 StatusCode sc = i_outStreamTransition<Gaudi::StateMachine::STOP>();
165
166 StatusCode ssc = GaudiAlgorithm::stop(); // must be called after all other actions
167 if (sc.isSuccess()) sc = ssc;
168 return sc;
169 }
170
171 void ReplayOutputStream::i_addOutputStream(const Gaudi::Utils::TypeNameString &outStream) {
172 // we prepend '/' to the name of the algorithm to simplify the handling in
173 // OutputStreamsCollector
174 const std::string algId = "/" + outStream.name();
175 if (m_outputStreams.find(algId) == m_outputStreams.end()) {
176 m_outputStreams[algId] = m_algMgr->algorithm(outStream);
177 if (!m_outputStreams[algId]) {
178 throw GaudiException(name(), "Could not get algorithm " + outStream.name(),
179 StatusCode::FAILURE);
180 }
181 } else {
182 warning() << "OutputStream instance " << outStream.name()
183 << " already added, ignoring " << outStream << endmsg;
184 }
185 }
186
187 // ============================================================================
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode::SUCCESS
Definition: StatusCode.h:30
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
ReplayOutputStream
Definition: ReplayOutputStream.h:19
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
StatusCode::FAILURE
Definition: StatusCode.h:29
ReplayOutputStream::OutStreamTrigger
Helper class to call the required OutputStream.
Definition: ReplayOutputStream.h:50
ReplayOutputStream::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: ReplayOutputStream.cpp:146
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:44
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
GaudiPython.Bindings.SUCCESS
SUCCESS
Definition: Bindings.py:52
MSG::DEBUG
Definition: IMessageSvc.h:18
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
IRegistry::name
virtual const name_type & name() const =0
Name of the directory (or key)
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
std::string
STL class.
ReplayOutputStream::i_outStreamTransition
StatusCode i_outStreamTransition()
Helper function to call the transition on the contained OutputStreams.
Definition: ReplayOutputStream.cpp:78
std::list::push_back
T push_back(T...args)
IDataManagerSvc.h
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:12
ReplayOutputStream::stop
StatusCode stop() override
Algorithm finalization.
Definition: ReplayOutputStream.cpp:161
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:58
DECLARE_ALGORITHM_FACTORY
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:620
ReplayOutputStream.h
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
ReplayOutputStream::i_addOutputStream
void i_addOutputStream(const Gaudi::Utils::TypeNameString &outStream)
Add a new algorithm to the list of OutputStreams.
Definition: ReplayOutputStream.cpp:171
std::list< std::string >
ReplayOutputStream::OutStreamAdder
Helper class to fill the internal map of OutputStreams.
Definition: ReplayOutputStream.h:40
IDataStoreAgent.h
std::pair
RecordOutputStream.h
ReplayOutputStream::execute
StatusCode execute() override
Algorithm execution.
Definition: ReplayOutputStream.cpp:131
IDataStoreAgent
Generic data agent interface.
Definition: IDataStoreAgent.h:16
Gaudi::Functional::operator()
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
ReplayOutputStream::start
StatusCode start() override
Algorithm initialization.
Definition: ReplayOutputStream.cpp:105
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
Algorithm::start
StatusCode start() override
the default (empty) implementation of IStateful::start() method
Definition: Algorithm.h:180
ReplayOutputStream::initialize
StatusCode initialize() override
Algorithm initialization.
Definition: ReplayOutputStream.cpp:87
IAlgManager.h
MSG::WARNING
Definition: IMessageSvc.h:20
Gaudi::Utils::TypeNameString::name
const std::string & name() const
Definition: TypeNameString.h:40
Algorithm::stop
StatusCode stop() override
the default (empty) implementation of IStateful::stop() method
Definition: Algorithm.h:182
std::for_each
T for_each(T...args)
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
RecordOutputStream::locationRoot
static const std::string locationRoot()
Return the path in the Transient Store used to record the triggered instances.
Definition: RecordOutputStream.h:33