ATLAS Offline Software
Loading...
Searching...
No Matches
python.AthOptionsParser Namespace Reference

Classes

class  JobOptAction
class  AthHelpFlags
class  AthOptionsError

Functions

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

Variables

bool __athenaCLI = False

Function Documentation

◆ _help_and_exit()

_help_and_exit ( reason = None)
protected

Definition at line 271 of file AthOptionsParser.py.

271def _help_and_exit(reason=None):
272 raise AthOptionsError(reason)
273
274

◆ check_tcmalloc()

check_tcmalloc ( opts)

Definition at line 67 of file AthOptionsParser.py.

67def check_tcmalloc(opts):
68 libname = 'libtcmalloc' # also covers libtcmalloc_minimal.so
69 # Warn if...
70 if ( libname not in os.getenv('LD_PRELOAD','') and # tcmalloc not loaded
71 os.getenv('USETCMALLOC') in ('1', None) ): # but requested (or default)
72
73 print ('*******************************************************************************')
74 print ('WARNING: option --tcmalloc used or implied, but libtcmalloc.so not loaded.')
75 print (' This is probably because you\'re using athena.py in a non standard way')
76 print (' such as "python athena.py ..." or "nohup athena.py"')
77 print (' If you wish to use tcmalloc, you will have to manually LD_PRELOAD it')
78 print ('*******************************************************************************')
79 print ('')
80
81

◆ configureCAfromArgs()

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

Definition at line 102 of file AthOptionsParser.py.

102def configureCAfromArgs(acc, opts):
103 """Configure CA from relevant command line arguments if running from pkl"""
104
105 if opts.interactive:
106 acc.interactive = opts.interactive
107
108 if opts.skipEvents:
109 try:
110 acc.getService('EventSelector').SkipEvents = opts.skipEvents
111 except Exception:
112 raise AthOptionsError("--skipEvents is not supported by this CA")
113
114 if opts.debug:
115 acc.setDebugStage(opts.debug)
116
117 if opts.loglevel:
118 from AthenaCommon import Constants
119 acc.getService('MessageSvc').OutputLevel = getattr(Constants, opts.loglevel)
120
121

◆ enable_athenaCLI()

enable_athenaCLI ( )
Enable athena-specific command linea arguments

Definition at line 13 of file AthOptionsParser.py.

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

◆ fill_athenaCommonFlags()

fill_athenaCommonFlags ( opts)

Definition at line 82 of file AthOptionsParser.py.

82def fill_athenaCommonFlags(opts):
83 from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
84
85 if opts.filesInput is not None:
86 import glob
87 files = []
88 for fe in opts.filesInput.split(","):
89 found = glob.glob(fe)
90 # if not found, add string directly
91 files += found if found else [fe]
92
93 athenaCommonFlags.FilesInput.set_Value_and_Lock(files)
94
95 if opts.evtMax is not None:
96 athenaCommonFlags.EvtMax.set_Value_and_Lock(opts.evtMax)
97
98 if opts.skipEvents is not None:
99 athenaCommonFlags.SkipEvents.set_Value_and_Lock(opts.skipEvents)
100
101

◆ get_version()

get_version ( )
Version string

Definition at line 48 of file AthOptionsParser.py.

48def get_version():
49 """Version string"""
50 from PyUtils.Helpers import release_metadata
51 return ('[%(project name)s-%(release)s] [%(platform)s] '
52 '[%(nightly name)s/%(nightly release)s] -- built on [%(date)s]' % release_metadata())
53
54

◆ getArgumentParser()

getArgumentParser ( legacy_args = False,
** kwargs )
Create default argument parser

Definition at line 122 of file AthOptionsParser.py.

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

◆ parse()

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

Definition at line 275 of file AthOptionsParser.py.

275def parse(legacy_args=False):
276 """parses command line arguments and returns an ``Options`` instance"""
277
278 # Everything after a single "-" is treated as "user options". This is for
279 # backwards compatibility with AthArgumentParser used in analysis.
280 # FIXME: we should revisit this and find an alternative
281 try:
282 dashpos = sys.argv.index("-")
283 except ValueError: # normal case, no isolated dash found
284 args = sys.argv[1:]
285 user_opts = []
286 else:
287 args = sys.argv[1:dashpos]
288 user_opts = sys.argv[dashpos+1:]
289
290 parser = getArgumentParser(legacy_args)
291
292 # perform a pre-parse without -h or --help
293 # if don't have a script, then will just re-parse with help active
294 # otherwise will effectively let script do the parsing
295 # i.e. this allows the following to work:
296 # athena MyScript.py --help
297 # to reveal the help messaging determined by MyScript.py
298 doHelp = any(a in ('-h', '--help') or a.startswith('--help=') for a in args)
299 if doHelp:
300 # need to unrequire any required arguments in order to do a "pre-parse"
301 unrequiredActions = []
302 for a in parser._actions:
303 if a.required:
304 unrequiredActions.append(a)
305 a.required = False
306
307 # remove the help actions for the "pre-parse"
308 helpActions = {'-h' : parser._option_string_actions.pop('-h'),
309 '--help' : parser._option_string_actions.pop('--help')}
310
311 # parse with the modified parser
312 opts, leftover = parser.parse_known_args(args)
313
314 # restore original settings
315 parser._option_string_actions.update(helpActions)
316 for a in unrequiredActions:
317 a.required = True
318
319 # no script, just run argparsing as normal
320 if not opts.scripts:
321 opts, leftover = parser.parse_known_args(args)
322 else:
323 opts, leftover = parser.parse_known_args(args)
324
325 opts.user_opts = user_opts
326
327 # If the argument parser has been extended, the script name(s) may end up
328 # in the leftovers. Try to find them there:
329 if not (opts.scripts or opts.fromdb) and leftover:
330 JobOptAction([], 'scripts')(parser, opts, leftover)
331
332 if not (opts.scripts or opts.fromdb) and not opts.interactive:
333 parser.error("the following arguments are required: scripts")
334
335 # Deprecation warning:
336 if opts.CA:
337 print(f"{os.path.basename(sys.argv[0])}: Warning: --CA is deprecated."
338 + f" Add a shebang (#!) to {opts.scripts[0]} to enable CA mode." if opts.scripts else "",
339 file=sys.stderr)
340
341 set_environment(opts)
342 check_tcmalloc(opts)
343
344 return opts
345
346
void print(char *figname, TCanvas *c1)
std::map< std::string, std::string, std::less<> > parse(const std::string &list)

◆ set_environment()

set_environment ( opts)
Set required envirnoment variables based on command line

Definition at line 55 of file AthOptionsParser.py.

55def set_environment(opts):
56 """Set required envirnoment variables based on command line"""
57
58 # user decision about TDAQ ERS signal handlers
59 if opts.enable_ers_hdlr == 'y':
60 os.unsetenv('TDAQ_ERS_NO_SIGNAL_HANDLERS')
61 else:
62 os.environ['TDAQ_ERS_NO_SIGNAL_HANDLERS'] = '1'
63
64 os.environ['LIBC_FATAL_STDERR_'] = '1' # ATEAM-241
65
66

Variable Documentation

◆ __athenaCLI

bool python.AthOptionsParser.__athenaCLI = False
private

Definition at line 11 of file AthOptionsParser.py.