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 SimTracker_TrackerMaterialAnalysis #23854

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
3 changes: 2 additions & 1 deletion SimTracker/TrackerMaterialAnalysis/crab/merge.py
@@ -1,11 +1,12 @@
from __future__ import print_function
#! /usr/bin/env cmsRun
import glob
import FWCore.ParameterSet.Config as cms

inputFiles = cms.untracked.vstring()
inputFiles.extend( [('file:%s ' % name) for name in glob.glob('files/*.root')] )
inputFiles.sort()
print inputFiles
print(inputFiles)

process = cms.Process("merge")
process.source = cms.Source("PoolSource",
Expand Down
@@ -1,3 +1,4 @@
from __future__ import print_function
from FWCore.ParameterSet.VarParsing import VarParsing
import sys

Expand Down
29 changes: 15 additions & 14 deletions SimTracker/TrackerMaterialAnalysis/test/dumpFullXML.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function
import argparse
import os, sys
import pprint
Expand Down Expand Up @@ -29,7 +30,7 @@ def checkEnvironment():
Check if the CMSSW environment is set. If not, quit the program.
"""
if not 'CMSSW_RELEASE_BASE' in os.environ.keys():
print 'CMSSW Environments not setup, quitting\n'
print('CMSSW Environments not setup, quitting\n')
sys.exit(CMSSW_NOT_SET)

def checkFileInRelease(filename):
Expand Down Expand Up @@ -57,7 +58,7 @@ def getTrackerRecoMaterialCopy(source_xml, filename):
tracker_reco_material = os.path.join(os.environ['CMSSW_RELEASE_BASE'],
source_xml)
if not os.path.exists(tracker_reco_material):
print 'Something is wrong with the CMSSW installation. The file %s is missing. Quitting.\n' % source_xml
print('Something is wrong with the CMSSW installation. The file %s is missing. Quitting.\n' % source_xml)
sys.exit(TRACKER_MATERIAL_FILE_MISSING)
copy2(tracker_reco_material, filename)

Expand Down Expand Up @@ -87,27 +88,27 @@ def produceXMLFromParameterFile(args):
sections = root.getchildren()
if args.verbose:
for child in sections[0]:
print child.attrib['name']
print(child.attrib['name'])

for spec_par in root.iter('%sSpecPar' % TAG_PREFIX):
current_detector = spec_par.attrib['name']
for parameter in spec_par.iter('%sParameter' % TAG_PREFIX):
if args.verbose:
print "Current Detector: %r, name=%s, value=%s" % (current_detector,
print("Current Detector: %r, name=%s, value=%s" % (current_detector,
parameter.attrib['name'],
parameter.attrib['value'])
parameter.attrib['value']))
updated_current_detector_node = root_updated.find(".//Group[@name='%s']" % current_detector)
if updated_current_detector_node is not None:
for child in updated_current_detector_node:
if child.attrib['name'] == parameter.attrib['name']:
parameter.set('name', child.attrib['name'])
parameter.set('value', child.attrib['value'])
if args.verbose:
print "Updated Detector: %r, name=%s, value=%s\n" % (child.attrib['name'],
print("Updated Detector: %r, name=%s, value=%s\n" % (child.attrib['name'],
parameter.attrib['name'],
parameter.attrib['value'])
parameter.attrib['value']))
else:
print "Missing group: %s" % current_detector
print("Missing group: %s" % current_detector)
tree.write('trackerRecoMaterial.xml', encoding='UTF-8', xml_declaration=True)

def compareNewXMLWithOld(args):
Expand Down Expand Up @@ -166,7 +167,7 @@ def compareNewXMLWithOld(args):
/float(parameter.attrib['value'])*100.)]
)
else:
print 'Element not found: %s' % current_detector
print('Element not found: %s' % current_detector)
for group in differences.keys():
header.write(' m_diff["%s"] = std::make_pair<float, float>(%f, %f);\n' % (group,
differences[group]['TrackerRadLength'][2],
Expand All @@ -179,23 +180,23 @@ def compareNewXMLWithOld(args):
for i in xrange(len(ordered_keys)):
key = ordered_keys[i]
if args.twiki:
print "| %s | %f | %f | %f%% | %f | %f | %f%% |" % (key,
print("| %s | %f | %f | %f%% | %f | %f | %f%% |" % (key,
differences[key]['TrackerRadLength'][0],
differences[key]['TrackerRadLength'][1],
differences[key]['TrackerRadLength'][2],
differences[key]['TrackerXi'][0],
differences[key]['TrackerXi'][1],
differences[key]['TrackerXi'][2]
)
))
else:
print "%s %f %f %f%% %f %f %f%%" % (key,
print("%s %f %f %f%% %f %f %f%%" % (key,
differences[key]['TrackerRadLength'][0],
differences[key]['TrackerRadLength'][1],
differences[key]['TrackerRadLength'][2],
differences[key]['TrackerXi'][0],
differences[key]['TrackerXi'][1],
differences[key]['TrackerXi'][2]
)
))
header.write(TRAILER)
header.close

Expand All @@ -209,7 +210,7 @@ def createTMGFromRelease(args):
"""
tracker_reco_material = checkFileInRelease(args.createTMG)
if not tracker_reco_material:
print "Input file not found in release, quitting"
print("Input file not found in release, quitting")
sys.exit(1)
ET.register_namespace('', "http://www.cern.ch/cms/DDL")
tree = ET.parse(tracker_reco_material)
Expand Down
23 changes: 12 additions & 11 deletions SimTracker/TrackerMaterialAnalysis/test/dumpFullXML_ForPhaseI.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function
import argparse
import os, sys
import pprint
Expand All @@ -25,7 +26,7 @@

def checkEnvironment():
if not 'CMSSW_RELEASE_BASE' in os.environ.keys():
print 'CMSSW Environments not setup, quitting\n'
print('CMSSW Environments not setup, quitting\n')
sys.exit(CMSSW_NOT_SET)

def getTrackerRecoMaterialCopy(filename):
Expand All @@ -35,7 +36,7 @@ def getTrackerRecoMaterialCopy(filename):
tracker_reco_material = os.path.join(os.environ['CMSSW_RELEASE_BASE'],
'src/Geometry/TrackerRecoData/data/PhaseI/pixfwd/trackerRecoMaterial.xml')
if not os.path.exists(tracker_reco_material):
print 'Something is wrong with the CMSSW installation. The file %s is missing. Quitting.\n' % tracker_reco_material
print('Something is wrong with the CMSSW installation. The file %s is missing. Quitting.\n' % tracker_reco_material)
sys.exit(TRACKER_MATERIAL_FILE_MISSING)
copy2(tracker_reco_material, filename)

Expand Down Expand Up @@ -63,21 +64,21 @@ def produceXMLFromParameterFile():
root_updated = tree_updated.getroot()
sections = root.getchildren()
for child in sections[0]:
print child.attrib['name']
print(child.attrib['name'])

for spec_par in root.iter('%sSpecPar' % TAG_PREFIX):
current_detector = spec_par.attrib['name']
for parameter in spec_par.iter('%sParameter' % TAG_PREFIX):
print current_detector, parameter.attrib['name'], parameter.attrib['value']
print(current_detector, parameter.attrib['name'], parameter.attrib['value'])
updated_current_detector_node = root_updated.find(".//Group[@name='%s']" % current_detector)
if updated_current_detector_node:
for child in updated_current_detector_node:
if child.attrib['name'] == parameter.attrib['name']:
parameter.set('name', child.attrib['name'])
parameter.set('value', child.attrib['value'])
print current_detector, parameter.attrib['name'], parameter.attrib['value']
print(current_detector, parameter.attrib['name'], parameter.attrib['value'])
else:
print "Missing group: %s" % current_detector
print("Missing group: %s" % current_detector)
tree.write('trackerRecoMaterial.xml', encoding='UTF-8', xml_declaration=True)

def compareNewXMLWithOld(format_for_twiki):
Expand Down Expand Up @@ -134,7 +135,7 @@ def compareNewXMLWithOld(format_for_twiki):
/float(parameter.attrib['value'])*100.)]
)
else:
print 'Element not found: %s' % current_detector
print('Element not found: %s' % current_detector)
for group in differences.keys():
header.write(' m_diff["%s"] = std::make_pair<float, float>(%f, %f);\n' % (group,
differences[group]['TrackerRadLength'][2],
Expand All @@ -147,23 +148,23 @@ def compareNewXMLWithOld(format_for_twiki):
for i in xrange(len(ordered_keys)):
key = ordered_keys[i]
if format_for_twiki:
print "| %s | %f | %f | %f%% | %f | %f | %f%% |" % (key,
print("| %s | %f | %f | %f%% | %f | %f | %f%% |" % (key,
differences[key]['TrackerRadLength'][0],
differences[key]['TrackerRadLength'][1],
differences[key]['TrackerRadLength'][2],
differences[key]['TrackerXi'][0],
differences[key]['TrackerXi'][1],
differences[key]['TrackerXi'][2]
)
))
else:
print "%s %f %f %f%% %f %f %f%%" % (key,
print("%s %f %f %f%% %f %f %f%%" % (key,
differences[key]['TrackerRadLength'][0],
differences[key]['TrackerRadLength'][1],
differences[key]['TrackerRadLength'][2],
differences[key]['TrackerXi'][0],
differences[key]['TrackerXi'][1],
differences[key]['TrackerXi'][2]
)
))
header.write(TRAILER)
header.close

Expand Down
1 change: 1 addition & 0 deletions SimTracker/TrackerMaterialAnalysis/test/listGroups.py
@@ -1,3 +1,4 @@
from __future__ import print_function
#! /usr/bin/env cmsRun

import sys
Expand Down
7 changes: 4 additions & 3 deletions SimTracker/TrackerMaterialAnalysis/test/tools/dump.py
@@ -1,14 +1,15 @@
#! /usr/bin/env python

from __future__ import print_function
import sys
import material

def usage():
print """Usage:
print("""Usage:
dump.py DIRECTION

Read a list of detectors from standard input and dump their coordinate along DIRECTION.
"""
""")

def dump():
if (len(sys.argv) < 2) or (sys.argv[1] not in material.Element.directions):
Expand All @@ -25,7 +26,7 @@ def dump():
positions.add(element.position[dir])
positions = sorted(positions)
for position in positions:
print position
print(position)


if __name__ == "__main__":
Expand Down
11 changes: 6 additions & 5 deletions SimTracker/TrackerMaterialAnalysis/test/tools/material.py
@@ -1,3 +1,4 @@
from __future__ import print_function
import sys
import re
import bisect
Expand Down Expand Up @@ -124,9 +125,9 @@ def parse(source):
for line in source:
match = pattern.match(line)
if not match:
print 'Warning: the following line does not match the parsing rules:'
print line
print
print('Warning: the following line does not match the parsing rules:')
print(line)
print()
continue
r = float(match.group(2))
z = float(match.group(3))
Expand Down Expand Up @@ -170,9 +171,9 @@ def split_along(direction, elements, cuts):
i = bisect.bisect(cuts, element.position[direction])
matching_filters = [ filter for filter in filters if filter.match(element) ]
if len(matching_filters) == 0:
print "Error: no matches for element %s" % element.full_name()
print("Error: no matches for element %s" % element.full_name())
elif len(matching_filters) > 1:
print "Error: too many matches for element %s" % element.full_name()
print("Error: too many matches for element %s" % element.full_name())
else:
groups[i].append( matching_filters[0] )
return groups
Expand Down
3 changes: 2 additions & 1 deletion SimTracker/TrackerMaterialAnalysis/test/tools/plot.py
@@ -1,11 +1,12 @@
#! /usr/bin/env python

from __future__ import print_function
import sys
import material
import ROOT

def usage():
print "Usage..."
print("Usage...")

def plot():
if (len(sys.argv) < 2) or (sys.argv[1] not in ("r", "z", "eta")):
Expand Down
5 changes: 3 additions & 2 deletions SimTracker/TrackerMaterialAnalysis/test/tools/split.py
@@ -1,18 +1,19 @@
#! /usr/bin/env python

from __future__ import print_function
import sys
import xml.dom
from xml.dom import minidom
import material
from domtools import DOMIterator, dom_strip

def usage():
print """Usage:
print("""Usage:
split.py NAME [DIRECTION CUT [CUT ...]]

Read a list of detectors from standard input, splits them into subgrouos at the CUTs position along the given DIRECTION, named after NAME, DIRECTION and relevant CUT.
The groups are appended to the trackingMaterialGroups.xml file - if not present an empty one is created beforehand.
"""
""")

def split():
if (len(sys.argv) < 2):
Expand Down