示例#1
0
def configure(config, colors=False):
    """Configure the application from parser data 
    """

    #
    if config.OutputLevel <= 3 and not config.Quiet:
        _vars = vars(config)
        _keys = _vars.keys()
        _keys.sort()
        logger.info('Configuration:')
        for _k in _keys:
            logger.info('  %15s : %-s ' % (_k, _vars[_k]))

    ## redefine output level for 'quiet'-mode
    if config.OutputLevel > 5:
        config.OutputLevel = 5
        logger.info('set OutputLevel to be %s ' % config.OutputLevel)

    if config.OutputLevel < 0:
        config.OutputLevel = 0
        logger.info('set OutputLevel to be %s ' % config.OutputLevel)

    if config.Quiet and 4 > config.OutputLevel:
        config.OutputLevel = 4
        logger.info('set OutputLevel to be %s ' % config.OutputLevel)
        from BenderTools.Utils import silence
        silence()
    #
    ## use coherent C++/Python logging levels
    setLogging(config.OutputLevel)
    #
    # some sanity actions:
    #
    config.RootInTES = config.RootInTES.strip()
    config.files = [i.strip() for i in config.files if i.strip()]
    #
    ## start the actual action:
    #
    from Configurables import DaVinci
    #
    ## get the file type for the file extension
    #
    from BenderTools.Parser import dataType
    pyfiles = [i for i in config.files if len(i) == 3 + i.rfind('.py')]
    files = [i for i in config.files if i not in pyfiles]

    from BenderTools.Parser import fileList
    for f in config.FileList:
        files += fileList(f)

    if not files and not config.ImportOptions:
        raise AttributeError('No data files are specified!')

    ## get some info from file names/extensision
    dtype, simu, ext = None, None, None
    if files:
        dtype, simu, ext = dataType(files)
        logger.debug('DataType,Simu&extension:"%s",%s,"%s" (from files)' %
                     (dtype, simu, ext))
    elif config.ImportOptions:
        from Bender.DataUtils import evtSelInput
        ifiles = evtSelInput(config.ImportOptions)
        dtype, simu, ext = dataType(ifiles)
        logger.debug(
            'DataType,Simu&extension:"%s",%s&"%s" (from EventSelector)' %
            (dtype, simu, ext))

    if '2013' == dtype:
        logger.info('Data type 2013 is redefined to be 2012')
        dtype = '2012'

        #
    if ext in ('gen', 'xgen', 'GEN', 'XGEN', 'ldst', 'LDST') and not simu:
        simu = True

    if dtype and dtype != config.DataType:
        logger.info('Redefine DataType from  %s to %s ' %
                    (config.DataType, dtype))
        config.DataType = dtype

    if simu and not config.Simulation:
        logger.info('Redefine Simulation from  %s to %s ' %
                    (config.Simulation, simu))
        config.Simulation = simu

    if config.Simulation and config.Lumi:
        logger.info('suppress Lumi for Simulated data')
        config.Lumi = False

    ## summary information (when available)
    from Configurables import LHCbApp
    LHCbApp().XMLSummary = 'summary.xml'

    daVinci = DaVinci(
        DataType=config.DataType,
        Simulation=config.Simulation,
        Lumi=config.Lumi,
    )

    if hasattr(config, 'TupleFile') and config.TupleFile:
        logger.info('Define TupleFile to be %s' % config.TupleFile)
        daVinci.TupleFile = config.TupleFile

    if hasattr(config, 'HistoFile') and config.HistoFile:
        logger.info('Define HistogramFile to be %s' % config.HistoFile)
        daVinci.HistogramFile = config.HistoFile

    if config.MicroDST or 'mdst' == ext or 'MDST' == ext or 'uDST' == ext:
        logger.info('Define input type as micro-DST')
        daVinci.InputType = 'MDST'

    #
    ## try to guess RootInTES
    #
    from BenderTools.Parser import hasInFile
    if hasInFile(files, 'CHARM.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/Charm'
        logger.info('RootInTES is set according to CHARM.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'LEPTONIC.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/Leptonic'
        logger.info('RootInTES is set according to LEPTONIC.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'BHADRON.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/Bhadron'
        logger.info('RootInTES is set according to BHADRON.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'PID.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/PID'
        logger.info('RootInTES is set according to PID.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'PSIX.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/PSIX'
        logger.info('RootInTES is set according to PSIX.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'PSIX0.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/PSIX0'
        logger.info('RootInTES is set according to PSIX0.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'BOTTOM.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/BOTTOM'
        logger.info('RootInTES is set according to BOTTOM.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'TURBO.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/Turbo'
        logger.info('RootInTES is set according to TURBO.MDST')
        daVinci.InputType = 'MDST'
    elif hasInFile(files, 'ALLSTREAMS.MDST') and not config.RootInTES:
        config.RootInTES = '/Event/AllStreams'
        logger.info('RootInTES is set according to ALLSTREAMS.MDST')
        daVinci.InputType = 'MDST'

    if config.RootInTES and 0 != config.RootInTES.find('/Event'):
        config.RootInTES = '/Event/' + config.RootInTES
    if config.RootInTES and '/' == config.RootInTES[-1]:
        config.RootInTES = config.RootInTES[:-1]
    if config.RootInTES and '/Event' != config.RootInTES:
        daVinci.RootInTES = config.RootInTES
    #
    ## check for Grid-access
    #
    if config.Grid:
        from Bender.DataUtils import hasGridProxy
        if not hasGridProxy():
            logger.warning(
                'GRID proxy is not available, switch off GRID-lookup')
            config.Grid = ''  ## SWITCH OFF Grid-lookup

    if not config.Simulation and config.DataType in ('2010', '2011', '2012',
                                                     '2013', '2015'):
        #
        ## try to use the latest available tags:
        #
        from Configurables import CondDB
        ## CondDB ( UseLatestTags = [ options.DataType ] )
        ## logger.info('Use latest tags for %s' % options.DataType )
        CondDB(LatestGlobalTagByDataType=config.DataType)
        logger.info('Use latest global tag for data type %s' % config.DataType)

    if config.Simulation:
        #
        ## try to get the tags from Rec/Header
        from BenderTools.GetDBtags import useDBTagsFromData
        tags = useDBTagsFromData(files,
                                 castor=config.Castor,
                                 grid=config.Grid,
                                 daVinci=daVinci,
                                 importOpts=config.ImportOptions,
                                 catalogs=config.XmlCatalogs)

    if config.IgnoreDQFlags:
        logger.info('DataQuality flags will be ignored')
        daVinci.IgnoreDQFlags = config.IgnoreDQFlags

    ## specific action for (x)gen files
    if ext in ('gen', 'xgen', 'GEN', 'XGEN'):
        from BenderTools.GenFiles import genAction
        genAction(ext)

    ## prepare to copy good/marked/tagged evenst
    if hasattr(config, 'OutputFile') and config.OutputFile:
        from BenderTools.GoodEvents import copyGoodEvents
        if 0 <= config.OutputFile.find('.'):
            copyGoodEvents(config.OutputFile)
        else:
            copyGoodEvents("%s.%s" % (config.OutputFile, ext))

    ##  OutptuLevel
    from Configurables import MessageSvc
    msgSvc = MessageSvc(OutputLevel=config.OutputLevel)

    ## import options (if specified)
    for i in config.ImportOptions:
        logger.info("Import options from file %s'" % i)
        from Gaudi.Configuration import importOptions
        importOptions(i)

    if colors:

        logger.debug('Add colorization to MessageSvc')

        from Configurables import MessageSvc
        msgsvc = MessageSvc(
            useColors=True,
            errorColorCode=['yellow', 'red'],
            warningColorCode=['red'],
            fatalColorCode=['blue', 'red'],
        )

        def _color_pre_start_action_():

            logger.debug('Add colorization to MessageSvc')
            from GaudiPython.Bindings import AppMgr
            _g = AppMgr()
            if not _g: return
            _s = _g.service('MessageSvc')
            if not _s: return
            _s.useColors = True
            _s.errorColorCode = ['yellow', 'red']
            _s.warningColorCode = ['red']
            _s.fatalColorCode = ['blue', 'red']
            ##_s.alwaysColorCode  = [ 'blue'            ]
            ##_s.infoColorCode    = [ 'green'           ]
            del _g, _s

        from Bender.Utils import addPreInitAction
        addPreInitAction(_color_pre_start_action_)

    ## set input data
    from Bender.Utils import setData
    setData(
        files,
        config.XmlCatalogs,  ## XML-catalogues 
        config.Castor,  ## use Castor/EOS lookup 
        config.Grid)  ## Use GRID to locate files

    return pyfiles
示例#2
0
from Configurables import (LHCbApp, ApplicationMgr, DataOnDemandSvc,
                           DecodeRawEvent, CondDB, DaVinci)

## Copypasted from LHCb Starterkit:
## (http://lhcb.github.io/first-analysis-steps/05-interactive-dst.html)

appConf = ApplicationMgr()
dv = DaVinci()
dv.DataType = '2015'
dre = DecodeRawEvent()
dre.DataOnDemand = True
lhcbApp = LHCbApp()
dv.PrintFreq = 1000000  # Only results from FT checking loop.
lhcbApp.Simulation = False
CondDB().Upgrade = True
dv.IgnoreDQFlags = True

inputFiles = [sys.argv[-1]]
stream = str(sys.argv[-2])
IOHelper('ROOT').inputFiles(inputFiles)

appMgr = GP.AppMgr()
evt = appMgr.evtsvc()
appMgr.run(1)


def advance(decision):
    """Advance until stripping decision is true, returns
    number of events by which we advanced"""
    n = 0
    while True: