Beispiel #1
0
def main():
    args = parse_args()

    logging.basicConfig(format='%(levelname)s:menu2lib:%(message)s',
                        level=logging.INFO)

    logging.info("using... %s %s", tmEventSetup.__name__,
                 tmEventSetup.__version__)
    logging.info("using... %s %s", tmGrammar.__name__, tmGrammar.__version__)

    logging.info("loading... %s", args.menu)
    menu = tmEventSetup.getTriggerMenu(args.menu)

    dirname = os.path.dirname(args.output)

    content = render(menu, 'MenuTemplate.cc')
    filename = args.output
    logging.info("writing... %s", filename)
    with open(filename, 'w') as fp:
        fp.write(content)

    content = render(menu, 'MenuTemplate.hh')
    filename = os.path.join(dirname, 'menulib.hh')
    logging.info("writing... %s", filename)
    with open(filename, 'w') as fp:
        fp.write(content)

    content = render(menu, 'menu.txt')
    filename = os.path.join(dirname, 'menu.txt')
    logging.info("writing... %s", filename)
    with open(filename, 'w') as fp:
        fp.write(content)

    logging.info("done.")
Beispiel #2
0
def main():
    logging.addLevelName(10, 'dbg')
    logging.addLevelName(20, 'inf')
    logging.addLevelName(30, 'war')
    logging.addLevelName(40, 'err')
    logging.addLevelName(50, 'fat')

    logging.info("VHDL producer")

    BASE_DIR = os.environ["UTM_ROOT"]
    defaultMenu = "/afs/cern.ch/user/t/tmatsush/public/tmGui/L1Menu_Collisions2015_25nsStage1_v6_uGT_v2.xml"

    parser = argparse.ArgumentParser()

    parser.add_argument("--menu",
                        dest="menu",
                        default=defaultMenu,
                        type=str,
                        action="store",
                        help="path to the level1 trigger menu xml file")
    parser.add_argument("--nModules",
                        dest="nModules",
                        default=1,
                        type=int,
                        action="store",
                        help="number of uGT modules")
    parser.add_argument(
        "--manual_dist",
        dest="manual_dist",
        action="store_true",
        help="manual distribution of algorithms in uGT modules")
    parser.add_argument("--output",
                        dest="outputDir",
                        default=BASE_DIR + "/tmVhdlProducer/test/vhdltest/",
                        type=str,
                        action="store",
                        help="directory for the VHDL producer output")
    parser.add_argument("--verbose",
                        dest="verbose",
                        action="store_true",
                        help="prints template output")

    options = parser.parse_args()

    ## -----------------------------------------------
    outputDir = options.outputDir
    vhdlTemplateDir = BASE_DIR + "/tmVhdlProducer/templates/"
    nModules = options.nModules
    verbose = options.verbose
    menu = tmEventSetup.getTriggerMenu(options.menu)

    producer = tmVhdlProducer.VhdlProducer(menu, vhdlTemplateDir, nModules,
                                           outputDir, verbose,
                                           options.manual_dist)
    producer.write()
Beispiel #3
0
 def __init__(self, templates_dir, filename):
     self.templates_dir = templates_dir
     hls_dir = os.path.join(templates_dir, 'hls')
     vhdl_dir = os.path.join(templates_dir, 'vhdl')
     self.engine = TemplateEngine([hls_dir, vhdl_dir])
     self.proc = sys.argv[0]
     self.timestamp = datetime.datetime.now().isoformat().rsplit('.', 1)[0]
     self.filename = filename
     self.menu = tmEventSetup.getTriggerMenu(filename)
     self.conditions = []
     for handle in self.menu.getConditionMapPtr().values():
         self.conditions.append(ConditionHelper(handle))
     self.seeds = []
     for handle in self.menu.getAlgorithmMapPtr().values():
         self.seeds.append(SeedHelper(handle))
     # sort by index
     self.seeds.sort(key=lambda seed: seed.index)
Beispiel #4
0
def main():
    args = parse_args()

    level = logging.DEBUG if args.verbose else logging.INFO
    logging.getLogger().setLevel(level)

    logging.info("reading event setup from XML menu: %s", args.filename)
    es = tmEventSetup.getTriggerMenu(args.filename)

    logging.info("loading resource information from JSON: %s", args.config)
    tray = ResourceTray(args.config)

    # List resource scales and exit.
    if args.list:
        list_resources(tray)
        logging.info("done.")
        return 0

    # Create module stubs
    collection = ModuleCollection(es, tray)

    list_algorithms(collection)

    logging.info("distributing algorithms, shadow ratio: %s", args.ratio)
    collection.ratio = args.ratio
    # Set sort order (asc or desc)
    collection.reverse_sorting = (args.sorting == 'desc')
    # Collect condition constraints
    if args.constraint:
        for k, v in args.constraint:
            collection.setConstraint(k, v)
    # Run distibution
    collection.distribute(args.modules)

    list_distribution(collection)

    list_summary(collection)

    if args.o:
        dump_distribution(collection, args)

    logging.info("done.")

    return 0
Beispiel #5
0
def analyze(filename):
    """Test an XML menu for condition expression hash collisions."""
    eventsetup = tmEventSetup.getTriggerMenu(filename)

    algorithms = eventsetup.getAlgorithmMapPtr()

    conditions = {}

    for name, algorithm in algorithms.items():
        tokens = parse(algorithm.getExpression())
        for token in tokens:
            hashulong = tmEventSetup.getHashUlong(token)
            if not hashulong in conditions.keys():
                conditions[hashulong] = set()
            conditions[hashulong].add(token)

    errors = []

    for hashulong, tokens in conditions.items():
        if len(tokens) > 1:
            errors.append((hashulong, tokens))

    return errors
Beispiel #6
0
import tmEventSetup
import tmGrammar
menu = tmEventSetup.getTriggerMenu('menu.xml')
algoMap = menu.getAlgorithmMapPtr()
condMap = menu.getConditionMapPtr()
scaleMap = menu.getScaleMapPtr()

indent = '  '

print 'name ', menu.getName()
print 'grammar ', menu.getVersion()
print 'comment ', menu.getComment()
print 'datetime ', menu.getDatetime()
print 'firmware uuid ', menu.getFirmwareUuid()
print 'scale set name ', menu.getScaleSetName()

print
for key, algo in algoMap.iteritems():
    print "algo name  = ", algo.getName()
    print "algo expr. = ", algo.getExpression()
    print "algo expr. = ", algo.getExpressionInCondition()
    list = algo.getRpnVector()
    for x in list:
        if tmGrammar.isGate(x): continue
        cond = condMap[x]
        print indent * 2, "cond type = ", cond.getType()
        cuts = cond.getCuts()
        for y in cuts:
            print y
        objects = cond.getObjects()
        for obj in objects:
if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('filename')
    parser.add_argument('-m', action='store_true', help="show modules")
    parser.add_argument('-c', action='store_true', help="show conditions")
    parser.add_argument('-o', action='store_true', help="show objects")
    args = parser.parse_args()

    # Create tray
    resource = os.path.join(os.path.dirname(__file__), '..', 'config',
                            'resource_default.json')
    tray = algodist.ResourceTray(resource)
    # Load event setup
    eventSetup = tmEventSetup.getTriggerMenu(args.filename)

    # Distribute modules
    collection = algodist.ModuleCollection(eventSetup, tray)
    collection.reverse_sorting = True
    collection.distribute(modules=6)
    # Create template helper
    menu = MenuHelper(collection)

    # Info
    print("*" * 80)
    print("menu.info.name          :", menu.info.name)
    print("menu.info.uuid_menu     :", menu.info.uuid_menu)
    print("menu.info.uuid_firmware :", menu.info.uuid_firmware)
    print("menu.info.scale_set     :", menu.info.scale_set)
    print("menu.info.version       :", menu.info.version)
Beispiel #8
0
def main():
    """Main routine."""
    args = parse_args()

    # Setup console logging
    level = logging.DEBUG if args.verbose else logging.INFO
    logging.basicConfig(format='%(levelname)s: %(message)s', level=level)

    logging.info("running VHDL producer...")

    logging.info("loading XML menu: %s", args.menu)
    eventSetup = tmEventSetup.getTriggerMenu(args.menu)
    output_dir = os.path.join(args.output, f"{eventSetup.getName()}-d{args.dist}")

    # Prevent overwirting source menu
    dest = os.path.realpath(os.path.join(output_dir, 'xml'))
    orig = os.path.dirname(os.path.realpath(args.menu))
    if dest == orig:
        logging.error("%s is in %s directory which will be overwritten during the process", args.menu, dest)
        logging.error("     specified menu not in %s directory", dest)
        return EXIT_FAILURE

    if not args.dryrun:
        if os.path.isdir(output_dir):
            logging.error("directory `%s' already exists", output_dir)
            return EXIT_FAILURE
        else:
            os.makedirs(output_dir)

    if not args.dryrun:
        # Forward logs to file
        handler = logging.FileHandler(os.path.join(output_dir, LOGFILE), mode='a')
        handler.setFormatter(logging.Formatter(fmt='%(asctime)s %(levelname)s : %(message)s', datefmt='%Y-%m-%d %H:%M:%S'))
        handler.setLevel(level)
        logging.getLogger().addHandler(handler)

    # Distribute algorithms, set sort order (asc or desc)
    reverse_sorting = (args.sorting == 'desc')
    # Collect condition constraints
    constraints = {}
    if args.constraint:
        for k, v in args.constraint:
            constraints[ConstraintTypes[k]] = v
    # Run distibution
    collection = distribute(
        eventSetup=eventSetup,
        modules=args.modules,
        config=args.config,
        ratio=args.ratio,
        reverse_sorting=reverse_sorting,
        constraints=constraints
    )

    if args.dryrun:
        logging.info("skipped writing output (dryrun mode)")
    else:

        logging.info("writing VHDL modules...")
        template_dir = os.path.join(ProjectDir, 'templates', 'vhdl')
        producer = VhdlProducer(template_dir)
        producer.write(collection, output_dir)
        logging.info("writing updated XML file %s", args.menu)

        filename = producer.writeXmlMenu(args.menu, os.path.join(output_dir, 'xml'), args.dist) # TODO

        # Write menu documentation.
        logging.info("generating menu documentation...")
        doc_dir = os.path.join(output_dir, 'doc')

        logging.info("writing HTML documentation %s", filename)
        subprocess.check_call([EXEC_REPORTER, '-m', 'html', '-o', doc_dir, filename])

        logging.info("writing TWIKI page template %s", filename)
        subprocess.check_call([EXEC_REPORTER, '-m', 'twiki', '-o', doc_dir, filename])

        logging.info("patching filenames...")
        for filename in glob.glob(os.path.join(doc_dir, '*')):
            newname = re.sub(r'(.+)\.([a-z]+)$', rf'\1-d{args.dist}.\2', filename)
            logging.info("%s --> %s", filename, newname)
            os.rename(filename, newname)

    logging.info("done.")

    return EXIT_SUCCESS