From 60e5d9a3bc7d8ee42da27854ff51fd937af7a685 Mon Sep 17 00:00:00 2001 From: scott snyder <snyder@bnl.gov> Date: Thu, 12 Mar 2020 15:48:30 +0100 Subject: [PATCH] TrigTransforms: Python 3 fixes Updates for python 3 compatibility. --- .../TrigTransform/python/dbgHltResult.py | 9 +++++---- .../TrigTransforms/TrigTransform/python/trigRecoExe.py | 9 +++++---- .../TrigTransform/python/trigUpdateArgs.py | 8 +++++--- .../TrigTransform/share/Trig_tf_simple.py | 10 ++++++---- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/HLT/Trigger/TrigTransforms/TrigTransform/python/dbgHltResult.py b/HLT/Trigger/TrigTransforms/TrigTransform/python/dbgHltResult.py index 31456ac969d..9907106f7aa 100644 --- a/HLT/Trigger/TrigTransforms/TrigTransform/python/dbgHltResult.py +++ b/HLT/Trigger/TrigTransforms/TrigTransform/python/dbgHltResult.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration #### This is the dbgHLTResult class for the Debug Stream event analysis from __future__ import print_function @@ -182,15 +182,16 @@ def print_HLTResult(result): def collect_feature_sizes(dest, result): for f in result.nav_payload: key = f[0]+'#'+f[1] - if not dest.has_key(key): + if key not in dest: dest[key] = 0 dest[key] += f[2] # keyed by type key = f[0] - if not dest.has_key(key): + if key not in dest: dest[key] = 0 dest[key] += f[2] - if not dest.has_key('Total'): dest['Total'] = 0 + if 'Total' not in dest: + dest['Total'] = 0 dest['Total'] += 4*result.as_int_v.size() diff --git a/HLT/Trigger/TrigTransforms/TrigTransform/python/trigRecoExe.py b/HLT/Trigger/TrigTransforms/TrigTransform/python/trigRecoExe.py index 6fc684c2755..e0a690c3174 100644 --- a/HLT/Trigger/TrigTransforms/TrigTransform/python/trigRecoExe.py +++ b/HLT/Trigger/TrigTransforms/TrigTransform/python/trigRecoExe.py @@ -13,6 +13,7 @@ import os import fnmatch import re import subprocess +import six from PyJobTransforms.trfExe import athenaExecutor @@ -54,7 +55,7 @@ class trigRecoExecutor(athenaExecutor): for dataType in input: inputEvents = self.conf.dataDictionary[dataType].nentries msg.debug('Got {0} events for {1}'.format(inputEvents, dataType)) - if not isinstance(inputEvents, (int, long)): + if not isinstance(inputEvents, six.integer_types): msg.warning('Are input events countable? Got nevents={0} so disabling event count check for this input'.format(inputEvents)) elif self.conf.argdict['skipEvents'].returnMyValue(name=self._name, substep=self._substep, first=self.conf.firstExecutor) >= inputEvents: raise trfExceptions.TransformExecutionException(trfExit.nameToCode('TRF_NOEVENTS'), @@ -70,7 +71,7 @@ class trigRecoExecutor(athenaExecutor): outputFiles[dataType] = self.conf.dataDictionary[dataType] # See if we have any 'extra' file arguments - for dataType, dataArg in self.conf.dataDictionary.iteritems(): + for dataType, dataArg in self.conf.dataDictionary.items(): if dataArg.io == 'input' and self._name in dataArg.executor: inputFiles[dataArg.subtype] = dataArg @@ -199,7 +200,7 @@ class trigRecoExecutor(athenaExecutor): matchedOutputFileNames = [] #list of input files that could be in the same folder and need ignoring ignoreInputFileNames = [] - for dataType, dataArg in self.conf.dataDictionary.iteritems(): + for dataType, dataArg in self.conf.dataDictionary.items(): if dataArg.io == 'input': ignoreInputFileNames.append(dataArg.value[0]) #loop over all files in folder to find matching output files @@ -376,7 +377,7 @@ class trigRecoExecutor(athenaExecutor): else: msg.info('Stream "All" requested, so not splitting BS file') self._renamefile(matchedOutputFileNames[0], argInDict.value[0]) - else: + else: msg.error('no BS files created with expected name: %s' % expectedOutputFileName ) else: msg.info('BS output filetype not defined so skip BS filename check') diff --git a/HLT/Trigger/TrigTransforms/TrigTransform/python/trigUpdateArgs.py b/HLT/Trigger/TrigTransforms/TrigTransform/python/trigUpdateArgs.py index f7a6e97bc6b..551917b0c5d 100644 --- a/HLT/Trigger/TrigTransforms/TrigTransform/python/trigUpdateArgs.py +++ b/HLT/Trigger/TrigTransforms/TrigTransform/python/trigUpdateArgs.py @@ -1,11 +1,13 @@ #!/usr/bin/env python -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration # @brief: Argument altering for trigger transform # @details: Code to convert trf args into the athenaMT/PT variable names # @author: Mark Stockton +from __future__ import print_function + #### #Notes: # @@ -348,7 +350,7 @@ def postCommand(inArgDict): if conf.find('costMonitor') !=-1: file_text.extend(costM_text) if conf.find('CoreHandler') !=-1: file_text.extend(Hndlr_text) - print >> postCommands, "".join(file_text) + print ("".join(file_text), f=postCommands) postCommands.close() #swap item name now finished using input values @@ -360,4 +362,4 @@ def postCommand(inArgDict): msg.info('Finished creating the PostCommands JO file') - \ No newline at end of file + diff --git a/HLT/Trigger/TrigTransforms/TrigTransform/share/Trig_tf_simple.py b/HLT/Trigger/TrigTransforms/TrigTransform/share/Trig_tf_simple.py index 2524003c4d5..dab56e0b8ba 100755 --- a/HLT/Trigger/TrigTransforms/TrigTransform/share/Trig_tf_simple.py +++ b/HLT/Trigger/TrigTransforms/TrigTransform/share/Trig_tf_simple.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import print_function + from optparse import OptionParser import subprocess import shlex @@ -54,9 +56,9 @@ path = temp.communicate()[0].strip() temp = ["python", path] temp.extend(args[1:]) -print com -print args -print temp +print (com) +print (args) +print (temp) #this works not process = subprocess.Popen(args) @@ -64,4 +66,4 @@ process = subprocess.Popen(args) #this works process = subprocess.Popen(temp) process.wait() -print process.returncode +print (process.returncode) -- GitLab