ATLAS Offline Software
TrigP1TestSteps.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 '''
6 Definitions of additional validation steps in Trigger ART tests relevant only for TrigP1Test.
7 The main common check steps are defined in the TrigValSteering.CheckSteps module.
8 '''
9 
10 from TrigValTools.TrigValSteering import Step, CheckSteps
11 from TrigValTools.TrigValSteering.Common import get_logger
12 import os
13 import inspect
14 import json
15 import re
16 
17 class 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'
27  self.auto_report_result = True
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 
90 class 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 
108 def 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 
135 def 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 
154 def 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 
165 def 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
grepfile.info
info
Definition: grepfile.py:38
python.TrigP1TestSteps.ExtractExpertMonitoring.args
args
Definition: TrigP1TestSteps.py:100
python.TrigP1TestSteps.TrigBSDumpGrepStep.__init__
def __init__(self, name='TrigBSDumpGrep')
Definition: TrigP1TestSteps.py:23
python.TrigP1TestSteps.default_check_steps_OHMon
def default_check_steps_OHMon(test, hist_path)
Definition: TrigP1TestSteps.py:135
vtune_athena.format
format
Definition: vtune_athena.py:14
python.TrigP1TestSteps.TrigBSDumpGrepStep.regex
regex
Definition: TrigP1TestSteps.py:29
python.TrigP1TestSteps.check_hlt_properties
def check_hlt_properties(filename='HLTJobOptions.db.json')
Definition: TrigP1TestSteps.py:108
python.TrigP1TestSteps.TrigBSDumpGrepStep.comparator
comparator
Definition: TrigP1TestSteps.py:30
python.TrigP1TestSteps.ExtractExpertMonitoring.output_stream
output_stream
Definition: TrigP1TestSteps.py:101
python.TrigP1TestSteps.TrigBSDumpGrepStep.file_name_base
file_name_base
Definition: TrigP1TestSteps.py:26
python.TrigP1TestSteps.ExtractExpertMonitoring.path_prefix
path_prefix
Definition: TrigP1TestSteps.py:98
python.TrigP1TestSteps.ExtractExpertMonitoring
Definition: TrigP1TestSteps.py:90
python.TrigP1TestSteps.ExtractExpertMonitoring.input_file
input_file
Definition: TrigP1TestSteps.py:97
python.TrigP1TestSteps.TrigBSDumpGrepStep.auto_report_result
auto_report_result
Definition: TrigP1TestSteps.py:27
python.TrigP1TestSteps.decodeBS
def decodeBS(stream_name, moduleID=0)
Definition: TrigP1TestSteps.py:165
run
Definition: run.py:1
python.TrigP1TestSteps.TrigBSDumpGrepStep.required
required
Definition: TrigP1TestSteps.py:28
python.TrigP1TestSteps.ExtractExpertMonitoring.__init__
def __init__(self, name='ExtractExpertMonitoring')
Definition: TrigP1TestSteps.py:95
python.TrigP1TestSteps.ExtractExpertMonitoring.configure
def configure(self, test)
Definition: TrigP1TestSteps.py:103
python.DumperConfig.find_file
def find_file(fname, refPaths)
Definition: DumperConfig.py:14
python.TrigP1TestSteps.filterBS
def filterBS(stream_name)
Definition: TrigP1TestSteps.py:154
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
python.TrigP1TestSteps.TrigBSDumpGrepStep.run
def run(self, dry_run=False)
Definition: TrigP1TestSteps.py:32
python.TrigP1TestSteps.TrigBSDumpGrepStep.executable
executable
Definition: TrigP1TestSteps.py:25
Trk::open
@ open
Definition: BinningType.h:40
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:64
python.TrigValSteering.Common.get_logger
def get_logger()
Definition: Common.py:33
python.TrigP1TestSteps.ExtractExpertMonitoring.executable
executable
Definition: TrigP1TestSteps.py:99
python.TrigP1TestSteps.TrigBSDumpGrepStep.result
result
Definition: TrigP1TestSteps.py:35
error
Definition: IImpactPoint3dEstimator.h:70
python.TrigP1TestSteps.TrigBSDumpGrepStep
Definition: TrigP1TestSteps.py:17
Trk::split
@ split
Definition: LayerMaterialProperties.h:38