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

Improve the documentation about extending the parser for k4run #269

Merged
merged 3 commits into from
Jan 24, 2025
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
18 changes: 16 additions & 2 deletions doc/k4run-args.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->


# Adding custom arguments to `k4run`

It is possible to extend `k4run` with custom arguments from a steering file using `k4FWCore.parseArgs`.
It is possible to extend `k4run` with custom arguments from a steering file
using `k4FWCore.parseArgs`.

Example:

Expand All @@ -32,4 +35,15 @@ if my_opts.trackingOnly:
# only run track reconstruction
```

Behind the scenes parser is just a normal instance of pythons [`argparse.ArgumentParser`](https://docs.python.org/3/library/argparse.html), please refer to its documentation for usage details. The only important thing to keep in mind is to always use `parse_known_args()` instead of `parse_args()` so that the normal `k4run` arguments keep working.
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`](https://docs.python.org/3/library/argparse.html),
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`.
Loading