CMS 3D CMS Logo

fileinputsource_cfi.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 # Parameters for runType
4 import FWCore.ParameterSet.VarParsing as VarParsing
5 import sys
6 import fnmatch
7 from dqmPythonTypes import *
8 
9 # part of the runTheMatrix magic
10 from Configuration.Applications.ConfigBuilder import filesFromDASQuery
11 
12 options = VarParsing.VarParsing("analysis")
13 
14 options.register(
15  "runkey",
16  "pp_run",
17  VarParsing.VarParsing.multiplicity.singleton,
18  VarParsing.VarParsing.varType.string,
19  "Run Keys of CMS"
20 )
21 
22 options.register('runNumber',
23  286520,
24  VarParsing.VarParsing.multiplicity.singleton,
25  VarParsing.VarParsing.varType.int,
26  "Run number. This run number has to be present in the dataset configured with the dataset option.")
27 
28 options.register('maxLumi',
29  2000,
30  VarParsing.VarParsing.multiplicity.singleton,
31  VarParsing.VarParsing.varType.int,
32  "Only lumisections up to maxLumi are processed.")
33 
34 options.register('minLumi',
35  1,
36  VarParsing.VarParsing.multiplicity.singleton,
37  VarParsing.VarParsing.varType.int,
38  "Only lumisections starting from minLumi are processed.")
39 
40 options.register('lumiPattern',
41  '*0',
42  VarParsing.VarParsing.multiplicity.singleton,
43  VarParsing.VarParsing.varType.string,
44  "Only lumisections with numbers matching lumiPattern are processed.")
45 
46 options.register('dataset',
47  'auto',
48  VarParsing.VarParsing.multiplicity.singleton,
49  VarParsing.VarParsing.varType.string,
50  "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.")
51 
52 options.parseArguments()
53 
54 try:
55  # fixed dataset, DAS 'py' snippet
56  from dataset_cfi import readFiles, secFiles
57  print "Using filenames from dataset_cfi.py."
58 except:
59  if options.dataset == 'auto':
60  print "Querying DAS for a dataset..."
61  import subprocess
62  out = subprocess.check_output("dasgoclient --query 'dataset run=%d dataset=/*Express*/*/*FEVT*'" % options.runNumber, shell=True)
63  dataset = out.splitlines()[-1]
64  print "Using dataset=%s." % dataset
65  else:
66  dataset = options.dataset
67 
68  print "Querying DAS for files..."
69  readFiles = cms.untracked.vstring()
70  secFiles = cms.untracked.vstring()
71  # this outputs all results, which can be a lot...
72  read, sec = filesFromDASQuery("file run=%d dataset=%s" % (options.runNumber, dataset), option=" --limit 10000 ")
73  readFiles.extend(read)
74  secFiles.extend(sec)
75 
76 print "Got %d files." % len(readFiles)
77 
78 runstr = str(options.runNumber)
79 runpattern = "*" + runstr[0:3] + "/" + runstr[3:] + "*"
80 readFiles = cms.untracked.vstring([f for f in readFiles if fnmatch.fnmatch(f, runpattern)])
81 secFiles = cms.untracked.vstring([f for f in secFiles if fnmatch.fnmatch(f, runpattern)])
82 lumirange = cms.untracked.VLuminosityBlockRange(
83  [ str(options.runNumber) + ":" + str(ls)
84  for ls in range(options.minLumi, options.maxLumi+1)
85  if fnmatch.fnmatch(str(ls), options.lumiPattern)
86  ]
87 )
88 
89 print "Selected %d files and %d LS." % (len(readFiles), len(lumirange))
90 
91 source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles, lumisToProcess = lumirange)
92 maxEvents = cms.untracked.PSet(
93  input = cms.untracked.int32(100)
94 )
95 
96 # Fix to allow scram to compile
97 #if len(sys.argv) > 1:
98 # options.parseArguments()
99 
100 runType = RunType()
101 if not options.runkey.strip():
102  options.runkey = "pp_run"
103 
104 runType.setRunType(options.runkey.strip())
def filesFromDASQuery(query, option="", s=None)
#define str(s)