ATLAS Offline Software
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 79 of file han_lark_tester.py.

79 def 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>
88 std::pair<std::vector<std::string>, std::vector<std::string>> get_lib_algs() {
89 std::vector<std::string> rv1;
90 std::vector<std::string> rv2;
91 for (const auto& p : dqm_core::AlgorithmManager::instance().getAlgorithmMap()) {
92  rv1.push_back(p.first);
93 }
94 for (const auto& p : dqm_core::AlgorithmManager::instance().getSummaryMakerMap()) {
95  rv2.push_back(p.first);
96 }
97 return 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:
106  print(f'ERROR: {e}')
107  return False
108  libs = {_.children[0].value for _ in tree.find_data('libname')} # Defined libraries
109  compalgs = {_.children[0].value for _ in tree.find_data('compalgname')} # Defined composite algorithms
110 
111  # Check if the referenced libraries exist
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  # Extract the list of "base" algorithms and summaries
122  libalgos, libsummaries = ROOT.get_lib_algs()
123 
124  # Check that the composite algorithms reference existing base algorithms (and not summaries!)
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  # Check that all the instantiated algorithms and summaries refer to existing base algorithms and summaries
134  instalgos = set()
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  # These SHOULD just be summaries
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  # These SHOULD just be non-summary algos
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 

Variable Documentation

◆ grammar

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

Definition at line 74 of file han_lark_tester.py.

◆ grammarfile

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

Definition at line 71 of file han_lark_tester.py.

◆ infile

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

Definition at line 172 of file han_lark_tester.py.

◆ parser

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

Definition at line 76 of file han_lark_tester.py.

◆ transformer

han_lark_tester.transformer = T()

Definition at line 75 of file han_lark_tester.py.

◆ tree

han_lark_tester.tree = parser.parse(infile)

Definition at line 174 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:79
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25