7 __doc__ =
'A set of python components for event filtering'
8 __author__ =
'Sebastien Binet <binet@cern.ch>'
10 import AthenaPython.PyAthena
as PyAthena
11 from AthenaPython.PyAthena
import StatusCode
14 """Filtering algorithm to be used in conjunction with an AthSequencer.
15 Different operating modes are possible:
16 - give a list of events to accept
17 - give a list of events to veto
18 For each of these modes, the list of events can be:
19 - a list of event numbers: [ 13, 45, 24, 90 ]
20 - a list of pairs run/evt [ (1,13), (1,45), ... ]
22 Note that when in 'event list' mode and an event is found in the
23 event list, the event is accepted or not according to the
24 'filter_policy' property value ('accept' XOR 'reject')
26 Another way of filtering events is to provide the component with a
27 filtering function (via the 'filter_fct' property) which is expected
29 def my_filter_fct (runnbr, evtnbr):
34 athena> seq = AthSequencer('seq')
35 athena> from GaudiSequencer.PyComps import PyEvtFilter
36 athena> seq += PyEvtFilter ('alg')
37 athena> seq.alg.filter_fct = lambda run,evt: evt in xrange(100)
40 athena> def my_filter_fct(runnbr, evtnbr):
41 ... if runnbr > 5001 and runnbr < 5100 and
42 ... ( evtnbr in [ 1, 34, 600] or evtnbr > 600 ):
45 athena> seq.alg.filter_fct = my_filter_fct
47 or: (veto events 3,4 and 10)
48 athena> seq.alg.filter_fct = lambda r,e : e not in [3,4,10]
51 athena> seq.alg.evt_list = [ (5010, 3), (5010, 4) ]
52 athena> seq.alg.evt_list = xrange(100)
53 athena> seq.alg.evt_list = range(10) + range(15,20)
54 athena> seq.alg.evt_list = map (lambda evt: (5100, evt), xrange(100))
57 athena> seq.alg.evt_list = [ 10, 3, 40 ]
58 athena> seq.alg.filter_policy = 'reject'
63 super(PyEvtFilter, self).
__init__(**kw)
80 _error = self.
msg.error
81 _info(
'==> initialize...')
85 _error (
'invalid properties: evt_list *and* filter_fct are None !')
86 _error (
'usage:\n%s', self.__doc__)
87 return StatusCode.Failure
89 if (
not (self.
evt_list is None))
and \
91 _error (
'invalid properties: evt_list *and* filter_fct '
93 _error (
'usage:\n%s', self.__doc__)
94 return StatusCode.Failure
102 _error (
'filter_fct has NOT the expected signature')
103 _error (
' nbr of arguments: %i', len(args))
104 _error (
' expected: 2')
105 return StatusCode.Failure
107 _error (
'invalid value for filter_policy: %r',
109 _error (
"valid values are 'reject' or 'accept'")
110 return StatusCode.Failure
116 if isinstance(i, tuple): irun, ievt = i
117 else: irun, ievt =
None, i
120 _info (
'EventInfo name: %s',
125 _info(
"filtering mode: evt_list")
130 _info (
"filtering mode: filter_fct")
132 self.
sg = PyAthena.py_svc (
'StoreGateSvc')
134 _error (
'could not retrieve event store')
135 return StatusCode.Failure
140 return StatusCode.Success
144 _info = self.
msg.info
145 _error= self.
msg.error
147 evtinfo = self.
sg.retrieve (
'EventInfo', self.
evt_info)
149 _error (
'could not retrieve EventInfo at [%s]', self.
evt_info)
150 return StatusCode.Failure
154 evtid = evtinfo.event_ID()
155 runnbr = evtid.run_number()
156 evtnbr = evtid.event_number()
158 filter_passed = self.
filter_fct (runnbr, evtnbr)
160 if (runnbr,evtnbr)
in self.
evt_list or \
167 if not isinstance(filter_passed, bool):
168 self.
msg.error (
'invalid filter-passed decision: %r', filter_passed)
169 return StatusCode.Failure
171 self.setFilterPassed (filter_passed)
178 _info (
'[run=%s | evt=%s] ==> [%s]',
179 str(runnbr).zfill(5),
180 str(evtnbr).zfill(5),
182 return StatusCode.Success
185 _info = self.
msg.info
186 _info (
'==> finalize...')
187 _info (
' #evts processed: %i', self.
_evt_cnt)
190 return StatusCode.Success