def readL1MenuFromXML(menu="LVL1config_Physics_pp_v6.xml"): from AthenaCommon.Logging import logging log = logging.getLogger("TriggerConfigLVL1") log.setLevel(logging.INFO) fullname = None if '/' in menu: fullname = menu import os for path in os.environ['XMLPATH'].split(':'): if not 'TriggerMenuXML' in os.listdir(path): continue if menu in os.listdir("%s/TriggerMenuXML/" % path): fullname = "%s/TriggerMenuXML/%s" % (path, menu) break # we only want to look into the first TriggerMenuXML package if fullname: tpcl1 = TriggerConfigLVL1(inputFile=fullname, outputFile="test.xml") tpcl1.writeXML() return tpcl1.menu else: print("Did not find file %s" % menu) return None
def generateL1Menu(menu, doFTK="False", useTopoMenu="MATCH"): from AthenaCommon.Logging import logging log = logging.getLogger("TriggerConfigLVL1") log.setLevel(logging.INFO) logging.getLogger("TriggerMenu.l1.Lvl1Menu").setLevel(logging.INFO) TF.doFTK = doFTK log.info("doFTK: %s " % TF.doFTK) # what menu to build TF.triggerMenuSetup = menu # TPC for L1 tpcl1 = TriggerConfigLVL1(outputFile=TF.outputLVL1configFile()) # build the menu structure tpcl1.generateMenu() # write xml file outfilename = tpcl1.writeXML() # consistency checker checkResult = os.system( "get_files -xmls -symlink LVL1config.dtd > /dev/null") checkResult = os.system("xmllint --noout --dtdvalid LVL1config.dtd %s" % outfilename) if checkResult == 0: log.info("XML file %s is conform with LVL1config.dtd" % outfilename) else: log.error( "the XML does not follow the document type definition LVL1config.dtd" ) return tpcl1.menu
def findUnneededRun2(): menus = ['Physics_pp_v6'] for menu in menus: TF.triggerMenuSetup = menu tpcl1 = TriggerConfigLVL1() print set(tpcl1.registeredItems.keys()) - set(Lvl1Flags.items())
def findFreeCTPIDs(menu): from pickle import load f = open("L1Items.pickle", "r") [menus, allItems, allThrs] = load(f) TF.triggerMenuSetup = menu tpcl1 = TriggerConfigLVL1(outputFile=TF.outputLVL1configFile()) print(set(Lvl1Flags.CtpIdMap().keys()) - allItems)
def findUnneededRun2(): from TriggerJobOpts.TriggerFlags import TriggerFlags as TF from TriggerMenu.l1.Lvl1Flags import Lvl1Flags menus = ['Physics_pp_v6'] for menu in menus: TF.triggerMenuSetup = menu tpcl1 = TriggerConfigLVL1() print(set(tpcl1.registeredItems.keys()) - set(Lvl1Flags.items()))
def findUnneededRun1(what="items"): from pickle import load f = open("L1Items.pickle", "r") [menus, allItems, allThrs] = load(f) # the TPC for L1 tpcl1 = TriggerConfigLVL1(outputFile=TF.outputLVL1configFile()) if what == "items": unneeded = sorted(list(set(tpcl1.registeredItems.keys()) - allItems)) else: unneeded = sorted( list(set(tpcl1.registeredThresholds.keys()) - allThrs)) print("==> unneeded ", what, ":", len(unneeded)) import re p = re.compile('.*$') print([x for x in unneeded if p.match(x)])
from TriggerMenu.TriggerConfigLVL1 import TriggerConfigLVL1 from TriggerMenu.l1.Lvl1Flags import Lvl1Flags from TriggerMenu.l1.Lvl1MenuItems import LVL1MenuItem from TriggerMenu.l1.TriggerTypeDef import TT from TriggerMenu.l1.Lvl1Condition import ThrCondition, Lvl1InternalTrigger from TriggerMenu.l1.Logic import Logic # # L1 # l1menu = TriggerConfigLVL1(outputFile='l1menu.xml', menuName='menutest', topoMenu=None) LVL1MenuItem.l1configForRegistration = l1menu Lvl1Flags.thresholds = ['MU06', 'MU20'] Lvl1Flags.items = ['L1_MU06', 'L1_MU20', 'L1_MU21'] bgrp = Logic(Lvl1InternalTrigger('BGRP0')) & Logic( Lvl1InternalTrigger('BGRP1')) thr = l1menu.registerThr('MU06', 'MUON').addThrValue(6) LVL1MenuItem('L1_MU06').setLogic(ThrCondition(thr) & bgrp).setTriggerType( TT.muon) thr = l1menu.registerThr('MU20', 'MUON').addThrValue(20) LVL1MenuItem('L1_MU20').setLogic(ThrCondition(thr) & bgrp).setTriggerType( TT.muon) LVL1MenuItem('L1_MU21').setLogic(ThrCondition(thr) & bgrp).setTriggerType( TT.muon)
def generate(self): log.info('GenerateMenu.py:generate ') ########################### # L1 Topo menu generation # ########################### if TriggerFlags.doL1Topo(): if not TriggerFlags.readL1TopoConfigFromXML( ) and not TriggerFlags.readMenuFromTriggerDb(): log.info('Generating L1 topo configuration for %s' % TriggerFlags.triggerMenuSetup()) from TriggerMenu.TriggerConfigL1Topo import TriggerConfigL1Topo self.trigConfL1Topo = TriggerConfigL1Topo( outputFile=TriggerFlags.outputL1TopoConfigFile()) # build the menu structure self.trigConfL1Topo.generateMenu() log.info('Topo Menu has %i trigger lines' % len(self.trigConfL1Topo.menu)) # write xml file self.trigConfL1Topo.writeXML() elif TriggerFlags.readL1TopoConfigFromXML(): log.info("Reading L1 topo configuration from '%s'" % TriggerFlags.inputL1TopoConfigFile()) from TriggerMenu.TriggerConfigL1Topo import TriggerConfigL1Topo self.trigConfL1Topo = TriggerConfigL1Topo( inputFile=TriggerFlags.inputL1TopoConfigFile()) else: log.info("Doing nothing with L1 topo menu configuration...") log.info( "Trigger xml files L1Topo : in = %s, out = %s (read from XML = %s)" % (TriggerFlags.inputL1TopoConfigFile(), TriggerFlags.outputL1TopoConfigFile(), TriggerFlags.readL1TopoConfigFromXML())) log.info( "Trigger xml files LVL1 : in = %s, out = %s (read from XML = %s)" % (TriggerFlags.inputLVL1configFile(), TriggerFlags.outputLVL1configFile(), TriggerFlags.readLVL1configFromXML())) log.info( "Trigger xml files HLT : in = %s, out = %s (read from XML = %s)" % (TriggerFlags.inputHLTconfigFile(), TriggerFlags.outputHLTconfigFile(), TriggerFlags.readHLTconfigFromXML())) ###################### # L1 menu generation # ###################### if not TriggerFlags.readLVL1configFromXML( ) and not TriggerFlags.readMenuFromTriggerDb(): log.info('Generating L1 configuration for %s' % TriggerFlags.triggerMenuSetup()) from TriggerMenu.TriggerConfigLVL1 import TriggerConfigLVL1 self.trigConfL1 = TriggerConfigLVL1( outputFile=TriggerFlags.outputLVL1configFile()) # build the menu structure self.trigConfL1.generateMenu() log.info('Menu has %i items' % len(self.trigConfL1.menu.items)) # write xml file self.trigConfL1.writeXML() elif TriggerFlags.readLVL1configFromXML(): log.info("Reading L1 configuration from '%s'" % TriggerFlags.inputLVL1configFile()) from TriggerMenu.TriggerConfigLVL1 import TriggerConfigLVL1 self.trigConfL1 = TriggerConfigLVL1( inputFile=TriggerFlags.inputLVL1configFile()) else: log.info("Doing nothing with L1 menu configuration...") ################## #setup of HLT menu ################## #(HLTPrescales, streamConfig) = self.setupMenu() (HLTPrescales) = self.setupMenu() #calling TriggerPythonConfig self.triggerPythonConfig = TriggerPythonConfig( TriggerFlags.outputHLTconfigFile(), self.signaturesOverwritten) #Setting trigger menu name self.triggerPythonConfig.menuName = TriggerFlags.triggerMenuSetup() ############################# # Start HLT menu generation # ############################# chainsInMenu = self.getChainsFromMenu( ) # get names of chains to be generated if hasattr(self, 'trigConfL1'): self.checkL1SeedsForChainsFromMenu(chainsInMenu) self.checkUnusedL1Items(chainsInMenu) # instantiate parser theDictFromChainName = DictFromChainName.DictFromChainName() counter = 0 for chain in chainsInMenu: log.info("Processing chain : %s", chain) chainDicts = theDictFromChainName.getChainDict(chain) counter += 1 chainCounter = counter chainDicts['chainCounter'] = chainCounter chainDicts['topoThreshold'] = None # only when we generate L1 menu we have trigConfL1 available if not (TriggerFlags.readHLTconfigFromXML() or TriggerFlags.readMenuFromTriggerDb()): if chainDicts['topoStartFrom'] is True: L1item = chainDicts['L1item'] for item in self.trigConfL1.menu.items: if str(item.name) == L1item: itemThrNames = item.thresholdNames( include_bgrp=False) myTEs = [] for itemThr in itemThrNames: if ('-' in itemThr ): # identifier for L1Topo itesm myTEs.append(str(itemThr)) else: myTEs = None chainDicts['topoThreshold'] = myTEs chainDef = self.getChainDef(chainDicts) #Insert entry for chain counter later #For now, just modify it by assigning it automatically streams = chain[3] groups = chain[4] EBstep = chain[5] streamTag = StreamInfo.getStreamTag(streams) if not chainDef: log.error( 'No chainDef for chain %s returned. Will ignore and continue.', chain) continue log.debug("GenerateMenu chainDef: %s", chainDef) # generate HLTChains and associated sequences if not self.chainDefIsConsistent(chainDef): log.error('ChainDef consistency checks failing for chain %s' % chain) theHLTChain = self.generateHLTChain( chainDef, str(chainDicts['chainCounter']), streamTag, groups, EBstep) theHLTSequences = self.generateHLTSequences( chainDef ) #replace this function and make separate constructor in HLTSequence # add / register HLTChains / sequences in TriggerPythonCofig for theHLTSequence in theHLTSequences: self.triggerPythonConfig.addHLTSequence(theHLTSequence) # chain_name is a key in allChains self.triggerPythonConfig.registerHLTChain(chain[0], theHLTChain) if not (TriggerFlags.readHLTconfigFromXML() or TriggerFlags.readMenuFromTriggerDb()): self.triggerPythonConfig.addHLTChain(theHLTChain) self.triggerPythonConfig.printIt() #----------DO NOT MOVE THESE LINES FROM THIS POSITION----------------- # Even if XML doesn't need to be generated, chains have to be loaded #--------------------------------------------------------------------- if TriggerFlags.readHLTconfigFromXML( ) or TriggerFlags.readMenuFromTriggerDb(): log.info('generation of HLT XML file not requested') return #----------------------------------- # info print out #----------------------------------- log.info('generating XML configuration files (true?): ') if self.trigConfL1.inputFile is not None: log.info('LVL1: %s (not generated but read in)', self.trigConfL1.inputFile) else: log.info('LVL1: %s', self.trigConfL1.outputFile) log.info('HLT : %s', self.triggerPythonConfig.getHLTConfigFile()) log.info('N L1 items : %s ', len(self.trigConfL1.menu.items)) log.info('N L1 thresholds: %s ', len(self.trigConfL1.menu.thresholds)) log.info("N HLT chains: %s ", len(self.triggerPythonConfig.allChains.keys())) log.debug("All chains: %s ", self.triggerPythonConfig.allChains.keys()) #log.info('checkTriggerGroupAssignment') #checkTriggerGroupAssignment(self.triggerPythonConfig) log.info('checkGroups') checkGroups(self.triggerPythonConfig) ##cpsMenus = ['Physics_pp_v5','Physics_pp_v6','Physics_pp_v7'] ##if TriggerFlags.triggerMenuSetup() in cpsMenus: if TriggerFlags.triggerMenuSetup().find("pp_v") >= 0: log.info('Assigning CPS groups now') addCPS(self.triggerPythonConfig, self.signaturesOverwritten) applyPrescales(self.triggerPythonConfig, HLTPrescales) # Modifying menu in TriggerPythonConfig # is not being executed global _func_to_modify_the_menu if _func_to_modify_the_menu is not None: log.info('generate: Modifying the trigger menu in TriggerPythonConfig with %s' % \ _func_to_modify_the_menu.__name__) _func_to_modify_the_menu(self.triggerPythonConfig) #dump configuration files log.info('generate: dump configuration Files') #self.dumpSignatureList(self.trigConfL1.menu.items.itemNames(),'hltsigs.txt') self.triggerPythonConfig.writeConfigFiles() if log.isEnabledFor(logging.DEBUG): self.triggerPythonConfig.dot(algs=True) #checking Stream Consistency log.info('checkStreamConsistency') checkStreamConsistency(self.triggerPythonConfig) # TrigConfConsistencyChecker log.info("Running TrigConfConsistencyChecker...") # Check for the Lvl1 XML first in the current dir, then in $XMLPATH (ret, output) = getstatusoutput('TrigConfConsistencyChecker --lvl1xml %s --hltxml %s --exceptions %s '% \ ( self.trigConfL1.inputFile if self.trigConfL1.inputFile is not None else self.trigConfL1.outputFile, self.triggerPythonConfig.getHLTConfigFile(), "TriggerMenu/menu_check_exceptions.xml") ) print(output) # this does test the triggertype (JS) #for bit in xrange(8): # print ("TriggerType",bit,":",self.triggerPythonConfig.Lvl1ItemByTriggerType(0x01<<bit,0x01<<bit)) if ret == 0: log.info("TrigConfConsistencyChecker successful.") else: log.warning("TrigConfConsistencyChecker failed.") for line in output.split(os.linesep): if line.find('Warning Cannot find threshold') >= 0: log.error('%s -> add the threshold explicitly' % line.split()[-1]) # print all chain counters if log.isEnabledFor(logging.DEBUG): for name, chains in self.triggerPythonConfig.allChains.items(): for c in chains: log.debug('Registered chain %04d %s', int(c.chain_counter), c.chain_name) # print all the chains that returned an ERROR chainDef object if self.listOfErrorChainDefs: log.error( 'ATTENTION: The following chains returned an ERROR chainDef object.' ) log.error( ' They will not be considered in the menu generation:' ) for chain in self.listOfErrorChainDefs: log.error(' chain: %s ' % chain) log.info('Check the List of chains in rerun with a special stream tag') self.GetStreamTagForRerunChains() log.info('generate END')