Commit 586e439b authored by scott snyder's avatar scott snyder Committed by scott snyder
Browse files

TrigConfigSvc: Fix flake8 py3 warnings.

 - print function
 - int/long
 - syntax for catching and raising exceptions
 - xrange -> range
 - file -> open; use binary files for pickles.
 - cmp
 
parent 09553919
#!/usr/bin/env python
from __future__ import print_function
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
from AthenaCommon.Logging import logging
import time
......@@ -47,10 +49,11 @@ class FrontierCursor2:
disables variable binding
"""
log = logging.getLogger( "TrigConfFrontier.py" )
from builtins import int
for var,val in bindvars.items():
if query.find(":%s" % var)<0:
raise NameError("variable '%s' is not a bound variable in this query: %s" % (var, query) )
if type(val) == long:
if isinstance (val, int):
query = query.replace(":%s" % var,"%s" % val)
else:
query = query.replace(":%s" % var,"%r" % val)
......@@ -139,8 +142,8 @@ Refresh cache: %s""" % (self.url, self.refreshFlag)
import urllib2
try:
urllib2.urlopen(url)
except urllib2.URLError, e:
print e
except urllib2.URLError as e:
print (e)
def execute(self, query, bindvars={}):
if len(bindvars)>0:
......@@ -205,7 +208,7 @@ Refresh cache: %s""" % (self.url, self.refreshFlag)
if node.data.strip() == "":
continue
if keepalives > 0:
print keepalives, "keepalives received\n"
print (keepalives, "keepalives received\n")
keepalives = 0
row = base64.decodestring(node.data)
......@@ -278,7 +281,7 @@ def testConnection():
cursor.execute(query)
for r in cursor.result[:20]:
print r
print (r)
query = """
SELECT DISTINCT
......@@ -317,7 +320,7 @@ TE2CP.HTE2CP_ALGORITHM_COUNTER DESC"""
cursor.execute(query)
for r in cursor.result[:20]:
print r
print (r)
return 0
......
......@@ -41,23 +41,23 @@ def checkPoolFileForRunLevel(poolfilename):
if hasattr(mdt,folderName["L1K"]):
br = mdt.GetBranch(folderName["L1K"])
for i in xrange(mdt.GetEntries()):
for i in range(mdt.GetEntries()):
br.GetEntry(i)
metaData = getattr(mdt, br.GetName())
plc = metaData.payloadContainer()
for payload in plc.iter():
for i in xrange(payload.size()):
for i in range(payload.size()):
chanNum = int(payload.chanNum(i))
l1keys += [ payload.attributeList(chanNum)["Lvl1PrescaleConfigurationKey"].data("unsigned int")() ]
if hasattr(mdt,folderName["HLTK"]):
br = mdt.GetBranch(folderName["HLTK"])
for i in xrange(mdt.GetEntries()):
for i in range(mdt.GetEntries()):
br.GetEntry(i)
metaData = getattr(mdt, br.GetName())
plc = metaData.payloadContainer()
for payload in plc.iter():
for i in xrange(payload.size()):
for i in range(payload.size()):
chanNum = int(payload.chanNum(i))
hltkeys += [ payload.attributeList(chanNum)["HltPrescaleConfigurationKey"].data("unsigned int")() ]
......
......@@ -738,7 +738,7 @@ def getBunchGroupContent(connection, bgsk):
res = executeQuery(cursor, output, condition, schemaname, tables, bindvars)
bg = dict( enumerate( [[] for x in xrange(16)] ) )
bg = dict( enumerate( [[] for x in range(16)] ) )
for e in res:
bg[e[0]] += [e[1]]
......@@ -754,7 +754,7 @@ def getL1Prescales(connection, l1prescalekey):
maxitems = 512 if isrun2 else 256
tables = { 'L' : 'L1_PRESCALE_SET' }
output = ['L.L1PS_NAME'] + ['L.L1PS_VAL%i' % i for i in xrange(1,maxitems+1)]
output = ['L.L1PS_NAME'] + ['L.L1PS_VAL%i' % i for i in range(1,maxitems+1)]
condition = [ "L.L1PS_ID = '%i'" % l1prescalekey ]
......
......@@ -5,6 +5,7 @@
## @author Joerg Stelzer <stelzer@cern.ch>
from __future__ import print_function
from past.builtins import cmp
import sys
import ROOT
......@@ -180,12 +181,12 @@ class TriggerConfigARA(object):
def printFileSummary(self, chaindetails=False):
br = self.mdt.GetBranch(self.__class__.__folderName['HLTK'])
iovs = []
for i in xrange(self.mdt.GetEntries()):
for i in range(self.mdt.GetEntries()):
br.GetEntry(i)
metaData = getattr(self.mdt, br.GetName())
plc = metaData.payloadContainer()
for payload in plc.iter():
for j in xrange(payload.size()):
for j in range(payload.size()):
chanNum = int(payload.chanNum(j))
iovr = payload.iovRange(chanNum)
iovs += [iovr]
......@@ -327,13 +328,13 @@ class TriggerConfigARA(object):
self.SMK = -1
self.HltPSK = -1
self.ConfigSrc = ""
for i in xrange(self.mdt.GetEntries()):
for i in range(self.mdt.GetEntries()):
br.GetEntry(i)
metaData = getattr(self.mdt, br.GetName())
plc = metaData.payloadContainer()
for payload in plc.iter():
#payload.dump()
for i in xrange(payload.size()):
for i in range(payload.size()):
chanNum = int(payload.chanNum(i))
# first check the iov
iovr = payload.iovRange(chanNum)
......@@ -353,13 +354,13 @@ class TriggerConfigARA(object):
def _loadHLTPSK(self, br, currentEvent):
validIOV = None
self.HltPSK = -1
for i in xrange(self.mdt.GetEntries()):
for i in range(self.mdt.GetEntries()):
br.GetEntry(i)
metaData = getattr(self.mdt, br.GetName())
plc = metaData.payloadContainer()
for payload in plc.iter():
#payload.dump()
for i in xrange(payload.size()):
for i in range(payload.size()):
chanNum = int(payload.chanNum(i))
# first check the iov
iovr = payload.iovRange(chanNum)
......@@ -377,12 +378,12 @@ class TriggerConfigARA(object):
foundAnyIOV = False
self.L1PSK = -1
payloadList = []
for i in xrange(self.mdt.GetEntries()):
for i in range(self.mdt.GetEntries()):
br.GetEntry(i)
metaData = getattr(self.mdt, br.GetName())
plc = metaData.payloadContainer()
for payload in plc.iter():
for i in xrange(payload.size()):
for i in range(payload.size()):
chanNum = int(payload.chanNum(i))
iovr = payload.iovRange(chanNum)
payloadList += [[iovr,payload.attributeList(chanNum)]]
......@@ -390,7 +391,7 @@ class TriggerConfigARA(object):
if not foundAnyIOV: return None
# sort the payload by IOV and remove the overlap
payloadList.sort(lambda x,y: cmp(x[0].start(),y[0].start()))
for i in xrange(len(payloadList)-1):
for i in range(len(payloadList)-1):
payloadList[i][0] = ROOT.IOVRange(payloadList[i][0].start(),payloadList[i+1][0].start())
# get the content
validIOV = None
......@@ -404,28 +405,28 @@ class TriggerConfigARA(object):
def _loadL1PS(self, br, currentEvent):
foundAnyIOV = False
self.L1PS = 256*[0]
payloadList = [[] for x in xrange(256)]
for i in xrange(self.mdt.GetEntries()):
payloadList = [[] for x in range(256)]
for i in range(self.mdt.GetEntries()):
br.GetEntry(i)
metaData = getattr(self.mdt, br.GetName())
plc = metaData.payloadContainer()
for payload in plc.iter():
for i in xrange(payload.size()):
for i in range(payload.size()):
chanNum = int(payload.chanNum(i))
iovr = payload.iovRange(chanNum)
payloadList[chanNum] += [[iovr,payload.attributeList(chanNum)]]
foundAnyIOV = True
if not foundAnyIOV: return None
# sort the payload by IOV and remove the overlap
for ch in xrange(256):
for ch in range(256):
x = payloadList[ch]
x.sort(lambda x,y: cmp(x[0].start(),y[0].start()))
for i in xrange(len(x)-1):
for i in range(len(x)-1):
x[i][0] = ROOT.IOVRange(x[i][0].start(),x[i+1][0].start())
# read the payload
psset = 256 * [0]
validIOV = None
for ch in xrange(256):
for ch in range(256):
for pl in payloadList[ch]:
if pl[0].isInRange(currentEvent):
if not validIOV: validIOV = pl[0]
......@@ -439,13 +440,13 @@ class TriggerConfigARA(object):
def _loadL1M(self, br, currentEvent):
validIOV = None
items = {}
for i in xrange(self.mdt.GetEntries()):
for i in range(self.mdt.GetEntries()):
br.GetEntry(i)
metaData = getattr(self.mdt, br.GetName())
plc = metaData.payloadContainer()
for payload in plc.iter():
#payload.dump()
for i in xrange(payload.size()):
for i in range(payload.size()):
chanNum = int(payload.chanNum(i))
# first check the iov
iovr = payload.iovRange(chanNum)
......@@ -462,13 +463,13 @@ class TriggerConfigARA(object):
def _loadHLTM(self, br, currentEvent):
validIOV = None
chains = {}
for i in xrange(self.mdt.GetEntries()):
for i in range(self.mdt.GetEntries()):
br.GetEntry(i)
metaData = getattr(self.mdt, br.GetName())
plc = metaData.payloadContainer()
for payload in plc.iter():
#payload.dump()
for i in xrange(payload.size()):
for i in range(payload.size()):
chanNum = int(payload.chanNum(i))
# first check the iov
iovr = payload.iovRange(chanNum)
......
......@@ -248,7 +248,7 @@ class PoolFile(object):
print("## Looping over all events now ...")
isFirstEvent = True
for i in xrange(transientTree.GetEntries()):
for i in range(transientTree.GetEntries()):
if EventInfo_br.GetEntry(i) <= 0 or TrigDecision_br.GetEntry(i) <= 0 :
print(":: could not get entry #%i" % i)
break
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment