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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
#!/usr/bin/env python3
"""
_AlCaNano_

Scenario supporting proton collisions for AlCa needs when ALCANANO is produced

"""

import os
import sys

from Configuration.DataProcessing.Scenario import *
from Configuration.DataProcessing.Utils import stepALCAPRODUCER,dqmIOSource,harvestingMode,dictIO,gtNameAndConnect,addMonitoring
import FWCore.ParameterSet.Config as cms

class AlCaNano(Scenario):
    def __init__(self):
        Scenario.__init__(self)
        self.recoSeq=''
        self.promptCustoms= [ 'Configuration/DataProcessing/RecoTLR.customisePrompt' ]
        self.promptModifiers = cms.ModifierChain()

    """
    _AlCaNano_

    Implement configuration building for data processing for proton
    collision data taking for AlCa needs when ALCANANO is produced

    """

    def skimsIfNotGiven(self,args,sl):
        if not 'skims' in args:
            args['skims']=sl

    def promptReco(self, globalTag, **args):
        if not 'skims' in args:
            args['skims']=self.skims
        if not 'customs' in args:
            args['customs']= [ ]
        for c in self.promptCustoms:
            args['customs'].append(c)

        options = Options()
        options.__dict__.update(defaultOptions.__dict__)
        options.scenario = "pp"
        dictIO(options,args)
        options.conditions = gtNameAndConnect(globalTag, args)

        if 'customs' in args:
            print(args['customs'])
            options.customisation_file=args['customs']

        options.step = 'RECO'
        options.step += self.recoSeq
        options.step += stepALCAPRODUCER(args['skims'])

        process = cms.Process('RECO', cms.ModifierChain(self.eras, self.promptModifiers) )
        cb = ConfigBuilder(options, process = process, with_output = True)

        # Input source
        process.source = cms.Source("PoolSource",
            fileNames = cms.untracked.vstring()
        )
        cb.prepare()

        return process

    def alcaSkim(self, skims, **args):
        """
        _alcaSkim_
        AlcaReco processing & skims for proton collisions
        """
        step = ""
        pclWflws = [x for x in skims if "PromptCalibProd" in x]
        skims = [x for x in skims if x not in pclWflws]

        if len(pclWflws):
            step += 'ALCA:'+('+'.join(pclWflws))

        if len(skims) > 0:
            if step != "":
                step += ","
            step += "ALCAOUTPUT:"+('+'.join(skims))

        options = Options()
        options.__dict__.update(defaultOptions.__dict__)
        options.scenario = "pp"
        options.step = step
        options.conditions = args['globaltag'] if 'globaltag' in args else 'None'
        if 'globalTagConnect' in args and args['globalTagConnect'] != '':
            options.conditions += ','+args['globalTagConnect']

        options.triggerResultsProcess = 'RECO'

        process = cms.Process('ALCA', self.eras)
        cb = ConfigBuilder(options, process=process)

        # Input source
        process.source = cms.Source(
           "PoolSource",
           fileNames=cms.untracked.vstring()
        )

        cb.prepare()

        for wfl in pclWflws:
            methodToCall = getattr(process, 'ALCARECOStream'+wfl)
            methodToCall.dataset.dataTier = cms.untracked.string('ALCAPROMPT')

        return process


    def dqmHarvesting(self, datasetName, runNumber, globalTag, **args):
        """
        _dqmHarvesting_
        Proton collisions data taking DQM Harvesting
        """
        options = defaultOptions
        options.scenario = "pp"
        options.step = "HARVESTING:alcaHarvesting"
        options.name = "EDMtoMEConvert"
        options.conditions = gtNameAndConnect(globalTag, args)

        process = cms.Process("HARVESTING", self.eras)
        process.source = dqmIOSource(args)
        configBuilder = ConfigBuilder(options, process = process)
        configBuilder.prepare()

        harvestingMode(process,datasetName,args)

        return process

    def alcaHarvesting(self, globalTag, datasetName, **args):
        """
        _alcaHarvesting_
        Proton collisions data taking AlCa Harvesting
        """
        skims = []
        if 'skims' in args:
            skims = args['skims']


        if 'alcapromptdataset' in args:
            skims.append('@'+args['alcapromptdataset'])

        if len(skims) == 0: return None
        options = defaultOptions
        options.scenario = self.cbSc if hasattr(self,'cbSc') else self.__class__.__name__
        options.step = "ALCAHARVEST:"+('+'.join(skims))
        options.name = "ALCAHARVEST"
        options.conditions = gtNameAndConnect(globalTag, args)

        process = cms.Process("ALCAHARVEST", self.eras)
        process.source = cms.Source("PoolSource")

        if 'customs' in args:
            options.customisation_file=args['customs']

        configBuilder = ConfigBuilder(options, process = process)
        configBuilder.prepare()

        process.source.processingMode = cms.untracked.string('RunsAndLumis')
        process.source.fileNames = cms.untracked(cms.vstring())
        process.maxEvents.input = -1
        process.dqmSaver.workflow = datasetName

        return process

    def expressProcessing(self, globalTag, **args):
        """
        _expressProcessing_
        Proton collision data taking express processing
        """
        skims = []
        if 'skims' in args:
            skims = args['skims']
            pclWkflws = [x for x in skims if "PromptCalibProd" in x]
            for wfl in pclWkflws:
                skims.remove(wfl)

        options = Options()
        options.__dict__.update(defaultOptions.__dict__)
        options.scenario = "pp"
        options.step = stepALCAPRODUCER(skims)

        if 'outputs' in args:
            # the RAW data-tier needs a special treatment since the event-content as defined in release is not good enough
            outputs_Raw = [x for x in args['outputs'] if x['dataTier'] == 'RAW']
            outputs_noRaw = [x for x in args['outputs'] if x['dataTier'] != 'RAW']
            if len(outputs_Raw) == 1:
                print('RAW data-tier requested')
            options.outputDefinition = outputs_noRaw.__str__()

        options.conditions = gtNameAndConnect(globalTag, args)

        options.filein = 'tobeoverwritten.xyz'
        if 'inputSource' in args:
            options.filetype = args['inputSource']
        process = cms.Process('RECO', self.eras)

        if 'customs' in args:
            options.customisation_file=args['customs']

        cb = ConfigBuilder(options, process = process, with_output = True, with_input = True)

        cb.prepare()

        addMonitoring(process)

        for output in outputs_Raw:
            print(output)
            moduleLabel = output['moduleLabel']
            selectEvents = output.get('selectEvents', None)
            maxSize = output.get('maxSize', None)

            outputModule = cms.OutputModule(
                "PoolOutputModule",
                fileName = cms.untracked.string("%s.root" % moduleLabel)
                )

            outputModule.dataset = cms.untracked.PSet(dataTier = cms.untracked.string("RAW"))

            if maxSize != None:
                outputModule.maxSize = cms.untracked.int32(maxSize)

            if selectEvents != None:
                outputModule.SelectEvents = cms.untracked.PSet(
                    SelectEvents = cms.vstring(selectEvents)
                    )
            outputModule.outputCommands = cms.untracked.vstring('drop *',
                                                                'keep  *_*_*_HLT')

            setattr(process, moduleLabel, outputModule)
	        # outputModule=getattr(self.process,theModuleLabel)
            setattr(process, moduleLabel+'_step', cms.EndPath(outputModule))
            path = getattr(process, moduleLabel+'_step')
            process.schedule.append(path)

        return process