File indexing completed on 2023-03-17 11:29:09
0001
0002
0003 from __future__ import print_function
0004 import os
0005 import sys
0006 import fileinput
0007 import string
0008
0009
0010 RefRelease='CMSSW_3_6_0_pre1'
0011
0012
0013 NewRelease='CMSSW_3_6_0_pre1'
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 startupsamples = []
0025
0026
0027
0028
0029
0030
0031
0032
0033 idealsamples = []
0034
0035
0036 mcsamples = ['RelValTTbar']
0037
0038
0039 Sequence = 'only_validation'
0040
0041
0042
0043 IdealTag = 'DESIGN_3X_V21'
0044
0045 StartupTag = 'STARTUP3X_V8H'
0046
0047
0048 MCTag = 'MC_3XY_V21'
0049
0050
0051
0052 PileUp = 'noPU'
0053
0054
0055 ReferenceSelection = 'DESIGN_3X_V21_'+PileUp
0056 MCReferenceSelection = 'MC_3XY_V21_'+PileUp
0057 StartupReferenceSelection = 'STARTUP3X_V8H_'+PileUp
0058
0059
0060
0061 RefRepository = '/nfs/data35/cms/drell/val360pre1'
0062
0063 NewRepository = '/nfs/data35/cms/drell/val360pre1'
0064
0065
0066 defaultNevents = '-1'
0067
0068
0069 Events = {}
0070
0071
0072 cfg = 'v0PerformanceValidation_cfg.py'
0073 macro = 'macros/V0ValHistoPublisher.C'
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 def replace(map, filein, fileout):
0091 replace_items = map.items()
0092 while True:
0093 line = filein.readline()
0094 if not line: break
0095 for old, new in replace_items:
0096 line = string.replace(line, old, new)
0097 fileout.write(line)
0098 fileout.close()
0099 filein.close()
0100
0101
0102
0103 def do_validation(samples, GlobalTag):
0104 global Sequence, RefSelection, RefRepository, NewSelection, NewRepository, defaultNevents, Events
0105 global cfg, macro, Tracksname
0106
0107 NewSelection = GlobalTag + '_' + PileUp
0108
0109 for sample in samples:
0110 templateCfgFile = open(cfg, 'r')
0111 templateMacroFile = open(macro, 'r')
0112 newdir = NewRepository + '/' + NewRelease + '/' + NewSelection + '/' + sample
0113 cfgFileName = sample + GlobalTag
0114
0115 if(os.path.isfile(newdir + '/K0sEff.pdf') != True):
0116
0117 harvestedfile = './DQM_V0001_R000000001__' + GlobalTag + '__' + sample + '__Validation.root'
0118 if(( Sequence == "harvesting" and os.path.isfile(harvestedfile)) == False):
0119
0120 cmd = 'dbsql "find dataset where dataset like *'
0121 cmd += sample + '/' + NewRelease + '_' + GlobalTag + '*GEN-SIM-RECO*" '
0122 cmd += '| grep ' + sample + ' | grep -v test | sort | tail -1 | cut -f2 '
0123 print(cmd)
0124 print('Finding data set...\n')
0125 dataset = os.popen(cmd).readline().strip()
0126 print('DataSet: ', dataset, '\n')
0127 if dataset != "":
0128 cmd2 = 'dbsql "find file where dataset like ' + dataset + '" | grep ' + sample
0129 filenames = 'import FWCore.ParameterSet.Config as cms\n'
0130 filenames += 'readFiles = cms.untracked.vstring()\n'
0131 filenames += 'secFiles = cms.untracked.vstring()\n'
0132 filenames += 'source = cms.Source("PoolSource", fileNames = readFiles, secondaryFileNames = secFiles)\n'
0133 filenames += 'readFiles.extend([\n'
0134 first = True
0135
0136 print('Getting file names for dataset ', dataset, '\n')
0137 for line in os.popen(cmd2).readlines():
0138 filename = line.strip()
0139 if first == True:
0140 filenames += " '"
0141 filenames += filename
0142 filenames += "'"
0143 first = False
0144 else:
0145 filenames += ",\n '"
0146 filenames += filename
0147 filenames += "'"
0148 filenames += ']);\n'
0149
0150 if(Sequence != 'harvesting'):
0151 cmd3 = 'dbsql "find dataset.parent where dataset like ' + dataset + '" | grep ' + sample
0152
0153 print('Getting parent dataset...\n')
0154 parentdataset = os.popen(cmd3).readline()
0155 print('Parent dataset: ', parentdataset, '\n')
0156 if parentdataset != "":
0157 cmd4 = 'dbsql "find file where dataset like ' + parentdataset + '" | grep ' + sample
0158
0159 filenames += 'secFiles.extend([\n'
0160 first = True
0161 for line in os.popen(cmd4).readlines():
0162 secfilename = line.strip()
0163 if first == True:
0164 filenames += " '"
0165 filenames += secfilename
0166 filenames += "'"
0167 first = False
0168 else:
0169 filenames += ",\n '"
0170 filenames += secfilename
0171 filenames += "'"
0172 filenames += ']);\n\n'
0173 else:
0174 print("No primary dataset found, skipping sample ", sample)
0175 continue
0176 else:
0177 filenames += 'secFiles.extend(( ))'
0178
0179 cfgFile = open(cfgFileName + '.py', 'w')
0180 cfgFile.write(filenames)
0181
0182 if(sample in Events):
0183 Nevents = Events[sample]
0184 else:
0185 Nevents = defaultNevents
0186
0187 symbol_map = {'NEVENT':Nevents, 'GLOBALTAG':GlobalTag, 'SEQUENCE':Sequence, 'SAMPLE':sample}
0188 cfgfile = open(cfgFileName + '.py', 'a')
0189 replace(symbol_map, templateCfgFile, cfgFile)
0190
0191 cmdrun = 'cmsRun ' + cfgFileName + '.py >& ' + cfgFileName + '.log < /dev/zero'
0192 print('Running validation on sample ' + sample + '...\n')
0193
0194 retcode = os.system(cmdrun)
0195 else:
0196 print('No dataset found, skipping sample ', sample, '\n')
0197 continue
0198 else:
0199 retcode = 0
0200 if(retcode):
0201 print('Job for sample ' + sample + ' failed.\n')
0202 print('Check log file ' + sample + '.log for details.\n')
0203 else:
0204 if Sequence == 'harvesting':
0205 rootcommand = 'root -b -q -l CopySubdir.C\\('+'\\\"DQM_V0001_R000000001__'+GlobalTag+'__'+sample+'__Validation.root\\\", \\\"val.'+sample+'.root\\\"\\) >& /dev/null'
0206 os.system(rootcommand)
0207 referenceSample = RefRepository + '/' + RefRelease + '/' + RefSelection + '/' + sample + '/' + 'val.'+sample+'.root'
0208 print('Reference sample: ' + referenceSample)
0209
0210 if os.path.isfile(referenceSample):
0211 print('Found reference.')
0212 replace_map = {'NEW_FILE':'val.'+sample+'.root', 'REF_FILE':RefRelease+'/'+RefSelection+'/'+'val.'+sample+'.root', 'REF_LABEL':sample, 'NEW_LABEL':sample, 'REF_RELEASE':RefRelease, 'NEW_RELEASE':NewRelease, 'REFSELECTION':RefSelection, 'NEWSELECTION':NewSelection, 'V0ValHistoPublisher':cfgFileName }
0213
0214 if not os.path.exists(RefRelease + '/' + RefSelection):
0215 os.makedirs(RefRelease + '/' + RefSelection)
0216 os.system('cp ' + referenceSample + ' ' + RefRelease+'/'+RefSelection)
0217
0218 else:
0219 print("No reference file found at ", RefRepository+'/'+RefRelease+'/'+RefSelection)
0220 replace_map = {'NEW_FILE':'val.'+sample+'.root', 'REF_FILE':'val.'+sample+'.root', 'REF_LABEL':sample, 'NEW_LABEL':sample, 'REF_RELEASE':NewRelease, 'NEW_RELEASE':NewRelease, 'REFSELECTION':NewSelection, 'NEWSELECTION':NewSelection, 'V0ValHistoPublisher':cfgFileName }
0221
0222 macroFile = open(cfgFileName+'.C', 'w')
0223 replace(replace_map, templateMacroFile, macroFile)
0224
0225 os.system('root -b -q -l ' + cfgFileName + '.C' + ' > macro.' + cfgFileName + '.log')
0226
0227 if not os.path.exists(newdir):
0228 os.makedirs(newdir)
0229
0230 print("Moving PDF and PNG files for sample: ", sample)
0231 os.system('mv *pdf *png ' + newdir)
0232
0233 print("Moving ROOT file for sample: ", sample)
0234 os.system('mv val.'+sample+'.root ' + newdir)
0235
0236 print("Copying .py file for sample: ", sample)
0237 os.system('cp '+cfgFileName+'.py ' + newdir)
0238 else:
0239 print('Validation for sample '+sample+' already done, skipping.\n')
0240
0241
0242
0243
0244 if(NewRelease == ''):
0245 try:
0246 NewRelease = os.environ["CMSSW_VERSION"]
0247 except KeyError:
0248 print('Error: The environment variable CMSSW_VERSION is not set.', file=sys.stderr)
0249 print(' Please run cmsenv in the appropriate release area.', file=sys.stderr)
0250 else:
0251 try:
0252 os.environ["CMSSW_VERSION"]
0253 except KeyError:
0254 print('Error: CMSSW environment variables are not set.', file=sys.stderr)
0255 print(' Please run cmsenv in the appropriate release area.', file=sys.stderr)
0256
0257 NewSelection = ''
0258 RefSelection = MCReferenceSelection
0259 do_validation(mcsamples, MCTag)
0260
0261 NewSelection = ''
0262 RefSelection = StartupReferenceSelection
0263 do_validation(startupsamples, StartupTag)
0264
0265 NewSelection = ''
0266 RefSelection = ReferenceSelection
0267 do_validation(idealsamples, IdealTag)
0268
0269 print('Finished running validation.')