3 datacl = re.compile(
"^class ")
4 mbcl = re.compile(
"(base|data) class")
5 farg = re.compile(
"(.*)\(\w+\)")
6 nsep = re.compile(
"\:\:")
7 topfunc = re.compile(
"::(produce|analyze|filter|beginLuminosityBlock|beginRun)\(")
8 baseclass = re.compile(
"edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
9 getfunc = re.compile(
"edm::eventsetup::EventSetupRecord::get\((.*)&\) const")
10 handle = re.compile(
"(.*),?class edm::ES(.*)Handle<(.*)>")
14 dataclassfuncs = set()
21 flaggedclasses = set()
26 f = open(
'classes.txt.dumperft')
28 if datacl.search(line) :
29 classname = line.split(
"'")[1]
30 esdclasses.add(classname)
33 f = open(
'classes.txt.inherits')
35 if datacl.search(line) :
36 classname = line.split(
"'")[1]
37 esdclasses.add(classname)
41 f = open(
'class-checker.txt')
44 fields = line.split(
"'")
47 badclasses.add(classname)
48 badfuncs.add(funcname)
52 f = open(
'classes.txt.dumperall')
54 if mbcl.search(line) :
55 fields = line.split(
"'")
56 if fields[2] ==
' member data class ':
57 H.add_edge(fields[1],fields[3],kind=fields[2])
58 if fields[2] ==
' templated member data class ':
59 H.add_edge(fields[1],fields[3],kind=fields[2])
60 if fields[2] ==
' base class ':
61 H.add_edge(fields[1],fields[3],kind=fields[2])
68 fields = line.split(
"'")
69 if fields[2] ==
' calls function ' :
70 G.add_edge(fields[1],fields[3],kind=
' calls function ')
71 if getfunc.search(fields[3]) :
72 dataclassfuncs.add(fields[3])
73 m = getfunc.match(fields[3])
74 n = handle.match(m.group(1))
77 p = re.sub(
"class ",
"",o)
78 dataclass = re.sub(
"struct ",
"",p)
79 dataclasses.add(dataclass)
80 if fields[2] ==
' overrides function ' :
81 if baseclass.search(fields[3]) :
82 G.add_edge(fields[1],fields[3],kind=
' overrides function ')
83 if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
84 else : G.add_edge(fields[3],fields[1], kind=
' calls override function ')
85 if fields[2] ==
' static variable ' :
86 G.add_edge(fields[1],fields[3],kind=
' static variable ')
87 statics.add(fields[3])
91 for n,nbrdict
in G.adjacency_iter():
92 for nbr,eattr
in nbrdict.items():
93 if n
in badfuncs
or nbr
in badfuncs :
94 if 'kind' in eattr
and eattr[
'kind'] ==
' overrides function ' :
95 print "'"+n+
"'"+eattr[
'kind']+
"'"+nbr+
"'"
99 for n,nbrdict
in H.adjacency_iter():
100 for nbr,eattr
in nbrdict.items():
101 if n
in badclasses
and 'kind' in eattr
and eattr[
'kind'] ==
' base class ' :
105 for n,nbrdict
in H.adjacency_iter():
106 for nbr,eattr
in nbrdict.items():
107 if nbr
in dataclasses
and 'kind' in eattr
and eattr[
'kind'] ==
' base class ' :
110 print "flagged functions found by checker"
111 for dfunc
in sorted(badfuncs) :
115 print "flagged classes found by checker "
116 for dclass
in sorted(badclasses) :
120 print "flagged classes found by checker union get"
121 for dclass
in sorted(dataclasses.intersection(badclasses)) :
125 print "flagged classes found by checker union dumper"
126 for dclass
in sorted(esdclasses.intersection(badclasses)) :
130 print "classes inheriting from flagged classes"
131 for dclass
in sorted(virtclasses):
135 print "functions overridden by flagged functions"
136 for dfunc
in sorted(virtfuncs):
141 for badclass
in sorted(badclasses):
142 print "Event setup data class '"+badclass+
"' is flagged."
143 flaggedclasses.add(badclass)
146 for virtclass
in sorted(virtclasses):
147 print "Event setup data class '"+virtclass+
"' is flagged because inheriting class is flagged"
148 flaggedclasses.add(virtclass)
151 for badclass
in sorted(badclasses):
152 for dataclass
in sorted(dataclasses):
153 if H.has_node(badclass)
and H.has_node(dataclass):
154 if nx.has_path(H,dataclass, badclass) :
155 print "Event setup data class '"+dataclass+
"' contains or inherits from flagged class '"+badclass+
"'."
156 flaggedclasses.add(dataclass)
161 for dataclassfunc
in sorted(dataclassfuncs):
162 for tfunc
in sorted(toplevelfuncs):
163 if nx.has_path(G,tfunc,dataclassfunc):
164 m = getfunc.match(dataclassfunc)
165 n = handle.match(m.group(1))
166 if n : o = n.group(3)
167 else : o = m.group(1)
168 p = re.sub(
"class ",
"",o)
169 dataclass = re.sub(
"struct ",
"",p)
170 for flaggedclass
in sorted(flaggedclasses):
171 if re.search(flaggedclass,dataclass) :
172 print "Flagged event setup data class '"+dataclass+
"' is accessed in call stack '",
173 path = nx.shortest_path(G,tfunc,dataclassfunc)
177 for key
in G[tfunc].
keys() :
178 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ' :
179 print "'"+tfunc+
"'"+G[tfunc][key][
'kind']+
"'"+key+
"'",
181 print "In call stack '",
182 path = nx.shortest_path(G,tfunc,dataclassfunc)
185 print "' flagged event setup data class '"+dataclass+
"' is accessed. ",
186 for key
in G[tfunc].
keys() :
187 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ' :
188 print "'"+tfunc+
"'"+G[tfunc][key][
'kind']+
"'"+key+
"'",