Exemple #1
0
def _createCfgFlags():

    acf = AthConfigFlags()

    #Flags steering the job execution:
    from AthenaCommon.Constants import INFO
    acf.addFlag('Exec.OutputLevel', INFO)  #Global Output Level
    acf.addFlag('Exec.MaxEvents', -1)
    acf.addFlag("Exec.SkipEvents", 0)
    acf.addFlag("Exec.DebugStage", "")

    #Flags describing the input data
    acf.addFlag('Input.Files', [
        "_ATHENA_GENERIC_INPUTFILE_NAME_",
    ])  # former global.InputFiles
    acf.addFlag('Input.SecondaryFiles',
                [])  # secondary input files for DoubleEventSelector
    acf.addFlag('Input.isMC', lambda prevFlags: "IS_SIMULATION" in GetFileMD(
        prevFlags.Input.Files).get("eventTypes", []))  # former global.isMC
    acf.addFlag('Input.RunNumber', lambda prevFlags: list(
        GetFileMD(prevFlags.Input.Files).get("runNumbers", []))
                )  # former global.RunNumber
    acf.addFlag(
        'Input.ProjectName',
        lambda prevFlags: GetFileMD(prevFlags.Input.Files).get(
            "project_name", "data17_13TeV"))  # former global.ProjectName
    acf.addFlag('Input.Format',
                lambda prevFlags: GetFileMD(prevFlags.Input.Files).get(
                    "file_type", ""))  # former global.InputFormat

    def _inputCollections(inputFile):
        if not inputFile:
            return []

        rawCollections = [
            type_key[1]
            for type_key in GetFileMD(inputFile).get("itemList", [])
        ]
        collections = filter(lambda col: not col.endswith('Aux.'),
                             rawCollections)
        return collections

    acf.addFlag('Input.Collections',
                lambda prevFlags: _inputCollections(prevFlags.Input.Files))
    acf.addFlag(
        'Input.SecondaryCollections',
        lambda prevFlags: _inputCollections(prevFlags.Input.SecondaryFiles))

    acf.addFlag('Concurrency.NumProcs', 0)
    acf.addFlag('Concurrency.NumThreads', 0)
    acf.addFlag('Concurrency.NumConcurrentEvents', 0)

    acf.addFlag('Scheduler.CheckDependencies', True)
    acf.addFlag('Scheduler.ShowDataDeps', True)
    acf.addFlag('Scheduler.ShowDataFlow', True)
    acf.addFlag('Scheduler.ShowControlFlow', True)

    acf.addFlag(
        'Common.isOnline', False
    )  #  Job runs in an online environment (access only to resources available at P1) # former global.isOnline
    acf.addFlag(
        'Common.useOnlineLumi', lambda prevFlags: prevFlags.Common.isOnline
    )  #  Use online version of luminosity. ??? Should just use isOnline?
    acf.addFlag('Common.doExpressProcessing', False)
    acf.addFlag('Common.bunchCrossingSource', lambda prevFlags: "MC"
                if prevFlags.Input.isMC else "TrigConf"
                )  # what BunchCrossingTool should we use?

    def _checkProject():
        import os
        if "AthSimulation_DIR" in os.environ:
            return "AthSimulation"
        if "AthGeneration_DIR" in os.environ:
            return "AthGeneration"
        #TODO expand this method.
        return "Athena"

    acf.addFlag('Common.Project', _checkProject())

    # replace global.Beam*
    acf.addFlag('Beam.BunchSpacing', 25)  # former global.BunchSpacing
    acf.addFlag('Beam.Type',
                lambda prevFlags: GetFileMD(prevFlags.Input.Files).get(
                    'beam_type', 'collisions'))  # former global.BeamType
    acf.addFlag("Beam.NumberOfCollisions", lambda prevFlags: 2.
                if prevFlags.Beam.Type == 'collisions' else 0.
                )  # former global.NumberOfCollisions
    acf.addFlag('Beam.Energy',
                lambda prevFlags: GetFileMD(prevFlags.Input.Files).get(
                    'beam_energy', 7 * TeV))  # former global.BeamEnergy
    acf.addFlag('Beam.estimatedLuminosity', lambda prevFlags : ( 1E33*(prevFlags.Beam.NumberOfCollisions)/2.3 ) *\
        (25./prevFlags.Beam.BunchSpacing)) # former flobal.estimatedLuminosity

    acf.addFlag('Output.EVNTFileName', '')
    acf.addFlag('Output.HITSFileName', '')
    acf.addFlag('Output.RDOFileName', '')
    acf.addFlag('Output.RDO_SGNLFileName', '')
    acf.addFlag('Output.ESDFileName', '')
    acf.addFlag('Output.AODFileName', '')
    acf.addFlag('Output.HISTFileName', '')

    acf.addFlag('Output.doWriteRDO', lambda prevFlags: bool(
        prevFlags.Output.RDOFileName))  # write out RDO file
    acf.addFlag('Output.doWriteRDO_SGNL', lambda prevFlags: bool(
        prevFlags.Output.RDO_SGNLFileName))  # write out RDO_SGNL file
    acf.addFlag('Output.doWriteESD', lambda prevFlags: bool(
        prevFlags.Output.ESDFileName))  # write out ESD file
    acf.addFlag('Output.doESD', lambda prevFlags: prevFlags.Output.doWriteESD
                )  # produce ESD containers
    acf.addFlag('Output.doWriteAOD', lambda prevFlags: bool(
        prevFlags.Output.AODFileName))  # write out AOD file
    acf.addFlag('Output.doWriteBS', False)  # write out RDO ByteStream file

    # Might move this elsewhere in the future.
    # Some flags from https://gitlab.cern.ch/atlas/athena/blob/master/Tracking/TrkDetDescr/TrkDetDescrSvc/python/TrkDetDescrJobProperties.py
    # (many, e.g. those that set properties of one tool are not needed)
    acf.addFlag('TrackingGeometry.MagneticFileMode', 6)
    acf.addFlag('TrackingGeometry.MaterialSource',
                'COOL')  # Can be COOL, Input or None

    #Detector Flags:
    def __detector():
        from AthenaConfiguration.DetectorConfigFlags import createDetectorConfigFlags
        return createDetectorConfigFlags()

    acf.addFlagsCategory("Detector", __detector)

    #Simulation Flags:
    def __simulation():
        from G4AtlasApps.SimConfigFlags import createSimConfigFlags
        return createSimConfigFlags()

    _addFlagsCategory(acf, "Sim", __simulation, 'G4AtlasApps')

    #Digitization Flags:
    def __digitization():
        from Digitization.DigitizationConfigFlags import createDigitizationCfgFlags
        return createDigitizationCfgFlags()

    _addFlagsCategory(acf, "Digitization", __digitization, 'Digitization')

    #Overlay Flags:
    def __overlay():
        from OverlayConfiguration.OverlayConfigFlags import createOverlayConfigFlags
        return createOverlayConfigFlags()

    _addFlagsCategory(acf, "Overlay", __overlay, 'OverlayConfiguration')

    #Geo Model Flags:
    def __geomodel():
        from AthenaConfiguration.GeoModelConfigFlags import createGeoModelConfigFlags
        return createGeoModelConfigFlags()

    acf.addFlagsCategory("GeoModel", __geomodel)

    #IOVDbSvc Flags:
    acf.addFlag(
        "IOVDb.GlobalTag",
        lambda prevFlags: GetFileMD(prevFlags.Input.Files).get(
            "IOVDbGlobalTag", None) or "CONDBR2-BLKPA-2017-05")
    from IOVDbSvc.IOVDbAutoCfgFlags import getDatabaseInstanceDefault
    acf.addFlag("IOVDb.DatabaseInstance", getDatabaseInstanceDefault)

    def __bfield():
        from MagFieldConfig.BFieldConfigFlags import createBFieldConfigFlags
        return createBFieldConfigFlags()

    _addFlagsCategory(acf, "BField", __bfield, 'MagFieldConfig')

    def __lar():
        from LArConfiguration.LArConfigFlags import createLArConfigFlags
        return createLArConfigFlags()

    _addFlagsCategory(acf, "LAr", __lar, 'LArConfiguration')

    def __tile():
        from TileConfiguration.TileConfigFlags import createTileConfigFlags
        return createTileConfigFlags()

    _addFlagsCategory(acf, 'Tile', __tile, 'TileConfiguration')

    def __calo():
        from CaloRec.CaloConfigFlags import createCaloConfigFlags
        return createCaloConfigFlags()

    _addFlagsCategory(acf, 'Calo', __calo, 'CaloRec')

    #Random engine Flags:
    acf.addFlag(
        "Random.Engine",
        "dSFMT")  # Random service used in {"dSFMT", "Ranlux64", "Ranecu"}

    def __trigger():
        from TriggerJobOpts.TriggerConfigFlags import createTriggerFlags
        return createTriggerFlags()

    _addFlagsCategory(acf, "Trigger", __trigger, 'TriggerJobOpts')

    def __indet():
        from InDetConfig.InDetConfigFlags import createInDetConfigFlags
        return createInDetConfigFlags()

    _addFlagsCategory(acf, "InDet", __indet, 'InDetConfig')

    def __muon():
        from MuonConfig.MuonConfigFlags import createMuonConfigFlags
        return createMuonConfigFlags()

    _addFlagsCategory(acf, "Muon", __muon, 'MuonConfig')

    def __muoncombined():
        from MuonCombinedConfig.MuonCombinedConfigFlags import createMuonCombinedConfigFlags
        return createMuonCombinedConfigFlags()

    _addFlagsCategory(acf, "MuonCombined", __muoncombined,
                      'MuonCombinedConfig')

    def __egamma():
        from egammaConfig.egammaConfigFlags import createEgammaConfigFlags
        return createEgammaConfigFlags()

    _addFlagsCategory(acf, "Egamma", __egamma, 'egammaConfig')

    def __met():
        from METReconstruction.METConfigFlags import createMETConfigFlags
        return createMETConfigFlags()

    _addFlagsCategory(acf, "MET", __met, 'METReconstruction')

    def __pflow():
        from eflowRec.PFConfigFlags import createPFConfigFlags
        return createPFConfigFlags()

    _addFlagsCategory(acf, "PF", __pflow, 'eflowRec')

    def __btagging():
        from BTagging.BTaggingConfigFlags import createBTaggingConfigFlags
        return createBTaggingConfigFlags()

    _addFlagsCategory(acf, "BTagging", __btagging, 'BTagging')

    def __dq():
        from AthenaMonitoring.DQConfigFlags import createDQConfigFlags
        dqf = createDQConfigFlags()
        return dqf

    _addFlagsCategory(acf, "DQ", __dq, 'AthenaMonitoring')

    def __perfmon():
        from PerfMonComps.PerfMonConfigFlags import createPerfMonConfigFlags
        return createPerfMonConfigFlags()

    _addFlagsCategory(acf, "PerfMon", __perfmon, 'PerfMonComps')

    return acf
Exemple #2
0
def createTriggerFlags():
    flags = AthConfigFlags()

    # enables L1 simulation
    flags.addFlag('Trigger.doLVL1', lambda prevFlags: prevFlags.Input.isMC)

    # enables L1 topological trigger simulation
    flags.addFlag('Trigger.doL1Topo', True)

    # writes additional info from Topo simulation
    flags.addFlag('Trigger.writeL1TopoValData', True)

    # need proper documentation
    flags.addFlag('Trigger.useL1CaloCalibration', False)

    # need proper documentation
    flags.addFlag('Trigger.useRun1CaloEnergyScale', False)

    # enable HLT part of the trigger
    flags.addFlag('Trigger.doHLT', True)

    # changes decoding of L1 so that allways all configured chains are enabled, testing mode
    flags.addFlag("Trigger.L1Decoder.forceEnableAllChains", False)

    # Enable Run-3 LVL1 simulation and/or decoding
    flags.addFlag('Trigger.enableL1Phase1', False)

    # Enable usage of new L1 menu
    flags.addFlag('Trigger.readLVL1FromJSON', True)

    # Enable Run-2 L1Calo simulation and/or decoding (possible even if enablePhase1 is True)
    flags.addFlag('Trigger.enableL1CaloLegacy', True)

    # Enable Inner Detector
    flags.addFlag('Trigger.doID', True)

    # Enable muon system
    flags.addFlag('Trigger.doMuon', True)

    # Enable calorimeters
    flags.addFlag('Trigger.doCalo', True)

    # if 1, Run1 decoding version is set; if 2, Run2; if 3, Run 3
    def EDMDecodingVersion(flags):
        log.debug("Attempting to determine EDMDecodingVersion.")
        version = 3
        if flags.Input.Format == "BS":
            log.debug("EDMDecodingVersion: Input format is ByteStream")
            inputFileName = flags.Input.Files[0]
            if not inputFileName and flags.Common.isOnline():
                log.debug(
                    "EDMDecodingVersion: Online reconstruction, no input file. Return default version, i.e. AthenaMT."
                )
                return version

            log.debug("EDMDecodingVersion: Checking ROD version.")
            import eformat
            from libpyeformat_helper import SubDetector
            bs = eformat.istream(inputFileName)

            rodVersionM = -1
            rodVersionL = -1
            # Find the first HLT ROBFragment in the first event
            for robf in bs[0]:
                if robf.rob_source_id().subdetector_id(
                ) == SubDetector.TDAQ_HLT:
                    rodVersionM = robf.rod_minor_version() >> 8
                    rodVersionL = robf.rod_minor_version() & 0xFF
                    log.debug(
                        "EDMDecodingVersion: HLT ROD minor version from input file is {:d}.{:d}"
                        .format(rodVersionM, rodVersionL))
                    break

            if rodVersionM >= 1:
                version = 3
                return version
            log.info(
                "EDMDecodingVersion: Could not determine ROD version -- falling back to run-number-based determination"
            )

            # Use run number to determine decoding version
            runNumber = flags.Input.RunNumber[0]
            log.debug(
                "EDMDecodingVersion: Read run number {}.".format(runNumber))

            boundary_run12 = 230000
            boundary_run23 = 368000

            if runNumber <= 0:
                log.warning(
                    "EDMDecodingVersion: Cannot determine decoding version because run number {} is invalid. Leaving the default version."
                    .format(runNumber))
            elif runNumber < boundary_run12:
                # Run-1 data
                version = 1
            elif runNumber < boundary_run23:
                # Run-2 data
                version = 2
            else:
                # Run-3 data
                version = 3
        else:
            log.debug(
                "EDMDecodingVersion: Input format is POOL -- determine from input file collections."
            )
            # POOL files: decide based on HLT output type present in file
            if "HLTResult_EF" in flags.Input.Collections:
                version = 1
            elif "TrigNavigation" in flags.Input.Collections:
                version = 2
            elif "HLTNav_Summary" in flags.Input.Collections:
                version = 3
            elif flags.Input.Format == "POOL":
                # If running Trigger on RDO input (without previous trigger result), choose Run-3
                version = 3
        log.info("Determined EDMDecodingVersion to be {}.".format({
            1: "Run 1",
            2: "Run 2",
            3: "AthenaMT"
        }[version]))
        return version

    flags.addFlag('Trigger.EDMDecodingVersion',
                  lambda prevFlags: EDMDecodingVersion(prevFlags))

    # enables additional algorithms colecting MC truth infrmation  (this is only used by IDso maybe we need Trigger.ID.doTruth only?)
    flags.addFlag('Trigger.doTruth', False)

    # only enable services for analysis and BS -> ESD processing (we need better name)
    flags.addFlag('Trigger.doTriggerConfigOnly', False)

    # Enables collection and export of detailed monitoring data of the HLT execution
    flags.addFlag('Trigger.CostMonitoring.doCostMonitoring', False)
    flags.addFlag('Trigger.CostMonitoring.chain',
                  'HLT_costmonitor_CostMonDS_L1All')
    flags.addFlag('Trigger.CostMonitoring.outputCollection',
                  'HLT_TrigCostContainer')
    flags.addFlag('Trigger.CostMonitoring.monitorAllEvents', False)

    # enable Bcm inputs simulation
    flags.addFlag('Trigger.L1.doBcm', True)

    # enable muon inputs simulation
    flags.addFlag('Trigger.L1.doMuons', True)

    # version of CTP data, int value up to 4
    flags.addFlag('Trigger.L1.CTPVersion', 4)

    # list of thresholds (not sure if we want to use new flags to generate L1, leaving out for now?)

    # partition name used to determine online vs offline BS result writing
    import os
    flags.addFlag('Trigger.Online.partitionName',
                  os.getenv('TDAQ_PARTITION') or '')

    # shortcut to check if job is running in a partition (i.e. partition name is not empty)
    flags.addFlag(
        'Trigger.Online.isPartition',
        lambda prevFlags: len(prevFlags.Trigger.Online.partitionName) > 0)

    # write BS output file
    flags.addFlag('Trigger.writeBS', False)

    # Write transient BS before executing HLT algorithms (for running on MC RDO with clients which require BS inputs)
    flags.addFlag('Trigger.doTransientByteStream', False)

    # list of EDM objects to be written to AOD
    flags.addFlag('Trigger.AODEDMSet', 'AODSLIM')

    # list of objects to be written to ESD
    flags.addFlag('Trigger.ESDEDMSet', 'ESD')

    # tag to be used for condutions used by HLT code
    flags.addFlag('Trigger.OnlineCondTag', 'CONDBR2-HLTP-2018-01')

    # geometry version used by HLT online
    flags.addFlag('Trigger.OnlineGeoTag', 'ATLAS-R2-2016-01-00-01')

    # configuration tune for various years of Run2 (why string?)
    flags.addFlag('Trigger.run2Config', '2018')

    # comissionig options
    # one of:  'HltOnly',
    #    'Lvl1Only',
    #    'FullTrigger',
    #    'NoTrigger'
    flags.addFlag('Trigger.dataTakingConditions', 'FullTrigger')

    # use or not frontier proxies
    flags.addFlag('Trigger.triggerUseFrontier', False)

    # the configuration source
    # see https://twiki.cern.ch/twiki/bin/view/Atlas/TriggerConfigFlag
    flags.addFlag('Trigger.triggerConfig', 'FILE')

    # name of the trigger menu
    flags.addFlag('Trigger.triggerMenuSetup', 'LS2_v1')

    # name of the trigger menu
    flags.addFlag('Trigger.generateMenuDiagnostics', False)

    # version of the menu
    from AthenaCommon.AppMgr import release_metadata
    flags.addFlag('Trigger.menuVersion',
                  lambda prevFlags: release_metadata()['release'])

    # generate or not the HLT configuration
    flags.addFlag('Trigger.generateHLTMenu', False)

    # HLT XML file name
    flags.addFlag(
        'Trigger.HLTMenuFile', lambda prevFlags: 'HLTMenu_' + prevFlags.Trigger
        .triggerMenuSetup + '_' + prevFlags.Trigger.menuVersion + '.xml')

    # generate or not the L1 configuration
    flags.addFlag('Trigger.generateL1Menu', False)

    def _deriveL1ConfigName(prevFlags):
        import re
        log = logging.getLogger('TrigConfigSvcCfg')
        pattern = re.compile(r'_v\d+|DC14')
        menuName = prevFlags.Trigger.triggerMenuSetup
        patternPos = pattern.search(menuName)
        if patternPos:
            menuName = menuName[:patternPos.end()]
        else:
            log.info(
                'Can\'t find pattern to shorten menu name, either non-existent in name or not implemented.'
            )

        return "LVL1config_" + menuName + "_" + prevFlags.Trigger.menuVersion + ".xml"

    # L1 XML file name
    flags.addFlag('Trigger.LVL1ConfigFile', _deriveL1ConfigName)

    # L1 Json file name
    flags.addFlag(
        'Trigger.L1MenuFile', lambda prevFlags: 'L1Menu_' + prevFlags.Trigger.
        triggerMenuSetup + '_' + prevFlags.Trigger.menuVersion + '.json')

    # L1 topo XML file name
    def _deriveTopoConfigName(prevFlags):
        import re
        menuSetup = prevFlags.Trigger.triggerMenuSetup
        m = re.match(r'(.*v\d).*', menuSetup)
        if m:
            menuSetup = m.groups()[0]
        return "L1Topoconfig_" + menuSetup + "_" + prevFlags.Trigger.menuVersion + ".xml"

    flags.addFlag('Trigger.LVL1TopoConfigFile', _deriveTopoConfigName)

    # trigger reconstruction

    # enables the correction for pileup in cell energy calibration (should it be moved to some place where other calo flags are defined?)
    flags.addFlag('Trigger.calo.doOffsetCorrection', True)

    # helper to switch between versions
    def __tunes(default, ver2016, ver2017):
        from collections import defaultdict
        return lambda year: defaultdict(lambda: default, (
            ('2016', ver2016), ('2017', ver2017)))[year]

    # Particle ID tune
    flags.addFlag(
        'Trigger.egamma.pidVersion', lambda prevFlags: __tunes(
            default='ElectronPhotonSelectorTools/trigger/rel21_mc16a/',
            ver2016='ElectronPhotonSelectorTools/trigger/rel21_mc16a/',
            ver2017='ElectronPhotonSelectorTools/trigger/rel21_20170214/')
        (prevFlags.Trigger.run2Config))

    # cluster correction version, allowed value is: None or v12phiflip_noecorrnogap
    flags.addFlag(
        'Trigger.egamma.clusterCorrectionVersion', lambda prevFlags: __tunes(
            default=None, ver2016=None, ver2017='v12phiflip_noecorrnogap')
        (prevFlags.Trigger.run2Config))
    # tune of MVA
    flags.addFlag(
        'Trigger.egamma.calibMVAVersion',
        lambda prevFlags: __tunes(default='egammaMVACalib/online/v3',
                                  ver2016='egammaMVACalib/online/v3',
                                  ver2017='egammaMVACalib/online/v6')
        (prevFlags.Trigger.run2Config))

    # muons
    flags.addFlag('Trigger.muon.doEFRoIDrivenAccess', False)

    # muon offline reco flags varaint for trigger
    def __muon():
        from MuonConfig.MuonConfigFlags import createMuonConfigFlags
        return createMuonConfigFlags()

    flags.addFlagsCategory('Trigger.Offline', __muon, prefix=True)

    from TriggerJobOpts.MenuConfigFlags import createMenuFlags
    flags.join(createMenuFlags())

    return flags