CMS 3D CMS Logo

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