Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-01 03:53:36

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 sys
0009 import fnmatch
0010 from .dqmPythonTypes import *
0011 
0012 # part of the runTheMatrix magic
0013 from Configuration.Applications.ConfigBuilder import filesFromDASQuery
0014 
0015 options = VarParsing.VarParsing("analysis")
0016 
0017 options.register(
0018     "runkey",
0019     "pp_run",
0020     VarParsing.VarParsing.multiplicity.singleton,
0021     VarParsing.VarParsing.varType.string,
0022     "Run Keys of CMS"
0023 )
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                  286520,
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('maxLumi',
0039                  2000,
0040                  VarParsing.VarParsing.multiplicity.singleton,
0041                  VarParsing.VarParsing.varType.int,
0042                  "Only lumisections up to maxLumi are processed.")
0043 
0044 options.register('minLumi',
0045                  1,
0046                  VarParsing.VarParsing.multiplicity.singleton,
0047                  VarParsing.VarParsing.varType.int,
0048                  "Only lumisections starting from minLumi are processed.")
0049 
0050 options.register('lumiPattern',
0051                  '*0',
0052                  VarParsing.VarParsing.multiplicity.singleton,
0053                  VarParsing.VarParsing.varType.string,
0054                  "Only lumisections with numbers matching lumiPattern are processed.")
0055 
0056 options.register('dataset',
0057                  'auto',
0058                  VarParsing.VarParsing.multiplicity.singleton,
0059                  VarParsing.VarParsing.varType.string,
0060                  "Dataset name like '/ExpressPhysicsPA/PARun2016D-Express-v1/FEVT', or 'auto' to guess it with a DAS query. A dataset_cfi.py that defines 'readFiles' and 'secFiles' (like a DAS Python snippet) will override this, to avoid DAS queries.")
0061 
0062 options.register('noDB',
0063                  True, # default value
0064                  VarParsing.VarParsing.multiplicity.singleton,
0065                  VarParsing.VarParsing.varType.bool,
0066                  "Don't upload the BeamSpot conditions to the DB")
0067 
0068 options.parseArguments()
0069 
0070 try:
0071   # fixed dataset, DAS 'py' snippet
0072   from dataset_cfi import readFiles, secFiles
0073   print("Using filenames from dataset_cfi.py.")
0074 except:
0075   if options.dataset == 'auto':
0076     print("Querying DAS for a dataset...")
0077     import subprocess
0078     out = subprocess.check_output("dasgoclient --query 'dataset run=%d dataset=/*Express*/*/*FEVT*'" % options.runNumber, shell=True)
0079     dataset = out.splitlines()[-1]
0080     print("Using dataset=%s." % dataset)
0081   else:
0082     dataset = options.dataset
0083 
0084   print("Querying DAS for files...")
0085   readFiles = cms.untracked.vstring()
0086   secFiles = cms.untracked.vstring()
0087   # this outputs all results, which can be a lot...
0088   read, sec = filesFromDASQuery("file run=%d dataset=%s" % (options.runNumber, dataset), option=" --limit 10000 ")
0089   readFiles.extend(read)
0090   secFiles.extend(sec)
0091 
0092 print("Got %d files." % len(readFiles))
0093 
0094 runstr = str(options.runNumber)
0095 runpattern = "*" + runstr[0:3] + "/" + runstr[3:] + "*"
0096 readFiles = cms.untracked.vstring([f for f in readFiles if fnmatch.fnmatch(f, runpattern)])
0097 secFiles = cms.untracked.vstring([f for f in secFiles if fnmatch.fnmatch(f, runpattern)])
0098 lumirange =  cms.untracked.VLuminosityBlockRange(
0099   [ str(options.runNumber) + ":" + str(ls) 
0100       for ls in range(options.minLumi, options.maxLumi+1)
0101       if fnmatch.fnmatch(str(ls), options.lumiPattern)
0102   ]
0103 )
0104 
0105 print("Selected %d files and %d LS." % (len(readFiles), len(lumirange)))
0106 
0107 source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles, lumisToProcess = lumirange)
0108 maxEvents = cms.untracked.PSet(
0109     input = cms.untracked.int32(-1)
0110 )
0111 
0112 # Fix to allow scram to compile
0113 #if len(sys.argv) > 1:
0114 #  options.parseArguments()
0115 
0116 runType = RunType()
0117 if not options.runkey.strip():
0118     options.runkey = "pp_run"
0119 
0120 runType.setRunType(options.runkey.strip())