Skip to content

Commit

Permalink
Merge pull request cms-nanoAOD#255 from Laurits7/master
Browse files Browse the repository at this point in the history
Typo fix (#6)
  • Loading branch information
mariadalfonso authored Nov 9, 2020
2 parents f6697c4 + 0ccc419 commit 582e0c5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions python/postprocessing/framework/crabhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def inputFiles():
print("ARGV: " + sys.argv)
print("ARGV: " + str(sys.argv))
JobNumber = sys.argv[1]
crabFiles = PSet.process.source.fileNames
print(crabFiles)
Expand Down Expand Up @@ -62,6 +62,6 @@ def runsAndLumis():
if rstart not in runsAndLumis:
runsAndLumis[rstart] = []
runsAndLumis[rstart].append([int(lstart), int(lstop)])
print("Runs and Lumis: " + runsAndLumis)
print("Runs and Lumis: " + str(runsAndLumis))
return runsAndLumis
return None
13 changes: 10 additions & 3 deletions python/postprocessing/framework/eventloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def addObjectList(self, names, obj):
setattr(self, obj.GetName(), objlist)


def eventLoop(modules, inputFile, outputFile, inputTree, wrappedOutputTree, maxEvents=-1, eventRange=None, progress=(10000, sys.stdout), filterOutput=True):
def eventLoop(
modules, inputFile, outputFile, inputTree, wrappedOutputTree,
maxEvents=-1, eventRange=None, progress=(10000, sys.stdout),
filterOutput=True
):
for m in modules:
m.beginFile(inputFile, outputFile, inputTree, wrappedOutputTree)

Expand Down Expand Up @@ -86,9 +90,12 @@ def eventLoop(modules, inputFile, outputFile, inputTree, wrappedOutputTree, maxE
if ie > 0 and ie % progress[0] == 0:
t1 = time.time()
progress[1].write("Processed %8d/%8d entries, %5.2f%% (elapsed time %7.1fs, curr speed %8.3f kHz, avg speed %8.3f kHz), accepted %8d/%8d events (%5.2f%%)\n" % (
ie, entries, ie / float(0.01 * entries), t1 - t0, (progress[0] / 1000.) / (max(t1 - tlast, 1e-9)), ie / 1000. / (max(t1 - t0, 1e-9)), acceptedEvents, doneEvents, acceptedEvents / (0.01 * doneEvents)))
ie, entries, ie / float(0.01 * entries),
t1 - t0, (progress[0] / 1000.) / (max(t1 - tlast, 1e-9)),
ie / 1000. / (max(t1 - t0, 1e-9)),
acceptedEvents, doneEvents,
acceptedEvents / (0.01 * doneEvents)))
tlast = t1
for m in modules:
m.endFile(inputFile, outputFile, inputTree, wrappedOutputTree)

return (doneEvents, acceptedEvents, time.time() - t0)
14 changes: 7 additions & 7 deletions python/postprocessing/framework/postprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def __init__(
"hadd. No name specified for the output file, will use tree.root")
self.haddFileName = "tree.root"
self.branchsel = BranchSelection(branchsel) if branchsel else None
if outputbranchsel != None:
if outputbranchsel is not None:
self.outputbranchsel = BranchSelection(outputbranchsel)
elif outputbranchsel == None and branchsel != None:
elif outputbranchsel is None and branchsel is not None:
# Use the same branches in the output as in input
self.outputbranchsel = BranchSelection(branchsel)
else:
Expand Down Expand Up @@ -96,7 +96,7 @@ def prefetchFile(self, fname, verbose=True):
return fname, False

def run(self):
outpostfix = self.postfix if self.postfix != None else (
outpostfix = self.postfix if self.postfix is not None else (
"_Friend" if self.friend else "_Skim")
if not self.noOut:

Expand Down Expand Up @@ -127,10 +127,10 @@ def run(self):
"Running with --noout and no modules does nothing!")

# Open histogram file, if desired
if (self.histFileName != None and self.histDirName == None) or (self.histFileName == None and self.histDirName != None):
if (self.histFileName is not None and self.histDirName is None) or (self.histFileName is None and self.histDirName is not None):
raise RuntimeError(
"Must specify both histogram file and histogram directory!")
elif self.histFileName != None and self.histDirName != None:
elif self.histFileName is not None and self.histDirName is None:
self.histFile = ROOT.TFile.Open(self.histFileName, "RECREATE")
else:
self.histFile = None
Expand Down Expand Up @@ -161,7 +161,7 @@ def run(self):

# get input tree
inTree = inFile.Get("Events")
if inTree == None:
if inTree is None:
inTree = inFile.Get("Friends")
nEntries = min(inTree.GetEntries() -
self.firstEntry, self.maxEntries)
Expand All @@ -182,7 +182,7 @@ def run(self):
for ffname in ffnames:
inAddFiles.append(ROOT.TFile.Open(ffname))
inAddTree = inAddFiles[-1].Get("Events")
if inAddTree == None:
if inAddTree is None:
inAddTree = inAddFiles[-1].Get("Friends")
inAddTrees.append(inAddTree)
inTree.AddFriend(inAddTree)
Expand Down
1 change: 0 additions & 1 deletion python/postprocessing/modules/common/PrefireCorr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from builtins import zip
from PhysicsTools.NanoAODTools.postprocessing.framework.eventloop import Module
from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel import Collection
import os
Expand Down
1 change: 0 additions & 1 deletion python/postprocessing/modules/jme/jetSmearer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from builtins import zip
from PhysicsTools.NanoAODTools.postprocessing.tools import matchObjectCollection, matchObjectCollectionMultiple
from PhysicsTools.NanoAODTools.postprocessing.framework.eventloop import Module
from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel import Collection, Object
Expand Down
10 changes: 5 additions & 5 deletions scripts/haddnano.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def zeroFill(tree, brName, brObj, allowNonBool=False):
fileHandles = []
goFast = True
for fn in files:
print(("Adding file", fn))
print("Adding file" + str(fn))
fileHandles.append(ROOT.TFile.Open(fn))
if fileHandles[-1].GetCompressionSettings() != fileHandles[0].GetCompressionSettings():
goFast = False
Expand All @@ -44,7 +44,7 @@ def zeroFill(tree, brName, brObj, allowNonBool=False):

for e in fileHandles[0].GetListOfKeys():
name = e.GetName()
print(("Merging", name))
print("Merging" + str(name))
obj = e.ReadObj()
cl = ROOT.TClass.GetClass(e.GetClassName())
inputs = ROOT.TList()
Expand All @@ -61,7 +61,7 @@ def zeroFill(tree, brName, brObj, allowNonBool=False):
for x in otherObj.GetListOfBranches()])
missingBranches = list(branchNames - otherBranches)
additionalBranches = list(otherBranches - branchNames)
print(("missing:", missingBranches, "\n Additional:", additionalBranches))
print("missing: " + str(missingBranches) + "\n Additional:" + str(additionalBranches))
for br in missingBranches:
# fill "Other"
zeroFill(otherObj, br, obj.GetListOfBranches().FindObject(br))
Expand All @@ -76,7 +76,7 @@ def zeroFill(tree, brName, brObj, allowNonBool=False):
for x in otherObj.GetListOfBranches()])
missingBranches = list(branchNames - otherBranches)
additionalBranches = list(otherBranches - branchNames)
print(("missing:", missingBranches, "\n Additional:", additionalBranches))
print("missing: " + str(missingBranches) + "\n Additional:" + str(additionalBranches))
for br in missingBranches:
# fill "Other"
zeroFill(otherObj, br, obj.GetListOfBranches(
Expand All @@ -102,4 +102,4 @@ def zeroFill(tree, brName, brObj, allowNonBool=False):
print("Strings are not matching")
obj.Write()
else:
print(("Cannot handle ", obj.IsA().GetName()))
print("Cannot handle " + str(obj.IsA().GetName()))
1 change: 0 additions & 1 deletion scripts/nano_postproc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
from PhysicsTools.NanoAODTools.postprocessing.framework.postprocessor import PostProcessor
from importlib import import_module
import os
Expand Down

0 comments on commit 582e0c5

Please sign in to comment.