Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix k4run -l #126

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions k4FWCore/scripts/k4run
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python

from __future__ import print_function
import os
import sys
import argparse
from multiprocessing import cpu_count
import logging


# these default properties are filtered as otherwise they will clutter the argument list
FILTER_GAUDI_PROPS = [ "ContextService", "Cardinality", "Context", "CounterList", "EfficiencyRowFormat",
"Enable", "ErrorCount", "ErrorMax", "ErrorsPrint", "ExtraInputs", "ExtraOutputs",
Expand All @@ -25,12 +23,21 @@ seen_files = set()
option_db = {}


# There is no way of knowing if parse_known_args() or parse_args() was called
# so we'll track wether this is the first parsing or not
first_run = True
class LoadFromFile(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
global first_run
if not values:
print('Error: missing gaudi options file.\n'
'Usage: k4run <options_file.py>, use --help to get a complete list of arguments')
sys.exit(1)
if not first_run:
print('Error: missing gaudi options file.\n'
'Usage: k4run <options_file.py>, use --help to get a complete list of arguments')
sys.exit(1)
first_run = False
return
first_run = False

for wrapper in values:
if wrapper.name in seen_files:
return
Expand Down Expand Up @@ -111,16 +118,12 @@ if __name__ == "__main__":
help="Start Gaudi in parallel mode using NCPUS processes. "
"0 => serial mode (default), -1 => use all CPUs")

# Once to parse the files and another time to have the new parameters
# Once to parse the files and another time below to have the new parameters
# in the namespace since parsing of the file happens when the namespace
# has already been filled
opts = parser.parse_known_args()
opts = parser.parse_args()

# print a doc line showing the configured algorithms
logger.info(' '.join(f'--> {alg.name()}' for alg in ApplicationMgr().TopAlg))

if opts.list:
if opts[0].list:
from Gaudi import Configuration
cfgDb = Configuration.cfgDb
logger.info("Available components:\n%s", (21 * "="))
Expand All @@ -136,6 +139,11 @@ if __name__ == "__main__":
print(" %s (from %s)" % (item, cfgDb[item]["lib"]))
sys.exit()

opts = parser.parse_args()

# print a doc line showing the configured algorithms
logger.info(' '.join(f'--> {alg.name()}' for alg in ApplicationMgr().TopAlg))

opts_dict = vars(opts)
for optionName, propTuple in option_db.items():
logger.info("Option name: %s %s %s", propTuple[1], optionName, opts_dict[optionName])
Expand Down
Loading