Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print function migration for PhysicsTools_PythonAnalysis #24088

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions PhysicsTools/PythonAnalysis/python/ParticleDecayDrawer.py
@@ -1,3 +1,4 @@
from __future__ import print_function
# Benedikt Hegner, DESY
# benedikt.hegner@cern.ch
#
Expand All @@ -8,7 +9,7 @@ class ParticleDecayDrawer(object):
"""Draws particle decay tree """

def __init__(self):
print "Init particleDecayDrawer"
print("Init particleDecayDrawer")
# booleans: printP4 printPtEtaPhi printVertex

def _accept(self, candidate, skipList):
Expand Down Expand Up @@ -71,28 +72,28 @@ def draw(self, particles):
if self._select(mom):
momsList.append(mom)

print "-- decay --"
print("-- decay --")
if len(momsList) > 0:
if len(momsList) > 1:
for m in xrange(len(momsList)):
decString = self._decay( momsList[m], skipList)
if len(decString) > 0:
print "{ %s } " %decString
print("{ %s } " %decString)
else:
print self._decay(momsList[0], skipList)
print(self._decay(momsList[0], skipList))

if len(nodesList) > 0:
print "-> "
print("-> ")
if len(nodesList) > 1:
for node in nodesList:
skipList.remove(node)
decString = self._decay(node, skipList)
if len(decString) > 0:
if "->" in decString: print " ( %s ) " %decString
else: print " " + decString
if "->" in decString: print(" ( %s ) " %decString)
else: print(" " + decString)
else:
skipList.remove(nodesList[0])
print self._decay(nodesList[0], skipList)
print(self._decay(nodesList[0], skipList))

print
print()

3 changes: 2 additions & 1 deletion PhysicsTools/PythonAnalysis/python/cmscompleter.py
Expand Up @@ -6,6 +6,7 @@

"""
from __future__ import absolute_import
from __future__ import print_function
# TODO: sometimes results are doubled. clean global_matches list!

import readline
Expand Down Expand Up @@ -34,7 +35,7 @@ def __init__(self, namespace = None):
from . import namespaceDict
self.cmsnamespace = namespaceDict.getNamespaceDict()
except:
print 'Could not load CMS namespace'
print('Could not load CMS namespace')


def global_matches(self, text):
Expand Down
9 changes: 5 additions & 4 deletions PhysicsTools/PythonAnalysis/python/cmstools.py
Expand Up @@ -4,6 +4,7 @@

"""
from __future__ import absolute_import
from __future__ import print_function
import re
import ROOT
import exceptions
Expand All @@ -14,7 +15,7 @@
import readline #cmscompleter
readline.parse_and_bind('tab: complete')
except:
print 'WARNING: Could not load tab completion'
print('WARNING: Could not load tab completion')


# for adding iterators at runtime
Expand Down Expand Up @@ -175,6 +176,6 @@ def __call__(self):
class cmserror(exceptions.Exception):
def __init__(self, message):
length = len(message)+7 #7=len("ERROR: ")
print "="*length
print "ERROR:", message
print "="*length
print("="*length)
print("ERROR:", message)
print("="*length)
23 changes: 12 additions & 11 deletions PhysicsTools/PythonAnalysis/python/diffProv.py
@@ -1,3 +1,4 @@
from __future__ import print_function

class difference :

Expand All @@ -15,15 +16,15 @@ def list_diff(self,aList1, aList2, string1, string2):
if self.verbose==str(2) or self.verbose==str(1):
str1 = aList1[i][2:aList1[i].index('=')+1] + aList1[i][aList1[i].index('=')+1:]+' ['+ string1+']'
str2 = len(aList1[i][2:aList1[i].index('=')+1])*' '+aList2[j][aList2[j].index('=')+1:]+' ['+string2+']'
print str1,'\n',str2,'\n'
print(str1,'\n',str2,'\n')
differences.append(str1)
differences.append(str2)

return differences

def module_diff(self,module1,module2, string1, string2):
"Searches for modules which are in both the files but whose parameters are setted at different values"
print '\nList of modules present in both the files with different parameter values\n'
print('\nList of modules present in both the files with different parameter values\n')
for i in module1.keys():
for j in module2.keys():
if (i==j) and (i=='Processing'):
Expand All @@ -37,19 +38,19 @@ def module_diff(self,module1,module2, string1, string2):
self._diffprocess.append( (key1,key2) )

if len(self._diffprocess)>1:
print 'Differences in the processing history'
print('Differences in the processing history')
for l,m in self._diffprocess:
print l+' ['+string1+']'
print m+' ['+string2+']'
print ''
print(l+' ['+string1+']')
print(m+' ['+string2+']')
print('')
if len(self._diffprocess)==1:
self._sameprocess=self._diffprocess[0]

elif ( (i==j)or (i,j)==self._sameprocess ) and (i!='Processing'):
for name1,value1 in module1[i]:
for name2,value2 in module2[j]:
if (name1==name2) and (value1[1:]!=value2[1:]):
print 'Process: '+'"'+i+'"'+'\n'+'Module: '+'"'+name1+'"'+'\n'
print('Process: '+'"'+i+'"'+'\n'+'Module: '+'"'+name1+'"'+'\n')
d=difference(self.verbose)
d.firstvalue=value1
d.secondvalue=value2
Expand All @@ -61,11 +62,11 @@ def module_diff(self,module1,module2, string1, string2):

def onefilemodules(self,module1,module2,string):
"Searches for modules present only in one of the two files"
print '\nModules run only on the '+string+ ' edmfile:'+'\n'
print('\nModules run only on the '+string+ ' edmfile:'+'\n')
for i in module1.keys():
labelList=[]
if (i not in module2.keys())and (i not in self._sameprocess):
print '\n Process '+i+' not run on edmfile '+string +'\n'
print('\n Process '+i+' not run on edmfile '+string +'\n')
elif i!='Processing':
k=i
if i in self._sameprocess:
Expand All @@ -77,10 +78,10 @@ def onefilemodules(self,module1,module2,string):
labelList1=[module[0] for module in module1[i]]
for name, value in module1[i] :
if (name not in labelList2):
print 'Process: '+'"'+i+'"'+'\n'+'Module: '+'"'+name+'"'
print('Process: '+'"'+i+'"'+'\n'+'Module: '+'"'+name+'"')
if self.verbose==str(2):
for k in value[1:]:
print k
print(k)



17 changes: 9 additions & 8 deletions PhysicsTools/PythonAnalysis/python/diff_provenance.py
@@ -1,3 +1,4 @@
from __future__ import print_function
class difference :

def __init__(self,v):
Expand All @@ -10,20 +11,20 @@ def list_diff(self,aList1, aList2, string1, string2):
if (i==j) and (aList1[i]!=aList2[j]):
if aList1[i][:(aList1[i].index('=')+1)] == aList2[j][:(aList2[j].index('=')+1)]:
if self.verbose==str(2) or self.verbose==str(1):
print aList1[i][2:aList1[i].index('=')+1] + aList1[i][aList1[i].index('=')+1:]+' ['+ string1+']'
print len(aList1[i][2:aList1[i].index('=')+1])*' '+aList2[j][aList2[j].index('=')+1:]+' ['+string2+']'
print ''
print(aList1[i][2:aList1[i].index('=')+1] + aList1[i][aList1[i].index('=')+1:]+' ['+ string1+']')
print(len(aList1[i][2:aList1[i].index('=')+1])*' '+aList2[j][aList2[j].index('=')+1:]+' ['+string2+']')
print('')


def module_diff(self,module1,module2, string1, string2):
"Searches for modules which are in both the files but whose parameters are setted at different values"
modulesfile1=[]
modulesfile2=[]
print '\nList of modules present in both the files with different parameter values\n'
print('\nList of modules present in both the files with different parameter values\n')
for i in module1.keys():
for j in module2.keys():
if (i==j) and (module1[i]!=module2[j]):
print 'Module: '+'"'+i+'"'
print('Module: '+'"'+i+'"')
d=difference(self.verbose)
d.module=i
d.firstvalue=module1[i]
Expand All @@ -41,11 +42,11 @@ def onefilemodules(self,module1,module2,string):
for i in module1.keys():
if i not in module2:
if not onlyonefile:
print '\nModule present only in the '+string+ ' file:'+'\n'
print('\nModule present only in the '+string+ ' file:'+'\n')
onlyonefile = True
print 'Module: '+'"'+i+'"'
print('Module: '+'"'+i+'"')
if self.verbose==str(2):
for k in range(1,len(module1[i])):
print module1[i][k]
print(module1[i][k])


25 changes: 13 additions & 12 deletions PhysicsTools/PythonAnalysis/python/rootplot/core.py
Expand Up @@ -2,6 +2,7 @@
An API and a CLI for quickly building complex figures.
"""
from __future__ import absolute_import
from __future__ import print_function

__license__ = '''\
Copyright (c) 2009-2010 Jeff Klukas <klukas@wisc.edu>
Expand Down Expand Up @@ -135,7 +136,7 @@ def process_configs(self, scope):
rc_name = use_mpl and 'rootplotmplrc' or 'rootplotrc'
rc_path = os.path.expanduser('~/.%s' % rc_name)
if os.path.exists(rc_path):
print "Using styles and options from ~/.%s" % rc_name
print("Using styles and options from ~/.%s" % rc_name)
shutil.copy(rc_path, joined(configdir, '%s.py' % rc_name))
configs.insert(1, '%s.py' % rc_name)
for f in configs:
Expand Down Expand Up @@ -549,8 +550,8 @@ def cli_rootplot():
try:
rootplot(*options.arguments(), **optdiff)
except Exception as e:
print "Error:", e
print "For usage details, call '%s --help'" % prog
print("Error:", e)
print("For usage details, call '%s --help'" % prog)
sys.exit(1)

##############################################################################
Expand Down Expand Up @@ -750,14 +751,14 @@ def rootplot(*args, **kwargs):
report_progress(i + 1, len(plotargs), options.output, options.ext)
report_progress(len(plotargs), len(plotargs),
options.output, options.ext)
print ''
print('')
## clean out empty directories
for root, dirs, files in os.walk(options.output):
if not os.listdir(root):
os.rmdir(root)
## add index.html files to all directories
if options.ext in ['png', 'gif', 'svg']:
print "Writing html index files..."
print("Writing html index files...")
width, height = options.size
if use_mpl:
width, height = [x * options.dpi for x in options.size]
Expand Down Expand Up @@ -813,7 +814,7 @@ def write_config():
f = open(filename, 'w')
f.write(config_string())
f.close()
print "Wrote %s to the current directory" % filename
print("Wrote %s to the current directory" % filename)
sys.exit(0)

def add_from_config_files(options, configs):
Expand All @@ -836,7 +837,7 @@ def append_to_options(config, options):
rc_name = 'rootplotrc'
rc_path = os.path.expanduser('~/.%s' % rc_name)
if os.path.exists(rc_path):
print "Using styles and options from ~/.%s" % rc_name
print("Using styles and options from ~/.%s" % rc_name)
shutil.copy(rc_path, joined(configdir, '%s.py' % rc_name))
configs.insert(0, '%s.py' % rc_name)
for f in configs:
Expand Down Expand Up @@ -1353,8 +1354,8 @@ def get_labels(hist, options):
def report_progress(counter, nplots, output, ext, divisor=1):
#### Print the current number of finished plots.
if counter % divisor == 0:
print("\r%i plots of %i written to %s/ in %s format" %
(counter, nplots, output, ext)),
print(("\r%i plots of %i written to %s/ in %s format" %
(counter, nplots, output, ext)), end=' ')
sys.stdout.flush()

def merge_pdf(options):
Expand All @@ -1364,9 +1365,9 @@ def merge_pdf(options):
for path, dirs, files in os.walk(options.output):
paths += [joined(path, x) for x in files if x.endswith('.pdf')]
if not paths:
print "No output files, so no merged pdf was made"
print("No output files, so no merged pdf was made")
return
print "Writing %s..." % destination
print("Writing %s..." % destination)
os.system('gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite '
'-dAutoRotatePages=/All '
'-sOutputFile=%s %s' % (destination, ' '.join(paths)))
Expand Down Expand Up @@ -1631,7 +1632,7 @@ def load_matplotlib(ext):
try:
import matplotlib as mpl
except ImportError:
print "Unable to access matplotlib"
print("Unable to access matplotlib")
sys.exit(1)
import numpy as np
mpldict = {'png' : 'AGG',
Expand Down