79def algorithm_check(tree):
80 import ROOT
81 import cppyy
82
83 ROOT.gSystem.Load('libdqm_core.so')
84 cppyy.include("dqm_core/AlgorithmManager.h")
85
86 cppyy.cppdef(r"""
87#include <dqm_core/AlgorithmManager.h>
88std::pair<std::vector<std::string>, std::vector<std::string>> get_lib_algs() {
89std::vector<std::string> rv1;
90std::vector<std::string> rv2;
91for (const auto& p : dqm_core::AlgorithmManager::instance().getAlgorithmMap()) {
92 rv1.push_back(p.first);
93}
94for (const auto& p : dqm_core::AlgorithmManager::instance().getSummaryMakerMap()) {
95 rv2.push_back(p.first);
96}
97return std::move(std::make_pair(rv1, rv2));
98}
99"""
100 )
101
102 rv = True
103 try:
104 AlgorithmNameInterpreter().visit(tree)
105 except ValueError as e:
107 return False
108 libs = {_.children[0].value for _ in tree.find_data('libname')}
109 compalgs = {_.children[0].value for _ in tree.find_data('compalgname')}
110
111
112 for lib in libs:
113 if ROOT.gSystem.Load(lib) < 0:
114 rv = False
115 print(f
'ERROR: Library {lib} defined by a libname clause cannot be found. Referenced by:')
116 for alg in tree.find_data('algorithmblock'):
117 alibname = alg.find_data('libname')
118 if alibname and lib in {_.children[0].value for _ in alibname}:
119 print(list(alg.find_data(
'algorithmname'))[0].children[0].value)
120
121
122 libalgos, libsummaries = ROOT.get_lib_algs()
123
124
125 for alg in tree.find_data('compalgblock'):
126 subalglist = [_ for _ in alg.children if _.data == 'subalglist']
127 for tok in subalglist[0].children:
128 if tok.value not in libalgos:
129 algname = list(alg.find_data('compalgname'))[0].children[0].value
130 print(f
'ERROR: composite algorithm {algname} references {tok.value} which is not a known algorithm')
131 rv = False
132
133
135 instsummaries =
set()
136 for alg in tree.find_data('algorithmblock'):
137 try:
138 algname = [_.children[0].value for _ in alg.children if isinstance(_, lark.Tree) and _.data == "algorithmname"][0]
139 algrealname = [_.children[0].value for _ in alg.children if isinstance(_, lark.Tree) and _.data == "realname"][0]
140 if algrealname in libalgos:
141 instalgos.add(algname)
142 elif algrealname in libsummaries:
143 instsummaries.add(algname)
144 elif algrealname in compalgs:
145 instalgos.add(algname)
146 else:
147 print(f
'ERROR: undefined base algorithm {algrealname} for {algname}')
148 rv = False
149 except Exception as e:
150 print(
'??? problem processing', alg, e)
151
152
153 for ref in tree.find_data('algorefstatement'):
154 nodealg = ref.children[0].children[0].value
155 if nodealg not in instsummaries:
156 print(f
'ERROR: an output is specifying algorithm = {nodealg} which is not a known summary algorithm')
157 rv = False
158
159
160 for ref in list(tree.find_data('dirblock')) + list(tree.find_data('histblock')):
161 nodealg = [_ for _ in ref.children if _.data == 'algorithmreference']
162 if nodealg:
163 nodealgname = nodealg[0].children[0].value
164 if nodealgname not in instalgos:
165 refname = [_ for _ in ref.children if _.data in ('histname', 'dirname')][0].children[0].value
166 print(f
'ERROR: a dir/hist is specifying algorthm = {nodealgname} which is not a known histogram algorithm. Referenced by {refname}')
167 rv = False
168
169 return rv
170
171
void print(char *figname, TCanvas *c1)