| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ReplayOutputStream.cpp
Go to the documentation of this file.
1 // Include files
2
3 // From Gaudi
4 #include "GaudiKernel/AlgFactory.h"
5 #include "GaudiKernel/IAlgManager.h"
6 #include "GaudiKernel/IDataManagerSvc.h"
7 #include "GaudiKernel/IDataStoreAgent.h"
8 // local
9 #include "ReplayOutputStream.h"
10 #include "RecordOutputStream.h"
11
12 #include <algorithm>
13 #include <functional>
14 #include <list>
15
16 // ----------------------------------------------------------------------------
17 // Implementation file for class: ReplayOutputStream
18 //
19 // 30/08/2013: Marco Clemencic
20 // ----------------------------------------------------------------------------
21 DECLARE_ALGORITHM_FACTORY(ReplayOutputStream)
22
23 // ============================================================================
24 // Standard constructor, initializes variables
25 // ============================================================================
26 ReplayOutputStream::ReplayOutputStream(const std::string& name, ISvcLocator* pSvcLocator)
27 : GaudiAlgorithm(name, pSvcLocator)
28 {
29 declareProperty("OutputStreams", m_outputStreamNames,
30 "OutputStream instances that can be called.");
31 }
32
33 // ============================================================================
34 // Destructor
35 // ============================================================================
36 ReplayOutputStream::~ReplayOutputStream() {}
37
38 namespace {
39
41 template <Gaudi::StateMachine::Transition TR>
42 class OutStreamTransition {
43 public:
44 typedef ReplayOutputStream::OutStreamsMapType::value_type ItemType;
45 OutStreamTransition(MsgStream &msg):
46 m_msg(msg),
47 m_code(StatusCode::SUCCESS, false)
48 {}
49
50 void operator() (ItemType &item);
51
52 StatusCode result() const { return m_code; }
53 private:
54 MsgStream &m_msg;
55 StatusCode m_code;
56 };
57
58 template <>
59 void OutStreamTransition<Gaudi::StateMachine::INITIALIZE>::operator() (ItemType &item) {
60 const StatusCode sc = item.second->sysInitialize();
61 if (sc.isFailure()) {
62 m_msg << MSG::WARNING << "Failed to initialize " << item.first << endmsg;
63 m_code = sc;
64 }
65 }
66 template <>
67 void OutStreamTransition<Gaudi::StateMachine::START>::operator() (ItemType &item) {
68 const StatusCode sc = item.second->sysStart();
69 if (sc.isFailure()) {
70 m_msg << MSG::WARNING << "Failed to start " << item.first << endmsg;
71 m_code = sc;
72 }
73 }
74 template <>
75 void OutStreamTransition<Gaudi::StateMachine::STOP>::operator() (ItemType &item) {
76 const StatusCode sc = item.second->sysStop();
77 if (sc.isFailure()) {
78 m_msg << MSG::WARNING << "Failed to stop " << item.first << endmsg;
79 m_code = sc;
80 }
81 }
82 template <>
83 void OutStreamTransition<Gaudi::StateMachine::FINALIZE>::operator() (ItemType &item) {
84 const StatusCode sc = item.second->sysFinalize();
85 if (sc.isFailure()) {
86 m_msg << MSG::WARNING << "Failed to finalize " << item.first << endmsg;
87 m_code = sc;
88 }
89 }
90
91 }
92
93 template <Gaudi::StateMachine::Transition TR>
94 StatusCode ReplayOutputStream::i_outStreamTransition() {
95 OutStreamTransition<TR> trans(msg());
96 std::for_each(m_outputStreams.begin(), m_outputStreams.end(), trans);
97 return trans.result();
98 }
99
100 // ============================================================================
101 // Initialization
102 // ============================================================================
103 StatusCode ReplayOutputStream::initialize() {
104 StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
105 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
106
107 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
108
109 m_algMgr = service("ApplicationMgr");
110 if (UNLIKELY(!m_algMgr.isValid())) {
111 return Error("cannot retrieve IAlgManager");
112 }
113
114 m_evtMgr = evtSvc();
115 if (UNLIKELY(!m_algMgr.isValid())) {
116 return Error("cannot retrieve IDataManagerSvc ");
117 }
118
119 std::for_each(m_outputStreamNames.begin(), m_outputStreamNames.end(),
120 OutStreamAdder(this));
121
122 return i_outStreamTransition<Gaudi::StateMachine::INITIALIZE>();
123 }
124
125 StatusCode ReplayOutputStream::start() {
126 StatusCode sc = GaudiAlgorithm::start(); // must be executed first
127 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
128
129 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Start" << endmsg;
130
131 return i_outStreamTransition<Gaudi::StateMachine::START>();
132 }
133
134
135 namespace {
138 struct OutputStreamsCollector: public IDataStoreAgent {
139 std::list<std::string> names;
140 virtual bool analyse(IRegistry* pRegistry, int lvl) {
141 if (lvl > 0)
142 names.push_back(pRegistry->name());
143 return true;
144 }
145 };
146 }
147
148 // ============================================================================
149 // Main execution
150 // ============================================================================
151 StatusCode ReplayOutputStream::execute() {
152 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
153
154 OutputStreamsCollector collector;
155 m_evtMgr->traverseSubTree(RecordOutputStream::locationRoot(), &collector);
156
157 std::for_each(collector.names.begin(), collector.names.end(),
158 OutStreamTrigger(this));
159
160 return StatusCode::SUCCESS;
161 }
162
163 // ============================================================================
164 // Finalize
165 // ============================================================================
166 StatusCode ReplayOutputStream::finalize() {
167 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
168
169 StatusCode sc = i_outStreamTransition<Gaudi::StateMachine::FINALIZE>();
170
171 // release interfaces
172 m_outputStreams.clear();
173 m_algMgr.reset();
174 m_evtMgr.reset();
175
176 StatusCode fsc = GaudiAlgorithm::finalize(); // must be called after all other actions
177 if (sc.isSuccess()) sc = fsc;
178 return sc;
179 }
180
181 StatusCode ReplayOutputStream::stop() {
182 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Stop" << endmsg;
183
184 StatusCode sc = i_outStreamTransition<Gaudi::StateMachine::STOP>();
185
186 StatusCode ssc = GaudiAlgorithm::stop(); // must be called after all other actions
187 if (sc.isSuccess()) sc = ssc;
188 return sc;
189 }
190
191 void ReplayOutputStream::i_addOutputStream(const Gaudi::Utils::TypeNameString &outStream) {
192 // we prepend '/' to the name of the algorithm to simplify the handling in
193 // OutputStreamsCollector
194 const std::string algId = "/" + outStream.name();
195 if (m_outputStreams.find(algId) == m_outputStreams.end()) {
196 if (!(m_outputStreams[algId] = m_algMgr->algorithm(outStream)).isValid()){
197 throw GaudiException(name(), "Could not get algorithm " + outStream.name(),
198 StatusCode::FAILURE);
199 }
200 } else {
201 warning() << "OutputStream instance " << outStream.name()
202 << " already added, ignoring " << outStream << endmsg;
203 }
204 }
205
206 // ============================================================================