示例#1
0
# here, the (default) top sequence is used:
from AthenaCommon.AlgSequence import AlgSequence
job = AlgSequence()

### Create the Menu ###
#######################
include("TrigSteering/pureSteering_menu.py")




###    Setup  TrigConfigSvc      ###
####################################
from TrigConfigSvc.TrigConfigSvcConfig import SetupTrigConfigSvc
log.info("setting up TrigConfigSvc:")
svc = SetupTrigConfigSvc()
svc.hltXmlFile = 'pureSteering_menu.xml'
svc.l1XmlFile  = 'l1.xml'

try:
    svc.SetStates( 'xml' )
except:
    log.warning( 'failed to set state of TrigConfigSvc ...')
try:
    svc.InitialiseSvc()
except:
    log.warning( 'failed to activate TrigConfigSvc ...')

ServiceMgr.TrigConfigSvc.OutputLevel=VERBOSE
ServiceMgr.HLTConfigSvc.OutputLevel=VERBOSE
ServiceMgr.LVL1ConfigSvc.OutputLevel=VERBOSE
示例#2
0
import MuonCnvExample.MuonCablingConfig
import MuonRecExample.MuonReadCalib

include("MuonRecExample/MuonRecLoadTools.py")

#######################
### MENUS AND STUFF ###
#######################

from TriggerMenuPython.GenerateMenu import GenerateMenu
GenerateMenu().generate()

from TrigConfigSvc.TrigConfigSvcConfig import SetupTrigConfigSvc

_svc = SetupTrigConfigSvc()

_svc.l1XmlFile = TriggerFlags.inputLVL1configFile() if TriggerFlags.readLVL1configFromXML() \
        else TriggerFlags.outputLVL1configFile()

_svc.hltXmlFile = TriggerFlags.inputHLTconfigFile() if TriggerFlags.readHLTconfigFromXML() \
        else TriggerFlags.outputHLTconfigFile()

try:
    _svc.SetStates(["xml"])
except:
    log.error('Failed to set state of TrigConfigSvc to ["xml"]')
else:
    log.info('State of TrigConfigSvc set to ["xml"]')

try:
示例#3
0
#"""

#roifile=open("Lvl1Results.txt", "w")
#for i in xrange(0,repeat):
#    roifile.write(RoIs)
#roifile.write("\n")
#roifile.close()

#if "useBusyEventSetup" not in dir():
#    useBusyEventSetup=False

###    Setup  TrigConfigSvc      ###
####################################
from TrigConfigSvc.TrigConfigSvcConfig import SetupTrigConfigSvc
log.info("setting up TrigConfigSvc:")
svc = SetupTrigConfigSvc()
svc.hltXmlFile = 'hlttest.xml'
svc.l1topoXmlFile = 'TopoTestMenu.xml'
svc.l1XmlFile = 'l1test.xml'

try:
    svc.SetStates('xml')
except:
    log.warning('failed to set state of TrigConfigSvc ...')
try:
    svc.InitialiseSvc()
except:
    log.warning('failed to activate TrigConfigSvc ...')

ServiceMgr.TrigConfigSvc.OutputLevel = VERBOSE
ServiceMgr.HLTConfigSvc.OutputLevel = VERBOSE
示例#4
0
# setup Lvl1
# initialize LVL1ConfigSvc
log.info("configuring LVL1 (L1Topo and CTP)")
from TriggerJobOpts.Lvl1TriggerOnlineGetter import Lvl1SimulationGetter
lvl1 = Lvl1SimulationGetter()

if globalflags.InputFormat() == 'pool':
    log.info("setting up transient BS")
    TriggerFlags.doTransientByteStream = True
    include("TriggerJobOpts/jobOfragment_TransBS_standalone.py")

# setup HLT
# initialize HLT config svc
from TrigConfigSvc.TrigConfigSvcConfig import SetupTrigConfigSvc
log.info('Creating the trigger configuration service wrapper')
svc = SetupTrigConfigSvc()
if TriggerFlags.readL1TopoConfigFromXML():
    svc.l1topoXmlFile = TriggerFlags.inputL1TopoConfigFile()  # given XML
else:
    svc.l1topoXmlFile = TriggerFlags.outputL1TopoConfigFile(
    )  # generated in python

if TriggerFlags.readLVL1configFromXML():
    svc.l1XmlFile = TriggerFlags.inputLVL1configFile()  # given XML
else:
    svc.l1XmlFile = TriggerFlags.outputLVL1configFile()  # generated in python

if TriggerFlags.readHLTconfigFromXML():
    svc.hltXmlFile = TriggerFlags.inputHLTconfigFile()  # given XML
else:
    svc.hltXmlFile = TriggerFlags.outputHLTconfigFile()  # generated in python
示例#5
0
def _setupConfig():
    rf = {}
    rf['readTAG'] = jp.Rec.readTAG()
    rf['readESD'] = jp.Rec.readESD()
    rf['readAOD'] = jp.Rec.readAOD()
    rf['readBS'] = jp.Rec.Trigger.readBS()
    rf['readRDO'] = jp.Rec.readRDO()
    rf['DataSource'] = jp.Global.DataSource()
    rf['readRDO'] = jp.Rec.readRDO()
    rf['doWriteESD'] = jp.Rec.doWriteESD()
    rf['doWriteAOD'] = jp.Rec.doWriteAOD()
    rf['doWriteTAG'] = jp.Rec.doWriteTAG()
    rf['TrigCoolSQLite'] = False

    global readRDO
    print "global readRDO=", readRDO
    varInit = globals().keys()
    print varInit
    print rf.keys()
    for o in [o for o in rf.keys() if o in varInit]:
        rf[o] = eval(o)

    #print "JJJJ DEBUG Print jobproperties"
    #jp.print_JobProperties('tree&value')
    #print "JJJJ DEBUG Print rec.jobproperties"
    #jp.Rec.print_JobProperties('tree&value')
    #print "JJJJ DEBUG Print rec.Trigger.jobproperties aka TriggerFlags"
    #jp.Rec.Trigger.print_JobProperties('tree&value')

    ## logging for this module
    msg = log.getLogger('TriggerConfig.py')

    ## the generic trigger configuration service needs to be set up
    from TrigConfigSvc.TrigConfigSvcConfig import SetupTrigConfigSvc
    msg.info('Creating the trigger configuration service wrapper')
    svc = SetupTrigConfigSvc()

    ## ================================================================================
    ## the service depends on the condition we are running in
    ##
    ##     environment       ConfigSvc      Data input   Config input   Flags
    ##     ---------------   ------------   ----------   ------------   -----
    ## (1) data taking       HLTConfigSvc   BS           TriggerDB      DataSource='data',...
    ##
    ## (2) MC simulation     HTLConfigSvc   BS, RDO      XML            DataSource='geant3/4' and (readBS=True or readRDO=True) and doFEX=True and doHypo=True
    ##                       (to be replaced by DSConfigSvc later)
    ##
    ## (3) data processing   DSConfigSvc    BS, RDO      COOL/Oracle    readBS=True or readRDO=True
    ##
    ## (4) AOD processing    DSConfigSvc    ESD/AOD      ESD/AOD(run)   (readESD=True or readAOD=True) and doFEX=False and doHypo=False
    ##                       AODConfigSvc                ESD/AOD(ev)
    ##
    ## (5) Trigger ESD/AOD   HLTConfigSvc   ESD/AOD      XML            (readESD or readAOD)=True and doFEX=True and doHypo=True
    ##
    ## (6) Trigger rerun     HLTConfigSvc   ESD/AOD      XML            (readBS or readRDO or readESD or readAOD)=True and doFEX=False and doHypo=True
    ##
    ## (7) TAG reading       HLTConfigSvc   TAG          XML            readTAG=True
    ##
    ##
    ## ================================================================================
    ## In cases (2), (3) and (5) the configuration information needs to be written
    ## into the header of the AOD file. This is completely independent of the configuration
    ## service, but will depend on the flags readESD, readAOD, doWriteESD, doWriteAOD, doWriteTAG
    ##
    ## ================================================================================
    ## two flags are steering the execution of the trigger, if neither
    ## is True, no trigger is used
    ##
    ## - doTrigger: if True, "TriggerRelease/jobOfragment_forRecExCommon.py"
    ## is included
    ##
    ## - doTriggerConfigOnly: if True, no TrigDecision is build/used
    ##
    ## ================================================================================
    ## flags that control the setup of the trigger are
    ##
    ## boolean:
    ## readBS,  readAOD,    readESD,    readRDO,    readTAG
    ## writeBS, doWriteAOD, doWriteESD, doWriteRDO, doWriteTAG
    ## readLVL1configFromXML, readHLTconfigFromXML
    ##
    ## string:
    ## inputHLTconfigFile, inputLVL1configFile, outputHLTconfigFile, outputLVL1configFile
    ##
    ## on/offline:
    ## DataSource: ['data','geant3','geant4']
    ## ================================================================================

    svc.hltXmlFile = lv1_menu_file_name = jp.Rec.Trigger.inputHLTconfigFile()
    svc.l1XmlFile = jp.Rec.Trigger.inputLVL1configFile()

    myList = []
    scenario = 0
    if len(jp.Rec.Trigger.configurationSourceList()) > 0:
        # take the user-defined list of trigger configuration sources:
        myList = jp.Rec.Trigger.configurationSourceList()

    else:
        print jp.Rec
        if rf['readTAG']:  # TAG
            myList = ['xml']

        elif rf['readESD'] or rf['readAOD']:  # AOD/ESD
            myList = ['ds', 'aod', 'xml']

        elif rf['readBS'] or rf['readRDO']:  # RDO/BS
            if rf['DataSource'] == 'data':
                myList = ['ds', 'xml']
            else:
                myList = ['xml']

        else:
            msg.fatal('no reading of BS, RDO, AOD, ESD, or TAG specified')

    message = 'setup the following services in order: '
    for s in myList:
        message += s + " "
    msg.info(message)

    try:
        svc.SetStates(myList)
    except:
        msg.error('failed to set state of TrigConfigSvc ...')

    try:
        svc.InitialiseSvc()
    except:
        msg.error('failed to activate TrigConfigSvc ...')

    if rf['doWriteESD'] or rf['doWriteAOD'] or rf['doWriteTAG'] or ('ds'
                                                                    in myList):

        ## setup the copying of configuration data from input to output metadatastore
        if rf['doWriteESD'] or rf['doWriteAOD'] or rf['doWriteTAG']:
            msg.info(
                'writing of ESD, AOD, or TAG requested, will setup IOVDbSvc to access configuration meta data'
            )
        else:
            msg.info(
                'DSConfigSvc enabled, will setup IOVDbSvc to access configuration meta data'
            )

        # first we need a new algorithm that triggers the copying
        from AthenaCommon.AlgSequence import AlgSequence
        from TrigConfigSvc.TrigConfigSvcConf import TrigConf__TrigConfDataIOVChanger as TrigConfDataIOVChanger
        topAlgs = AlgSequence()
        TrigConfDataIOVChanger = TrigConfDataIOVChanger(
            'TrigConfDataIOVChanger')
        topAlgs += TrigConfDataIOVChanger

        from AthenaCommon.AppMgr import ServiceMgr as svcMgr
        from AthenaCommon.AppMgr import ToolSvc

        if not hasattr(ToolSvc, 'IOVDbMetaDataTool'):
            from IOVDbMetaDataTools.IOVDbMetaDataToolsConf import IOVDbMetaDataTool
            ToolSvc += IOVDbMetaDataTool("IOVDbMetaDataTool")

        if not hasattr(svcMgr, 'MetaDataSvc'):
            from EventSelectorAthenaPool.EventSelectorAthenaPoolConf import MetaDataSvc
            svcMgr += MetaDataSvc("MetaDataSvc")
            svcMgr.MetaDataSvc.MetaDataContainer = "MetaDataHdr"
            svcMgr.MetaDataSvc.MetaDataTools += ["IOVDbMetaDataTool"]

        # for debugging uncomment the following three lines
        from AthenaCommon.Constants import VERBOSE
        ToolSvc.IOVDbMetaDataTool.OutputLevel = VERBOSE
        svcMgr.MetaDataSvc.OutputLevel = VERBOSE

        dbConnection = "<dbConnection>impl=cool;techno=oracle;schema=ATLAS_COOLONL_READER;devdb10:COOLTEST:atlas_trig_stelzer</dbConnection>"

        ### when moving to configurable IOVDbSvc use the ### lines and remove those with ## at the end
        ### import IOVDbSvc.IOVDb
        ### IOVDbSvc = svcMgr.IOVDbSvc
        from AthenaCommon.Include import include  ##
        include("IOVDbSvc/IOVDbSvc_jobOptions.py")  ##
        IOVDbSvc = theApp.service("IOVDbSvc")  ##
        #from AthenaCommon.Constants import VERBOSE
        #IOVDbSvc.OutputLevel = VERBOSE

        ## if we process MC from an XML file the dbConnection needs to
        ## be set to a local SQlite file

        if (rf['readRDO'] or rf['readBS']) and (rf['DataSource'] == 'geant3'
                                                or rf['DataSource'] == 'geant4'
                                                or rf['TrigCoolSQLite']):
            from TrigConfigSvc.TrigConf2COOL import theConfCOOLWriter
            dbConnection = theConfCOOLWriter.dbConnection
            theConfCOOLWriter.isWritingNeeded = True
            TrigConfDataIOVChanger.AdjustIOV = True

        msg.info("COOL DBConnection: " + dbConnection)

        ### svcMgr.IOVDbSvc.Folders+=[dbConnection + "/TRIGGER/HLT/Menu <tag>HEAD</tag>"]
        ### svcMgr.IOVDbSvc.Folders+=[dbConnection + "/TRIGGER/HLT/HltConfigKeys <tag>HEAD</tag>"]
        ### svcMgr.IOVDbSvc.Folders+=[dbConnection + "/TRIGGER/LVL1/Lvl1ConfigKey <tag>HEAD</tag>"]
        ### svcMgr.IOVDbSvc.Folders+=[dbConnection + "/TRIGGER/LVL1/Menu <tag>HEAD</tag>"]
        ### svcMgr.IOVDbSvc.Folders+=[dbConnection + "/TRIGGER/LVL1/Prescales <tag>HEAD</tag>"]
        ### svcMgr.IOVDbSvc.Folders+=[dbConnection + "/TRIGGER/LVL1/ItemDef <tag>HEAD</tag>"]
        ### svcMgr.IOVDbSvc.Folders+=[dbConnection + "/TRIGGER/HLT/Prescales <tag>HEAD</tag>"]
        ### svcMgr.IOVDbSvc.Folders+=[dbConnection + "/TRIGGER/HLT/PrescaleKey <tag>HEAD</tag>"]

        IOVDbSvc.Folders += [
            dbConnection + "/TRIGGER/HLT/Menu <tag>HEAD</tag>"
        ]  ##
        IOVDbSvc.Folders += [
            dbConnection + "/TRIGGER/HLT/HltConfigKeys <tag>HEAD</tag>"
        ]  ##
        IOVDbSvc.Folders += [
            dbConnection + "/TRIGGER/LVL1/Lvl1ConfigKey <tag>HEAD</tag>"
        ]  ##
        IOVDbSvc.Folders += [
            dbConnection + "/TRIGGER/LVL1/Menu <tag>HEAD</tag>"
        ]  ##
        IOVDbSvc.Folders += [
            dbConnection + "/TRIGGER/LVL1/Prescales <tag>HEAD</tag>"
        ]  ##
        IOVDbSvc.Folders += [
            dbConnection + "/TRIGGER/LVL1/ItemDef <tag>HEAD</tag>"
        ]  ##
        IOVDbSvc.Folders += [
            dbConnection + "/TRIGGER/HLT/Prescales <tag>HEAD</tag>"
        ]  ##
        IOVDbSvc.Folders += [
            dbConnection + "/TRIGGER/HLT/PrescaleKey <tag>HEAD</tag>"
        ]  ##

        # only in jobs that write AOD or ESD
        if rf['doWriteAOD'] or rf['doWriteESD']:
            msg.info(
                'writing of ESD or AOD enabled, will setup IOVDbSvc to write configuration meta data'
            )
            ### svcMgr.IOVDbSvc.FoldersToMetaData+=["/TRIGGER/HLT/Menu"]
            ### svcMgr.IOVDbSvc.FoldersToMetaData+=["/TRIGGER/HLT/HltConfigKeys"]
            ### svcMgr.IOVDbSvc.FoldersToMetaData+=["/TRIGGER/LVL1/Lvl1ConfigKey"]
            ### svcMgr.IOVDbSvc.FoldersToMetaData+=["/TRIGGER/LVL1/Menu"]
            ### svcMgr.IOVDbSvc.FoldersToMetaData+=["/TRIGGER/LVL1/Prescales"]
            ### svcMgr.IOVDbSvc.FoldersToMetaData+=["/TRIGGER/LVL1/ItemDef"]
            ### svcMgr.IOVDbSvc.FoldersToMetaData+=["/TRIGGER/HLT/Prescales"]
            ### svcMgr.IOVDbSvc.FoldersToMetaData+=["/TRIGGER/HLT/PrescaleKey"]

            IOVDbSvc.FoldersToMetaData += ["/TRIGGER/HLT/Menu"]  ##
            IOVDbSvc.FoldersToMetaData += ["/TRIGGER/HLT/HltConfigKeys"]  ##
            IOVDbSvc.FoldersToMetaData += ["/TRIGGER/LVL1/Lvl1ConfigKey"]  ##
            IOVDbSvc.FoldersToMetaData += ["/TRIGGER/LVL1/Menu"]  ##
            IOVDbSvc.FoldersToMetaData += ["/TRIGGER/LVL1/Prescales"]  ##
            IOVDbSvc.FoldersToMetaData += ["/TRIGGER/LVL1/ItemDef"]  ##
            IOVDbSvc.FoldersToMetaData += ["/TRIGGER/HLT/Prescales"]  ##
            IOVDbSvc.FoldersToMetaData += ["/TRIGGER/HLT/PrescaleKey"]  ##
示例#6
0
tdt = CfgMgr.Trig__TrigDecisionTool(OutputLevel=Lvl.INFO)
toolSvc += tdt

from RecExConfig.RecFlags import rec
rec.readAOD = True

from TriggerJobOpts.TriggerFlags import TriggerFlags
TriggerFlags.doTriggerConfigOnly = True

## setup configuration service
from TrigConfigSvc.TrigConfigSvcConfig import DSConfigSvc, SetupTrigConfigSvc
dscfg = DSConfigSvc()
dscfg.OutputLevel = Lvl.VERBOSE
svcMgr += dscfg

trigcfg = SetupTrigConfigSvc()
trigcfg.OutputLevel = Lvl.VERBOSE
trigcfg.SetStates('ds')
trigcfg.InitialiseSvc()
#svcMgr += trigcfg

#theApp.ReflexPluginDebugLevel = 1000

## configure the job to write out POOL files
import AthenaPoolCnvSvc.WriteAthenaPool
## create an output stream
job += CfgMgr.AthenaOutputStream('OutStream',
                                 WritingTool="AthenaOutputStreamTool")
# Copy everything from the input and must force reading of all input
# objects
job.OutStream.OutputFile = OUTPUT
chain.addStreamTag('fake')
menu.addHLTChain(chain)

chain = HLTChain('SingleMC_Jet', '6', 'DummyL2_Jet', 'EF')
chain.addHLTSignature( 'EFInDet_Jet' )
chain.addTriggerTypeBit(34)
chain.addStreamTag('jets')
menu.addHLTChain(chain)

menu.writeConfigFiles()

###    Setup  TrigConfigSvc      ###
####################################
from TrigConfigSvc.TrigConfigSvcConfig import SetupTrigConfigSvc
log.info("setting up TrigConfigSvc:")
svc = SetupTrigConfigSvc()
svc.hltXmlFile = 'newMenu.xml'
svc.l1XmlFile  = 'lvl1Menu.xml'

try:
  svc.SetStates( 'xml' )
except:
  log.warning( 'failed to set state of TrigConfigSvc ...')
try:
  svc.InitialiseSvc()
except:
  log.warning( 'failed to activate TrigConfigSvc ...')

ServiceMgr.TrigConfigSvc.OutputLevel=VERBOSE
ServiceMgr.HLTConfigSvc.OutputLevel=VERBOSE
ServiceMgr.LVL1ConfigSvc.OutputLevel=VERBOSE
示例#8
0
                                     CheckRate        = 1000,
                                     doPositiveEndcap = True,
                                     doNegativeEndcap = True)

if jobproperties.Beam.beamType()=='collisions' and hasattr(ToolSvc, 'DQFilledBunchFilterTool'):
  InDetSCTErrMonTool.FilterTools.append(monFilledBunchFilterTool)
  
ToolSvc += InDetSCTErrMonTool
if (InDetFlags.doPrintConfigurables()):
  print InDetSCTErrMonTool
               


if not hasattr(ServiceMgr,"TrigConfigSvc"):
  from TrigConfigSvc.TrigConfigSvcConfig import SetupTrigConfigSvc
  trigconfigsvc= SetupTrigConfigSvc()
  trigconfigsvc.SetStates('ds')
  trigconfigsvc.InitialiseSvc()
  pass

from TrigBunchCrossingTool.BunchCrossingTool import BunchCrossingTool
SCT_BunchCrossingTool = BunchCrossingTool()


from SCT_Monitoring.SCT_MonitoringConf import SCTHitEffMonTool
InDetSCTHitEffMonTool = SCTHitEffMonTool(name = "InDetSCTHitEffMonTool",
                                         DetectorMode            = 3,
                                         OutputLevel             = 4,
                                         IsCosmic                = InDetFlags.doCosmics(),
                                         UseMasks                = False,
                                         LookAtDatabase          = False,
示例#9
0
class TriggerConfigGetter(Configured):
    """ This class brings to the job Trigger Configuration.
    """

    _environment = ""

    def __init__(self, environment=""):
        log = logging.getLogger("TriggerConfigGetter.py")
        if environment:
            log.info('Initialize (environment "%s")' % environment)
        else:
            log.info('Initialize (interpreting rec and trigger flags)')
        self._environment = environment
        super(TriggerConfigGetter, self).__init__()  # calls configure

    def checkFileMetaData(self):
        log = logging.getLogger("TriggerConfigGetter.py")
        from RecExConfig.InputFilePeeker import inputFileSummary
        self.hasLBwiseHLTPrescalesAndL1ItemDef = True
        if rec.readESD() or rec.readAOD() or "ReadPool" in self._environment:
            self.hasLBwiseHLTPrescalesAndL1ItemDef = inputFileSummary[
                'metadata'].has_key(
                    '/TRIGGER/HLT/Prescales'
                )  # they were all added at the same time (Repro with 15.6.3.2 Prod)
        # protection against early runs
        if inputFileSummary.has_key(
                'run_number'
        ) and self._environment == "" and globalflags.DataSource(
        ) == 'data' and rec.readRDO() and any(
            [run < 134230 for run in inputFileSummary['run_number']]):
            self.hasLBwiseHLTPrescalesAndL1ItemDef = False
        if self.hasLBwiseHLTPrescalesAndL1ItemDef:
            log.info("Using LB-wise HLT prescales")
        else:
            log.info("Using run-wise HLT prescales")

    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("TrigTier0/TriggerConfigCheckMetadata.py")

        if rec.readRDO() and globalflags.InputFormat(
        ) == 'bytestream' and globalflags.DataSource() == 'data':
            protectedInclude("TrigTier0/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 setConfigSvcConnParams(self, connectionParameters):
        sl = []
        if hasattr(svcMgr, 'L1TopoConfigSvc'): sl += [svcMgr.L1TopoConfigSvc]
        if hasattr(svcMgr, 'LVL1ConfigSvc'): sl += [svcMgr.LVL1ConfigSvc]
        if hasattr(svcMgr, 'HLTConfigSvc'): sl += [svcMgr.HLTConfigSvc]

        if "alias" in connectionParameters:
            for svc in sl:
                svc.ConfigSource = 'DBLookUp'
                svc.DBServer = connectionParameters["alias"]
                svc.DBUser = ""
        else:
            technology = connectionParameters["techno"]
            for svc in sl:
                svc.ConfigSource = technology

            if technology == 'sqlite':
                for svc in sl:
                    svc.DBServer = connectionParameters["filename"]
                    svc.DBUser = "******"

            if technology == 'oracle':
                for svc in sl:
                    svc.DBServer = connectionParameters["server"]
                    svc.DBAccount = connectionParameters["schema"]
                    svc.DBUser = connectionParameters["user"]
                    svc.DBPass = connectionParameters["passwd"]

        if hasattr(svcMgr, 'L1TopoConfigSvc'):
            svcMgr.L1TopoConfigSvc.DBSMKey = TriggerFlags.triggerDbKeys()[0]
            svcMgr.L1TopoConfigSvc.UseFrontier = TriggerFlags.triggerUseFrontier(
            )
        if hasattr(svcMgr, 'LVL1ConfigSvc'):
            svcMgr.LVL1ConfigSvc.DBSMKey = TriggerFlags.triggerDbKeys()[0]
            svcMgr.LVL1ConfigSvc.DBLVL1PSKey = TriggerFlags.triggerDbKeys()[1]
            svcMgr.LVL1ConfigSvc.DBBGSKey = TriggerFlags.triggerDbKeys()[3]
            svcMgr.LVL1ConfigSvc.UseFrontier = TriggerFlags.triggerUseFrontier(
            )
        if hasattr(svcMgr, 'HLTConfigSvc'):
            svcMgr.HLTConfigSvc.DBSMKey = TriggerFlags.triggerDbKeys()[0]
            svcMgr.HLTConfigSvc.DBHLTPSKey = TriggerFlags.triggerDbKeys()[2]
            svcMgr.HLTConfigSvc.UseFrontier = TriggerFlags.triggerUseFrontier()

    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)

        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 or self.writeESDAOD:
            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 self.writeESDAOD:
            self.setupCOOLWriting()
            self.setupxAODWriting()

        # all went fine we are configured
        return True
示例#10
0
    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)
示例#11
0
class TriggerConfigGetter(Configured):
    """ This class brings to the job Trigger Configuration.
    """

    _environment=""

    def __init__(self, environment=""):
        log = logging.getLogger( "TriggerConfigGetter.py" )
        if environment:
            log.info('Initialize (environment "%s")', environment)
        else:
            log.info('Initialize (interpreting rec and trigger flags)')
        self._environment = environment
        super(TriggerConfigGetter,self).__init__() # calls configure



    def checkFileMetaData(self):
        log = logging.getLogger( "TriggerConfigGetter.py" )
        from PyUtils.MetaReaderPeekerFull import metadata
        self.hasLBwiseHLTPrescalesAndL1ItemDef = True

        # protection against early runs
        if 'runNumbers' in metadata and self._environment == "" and globalflags.DataSource() == 'data' and rec.readRDO() and any([run < 134230 for run in metadata['runNumbers']]):
            self.hasLBwiseHLTPrescalesAndL1ItemDef = False
        if self.hasLBwiseHLTPrescalesAndL1ItemDef:
            log.info("Using LB-wise HLT prescales")
        else:
            log.info("Using run-wise HLT prescales")

    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 setConfigSvcConnParams(self,connectionParameters):
        sl = []
        if hasattr(svcMgr,'L1TopoConfigSvc'):
            sl += [svcMgr.L1TopoConfigSvc]
        if hasattr(svcMgr,'LVL1ConfigSvc'):
            sl += [svcMgr.LVL1ConfigSvc]
        if hasattr(svcMgr,'HLTConfigSvc'):
            sl += [svcMgr.HLTConfigSvc]

        if "alias" in connectionParameters:
            for svc in sl:
                svc.ConfigSource = 'DBLookUp'
                svc.DBServer  = connectionParameters["alias"]
                svc.DBUser = ""
        else:
            technology = connectionParameters["techno"]
            for svc in sl:
                svc.ConfigSource = technology

            if technology == 'sqlite':
                for svc in sl:
                    svc.DBServer = connectionParameters["filename"]
                    svc.DBUser = "******"

            if technology == 'oracle':
                for svc in sl:
                    svc.DBServer  = connectionParameters["server"]
                    svc.DBAccount = connectionParameters["schema"]
                    svc.DBUser    = connectionParameters["user"  ]
                    svc.DBPass    = connectionParameters["passwd"]

        if hasattr(svcMgr,'L1TopoConfigSvc'):
            svcMgr.L1TopoConfigSvc.DBSMKey     = TriggerFlags.triggerDbKeys()[0]
            svcMgr.L1TopoConfigSvc.UseFrontier = TriggerFlags.triggerUseFrontier()
        if hasattr(svcMgr,'LVL1ConfigSvc'):
            svcMgr.LVL1ConfigSvc.DBSMKey     = TriggerFlags.triggerDbKeys()[0]
            svcMgr.LVL1ConfigSvc.DBLVL1PSKey = TriggerFlags.triggerDbKeys()[1]
            svcMgr.LVL1ConfigSvc.DBBGSKey    = TriggerFlags.triggerDbKeys()[3]
            svcMgr.LVL1ConfigSvc.UseFrontier = TriggerFlags.triggerUseFrontier()
        if hasattr(svcMgr,'HLTConfigSvc'):
            svcMgr.HLTConfigSvc.DBSMKey      = TriggerFlags.triggerDbKeys()[0]
            svcMgr.HLTConfigSvc.DBHLTPSKey   = TriggerFlags.triggerDbKeys()[2]
            svcMgr.HLTConfigSvc.UseFrontier  = TriggerFlags.triggerUseFrontier()




    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





    def setupTempCOOLWriting(self,TrigCoolDbConnection):
        log = logging.getLogger( "TriggerConfigGetter.py" )

        log.info( 'Trigger the copying of COOL data into DetectorStore. I am not certain this is needed any longer JS.')

        # if we have MC data (nothing in ORACLE/COOL) we need to write an SQlite file
        # and change the dbConnection
        if ( self.readMC \
             or (self.isCommisioning and (TriggerFlags.readLVL1configFromXML and TriggerFlags.readHLTconfigFromXML)) \
             or TriggerFlags.readMenuFromTriggerDb ):

            log.info( 'TempCoolSetup: Setting up the writing of a temporary COOL DB')

            from TrigConfigSvc.TrigConf2COOL import theConfCOOLWriter
            if self.readTriggerDB:
                log.info("TempCoolSetup: source is db [%s] with keys %s/%s/%s", TriggerFlags.triggerDbConnection(),TriggerFlags.triggerDbKeys()[0],TriggerFlags.triggerDbKeys()[1],TriggerFlags.triggerDbKeys()[2])
                theConfCOOLWriter.smk        = TriggerFlags.triggerDbKeys()[0]
                theConfCOOLWriter.l1psk      = TriggerFlags.triggerDbKeys()[1]
                theConfCOOLWriter.hltpsk     = TriggerFlags.triggerDbKeys()[2]
                theConfCOOLWriter.setTriggerDBConnection(self.trigDbConnectionParameters)
            else:
                log.info("TempCoolSetup: sources are '%s' and '%s'", self.svc.l1XmlFile,self.svc.hltXmlFile)
                theConfCOOLWriter.lvl1menu = self.svc.l1XmlFile
                theConfCOOLWriter.hltmenu  = self.svc.hltXmlFile
            if TrigCoolDbConnection == "": # nothing specified by the user
                TrigCoolDbConnection = re.match(".*;schema=(.*);dbname=.*",theConfCOOLWriter.dbConnection).group(1)
                theConfCOOLWriter.isWritingNeeded = True
                log.info("TempCoolSetup: Setting TrigCoolDbConnection to %s", TrigCoolDbConnection )
                log.info("TempCoolSetup: Enabling writing and IOV adjustment")

        return TrigCoolDbConnection



    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 setupxAODWriting( self ):
        """
        Method setting up the writing of the ROOT-readable trigger configuration
        metadata.
        """

        # Get a logger:
        log = logging.getLogger( "TriggerConfigGetter.py" )
        log.info( "ESD/AOD writing enabled, will set up xAOD trigger "
                  "configuration metadata writing" )

        # Get the algorithm sequence:
        from AthenaCommon.AlgSequence import AlgSequence
        from .TriggerFlags import TriggerFlags
        topAlgs = AlgSequence()

        # Add the algorithm creating the trigger configuration metadata for
        # the output:
        try: 
            if TriggerFlags.EDMDecodingVersion() <= 2:
                from TrigConfxAOD.TrigConfxAODConf import TrigConf__xAODMenuWriter
                topAlgs += TrigConf__xAODMenuWriter( OverwriteEventObj = True )
            else:
                from TrigConfxAOD.TrigConfxAODConf import TrigConf__xAODMenuWriterMT
                menuwriter = TrigConf__xAODMenuWriterMT()
                menuwriter.IsHLTJSONConfig = True
                menuwriter.IsL1JSONConfig = True
                topAlgs += menuwriter

            # The metadata objects to add to the output:
            metadataItems = [ "xAOD::TriggerMenuContainer#TriggerMenu",
                              "xAOD::TriggerMenuAuxContainer#TriggerMenuAux." ]

            # Set up the metadata for the output ESD and AOD:
            from RecExConfig.ObjKeyStore import objKeyStore
            objKeyStore.addManyTypesMetaData( metadataItems )
        except ImportError: # don't want to branch in rel 18
            pass

        # Return gracefully:
        return
示例#12
0
    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