def initializeDic(self,dic): for name in dic.keys(): alg=PyAthena.py_alg(name,iface='Algorithm') if alg: pass else: alg=PyAthena.py_alg(name,iface='IAlgorithm') if alg: dic[name]["Alg"]=alg self.msg.debug("Succesfully added algorithm '%s'"%name) else: self.msg.warning("BookkeepingWriterBase cannot get algorithm '%s'. This alg will not be bookkept."%name) dic.pop(name) return
def getJobOptions(self): self.StreamToFileTool = PyAthena.py_tool('JiveXML::StreamToFileTool', iface='IProperty') self.StreamToServerTool = PyAthena.py_tool( 'JiveXML::StreamToServerTool', iface='IProperty') # Some casting magic is needed to access algorithm properties from GaudiPython.Bindings import gbl, InterfaceCast vp1alg = PyAthena.py_alg('VP1EventProd') self.VP1EventProducer = InterfaceCast(gbl.IProperty).cast(vp1alg) self.msg.info("StreamToFileTool: %s" % self.StreamToFileTool) self.msg.info("StreamToServerTool: %s" % self.StreamToServerTool) self.msg.info("VP1EventProducer: %s" % self.VP1EventProducer)
def initialize(self): self.msg.info( '************************************' ) self.msg.info( '==> initialize %s...', self.name() ) self.msg.info( '************************************' ) self.cutFlowSvc().setFilterDescription(self.cutID,self.cmdstring) # look if parentheses are matched if self.cmdstring.count("(") != self.cmdstring.count(")"): self.msg.fatal("Mismatched parentheses in filter string: %s" % self.cmdstring) return False # these parentheses are not logically correct if self.cmdstring.count("{") != 0 or \ self.cmdstring.count("}") != 0 or \ self.cmdstring.count("[") != 0 or \ self.cmdstring.count("]") != 0: self.msg.fatal("Wrong type of parentheses in filter string: %s" % self.cmdstring) return False try: tokenobj = tokenize.generate_tokens(StringIO(self.cmdstring).readline) self.algdict = {} result = [] for toknum, tokval, _, _, _ in tokenobj: if toknum == tokenize.NAME and \ tokval != 'or' and \ tokval != 'not' and \ tokval != 'and' and \ tokval != 'True' and \ tokval != 'False': if self.prefix != '': tokval = "%s_%s" % (self.prefix, tokval) self.msg.info("Adding algorithm: %s", tokval) _alg = None _alg = PyAthena.py_alg(tokval) self.algdict.update({tokval : _alg}) if not _alg: self.msg.error("Algorithm %s not found" , tokval) return False else: self.msg.debug("Found algorithm: %s -> %s" % (tokval, _alg)) exec('self.%s = _alg' % tokval) self.cutFlowSvc().declareChildFilter(tokval,self.cutID) result.extend([ (tokenize.STRING, 'self.%s' % tokval), (tokenize.OP, '.'), (tokenize.STRING, 'filterPassed'), (tokenize.OP, '('), (tokenize.OP, ')') ]) else: result.append((toknum, tokval)) self.cmd = tokenize.untokenize(result) self.msg.debug("String changed internally to:\n%s", self.cmd) #execute command once to validate response = bool(eval(self.cmd)) except Exception, e: self.msg.fatal("Not a valid Python string. Exception: %s" % e) return False
def initialize(self): self.algdict = {} filterNames = [] # go through filters, creating if necessary for filterTypeAndName in self.filters: l = filterTypeAndName.split('/') filterType = l[0] filterName = l[1] filterNames += [filterName] _alg = PyAthena.py_alg(filterName, 'IAlgorithm') if not _alg: #try to create algmgr = PyAthena.py_svc('ApplicationMgr', iface='IAlgManager') if not algmgr: error = 'could not retrieve IAlgManager/ApplicationMgr' self.msg.error(error) raise RuntimeError(error) import PyCintex _alg = PyCintex.libPyROOT.MakeNullPointer("IAlgorithm") if algmgr.createAlgorithm(filterType, filterName, _alg).isFailure() or not _alg: self.msg.error('could not create alg: ' + filterTypeAndName) raise RuntimeError('could not create alg: ' + filterTypeAndName) #we are responsible for initializing it too if _alg.sysInitialize().isFailure(): self.msg.error('Failed to initialize alg: ' + filterTypeAndName) raise RuntimeError('Failed not initialize alg: ' + filterTypeAndName) self.ownedAlgs += [_alg] self.algdict[filterName] = _alg if self.Expression == "": #do a simple and of all the filters given self.Expression = " and ".join(filterNames) self.msg.debug("Filter Expression = " + self.Expression) # look if parentheses are matched if self.Expression.count("(") != self.Expression.count(")"): self.msg.fatal("Mismatched parentheses in filter string: %s" % self.Expression) return StatusCode.Failure # these parentheses are not logically correct if self.Expression.count("{") != 0 or \ self.Expression.count("}") != 0 or \ self.Expression.count("[") != 0 or \ self.Expression.count("]") != 0: self.msg.fatal("Wrong type of parentheses in filter string: %s" % self.Expression) return StatusCode.Failure try: tokenobj = tokenize.generate_tokens( StringIO(self.Expression).readline) result = [] for toknum, tokval, _, _, _ in tokenobj: if toknum == tokenize.NAME and \ tokval != 'or' and \ tokval != 'not' and \ tokval != 'and' and \ tokval != 'True' and \ tokval != 'False': #check the token is a known alg if tokval not in self.algdict: self.msg.error("Unknown alg : " + tokval) return StatusCode.Failure result.extend([(tokenize.STRING, 'self'), (tokenize.OP, '.'), (tokenize.STRING, 'evalFilter'), (tokenize.OP, '('), (tokenize.OP, '"%s"' % tokval), (tokenize.OP, ')')]) else: result.append((toknum, tokval)) self.cmd = tokenize.untokenize(result) self.msg.debug("String changed internally to:\n%s", self.cmd) #execute command once to validate #response = bool(eval(self.cmd)) except Exception as e: self.msg.fatal( "%s is not a valid Python expression string. Exception: %s" % (self.Expression, e)) return StatusCode.Failure # If needed, set up a random number generator if self.Sampling >= 0: random.seed(1234) return StatusCode.Success