Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-10 22:24:31

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