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