ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.TrigValSteering.Test.Test Class Reference
Inheritance diagram for python.TrigValSteering.Test.Test:
Collaboration diagram for python.TrigValSteering.Test.Test:

Public Member Functions

def __init__ (self)
 
def configure (self)
 
def run (self)
 
def run_steps (self, steps, commands_list, exec_status=0)
 
def configure_timeout (self)
 
def configure_name (self)
 
def duplicate_step_names (self)
 
def configuration_error (self, message)
 
def get_step (self, step_name)
 
def get_step_by_type (self, step_type)
 
def pre_exec (self)
 

Public Attributes

 log
 
 name
 
 package_name
 
 art_type
 
 exec_steps
 
 check_steps
 
 dry_run
 
 configured
 

Detailed Description

Definition of a Trigger ART test to be configured and executed

Definition at line 18 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TrigValSteering.Test.Test.__init__ (   self)

Definition at line 20 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

20  def __init__(self):
21  self.log = get_logger()
22  self.name = None
23  self.package_name = None
24  self.art_type = None
25  self.exec_steps = []
26  self.check_steps = []
27  self.dry_run = None
28  self.configured = False
29 

Member Function Documentation

◆ configuration_error()

def python.TrigValSteering.Test.Test.configuration_error (   self,
  message 
)

Definition at line 199 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

199  def configuration_error(self, message):
200  self.log.error(message)
201  art_result(1, 'TestConfig')
202  sys.exit(1)
203 

◆ configure()

def python.TrigValSteering.Test.Test.configure (   self)

Definition at line 30 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

30  def configure(self):
31  # Configure name
32  self.configure_name()
33  self.log.info("Configuring test %s", self.name)
34 
35  # Configure timeout for all steps
36  self.configure_timeout()
37 
38  # Configure steps
39  for step in self.exec_steps:
40  step.configure(self)
41  for step in self.check_steps:
42  self.log.debug('Configuring check step %s', step.name)
43  step.configure(self)
44 
45  duplicate_names = self.duplicate_step_names()
46  if len(duplicate_names) > 0:
47  self.configuration_error(
48  'Found test steps with duplicate names: '
49  '{}'.format(duplicate_names)+' Aborting because this'
50  ' configuration could lead to overwriting logs')
51 
52  # Configure dry_run option
53  if self.dry_run is None:
54  # A hook to use dry_run for unit tests
55  env = os.environ.get('TRIGVALSTEERING_DRY_RUN')
56  if env:
57  self.dry_run = True
58 
59  self.configured = True
60 
61  # Print configuration
62  self.log.debug(
63  'Test configuration complete:\n-- %s',
64  '\n-- '.join(['{}: {}'.format(k, v) for k, v in self.__dict__.items()]))
65 

◆ configure_name()

def python.TrigValSteering.Test.Test.configure_name (   self)

Definition at line 153 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

153  def configure_name(self):
154  filename = os.path.basename(sys.argv[0])
155  self.log.debug('Parsing file name %s', filename)
156  prefix = 'test_'
157  suffix = '.py'
158  if not filename.startswith(prefix) or not filename.endswith(suffix):
159  self.configuration_error(
160  'Test file name {} does not match '.format(filename) +
161  'the required pattern {}*{}'.format(prefix, suffix))
162  for package_name, package_prefix in package_prefix_dict.items():
163  if filename.startswith(prefix+package_prefix):
164  self.package_name = package_name
165  this_package_prefix = package_prefix
166  if self.package_name is None:
167  self.configuration_error(
168  'Test file name {} could not be matched '.format(filename) +
169  'to any of the required package prefixes: {}'.format(
170  package_prefix_dict.values()))
171  if not self.art_type or self.art_type not in ['build', 'grid']:
172  self.configuration_error(
173  'Incorrect test art_type = {:s}, only "build" and "grid" are supported'.format(self.art_type))
174  if not filename.endswith('_' + self.art_type + suffix) and \
175  self.package_name != "TrigInDetValidation": # TIDV is exempt from this rule
176  self.configuration_error(
177  'Test file name does not match the art_type="{:s}". '.format(self.art_type) +
178  'Expected name {:s}'.format(prefix+this_package_prefix+'*_'+self.art_type+suffix))
179  max_len = 50
180  if len(filename) > max_len:
181  self.configuration_error(
182  'Test file name is too long. The limit is {} '.format(max_len) +
183  'characters, but it has {}'.format(len(filename)))
184  self.name = filename[len(prefix):-len(suffix)]
185 

◆ configure_timeout()

def python.TrigValSteering.Test.Test.configure_timeout (   self)
Set default timeout values for steps which don't have it set

Definition at line 142 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

142  def configure_timeout(self):
143  '''Set default timeout values for steps which don't have it set'''
144  for exec_step in self.exec_steps:
145  if exec_step.timeout is None:
146  # 12h for grid tests, 1h for build tests
147  exec_step.timeout = 12*3600 if self.art_type == 'grid' else 3600
148  for check_step in self.check_steps:
149  if check_step.timeout is None:
150  # 5 min for all check steps
151  check_step.timeout = 5*60
152 

◆ duplicate_step_names()

def python.TrigValSteering.Test.Test.duplicate_step_names (   self)

Definition at line 186 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

186  def duplicate_step_names(self):
187  d = {}
188  for step in self.exec_steps:
189  d.setdefault(step.name, 0)
190  d[step.name] += 1
191  for step in self.check_steps:
192  d.setdefault(step.name, 0)
193  d[step.name] += 1
194  duplicates = [name for name, count in d.items() if count > 1]
195  self.log.debug('all steps: %s', d)
196  self.log.debug('duplicates: %s', duplicates)
197  return duplicates
198 

◆ get_step()

def python.TrigValSteering.Test.Test.get_step (   self,
  step_name 
)

Definition at line 204 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

204  def get_step(self, step_name):
205  step = get_step_from_list(step_name, self.exec_steps)
206  if step is None:
207  step = get_step_from_list(step_name, self.check_steps)
208  return step
209 

◆ get_step_by_type()

def python.TrigValSteering.Test.Test.get_step_by_type (   self,
  step_type 
)

Definition at line 210 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

210  def get_step_by_type(self, step_type):
211  step = get_step_type_from_list(step_type, self.exec_steps)
212  if step is None:
213  step = get_step_type_from_list(step_type, self.check_steps)
214  return step
215 

◆ pre_exec()

def python.TrigValSteering.Test.Test.pre_exec (   self)
Extra pre-exec function executed just before the steps

Definition at line 216 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

216  def pre_exec(self):
217  '''Extra pre-exec function executed just before the steps'''
218  cmd_list = []
219  # Create empty POOL File Catalog to avoid incorrect grid failure handling
220  if self.art_type == 'grid':
221  cmd = 'which art.py >/dev/null 2>&1'
222  art_available = subprocess.call(cmd, shell=True)
223  if art_available == 0:
224  cmd = 'art.py createpoolfile'
225  self.log.debug('Executing pre-exec command %s', cmd)
226  subprocess.call(cmd, shell=True)
227  cmd_list.append(cmd)
228  return cmd_list

◆ run()

def python.TrigValSteering.Test.Test.run (   self)

Definition at line 66 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

66  def run(self):
67  if not self.configured:
68  self.configure()
69 
70  self.log.info("Running test %s", self.name)
71 
72  # Clear the result summary log
74 
75  # Store the executed commands
76  commands = {}
77 
78  # Pre-exec - a useful hook for some workarounds
79  pre_exec_cmd = self.pre_exec()
80  if len(pre_exec_cmd) > 0:
81  commands['pre_exec'] = pre_exec_cmd
82 
83  commands['exec_steps'] = []
84  commands['check_steps'] = []
85 
86  # Run the exec steps
87  self.run_steps(self.exec_steps, commands['exec_steps'])
88 
89  # Make a summary result code for all exec steps if there are multiple
90  exec_summary = 0
91  if len(self.exec_steps) > 1:
92  for step in self.exec_steps:
93  if step.result > exec_summary:
94  exec_summary = step.result
95  if exec_summary > 0:
96  self.log.info('At least one of the exec steps failed, using the largest code as ExecSummary')
97  else:
98  self.log.info('All exec steps succeeded')
99  art_result(exec_summary, 'ExecSummary')
100  elif len(self.exec_steps) == 1:
101  exec_summary = self.exec_steps[0].result
102 
103  # Run the check steps
104  self.run_steps(self.check_steps, commands['check_steps'], exec_status=exec_summary)
105 
106  # Dump all commands to JSON
107  with open('commands.json', 'w') as outfile:
108  json.dump(commands, outfile, indent=4)
109 
110  # Create the exit code and message from required steps
111  exit_code = 0
112  failed_required_steps = []
113  for step in self.exec_steps + self.check_steps:
114  if step.required and (step.result != 0):
115  self.log.debug('Required step %s finished with result %s', step.name, step.result)
116  failed_required_steps.append(step.name)
117  if abs(step.result) > exit_code:
118  exit_code = abs(step.result)
119  exit_msg = 'Test {:s} finished with code {:d}'.format(self.name, exit_code)
120  if exit_code == 0:
121  exit_msg += ' because all required steps were successful'
122  else:
123  exit_msg += ' because the following required steps failed: {:s}'.format(str(failed_required_steps))
124  self.log.info(exit_msg)
125  return exit_code
126 

◆ run_steps()

def python.TrigValSteering.Test.Test.run_steps (   self,
  steps,
  commands_list,
  exec_status = 0 
)

Definition at line 127 of file Trigger/TrigValidation/TrigValTools/python/TrigValSteering/Test.py.

127  def run_steps(self, steps, commands_list, exec_status=0):
128  previous_code = 0
129  for step in steps:
130  if (previous_code != 0 and step.depends_on_previous) or \
131  (exec_status != 0 and step.depends_on_exec):
132  self.log.error('Skipping step %s because previous step(s) failed', step.name)
133  step.result = 1
134  code, cmd = step.result, '# Skipped {} because of earlier failure'.format(step.name)
135  if step.auto_report_result:
136  step.report_result()
137  continue
138  code, cmd = step.run(self.dry_run)
139  previous_code = code
140  commands_list.append(cmd)
141 

Member Data Documentation

◆ art_type

python.TrigValSteering.Test.Test.art_type

◆ check_steps

python.TrigValSteering.Test.Test.check_steps

◆ configured

python.TrigValSteering.Test.Test.configured

◆ dry_run

python.TrigValSteering.Test.Test.dry_run

◆ exec_steps

python.TrigValSteering.Test.Test.exec_steps

◆ log

python.TrigValSteering.Test.Test.log

◆ name

python.TrigValSteering.Test.Test.name

◆ package_name

python.TrigValSteering.Test.Test.package_name

The documentation for this class was generated from the following file:
vtune_athena.format
format
Definition: vtune_athena.py:14
configure
bool configure(asg::AnaToolHandle< ITrigGlobalEfficiencyCorrectionTool > &tool, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronEffToolsHandles, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronSFToolsHandles, ToolHandleArray< CP::IMuonTriggerScaleFactors > &muonToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonEffToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonSFToolsHandles, const std::string &triggers, const std::map< std::string, std::string > &legsPerTool, unsigned long nToys, bool debug)
Definition: TrigGlobEffCorrValidation.cxx:514
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
python.TrigValSteering.Step.get_step_from_list
def get_step_from_list(step_name, step_list)
Definition: Step.py:230
python.TrigValSteering.Common.clear_art_summary
def clear_art_summary()
Definition: Common.py:51
python.TrigValSteering.Step.get_step_type_from_list
def get_step_type_from_list(step_type, step_list)
Definition: Step.py:241
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
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:71
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
python.TrigValSteering.Common.get_logger
def get_logger()
Definition: Common.py:33
str
Definition: BTagTrackIpAccessor.cxx:11
python.TrigValSteering.Common.art_result
def art_result(result, name)
Definition: Common.py:42
error
Definition: IImpactPoint3dEstimator.h:70
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87