From acf82a1c23a6beb9b96ee162de7b43bef4a93ae7 Mon Sep 17 00:00:00 2001 From: Sam Naugle <47705836+smnaugle@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:00:35 -0500 Subject: [PATCH] Specify experiment binaries with rattests (#222) * Add in command line argument to specify which experiment binary should be used with the rattests. * Specifying default for rattest experiment --- python/rattest.py | 6 +++++- python/rattest/__init__.py | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/python/rattest.py b/python/rattest.py index 719a02eb..3a568829 100644 --- a/python/rattest.py +++ b/python/rattest.py @@ -34,6 +34,10 @@ action='store_false', dest='web', default=True, help='Do not open web pages with plots.') +parser.add_argument('-e', '--experiment', + type=str, dest='experiment_bin', default=None, + help='Absolute path to experiment binary to run test with. Uses `rat` as default.') + parser.add_argument('--make-template', type=str, dest='template', default=None, help='Write a template rattest to current directory for you to edit. '\ 'Supplied name is used for .mac and .C files.') @@ -52,7 +56,7 @@ for dirname in args.input: for dirpath, _, filenames in os.walk(dirname): if configname in filenames: - testcase = RatTest(os.path.join(dirpath, configname)) + testcase = RatTest(os.path.join(dirpath, configname), rat_bin=args.experiment_bin) if args.update: testcase.update(regen_mc=args.regen_mc, regen_plots=args.regen_plots) else: diff --git a/python/rattest/__init__.py b/python/rattest/__init__.py index 58430df2..2d0c3055 100644 --- a/python/rattest/__init__.py +++ b/python/rattest/__init__.py @@ -84,7 +84,7 @@ class RatTest: Also compares and saves the histograms. ''' - def __init__(self, config_file): + def __init__(self, config_file, rat_bin=None): self.config_file = config_file self.testdir = os.path.abspath(os.path.dirname(config_file)) # Create default name out of bottom level dir name @@ -106,7 +106,11 @@ def __init__(self, config_file): self.rat_macro = os.path.abspath(os.path.join(self.testdir, self.rat_macro)) self.root_macro = os.path.abspath(os.path.join(self.testdir, self.root_macro)) self.rat_script = os.path.abspath(os.path.join(os.environ['RATROOT'], 'bin', 'rat')) - self.rat_bin = os.path.abspath(os.path.join(os.environ['RATROOT'], 'bin', 'rat')) + # Allow users to specify rat binary so tests can be ran with downstream experiments + if rat_bin is None: + self.rat_bin = os.path.abspath(os.path.join(os.environ['RATROOT'], 'bin', 'rat')) + else: + self.rat_bin = rat_bin # Find name of file holding events from last macro mac = self.rat_macro @@ -163,9 +167,9 @@ def run_rat(self): suffix = "_" + str(i) + ".mac" mac = self.rat_macro.replace(".mac", suffix) if self.seed == -1: - self.run_cmd_in_testdir('rat ' + os.path.basename(mac)) + self.run_cmd_in_testdir(self.rat_bin + ' ' + os.path.basename(mac)) else: - self.run_cmd_in_testdir('rat -s ' + str(self.seed) + ' ' + os.path.basename(mac)) + self.run_cmd_in_testdir(self.rat_bin + ' -s ' + str(self.seed) + ' ' + os.path.basename(mac)) def run_root(self): '''