16 __doc__ =
"""This algorithm combines the results of one or more skim filters"""
18 __author__ =
"Marcello Barisonzi <Marcello.Barisonzi@desy.de>"
20 import AthenaPython.PyAthena
as PyAthena
23 from io
import StringIO
27 def __init__ ( self, name = 'LogicalFilterCombiner', **kw ):
30 super(LogicalFilterCombiner, self).
__init__(**kw)
44 self.msg.
info(
'************************************' )
45 self.msg.
info(
'==> initialize %s...', self.name() )
46 self.msg.
info(
'************************************' )
47 self.cutFlowSvc().setFilterDescription(self.cutID,self.
cmdstring)
51 self.msg.fatal(
"Mismatched parentheses in filter string: %s" % self.
cmdstring)
59 self.msg.fatal(
"Wrong type of parentheses in filter string: %s" % self.
cmdstring)
63 tokenobj = tokenize.generate_tokens(StringIO(self.
cmdstring).readline)
69 for toknum, tokval, _, _, _
in tokenobj:
70 if toknum == tokenize.NAME
and \
74 tokval !=
'True' and \
78 tokval =
"%s_%s" % (self.
prefix, tokval)
80 self.msg.
info(
"Adding algorithm: %s", tokval)
85 _alg = PyAthena.py_alg(tokval)
90 self.msg.
error(
"Algorithm %s not found" , tokval)
93 self.msg.
debug(
"Found algorithm: %s -> %s", tokval, _alg)
95 exec(
'self.%s = _alg' % tokval)
96 self.cutFlowSvc().declareChildFilter(tokval,self.cutID)
99 (tokenize.STRING,
'self.%s' % tokval),
101 (tokenize.STRING,
'filterPassed'),
107 result.append((toknum, tokval))
109 self.
cmd = tokenize.untokenize(result)
111 self.msg.
debug(
"String changed internally to:\n%s", self.
cmd)
115 except Exception
as e:
116 self.msg.fatal(
"Not a valid Python string. Exception: %s" % e)
118 self.msg.fatal(traceback.format_exc())
121 self.msg.
info(
"Filter string validated")
129 self.msg.
debug(
"Alg %s : %s", k, v.filterPassed())
134 response =
bool(eval(self.
cmd))
137 self.msg.
debug(
"Response is: %s", response)
138 self.setFilterPassed(response)