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