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 # Parameter for frontierKey
28 options.register('runUniqueKey',
29  'InValid',
30  VarParsing.VarParsing.multiplicity.singleton,
31  VarParsing.VarParsing.varType.string,
32  "Unique run key from RCMS for Frontier")
33 
34 options.register('runNumber',
35  344518,
36  VarParsing.VarParsing.multiplicity.singleton,
37  VarParsing.VarParsing.varType.int,
38  "Run number. This run number has to be present in the dataset configured with the dataset option.")
39 
40 options.register('dataset',
41  '/ExpressCosmics/Commissioning2021-Express-v1/FEVT',
42  VarParsing.VarParsing.multiplicity.singleton,
43  VarParsing.VarParsing.varType.string,
44  "Dataset name like '/ExpressCosmics/Commissioning2021-Express-v1/FEVT'")
45 
46 options.register('maxLumi',
47  2,
48  VarParsing.VarParsing.multiplicity.singleton,
49  VarParsing.VarParsing.varType.int,
50  "Only lumisections up to maxLumi are processed.")
51 
52 options.register('minLumi',
53  1,
54  VarParsing.VarParsing.multiplicity.singleton,
55  VarParsing.VarParsing.varType.int,
56  "Only lumisections starting from minLumi are processed.")
57 
58 options.register('lumiPattern',
59  '*',
60  VarParsing.VarParsing.multiplicity.singleton,
61  VarParsing.VarParsing.varType.string,
62  "Only lumisections with numbers matching lumiPattern are processed.")
63 
64 options.register('eventsPerLumi',
65  100,
66  VarParsing.VarParsing.multiplicity.singleton,
67  VarParsing.VarParsing.varType.int,
68  "This number of last events in each lumisection will be processed.")
69 
70 options.register('transDelay',
71  0, #default value, int limit -3
72  VarParsing.VarParsing.multiplicity.singleton,
73  VarParsing.VarParsing.varType.int,
74  "delay in seconds for the commit of the db transaction")
75 
76 # This is used only by the online clients themselves.
77 # We need to register it here because otherwise an error occurs saying that there is an unidentified option.
78 options.register('unitTest',
79  True,
80  VarParsing.VarParsing.multiplicity.singleton,
81  VarParsing.VarParsing.varType.bool,
82  "Required to avoid the error.")
83 
84 options.register('noDB',
85  True, # default value
86  VarParsing.VarParsing.multiplicity.singleton,
87  VarParsing.VarParsing.varType.bool,
88  "Don't upload the BeamSpot conditions to the DB")
89 
90 options.parseArguments()
91 
92 print("Querying DAS for files...")
93 readFiles = cms.untracked.vstring()
94 secFiles = cms.untracked.vstring()
95 eventsToProcess = []
96 
97 # Query DAS for a ROOT file for every lumisection
98 for ls in range(options.minLumi, options.maxLumi+1):
99  if fnmatch.fnmatch(str(ls), options.lumiPattern):
100  read, sec = filesFromDASQuery("file run=%d dataset=%s lumi=%s" % (options.runNumber, options.dataset, ls))
101  readFiles.extend(read)
102  secFiles.extend(sec)
103 
104  # Get last eventsPerLumi of events in this file
105  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]
106  print(command)
107  events = subprocess.check_output(command, shell=True)
108  events = events.split(b'\n')
109  events = filter(lambda x: x != b"", events)
110  events = map(int, events)
111  events = sorted(events)
112  events = events[-options.eventsPerLumi:]
113  eventsToProcess.append("%s:%s:%s-%s:%s:%s" % (options.runNumber, ls, events[0], options.runNumber, ls, events[-1]))
114 
115 eventRange = cms.untracked.VEventRange(eventsToProcess)
116 
117 print("Got %d files." % len(readFiles))
118 
119 source = cms.Source ("PoolSource",
120  fileNames = readFiles,
121  secondaryFileNames = secFiles,
122  eventsToProcess = eventRange,
123 
125  inputCommands = cms.untracked.vstring(
126  'drop *',
127  'keep FEDRawDataCollection_rawDataCollector_*_*',
128  'keep GlobalObjectMapRecord_hltGtStage2ObjectMap_*_*',
129  'keep edmTriggerResults_TriggerResults_*_*'
130  ),
131  dropDescendantsOfDroppedBranches = cms.untracked.bool(True)
132  )
133 maxEvents = cms.untracked.PSet(
134  input = cms.untracked.int32(-1)
135 )
136 
137 runType = RunType()
138 if not options.runkey.strip():
139  options.runkey = "pp_run"
140 
141 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:136
str
#define str(s)
Definition: TestProcessor.cc:53
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:9