File indexing completed on 2024-11-26 02:34:08
0001 from builtins import range
0002 import FWCore.ParameterSet.Config as cms
0003
0004
0005 import FWCore.ParameterSet.VarParsing as VarParsing
0006 import fnmatch
0007 from future.moves import subprocess
0008 from .dqmPythonTypes import *
0009
0010
0011 from Configuration.Applications.ConfigBuilder import filesFromDASQuery
0012
0013
0014
0015 options = VarParsing.VarParsing("analysis")
0016
0017 options.register("runkey",
0018 "pp_run",
0019 VarParsing.VarParsing.multiplicity.singleton,
0020 VarParsing.VarParsing.varType.string,
0021 "Run Keys of CMS")
0022
0023
0024 options.register('runUniqueKey',
0025 'InValid',
0026 VarParsing.VarParsing.multiplicity.singleton,
0027 VarParsing.VarParsing.varType.string,
0028 "Unique run key from RCMS for Frontier")
0029
0030 options.register('runNumber',
0031 355380,
0032 VarParsing.VarParsing.multiplicity.singleton,
0033 VarParsing.VarParsing.varType.int,
0034 "Run number. This run number has to be present in the dataset configured with the dataset option.")
0035
0036 options.register('dataset',
0037 '/ExpressPhysics/Run2022B-Express-v1/FEVT',
0038 VarParsing.VarParsing.multiplicity.singleton,
0039 VarParsing.VarParsing.varType.string,
0040 "Dataset name like '/ExpressCosmics/Commissioning2021-Express-v1/FEVT'")
0041
0042 options.register('maxLumi',
0043 20,
0044 VarParsing.VarParsing.multiplicity.singleton,
0045 VarParsing.VarParsing.varType.int,
0046 "Only lumisections up to maxLumi are processed.")
0047
0048 options.register('minLumi',
0049 19,
0050 VarParsing.VarParsing.multiplicity.singleton,
0051 VarParsing.VarParsing.varType.int,
0052 "Only lumisections starting from minLumi are processed.")
0053
0054 options.register('lumiPattern',
0055 '*',
0056 VarParsing.VarParsing.multiplicity.singleton,
0057 VarParsing.VarParsing.varType.string,
0058 "Only lumisections with numbers matching lumiPattern are processed.")
0059
0060 options.register('eventsPerLumi',
0061 100,
0062 VarParsing.VarParsing.multiplicity.singleton,
0063 VarParsing.VarParsing.varType.int,
0064 "This number of last events in each lumisection will be processed.")
0065
0066 options.register('BeamSplashRun',
0067 False,
0068 VarParsing.VarParsing.multiplicity.singleton,
0069 VarParsing.VarParsing.varType.bool,
0070 "Set client source settings for beam SPLASH run")
0071
0072
0073
0074 options.register('unitTest',
0075 True,
0076 VarParsing.VarParsing.multiplicity.singleton,
0077 VarParsing.VarParsing.varType.bool,
0078 "Required to avoid the error.")
0079
0080 options.register('noDB',
0081 True,
0082 VarParsing.VarParsing.multiplicity.singleton,
0083 VarParsing.VarParsing.varType.bool,
0084 "Don't upload the BeamSpot conditions to the DB")
0085
0086 options.parseArguments()
0087
0088 print("Querying DAS for files...")
0089 readFiles = cms.untracked.vstring()
0090 secFiles = cms.untracked.vstring()
0091 eventsToProcess = []
0092
0093
0094 for ls in range(options.minLumi, options.maxLumi+1):
0095 if fnmatch.fnmatch(str(ls), options.lumiPattern):
0096 read, sec = filesFromDASQuery("file run=%d dataset=%s lumi=%s" % (options.runNumber, options.dataset, ls))
0097 readFiles.extend(read)
0098 secFiles.extend(sec)
0099
0100
0101 command = "edmFileUtil --events %s | tail -n +9 | head -n -5 | awk '{ print $3 }'" % read[0]
0102 print(command)
0103 events = subprocess.check_output(command, shell=True)
0104 events = events.split(b'\n')
0105 events = filter(lambda x: x != b"", events)
0106 events = map(int, events)
0107 events = sorted(events)
0108 events = events[-options.eventsPerLumi:]
0109 eventsToProcess.append("%s:%s:%s-%s:%s:%s" % (options.runNumber, ls, events[0], options.runNumber, ls, events[-1]))
0110
0111 eventRange = cms.untracked.VEventRange(eventsToProcess)
0112
0113 print("Got %d files." % len(readFiles))
0114
0115 source = cms.Source ("PoolSource",
0116 fileNames = readFiles,
0117 secondaryFileNames = secFiles,
0118 eventsToProcess = eventRange,
0119
0120
0121 inputCommands = cms.untracked.vstring(
0122 'drop *',
0123 'keep FEDRawDataCollection_rawDataCollector_*_*',
0124 'keep GlobalObjectMapRecord_hltGtStage2ObjectMap_*_*',
0125 'keep edmTriggerResults_TriggerResults_*_*'
0126 ),
0127 dropDescendantsOfDroppedBranches = cms.untracked.bool(True)
0128 )
0129 maxEvents = cms.untracked.PSet(
0130 input = cms.untracked.int32(-1)
0131 )
0132
0133 runType = RunType()
0134 if not options.runkey.strip():
0135 options.runkey = "pp_run"
0136
0137 runType.setRunType(options.runkey.strip())