Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Classes | Functions | Variables
han_lark_tester Namespace Reference

Classes

class  AlgorithmNameInterpreter
 
class  T
 

Functions

def algorithm_check (tree)
 

Variables

 grammarfile = find_datafile('DataQualityInterfaces/han_def.lark')
 
 grammar = open(grammarfile).read()
 
 transformer = T()
 
 parser = lark.Lark(grammar, parser='lalr', lexer='contextual', transformer=transformer)
 
 infile = open(sys.argv[1]).read()
 
 tree = parser.parse(infile)
 

Function Documentation

◆ algorithm_check()

def han_lark_tester.algorithm_check (   tree)

Definition at line 80 of file han_lark_tester.py.

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

Variable Documentation

◆ grammar

han_lark_tester.grammar = open(grammarfile).read()

Definition at line 75 of file han_lark_tester.py.

◆ grammarfile

han_lark_tester.grammarfile = find_datafile('DataQualityInterfaces/han_def.lark')

Definition at line 72 of file han_lark_tester.py.

◆ infile

han_lark_tester.infile = open(sys.argv[1]).read()

Definition at line 173 of file han_lark_tester.py.

◆ parser

han_lark_tester.parser = lark.Lark(grammar, parser='lalr', lexer='contextual', transformer=transformer)

Definition at line 77 of file han_lark_tester.py.

◆ transformer

han_lark_tester.transformer = T()

Definition at line 76 of file han_lark_tester.py.

◆ tree

han_lark_tester.tree = parser.parse(infile)

Definition at line 175 of file han_lark_tester.py.

histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
han_lark_tester.algorithm_check
def algorithm_check(tree)
Definition: han_lark_tester.py:80
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25