CMS 3D CMS Logo

unittestinputsource_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 fnmatch
9 from future.moves import subprocess
10 from .dqmPythonTypes import *
11 
12 # part of the runTheMatrix magic
13 from Configuration.Applications.ConfigBuilder import filesFromDASQuery
14 
15 # This source will process last eventsPerLumi in each provided lumisection.
16 
17 options = VarParsing.VarParsing("analysis")
18 
19 options.register(
20  "runkey",
21  "pp_run",
22  VarParsing.VarParsing.multiplicity.singleton,
23  VarParsing.VarParsing.varType.string,
24  "Run Keys of CMS"
25 )
26 
27 options.register('runNumber',
28  334393,
29  VarParsing.VarParsing.multiplicity.singleton,
30  VarParsing.VarParsing.varType.int,
31  "Run number. This run number has to be present in the dataset configured with the dataset option.")
32 
33 options.register('dataset',
34  '/ExpressCosmics/Commissioning2019-Express-v1/FEVT',
35  VarParsing.VarParsing.multiplicity.singleton,
36  VarParsing.VarParsing.varType.string,
37  "Dataset name like '/ExpressCosmics/Commissioning2019-Express-v1/FEVT'")
38 
39 options.register('maxLumi',
40  2,
41  VarParsing.VarParsing.multiplicity.singleton,
42  VarParsing.VarParsing.varType.int,
43  "Only lumisections up to maxLumi are processed.")
44 
45 options.register('minLumi',
46  1,
47  VarParsing.VarParsing.multiplicity.singleton,
48  VarParsing.VarParsing.varType.int,
49  "Only lumisections starting from minLumi are processed.")
50 
51 options.register('lumiPattern',
52  '*',
53  VarParsing.VarParsing.multiplicity.singleton,
54  VarParsing.VarParsing.varType.string,
55  "Only lumisections with numbers matching lumiPattern are processed.")
56 
57 options.register('eventsPerLumi',
58  100,
59  VarParsing.VarParsing.multiplicity.singleton,
60  VarParsing.VarParsing.varType.int,
61  "This number of last events in each lumisection will be processed.")
62 
63 options.register('transDelay',
64  0, #default value, int limit -3
65  VarParsing.VarParsing.multiplicity.singleton,
66  VarParsing.VarParsing.varType.int,
67  "delay in seconds for the commit of the db transaction")
68 
69 # This is used only by the online clients themselves.
70 # We need to register it here because otherwise an error occurs saying that there is an unidentified option.
71 options.register('unitTest',
72  True,
73  VarParsing.VarParsing.multiplicity.singleton,
74  VarParsing.VarParsing.varType.bool,
75  "Required to avoid the error.")
76 
77 options.register('noDB',
78  True, # default value
79  VarParsing.VarParsing.multiplicity.singleton,
80  VarParsing.VarParsing.varType.bool,
81  "Don't upload the BeamSpot conditions to the DB")
82 
83 options.parseArguments()
84 
85 print("Querying DAS for files...")
86 readFiles = cms.untracked.vstring()
87 secFiles = cms.untracked.vstring()
88 eventsToProcess = []
89 
90 # Query DAS for a ROOT file for every lumisection
91 for ls in range(options.minLumi, options.maxLumi+1):
92  if fnmatch.fnmatch(str(ls), options.lumiPattern):
93  read, sec = filesFromDASQuery("file run=%d dataset=%s lumi=%s" % (options.runNumber, options.dataset, ls))
94  readFiles.extend(read)
95  secFiles.extend(sec)
96 
97  # Get last eventsPerLumi of events in this file
98  command = "edmFileUtil --catalog file:/cvmfs/cms-ib.cern.ch/SITECONF/local/PhEDEx/storage.xml?protocol=xrootd --events %s | tail -n +9 | head -n -5 | awk '{ print $3 }'" % read[0]
99  print(command)
100  events = subprocess.check_output(command, shell=True)
101  events = events.split(b'\n')
102  events = filter(lambda x: x != b"", events)
103  events = map(int, events)
104  events = sorted(events)
105  events = events[-options.eventsPerLumi:]
106  eventsToProcess.append("%s:%s:%s-%s:%s:%s" % (options.runNumber, ls, events[0], options.runNumber, ls, events[-1]))
107 
108 eventRange = cms.untracked.VEventRange(eventsToProcess)
109 
110 print("Got %d files." % len(readFiles))
111 
112 source = cms.Source ("PoolSource", fileNames = readFiles, secondaryFileNames = secFiles, eventsToProcess = eventRange)
113 maxEvents = cms.untracked.PSet(
114  input = cms.untracked.int32(-1)
115 )
116 
117 runType = RunType()
118 if not options.runkey.strip():
119  options.runkey = "pp_run"
120 
121 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:48
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
dqmPythonTypes.RunType
Definition: dqmPythonTypes.py:4
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
genParticles_cff.map
map
Definition: genParticles_cff.py:11
VarParsing.VarParsing
Definition: VarParsing.py:10