CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 # This is used only by the online clients themselves.
71 # We need to register it here because otherwise an error occurs saying that there is an unidentified option.
72 options.register('unitTest',
73  True,
74  VarParsing.VarParsing.multiplicity.singleton,
75  VarParsing.VarParsing.varType.bool,
76  "Required to avoid the error.")
77 
78 options.register('noDB',
79  True, # default value
80  VarParsing.VarParsing.multiplicity.singleton,
81  VarParsing.VarParsing.varType.bool,
82  "Don't upload the BeamSpot conditions to the DB")
83 
84 options.parseArguments()
85 
86 print("Querying DAS for files...")
87 readFiles = cms.untracked.vstring()
88 secFiles = cms.untracked.vstring()
89 eventsToProcess = []
90 
91 # Query DAS for a ROOT file for every lumisection
92 for ls in range(options.minLumi, options.maxLumi+1):
93  if fnmatch.fnmatch(str(ls), options.lumiPattern):
94  read, sec = filesFromDASQuery("file run=%d dataset=%s lumi=%s" % (options.runNumber, options.dataset, ls))
95  readFiles.extend(read)
96  secFiles.extend(sec)
97 
98  # Get last eventsPerLumi of events in this file
99  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]
100  print(command)
101  events = subprocess.check_output(command, shell=True)
102  events = events.split(b'\n')
103  events = filter(lambda x: x != b"", events)
104  events = map(int, events)
105  events = sorted(events)
106  events = events[-options.eventsPerLumi:]
107  eventsToProcess.append("%s:%s:%s-%s:%s:%s" % (options.runNumber, ls, events[0], options.runNumber, ls, events[-1]))
108 
109 eventRange = cms.untracked.VEventRange(eventsToProcess)
110 
111 print("Got %d files." % len(readFiles))
112 
113 source = cms.Source ("PoolSource",
114  fileNames = readFiles,
115  secondaryFileNames = secFiles,
116  eventsToProcess = eventRange,
117  ### As we are testing with FEVT, we don't want any unpacked collection
118  ### This makes the tests slightly more realistic (live production uses streamer files
119  inputCommands = cms.untracked.vstring(
120  'drop *',
121  'keep FEDRawDataCollection_rawDataCollector_*_*',
122  'keep GlobalObjectMapRecord_hltGtStage2ObjectMap_*_*',
123  'keep edmTriggerResults_TriggerResults_*_*'
124  ),
125  dropDescendantsOfDroppedBranches = cms.untracked.bool(True)
126  )
127 maxEvents = cms.untracked.PSet(
128  input = cms.untracked.int32(-1)
129 )
130 
131 runType = RunType()
132 if not options.runkey.strip():
133  options.runkey = "pp_run"
134 
135 runType.setRunType(options.runkey.strip())
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)