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

Test/Debugging harness for the repack configuration builder

"""

import sys
import getopt

from Configuration.DataProcessing.Repack import repackProcess


class RunRepack:

    def __init__(self):
        self.selectEvents = None
        self.inputLFN = None
        self.dataTier = None
        self.rawSkim = None
        self.globalTag= None

    def __call__(self):
        if self.inputLFN == None:
            msg = "No --lfn specified"
            raise RuntimeError(msg)
        allowedDataTiers = ["RAW", "HLTSCOUT", "L1SCOUT"]
        if self.dataTier == None: 
            self.dataTier = "RAW"
        elif self.dataTier not in allowedDataTiers:
            msg = f"{self.dataTier} isn't an allowed datatier for repacking. Allowed data tiers: {allowedDataTiers}"
            raise RuntimeError(msg)

        outputs = []
        outputs.append( { 'moduleLabel' : f"write_PrimDS1_{self.dataTier}" } )
        outputs.append( { 'moduleLabel' : f"write_PrimDS2_{self.dataTier}" } )
        if self.selectEvents != None:
            outputs[0]['selectEvents'] = self.selectEvents.split(',')
            outputs[1]['selectEvents'] = self.selectEvents.split(',')
        if self.rawSkim != None:
            outputs[0]['rawSkim'] = self.rawSkim
            outputs[1]['rawSkim'] = None
        try:
            process = repackProcess(outputs = outputs, globalTag = self.globalTag, dataTier = self.dataTier)
        except Exception as ex:
            msg = "Error creating process for Repack:\n"
            msg += str(ex)
            raise RuntimeError(msg)

        process.source.fileNames.append(self.inputLFN)

        import FWCore.ParameterSet.Config as cms

        process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10) )

        psetFile = open("RunRepackCfg.py", "w")
        psetFile.write(process.dumpPython())
        psetFile.close()
        cmsRun = "cmsRun -e RunRepackCfg.py"
        print("Now do:\n%s" % cmsRun)
        
                


if __name__ == '__main__':
    valid = ["select-events=", "lfn=", "data-tier=", "raw-skim=", "global-tag="]
             
    usage = \
"""
RunRepack.py <options>

Where options are:
 --select-events (option, event selection based on trigger paths)
 --lfn=/store/input/lfn
 --data-tier=RAW|HLTSCOUT|L1SCOUT

Example:
python RunRepack.py --select-events HLT:path1,HLT:path2 --lfn /store/whatever --data-tier RAW|HLTSCOUT|L1SCOUT

"""
    try:
        opts, args = getopt.getopt(sys.argv[1:], "", valid)
    except getopt.GetoptError as ex:
        print(usage)
        print(str(ex))
        sys.exit(1)


    repackinator = RunRepack()

    for opt, arg in opts:
        if opt == "--select-events":
            repackinator.selectEvents = arg
        if opt == "--lfn" :
            repackinator.inputLFN = arg
        if opt == "--data-tier" :
            repackinator.dataTier = arg
        if opt == "--raw-skim":
            repackinator.rawSkim = arg
        if opt == "--global-tag":
            repackinator.globalTag = arg

    repackinator()