Skip to content
Snippets Groups Projects
run_bandwidth_test_jobs.py 3.06 KiB
Newer Older
#!/usr/bin/env python
###############################################################################
# (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration           #
#                                                                             #
# This software is distributed under the terms of the GNU General Public      #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
#                                                                             #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization  #
# or submit itself to any jurisdiction.                                       #
###############################################################################
""" Launch one Moore job to produce MDF output for bandwidth measurement.

    The corresponding option files are under:
    $HLT2CONFROOT/tests/options/bandwidth/

"""

from __future__ import print_function, division
import argparse
import logging
import subprocess
import os


def run_gaudi_job(args, n_events):

    # build command line
    extra_options = """
from Moore import options
options.n_threads = {n_threads!r}
options.n_event_slots = {evt_slots!r}
options.evt_max = {n_evts!r}
options.input_type = 'MDF'
options.set_input_and_conds_from_testfiledb({TFDBkey!r})
""".format(
        n_evts=n_events,
        evt_slots=args.evtSlots,
        n_threads=args.threads,
        TFDBkey=args.test_file_db_key)

    cmd = ['gaudirun.py', '--option', extra_options
           ] + [os.path.expandvars(x) for x in args.options]
    cmd.insert(1, '-T')

    # run the test
    subprocess.run(cmd)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
    parser.add_argument('options', nargs='+', help='Gaudi options files.')
    parser.add_argument(
        '-t',
        '--threads',
        type=int,
        default=1,
        help='Number of threads per job (defaults to # logical cpus')
    parser.add_argument(
        '-e',
        '--evtSlots',
        type=int,
        default=None,
        help='Number of event slots per job (defaults to max(1.2 * # threads, '
        '1 + # threads)')
    parser.add_argument(
        '-n',
        '--events',
        default=100,
        type=lambda x: int(round(float(x))),
        help='nb of events to process per job')
    parser.add_argument(
        '--test-file-db-key',
        default='UpgradeHLT1FilteredWithGEC',
        help='TestFileDB key defining input files and tags.')
    parser.add_argument(
        '--debug', action='store_true', help='Debugging output')
    args = parser.parse_args()

    logging.basicConfig(
        format='%(levelname)-7s %(message)s',
        level=(logging.DEBUG if args.debug else logging.INFO))

    # run at most 1e5 events for each test
    n_events = args.events
    if n_events == -1 or n_events > 1e5: n_events = 1e5

    if args.evtSlots is None:
        args.evtSlots = max(int(round(1.2 * args.threads)), 1 + args.threads)

    run_gaudi_job(args, n_events)