2 from __future__
import print_function
6 from yaml
import load, dump, FullLoader
8 from yaml
import CLoader
as Loader, CDumper
as Dumper
10 from yaml
import Loader, Dumper
12 topfunc =
r"::(accumulate|acquire|startingNewLoop|duringLoop|endOfLoop|beginOfJob|endOfJob|produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream|streamBeginRun|streamBeginLuminosityBlock|streamEndRun|streamEndLuminosityBlock|globalBeginRun|globalEndRun|globalBeginLuminosityBlock|globalEndLuminosityBlock|endRun|endLuminosityBlock)\("
13 topfuncre = re.compile(topfunc)
15 baseclass =
r"\b(edm::)?(one::|stream::|global::)?((DQM)?(Global|One)?ED(Producer|Filter|Analyzer|(IterateNTimes|NavigateEvents)?Looper)(Base)?|impl::(ExternalWork|Accumulator|RunWatcher|RunCacheHolder))\b"
16 baseclassre = re.compile(baseclass)
17 assert(baseclassre.match(
'edm::global::EDFilter::filter() virtual'))
18 assert(topfuncre.search(
'edm::global::EDFilterBase::filter(&) const virtual'))
20 farg = re.compile(
r"\(.*?\)")
21 tmpl = re.compile(
r'<.*?>')
24 epfuncre = re.compile(
r"edm::eventsetup::EventSetupRecord::get<(class|struct) edm::ES(Transient)?Handle<(class|struct) .*>>\((const char \*, |const std::string &, )(class|struct) edm::ES(Transient)?Handle<(class|struct).*> &\) const")
25 f=
'edm::eventsetup::EventSetupRecord::get<class edm::ESHandle<class CaloTopology>>(const std::string &, class edm::ESHandle<class CaloTopology> &) const'
28 skipfunc = re.compile(
r"TGraph::IsA\(.*\)")
31 function=
'(anonymous namespace in /src/RecoTracker/TkHitPairs/plugins/HitPairEDProducer.cc)::Impl<(anonymous namespace)::ImplSeedingHitSets, (anonymous namespace)::DoNothing, (anonymous namespace)::RegionsLayersSeparate>::produce(const _Bool, edm::Event &, const edm::EventSetup &);'
32 function2=
'HitPairEDProducer::produce(edm::Event &, const edm::EventSetup &);'
33 value=
'HitPairEDProducer'
34 valuere=
r'\b%s\b' % value
35 vre=re.compile(valuere)
36 m=vre.search(function)
38 m2=vre.search(function2)
42 with open(
'modules_in_ib.txt',
'r')
as m:
44 modules.append(line.strip())
46 mods_regex=
r'\b(' + mods+
r'QQQQQQQQ)\b'
47 comp_mods_regex=re.compile(mods_regex)
48 n=comp_mods_regex.search(function)
50 n2=comp_mods_regex.search(function2)
53 module2package = dict()
54 with open(
'module_to_package.yaml')
as m:
55 module2package=
load(m, Loader=FullLoader)
57 with open(
'packages.json',
'r')
as j:
61 module=k.split(
'|')[0]
63 package=dirs[0]+
'/'+dirs[1]
64 module2package.setdefault(package, []).
append(module)
66 for k
in module2package.keys():
67 module2package[k]=sorted(set(module2package[k]))
70 with open(
'function-calls-db.txt')
as f:
72 fields = line.split(
"'")
75 if fields[2] ==
' calls function ':
76 G.add_edge(fields[1], fields[3], kind=fields[2])
77 if epfuncre.search(fields[3]):
78 epfuncs.add(fields[3])
79 if fields[2] ==
' overrides function ':
80 if baseclassre.match(fields[3]):
81 G.add_edge(fields[1], fields[3], kind=
' overrides function ')
82 if topfuncre.search(fields[1])
and comp_mods_regex.search(fields[1]):
83 toplevelfuncs.add(fields[1])
85 G.add_edge(fields[3], fields[1], kind=
' overriden function calls function ')
86 if epfuncre.search(fields[3]):
87 epfuncs.add(fields[3])
90 for tfunc
in toplevelfuncs:
91 for epfunc
in epfuncs:
92 if G.has_node(tfunc)
and G.has_node(epfunc)
and nx.has_path(G, tfunc, epfunc):
93 for path
in nx.all_shortest_paths(G, tfunc, epfunc):
101 if previous != stripped:
102 cs += stripped +
'; '
104 if cs
not in callstacks:
108 for key
in sorted(set(module2package.keys())):
109 for value
in sorted(set(module2package[key])):
110 if comp_mods_regex.match(value):
111 regex_str =
r'\b%s\b'%value
112 vre=re.compile(regex_str)
113 for callstack
in sorted(callstacks):
114 if vre.search(callstack):
115 report.setdefault(
str(key), {}).setdefault(
str(value), []).
append(
str(callstack))
117 r = open(
'eventsetuprecord-get.yaml',
'w')