Skip to content

Commit

Permalink
Fixed some errors and improved usage for a large number of skims
Browse files Browse the repository at this point in the history
  • Loading branch information
mteroerd committed Sep 3, 2018
1 parent 5b714bb commit fae3000
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Expand Up @@ -58,7 +58,7 @@
if "iov" in options.sample:
isMultiIOV = True
isData = True
if options.sample == 'data1':
elif options.sample == 'data1':
isData1 = True
isData = True
elif options.sample == 'data2':
Expand Down
30 changes: 26 additions & 4 deletions Alignment/APEEstimation/test/batch/startSkim.py
Expand Up @@ -19,14 +19,15 @@ def doSkim(sample):
outFilePath = None

# start cmsRun
proc = subprocess.Popen(toExec, stdout=subprocess.PIPE)
proc = subprocess.Popen(toExec, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

def get_output(proc):
while True:
line = proc.stdout.readline().rstrip()
if not line:
break
yield line


# print output in shell while program runs, also extract output filename
try:
Expand All @@ -35,7 +36,7 @@ def get_output(proc):
outFileName = line.split("output name ")[1].split(".root")[0]
if "Using output path" in line:
outFilePath = line.split("output path ")[1]
print(line)
print(sample+": "+line)
except KeyboardInterrupt:
#this way, the current file is closed and the skimming is finished in a way that the last opened file is actually usable

Expand All @@ -61,7 +62,7 @@ def get_output(proc):
try:
fileNo = int(fileNoString)
# For (most) weird naming conventions to not mess up renaming
if len(fileNoString) != 3 or fileNo == 1:
if len(fileNoString) != 3:
continue

newFileName = "%s_%d.root"%(outFileName, fileNo+1)
Expand All @@ -80,7 +81,8 @@ def get_output(proc):
if not os.path.isdir(outFilePath):
os.makedirs(outFilePath)
for fi in targetFiles:
subprocess.call("xrdcp %s %s/"%(fi, outFilePath), shell=True)
if not subprocess.call("xrdcp %s %s/"%(fi, outFilePath), shell=True):
os.remove(fi)

def main(argv):
if not 'CMSSW_BASE' in os.environ:
Expand All @@ -99,6 +101,26 @@ def main(argv):
print("Usage: python startSkim.py -s <sample>")
sys.exit()

finalSamples = []
for sample in args.samples:
if "[" in sample and "]" in sample:
sampleName = sample[:sample.find("[")]
nums = sample[sample.find("[")+1:sample.find("]")]
for interval in nums.split(","):
interval = interval.strip()
if "-" in interval:
lowNum = int(interval.split("-")[0])
upNum = int(interval.split("-")[1])
for i in range(lowNum, upNum+1):
finalSamples.append("%s%d"%(sampleName, i))
else:
finalSamples.append("%s%d"%(sampleName, int(interval)))
else:
finalSamples.append(sample)

args.samples = finalSamples
print(args.samples)
return
if len(args.samples) == 1 or args.consecutive:
for sample in args.samples:
doSkim(sample)
Expand Down

0 comments on commit fae3000

Please sign in to comment.