File indexing completed on 2023-03-17 11:28:38
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 NewRelease='CMSSW_3_8_0_pre2'
0015
0016
0017
0018 startupsamples= []
0019
0020
0021 idealsamples= ['RelValSingleMuPt100']
0022
0023
0024 Algos= ['']
0025 Qualities=['']
0026
0027
0028
0029 Tracksname=''
0030
0031
0032
0033
0034
0035
0036 Sequence='reco_and_val'
0037
0038 SearchContent="*GEN-SIM-RECO*"
0039 DriverSteps="HARVESTING:validationHarvesting"
0040 if(Sequence=="harvesting"):
0041 SearchContent="*GEN-SIM-RECO*"
0042 DriverSteps="HARVESTING:validationHarvesting+dqmHarvesting"
0043 if(Sequence=="reco_and_val"):
0044 SearchContent="*GEN-SIM*HLTDEBUG*"
0045 DriverSteps="RAW2DIGI,RECO,VALIDATION"
0046 if(Sequence=="only_val"):
0047 SearchContent="*GEN-SIM-RECO*"
0048 DriverSteps="POSTRECO,VALIDATION"
0049
0050 print(Sequence+' '+SearchContent)
0051
0052 Submit=False
0053 DBS=True
0054 OneAtATime=False
0055
0056
0057 IdealTag='MC_38Y_V1'
0058 StartupTag='STARTUP_31X_v1'
0059
0060
0061 NewSelectionLabel='_test'
0062
0063 WorkDirBase = '/tmp/'
0064
0065
0066
0067
0068 defaultNevents ='-1'
0069
0070
0071 Events={}
0072
0073
0074
0075
0076
0077
0078
0079 def replace(map, filein, fileout):
0080 replace_items = map.items()
0081 while True:
0082 line = filein.readline()
0083 if not line: break
0084 for old, new in replace_items:
0085 line = string.replace(line, old, new)
0086 fileout.write(line)
0087 fileout.close()
0088 filein.close()
0089
0090
0091
0092
0093 def do_validation(samples, GlobalTagUse, trackquality, trackalgorithm):
0094 global Sequence, NewSelection, defaultNevents, Events
0095 global Tracksname,SearchContent,DriverSteps
0096 splitResult = GlobalTagUse.split('_')
0097 GlobalTag = splitResult[0]
0098 print('Search Tag: ' + GlobalTag)
0099 print('Tag to use: ' + GlobalTagUse)
0100
0101
0102 NewSelection=GlobalTag +'_noPU'
0103 if( trackquality !=''):
0104 NewSelection+='_'+trackquality
0105 if(trackalgorithm!=''):
0106 NewSelection+='_'+trackalgorithm
0107 if(trackquality =='') and (trackalgorithm==''):
0108 if(Tracksname==''):
0109 NewSelection+='_ootb'
0110 Tracks='generalTracks'
0111 else:
0112 NewSelection+= Tracks
0113 elif(Tracksname==''):
0114 Tracks='cutsRecoTracks'
0115 else:
0116 Tracks=Tracksname
0117 NewSelection+=NewSelectionLabel
0118
0119
0120 for sample in samples :
0121 print('Get information from DBS for sample', sample)
0122
0123 WorkDir = WorkDirBase+'/'+NewRelease+'/'+NewSelection+'/'+sample
0124
0125 if(os.path.exists(WorkDir)==False):
0126 os.makedirs(WorkDir)
0127
0128
0129
0130
0131 if(True):
0132
0133 cmd='dbsql "find dataset where dataset like *'
0134 cmd+=sample+'/'+NewRelease+'_'+GlobalTag+SearchContent+' "'
0135 cmd+='|grep '+sample+'|grep -v test|sort|tail -1|cut -f2 '
0136 print(cmd)
0137 dataset= os.popen(cmd).readline().strip()
0138 print('DataSet: ', dataset, '\n')
0139
0140 if(dataset!="" or DBS==False):
0141
0142
0143 cmd2='dbsql "find file where dataset like '+ dataset +'"|grep ' + sample
0144 thisFile=0
0145 filenames='import FWCore.ParameterSet.Config as cms\n'
0146 filenames+='readFiles = cms.untracked.vstring()\n'
0147 filenames+='secFiles = cms.untracked.vstring()\n'
0148 filenames+='source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles)\n'
0149 filenames+='readFiles.extend( [\n'
0150 first=True
0151 print(cmd2)
0152 for line in os.popen(cmd2).readlines():
0153 filename=line.strip()
0154 thisFile=thisFile+1
0155 if first==True:
0156 filenames+="'"
0157 filenames+=filename
0158 filenames+="'"
0159 first=False
0160 else :
0161 filenames+=",\n'"
0162 filenames+=filename
0163 filenames+="'"
0164 filenames+='\n]);\n'
0165
0166
0167 if(Sequence!="harvesting" and Sequence!="reco_and_val"):
0168 cmd3='dbsql "find dataset.parent where dataset like '+ dataset +'"|grep ' + sample
0169 parentdataset=os.popen(cmd3).readline()
0170 print('Parent DataSet: ', parentdataset, '\n')
0171
0172
0173 if parentdataset!="":
0174 cmd4='dbsql "find file where dataset like '+ parentdataset +'"|grep ' + sample
0175 filenames+='secFiles.extend( [\n'
0176 first=True
0177
0178 for line in os.popen(cmd4).readlines():
0179 secfilename=line.strip()
0180 if first==True:
0181 filenames+="'"
0182 filenames+=secfilename
0183 filenames+="'"
0184 first=False
0185 else :
0186 filenames+=",\n'"
0187 filenames+=secfilename
0188 filenames+="'"
0189 filenames+='\n]);\n'
0190 else :
0191 print("No parent dataset found skipping sample: ", sample)
0192 filenames+='secFiles.extend( ( ) )\n'
0193
0194
0195 else :
0196 filenames+='secFiles.extend( ( ) )\n'
0197
0198
0199
0200
0201 cfgFileName=('%s_%s_%d') % (sample,Sequence,thisFile)
0202 print('cfgFileName ' + cfgFileName)
0203
0204
0205 sampleFileName='sample_'+Sequence
0206 sampleFile = open(sampleFileName+'.py','w' )
0207 sampleFile.write(filenames)
0208 sampleFile.close()
0209
0210
0211 if ((sample in Events)!=True):
0212 Nevents=defaultNevents
0213 else:
0214 Nevents=Events[sample]
0215
0216 symbol_map = { 'NEVENT':Nevents, 'GLOBALTAG':GlobalTagUse, 'SEQUENCE':Sequence, 'SAMPLE': sample, 'ALGORITHM':trackalgorithm, 'QUALITY':trackquality, 'TRACKS':Tracks}
0217
0218 cmdrun='cmsRun ' + WorkDir +'/'+cfgFileName+ '.py >& ' + cfgFileName + '.log < /dev/zero '
0219
0220 print(cmdrun)
0221
0222 lancialines='#!/bin/bash \n'
0223 lancialines+='cd '+ProjectBase+'/src \n'
0224 lancialines+='eval `scramv1 run -sh` \n\n'
0225 lancialines+='export PYTHONPATH=.:$PYTHONPATH \n'
0226 lancialines+='cd '+WorkDir+'\n'
0227 lancialines+='cmsRun '+cfgFileName+'.py >& ' + cfgFileName + '.log < /dev/zero \n'
0228
0229 lancialines+='mv DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root' + ' ' + 'val.' +sample+'.root \n'
0230
0231 lanciaName=('lancia_%s_%s_%s_%d') % (GlobalTag,sample,Sequence,thisFile)
0232 lanciaFile = open(lanciaName,'w')
0233 lanciaFile.write(lancialines)
0234 lanciaFile.close()
0235
0236 previousFileOut=''
0237 command=''
0238 nextFileOut=''
0239 specialCommand=''
0240 processName=''
0241 if(Sequence=="reco_and_val"):
0242 nextFileOut+='step2_RECO_VALIDATION.root'
0243 command+='step2'
0244 previousFileOut+='step1.root'
0245 processName+='RecVal'
0246 if(Sequence=="only_val"):
0247 nextFileOut+='step2_VALIDATION.root'
0248 command+='step2'
0249 previousFileOut+='step2.root'
0250 processName+='VAL'
0251 if(Sequence=="harvesting"):
0252 if(previousFileOut==''):
0253 previousFileOut+='step2.root'
0254 command+='harvest'
0255 nextFileOut+='harvest_out.root'
0256 specialCommand+=' --harvesting AtJobEnd'
0257 processName+='HARV'
0258
0259 driverCmdNew='cmsDriver.py '+ command
0260 driverCmdNew+=' -s '+DriverSteps
0261 driverCmdNew+=' '+processName+' '
0262 driverCmdNew+=' --mc '
0263 driverCmdNew+=' -n'+Nevents
0264 driverCmdNew+=' --conditions FrontierConditions_GlobalTag,'+GlobalTagUse+'::All'
0265 driverCmdNew+=' --filein file:'+previousFileOut
0266 driverCmdNew+=' --fileout '+nextFileOut
0267 driverCmdNew+=' --python_filename='+cfgFileName+'.py '
0268 driverCmdNew+=' --no_exec '
0269 driverCmdNew+=' --customise=Validation/RecoMuon/customise.py '
0270 driverCmdNew+=' '+specialCommand+' '
0271
0272 print(driverCmdNew)
0273 iii=os.system(driverCmdNew)
0274
0275 print(("copying py file for sample: %s %s") % (sample,lanciaName))
0276 iii = os.system('mv '+lanciaName+' '+WorkDir+'/.')
0277 print(iii)
0278 iii = os.system('mv '+sampleFileName+'.py '+WorkDir)
0279 iii = os.system('mv '+cfgFileName+'.py '+WorkDir)
0280
0281
0282
0283
0284 retcode=0
0285
0286 if(Submit):
0287 retcode=os.system(cmdrun)
0288 if os.path.isfile(sample+'.log'):
0289 os.system('mv '+sample+'.log ' + WorkDir)
0290 else:
0291 continue
0292
0293 if (retcode!=0):
0294 print('Job for sample '+ sample + ' failed. \n')
0295 else:
0296 if Sequence=="harvesting":
0297 os.system('mv DQM_V0001_R000000001__' + GlobalTag+ '__' + sample + '__Validation.root' + ' ' + WorkDir+'/val.' +sample+'.root')
0298 if os.path.isfile('fullOutput.'+sample+'.root'):
0299 os.system('mv fullOutput.'+sample+'.root ' + WorkDir)
0300 if os.path.isfile('output.'+sample+'.root'):
0301 os.system('mv output.'+sample+'.root ' + WorkDir)
0302
0303 else:
0304 print('No dataset found skipping sample: '+ sample, '\n')
0305 else:
0306 print('Validation for sample ' + sample + ' already done. Skipping this sample. \n')
0307
0308
0309
0310
0311
0312
0313
0314
0315 try:
0316
0317 if Submit:
0318 print('Will Submit job')
0319
0320 ProjectBase = os.environ["CMSSW_BASE"]
0321
0322
0323
0324
0325
0326 except KeyError:
0327 print('Error: The environment variable CMSSW_VERSION is not available.', file=sys.stderr)
0328 print(' Please run eval `scramv1 runtime -csh` to set your environment variables', file=sys.stderr)
0329 sys.exit()
0330
0331
0332
0333
0334 if os.path.isfile( 'dbsCommandLine.py')!=True:
0335 print("Failed to find the file ($DBSCMD_HOME/dbsCommandLine.py)", file=sys.stderr)
0336
0337 NewSelection=''
0338
0339 for algo in Algos:
0340 print('algo ' + algo)
0341 for quality in Qualities:
0342 print('quality ' + quality)
0343 do_validation(idealsamples, IdealTag, quality , algo)
0344 do_validation(startupsamples, StartupTag, quality , algo)
0345