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