ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DataQuality
DQDefects
share
dq_defect_ls.py
Go to the documentation of this file.
1
#! /usr/bin/env python
2
"""
3
dq_defect_ls.py
4
5
A short script to list defects.
6
"""
7
8
import
fnmatch
9
10
from
argparse
import
ArgumentParser
11
12
from
DQDefects
import
DefectsDB
13
from
DQDefects.db
import
DEFAULT_CONNECTION_STRING
14
15
def
get_primary
(ddb):
16
return
ddb.defect_names
17
def
get_virtual
(ddb):
18
return
ddb.virtual_defect_names
19
def
get_both
(ddb):
20
return
ddb.defect_names | ddb.virtual_defect_names
21
22
def
show_tags
(connection_string, args):
23
ddb = DefectsDB(connection_string)
24
25
nspec = sum(bool(x)
for
x
in
(args.tags, args.defect_tags, args.logic_tags))
26
assert
nspec == 1,
"Only one of --tags, --logic-tags and --defect-tags can be specified."
27
28
if
args.tags:
29
tags = ddb.tags
30
if
args.logic_tags:
31
tags = ddb.logics_tags
32
if
args.defect_tags:
33
tags = ddb.defects_tags
34
35
for
t
in
tags:
36
print
(t)
37
38
def
show_defects
(connection_string, tag, get_defects, patterns, args):
39
ddb = DefectsDB(connection_string, tag=tag)
40
41
all_defects = get_defects(ddb)
42
43
for
pattern
in
patterns:
44
if
len(patterns) != 1:
45
print
()
# Extra newline to separate the patterns
46
print
(f
"{pattern}:"
)
47
for
defect
in
sorted(fnmatch.filter(all_defects, pattern)):
48
print
(defect)
49
50
def
show_defects_with_desc
(connection_string, tag, get_defects, patterns, args):
51
ddb = DefectsDB(connection_string, tag=tag)
52
53
descriptions = ddb.all_defect_descriptions
if
args.descriptions
else
{}
54
55
all_defects = get_defects(ddb)
56
all_matching = [d
for
pat
in
patterns
for
d
in
fnmatch.filter(all_defects, pat)]
57
if
not
all_matching:
58
return
59
60
get_virtuality =
lambda
defect:
""
61
if
args.show_virtuality:
62
primary_defects = ddb.defect_names
63
def
get_virtuality(defect):
64
if
defect
in
primary_defects:
65
return
"[P] "
66
return
"[V] "
67
68
ldl = longest_defect_length =
max
(len(d)
for
d
in
all_matching)
69
70
for
pattern
in
patterns:
71
if
len(patterns) != 1:
72
print
(f
"{pattern}:"
)
73
for
defect
in
sorted(fnmatch.filter(all_defects, pattern)):
74
desc = descriptions.get(defect,
""
)
75
print
(
"{virtuality}{0:<{width}}: {1}"
.format(
76
defect, desc, width=ldl, virtuality=get_virtuality(defect)))
77
print
78
79
def
show_defects_with_logic
(connection_string, tag, patterns, args):
80
ddb = DefectsDB(connection_string, tag=tag)
81
82
defects = ddb.virtual_defect_names
83
logics = ddb.virtual_defect_logics
84
85
all_matching = [d
for
pat
in
patterns
for
d
in
fnmatch.filter(defects, pat)]
86
if
not
all_matching:
87
return
88
89
ldl = longest_defect_length =
max
(len(d)
for
d
in
all_matching)
90
91
for
pattern
in
patterns:
92
if
len(patterns) != 1:
93
print
(f
"{pattern}:"
)
94
for
defect
in
sorted(fnmatch.filter(defects, pattern)):
95
print
(
"{0:<{width}}: {1}"
.format(
96
defect,
", "
.join(logics[defect].clauses), width=ldl))
97
print
98
99
def
main
():
100
parser = ArgumentParser(description=
"List information from the defects "
101
"database"
)
102
a = parser.add_argument
103
add_group = parser.add_argument_group
104
105
a
(
"-c"
,
"--connection-string"
, default=DEFAULT_CONNECTION_STRING,
106
help=
"Database connection to use (default: %s)"
% DEFAULT_CONNECTION_STRING)
107
108
#
109
# TAGS
110
#
111
tag_group = add_group(
"tags"
,
"Show information about tags"
)
112
a = tag_group.add_argument
113
114
a
(
"--tags"
, action=
"store_true"
,
115
help=
"List all available hierarchical tags"
)
116
117
a
(
"--logic-tags"
, action=
"store_true"
,
118
help=
"Show all logic tags"
)
119
120
a
(
"--defect-tags"
, action=
"store_true"
,
121
help=
"Show all defect tags"
)
122
123
#
124
# DEFECTS
125
#
126
defect_group = add_group(
"defects"
,
"Show information about defects"
)
127
a = defect_group.add_argument
128
129
a
(
"-t"
,
"--tag"
, default=
None
,
130
help=
"Tag to use (default: HEAD)"
)
131
132
a
(
"-l"
,
"--logic"
, action=
"store_true"
,
133
help=
"Show logic used for virtual flags (use -v)"
)
134
135
a
(
"-V"
,
"--show-virtuality"
, action=
"store_true"
,
136
help=
"Indicate virtual vs nonvirtual flags"
)
137
138
a
(
"-v"
,
"--virtual"
, action=
"store_true"
,
139
help=
"Show only virtual flags"
)
140
141
a
(
"-p"
,
"--primary"
, action=
"store_true"
,
142
help=
"Show only primary flags"
)
143
144
a
(
"-d"
,
"--descriptions"
, action=
"store_true"
,
145
help=
"Show descriptions"
)
146
147
a
(
"patterns"
, metavar=
"defect"
, type=str, nargs=
"*"
, default=[],
148
help=
"One or more defect globs"
)
149
150
# These options shouldn't be specified with tag listing options
151
DEFECT_OPTIONS = [
"logic"
,
"show_virtuality"
,
"virtual"
,
"primary"
,
152
"descriptions"
,
"patterns"
,
"tag"
]
153
154
args = parser.parse_args()
155
156
#print args
157
158
if
args.tags
or
args.logic_tags
or
args.defect_tags:
159
160
for
arg
in
DEFECT_OPTIONS:
161
if
getattr(args, arg):
162
raise
RuntimeError(
"--%s doesn't work with any --tags options"
% arg)
163
164
show_tags
(args.connection_string, args)
165
166
else
:
167
if
not
args.patterns:
168
# Default: show all
169
args.patterns = [
"*"
]
170
if
not
args.tag:
171
args.tag =
"HEAD"
172
173
if
args.logic:
174
assert
not
args.primary,
"--primary doesn't work with --logic"
175
assert
not
args.descriptions,
"--descriptions doesn't work with --logic"
176
assert
not
args.show_virtuality,
"--show-virtuality doesn't work with --logic"
177
178
arguments = args.connection_string, args.tag, args.patterns, args
179
180
show_defects_with_logic
(*arguments)
181
return
182
183
get_defects = get_both
184
if
args.primary
or
args.virtual:
185
if
args.primary
and
not
args.virtual:
186
get_defects = get_primary
187
else
:
188
get_defects = get_virtual
189
190
arguments = args.connection_string, args.tag, get_defects, args.patterns, args
191
192
if
args.descriptions:
193
show_defects_with_desc
(*arguments)
194
else
:
195
show_defects
(*arguments)
196
197
if
__name__ ==
"__main__"
:
198
main
()
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
max
#define max(a, b)
Definition
cfImp.cxx:41
dq_defect_ls.show_defects_with_desc
show_defects_with_desc(connection_string, tag, get_defects, patterns, args)
Definition
dq_defect_ls.py:50
dq_defect_ls.main
main()
Definition
dq_defect_ls.py:99
dq_defect_ls.show_tags
show_tags(connection_string, args)
Definition
dq_defect_ls.py:22
dq_defect_ls.get_virtual
get_virtual(ddb)
Definition
dq_defect_ls.py:17
dq_defect_ls.show_defects_with_logic
show_defects_with_logic(connection_string, tag, patterns, args)
Definition
dq_defect_ls.py:79
dq_defect_ls.show_defects
show_defects(connection_string, tag, get_defects, patterns, args)
Definition
dq_defect_ls.py:38
dq_defect_ls.get_primary
get_primary(ddb)
Definition
dq_defect_ls.py:15
dq_defect_ls.get_both
get_both(ddb)
Definition
dq_defect_ls.py:19
Generated on
for ATLAS Offline Software by
1.17.0