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('noDB',
63  True, # default value
64  VarParsing.VarParsing.multiplicity.singleton,
65  VarParsing.VarParsing.varType.bool,
66  "Don't upload the BeamSpot conditions to the DB")
67 
68 options.parseArguments()
69 
70 try:
71  # fixed dataset, DAS 'py' snippet
72  from dataset_cfi import readFiles, secFiles
73  print("Using filenames from dataset_cfi.py.")
74 except:
75  if options.dataset == 'auto':
76  print("Querying DAS for a dataset...")
77  import subprocess
78  out = subprocess.check_output("dasgoclient --query 'dataset run=%d dataset=/*Express*/*/*FEVT*'" % options.runNumber, shell=True)
79  dataset = out.splitlines()[-1]
80  print("Using dataset=%s." % dataset)
81  else:
82  dataset = options.dataset
83 
84  print("Querying DAS for files...")
85  readFiles = cms.untracked.vstring()
86  secFiles = cms.untracked.vstring()
87  # this outputs all results, which can be a lot...
88  read, sec = filesFromDASQuery("file run=%d dataset=%s" % (options.runNumber, dataset), option=" --limit 10000 ")
89  readFiles.extend(read)
90  secFiles.extend(sec)
91 
92 print("Got %d files." % len(readFiles))
93 
94 runstr = str(options.runNumber)
95 runpattern = "*" + runstr[0:3] + "/" + runstr[3:] + "*"
96 readFiles = cms.untracked.vstring([f for f in readFiles if fnmatch.fnmatch(f, runpattern)])
97 secFiles = cms.untracked.vstring([f for f in secFiles if fnmatch.fnmatch(f, runpattern)])
98 lumirange = cms.untracked.VLuminosityBlockRange(
99  [ str(options.runNumber) + ":" + str(ls)
100  for ls in range(options.minLumi, options.maxLumi+1)
101  if fnmatch.fnmatch(str(ls), options.lumiPattern)
102  ]
103 )
104 
105 print("Selected %d files and %d LS." % (len(readFiles), len(lumirange)))
106 
107 source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles, lumisToProcess = lumirange)
108 maxEvents = cms.untracked.PSet(
109  input = cms.untracked.int32(-1)
110 )
111 
112 # Fix to allow scram to compile
113 #if len(sys.argv) > 1:
114 # options.parseArguments()
115 
116 runType = RunType()
117 if not options.runkey.strip():
118  options.runkey = "pp_run"
119 
120 runType.setRunType(options.runkey.strip())
def filesFromDASQuery(query, option="", s=None)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)