ATLAS Offline Software
McEventSelector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 McEventSelector::McEventSelector( const std::string& name, ISvcLocator* svcloc ) :
204  base_class( name, svcloc),
205  m_ctx(0)
206 {
207 
208  declareProperty( "RunNumber", m_runNo = 0 );
209  declareProperty( "EventsPerRun", m_eventsPerRun = 2000000000 );
210  declareProperty( "FirstEvent", m_firstEventNo = 1 );
211  m_firstEventNo.verifier().setLower( 1 );
212  declareProperty( "FirstLB", m_firstLBNo = 0);
213  declareProperty( "EventsPerLB", m_eventsPerLB = 1000 );
214  declareProperty( "InitialTimeStamp", m_initTimeStamp = 0);
215  declareProperty( "TimeStampInterval", m_timeStampInterval = 0 );
216 
221  declareProperty( "OverrideRunNumber", m_overrideRunNumber = true );
222  declareProperty( "OverrideEventNumber", m_overrideEventNumber = true );
223  declareProperty( "OverrideTimeStamp", m_overrideTimeStamp = true );
224  declareProperty( "OverrideLBNumber", m_overrideLBNumber = true );
225 
226 }
227 
229  // FIXME: who deletes the Context?
230 }
231 
233 McEventSelector::createContext(Context*& refpCtxt) const
234 {
235  McContext* ctx = new McContext(this,
236  m_runNo.value( ),
237  (uint64_t) m_firstEventNo.value( ),
238  (uint64_t) m_eventsPerRun.value( ),
239  m_firstLBNo.value( ),
240  m_eventsPerLB.value( ),
241  m_initTimeStamp.value( ),
242  m_timeStampInterval.value( )
243  );
244  refpCtxt = ctx;
245 
246  m_ctx = ctx;
247 
248  return StatusCode::SUCCESS;
249 }
250 
252  ATH_MSG_INFO (" Enter McEventSelector Initialization ");
253  return StatusCode::SUCCESS;
254 }
255 
257  ATH_MSG_DEBUG ("............. stop .............");
258 
259  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", name());
260  ATH_CHECK( incSvc.retrieve() );
261 
262  Incident lastInputIncident(name(), "LastInput");
263  incSvc->fireIncident(lastInputIncident);
264 
265  return StatusCode::SUCCESS;
266 }
267 
268 
269 // IEvtSelector::next
271 McEventSelector::next(Context& ctxt) const {
272  ATH_MSG_DEBUG ("............. Next Event .............");
273 
274  McContext* ct = dynamic_cast<McContext*>(&ctxt);
275  StatusCode sc(StatusCode::FAILURE);
276 
277  if (ct != 0 ) {
278  ct->next();
279  sc = StatusCode::SUCCESS;
280  } else {
281  ATH_MSG_ERROR ("Could not dcast to McContext");
282  }
283 
284  m_ctx = ct;
285 
286  return sc;
287 
288 }
290 McEventSelector::next(Context& ctxt,int jump) const
291 {
292  ATH_MSG_DEBUG ("............. Next (" << jump << ") .............");
293 
294  if ( jump > 0 ) {
295  for ( int i = 0; i < jump; ++i ) {
296  StatusCode status = next(ctxt);
297  if ( !status.isSuccess() ) {
298  return status;
299  }
300  }
301  return StatusCode::SUCCESS;
302  }
303  return StatusCode::FAILURE;
304 }
305 
306 
307 // IEvtSelector::previous
309 McEventSelector::previous(Context& ctxt) const {
310  ATH_MSG_DEBUG ("............. previous .............");
311 
312  McContext* ct = dynamic_cast<McContext*>(&ctxt);
313 
314  StatusCode sc(StatusCode::FAILURE);
315 
316  if (ct != 0 ) {
317  ct->previous();
318  sc = StatusCode::SUCCESS;
319  } else {
320  ATH_MSG_ERROR ("Could not dcast to McContext");
321  }
322 
323  m_ctx = ct;
324 
325  return sc;
326 
327 }
328 
330 McEventSelector::previous(Context& ctxt, int jump) const
331 {
332  if ( jump > 0 ) {
333  for ( int i = 0; i < jump; ++i ) {
334  StatusCode status = previous(ctxt);
335  if ( !status.isSuccess() ) {
336  return status;
337  }
338  }
339  return StatusCode::SUCCESS;
340  }
341  return StatusCode::FAILURE;
342 }
343 
345 McEventSelector::last(Context& /*ctxt*/) const {
346  ATH_MSG_ERROR ("............. Last Event Not Implemented .............");
347  return StatusCode::FAILURE;
348 }
349 
350 
352 McEventSelector::rewind(Context& ctxt) const
353 {
354  ATH_MSG_DEBUG ("............. rewind .............");
355 
356  McContext* ct = dynamic_cast<McContext*>(&ctxt);
357  StatusCode sc(StatusCode::FAILURE);
358 
359  if (ct != 0 ) {
360  ct->rewind();
361  sc = StatusCode::SUCCESS;
362  } else {
363  ATH_MSG_ERROR ("Could not dcast to McContext");
364  }
365 
366  m_ctx = ct;
367  return sc;
368 
369 }
370 
371 
373 McEventSelector::createAddress(const Context& refCtxt,
374  IOpaqueAddress*& addr) const {
375 
376  ATH_MSG_DEBUG ("............. createAddress .............");
377 
378  const McContext* ctx = dynamic_cast<const McContext*>( &refCtxt );
379 
380  if (ctx != 0) {
381  addr = new McAddress(EventInfo::classID(), "McEventInfo",
382  ctx->runNumber(), ctx->eventNumber(),
383  ctx->lumiBlock(),ctx->timeStamp());
384  m_ctx = const_cast<McContext*> (ctx);
385  } else {
386  ATH_MSG_ERROR ("casting to a McContext");
387  return StatusCode::FAILURE;
388  }
389 
390  return StatusCode::SUCCESS;
391 
392 }
393 
395 McEventSelector::releaseContext(Context*& /*refCtxt*/) const {
396 
397  // Nothing to do.
398  return StatusCode::SUCCESS;
399 
400 }
401 
403 McEventSelector::resetCriteria(const std::string&, Context& ) const {
404 
405  ATH_MSG_ERROR ("............. resetCriteria Not Implemented .............");
406  return StatusCode::FAILURE;
407 
408 }
409 
411 McEventSelector::seek(Context& /*refCtxt*/, int evtNum) const {
412 
413  ATH_MSG_DEBUG ("............. seek(" << evtNum << ") .............");
414 
415  m_ctx->rewind();
416 
417  for (int i=0; i < evtNum; ++i) {
418  m_ctx->next();
419  }
420 
421  return StatusCode::SUCCESS;
422 }
423 
424 int
425 McEventSelector::curEvent (const Context& /*refCtxt*/) const {
426 
427  ATH_MSG_DEBUG ("............. curEvent .............");
428 
429 
430  return m_ctx->serialEventNumber();
431 }
432 
433 int
434 McEventSelector::size (Context& /*refCtxt*/) const
435 {
436  return -1;
437 }
438 
McEventSelector::m_runNo
Gaudi::CheckedProperty< unsigned > m_runNo
Definition: McEventSelector.h:74
McContext::m_eventsPLB
unsigned int m_eventsPLB
Definition: McEventSelector.cxx:47
McEventSelector::~McEventSelector
~McEventSelector()
Definition: McEventSelector.cxx:228
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
Definition: McEventSelector.cxx:425
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:76
McEventSelector::m_overrideLBNumber
Gaudi::Property< bool > m_overrideLBNumber
Definition: McEventSelector.h:88
McEventSelector::stop
virtual StatusCode stop() override
Definition: McEventSelector.cxx:256
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:352
McEventSelector::seek
virtual StatusCode seek(Context &refCtxt, int) const override
Definition: McEventSelector.cxx:411
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:86
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:89
McEventSelector::m_timeStampInterval
Gaudi::Property< unsigned > m_timeStampInterval
Definition: McEventSelector.h:80
McEventSelector::releaseContext
virtual StatusCode releaseContext(Context *&refCtxt) const override
Definition: McEventSelector.cxx:395
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:87
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:316
McContext::setRunNumber
void setRunNumber(unsigned int runNo)
Definition: McEventSelector.cxx:151
McEventSelector::next
virtual StatusCode next(Context &refCtxt) const override
Definition: McEventSelector.cxx:271
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:309
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:85
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
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:203
McEventSelector::createAddress
virtual StatusCode createAddress(const Context &refCtxt, IOpaqueAddress *&) const override
Definition: McEventSelector.cxx:373
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
McEventSelector::size
virtual int size(Context &refCtxt) const override
Definition: McEventSelector.cxx:434
McEventSelector::m_initTimeStamp
Gaudi::CheckedProperty< unsigned > m_initTimeStamp
Definition: McEventSelector.h:79
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:228
McEventSelector::m_eventsPerLB
Gaudi::CheckedProperty< unsigned > m_eventsPerLB
Definition: McEventSelector.h:78
McEventSelector::initialize
virtual StatusCode initialize() override
Definition: McEventSelector.cxx:251
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:75
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:345
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
McEventSelector::resetCriteria
virtual StatusCode resetCriteria(const std::string &cr, Context &c) const override
Definition: McEventSelector.cxx:403
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:233
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:91
McAddress.h
ServiceHandle< IIncidentSvc >
McEventSelector
Definition: McEventSelector.h:44
McEventSelector::m_firstLBNo
Gaudi::CheckedProperty< unsigned > m_firstLBNo
Definition: McEventSelector.h:77