ATLAS Offline Software
McEventSelector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //====================================================================
6 // EventSelector.cpp
7 //--------------------------------------------------------------------
8 //
9 // Package : McEventSelector
10 //
11 // Description: The EventSelector component is able
12 // to produce a list of event references given a set of "selection
13 // criteria".
14 //
15 // Author : P. Calafiura
16 // Created : 2/29/00
17 // Changes : 11/8/01 new storegate -- I Hinchliffe
18 //
19 //
20 //====================================================================
21 
22 // Include files
23 //stdlib
24 #include <vector>
25 //own
28 #include "EventInfo/EventInfo.h"
29 
30 //framework
31 #include "GaudiKernel/ISvcLocator.h"
32 #include "GaudiKernel/GenericAddress.h"
33 #include "GaudiKernel/StatusCode.h"
34 #include "GaudiKernel/MsgStream.h"
35 #include "GaudiKernel/IIncidentSvc.h"
36 #include "GaudiKernel/Incident.h"
37 
38 class ATLAS_NOT_THREAD_SAFE McContext : public IEvtSelector::Context {
39 private:
41  std::string m_criteria;
42 
43  unsigned int m_initRunNo;
46  unsigned int m_initLBNo;
47  unsigned int m_eventsPLB;
48 
49  unsigned int m_initTimeStamp;
50  unsigned int m_timeStampInt;
51 
52  unsigned int m_runNo;
54  unsigned int m_LBNo;
55  unsigned int m_timeStamp;
56  unsigned int m_LBTick;
57  int m_nevt;
58 
60 
61 
62 public:
64  McContext(const McEventSelector* pSelector);
65  McContext(const McEventSelector* pSelector,
66  const unsigned int &initRunNo, const uint64_t &initEventNo,
67  const uint64_t &evPR,
68  const unsigned int &initLBNo, const unsigned int &evPLB,
69  const unsigned int &initTimeStamp,
70  const unsigned int &timeStampInt);
71 
73  virtual ~McContext();
74 
75  virtual void* identifier() const {
76  return (void*)m_pSelector;
77  }
78  void setCriteria(const std::string& crit) {
79  m_criteria = crit;
80  }
81 
82  void rewind() {
83 
84  // Question: should this rewind to before the first event, or to
85  // it? ie, will next() be called right after rewind()?
86  // if so, then should set m_firstEvent to true;
87 
88  // CGL 2011.6.9: by process of experimental programming, we have
89  // determined that next() is called right after rewind() for the
90  // first event, so set m_firstEvent to true.
91 
92  m_firstEvent = true;
93 
94  m_eventNo = m_initEventNo;
95  m_runNo = m_initRunNo;
96  m_LBNo = m_initLBNo;
97  m_timeStamp = m_initTimeStamp;
98  m_nevt = 0;
99  }
100 
101  void next() {
102  m_nevt++; // advance serial event number
103 
104  if (m_firstEvent) {
105  m_firstEvent = false;
106 
107  m_eventNo = m_initEventNo;
108  m_runNo = m_initRunNo;
109  m_LBNo = m_initLBNo;
110  m_timeStamp = m_initTimeStamp;
111  m_LBTick=0;
112 
113  return;
114  }
115 
116  // Andy Buckley, 10 Feb 2014: commenting out to reduce Athena evgen noise
117  //std::cout << "evt no, per run " << m_eventNo << "/" << m_eventsP << std::endl;
118 
119  if(m_eventNo>=m_eventsP) {
120  m_runNo++;
121  m_eventNo=0;
122  m_LBNo=0; // lumiblock starts at 1 by default
123  m_LBTick=0;
124  }
125  m_eventNo++;
126  if (++m_LBTick >= m_eventsPLB) {
127  m_LBTick=0;
128  ++m_LBNo;
129  }
130  m_timeStamp += m_timeStampInt;
131  }
132 
133  void previous() {
134  m_nevt--; // decrement serial event number
135  m_eventNo--;
136  m_timeStamp -= m_timeStampInt;
137  if (--m_LBTick <=0) {
138  m_LBTick=m_eventsPLB;
139  --m_LBNo;
140  }
141  }
142 
143  unsigned int runNumber() const { return m_runNo; }
144  uint64_t eventNumber() const { return m_eventNo; }
145  unsigned int lumiBlock() const { return m_LBNo; }
146  unsigned int timeStamp() const { return m_timeStamp; }
147  int serialEventNumber() const { return m_nevt; }
148 
149 
150 
151  void setRunNumber( unsigned int runNo ) { m_runNo = runNo; }
152  void setEventNumber( uint64_t eventNo ) { m_eventNo = eventNo ; }
153  void setEventsPerRun( uint64_t eventsP) { m_eventsP = eventsP ; }
154  void setTimeStamp( unsigned int time ) { m_timeStamp = time; }
155  void setTimeStampInterval( unsigned int intvl ) { m_timeStampInt = intvl; }
156 
157 };
158 
160  m_pSelector(pSelector),
161  m_initRunNo(0),
162  m_initEventNo(0),
163  m_eventsP(2000000000), // <-- match default property of McEventSelector
164  m_initLBNo(0),
165  m_eventsPLB(1000), // <-- ditto
166  m_initTimeStamp(0),
167  m_timeStampInt(0),
168  m_runNo(0),
169  m_eventNo(0),
170  m_LBNo(0),
171  m_timeStamp(0),
172  m_LBTick(0),
173  m_nevt(0),
174  m_firstEvent(true)
175 {}
176 
178  const unsigned int &initRunNo,
179  const uint64_t &initEventNo,
180  const uint64_t &evPR,
181  const unsigned int &initLBNo,
182  const unsigned int &evPLB,
183  const unsigned int &initTimeStamp,
184  const unsigned int &timeStampInt):
185  m_pSelector(pSelector),
186  m_initRunNo(initRunNo), m_initEventNo(initEventNo), m_eventsP(evPR),
187  m_initLBNo(initLBNo), m_eventsPLB(evPLB),
188  m_initTimeStamp(initTimeStamp), m_timeStampInt(timeStampInt),
189  m_runNo(0),
190  m_eventNo(0),
191  m_LBNo(0),
192  m_timeStamp(0),
193  m_LBTick(0),
194  m_nevt(0),
195  m_firstEvent(true)
196 {}
197 
198 
200 }
201 
202 
203 // IInterface::queryInterface
205  void** ppvIf) {
206  if ( riid == IEvtSelector::interfaceID() ) {
207  *ppvIf = (IEvtSelector*)this;
208  addRef();
209  return StatusCode::SUCCESS;
210  } else if (riid == IEvtSelectorSeek::interfaceID() ) {
211  *ppvIf = dynamic_cast<IEvtSelectorSeek*>(this);
212  addRef();
213  return StatusCode::SUCCESS;
214  }
215  return AthService::queryInterface( riid, ppvIf );
216 }
217 
218 
219 McEventSelector::McEventSelector( const std::string& name, ISvcLocator* svcloc ) :
220  AthService( name, svcloc),
221  m_ctx(0)
222 {
223 
224  declareProperty( "RunNumber", m_runNo = 0 );
225  declareProperty( "EventsPerRun", m_eventsPerRun = 2000000000 );
226  declareProperty( "FirstEvent", m_firstEventNo = 1 );
227  m_firstEventNo.verifier().setLower( 1 );
228  declareProperty( "FirstLB", m_firstLBNo = 0);
229  declareProperty( "EventsPerLB", m_eventsPerLB = 1000 );
230  declareProperty( "InitialTimeStamp", m_initTimeStamp = 0);
231  declareProperty( "TimeStampInterval", m_timeStampInterval = 0 );
232 
237  declareProperty( "OverrideRunNumber", m_overrideRunNumber = true );
238  declareProperty( "OverrideEventNumber", m_overrideEventNumber = true );
239  declareProperty( "OverrideTimeStamp", m_overrideTimeStamp = true );
240  declareProperty( "OverrideLBNumber", m_overrideLBNumber = true );
241 
242 }
243 
245  // FIXME: who deletes the Context?
246 }
247 
249 McEventSelector::createContext(Context*& refpCtxt) const
250 {
251  McContext* ctx = new McContext(this,
252  m_runNo.value( ),
253  (uint64_t) m_firstEventNo.value( ),
254  (uint64_t) m_eventsPerRun.value( ),
255  m_firstLBNo.value( ),
256  m_eventsPerLB.value( ),
257  m_initTimeStamp.value( ),
258  m_timeStampInterval.value( )
259  );
260  refpCtxt = ctx;
261 
262  m_ctx = ctx;
263 
264  return StatusCode::SUCCESS;
265 }
266 
268  ATH_MSG_INFO (" Enter McEventSelector Initialization ");
269  return StatusCode::SUCCESS;
270 }
271 
273  ATH_MSG_DEBUG ("............. stop .............");
274 
275  const bool createIf = true;
276  IIncidentSvc* incSvc = 0;
277  if ( !service("IncidentSvc", incSvc, createIf).isSuccess() || 0 == incSvc ) {
278  ATH_MSG_ERROR ("Could not retrieve IncidentSvc ");
279  return StatusCode::FAILURE;
280  }
281  Incident lastInputIncident(name(), "LastInput");
282  incSvc->fireIncident(lastInputIncident);
283 
284  return StatusCode::SUCCESS;
285 }
286 
287 
288 // IEvtSelector::next
290 McEventSelector::next(Context& ctxt) const {
291  ATH_MSG_DEBUG ("............. Next Event .............");
292 
293  McContext* ct = dynamic_cast<McContext*>(&ctxt);
294  StatusCode sc(StatusCode::FAILURE);
295 
296  if (ct != 0 ) {
297  ct->next();
298  sc = StatusCode::SUCCESS;
299  } else {
300  ATH_MSG_ERROR ("Could not dcast to McContext");
301  }
302 
303  m_ctx = ct;
304 
305  return sc;
306 
307 }
309 McEventSelector::next(Context& ctxt,int jump) const
310 {
311  ATH_MSG_DEBUG ("............. Next (" << jump << ") .............");
312 
313  if ( jump > 0 ) {
314  for ( int i = 0; i < jump; ++i ) {
315  StatusCode status = next(ctxt);
316  if ( !status.isSuccess() ) {
317  return status;
318  }
319  }
320  return StatusCode::SUCCESS;
321  }
322  return StatusCode::FAILURE;
323 }
324 
325 
326 // IEvtSelector::previous
328 McEventSelector::previous(Context& ctxt) const {
329  ATH_MSG_DEBUG ("............. previous .............");
330 
331  McContext* ct = dynamic_cast<McContext*>(&ctxt);
332 
333  StatusCode sc(StatusCode::FAILURE);
334 
335  if (ct != 0 ) {
336  ct->previous();
337  sc = StatusCode::SUCCESS;
338  } else {
339  ATH_MSG_ERROR ("Could not dcast to McContext");
340  }
341 
342  m_ctx = ct;
343 
344  return sc;
345 
346 }
347 
349 McEventSelector::previous(Context& ctxt, int jump) const
350 {
351  if ( jump > 0 ) {
352  for ( int i = 0; i < jump; ++i ) {
353  StatusCode status = previous(ctxt);
354  if ( !status.isSuccess() ) {
355  return status;
356  }
357  }
358  return StatusCode::SUCCESS;
359  }
360  return StatusCode::FAILURE;
361 }
362 
364 McEventSelector::last(Context& /*ctxt*/) const {
365  ATH_MSG_ERROR ("............. Last Event Not Implemented .............");
366  return StatusCode::FAILURE;
367 }
368 
369 
371 McEventSelector::rewind(Context& ctxt) const
372 {
373  ATH_MSG_DEBUG ("............. rewind .............");
374 
375  McContext* ct = dynamic_cast<McContext*>(&ctxt);
376  StatusCode sc(StatusCode::FAILURE);
377 
378  if (ct != 0 ) {
379  ct->rewind();
380  sc = StatusCode::SUCCESS;
381  } else {
382  ATH_MSG_ERROR ("Could not dcast to McContext");
383  }
384 
385  m_ctx = ct;
386  return sc;
387 
388 }
389 
390 
392 McEventSelector::createAddress(const Context& refCtxt,
393  IOpaqueAddress*& addr) const {
394 
395  ATH_MSG_DEBUG ("............. createAddress .............");
396 
397  const McContext* ctx = dynamic_cast<const McContext*>( &refCtxt );
398 
399  if (ctx != 0) {
400  addr = new McAddress(EventInfo::classID(), "McEventInfo",
401  ctx->runNumber(), ctx->eventNumber(),
402  ctx->lumiBlock(),ctx->timeStamp());
403  m_ctx = const_cast<McContext*> (ctx);
404  } else {
405  ATH_MSG_ERROR ("casting to a McContext");
406  return StatusCode::FAILURE;
407  }
408 
409  return StatusCode::SUCCESS;
410 
411 }
412 
414 McEventSelector::releaseContext(Context*& /*refCtxt*/) const {
415 
416  // Nothing to do.
417  return StatusCode::SUCCESS;
418 
419 }
420 
422 McEventSelector::resetCriteria(const std::string&, Context& ) const {
423 
424  ATH_MSG_ERROR ("............. resetCriteria Not Implemented .............");
425  return StatusCode::FAILURE;
426 
427 }
428 
430 McEventSelector::seek(Context& /*refCtxt*/, int evtNum) const {
431 
432  ATH_MSG_DEBUG ("............. seek(" << evtNum << ") .............");
433 
434  m_ctx->rewind();
435 
436  for (int i=0; i < evtNum; ++i) {
437  m_ctx->next();
438  }
439 
440  return StatusCode::SUCCESS;
441 }
442 
443 int
444 McEventSelector::curEvent (const Context& /*refCtxt*/) const {
445 
446  ATH_MSG_DEBUG ("............. curEvent .............");
447 
448 
449  return m_ctx->serialEventNumber();
450 }
451 
452 int
453 McEventSelector::size (Context& /*refCtxt*/) const
454 {
455  return -1;
456 }
457 
McEventSelector::m_runNo
Gaudi::CheckedProperty< unsigned > m_runNo
Definition: McEventSelector.h:76
McContext::m_eventsPLB
unsigned int m_eventsPLB
Definition: McEventSelector.cxx:47
McEventSelector::~McEventSelector
~McEventSelector()
Definition: McEventSelector.cxx:244
McContext::m_pSelector
const McEventSelector * m_pSelector
Definition: McEventSelector.cxx:40
McContext::m_initLBNo
unsigned int m_initLBNo
Definition: McEventSelector.cxx:46
McEventSelector::curEvent
virtual int curEvent(const Context &refCtxt) const override
return the current event number.
Definition: McEventSelector.cxx:444
McContext::m_LBNo
unsigned int m_LBNo
Definition: McEventSelector.cxx:54
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
McEventSelector::m_eventsPerRun
Gaudi::CheckedProperty< unsigned long long > m_eventsPerRun
Definition: McEventSelector.h:78
McEventSelector::m_overrideLBNumber
Gaudi::Property< bool > m_overrideLBNumber
Definition: McEventSelector.h:90
McEventSelector::stop
virtual StatusCode stop() override
Definition: McEventSelector.cxx:272
McContext::m_firstEvent
bool m_firstEvent
Definition: McEventSelector.cxx:59
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition: checker_macros.h:212
McContext::setEventNumber
void setEventNumber(uint64_t eventNo)
Definition: McEventSelector.cxx:152
McEventSelector::rewind
virtual StatusCode rewind(Context &refCtxt) const override
Definition: McEventSelector.cxx:371
McEventSelector::seek
virtual StatusCode seek(Context &refCtxt, int) const override
Seek to a given event number.
Definition: McEventSelector.cxx:430
McContext::m_runNo
unsigned int m_runNo
Definition: McEventSelector.cxx:52
McContext::setTimeStampInterval
void setTimeStampInterval(unsigned int intvl)
Definition: McEventSelector.cxx:155
McEventSelector::m_overrideRunNumber
Gaudi::Property< bool > m_overrideRunNumber
Flags to indicate override of run/event/time These are always true and are here for consistency with ...
Definition: McEventSelector.h:88
McContext::m_eventNo
uint64_t m_eventNo
Definition: McEventSelector.cxx:53
McContext::eventNumber
uint64_t eventNumber() const
Definition: McEventSelector.cxx:144
McContext::m_initRunNo
unsigned int m_initRunNo
Definition: McEventSelector.cxx:43
McEventSelector::m_overrideTimeStamp
Gaudi::Property< bool > m_overrideTimeStamp
Definition: McEventSelector.h:91
McEventSelector::m_timeStampInterval
Gaudi::Property< unsigned > m_timeStampInterval
Definition: McEventSelector.h:82
McEventSelector::releaseContext
virtual StatusCode releaseContext(Context *&refCtxt) const override
Definition: McEventSelector.cxx:414
McContext::m_nevt
int m_nevt
Definition: McEventSelector.cxx:57
McContext::serialEventNumber
int serialEventNumber() const
Definition: McEventSelector.cxx:147
McEventSelector::m_overrideEventNumber
Gaudi::Property< bool > m_overrideEventNumber
Definition: McEventSelector.h:89
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
McContext::setTimeStamp
void setTimeStamp(unsigned int time)
Definition: McEventSelector.cxx:154
EventInfo::classID
static const CLID & classID()
Definition: EventInfo/EventInfo/EventInfo.h:302
McEventSelector::queryInterface
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface) override
Definition: McEventSelector.cxx:204
McContext::setRunNumber
void setRunNumber(unsigned int runNo)
Definition: McEventSelector.cxx:151
McEventSelector::next
virtual StatusCode next(Context &refCtxt) const override
Definition: McEventSelector.cxx:290
McAddress
Definition: McAddress.h:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
McEventSelector::previous
virtual StatusCode previous(Context &refCtxt) const override
Definition: McEventSelector.cxx:328
McContext::m_timeStampInt
unsigned int m_timeStampInt
Definition: McEventSelector.cxx:50
McContext::m_eventsP
uint64_t m_eventsP
Definition: McEventSelector.cxx:45
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthService
Definition: AthService.h:32
McContext::m_initEventNo
uint64_t m_initEventNo
Definition: McEventSelector.cxx:44
McContext::runNumber
unsigned int runNumber() const
Definition: McEventSelector.cxx:143
McContext::timeStamp
unsigned int timeStamp() const
Definition: McEventSelector.cxx:146
McEventSelector::McEventSelector
McEventSelector(const std::string &name, ISvcLocator *svcloc)
Service Constructor.
Definition: McEventSelector.cxx:219
McEventSelector::createAddress
virtual StatusCode createAddress(const Context &refCtxt, IOpaqueAddress *&) const override
Definition: McEventSelector.cxx:392
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
McEventSelector::size
virtual int size(Context &refCtxt) const override
Return the size of the collection, or -1 if we can't get the size.
Definition: McEventSelector.cxx:453
McEventSelector::m_initTimeStamp
Gaudi::CheckedProperty< unsigned > m_initTimeStamp
Definition: McEventSelector.h:81
calibdata.ct
ct
Definition: calibdata.py:418
McContext::rewind
void rewind()
Definition: McEventSelector.cxx:82
McContext::m_initTimeStamp
unsigned int m_initTimeStamp
Definition: McEventSelector.cxx:49
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
McEventSelector::m_eventsPerLB
Gaudi::CheckedProperty< unsigned > m_eventsPerLB
Definition: McEventSelector.h:80
McEventSelector::initialize
virtual StatusCode initialize() override
Definition: McEventSelector.cxx:267
McContext::lumiBlock
unsigned int lumiBlock() const
Definition: McEventSelector.cxx:145
McContext::setEventsPerRun
void setEventsPerRun(uint64_t eventsP)
Definition: McEventSelector.cxx:153
McEventSelector::m_firstEventNo
Gaudi::CheckedProperty< unsigned long long > m_firstEventNo
Definition: McEventSelector.h:77
McContext::next
void next()
Definition: McEventSelector.cxx:101
McContext::identifier
virtual void * identifier() const
Definition: McEventSelector.cxx:75
McContext::m_LBTick
unsigned int m_LBTick
Definition: McEventSelector.cxx:56
McContext::previous
void previous()
Definition: McEventSelector.cxx:133
McEventSelector::last
virtual StatusCode last(Context &refContext) const override
Definition: McEventSelector.cxx:364
McContext::m_criteria
std::string m_criteria
Definition: McEventSelector.cxx:41
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
McContext::m_timeStamp
unsigned int m_timeStamp
Definition: McEventSelector.cxx:55
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
McEventSelector::resetCriteria
virtual StatusCode resetCriteria(const std::string &cr, Context &c) const override
Definition: McEventSelector.cxx:422
McContext::setCriteria
void setCriteria(const std::string &crit)
Definition: McEventSelector.cxx:78
merge.status
status
Definition: merge.py:17
McEventSelector::createContext
virtual StatusCode createContext(Context *&refpCtxt) const override
Definition: McEventSelector.cxx:249
McContext::McContext
McContext(const McEventSelector *pSelector)
Standard constructor.
Definition: McEventSelector.cxx:159
McEventSelector.h
McContext::~McContext
virtual ~McContext()
Standard destructor.
Definition: McEventSelector.cxx:199
McContext
Definition: McEventSelector.cxx:38
McEventSelector::m_ctx
McContext * m_ctx
Definition: McEventSelector.h:93
IEvtSelectorSeek
Abstract interface for seeking for an event selector.
Definition: IEvtSelectorSeek.h:28
McAddress.h
McEventSelector
Definition: McEventSelector.h:44
McEventSelector::m_firstLBNo
Gaudi::CheckedProperty< unsigned > m_firstLBNo
Definition: McEventSelector.h:79