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.parseArguments()
56 
57 try:
58  # fixed dataset, DAS 'py' snippet
59  from dataset_cfi import readFiles, secFiles
60  print("Using filenames from dataset_cfi.py.")
61 except:
62  if options.dataset == 'auto':
63  print("Querying DAS for a dataset...")
64  import subprocess
65  out = subprocess.check_output("dasgoclient --query 'dataset run=%d dataset=/*Express*/*/*FEVT*'" % options.runNumber, shell=True)
66  dataset = out.splitlines()[-1]
67  print("Using dataset=%s." % dataset)
68  else:
69  dataset = options.dataset
70 
71  print("Querying DAS for files...")
72  readFiles = cms.untracked.vstring()
73  secFiles = cms.untracked.vstring()
74  # this outputs all results, which can be a lot...
75  read, sec = filesFromDASQuery("file run=%d dataset=%s" % (options.runNumber, dataset), option=" --limit 10000 ")
76  readFiles.extend(read)
77  secFiles.extend(sec)
78 
79 print("Got %d files." % len(readFiles))
80 
81 runstr = str(options.runNumber)
82 runpattern = "*" + runstr[0:3] + "/" + runstr[3:] + "*"
83 readFiles = cms.untracked.vstring([f for f in readFiles if fnmatch.fnmatch(f, runpattern)])
84 secFiles = cms.untracked.vstring([f for f in secFiles if fnmatch.fnmatch(f, runpattern)])
85 lumirange = cms.untracked.VLuminosityBlockRange(
86  [ str(options.runNumber) + ":" + str(ls)
87  for ls in range(options.minLumi, options.maxLumi+1)
88  if fnmatch.fnmatch(str(ls), options.lumiPattern)
89  ]
90 )
91 
92 print("Selected %d files and %d LS." % (len(readFiles), len(lumirange)))
93 
94 source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles, lumisToProcess = lumirange)
95 maxEvents = cms.untracked.PSet(
96  input = cms.untracked.int32(-1)
97 )
98 
99 # Fix to allow scram to compile
100 #if len(sys.argv) > 1:
101 # options.parseArguments()
102 
103 runType = RunType()
104 if not options.runkey.strip():
105  options.runkey = "pp_run"
106 
107 runType.setRunType(options.runkey.strip())
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def filesFromDASQuery(query, option="", s=None)
#define str(s)