Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:42

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