Gaudi Framework, version v23r0 |
Home | Generated: Mon Jan 30 2012 |
Definition of class EventSelector. More...
#include <EventSelector.h>
Public Types | |
typedef std::vector < EventSelectorDataStream * > | Streams |
typedef std::vector< std::string > | StreamSpecs |
typedef std::vector < StringProperty > | Properties |
Public Member Functions | |
virtual StatusCode | initialize () |
IService implementation: Db event selector override. | |
virtual StatusCode | finalize () |
IService implementation: Service finalization. | |
virtual StatusCode | reinitialize () |
Service override: Reinitialize service. | |
virtual StatusCode | createContext (Context *&refpCtxt) const |
Create a new event loop context. | |
virtual StatusCode | next (Context &refCtxt) const |
Get next iteration item from the event loop context. | |
virtual StatusCode | next (Context &refCtxt, int jump) const |
Get next iteration item from the event loop context, but skip jump elements. | |
virtual StatusCode | previous (Context &refCtxt) const |
Get previous iteration item from the event loop context. | |
virtual StatusCode | previous (Context &refCtxt, int jump) const |
Get previous iteration item from the event loop context, but skip jump elements. | |
virtual StatusCode | rewind (Context &refCtxt) const |
Rewind the dataset. | |
virtual StatusCode | createAddress (const Context &refCtxt, IOpaqueAddress *&refpAddr) const |
Create new Opaque address corresponding to the current record. | |
virtual StatusCode | releaseContext (Context *&refCtxt) const |
Release existing event iteration context. | |
virtual StatusCode | resetCriteria (const std::string &cr, Context &c) const |
Will set a new criteria for the selection of the next list of events and will change the state of the context in a way to point to the new list. | |
virtual StatusCode | last (Context &c) const |
Access last item in the iteration. | |
StatusCode | firstOfNextStream (bool shutDown, EvtSelectorContext &it) const |
Retrieve first entry of the next data stream. | |
StatusCode | lastOfPreviousStream (bool shutDown, EvtSelectorContext &it) const |
Retrieve last entry of the previous data stream. | |
EventSelector (const std::string &name, ISvcLocator *svcloc) | |
Standard Constructor. | |
virtual | ~EventSelector () |
Standard Destructor. | |
Public Attributes | |
long int | m_streamID |
Protected Member Functions | |
virtual void | printEvtInfo (const EvtSelectorContext *iter) const |
Progress report. | |
Protected Attributes | |
SmartIF< IIncidentSvc > | m_incidentSvc |
Reference to the indicent service. | |
SmartIF< IToolSvc > | m_toolSvc |
IDataStreamTool * | m_streamtool |
bool | m_reconfigure |
Reconfigure occurred. | |
StreamSpecs | m_streamSpecs |
Input stream specifiers (for job options) | |
StreamSpecs | m_streamSpecsLast |
Input stream specifiers (last used) | |
Streams | m_streams |
Input streams. | |
int | m_streamCount |
Input stream counter (0..oo, monotonely increasing) | |
int | m_firstEvent |
First event to be processed. | |
int | m_evtMax |
Maximum number of events to be processed. | |
int | m_evtPrintFrequency |
Printout frequency. | |
std::string | m_streamManager |
Definition of class EventSelector.
Basic event selector service. The event selector service itself is able to connect other services to attached streams.
History: +---------+----------------------------------------------+------------+ | Date | Comment | Who | +---------+----------------------------------------------+------------+ | 3/10/00 | Initial version | M.Frank | +---------+----------------------------------------------+------------+ | 4/09/09 | Added firing incident on opening/ending file | R. Lambert | +---------+----------------------------------------------+------------+
Definition at line 53 of file EventSelector.h.
Definition at line 57 of file EventSelector.h.
Definition at line 55 of file EventSelector.h.
Definition at line 56 of file EventSelector.h.
EventSelector::EventSelector | ( | const std::string & | name, |
ISvcLocator * | svcloc | ||
) |
Standard Constructor.
Definition at line 27 of file EventSelector.cpp.
: base_class( name, svcloc) { m_incidentSvc = 0; m_toolSvc = 0; m_streamCount = 0; m_firstEvent = 0; m_evtPrintFrequency = 10; m_evtMax = INT_MAX; declareProperty( "Input", m_streamSpecs); declareProperty( "FirstEvent", m_firstEvent); declareProperty( "EvtMax", m_evtMax); declareProperty( "PrintFreq", m_evtPrintFrequency); declareProperty( "StreamManager", m_streamManager="DataStreamTool"); m_reconfigure = false; }
EventSelector::~EventSelector | ( | ) | [virtual] |
StatusCode EventSelector::createAddress | ( | const Context & | refCtxt, |
IOpaqueAddress *& | refpAddr | ||
) | const [virtual] |
Create new Opaque address corresponding to the current record.
refCtxt | [IN/OUT] Reference to the context |
refpAddr | [OUT] Reference to address pointer |
Implements IEvtSelector.
Definition at line 335 of file EventSelector.cpp.
{ const EvtSelectorContext *cpIt = dynamic_cast<const EvtSelectorContext*>(&refCtxt); EvtSelectorContext *pIt = const_cast<EvtSelectorContext*>(cpIt); refpAddr = 0; if ( pIt ) { const EventSelectorDataStream* s = m_streamtool->getStream(pIt->ID()); Context* it = pIt->context(); IEvtSelector* sel = s->selector(); if ( it && sel ) { IOpaqueAddress* pAddr = 0; StatusCode sc = sel->createAddress(*it, pAddr); if ( sc.isSuccess() ) { refpAddr = pAddr; } pIt->set(it, pAddr); return sc; } } return StatusCode::FAILURE; }
StatusCode EventSelector::createContext | ( | Context *& | refpCtxt ) | const [virtual] |
Create a new event loop context.
refpCtxt | [IN/OUT] Reference to pointer to store the context |
Implements IEvtSelector.
Definition at line 194 of file EventSelector.cpp.
{ // Max event is zero. Return begin = end refpCtxt = 0; if ( m_firstEvent < 0 ) { MsgStream log(msgSvc(), name()); log << MSG::ERROR << "First Event = " << m_firstEvent << " not valid" << endmsg; log << MSG::ERROR << "It should be > 0 " << endmsg; return StatusCode::FAILURE; // if failure => iterators = end(); } EvtSelectorContext* ctxt = new EvtSelectorContext(this); ctxt->set(0, -1, 0, 0); firstOfNextStream(true, *ctxt).ignore(); refpCtxt = ctxt; long nskip = m_firstEvent; while( --nskip > 0 ) { StatusCode sc = next(*refpCtxt); if ( sc.isFailure() ) { MsgStream log(msgSvc(), name()); log << MSG::ERROR << " createContext() failed to start with event number " << m_firstEvent << endmsg; releaseContext(refpCtxt); refpCtxt = 0; return StatusCode::FAILURE; } } return StatusCode::SUCCESS; }
StatusCode EventSelector::finalize | ( | ) | [virtual] |
IService implementation: Service finalization.
Reimplemented from Service.
Definition at line 452 of file EventSelector.cpp.
{ MsgStream log(msgSvc(), name()); log << MSG::DEBUG << "finalize()" << endmsg; m_incidentSvc = 0; if (m_streamtool) { if (m_toolSvc.isValid()) { m_toolSvc->releaseTool(m_streamtool).ignore(); } else { // It should not be possible to get here m_streamtool->release(); } m_streamtool = 0; } m_toolSvc = 0; return Service::finalize(); }
StatusCode EventSelector::firstOfNextStream | ( | bool | shutDown, |
EvtSelectorContext & | it | ||
) | const |
Retrieve first entry of the next data stream.
Definition at line 83 of file EventSelector.cpp.
{ 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->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; } } } } if(s!=NULL) { 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 EventSelector::initialize | ( | ) | [virtual] |
IService implementation: Db event selector override.
Reimplemented from Service.
Definition at line 382 of file EventSelector.cpp.
{ // Initialize base class StatusCode status = Service::initialize(); MsgStream logger(msgSvc(), name()); if ( !status.isSuccess() ) { logger << MSG::ERROR << "Error initializing base class Service!" << endmsg; return status; } // Get the references to the services that are needed by the ApplicationMgr itself m_incidentSvc = serviceLocator()->service("IncidentSvc"); if( !m_incidentSvc.isValid() ) { logger << MSG::FATAL << "Error retrieving IncidentSvc." << endmsg; return StatusCode::FAILURE; } if ( m_evtMax != INT_MAX ) { logger << MSG::ERROR << "EvtMax is an obsolete property of the event selector." << endmsg; logger << MSG::ERROR << "Please set \"ApplicationMgr.EvtMax = " << m_evtMax << ";\" to process the requested number of events." << endmsg; return StatusCode::FAILURE; } m_toolSvc = serviceLocator()->service("ToolSvc"); if ( !m_toolSvc.isValid() ) { logger << MSG::ERROR << " Could not locate the Tool Service! " << endmsg; return StatusCode::FAILURE; } status = m_toolSvc->retrieveTool(m_streamManager.c_str(), m_streamtool, this); if( status.isFailure() ) { logger << MSG::ERROR << "Error initializing " << m_streamManager << endmsg; return status; } status = m_streamtool->clear(); if( status.isFailure() ) { // Message already printed by the tool return status; } status = m_streamtool->addStreams(m_streamSpecs); m_streamSpecsLast = m_streamSpecs; m_streamID = 0; return status; }
StatusCode EventSelector::last | ( | Context & | c ) | const [virtual] |
Access last item in the iteration.
c | Reference to the Context object. |
Implements IEvtSelector.
Definition at line 305 of file EventSelector.cpp.
{ EvtSelectorContext *pIt = dynamic_cast<EvtSelectorContext*>(&refCtxt); if ( pIt ) { } return StatusCode::FAILURE; }
StatusCode EventSelector::lastOfPreviousStream | ( | bool | shutDown, |
EvtSelectorContext & | it | ||
) | const |
Retrieve last entry of the previous data stream.
Definition at line 143 of file EventSelector.cpp.
{ StatusCode status = StatusCode::SUCCESS; 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); iter.set(0,0); } status = thisPtr->m_streamtool->finalizeStream(const_cast<EventSelectorDataStream*>(s)); iter.set(0,0); } } } IDataStreamTool::size_type iter_id = iter.ID()-1; const EventSelectorDataStream* s ; status = m_streamtool->getPreviousStream( s , iter_id ); if ( status.isSuccess() ) { 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; return StatusCode::SUCCESS; } } } } } iter.set(this, -1, 0, 0); return StatusCode::FAILURE; }
StatusCode EventSelector::next | ( | Context & | refCtxt ) | const [virtual] |
Get next iteration item from the event loop context.
refCtxt | [IN/OUT] Reference to the context |
Implements IEvtSelector.
Definition at line 224 of file EventSelector.cpp.
{ return next(refCtxt, 1); }
StatusCode EventSelector::next | ( | Context & | refCtxt, |
int | jump | ||
) | const [virtual] |
Get next iteration item from the event loop context, but skip jump elements.
refCtxt | [IN/OUT] Reference to the context |
Implements IEvtSelector.
Definition at line 229 of file EventSelector.cpp.
{ 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; }
StatusCode EventSelector::previous | ( | Context & | refCtxt ) | const [virtual] |
Get previous iteration item from the event loop context.
refCtxt | [IN/OUT] Reference to the context |
jump | [IN] Number of events to be skipped |
Implements IEvtSelector.
Definition at line 268 of file EventSelector.cpp.
{ return previous(refCtxt, 1); }
StatusCode EventSelector::previous | ( | Context & | refCtxt, |
int | jump | ||
) | const [virtual] |
Get previous iteration item from the event loop context, but skip jump elements.
refCtxt | [IN/OUT] Reference to the context |
jump | [IN] Number of events to be skipped |
Implements IEvtSelector.
Definition at line 273 of file EventSelector.cpp.
{ EvtSelectorContext *pIt = dynamic_cast<EvtSelectorContext*>(&refCtxt); if ( pIt && jump > 0 ) { StatusCode sc = StatusCode::SUCCESS; for ( int i = 0; i < jump && sc.isSuccess(); ++i ) { const EventSelectorDataStream* s = m_streamtool->getStream(pIt->ID()); Context* it = pIt->context(); IEvtSelector* sel = s->selector(); if ( it && sel ) { // First exploit the current stream // This stream is empty: advance to the next stream sc = sel->previous(*it); // This stream is empty: advance to the next stream if ( !sc.isSuccess() ) { sc = lastOfPreviousStream(true, *pIt); } else { pIt->increaseCounters(false); pIt->set(it, 0); } printEvtInfo(pIt); if ( !sc.isSuccess() ) { return sc; } } pIt->increaseCounters(false); } return sc; } printEvtInfo(pIt); return StatusCode::FAILURE; }
void EventSelector::printEvtInfo | ( | const EvtSelectorContext * | iter ) | const [protected, virtual] |
Progress report.
Definition at line 57 of file EventSelector.cpp.
{ if ( 0 != iter ) { long count = iter->numEvent(); // Print an message every m_evtPrintFrequency events if ( 0 == iter->context() ) { MsgStream log(msgSvc(), name()); log << MSG::INFO << "End of event input reached." << endmsg; } else if( iter->numStreamEvent() == -1 ) { // Intial value for this stream } else if( m_evtPrintFrequency != -1 && (count % m_evtPrintFrequency == 0)) { MsgStream log(msgSvc(), name()); log << MSG::ALWAYS << "Reading Event record " << count+1 << ". Record number within stream " << iter->ID()+1 << ": " << iter->numStreamEvent()+1 << endmsg; } } else { MsgStream log(msgSvc(), name()); log << MSG::INFO << "End of event input reached." << endmsg; } }
StatusCode EventSelector::reinitialize | ( | ) | [virtual] |
Service override: Reinitialize service.
Reimplemented from Service.
Definition at line 433 of file EventSelector.cpp.
{ if ( FSMState() != Gaudi::StateMachine::INITIALIZED ) { MsgStream logger(msgSvc(), name()); logger << MSG::ERROR << "Cannot reinitialize: service not in state initialized" << endmsg; return StatusCode::FAILURE; } if( m_streamSpecsLast != m_streamSpecs ) { StatusCode status = m_streamtool->clear(); if ( status.isFailure() ) return status; m_streamSpecsLast = m_streamSpecs; m_reconfigure = true; return m_streamtool->addStreams(m_streamSpecs); } return StatusCode::SUCCESS; }
StatusCode EventSelector::releaseContext | ( | Context *& | refCtxt ) | const [virtual] |
Release existing event iteration context.
refCtxt | [IN/OUT] Reference to the context |
Implements IEvtSelector.
Definition at line 359 of file EventSelector.cpp.
{ const EvtSelectorContext *cpIt = dynamic_cast<const EvtSelectorContext*>(refCtxt); EvtSelectorContext *pIt = const_cast<EvtSelectorContext*>(cpIt); if ( pIt && pIt->ID() >= 0 && pIt->ID() < (long)m_streamtool->size() ) { const EventSelectorDataStream* s = m_streamtool->getStream(pIt->ID()); Context* it = pIt->context(); IEvtSelector* sel = s->selector(); if ( it && sel ) { StatusCode sc = sel->releaseContext(it); if ( sc.isSuccess() ) { refCtxt = 0; delete pIt; return sc; } } } if ( pIt ) { delete pIt; } return StatusCode::SUCCESS; }
StatusCode EventSelector::resetCriteria | ( | const std::string & | cr, |
Context & | c | ||
) | const [virtual] |
Will set a new criteria for the selection of the next list of events and will change the state of the context in a way to point to the new list.
cr | The new criteria string. |
c | Reference pointer to the Context object. |
Implements IEvtSelector.
Definition at line 50 of file EventSelector.cpp.
{ return StatusCode::FAILURE; }
StatusCode EventSelector::rewind | ( | Context & | refCtxt ) | const [virtual] |
Rewind the dataset.
refCtxt | [IN/OUT] Reference to the context |
Implements IEvtSelector.
Definition at line 313 of file EventSelector.cpp.
{ EvtSelectorContext *ctxt = dynamic_cast<EvtSelectorContext*>(&refCtxt); if ( ctxt ) { ctxt->set(0, -1, 0, 0); firstOfNextStream(true, *ctxt); long nskip = m_firstEvent; while( --nskip > 0 ) { StatusCode sc = next(*ctxt); if ( sc.isFailure() ) { MsgStream log(msgSvc(), name()); log << MSG::ERROR << "rewind() failed to start with event number " << m_firstEvent << endmsg; return StatusCode::FAILURE; } } return StatusCode::SUCCESS; } return StatusCode::FAILURE; }
int EventSelector::m_evtMax [protected] |
Maximum number of events to be processed.
Definition at line 82 of file EventSelector.h.
int EventSelector::m_evtPrintFrequency [protected] |
Printout frequency.
Definition at line 84 of file EventSelector.h.
int EventSelector::m_firstEvent [protected] |
First event to be processed.
Definition at line 80 of file EventSelector.h.
SmartIF<IIncidentSvc> EventSelector::m_incidentSvc [protected] |
Reference to the indicent service.
Definition at line 63 of file EventSelector.h.
bool EventSelector::m_reconfigure [protected] |
Reconfigure occurred.
Definition at line 70 of file EventSelector.h.
int EventSelector::m_streamCount [protected] |
Input stream counter (0..oo, monotonely increasing)
Definition at line 78 of file EventSelector.h.
long int EventSelector::m_streamID |
Definition at line 59 of file EventSelector.h.
std::string EventSelector::m_streamManager [protected] |
Definition at line 86 of file EventSelector.h.
Streams EventSelector::m_streams [protected] |
Input streams.
Definition at line 76 of file EventSelector.h.
StreamSpecs EventSelector::m_streamSpecs [protected] |
Input stream specifiers (for job options)
Definition at line 72 of file EventSelector.h.
StreamSpecs EventSelector::m_streamSpecsLast [protected] |
Input stream specifiers (last used)
Definition at line 74 of file EventSelector.h.
IDataStreamTool* EventSelector::m_streamtool [protected] |
Definition at line 67 of file EventSelector.h.
SmartIF<IToolSvc> EventSelector::m_toolSvc [protected] |
Definition at line 65 of file EventSelector.h.