def setupCOOLReading(self,TrigCoolDbConnection): log = logging.getLogger( "TriggerConfigGetter.py" ) log.info( 'DSConfigSvc enabled, will setup IOVDbSvc to access configuration meta data') #usePresetConnection = (TrigCoolDbConnection != "") ## if we process MC from an XML file the dbConnection needs to ## be set to a local SQlite file # when reading from the COOL database (either form # ORACLE/SQlite) we need an algorithm that triggers the # copying # # In addition for MC the IOV has to be adjusted since in COOL the config data is written with IOV=infinity if TrigCoolDbConnection=='': log.info("COOL DBConnection: not set, will use default conditions database" ) TrigCoolDbConnection = 'TRIGGER' addNewFolders = TriggerFlags.configForStartup()=="HLTonline" and self.readRDO else: # for sqlite COOL: temp (usually /tmp/hltMenu.xxx.db) or predefined (e.g. trigconf.db) log.info("COOL DBConnection: " + TrigCoolDbConnection ) addNewFolders = ( ( TriggerFlags.configForStartup()=="HLToffline" or TriggerFlags.configForStartup()=="HLTonline" or globalflags.DataSource()!='data') and self.readRDO ) # bytestream or MC RDO # add folders for reading from IOVDbSvc.CondDB import conddb folders = [] if self.hltFolders: folders += [ "HLT/Menu", "HLT/HltConfigKeys" ] if self.l1Folders: folders += [ "LVL1/Lvl1ConfigKey", "LVL1/Menu", "LVL1/Prescales" ] if globalflags.DataSource() == 'data': if self.l1Folders: folders += [ "LVL1/BunchGroupKey", "LVL1/BunchGroupDescription", "LVL1/BunchGroupContent" ] if self.hasLBwiseHLTPrescalesAndL1ItemDef: if self.hltFolders: folders += [ "HLT/Prescales", "HLT/PrescaleKey" ] if self.l1Folders: folders += [ "LVL1/ItemDef" ] log.info("Adding folders to IOVDbSvc") if addNewFolders: # Need thresholds folders but only for Tier0 BS->ESD log.info("Also adding new folders to IOVDbSvc") if self.hltFolders: folders += [ "HLT/Groups" ] if self.l1Folders: folders += [ "LVL1/Thresholds" ] for f in folders: log.info(" /TRIGGER/%s", f) conddb.addFolderWithTag(TrigCoolDbConnection, "/TRIGGER/%s" % f, "HEAD")
def checkInput(self): self.checkFileMetaData() log = logging.getLogger( "TriggerConfigGetter.py" ) if "ReadPool" in self._environment or "WritePool" in self._environment: log.info("Flags are ignored, since 'ReadPool' or 'WritePool' is specified") return True if rec.readESD() or rec.readAOD(): # and globalflags.DataSource()=='data': # need this for MC as well protectedInclude("TriggerJobOpts/TriggerConfigCheckMetadata.py") if rec.readRDO() and globalflags.InputFormat()=='bytestream' and globalflags.DataSource()=='data' and TriggerFlags.configForStartup()!='HLToffline': protectedInclude("TriggerJobOpts/TriggerConfigCheckHLTpsk.py") log.info("The following flags are set:") log.info("globalflags.InputFormat : %s", globalflags.InputFormat()) log.info("rec.read.* : RDO: %s, ESD: %s, AOD: %s, TAG: %s", rec.readRDO(), rec.readESD(), rec.readAOD(), rec.readTAG()) log.info("rec.doWrite.* : ESD: %s, AOD: %s, TAG: %s", rec.doWriteESD(), rec.doWriteAOD(), rec.doWriteTAG()) log.info("globalflags.DataSource : %s", globalflags.DataSource()) log.info("TriggerFlags.configForStartup : %s", TriggerFlags.configForStartup()) log.info("TriggerFlags.dataTakingConditions : %s", TriggerFlags.dataTakingConditions()) log.info("TriggerFlags.configurationSourceList: %s", TriggerFlags.configurationSourceList()) count = len([1 for x in [rec.readRDO(),rec.readESD(),rec.readAOD()] if x ]) #readTAG is only set with another input if count == 0: log.warning("Don't know what the input format is.") return False if count >= 2: log.warning("More than one input format specified, please set only the appropriate one.") return False return True
def InitialiseSvc(self): if self.initialised: raise (RuntimeError, 'athena service has already been added, do nothing.') self.initialised = True from AthenaCommon.AppMgr import ServiceMgr self.mlog.info("initialising TrigConfigSvc using state %s", self.states) if 'xml' in self.states: from TriggerJobOpts.TriggerFlags import TriggerFlags if TriggerFlags.doLVL2() or TriggerFlags.doEF( ) or TriggerFlags.doHLT() or TriggerFlags.configForStartup( ) == 'HLToffline': self.mlog.info( "setup HLTConfigSvc and add instance to ServiceMgr (xml file=" + self.hltXmlFile + ")") hlt = HLTConfigSvc("HLTConfigSvc") hlt.XMLMenuFile = self.hltXmlFile hlt.doMergedHLT = TriggerFlags.doHLT() ServiceMgr += hlt else: self.mlog.info( "Will not setup HLTConfigSvc, since TriggerFlags doLVL2(), doEF(), and doHLT() are all False" ) self.states[self.states.index("xml")] = "xmll1" self.mlog.info( "setup LVL1ConfigSvc and add instance to ServiceMgr (xml file=" + self.l1XmlFile + ")") l1 = LVL1ConfigSvc("LVL1ConfigSvc") l1.XMLMenuFile = self.l1XmlFile ServiceMgr += l1 self.mlog.info( "setup L1TopoConfigSvc and add instance to ServiceMgr (xml file=" + self.l1topoXmlFile + ")") l1topo = L1TopoConfigSvc() l1topo.XMLMenuFile = self.l1topoXmlFile ServiceMgr += l1topo if 'ds' in self.states: self.mlog.info( "setup DSConfigSvc and add instance to ServiceMgr") ds = DSConfigSvc("DSConfigSvc") ServiceMgr += ds self.mlog.info( "setup TrigConfigSvc and add instance to ServiceMgr") trigSvc = TrigConfigSvc("TrigConfigSvc") trigSvc.PriorityList = self.states ServiceMgr += trigSvc from AthenaCommon.AppMgr import theApp theApp.CreateSvc += [ServiceMgr.TrigConfigSvc.getFullName()]
#HLTonlineNoL1Thr : Everything is taken from COOL, except LVL1ConfigSvc for thresholds #HLToffline : HLT is ran offline. Needs to specify the .xml files #HLTonline : Normal running, everything is taken from COOL tf.configForStartup= "HLTonlineNoL1Thr" try: from TriggerJobOpts.TriggerConfigGetter import TriggerConfigGetter cfg=TriggerConfigGetter() except Exception: treatException("Could not run TriggerConfigGetter()") #--------------------------------------------------------------------------- if tf.configForStartup() == "HLTonlineNoL1Thr": # Want to use LVL1ConfigSvc for LVL1 thresholds only from TrigConfigSvc.TrigConfigSvcConf import TrigConf__LVL1ConfigSvc from AthenaCommon.AppMgr import ServiceMgr l1 = TrigConf__LVL1ConfigSvc("LVL1ConfigSvc") l1.XMLFile = "LVL1config_SingleBeam_v1_7-bit_trigger_types.xml" l1.CreateLegacyObjects=True ServiceMgr += l1 tf.inputLVL1configFile = "LVL1config_SingleBeam_v1_7-bit_trigger_types.xml" tf.inputLVL1configFile.lock() # this is needed to not be overwritten by TrigT1CTMonitoring # The following are using LVL1ConfigSvc (no thresholds involved) # They should use COOL and not the xml file if not hasattr(ToolSvc,'RecMuCTPIByteStreamTool'):
def configure(self): log = logging.getLogger("TriggerConfigGetter.py") # first check the input if "HIT2RDO" in self._environment: TriggerFlags.doLVL2 = False TriggerFlags.doEF = False log.info("For simulation jobs the following flags are set:") log.info("globalflags.InputFormat : %s" % globalflags.InputFormat()) log.info("globalflags.DataSource : %s" % globalflags.DataSource()) log.info("TriggerFlags.configForStartup : %s" % TriggerFlags.configForStartup()) log.info("TriggerFlags.dataTakingConditions : %s" % TriggerFlags.dataTakingConditions()) log.info("TriggerFlags.doLVL2 : %s" % TriggerFlags.doLVL2()) log.info("TriggerFlags.doEF : %s" % TriggerFlags.doEF()) else: if not self.checkInput(): log.error( "Could not determine job input. Can't setup trigger configuration and will return!" ) return self.readPool = globalflags.InputFormat() == 'pool' self.readRDO = rec.readRDO() self.writeESDAOD = rec.doWriteESD() or rec.doWriteAOD( ) or rec.doWriteDPD() self.ConfigSrcList = TriggerFlags.configurationSourceList() self.readMC = globalflags.DataSource( ) == 'geant3' or globalflags.DataSource() == 'geant4' self.readTriggerDB = TriggerFlags.readMenuFromTriggerDb( ) and self.readRDO self.isCommisioning = globalflags.DataSource( ) == 'data' and globalflags.DetGeo() == 'commis' self.l1Folders = TriggerFlags.dataTakingConditions( ) == 'FullTrigger' or TriggerFlags.dataTakingConditions() == 'Lvl1Only' self.hltFolders = TriggerFlags.dataTakingConditions( ) == 'FullTrigger' or TriggerFlags.dataTakingConditions() == 'HltOnly' self.isRun1Data = False if globalflags.DataSource() == 'data': from RecExConfig.AutoConfiguration import GetRunNumber runNumber = GetRunNumber() if runNumber > 0 and runNumber < 230000: self.isRun1Data = True self.isTriggerReprocessing = False # the TriggerFlags.readMenuFromTriggerDb() tells us that we read the trigger menu from the database # the connection itself is defined in TriggerFlags.triggerDbConnection() # reading from the TriggerDB can mean different things: # a) TriggerFlags doLVL2() and doEF() are both False: # - create a tmp sqlite file with the conditions (menu) # - use DSConfigSvc # b) TriggerFlags doLVL2() or doEF() is True: # - use HLTConfigSvc if self.readTriggerDB and (TriggerFlags.doLVL2() or TriggerFlags.doEF() or TriggerFlags.doHLT()): self.ConfigSrcList = [ 'xml' ] # to use L1/HLTConfigSvc and not DSConfigSvc, but only if we are running the HLT if self._environment: # I don't think anyone calls TriggerConfigGetter with an argument self.readPool = False self.writeESDAOD = False self.readHits = False if "ReadPoolRDO" in self._environment: self.readPool = True self.readRDO = True elif "ReadPool" in self._environment: self.readPool = True self.readRDO = False if "WritePool" in self._environment: self.writeESDAOD = True if "HIT2RDO" in self._environment: self.readRDO = False self.readHits = True # define ConfigSvc if not self.ConfigSrcList: if (self.readPool and not self.readRDO) or ( self.readRDO and not self.readPool): # (ESD, AOD, DPD) or (RDO-BS) self.ConfigSrcList = ['ds'] elif (self.readRDO and self.readPool ) or rec.readTAG() or self.readHits: # (RDO-MC) or TAG self.ConfigSrcList = ['xml'] else: # should not get here: should be found by checkInput log.fatal('no reading of BS, RDO, AOD, ESD, or TAG specified') # we need the temporary COOL database, if we read the configuration from XML and write ESD/AOD (or have 'ds' set for some reason) self.makeTempCool = self.readRDO and \ ( self.writeESDAOD or 'ds' in self.ConfigSrcList ) and \ ( self.readMC \ or (self.isCommisioning and (TriggerFlags.readLVL1configFromXML() and TriggerFlags.readHLTconfigFromXML())) \ or TriggerFlags.readMenuFromTriggerDb() ) log.info("Need to create temporary cool file? : %r" % self.makeTempCool) log.info('Creating the Trigger Configuration Services') self.svc = SetupTrigConfigSvc() #set the merged system #self.svc.doMergedHLT = TriggerFlags.doHLT() if 'xml' in self.ConfigSrcList or self.makeTempCool: # sets them if plain XML reading is to be used self.svc.l1topoXmlFile = TriggerFlags.outputL1TopoConfigFile( ) # generated in python self.svc.l1XmlFile = TriggerFlags.outputLVL1configFile( ) # generated in python self.svc.hltXmlFile = TriggerFlags.outputHLTconfigFile( ) # generated in python if TriggerFlags.readL1TopoConfigFromXML(): self.svc.l1topoXmlFile = TriggerFlags.inputL1TopoConfigFile( ) # given XML if TriggerFlags.readLVL1configFromXML(): self.svc.l1XmlFile = TriggerFlags.inputLVL1configFile( ) # given XML if TriggerFlags.readHLTconfigFromXML(): self.svc.hltXmlFile = TriggerFlags.inputHLTconfigFile( ) # given XML ### preparations are done! try: self.svc.SetStates(self.ConfigSrcList) except: log.error('Failed to set state of TrigConfigSvc to %r' % self.ConfigSrcList) else: log.info('The following configuration services will be tried: %r' % self.ConfigSrcList) try: self.svc.InitialiseSvc() except Exception, ex: log.error('Failed to activate TrigConfigSvc: %r' % ex)
def configure(self): log = logging.getLogger( "TriggerConfigGetter.py" ) from PyUtils.MetaReaderPeekerFull import metadata # first check the input if "HIT2RDO" in self._environment: TriggerFlags.doLVL2 = False TriggerFlags.doEF = False log.info("For simulation jobs the following flags are set:") log.info("globalflags.InputFormat : %s", globalflags.InputFormat()) log.info("globalflags.DataSource : %s", globalflags.DataSource()) log.info("TriggerFlags.configForStartup : %s", TriggerFlags.configForStartup()) log.info("TriggerFlags.dataTakingConditions : %s", TriggerFlags.dataTakingConditions()) log.info("TriggerFlags.doLVL2 : %s", TriggerFlags.doLVL2()) log.info("TriggerFlags.doEF : %s", TriggerFlags.doEF()) else: if not self.checkInput(): log.error("Could not determine job input. Can't setup trigger configuration and will return!") return # self.checkInput() may call TriggerConfigCheckMetadata, this can in turn set "rec.doTrigger.set_Value_and_Lock(False)" # but TriggerConfigGetter might have only been called in the first place due to this flag having been true, # so re-check that we're still OK to be executing here if not (recAlgs.doTrigger() or rec.doTrigger() or TriggerFlags.doTriggerConfigOnly()): log.info("Aborting TriggerConfigGetter as the trigger flags were switched to false in checkInput()") return True self.readPool = globalflags.InputFormat() == 'pool' self.readRDO = rec.readRDO() self.writeESDAOD = rec.doWriteESD() or rec.doWriteAOD() or rec.doWriteDPD() self.writeAOD = rec.doWriteAOD() or rec.doWriteDPD() self.ConfigSrcList = TriggerFlags.configurationSourceList() self.readMC = globalflags.DataSource()=='geant3' or globalflags.DataSource()=='geant4' self.readTriggerDB = TriggerFlags.readMenuFromTriggerDb() and self.readRDO self.isCommisioning = globalflags.DataSource()=='data' and globalflags.DetGeo()=='commis' self.l1Folders = TriggerFlags.dataTakingConditions()=='FullTrigger' or TriggerFlags.dataTakingConditions()=='Lvl1Only' self.hltFolders = TriggerFlags.dataTakingConditions()=='FullTrigger' or TriggerFlags.dataTakingConditions()=='HltOnly' self.isRun1Data = False self.hasxAODMeta = ("metadata_items" in metadata and any(('TriggerMenu' in key) for key in metadata["metadata_items"].keys())) if globalflags.DataSource()=='data': from RecExConfig.AutoConfiguration import GetRunNumber runNumber = GetRunNumber() if runNumber is not None and runNumber > 0 and runNumber < 230000 : self.isRun1Data = True self.isTriggerReprocessing = False # the TriggerFlags.readMenuFromTriggerDb() tells us that we read the trigger menu from the database # the connection itself is defined in TriggerFlags.triggerDbConnection() # reading from the TriggerDB can mean different things: # a) TriggerFlags doLVL2() and doEF() are both False: # - create a tmp sqlite file with the conditions (menu) # - use DSConfigSvc # b) TriggerFlags doLVL2() or doEF() is True: # - use HLTConfigSvc if self.readTriggerDB and (TriggerFlags.doLVL2() or TriggerFlags.doEF() or TriggerFlags.doHLT()): self.ConfigSrcList = ['xml'] # to use L1/HLTConfigSvc and not DSConfigSvc, but only if we are running the HLT if self._environment: # I don't think anyone calls TriggerConfigGetter with an argument self.readPool = False self.writeESDAOD = False self.readHits = False if "ReadPoolRDO" in self._environment: self.readPool = True self.readRDO = True elif "ReadPool" in self._environment: self.readPool = True self.readRDO = False if "WritePool" in self._environment: self.writeESDAOD = True if "HIT2RDO" in self._environment: self.readRDO = False self.readHits = True # define ConfigSvc if not self.ConfigSrcList: if (self.readPool and not self.readRDO) or (self.readRDO and not self.readPool): # (ESD, AOD, DPD) or (RDO-BS) self.ConfigSrcList = ['ds'] elif (self.readRDO and self.readPool) or rec.readTAG() or self.readHits: # (RDO-MC) or TAG self.ConfigSrcList = ['xml'] else: # should not get here: should be found by checkInput log.fatal('no reading of BS, RDO, AOD, ESD, or TAG specified') # we need the temporary COOL database, if we read the configuration from XML and write ESD/AOD (or have 'ds' set for some reason) self.makeTempCool = self.readRDO and \ ( self.writeESDAOD or 'ds' in self.ConfigSrcList ) and \ ( self.readMC \ or (self.isCommisioning and (TriggerFlags.readLVL1configFromXML() and TriggerFlags.readHLTconfigFromXML())) \ or TriggerFlags.readMenuFromTriggerDb() ) log.info("Need to create temporary cool file? : %r", self.makeTempCool) log.info('Creating the Trigger Configuration Services') from AthenaCommon.AppMgr import ServiceMgr as svcMgr ######################################################################## # START OF TEMPORARY SOLUTION FOR RUN-3 TRIGGER DEVELOPMENT ######################################################################## from TriggerJobOpts.HLTTriggerResultGetter import EDMDecodingVersion EDMDecodingVersion() # In most use cases this needs to be called much earlier than in HLTTriggerResultGetter if TriggerFlags.EDMDecodingVersion() >= 3: if self.hasxAODMeta: if not hasattr(svcMgr, 'xAODConfigSvc'): from TrigConfxAOD.TrigConfxAODConf import TrigConf__xAODConfigSvc svcMgr += TrigConf__xAODConfigSvc('xAODConfigSvc') else: # Does not have xAODMeta # Run-3 Trigger Configuration Services from TrigConfigSvc.TrigConfigSvcCfg import getL1ConfigSvc, getHLTConfigSvc from AthenaConfiguration.AllConfigFlags import ConfigFlags svcMgr += getL1ConfigSvc(ConfigFlags) svcMgr += getHLTConfigSvc(ConfigFlags) # Needed for TrigConf::xAODMenuWriterMT from TrigConfigSvc.TrigConfigSvcConfig import TrigConfigSvc svcMgr += TrigConfigSvc("TrigConfigSvc") svcMgr.TrigConfigSvc.PriorityList = ["none", "ds", "xml"] else: # non-MT (Run-2) Trigger Configuration self.svc = SetupTrigConfigSvc() if 'xml' in self.ConfigSrcList or self.makeTempCool: # sets them if plain XML reading is to be used self.svc.l1topoXmlFile = TriggerFlags.outputL1TopoConfigFile() # generated in python self.svc.l1XmlFile = TriggerFlags.outputLVL1configFile() # generated in python self.svc.hltXmlFile = TriggerFlags.outputHLTconfigFile() # generated in python if TriggerFlags.readL1TopoConfigFromXML(): self.svc.l1topoXmlFile = TriggerFlags.inputL1TopoConfigFile() # given XML if TriggerFlags.readLVL1configFromXML(): self.svc.l1XmlFile = TriggerFlags.inputLVL1configFile() # given XML if TriggerFlags.readHLTconfigFromXML(): self.svc.hltXmlFile = TriggerFlags.inputHLTconfigFile() # given XML try: self.svc.SetStates( self.ConfigSrcList ) except Exception: log.error( 'Failed to set state of TrigConfigSvc to %r', self.ConfigSrcList ) else: log.info('The following configuration services will be tried: %r', self.ConfigSrcList ) try: self.svc.InitialiseSvc() except Exception as ex: log.error( 'Failed to activate TrigConfigSvc: %r', ex ) ######################################################################## # END OF TEMPORARY SOLUTION FOR RUN-3 TRIGGER DEVELOPMENT ######################################################################## if self.readTriggerDB: log.info( "Using TriggerDB connection '%s'", TriggerFlags.triggerDbConnection() ) self.trigDbConnectionParameters = interpretConnection(TriggerFlags.triggerDbConnection(), resolveAlias=False) self.setConfigSvcConnParams(self.trigDbConnectionParameters) log.info("TriggerFlags.triggerCoolDbConnection is '%s' [default: '']", TriggerFlags.triggerCoolDbConnection()) TrigCoolDbConnection = TriggerFlags.triggerCoolDbConnection() if self.makeTempCool: TrigCoolDbConnection = self.setupTempCOOLWriting(TrigCoolDbConnection) if ('ds' in self.ConfigSrcList) and not self.hasxAODMeta: self.setupCOOLReading(TrigCoolDbConnection) if hasattr(svcMgr, 'DSConfigSvc'): db = 'TRIGGERDB' if self.isRun1Data: db = 'TRIGGERDB_RUN1' elif self.readMC: db = 'TRIGGERDBMC' elif self.isTriggerReprocessing: db = 'TRIGGERDBREPR' svcMgr.DSConfigSvc.ConfigSource = 'dblookup' svcMgr.DSConfigSvc.DBServer = db log.info("DSConfigSvc trigger database is '%s'", db) if not self.hasxAODMeta: self.setupxAODWriting() # all went fine we are configured return True