EventSelector Class Reference

Definition of class EventSelector. More...

#include <src/EventSelector/EventSelector.h>

Inheritance diagram for EventSelector:
Collaboration diagram for EventSelector:

Public Types

typedef std::vector< EventSelectorDataStream * > Streams
 
typedef std::vector< std::string > StreamSpecs
 
typedef std::vector< StringPropertyProperties
 
- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Public Member Functions

StatusCode initialize () override
 IService implementation: Db event selector override. More...
 
StatusCode finalize () override
 IService implementation: Service finalization. More...
 
StatusCode reinitialize () override
 Service override: Reinitialize service. More...
 
StatusCode createContext (Context *&refpCtxt) const override
 Create a new event loop context. More...
 
StatusCode next (Context &refCtxt) const override
 Get next iteration item from the event loop context. More...
 
StatusCode next (Context &refCtxt, int jump) const override
 Get next iteration item from the event loop context, but skip jump elements. More...
 
StatusCode previous (Context &refCtxt) const override
 Get previous iteration item from the event loop context. More...
 
StatusCode previous (Context &refCtxt, int jump) const override
 Get previous iteration item from the event loop context, but skip jump elements. More...
 
StatusCode rewind (Context &refCtxt) const override
 Rewind the dataset. More...
 
StatusCode createAddress (const Context &refCtxt, IOpaqueAddress *&refpAddr) const override
 Create new Opaque address corresponding to the current record. More...
 
StatusCode releaseContext (Context *&refCtxt) const override
 Release existing event iteration context. More...
 
StatusCode resetCriteria (const std::string &cr, Context &c) const override
 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. More...
 
StatusCode last (Context &c) const override
 Access last item in the iteration. More...
 
StatusCode firstOfNextStream (bool shutDown, EvtSelectorContext &it) const
 Retrieve first entry of the next data stream. More...
 
StatusCode lastOfPreviousStream (bool shutDown, EvtSelectorContext &it) const
 Retrieve last entry of the previous data stream. More...
 
 EventSelector (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
 ~EventSelector () override=default
 Standard Destructor. More...
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Public Attributes

long int m_streamID
 

Protected Member Functions

virtual void printEvtInfo (const EvtSelectorContext *iter) const
 Progress report. More...
 

Protected Attributes

SmartIF< IIncidentSvcm_incidentSvc = nullptr
 Reference to the indicent service. More...
 
SmartIF< IToolSvcm_toolSvc = nullptr
 
IDataStreamToolm_streamtool = nullptr
 
bool m_reconfigure = false
 Reconfigure occurred. More...
 
StreamSpecs m_streamSpecs
 Input stream specifiers (for job options) More...
 
StreamSpecs m_streamSpecsLast
 Input stream specifiers (last used) More...
 
Streams m_streams
 Input streams. More...
 
int m_streamCount = 0
 Input stream counter (0..oo, monotonely increasing) More...
 
int m_firstEvent = 0
 First event to be processed. More...
 
int m_evtMax = INT_MAX
 Maximum number of events to be processed. More...
 
int m_evtPrintFrequency = 10
 Printout frequency. More...
 
std::string m_streamManager ="DataStreamTool"
 

Detailed Description

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 | +------—+-------------------------------------------—+---------—+

Author
Markus Frank
R. Lambert
Version
1.0

Definition at line 53 of file EventSelector.h.

Member Typedef Documentation

Definition at line 57 of file EventSelector.h.

Definition at line 55 of file EventSelector.h.

typedef std::vector<std::string> EventSelector::StreamSpecs

Definition at line 56 of file EventSelector.h.

Constructor & Destructor Documentation

EventSelector::EventSelector ( const std::string &  name,
ISvcLocator svcloc 
)

Standard Constructor.

Definition at line 21 of file EventSelector.cpp.

22  : base_class( name, svcloc)
23 {
24  declareProperty( "Input", m_streamSpecs);
25  declareProperty( "FirstEvent", m_firstEvent);
26  declareProperty( "EvtMax", m_evtMax);
27  declareProperty( "PrintFreq", m_evtPrintFrequency);
28  declareProperty( "StreamManager", m_streamManager);
29 }
int m_evtPrintFrequency
Printout frequency.
Definition: EventSelector.h:84
int m_firstEvent
First event to be processed.
Definition: EventSelector.h:80
int m_evtMax
Maximum number of events to be processed.
Definition: EventSelector.h:82
extends base_class
Typedef to this class.
Definition: extends.h:14
StreamSpecs m_streamSpecs
Input stream specifiers (for job options)
Definition: EventSelector.h:72
std::string m_streamManager
Definition: EventSelector.h:86
EventSelector::~EventSelector ( )
overridedefault

Standard Destructor.

Member Function Documentation

StatusCode EventSelector::createAddress ( const Context &  refCtxt,
IOpaqueAddress *&  refpAddr 
) const
override

Create new Opaque address corresponding to the current record.

Parameters
refCtxt[IN/OUT] Reference to the context
refpAddr[OUT] Reference to address pointer
Returns
StatusCode indicating success or failure

Definition at line 317 of file EventSelector.cpp.

319 {
320  const EvtSelectorContext *cpIt = dynamic_cast<const EvtSelectorContext*>(&refCtxt);
321  EvtSelectorContext *pIt = const_cast<EvtSelectorContext*>(cpIt);
322  refpAddr = nullptr;
323  if ( pIt ) {
325  Context* it = pIt->context();
326  IEvtSelector* sel = s->selector();
327  if ( it && sel ) {
328  IOpaqueAddress* pAddr = nullptr;
329  StatusCode sc = sel->createAddress(*it, pAddr);
330  if ( sc.isSuccess() ) refpAddr = pAddr;
331  pIt->set(it, pAddr);
332  return sc;
333  }
334  }
335  return StatusCode::FAILURE;
336 }
IEvtSelector::Context * context() const
Access "real" iterator.
Definition: EventIterator.h:70
The Event Selector Interface.
Definition: IEvtSelector.h:18
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
IDataStreamTool * m_streamtool
Definition: EventSelector.h:67
IEvtSelector * selector() const
Retrieve event selector object.
Definition of class EventIterator.
Definition: EventIterator.h:32
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual EventSelectorDataStream * getStream(size_type)=0
void set(const IEvtSelector *sel, IDataStreamTool::size_type id, IEvtSelector::Context *it, IOpaqueAddress *pA)
Set the address of the iterator.
Definition: EventIterator.h:53
Definition of class EventSelectorDataStream.
virtual IDataStreamTool::size_type ID() const
Stream identifier.
Definition: EventIterator.h:95
string s
Definition: gaudirun.py:245
Opaque address interface definition.
virtual StatusCode createAddress(const Context &c, IOpaqueAddress *&iop) const =0
Create an IOpaqueAddress object from the event fetched.
StatusCode EventSelector::createContext ( Context *&  refpCtxt) const
override

Create a new event loop context.

Parameters
refpCtxt[IN/OUT] Reference to pointer to store the context
Returns
StatusCode indicating success or failure

Definition at line 176 of file EventSelector.cpp.

177 {
178  // Max event is zero. Return begin = end
179  refpCtxt = nullptr;
180  if ( m_firstEvent < 0 ) {
181  MsgStream log(msgSvc(), name());
182  log << MSG::ERROR << "First Event = " << m_firstEvent << " not valid" << endmsg;
183  log << MSG::ERROR << "It should be > 0 " << endmsg;
184  return StatusCode::FAILURE; // if failure => iterators = end();
185  }
186  EvtSelectorContext* ctxt = new EvtSelectorContext(this);
187  ctxt->set(0, -1, 0, 0);
188  firstOfNextStream(true, *ctxt).ignore();
189  refpCtxt = ctxt;
190  long nskip = m_firstEvent;
191  while( --nskip > 0 ) {
192  StatusCode sc = next(*refpCtxt);
193  if ( sc.isFailure() ) {
194  MsgStream log(msgSvc(), name());
195  log << MSG::ERROR << " createContext() failed to start with event number "
196  << m_firstEvent << endmsg;
197  releaseContext(refpCtxt);
198  refpCtxt = nullptr;
199  return StatusCode::FAILURE;
200  }
201  }
202  return StatusCode::SUCCESS;
203 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
int m_firstEvent
First event to be processed.
Definition: EventSelector.h:80
StatusCode releaseContext(Context *&refCtxt) const override
Release existing event iteration context.
StatusCode firstOfNextStream(bool shutDown, EvtSelectorContext &it) const
Retrieve first entry of the next data stream.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
StatusCode next(Context &refCtxt) const override
Get next iteration item from the event loop context.
Definition of class EventIterator.
Definition: EventIterator.h:32
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void set(const IEvtSelector *sel, IDataStreamTool::size_type id, IEvtSelector::Context *it, IOpaqueAddress *pA)
Set the address of the iterator.
Definition: EventIterator.h:53
void ignore() const
Definition: StatusCode.h:108
StatusCode EventSelector::finalize ( )
override

IService implementation: Service finalization.

Definition at line 434 of file EventSelector.cpp.

434  {
435 
436  if (msgLevel(MSG::DEBUG)) {
437  MsgStream log(msgSvc(), name());
438  log << MSG::DEBUG << "finalize()" << endmsg;
439  }
440 
441  m_incidentSvc = nullptr;
442 
443  if (m_streamtool) {
444  if (m_toolSvc) {
446  } else {
447  // It should not be possible to get here
448  m_streamtool->release();
449  }
450  m_streamtool = nullptr;
451  }
452  m_toolSvc.reset();
453 
454  return Service::finalize();
455 }
SmartIF< IIncidentSvc > m_incidentSvc
Reference to the indicent service.
Definition: EventSelector.h:63
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode finalize() override
Definition: Service.cpp:188
IDataStreamTool * m_streamtool
Definition: EventSelector.h:67
SmartIF< IToolSvc > m_toolSvc
Definition: EventSelector.h:65
virtual StatusCode releaseTool(IAlgTool *tool)=0
Release the tool.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
void ignore() const
Definition: StatusCode.h:108
StatusCode EventSelector::firstOfNextStream ( bool  shutDown,
EvtSelectorContext it 
) const

Retrieve first entry of the next data stream.

Definition at line 65 of file EventSelector.cpp.

65  {
67  IDataStreamTool::size_type iter_id = (m_reconfigure) ? 0 : iter.ID()+1;
68  if ( m_reconfigure ) const_cast<EventSelector*>(this)->m_reconfigure = false;
69  if ( shutDown ) {
70  if ( iter.ID() >= 0 && iter.ID() < (long)m_streamtool->size() ) {
71  const EventSelectorDataStream* s = m_streamtool->getStream(iter.ID());
72  if ( s->isInitialized() ) {
73  EventSelector* thisPtr = const_cast<EventSelector*>(this);
74  if ( s->selector() && iter.context() ) {
75  Context* ctxt = iter.context();
76  s->selector()->releaseContext(ctxt).ignore();
77  iter.set(0,0);
78  }
79  status = thisPtr->m_streamtool->finalizeStream(const_cast<EventSelectorDataStream*>(s));
80  iter.set(0,0);
81  }
82  }
83  }
84 
85  const EventSelectorDataStream* s ;
86  status = m_streamtool->getNextStream( s , iter_id );
87 
88  if ( status.isSuccess() ) {
89 
90  if (s) {
91  if ( !s->isInitialized() ) {
92  EventSelector* thisPtr = const_cast<EventSelector*>(this);
93  status = thisPtr->m_streamtool->initializeStream(const_cast<EventSelectorDataStream*>(s));
94  }
95 
96  if ( status.isSuccess() ) {
97  const IEvtSelector* sel = s->selector();
98  if ( sel ) {
99  Context* ctxt = nullptr;
100  status = sel->createContext(ctxt);
101  if ( status.isSuccess() ) {
102  status = sel->resetCriteria(s->criteria(), *ctxt);
103  if ( status.isSuccess() ) {
104  MsgStream log(msgSvc(), name());
105  iter.set(this, iter_id, ctxt, 0);
106  log << MSG::INFO << *s << endmsg;
107  m_incidentSvc->fireIncident(Incident(s->dbName(),IncidentType::BeginInputFile));
108  return StatusCode::SUCCESS;
109  }
110  }
111  }
112  }
113  m_incidentSvc->fireIncident(Incident(s->dbName(),IncidentType::FailInputFile));
114  }
115  }
116 
117  iter.set(this, -1, 0, 0);
118  status.setChecked();
119  //m_incidentSvc->fireIncident(Incident(s->dbName(),IncidentType::FailInputFile));
120  return StatusCode::FAILURE;
121 }
SmartIF< IIncidentSvc > m_incidentSvc
Reference to the indicent service.
Definition: EventSelector.h:63
bool isInitialized() const
Check initialization status.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual StatusCode finalizeStream(EventSelectorDataStream *)=0
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
The Event Selector Interface.
Definition: IEvtSelector.h:18
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
IDataStreamTool * m_streamtool
Definition: EventSelector.h:67
IEvtSelector * selector() const
Retrieve event selector object.
virtual StatusCode resetCriteria(const std::string &cr, Context &c) const =0
Will set a new criteria for the selection of the next list of events and will change the state of the...
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual StatusCode createContext(Context *&c) const =0
Create and return a context object that will keep track of the state of selection.
virtual EventSelectorDataStream * getStream(size_type)=0
virtual StatusCode releaseContext(Context *&) const =0
Release the Context object.
Definition of class EventSelectorDataStream.
Base class for all Incidents (computing events).
Definition: Incident.h:16
string s
Definition: gaudirun.py:245
Definition of class EventSelector.
Definition: EventSelector.h:53
virtual size_type size()=0
virtual StatusCode initializeStream(EventSelectorDataStream *)=0
const std::string & criteria() const
Retrieve stream criteria.
bool m_reconfigure
Reconfigure occurred.
Definition: EventSelector.h:70
void ignore() const
Definition: StatusCode.h:108
virtual StatusCode getNextStream(const EventSelectorDataStream *&, size_type &)=0
const std::string & dbName() const
Retrieve stream dbName.
void setChecked() const
Ignore the checking code;.
Definition: StatusCode.h:105
StatusCode EventSelector::initialize ( )
override

IService implementation: Db event selector override.

Definition at line 358 of file EventSelector.cpp.

358  {
359  // Initialize base class
360  StatusCode status = Service::initialize();
361  MsgStream logger(msgSvc(), name());
362  if ( !status.isSuccess() ) {
363  logger << MSG::ERROR << "Error initializing base class Service!" << endmsg;
364  return status;
365  }
366  // Get the references to the services that are needed by the ApplicationMgr itself
367  m_incidentSvc = serviceLocator()->service("IncidentSvc");
368  if( !m_incidentSvc ) {
369  logger << MSG::FATAL << "Error retrieving IncidentSvc." << endmsg;
370  return StatusCode::FAILURE;
371  }
372  if ( m_evtMax != INT_MAX ) {
373  logger << MSG::ERROR << "EvtMax is an obsolete property of the event selector." << endmsg;
374  logger << MSG::ERROR << "Please set \"ApplicationMgr.EvtMax = " << m_evtMax
375  << ";\" to process the requested number of events." << endmsg;
376  return StatusCode::FAILURE;
377  }
378 
379  m_toolSvc = serviceLocator()->service("ToolSvc");
380  if ( !m_toolSvc ) {
381  logger << MSG::ERROR << " Could not locate the Tool Service! " << endmsg;
382  return StatusCode::FAILURE;
383  }
384  // make sure we finalize _prior_ to ToolSvc... we are about to get a
385  // a pointer to a tool which gets finalized and released by the ToolSvc
386  // during ToolSvc::finalize, and we don't want dangling pointers...
387  SmartIF<ISvcManager> mgr(serviceLocator());
388  auto prio = mgr->getPriority("ToolSvc");
389  mgr->setPriority(name(),prio+1).ignore();
390 
391  status = m_toolSvc->retrieveTool(m_streamManager.c_str(), m_streamtool, this);
392 
393  if( status.isFailure() ) {
394  logger << MSG::ERROR << "Error initializing "
395  << m_streamManager << endmsg;
396  return status;
397  }
398 
399  status = m_streamtool->clear();
400  if( status.isFailure() ) {
401  // Message already printed by the tool
402  return status;
403  }
404 
406 
408 
409  m_streamID = 0;
410 
411  return status;
412 }
SmartIF< IIncidentSvc > m_incidentSvc
Reference to the indicent service.
Definition: EventSelector.h:63
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:63
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
int m_evtMax
Maximum number of events to be processed.
Definition: EventSelector.h:82
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
IDataStreamTool * m_streamtool
Definition: EventSelector.h:67
long int m_streamID
Definition: EventSelector.h:59
GAUDIPS_API Logger & logger()
Return the current logger instance.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
StatusCode retrieveTool(const std::string &type, T *&tool, const IInterface *parent=nullptr, bool createIf=true)
Retrieve specified tool sub-type with tool dependent part of the name automatically assigned...
Definition: IToolSvc.h:145
StreamSpecs m_streamSpecsLast
Input stream specifiers (last used)
Definition: EventSelector.h:74
virtual StatusCode addStreams(const StreamSpecs &)=0
virtual StatusCode clear()=0
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StreamSpecs m_streamSpecs
Input stream specifiers (for job options)
Definition: EventSelector.h:72
SmartIF< IToolSvc > m_toolSvc
Definition: EventSelector.h:65
std::string m_streamManager
Definition: EventSelector.h:86
StatusCode EventSelector::last ( Context &  c) const
override

Access last item in the iteration.

Parameters
cReference to the Context object.
Returns
StatusCode indicating success or failure

Definition at line 287 of file EventSelector.cpp.

287  {
288  EvtSelectorContext *pIt = dynamic_cast<EvtSelectorContext*>(&refCtxt);
289  if ( pIt ) {
290  }
291  return StatusCode::FAILURE;
292 }
Definition of class EventIterator.
Definition: EventIterator.h:32
StatusCode EventSelector::lastOfPreviousStream ( bool  shutDown,
EvtSelectorContext it 
) const

Retrieve last entry of the previous data stream.

Definition at line 125 of file EventSelector.cpp.

125  {
127  if ( shutDown ) {
128  if ( iter.ID() >= 0 && iter.ID() < (long)m_streamtool->size() ) {
129  const EventSelectorDataStream* s = m_streamtool->getStream(iter.ID());
130  if ( s->isInitialized() ) {
131  EventSelector* thisPtr = const_cast<EventSelector*>(this);
132  if ( s->selector() && iter.context() ) {
133  Context* ctxt = iter.context();
134  s->selector()->releaseContext(ctxt);
135  iter.set(0,0);
136  }
137  status = thisPtr->m_streamtool->finalizeStream(const_cast<EventSelectorDataStream*>(s));
138  iter.set(0,0);
139  }
140  }
141  }
142 
143  IDataStreamTool::size_type iter_id = iter.ID()-1;
144  const EventSelectorDataStream* s = nullptr;
145  status = m_streamtool->getPreviousStream( s , iter_id );
146 
147  if ( status.isSuccess() ) {
148 
149  if ( !s->isInitialized() ) {
150  EventSelector* thisPtr = const_cast<EventSelector*>(this);
151  status = thisPtr->m_streamtool->initializeStream(const_cast<EventSelectorDataStream*>(s));
152  }
153  if ( status.isSuccess() ) {
154  const IEvtSelector* sel = s->selector();
155  if ( sel ) {
156  Context* ctxt = nullptr;
157  status = sel->createContext(ctxt);
158  if ( status.isSuccess() ) {
159  status = sel->resetCriteria(s->criteria(), *ctxt);
160  if ( status.isSuccess() ) {
161  MsgStream log(msgSvc(), name());
162  iter.set(this, iter_id, ctxt, 0);
163  log << MSG::INFO << *s << endmsg;
164  return StatusCode::SUCCESS;
165  }
166  }
167  }
168  }
169  }
170 
171  iter.set(this, -1, 0, 0);
172  return StatusCode::FAILURE;
173 }
bool isInitialized() const
Check initialization status.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual StatusCode finalizeStream(EventSelectorDataStream *)=0
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
The Event Selector Interface.
Definition: IEvtSelector.h:18
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
IDataStreamTool * m_streamtool
Definition: EventSelector.h:67
IEvtSelector * selector() const
Retrieve event selector object.
virtual StatusCode resetCriteria(const std::string &cr, Context &c) const =0
Will set a new criteria for the selection of the next list of events and will change the state of the...
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual StatusCode createContext(Context *&c) const =0
Create and return a context object that will keep track of the state of selection.
virtual EventSelectorDataStream * getStream(size_type)=0
virtual StatusCode releaseContext(Context *&) const =0
Release the Context object.
virtual StatusCode getPreviousStream(const EventSelectorDataStream *&, size_type &)=0
Definition of class EventSelectorDataStream.
string s
Definition: gaudirun.py:245
Definition of class EventSelector.
Definition: EventSelector.h:53
virtual size_type size()=0
virtual StatusCode initializeStream(EventSelectorDataStream *)=0
const std::string & criteria() const
Retrieve stream criteria.
StatusCode EventSelector::next ( Context &  refCtxt) const
override

Get next iteration item from the event loop context.

Parameters
refCtxt[IN/OUT] Reference to the context
Returns
StatusCode indicating success or failure

Definition at line 206 of file EventSelector.cpp.

206  {
207  return next(refCtxt, 1);
208 }
StatusCode next(Context &refCtxt) const override
Get next iteration item from the event loop context.
StatusCode EventSelector::next ( Context &  refCtxt,
int  jump 
) const
override

Get next iteration item from the event loop context, but skip jump elements.

Parameters
refCtxt[IN/OUT] Reference to the context
Returns
StatusCode indicating success or failure

Definition at line 211 of file EventSelector.cpp.

211  {
212  EvtSelectorContext *pIt = dynamic_cast<EvtSelectorContext*>(&refCtxt);
213  if ( pIt ) {
214  if ( pIt->ID() != -1 ) {
216  Context* it = pIt->context();
217  IEvtSelector* sel = s->selector();
218  if ( it && sel ) { // First exploit the current stream
219  StatusCode sc = sel->next(*it); // This stream is empty: advance to the next stream
220  if ( !sc.isSuccess() ) {
221  m_incidentSvc->fireIncident(Incident(s->dbName(),IncidentType::EndInputFile));
222  sc = firstOfNextStream(true, *pIt);
223  if (sc.isSuccess() ) sc = next(*pIt);
224  }
225  else {
226  pIt->increaseCounters(false);
227  pIt->set(it, 0);
228  printEvtInfo(pIt);
229  }
230  return sc;
231  }
232  else if ( m_reconfigure ) {
233  StatusCode sc = firstOfNextStream(false, *pIt);
234  printEvtInfo(pIt);
235  return sc;
236  }
237  }
238  else if ( m_reconfigure ) {
239  StatusCode sc = firstOfNextStream(false, *pIt);
240  printEvtInfo(pIt);
241  return sc;
242  }
243  pIt->increaseCounters(false);
244  }
245  printEvtInfo(pIt);
246  return StatusCode::FAILURE;
247 }
SmartIF< IIncidentSvc > m_incidentSvc
Reference to the indicent service.
Definition: EventSelector.h:63
IEvtSelector::Context * context() const
Access "real" iterator.
Definition: EventIterator.h:70
The Event Selector Interface.
Definition: IEvtSelector.h:18
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
IDataStreamTool * m_streamtool
Definition: EventSelector.h:67
IEvtSelector * selector() const
Retrieve event selector object.
virtual void printEvtInfo(const EvtSelectorContext *iter) const
Progress report.
StatusCode firstOfNextStream(bool shutDown, EvtSelectorContext &it) const
Retrieve first entry of the next data stream.
StatusCode next(Context &refCtxt) const override
Get next iteration item from the event loop context.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
Definition of class EventIterator.
Definition: EventIterator.h:32
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual StatusCode next(Context &c) const =0
Fetch the next event or the first event if it will be use soon after the creation of the context...
virtual EventSelectorDataStream * getStream(size_type)=0
void set(const IEvtSelector *sel, IDataStreamTool::size_type id, IEvtSelector::Context *it, IOpaqueAddress *pA)
Set the address of the iterator.
Definition: EventIterator.h:53
Definition of class EventSelectorDataStream.
Base class for all Incidents (computing events).
Definition: Incident.h:16
virtual IDataStreamTool::size_type ID() const
Stream identifier.
Definition: EventIterator.h:95
string s
Definition: gaudirun.py:245
IDataStreamTool::size_type increaseCounters(bool reset=false)
Increase counters.
Definition: EventIterator.h:74
bool m_reconfigure
Reconfigure occurred.
Definition: EventSelector.h:70
const std::string & dbName() const
Retrieve stream dbName.
StatusCode EventSelector::previous ( Context &  refCtxt) const
override

Get previous iteration item from the event loop context.

Parameters
refCtxt[IN/OUT] Reference to the context
jump[IN] Number of events to be skipped
Returns
StatusCode indicating success or failure

Definition at line 250 of file EventSelector.cpp.

250  {
251  return previous(refCtxt, 1);
252 }
StatusCode previous(Context &refCtxt) const override
Get previous iteration item from the event loop context.
StatusCode EventSelector::previous ( Context &  refCtxt,
int  jump 
) const
override

Get previous iteration item from the event loop context, but skip jump elements.

Parameters
refCtxt[IN/OUT] Reference to the context
jump[IN] Number of events to be skipped
Returns
StatusCode indicating success or failure

Definition at line 255 of file EventSelector.cpp.

255  {
256  EvtSelectorContext *pIt = dynamic_cast<EvtSelectorContext*>(&refCtxt);
257  if ( pIt && jump > 0 ) {
259  for ( int i = 0; i < jump && sc.isSuccess(); ++i ) {
261  Context* it = pIt->context();
262  IEvtSelector* sel = s->selector();
263  if ( it && sel ) { // First exploit the current stream
264  // This stream is empty: advance to the next stream
265  sc = sel->previous(*it); // This stream is empty: advance to the next stream
266  if ( !sc.isSuccess() ) {
267  sc = lastOfPreviousStream(true, *pIt);
268  }
269  else {
270  pIt->increaseCounters(false);
271  pIt->set(it, 0);
272  }
273  printEvtInfo(pIt);
274  if ( !sc.isSuccess() ) {
275  return sc;
276  }
277  }
278  pIt->increaseCounters(false);
279  }
280  return sc;
281  }
282  printEvtInfo(pIt);
283  return StatusCode::FAILURE;
284 }
StatusCode lastOfPreviousStream(bool shutDown, EvtSelectorContext &it) const
Retrieve last entry of the previous data stream.
IEvtSelector::Context * context() const
Access "real" iterator.
Definition: EventIterator.h:70
The Event Selector Interface.
Definition: IEvtSelector.h:18
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
IDataStreamTool * m_streamtool
Definition: EventSelector.h:67
IEvtSelector * selector() const
Retrieve event selector object.
virtual void printEvtInfo(const EvtSelectorContext *iter) const
Progress report.
Definition of class EventIterator.
Definition: EventIterator.h:32
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual EventSelectorDataStream * getStream(size_type)=0
void set(const IEvtSelector *sel, IDataStreamTool::size_type id, IEvtSelector::Context *it, IOpaqueAddress *pA)
Set the address of the iterator.
Definition: EventIterator.h:53
Definition of class EventSelectorDataStream.
virtual IDataStreamTool::size_type ID() const
Stream identifier.
Definition: EventIterator.h:95
string s
Definition: gaudirun.py:245
IDataStreamTool::size_type increaseCounters(bool reset=false)
Increase counters.
Definition: EventIterator.h:74
virtual StatusCode previous(Context &c) const =0
Fetch the previous event.
list i
Definition: ana.py:128
void EventSelector::printEvtInfo ( const EvtSelectorContext iter) const
protectedvirtual

Progress report.

Definition at line 39 of file EventSelector.cpp.

39  {
40  if ( iter ) {
41  long count = iter->numEvent();
42  // Print an message every m_evtPrintFrequency events
43  if ( 0 == iter->context() ) {
44  MsgStream log(msgSvc(), name());
45  log << MSG::INFO << "End of event input reached." << endmsg;
46  }
47  else if( iter->numStreamEvent() == -1 ) {
48  // Intial value for this stream
49  }
50  else if( m_evtPrintFrequency != -1 && (count % m_evtPrintFrequency == 0)) {
51  MsgStream log(msgSvc(), name());
52  log << MSG::ALWAYS << "Reading Event record " << count+1
53  << ". Record number within stream " << iter->ID()+1
54  << ": " << iter->numStreamEvent()+1 << endmsg;
55  }
56  }
57  else {
58  MsgStream log(msgSvc(), name());
59  log << MSG::INFO << "End of event input reached." << endmsg;
60  }
61 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
IEvtSelector::Context * context() const
Access "real" iterator.
Definition: EventIterator.h:70
int m_evtPrintFrequency
Printout frequency.
Definition: EventSelector.h:84
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
long numStreamEvent() const
Access counter within stream.
virtual IDataStreamTool::size_type ID() const
Stream identifier.
Definition: EventIterator.h:95
long numEvent() const
Access counter.
Definition: EventIterator.h:99
StatusCode EventSelector::reinitialize ( )
override

Service override: Reinitialize service.

Definition at line 415 of file EventSelector.cpp.

415  {
416  if ( FSMState() != Gaudi::StateMachine::INITIALIZED ) {
417  MsgStream logger(msgSvc(), name());
418  logger << MSG::ERROR << "Cannot reinitialize: service not in state initialized" << endmsg;
419  return StatusCode::FAILURE;
420  }
421 
423  StatusCode status = m_streamtool->clear();
424  if ( status.isFailure() ) return status;
426  m_reconfigure = true;
428  }
429 
430  return StatusCode::SUCCESS;
431 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
IDataStreamTool * m_streamtool
Definition: EventSelector.h:67
GAUDIPS_API Logger & logger()
Return the current logger instance.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
StreamSpecs m_streamSpecsLast
Input stream specifiers (last used)
Definition: EventSelector.h:74
virtual StatusCode addStreams(const StreamSpecs &)=0
virtual StatusCode clear()=0
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StreamSpecs m_streamSpecs
Input stream specifiers (for job options)
Definition: EventSelector.h:72
bool m_reconfigure
Reconfigure occurred.
Definition: EventSelector.h:70
StatusCode EventSelector::releaseContext ( Context *&  refCtxt) const
override

Release existing event iteration context.

Parameters
refCtxt[IN/OUT] Reference to the context
Returns
StatusCode indicating success or failure

Definition at line 339 of file EventSelector.cpp.

339  {
340  const EvtSelectorContext *cpIt = dynamic_cast<const EvtSelectorContext*>(refCtxt);
341  std::unique_ptr<EvtSelectorContext> pIt{ const_cast<EvtSelectorContext*>(cpIt) };
342  if ( pIt && pIt->ID() >= 0 && pIt->ID() < (long)m_streamtool->size() ) {
343  const EventSelectorDataStream* s = m_streamtool->getStream(pIt->ID());
344  Context* it = pIt->context();
345  IEvtSelector* sel = s->selector();
346  if ( it && sel ) {
347  StatusCode sc = sel->releaseContext(it);
348  if ( sc.isSuccess() ) {
349  refCtxt = nullptr;
350  return sc;
351  }
352  }
353  }
354  return StatusCode::SUCCESS;
355 }
The Event Selector Interface.
Definition: IEvtSelector.h:18
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
IDataStreamTool * m_streamtool
Definition: EventSelector.h:67
IEvtSelector * selector() const
Retrieve event selector object.
Definition of class EventIterator.
Definition: EventIterator.h:32
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual EventSelectorDataStream * getStream(size_type)=0
virtual StatusCode releaseContext(Context *&) const =0
Release the Context object.
Definition of class EventSelectorDataStream.
string s
Definition: gaudirun.py:245
virtual size_type size()=0
StatusCode EventSelector::resetCriteria ( const std::string &  cr,
Context &  c 
) const
override

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.

Parameters
crThe new criteria string.
cReference pointer to the Context object.
Returns
StatusCode indicating success or failure

Definition at line 32 of file EventSelector.cpp.

34 {
35  return StatusCode::FAILURE;
36 }
StatusCode EventSelector::rewind ( Context &  refCtxt) const
override

Rewind the dataset.

Parameters
refCtxt[IN/OUT] Reference to the context
Returns
StatusCode indicating success or failure

Definition at line 295 of file EventSelector.cpp.

295  {
296  EvtSelectorContext *ctxt = dynamic_cast<EvtSelectorContext*>(&refCtxt);
297  if ( ctxt ) {
298  ctxt->set(0, -1, 0, 0);
299  firstOfNextStream(true, *ctxt);
300  long nskip = m_firstEvent;
301  while( --nskip > 0 ) {
302  StatusCode sc = next(*ctxt);
303  if ( sc.isFailure() ) {
304  MsgStream log(msgSvc(), name());
305  log << MSG::ERROR << "rewind() failed to start with event number "
306  << m_firstEvent << endmsg;
307  return StatusCode::FAILURE;
308  }
309  }
310  return StatusCode::SUCCESS;
311  }
312  return StatusCode::FAILURE;
313 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
int m_firstEvent
First event to be processed.
Definition: EventSelector.h:80
StatusCode firstOfNextStream(bool shutDown, EvtSelectorContext &it) const
Retrieve first entry of the next data stream.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
StatusCode next(Context &refCtxt) const override
Get next iteration item from the event loop context.
Definition of class EventIterator.
Definition: EventIterator.h:32
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void set(const IEvtSelector *sel, IDataStreamTool::size_type id, IEvtSelector::Context *it, IOpaqueAddress *pA)
Set the address of the iterator.
Definition: EventIterator.h:53

Member Data Documentation

int EventSelector::m_evtMax = INT_MAX
protected

Maximum number of events to be processed.

Definition at line 82 of file EventSelector.h.

int EventSelector::m_evtPrintFrequency = 10
protected

Printout frequency.

Definition at line 84 of file EventSelector.h.

int EventSelector::m_firstEvent = 0
protected

First event to be processed.

Definition at line 80 of file EventSelector.h.

SmartIF<IIncidentSvc> EventSelector::m_incidentSvc = nullptr
protected

Reference to the indicent service.

Definition at line 63 of file EventSelector.h.

bool EventSelector::m_reconfigure = false
protected

Reconfigure occurred.

Definition at line 70 of file EventSelector.h.

int EventSelector::m_streamCount = 0
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 ="DataStreamTool"
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 = nullptr
protected

Definition at line 67 of file EventSelector.h.

SmartIF<IToolSvc> EventSelector::m_toolSvc = nullptr
protected

Definition at line 65 of file EventSelector.h.


The documentation for this class was generated from the following files: