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 # Parameter for frontierKey
26 options.register('runUniqueKey',
27  'InValid',
28  VarParsing.VarParsing.multiplicity.singleton,
29  VarParsing.VarParsing.varType.string,
30  "Unique run key from RCMS for Frontier")
31 
32 options.register('runNumber',
33  286520,
34  VarParsing.VarParsing.multiplicity.singleton,
35  VarParsing.VarParsing.varType.int,
36  "Run number. This run number has to be present in the dataset configured with the dataset option.")
37 
38 options.register('maxLumi',
39  2000,
40  VarParsing.VarParsing.multiplicity.singleton,
41  VarParsing.VarParsing.varType.int,
42  "Only lumisections up to maxLumi are processed.")
43 
44 options.register('minLumi',
45  1,
46  VarParsing.VarParsing.multiplicity.singleton,
47  VarParsing.VarParsing.varType.int,
48  "Only lumisections starting from minLumi are processed.")
49 
50 options.register('lumiPattern',
51  '*0',
52  VarParsing.VarParsing.multiplicity.singleton,
53  VarParsing.VarParsing.varType.string,
54  "Only lumisections with numbers matching lumiPattern are processed.")
55 
56 options.register('dataset',
57  'auto',
58  VarParsing.VarParsing.multiplicity.singleton,
59  VarParsing.VarParsing.varType.string,
60  "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.")
61 
62 options.register('transDelay',
63  0, #default value, int limit -3
64  VarParsing.VarParsing.multiplicity.singleton,
65  VarParsing.VarParsing.varType.int,
66  "delay in seconds for the commit of the db transaction")
67 
68 options.register('noDB',
69  True, # default value
70  VarParsing.VarParsing.multiplicity.singleton,
71  VarParsing.VarParsing.varType.bool,
72  "Don't upload the BeamSpot conditions to the DB")
73 
74 options.parseArguments()
75 
76 try:
77  # fixed dataset, DAS 'py' snippet
78  from dataset_cfi import readFiles, secFiles
79  print("Using filenames from dataset_cfi.py.")
80 except:
81  if options.dataset == 'auto':
82  print("Querying DAS for a dataset...")
83  import subprocess
84  out = subprocess.check_output("dasgoclient --query 'dataset run=%d dataset=/*Express*/*/*FEVT*'" % options.runNumber, shell=True)
85  dataset = out.splitlines()[-1]
86  print("Using dataset=%s." % dataset)
87  else:
88  dataset = options.dataset
89 
90  print("Querying DAS for files...")
91  readFiles = cms.untracked.vstring()
92  secFiles = cms.untracked.vstring()
93  # this outputs all results, which can be a lot...
94  read, sec = filesFromDASQuery("file run=%d dataset=%s" % (options.runNumber, dataset), option=" --limit 10000 ")
95  readFiles.extend(read)
96  secFiles.extend(sec)
97 
98 print("Got %d files." % len(readFiles))
99 
100 runstr = str(options.runNumber)
101 runpattern = "*" + runstr[0:3] + "/" + runstr[3:] + "*"
102 readFiles = cms.untracked.vstring([f for f in readFiles if fnmatch.fnmatch(f, runpattern)])
103 secFiles = cms.untracked.vstring([f for f in secFiles if fnmatch.fnmatch(f, runpattern)])
104 lumirange = cms.untracked.VLuminosityBlockRange(
105  [ str(options.runNumber) + ":" + str(ls)
106  for ls in range(options.minLumi, options.maxLumi+1)
107  if fnmatch.fnmatch(str(ls), options.lumiPattern)
108  ]
109 )
110 
111 print("Selected %d files and %d LS." % (len(readFiles), len(lumirange)))
112 
113 source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles, lumisToProcess = lumirange)
114 maxEvents = cms.untracked.PSet(
115  input = cms.untracked.int32(-1)
116 )
117 
118 # Fix to allow scram to compile
119 #if len(sys.argv) > 1:
120 # options.parseArguments()
121 
122 runType = RunType()
123 if not options.runkey.strip():
124  options.runkey = "pp_run"
125 
126 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:135
str
#define str(s)
Definition: TestProcessor.cc:52
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