ATLAS Offline Software
Loading...
Searching...
No Matches
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
38class ATLAS_NOT_THREAD_SAFE McContext : public IEvtSelector::Context {
39private:
41 std::string m_criteria;
42
43 unsigned int m_initRunNo;
44 uint64_t m_initEventNo;
45 uint64_t m_eventsP;
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;
53 uint64_t m_eventNo;
54 unsigned int m_LBNo;
55 unsigned int m_timeStamp;
56 unsigned int m_LBTick;
57 int m_nevt;
58
60
61
62public:
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
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
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 }
131 }
132
133 void previous() {
134 m_nevt--; // decrement serial event number
135 m_eventNo--;
137 if (--m_LBTick <=0) {
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
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
201
202
203McEventSelector::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
232StatusCode
233McEventSelector::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
270StatusCode
271McEventSelector::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}
289StatusCode
290McEventSelector::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
308StatusCode
309McEventSelector::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
329StatusCode
330McEventSelector::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
344StatusCode
345McEventSelector::last(Context& /*ctxt*/) const {
346 ATH_MSG_ERROR ("............. Last Event Not Implemented .............");
347 return StatusCode::FAILURE;
348}
349
350
351StatusCode
352McEventSelector::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
372StatusCode
373McEventSelector::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
394StatusCode
395McEventSelector::releaseContext(Context*& /*refCtxt*/) const {
396
397 // Nothing to do.
398 return StatusCode::SUCCESS;
399
400}
401
402StatusCode
403McEventSelector::resetCriteria(const std::string&, Context& ) const {
404
405 ATH_MSG_ERROR ("............. resetCriteria Not Implemented .............");
406 return StatusCode::FAILURE;
407
408}
409
410StatusCode
411McEventSelector::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
424int
425McEventSelector::curEvent (const Context& /*refCtxt*/) const {
426
427 ATH_MSG_DEBUG ("............. curEvent .............");
428
429
430 return m_ctx->serialEventNumber();
431}
432
433int
434McEventSelector::size (Context& /*refCtxt*/) const
435{
436 return -1;
437}
438
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
unsigned int m_initRunNo
uint64_t m_initEventNo
unsigned int m_initTimeStamp
std::string m_criteria
void setCriteria(const std::string &crit)
virtual ~McContext()
Standard destructor.
uint64_t eventNumber() const
unsigned int m_LBTick
const McEventSelector * m_pSelector
unsigned int m_LBNo
int serialEventNumber() const
void setEventNumber(uint64_t eventNo)
uint64_t m_eventNo
void setTimeStamp(unsigned int time)
unsigned int m_timeStamp
unsigned int m_initLBNo
unsigned int runNumber() const
virtual void * identifier() const
unsigned int m_eventsPLB
unsigned int timeStamp() const
unsigned int m_runNo
unsigned int lumiBlock() const
void setTimeStampInterval(unsigned int intvl)
unsigned int m_timeStampInt
void setRunNumber(unsigned int runNo)
McContext(const McEventSelector *pSelector)
Standard constructor.
uint64_t m_eventsP
void setEventsPerRun(uint64_t eventsP)
Gaudi::CheckedProperty< uint32_t > m_runNo
McContext * m_ctx
virtual StatusCode next(Context &refCtxt) const override
Gaudi::CheckedProperty< uint64_t > m_eventsPerRun
virtual StatusCode rewind(Context &refCtxt) const override
virtual StatusCode last(Context &refContext) const override
virtual StatusCode resetCriteria(const std::string &cr, Context &c) const override
virtual StatusCode seek(Context &refCtxt, int) const override
Gaudi::Property< bool > m_overrideEventNumber
virtual int size(Context &refCtxt) const override
Gaudi::Property< uint32_t > m_timeStampInterval
Gaudi::CheckedProperty< uint32_t > m_initTimeStamp
Gaudi::CheckedProperty< uint32_t > m_firstLBNo
Gaudi::Property< bool > m_overrideTimeStamp
McEventSelector(const std::string &name, ISvcLocator *svcloc)
Service Constructor.
virtual StatusCode stop() override
Gaudi::Property< bool > m_overrideRunNumber
Flags to indicate override of run/event/time These are always true and are here for consistency with ...
virtual StatusCode createAddress(const Context &refCtxt, IOpaqueAddress *&) const override
virtual StatusCode createContext(Context *&refpCtxt) const override
Gaudi::CheckedProperty< uint32_t > m_eventsPerLB
virtual int curEvent(const Context &refCtxt) const override
Gaudi::Property< bool > m_overrideLBNumber
Gaudi::CheckedProperty< uint64_t > m_firstEventNo
virtual StatusCode releaseContext(Context *&refCtxt) const override
virtual StatusCode previous(Context &refCtxt) const override
virtual StatusCode initialize() override