Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
#!/usr/bin/env python3
"""
_Utils_

Module containing some utility tools

"""

def stepALCAPRODUCER(skims):
    """
    _stepALCAPRODUCER_

    Creates and returns the configuration string for the ALCAPRODUCER step
    starting from the list of AlcaReco path to be run.

    """

    step = ''
    if len(skims) >0:
        step = ',ALCAPRODUCER:'+('+'.join(skims))
    return step


def stepSKIMPRODUCER(PhysicsSkims):
    """
    _stepSKIMPRODUCER_

    Creates and returns the configuration string for the SKIM step
    starting from the list of skims to be run.

    """

    step = ''
    if len(PhysicsSkims) >0 :
        step = ',SKIM:'+('+'.join(PhysicsSkims))
    return step

def addMonitoring(process):
    """
    _addMonitoring_
    
    Add the monitoring services to the process provided
    in order to write out performance summaries to the framework job report
    """
    import FWCore.ParameterSet.Config as cms
    
    process.SimpleMemoryCheck = cms.Service("SimpleMemoryCheck",
                                            jobReportOutputOnly = cms.untracked.bool(True)
                                            )
    process.Timing = cms.Service("Timing",
                                 summaryOnly = cms.untracked.bool(True)
                                 )
    
    return process


def validateProcess(process):
    """
    _validateProcess_
    
    Check attributes of process are appropriate for production
    This method returns nothing but will throw a RuntimeError for any issues it finds
    likely to cause problems in the production system
    
    """
    
    schedule=process.schedule_()
    paths=process.paths_()
    endpaths=process.endpaths_()
    
    # check output mods are in paths and have appropriate settings
    for outputModName in process.outputModules_().keys():
        outputMod = getattr(process, outputModName)
        if not hasattr(outputMod, 'dataset'):
            msg = "Process contains output module without dataset PSET: %s \n" % outputModName
            msg += " You need to add this PSET to this module to set dataTier and filterName\n"
            raise RuntimeError(msg)
        ds=getattr(outputMod,'dataset')
        if not hasattr(ds, "dataTier"):
            msg = "Process contains output module without dataTier parameter: %s \n" % outputModName
            msg += " You need to add an untracked parameter to the dataset PSET of this module to set dataTier\n"
            raise RuntimeError(msg)

        # check module in path or whatever (not sure of exact syntax for endpath)
        omRun=False

        if schedule==None:
            for path in paths:
                if outputModName in getattr(process,path).moduleNames():
                    omRun=True
            for path in endpaths:
                if outputModName in getattr(process,path).moduleNames():
                    omRun=True
        else:
            for path in schedule:
                if outputModName in path.moduleNames():
                    omRun=True
        if omRun==False:
            msg = "Output Module %s not in endPath" % outputModName
            raise RuntimeError(msg)

        
def dqmIOSource(args):
    import FWCore.ParameterSet.Config as cms
    if args.get('newDQMIO', False):
        return cms.Source("DQMRootSource",
                          fileNames = cms.untracked(cms.vstring())
                          )
    else:
        return cms.Source("PoolSource",
                          fileNames = cms.untracked(cms.vstring())
                          )

def harvestingMode(process, datasetName, args,rANDl=True):
    import FWCore.ParameterSet.Config as cms
    if rANDl and (not args.get('newDQMIO', False)):
        process.source.processingMode = cms.untracked.string('RunsAndLumis')
    process.dqmSaver.workflow = datasetName
    process.dqmSaver.saveByLumiSection = 1

def dictIO(options,args):
    if 'outputs' in args:
        options.outputDefinition = args['outputs'].__str__()
    else:
        writeTiers = args.get('writeTiers', [])
        options.eventcontent = ','.join(writeTiers)
        options.datatier = ','.join(writeTiers)

def dqmSeq(args,default):
    if 'dqmSeq' in args and len(args['dqmSeq'])!=0:
        return ':'+('+'.join(args['dqmSeq']))
    else:
        return default

def nanoFlavours(flavours):
    """
    _nanoFlavours_

    Creates and returns the configuration string for the NANO flavours
    from the list of flavors to be run.

    """

    step = ''
    if len(flavours) >0 :
        step = ':'+('+'.join(flavours))
    return step

def gtNameAndConnect(globalTag, args):
    if 'globalTagConnect' in args and args['globalTagConnect'] != '':
        return globalTag + ','+args['globalTagConnect']        
    # we override here the default in the release which uses the FrontierProd servlet not suited for Tier0 activity
    return globalTag +',frontier://PromptProd/CMS_CONDITIONS'