HPS-MC
help.py
Go to the documentation of this file.
1 """! Utility script for printing help about component classes."""
2 
3 from hpsmc.component import Component
4 from hpsmc.job import Job
5 
6 # These are here so all available components appear in the globals dict.
7 from hpsmc.tools import *
8 from hpsmc.generators import *
9 
10 # These are all interfaces and not runnable components, which should be ignored.
11 _ignore = ('Component', 'EventGenerator', 'StdHepTool', 'JavaTool', 'MG')
12 
13 
15  """! Accepts Component class and prints info about it."""
16  try:
17  if isinstance(v, str):
18  obj = eval(v)()
19  v = obj.__class__
20  else:
21  obj = eval(v.__name__)()
22  print('%s(%s)' % (v.__name__, ','.join([b.__name__ for b in v.__bases__])))
23  print('')
24  print(' DESCRIPTION: \n %s' % v.__doc__.strip())
25  print('')
26  print(' REQUIRED PARAMETERS:')
27  for pname in obj.required_parameters():
28  print(' - %s' % pname)
29  print('')
30  print(' OPTIONAL PARAMETERS:')
31  for pname in obj.optional_parameters():
32  print(' - %s' % pname)
33  print('')
34  print(' CONFIG:')
35  for cname in obj.required_config():
36  print(' - %s' % cname)
37  print('')
38  try:
39  print(' APPEND TOKEN:\n %s' % obj.append_tok)
40  except BaseException:
41  pass
42  print('')
43  try:
44  print(' OUTPUT EXTENSION:\n %s' % obj.output_ext)
45  except BaseException:
46  pass
47  print('')
48  except Exception as e:
49  print(e)
50 
51 
53  """! Print info for all Component classes."""
54  print("AVAILABLE COMPONENTS: ")
55  for k in sorted(globals().keys()):
56  v = globals()[k]
57  if isinstance(v, Component.__class__):
58  if v.__name__ not in _ignore:
59  print(' {}'.format(v.__name__))
60 
61 
62 def print_job_script(script_path):
63 
64  job = Job()
65  job.script = script_path
66 
67  # Dummy parameters so certain scripts don't crash when loaded.
68  job.input_files = {'signal': 'signal',
69  'beam': 'beam'}
70  job.output_files = {'dummy.out': 'dummy.out'}
71  job.params['run_params'] = '4pt55'
72  job.params['nevents'] = 9999
73 
74  job._load_script()
75 
76  print('JOB SCRIPT: {}'.format(job.script))
77  print('')
78  print(' DESCRIPTION: {}'.format(job.description))
79  print('')
80  print(' COMPONENTS:')
81  for component in job.components:
82  print(' {}'.format(component.__class__.__name__))
83  print('')
84  print(' PTAGS:')
85  for ptag in job.ptags:
86  print(' {}'.format(ptag))
87 
88 
89 if __name__ == '__main__':
Primary class to run HPS jobs from a Python script.
Definition: job.py:160
def print_component(v)
Accepts Component class and prints info about it.
Definition: help.py:14
def print_job_script(script_path)
Definition: help.py:62
def print_components()
Print info for all Component classes.
Definition: help.py:52
Definition: job.py:1
Tools that can be used in HPSMC jobs.
Definition: tools.py:1