| The Gaudi Framework v27r1

- 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 // ============================================================================
23 // Standard constructor, initializes variables
24 // ============================================================================
25 ReplayOutputStream::ReplayOutputStream(const std::string& name, ISvcLocator* pSvcLocator)
26 : GaudiAlgorithm(name, pSvcLocator)
27 {
28 declareProperty("OutputStreams", m_outputStreamNames,
29 "OutputStream instances that can be called.");
30 }
31
32 // ============================================================================
33 // Destructor
34 // ============================================================================
35 ReplayOutputStream::~ReplayOutputStream() {}
36
37 namespace {
38
40 template <Gaudi::StateMachine::Transition TR>
41 class OutStreamTransition {
42 public:
43 typedef ReplayOutputStream::OutStreamsMapType::value_type ItemType;
44 OutStreamTransition(MsgStream &msg):
45 m_msg(msg),
46 m_code(StatusCode::SUCCESS, false)
47 {}
48
49 void operator() (ItemType &item);
50
51 StatusCode result() const { return m_code; }
52 private:
53 MsgStream &m_msg;
54 StatusCode m_code;
55 };
56
57 template <>
58 void OutStreamTransition<Gaudi::StateMachine::INITIALIZE>::operator() (ItemType &item) {
59 const StatusCode sc = item.second->sysInitialize();
60 if (sc.isFailure()) {
61 m_msg << MSG::WARNING << "Failed to initialize " << item.first << endmsg;
62 m_code = sc;
63 }
64 }
65 template <>
66 void OutStreamTransition<Gaudi::StateMachine::START>::operator() (ItemType &item) {
67 const StatusCode sc = item.second->sysStart();
68 if (sc.isFailure()) {
69 m_msg << MSG::WARNING << "Failed to start " << item.first << endmsg;
70 m_code = sc;
71 }
72 }
73 template <>
74 void OutStreamTransition<Gaudi::StateMachine::STOP>::operator() (ItemType &item) {
75 const StatusCode sc = item.second->sysStop();
76 if (sc.isFailure()) {
77 m_msg << MSG::WARNING << "Failed to stop " << item.first << endmsg;
78 m_code = sc;
79 }
80 }
81 template <>
82 void OutStreamTransition<Gaudi::StateMachine::FINALIZE>::operator() (ItemType &item) {
83 const StatusCode sc = item.second->sysFinalize();
84 if (sc.isFailure()) {
85 m_msg << MSG::WARNING << "Failed to finalize " << item.first << endmsg;
86 m_code = sc;
87 }
88 }
89
90 }
91
92 template <Gaudi::StateMachine::Transition TR>
93 StatusCode ReplayOutputStream::i_outStreamTransition() {
94 OutStreamTransition<TR> trans(msg());
95 std::for_each(m_outputStreams.begin(), m_outputStreams.end(), trans);
96 return trans.result();
97 }
98
99 // ============================================================================
100 // Initialization
101 // ============================================================================
102 StatusCode ReplayOutputStream::initialize() {
103 StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
104 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
105
106 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
107
108 m_algMgr = service("ApplicationMgr");
109 if (UNLIKELY(!m_algMgr)) return Error("cannot retrieve IAlgManager");
110
111 m_evtMgr = evtSvc();
112 if (UNLIKELY(!m_evtMgr)) return Error("cannot retrieve IDataManagerSvc ");
113
114 std::for_each(m_outputStreamNames.begin(), m_outputStreamNames.end(),
115 OutStreamAdder(this));
116
117 return i_outStreamTransition<Gaudi::StateMachine::INITIALIZE>();
118 }
119
120 StatusCode ReplayOutputStream::start() {
121 StatusCode sc = GaudiAlgorithm::start(); // must be executed first
122 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
123
124 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Start" << endmsg;
125
126 return i_outStreamTransition<Gaudi::StateMachine::START>();
127 }
128
129
130 namespace {
133 struct OutputStreamsCollector: public IDataStoreAgent {
134 std::list<std::string> names;
135 virtual bool analyse(IRegistry* pRegistry, int lvl) {
136 if (lvl > 0)
137 names.push_back(pRegistry->name());
138 return true;
139 }
140 };
141 }
142
143 // ============================================================================
144 // Main execution
145 // ============================================================================
146 StatusCode ReplayOutputStream::execute() {
147 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
148
149 OutputStreamsCollector collector;
150 m_evtMgr->traverseSubTree(RecordOutputStream::locationRoot(), &collector);
151
152 std::for_each(collector.names.begin(), collector.names.end(),
153 OutStreamTrigger(this));
154
155 return StatusCode::SUCCESS;
156 }
157
158 // ============================================================================
159 // Finalize
160 // ============================================================================
161 StatusCode ReplayOutputStream::finalize() {
162 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
163
164 StatusCode sc = i_outStreamTransition<Gaudi::StateMachine::FINALIZE>();
165
166 // release interfaces
167 m_outputStreams.clear();
168 m_algMgr.reset();
169 m_evtMgr.reset();
170
171 StatusCode fsc = GaudiAlgorithm::finalize(); // must be called after all other actions
172 if (sc.isSuccess()) sc = fsc;
173 return sc;
174 }
175
176 StatusCode ReplayOutputStream::stop() {
177 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Stop" << endmsg;
178
179 StatusCode sc = i_outStreamTransition<Gaudi::StateMachine::STOP>();
180
181 StatusCode ssc = GaudiAlgorithm::stop(); // must be called after all other actions
182 if (sc.isSuccess()) sc = ssc;
183 return sc;
184 }
185
186 void ReplayOutputStream::i_addOutputStream(const Gaudi::Utils::TypeNameString &outStream) {
187 // we prepend '/' to the name of the algorithm to simplify the handling in
188 // OutputStreamsCollector
189 const std::string algId = "/" + outStream.name();
190 if (m_outputStreams.find(algId) == m_outputStreams.end()) {
191 m_outputStreams[algId] = m_algMgr->algorithm(outStream);
192 if (!m_outputStreams[algId]) {
193 throw GaudiException(name(), "Could not get algorithm " + outStream.name(),
194 StatusCode::FAILURE);
195 }
196 } else {
197 warning() << "OutputStream instance " << outStream.name()
198 << " already added, ignoring " << outStream << endmsg;
199 }
200 }
201
202 // ============================================================================
IAlgManager::algorithm
virtual SmartIF< IAlgorithm > & algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:133
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ReplayOutputStream
Definition: ReplayOutputStream.h:18
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
ReplayOutputStream::finalize
virtual StatusCode finalize()
Algorithm finalization.
Definition: ReplayOutputStream.cpp:161
GaudiMP.FdsRegistry.msg
tuple msg
Definition: FdsRegistry.py:8
ReplayOutputStream::m_outputStreams
OutStreamsMapType m_outputStreams
Internal storage for the OutputStreams to call.
Definition: ReplayOutputStream.h:79
ReplayOutputStream::OutStreamTrigger
Helper class to call the required OutputStream.
Definition: ReplayOutputStream.h:51
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:48
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
IDataStoreAgent::analyse
virtual bool analyse(IRegistry *pObject, int level)=0
Analyse the data object.
GaudiCommon< Algorithm >::Error
StatusCode Error(const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the error message and return with the given StatusCode.
ReplayOutputStream::stop
virtual StatusCode stop()
Algorithm finalization.
Definition: ReplayOutputStream.cpp:176
ReplayOutputStream::start
virtual StatusCode start()
Algorithm initialization.
Definition: ReplayOutputStream.cpp:120
MSG::DEBUG
Definition: IMessageSvc.h:18
ReplayOutputStream::~ReplayOutputStream
virtual ~ReplayOutputStream()
Destructor.
Definition: ReplayOutputStream.cpp:35
std
STL namespace.
IRegistry::name
virtual const name_type & name() const =0
Name of the directory (or key)
std::vector::end
T end(T...args)
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
std::string
STL class.
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:820
ReplayOutputStream::i_outStreamTransition
StatusCode i_outStreamTransition()
Helper function to call the transition on the contained OutputStreams.
Definition: ReplayOutputStream.cpp:93
std::list::push_back
T push_back(T...args)
IDataManagerSvc.h
GaudiUtils::Map::end
iterator end()
Definition: Map.h:132
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:9
GaudiPython.Bindings.SUCCESS
tuple SUCCESS
Definition: Bindings.py:51
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
StatusCode::FAILURE
Definition: StatusCode.h:29
ReplayOutputStream::execute
virtual StatusCode execute()
Algorithm execution.
Definition: ReplayOutputStream.cpp:146
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
GaudiUtils::Map::find
iterator find(const key_type &key)
Definition: Map.h:149
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
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:186
ReplayOutputStream::m_outputStreamNames
std::vector< std::string > m_outputStreamNames
(property) Type/Name list of OutputStream we have to call.
Definition: ReplayOutputStream.h:77
std::list< std::string >
ReplayOutputStream::OutStreamAdder
Helper class to fill the internal map of OutputStreams.
Definition: ReplayOutputStream.h:40
IDataStoreAgent.h
GaudiUtils::Map::begin
iterator begin()
Definition: Map.h:131
std::pair
Algorithm::evtSvc
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition: Algorithm.h:284
RecordOutputStream.h
IDataStoreAgent
Generic data agent interface.
Definition: IDataStoreAgent.h:16
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
std::vector::begin
T begin(T...args)
Algorithm::start
StatusCode start() override
the default (empty) implementation of IStateful::start() method
Definition: Algorithm.h:183
ana.item
tuple item
print s1,s2
Definition: ana.py:146
IAlgManager.h
GaudiUtils::Map::clear
void clear()
Definition: Map.h:178
MSG::WARNING
Definition: IMessageSvc.h:20
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
Gaudi::Utils::TypeNameString::name
const std::string & name() const
Definition: TypeNameString.h:23
ReplayOutputStream::m_evtMgr
SmartIF< IDataManagerSvc > m_evtMgr
Definition: ReplayOutputStream.h:82
Algorithm::service
StatusCode service(const std::string &name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Algorithm.h:232
Algorithm::stop
StatusCode stop() override
the default (empty) implementation of IStateful::stop() method
Definition: Algorithm.h:185
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
std::for_each
T for_each(T...args)
IDataManagerSvc::traverseSubTree
virtual StatusCode traverseSubTree(const std::string &sub_path, IDataStoreAgent *pAgent)=0
Analyse by traversing all data objects below the sub tree identified by its full path name...
ReplayOutputStream::m_algMgr
SmartIF< IAlgManager > m_algMgr
Definition: ReplayOutputStream.h:81
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
ReplayOutputStream::initialize
virtual StatusCode initialize()
Algorithm initialization.
Definition: ReplayOutputStream.cpp:102