CMS 3D CMS Logo

runTheMatrix.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from __future__ import print_function
3 import sys, os
4 
5 from Configuration.PyReleaseValidation.MatrixReader import MatrixReader
6 from Configuration.PyReleaseValidation.MatrixRunner import MatrixRunner
7 from Configuration.PyReleaseValidation.MatrixInjector import MatrixInjector,performInjectionOptionTest
8 
9 # ================================================================================
10 
11 def showRaw(opt):
12 
13  mrd = MatrixReader(opt)
14  mrd.showRaw(opt.useInput, opt.refRel, opt.fromScratch, opt.raw, opt.step1Only, selected=opt.testList)
15 
16  return 0
17 
18 # ================================================================================
19 
20 def runSelected(opt):
21 
22  mrd = MatrixReader(opt)
23  mrd.prepare(opt.useInput, opt.refRel, opt.fromScratch)
24 
25  # test for wrong input workflows
26  if opt.testList:
27  definedSet = set([dwf.numId for dwf in mrd.workFlows])
28  testSet = set(opt.testList)
29  undefSet = testSet - definedSet
30  if len(undefSet)>0: raise ValueError('Undefined workflows: '+', '.join(map(str,list(undefSet))))
31 
32  ret = 0
33  if opt.show:
34  mrd.show(opt.testList, opt.extended, opt.cafVeto)
35  if opt.testList : print('testListected items:', opt.testList)
36  else:
37  mRunnerHi = MatrixRunner(mrd.workFlows, opt.nProcs, opt.nThreads)
38  ret = mRunnerHi.runTests(opt)
39 
40  if opt.wmcontrol:
41  if ret!=0:
42  print('Cannot go on with wmagent injection with failing workflows')
43  else:
44  wfInjector = MatrixInjector(opt,mode=opt.wmcontrol,options=opt.wmoptions)
45  ret= wfInjector.prepare(mrd,
46  mRunnerHi.runDirs)
47  if ret==0:
48  wfInjector.upload()
49  wfInjector.submit()
50  return ret
51 
52 # ================================================================================
53 
54 if __name__ == '__main__':
55 
56  #this can get out of here
57  predefinedSet={
58  'limited' : [5.1, #FastSim ttbar
59  7.3, #CosmicsSPLoose_UP17
60  8, #BH/Cosmic MC
61  25, #MC ttbar
62  4.22, #cosmic data
63  4.53, #run1 data + miniAOD
64  9.0, #Higgs200 charged taus
65  1000, #data+prompt
66  1001, #data+express
67  101.0, #SingleElectron120E120EHCAL
68  136.731, #2016B Photon data
69  136.7611, #2016E JetHT reMINIAOD from 80X legacy
70  136.8311, #2017F JetHT reMINIAOD from 94X reprocessing
71  136.88811,#2018D JetHT reMINIAOD from UL processing
72  136.793, #2017C DoubleEG
73  136.874, #2018C EGamma
74  140.53, #2011 HI data
75  140.56, #2018 HI data
76  158.01, #reMiniAOD of 2018 HI MC with pp-like reco
77  312.0, #2021/Run3 HI MC Pyquen_ZeemumuJets_pt10 with pp-like reco
78  1306.0, #SingleMu Pt1 UP15
79  1325.81, #test NanoAOD from existing MINI UL 106Xv1
80  136.8523, #test NanoAOD from existing reMINI UL 106Xv2
81  1330, #Run2 MC Zmm
82  135.4, #Run 2 Zee ttbar
83  10042.0, #2017 ZMM
84  10024.0, #2017 ttbar
85  10224.0, #2017 ttbar PU
86  10824.0, #2018 ttbar
87  11634.0, #2021 ttbar
88  12434.0, #2023 ttbar
89  23234.0, #2026D49 ttbar (HLT TDR baseline w/ HGCal v11)
90  23434.999, #2026D49 ttbar premixing stage1+stage2, PU50
91  28234.0, #2026D60 (exercise HF nose)
92  25202.0, #2016 ttbar UP15 PU
93  250202.181, #2018 ttbar stage1 + stage2 premix
94  ],
95  'jetmc': [5.1, 13, 15, 25, 38, 39], #MC
96  'metmc' : [5.1, 15, 25, 37, 38, 39], #MC
97  'muonmc' : [5.1, 124.4, 124.5, 20, 21, 22, 23, 25, 30], #MC
98  }
99 
100 
101  import optparse
102  usage = 'usage: runTheMatrix.py --show -s '
103 
104  parser = optparse.OptionParser(usage)
105 
106  parser.add_option('-b','--batchName',
107  help='relval batch: suffix to be appended to Campaign name',
108  dest='batchName',
109  default=''
110  )
111 
112  parser.add_option('-m','--memoryOffset',
113  help='memory of the wf for single core',
114  dest='memoryOffset',
115  default=3000
116  )
117  parser.add_option('--addMemPerCore',
118  help='increase of memory per each n > 1 core: memory(n_core) = memoryOffset + (n_core-1) * memPerCore',
119  dest='memPerCore',
120  default=1500
121  )
122  parser.add_option('-j','--nproc',
123  help='number of processes. 0 Will use 4 processes, not execute anything but create the wfs',
124  dest='nProcs',
125  default=4
126  )
127  parser.add_option('-t','--nThreads',
128  help='number of threads per process to use in cmsRun.',
129  dest='nThreads',
130  default=1
131  )
132  parser.add_option('--nStreams',
133  help='number of streams to use in cmsRun.',
134  dest='nStreams',
135  default=0
136  )
137  parser.add_option('--numberEventsInLuminosityBlock',
138  help='number of events in a luminosity block',
139  dest='numberEventsInLuminosityBlock',
140  default=-1
141  )
142 
143  parser.add_option('-n','--showMatrix',
144  help='Only show the worflows. Use --ext to show more',
145  dest='show',
146  default=False,
147  action='store_true'
148  )
149  parser.add_option('-e','--extended',
150  help='Show details of workflows, used with --show',
151  dest='extended',
152  default=False,
153  action='store_true'
154  )
155  parser.add_option('-s','--selected',
156  help='Run a pre-defined selected matrix of wf. Deprecated, please use -l limited',
157  dest='restricted',
158  default=False,
159  action='store_true'
160  )
161  parser.add_option('-l','--list',
162  help='Coma separated list of workflow to be shown or ran. Possible keys are also '+str(predefinedSet.keys())+'. and wild card like muon, or mc',
163  dest='testList',
164  default=None
165  )
166  parser.add_option('-r','--raw',
167  help='Temporary dump the .txt needed for prodAgent interface. To be discontinued soon. Argument must be the name of the set (standard, pileup,...)',
168  dest='raw'
169  )
170  parser.add_option('-i','--useInput',
171  help='Use recyling where available. Either all, or a coma separated list of wf number.',
172  dest='useInput',
173  default=None
174  )
175  parser.add_option('-w','--what',
176  help='Specify the set to be used. Argument must be the name of the set (standard, pileup,...)',
177  dest='what',
178  default='all'
179  )
180  parser.add_option('--step1',
181  help='Used with --raw. Limit the production to step1',
182  dest='step1Only',
183  default=False
184  )
185  parser.add_option('--maxSteps',
186  help='Only run maximum on maxSteps. Used when we are only interested in first n steps.',
187  dest='maxSteps',
188  default=9999,
189  type="int"
190  )
191  parser.add_option('--fromScratch',
192  help='Coma separated list of wf to be run without recycling. all is not supported as default.',
193  dest='fromScratch',
194  default=None
195  )
196  parser.add_option('--refRelease',
197  help='Allow to modify the recycling dataset version',
198  dest='refRel',
199  default=None
200  )
201  parser.add_option('--wmcontrol',
202  help='Create the workflows for injection to WMAgent. In the WORKING. -wmcontrol init will create the the workflows, -wmcontrol test will dryRun a test, -wmcontrol submit will submit to wmagent',
203  choices=['init','test','submit','force'],
204  dest='wmcontrol',
205  default=None,
206  )
207  parser.add_option('--revertDqmio',
208  help='When submitting workflows to wmcontrol, force DQM outout to use pool and not DQMIO',
209  choices=['yes','no'],
210  dest='revertDqmio',
211  default='no',
212  )
213  parser.add_option('--optionswm',
214  help='Specify a few things for wm injection',
215  default='',
216  dest='wmoptions')
217  parser.add_option('--keep',
218  help='allow to specify for which coma separated steps the output is needed',
219  default=None)
220  parser.add_option('--label',
221  help='allow to give a special label to the output dataset name',
222  default='')
223  parser.add_option('--command',
224  help='provide a way to add additional command to all of the cmsDriver commands in the matrix',
225  dest='command',
226  default=None
227  )
228  parser.add_option('--apply',
229  help='allow to use the --command only for 1 coma separeated',
230  dest='apply',
231  default=None)
232  parser.add_option('--workflow',
233  help='define a workflow to be created or altered from the matrix',
234  action='append',
235  dest='workflow',
236  default=None
237  )
238  parser.add_option('--dryRun',
239  help='do not run the wf at all',
240  action='store_true',
241  dest='dryRun',
242  default=False
243  )
244  parser.add_option('--testbed',
245  help='workflow injection to cmswebtest (you need dedicated rqmgr account)',
246  dest='testbed',
247  default=False,
248  action='store_true'
249  )
250  parser.add_option('--noCafVeto',
251  help='Run from any source, ignoring the CAF label',
252  dest='cafVeto',
253  default=True,
254  action='store_false'
255  )
256  parser.add_option('--overWrite',
257  help='Change the content of a step for another. List of pairs.',
258  dest='overWrite',
259  default=None
260  )
261  parser.add_option('--noRun',
262  help='Remove all run list selection from wfs',
263  dest='noRun',
264  default=False,
265  action='store_true')
266 
267  parser.add_option('--das-options',
268  help='Options to be passed to dasgoclient.',
269  dest='dasOptions',
270  default="--limit 0",
271  action='store')
272 
273  parser.add_option('--job-reports',
274  help='Dump framework job reports',
275  dest='jobReports',
276  default=False,
277  action='store_true')
278 
279  parser.add_option('--ibeos',
280  help='Use IB EOS site configuration',
281  dest='IBEos',
282  default=False,
283  action='store_true')
284 
285  parser.add_option('--sites',
286  help='Run DAS query to get data from a specific site (default is T2_CH_CERN). Set it to empty string to search all sites.',
287  dest='dasSites',
288  default='T2_CH_CERN',
289  action='store')
290 
291  parser.add_option('--dbs-url',
292  help='Overwrite DbsUrl value in JSON submitted to ReqMgr2',
293  dest='dbsUrl',
294  default=None,
295  action='store')
296 
297  opt,args = parser.parse_args()
298  os.environ["CMSSW_DAS_QUERY_SITES"]=opt.dasSites
299  if opt.IBEos:
300  try:from commands import getstatusoutput as run_cmd
301  except:from subprocess import getstatusoutput as run_cmd
302 
303  ibeos_cache = os.path.join(os.getenv("LOCALRT"), "ibeos_cache.txt")
304  if not os.path.exists(ibeos_cache):
305  err, out = run_cmd("curl -L -s -o %s https://raw.githubusercontent.com/cms-sw/cms-sw.github.io/master/das_queries/ibeos.txt" % ibeos_cache)
306  if err:
307  run_cmd("rm -f %s" % ibeos_cache)
308  print("Error: Unable to download ibeos cache information")
309  print(out)
310  sys.exit(err)
311 
312  for cmssw_env in [ "CMSSW_BASE", "CMSSW_RELEASE_BASE" ]:
313  cmssw_base = os.getenv(cmssw_env,None)
314  if not cmssw_base: continue
315  cmssw_base = os.path.join(cmssw_base,"src/Utilities/General/ibeos")
316  if os.path.exists(cmssw_base):
317  os.environ["PATH"]=cmssw_base+":"+os.getenv("PATH")
318  os.environ["CMS_PATH"]="/cvmfs/cms-ib.cern.ch"
319  os.environ["CMSSW_USE_IBEOS"]="true"
320  print(">> WARNING: You are using SITECONF from /cvmfs/cms-ib.cern.ch")
321  break
322  if opt.restricted:
323  print('Deprecated, please use -l limited')
324  if opt.testList: opt.testList+=',limited'
325  else: opt.testList='limited'
326 
327  def stepOrIndex(s):
328  if s.isdigit():
329  return int(s)
330  else:
331  return s
332  if opt.apply:
333  opt.apply=map(stepOrIndex,opt.apply.split(','))
334  if opt.keep:
335  opt.keep=map(stepOrIndex,opt.keep.split(','))
336 
337 
338 
339  if opt.testList:
340  testList=[]
341  for entry in opt.testList.split(','):
342  if not entry: continue
343  mapped=False
344  for k in predefinedSet:
345  if k.lower().startswith(entry.lower()) or k.lower().endswith(entry.lower()):
346  testList.extend(predefinedSet[k])
347  mapped=True
348  break
349  if not mapped:
350  try:
351  testList.append(float(entry))
352  except:
353  print(entry,'is not a possible selected entry')
354 
355  opt.testList = list(set(testList))
356 
357 
358  if opt.useInput: opt.useInput = opt.useInput.split(',')
359  if opt.fromScratch: opt.fromScratch = opt.fromScratch.split(',')
360  if opt.nProcs: opt.nProcs=int(opt.nProcs)
361  if opt.nThreads: opt.nThreads=int(opt.nThreads)
362  if opt.nStreams: opt.nStreams=int(opt.nStreams)
363  if (opt.numberEventsInLuminosityBlock): opt.numberEventsInLuminosityBlock=int(opt.numberEventsInLuminosityBlock)
364  if (opt.memoryOffset): opt.memoryOffset=int(opt.memoryOffset)
365  if (opt.memPerCore): opt.memPerCore=int(opt.memPerCore)
366 
367  if opt.wmcontrol:
369  if opt.overWrite:
370  opt.overWrite=eval(opt.overWrite)
371 
372  if opt.raw and opt.show:
373  ret = showRaw(opt)
374  else:
375  ret = runSelected(opt)
376 
377 
378  sys.exit(ret)
MatrixReader
Definition: MatrixReader.py:1
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
MatrixRunner
Definition: MatrixRunner.py:1
runTheMatrix.showRaw
def showRaw(opt)
Definition: runTheMatrix.py:11
runTheMatrix.runSelected
def runSelected(opt)
Definition: runTheMatrix.py:20
str
#define str(s)
Definition: TestProcessor.cc:51
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
createfilelist.int
int
Definition: createfilelist.py:10
MatrixInjector.performInjectionOptionTest
def performInjectionOptionTest(opt)
Definition: MatrixInjector.py:12
MatrixInjector
Definition: MatrixInjector.py:1
genParticles_cff.map
map
Definition: genParticles_cff.py:11
runTheMatrix.stepOrIndex
def stepOrIndex(s)
Definition: runTheMatrix.py:327