14 """Enable athena-specific command linea arguments"""
20 """Check filename extension and fill relevant options"""
21 def __call__(self, parser, args, values, option_string=None):
22 scripts = [f
for f
in values
if f[-3:] ==
'.py']
23 pkls = [f
for f
in values
if f[-4:] ==
'.pkl']
25 if (scripts
and pkls)
or len(pkls)>1:
26 raise ValueError(
'Only job options or one pickle file is allowed')
28 setattr(args, self.dest, scripts)
29 args.fromdb = pkls[0]
if pkls
else None
33 """Enable Hepheastus"""
34 def __call__(self, parser, args, values, option_string=None):
36 setattr(args, self.dest,
37 []
if values==
'all' else [values])
40 import Hephaestus.MemoryTracker
as memtrack
42 if option_string==
'--delete-check':
43 args.memchk_mode =
'delete-check'
44 import Hephaestus.DeleteChecker
46 args.memchk_mode =
'leak-check'
50 """Custom help action to support flags"""
51 def __call__(self, parser, namespace, values, option_string=None):
57 sys.argv = [
'athena.py',
'--help']
59 sys.argv.append(values)
60 runpy.run_module(
'AthenaConfiguration.AthNoop', run_name=
'__main__')
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())
73 """Set required envirnoment variables based on command line"""
76 if opts.enable_ers_hdlr ==
'y':
77 os.unsetenv(
'TDAQ_ERS_NO_SIGNAL_HANDLERS')
79 os.environ[
'TDAQ_ERS_NO_SIGNAL_HANDLERS'] =
'1'
81 os.environ[
'LIBC_FATAL_STDERR_'] =
'1'
85 libname =
'libtcmalloc'
87 if ( libname
not in os.getenv(
'LD_PRELOAD',
'')
and
88 os.getenv(
'USETCMALLOC')
in (
'1',
None)
and
89 opts.do_leak_chk
is None ):
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 (
'*******************************************************************************')
101 from AthenaCommon.AthenaCommonFlags
import athenaCommonFlags
103 if opts.filesInput
is not None:
106 for fe
in opts.filesInput.split(
","):
107 found = glob.glob(fe)
109 files += found
if found
else [fe]
111 athenaCommonFlags.FilesInput.set_Value_and_Lock(files)
113 if opts.evtMax
is not None:
114 athenaCommonFlags.EvtMax.set_Value_and_Lock(opts.evtMax)
116 if opts.skipEvents
is not None:
117 athenaCommonFlags.SkipEvents.set_Value_and_Lock(opts.skipEvents)
121 """Configure CA from relevant command line arguments if running from pkl"""
124 acc.interactive = opts.interactive
128 acc.getService(
'EventSelector').SkipEvents = opts.skipEvents
133 acc.setDebugStage(opts.debug)
136 from AthenaCommon
import Constants
137 acc.getService(
'MessageSvc').OutputLevel = getattr(Constants, opts.loglevel)
141 """Create default argument parser"""
143 parser = argparse.ArgumentParser(formatter_class=
144 lambda prog : argparse.HelpFormatter(
145 prog, max_help_position=40, width=100),
146 add_help=
False, **kwargs)
148 parser.expert_groups = []
151 g = parser.add_argument_group(
'Main options')
153 if __athenaCLI
and legacy_args:
154 g.add_argument(
'scripts', nargs=
'*', action=JobOptAction,
155 help=
'scripts or pickle file to run')
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')
161 g.add_argument(
'--filesInput', metavar=
'FILES',
162 help=
'set FilesInput property (comma-separated list with wildcards)')
164 g.add_argument(
'--evtMax', metavar=
'N', type=int,
165 help=
'max number of events to process')
167 g.add_argument(
'--skipEvents', metavar=
'N', type=int,
168 help=
'number of events to skip')
170 g.add_argument(
'--nprocs', metavar=
'N', type=int,
171 help=
'enable AthenaMP if %(metavar)s>=1 or %(metavar)s==-1')
173 g.add_argument(
'--threads', metavar=
'N', type=int,
174 help=
'number of threads for AthenaMT, threads per worker for athenaMP')
176 g.add_argument(
'--concurrent-events', metavar=
'N', type=int,
177 help=
'number of concurrent events for AthenaMT')
179 g.add_argument(
'--CA', action=
'store_true',
180 help=
'force ComponentAccumulator mode')
182 g.add_argument(
'--config-only', metavar=
'FILE', nargs=
'?', default=
False, const=
True,
183 help=
'run only configuration and optionally store in %(metavar)s')
185 g.add_argument(
'--mtes', action=
'store_true',
186 help=
'activate multi-threaded event service')
188 g.add_argument(
'--mtes-channel', metavar=
'NAME', default=
'EventService_EventRanges',
189 help=
'yampl channel name between pilot and AthenaMT in event service mode')
191 g.add_argument(
'--version', action=
'version', version=
get_version(),
192 help=
'print version number')
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)')
199 g = parser.add_argument_group(
'Monitoring and debugging')
201 g.add_argument(
'--perfmon', metavar=
'MODE', nargs=
'?', const=
'fastmonmt',
202 help=
'enable performance monitoring toolkit in MODE')
204 g.add_argument(
'-i',
'--interactive', nargs=
'?', choices=[
'init',
'run'], const=
'init',
205 help=
'interactive mode with optional stage (default: init)')
207 g.add_argument(
'--profile-python', metavar=
'FILE',
208 help=
'profile python code, dump in %(metavar)s (.pkl or .txt)')
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]')
214 g.add_argument(
'--debugWorker', action=
'store_true', dest=
'debug_worker',
215 help=
'pause AthenaMP workers at bootstrap until SIGUSR1 signal received')
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.')
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.')
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)')
232 g = parser.add_argument_group(
'Legacy options')
234 g.add_argument(
'-c',
'--command', metavar=
'CMD',
235 help=
'one-liner, runs before any scripts')
237 g.add_argument(
'--drop-and-reload', action=
'store_true', dest=
'drop_reload',
238 help=
'offload configuration and start new process')
240 g.add_argument(
'--dump-configuration', metavar=
'FILE', dest=
'config_dump_file',
241 help=
'dump an ASCII version of the configuration to %(metavar)s')
243 g.add_argument(
'-s',
'--showincludes', action=
'store_true',
244 help=
'show printout of included files')
248 g = parser.add_argument_group(
'System options')
250 g.add_argument(
'--tcmalloc', action=
'store_true', dest=
'tcmalloc', default=
True,
251 help=
'use tcmalloc.so for memory allocation [DEFAULT]')
253 g.add_argument(
'--stdcmalloc', action=
'store_false', dest=
'tcmalloc',
254 help=
'use libc malloc for memory allocation')
256 g.add_argument(
'--stdcmath', action=
'store_true', default=
True,
257 help=
'use libc malloc for memory allocation [DEFAULT]')
259 g.add_argument(
'--imf', action=
'store_true',
260 help=
'use Intel Math Function library')
262 g.add_argument(
'--exctrace', action=
'store_true',
263 help=
'preload exception trace collector')
265 g.add_argument(
'--no-excabort', action=
'store_true',
266 help=
'disable converting some exceptions to abort')
268 g.add_argument(
'--preloadlib', metavar=
'LIB',
269 help=
'localized preload of library %(metavar)s')
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]')
279 import AthenaCommon.ExitCodes
as ath_codes
281 reason = ath_codes.OPTIONS_UNKNOWN
283 message = ath_codes.codes[reason]
285 message = ath_codes.codes[ath_codes.OPTIONS_UNKNOWN]
287 SystemExit.__init__(self, reason, message)
295 """parses command line arguments and returns an ``Options`` instance"""
301 dashpos = sys.argv.index(
"-")
306 args = sys.argv[1:dashpos]
307 user_opts = sys.argv[dashpos+1:]
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")
321 unrequiredActions = []
322 for a
in parser._actions:
324 unrequiredActions.append(a)
326 opts, leftover = parser.parse_known_args(args)
327 for a
in unrequiredActions: a.required=
True
331 opts, leftover = parser.parse_known_args(args)
333 opts, leftover = parser.parse_known_args(args)
335 opts.user_opts = user_opts
339 if not (opts.scripts
or opts.fromdb)
and leftover:
342 if not (opts.scripts
or opts.fromdb)
and not opts.interactive:
343 parser.error(
"the following arguments are required: scripts")
351 if __name__ ==
'__main__':
352 from pprint
import pprint
353 pprint(vars(
parse()))
354 print(
'TDAQ_ERS_NO_SIGNAL_HANDLERS', os.getenv(
'TDAQ_ERS_NO_SIGNAL_HANDLERS'))