2 from __future__
import print_function
6 datacl = re.compile(
"^class ")
7 bfunc = re.compile(
"^function ")
8 mbcl = re.compile(
"(base|data) class")
9 farg = re.compile(
r"(.*)\(\w+\)")
10 nsep = re.compile(
r"\:\:")
12 r"::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream)\(")
13 baseclass = re.compile(
14 r"edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
16 r"edm::eventsetup::EventSetupRecord::get<.*>\((.*)&\) const")
17 handle = re.compile(
"(.*),?class edm::ES(.*)Handle<(.*)>")
19 "edm::serviceregistry::ServicesManager::MakerHolder::add() const")
23 dataclassfuncs = set()
31 flaggedclasses = set()
35 f = open(
'classes.txt.dumperft')
37 if datacl.search(line):
38 classname = line.split(
"'")[1]
39 dclasses.add(classname)
42 f = open(
'classes.txt.inherits')
44 if datacl.search(line):
45 classname = line.split(
"'")[1]
46 dataclasses.add(classname)
50 f = open(
'class-checker.txt')
53 fields = line.split(
"'")
56 badclasses.add(classname)
57 badfuncs.add(funcname)
61 f = open(
'classes.txt.dumperall')
64 fields = line.split(
"'")
65 if fields[2] ==
' member data class ':
66 H.add_edge(fields[1], fields[3], kind=fields[2])
67 if fields[2] ==
' templated member data class ':
68 H.add_edge(fields[1], fields[3], kind=fields[2])
69 if fields[2] ==
' base class ':
70 H.add_edge(fields[1], fields[3], kind=fields[2])
74 for line
in fileinput.input(files=(
'function-statics-db.txt',
'function-calls-db.txt')):
75 if not bfunc.search(line):
77 fields = line.split(
"'")
78 if skip.search(fields[1])
or skip.search(fields[3]):
80 if fields[2] ==
' calls function ':
81 G.add_edge(fields[1], fields[3], kind=
' calls function ')
82 if getfunc.search(fields[3]):
83 dataclassfuncs.add(fields[3])
84 m = getfunc.match(fields[3])
85 n = handle.match(m.group(1))
90 p = re.sub(
"class ",
"", o)
91 dataclass = re.sub(
"struct ",
"", p)
92 dataclasses.add(dataclass)
93 if fields[2] ==
' overrides function ':
94 if baseclass.search(fields[3]):
95 G.add_edge(fields[1], fields[3], kind=
' overrides function ')
96 if topfunc.search(fields[3]):
97 toplevelfuncs.add(fields[1])
99 G.add_edge(fields[3], fields[1], kind=
' calls override function ')
100 if fields[2] ==
' static variable ':
101 G.add_edge(fields[1], fields[3], kind=
' static variable ')
102 statics.add(fields[3])
105 for n, nbrdict
in G.adjacency():
106 for nbr, eattr
in nbrdict.items():
107 if n
in badfuncs
or nbr
in badfuncs:
108 if 'kind' in eattr
and eattr[
'kind'] ==
' overrides function ':
109 print(
"'"+n+
"'"+eattr[
'kind']+
"'"+nbr+
"'")
113 for n, nbrdict
in H.adjacency():
114 for nbr, eattr
in nbrdict.items():
115 if n
in badclasses
and 'kind' in eattr
and eattr[
'kind'] ==
' base class ':
119 for n, nbrdict
in H.adjacency():
120 for nbr, eattr
in nbrdict.items():
121 if nbr
in dclasses
and 'kind' in eattr
and eattr[
'kind'] ==
' base class ':
124 print(
"flagged functions found by checker")
125 for dfunc
in sorted(badfuncs):
129 print(
"flagged classes found by checker ")
130 for dclass
in sorted(badclasses):
134 print(
"flagged classes found by checker union get")
135 for dclass
in sorted(dclasses.intersection(badclasses)):
140 print(
"classes inheriting from flagged classes")
141 for dclass
in sorted(virtclasses):
145 print(
"functions overridden by flagged functions")
146 for dfunc
in sorted(virtfuncs):
151 for badclass
in sorted(badclasses):
152 print(
"Event setup data class '"+badclass+
"' is flagged.")
153 flaggedclasses.add(badclass)
156 for virtclass
in sorted(virtclasses):
157 print(
"Event setup data class '"+virtclass +
158 "' is flagged because inheriting class is flagged")
159 flaggedclasses.add(virtclass)
162 for badclass
in sorted(badclasses):
163 for dataclass
in sorted(dataclasses):
164 if H.has_node(badclass)
and H.has_node(dataclass):
165 if nx.has_path(H, dataclass, badclass):
166 print(
"Event setup data class '" + dataclass +
167 "' contains or inherits from flagged class '" + badclass +
"'.")
168 flaggedclasses.add(dataclass)
173 for dataclassfunc
in sorted(dataclassfuncs):
174 for tfunc
in sorted(toplevelfuncs):
175 if G.has_node(tfunc)
and G.has_node(dataclassfunc)
and nx.has_path(G, tfunc, dataclassfunc):
176 m = getfunc.match(dataclassfunc)
177 n = handle.match(m.group(1))
182 p = re.sub(
"class ",
"", o)
183 q = re.sub(
"struct ",
"", p)
184 dataclass = re.sub(
r"<.*> ",
"", q)
185 for flaggedclass
in sorted(flaggedclasses):
186 exact =
r"^" + re.escape(flaggedclass) +
r"$" 187 exactmatch = re.match(exact, dataclass)
189 print(
"Flagged event setup data class '"+dataclass +
190 "' is accessed in call stack '", end=
' ')
191 path = nx.shortest_path(G, tfunc, dataclassfunc)
193 print(p+
"; ", end=
' ')
195 for key
in G[tfunc].
keys():
196 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ':
197 print(
"'"+tfunc+
"'"+G[tfunc][key]
198 [
'kind']+
"'"+key+
"'", end=
' ')
200 print(
"In call stack '", end=
' ')
201 path = nx.shortest_path(G, tfunc, dataclassfunc)
203 print(p+
"; ", end=
' ')
204 print(
"' flagged event setup data class '" +
205 dataclass+
"' is accessed. ", end=
' ')
206 for key
in G[tfunc].
keys():
207 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ':
208 print(
"'"+tfunc+
"'"+G[tfunc][key]
209 [
'kind']+
"'"+key+
"'", end=
' ')
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)