239 {
240
241
242 StatusCode status = StatusCode::FAILURE;
243 MsgStream log(
msgSvc(), name() );
244
245 if ( 0 == m_appMgrUI ) return status;
246
247 IProperty* propMgr = 0;
248 status = serviceLocator()->service( "ApplicationMgr", propMgr );
249 if ( status.isFailure() )
250 {
251 log << MSG::ERROR << "Unable to locate PropertyManager Service" << endmsg;
252 return status;
253 }
254
255 IntegerProperty evtMax( "EvtMax", 0 );
256 status = propMgr->getProperty( &evtMax );
257 if ( status.isFailure() ) return status;
258
259
260
261 IntegerProperty rootEvtMax( "EvtMax", m_rootEvtMax );
262 if ( rootEvtMax < evtMax ) setProperty( rootEvtMax );
263 else setProperty( evtMax );
264
265
266
267 IAlgManager* theAlgMgr;
268 status = serviceLocator()->getService( "ApplicationMgr", IAlgManager::interfaceID(),
269 (IInterface*&)theAlgMgr );
270 IAlgorithm* theIAlg;
271 Algorithm* theAlgorithm = 0;
272 IntegerProperty errorProperty( "ErrorCount", 0 );
273
274 status = theAlgMgr->getAlgorithm( "Top", theIAlg );
275 if ( status.isSuccess() )
276 {
277 try
278 { theAlgorithm = dynamic_cast<Algorithm*>( theIAlg ); } catch ( ... )
279 { status = StatusCode::FAILURE; }
280 }
281 if ( status.isFailure() )
282 {
283 log << MSG::WARNING << "Could not find algorithm 'Top'; will not monitor errors" << endmsg;
284 }
285
286
287
288 int eventNumber = 0;
289 double currentTime = m_startTime;
290
291 {
292 bool noend = true;
293 log << MSG::INFO << "Runable interface starting event loop as :";
294 if ( m_evtMax > 0 )
295 {
296 log << " MaxEvt = " << m_evtMax;
297 noend = false;
298 }
299 if ( m_endTime > 0 )
300 {
301 log << " EndTime= " << m_endTime;
302 noend = false;
303 }
304 log << endmsg;
305
306 if ( noend )
307 {
308 log << MSG::WARNING << "No end condition specified: will not process any events!"
309 << endmsg;
310 }
311 }
312
313 while ( m_evtMax > 0 && eventNumber < m_evtMax || m_endTime > 0 && currentTime < m_endTime )
314 {
315
316 status = m_appMgrUI->nextEvent( 1 );
317
318
319
320 if ( theAlgorithm != 0 ) theAlgorithm->getProperty( &errorProperty );
321 if ( status.isFailure() || errorProperty.value() > 0 ) { status = StatusCode::FAILURE; }
322
323 if ( status.isFailure() ) break;
324
325
326
327 eventNumber++;
328 }
329 if ( status.isFailure() )
330 { log << MSG::ERROR << "Terminating RootIoSvc loop due to error" << endmsg; }
331 else if ( m_endTime > 0 && currentTime >= m_endTime )
332 { log << MSG::INFO << "Loop terminated by time " << endmsg; }
333 else { log << MSG::INFO << "Processing loop terminated by event count" << endmsg; }
334 return status;
335}