1 |
|
#!/usr/bin/env python |
2 |
|
|
3 |
– |
import re |
3 |
|
import sys |
4 |
|
from optparse import OptionParser |
5 |
+ |
from xml.dom.minidom import parseString |
6 |
|
|
7 |
|
parser = OptionParser() |
8 |
|
parser.add_option("-f", "--file", dest="filename", help="list of jfr files", metavar="FILE") |
10 |
|
(options, args) = parser.parse_args() |
11 |
|
|
12 |
|
filenames = [] |
13 |
– |
lines = [] |
13 |
|
|
14 |
|
if options.filename: |
15 |
|
filelist = file(options.filename, "r") |
20 |
|
else: |
21 |
|
filenames = args |
22 |
|
|
23 |
+ |
# hack to make multiple file processing possible |
24 |
+ |
lines = '<Files>' |
25 |
+ |
|
26 |
|
for f in filenames: |
27 |
|
try: |
28 |
< |
lines += file(f, "r").readlines() |
28 |
> |
lines += file(f, "r").read() |
29 |
|
except IOError: |
30 |
|
sys.stderr.write("Cannot open " + f + "\n") |
31 |
|
|
32 |
< |
runPat = re.compile('\s*<Run[ ]ID[=]"([0-9]+)">') |
31 |
< |
lumiPat = re.compile('\s*<LumiSection[ ]ID[=]"([0-9]+)"/>') |
32 |
> |
lines += '</Files>' |
33 |
|
|
34 |
< |
inRunBlock = False |
34 |
> |
dom = parseString(lines) |
35 |
|
|
36 |
< |
lumilist = dict() |
36 |
> |
runBlocks = dom.getElementsByTagName('Run') |
37 |
|
|
38 |
< |
run = 0 |
38 |
< |
for line in lines: |
39 |
< |
runMatch = runPat.match(line) |
40 |
< |
if runMatch: |
41 |
< |
run = int(runMatch.group(1)) |
42 |
< |
if run not in lumilist: |
43 |
< |
lumilist[run] = list() |
44 |
< |
|
45 |
< |
continue |
46 |
< |
|
47 |
< |
if run != 0: |
48 |
< |
if '</Run>' in line: |
49 |
< |
run = 0 |
50 |
< |
continue |
51 |
< |
|
52 |
< |
lumiMatch = lumiPat.match(line) |
53 |
< |
if lumiMatch: |
54 |
< |
lumilist[run].append(int(lumiMatch.group(1))) |
38 |
> |
lumilist = dict() |
39 |
|
|
40 |
+ |
for runTag in runBlocks: |
41 |
+ |
run = 0 |
42 |
+ |
for i in range(runTag.attributes.length): |
43 |
+ |
attr = runTag.attributes.item(i) |
44 |
+ |
if attr.name == "ID": |
45 |
+ |
run = attr.value |
46 |
+ |
|
47 |
+ |
if run == 0: |
48 |
+ |
raise RuntimeError("No runnumber") |
49 |
+ |
|
50 |
+ |
if run not in lumilist: |
51 |
+ |
lumilist[run] = list() |
52 |
+ |
|
53 |
+ |
children = runTag.childNodes |
54 |
+ |
|
55 |
+ |
for child in children: |
56 |
+ |
if child.localName == "LumiSection": |
57 |
+ |
for i in range(child.attributes.length): |
58 |
+ |
attr = child.attributes.item(i) |
59 |
+ |
if attr.name == "ID": |
60 |
+ |
lumilist[run].append(int(attr.value)) |
61 |
|
|
62 |
|
jsonTxt = "{" |
63 |
|
|