File indexing completed on 2024-04-06 12:33:12
0001
0002
0003 from __future__ import print_function
0004 import os
0005 import sys
0006 import fileinput
0007 import string
0008
0009
0010
0011
0012
0013
0014 FastSimUse="False"
0015
0016
0017 onlyRecoMuons="False"
0018
0019
0020 NewRelease='CMSSW_3_8_0_pre1'
0021
0022
0023 if (FastSimUse=="True"):
0024 startupsamples= ['RelValTTbar']
0025 idealsamples= ['RelValSingleMuPt10', 'RelValSingleMuPt100', 'RelValTTbar']
0026 else:
0027 startupsamples= ['RelValTTbar','RelValZMM','RelValJpsiMM']
0028 idealsamples= ['RelValSingleMuPt10', 'RelValSingleMuPt100', 'RelValSingleMuPt1000', 'RelValTTbar']
0029
0030
0031
0032 Algos= ['']
0033 Qualities=['']
0034
0035
0036
0037 Tracksname=''
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 Sequence='harvesting'
0050
0051 Submit=False
0052
0053 DBS=True
0054 OneAtATime=False
0055
0056
0057 IdealTag='MC'
0058 StartupTag='STARTUP'
0059
0060 IdealTagUse='MC_37Y_V5'
0061 StartupTagUse='START37_V5'
0062 VersionTag='v1'
0063
0064
0065
0066 ReferenceSelection='IDEAL_31X__noPU'
0067 StartupReferenceSelection='STARTUP_31X_noPU'
0068
0069
0070 if (FastSimUse=="True"):
0071 NewSelectionLabel='_FSIM'
0072 else:
0073 NewSelectionLabel=''
0074
0075 WorkDirBase = '/tmp/aperrott/'+NewRelease+'/src/Validation/RecoMuon/test'
0076
0077
0078
0079
0080 RefRepository = '/afs/cern.ch/cms/Physics/muon/CMSSW/Performance/RecoMuon/Validation/val'
0081 NewRepository = '/afs/cern.ch/cms/Physics/muon/CMSSW/Performance/RecoMuon/Validation/val'
0082
0083
0084 defaultNevents ='-1'
0085
0086
0087 Events={}
0088
0089
0090
0091 cfg='muonReleaseValidationFastSim_cfg.py'
0092 macro='macro/TrackValHistoPublisher.C'
0093
0094
0095 ProcessName = 'MUVAL'
0096 if (Sequence=='harvesting'):
0097 ProcessName = 'MUVALHV'
0098 elif (Sequence=='only_validation_and_TP'):
0099 ProcessName = 'MUVALTP'
0100
0101
0102
0103
0104
0105
0106 def replace(map, filein, fileout):
0107 replace_items = map.items()
0108 while True:
0109 line = filein.readline()
0110 if not line: break
0111 for old, new in replace_items:
0112 line = string.replace(line, old, new)
0113 fileout.write(line)
0114 fileout.close()
0115 filein.close()
0116
0117
0118
0119
0120 def do_validation(samples, GlobalTag, trackquality, trackalgorithm):
0121 global Sequence, RefSelection, RefRepository, NewSelection, NewRepository, defaultNevents, Events, GlobalTagUse
0122 global cfg, macro, Tracksname
0123 print('Search Tag: ' + GlobalTag)
0124 print('Tag to use: ' + GlobalTagUse)
0125
0126
0127 NewSelection=GlobalTag +'_noPU'
0128 if( trackquality !=''):
0129 NewSelection+='_'+trackquality
0130 if(trackalgorithm!=''):
0131 NewSelection+='_'+trackalgorithm
0132 if(trackquality =='') and (trackalgorithm==''):
0133 if(Tracksname==''):
0134 NewSelection+='_ootb'
0135 Tracks='generalTracks'
0136 else:
0137 NewSelection+= Tracks
0138 elif(Tracksname==''):
0139 Tracks='cutsRecoTracks'
0140 else:
0141 Tracks=Tracksname
0142 NewSelection+=NewSelectionLabel
0143
0144
0145 for sample in samples :
0146 print('Get information from DBS for sample', sample)
0147
0148 newdir=NewRepository+'/'+NewRelease+'/'+NewSelection+'/'+sample
0149
0150 WorkDir = WorkDirBase+'/'+NewRelease+'/'+NewSelection+'/'+sample
0151
0152 if(os.path.exists(WorkDir)==False):
0153 os.makedirs(WorkDir)
0154
0155
0156
0157 if(os.path.isfile(newdir+'/val.'+sample+'.rootytootie' )!=True):
0158
0159
0160 cmd='python3 $DBSCMD_HOME/dbsCommandLine.py "find dataset where dataset like *'
0161
0162 if (FastSimUse=="True"):
0163 cmd+=sample+'/'+NewRelease+'-'+GlobalTagUse+'*GEN-SIM-DIGI-RECO* AND site like *cern* "'
0164
0165 cmd+='|grep '+sample+'|grep '+VersionTag+'|grep FastSim |sort| tail -1 | cut -d "," -f2 '
0166 else:
0167
0168 cmd+=sample+'/'+NewRelease+'-'+GlobalTagUse+'*GEN-SIM-RECO* AND site like *cern* "'
0169
0170 cmd+='|grep '+sample+'|grep '+VersionTag+'|grep -v FastSim |sort| tail -1 | cut -d "," -f2 '
0171 print(cmd)
0172 dataset= os.popen(cmd).readline()
0173 print('DataSet: ', dataset, '\n')
0174
0175
0176 if(dataset!="" or DBS==False):
0177 print('dataset found ', dataset[:-1])
0178
0179 cmd2='python3 $DBSCMD_HOME/dbsCommandLine.py "find file where dataset like '+ dataset[:-1] +'"|grep ' + sample
0180
0181 thisFile=0
0182 for thisFilename in os.popen(cmd2).readlines():
0183 templatecfgFile = open(cfg, 'r')
0184 thisFile=thisFile+1
0185 filenames='import FWCore.ParameterSet.Config as cms\n\n'
0186 filenames+='readFiles = cms.untracked.vstring()\n'
0187 filenames+='secFiles = cms.untracked.vstring()\n'
0188 filenames+='source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles)\n'
0189 filenames+='readFiles.extend( [\n'
0190 if dataset!="":
0191 if (OneAtATime==False):
0192 for filename in os.popen(cmd2).readlines():
0193 filenames+='"'+filename[:-1]+'",'
0194 else:
0195 filenames+='"'+thisFilename+'",'
0196 filenames+=']);\n'
0197
0198
0199
0200 if(dataset!="" and Sequence!="harvesting"):
0201 print('Getting secondary files')
0202 if (FastSimUse=="True"):
0203 cmd3=cmd
0204 else:
0205 cmd3='python3 $DBSCMD_HOME/dbsCommandLine.py "find dataset.parent where dataset like '+ dataset[:-1] +'"|grep ' + sample
0206 parentdataset=os.popen(cmd3).readline()
0207 print('Parent DataSet: ', parentdataset, '\n')
0208
0209
0210 if parentdataset!="":
0211 cmd4='python3 $DBSCMD_HOME/dbsCommandLine.py "find file where dataset like '+ parentdataset[:-1] +'"|grep ' + sample
0212 filenames+='secFiles.extend( [\n'
0213 first=True
0214 for line in os.popen(cmd4).readlines():
0215 filenames+='"'+line[:-1]+'",'
0216 filenames+=']);\n'
0217 else :
0218 print("No primary dataset found skipping sample: ", sample)
0219 continue
0220 else :
0221 filenames+='secFiles.extend( ( ) )\n'
0222
0223 cfgFileName=('%s_%d') % (sample,thisFile)
0224 print('cfgFileName ' + cfgFileName)
0225 cfgFile = open(cfgFileName+'.py' , 'w' )
0226 cfgFile.write(filenames)
0227
0228 if ((sample in Events)!=True):
0229 Nevents=defaultNevents
0230 else:
0231 Nevents=Events[sample]
0232 print('line 199')
0233 symbol_map = { 'PROCESSNAME':ProcessName, 'NEVENT':Nevents, 'GLOBALTAG':GlobalTagUse, 'SEQUENCE':Sequence, 'SAMPLE': sample, 'ALGORITHM':trackalgorithm, 'QUALITY':trackquality, 'TRACKS':Tracks, 'FASTSIM':FastSimUse, 'ONLYRECOMUONS':onlyRecoMuons}
0234
0235
0236 cfgFile = open(cfgFileName+'.py' , 'a' )
0237 replace(symbol_map, templatecfgFile, cfgFile)
0238
0239 cmdrun='cmsRun ' + WorkDir +'/'+cfgFileName+ '.py >& ' + cfgFileName + '.log < /dev/zero '
0240
0241 print(cmdrun)
0242
0243 lancialines='#!/usr/local/bin/bash \n'
0244 lancialines+='cd '+ProjectBase+'/src \n'
0245 lancialines+='eval `scramv1 run -sh` \n\n'
0246 lancialines+='cd '+WorkDir+'\n'
0247 lancialines+='cmsRun '+cfgFileName+'.py >& ' + cfgFileName + '.log < /dev/zero \n'
0248 lancialines+='mv DQM_V0001_R000000001__' + GlobalTagUse+ '__' + sample + '__Validation.root' + ' ' + 'val.' +sample+'.root \n'
0249
0250 lanciaName=('lancia_%s_%s_%d') % (GlobalTag,sample,thisFile)
0251 lanciaFile = open(lanciaName,'w')
0252 lanciaFile.write(lancialines)
0253 lanciaFile.close()
0254
0255 print(("copying py file for sample: %s %s") % (sample,lanciaName))
0256 iii = os.system('mv '+lanciaName+' '+WorkDir+'/.')
0257 print(iii)
0258 iii = os.system('mv '+cfgFileName+'.py '+WorkDir)
0259 print(iii)
0260 if(OneAtATime==False):
0261 break
0262
0263 retcode=0
0264
0265 if(Submit):
0266 retcode=os.system(cmdrun)
0267 if os.path.isfile(sample+'.log'):
0268 os.system('mv '+sample+'.log ' + WorkDir)
0269 else:
0270 continue
0271
0272 if (retcode!=0):
0273 print('Job for sample '+ sample + ' failed. \n')
0274 else:
0275 if Sequence=="harvesting":
0276 os.system('mv DQM_V0001_R000000001__' + GlobalTag+ '__' + sample + '__Validation.root' + ' ' + WorkDir+'/val.' +sample+'.root')
0277 if os.path.isfile('fullOutput.'+sample+'.root'):
0278 os.system('mv fullOutput.'+sample+'.root ' + WorkDir)
0279 if os.path.isfile('output.'+sample+'.root'):
0280 os.system('mv output.'+sample+'.root ' + WorkDir)
0281
0282 else:
0283 print('No dataset found skipping sample: '+ sample, '\n')
0284 else:
0285 print('Validation for sample ' + sample + ' already done. Skipping this sample. \n')
0286
0287
0288
0289
0290
0291
0292
0293
0294 try:
0295
0296 if Submit:
0297 print('Will Submit job')
0298
0299 ProjectBase = os.environ["CMSSW_BASE"]
0300
0301
0302
0303
0304
0305 except KeyError:
0306 print('Error: The environment variable CMSSW_VERSION is not available.', file=sys.stderr)
0307 print(' Please run eval `scramv1 runtime -csh` to set your environment variables', file=sys.stderr)
0308 sys.exit()
0309
0310
0311
0312
0313 if os.path.isfile( 'dbsCommandLine.py')!=True:
0314 print("Failed to find the file ($DBSCMD_HOME/dbsCommandLine.py)", file=sys.stderr)
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325 NewSelection=''
0326
0327 for algo in Algos:
0328 print('algo ' + algo)
0329 for quality in Qualities:
0330 print('quality ' + quality)
0331 RefSelection=ReferenceSelection
0332 print('Before RefSelection: ' + RefSelection)
0333 if( quality !=''):
0334 RefSelection+='_'+quality
0335 if(algo!=''):
0336 RefSelection+='_'+algo
0337 if(quality =='') and (algo==''):
0338 RefSelection+='_ootb'
0339 print('After RefSelection: ' + RefSelection)
0340 GlobalTagUse=IdealTagUse
0341 do_validation(idealsamples, IdealTag, quality , algo)
0342 RefSelection=StartupReferenceSelection
0343 print('Before StartupRefSelection: ' + RefSelection)
0344 if( quality !=''):
0345 RefSelection+='_'+quality
0346 if(algo!=''):
0347 RefSelection+='_'+algo
0348 if(quality =='') and (algo==''):
0349 RefSelection+='_ootb'
0350 print('After StartupRefSelection: ' + RefSelection)
0351 GlobalTagUse=StartupTagUse
0352 do_validation(startupsamples, StartupTag, quality , algo)
0353