ATLAS Offline Software
Classes | Functions | Variables
python.AthOptionsParser Namespace Reference

Classes

class  AthHelpFlags
 
class  AthOptionsError
 
class  JobOptAction
 
class  MemCheckAction
 

Functions

def enable_athenaCLI ()
 
def get_version ()
 
def set_environment (opts)
 
def check_tcmalloc (opts)
 
def fill_athenaCommonFlags (opts)
 
def configureCAfromArgs (acc, opts)
 
def getArgumentParser (legacy_args=False, **kwargs)
 
def _help_and_exit (reason=None)
 
def parse (legacy_args=False)
 

Variables

bool __athenaCLI = False
 

Function Documentation

◆ _help_and_exit()

def python.AthOptionsParser._help_and_exit (   reason = None)
private

Definition at line 290 of file AthOptionsParser.py.

290 def _help_and_exit(reason=None):
291  raise AthOptionsError(reason)
292 
293 

◆ check_tcmalloc()

def python.AthOptionsParser.check_tcmalloc (   opts)

Definition at line 84 of file AthOptionsParser.py.

84 def check_tcmalloc(opts):
85  libname = 'libtcmalloc' # also covers libtcmalloc_minimal.so
86  # Warn if...
87  if ( libname not in os.getenv('LD_PRELOAD','') and # tcmalloc not loaded
88  os.getenv('USETCMALLOC') in ('1', None) and # but requested (or default)
89  opts.do_leak_chk is None ): # and not disabled by leak checker
90 
91  print ('*******************************************************************************')
92  print ('WARNING: option --tcmalloc used or implied, but libtcmalloc.so not loaded.')
93  print (' This is probably because you\'re using athena.py in a non standard way')
94  print (' such as "python athena.py ..." or "nohup athena.py"')
95  print (' If you wish to use tcmalloc, you will have to manually LD_PRELOAD it')
96  print ('*******************************************************************************')
97  print ('')
98 
99 

◆ configureCAfromArgs()

def python.AthOptionsParser.configureCAfromArgs (   acc,
  opts 
)
Configure CA from relevant command line arguments if running from pkl

Definition at line 120 of file AthOptionsParser.py.

120 def configureCAfromArgs(acc, opts):
121  """Configure CA from relevant command line arguments if running from pkl"""
122 
123  if opts.interactive:
124  acc.interactive = opts.interactive
125 
126  if opts.skipEvents:
127  try:
128  acc.getService('EventSelector').SkipEvents = opts.skipEvents
129  except Exception:
130  raise AthOptionsError("--skipEvents is not supported by this CA")
131 
132  if opts.debug:
133  acc.setDebugStage(opts.debug)
134 
135  if opts.loglevel:
136  from AthenaCommon import Constants
137  acc.getService('MessageSvc').OutputLevel = getattr(Constants, opts.loglevel)
138 
139 

◆ enable_athenaCLI()

def python.AthOptionsParser.enable_athenaCLI ( )
Enable athena-specific command linea arguments

Definition at line 13 of file AthOptionsParser.py.

13 def enable_athenaCLI():
14  """Enable athena-specific command linea arguments"""
15  global __athenaCLI
16  __athenaCLI = True
17 
18 

◆ fill_athenaCommonFlags()

def python.AthOptionsParser.fill_athenaCommonFlags (   opts)

Definition at line 100 of file AthOptionsParser.py.

100 def fill_athenaCommonFlags(opts):
101  from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
102 
103  if opts.filesInput is not None:
104  import glob
105  files = []
106  for fe in opts.filesInput.split(","):
107  found = glob.glob(fe)
108  # if not found, add string directly
109  files += found if found else [fe]
110 
111  athenaCommonFlags.FilesInput.set_Value_and_Lock(files)
112 
113  if opts.evtMax is not None:
114  athenaCommonFlags.EvtMax.set_Value_and_Lock(opts.evtMax)
115 
116  if opts.skipEvents is not None:
117  athenaCommonFlags.SkipEvents.set_Value_and_Lock(opts.skipEvents)
118 
119 

◆ get_version()

def python.AthOptionsParser.get_version ( )
Version string

Definition at line 65 of file AthOptionsParser.py.

65 def get_version():
66  """Version string"""
67  from PyUtils.Helpers import release_metadata
68  return ('[%(project name)s-%(release)s] [%(platform)s] '
69  '[%(nightly name)s/%(nightly release)s] -- built on [%(date)s]' % release_metadata())
70 
71 

◆ getArgumentParser()

def python.AthOptionsParser.getArgumentParser (   legacy_args = False,
**  kwargs 
)
Create default argument parser

Definition at line 140 of file AthOptionsParser.py.

140 def getArgumentParser(legacy_args=False, **kwargs):
141  """Create default argument parser"""
142 
143  parser = argparse.ArgumentParser(formatter_class=
144  lambda prog : argparse.HelpFormatter(
145  prog, max_help_position=40, width=100),
146  add_help=False, **kwargs)
147 
148  parser.expert_groups = [] # List of expert option groups
149 
150  # --------------------------------------------------------------------------
151  g = parser.add_argument_group('Main options')
152 
153  if __athenaCLI and legacy_args:
154  g.add_argument('scripts', nargs='*', action=JobOptAction,
155  help='scripts or pickle file to run')
156 
157  g.add_argument('-l', '--loglevel', metavar='LVL', type=str.upper, default='INFO',
158  choices=['ALL', 'VERBOSE', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'FATAL'],
159  help='logging level: %(choices)s')
160 
161  g.add_argument('--filesInput', metavar='FILES',
162  help='set FilesInput property (comma-separated list with wildcards)')
163 
164  g.add_argument('--evtMax', metavar='N', type=int,
165  help='max number of events to process')
166 
167  g.add_argument('--skipEvents', metavar='N', type=int,
168  help='number of events to skip')
169 
170  g.add_argument('--nprocs', metavar='N', type=int,
171  help='enable AthenaMP if %(metavar)s>=1 or %(metavar)s==-1')
172 
173  g.add_argument('--threads', metavar='N', type=int,
174  help='number of threads for AthenaMT, threads per worker for athenaMP')
175 
176  g.add_argument('--concurrent-events', metavar='N', type=int,
177  help='number of concurrent events for AthenaMT')
178 
179  g.add_argument('--CA', action='store_true',
180  help='force ComponentAccumulator mode')
181 
182  g.add_argument('--config-only', metavar='FILE', nargs='?', default=False, const=True,
183  help='run only configuration and optionally store in %(metavar)s')
184 
185  g.add_argument('--mtes', action='store_true',
186  help='activate multi-threaded event service')
187 
188  g.add_argument('--mtes-channel', metavar='NAME', default='EventService_EventRanges',
189  help='yampl channel name between pilot and AthenaMT in event service mode')
190 
191  g.add_argument('--version', action='version', version=get_version(),
192  help='print version number')
193 
194  g.add_argument('-h', '--help', metavar='FLAGS', nargs='?', action=AthHelpFlags,
195  help='show help message (for FLAGS, "flags" for all categories)' if __athenaCLI
196  else 'show help message (for FLAGS category)')
197 
198  # --------------------------------------------------------------------------
199  g = parser.add_argument_group('Monitoring and debugging')
200 
201  g.add_argument('--perfmon', metavar='MODE', nargs='?', const='fastmonmt',
202  help='enable performance monitoring toolkit in MODE')
203 
204  g.add_argument('-i', '--interactive', nargs='?', choices=['init', 'run'], const='init',
205  help='interactive mode with optional stage (default: init)')
206 
207  g.add_argument('--profile-python', metavar='FILE',
208  help='profile python code, dump in %(metavar)s (.pkl or .txt)')
209 
210  g.add_argument('-d', '--debug', metavar='STAGE', nargs='?', const='init',
211  choices=['conf', 'init', 'exec', 'fini'],
212  help='attach debugger at stage: %(choices)s [%(const)s]')
213 
214  g.add_argument('--debugWorker', action='store_true', dest='debug_worker',
215  help='pause AthenaMP workers at bootstrap until SIGUSR1 signal received')
216 
217  g.add_argument('--leak-check', metavar='STAGE', dest='do_leak_chk', action=MemCheckAction,
218  choices=['initialize', 'start', 'beginrun', 'execute', 'finalize',
219  'endrun', 'stop', 'full', 'full-athena', 'all'],
220  help='perform basic memory leak checking, disables the use of tcmalloc.')
221 
222  g.add_argument('--delete-check', metavar='STAGE', dest='do_leak_chk', action=MemCheckAction,
223  choices=['initialize', 'start', 'beginrun', 'execute', 'finalize',
224  'endrun', 'stop', 'full', 'full-athena', 'all'],
225  help='perform double delete checking, disables the use of tcmalloc.')
226 
227  g.add_argument('--tracelevel', metavar='LEVEL', nargs='?', type=int, choices=range(1,4), const=3,
228  help='trace level for python configuration (%(choices)s)')
229 
230  # --------------------------------------------------------------------------
231  if legacy_args:
232  g = parser.add_argument_group('Legacy options')
233 
234  g.add_argument('-c', '--command', metavar='CMD',
235  help='one-liner, runs before any scripts')
236 
237  g.add_argument('--drop-and-reload', action='store_true', dest='drop_reload',
238  help='offload configuration and start new process')
239 
240  g.add_argument('--dump-configuration', metavar='FILE', dest='config_dump_file',
241  help='dump an ASCII version of the configuration to %(metavar)s')
242 
243  g.add_argument('-s', '--showincludes', action='store_true',
244  help='show printout of included files')
245 
246  # --------------------------------------------------------------------------
247  if __athenaCLI:
248  g = parser.add_argument_group('System options')
249 
250  g.add_argument('--tcmalloc', action='store_true', dest='tcmalloc', default=True,
251  help='use tcmalloc.so for memory allocation [DEFAULT]')
252 
253  g.add_argument('--stdcmalloc', action='store_false', dest='tcmalloc',
254  help='use libc malloc for memory allocation')
255 
256  g.add_argument('--stdcmath', action='store_true', default=True,
257  help='use libc malloc for memory allocation [DEFAULT]')
258 
259  g.add_argument('--imf', action='store_true',
260  help='use Intel Math Function library')
261 
262  g.add_argument('--exctrace', action='store_true',
263  help='preload exception trace collector')
264 
265  g.add_argument('--no-excabort', action='store_true',
266  help='disable converting some exceptions to abort')
267 
268  g.add_argument('--preloadlib', metavar='LIB',
269  help='localized preload of library %(metavar)s')
270 
271  g.add_argument('--enable-ers-hdlr', metavar='y/n', default='n', choices=['y','n'],
272  help='enable or not the ERS handler [%(default)s]')
273 
274  return parser
275 
276 

◆ parse()

def python.AthOptionsParser.parse (   legacy_args = False)
parses command line arguments and returns an ``Options`` instance

Definition at line 294 of file AthOptionsParser.py.

294 def parse(legacy_args=False):
295  """parses command line arguments and returns an ``Options`` instance"""
296 
297  # Everything after a single "-" is treated as "user options". This is for
298  # backwards compatibility with AthArgumentParser used in analysis.
299  # FIXME: we should revisit this and find an alternative
300  try:
301  dashpos = sys.argv.index("-")
302  except ValueError: # normal case, no isolated dash found
303  args = sys.argv[1:]
304  user_opts = []
305  else:
306  args = sys.argv[1:dashpos]
307  user_opts = sys.argv[dashpos+1:]
308 
309  parser = getArgumentParser(legacy_args)
310 
311  # perform a pre-parse without -h or --help
312  # if don't have a script, then will just re-parse with help active
313  # otherwise will effectively let script do the parsing
314  # i.e. this allows the following to work:
315  # athena MyScript.py --help
316  # to reveal the help messaging determined by MyScript.py
317  if "-h" in args or "--help" in args:
318  if "-h" in args: args.remove("-h")
319  if "--help" in args: args.remove("--help")
320  # need to unrequire any required arguments in order to do a "pre parse"
321  unrequiredActions = []
322  for a in parser._actions:
323  if a.required:
324  unrequiredActions.append(a)
325  a.required = False
326  opts, leftover = parser.parse_known_args(args)
327  for a in unrequiredActions: a.required=True
328  if not opts.scripts:
329  # no script, just run argparsing as normal, with --help as for: athena --help
330  args += ["--help"]
331  opts, leftover = parser.parse_known_args(args)
332  else:
333  opts, leftover = parser.parse_known_args(args)
334 
335  opts.user_opts = user_opts
336 
337  # If the argument parser has been extended, the script name(s) may end up
338  # in the leftovers. Try to find them there:
339  if not (opts.scripts or opts.fromdb) and leftover:
340  JobOptAction([], 'scripts')(parser, opts, leftover)
341 
342  if not (opts.scripts or opts.fromdb) and not opts.interactive:
343  parser.error("the following arguments are required: scripts")
344 
345  set_environment(opts)
346  check_tcmalloc(opts)
347 
348  return opts
349 
350 

◆ set_environment()

def python.AthOptionsParser.set_environment (   opts)
Set required envirnoment variables based on command line

Definition at line 72 of file AthOptionsParser.py.

72 def set_environment(opts):
73  """Set required envirnoment variables based on command line"""
74 
75  # user decision about TDAQ ERS signal handlers
76  if opts.enable_ers_hdlr == 'y':
77  os.unsetenv('TDAQ_ERS_NO_SIGNAL_HANDLERS')
78  else:
79  os.environ['TDAQ_ERS_NO_SIGNAL_HANDLERS'] = '1'
80 
81  os.environ['LIBC_FATAL_STDERR_'] = '1' # ATEAM-241
82 
83 

Variable Documentation

◆ __athenaCLI

bool python.AthOptionsParser.__athenaCLI = False
private

Definition at line 11 of file AthOptionsParser.py.

python.AthOptionsParser.get_version
def get_version()
Definition: AthOptionsParser.py:65
python.AthOptionsParser.getArgumentParser
def getArgumentParser(legacy_args=False, **kwargs)
Definition: AthOptionsParser.py:140
python.Helpers.release_metadata
def release_metadata()
Definition: Tools/PyUtils/python/Helpers.py:143
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.AthOptionsParser.set_environment
def set_environment(opts)
Definition: AthOptionsParser.py:72
python.AthOptionsParser._help_and_exit
def _help_and_exit(reason=None)
Definition: AthOptionsParser.py:290
python.AthOptionsParser.fill_athenaCommonFlags
def fill_athenaCommonFlags(opts)
Definition: AthOptionsParser.py:100
python.AthOptionsParser.configureCAfromArgs
def configureCAfromArgs(acc, opts)
Definition: AthOptionsParser.py:120
python.AthOptionsParser.check_tcmalloc
def check_tcmalloc(opts)
Definition: AthOptionsParser.py:84
python.AthOptionsParser.enable_athenaCLI
def enable_athenaCLI()
Definition: AthOptionsParser.py:13