Example #1
0
def generateChainConfigs(chainDict):

    listOfChainDicts = splitChainDict(chainDict)
    log.debug("Will generate Config for monitor chain: %s",
              chainDict['chainName'])

    listOfChainDefs = []

    #streamers will never have more than one chainPart but this is still
    #needed to move to the correct format [{}]->{}
    for subChainDict in listOfChainDicts:

        Monitor = MonitorChainConfiguration(subChainDict).assembleChain()

        listOfChainDefs += [Monitor]
        log.debug('length of chaindefs %s', len(listOfChainDefs))

    if len(listOfChainDefs) > 1:
        log.warning(
            "This is a streamer with more than one chainPart, is this really intended?"
        )
        theChainDef = mergeChainDefs(listOfChainDefs, chainDict)
    else:
        theChainDef = listOfChainDefs[0]

    log.debug("theChainDef %s", theChainDef)

    return theChainDef
Example #2
0
def generateChainConfigs(chainDict):

    listOfChainDicts = splitChainDict(chainDict)
    listOfChainDefs = []

    for subChainDict in listOfChainDicts:
        log.debug('Assembling subChainsDict %s for chain %s',
                  len(listOfChainDefs), subChainDict['chainName'])
        Test = TestChainConfiguration(subChainDict).assembleChain()

        listOfChainDefs += [Test]

    if len(listOfChainDefs) > 1:
        theChainDef = mergeChainDefs(listOfChainDefs, chainDict)
    else:
        theChainDef = listOfChainDefs[0]

    return theChainDef
Example #3
0
def generateChainConfigs(chainDict):
    log.debug('dictionary is: %s\n', pprint.pformat(chainDict))

    listOfChainDicts = splitChainDict(chainDict)
    listOfChainDefs = []

    for subChainDict in listOfChainDicts:
        log.debug('Assembling subChainsDict %s for chain %s',
                  len(listOfChainDefs), subChainDict['chainName'])
        Photon = PhotonChainConfiguration(subChainDict).assembleChain()

        listOfChainDefs += [Photon]

    if len(listOfChainDefs) > 1:
        theChainDef = mergeChainDefs(listOfChainDefs, chainDict)
    else:
        theChainDef = listOfChainDefs[0]

    return theChainDef
Example #4
0
def generateChainConfigs(chainDict):

    if not chainDict['topo']:
        log.error('No topo given -> not a bphysics chain...')

    listOfChainDicts = splitChainDict(chainDict)

    listOfChainDefs = []
    for subChainDict in listOfChainDicts:
        subChain = BphysicsChainConfiguration(
            subChainDict).assembleBphysChain()
        listOfChainDefs += [subChain]

    log.debug('length of chaindefs %s', len(listOfChainDefs))

    if len(listOfChainDefs) > 1:
        chainDef = mergeChainDefs(listOfChainDefs, chainDict)
    else:
        chainDef = listOfChainDefs[0]

    log.debug('ChainDef %s', chainDef)
    return chainDef
Example #5
0
def generateMenu(flags):
    """
    Using flags generate appropriate Control Flow Graph wiht all HLT algorithms
    """

    # convert to chainDefs
    from TriggerMenuMT.HLTMenuConfig.Menu.DictFromChainName import dictFromChainName

    counter = 0
    signatureToGenerator = {}
    menuChains = []
    allChainDicts = []

    menuAcc = ComponentAccumulator()
    mainSequenceName = 'HLTAllSteps'
    menuAcc.addSequence(seqAND(mainSequenceName))

    for name, cfgFlag in list(iteritems(flags._flagdict)):
        if 'Trigger.menu.' not in name:
            continue
        value = flags._get(name)
        if len(value) == 0:
            continue

        signatureName = name.split('.')[-1]
        signatures = []

        # fill the map[signature, generating function]
        if signatureName == 'combined':
            for chain in cfgFlag.get():
                signatures += dictFromChainName(chain)['signatures']
        else:
            signatures = [signatureName]

        for sig in signatures:
            fillGeneratorsMap(signatureToGenerator, sig.lower())

        # call generating function and pass to CF builder
        for chain in cfgFlag.get():
            # TODO topo threshold
            mainChainDict = dictFromChainName(chain)

            counter += 1
            mainChainDict['chainCounter'] = counter

            #set default chain prescale
            mainChainDict['prescale'] = 1

            allChainDicts.append(mainChainDict)

            chainDicts = splitInterSignatureChainDict(mainChainDict)
            listOfChainConfigs = []

            for chainDict in chainDicts:
                signature = chainDict['signature'].lower()

                if signature not in signatureToGenerator:
                    log.warning(
                        'Generator for {} is missing. Chain dict will not be built'
                        .format(signature))
                    continue

                chainConfig = signatureToGenerator[signature](flags, chainDict)
                listOfChainConfigs.append(chainConfig)

            if len(listOfChainConfigs) > 1:
                theChainConfig = mergeChainDefs(listOfChainConfigs,
                                                mainChainDict)

            else:
                theChainConfig = listOfChainConfigs[0]

            TriggerConfigHLT.registerChain(mainChainDict, theChainConfig)
            menuChains.append(theChainConfig)

    log.info('Obtained Menu Chain objects')

    # pass all menuChain to CF builder
    useReworked = True

    if useReworked:
        menuAcc.wasMerged()
        menuAcc = generateDecisionTree(menuChains)
    else:
        menuAcc.wasMerged()
        menuAcc = ComponentAccumulator()
        mainSequenceName = 'HLTAllSteps'
        menuAcc.addSequence(seqAND(mainSequenceName))
        chainsAcc = generateDecisionTreeOld(
            menuAcc.getSequence(mainSequenceName), menuChains, allChainDicts)
        menuAcc.merge(chainsAcc)

    menuAcc.printConfig()

    log.info('CF is built')

    # # generate JOSON representation of the config
    from TriggerMenuMT.HLTMenuConfig.Menu.HLTMenuJSON import generateJSON_newJO
    generateJSON_newJO(allChainDicts, menuChains,
                       menuAcc.getSequence("HLTAllSteps"))

    from TriggerMenuMT.HLTMenuConfig.Menu.HLTPrescaleJSON import generateJSON_newJO as generatePrescaleJSON_newJO
    generatePrescaleJSON_newJO(allChainDicts, menuChains)

    return menuAcc
Example #6
0
    def __generateChainConfig(self, mainChainDict):
        """
        # Assembles the chain configuration and returns a chain object with (name, L1see and list of ChainSteps)
        """
        # check if all the signature files can be imported files can be imported
        for sig in self.signaturesToGenerate:
            try:
                if eval('self.do' + sig + 'Chains'):
                    if sig == 'Egamma':
                        sigFolder = sig
                        subSigs = ['Electron', 'Photon']
                    elif sig in self.calibCosmicMonSigs:
                        sigFolder = 'CalibCosmicMon'
                        subSigs = self.calibCosmicMonSigs
                    else:
                        sigFolder = sig
                        subSigs = [sig]
                    for ss in subSigs:
                        if sigFolder == 'Combined':
                            continue
                        else:
                            exec('import TriggerMenuMT.HLTMenuConfig.' +
                                 sigFolder + '.Generate' + ss + 'ChainDefs')
                            if ss not in self.availableSignatures:
                                self.availableSignatures.append(ss)

            except ImportError:
                log.exception(
                    'Problems when importing ChainDef generating code for %s',
                    sig)
                import traceback
                traceback.print_exc()

        log.debug('Available signature(s) for chain generation: %s',
                  self.availableSignatures)

        import pprint
        pp = pprint.PrettyPrinter(indent=4, depth=8)

        # split the the chainDictionaries for each chain and print them in a pretty way
        chainDicts = splitInterSignatureChainDict(mainChainDict)

        if log.isEnabledFor(logging.DEBUG):
            import pprint
            pp = pprint.PrettyPrinter(indent=4, depth=8)
            log.debug('dictionary is: %s', pp.pformat(chainDicts))

        # Loop over all chainDicts and send them off to their respective assembly code
        listOfChainConfigs = []
        lengthOfChainConfigs = []

        for chainDict in chainDicts:
            chainConfigs = None
            currentSig = chainDict['signature']
            chainName = chainDict['chainName']
            log.debug('Checking chainDict for chain %s in signature %s',
                      chainName, currentSig)

            sigFolder = ''
            if currentSig == 'Electron' or currentSig == 'Photon':
                sigFolder = 'Egamma'
            elif currentSig in self.calibCosmicMonSigs:
                sigFolder = 'CalibCosmicMon'
            else:
                sigFolder = currentSig

            if currentSig in self.availableSignatures and currentSig != 'Combined':
                try:
                    log.debug("Trying to get chain config for %s in folder %s",
                              currentSig, sigFolder)
                    functionToCall = 'TriggerMenuMT.HLTMenuConfig.' + sigFolder + '.Generate' + currentSig + 'ChainDefs.generateChainConfigs(chainDict)'
                    chainConfigs = eval(functionToCall)
                except RuntimeError:
                    log.exception('Problems creating ChainDef for chain\n %s ',
                                  chainName)
                    continue
            else:
                log.error('Chain %s ignored - Signature not available',
                          chainDict['chainName'])
            listOfChainConfigs.append(chainConfigs)
            lengthOfChainConfigs.append((len(chainConfigs.steps), currentSig))

        ## if log.isEnabledFor(logging.DEBUG):
        ##     import pprint
        ##     pp = pprint.PrettyPrinter(indent=4, depth=8)
        ##     log.debug('mainChainDict dictionary: %s', pp.pformat(mainChainDict))

        # This part is to deal with combined chains between different signatures
        if len(listOfChainConfigs) == 0:
            log.error('No Chain Configuration found ')
            return False

        elif len(listOfChainConfigs) > 1:
            log.debug("Merging strategy from dictionary: %s",
                      mainChainDict["mergingStrategy"])
            theChainConfig = mergeChainDefs(listOfChainConfigs, mainChainDict)

            # This needs to be added for topological chains - needs implementation
            #doTopo = self.CheckIntraSignatureTopo(chainDicts) and chainDict["topo"]
            #if doTopo:
            # theChainDef = TriggerMenu.combined.generateCombinedChainDefs._addTopoInfo(theChainDef,chainDicts,listOfChainDefs)

        else:
            theChainConfig = listOfChainConfigs[0]

        # Configure event building strategy
        eventBuildType = mainChainDict['eventBuildType']
        if eventBuildType:
            log.debug('Configuring event building sequence %s for chain %s',
                      eventBuildType, mainChainDict['chainName'])
            from TriggerMenuMT.HLTMenuConfig.CommonSequences.EventBuildingSequenceSetup import addEventBuildingSequence
            addEventBuildingSequence(theChainConfig, eventBuildType)

        log.debug('ChainConfigs  %s ', theChainConfig)
        return theChainConfig, lengthOfChainConfigs