Gaudi Framework, version v23r9

Home   Generated: Thu Jul 18 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataStreamTool.cpp
Go to the documentation of this file.
1 // $Id: DataStreamTool.cpp,v 1.5 2008/04/04 15:12:19 marcocle Exp $
2 // Include files
3 
4 // from Gaudi
6 #include "GaudiKernel/xtoa.h"
7 #include "GaudiKernel/SmartIF.h"
8 #include "GaudiKernel/Incident.h"
10 #include "GaudiKernel/MsgStream.h"
19 #include "GaudiKernel/SvcFactory.h"
20 
21 #include <sstream>
22 
23 //-----------------------------------------------------------------------------
24 // Implementation file for class : DataStreamTool
25 //
26 // 2006-09-21 : Andres Felipe Osorio Oliveros
27 //-----------------------------------------------------------------------------
28 
29 // Declaration of the Tool Factory
30 // Now the declaration is done in GaudiSvc
31 //DECLARE_TOOL_FACTORY( DataStreamTool )
32 
33 //=============================================================================
34 // Standard constructor, initializes variables
35 //=============================================================================
37  const std::string& name,
38  const IInterface* parent )
39  : base_class ( type, name , parent )
40 {
41  //declareInterface<IDataStreamTool>(this);
42 
43  m_incidentSvc = 0;
44  m_streamCount = 0;
45  m_streamID = 0;
46 
47 }
48 //=============================================================================
49 // Destructor
50 //=============================================================================
52 }
53 
54 //=============================================================================
56 
57  MsgStream logger(msgSvc(), name());
58 
60  if( !status.isSuccess() ) {
61  logger << MSG::FATAL << "Error. Cannot initialize base class." << endmsg;
62  return status;
63  }
64 
65  // Get the references to the services that are needed by the ApplicationMgr itself
66  m_incidentSvc = serviceLocator()->service("IncidentSvc");
67  if( !m_incidentSvc.isValid() ) {
68  logger << MSG::FATAL << "Error retrieving IncidentSvc." << endmsg;
69  return StatusCode::FAILURE;
70  }
71 
72  return StatusCode::SUCCESS;
73 
74 }
75 
77 
78  if ( NULL != getStream(input) ) {
79  MsgStream log(msgSvc(), name());
80  log << MSG::WARNING << "Input stream " << input << "already in use" << endmsg;
81  }
82 
83  m_streamSpecs.push_back(input);
84 
85  std::ostringstream strname;
86  strname << name() << '_' << ++m_streamCount;
87 
89 
90  StatusCode status = createStream(strname.str(), input , s );
91 
92  if( status.isSuccess() && 0 != s ) {
93  s->addRef();
95  status = StatusCode::SUCCESS;
96  }
97  else {
98  MsgStream log(msgSvc(), name());
99  if (s) {
100  s->release();
101  log << MSG::ERROR << "Error connecting/creating Stream: " << s << endmsg;
102  }
103  log << MSG::ERROR << "Error connecting/creating Stream: " << input << endmsg;
104  status = StatusCode::FAILURE;
105  }
106 
107  return status;
108 
109 }
110 
112 
114 
115  for ( StreamSpecs::const_iterator itr = inputs.begin(); itr != inputs.end() && status.isSuccess(); ++itr ) {
116 
117  status = addStream(*itr);
118 
119  }
120 
121  return status;
122 
123 }
124 
126  clear().ignore();
127  m_incidentSvc = 0; // release
128 
129  return AlgTool::finalize();
130 }
131 
133  IEvtSelector* sel = 0;
134  StatusCode status = s->initialize();
135  if ( status.isSuccess() ) {
136  status = createSelector(s->name(), s->selectorType(), sel);
137  if ( status.isSuccess() ) {
138  SmartIF<IProperty> prop(sel); //Att: IProperty, IService used to point to EventSelector
139  SmartIF<IService> isvc(sel);
140  s->setSelector(sel);
141  sel->release(); // No need of this interface anymore, it is passed to the stream
142  if ( prop.isValid( ) && isvc.isValid( ) ) {
143  const Properties& p = s->properties();
144  for(Properties::const_iterator i=p.begin(); i!=p.end(); i++) {
145  prop->setProperty((*i)).ignore();
146  }
147  int output_level = this->outputLevel();
148  prop->setProperty(IntegerProperty("OutputLevel",output_level)).ignore();
149  // FIXME: (MCl) Why do we have to initialize the selector here?
150  return isvc->sysInitialize();
151  }
152  }
153  }
154  return StatusCode::FAILURE;
155 }
156 
157 // Create (sub-) Event selector service
159  IService* isvc = ROOT::Reflex::PluginService::Create<IService*>(typ, nam, serviceLocator());
160  if ( isvc ) {
161  StatusCode status = isvc->queryInterface(IEvtSelector::interfaceID(), (void**)&sel);
162  if ( status.isSuccess() ) {
163  return status;
164  }
165  sel = 0;
166  isvc->release();
167  }
168  MsgStream log(msgSvc(), name());
169  log << MSG::ERROR << "Failed to create IEvtSelector " << typ << "/" << nam << endmsg;
170  return StatusCode::FAILURE;
171 }
172 
173 
175  if ( s ) {
176  IEvtSelector* sel = const_cast<IEvtSelector*>(s->selector());
177  if ( sel ) {
178  SmartIF<IService> isvc(sel);
179  if ( isvc.isValid() ) {
180  isvc->finalize().ignore();
181  s->finalize().ignore();
182  // Fire EndStream "Incident"
184  return StatusCode::SUCCESS;
185  }
186  // Failed to get service interface of sub-event selector
187  return StatusCode::FAILURE;
188  }
189  // No selector (yet) attached - no need to finalize it!
190  return StatusCode::SUCCESS;
191  }
192  return StatusCode::FAILURE;
193 }
194 
195 
197 
199 
200  if ( m_streams.end() != i ) {
201  (*i)->release();
202  m_streams.erase(i);
203  return StatusCode::SUCCESS;
204  }
205 
206  return StatusCode::FAILURE;
207 }
208 
210  EventSelectorDataStream*& stream) {
211  stream = new EventSelectorDataStream(nam, info, serviceLocator());
212 
213  return StatusCode::SUCCESS;
214 }
215 
216 
219  if ( m_streams.end() == i ) return NULL;
220  return *i;
221 }
222 
224  for ( Streams::iterator i = m_streams.begin(); i != m_streams.end(); i++ ) {
225  if ( (*i)->definition() == info ) {
226  return i;
227  }
228  }
229  return m_streams.end();
230 }
231 
233  if ( (pos >= 0) && ((size_t)pos < m_streams.size()) ) // pos has to point inside the vector
234  return m_streams[pos];
235  else
236  return 0;
237 }
238 
240 {
241  if (m_streams.size() > 1 )
242  return *(--m_streams.end());
243  else return *m_streams.begin();
244 
245 }
246 
247 
248 
250 {
251 
252  StatusCode iret, status = StatusCode::SUCCESS;
253  iret.ignore();
254 
255  MsgStream log(msgSvc(), name());
256 
257  // disconnect the streams
258  for ( StreamSpecs::const_iterator il = m_streamSpecs.begin(); il != m_streamSpecs.end(); il++ ) {
260  if ( NULL != s ) {
261  if ( s->isInitialized() ) {
262  iret = finalizeStream(s);
263  if ( !iret.isSuccess() ) {
264  log << MSG::ERROR << "Error finalizing Stream" << *il << endmsg;
265  status = iret;
266  }
267  }
268  iret = eraseStream( *il );
269  if ( !iret.isSuccess() ) {
270  log << MSG::ERROR << "Error diconnecting Stream" << *il << endmsg;
271  status = iret;
272  }
273  }
274  }
275 
277 
278  return status;
279 }
280 
281 
283 {
284 
285  if ( 0 != s ) {
286  s->addRef();
287  m_streams.push_back(s);
288  return StatusCode::SUCCESS;
289  }
290 
291  return StatusCode::FAILURE;
292 
293 }
294 
296 {
297 
298  if ( NULL != getStream(info) ) {
299  MsgStream log(msgSvc(), name());
300  log << MSG::WARNING << "Input stream " << info << "already in use" << endmsg;
301  }
302  std::ostringstream nam;
303  nam << name() << '_' << ++m_streamCount;
305  StatusCode status = createStream(nam.str(), info, s);
306  if ( status.isSuccess() ) {
307  return connectStream(s);
308  }
309  s->release();
310  return status;
311 
312 
313 }
314 
315 /*
316 
317  Taking control over Streams and return them to EventSelector
318 
319 */
320 
321 
323 {
324 
325  EventSelectorDataStream * nextStream = getStream(dsid);
326  if ( NULL == nextStream ) return StatusCode::FAILURE; //<-end of streams reached
327 
328  esds = nextStream;
329  ++m_streamID;
330 
331  return StatusCode::SUCCESS;
332 
333 }
334 
336 {
337 
338  EventSelectorDataStream * previousStream = getStream(dsid);
339  if ( NULL == previousStream ) return StatusCode::FAILURE; //<-begin of streams reached
340 
341  esds = previousStream;
342  --m_streamID;
343 
344  return StatusCode::SUCCESS;
345 
346 }
347 
348 
349 

Generated at Thu Jul 18 2013 12:18:04 for Gaudi Framework, version v23r9 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004