CMS 3D CMS Logo

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