| The Gaudi Framework v28r2p1 (f1a77ff4)

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

- File List
- File Members

DataStreamTool.cpp
Go to the documentation of this file.
1 // Include files
2
3 // from Gaudi
4 #include "GaudiKernel/DataStreamTool.h"
5 #include "GaudiKernel/EventSelectorDataStream.h"
6 #include "GaudiKernel/IAddressCreator.h"
7 #include "GaudiKernel/ISvcLocator.h"
8 #include "GaudiKernel/ISvcManager.h"
9 #include "GaudiKernel/Incident.h"
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/MsgStream.h"
12 #include "GaudiKernel/PropertyHolder.h"
13 #include "GaudiKernel/Service.h"
14 #include "GaudiKernel/SmartIF.h"
15
16 //-----------------------------------------------------------------------------
17 // Implementation file for class : DataStreamTool
18 //
19 // 2006-09-21 : Andres Felipe Osorio Oliveros
20 //-----------------------------------------------------------------------------
21
22 //=============================================================================
23 // Standard constructor, initializes variables
24 //=============================================================================
25 DataStreamTool::DataStreamTool( const std::string& type, const std::string& name, const IInterface* parent )
26 : base_class( type, name, parent )
27 {
28 // declareInterface<IDataStreamTool>(this);
29 }
30 //=============================================================================
31 StatusCode DataStreamTool::initialize()
32 {
33
34 StatusCode status = AlgTool::initialize();
35 if ( !status.isSuccess() ) {
36 fatal() << "Error. Cannot initialize base class." << endmsg;
37 return status;
38 }
39
40 // Get the references to the services that are needed by the ApplicationMgr itself
41 m_incidentSvc = serviceLocator()->service( "IncidentSvc" );
42 if ( !m_incidentSvc ) {
43 fatal() << "Error retrieving IncidentSvc." << endmsg;
44 return StatusCode::FAILURE;
45 }
46
47 return StatusCode::SUCCESS;
48 }
49
50 StatusCode DataStreamTool::addStream( const std::string& input )
51 {
52
53 if ( getStream( input ) ) {
54 warning() << "Input stream " << input << "already in use" << endmsg;
55 }
56
57 m_streamSpecs.push_back( input );
58
59 auto strname = name() + '_' + std::to_string( ++m_streamCount );
60 EventSelectorDataStream* s = nullptr;
61
62 StatusCode status = createStream( strname, input, s );
63
64 if ( status.isSuccess() && s ) {
65 s->addRef();
66 m_streams.push_back( s );
67 status = StatusCode::SUCCESS;
68 } else {
69 if ( s ) {
70 s->release();
71 error() << "Error connecting/creating Stream: " << s << endmsg;
72 }
73 error() << "Error connecting/creating Stream: " << input << endmsg;
74 status = StatusCode::FAILURE;
75 }
76 return status;
77 }
78
79 StatusCode DataStreamTool::addStreams( const StreamSpecs& inputs )
80 {
81
82 StatusCode status = StatusCode::SUCCESS;
83 for ( auto& i : inputs ) {
84 status = addStream( i );
85 if ( !status.isSuccess() ) break;
86 }
87 return status;
88 }
89
90 StatusCode DataStreamTool::finalize()
91 {
92 clear().ignore();
93 m_incidentSvc.reset();
94 return AlgTool::finalize();
95 }
96
97 StatusCode DataStreamTool::initializeStream( EventSelectorDataStream* s )
98 {
99 IEvtSelector* sel = nullptr;
100 StatusCode status = s->initialize();
101 if ( status.isSuccess() ) {
102 status = createSelector( s->name(), s->selectorType(), sel );
103 if ( status.isSuccess() ) {
104 SmartIF<IProperty> prop( sel ); // Att: IProperty, IService used to point to EventSelector
105 SmartIF<IService> isvc( sel );
106 s->setSelector( sel );
107 sel->release(); // No need for this interface anymore, it is passed to the stream
108 if ( prop && isvc ) {
109 for ( const auto& i : s->properties() ) prop->setProperty( i ).ignore();
110 prop->setProperty( Gaudi::Property<int>( "OutputLevel", msgLevel() ) ).ignore();
111 // FIXME: (MCl) Why do we have to initialize the selector here?
112 return isvc->sysInitialize();
113 }
114 }
115 }
116 return StatusCode::FAILURE;
117 }
118
119 // Create (sub-) Event selector service
120 StatusCode DataStreamTool::createSelector( const std::string& nam, const std::string& typ, IEvtSelector*& sel )
121 {
122 auto isvc = make_SmartIF( Service::Factory::create( typ, nam, serviceLocator() ) );
123 if ( isvc ) {
124 auto isel = isvc.as<IEvtSelector>();
125 if ( isel ) {
126 sel = isel.get();
127 sel->addRef(); // make sure that sel is not left dangling once isel and isvc go out of scope...
128 return StatusCode::SUCCESS;
129 }
130 }
131 sel = nullptr;
132 error() << "Failed to create IEvtSelector " << typ << "/" << nam << endmsg;
133 return StatusCode::FAILURE;
134 }
135
136 StatusCode DataStreamTool::finalizeStream( EventSelectorDataStream* s )
137 {
138 if ( s ) {
139 IEvtSelector* sel = s->selector();
140 if ( sel ) {
141 SmartIF<IService> isvc( sel );
142 if ( isvc ) {
143 isvc->finalize().ignore();
144 s->finalize().ignore();
145 // Fire EndStream "Incident"
146 m_incidentSvc->fireIncident( Incident( name(), IncidentType::EndStream ) );
147 return StatusCode::SUCCESS;
148 }
149 // Failed to get service interface of sub-event selector
150 return StatusCode::FAILURE;
151 }
152 // No selector (yet) attached - no need to finalize it!
153 return StatusCode::SUCCESS;
154 }
155 return StatusCode::FAILURE;
156 }
157
158 StatusCode DataStreamTool::eraseStream( const std::string& info )
159 {
160
161 auto i = getStreamIterator( info );
162 if ( i != m_streams.end() ) {
163 ( *i )->release();
164 m_streams.erase( i );
165 return StatusCode::SUCCESS;
166 }
167 return StatusCode::FAILURE;
168 }
169
170 StatusCode DataStreamTool::createStream( const std::string& nam, const std::string& info,
171 EventSelectorDataStream*& stream )
172 {
173 stream = new EventSelectorDataStream( nam, info, serviceLocator() );
174 return StatusCode::SUCCESS;
175 }
176
177 EventSelectorDataStream* DataStreamTool::getStream( const std::string& info )
178 {
179 auto i = getStreamIterator( info );
180 return i != m_streams.end() ? *i : nullptr;
181 }
182
183 DataStreamTool::Streams::iterator DataStreamTool::getStreamIterator( const std::string& info )
184 {
185 return std::find_if( std::begin( m_streams ), std::end( m_streams ),
186 [&]( const EventSelectorDataStream* i ) { return i->definition() == info; } );
187 }
188
189 EventSelectorDataStream* DataStreamTool::getStream( size_type pos )
190 {
191 // pos has to point inside the vector
192 return ( ( pos >= 0 ) && ( (size_t)pos < m_streams.size() ) ) ? m_streams[pos] : nullptr;
193 }
194
195 EventSelectorDataStream* DataStreamTool::lastStream() { return m_streams.back(); }
196
197 StatusCode DataStreamTool::clear()
198 {
199
200 StatusCode iret, status = StatusCode::SUCCESS;
201 iret.ignore();
202
203 // disconnect the streams
204 for ( auto& il : m_streamSpecs ) {
205 EventSelectorDataStream* s = getStream( il );
206 if ( s ) {
207 if ( s->isInitialized() ) {
208 iret = finalizeStream( s );
209 if ( !iret.isSuccess() ) {
210 error() << "Error finalizing Stream" << il << endmsg;
211 status = iret;
212 }
213 }
214 iret = eraseStream( il );
215 if ( !iret.isSuccess() ) {
216 error() << "Error diconnecting Stream" << il << endmsg;
217 status = iret;
218 }
219 }
220 }
221
222 m_streamSpecs.clear();
223
224 return status;
225 }
226
227 StatusCode DataStreamTool::connectStream( EventSelectorDataStream* s )
228 {
229
230 if ( !s ) return StatusCode::FAILURE;
231 s->addRef();
232 m_streams.push_back( s );
233 return StatusCode::SUCCESS;
234 }
235
236 StatusCode DataStreamTool::connectStream( const std::string& info )
237 {
238 if ( getStream( info ) ) {
239 warning() << "Input stream " << info << "already in use" << endmsg;
240 }
241 auto nam = name() + '_' + std::to_string( ++m_streamCount );
242 EventSelectorDataStream* s = nullptr;
243 StatusCode status = createStream( nam, info, s );
244 if ( status.isSuccess() ) return connectStream( s );
245 s->release();
246 return status;
247 }
248
249 /*
250
251 Taking control over Streams and return them to EventSelector
252
253 */
254
255 StatusCode DataStreamTool::getNextStream( const EventSelectorDataStream*& esds, size_type& dsid )
256 {
257
258 EventSelectorDataStream* nextStream = getStream( dsid );
259 if ( !nextStream ) return StatusCode::FAILURE; //<-end of streams reached
260
261 esds = nextStream;
262 ++m_streamID;
263
264 return StatusCode::SUCCESS;
265 }
266
267 StatusCode DataStreamTool::getPreviousStream( const EventSelectorDataStream*& esds, size_type& dsid )
268 {
269
270 EventSelectorDataStream* previousStream = getStream( dsid );
271 if ( !previousStream ) return StatusCode::FAILURE; //<-begin of streams reached
272
273 esds = previousStream;
274 --m_streamID;
275
276 return StatusCode::SUCCESS;
277 }
EventSelectorDataStream::isInitialized
bool isInitialized() const
Check initialization status.
Definition: EventSelectorDataStream.h:105
PropertyHolder.h
StatusCode::SUCCESS
Definition: StatusCode.h:30
DataStreamTool::getStreamIterator
Streams::iterator getStreamIterator(const std::string &)
Definition: DataStreamTool.cpp:183
SmartIF< IProperty >
EventSelectorDataStream::name
const std::string & name() const
Retrieve stream name.
Definition: EventSelectorDataStream.h:93
DataStreamTool::getNextStream
StatusCode getNextStream(const EventSelectorDataStream *&, size_type &) override
Definition: DataStreamTool.cpp:255
AlgTool::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: AlgTool.cpp:84
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
StatusCode::FAILURE
Definition: StatusCode.h:29
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:314
MsgStream.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:123
AlgTool::initialize
StatusCode initialize() override
Definition: AlgTool.cpp:227
DataStreamTool::clear
StatusCode clear() override
Definition: DataStreamTool.cpp:197
IEvtSelector
The Event Selector Interface.
Definition: IEvtSelector.h:18
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
std::to_string
T to_string(T...args)
EventSelectorDataStream::selector
IEvtSelector * selector() const
Retrieve event selector object.
Definition: EventSelectorDataStream.h:103
IOTest.sel
sel
Definition: IOTest.py:84
DataStreamTool::createStream
StatusCode createStream(const std::string &, const std::string &, EventSelectorDataStream *&) override
Definition: DataStreamTool.cpp:170
std::vector::end
T end(T...args)
DataStreamTool::initializeStream
StatusCode initializeStream(EventSelectorDataStream *) override
Initialize newly opened stream.
Definition: DataStreamTool.cpp:97
ISvcManager.h
std::string
STL class.
Incident.h
Service.h
DataStreamTool::finalize
StatusCode finalize() override
Definition: DataStreamTool.cpp:90
AlgTool::finalize
StatusCode finalize() override
Definition: AlgTool.cpp:297
IService::sysInitialize
virtual StatusCode sysInitialize()=0
Initialize Service.
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
std::vector::push_back
T push_back(T...args)
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
IProperty::setProperty
virtual StatusCode setProperty(const Gaudi::Details::PropertyBase &p)=0
Set the property by property.
EventSelectorDataStream::initialize
virtual StatusCode initialize()
Parse input criteria.
Definition: EventSelectorDataStream.cpp:62
IIncidentSvc::fireIncident
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:120
DataStreamTool.h
BrunelScenarioForwardScheduler.inputs
inputs
Definition: BrunelScenarioForwardScheduler.py:123
DataStreamTool::lastStream
EventSelectorDataStream * lastStream() override
Definition: DataStreamTool.cpp:195
implements::addRef
unsigned long addRef() override
Reference Interface instance.
Definition: implements.h:44
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IInterface
Definition of the basic interface.
Definition: IInterface.h:234
gaudirun.type
type
Definition: gaudirun.py:125
EventSelectorDataStream::finalize
virtual StatusCode finalize()
Finalize stream and release resources.
Definition: EventSelectorDataStream.cpp:188
SmartIF.h
DataStreamTool::finalizeStream
StatusCode finalizeStream(EventSelectorDataStream *) override
Finalize no longer needed stream.
Definition: DataStreamTool.cpp:136
std::vector::erase
T erase(T...args)
DataStreamTool::createSelector
StatusCode createSelector(const std::string &, const std::string &, IEvtSelector *&) override
Definition: DataStreamTool.cpp:120
EventSelectorDataStream.h
DataStreamTool::m_incidentSvc
SmartIF< IIncidentSvc > m_incidentSvc
Reference to the incident service.
Definition: DataStreamTool.h:94
DataStreamTool::connectStream
StatusCode connectStream(EventSelectorDataStream *)
Connect single stream by reference.
Definition: DataStreamTool.cpp:227
DataStreamTool::DataStreamTool
DataStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: DataStreamTool.cpp:25
DataStreamTool::getStream
EventSelectorDataStream * getStream(const std::string &) override
Retrieve stream by name.
Definition: DataStreamTool.cpp:177
DataStreamTool::addStream
StatusCode addStream(const std::string &) override
Definition: DataStreamTool.cpp:50
DataStreamTool::eraseStream
StatusCode eraseStream(const std::string &) override
Definition: DataStreamTool.cpp:158
EventSelectorDataStream::definition
const std::string & definition() const
Retrieve definition string.
Definition: EventSelectorDataStream.h:101
std::find_if
T find_if(T...args)
std::vector::size
T size(T...args)
AlgTool::name
const std::string & name() const override
Retrieve full identifying name of the concrete tool object.
Definition: AlgTool.cpp:63
IInterface::release
virtual unsigned long release()=0
Release Interface instance.
DataStreamTool::initialize
StatusCode initialize() override
Definition: DataStreamTool.cpp:31
DataStreamTool::m_streamID
size_type m_streamID
Definition: DataStreamTool.h:85
IAddressCreator.h
std::begin
T begin(T...args)
EventSelectorDataStream
Definition of class EventSelectorDataStream.
Definition: EventSelectorDataStream.h:45
DataStreamTool::getPreviousStream
StatusCode getPreviousStream(const EventSelectorDataStream *&, size_type &) override
Definition: DataStreamTool.cpp:267
EventSelectorDataStream::selectorType
const std::string & selectorType() const
Retrieve event selector type.
Definition: EventSelectorDataStream.h:99
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
DataStreamTool::m_streamCount
size_type m_streamCount
Definition: DataStreamTool.h:87
std::vector::back
T back(T...args)
gaudirun.s
string s
Definition: gaudirun.py:245
CommonMessaging
Definition: CommonMessaging.h:55
IInterface::addRef
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
DataStreamTool::addStreams
StatusCode addStreams(const StreamSpecs &) override
Definition: DataStreamTool.cpp:79
make_SmartIF
SmartIF< IFace > make_SmartIF(IFace *iface)
Definition: SmartIF.h:143
EventSelectorDataStream::properties
const Properties & properties()
Access properties.
Definition: EventSelectorDataStream.h:91
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:106
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:111
DataStreamTool::m_streams
Streams m_streams
Definition: DataStreamTool.h:89
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:135
ISvcLocator.h
EventSelectorDataStream::setSelector
virtual void setSelector(IEvtSelector *pSelector)
Attach event selector object.
Definition: EventSelectorDataStream.cpp:43
DataStreamTool::m_streamSpecs
StreamSpecs m_streamSpecs
Definition: DataStreamTool.h:91
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
implements::release
unsigned long release() override
Release Interface instance.
Definition: implements.h:46