// IEvtSelector::first() StatusCode EventSelector::firstOfNextStream(bool shutDown, EvtSelectorContext& iter) const { StatusCode status = StatusCode::SUCCESS; IDataStreamTool::size_type iter_id = (m_reconfigure) ? 0 : iter.ID()+1; if ( m_reconfigure ) const_cast<EventSelector*>(this)->m_reconfigure = false; if ( shutDown ) { if ( iter.ID() >= 0 && iter.ID() < (long)m_streamtool->size() ) { const EventSelectorDataStream* s = m_streamtool->getStream(iter.ID()); if ( s->isInitialized() ) { EventSelector* thisPtr = const_cast<EventSelector*>(this); if ( s->selector() && iter.context() ) { Context* ctxt = iter.context(); s->selector()->releaseContext(ctxt).ignore(); iter.set(0,0); } status = thisPtr->m_streamtool->finalizeStream(const_cast<EventSelectorDataStream*>(s)); iter.set(0,0); } } } const EventSelectorDataStream* s ; status = m_streamtool->getNextStream( s , iter_id ); if ( status.isSuccess() ) { if(s!=NULL) { if ( !s->isInitialized() ) { EventSelector* thisPtr = const_cast<EventSelector*>(this); status = thisPtr->m_streamtool->initializeStream(const_cast<EventSelectorDataStream*>(s)); } if ( status.isSuccess() ) { const IEvtSelector* sel = s->selector(); if ( sel ) { Context* ctxt = 0; status = sel->createContext(ctxt); if ( status.isSuccess() ) { status = sel->resetCriteria(s->criteria(), *ctxt); if ( status.isSuccess() ) { MsgStream log(msgSvc(), name()); iter.set(this, iter_id, ctxt, 0); log << MSG::INFO << *s << endmsg; m_incidentSvc->fireIncident(Incident(s->dbName(),IncidentType::BeginInputFile)); return StatusCode::SUCCESS; } } } } m_incidentSvc->fireIncident(Incident(s->dbName(),IncidentType::FailInputFile)); } } iter.set(this, -1, 0, 0); status.setChecked(); //m_incidentSvc->fireIncident(Incident(s->dbName(),IncidentType::FailInputFile)); return StatusCode::FAILURE; }
StatusCode execute(){ if (m_eventCount == 0) { info() << "Firing incident " << m_incident << endmsg; m_incidentSvc->fireIncident(Incident(name(), m_incident)); } else if (m_eventCount > 0) { info() << m_eventCount << " events to go" << endmsg; } else { info() << "keep processing events..." << endmsg; } --m_eventCount; return StatusCode::SUCCESS; }
/// Get next iteration item from the event loop context, but skip jump elements StatusCode EventSelector::next(Context& refCtxt, int /* jump */ ) const { EvtSelectorContext *pIt = dynamic_cast<EvtSelectorContext*>(&refCtxt); if ( pIt ) { if ( pIt->ID() != -1 ) { const EventSelectorDataStream* s = m_streamtool->getStream(pIt->ID()); Context* it = pIt->context(); IEvtSelector* sel = s->selector(); if ( it && sel ) { // First exploit the current stream StatusCode sc = sel->next(*it); // This stream is empty: advance to the next stream if ( !sc.isSuccess() ) { m_incidentSvc->fireIncident(Incident(s->dbName(),IncidentType::EndInputFile)); sc = firstOfNextStream(true, *pIt); if (sc.isSuccess() ) sc = next(*pIt); } else { pIt->increaseCounters(false); pIt->set(it, 0); printEvtInfo(pIt); } return sc; } else if ( m_reconfigure ) { StatusCode sc = firstOfNextStream(false, *pIt); printEvtInfo(pIt); return sc; } } else if ( m_reconfigure ) { StatusCode sc = firstOfNextStream(false, *pIt); printEvtInfo(pIt); return sc; } pIt->increaseCounters(false); } printEvtInfo(pIt); return StatusCode::FAILURE; }
//-------------------------------------------------------------------------------------------- // implementation of IAppMgrUI::nextEvent //-------------------------------------------------------------------------------------------- StatusCode MTEventLoopMgr::nextEvent(int maxevt) { DataObject* pObject = 0; StatusCode sc; // loop over events if the maxevt (received as input) if different from -1. // if evtmax is -1 it means infinite loop for( int nevt = 0; (maxevt == -1 ? true : nevt < maxevt); nevt++, m_total_nevt++) { // Clear the event store, if used in the event loop if( 0 != m_total_nevt ) { sc = m_evtDataMgrSvc->clearStore(); if( !sc.isSuccess() ) { MsgStream log( msgSvc(), name() ); log << MSG::DEBUG << "Clear of Event data store failed" << endmsg; } } // Setup event in the event store if( m_evtCtxt ) { IOpaqueAddress* addr = 0; // Only if there is a EventSelector sc = getEventRoot(addr); if( !sc.isSuccess() ) { MsgStream log( msgSvc(), name() ); log << MSG::INFO << "No more events in event selection " << endmsg; break; } // Set root clears the event data store first sc = m_evtDataMgrSvc->setRoot ("/Event", addr); if( !sc.isSuccess() ) { MsgStream log( msgSvc(), name() ); log << MSG::WARNING << "Error declaring event root address." << endmsg; continue; } sc = m_evtDataSvc->retrieveObject("/Event", pObject); if( !sc.isSuccess() ) { MsgStream log( msgSvc(), name() ); log << MSG::WARNING << "Unable to retrieve Event root object" << endmsg; break; } } else { sc = m_evtDataMgrSvc->setRoot ("/Event", new DataObject()); if( !sc.isSuccess() ) { MsgStream log( msgSvc(), name() ); log << MSG::WARNING << "Error declaring event root DataObject" << endmsg; } } // Execute event for all required algorithms // Fire BeginEvent "Incident" m_incidentSvc->fireIncident(Incident(name(),IncidentType::BeginEvent)); // Execute Algorithms StatusCode sc = executeEvent(NULL); // Fire EndEvent "Incident" m_incidentSvc->fireIncident(Incident(name(),IncidentType::EndEvent)); if( !sc.isSuccess() ){ MsgStream log( msgSvc(), name() ); log << MSG::ERROR << "Terminating event processing loop due to errors" << endmsg; break; } } return StatusCode::SUCCESS; }
//============================================================================= StatusCode IncidentListenerTestAlg::execute() { info() << "Firing incident" << endmsg; m_incSvc->fireIncident(Incident(name(),incident())); return StatusCode::SUCCESS; }
StatusCode PythiaInterface::execute() { /// Interface for conversion from Pythia8::Event to HepMC event. HepMC::Pythia8ToHepMC *toHepMC = new HepMC::Pythia8ToHepMC(); /// Generate events. Quit if many failures in a raw while ( !m_pythia->next() ) { if (++iAbort > nAbort) { IIncidentSvc* incidentSvc; service("IncidentSvc",incidentSvc); incidentSvc->fireIncident(Incident(name(),IncidentType::AbortEvent)); return Error ( "Event generation aborted prematurely, owing to error!" ); } else{ warning () << "PythiaInterface Pythia8 abort : "<< iAbort << "/" <<nAbort<<std::endl; } } /// reset the counter to count failed events in a raw iAbort=0; /* for (int i = 0; i < m_pythia->event.size(); ++i){ //if (m_pythia->event[i].isFinal() && m_pythia->event[i].isCharged()) std::cout << "PythiaInterface : id : stat : px : py : pz : e : m : " << " " << m_pythia->event[i].id() << " " << m_pythia->event[i].status() //<< " " << m_pythia->event[i].mother1() //<< " " << m_pythia->event[i].mother2() //<< " " << m_pythia->event[i].daughter1() //<< " " << m_pythia->event[i].daughter2() << " " << m_pythia->event[i].px() << " " << m_pythia->event[i].py() << " " << m_pythia->event[i].pz() << " " << m_pythia->event[i].e() << " " << m_pythia->event[i].m() << std::endl; } */ /// Construct new emhepmcevtpty HepMC event HepMC::GenEvent* theEvent = new HepMC::GenEvent( HepMC::Units::GEV, HepMC::Units::MM); toHepMC->fill_next_event(*m_pythia,theEvent); //theEvent-> print(); /* for (HepMC::GenEvent::particle_iterator ipart = theEvent->particles_begin() ; ipart!=theEvent->particles_end(); ++ipart) std::cout << "HepMC : id : stat : px : py : pz : e : m : " << (*ipart)->pdg_id() << " " << (*ipart)->status() << " " << (*ipart)->momentum().px() << " " << (*ipart)->momentum().py() << " " << (*ipart)->momentum().pz() << " " << (*ipart)->momentum().e() << " " << (*ipart)->momentum().m() << std::endl; */ m_hepmchandle.put(theEvent); return StatusCode::SUCCESS; }