Skip to content

Commit

Permalink
Merge pull request #23834 from davidlange6/printMig_180718T4_Utilitie…
Browse files Browse the repository at this point in the history
…s_RelMon

Print function migration for Utilities_RelMon
  • Loading branch information
cmsbuild committed Jul 19, 2018
2 parents 1066b4d + 3ae04aa commit 20f6e7b
Show file tree
Hide file tree
Showing 19 changed files with 211 additions and 192 deletions.
5 changes: 3 additions & 2 deletions Utilities/RelMon/python/authentication.py
@@ -1,3 +1,4 @@
from __future__ import print_function
################################################################################
# RelMon: a tool for automatic Release Comparison
# https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
Expand Down Expand Up @@ -48,11 +49,11 @@ def __init__(self, host, *args, **kwargs):
cert_file = x509_path

if not key_file or not exists(key_file):
print >>stderr, "No certificate private key file found"
print("No certificate private key file found", file=stderr)
exit(1)

if not cert_file or not exists(cert_file):
print >>stderr, "No certificate public key file found"
print("No certificate public key file found", file=stderr)
exit(1)

#print "Using SSL private key", key_file
Expand Down
3 changes: 2 additions & 1 deletion Utilities/RelMon/python/directories2html.py
@@ -1,3 +1,4 @@
from __future__ import print_function
################################################################################
# RelMon: a tool for automatic Release Comparison
# https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
Expand Down Expand Up @@ -568,7 +569,7 @@ def get_aggr_pairs_info(dir_dict,the_aggr_pairs=[]):
present_subdirs[subsubdirname]={"nsucc":nsucc,"weight":weight}

if total_ndirs == 0:
print "No directory of the category %s is present in the samples: skipping." %cat_name
print("No directory of the category %s is present in the samples: skipping." %cat_name)
continue

average_success_rate=total_directory_successes/(total_ndirs)
Expand Down
35 changes: 18 additions & 17 deletions Utilities/RelMon/python/dirstructure.py
@@ -1,3 +1,4 @@
from __future__ import print_function
################################################################################
# RelMon: a tool for automatic Release Comparison
# https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
Expand Down Expand Up @@ -33,7 +34,7 @@
_log_level=5
def logger(msg_level,message):
if msg_level>=_log_level:
print "[%s] %s" %(asctime(),message)
print("[%s] %s" %(asctime(),message))

#-------------------------------------------------------------------------------

Expand Down Expand Up @@ -109,8 +110,8 @@ def calcStats(self,make_pie=True):
self.n_comp_skiped = 0
self.n_missing_objs = len(self.different_histograms['file1'])+len(self.different_histograms['file2'])
if self.n_missing_objs != 0:
print " [*] Missing in %s: %s" %(self.filename1, self.different_histograms['file1'])
print " [*] Missing in %s: %s" %(self.filename2, self.different_histograms['file2'])
print(" [*] Missing in %s: %s" %(self.filename1, self.different_histograms['file1']))
print(" [*] Missing in %s: %s" %(self.filename2, self.different_histograms['file2']))
# clean from empty dirs
self.subdirs = [subdir for subdir in self.subdirs if not subdir.is_empty()]

Expand Down Expand Up @@ -185,19 +186,19 @@ def print_report(self,indent="",verbose=False):
fail_comps=[comp for comp in self.comparisons if comp.status==FAIL]
fail_comps=sorted(fail_comps,key=lambda comp:comp.name )
if len(fail_comps)>0:
print indent+"* %s/%s:" %(self.mother_dir,self.name)
print(indent+"* %s/%s:" %(self.mother_dir,self.name))
for comp in fail_comps:
print indent+" - %s: %s Test Failed (pval = %s) " %(comp.name,comp.test_name,comp.rank)
print(indent+" - %s: %s Test Failed (pval = %s) " %(comp.name,comp.test_name,comp.rank))
for subdir in self.subdirs:
subdir.print_report(indent+" ",verbose)

if len(indent)==0:
print "\n%s - summary of %s tests:" %(self.name,self.weight)
print " o Failiures: %.2f%% (%s/%s)" %(self.get_fail_rate(),self.n_fails,self.weight)
print " o Nulls: %.2f%% (%s/%s) " %(self.get_null_rate(),self.n_nulls,self.weight)
print " o Successes: %.2f%% (%s/%s) " %(self.get_success_rate(),self.n_successes,self.weight)
print " o Skipped: %.2f%% (%s/%s) " %(self.get_skiped_rate(),self.n_skiped,self.weight)
print " o Missing objects: %s" %(self.n_missing_objs)
print("\n%s - summary of %s tests:" %(self.name,self.weight))
print(" o Failiures: %.2f%% (%s/%s)" %(self.get_fail_rate(),self.n_fails,self.weight))
print(" o Nulls: %.2f%% (%s/%s) " %(self.get_null_rate(),self.n_nulls,self.weight))
print(" o Successes: %.2f%% (%s/%s) " %(self.get_success_rate(),self.n_successes,self.weight))
print(" o Skipped: %.2f%% (%s/%s) " %(self.get_skiped_rate(),self.n_skiped,self.weight))
print(" o Missing objects: %s" %(self.n_missing_objs))

def get_skiped_rate(self):
if self.weight == 0: return 0
Expand Down Expand Up @@ -261,10 +262,10 @@ def __create_pie_image(self):
pie.Draw("3d nol");
can.Print(self.get_summary_chart_name());
except:
print "self.name = %s" %self.name
print "len(vals) = %s (vals=%s)" %(len(vals),vals)
print "valsa = %s" %valsa
print "colorsa = %s" %colorsa
print("self.name = %s" %self.name)
print("len(vals) = %s (vals=%s)" %(len(vals),vals))
print("valsa = %s" %valsa)
print("colorsa = %s" %colorsa)

def prune(self,expandable_dir):
"""Eliminate from the tree the directory the expandable ones.
Expand All @@ -287,7 +288,7 @@ def prune(self,expandable_dir):
#print "*******",subsubdir.mother_dir,
subsubdir.mother_dir=subsubdir.mother_dir.replace("/"+expandable_dir,"")
while "//" in subsubdir.mother_dir:
print subsubdir.mother_dir
print(subsubdir.mother_dir)
subsubdir.mother_dir=subsubdir.mother_dir.replace("//","/")
#print "*******",subsubdir.mother_dir
self.subdirs.append(subsubdir)
Expand Down Expand Up @@ -445,7 +446,7 @@ def __make_image(self,obj1,obj2):
# Put together the TLatex for the stat test if possible
color=kGreen+2 # which is green, as everybody knows
if self.status==FAIL:
print "This comparison failed %f" %self.rank
print("This comparison failed %f" %self.rank)
color=kRed
elif self.status==NULL:
color=kYellow
Expand Down
29 changes: 15 additions & 14 deletions Utilities/RelMon/python/dqm_interfaces.py
@@ -1,3 +1,4 @@
from __future__ import print_function
################################################################################
# RelMon: a tool for automatic Release Comparison
# https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
Expand Down Expand Up @@ -108,7 +109,7 @@ def ls_url(self, url):
try:
raw_folder=eval(self.get_data(url))
except:
print "Retrying.."
print("Retrying..")
for ntrials in xrange(5):
try:
if ntrials!=0:
Expand All @@ -117,7 +118,7 @@ def ls_url(self, url):
raw_folder=eval(self.get_data(url))
break
except:
print "Could not fetch %s. Retrying" %url
print("Could not fetch %s. Retrying" %url)

#raw_folder=loads(self.get_data(url))
for content_dict in raw_folder["contents"]:
Expand Down Expand Up @@ -408,7 +409,7 @@ def run(self):

this_dir=DirID(self.directory.name,self.depth)
if this_dir in self.black_list:
print "Skipping %s since blacklisted!" %this_dir
print("Skipping %s since blacklisted!" %this_dir)
return 0

self.depth+=1
Expand Down Expand Up @@ -479,14 +480,14 @@ def __init__(self,rootfilename):
self.rootfilepwd=self.rootfile.GetDirectory(dqmdatadir)
self.rootfileprevpwd=self.rootfile.GetDirectory(dqmdatadir)
if self.rootfilepwd == None:
print "Directory %s does not exist: skipping. Is this a custom rootfile?" %dqmdatadir
print("Directory %s does not exist: skipping. Is this a custom rootfile?" %dqmdatadir)
self.rootfilepwd=self.rootfile
self.rootfileprevpwd=self.rootfile

def __is_null(self,directory,name):
is_null = not directory
if is_null:
print >> stderr, "Directory %s does not exist!" %name
print("Directory %s does not exist!" %name, file=stderr)
return is_null

def ls(self,directory_name=""):
Expand Down Expand Up @@ -657,7 +658,7 @@ def __fill_single_dir(self,dir_name,directory,mother_name="",depth=0):
#We have a dir, launch recursion!
#Some feedback on the progress
if depth==1:
print "Studying directory %s, %s/%s" %(name,cont_counter,n_top_contents)
print("Studying directory %s, %s/%s" %(name,cont_counter,n_top_contents))
cont_counter+=1

#print "Studying directory",name
Expand All @@ -668,10 +669,10 @@ def __fill_single_dir(self,dir_name,directory,mother_name="",depth=0):
self.__fill_single_dir(name,subdir,join(mother_name,dir_name),depth)
if not subdir.is_empty():
if depth==1:
print " ->Appending %s..." %name,
print(" ->Appending %s..." %name, end=' ')
directory.subdirs.append(subdir)
if depth==1:
print "Appended."
print("Appended.")
else:
# We have probably an histo. Let's make the plot and the png.
if obj_type[:2]!="TH" and obj_type[:3]!="TPr" :
Expand All @@ -680,7 +681,7 @@ def __fill_single_dir(self,dir_name,directory,mother_name="",depth=0):
#print "COMPARISON : +%s+%s+" %(mother_name,dir_name)
path = join(mother_name,dir_name,name)
if path in self.black_list_histos:
print " Skipping %s" %(path)
print(" Skipping %s" %(path))
directory.comparisons.append(Comparison(name,
join(mother_name,dir_name),
h1,h2,
Expand Down Expand Up @@ -711,27 +712,27 @@ def walk(self):
try:
first_run_dir = filter(lambda k: "Run " in k, self.ls().keys())[0]
except:
print "\nRundir not there: Is this a generic rootfile?\n"
print("\nRundir not there: Is this a generic rootfile?\n")
rundir=first_run_dir
try:
self.run= int(rundir.split(" ")[1])
except:
print "Setting run number to 0"
print("Setting run number to 0")
self.run= 0
else:
rundir="Run %s"%self.run

try:
self.cd(rundir, False, True) #True -> for checking the Rundir in case of different runs
except:
print "\nRundir not there: Is this a generic rootfile?\n"
print("\nRundir not there: Is this a generic rootfile?\n")

# Let's rock!
self.__fill_single_dir(self.directory.name,self.directory)
print "Finished"
print("Finished")
n_left_threads=len(tcanvas_print_processes)
if n_left_threads>0:
print "Waiting for %s threads to finish..." %n_left_threads
print("Waiting for %s threads to finish..." %n_left_threads)
for p in tcanvas_print_processes:
p.join()

Expand Down
41 changes: 21 additions & 20 deletions Utilities/RelMon/python/utils.py
@@ -1,3 +1,4 @@
from __future__ import print_function
################################################################################
# RelMon: a tool for automatic Release Comparison
# https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
Expand Down Expand Up @@ -43,7 +44,7 @@
_log_level=10
def logger(msg_level,message):
if msg_level>=_log_level:
print "[%s] %s" %(asctime(),message)
print("[%s] %s" %(asctime(),message))

#-------------------------------------------------------------------------------
def setTDRStyle():
Expand Down Expand Up @@ -71,8 +72,8 @@ def literal2root (literal,rootType):
try:
tbuffer = TBufferFile(TBufferFile.kRead, len(bitsarray), bitsarray, False,0)
except:
print "could not transform to object array:"
print [ i for i in bitsarray ]
print("could not transform to object array:")
print([ i for i in bitsarray ])

# replace a couple of shortcuts with the real root class name
if rootType == 'TPROF':
Expand Down Expand Up @@ -337,15 +338,15 @@ def do_test(self):
n_ok_bins+=1
#print "Bin %ibin: bindiff %s" %(ibin,bindiff)
else:
print "Bin %ibin: bindiff %s" %(ibin,bindiff)
print("Bin %ibin: bindiff %s" %(ibin,bindiff))

#if abs(bindiff)!=0 :
#print "Bin %ibin: bindiff %s" %(ibin,bindiff)

rank=n_ok_bins/nbins

if rank!=1:
print "Histogram %s differs: nok: %s ntot: %s" %(self.h1.GetName(),n_ok_bins,nbins)
print("Histogram %s differs: nok: %s ntot: %s" %(self.h1.GetName(),n_ok_bins,nbins))

return rank

Expand Down Expand Up @@ -396,15 +397,15 @@ def do_test(self):
n_ok_bins+=1
#print "Bin %i bin: bindiff %s" %(ibin,bindiff)
else:
print "-->Bin %i bin: bindiff %s (%s - %s )" %(ibin,bindiff,h1bin,h2bin)
print("-->Bin %i bin: bindiff %s (%s - %s )" %(ibin,bindiff,h1bin,h2bin))

#if abs(bindiff)!=0 :
#print "Bin %ibin: bindiff %s" %(ibin,bindiff)

rank=n_ok_bins/nbins

if rank!=1:
print "%s nok: %s ntot: %s" %(self.h1.GetName(),n_ok_bins,nbins)
print("%s nok: %s ntot: %s" %(self.h1.GetName(),n_ok_bins,nbins))

return rank
#-------------------------------------------------------------------------------
Expand All @@ -426,7 +427,7 @@ def ask_ok(prompt, retries=4, complaint='yes or no'):
retries = retries - 1
if retries < 0:
raise IOError('refusenik user')
print complaint
print(complaint)

#-------------------------------------------------------------------------------

Expand All @@ -437,7 +438,7 @@ def __init__(self,filename):
self.directory=""

def run(self):
print "Reading directory from %s" %(self.filename)
print("Reading directory from %s" %(self.filename))
ifile=open(self.filename,"rb")
self.directory=load(ifile)
ifile.close()
Expand All @@ -453,13 +454,13 @@ def wget(url):
bin_content=None
try:
filename=basename(url)
print "Checking existence of file %s on disk..."%filename
print("Checking existence of file %s on disk..."%filename)
if not isfile("./%s"%filename):
bin_content=opener.open(datareq).read()
else:
print "File %s exists, skipping.." %filename
print("File %s exists, skipping.." %filename)
except ValueError:
print "Error: Unknown url %s" %url
print("Error: Unknown url %s" %url)

if bin_content!=None:
ofile = open(filename, 'wb')
Expand Down Expand Up @@ -584,12 +585,12 @@ def make_files_pairs(files, verbose=True):

## Print the division into groups
if verbose:
print '\nFound versions:'
print('\nFound versions:')
for version in versions_files:
print '%s: %d files' % (str(version), len(versions_files[version]))
print('%s: %d files' % (str(version), len(versions_files[version])))

if len(versions_files) <= 1:
print '\nFound too little versions, there is nothing to pair. Exiting...\n'
print('\nFound too little versions, there is nothing to pair. Exiting...\n')
exit()

## Select two biggest groups.
Expand All @@ -602,11 +603,11 @@ def make_files_pairs(files, verbose=True):

## Print two biggest groups.
if verbose:
print '\nPairing %s (%d files) and %s (%d files)' % (str(v1),
len(versions_files[v1]), str(v2), len(versions_files[v2]))
print('\nPairing %s (%d files) and %s (%d files)' % (str(v1),
len(versions_files[v1]), str(v2), len(versions_files[v2])))

## Pairing two versions
print '\nGot pairs:'
print('\nGot pairs:')
pairs = []
for unique_id in set([get_id(file) for file in versions_files[v1]]):
if is_relval_data:
Expand All @@ -624,8 +625,8 @@ def make_files_pairs(files, verbose=True):
if len(c1_files) > 0 and len(c2_files) > 0:
first_file = get_max_version(c1_files)
second_file = get_max_version(c2_files)
print '%s\n%s\n' % (first_file, second_file)
print('%s\n%s\n' % (first_file, second_file))
pairs.extend((first_file, second_file))
if verbose:
print "Paired and got %d files.\n" % len(pairs)
print("Paired and got %d files.\n" % len(pairs))
return pairs

0 comments on commit 20f6e7b

Please sign in to comment.