| The Gaudi Framework v30r0 (c919700c)

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