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",
113  fileNames = readFiles,
114  secondaryFileNames = secFiles,
115  eventsToProcess = eventRange,
116 
118  inputCommands = cms.untracked.vstring(
119  'drop *',
120  'keep FEDRawDataCollection_rawDataCollector_*_*',
121  'keep GlobalObjectMapRecord_hltGtStage2ObjectMap_*_*',
122  'keep edmTriggerResults_TriggerResults_*_*'
123  ),
124  dropDescendantsOfDroppedBranches = cms.untracked.bool(True)
125  )
126 maxEvents = cms.untracked.PSet(
127  input = cms.untracked.int32(-1)
128 )
129 
130 runType = RunType()
131 if not options.runkey.strip():
132  options.runkey = "pp_run"
133 
134 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:51
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
dqmPythonTypes.RunType
Definition: dqmPythonTypes.py:4
genParticles_cff.map
map
Definition: genParticles_cff.py:11
VarParsing.VarParsing
Definition: VarParsing.py:10