ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tools
PROCTools
python
comparexAODDigest.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4
import
argparse
5
import
sys
6
7
def
extractData
(filename):
8
9
result=dict()
10
11
rein=open(filename)
12
for
line
in
rein:
13
l=line.split()
14
if
l[0]==
'run'
:
15
header=l
16
else
:
17
run=int(l[0])
18
evt=int(l[1])
19
result[(run,evt)]=[float(s)
for
s
in
l[2:]]
20
rein.close()
21
return
result,header
22
23
24
def
compare2Files
(file1, file2, ignoredColumns=None):
25
26
res1,h1=
extractData
(file1)
27
res2,h2=
extractData
(file2)
28
29
30
if
(h1 != h2):
31
print
(
"ERROR, headers don't match"
)
32
print
(h1)
33
print
(h2)
34
return
1
35
36
runEvts = res1.keys()
37
if
len(res2) < len(res1):
38
runEvts = res2.keys()
39
40
diffCounter=dict()
41
for
h
in
h1[2:]:
42
diffCounter[h]=0
43
44
# Loop over events:
45
for
runEvt
in
runEvts:
46
values1 = res1[runEvt]
47
values2 = res2[runEvt]
48
for
i, name
in
enumerate(h1[2:]):
49
#print (name,i,len(values1),len(values2))
50
if
values1[i] != values2[i]:
51
ignored =
False
52
if
ignoredColumns
and
name
in
ignoredColumns:
53
ignored =
True
54
suffix =
' (ignored)'
if
ignored
else
''
55
print
(
"Diff: Run {} Evt {} {} {} -> {}{}"
.format(runEvt[0],runEvt[1],name,values1[i],values2[i],suffix))
56
diffCounter[name]+=1
57
pass
58
pass
59
pass
60
61
print
(
"Summary of differences:"
)
62
noChanges=
""
63
nEvt=len(runEvts)
64
changed =
False
65
for
(name,count)
in
diffCounter.items():
66
if
(count>0):
67
#print (name,":",count,"(of ",nEvt,")")
68
print
(
"{}: {} events (out of {})"
.format(name,count,nEvt))
69
if
not
ignoredColumns
or
name
not
in
ignoredColumns:
70
changed =
True
71
else
:
72
noChanges+=
" "
+name
73
if
not
changed:
74
print
(
"No changes"
)
75
else
:
76
print
(
"No changes for:"
,noChanges)
77
return
changed
78
79
80
def
compareDigest
(filelist):
81
if
len(filelist)<2:
82
print
(
"Got only %i files. Can't compare"
)
83
return
None
84
85
runevtset=
set
()
86
87
summary=dict()
#key is the datestamp
88
89
for
f
in
filelist:
90
datestamp=f.split(
'/'
)[9]
91
print
(
"Fond file for %s"
% datestamp)
92
header=
None
93
if
datestamp
in
summary:
94
print
(
"ERROR, duplicate date-stamp %s"
% datestamp)
95
continue
96
97
res,hdr=
extractData
(f)
98
if
header
is
None
:
99
header=hdr
100
elif
(header!=hdr):
101
print
(
"ERROR, headers of file %s doesn't match!"
% f)
102
continue
103
104
summary[datestamp]=res
105
runevtset |=
set
(res.keys())
106
pass
107
108
109
#collected all data, now invert the matrix, sort per run/event
110
nValues=len(header)-2
111
112
perEvt=dict()
113
for
runevt
in
runevtset:
114
perEvt[runevt]=[]
115
for
i
in
range(nValues):
116
perEvt[runevt].append(
set
())
117
118
for
day,data
in
summary.items():
119
for
runevt,v
in
data.items():
120
for
i
in
range(nValues):
121
perEvt[runevt][i].
add
(v[i])
122
123
124
row_format =
"{:>12}"
* len(header)
125
#row_format+=os.linesep
126
print
(row_format.format(*header))
127
for
runevt,v
in
perEvt.items():
128
updates=[runevt[0],runevt[1]]
129
updates+=[len(x)-1
for
x
in
v]
130
print
(row_format.format(*updates))
131
132
133
if
__name__ ==
"__main__"
:
134
parser = argparse.ArgumentParser(
135
description=
"A script to compare 2 xAODDigest files"
)
136
parser.add_argument(
"digestFile"
, nargs=2, type=str,
137
help=
"digest filename"
, action=
"store"
)
138
parser.add_argument(
"--ignoreMuons"
, help=
"Ignore muons"
,
139
action=
"store_true"
, default=
False
)
140
parser.add_argument(
"--ignoreMET"
, help=
"Ignore MET"
,
141
action=
"store_true"
, default=
False
)
142
143
args = parser.parse_args()
144
145
ignored = []
146
if
args.ignoreMuons:
147
ignored += [
'nMuons'
,
'muon1pt'
,
'muon1eta'
,
'muon1phi'
]
148
if
args.ignoreMET:
149
ignored += [
'nmet'
,
'metx'
,
'mety'
,
'sumet'
]
150
151
retval =
compare2Files
(args.digestFile[0], args.digestFile[1], ignoredColumns=ignored)
152
153
sys.exit(retval)
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
set
STL class.
add
bool add(const std::string &hname, TKey *tobj)
Definition
fastadd.cxx:55
python.comparexAODDigest.compareDigest
compareDigest(filelist)
Definition
comparexAODDigest.py:80
python.comparexAODDigest.compare2Files
compare2Files(file1, file2, ignoredColumns=None)
Definition
comparexAODDigest.py:24
python.comparexAODDigest.extractData
extractData(filename)
Definition
comparexAODDigest.py:7
Generated on
for ATLAS Offline Software by
1.17.0