Adding custom arguments to k4run
It is possible to extend k4run with custom arguments from a steering file
using k4FWCore.parseArgs.
Example:
from k4FWCore.parseArgs import parser
parser.add_argument("--trackingOnly", action="store_true", help="Run only track reconstruction", default=False)
my_opts = parser.parse_known_args()[0]
# later
if my_opts.trackingOnly:
# only run track reconstruction
The example steering file can then be executed as follows:
k4run example_steering_file.py --trackingOnly --some-other-args
Behind the scenes parser is just a normal instance of python’s
argparse.ArgumentParser,
please refer to its documentation for usage details. Use parse_known_args()
instead of parse_args() so that the normal k4run arguments keep working. The
[0] is necessary because the added arguments will be in the first element of
the tuple returned from parse_known_args.
Interactive python prompt
The -i, --interactive option for k4run in k4FWCore starts an interactive
Python command prompt after reading the configuration files. In this mode,
algorithm instances are accessible from the prompt. You can inspect them using
commands like print(alg) (where alg is the name of the python variable that
holds the algorithm) which displays information about the algorithm instance and
its properties. Most properties can be modified interactively. For example,
after k4run steering.py -i:
>>> print(alg)
/***** Algorithm ExampleFunctionalProducer/ExampleFunctionalProducer *******************************
|-OutputLevel = 0 (default: 0)
...
|-ExampleInt = 3 (default: 3)
>>> alg.ExampleInt = 4
>>> print(alg)
/***** Algorithm ExampleFunctionalProducer/ExampleFunctionalProducer *******************************
|-OutputLevel = 0 (default: 0)
...
|-ExampleInt = 4 (default: 3)