CMS 3D CMS Logo

MatrixInjector.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import sys
3 import json
4 import os
5 import copy
6 import multiprocessing
7 import time
8 import re
9 
10 MAXWORKFLOWLENGTH = 81
11 
13  if opt.show:
14  print('Not injecting to wmagent in --show mode. Need to run the worklfows.')
15  sys.exit(-1)
16  if opt.wmcontrol=='init':
17  #init means it'll be in test mode
18  opt.nProcs=0
19  if opt.wmcontrol=='test':
20  #means the wf were created already, and we just dryRun it.
21  opt.dryRun=True
22  if opt.wmcontrol=='submit' and opt.nProcs==0:
23  print('Not injecting to wmagent in -j 0 mode. Need to run the worklfows.')
24  sys.exit(-1)
25  if opt.wmcontrol=='force':
26  print("This is an expert setting, you'd better know what you're doing")
27  opt.dryRun=True
28 
29 def upload_to_couch_oneArg(arguments):
30  from modules.wma import upload_to_couch
31  (filePath,labelInCouch,user,group,where) = arguments
32  cacheId=upload_to_couch(filePath,
33  labelInCouch,
34  user,
35  group,
36  test_mode=False,
37  url=where)
38  return cacheId
39 
40 
42 
43  def __init__(self,opt,mode='init',options=''):
44  self.count=1040
45 
46  self.dqmgui=None
47  self.wmagent=None
48  for k in options.split(','):
49  if k.startswith('dqm:'):
50  self.dqmgui=k.split(':',1)[-1]
51  elif k.startswith('wma:'):
52  self.wmagent=k.split(':',1)[-1]
53 
54  self.testMode=((mode!='submit') and (mode!='force'))
55  self.version =1
56  self.keep = opt.keep
57  self.memoryOffset = opt.memoryOffset
58  self.memPerCore = opt.memPerCore
59  self.numberEventsInLuminosityBlock = opt.numberEventsInLuminosityBlock
60  self.numberOfStreams = 0
61  if(opt.nStreams>0):
62  self.numberOfStreams = opt.nStreams
63  self.batchName = ''
64  self.batchTime = str(int(time.time()))
65  if(opt.batchName):
66  self.batchName = '__'+opt.batchName+'-'+self.batchTime
67 
68  # WMagent url
69  if not self.wmagent:
70  # Overwrite with env variable
71  self.wmagent = os.getenv('WMAGENT_REQMGR')
72 
73  if not self.wmagent:
74  # Default values
75  if not opt.testbed:
76  self.wmagent = 'cmsweb.cern.ch'
77  else:
78  self.wmagent = 'cmsweb-testbed.cern.ch'
79 
80  # DBSReader url
81  if opt.dbsUrl is not None:
82  self.DbsUrl = opt.dbsUrl
83  elif os.getenv('CMS_DBSREADER_URL') is not None:
84  self.DbsUrl = os.getenv('CMS_DBSREADER_URL')
85  else:
86  # Default values
87  if not opt.testbed:
88  self.DbsUrl = "https://cmsweb-prod.cern.ch/dbs/prod/global/DBSReader"
89  else:
90  self.DbsUrl = "https://cmsweb-testbed.cern.ch/dbs/int/global/DBSReader"
91 
92  if not self.dqmgui:
93  self.dqmgui="https://cmsweb.cern.ch/dqm/relval"
94  #couch stuff
95  self.couch = 'https://'+self.wmagent+'/couchdb'
96 # self.couchDB = 'reqmgr_config_cache'
97  self.couchCache={} # so that we do not upload like crazy, and recyle cfgs
98  self.user = os.getenv('USER')
99  self.group = 'ppd'
100  self.label = 'RelValSet_'+os.getenv('CMSSW_VERSION').replace('-','')+'_v'+str(self.version)
101  self.speciallabel=''
102  if opt.label:
103  self.speciallabel= '_'+opt.label
104  self.longWFName = []
105 
106  if not os.getenv('WMCORE_ROOT'):
107  print('\n\twmclient is not setup properly. Will not be able to upload or submit requests.\n')
108  if not self.testMode:
109  print('\n\t QUIT\n')
110  sys.exit(-18)
111  else:
112  print('\n\tFound wmclient\n')
113 
115  "RequestType" : "TaskChain", #this is how we handle relvals
116  "SubRequestType" : "RelVal", #this is how we handle relvals, now that TaskChain is also used for central MC production
117  "RequestPriority": 500000,
118  "Requestor": self.user, #Person responsible
119  "Group": self.group, #group for the request
120  "CMSSWVersion": os.getenv('CMSSW_VERSION'), #CMSSW Version (used for all tasks in chain)
121  "Campaign": os.getenv('CMSSW_VERSION'), # = AcquisitionEra, will be reset later to the one of first task, will both be the CMSSW_VERSION
122  "ScramArch": os.getenv('SCRAM_ARCH'), #Scram Arch (used for all tasks in chain)
123  "ProcessingVersion": self.version, #Processing Version (used for all tasks in chain)
124  "GlobalTag": None, #Global Tag (overridden per task)
125  "ConfigCacheUrl": self.couch, #URL of CouchDB containing Config Cache
126  "DbsUrl": self.DbsUrl,
127  #- Will contain all configs for all Tasks
128  #"SiteWhitelist" : ["T2_CH_CERN", "T1_US_FNAL"], #Site whitelist
129  "TaskChain" : None, #Define number of tasks in chain.
130  "nowmTasklist" : [], #a list of tasks as we put them in
131  "Multicore" : 1, # do not set multicore for the whole chain
132  "Memory" : 3000,
133  "SizePerEvent" : 1234,
134  "TimePerEvent" : 10,
135  "PrepID": os.getenv('CMSSW_VERSION')
136  }
137 
139  "EnableHarvesting" : "True",
140  "DQMUploadUrl" : self.dqmgui,
141  "DQMConfigCacheID" : None,
142  "Multicore" : 1 # hardcode Multicore to be 1 for Harvest
143  }
144 
146  "TaskName" : None, #Task Name
147  "ConfigCacheID" : None, #Generator Config id
148  "GlobalTag": None,
149  "SplittingAlgo" : "EventBased", #Splitting Algorithm
150  "EventsPerJob" : None, #Size of jobs in terms of splitting algorithm
151  "EventsPerLumi" : None,
152  "RequestNumEvents" : None, #Total number of events to generate
153  "Seeding" : "AutomaticSeeding", #Random seeding method
154  "PrimaryDataset" : None, #Primary Dataset to be created
155  "nowmIO": {},
156  "Multicore" : opt.nThreads, # this is the per-taskchain Multicore; it's the default assigned to a task if it has no value specified
157  "EventStreams": self.numberOfStreams,
158  "KeepOutput" : False
159  }
161  "TaskName" : "DigiHLT", #Task Name
162  "ConfigCacheID" : None, #Processing Config id
163  "GlobalTag": None,
164  "InputDataset" : None, #Input Dataset to be processed
165  "SplittingAlgo" : "LumiBased", #Splitting Algorithm
166  "LumisPerJob" : 10, #Size of jobs in terms of splitting algorithm
167  "nowmIO": {},
168  "Multicore" : opt.nThreads, # this is the per-taskchain Multicore; it's the default assigned to a task if it has no value specified
169  "EventStreams": self.numberOfStreams,
170  "KeepOutput" : False
171  }
172  self.defaultTask={
173  "TaskName" : None, #Task Name
174  "InputTask" : None, #Input Task Name (Task Name field of a previous Task entry)
175  "InputFromOutputModule" : None, #OutputModule name in the input task that will provide files to process
176  "ConfigCacheID" : None, #Processing Config id
177  "GlobalTag": None,
178  "SplittingAlgo" : "LumiBased", #Splitting Algorithm
179  "LumisPerJob" : 10, #Size of jobs in terms of splitting algorithm
180  "nowmIO": {},
181  "Multicore" : opt.nThreads, # this is the per-taskchain Multicore; it's the default assigned to a task if it has no value specified
182  "EventStreams": self.numberOfStreams,
183  "KeepOutput" : False
184  }
185 
186  self.chainDicts={}
187 
188  @staticmethod
189  def get_wmsplit():
190  """
191  Return a "wmsplit" dictionary that contain non-default LumisPerJob values
192  """
193  wmsplit = {}
194  try:
195  wmsplit['DIGIHI'] = 5
196  wmsplit['RECOHI'] = 5
197  wmsplit['HLTD'] = 5
198  wmsplit['RECODreHLT'] = 2
199  wmsplit['DIGIPU'] = 4
200  wmsplit['DIGIPU1'] = 4
201  wmsplit['RECOPU1'] = 1
202  wmsplit['DIGIUP15_PU50'] = 1
203  wmsplit['RECOUP15_PU50'] = 1
204  wmsplit['DIGIUP15_PU25'] = 1
205  wmsplit['RECOUP15_PU25'] = 1
206  wmsplit['DIGIUP15_PU25HS'] = 1
207  wmsplit['RECOUP15_PU25HS'] = 1
208  wmsplit['DIGIHIMIX'] = 5
209  wmsplit['RECOHIMIX'] = 5
210  wmsplit['RECODSplit'] = 1
211  wmsplit['SingleMuPt10_UP15_ID'] = 1
212  wmsplit['DIGIUP15_ID'] = 1
213  wmsplit['RECOUP15_ID'] = 1
214  wmsplit['TTbar_13_ID'] = 1
215  wmsplit['SingleMuPt10FS_ID'] = 1
216  wmsplit['TTbarFS_ID'] = 1
217  wmsplit['RECODR2_50nsreHLT'] = 5
218  wmsplit['RECODR2_25nsreHLT'] = 5
219  wmsplit['RECODR2_2016reHLT'] = 5
220  wmsplit['RECODR2_50nsreHLT_HIPM'] = 5
221  wmsplit['RECODR2_25nsreHLT_HIPM'] = 5
222  wmsplit['RECODR2_2016reHLT_HIPM'] = 1
223  wmsplit['RECODR2_2016reHLT_skimSingleMu'] = 1
224  wmsplit['RECODR2_2016reHLT_skimDoubleEG'] = 1
225  wmsplit['RECODR2_2016reHLT_skimMuonEG'] = 1
226  wmsplit['RECODR2_2016reHLT_skimJetHT'] = 1
227  wmsplit['RECODR2_2016reHLT_skimMET'] = 1
228  wmsplit['RECODR2_2016reHLT_skimSinglePh'] = 1
229  wmsplit['RECODR2_2016reHLT_skimMuOnia'] = 1
230  wmsplit['RECODR2_2016reHLT_skimSingleMu_HIPM'] = 1
231  wmsplit['RECODR2_2016reHLT_skimDoubleEG_HIPM'] = 1
232  wmsplit['RECODR2_2016reHLT_skimMuonEG_HIPM'] = 1
233  wmsplit['RECODR2_2016reHLT_skimJetHT_HIPM'] = 1
234  wmsplit['RECODR2_2016reHLT_skimMET_HIPM'] = 1
235  wmsplit['RECODR2_2016reHLT_skimSinglePh_HIPM'] = 1
236  wmsplit['RECODR2_2016reHLT_skimMuOnia_HIPM'] = 1
237  wmsplit['RECODR2_2017reHLT_Prompt'] = 1
238  wmsplit['RECODR2_2017reHLT_skimSingleMu_Prompt_Lumi'] = 1
239  wmsplit['RECODR2_2017reHLT_skimDoubleEG_Prompt'] = 1
240  wmsplit['RECODR2_2017reHLT_skimMET_Prompt'] = 1
241  wmsplit['RECODR2_2017reHLT_skimMuOnia_Prompt'] = 1
242  wmsplit['RECODR2_2017reHLT_Prompt_L1TEgDQM'] = 1
243  wmsplit['RECODR2_2018reHLT_Prompt'] = 1
244  wmsplit['RECODR2_2018reHLT_skimSingleMu_Prompt_Lumi'] = 1
245  wmsplit['RECODR2_2018reHLT_skimDoubleEG_Prompt'] = 1
246  wmsplit['RECODR2_2018reHLT_skimJetHT_Prompt'] = 1
247  wmsplit['RECODR2_2018reHLT_skimMET_Prompt'] = 1
248  wmsplit['RECODR2_2018reHLT_skimMuOnia_Prompt'] = 1
249  wmsplit['RECODR2_2018reHLT_skimEGamma_Prompt_L1TEgDQM'] = 1
250  wmsplit['RECODR2_2018reHLT_skimMuonEG_Prompt'] = 1
251  wmsplit['RECODR2_2018reHLT_skimCharmonium_Prompt'] = 1
252  wmsplit['RECODR2_2018reHLT_skimJetHT_Prompt_HEfail'] = 1
253  wmsplit['RECODR2_2018reHLT_skimJetHT_Prompt_BadHcalMitig'] = 1
254  wmsplit['RECODR2_2018reHLTAlCaTkCosmics_Prompt'] = 1
255  wmsplit['RECODR2_2018reHLT_skimDisplacedJet_Prompt'] = 1
256  wmsplit['RECODR2_2018reHLT_ZBPrompt'] = 1
257  wmsplit['RECODR2_2018reHLT_Offline'] = 1
258  wmsplit['RECODR2_2018reHLT_skimSingleMu_Offline_Lumi'] = 1
259  wmsplit['RECODR2_2018reHLT_skimDoubleEG_Offline'] = 1
260  wmsplit['RECODR2_2018reHLT_skimJetHT_Offline'] = 1
261  wmsplit['RECODR2_2018reHLT_skimMET_Offline'] = 1
262  wmsplit['RECODR2_2018reHLT_skimMuOnia_Offline'] = 1
263  wmsplit['RECODR2_2018reHLT_skimEGamma_Offline_L1TEgDQM'] = 1
264  wmsplit['RECODR2_2018reHLT_skimMuonEG_Offline'] = 1
265  wmsplit['RECODR2_2018reHLT_skimCharmonium_Offline'] = 1
266  wmsplit['RECODR2_2018reHLT_skimJetHT_Offline_HEfail'] = 1
267  wmsplit['RECODR2_2018reHLT_skimJetHT_Offline_BadHcalMitig'] = 1
268  wmsplit['RECODR2_2018reHLTAlCaTkCosmics_Offline'] = 1
269  wmsplit['RECODR2_2018reHLT_skimDisplacedJet_Offline'] = 1
270  wmsplit['RECODR2_2018reHLT_ZBOffline'] = 1
271  wmsplit['HLTDR2_50ns'] = 1
272  wmsplit['HLTDR2_25ns'] = 1
273  wmsplit['HLTDR2_2016'] = 1
274  wmsplit['HLTDR2_2017'] = 1
275  wmsplit['HLTDR2_2018'] = 1
276  wmsplit['HLTDR2_2018_BadHcalMitig'] = 1
277  wmsplit['Hadronizer'] = 1
278  wmsplit['DIGIUP15'] = 1
279  wmsplit['RECOUP15'] = 1
280  wmsplit['RECOAODUP15'] = 5
281  wmsplit['DBLMINIAODMCUP15NODQM'] = 5
282  wmsplit['Digi'] = 5
283  wmsplit['Reco'] = 5
284  wmsplit['DigiPU'] = 1
285  wmsplit['RecoPU'] = 1
286  wmsplit['RECOHID11'] = 1
287  wmsplit['DIGIUP17'] = 1
288  wmsplit['RECOUP17'] = 1
289  wmsplit['DIGIUP17_PU25'] = 1
290  wmsplit['RECOUP17_PU25'] = 1
291  wmsplit['DIGICOS_UP16'] = 1
292  wmsplit['RECOCOS_UP16'] = 1
293  wmsplit['DIGICOS_UP17'] = 1
294  wmsplit['RECOCOS_UP17'] = 1
295  wmsplit['DIGICOS_UP18'] = 1
296  wmsplit['RECOCOS_UP18'] = 1
297  wmsplit['DIGICOS_UP21'] = 1
298  wmsplit['RECOCOS_UP21'] = 1
299  wmsplit['HYBRIDRepackHI2015VR'] = 1
300  wmsplit['HYBRIDZSHI2015'] = 1
301  wmsplit['RECOHID15'] = 1
302  wmsplit['RECOHID18'] = 1
303  # automate for phase 2
304  from .upgradeWorkflowComponents import upgradeKeys
305  for key in upgradeKeys[2026]:
306  if 'PU' not in key:
307  continue
308 
309  wmsplit['DigiTriggerPU_' + key] = 1
310  wmsplit['RecoGlobalPU_' + key] = 1
311 
312  except Exception as ex:
313  print('Exception while building a wmsplit dictionary: %s' % (str(ex)))
314  return {}
315 
316  return wmsplit
317 
318  def prepare(self, mReader, directories, mode='init'):
319  wmsplit = MatrixInjector.get_wmsplit()
320  acqEra=False
321  for (n,dir) in directories.items():
322  chainDict=copy.deepcopy(self.defaultChain)
323  print("inspecting",dir)
324  nextHasDSInput=None
325  for (x,s) in mReader.workFlowSteps.items():
326  #x has the format (num, prefix)
327  #s has the format (num, name, commands, stepList)
328  if x[0]==n:
329  #print "found",n,s[3]
330  #chainDict['RequestString']='RV'+chainDict['CMSSWVersion']+s[1].split('+')[0]
331  index=0
332  splitForThisWf=None
333  thisLabel=self.speciallabel
334  #if 'HARVESTGEN' in s[3]:
335  if len( [step for step in s[3] if "HARVESTGEN" in step] )>0:
336  chainDict['TimePerEvent']=0.01
337  thisLabel=thisLabel+"_gen"
338  # for double miniAOD test
339  if len( [step for step in s[3] if "DBLMINIAODMCUP15NODQM" in step] )>0:
340  thisLabel=thisLabel+"_dblMiniAOD"
341  processStrPrefix=''
342  setPrimaryDs=None
343  nanoedmGT=''
344  for step in s[3]:
345 
346  if 'INPUT' in step or (not isinstance(s[2][index],str)):
347  nextHasDSInput=s[2][index]
348 
349  else:
350 
351  if (index==0):
352  #first step and not input -> gen part
353  chainDict['nowmTasklist'].append(copy.deepcopy(self.defaultScratch))
354  try:
355  chainDict['nowmTasklist'][-1]['nowmIO']=json.loads(open('%s/%s.io'%(dir,step)).read())
356  except:
357  print("Failed to find",'%s/%s.io'%(dir,step),".The workflows were probably not run on cfg not created")
358  return -15
359 
360  chainDict['nowmTasklist'][-1]['PrimaryDataset']='RelVal'+s[1].split('+')[0]
361  if not '--relval' in s[2][index]:
362  print('Impossible to create task from scratch without splitting information with --relval')
363  return -12
364  else:
365  arg=s[2][index].split()
366  ns=list(map(int,arg[len(arg) - arg[-1::-1].index('--relval')].split(',')))
367  chainDict['nowmTasklist'][-1]['RequestNumEvents'] = ns[0]
368  chainDict['nowmTasklist'][-1]['EventsPerJob'] = ns[1]
369  chainDict['nowmTasklist'][-1]['EventsPerLumi'] = ns[1]
370  #overwrite EventsPerLumi if numberEventsInLuminosityBlock is set in cmsDriver
371  if 'numberEventsInLuminosityBlock' in s[2][index]:
372  nEventsInLuminosityBlock = re.findall('process.source.numberEventsInLuminosityBlock=cms.untracked.uint32\(([ 0-9 ]*)\)', s[2][index],re.DOTALL)
373  if nEventsInLuminosityBlock[-1].isdigit() and int(nEventsInLuminosityBlock[-1]) < ns[1]:
374  chainDict['nowmTasklist'][-1]['EventsPerLumi'] = int(nEventsInLuminosityBlock[-1])
376  chainDict['nowmTasklist'][-1]['EventsPerLumi'] = self.numberEventsInLuminosityBlock
377  if 'FASTSIM' in s[2][index] or '--fast' in s[2][index]:
378  thisLabel+='_FastSim'
379  if 'lhe' in s[2][index] in s[2][index]:
380  chainDict['nowmTasklist'][-1]['LheInputFiles'] =True
381 
382  elif nextHasDSInput:
383  chainDict['nowmTasklist'].append(copy.deepcopy(self.defaultInput))
384  try:
385  chainDict['nowmTasklist'][-1]['nowmIO']=json.loads(open('%s/%s.io'%(dir,step)).read())
386  except:
387  print("Failed to find",'%s/%s.io'%(dir,step),".The workflows were probably not run on cfg not created")
388  return -15
389  chainDict['nowmTasklist'][-1]['InputDataset']=nextHasDSInput.dataSet
390  if ('DQMHLTonRAWAOD' in step) :
391  chainDict['nowmTasklist'][-1]['IncludeParents']=True
392  splitForThisWf=nextHasDSInput.split
393  chainDict['nowmTasklist'][-1]['LumisPerJob']=splitForThisWf
394  if step in wmsplit:
395  chainDict['nowmTasklist'][-1]['LumisPerJob']=wmsplit[step]
396  # get the run numbers or #events
397  if len(nextHasDSInput.run):
398  chainDict['nowmTasklist'][-1]['RunWhitelist']=nextHasDSInput.run
399  if len(nextHasDSInput.ls):
400  chainDict['nowmTasklist'][-1]['LumiList']=nextHasDSInput.ls
401  #print "what is s",s[2][index]
402  if '--data' in s[2][index] and nextHasDSInput.label:
403  thisLabel+='_RelVal_%s'%nextHasDSInput.label
404  if 'filter' in chainDict['nowmTasklist'][-1]['nowmIO']:
405  print("This has an input DS and a filter sequence: very likely to be the PyQuen sample")
406  processStrPrefix='PU_'
407  setPrimaryDs = 'RelVal'+s[1].split('+')[0]
408  if setPrimaryDs:
409  chainDict['nowmTasklist'][-1]['PrimaryDataset']=setPrimaryDs
410  nextHasDSInput=None
411  else:
412  #not first step and no inputDS
413  chainDict['nowmTasklist'].append(copy.deepcopy(self.defaultTask))
414  try:
415  chainDict['nowmTasklist'][-1]['nowmIO']=json.loads(open('%s/%s.io'%(dir,step)).read())
416  except:
417  print("Failed to find",'%s/%s.io'%(dir,step),".The workflows were probably not run on cfg not created")
418  return -15
419  if splitForThisWf:
420  chainDict['nowmTasklist'][-1]['LumisPerJob']=splitForThisWf
421  if step in wmsplit:
422  chainDict['nowmTasklist'][-1]['LumisPerJob']=wmsplit[step]
423 
424  # change LumisPerJob for Hadronizer steps.
425  if 'Hadronizer' in step:
426  chainDict['nowmTasklist'][-1]['LumisPerJob']=wmsplit['Hadronizer']
427 
428  #print step
429  chainDict['nowmTasklist'][-1]['TaskName']=step
430  if setPrimaryDs:
431  chainDict['nowmTasklist'][-1]['PrimaryDataset']=setPrimaryDs
432  chainDict['nowmTasklist'][-1]['ConfigCacheID']='%s/%s.py'%(dir,step)
433  chainDict['nowmTasklist'][-1]['GlobalTag']=chainDict['nowmTasklist'][-1]['nowmIO']['GT'] # copy to the proper parameter name
434  chainDict['GlobalTag']=chainDict['nowmTasklist'][-1]['nowmIO']['GT'] #set in general to the last one of the chain
435  if 'NANOEDM' in step :
436  nanoedmGT = chainDict['nowmTasklist'][-1]['nowmIO']['GT']
437  if 'NANOMERGE' in step :
438  chainDict['GlobalTag'] = nanoedmGT
439  if 'pileup' in chainDict['nowmTasklist'][-1]['nowmIO']:
440  chainDict['nowmTasklist'][-1]['MCPileup']=chainDict['nowmTasklist'][-1]['nowmIO']['pileup']
441  if '--pileup ' in s[2][index]: # catch --pileup (scenarion) and not --pileup_ (dataset to be mixed) => works also making PRE-MIXed dataset
442  processStrPrefix='PU_' # take care of pu overlay done with GEN-SIM mixing
443  if ( s[2][index].split()[ s[2][index].split().index('--pileup')+1 ] ).find('25ns') > 0 :
444  processStrPrefix='PU25ns_'
445  elif ( s[2][index].split()[ s[2][index].split().index('--pileup')+1 ] ).find('50ns') > 0 :
446  processStrPrefix='PU50ns_'
447  if 'premix_stage2' in s[2][index] and '--pileup_input' in s[2][index]: # take care of pu overlay done with DIGI mixing of premixed events
448  if s[2][index].split()[ s[2][index].split().index('--pileup_input')+1 ].find('25ns') > 0 :
449  processStrPrefix='PUpmx25ns_'
450  elif s[2][index].split()[ s[2][index].split().index('--pileup_input')+1 ].find('50ns') > 0 :
451  processStrPrefix='PUpmx50ns_'
452 
453  if acqEra:
454  #chainDict['AcquisitionEra'][step]=(chainDict['CMSSWVersion']+'-PU_'+chainDict['nowmTasklist'][-1]['GlobalTag']).replace('::All','')+thisLabel
455  chainDict['AcquisitionEra'][step]=chainDict['CMSSWVersion']
456  chainDict['ProcessingString'][step]=processStrPrefix+chainDict['nowmTasklist'][-1]['GlobalTag'].replace('::All','').replace('-','_')+thisLabel
457  if 'NANOMERGE' in step :
458  chainDict['ProcessingString'][step]=processStrPrefix+nanoedmGT.replace('::All','').replace('-','_')+thisLabel
459  else:
460  #chainDict['nowmTasklist'][-1]['AcquisitionEra']=(chainDict['CMSSWVersion']+'-PU_'+chainDict['nowmTasklist'][-1]['GlobalTag']).replace('::All','')+thisLabel
461  chainDict['nowmTasklist'][-1]['AcquisitionEra']=chainDict['CMSSWVersion']
462  chainDict['nowmTasklist'][-1]['ProcessingString']=processStrPrefix+chainDict['nowmTasklist'][-1]['GlobalTag'].replace('::All','').replace('-','_')+thisLabel
463  if 'NANOMERGE' in step :
464  chainDict['nowmTasklist'][-1]['ProcessingString']=processStrPrefix+nanoedmGT.replace('::All','').replace('-','_')+thisLabel
465 
466  if (self.batchName):
467  chainDict['nowmTasklist'][-1]['Campaign'] = chainDict['nowmTasklist'][-1]['AcquisitionEra']+self.batchName
468 
469  # specify different ProcessingString for double miniAOD dataset
470  if ('DBLMINIAODMCUP15NODQM' in step):
471  chainDict['nowmTasklist'][-1]['ProcessingString']=chainDict['nowmTasklist'][-1]['ProcessingString']+'_miniAOD'
472 
473  if( chainDict['nowmTasklist'][-1]['Multicore'] ):
474  # the scaling factor of 1.2GB / thread is empirical and measured on a SECOND round of tests with PU samples
475  # the number of threads is NO LONGER assumed to be the same for all tasks
476  # https://hypernews.cern.ch/HyperNews/CMS/get/edmFramework/3509/1/1/1.html
477  # now change to 1.5GB / additional thread according to discussion:
478  # https://hypernews.cern.ch/HyperNews/CMS/get/relval/4817/1/1.html
479 # chainDict['nowmTasklist'][-1]['Memory'] = 3000 + int( chainDict['nowmTasklist'][-1]['Multicore'] -1 )*1500
480  chainDict['nowmTasklist'][-1]['Memory'] = self.memoryOffset + int( chainDict['nowmTasklist'][-1]['Multicore'] -1 ) * self.memPerCore
481 
482  index+=1
483  #end of loop through steps
484  chainDict['RequestString']='RV'+chainDict['CMSSWVersion']+s[1].split('+')[0]
485  if processStrPrefix or thisLabel:
486  chainDict['RequestString']+='_'+processStrPrefix+thisLabel
487  #check candidate WF name
488  self.candidateWFName = self.user+'_'+chainDict['RequestString']
489  if (len(self.candidateWFName)>MAXWORKFLOWLENGTH):
491 
492 
493  chainDict['PrepID'] = chainDict['CMSSWVersion']+'__'+self.batchTime+'-'+s[1].split('+')[0]
494  if(self.batchName):
495  chainDict['PrepID'] = chainDict['CMSSWVersion']+self.batchName+'-'+s[1].split('+')[0]
496  if( 'HIN' in self.batchName ):
497  chainDict['SubRequestType'] = "HIRelVal"
498 
499  #wrap up for this one
500  import pprint
501  #print 'wrapping up'
502  #pprint.pprint(chainDict)
503  #loop on the task list
504  for i_second in reversed(range(len(chainDict['nowmTasklist']))):
505  t_second=chainDict['nowmTasklist'][i_second]
506  #print "t_second taskname", t_second['TaskName']
507  if 'primary' in t_second['nowmIO']:
508  #print t_second['nowmIO']['primary']
509  primary=t_second['nowmIO']['primary'][0].replace('file:','')
510  for i_input in reversed(range(0,i_second)):
511  t_input=chainDict['nowmTasklist'][i_input]
512  for (om,o) in t_input['nowmIO'].items():
513  if primary in o:
514  #print "found",primary,"procuced by",om,"of",t_input['TaskName']
515  #ad-hoc fix due to restriction in TaskName of 50 characters
516  if (len(t_input['TaskName'])>50):
517  if (t_input['TaskName'].find('GenSim') != -1):
518  t_input['TaskName'] = 'GenSimFull'
519  if (t_input['TaskName'].find('Hadronizer') != -1):
520  t_input['TaskName'] = 'HadronizerFull'
521  t_second['InputTask'] = t_input['TaskName']
522  t_second['InputFromOutputModule'] = om
523  #print 't_second',pprint.pformat(t_second)
524  if t_second['TaskName'].startswith('HARVEST'):
525  chainDict.update(copy.deepcopy(self.defaultHarvest))
526  if "_RD" in t_second['TaskName']:
527  chainDict['DQMHarvestUnit'] = "multiRun"
528  chainDict['DQMConfigCacheID']=t_second['ConfigCacheID']
529 
532  break
533 
534  # agreed changes for wm injection:
535  # - Campaign: *optional* string during creation. It will default to AcqEra value if possible.
536  # Otherwise it will be empty.
537  # - AcquisitionEra: *mandatory* string at request level during creation. *optional* string
538  # at task level during creation. "optional" during assignment.
539  # - ProcessingString: *mandatory* string at request level during creation. *optional* string
540  # at task level during creation. "optional" during assignment.
541  # - ProcessingVersion: *optional* during creation (default 1). *optional* during assignment.
542  #
543  # Which requires following changes here:
544  # - reset Global AcuisitionEra, ProcessingString to be the one in the first task
545  # - and also Campaign to be always the same as the AcquisitionEra
546 
547  if acqEra:
548  chainDict['AcquisitionEra'] = chainDict['AcquisitionEra'].values()[0]
549  chainDict['ProcessingString'] = chainDict['ProcessingString'].values()[0]
550  else:
551  chainDict['AcquisitionEra'] = chainDict['nowmTasklist'][0]['AcquisitionEra']
552  chainDict['ProcessingString'] = chainDict['nowmTasklist'][0]['ProcessingString']
553 
554 
556  chainDict['Campaign'] = chainDict['AcquisitionEra']+self.batchName
557 
558 
559  itask=0
560  if self.keep:
561  for i in self.keep:
562  if isinstance(i, int) and i < len(chainDict['nowmTasklist']):
563  chainDict['nowmTasklist'][i]['KeepOutput']=True
564  for (i,t) in enumerate(chainDict['nowmTasklist']):
565  if t['TaskName'].startswith('HARVEST'):
566  continue
567  if not self.keep:
568  t['KeepOutput']=True
569  elif t['TaskName'] in self.keep:
570  t['KeepOutput']=True
571  if t['TaskName'].startswith('HYBRIDRepackHI2015VR'):
572  t['KeepOutput']=False
573  t.pop('nowmIO')
574  itask+=1
575  chainDict['Task%d'%(itask)]=t
576 
577 
578 
579 
580 
581 
582  chainDict['TaskChain']=itask#len(chainDict['nowmTasklist'])
583 
584  chainDict.pop('nowmTasklist')
585  self.chainDicts[n]=chainDict
586 
587 
588  return 0
589 
590  def uploadConf(self,filePath,label,where):
591  labelInCouch=self.label+'_'+label
592  cacheName=filePath.split('/')[-1]
593  if self.testMode:
594  self.count+=1
595  print('\tFake upload of',filePath,'to couch with label',labelInCouch)
596  return self.count
597  else:
598  try:
599  from modules.wma import upload_to_couch,DATABASE_NAME
600  except:
601  print('\n\tUnable to find wmcontrol modules. Please include it in your python path\n')
602  print('\n\t QUIT\n')
603  sys.exit(-16)
604 
605  if cacheName in self.couchCache:
606  print("Not re-uploading",filePath,"to",where,"for",label)
607  cacheId=self.couchCache[cacheName]
608  else:
609  print("Loading",filePath,"to",where,"for",label)
610 
611  pool = multiprocessing.Pool(1)
612  cacheIds = pool.map( upload_to_couch_oneArg, [(filePath,labelInCouch,self.user,self.group,where)] )
613  cacheId = cacheIds[0]
614  self.couchCache[cacheName]=cacheId
615  return cacheId
616 
617  def upload(self):
618  for (n,d) in self.chainDicts.items():
619  for it in d:
620  if it.startswith("Task") and it!='TaskChain':
621  #upload
622  couchID=self.uploadConf(d[it]['ConfigCacheID'],
623  str(n)+d[it]['TaskName'],
624  d['ConfigCacheUrl']
625  )
626  print(d[it]['ConfigCacheID']," uploaded to couchDB for",str(n),"with ID",couchID)
627  d[it]['ConfigCacheID']=couchID
628  if it =='DQMConfigCacheID':
629  couchID=self.uploadConf(d['DQMConfigCacheID'],
630  str(n)+'harvesting',
631  d['ConfigCacheUrl']
632  )
633  print(d['DQMConfigCacheID'],"uploaded to couchDB for",str(n),"with ID",couchID)
634  d['DQMConfigCacheID']=couchID
635 
636 
637  def submit(self):
638  try:
639  from modules.wma import makeRequest,approveRequest
640  from wmcontrol import random_sleep
641  print('\n\tFound wmcontrol\n')
642  except:
643  print('\n\tUnable to find wmcontrol modules. Please include it in your python path\n')
644  if not self.testMode:
645  print('\n\t QUIT\n')
646  sys.exit(-17)
647 
648  import pprint
649  for (n,d) in self.chainDicts.items():
650  if self.testMode:
651  print("Only viewing request",n)
652  print(pprint.pprint(d))
653  else:
654  #submit to wmagent each dict
655  print("For eyes before submitting",n)
656  print(pprint.pprint(d))
657  print("Submitting",n,"...........")
658  workFlow=makeRequest(self.wmagent,d,encodeDict=True)
659  print("...........",n,"submitted")
660  random_sleep()
661  if self.testMode and len(self.longWFName)>0:
662  print("\n*** WARNING: "+str(len(self.longWFName))+" workflows have too long names for submission (>"+str(MAXWORKFLOWLENGTH)+ "characters) ***")
663  print('\n'.join(self.longWFName))
MatrixInjector.MatrixInjector.upload
def upload(self)
Definition: MatrixInjector.py:617
MatrixInjector.MatrixInjector.longWFName
longWFName
Definition: MatrixInjector.py:104
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
MatrixInjector.MatrixInjector
Definition: MatrixInjector.py:41
MatrixInjector.MatrixInjector.defaultInput
defaultInput
Definition: MatrixInjector.py:160
MatrixInjector.MatrixInjector.keep
keep
Definition: MatrixInjector.py:56
MatrixInjector.MatrixInjector.memoryOffset
memoryOffset
Definition: MatrixInjector.py:57
MatrixInjector.MatrixInjector.couch
couch
Definition: MatrixInjector.py:95
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:58
MatrixInjector.MatrixInjector.DbsUrl
DbsUrl
Definition: MatrixInjector.py:82
MatrixInjector.MatrixInjector.couchCache
couchCache
Definition: MatrixInjector.py:97
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
MatrixInjector.upload_to_couch_oneArg
def upload_to_couch_oneArg(arguments)
Definition: MatrixInjector.py:29
mps_monitormerge.items
list items
Definition: mps_monitormerge.py:29
MatrixInjector.MatrixInjector.wmagent
wmagent
Definition: MatrixInjector.py:47
MatrixInjector.MatrixInjector.batchTime
batchTime
Definition: MatrixInjector.py:64
MatrixInjector.MatrixInjector.candidateWFName
candidateWFName
Definition: MatrixInjector.py:488
MatrixInjector.MatrixInjector.speciallabel
speciallabel
Definition: MatrixInjector.py:101
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
MatrixInjector.MatrixInjector.uploadConf
def uploadConf(self, filePath, label, where)
the info are not in the task specific dict but in the general dict t_input.update(copy....
Definition: MatrixInjector.py:590
str
#define str(s)
Definition: TestProcessor.cc:53
MatrixInjector.MatrixInjector.defaultHarvest
defaultHarvest
Definition: MatrixInjector.py:138
MatrixInjector.MatrixInjector.prepare
def prepare(self, mReader, directories, mode='init')
Definition: MatrixInjector.py:318
MatrixInjector.MatrixInjector.group
group
Definition: MatrixInjector.py:99
MatrixInjector.MatrixInjector.chainDicts
chainDicts
Definition: MatrixInjector.py:186
MatrixInjector.MatrixInjector.defaultTask
defaultTask
Definition: MatrixInjector.py:172
MatrixInjector.MatrixInjector.testMode
testMode
Definition: MatrixInjector.py:54
MatrixInjector.MatrixInjector.numberOfStreams
numberOfStreams
Definition: MatrixInjector.py:60
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
mps_setup.append
append
Definition: mps_setup.py:85
MatrixInjector.MatrixInjector.batchName
batchName
Definition: MatrixInjector.py:63
MatrixInjector.MatrixInjector.count
count
Definition: MatrixInjector.py:44
MatrixInjector.MatrixInjector.defaultScratch
defaultScratch
Definition: MatrixInjector.py:145
createfilelist.int
int
Definition: createfilelist.py:10
MatrixInjector.MatrixInjector.memPerCore
memPerCore
Definition: MatrixInjector.py:58
MatrixInjector.MatrixInjector.__init__
def __init__(self, opt, mode='init', options='')
Definition: MatrixInjector.py:43
MatrixInjector.performInjectionOptionTest
def performInjectionOptionTest(opt)
Definition: MatrixInjector.py:12
MatrixInjector.MatrixInjector.submit
def submit(self)
Definition: MatrixInjector.py:637
MatrixInjector.MatrixInjector.get_wmsplit
def get_wmsplit()
Definition: MatrixInjector.py:189
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
MatrixInjector.MatrixInjector.label
label
Definition: MatrixInjector.py:100
MatrixInjector.MatrixInjector.numberEventsInLuminosityBlock
numberEventsInLuminosityBlock
Definition: MatrixInjector.py:59
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
genParticles_cff.map
map
Definition: genParticles_cff.py:11
MatrixInjector.MatrixInjector.version
version
Definition: MatrixInjector.py:55
MatrixInjector.MatrixInjector.user
user
Definition: MatrixInjector.py:98
MatrixInjector.MatrixInjector.defaultChain
defaultChain
Definition: MatrixInjector.py:114
MatrixInjector.MatrixInjector.dqmgui
dqmgui
Definition: MatrixInjector.py:46
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444