From e93c35cd3936cacdad09d03e2bed1c320b940629 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 25 Apr 2020 14:53:20 +0200 Subject: [PATCH] run basic python3 converters --- condDatasetSubmitter.py | 53 ++++----- .../MatrixReader_AlcaValidW13.py | 53 ++++----- .../relval_steps_AlcaValidW13.py | 15 +-- .../13jun-ConfigBuilder.py | 89 +++++++------- .../SpecialRequests2013/13jun-relval_steps.py | 15 +-- .../14jun-ConfigBuilder.py | 77 +++++++------ .../SpecialRequests2013/14jun-MatrixReader.py | 55 ++++----- .../SpecialRequests2013/14jun-relval_steps.py | 7 +- configs/SpecialRequests2013/16jul_Mixing.py | 7 +- .../SpecialRequests2013/16jul_relval_steps.py | 5 +- .../SpecialRequests2013/17jul_relval_steps.py | 15 +-- .../SpecialRequests2013/9jul-relval_steps.py | 15 +-- .../Aug13_ConfigBuilder.py | 89 +++++++------- .../SpecialRequests2013/Aug13_relval_steps.py | 15 +-- ...3_7_patch5_Battilana_taskForce_ZeroBias.py | 5 +- ...Battilana_taskForce_ZeroBias_RECOOUTOUT.py | 5 +- .../ConfigBuilder_24june.py | 77 +++++++------ ...ixInjector_KeepFirstAndLast_61X_GEDEGAM.py | 53 ++++----- .../MatrixReader_24june.py | 55 ++++----- .../MatrixReader_alcaW13-2012D.py | 53 ++++----- .../SpecialRequests2013/jul2-relval_steps.py | 15 +-- .../SpecialRequests2013/jun27-relval_steps.py | 15 +-- .../relval_steps_24june.py | 7 +- .../relval_steps_Ene50Photon.py | 15 +-- .../relval_steps_GEDEGAM.py | 15 +-- .../SpecialRequests2013/relval_steps_Mar12.py | 15 +-- .../relval_steps_RDverification.py | 15 +-- .../relval_steps_alcaW13-2012D.py | 15 +-- .../relval_steps_runDepMonteCarloApr24.py | 15 +-- configs/prepare_conf.py | 17 +-- launch_full_rereco.py | 11 +- modules/full_rereco.py | 60 +++++----- modules/helper.py | 12 +- modules/wma.py | 71 ++++++------ relval_submit.py | 37 +++--- wmapprove.py | 11 +- wmcontrol.py | 109 +++++++++--------- wmpriority.py | 7 +- wmupload.py | 7 +- 39 files changed, 634 insertions(+), 593 deletions(-) diff --git a/condDatasetSubmitter.py b/condDatasetSubmitter.py index a669f18..055eaff 100755 --- a/condDatasetSubmitter.py +++ b/condDatasetSubmitter.py @@ -1,5 +1,6 @@ #! /usr/bin/env python +from __future__ import print_function import ast import os import sys @@ -98,8 +99,8 @@ def createOptionParser(): CMSSW_VERSION = 'CMSSW_VERSION' - if not os.environ.has_key(CMSSW_VERSION): - print "\n CMSSW not properly set. Exiting" + if CMSSW_VERSION not in os.environ: + print("\n CMSSW not properly set. Exiting") sys.exit(1) options.release = os.getenv(CMSSW_VERSION) @@ -180,11 +181,11 @@ def isAtSite(ds, run): blocks.append('#' + block.split('#')[-1]) if len(blocks) == 0: - print "No possible block for %s in %s" % (run, ds) + print("No possible block for %s in %s" % (run, ds)) return False else: - print "\n\n\t Block testing succeeded for %s in %s \n\n" % (run, ds) - print blocks + print("\n\n\t Block testing succeeded for %s in %s \n\n" % (run, ds)) + print(blocks) return list(set(blocks)) #------------------------------------------------------------------------------- @@ -363,12 +364,12 @@ def getDriverDetails(Type, release, ds, B0T, HIon, pA, recoRelease): def execme(command): if DRYRUN: - print command + print(command) else: - print " * Executing: %s..." % command + print(" * Executing: %s..." % command) ##TO-DO: rewrite to subprocess! os.system(command) - print " * Executed!" + print(" * Executed!") #------------------------------------------------------------------------------- def createHLTConfig(options): @@ -400,7 +401,7 @@ def createHLTConfig(options): execme(cmssw_command + '; ' + hlt_command + '; ' + build_command) else: execme(cmssw_command + '; ' + hlt_command + '; ' + patch_command + '; ' + patch_command2 + '; ' + build_command) - print "\n CMSSW release for HLT doesn't allow usage of hltGetConfiguration out-of-the-box, patching configuration " + print("\n CMSSW release for HLT doesn't allow usage of hltGetConfiguration out-of-the-box, patching configuration ") def createCMSSWConfigs(options,confCondDictionary,allRunsAndBlocks): details = getDriverDetails(options.Type, options.release, options.ds, options.B0T, options.HIon,options.pA,options.recoRelease) @@ -418,7 +419,7 @@ def createCMSSWConfigs(options,confCondDictionary,allRunsAndBlocks): # Create the drivers for c in confCondList: (cfgname,custgt) = c - print "\n\n\tCreating for", cfgname, "\n\n" + print("\n\n\tCreating for", cfgname, "\n\n") driver_command = "cmsDriver.py %s " % (details['reqtype'])+\ "-s %s " % (details['steps']) +\ "--processName %s " % (details['procname']) +\ @@ -669,7 +670,7 @@ def createCMSSWConfigs(options,confCondDictionary,allRunsAndBlocks): 'harvest_cfg=step4_refer_HARVESTING.py\n\n' # this is ugly and depends on [0:5]; can't be easliy fixed w/o reorganization task = 2 - print confCondList + print(confCondList) for (i, c) in enumerate(confCondList): cfgname = c[0] if "REFERENCE" in cfgname: @@ -795,7 +796,7 @@ def createCMSSWConfigs(options,confCondDictionary,allRunsAndBlocks): wmcconf.close() execme('./wmcontrol.py --test --req_file %s' % (wmconf_name)) - print 'Now execute:\n./wmcontrol.py --req_file %s |& tee wmcontrol.1.log' % (wmconf_name) + print('Now execute:\n./wmcontrol.py --req_file %s |& tee wmcontrol.1.log' % (wmconf_name)) def printInfo(options): if "HLT" in options.Type: @@ -826,24 +827,24 @@ def printInfo(options): else: gtshort = options.gt - print "" - print "type: %s" % (options.Type) - print "dataset: %s" % (",".join(options.ds)) + print("") + print("type: %s" % (options.Type)) + print("dataset: %s" % (",".join(options.ds))) #print "run: %s" % (",".join(options.run)) if (options.run): - print "run: %s" % (",".join(options.run)) + print("run: %s" % (",".join(options.run))) elif (options.runLs): - print "run: %s" % (options.runLs) + print("run: %s" % (options.runLs)) if "HLT" in options.Type: - print "HLT menu: %s" % (menu) - print "Target HLT GT: %s" % (newgtshort) - print "Reference HLT GT: %s" % (gtshort) + print("HLT menu: %s" % (menu)) + print("Target HLT GT: %s" % (newgtshort)) + print("Reference HLT GT: %s" % (gtshort)) if "HLT" in options.Type and "RECO" in options.Type: - print "Common Prompt GT: %s" % (options.basegt) + print("Common Prompt GT: %s" % (options.basegt)) if "PR" in options.Type: - print "Target Prompt GT: %s" % (newgtshort) - print "Reference Prompt GT: %s" % (gtshort) + print("Target Prompt GT: %s" % (newgtshort)) + print("Reference Prompt GT: %s" % (gtshort)) #------------------------------------------------------------------------------- @@ -861,8 +862,8 @@ def printInfo(options): # Get the options options = createOptionParser() - print options.run - print type(options.run) + print(options.run) + print(type(options.run)) # this type is LIST in the normal CASE, # and it's also list with a single element == dictionary in the LS-filtering case. This is a problem @@ -881,7 +882,7 @@ def printInfo(options): for run in options.run: newblocks = isAtSite(ds, int(run)) if newblocks == False: - print "Cannot proceed with %s in %s (no suitable blocks found)" % (ds, run) + print("Cannot proceed with %s in %s (no suitable blocks found)" % (ds, run)) sys.exit(1) else: allRunsAndBlocks[ds].extend(newblocks) diff --git a/configs/SpecialRequests2012/MatrixReader_AlcaValidW13.py b/configs/SpecialRequests2012/MatrixReader_AlcaValidW13.py index 98d6f88..e60e5b3 100644 --- a/configs/SpecialRequests2012/MatrixReader_AlcaValidW13.py +++ b/configs/SpecialRequests2012/MatrixReader_AlcaValidW13.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys @@ -84,16 +85,16 @@ def readMatrix(self, fileNameIn, useInput=None, refRel=None, fromScratch=None): prefix = self.filesPrefMap[fileNameIn] - print "processing ", fileNameIn + print("processing ", fileNameIn) try: _tmpMod = __import__( 'Configuration.PyReleaseValidation.'+fileNameIn ) self.relvalModule = sys.modules['Configuration.PyReleaseValidation.'+fileNameIn] - except Exception, e: - print "ERROR importing file ", fileNameIn, str(e) + except Exception as e: + print("ERROR importing file ", fileNameIn, str(e)) return - print "request for INPUT for ", useInput + print("request for INPUT for ", useInput) fromInput={} @@ -254,13 +255,13 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= self.reset(what) if self.what != 'all' and self.what not in matrixFile: - print "ignoring non-requested file",matrixFile + print("ignoring non-requested file",matrixFile) continue try: self.readMatrix(matrixFile, useInput, refRel, fromScratch) - except Exception, e: - print "ERROR reading file:", matrixFile, str(e) + except Exception as e: + print("ERROR reading file:", matrixFile, str(e)) raise if not self.workFlowSteps: continue @@ -268,7 +269,7 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= dataFileName = matrixFile.replace('relval_', 'cmsDriver_')+'_hlt.txt' outFile = open(dataFileName,'w') - print "found ", len(self.workFlowSteps.keys()), ' workflows for ', dataFileName + print("found ", len(self.workFlowSteps.keys()), ' workflows for ', dataFileName) ids = self.workFlowSteps.keys() ids.sort() indexAndSteps=[] @@ -340,7 +341,7 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= outFile.write(line+'\n') outFile.write('\n'+'\n') outFile.close() - print "wrote ",writtenWF, ' workflow'+('s' if (writtenWF!=1) else ''),' to ', outFile.name + print("wrote ",writtenWF, ' workflow'+('s' if (writtenWF!=1) else ''),' to ', outFile.name) return @@ -349,9 +350,9 @@ def showWorkFlows(self, selected=None, extended=True): maxLen = 100 # for summary, limit width of output fmt1 = "%-6s %-35s [1]: %s ..." fmt2 = " %35s [%d]: %s ..." - print "\nfound a total of ", len(self.workFlows), ' workflows:' + print("\nfound a total of ", len(self.workFlows), ' workflows:') if selected: - print " of which the following", len(selected), 'were selected:' + print(" of which the following", len(selected), 'were selected:') #-ap for now: maxLen = -1 # for individual listing, no limit on width fmt1 = "%-6s %-35s [1]: %s " @@ -360,7 +361,7 @@ def showWorkFlows(self, selected=None, extended=True): N=[] for wf in self.workFlows: if selected and float(wf.numId) not in selected: continue - if extended: print '' + if extended: print('') #pad with zeros for i in range(len(N),len(wf.cmds)): N.append(0) N[len(wf.cmds)-1]+=1 @@ -368,15 +369,15 @@ def showWorkFlows(self, selected=None, extended=True): for i,s in enumerate(wf.cmds): if extended: if i==0: - print fmt1 % (wf.numId, stepNames, (str(s)+' ')[:maxLen]) + print(fmt1 % (wf.numId, stepNames, (str(s)+' ')[:maxLen])) else: - print fmt2 % ( ' ', i+1, (str(s)+' ')[:maxLen]) + print(fmt2 % ( ' ', i+1, (str(s)+' ')[:maxLen])) else: - print "%-6s %-35s "% (wf.numId, stepNames) + print("%-6s %-35s "% (wf.numId, stepNames)) break - print '' + print('') for i,n in enumerate(N): - if n: print n,'workflows with',i+1,'steps' + if n: print(n,'workflows with',i+1,'steps') return @@ -397,9 +398,9 @@ def createWorkFlows(self, fileNameIn): num, name, commands, stepList = val nameId = str(num)+'_'+name if nameId in self.nameList: - print "==> duplicate name found for ", nameId - print ' keeping : ', self.nameList[nameId] - print ' ignoring : ', val + print("==> duplicate name found for ", nameId) + print(' keeping : ', self.nameList[nameId]) + print(' ignoring : ', val) else: self.nameList[nameId] = val @@ -411,26 +412,26 @@ def prepare(self, useInput=None, refRel='', fromScratch=None): for matrixFile in self.files: if self.what != 'all' and self.what not in matrixFile: - print "ignoring non-requested file",matrixFile + print("ignoring non-requested file",matrixFile) continue try: self.readMatrix(matrixFile, useInput, refRel, fromScratch) - except Exception, e: - print "ERROR reading file:", matrixFile, str(e) + except Exception as e: + print("ERROR reading file:", matrixFile, str(e)) raise try: self.createWorkFlows(matrixFile) - except Exception, e: - print "ERROR creating workflows :", str(e) + except Exception as e: + print("ERROR creating workflows :", str(e)) raise def show(self, selected=None, extended=True): self.showWorkFlows(selected,extended) - print '\n','-'*80,'\n' + print('\n','-'*80,'\n') def updateDB(self): diff --git a/configs/SpecialRequests2012/relval_steps_AlcaValidW13.py b/configs/SpecialRequests2012/relval_steps_AlcaValidW13.py index 4db7b31..9f03fc8 100644 --- a/configs/SpecialRequests2012/relval_steps_AlcaValidW13.py +++ b/configs/SpecialRequests2012/relval_steps_AlcaValidW13.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -15,8 +16,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -26,7 +27,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -67,13 +68,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/13jun-ConfigBuilder.py b/configs/SpecialRequests2013/13jun-ConfigBuilder.py index 6ee4520..8883e2b 100644 --- a/configs/SpecialRequests2013/13jun-ConfigBuilder.py +++ b/configs/SpecialRequests2013/13jun-ConfigBuilder.py @@ -1,5 +1,6 @@ #! /usr/bin/env python +from __future__ import print_function __version__ = "$Revision: 1.381.2.27 $" __source__ = "$Source: /local/reps/CMSSW/CMSSW/Configuration/PyReleaseValidation/python/ConfigBuilder.py,v $" @@ -104,9 +105,9 @@ def filesFromList(fileName,s=None): s.secondaryFileNames=cms.untracked.vstring(sec) else: s.secondaryFileNames.extend(sec) - print "found files: ",prim + print("found files: ",prim) if len(sec)!=0: - print "found parent files:",sec + print("found parent files:",sec) return (prim,sec) def filesFromDBSQuery(query,s=None): @@ -114,7 +115,7 @@ def filesFromDBSQuery(query,s=None): import FWCore.ParameterSet.Config as cms prim=[] sec=[] - print "the query is",query + print("the query is",query) for line in os.popen('dbs search --query "%s"'%(query)): if line.count(".root")>=2: #two files solution... @@ -137,9 +138,9 @@ def filesFromDBSQuery(query,s=None): s.secondaryFileNames=cms.untracked.vstring(sec) else: s.secondaryFileNames.extend(sec) - print "found files: ",prim + print("found files: ",prim) if len(sec)!=0: - print "found parent files:",sec + print("found parent files:",sec) return (prim,sec) def MassReplaceInputTag(aProcess,oldT="rawDataCollector",newT="rawDataRepacker"): @@ -319,7 +320,7 @@ def addSource(self): def filesFromOption(self): for entry in self._options.filein.split(','): - print "entry",entry + print("entry",entry) if entry.startswith("filelist:"): filesFromList(entry[9:],self.process.source) elif entry.startswith("dbs:"): @@ -330,7 +331,7 @@ def filesFromOption(self): if not hasattr(self.process.source,"secondaryFileNames"): raise Exception("--secondfilein not compatible with "+self._options.filetype+"input type") for entry in self._options.secondfilein.split(','): - print "entry",entry + print("entry",entry) if entry.startswith("filelist:"): self.process.source.secondaryFileNames.extend((filesFromList(entry[9:]))[0]) elif entry.startswith("dbs:"): @@ -353,7 +354,7 @@ def filesFromOption(self): #list the article directory automatically args=self._options.filein.split(':') article=args[1] - print 'LHE input from article ',article + print('LHE input from article ',article) location='/store/lhe/' import os textOfFiles=os.popen('cmsLHEtoEOSManager.py -l '+article) @@ -431,7 +432,7 @@ def addOutput(self): result="" if self._options.outputDefinition: if self._options.datatier: - print "--datatier & --eventcontent options ignored" + print("--datatier & --eventcontent options ignored") def anyOf(listOfKeys,dict,opt=None): for k in listOfKeys: @@ -607,7 +608,7 @@ def addStandardSequences(self): if 'file:' in pileupSpec: #the file is local self.process.load(mixingDict['file']) - print "inlining mixing module configuration" + print("inlining mixing module configuration") self._options.inlineObjets+=',mix' else: self.loadAndRemember(mixingDict['file']) @@ -634,7 +635,7 @@ def addStandardSequences(self): if self.geometryDBLabel: self.executeAndRemember('process.XMLFromDBSource.label = cms.string("%s")'%(self.geometryDBLabel)) except ImportError: - print "Geometry option",self._options.geometry,"unknown." + print("Geometry option",self._options.geometry,"unknown.") raise if len(self.stepMap): @@ -643,7 +644,7 @@ def addStandardSequences(self): for stepName in self.stepKeys: stepSpec = self.stepMap[stepName] - print "Step:", stepName,"Spec:",stepSpec + print("Step:", stepName,"Spec:",stepSpec) if stepName.startswith('re'): ##add the corresponding input content if stepName[2:] not in self._options.donotDropOnInput: @@ -714,7 +715,7 @@ def addConditions(self): if not self._options.conditions: return if 'FrontierConditions_GlobalTag' in self._options.conditions: - print 'using FrontierConditions_GlobalTag in --conditions is not necessary anymore and will be deprecated soon. please update your command line' + print('using FrontierConditions_GlobalTag in --conditions is not necessary anymore and will be deprecated soon. please update your command line') self._options.conditions = self._options.conditions.replace("FrontierConditions_GlobalTag,",'') self.loadAndRemember(self.ConditionsDefaultCFF) @@ -778,7 +779,7 @@ def addCustomise(self): else: final_snippet += 'from %s import %s \n'%(packageName,','.join(custMap[f])) for fcn in custMap[f]: - print "customising the process with",fcn,"from",f + print("customising the process with",fcn,"from",f) if not hasattr(package,fcn): #bound to fail at run time raise Exception("config "+f+" has no function "+fcn) @@ -810,8 +811,8 @@ def define_Configs(self): if len(self.stepMap): self.loadAndRemember('Configuration/StandardSequences/Services_cff') if self._options.particleTable not in defaultOptions.particleTableList: - print 'Invalid particle table provided. Options are:' - print defaultOptions.particleTable + print('Invalid particle table provided. Options are:') + print(defaultOptions.particleTable) sys.exit(-1) else: if len(self.stepMap): @@ -914,7 +915,7 @@ def define_Configs(self): self.DQMDefaultSeq='DQMOfflineCosmics' if self._options.himix: - print "From the presence of the himix option, we have determined that this is heavy ions and will use '--scenario HeavyIons'." + print("From the presence of the himix option, we have determined that this is heavy ions and will use '--scenario HeavyIons'.") self._options.scenario='HeavyIons' if self._options.scenario=='HeavyIons': @@ -947,7 +948,7 @@ def define_Configs(self): # the magnetic field if self._options.isData: if self._options.magField==defaultOptions.magField: - print "magnetic field option forced to: AutoFromDBCurrent" + print("magnetic field option forced to: AutoFromDBCurrent") self._options.magField='AutoFromDBCurrent' self.magFieldCFF = 'Configuration/StandardSequences/MagneticField_'+self._options.magField.replace('.','')+'_cff' self.magFieldCFF = self.magFieldCFF.replace("__",'_') @@ -981,7 +982,7 @@ def inGeometryKeys(opt): if (geoms[0].startswith('DB:')): self.SimGeometryCFF='Configuration/StandardSequences/GeometrySimDB_cff' self.geometryDBLabel=geoms[0][3:] - print "with DB:" + print("with DB:") else: if '/' in geoms[0] or '_cff' in geoms[0]: self.SimGeometryCFF=geoms[0] @@ -997,7 +998,7 @@ def inGeometryKeys(opt): self.SIMDefaultCFF="Configuration/StandardSequences/SimIdeal_cff" if self._options.scenario=='nocoll' or self._options.scenario=='cosmics': - print simGeometry + print(simGeometry) self.SIMDefaultCFF="Configuration/StandardSequences/SimNOBEAM_cff" self._options.beamspot='NoSmear' @@ -1102,8 +1103,8 @@ def loadDefaultOrSpecifiedCFF(self, sequence,defaultCFF): l=self.loadAndRemember(sequence.split('.')[0]) sequence=sequence.split('.')[1] else: - print "sub sequence configuration must be of the form dir/subdir/cff.a+b+c or cff.a" - print sequence,"not recognized" + print("sub sequence configuration must be of the form dir/subdir/cff.a+b+c or cff.a") + print(sequence,"not recognized") raise return l @@ -1195,8 +1196,8 @@ def prepare_ALCA(self, sequence = None, workflow = 'full'): alcastream = getattr(alcaConfig,name) if isinstance(alcastream,cms.FilteredStream): available.append(name.replace('ALCARECOStream','')) - print "The following alcas could not be found "+str(alcaList) - print "available ",available + print("The following alcas could not be found "+str(alcaList)) + print("available ",available) #print "verify your configuration, ignoring for now" raise Exception("The following alcas could not be found "+str(alcaList)) @@ -1204,7 +1205,7 @@ def prepare_LHE(self, sequence = None): #load the fragment ##make it loadable loadFragment = self._options.evt_type.replace('.py','',).replace('.','_').replace('python/','').replace('/','.') - print "Loading lhe fragment from",loadFragment + print("Loading lhe fragment from",loadFragment) __import__(loadFragment) self.process.load(loadFragment) ##inline the modules @@ -1229,7 +1230,7 @@ def prepare_GEN(self, sequence = None): else: loadFragment=loadFragment.replace('/','.') try: - print "Loading generator fragment from",loadFragment + print("Loading generator fragment from",loadFragment) __import__(loadFragment) except: loadFailure=True @@ -1361,7 +1362,7 @@ def prepare_L1(self, sequence = None): def prepare_L1REPACK(self, sequence = None): """ Enrich the schedule with the L1 simulation step, running the L1 emulator on data unpacked from the RAW collection, and repacking the result in a new RAW collection""" if sequence is not 'GT': - print 'Running the full L1 emulator is not supported yet' + print('Running the full L1 emulator is not supported yet') raise Exception('unsupported feature') if sequence is 'GT': self.loadAndRemember('Configuration/StandardSequences/SimL1EmulatorRepack_GT_cff') @@ -1373,7 +1374,7 @@ def prepare_L1REPACK(self, sequence = None): def prepare_HLT(self, sequence = None): """ Enrich the schedule with the HLT simulation step""" if not sequence: - print "no specification of the hlt menu has been given, should never happen" + print("no specification of the hlt menu has been given, should never happen") raise Exception('no HLT sequence provided') if '@' in sequence: @@ -1430,7 +1431,7 @@ def prepare_RAW2RECO(self, sequence = None): seqReco=sequence.split(',')[1] seqDigi=sequence.split(',')[0] else: - print "RAW2RECO requires two specifications",sequence,"insufficient" + print("RAW2RECO requires two specifications",sequence,"insufficient") self.prepare_RAW2DIGI(seqDigi) self.prepare_RECO(seqReco) @@ -1447,7 +1448,7 @@ def prepare_L1HwVal(self, sequence = 'L1HwVal'): ''' Enrich the schedule with L1 HW validation ''' self.loadDefaultOrSpecifiedCFF(sequence,self.L1HwValDefaultCFF) #self.scheduleSequence(sequence.split('.')[-1],'l1hwval_step') - print '\n\n\n DEPRECATED this has no action \n\n\n' + print('\n\n\n DEPRECATED this has no action \n\n\n') return def prepare_L1Reco(self, sequence = "L1Reco"): @@ -1535,7 +1536,7 @@ def prepare_SKIM(self, sequence = "all"): if (skimlist.__len__()!=0 and sequence!="all"): - print 'WARNING, possible typo with SKIM:'+'+'.join(skimlist) + print('WARNING, possible typo with SKIM:'+'+'.join(skimlist)) raise Exception('WARNING, possible typo with SKIM:'+'+'.join(skimlist)) def prepare_USER(self, sequence = None): @@ -1620,7 +1621,7 @@ def doIt(self,pset,base): for (i,ps) in enumerate(value): self.doIt(ps, "%s.%s[%d]"%(base,name,i) ) elif type in ('cms.string', 'cms.untracked.string'): if value.value() == self._paramSearch: - if self._verbose: print "set string process name %s.%s %s ==> %s"% (base, name, value, self._paramReplace) + if self._verbose: print("set string process name %s.%s %s ==> %s"% (base, name, value, self._paramReplace)) setattr(pset, name,self._paramReplace) elif type in ('cms.VInputTag', 'cms.untracked.VInputTag'): for (i,n) in enumerate(value): @@ -1628,7 +1629,7 @@ def doIt(self,pset,base): n=cms.InputTag(n) if n.processName == self._paramSearch: # VInputTag can be declared as a list of strings, so ensure that n is formatted correctly - if self._verbose:print "set process name %s.%s[%d] %s ==> %s " % (base, name, i, n, self._paramReplace) + if self._verbose:print("set process name %s.%s[%d] %s ==> %s " % (base, name, i, n, self._paramReplace)) setattr(n,"processName",self._paramReplace) value[i]=n elif type in ('cms.vstring', 'cms.untracked.vstring'): @@ -1637,7 +1638,7 @@ def doIt(self,pset,base): getattr(pset,name)[i]=self._paramReplace elif type in ('cms.InputTag', 'cms.untracked.InputTag'): if value.processName == self._paramSearch: - if self._verbose: print "set process name %s.%s %s ==> %s " % (base, name, value, self._paramReplace) + if self._verbose: print("set process name %s.%s %s ==> %s " % (base, name, value, self._paramReplace)) setattr(getattr(pset, name),"processName",self._paramReplace) def enter(self,visitee): @@ -1655,7 +1656,7 @@ def leave(self,visitee): #visit a sequence to repalce all input tags def renameInputTagsInSequence(self,sequence,oldT="rawDataCollector",newT="rawDataRepacker"): - print "Replacing all InputTag %s => %s"%(oldT,newT) + print("Replacing all InputTag %s => %s"%(oldT,newT)) from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag massSearchReplaceAnyInputTag(getattr(self.process,sequence),oldT,newT) loadMe='from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag' @@ -1671,7 +1672,7 @@ def renameHLTprocessInSequence(self,sequence,proc=None,HLTprocess='HLT'): proc=self.process.name_() if proc==HLTprocess: return # look up all module in dqm sequence - print "replacing %s process name - sequence %s will use '%s'" % (HLTprocess,sequence, proc) + print("replacing %s process name - sequence %s will use '%s'" % (HLTprocess,sequence, proc)) getattr(self.process,sequence).visit(ConfigBuilder.MassSearchReplaceProcessNameVisitor(HLTprocess,proc,whitelist = ("subSystemFolder",))) if 'from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder' not in self.additionalCommands: self.additionalCommands.append('from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder') @@ -1707,7 +1708,7 @@ def prepare_DQM(self, sequence = 'DQMOffline'): if len(set(sequenceList))!=len(sequenceList): sequenceList=list(set(sequenceList)) - print "Duplicate entries for DQM:, using",sequenceList + print("Duplicate entries for DQM:, using",sequenceList) pathName='dqmoffline_step' for (i,sequence) in enumerate(sequenceList): @@ -1746,11 +1747,11 @@ def prepare_HARVESTING(self, sequence = None): if len(set(harvestingList))!=len(harvestingList): harvestingList=list(set(harvestingList)) - print "Duplicate entries for HARVESTING, using",harvestingList + print("Duplicate entries for HARVESTING, using",harvestingList) for name in harvestingList: if not name in harvestingConfig.__dict__: - print name,"is not a possible harvesting type. Available are",harvestingConfig.__dict__.keys() + print(name,"is not a possible harvesting type. Available are",harvestingConfig.__dict__.keys()) continue harvestingstream = getattr(harvestingConfig,name) if isinstance(harvestingstream,cms.Path): @@ -1782,7 +1783,7 @@ def prepare_ALCAHARVEST(self, sequence = None): self.schedule.append(lastStep) if len(harvestingList) != 0 and 'dummyHarvesting' not in harvestingList : - print "The following harvesting could not be found : ", harvestingList + print("The following harvesting could not be found : ", harvestingList) raise Exception("The following harvesting could not be found : "+str(harvestingList)) @@ -1823,7 +1824,7 @@ def prepare_FASTSIM(self, sequence = "all"): # now the additional commands we need to make the config work self.executeAndRemember("process.VolumeBasedMagneticFieldESProducer.useParametrizedTrackerField = True") else: - print "FastSim setting", sequence, "unknown." + print("FastSim setting", sequence, "unknown.") raise ValueError if 'Flat' in self._options.beamspot: @@ -1921,7 +1922,7 @@ def prepare(self, doChecking = False): if not object: continue if not hasattr(self.process,object): - print 'cannot inline -'+object+'- : not known' + print('cannot inline -'+object+'- : not known') else: self.pythonCfgCode +='\n' self.pythonCfgCode +=dumpPython(self.process,object) @@ -2062,7 +2063,7 @@ def addOutputModule(process, tier, content): Function to add an output module to a given process with given data tier and event content """ - print "WARNING. this method will not be supported any more SOON, please use --eventcontent --datatier field to drive the output module definitions" + print("WARNING. this method will not be supported any more SOON, please use --eventcontent --datatier field to drive the output module definitions") moduleName = "output%s%s" % (tier, content) pathName = "%sPath" % moduleName @@ -2077,7 +2078,7 @@ def addOutputModule(process, tier, content): ), ) ) - print getattr(process,moduleName) + print(getattr(process,moduleName)) # put it in an EndPath and put the EndPath into the schedule setattr(process, pathName, cms.EndPath(getattr(process,moduleName)) ) process.schedule.append(getattr(process, pathName)) diff --git a/configs/SpecialRequests2013/13jun-relval_steps.py b/configs/SpecialRequests2013/13jun-relval_steps.py index 6c60e1a..c57b2ea 100644 --- a/configs/SpecialRequests2013/13jun-relval_steps.py +++ b/configs/SpecialRequests2013/13jun-relval_steps.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -15,8 +16,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -26,7 +27,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -85,13 +86,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/14jun-ConfigBuilder.py b/configs/SpecialRequests2013/14jun-ConfigBuilder.py index 17c0d6c..e594ca4 100644 --- a/configs/SpecialRequests2013/14jun-ConfigBuilder.py +++ b/configs/SpecialRequests2013/14jun-ConfigBuilder.py @@ -1,5 +1,6 @@ #! /usr/bin/env python +from __future__ import print_function __version__ = "$Revision: 1.303.2.11 $" __source__ = "$Source: /local/reps/CMSSW/CMSSW/Configuration/PyReleaseValidation/python/ConfigBuilder.py,v $" @@ -90,9 +91,9 @@ def filesFromList(fileName,s=None): s.secondaryFileNames=cms.untracked.vstring(sec) else: s.secondaryFileNames.extend(sec) - print "found files: ",prim + print("found files: ",prim) if len(sec)!=0: - print "found parent files:",sec + print("found parent files:",sec) return (prim,sec) def filesFromDBSQuery(query,s=None): @@ -100,7 +101,7 @@ def filesFromDBSQuery(query,s=None): import FWCore.ParameterSet.Config as cms prim=[] sec=[] - print "the query is",query + print("the query is",query) for line in os.popen('dbs search --query "%s"'%(query)): if line.count(".root")>=2: #two files solution... @@ -123,9 +124,9 @@ def filesFromDBSQuery(query,s=None): s.secondaryFileNames=cms.untracked.vstring(sec) else: s.secondaryFileNames.extend(sec) - print "found files: ",prim + print("found files: ",prim) if len(sec)!=0: - print "found parent files:",sec + print("found parent files:",sec) return (prim,sec) @@ -235,7 +236,7 @@ def addSource(self): def filesFromOption(self): for entry in self._options.filein.split(','): - print "entry",entry + print("entry",entry) if entry.startswith("filelist:"): filesFromList(entry[9:],self.process.source) elif entry.startswith("dbs:"): @@ -246,7 +247,7 @@ def filesFromOption(self): if not hasattr(self.process.source,"secondaryFileNames"): raise Exception("--secondfilein not compatible with "+self._options.filetype+"input type") for entry in self._options.secondfilein.split(','): - print "entry",entry + print("entry",entry) if entry.startswith("filelist:"): self.process.source.secondaryFileNames.extend((filesFromList(entry[9:]))[0]) elif entry.startswith("dbs:"): @@ -263,7 +264,7 @@ def filesFromOption(self): self.process.source=cms.Source("LHESource", fileNames = cms.untracked.vstring()) #provided by article number if self._options.filein.startswith("lhe:"): - print 'LHE input from article',self._options.filein + print('LHE input from article',self._options.filein) #list the article directory automatically args=self._options.filein.split(':') article=args[1] @@ -285,7 +286,7 @@ def filesFromOption(self): if self._options.dbsquery!='': self.process.source=cms.Source("PoolSource", fileNames = cms.untracked.vstring(),secondaryFileNames = cms.untracked.vstring()) import os - print "the query is",self._options.dbsquery + print("the query is",self._options.dbsquery) for line in os.popen('dbs search --query "%s"'%(self._options.dbsquery,)): if line.count(".root")>=2: #two files solution... @@ -299,9 +300,9 @@ def filesFromOption(self): entry=line.replace("\n","") if not entry in self.process.source.fileNames.value(): self.process.source.fileNames.append(entry) - print "found files: ",self.process.source.fileNames.value() + print("found files: ",self.process.source.fileNames.value()) if self.process.source.secondaryFileNames.__len__()!=0: - print "found parent files:",self.process.source.secondaryFileNames.value() + print("found parent files:",self.process.source.secondaryFileNames.value()) if self._options.inputCommands: self.process.source.inputCommands = cms.untracked.vstring() @@ -337,7 +338,7 @@ def addOutput(self): raise Exception("number of event content arguments does not match number of datatier arguments") if self._options.outputDefinition: if self._options.datatier: - print "--datatier & --eventcontent options ignored" + print("--datatier & --eventcontent options ignored") def anyOf(listOfKeys,dict,opt=None): for k in listOfKeys: @@ -502,7 +503,7 @@ def addStandardSequences(self): try: self.loadAndRemember(self.GeometryCFF) except ImportError: - print "Geometry option",self._options.geometry,"unknown." + print("Geometry option",self._options.geometry,"unknown.") raise self.loadAndRemember(self.magFieldCFF) @@ -518,7 +519,7 @@ def addStandardSequences(self): for step in self._options.step.split(","): if step == "": continue - print step + print(step) stepParts = step.split(":") # for format STEP:alternativeSequence stepName = stepParts[0] if stepName not in stepList: @@ -591,7 +592,7 @@ def addConditions(self): if i<2: untracked='' else: untracked='untracked.' payloadSpecToAppend+='%s=cms.%sstring("%s"),'%(item,untracked,payloadSpec[item]) - print 'customising the GlogalTag with:',payloadSpecToAppend + print('customising the GlogalTag with:',payloadSpecToAppend) self.executeAndRemember('process.GlobalTag.toGet.append(cms.PSet(%s))'%(payloadSpecToAppend,)) @@ -644,7 +645,7 @@ def addCustomise(self): else: final_snippet += 'from %s import %s \n'%(packageName,','.join(custMap[f])) for fcn in custMap[f]: - print "customising the process with",fcn,"from",f + print("customising the process with",fcn,"from",f) if not hasattr(package,fcn): #bound to fail at run time raise Exception("config "+f+" has no function "+fcn) @@ -661,14 +662,14 @@ def addCustomise(self): #---------------------------------------------------------------------------- def define_Configs(self): if ( self._options.scenario not in defaultOptions.scenarioOptions): - print 'Invalid scenario provided. Options are:' - print defaultOptions.scenarioOptions + print('Invalid scenario provided. Options are:') + print(defaultOptions.scenarioOptions) sys.exit(-1) self.loadAndRemember('Configuration/StandardSequences/Services_cff') if self._options.particleTable not in defaultOptions.particleTableList: - print 'Invalid particle table provided. Options are:' - print defaultOptions.particleTable + print('Invalid particle table provided. Options are:') + print(defaultOptions.particleTable) sys.exit(-1) else: self.loadAndRemember('SimGeneral.HepPDTESSource.'+self._options.particleTable+'_cfi') @@ -772,7 +773,7 @@ def define_Configs(self): self.eventcontent='FEVT' if self._options.himix: - print "From the presence of the himix option, we have determined that this is heavy ions and will use '--scenario HeavyIons'." + print("From the presence of the himix option, we have determined that this is heavy ions and will use '--scenario HeavyIons'.") self._options.scenario='HeavyIons' if self._options.scenario=='HeavyIons': @@ -906,8 +907,8 @@ def loadDefaultOrSpecifiedCFF(self, sequence,defaultCFF): l=self.loadAndRemember(sequence.split('.')[0]) sequence=sequence.split('.')[1] else: - print "sub sequence configuration must be of the form dir/subdir/cff.a+b+c or cff.a" - print sequence,"not recognized" + print("sub sequence configuration must be of the form dir/subdir/cff.a+b+c or cff.a") + print(sequence,"not recognized") raise return l @@ -1003,8 +1004,8 @@ def prepare_ALCA(self, sequence = None, workflow = 'full'): alcastream = getattr(alcaConfig,name) if isinstance(alcastream,cms.FilteredStream): available.append(name.replace('ALCARECOStream','')) - print "The following alcas could not be found "+str(alcaList) - print "available ",available + print("The following alcas could not be found "+str(alcaList)) + print("available ",available) #print "verify your configuration, ignoring for now" raise Exception("The following alcas could not be found "+str(alcaList)) @@ -1146,7 +1147,7 @@ def prepare_HLT(self, sequence = None): fastSim=True loadDir='FastSimulation' if not sequence: - print "no specification of the hlt menu has been given, should never happen" + print("no specification of the hlt menu has been given, should never happen") raise Exception('no HLT sequence provided') else: if ',' in sequence: @@ -1175,7 +1176,7 @@ def prepare_RAW2RECO(self, sequence = None): seqReco=sequence.split(',')[1] seqDigi=sequence.split(',')[0] else: - print "RAW2RECO requires two specifications",sequence,"insufficient" + print("RAW2RECO requires two specifications",sequence,"insufficient") self.prepare_RAW2DIGI(seqDigi) self.prepare_RECO(seqReco) @@ -1251,7 +1252,7 @@ def prepare_SKIM(self, sequence = "all"): if (skimlist.__len__()!=0 and sequence!="all"): - print 'WARNING, possible typo with SKIM:'+'+'.join(skimlist) + print('WARNING, possible typo with SKIM:'+'+'.join(skimlist)) raise Exception('WARNING, possible typo with SKIM:'+'+'.join(skimlist)) def prepare_POSTRECO(self, sequence = None): @@ -1327,7 +1328,7 @@ def doIt(self,pset,base): for (i,ps) in enumerate(value): self.doIt(ps, "%s.%s[%d]"%(base,name,i) ) elif type in ('cms.string', 'cms.untracked.string'): if value.value() == self._paramSearch: - if self._verbose: print "set string process name %s.%s %s ==> %s"% (base, name, value, self._paramReplace) + if self._verbose: print("set string process name %s.%s %s ==> %s"% (base, name, value, self._paramReplace)) setattr(pset, name,self._paramReplace) elif type in ('cms.VInputTag', 'cms.untracked.VInputTag'): for (i,n) in enumerate(value): @@ -1335,7 +1336,7 @@ def doIt(self,pset,base): n=cms.InputTag(n) if n.processName == self._paramSearch: # VInputTag can be declared as a list of strings, so ensure that n is formatted correctly - if self._verbose:print "set process name %s.%s[%d] %s ==> %s " % (base, name, i, n, self._paramReplace) + if self._verbose:print("set process name %s.%s[%d] %s ==> %s " % (base, name, i, n, self._paramReplace)) setattr(n,"processName",self._paramReplace) value[i]=n elif type in ('cms.vstring', 'cms.untracked.vstring'): @@ -1344,7 +1345,7 @@ def doIt(self,pset,base): getattr(pset,name)[i]=self._paramReplace elif type in ('cms.InputTag', 'cms.untracked.InputTag'): if value.processName == self._paramSearch: - if self._verbose: print "set process name %s.%s %s ==> %s " % (base, name, value, self._paramReplace) + if self._verbose: print("set process name %s.%s %s ==> %s " % (base, name, value, self._paramReplace)) setattr(getattr(pset, name),"processName",self._paramReplace) def enter(self,visitee): @@ -1368,7 +1369,7 @@ def renameHLTprocessInSequence(self,sequence,proc=None,HLTprocess='HLT'): proc=self.process.name_() if proc==HLTprocess: return # look up all module in dqm sequence - print "replacing %s process name - sequence %s will use '%s'" % (HLTprocess,sequence, proc) + print("replacing %s process name - sequence %s will use '%s'" % (HLTprocess,sequence, proc)) getattr(self.process,sequence).visit(ConfigBuilder.MassSearchReplaceProcessNameVisitor(HLTprocess,proc,whitelist = ("subSystemFolder",))) if 'from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder' not in self.additionalCommands: self.additionalCommands.append('from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder') @@ -1422,7 +1423,7 @@ def prepare_HARVESTING(self, sequence = None): harvestingList.remove('alcaHarvesting') if len(harvestingList) != 0 and 'dummyHarvesting' not in harvestingList : - print "The following harvesting could not be found : ", harvestingList + print("The following harvesting could not be found : ", harvestingList) raise self.scheduleSequence('DQMSaver','dqmsave_step') @@ -1447,7 +1448,7 @@ def prepare_ALCAHARVEST(self, sequence = None): self.schedule.append(lastStep) if len(harvestingList) != 0 and 'dummyHarvesting' not in harvestingList : - print "The following harvesting could not be found : ", harvestingList + print("The following harvesting could not be found : ", harvestingList) raise @@ -1488,7 +1489,7 @@ def prepare_FASTSIM(self, sequence = "all"): # now the additional commands we need to make the config work self.executeAndRemember("process.VolumeBasedMagneticFieldESProducer.useParametrizedTrackerField = True") else: - print "FastSim setting", sequence, "unknown." + print("FastSim setting", sequence, "unknown.") raise ValueError if 'Flat' in self._options.beamspot: @@ -1582,7 +1583,7 @@ def prepare(self, doChecking = False): if not object: continue if not hasattr(self.process,object): - print 'cannot inline -'+object+'- : not known' + print('cannot inline -'+object+'- : not known') else: self.pythonCfgCode +='\n' self.pythonCfgCode +=dumpPython(self.process,object) @@ -1707,7 +1708,7 @@ def addOutputModule(process, tier, content): Function to add an output module to a given process with given data tier and event content """ - print "WARNING. this method will not be supported any more SOON, please use --eventcontent --datatier field to drive the output module definitions" + print("WARNING. this method will not be supported any more SOON, please use --eventcontent --datatier field to drive the output module definitions") moduleName = "output%s%s" % (tier, content) pathName = "%sPath" % moduleName @@ -1722,7 +1723,7 @@ def addOutputModule(process, tier, content): ), ) ) - print getattr(process,moduleName) + print(getattr(process,moduleName)) # put it in an EndPath and put the EndPath into the schedule setattr(process, pathName, cms.EndPath(getattr(process,moduleName)) ) process.schedule.append(getattr(process, pathName)) diff --git a/configs/SpecialRequests2013/14jun-MatrixReader.py b/configs/SpecialRequests2013/14jun-MatrixReader.py index e087ae7..ff1d4ac 100644 --- a/configs/SpecialRequests2013/14jun-MatrixReader.py +++ b/configs/SpecialRequests2013/14jun-MatrixReader.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys @@ -86,16 +87,16 @@ def readMatrix(self, fileNameIn, useInput=None, refRel=None, fromScratch=None): prefix = self.filesPrefMap[fileNameIn] - print "processing ", fileNameIn + print("processing ", fileNameIn) try: _tmpMod = __import__( 'Configuration.PyReleaseValidation.'+fileNameIn ) self.relvalModule = sys.modules['Configuration.PyReleaseValidation.'+fileNameIn] - except Exception, e: - print "ERROR importing file ", fileNameIn, str(e) + except Exception as e: + print("ERROR importing file ", fileNameIn, str(e)) return - print "request for INPUT for ", useInput + print("request for INPUT for ", useInput) fromInput={} @@ -269,13 +270,13 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= self.reset(what) if self.what != 'all' and self.what not in matrixFile: - print "ignoring non-requested file",matrixFile + print("ignoring non-requested file",matrixFile) continue try: self.readMatrix(matrixFile, useInput, refRel, fromScratch) - except Exception, e: - print "ERROR reading file:", matrixFile, str(e) + except Exception as e: + print("ERROR reading file:", matrixFile, str(e)) raise if not self.workFlowSteps: continue @@ -283,7 +284,7 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= dataFileName = matrixFile.replace('relval_', 'cmsDriver_')+'_hlt.txt' outFile = open(dataFileName,'w') - print "found ", len(self.workFlowSteps.keys()), ' workflows for ', dataFileName + print("found ", len(self.workFlowSteps.keys()), ' workflows for ', dataFileName) ids = self.workFlowSteps.keys() ids.sort() indexAndSteps=[] @@ -355,7 +356,7 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= outFile.write(line+'\n') outFile.write('\n'+'\n') outFile.close() - print "wrote ",writtenWF, ' workflow'+('s' if (writtenWF!=1) else ''),' to ', outFile.name + print("wrote ",writtenWF, ' workflow'+('s' if (writtenWF!=1) else ''),' to ', outFile.name) return @@ -364,9 +365,9 @@ def showWorkFlows(self, selected=None, extended=True): maxLen = 100 # for summary, limit width of output fmt1 = "%-6s %-35s [1]: %s ..." fmt2 = " %35s [%d]: %s ..." - print "\nfound a total of ", len(self.workFlows), ' workflows:' + print("\nfound a total of ", len(self.workFlows), ' workflows:') if selected: - print " of which the following", len(selected), 'were selected:' + print(" of which the following", len(selected), 'were selected:') #-ap for now: maxLen = -1 # for individual listing, no limit on width fmt1 = "%-6s %-35s [1]: %s " @@ -375,7 +376,7 @@ def showWorkFlows(self, selected=None, extended=True): N=[] for wf in self.workFlows: if selected and float(wf.numId) not in selected: continue - if extended: print '' + if extended: print('') #pad with zeros for i in range(len(N),len(wf.cmds)): N.append(0) N[len(wf.cmds)-1]+=1 @@ -383,15 +384,15 @@ def showWorkFlows(self, selected=None, extended=True): for i,s in enumerate(wf.cmds): if extended: if i==0: - print fmt1 % (wf.numId, stepNames, (str(s)+' ')[:maxLen]) + print(fmt1 % (wf.numId, stepNames, (str(s)+' ')[:maxLen])) else: - print fmt2 % ( ' ', i+1, (str(s)+' ')[:maxLen]) + print(fmt2 % ( ' ', i+1, (str(s)+' ')[:maxLen])) else: - print "%-6s %-35s "% (wf.numId, stepNames) + print("%-6s %-35s "% (wf.numId, stepNames)) break - print '' + print('') for i,n in enumerate(N): - if n: print n,'workflows with',i+1,'steps' + if n: print(n,'workflows with',i+1,'steps') return @@ -412,9 +413,9 @@ def createWorkFlows(self, fileNameIn): num, name, commands, stepList = val nameId = str(num)+'_'+name if nameId in self.nameList: - print "==> duplicate name found for ", nameId - print ' keeping : ', self.nameList[nameId] - print ' ignoring : ', val + print("==> duplicate name found for ", nameId) + print(' keeping : ', self.nameList[nameId]) + print(' ignoring : ', val) else: self.nameList[nameId] = val @@ -426,29 +427,29 @@ def prepare(self, useInput=None, refRel='', fromScratch=None): for matrixFile in self.files: if self.what != 'all' and self.what not in matrixFile: - print "ignoring non-requested file",matrixFile + print("ignoring non-requested file",matrixFile) continue if self.what == 'all' and ('upgrade' in matrixFile): - print "ignoring",matrixFile,"from default matrix" + print("ignoring",matrixFile,"from default matrix") continue try: self.readMatrix(matrixFile, useInput, refRel, fromScratch) - except Exception, e: - print "ERROR reading file:", matrixFile, str(e) + except Exception as e: + print("ERROR reading file:", matrixFile, str(e)) raise try: self.createWorkFlows(matrixFile) - except Exception, e: - print "ERROR creating workflows :", str(e) + except Exception as e: + print("ERROR creating workflows :", str(e)) raise def show(self, selected=None, extended=True): self.showWorkFlows(selected,extended) - print '\n','-'*80,'\n' + print('\n','-'*80,'\n') def updateDB(self): diff --git a/configs/SpecialRequests2013/14jun-relval_steps.py b/configs/SpecialRequests2013/14jun-relval_steps.py index 5aa9401..bd87085 100644 --- a/configs/SpecialRequests2013/14jun-relval_steps.py +++ b/configs/SpecialRequests2013/14jun-relval_steps.py @@ -1,3 +1,4 @@ +from __future__ import print_function class InputInfo(object): def __init__(self,label,dataSet,run=0,files=1000,events=2000000,location='CAF') : @@ -29,13 +30,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item @@ -534,7 +535,7 @@ def updateme(aDict, anotherOne): if not new_key in aDict: aDict[new_key] = anotherOne[new_key] else: - print "Redefininig %s ? ==> no"%(new_key) + print("Redefininig %s ? ==> no"%(new_key)) updateme(steps,step1) updateme(steps,step2) diff --git a/configs/SpecialRequests2013/16jul_Mixing.py b/configs/SpecialRequests2013/16jul_Mixing.py index f74971e..923b09a 100644 --- a/configs/SpecialRequests2013/16jul_Mixing.py +++ b/configs/SpecialRequests2013/16jul_Mixing.py @@ -1,10 +1,11 @@ +from __future__ import print_function Mixing = {} def addMixingScenario(label,dict): global Mixing if label in Mixing: - print 'duplicated definition of',label + print('duplicated definition of',label) else: #try: # m=__import__(dict['file']) @@ -113,10 +114,10 @@ def printMe(): if '_FS' in key: fskeys.append(key) else: - print 'addMixingScenario("%s",%s)'%(key,repr(Mixing[key])) + print('addMixingScenario("%s",%s)'%(key,repr(Mixing[key]))) for key in fskeys: - print 'addMixingScenario("%s",%s)'%(key,repr(Mixing[key])) + print('addMixingScenario("%s",%s)'%(key,repr(Mixing[key]))) def defineMixing(dict,FS=False): diff --git a/configs/SpecialRequests2013/16jul_relval_steps.py b/configs/SpecialRequests2013/16jul_relval_steps.py index 67e28fc..d4aaa14 100644 --- a/configs/SpecialRequests2013/16jul_relval_steps.py +++ b/configs/SpecialRequests2013/16jul_relval_steps.py @@ -1,3 +1,4 @@ +from __future__ import print_function InputInfoNDefault=2000000 class InputInfo(object): @@ -33,13 +34,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/17jul_relval_steps.py b/configs/SpecialRequests2013/17jul_relval_steps.py index 1ff4d31..d9e7bea 100644 --- a/configs/SpecialRequests2013/17jul_relval_steps.py +++ b/configs/SpecialRequests2013/17jul_relval_steps.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -15,8 +16,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -26,7 +27,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -85,13 +86,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/9jul-relval_steps.py b/configs/SpecialRequests2013/9jul-relval_steps.py index 7fae1e9..7a0b073 100644 --- a/configs/SpecialRequests2013/9jul-relval_steps.py +++ b/configs/SpecialRequests2013/9jul-relval_steps.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -15,8 +16,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -26,7 +27,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -85,13 +86,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/Aug13_ConfigBuilder.py b/configs/SpecialRequests2013/Aug13_ConfigBuilder.py index 573a736..22a7f5d 100644 --- a/configs/SpecialRequests2013/Aug13_ConfigBuilder.py +++ b/configs/SpecialRequests2013/Aug13_ConfigBuilder.py @@ -1,5 +1,6 @@ #! /usr/bin/env python +from __future__ import print_function __version__ = "$Revision: 1.381.2.28 $" __source__ = "$Source: /local/reps/CMSSW/CMSSW/Configuration/PyReleaseValidation/python/ConfigBuilder.py,v $" @@ -104,9 +105,9 @@ def filesFromList(fileName,s=None): s.secondaryFileNames=cms.untracked.vstring(sec) else: s.secondaryFileNames.extend(sec) - print "found files: ",prim + print("found files: ",prim) if len(sec)!=0: - print "found parent files:",sec + print("found parent files:",sec) return (prim,sec) def filesFromDBSQuery(query,s=None): @@ -114,7 +115,7 @@ def filesFromDBSQuery(query,s=None): import FWCore.ParameterSet.Config as cms prim=[] sec=[] - print "the query is",query + print("the query is",query) for line in os.popen('dbs search --query "%s"'%(query)): if line.count(".root")>=2: #two files solution... @@ -137,9 +138,9 @@ def filesFromDBSQuery(query,s=None): s.secondaryFileNames=cms.untracked.vstring(sec) else: s.secondaryFileNames.extend(sec) - print "found files: ",prim + print("found files: ",prim) if len(sec)!=0: - print "found parent files:",sec + print("found parent files:",sec) return (prim,sec) def MassReplaceInputTag(aProcess,oldT="rawDataCollector",newT="rawDataRepacker"): @@ -319,7 +320,7 @@ def addSource(self): def filesFromOption(self): for entry in self._options.filein.split(','): - print "entry",entry + print("entry",entry) if entry.startswith("filelist:"): filesFromList(entry[9:],self.process.source) elif entry.startswith("dbs:"): @@ -330,7 +331,7 @@ def filesFromOption(self): if not hasattr(self.process.source,"secondaryFileNames"): raise Exception("--secondfilein not compatible with "+self._options.filetype+"input type") for entry in self._options.secondfilein.split(','): - print "entry",entry + print("entry",entry) if entry.startswith("filelist:"): self.process.source.secondaryFileNames.extend((filesFromList(entry[9:]))[0]) elif entry.startswith("dbs:"): @@ -353,7 +354,7 @@ def filesFromOption(self): #list the article directory automatically args=self._options.filein.split(':') article=args[1] - print 'LHE input from article ',article + print('LHE input from article ',article) location='/store/lhe/' import os textOfFiles=os.popen('cmsLHEtoEOSManager.py -l '+article) @@ -431,7 +432,7 @@ def addOutput(self): result="" if self._options.outputDefinition: if self._options.datatier: - print "--datatier & --eventcontent options ignored" + print("--datatier & --eventcontent options ignored") def anyOf(listOfKeys,dict,opt=None): for k in listOfKeys: @@ -607,7 +608,7 @@ def addStandardSequences(self): if 'file:' in pileupSpec: #the file is local self.process.load(mixingDict['file']) - print "inlining mixing module configuration" + print("inlining mixing module configuration") self._options.inlineObjets+=',mix' else: self.loadAndRemember(mixingDict['file']) @@ -634,7 +635,7 @@ def addStandardSequences(self): if self.geometryDBLabel: self.executeAndRemember('process.XMLFromDBSource.label = cms.string("%s")'%(self.geometryDBLabel)) except ImportError: - print "Geometry option",self._options.geometry,"unknown." + print("Geometry option",self._options.geometry,"unknown.") raise if len(self.stepMap): @@ -643,7 +644,7 @@ def addStandardSequences(self): for stepName in self.stepKeys: stepSpec = self.stepMap[stepName] - print "Step:", stepName,"Spec:",stepSpec + print("Step:", stepName,"Spec:",stepSpec) if stepName.startswith('re'): ##add the corresponding input content if stepName[2:] not in self._options.donotDropOnInput: @@ -714,7 +715,7 @@ def addConditions(self): if not self._options.conditions: return if 'FrontierConditions_GlobalTag' in self._options.conditions: - print 'using FrontierConditions_GlobalTag in --conditions is not necessary anymore and will be deprecated soon. please update your command line' + print('using FrontierConditions_GlobalTag in --conditions is not necessary anymore and will be deprecated soon. please update your command line') self._options.conditions = self._options.conditions.replace("FrontierConditions_GlobalTag,",'') self.loadAndRemember(self.ConditionsDefaultCFF) @@ -778,7 +779,7 @@ def addCustomise(self): else: final_snippet += 'from %s import %s \n'%(packageName,','.join(custMap[f])) for fcn in custMap[f]: - print "customising the process with",fcn,"from",f + print("customising the process with",fcn,"from",f) if not hasattr(package,fcn): #bound to fail at run time raise Exception("config "+f+" has no function "+fcn) @@ -810,8 +811,8 @@ def define_Configs(self): if len(self.stepMap): self.loadAndRemember('Configuration/StandardSequences/Services_cff') if self._options.particleTable not in defaultOptions.particleTableList: - print 'Invalid particle table provided. Options are:' - print defaultOptions.particleTable + print('Invalid particle table provided. Options are:') + print(defaultOptions.particleTable) sys.exit(-1) else: if len(self.stepMap): @@ -914,7 +915,7 @@ def define_Configs(self): self.DQMDefaultSeq='DQMOfflineCosmics' if self._options.himix: - print "From the presence of the himix option, we have determined that this is heavy ions and will use '--scenario HeavyIons'." + print("From the presence of the himix option, we have determined that this is heavy ions and will use '--scenario HeavyIons'.") self._options.scenario='HeavyIons' if self._options.scenario=='HeavyIons': @@ -947,7 +948,7 @@ def define_Configs(self): # the magnetic field if self._options.isData: if self._options.magField==defaultOptions.magField: - print "magnetic field option forced to: AutoFromDBCurrent" + print("magnetic field option forced to: AutoFromDBCurrent") self._options.magField='AutoFromDBCurrent' self.magFieldCFF = 'Configuration/StandardSequences/MagneticField_'+self._options.magField.replace('.','')+'_cff' self.magFieldCFF = self.magFieldCFF.replace("__",'_') @@ -981,7 +982,7 @@ def inGeometryKeys(opt): if (geoms[0].startswith('DB:')): self.SimGeometryCFF='Configuration/StandardSequences/GeometrySimDB_cff' self.geometryDBLabel=geoms[0][3:] - print "with DB:" + print("with DB:") else: if '/' in geoms[0] or '_cff' in geoms[0]: self.SimGeometryCFF=geoms[0] @@ -997,7 +998,7 @@ def inGeometryKeys(opt): self.SIMDefaultCFF="Configuration/StandardSequences/SimIdeal_cff" if self._options.scenario=='nocoll' or self._options.scenario=='cosmics': - print simGeometry + print(simGeometry) self.SIMDefaultCFF="Configuration/StandardSequences/SimNOBEAM_cff" self._options.beamspot='NoSmear' @@ -1102,8 +1103,8 @@ def loadDefaultOrSpecifiedCFF(self, sequence,defaultCFF): l=self.loadAndRemember(sequence.split('.')[0]) sequence=sequence.split('.')[1] else: - print "sub sequence configuration must be of the form dir/subdir/cff.a+b+c or cff.a" - print sequence,"not recognized" + print("sub sequence configuration must be of the form dir/subdir/cff.a+b+c or cff.a") + print(sequence,"not recognized") raise return l @@ -1195,8 +1196,8 @@ def prepare_ALCA(self, sequence = None, workflow = 'full'): alcastream = getattr(alcaConfig,name) if isinstance(alcastream,cms.FilteredStream): available.append(name.replace('ALCARECOStream','')) - print "The following alcas could not be found "+str(alcaList) - print "available ",available + print("The following alcas could not be found "+str(alcaList)) + print("available ",available) #print "verify your configuration, ignoring for now" raise Exception("The following alcas could not be found "+str(alcaList)) @@ -1204,7 +1205,7 @@ def prepare_LHE(self, sequence = None): #load the fragment ##make it loadable loadFragment = self._options.evt_type.replace('.py','',).replace('.','_').replace('python/','').replace('/','.') - print "Loading lhe fragment from",loadFragment + print("Loading lhe fragment from",loadFragment) __import__(loadFragment) self.process.load(loadFragment) ##inline the modules @@ -1229,7 +1230,7 @@ def prepare_GEN(self, sequence = None): else: loadFragment=loadFragment.replace('/','.') try: - print "Loading generator fragment from",loadFragment + print("Loading generator fragment from",loadFragment) __import__(loadFragment) except: loadFailure=True @@ -1361,7 +1362,7 @@ def prepare_L1(self, sequence = None): def prepare_L1REPACK(self, sequence = None): """ Enrich the schedule with the L1 simulation step, running the L1 emulator on data unpacked from the RAW collection, and repacking the result in a new RAW collection""" if sequence is not 'GT': - print 'Running the full L1 emulator is not supported yet' + print('Running the full L1 emulator is not supported yet') raise Exception('unsupported feature') if sequence is 'GT': self.loadAndRemember('Configuration/StandardSequences/SimL1EmulatorRepack_GT_cff') @@ -1373,7 +1374,7 @@ def prepare_L1REPACK(self, sequence = None): def prepare_HLT(self, sequence = None): """ Enrich the schedule with the HLT simulation step""" if not sequence: - print "no specification of the hlt menu has been given, should never happen" + print("no specification of the hlt menu has been given, should never happen") raise Exception('no HLT sequence provided') if '@' in sequence: @@ -1441,7 +1442,7 @@ def prepare_RAW2RECO(self, sequence = None): seqReco=sequence.split(',')[1] seqDigi=sequence.split(',')[0] else: - print "RAW2RECO requires two specifications",sequence,"insufficient" + print("RAW2RECO requires two specifications",sequence,"insufficient") self.prepare_RAW2DIGI(seqDigi) self.prepare_RECO(seqReco) @@ -1458,7 +1459,7 @@ def prepare_L1HwVal(self, sequence = 'L1HwVal'): ''' Enrich the schedule with L1 HW validation ''' self.loadDefaultOrSpecifiedCFF(sequence,self.L1HwValDefaultCFF) #self.scheduleSequence(sequence.split('.')[-1],'l1hwval_step') - print '\n\n\n DEPRECATED this has no action \n\n\n' + print('\n\n\n DEPRECATED this has no action \n\n\n') return def prepare_L1Reco(self, sequence = "L1Reco"): @@ -1546,7 +1547,7 @@ def prepare_SKIM(self, sequence = "all"): if (skimlist.__len__()!=0 and sequence!="all"): - print 'WARNING, possible typo with SKIM:'+'+'.join(skimlist) + print('WARNING, possible typo with SKIM:'+'+'.join(skimlist)) raise Exception('WARNING, possible typo with SKIM:'+'+'.join(skimlist)) def prepare_USER(self, sequence = None): @@ -1631,7 +1632,7 @@ def doIt(self,pset,base): for (i,ps) in enumerate(value): self.doIt(ps, "%s.%s[%d]"%(base,name,i) ) elif type in ('cms.string', 'cms.untracked.string'): if value.value() == self._paramSearch: - if self._verbose: print "set string process name %s.%s %s ==> %s"% (base, name, value, self._paramReplace) + if self._verbose: print("set string process name %s.%s %s ==> %s"% (base, name, value, self._paramReplace)) setattr(pset, name,self._paramReplace) elif type in ('cms.VInputTag', 'cms.untracked.VInputTag'): for (i,n) in enumerate(value): @@ -1639,7 +1640,7 @@ def doIt(self,pset,base): n=cms.InputTag(n) if n.processName == self._paramSearch: # VInputTag can be declared as a list of strings, so ensure that n is formatted correctly - if self._verbose:print "set process name %s.%s[%d] %s ==> %s " % (base, name, i, n, self._paramReplace) + if self._verbose:print("set process name %s.%s[%d] %s ==> %s " % (base, name, i, n, self._paramReplace)) setattr(n,"processName",self._paramReplace) value[i]=n elif type in ('cms.vstring', 'cms.untracked.vstring'): @@ -1648,7 +1649,7 @@ def doIt(self,pset,base): getattr(pset,name)[i]=self._paramReplace elif type in ('cms.InputTag', 'cms.untracked.InputTag'): if value.processName == self._paramSearch: - if self._verbose: print "set process name %s.%s %s ==> %s " % (base, name, value, self._paramReplace) + if self._verbose: print("set process name %s.%s %s ==> %s " % (base, name, value, self._paramReplace)) setattr(getattr(pset, name),"processName",self._paramReplace) def enter(self,visitee): @@ -1666,7 +1667,7 @@ def leave(self,visitee): #visit a sequence to repalce all input tags def renameInputTagsInSequence(self,sequence,oldT="rawDataCollector",newT="rawDataRepacker"): - print "Replacing all InputTag %s => %s"%(oldT,newT) + print("Replacing all InputTag %s => %s"%(oldT,newT)) from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag massSearchReplaceAnyInputTag(getattr(self.process,sequence),oldT,newT) loadMe='from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag' @@ -1682,7 +1683,7 @@ def renameHLTprocessInSequence(self,sequence,proc=None,HLTprocess='HLT'): proc=self.process.name_() if proc==HLTprocess: return # look up all module in dqm sequence - print "replacing %s process name - sequence %s will use '%s'" % (HLTprocess,sequence, proc) + print("replacing %s process name - sequence %s will use '%s'" % (HLTprocess,sequence, proc)) getattr(self.process,sequence).visit(ConfigBuilder.MassSearchReplaceProcessNameVisitor(HLTprocess,proc,whitelist = ("subSystemFolder",))) if 'from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder' not in self.additionalCommands: self.additionalCommands.append('from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder') @@ -1718,7 +1719,7 @@ def prepare_DQM(self, sequence = 'DQMOffline'): if len(set(sequenceList))!=len(sequenceList): sequenceList=list(set(sequenceList)) - print "Duplicate entries for DQM:, using",sequenceList + print("Duplicate entries for DQM:, using",sequenceList) pathName='dqmoffline_step' for (i,sequence) in enumerate(sequenceList): @@ -1757,11 +1758,11 @@ def prepare_HARVESTING(self, sequence = None): if len(set(harvestingList))!=len(harvestingList): harvestingList=list(set(harvestingList)) - print "Duplicate entries for HARVESTING, using",harvestingList + print("Duplicate entries for HARVESTING, using",harvestingList) for name in harvestingList: if not name in harvestingConfig.__dict__: - print name,"is not a possible harvesting type. Available are",harvestingConfig.__dict__.keys() + print(name,"is not a possible harvesting type. Available are",harvestingConfig.__dict__.keys()) continue harvestingstream = getattr(harvestingConfig,name) if isinstance(harvestingstream,cms.Path): @@ -1793,7 +1794,7 @@ def prepare_ALCAHARVEST(self, sequence = None): self.schedule.append(lastStep) if len(harvestingList) != 0 and 'dummyHarvesting' not in harvestingList : - print "The following harvesting could not be found : ", harvestingList + print("The following harvesting could not be found : ", harvestingList) raise Exception("The following harvesting could not be found : "+str(harvestingList)) @@ -1834,7 +1835,7 @@ def prepare_FASTSIM(self, sequence = "all"): # now the additional commands we need to make the config work self.executeAndRemember("process.VolumeBasedMagneticFieldESProducer.useParametrizedTrackerField = True") else: - print "FastSim setting", sequence, "unknown." + print("FastSim setting", sequence, "unknown.") raise ValueError if 'Flat' in self._options.beamspot: @@ -1932,7 +1933,7 @@ def prepare(self, doChecking = False): if not object: continue if not hasattr(self.process,object): - print 'cannot inline -'+object+'- : not known' + print('cannot inline -'+object+'- : not known') else: self.pythonCfgCode +='\n' self.pythonCfgCode +=dumpPython(self.process,object) @@ -2073,7 +2074,7 @@ def addOutputModule(process, tier, content): Function to add an output module to a given process with given data tier and event content """ - print "WARNING. this method will not be supported any more SOON, please use --eventcontent --datatier field to drive the output module definitions" + print("WARNING. this method will not be supported any more SOON, please use --eventcontent --datatier field to drive the output module definitions") moduleName = "output%s%s" % (tier, content) pathName = "%sPath" % moduleName @@ -2088,7 +2089,7 @@ def addOutputModule(process, tier, content): ), ) ) - print getattr(process,moduleName) + print(getattr(process,moduleName)) # put it in an EndPath and put the EndPath into the schedule setattr(process, pathName, cms.EndPath(getattr(process,moduleName)) ) process.schedule.append(getattr(process, pathName)) diff --git a/configs/SpecialRequests2013/Aug13_relval_steps.py b/configs/SpecialRequests2013/Aug13_relval_steps.py index c1b7a72..f57ee47 100644 --- a/configs/SpecialRequests2013/Aug13_relval_steps.py +++ b/configs/SpecialRequests2013/Aug13_relval_steps.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -15,8 +16,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -26,7 +27,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -87,13 +88,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/CMSSW_5_3_7_patch5_Battilana_taskForce_ZeroBias.py b/configs/SpecialRequests2013/CMSSW_5_3_7_patch5_Battilana_taskForce_ZeroBias.py index 74e55d8..85e988f 100644 --- a/configs/SpecialRequests2013/CMSSW_5_3_7_patch5_Battilana_taskForce_ZeroBias.py +++ b/configs/SpecialRequests2013/CMSSW_5_3_7_patch5_Battilana_taskForce_ZeroBias.py @@ -1,3 +1,4 @@ +from __future__ import print_function # Auto generated configuration file # using: # Revision: 1.381.2.13 @@ -119,8 +120,8 @@ def customiseCosmicMC(process): ############################################################################## def customiseVALSKIM(process): - print "WARNING" - print "this method is outdated, please use RecoTLR.customisePPData" + print("WARNING") + print("this method is outdated, please use RecoTLR.customisePPData") process= customisePPData(process) return process diff --git a/configs/SpecialRequests2013/CMSSW_5_3_7_patch5_Battilana_taskForce_ZeroBias_RECOOUTOUT.py b/configs/SpecialRequests2013/CMSSW_5_3_7_patch5_Battilana_taskForce_ZeroBias_RECOOUTOUT.py index 49df5e7..73ea514 100644 --- a/configs/SpecialRequests2013/CMSSW_5_3_7_patch5_Battilana_taskForce_ZeroBias_RECOOUTOUT.py +++ b/configs/SpecialRequests2013/CMSSW_5_3_7_patch5_Battilana_taskForce_ZeroBias_RECOOUTOUT.py @@ -1,3 +1,4 @@ +from __future__ import print_function # Auto generated configuration file # using: # Revision: 1.381.2.13 @@ -131,8 +132,8 @@ def customiseCosmicMC(process): ############################################################################## def customiseVALSKIM(process): - print "WARNING" - print "this method is outdated, please use RecoTLR.customisePPData" + print("WARNING") + print("this method is outdated, please use RecoTLR.customisePPData") process= customisePPData(process) return process diff --git a/configs/SpecialRequests2013/ConfigBuilder_24june.py b/configs/SpecialRequests2013/ConfigBuilder_24june.py index 17c0d6c..e594ca4 100644 --- a/configs/SpecialRequests2013/ConfigBuilder_24june.py +++ b/configs/SpecialRequests2013/ConfigBuilder_24june.py @@ -1,5 +1,6 @@ #! /usr/bin/env python +from __future__ import print_function __version__ = "$Revision: 1.303.2.11 $" __source__ = "$Source: /local/reps/CMSSW/CMSSW/Configuration/PyReleaseValidation/python/ConfigBuilder.py,v $" @@ -90,9 +91,9 @@ def filesFromList(fileName,s=None): s.secondaryFileNames=cms.untracked.vstring(sec) else: s.secondaryFileNames.extend(sec) - print "found files: ",prim + print("found files: ",prim) if len(sec)!=0: - print "found parent files:",sec + print("found parent files:",sec) return (prim,sec) def filesFromDBSQuery(query,s=None): @@ -100,7 +101,7 @@ def filesFromDBSQuery(query,s=None): import FWCore.ParameterSet.Config as cms prim=[] sec=[] - print "the query is",query + print("the query is",query) for line in os.popen('dbs search --query "%s"'%(query)): if line.count(".root")>=2: #two files solution... @@ -123,9 +124,9 @@ def filesFromDBSQuery(query,s=None): s.secondaryFileNames=cms.untracked.vstring(sec) else: s.secondaryFileNames.extend(sec) - print "found files: ",prim + print("found files: ",prim) if len(sec)!=0: - print "found parent files:",sec + print("found parent files:",sec) return (prim,sec) @@ -235,7 +236,7 @@ def addSource(self): def filesFromOption(self): for entry in self._options.filein.split(','): - print "entry",entry + print("entry",entry) if entry.startswith("filelist:"): filesFromList(entry[9:],self.process.source) elif entry.startswith("dbs:"): @@ -246,7 +247,7 @@ def filesFromOption(self): if not hasattr(self.process.source,"secondaryFileNames"): raise Exception("--secondfilein not compatible with "+self._options.filetype+"input type") for entry in self._options.secondfilein.split(','): - print "entry",entry + print("entry",entry) if entry.startswith("filelist:"): self.process.source.secondaryFileNames.extend((filesFromList(entry[9:]))[0]) elif entry.startswith("dbs:"): @@ -263,7 +264,7 @@ def filesFromOption(self): self.process.source=cms.Source("LHESource", fileNames = cms.untracked.vstring()) #provided by article number if self._options.filein.startswith("lhe:"): - print 'LHE input from article',self._options.filein + print('LHE input from article',self._options.filein) #list the article directory automatically args=self._options.filein.split(':') article=args[1] @@ -285,7 +286,7 @@ def filesFromOption(self): if self._options.dbsquery!='': self.process.source=cms.Source("PoolSource", fileNames = cms.untracked.vstring(),secondaryFileNames = cms.untracked.vstring()) import os - print "the query is",self._options.dbsquery + print("the query is",self._options.dbsquery) for line in os.popen('dbs search --query "%s"'%(self._options.dbsquery,)): if line.count(".root")>=2: #two files solution... @@ -299,9 +300,9 @@ def filesFromOption(self): entry=line.replace("\n","") if not entry in self.process.source.fileNames.value(): self.process.source.fileNames.append(entry) - print "found files: ",self.process.source.fileNames.value() + print("found files: ",self.process.source.fileNames.value()) if self.process.source.secondaryFileNames.__len__()!=0: - print "found parent files:",self.process.source.secondaryFileNames.value() + print("found parent files:",self.process.source.secondaryFileNames.value()) if self._options.inputCommands: self.process.source.inputCommands = cms.untracked.vstring() @@ -337,7 +338,7 @@ def addOutput(self): raise Exception("number of event content arguments does not match number of datatier arguments") if self._options.outputDefinition: if self._options.datatier: - print "--datatier & --eventcontent options ignored" + print("--datatier & --eventcontent options ignored") def anyOf(listOfKeys,dict,opt=None): for k in listOfKeys: @@ -502,7 +503,7 @@ def addStandardSequences(self): try: self.loadAndRemember(self.GeometryCFF) except ImportError: - print "Geometry option",self._options.geometry,"unknown." + print("Geometry option",self._options.geometry,"unknown.") raise self.loadAndRemember(self.magFieldCFF) @@ -518,7 +519,7 @@ def addStandardSequences(self): for step in self._options.step.split(","): if step == "": continue - print step + print(step) stepParts = step.split(":") # for format STEP:alternativeSequence stepName = stepParts[0] if stepName not in stepList: @@ -591,7 +592,7 @@ def addConditions(self): if i<2: untracked='' else: untracked='untracked.' payloadSpecToAppend+='%s=cms.%sstring("%s"),'%(item,untracked,payloadSpec[item]) - print 'customising the GlogalTag with:',payloadSpecToAppend + print('customising the GlogalTag with:',payloadSpecToAppend) self.executeAndRemember('process.GlobalTag.toGet.append(cms.PSet(%s))'%(payloadSpecToAppend,)) @@ -644,7 +645,7 @@ def addCustomise(self): else: final_snippet += 'from %s import %s \n'%(packageName,','.join(custMap[f])) for fcn in custMap[f]: - print "customising the process with",fcn,"from",f + print("customising the process with",fcn,"from",f) if not hasattr(package,fcn): #bound to fail at run time raise Exception("config "+f+" has no function "+fcn) @@ -661,14 +662,14 @@ def addCustomise(self): #---------------------------------------------------------------------------- def define_Configs(self): if ( self._options.scenario not in defaultOptions.scenarioOptions): - print 'Invalid scenario provided. Options are:' - print defaultOptions.scenarioOptions + print('Invalid scenario provided. Options are:') + print(defaultOptions.scenarioOptions) sys.exit(-1) self.loadAndRemember('Configuration/StandardSequences/Services_cff') if self._options.particleTable not in defaultOptions.particleTableList: - print 'Invalid particle table provided. Options are:' - print defaultOptions.particleTable + print('Invalid particle table provided. Options are:') + print(defaultOptions.particleTable) sys.exit(-1) else: self.loadAndRemember('SimGeneral.HepPDTESSource.'+self._options.particleTable+'_cfi') @@ -772,7 +773,7 @@ def define_Configs(self): self.eventcontent='FEVT' if self._options.himix: - print "From the presence of the himix option, we have determined that this is heavy ions and will use '--scenario HeavyIons'." + print("From the presence of the himix option, we have determined that this is heavy ions and will use '--scenario HeavyIons'.") self._options.scenario='HeavyIons' if self._options.scenario=='HeavyIons': @@ -906,8 +907,8 @@ def loadDefaultOrSpecifiedCFF(self, sequence,defaultCFF): l=self.loadAndRemember(sequence.split('.')[0]) sequence=sequence.split('.')[1] else: - print "sub sequence configuration must be of the form dir/subdir/cff.a+b+c or cff.a" - print sequence,"not recognized" + print("sub sequence configuration must be of the form dir/subdir/cff.a+b+c or cff.a") + print(sequence,"not recognized") raise return l @@ -1003,8 +1004,8 @@ def prepare_ALCA(self, sequence = None, workflow = 'full'): alcastream = getattr(alcaConfig,name) if isinstance(alcastream,cms.FilteredStream): available.append(name.replace('ALCARECOStream','')) - print "The following alcas could not be found "+str(alcaList) - print "available ",available + print("The following alcas could not be found "+str(alcaList)) + print("available ",available) #print "verify your configuration, ignoring for now" raise Exception("The following alcas could not be found "+str(alcaList)) @@ -1146,7 +1147,7 @@ def prepare_HLT(self, sequence = None): fastSim=True loadDir='FastSimulation' if not sequence: - print "no specification of the hlt menu has been given, should never happen" + print("no specification of the hlt menu has been given, should never happen") raise Exception('no HLT sequence provided') else: if ',' in sequence: @@ -1175,7 +1176,7 @@ def prepare_RAW2RECO(self, sequence = None): seqReco=sequence.split(',')[1] seqDigi=sequence.split(',')[0] else: - print "RAW2RECO requires two specifications",sequence,"insufficient" + print("RAW2RECO requires two specifications",sequence,"insufficient") self.prepare_RAW2DIGI(seqDigi) self.prepare_RECO(seqReco) @@ -1251,7 +1252,7 @@ def prepare_SKIM(self, sequence = "all"): if (skimlist.__len__()!=0 and sequence!="all"): - print 'WARNING, possible typo with SKIM:'+'+'.join(skimlist) + print('WARNING, possible typo with SKIM:'+'+'.join(skimlist)) raise Exception('WARNING, possible typo with SKIM:'+'+'.join(skimlist)) def prepare_POSTRECO(self, sequence = None): @@ -1327,7 +1328,7 @@ def doIt(self,pset,base): for (i,ps) in enumerate(value): self.doIt(ps, "%s.%s[%d]"%(base,name,i) ) elif type in ('cms.string', 'cms.untracked.string'): if value.value() == self._paramSearch: - if self._verbose: print "set string process name %s.%s %s ==> %s"% (base, name, value, self._paramReplace) + if self._verbose: print("set string process name %s.%s %s ==> %s"% (base, name, value, self._paramReplace)) setattr(pset, name,self._paramReplace) elif type in ('cms.VInputTag', 'cms.untracked.VInputTag'): for (i,n) in enumerate(value): @@ -1335,7 +1336,7 @@ def doIt(self,pset,base): n=cms.InputTag(n) if n.processName == self._paramSearch: # VInputTag can be declared as a list of strings, so ensure that n is formatted correctly - if self._verbose:print "set process name %s.%s[%d] %s ==> %s " % (base, name, i, n, self._paramReplace) + if self._verbose:print("set process name %s.%s[%d] %s ==> %s " % (base, name, i, n, self._paramReplace)) setattr(n,"processName",self._paramReplace) value[i]=n elif type in ('cms.vstring', 'cms.untracked.vstring'): @@ -1344,7 +1345,7 @@ def doIt(self,pset,base): getattr(pset,name)[i]=self._paramReplace elif type in ('cms.InputTag', 'cms.untracked.InputTag'): if value.processName == self._paramSearch: - if self._verbose: print "set process name %s.%s %s ==> %s " % (base, name, value, self._paramReplace) + if self._verbose: print("set process name %s.%s %s ==> %s " % (base, name, value, self._paramReplace)) setattr(getattr(pset, name),"processName",self._paramReplace) def enter(self,visitee): @@ -1368,7 +1369,7 @@ def renameHLTprocessInSequence(self,sequence,proc=None,HLTprocess='HLT'): proc=self.process.name_() if proc==HLTprocess: return # look up all module in dqm sequence - print "replacing %s process name - sequence %s will use '%s'" % (HLTprocess,sequence, proc) + print("replacing %s process name - sequence %s will use '%s'" % (HLTprocess,sequence, proc)) getattr(self.process,sequence).visit(ConfigBuilder.MassSearchReplaceProcessNameVisitor(HLTprocess,proc,whitelist = ("subSystemFolder",))) if 'from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder' not in self.additionalCommands: self.additionalCommands.append('from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder') @@ -1422,7 +1423,7 @@ def prepare_HARVESTING(self, sequence = None): harvestingList.remove('alcaHarvesting') if len(harvestingList) != 0 and 'dummyHarvesting' not in harvestingList : - print "The following harvesting could not be found : ", harvestingList + print("The following harvesting could not be found : ", harvestingList) raise self.scheduleSequence('DQMSaver','dqmsave_step') @@ -1447,7 +1448,7 @@ def prepare_ALCAHARVEST(self, sequence = None): self.schedule.append(lastStep) if len(harvestingList) != 0 and 'dummyHarvesting' not in harvestingList : - print "The following harvesting could not be found : ", harvestingList + print("The following harvesting could not be found : ", harvestingList) raise @@ -1488,7 +1489,7 @@ def prepare_FASTSIM(self, sequence = "all"): # now the additional commands we need to make the config work self.executeAndRemember("process.VolumeBasedMagneticFieldESProducer.useParametrizedTrackerField = True") else: - print "FastSim setting", sequence, "unknown." + print("FastSim setting", sequence, "unknown.") raise ValueError if 'Flat' in self._options.beamspot: @@ -1582,7 +1583,7 @@ def prepare(self, doChecking = False): if not object: continue if not hasattr(self.process,object): - print 'cannot inline -'+object+'- : not known' + print('cannot inline -'+object+'- : not known') else: self.pythonCfgCode +='\n' self.pythonCfgCode +=dumpPython(self.process,object) @@ -1707,7 +1708,7 @@ def addOutputModule(process, tier, content): Function to add an output module to a given process with given data tier and event content """ - print "WARNING. this method will not be supported any more SOON, please use --eventcontent --datatier field to drive the output module definitions" + print("WARNING. this method will not be supported any more SOON, please use --eventcontent --datatier field to drive the output module definitions") moduleName = "output%s%s" % (tier, content) pathName = "%sPath" % moduleName @@ -1722,7 +1723,7 @@ def addOutputModule(process, tier, content): ), ) ) - print getattr(process,moduleName) + print(getattr(process,moduleName)) # put it in an EndPath and put the EndPath into the schedule setattr(process, pathName, cms.EndPath(getattr(process,moduleName)) ) process.schedule.append(getattr(process, pathName)) diff --git a/configs/SpecialRequests2013/MatrixInjector_KeepFirstAndLast_61X_GEDEGAM.py b/configs/SpecialRequests2013/MatrixInjector_KeepFirstAndLast_61X_GEDEGAM.py index 6393199..769532f 100644 --- a/configs/SpecialRequests2013/MatrixInjector_KeepFirstAndLast_61X_GEDEGAM.py +++ b/configs/SpecialRequests2013/MatrixInjector_KeepFirstAndLast_61X_GEDEGAM.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys import json import os @@ -5,7 +6,7 @@ def performInjectionOptionTest(opt): if opt.show: - print 'Not injecting to wmagent in --show mode. Need to run the worklfows.' + print('Not injecting to wmagent in --show mode. Need to run the worklfows.') sys.exit(-1) if opt.wmcontrol=='init': #init means it'll be in test mode @@ -14,10 +15,10 @@ def performInjectionOptionTest(opt): #means the wf were created already, and we just dryRun it. opt.dryRun=True if opt.wmcontrol=='submit' and opt.nThreads==0: - print 'Not injecting to wmagent in -j 0 mode. Need to run the worklfows.' + print('Not injecting to wmagent in -j 0 mode. Need to run the worklfows.') sys.exit(-1) if opt.wmcontrol=='force': - print "This is an expert setting, you'd better know what you're doing" + print("This is an expert setting, you'd better know what you're doing") opt.dryRun=True @@ -43,12 +44,12 @@ def __init__(self,mode='init'): if not os.getenv('WMCORE_ROOT'): - print '\n\twmclient is not setup properly. Will not be able to upload or submit requests.\n' + print('\n\twmclient is not setup properly. Will not be able to upload or submit requests.\n') if not self.testMode: - print '\n\t QUIT\n' + print('\n\t QUIT\n') sys.exit(-18) else: - print '\n\tFound wmclient\n' + print('\n\tFound wmclient\n') self.defaultChain={ "RequestType" : "TaskChain", #this is how we handle relvals @@ -123,13 +124,13 @@ def prepare(self,mReader, directories, mode='init'): import pprint pprint.pprint(wmsplit) except: - print "Not set up for step splitting" + print("Not set up for step splitting") wmsplit={} acqEra=False for (n,dir) in directories.items(): chainDict=copy.deepcopy(self.defaultChain) - print "inspecting",dir + print("inspecting",dir) nextHasDSInput=None for (x,s) in mReader.workFlowSteps.items(): #x has the format (num, prefix) @@ -151,7 +152,7 @@ def prepare(self,mReader, directories, mode='init'): chainDict['nowmTasklist'].append(copy.deepcopy(self.defaultScratch)) chainDict['nowmTasklist'][-1]['PrimaryDataset']='RelVal'+s[1].split('+')[0] if not '--relval' in s[2][index]: - print 'Impossible to create task from scratch' + print('Impossible to create task from scratch') return -12 else: arg=s[2][index].split() @@ -188,7 +189,7 @@ def prepare(self,mReader, directories, mode='init'): try: chainDict['nowmTasklist'][-1]['nowmIO']=json.loads(open('%s/%s.io'%(dir,step)).read()) except: - print "Failed to find",'%s/%s.io'%(dir,step),".The workflows were probably not run on cfg not created" + print("Failed to find",'%s/%s.io'%(dir,step),".The workflows were probably not run on cfg not created") return -15 chainDict['nowmTasklist'][-1]['ConfigCacheID']='%s/%s.py'%(dir,step) chainDict['nowmTasklist'][-1]['GlobalTag']=chainDict['nowmTasklist'][-1]['nowmIO']['GT'] # copy to the proper parameter name @@ -267,20 +268,20 @@ def uploadConf(self,filePath,label,where): cacheName=filePath.split('/')[-1] if self.testMode: self.count+=1 - print '\tFake upload of',filePath,'to couch with label',labelInCouch + print('\tFake upload of',filePath,'to couch with label',labelInCouch) return self.count else: try: from modules.wma import upload_to_couch except: - print '\n\tUnable to find wmcontrol modules. Please include it in your python path\n' - print '\n\t QUIT\n' + print('\n\tUnable to find wmcontrol modules. Please include it in your python path\n') + print('\n\t QUIT\n') sys.exit(-16) if cacheName in self.couchCache: - print "Not re-uploading",filePath,"to",where,"for",label + print("Not re-uploading",filePath,"to",where,"for",label) cacheId=self.couchCache[cacheName] else: - print "Loading",filePath,"to",where,"for",label + print("Loading",filePath,"to",where,"for",label) cacheId=upload_to_couch(filePath, labelInCouch, self.user, @@ -300,14 +301,14 @@ def upload(self): str(n)+d[it]['TaskName'], d['CouchURL'] ) - print d[it]['ConfigCacheID']," uploaded to couchDB for",str(n),"with ID",couchID + print(d[it]['ConfigCacheID']," uploaded to couchDB for",str(n),"with ID",couchID) d[it]['ConfigCacheID']=couchID if it =='DQMConfigCacheID': couchID=self.uploadConf(d['DQMConfigCacheID'], str(n)+'harvesting', d['CouchURL'] ) - print d['DQMConfigCacheID'],"uploaded to couchDB for",str(n),"with ID",couchID + print(d['DQMConfigCacheID'],"uploaded to couchDB for",str(n),"with ID",couchID) d['DQMConfigCacheID']=couchID @@ -315,26 +316,26 @@ def submit(self): try: from modules.wma import makeRequest,approveRequest from wmcontrol import random_sleep - print '\n\tFound wmcontrol\n' + print('\n\tFound wmcontrol\n') except: - print '\n\tUnable to find wmcontrol modules. Please include it in your python path\n' + print('\n\tUnable to find wmcontrol modules. Please include it in your python path\n') if not self.testMode: - print '\n\t QUIT\n' + print('\n\t QUIT\n') sys.exit(-17) import pprint for (n,d) in self.chainDicts.items(): if self.testMode: - print "Only viewing request",n - print pprint.pprint(d) + print("Only viewing request",n) + print(pprint.pprint(d)) else: #submit to wmagent each dict - print "For eyes before submitting",n - print pprint.pprint(d) - print "Submitting",n,"..........." + print("For eyes before submitting",n) + print(pprint.pprint(d)) + print("Submitting",n,"...........") workFlow=makeRequest(self.wmagent,d,encodeDict=True) approveRequest(self.wmagent,workFlow) - print "...........",n,"submitted" + print("...........",n,"submitted") random_sleep() diff --git a/configs/SpecialRequests2013/MatrixReader_24june.py b/configs/SpecialRequests2013/MatrixReader_24june.py index f7f7b84..bd40d2b 100644 --- a/configs/SpecialRequests2013/MatrixReader_24june.py +++ b/configs/SpecialRequests2013/MatrixReader_24june.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys @@ -86,16 +87,16 @@ def readMatrix(self, fileNameIn, useInput=None, refRel=None, fromScratch=None): prefix = self.filesPrefMap[fileNameIn] - print "processing ", fileNameIn + print("processing ", fileNameIn) try: _tmpMod = __import__( 'Configuration.PyReleaseValidation.'+fileNameIn ) self.relvalModule = sys.modules['Configuration.PyReleaseValidation.'+fileNameIn] - except Exception, e: - print "ERROR importing file ", fileNameIn, str(e) + except Exception as e: + print("ERROR importing file ", fileNameIn, str(e)) return - print "request for INPUT for ", useInput + print("request for INPUT for ", useInput) fromInput={} @@ -275,13 +276,13 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= self.reset(what) if self.what != 'all' and self.what not in matrixFile: - print "ignoring non-requested file",matrixFile + print("ignoring non-requested file",matrixFile) continue try: self.readMatrix(matrixFile, useInput, refRel, fromScratch) - except Exception, e: - print "ERROR reading file:", matrixFile, str(e) + except Exception as e: + print("ERROR reading file:", matrixFile, str(e)) raise if not self.workFlowSteps: continue @@ -289,7 +290,7 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= dataFileName = matrixFile.replace('relval_', 'cmsDriver_')+'_hlt.txt' outFile = open(dataFileName,'w') - print "found ", len(self.workFlowSteps.keys()), ' workflows for ', dataFileName + print("found ", len(self.workFlowSteps.keys()), ' workflows for ', dataFileName) ids = self.workFlowSteps.keys() ids.sort() indexAndSteps=[] @@ -361,7 +362,7 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= outFile.write(line+'\n') outFile.write('\n'+'\n') outFile.close() - print "wrote ",writtenWF, ' workflow'+('s' if (writtenWF!=1) else ''),' to ', outFile.name + print("wrote ",writtenWF, ' workflow'+('s' if (writtenWF!=1) else ''),' to ', outFile.name) return @@ -370,9 +371,9 @@ def showWorkFlows(self, selected=None, extended=True): maxLen = 100 # for summary, limit width of output fmt1 = "%-6s %-35s [1]: %s ..." fmt2 = " %35s [%d]: %s ..." - print "\nfound a total of ", len(self.workFlows), ' workflows:' + print("\nfound a total of ", len(self.workFlows), ' workflows:') if selected: - print " of which the following", len(selected), 'were selected:' + print(" of which the following", len(selected), 'were selected:') #-ap for now: maxLen = -1 # for individual listing, no limit on width fmt1 = "%-6s %-35s [1]: %s " @@ -381,7 +382,7 @@ def showWorkFlows(self, selected=None, extended=True): N=[] for wf in self.workFlows: if selected and float(wf.numId) not in selected: continue - if extended: print '' + if extended: print('') #pad with zeros for i in range(len(N),len(wf.cmds)): N.append(0) N[len(wf.cmds)-1]+=1 @@ -389,15 +390,15 @@ def showWorkFlows(self, selected=None, extended=True): for i,s in enumerate(wf.cmds): if extended: if i==0: - print fmt1 % (wf.numId, stepNames, (str(s)+' ')[:maxLen]) + print(fmt1 % (wf.numId, stepNames, (str(s)+' ')[:maxLen])) else: - print fmt2 % ( ' ', i+1, (str(s)+' ')[:maxLen]) + print(fmt2 % ( ' ', i+1, (str(s)+' ')[:maxLen])) else: - print "%-6s %-35s "% (wf.numId, stepNames) + print("%-6s %-35s "% (wf.numId, stepNames)) break - print '' + print('') for i,n in enumerate(N): - if n: print n,'workflows with',i+1,'steps' + if n: print(n,'workflows with',i+1,'steps') return @@ -418,9 +419,9 @@ def createWorkFlows(self, fileNameIn): num, name, commands, stepList = val nameId = str(num)+'_'+name if nameId in self.nameList: - print "==> duplicate name found for ", nameId - print ' keeping : ', self.nameList[nameId] - print ' ignoring : ', val + print("==> duplicate name found for ", nameId) + print(' keeping : ', self.nameList[nameId]) + print(' ignoring : ', val) else: self.nameList[nameId] = val @@ -432,29 +433,29 @@ def prepare(self, useInput=None, refRel='', fromScratch=None): for matrixFile in self.files: if self.what != 'all' and self.what not in matrixFile: - print "ignoring non-requested file",matrixFile + print("ignoring non-requested file",matrixFile) continue if self.what == 'all' and ('upgrade' in matrixFile): - print "ignoring",matrixFile,"from default matrix" + print("ignoring",matrixFile,"from default matrix") continue try: self.readMatrix(matrixFile, useInput, refRel, fromScratch) - except Exception, e: - print "ERROR reading file:", matrixFile, str(e) + except Exception as e: + print("ERROR reading file:", matrixFile, str(e)) raise try: self.createWorkFlows(matrixFile) - except Exception, e: - print "ERROR creating workflows :", str(e) + except Exception as e: + print("ERROR creating workflows :", str(e)) raise def show(self, selected=None, extended=True): self.showWorkFlows(selected,extended) - print '\n','-'*80,'\n' + print('\n','-'*80,'\n') def updateDB(self): diff --git a/configs/SpecialRequests2013/MatrixReader_alcaW13-2012D.py b/configs/SpecialRequests2013/MatrixReader_alcaW13-2012D.py index f2d52e4..93137c5 100644 --- a/configs/SpecialRequests2013/MatrixReader_alcaW13-2012D.py +++ b/configs/SpecialRequests2013/MatrixReader_alcaW13-2012D.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys @@ -86,16 +87,16 @@ def readMatrix(self, fileNameIn, useInput=None, refRel=None, fromScratch=None): prefix = self.filesPrefMap[fileNameIn] - print "processing ", fileNameIn + print("processing ", fileNameIn) try: _tmpMod = __import__( 'Configuration.PyReleaseValidation.'+fileNameIn ) self.relvalModule = sys.modules['Configuration.PyReleaseValidation.'+fileNameIn] - except Exception, e: - print "ERROR importing file ", fileNameIn, str(e) + except Exception as e: + print("ERROR importing file ", fileNameIn, str(e)) return - print "request for INPUT for ", useInput + print("request for INPUT for ", useInput) fromInput={} @@ -256,13 +257,13 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= self.reset(what) if self.what != 'all' and self.what not in matrixFile: - print "ignoring non-requested file",matrixFile + print("ignoring non-requested file",matrixFile) continue try: self.readMatrix(matrixFile, useInput, refRel, fromScratch) - except Exception, e: - print "ERROR reading file:", matrixFile, str(e) + except Exception as e: + print("ERROR reading file:", matrixFile, str(e)) raise if not self.workFlowSteps: continue @@ -270,7 +271,7 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= dataFileName = matrixFile.replace('relval_', 'cmsDriver_')+'_hlt.txt' outFile = open(dataFileName,'w') - print "found ", len(self.workFlowSteps.keys()), ' workflows for ', dataFileName + print("found ", len(self.workFlowSteps.keys()), ' workflows for ', dataFileName) ids = self.workFlowSteps.keys() ids.sort() indexAndSteps=[] @@ -342,7 +343,7 @@ def showRaw(self, useInput, refRel=None, fromScratch=None, what='all',step1Only= outFile.write(line+'\n') outFile.write('\n'+'\n') outFile.close() - print "wrote ",writtenWF, ' workflow'+('s' if (writtenWF!=1) else ''),' to ', outFile.name + print("wrote ",writtenWF, ' workflow'+('s' if (writtenWF!=1) else ''),' to ', outFile.name) return @@ -351,9 +352,9 @@ def showWorkFlows(self, selected=None, extended=True): maxLen = 100 # for summary, limit width of output fmt1 = "%-6s %-35s [1]: %s ..." fmt2 = " %35s [%d]: %s ..." - print "\nfound a total of ", len(self.workFlows), ' workflows:' + print("\nfound a total of ", len(self.workFlows), ' workflows:') if selected: - print " of which the following", len(selected), 'were selected:' + print(" of which the following", len(selected), 'were selected:') #-ap for now: maxLen = -1 # for individual listing, no limit on width fmt1 = "%-6s %-35s [1]: %s " @@ -362,7 +363,7 @@ def showWorkFlows(self, selected=None, extended=True): N=[] for wf in self.workFlows: if selected and float(wf.numId) not in selected: continue - if extended: print '' + if extended: print('') #pad with zeros for i in range(len(N),len(wf.cmds)): N.append(0) N[len(wf.cmds)-1]+=1 @@ -370,15 +371,15 @@ def showWorkFlows(self, selected=None, extended=True): for i,s in enumerate(wf.cmds): if extended: if i==0: - print fmt1 % (wf.numId, stepNames, (str(s)+' ')[:maxLen]) + print(fmt1 % (wf.numId, stepNames, (str(s)+' ')[:maxLen])) else: - print fmt2 % ( ' ', i+1, (str(s)+' ')[:maxLen]) + print(fmt2 % ( ' ', i+1, (str(s)+' ')[:maxLen])) else: - print "%-6s %-35s "% (wf.numId, stepNames) + print("%-6s %-35s "% (wf.numId, stepNames)) break - print '' + print('') for i,n in enumerate(N): - if n: print n,'workflows with',i+1,'steps' + if n: print(n,'workflows with',i+1,'steps') return @@ -399,9 +400,9 @@ def createWorkFlows(self, fileNameIn): num, name, commands, stepList = val nameId = str(num)+'_'+name if nameId in self.nameList: - print "==> duplicate name found for ", nameId - print ' keeping : ', self.nameList[nameId] - print ' ignoring : ', val + print("==> duplicate name found for ", nameId) + print(' keeping : ', self.nameList[nameId]) + print(' ignoring : ', val) else: self.nameList[nameId] = val @@ -413,26 +414,26 @@ def prepare(self, useInput=None, refRel='', fromScratch=None): for matrixFile in self.files: if self.what != 'all' and self.what not in matrixFile: - print "ignoring non-requested file",matrixFile + print("ignoring non-requested file",matrixFile) continue try: self.readMatrix(matrixFile, useInput, refRel, fromScratch) - except Exception, e: - print "ERROR reading file:", matrixFile, str(e) + except Exception as e: + print("ERROR reading file:", matrixFile, str(e)) raise try: self.createWorkFlows(matrixFile) - except Exception, e: - print "ERROR creating workflows :", str(e) + except Exception as e: + print("ERROR creating workflows :", str(e)) raise def show(self, selected=None, extended=True): self.showWorkFlows(selected,extended) - print '\n','-'*80,'\n' + print('\n','-'*80,'\n') def updateDB(self): diff --git a/configs/SpecialRequests2013/jul2-relval_steps.py b/configs/SpecialRequests2013/jul2-relval_steps.py index fa067fb..8fa9104 100644 --- a/configs/SpecialRequests2013/jul2-relval_steps.py +++ b/configs/SpecialRequests2013/jul2-relval_steps.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -15,8 +16,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -26,7 +27,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -85,13 +86,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/jun27-relval_steps.py b/configs/SpecialRequests2013/jun27-relval_steps.py index 7b974c3..70c7426 100644 --- a/configs/SpecialRequests2013/jun27-relval_steps.py +++ b/configs/SpecialRequests2013/jun27-relval_steps.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") else: self.update({float(key):WF(float(key),value)}) @@ -13,8 +14,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -24,7 +25,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -82,13 +83,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/relval_steps_24june.py b/configs/SpecialRequests2013/relval_steps_24june.py index ced9adf..071ce09 100644 --- a/configs/SpecialRequests2013/relval_steps_24june.py +++ b/configs/SpecialRequests2013/relval_steps_24june.py @@ -1,3 +1,4 @@ +from __future__ import print_function # GFXX InputInfoNDefault=2000000 class InputInfo(object): @@ -41,13 +42,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item @@ -600,7 +601,7 @@ def updateme(aDict, anotherOne): if not new_key in aDict: aDict[new_key] = anotherOne[new_key] else: - print "Redefininig %s ? ==> no"%(new_key) + print("Redefininig %s ? ==> no"%(new_key)) updateme(steps,step1) updateme(steps,step2) diff --git a/configs/SpecialRequests2013/relval_steps_Ene50Photon.py b/configs/SpecialRequests2013/relval_steps_Ene50Photon.py index acf6aa3..83ead30 100644 --- a/configs/SpecialRequests2013/relval_steps_Ene50Photon.py +++ b/configs/SpecialRequests2013/relval_steps_Ene50Photon.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") else: self.update({float(key):WF(float(key),value)}) @@ -13,8 +14,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -24,7 +25,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -65,13 +66,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/relval_steps_GEDEGAM.py b/configs/SpecialRequests2013/relval_steps_GEDEGAM.py index d418224..f140d63 100644 --- a/configs/SpecialRequests2013/relval_steps_GEDEGAM.py +++ b/configs/SpecialRequests2013/relval_steps_GEDEGAM.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") else: self.update({float(key):WF(float(key),value)}) @@ -13,8 +14,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -24,7 +25,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -65,13 +66,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/relval_steps_Mar12.py b/configs/SpecialRequests2013/relval_steps_Mar12.py index 6d696ff..eaec602 100644 --- a/configs/SpecialRequests2013/relval_steps_Mar12.py +++ b/configs/SpecialRequests2013/relval_steps_Mar12.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") else: self.update({float(key):WF(float(key),value)}) @@ -13,8 +14,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -24,7 +25,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -65,13 +66,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/relval_steps_RDverification.py b/configs/SpecialRequests2013/relval_steps_RDverification.py index 9ad4e66..42d31a3 100644 --- a/configs/SpecialRequests2013/relval_steps_RDverification.py +++ b/configs/SpecialRequests2013/relval_steps_RDverification.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -15,8 +16,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -26,7 +27,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -85,13 +86,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/relval_steps_alcaW13-2012D.py b/configs/SpecialRequests2013/relval_steps_alcaW13-2012D.py index e3cd95f..2fb3d83 100644 --- a/configs/SpecialRequests2013/relval_steps_alcaW13-2012D.py +++ b/configs/SpecialRequests2013/relval_steps_alcaW13-2012D.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -15,8 +16,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -26,7 +27,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -67,13 +68,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/SpecialRequests2013/relval_steps_runDepMonteCarloApr24.py b/configs/SpecialRequests2013/relval_steps_runDepMonteCarloApr24.py index cd04340..af38537 100644 --- a/configs/SpecialRequests2013/relval_steps_runDepMonteCarloApr24.py +++ b/configs/SpecialRequests2013/relval_steps_runDepMonteCarloApr24.py @@ -1,10 +1,11 @@ +from __future__ import print_function class Matrix(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Matrix" - print "overwritting",key,"not allowed" + print("ERROR in Matrix") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -15,8 +16,8 @@ def __setitem__(self,key,value): class Steps(dict): def __setitem__(self,key,value): if key in self: - print "ERROR in Step" - print "overwritting",key,"not allowed" + print("ERROR in Step") + print("overwritting",key,"not allowed") import sys sys.exit(-9) else: @@ -26,7 +27,7 @@ def __setitem__(self,key,value): def overwrite(self,keypair): value=self[keypair[1]] - print "overwritting step",keypair[0],"with",keypair[1],str(value) + print("overwritting step",keypair[0],"with",keypair[1],str(value)) self.update({keypair[0]:value}) class WF(list): @@ -85,13 +86,13 @@ def __str__(self): def merge(dictlist,TELL=False): import copy last=len(dictlist)-1 - if TELL: print last,dictlist + if TELL: print(last,dictlist) if last==0: # ONLY ONE ITEM LEFT return copy.copy(dictlist[0]) else: reducedlist=dictlist[0:max(0,last-1)] - if TELL: print reducedlist + if TELL: print(reducedlist) # make a copy of the last item d=copy.copy(dictlist[last]) # update with the last but one item diff --git a/configs/prepare_conf.py b/configs/prepare_conf.py index 6b20d20..19786da 100644 --- a/configs/prepare_conf.py +++ b/configs/prepare_conf.py @@ -1,3 +1,4 @@ +from __future__ import print_function # # eval `scramv1 runtime -csh` # if we don't source subSetupAuto we need grid proxy and crab env: @@ -14,8 +15,8 @@ ##TO-DO add option to use local instance # for now comented out #from autoAlca import autoAlca -print autoSkim -print autoAlca +print(autoSkim) +print(autoAlca) DBS3_CONNECT = ConnectionWrapper() @@ -54,7 +55,7 @@ for mydataset in theDatasetsAOD: tempdataset = mydataset['dataset'] theDatasetsToProcessAOD.append((tempdataset.split('/'))[1]) -print theDatasetsToProcessAOD +print(theDatasetsToProcessAOD) nd = 0 @@ -140,7 +141,7 @@ # cmsDriver to make reco cfg reco_command = 'cmsDriver.py RECO -s RAW2DIGI,L1Reco,RECO,'+alcaseq+'EI,PAT,DQM:@standardDQM+@miniAODDQM --runUnscheduled --nThreads '+num_core+ ' --data --scenario pp --conditions %s --eventcontent %sAOD,MINIAOD,DQM --datatier %sAOD,MINIAOD,DQMIO --customise Configuration/DataProcessing/RecoTLR.%s --filein blah.root -n 100 --python_filename=reco_%s_%s.py --no_exec'%(GT, recotier, recotier, customera[campaign], campaign, datasetstr) - print reco_command + print(reco_command) os.system(reco_command) # write the skim parameters in conf file @@ -152,12 +153,12 @@ # cmsDriver to make skim cfg skim_command='cmsDriver.py skim -s SKIM:%s --data --no_output --conditions %s --runUnscheduled --nThreads %s --python_filename skim_%s_%s.py --no_exec'%(autoSkim[datasetstr],GT,num_core,campaign,datasetstr) - print skim_command + print(skim_command) os.system(skim_command) # write the requestID for the workflow in the conf file master.write("request_id=ReReco-"+campaign+"-"+proc_string+"-"+(format(nd, '04d'))+ "\n") -print -print -print "\n".join(theDatasetsToProcess) +print() +print() +print("\n".join(theDatasetsToProcess)) diff --git a/launch_full_rereco.py b/launch_full_rereco.py index 564a1fa..1c86db9 100755 --- a/launch_full_rereco.py +++ b/launch_full_rereco.py @@ -1,11 +1,12 @@ #! /usr/bin/env python +from __future__ import print_function import sys import os import optparse import pprint -from ConfigParser import SafeConfigParser +from configparser import SafeConfigParser sys.path.append(os.path.join(sys.path[0], 'modules')) from full_rereco import * @@ -52,12 +53,12 @@ def commasep2list(string): def get_params(cfgfilename): if cfgfilename == None: - print "No configfile selected!" + print("No configfile selected!") sys.exit(1) if not os.path.exists(cfgfilename): - print "Configfile %s does not exist: please select an existing one!" % ( - cfgfilename) + print("Configfile %s does not exist: please select an existing one!" % ( + cfgfilename)) sys.exit(1) @@ -114,7 +115,7 @@ def get_params(cfgfilename): options, args = build_parser() params_dict = get_params(options.reprocfg) - print "The parameters are: " + print("The parameters are: ") pprint.pprint(params_dict) if options.prepare_configs: diff --git a/modules/full_rereco.py b/modules/full_rereco.py index 612c698..681c7b8 100644 --- a/modules/full_rereco.py +++ b/modules/full_rereco.py @@ -2,6 +2,8 @@ # Originally Written by Jean-Roch Vlimant, remixed several times by others.. +from __future__ import print_function +from __future__ import absolute_import import os import sys import ast @@ -14,17 +16,17 @@ #------------------------------------------------------------------------------- # Check if it is the case to start -if not (os.environ.has_key('WMCONTROL_USER') and os.environ.has_key('WMCONTROL_GROUP')): - print "The environmental variables WMCONTROL_USER or WMCONTROL_GROUP do not seem to be set. Please check." +if not ('WMCONTROL_USER' in os.environ and 'WMCONTROL_GROUP' in os.environ): + print("The environmental variables WMCONTROL_USER or WMCONTROL_GROUP do not seem to be set. Please check.") sys.exit(1) -if not os.environ.has_key('CMSSW_VERSION'): - print "The CMSSW environment does not seem to be set. Please check." +if 'CMSSW_VERSION' not in os.environ: + print("The CMSSW environment does not seem to be set. Please check.") sys.exit(1) #------------------------------------------------------------------------------- -import wma +from . import wma DUMPED_REQUESTS_SCHELETON = "requests_for_%s_cache" @@ -62,7 +64,7 @@ def addSkimToRequest(params, cfg): g_dry_run) if cfgid == None: - print "no id for", cfg + print("no id for", cfg) sys.exit() params['Skim%dConfigCacheID' % (nextIndex,)] = cfgid @@ -144,17 +146,17 @@ def prepareRequest(rawdataset, options): def onePar(request, par): if par in request: - print par, request[par] + print(par, request[par]) return for k in request: if par in k: - print k, ":", request[k] + print(k, ":", request[k]) #------------------------------------------------------------------------------- def cat_file(filename): f = open(filename, "r") - print f.read() + print(f.read()) f.close() #------------------------------------------------------------------------------- @@ -202,7 +204,7 @@ def twikiPrint(requests): def prettyPrint(request): onePar(request, 'InputDataset') if len(request["RunWhitelist"]): - print request["RunWhitelist"] + print(request["RunWhitelist"]) onePar(request, 'RequestString') onePar(request, 'Scenario') onePar(request, 'SkimName') @@ -212,26 +214,26 @@ def prettyPrint(request): def prettyPrintRequest(requests): for request in requests: - print + print() prettyPrint(request) #print request - print + print() #------------------------------------------------------------------------------- def printRequest(requests): for request in requests: - print "------------------ SHOWING ----------------------" - print request - print + print("------------------ SHOWING ----------------------") + print(request) + print() #------------------------------------------------------------------------------- def make_requests(requests): - print 'Making the requests' + print('Making the requests') global dry_run for request in requests: - print " ----------------- SENDING ----------------------" + print(" ----------------- SENDING ----------------------") prettyPrint(request) trimmedRequest = copy.copy(request) for k in trimmedRequest.keys(): @@ -256,18 +258,18 @@ def makerawdatsetfromdbs(query): def runlistfromdbs(query): runlist = [] - print "getting run list from dbs for the query:", query + print("getting run list from dbs for the query:", query) queryhash = hashlib.sha224(query).hexdigest() runlist = "runList_%s.list" % (queryhash,) try: dbs = open(runlist,'r') - print runlist, "opened for reading run list for query:", query + print(runlist, "opened for reading run list for query:", query) except: - print "query never done doing it" + print("query never done doing it") dbs = os.popen('dbs search --noheader --query "find run.number where %s"' % (query,)) store = open(runlist, 'w') - print runlist, "opened for writing run list for query:", query + print(runlist, "opened for writing run list for query:", query) store.write('QUERY: ' + query + '\n') for line in dbs: store.write(line) @@ -279,10 +281,10 @@ def runlistfromdbs(query): if 'QUERY' in line: querystore = (line[7:]).replace('\n', '') if query != querystore: - print "Problem:", - print query, "---" - print "different than" - print querystore, "---" + print("Problem:", end=' ') + print(query, "---") + print("different than") + print(querystore, "---") sys.exit() continue runnumber = int(line.split()[0]) @@ -296,7 +298,7 @@ def dump_requests(reprocfg_filename, requests): ofile = file(ofilename, "w") pprint.pprint(requests, ofile) ofile.close() - print "Requests dumped in %s" % (ofilename) + print("Requests dumped in %s" % (ofilename)) #------------------------------------------------------------------------------- @@ -306,14 +308,14 @@ def read_requests(reprocfg_filename): requests = ast.literal_eval(ifile.read()) pprint.pprint(requests) ifile.close() - print "Requests read from %s" % (ifilename) + print("Requests read from %s" % (ifilename)) return requests #------------------------------------------------------------------------------- def print_and_exec(command): - print "Executing %s" % (command) + print("Executing %s" % (command)) os.system(command) #------------------------------------------------------------------------------- @@ -346,7 +348,7 @@ def request(rawdataset, options): dry_run = options.test if options.upload: - print 'Ready for uploading configs to couchDB' + print('Ready for uploading configs to couchDB') check_rawdataset(rawdataset) diff --git a/modules/helper.py b/modules/helper.py index 281c2d0..7c8956e 100644 --- a/modules/helper.py +++ b/modules/helper.py @@ -1,9 +1,11 @@ #! /usr/bin/env python +from __future__ import print_function +from __future__ import absolute_import import json -import subset +from . import subset import urllib -import wma +from . import wma from collections import defaultdict class SubsetByLumi(): @@ -67,7 +69,7 @@ def run(self, events, brute=False, only_lumis=False): for d in data: res.append(d['name']) return ('blocks', map(lambda x: x.encode('ascii'), res)) - print "Block based splitting not enough. Trying with lumis." + print("Block based splitting not enough. Trying with lumis.") # get files per dataset files = self.DBS3.api('files', 'dataset', self.dataset, True) @@ -118,7 +120,7 @@ def run(self, events, brute=False, only_lumis=False): # get a list of lumis (full list added) rep = defaultdict(list) if len(data): - print "using data" + print("using data") res = self.DBS3.api('filelumis', 'logical_file_name', [d['name'] for d in data if d not in extended['data']], post=True) @@ -128,7 +130,7 @@ def run(self, events, brute=False, only_lumis=False): # get extended list of lumis (only some will be added) if len(extended['data']): - print "using extended" + print("using extended") ext = extended['data'] res = self.DBS3.api('filelumis', 'logical_file_name', [e['name'] for e in ext], post=True) diff --git a/modules/wma.py b/modules/wma.py index 7bb460f..d9142aa 100644 --- a/modules/wma.py +++ b/modules/wma.py @@ -4,9 +4,10 @@ Module containing the functions necessary to interact with the wma. Credit and less than optimal code has to be spreaded among lots of people. ''' +from __future__ import print_function import os import urllib -import httplib +import http.client as httplib import imp import sys import time @@ -16,7 +17,7 @@ from PSetTweaks.WMTweak import makeTweak from WMCore.Cache.WMConfigCache import ConfigCache except: - print "Probably no WMClient was set up. Trying to proceed anyway..." + print("Probably no WMClient was set up. Trying to proceed anyway...") URL = 'https://cmsweb.cern.ch' DBS_URL = URL + '/dbs/prod/global/DBSReader' @@ -100,8 +101,8 @@ def httpget(conn, query): except httplib.BadStatusLine: raise RuntimeError('Something is really wrong') if response.status != 200: - print "Problems quering DBS3 RESTAPI with %s: %s" % ( - conn.host + query.replace('#', '%23'), response.read()) + print("Problems quering DBS3 RESTAPI with %s: %s" % ( + conn.host + query.replace('#', '%23'), response.read())) return None return response.read() @@ -114,27 +115,27 @@ def httppost(conn, where, params): except httplib.BadStatusLine: raise RuntimeError('Something is really wrong') if response.status != 200: - print "Problems quering DBS3 RESTAPI with %s: %s" % ( - params, response.read()) + print("Problems quering DBS3 RESTAPI with %s: %s" % ( + params, response.read())) return None return response.read() def __check_GT(gt): if not gt.endswith("::All"): - print ("It seemslike the name of the GT '%s' has a typo in it, " + print(("It seemslike the name of the GT '%s' has a typo in it, " "missing the final ::All which will crash your job. " - "If insted you're using CondDBv2, you're fine.") % gt + "If insted you're using CondDBv2, you're fine.") % gt) def __check_input_dataset(dataset): if dataset and dataset.count('/')!=3: raise Exception ("Malformed dataset name %s!" %dataset) def __check_request_params(params): - if params.has_key('GlobalTag'): + if 'GlobalTag' in params: __check_GT(params['GlobalTag']) for inputdataset in ('MCPileup','DataPileup','InputDataset'): - if params.has_key(inputdataset): + if inputdataset in params: __check_input_dataset(params[inputdataset]) #------------------------------------------------------------------------------- @@ -150,18 +151,18 @@ def approveRequest(url, workflow, encodeDict=False): conn.request("PUT", "/reqmgr2/data/request/%s" % workflow, json.dumps(params), headers) response = conn.getresponse() if response.status != 200: - print 'could not approve request with following parameters:' + print('could not approve request with following parameters:') for item in params.keys(): - print item + ": " + str(params[item]) - print 'Response from http call:' - print 'Status:', response.status, 'Reason:', response.reason - print 'Explanation:' + print(item + ": " + str(params[item])) + print('Response from http call:') + print('Status:', response.status, 'Reason:', response.reason) + print('Explanation:') data = response.read() - print data - print "Exiting!" + print(data) + print("Exiting!") sys.exit(1) conn.close() - print 'Approved workflow:', workflow + print('Approved workflow:', workflow) return #------------------------------------------------------------------------------- @@ -178,7 +179,7 @@ def getWorkflowStatus(url, workflow): data = json.loads(response) workflow_status = data['result'][0][workflow]['RequestStatus'] except Exception as e: - print 'Error parsing workflow %s' % str(e) + print('Error parsing workflow %s' % str(e)) conn.close() return workflow_status @@ -190,14 +191,14 @@ def __loadConfig(configPath): Import a config. """ - print "Importing the config, this may take a while...", + print("Importing the config, this may take a while...", end=' ') sys.stdout.flush() cfgBaseName = os.path.basename(configPath).replace(".py", "") cfgDirName = os.path.dirname(configPath) modPath = imp.find_module(cfgBaseName, [cfgDirName]) loadedConfig = imp.load_module(cfgBaseName, modPath[0],modPath[1], modPath[2]) - print "done." + print("done.") return loadedConfig #------------------------------------------------------------------------------- @@ -215,24 +216,24 @@ def makeRequest(url, params, encodeDict=False): ##TO-DO do we move it to top of file? __service_url = "/reqmgr2/data/request" - print "Will do POST request to:%s%s" % (url, __service_url) + print("Will do POST request to:%s%s" % (url, __service_url)) conn.request("POST", __service_url, json.dumps(params), headers) response = conn.getresponse() data = response.read() if response.status != 200: - print 'could not post request with following parameters:' - print json.dumps(params, indent=4) - print - print 'Response from http call:' - print 'Status:', response.status, 'Reason:', response.reason - print 'Explanation:' - print data - print "Exiting!" + print('could not post request with following parameters:') + print(json.dumps(params, indent=4)) + print() + print('Response from http call:') + print('Status:', response.status, 'Reason:', response.reason) + print('Explanation:') + print(data) + print("Exiting!") sys.exit(1) workflow = json.loads(data)['result'][0]['request'] - print 'Injected workflow:', workflow + print('Injected workflow:', workflow) conn.close() return workflow @@ -253,7 +254,7 @@ def upload_to_couch(cfg_name, section_name, user_name, group_name, test_mode=Fal f = open(oldID) the_id = f.readline().replace('\n','') f.close() - print cfg_name, 'already uploaded with ID', the_id, 'from', oldID + print(cfg_name, 'already uploaded with ID', the_id, 'from', oldID) return the_id try: @@ -275,9 +276,9 @@ def upload_to_couch(cfg_name, section_name, user_name, group_name, test_mode=Fal configCache.setDescription(section_name) configCache.save() - print "Added file to the config cache:" - print " DocID: %s" % configCache.document["_id"] - print " Revision: %s" % configCache.document["_rev"] + print("Added file to the config cache:") + print(" DocID: %s" % configCache.document["_id"]) + print(" Revision: %s" % configCache.document["_rev"]) f = open(oldID,"w") f.write(configCache.document["_id"]) diff --git a/relval_submit.py b/relval_submit.py index 9af2906..dcb6f62 100755 --- a/relval_submit.py +++ b/relval_submit.py @@ -1,6 +1,7 @@ #!/usr/bin/env python '''Script that submits relval workflows for AlCa@HLT,Prompt condition validation ''' +from __future__ import print_function __author__ = 'Javier Duarte' __copyright__ = 'Copyright 2012, CERN CMS' @@ -24,11 +25,11 @@ def execme(command, dryrun=False): '''Wrapper for executing commands. ''' if dryrun: - print command + print(command) else: - print " * Executing: %s..." % (command) + print(" * Executing: %s..." % (command)) os.system(command) - print " * Executed!" + print(" * Executed!") def getInput(default, prompt=''): '''Like raw_input() but with a default and automatic strip(). @@ -129,14 +130,14 @@ def main(): # Wizard while True: - print '''\nWizard for metadata -I will ask you some questions to fill the metadata file. For some of the questions there are defaults between square brackets (i.e. []), leave empty (i.e. hit Enter) to use them.''' + print('''\nWizard for metadata +I will ask you some questions to fill the metadata file. For some of the questions there are defaults between square brackets (i.e. []), leave empty (i.e. hit Enter) to use them.''') typeList = ['HLT+RECO', 'PR', 'HLT+RECO+ALCA', 'PR+ALCA'] - print '\nTypes of workflow submissions' + print('\nTypes of workflow submissions') for (index, type) in enumerate(typeList): - print ' %s) %s' % (index, type) + print(' %s) %s' % (index, type)) type = getInputChoose(typeList, '0', '\nWhich type of workflow submission\ntype [0]: ') @@ -178,7 +179,7 @@ def main(): Lumisec_forcheck = '[[' for i_tmp in range(len(lumi_tmp)): for j_tmp in range(len(lumi_tmp[i_tmp])): - print str(lumi_tmp[i_tmp][j_tmp]) + print(str(lumi_tmp[i_tmp][j_tmp])) if j_tmp < (len(lumi_tmp[i_tmp])-1): Lumisec_forcheck = Lumisec_forcheck + str(lumi_tmp[i_tmp][j_tmp]) + ',' elif j_tmp == (len(lumi_tmp[i_tmp])-1) and i_tmp == (len(lumi_tmp)-1): @@ -192,7 +193,7 @@ def main(): Lumisec_forcheck = '[[' for i_tmp in range(len(lumi_tmp)): for j_tmp in range(len(lumi_tmp[i_tmp])): - print str(lumi_tmp[i_tmp][j_tmp]) + print(str(lumi_tmp[i_tmp][j_tmp])) if j_tmp < (len(lumi_tmp[i_tmp])-1): Lumisec_forcheck = Lumisec_forcheck + str(lumi_tmp[i_tmp][j_tmp]) + ',' elif j_tmp == (len(lumi_tmp[i_tmp])-1) and i_tmp == (len(lumi_tmp)-1): @@ -219,16 +220,16 @@ def main(): logging.error(run_err_mess) for DataSet in ds.split(","): # check if you have enough events in each dataset - print Runs_forcheck - print Lumisec_forcheck + print(Runs_forcheck) + print(Lumisec_forcheck) nEvents = checkenoughEvents(DataSet, Runs_forcheck, Lumisec_forcheck) checkStat_out = checkStat(DataSet, nEvents) - print DataSet, 'with RUN', Runs_forcheck, Lumisec_forcheck, 'contains:', nEvents, 'events' + print(DataSet, 'with RUN', Runs_forcheck, Lumisec_forcheck, 'contains:', nEvents, 'events') if checkStat_out == 'TOO_LOW_STAT': - print 'ERROR! The statistic is too low. I will exit the script.' + print('ERROR! The statistic is too low. I will exit the script.') sys.exit('POOR_STATISTIC') elif checkStat_out == 'LOW_STAT': - print 'WARNING! The statistic is low. Please check carefully if you do not want to consider a better RUN/lumisection.' + print('WARNING! The statistic is low. Please check carefully if you do not want to consider a better RUN/lumisection.') b0T = getInput('n', '\nIs this for B=0T?\nAnswer [n]: ') hion = getInput('n', '\nIs this for Heavy Ions? Note B=0T is not compatible with Heavy Ions at the moment, also pA runs and Heavy Ions runs are mutually exclusive\nAnswer [n]: ') pa_run = getInput('n', '\nIs this for pA run?\nAnswer [n]:') @@ -268,7 +269,7 @@ def main(): metadata['options']['recoCmsswDir'] = '../%s/' % (pr_release) metadata = json.dumps(metadata, sort_keys=True, indent=4) - print '\nThis is the generated metadata:\n%s' % (metadata) + print('\nThis is the generated metadata:\n%s' % (metadata)) if getInput('n', '\nIs it fine (i.e. save in %s)?\nAnswer [n]: ' % (metadataFilename)).lower() == 'y': break @@ -280,7 +281,7 @@ def main(): with open(metadataFilename, 'rb') as metadataFile: metadata = json.loads(metadataFile.read()) - print '\nexecute the following commands:\n' + print('\nexecute the following commands:\n') commands = [] try: if metadata['HLT_release']: @@ -367,14 +368,14 @@ def main(): for command in commands: execme(command, dryrun) - print "\n------: EXECUTE ALL THE ABOVE COMMANDS IN ONE GO :-------\n" + print("\n------: EXECUTE ALL THE ABOVE COMMANDS IN ONE GO :-------\n") command_comb = '' for command in commands: if command!=commands[-1]: command_comb += command +" && " else: command_comb += command - print command_comb + print(command_comb) if __name__ == '__main__': logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', diff --git a/wmapprove.py b/wmapprove.py index 70f5a33..e83754b 100644 --- a/wmapprove.py +++ b/wmapprove.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys import optparse import time @@ -15,16 +16,16 @@ def getOptions(): options,_ = parser.parse_args() return options except SystemExit: - print "Error in parsing options" + print("Error in parsing options") sys.exit(-1) def approveRequest(options): if options.workflows == '': - print 'No workflows found' + print('No workflows found') sys.exit(-1) workflows = set(options.workflows.split(',')) - print 'Approving requests: %s' % workflows + print('Approving requests: %s' % workflows) if options.wmtest: wma.testbed(options.wmtesturl) for workflow in workflows: @@ -34,9 +35,9 @@ def approveRequest(options): if(wma.getWorkflowStatus(wma.WMAGENT_URL, workflow) == 'new'): wma.approveRequest(wma.WMAGENT_URL, workflow) break - except Exception, e: + except Exception as e: time.sleep(1) - print 'Something went wrong: %s Try number: %s' % (str(e), tries) + print('Something went wrong: %s Try number: %s' % (str(e), tries)) tries += 1 diff --git a/wmcontrol.py b/wmcontrol.py index 358cedf..ff7b2b2 100755 --- a/wmcontrol.py +++ b/wmcontrol.py @@ -10,6 +10,7 @@ # # ################################################################################ +from __future__ import print_function import os import urllib import sys @@ -19,7 +20,7 @@ import optparse import json import pprint -import ConfigParser +import configparser as ConfigParser import traceback import re import time @@ -82,7 +83,7 @@ def __init__ (self, parser): try: options,args = parser.parse_args() except SystemExit: - print "Error in parsing options" + print("Error in parsing options") sys.stderr.write("[wmcontrol exception] Error in parsing options") sys.exit(-1) @@ -90,15 +91,15 @@ def __init__ (self, parser): test_mode = test_mode or options.test self.dont_approve = options.DontApprove if options.wmtest: - print "Setting to injection in cmswebtest : ", options.wmtesturl + print("Setting to injection in cmswebtest : ", options.wmtesturl) wma.testbed(options.wmtesturl) if options.req_file != '' and options.req_file != None: cfg_filename = options.req_file - print "We have a configfile: %s." % (cfg_filename) + print("We have a configfile: %s." % (cfg_filename)) self.configparser.read(cfg_filename) else: # ... otherwise, we have to convert the command line option parser to a .conf, and populate self.configparser - print "We have a commandline." + print("We have a commandline.") self.__fill_configparser(options) def __fill_configparser(self, options): @@ -124,8 +125,8 @@ def get_param(self, name, default=None, section=default_section, verbose=False): ''' ret_val = None if verbose: - print "I am looking for section %s and option %s, the default is #%s#" % ( - name, section, default) + print("I am looking for section %s and option %s, the default is #%s#" % ( + name, section, default)) if self.configparser.has_section(section): if self.configparser.has_option(section,name): @@ -134,8 +135,8 @@ def get_param(self, name, default=None, section=default_section, verbose=False): # We had a cfg file and the default was not given if ret_val == "__NOT-DEFINED__": if verbose: - print "I was reading parameter %s and I put the default %s" % ( - name, default) + print("I was reading parameter %s and I put the default %s" % ( + name, default)) ret_val = default # we have both: read and return! @@ -156,19 +157,19 @@ def get_param(self, name, default=None, section=default_section, verbose=False): raise Exception ("No section %s found in configuration." % (section)) if verbose: - print "I am returning the value #%s# type:%s" % (ret_val, ret_val.__class__) + print("I am returning the value #%s# type:%s" % (ret_val, ret_val.__class__)) return ret_val def get_runs(dset_name, minrun=-1, maxrun=-1): ''' Get the runs from the DBS via the DBS interface ''' - print "Looking for runs in DBS for %s" % (dset_name) + print("Looking for runs in DBS for %s" % (dset_name)) minrun = int(minrun) maxrun = int(maxrun) # check if cmssw is set up for the dbs command - if not os.environ.has_key("CMSSW_BASE"): + if "CMSSW_BASE" not in os.environ: raise Exception("No CMSSW environment set. You need it to query dbs.") return_data = json.loads(wma.generic_get(wma.WMAGENT_URL, wma.DBS3_URL + "runs?dataset=%s" % (dset_name))) @@ -220,7 +221,7 @@ def custodial(datasetpath): try: result = json.load(urllib.urlopen(url)) except: - print 'Problems with url', url + print('Problems with url', url) try: for block in result['phedex']['block']: @@ -241,7 +242,7 @@ def custodial(datasetpath): else : non_custodial[site] += int(files) except: - print 'Problems with dataset:', datasetpath + print('Problems with dataset:', datasetpath) custodial_sites = custodial.keys() non_custodial_sites = non_custodial.keys() @@ -273,7 +274,7 @@ def custodial(datasetpath): custsites = custsites[:-1] #if lfn == None: - print 'dataset:',datasetpath,'custodial:',custsites,'non-custodial:',sites + print('dataset:',datasetpath,'custodial:',custsites,'non-custodial:',sites) # else : # print 'lfn:',lfn,'custodial:',custsites,'non-custodial:',sites @@ -324,8 +325,8 @@ def get_dataset_runs_dict(section, cfg): json_info = json.load(json_file) json_file.close() except ValueError: - print "Error in JSON file: ", dataset_runs_dict[key], " Exiting..." - print traceback.format_exc() + print("Error in JSON file: ", dataset_runs_dict[key], " Exiting...") + print(traceback.format_exc()) #sys.exit() return False for run_number in json_info: @@ -334,7 +335,7 @@ def get_dataset_runs_dict(section, cfg): dataset_runs_dict[key] = run_list run_list = [] else: - print "JSON file doesn't exists. ", os.path.join(os.getcwd(), dataset_runs_dict[key]), " Exiting..." + print("JSON file doesn't exists. ", os.path.join(os.getcwd(), dataset_runs_dict[key]), " Exiting...") #sys.exit() return False except: @@ -461,13 +462,13 @@ def loop_and_submit(cfg): runs.append(item) params['RunWhitelist'] = runs - if params.has_key("BlockWhitelist"): + if "BlockWhitelist" in params: if params['BlockWhitelist'] == []: params['BlockWhitelist'] = new_blocks if params['BlockWhitelist'] != [] and new_blocks != []: - print "WARNING: a different set of blocks was made available in the input dataset and in the blocks option." - print "Keeping the blocks option (%s) instead of (%s)" % (str(sorted(new_blocks)), - str(sorted(params['BlockWhitelist']))) + print("WARNING: a different set of blocks was made available in the input dataset and in the blocks option.") + print("Keeping the blocks option (%s) instead of (%s)" % (str(sorted(new_blocks)), + str(sorted(params['BlockWhitelist'])))) params['BlockWhitelist'] = new_blocks @@ -475,10 +476,10 @@ def loop_and_submit(cfg): lumi_list_dict = ast.literal_eval(service_params['lumi_list']) if ( len(lumi_list_dict.keys()) > 0 ): params['LumiList'] = ast.literal_eval(service_params['lumi_list']) - if params.has_key("RunWhitelist") and params['RunWhitelist'] != []: - print "WARNING: both lumi_list (to set LumiList) and dset_run_dict (to set RunWhitelist) are present" - print "Keeping only the lumi_list option (%s) instead of dset_run_dict (%s)" % ( - params['LumiList'], params['RunWhitelist']) + if "RunWhitelist" in params and params['RunWhitelist'] != []: + print("WARNING: both lumi_list (to set LumiList) and dset_run_dict (to set RunWhitelist) are present") + print("Keeping only the lumi_list option (%s) instead of dset_run_dict (%s)" % ( + params['LumiList'], params['RunWhitelist'])) params.pop('RunWhitelist') @@ -529,9 +530,9 @@ def loop_and_submit(cfg): elif split == 'lumis': params[__first_step]['LumiList'] = details elif split == 'dataset': - print "no white listing" + print("no white listing") if test_mode: - print "Finished in", int((time.time()-t)*1000), "\bms" + print("Finished in", int((time.time()-t)*1000), "\bms") if params['RunWhitelist']: params[__first_step]['RunWhitelist'] = params['RunWhitelist'] @@ -542,7 +543,7 @@ def loop_and_submit(cfg): if 'InputDataset' in params: params.pop('InputDataset') - if params.has_key("LumiList") and params['LumiList']: + if "LumiList" in params and params['LumiList']: params[__first_step]['LumiList'] = params['LumiList'] params.pop('LumiList') #if params has LumiList we remove it because it was set as Task1 parameter @@ -576,10 +577,10 @@ def loop_and_submit(cfg): params['LumiList'] = details params['LumiList'] = details # incomplete ? elif split == 'dataset': - print "no white listing" + print("no white listing") pass if test_mode: - print "Finished in", int((time.time()-t)*1000), "\bms" + print("Finished in", int((time.time()-t)*1000), "\bms") # just print the parameters of the request you would have injected if test_mode: @@ -618,7 +619,7 @@ def make_cfg_docid_dict(filename): if filename == '': return {} - print "Building a cfg-docID dictionary.." + print("Building a cfg-docID dictionary..") cfg_db_file = None @@ -642,7 +643,7 @@ def make_cfg_docid_dict(filename): # split the line cfg_name,docid = line.split(' ') if test_mode: - print "Name, DocID in file %s: %s %s" % (filename, cfg_name,docid) + print("Name, DocID in file %s: %s %s" % (filename, cfg_name,docid)) cfg_docid_dict[cfg_name] = docid cfg_db_file.close() @@ -657,9 +658,9 @@ def get_user_group(cfg, section): user_default = '' group_default = '' - if os.environ.has_key(user_env_name): + if user_env_name in os.environ: user_default = os.environ[user_env_name] - if os.environ.has_key(group_env_name): + if group_env_name in os.environ: group_default = os.environ[group_env_name] #print os.environ.has_key(user_env_name) @@ -744,7 +745,7 @@ def build_params_dict(section,cfg): skim_input = cfg.get_param('skim_input', 'RECOoutput', section) if not skim_docid and skim_cfg: - if cfg_docid_dict.has_key(skim_cfg): + if skim_cfg in cfg_docid_dict: skim_docid = cfg_docid_dict[skim_cfg] else: skim_docid = wma.upload_to_couch(skim_cfg, section, user, group,test_mode) @@ -800,11 +801,11 @@ def build_params_dict(section,cfg): if step_cfg_name != '' and step_docid == '': #print step_cfg_name, step_docid # try to see if it is in the cfg name dict - if cfg_docid_dict.has_key(step_cfg_name): - print "Using the one in the cfg-docid dictionary." + if step_cfg_name in cfg_docid_dict: + print("Using the one in the cfg-docid dictionary.") docIDs[step] = cfg_docid_dict[step_cfg_name] else: - print "No DocId found for section %s. Uploading the cfg to the couch." % (section) + print("No DocId found for section %s. Uploading the cfg to the couch." % (section)) docIDs[step] = wma.upload_to_couch(step_cfg_name, section, user, group,test_mode) step1_docID, step2_docID, step3_docID = docIDs @@ -813,18 +814,18 @@ def build_params_dict(section,cfg): # check if the request is valid if step1_docID == '' and url_dict == "" and request_type != "DQMHarvest": - print "Invalid request, no docID configuration specified." + print("Invalid request, no docID configuration specified.") sys.stderr.write("[wmcontrol exception] Invalid request, no docID configuration specified.") sys.exit(-1) # Extract Campaign from PREP-ID if necessary campaign = cfg.get_param('campaign', '', section) if campaign == "" and request_id == "": - print "Campaign and request-id are not set. Provide at least the Campaign." + print("Campaign and request-id are not set. Provide at least the Campaign.") elif campaign == "" and request_id != "": campaign = re.match(".*-(.*)-.*", request_id).group(1) elif campaign != "" and request_id != "": - print "Campaign and request-id are set. Using %s as campaign." % (campaign) + print("Campaign and request-id are set. Using %s as campaign." % (campaign)) ##get acquisitionEra if it was passed acquisition_era = cfg.get_param('acquisition_era', 'FAKE', section) @@ -913,9 +914,9 @@ def build_params_dict(section,cfg): if number_events: if blocks: ## cannot perform automatic block selection - print "\n\n\n WARNING number_events is not functionnal because you specified blocks in input\n\n\n" + print("\n\n\n WARNING number_events is not functionnal because you specified blocks in input\n\n\n") else: - print "\n\n\n WARNING automated block selection performed \n\n\n" + print("\n\n\n WARNING automated block selection performed \n\n\n") params.update({"RequestNumEvents": number_events}) params.update({"ConfigCacheID": step1_docID, @@ -926,7 +927,7 @@ def build_params_dict(section,cfg): "Multicore": multicore}) if skim_docid != '': - print "This is a skim" + print("This is a skim") params.update({"SkimName1": skim_name, "SkimInput1": skim_input, "Skim1ConfigCacheID": skim_docid, @@ -952,7 +953,7 @@ def build_params_dict(section,cfg): if params["LheInputFiles"] == 'True' or params["LheInputFiles"] == True: #max out to 500K for "lhe step zero" - print "Setting events per job here !!!!",type(params["LheInputFiles"]),params["LheInputFiles"] + print("Setting events per job here !!!!",type(params["LheInputFiles"]),params["LheInputFiles"]) events_per_job = 500000 if wmtest: events_per_job = 15000 @@ -1008,9 +1009,9 @@ def build_params_dict(section,cfg): if number_events: if blocks: ## cannot perform automatic block selection - print "\n\n\n WARNING number_events is not functionnal because you specified blocks in input\n\n\n" + print("\n\n\n WARNING number_events is not functionnal because you specified blocks in input\n\n\n") else: - print "\n\n\n WARNING automated block selection performed \n\n\n" + print("\n\n\n WARNING automated block selection performed \n\n\n") params.update({"RequestNumEvents" : number_events}) params.update({"RequestString": identifier, @@ -1034,11 +1035,11 @@ def build_params_dict(section,cfg): params['StepThreeConfigCacheID'] = step3_docID else: if not keep_step2: - print 'Request not keeping its step 2 output' + print('Request not keeping its step 2 output') raise Exception("The request has a second step, no third step and not keeping it's second output") else: if not keep_step1: - print 'Request not keeping anything' + print('Request not keeping anything') raise Exception('The request has one step and not keeping anything') elif request_type == 'TaskChain': @@ -1116,7 +1117,7 @@ def build_params_dict(section,cfg): "DQMConfigCacheID": harvest_docID}) else: - print "Request type chose: " + str(request_type) + print("Request type chose: " + str(request_type)) raise Exception('Unknown request type, aborting') if harvest_docID and request_type != "DQMHarvest": @@ -1131,8 +1132,8 @@ def build_params_dict(section,cfg): elif __enable_harvesting.upper() == 'FALSE': params["EnableHarvesting"] = False else: - print "enableHarvesting parameter given: %s. Expecting a boolean" % ( - __enable_harvesting) + print("enableHarvesting parameter given: %s. Expecting a boolean" % ( + __enable_harvesting)) raise Exception('enableharvesting value is wrong type') @@ -1294,7 +1295,7 @@ def build_parser(): if __name__ == "__main__": - print banner + print(banner) # Build a parser # https://docs.python.org/2/library/optparse.html diff --git a/wmpriority.py b/wmpriority.py index f636611..9e7c561 100755 --- a/wmpriority.py +++ b/wmpriority.py @@ -1,5 +1,6 @@ #! /usr/bin/env python -import httplib +from __future__ import print_function +import http.client as httplib import sys import os import optparse @@ -21,7 +22,7 @@ def changePriorityWorkflow(url, workflow, priority, cert, key, retry): ##print "ReqMgr2 returned:\n%s" % (data) data = "Unable to change priority of workflow {0}, status code: {1}".format(workflow, stats) time.sleep(1) - print data + print(data) def send_message(url, cert, key, workflow, params, headers): conn = httplib.HTTPSConnection(url, cert_file=cert, key_file=key) @@ -47,7 +48,7 @@ def main(): parser = prepare_parser() options, args = parser.parse_args() if len(args) < 2: - print "usage: wmpriority.py [options]" + print("usage: wmpriority.py [options]") sys.exit(1) workflow = args[0] priority = args[1] diff --git a/wmupload.py b/wmupload.py index e33ec85..5c8f13a 100755 --- a/wmupload.py +++ b/wmupload.py @@ -1,4 +1,5 @@ #! /usr/bin/env python +from __future__ import print_function import optparse import os from modules import wma @@ -6,9 +7,9 @@ def prepare_parser(): parser = optparse.OptionParser() parser.add_option('-u', '--user', help='Username', dest='user', - default=os.environ['WMCONTROL_USER'] if os.environ.has_key('WMCONTROL_USER') else '') + default=os.environ['WMCONTROL_USER'] if 'WMCONTROL_USER' in os.environ else '') parser.add_option('-g', '--group', help='User group', dest='group', - default=os.environ['WMCONTROL_GROUP'] if os.environ.has_key('WMCONTROL_GROUP') else '') + default=os.environ['WMCONTROL_GROUP'] if 'WMCONTROL_GROUP' in os.environ else '') parser.add_option('-l', '--label', help='Label and description of config', dest='label', default='Uploaded through wmupload') parser.add_option('--wmtest', help='To inject requests to the cmsweb test bed', action='store_true' , @@ -21,7 +22,7 @@ def main(): parser = prepare_parser() options, args = parser.parse_args() if options.wmtest: - print "Setting to injection in cmswebtest : ", options.wmtesturl + print("Setting to injection in cmswebtest : ", options.wmtesturl) wma.testbed(options.wmtesturl) for cfg_name in args: wma.upload_to_couch(cfg_name, options.label, options.user, options.group)