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
#!/usr/bin/env python3
"""
_Repack_

Module that generates standard repack configurations

"""
import copy
import FWCore.ParameterSet.Config as cms
import HLTrigger.HLTfilters.hltHighLevel_cfi as hlt
import Configuration.Skimming.RAWSkims_cff as RawSkims
from Configuration.AlCa.GlobalTag import GlobalTag

def repackProcess(**args):
    """
    _repackProcess_

    Creates and returns a repack process

    supported options:

    - outputs      : defines output modules
    - globalTag    : contains trigger paths for the selected raw skims in outputs

    Additional comments:

    The selectEvents parameter within the outputs option is of type list, provided by T0.
    The paths in the list have an added ":HLT" to the string, which needs to be removed for propper use of the raw skim machinery.

    """
    from Configuration.EventContent.EventContent_cff import RAWEventContent
    from Configuration.EventContent.EventContent_cff import HLTSCOUTEventContent
    from Configuration.EventContent.EventContent_cff import L1SCOUTEventContent
    process = cms.Process("REPACK")
    process.load("FWCore.MessageLogger.MessageLogger_cfi")
    
    process.maxEvents = cms.untracked.PSet(input=cms.untracked.int32(-1))

    process.configurationMetadata = cms.untracked.PSet(
        name=cms.untracked.string("repack-config"),
        version=cms.untracked.string("none"),
        annotation=cms.untracked.string("auto generated configuration")
    )

    process.options = cms.untracked.PSet(
        Rethrow=cms.untracked.vstring("ProductNotFound", "TooManyProducts", "TooFewProducts"),
        wantSummary=cms.untracked.bool(False)
    )

    process.source = cms.Source(
        "NewEventStreamFileReader",
        fileNames=cms.untracked.vstring()
    )

    defaultDataTier = "RAW"

    # Should we default to something if dataTier arg isn't provided?
    dataTier = args.get('dataTier', defaultDataTier)
    eventContent = RAWEventContent
    if dataTier == "HLTSCOUT":
        eventContent = HLTSCOUTEventContent
    elif dataTier == "L1SCOUT":
        eventContent = L1SCOUTEventContent

    outputs = args.get('outputs', [])

    if len(outputs) > 0:
        process.outputPath = cms.EndPath()
        
    globalTag = args.get('globalTag', None)   
    if globalTag:
        process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
        process.GlobalTag = GlobalTag(process.GlobalTag, globalTag, '')
    
    for output in outputs:

        selectEventsBase = output.get('selectEvents', None)
        rawSkim = output.get('rawSkim', None)

        if rawSkim:

            selectEventsBase = [item.replace(":HLT", "") for item in selectEventsBase]

            process.baseSelection = hlt.hltHighLevel.clone(
                TriggerResultsTag = "TriggerResults::HLT",
                HLTPaths = cms.vstring(selectEventsBase)
            )
            skim = getattr(RawSkims, rawSkim)
            setattr(process, rawSkim, skim)
            path = cms.Path(skim + process.baseSelection)
            selectEvents = f"{rawSkim}Path"
            setattr(process, selectEvents, path)

        else:
            selectEvents = selectEventsBase

        moduleLabel = output['moduleLabel']
        maxSize = output.get('maxSize', None)

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

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

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

        if selectEvents is not None:
            outputModule.SelectEvents = cms.untracked.PSet(
                SelectEvents=cms.vstring(selectEvents)
            )

        setattr(process, moduleLabel, outputModule)

        process.outputPath += outputModule

    return process