From 20cafd85350e8adaa39f20d759fe485e3139ddf0 Mon Sep 17 00:00:00 2001 From: erodrigu <eduardo.rodrigues@cern.ch> Date: Thu, 9 Dec 2021 16:51:16 +0100 Subject: [PATCH 1/5] More davinci script doc --- DaVinciSys/scripts/davinci | 41 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/DaVinciSys/scripts/davinci b/DaVinciSys/scripts/davinci index e87378732..e6bf2087c 100755 --- a/DaVinciSys/scripts/davinci +++ b/DaVinciSys/scripts/davinci @@ -12,6 +12,7 @@ """ This script is meant to implement the Python Click functionality when running a DaVinci (Gaudi) application. + Two possible functions have been developed to automatically handle the differences between jobs using data or simulated input files. @@ -42,23 +43,26 @@ else: "--export", default=None, help= - "export the options in a format suitable for gaudirun.py. Filename has to be provided as argument.", + "Export the options in a format suitable for gaudirun.py.\nFilename has to be provided, with extension .opts.\nTypically used in conjunction with --dry-run.", ) @click.option( "--with-defaults", is_flag=True, default=False, help= - "explicitly include default values of properties in the final configuration", + "Explicitly include default values of properties in the final configuration.", ) @click.option( "--dry-run", is_flag=True, default=False, - help="just process the options but do not run the application", + help="Process the options but do not run the application.", ) @click.version_option(version=APP_VERSION) def main(export, with_defaults, dry_run): + """ + Try `davinci COMMAND --help` for information on COMMAND options available. + """ assert not export or export.endswith( ".opts"), "--export argument must have '.opts' extension" @@ -66,8 +70,8 @@ def main(export, with_defaults, dry_run): @main.resultcallback() def run_job(configurables, export=None, with_defaults=False, dry_run=None): """ - This function is not invoked directly in Davinci but it is used to override the - default click 'result_callback' function by means of the 'resultcallback' decorator. + This function is not invoked directly by davinci but it is used to override the + default Click 'result_callback' function by means of the 'resultcallback' decorator. The 'result_callback' method is invoked automatically when returning the values of the main subcommnads: run_mc and run_data. """ @@ -143,18 +147,19 @@ def run_job(configurables, export=None, with_defaults=False, dry_run=None): is_flag=True, default=False, help= - "Option for running a simple DaVinci jobs without any specific configuration (.py)." + "Option for running a simple DaVinci job without any specific configuration (.py)." ) @click.pass_context def run_mc(ctx, inputfiledb, joboptfile, simplejob): """ DaVinci function for running jobs on simulated samples. + Ctx: click.core.Context class (dict). - Predefined click object storing information about the invoked command. - All the options passed by command line which are not recognised by click are stored into the ctx.args element. + Predefined Click object storing information about the invoked command. + All options passed via the command line which are not recognised by Click are stored into the ctx.args element. Ctx.args is a simple array and each extra option is stored using two values: the first one is the key and the second one is the corresponding value. - Eg: --evt_max 100 will be stored as: ctx.args[0] = --evt_max, ctx.args[1] = 100 + Ex.: --evt_max 100 will be stored as: ctx.args[0] = --evt_max, ctx.args[1] = 100 Note: Click automatically converts "_" in "-", so this function can be invoked calling run-mc as shown in the help. @@ -193,31 +198,33 @@ def run_mc(ctx, inputfiledb, joboptfile, simplejob): "If you want to use the standard TestFileDB set 'filedb-path' = '-'." ) @click.option( - "--joboption-file", + "--joboptfile", default="", - help="Option file containing the job information (.yaml, .py)") + help="Option file containing the job information (.py, .yaml)") @click.pass_context def run_data(ctx, inputfiledb, optfile): """ DaVinci function for running jobs on real data samples. - Ctx: click.core.Context class (dict). Predefined click object storing information about the invoked command. - All options passed by the command line that are not recognised by click are stored into the ctx.args element. + + Ctx: click.core.Context class (dict). + Predefined Click object storing information about the invoked command. + All options passed via the command line that are not recognised by Click are stored into the ctx.args element. Ctx.args is a simple array and each extra option is stored using two values: the first one is the key and the second one is the corresponding value. - Eg: --evt_max 100 will be stored as: ctx.args[0] = --evt_max, ctx.args[1] = 100 + Ex.: --evt_max 100 will be stored as: ctx.args[0] = --evt_max, ctx.args[1] = 100 Note: - Click automatically converts "_" in "-", so this function can be invoked calling run-data as shown in the help. + Click automatically converts "_" in "-", so this function can be invoked calling run-data as shown in the help. """ raise ValueError( 'Data file with upgrade conditions are not yet available. Please use :mc function instead.' ) - # Run on data sample + # Run on a data sample options.simulation = False - # Test file DB key request overrides inputfiledb + # TestFileDB key request overrides inputfiledb inputfiledb_key, inputfiledb_file = set_testfiledb(inputfiledb) ctx_args = (ctx.args if (len(ctx.args) > 1) else []) -- GitLab From afeee58b05cd9ebbd3497cb964d5e4bb1ec3434b Mon Sep 17 00:00:00 2001 From: erodrigu <eduardo.rodrigues@cern.ch> Date: Thu, 9 Dec 2021 16:57:55 +0100 Subject: [PATCH 2/5] Follow-up adaptations --- DaVinciSys/scripts/davinci | 2 +- Phys/DaVinci/python/DaVinci/utilities_script.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/DaVinciSys/scripts/davinci b/DaVinciSys/scripts/davinci index e6bf2087c..dfe4dce99 100755 --- a/DaVinciSys/scripts/davinci +++ b/DaVinciSys/scripts/davinci @@ -200,7 +200,7 @@ def run_mc(ctx, inputfiledb, joboptfile, simplejob): @click.option( "--joboptfile", default="", - help="Option file containing the job information (.py, .yaml)") + help="Option file containing the job information (.yaml, .py)") @click.pass_context def run_data(ctx, inputfiledb, optfile): """ diff --git a/Phys/DaVinci/python/DaVinci/utilities_script.py b/Phys/DaVinci/python/DaVinci/utilities_script.py index 33d69cf6c..612581ffd 100644 --- a/Phys/DaVinci/python/DaVinci/utilities_script.py +++ b/Phys/DaVinci/python/DaVinci/utilities_script.py @@ -28,10 +28,10 @@ def dump_call(testfiledb_file, testfiledb_key, joboptfile, ctx_args): indentStr = "# " click.echo("%sDaVinci: running using the following arguments:" % indentStr) click.echo( - "%s - testfiledb-file: %s" % (indentStr, testfiledb_file)) + "%s - TestFileDB file: %s" % (indentStr, testfiledb_file)) click.echo( - "%s - testfiledb-key: %s" % (indentStr, testfiledb_key)) - click.echo("%s - joboption-file: %s" % (indentStr, joboptfile)) + "%s - TestFileDB key: %s" % (indentStr, testfiledb_key)) + click.echo("%s - joboptfile: %s" % (indentStr, joboptfile)) if len(ctx_args) > 1: for i in range(0, len(ctx_args), 2): @@ -85,14 +85,14 @@ def get_configurable_opts(configurables, with_defaults): def set_testfiledb(inputfiledb): """ - Set the testfileDB file and the related key to be used in the DV job. + Set the TestFileDB file and the related key to be used in the job. Args: - - testfiledb: pair of values containing information on the testfileDB and the key chosen by the user. + inputfiledb: pair of values containing information on the TestFileDB and the key chosen by the user. Returns: - - key for the testfileDB. - - file containing the testfileDB. + - key for the TestFileDB. + - file containing the TestFileDB. """ assert len( inputfiledb -- GitLab From 6dd2481b11c2340abb7a0994c0b55eb93ea38243 Mon Sep 17 00:00:00 2001 From: Patrick Koppenburg <patrick.koppenburg@cern.ch> Date: Fri, 10 Dec 2021 10:47:29 +0100 Subject: [PATCH 3/5] Apply 1 suggestion(s) to 1 file(s) --- DaVinciSys/scripts/davinci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DaVinciSys/scripts/davinci b/DaVinciSys/scripts/davinci index dfe4dce99..e03578b49 100755 --- a/DaVinciSys/scripts/davinci +++ b/DaVinciSys/scripts/davinci @@ -204,7 +204,7 @@ def run_mc(ctx, inputfiledb, joboptfile, simplejob): @click.pass_context def run_data(ctx, inputfiledb, optfile): """ - DaVinci function for running jobs on real data samples. + DaVinci function for running jobs on detector data samples. Ctx: click.core.Context class (dict). Predefined Click object storing information about the invoked command. -- GitLab From 5880c5c2dc5276503ed6840aa5986620969b8a10 Mon Sep 17 00:00:00 2001 From: Davide Fazzini <davide.fazzini@cern.ch> Date: Fri, 10 Dec 2021 12:22:51 +0100 Subject: [PATCH 4/5] solve helper redundancy --- DaVinciSys/scripts/davinci | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/DaVinciSys/scripts/davinci b/DaVinciSys/scripts/davinci index e03578b49..945e24f8f 100755 --- a/DaVinciSys/scripts/davinci +++ b/DaVinciSys/scripts/davinci @@ -125,6 +125,11 @@ def run_job(configurables, export=None, with_defaults=False, dry_run=None): exit(app.run()) +inputfiledb_helper = "TestFileDB-like file containing job input and conditions information (.yaml). Takes the pair of values 'filedb-key', 'filedb-path'."\ + "If you want to use the standard TestFileDB set 'filedb-path' = '-'." +joboptfile_helper = "Option file containing the job information (.yaml, .py)" +simplejob_helper = "Option for running a simple DaVinci job without any specific configuration (.py)." + @main.command( context_settings=dict( ignore_unknown_options=True, @@ -134,20 +139,18 @@ def run_job(configurables, export=None, with_defaults=False, dry_run=None): "--inputfiledb", default=("", "TestFileDB"), nargs=2, - help= - "TestFileDB-like file containing job input and conditions information (.yaml). Takes the pair of values 'filedb-key', 'filedb-path'."\ - "If you want to use the standard TestFileDB set 'filedb-path' = '-'." + help=inputfiledb_helper ) @click.option( "--joboptfile", default="", - help="Option file containing the job information (.yaml, .py)") + help=joboptfile_helper +) @click.option( "--simplejob", is_flag=True, default=False, - help= - "Option for running a simple DaVinci job without any specific configuration (.py)." + help=simplejob_helper ) @click.pass_context def run_mc(ctx, inputfiledb, joboptfile, simplejob): @@ -193,16 +196,21 @@ def run_mc(ctx, inputfiledb, joboptfile, simplejob): "--inputfiledb", default=("", "TestFileDB"), nargs=2, - help= - "TestFileDB-like file containing job input and conditions information (.yaml). Takes the pair of values 'filedb-key', 'filedb-path'."\ - "If you want to use the standard TestFileDB set 'filedb-path' = '-'." + help=inputfiledb_helper ) @click.option( "--joboptfile", default="", - help="Option file containing the job information (.yaml, .py)") + help=joboptfile_helper +) +@click.option( + "--simplejob", + is_flag=True, + default=False, + help=simplejob_helper +) @click.pass_context -def run_data(ctx, inputfiledb, optfile): +def run_data(ctx, inputfiledb, joboptfile, simplejob): """ DaVinci function for running jobs on detector data samples. @@ -223,7 +231,6 @@ def run_data(ctx, inputfiledb, optfile): # Run on a data sample options.simulation = False - # TestFileDB key request overrides inputfiledb inputfiledb_key, inputfiledb_file = set_testfiledb(inputfiledb) -- GitLab From f6910afb2831874813735e4c0c89b1a0a25879d3 Mon Sep 17 00:00:00 2001 From: Gitlab CI <noreply@cern.ch> Date: Fri, 10 Dec 2021 11:24:58 +0000 Subject: [PATCH 5/5] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/DaVinci/-/jobs/18236756 --- DaVinciSys/scripts/davinci | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/DaVinciSys/scripts/davinci b/DaVinciSys/scripts/davinci index 945e24f8f..d0b26478e 100755 --- a/DaVinciSys/scripts/davinci +++ b/DaVinciSys/scripts/davinci @@ -130,6 +130,7 @@ inputfiledb_helper = "TestFileDB-like file containing job input and conditions i joboptfile_helper = "Option file containing the job information (.yaml, .py)" simplejob_helper = "Option for running a simple DaVinci job without any specific configuration (.py)." + @main.command( context_settings=dict( ignore_unknown_options=True, @@ -139,19 +140,10 @@ simplejob_helper = "Option for running a simple DaVinci job without any specific "--inputfiledb", default=("", "TestFileDB"), nargs=2, - help=inputfiledb_helper -) -@click.option( - "--joboptfile", - default="", - help=joboptfile_helper -) + help=inputfiledb_helper) +@click.option("--joboptfile", default="", help=joboptfile_helper) @click.option( - "--simplejob", - is_flag=True, - default=False, - help=simplejob_helper -) + "--simplejob", is_flag=True, default=False, help=simplejob_helper) @click.pass_context def run_mc(ctx, inputfiledb, joboptfile, simplejob): """ @@ -196,19 +188,10 @@ def run_mc(ctx, inputfiledb, joboptfile, simplejob): "--inputfiledb", default=("", "TestFileDB"), nargs=2, - help=inputfiledb_helper -) -@click.option( - "--joboptfile", - default="", - help=joboptfile_helper -) + help=inputfiledb_helper) +@click.option("--joboptfile", default="", help=joboptfile_helper) @click.option( - "--simplejob", - is_flag=True, - default=False, - help=simplejob_helper -) + "--simplejob", is_flag=True, default=False, help=simplejob_helper) @click.pass_context def run_data(ctx, inputfiledb, joboptfile, simplejob): """ -- GitLab