ATLAS Offline Software
Loading...
Searching...
No Matches
TrigP1TestSteps.py
Go to the documentation of this file.
2# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3#
4
5'''
6Definitions of additional validation steps in Trigger ART tests relevant only for TrigP1Test.
7The main common check steps are defined in the TrigValSteering.CheckSteps module.
8'''
9
10from TrigValTools.TrigValSteering import Step, CheckSteps
11from TrigValTools.TrigValSteering.Common import get_logger
12import os
13import inspect
14import json
15import re
16
17class TrigBSDumpGrepStep(Step.Step):
18 '''
19 Extra step based on grepping trigbs_dumpHLTContentInBS.py output
20 and comparing the line count to expected value
21 '''
22
23 def __init__(self, name='TrigBSDumpGrep'):
24 super(TrigBSDumpGrepStep, self).__init__(name)
25 self.executable = 'trigbs_dumpHLTContentInBS_run3.py'
26 self.file_name_base = 'output'
28 self.required = True
29 self.regex = ''
30 self.comparator = lambda n: n > 0
31
32 def run(self, dry_run=False):
33 if dry_run:
34 self.log.info('Skipping %s in dry run', self.name)
35 self.result = 0
36 return self.result, '# (internal) {} -> skipped'.format(self.name)
37 file_name = None
38 for ls_file in os.listdir('.'):
39 if self.file_name_base in ls_file:
40 file_name = ls_file
41 if file_name is None:
42 self.log.error('%s cannot find the BS output file', self.name)
43 self.result = 1
44 if self.auto_report_result:
45 self.report_result()
46 return self.result, '# (internal) {} -> failed'.format(self.name)
47 self.log.debug('%s found BS file %s', self.name, file_name)
48 self.args += ' ' + file_name
49 self.args += ' | grep "{}" | wc -l'.format(self.regex)
50
51 old_auto_report = self.auto_report_result
52 self.auto_report_result = False
53 ret, cmd = super(TrigBSDumpGrepStep, self).run(dry_run)
54 self.auto_report_result = old_auto_report
55
56 if ret != 0:
57 self.log.error('%s failed', self.name)
58 if self.auto_report_result:
59 self.report_result()
60 return self.result, cmd
61
62 if not os.path.isfile(self.get_log_file_name()):
63 self.log.error('%s failed, the file %s is missing',
64 self.name, self.get_log_file_name())
65 self.result = 1
66 if self.auto_report_result:
67 self.report_result()
68 return self.result, cmd
69
70 num = None
71 with open(self.get_log_file_name()) as log_file:
72 num = eval(log_file.read())
73 if not self.comparator(num) or num is None:
74 self.log.error('%s failed the comparison', self.name)
75 self.result = 1
76 if self.auto_report_result:
77 self.report_result()
78 return self.result, cmd
79
80 compare_str_list = inspect.getsource(self.comparator).split(':')
81 compare_str = ''.join(compare_str_list[1:])
82 compare_str = compare_str.strip()
83 self.log.info('Comparison %s for num=%s gives True', compare_str, num)
84 self.result = 0
85 if self.auto_report_result:
86 self.report_result()
87 return self.result, cmd
88
89
90class ExtractExpertMonitoring(CheckSteps.InputDependentStep):
91 '''
92 Step which extracts the EXPERT directory from an online monitoring file
93 produced by OH server into an offline-like expert-monitoring.root
94 '''
95 def __init__(self, name='ExtractExpertMonitoring'):
96 super(ExtractExpertMonitoring, self).__init__(name)
97 self.input_file = None
98 self.path_prefix = None
99 self.executable = 'rootcp'
100 self.args = '--recreate -r'
101 self.output_stream = Step.Step.OutputStream.STDOUT_ONLY
102
103 def configure(self, test):
104 self.args += ' {:s}:{:s}/HLT-Histogramming/*/EXPERT/* expert-monitoring.root'.format(self.input_file, self.path_prefix or '')
105 super(ExtractExpertMonitoring, self).configure(test)
106
107
108def check_hlt_properties(filename='HLTJobOptions.db.json'):
109 '''Check a few important job options in the JSON file'''
110
111 log = get_logger()
112
113 with open(filename) as f:
114 props = json.load(f)['properties']
115
116 def checkprop(comp, prop, regex):
117 value = props[comp][prop]
118 if re.match(regex, value) is None:
119 log.error('Property "%s.%s" does not match "%s". Current value: "%s"', comp, prop, regex, value)
120 return False
121 return True
122
123 checks = [
124 checkprop('IOVDbSvc', 'CacheAlign', '0'),
125 checkprop('IOVDbSvc', 'CacheRun', '0'),
126 checkprop('IOVDbSvc', 'CacheTime', '0'),
127 checkprop('AtlasFieldMapCondAlg', 'LoadMapOnStart', 'True'),
128 checkprop('IOVDbSvc', 'Folders', r'.*/TRIGGER/LUMI/HLTPrefLumi\s*<extensible/>.*'),
129 checkprop('IOVDbSvc', 'Folders', r'.*/Indet/Onl/Beampos\s*<extensible/>.*'),
130 checkprop('IOVDbSvc', 'Folders', r'.*/TRIGGER/HLT/PrescaleKey <tag>HEAD</tag>\s*<extensible/>.*'),
131 ]
132 return 0 if all(checks) else 1
133
134
135def default_check_steps_OHMon(test, hist_path):
136 steps = []
137 # Extract expert-monitoring.root file from OH server output
138 extract_hist = ExtractExpertMonitoring()
139 hist_path_split = hist_path.split(':')
140 if len(hist_path_split) > 1:
141 extract_hist.input_file = hist_path_split[0]
142 extract_hist.path_prefix = hist_path_split[1]
143 else:
144 extract_hist.input_file = hist_path
145 steps.append(extract_hist)
146 # Default check steps
147 steps.extend(CheckSteps.default_check_steps(test))
148 # Remove histogram merging step
149 matches = [step for step in steps if step.name == 'HistMerge']
150 for hm_step in matches:
151 steps.remove(hm_step)
152 return steps
153
154def filterBS(stream_name):
155 '''Extract ByteStream data for a given stream from a file with multiple streams'''
156 from TrigValTools.TrigValSteering import ExecStep
157 from TrigValTools.TrigValSteering.Common import find_file
158 filterStep = ExecStep.ExecStep('FilterBS_'+stream_name)
159 filterStep.type = 'other'
160 filterStep.executable = 'trigbs_extractStream.py'
161 filterStep.input = ''
162 filterStep.args = '-s ' + stream_name + ' ' + find_file('*_HLTMPPy_output.*.data')
163 return filterStep
164
165def decodeBS(stream_name, moduleID=0):
166 '''Deserialise HLT data from ByteStream and save to an ESD file'''
167 from TrigValTools.TrigValSteering import ExecStep
168 from TrigValTools.TrigValSteering.Common import find_file
169 decodeStep = ExecStep.ExecStep('DecodeBS_'+stream_name)
170 decodeStep.type = 'other'
171 decodeStep.executable = 'python'
172 decodeStep.input = ''
173 decodeStep.explicit_input = True
174 decodeStep.args = f'-m TrigP1Test.DecodeBS --moduleID={moduleID} --filesInput=' + find_file('*'+stream_name+'*._athenaHLT*.data')
175 return decodeStep
const bool debug
__init__(self, name='ExtractExpertMonitoring')
__init__(self, name='TrigBSDumpGrep')
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
check_hlt_properties(filename='HLTJobOptions.db.json')
default_check_steps_OHMon(test, hist_path)
decodeBS(stream_name, moduleID=0)
Definition run.py:1