ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MuJetAnalysis/AnalysisTools/scripts/countSuccessfulEvents.py
Revision: 1.2
Committed: Wed Oct 6 01:26:21 2010 UTC (14 years, 7 months ago) by pivarski
Content type: text/x-python
Branch: MAIN
CVS Tags: JP-2010-10-05-a
Changes since 1.1: +10 -3 lines
Log Message:
can use countevents script on condor output

File Contents

# Content
1 import sys, re, glob
2
3 fileList, crabResDir = sys.argv[1:]
4 execfile(fileList)
5
6 fileNameRE = re.compile("output_([0-9]+)_.*")
7 fileNameRE2 = re.compile("patified_([0-9]+).root")
8 lineRE = re.compile("\[E\( ([0-9]+) \)E\]")
9
10 indexes = {}
11 total_number_of_events = 0
12 for fileName in source.fileNames:
13 m = fileNameRE.search(fileName)
14 if m is None:
15 m = fileNameRE2.search(fileName)
16 if m is None:
17 raise Exception, "File \"%s\" is not of the right form." % fileName
18
19 index = int(m.group(1))
20 if index in indexes:
21 raise Exception, "Index %s appears for the second time in \"%s\"." % (m.group(0), fileName)
22
23 try:
24 f = open("%s/CMSSW_%d.stdout" % (crabResDir, index))
25 except IOError:
26 try:
27 f = open("%s/Submission_1/CMSSW_%d.stdout" % (crabResDir, index))
28 except IOError:
29 fname = glob.glob("%s/output_*_%d.stdout" % (crabResDir, index))
30 f = open(fname[0])
31
32 eventnumber = None
33 for line in f.xreadlines():
34 m2 = lineRE.search(line)
35 if m2 is not None:
36 e = int(m2.group(1))
37 if eventnumber is not None and e <= eventnumber:
38 raise Exception, "%s/CMSSW_%d.stdout has an out-of-order event (number %d)." % (crabResDir, index, e)
39 eventnumber = e
40
41 total_number_of_events += eventnumber
42 print fileName, eventnumber
43
44 print "======================================================"
45 print "Total:", total_number_of_events