Functions | |
def | add_to_blacklist |
def | call_compare_using_files |
def | check_root_files |
def | count_alive_processes |
def | do_comparisons_threaded |
def | do_html |
def | do_reports |
def | get_clean_fileanames |
def | get_filenames_from_pool |
def | get_roofiles_in_dir |
def | guess_blacklists |
def | guess_params |
def | name2run |
def | name2runskim |
def | name2sample |
def | name2version |
Variables | |
string | action = "store" |
---HASHING---## | |
string | all_samples = "" |
argv = sys.argv | |
default = ref_samples, | |
string | dest = "ref_samples" |
string | help = "The samples that act as reference (comma separated list)" |
hlt = False | |
string | in_dir = "" |
int | n_processes = 1 |
int | n_threads = 1 |
string | out_dir = "" |
tuple | parser = OptionParser(usage="usage: %prog [options]") |
string | ref_samples = "" |
int | run = 1 |
string | stat_test = "Chi2" |
string | test_samples = "" |
float | test_threshold = 0.00001 |
def ValidationMatrix::add_to_blacklist | ( | blacklist, | |
pattern, | |||
target, | |||
blist_piece | |||
) |
Definition at line 122 of file ValidationMatrix.py.
00123 : 00124 int_pattern=pattern 00125 int_pattern=pattern.strip() 00126 flip_condition=False 00127 if int_pattern[0]=='!': 00128 int_pattern=int_pattern[1:] 00129 flip_condition=True 00130 00131 condition = search(int_pattern,target)!=None 00132 if flip_condition: 00133 condition = not condition 00134 00135 if condition: 00136 #print "Found %s in %s" %(pattern,target) 00137 if blacklist!="": # if not the first, add a comma 00138 blacklist+="," 00139 blacklist+=blist_piece 00140 #else: 00141 #print " NOT Found %s in %s" %(pattern,target) 00142 return blacklist 00143 00144 #-------------------------------------------------------------------------------
def ValidationMatrix::call_compare_using_files | ( | args | ) |
Creates shell command to compare two files using compare_using_files.py script and calls it.
Definition at line 272 of file ValidationMatrix.py.
00273 : 00274 """Creates shell command to compare two files using compare_using_files.py 00275 script and calls it.""" 00276 sample, ref_filename, test_filename, options = args 00277 blacklists=guess_blacklists([sample],name2version(ref_filename),name2version(test_filename),options.hlt) 00278 command = " compare_using_files.py " 00279 command+= "%s %s " %(ref_filename,test_filename) 00280 command+= " -C -R " 00281 if options.do_pngs: 00282 command+= " -p " 00283 command+= " -o %s " %sample 00284 # Change threshold to an experimental and empirical value of 10^-5 00285 command+= " --specify_run " 00286 command+= " -t %s " %options.test_threshold 00287 command+= " -s %s " %options.stat_test 00288 00289 # Inspect the HLT directories 00290 if options.hlt: 00291 command+=" -d HLT " 00292 00293 if options.hash_name: 00294 command += " --hash_name " 00295 00296 if options.blacklist_file: 00297 command += " --use_black_file " 00298 00299 if len(blacklists[sample]) >0: 00300 command+= '-B %s ' %blacklists[sample] 00301 print "\nExecuting -- %s" %command 00302 00303 process=call(filter(lambda x: len(x)>0,command.split(" "))) 00304 return process 00305 00306 00307 #--------------------------------------------------------------------------------
def ValidationMatrix::check_root_files | ( | names_list | ) |
Definition at line 113 of file ValidationMatrix.py.
def ValidationMatrix::count_alive_processes | ( | p_list | ) |
Definition at line 267 of file ValidationMatrix.py.
def ValidationMatrix::do_comparisons_threaded | ( | options | ) |
Definition at line 308 of file ValidationMatrix.py.
00309 : 00310 00311 n_processes= int(options.n_processes) 00312 00313 ref_filenames=[] 00314 test_filenames=[] 00315 00316 if len(options.all_samples)>0: 00317 ref_filenames,test_filenames=get_filenames_from_pool(options.all_samples) 00318 else: 00319 ref_filenames,test_filenames=get_clean_fileanames(options.ref_samples,options.test_samples) 00320 00321 # make the paths absolute 00322 ref_filenames=map(os.path.abspath,ref_filenames) 00323 test_filenames=map(os.path.abspath,test_filenames) 00324 00325 samples,cmssw_version1,cmssw_version2=guess_params(ref_filenames,test_filenames) 00326 00327 if len(samples)==0: 00328 print "No Samples found... Quitting" 00329 return 0 00330 00331 # blacklists=guess_blacklists(samples,cmssw_version1,cmssw_version2,options.hlt) 00332 00333 # Launch the single comparisons 00334 original_dir=os.getcwd() 00335 00336 outdir=options.out_dir 00337 if len(outdir)==0: 00338 print "Creating automatic outdir:", 00339 outdir="%sVS%s" %(cmssw_version1,cmssw_version2) 00340 print outdir 00341 if len(options.input_dir)==0: 00342 print "Creating automatic indir:", 00343 options.input_dir=outdir 00344 print options.input_dir 00345 00346 if not os.path.exists(outdir): 00347 os.mkdir(outdir) 00348 os.chdir(outdir) 00349 00350 # adjust the number of threads 00351 n_comparisons=len(ref_filenames) 00352 if n_comparisons < n_processes: 00353 print "Less comparisons than possible processes: reducing n processes to", 00354 n_processes=n_comparisons 00355 #elif n_processes/n_comparisons == 0: 00356 #print "More comparisons than possible processes, can be done in N rounds: reducing n processes to", 00357 #original_nprocesses=n_processes 00358 #first=True 00359 #n_bunches=0 00360 #while first or n_processes > original_nprocesses: 00361 #n_processes=n_comparisons/2 00362 #if n_comparisons%2 !=0: 00363 #n_processes+=1 00364 #first=False 00365 00366 #print n_processes 00367 #print n_processes 00368 00369 # Test if we treat data 00370 skim_name="" 00371 if search("20[01]",cmssw_version1)!=None: 00372 skim_name=cmssw_version1.split("_")[-1] 00373 00374 running_subprocesses=[] 00375 process_counter=0 00376 #print ref_filenames 00377 00378 ## Compare all pairs of root files 00379 pool = Pool(n_processes) 00380 args_iterable = [list(args) + [options] for args in zip(samples, ref_filenames, test_filenames)] 00381 pool.map(call_compare_using_files, args_iterable) 00382 # move the pickles on the top, hack 00383 os.system("mv */*pkl .") 00384 00385 os.chdir("..") #-------------------------------------------------------------------------------
def ValidationMatrix::do_html | ( | options, | |
hashing_flag | |||
) |
Definition at line 414 of file ValidationMatrix.py.
00415 : 00416 00417 if options.reports: 00418 print "Preparing reports for the single files..." 00419 do_reports(options.input_dir) 00420 # Do the summary page 00421 aggregation_rules={} 00422 aggregation_rules_twiki={} 00423 # check which aggregation rules are to be used 00424 if options.hlt: 00425 print "Aggregating directories according to HLT rules" 00426 aggregation_rules=definitions.aggr_pairs_dict['HLT'] 00427 aggregation_rules_twiki=definitions.aggr_pairs_twiki_dict['HLT'] 00428 else: 00429 aggregation_rules=definitions.aggr_pairs_dict['reco'] 00430 aggregation_rules_twiki=definitions.aggr_pairs_twiki_dict['reco'] 00431 table_html = make_summary_table(options.input_dir,aggregation_rules,aggregation_rules_twiki, hashing_flag) 00432 00433 # create summary html file 00434 ofile = open("RelMonSummary.html","w") 00435 ofile.write(table_html) 00436 ofile.close() 00437 00438 #-------------------------------------------------------------------------------
def ValidationMatrix::do_reports | ( | indir | ) |
Definition at line 386 of file ValidationMatrix.py.
00387 : 00388 #print indir 00389 os.chdir(indir) 00390 pkl_list=filter(lambda x:".pkl" in x, os.listdir("./")) 00391 running_subprocesses=[] 00392 n_processes=int(options.n_processes) 00393 process_counter=0 00394 for pklfilename in pkl_list: 00395 command = "compare_using_files.py " 00396 command+= "-R " 00397 if options.do_pngs: 00398 command+= " -p " 00399 command+= "-P %s " %pklfilename 00400 command+= "-o %s " %pklfilename[:-4] 00401 print "Executing %s" %command 00402 process=call(filter(lambda x: len(x)>0,command.split(" "))) 00403 process_counter+=1 00404 # add it to the list 00405 running_subprocesses.append(process) 00406 if process_counter>=n_processes: 00407 process_counter=0 00408 for p in running_subprocesses: 00409 #print "Waiting for %s" %p.name 00410 p.wait() 00411 00412 os.chdir("..") 00413 #-------------------------------------------------------------------------------
def ValidationMatrix::get_clean_fileanames | ( | ref_samples, | |
test_samples | |||
) |
Definition at line 252 of file ValidationMatrix.py.
00253 : 00254 # Process the samples starting from the names 00255 ref_filenames=map(lambda s:s.strip(),ref_samples.split(",")) 00256 test_filenames=map(lambda s:s.strip(),test_samples.split(",")) 00257 00258 if len(ref_filenames)!=len(test_filenames): 00259 print "The numebr of reference and test files does not seem to be the same. Please check." 00260 exit(2) 00261 00262 if not (check_root_files(ref_filenames) and check_root_files(test_filenames)): 00263 exit(2) 00264 return ref_filenames,test_filenames 00265 00266 #-------------------------------------------------------------------------------
def ValidationMatrix::get_filenames_from_pool | ( | all_samples | ) |
Definition at line 198 of file ValidationMatrix.py.
00199 : 00200 00201 # get a list of the files 00202 files_list=get_roofiles_in_dir(all_samples) 00203 00204 if len(files_list)==0: 00205 print "Zero files found in directory %s!" %all_samples 00206 return [],[] 00207 00208 # Are they an even number? 00209 for name in files_list: 00210 print "* ",name 00211 if len(files_list)%2!=0: 00212 print "The numbuer of file is not even... Trying to recover a catastrophe." 00213 00214 files_list=make_files_pairs(files_list) 00215 00216 # Try to couple them according to their sample 00217 ref_filenames=[] 00218 test_filenames=[] 00219 #files_list.sort(key=name2version) 00220 #files_list.sort(key=name2sample) 00221 #files_list.sort(key=name2run) 00222 for iname in xrange(len(files_list)): 00223 filename=files_list[iname] 00224 if iname%2==0: 00225 ref_filenames.append(filename) 00226 else: 00227 test_filenames.append(filename) 00228 00229 print "The guess would be the following:" 00230 for ref,test in zip(ref_filenames,test_filenames): 00231 refbasedir=os.path.dirname(ref) 00232 testbasedir=os.path.dirname(test) 00233 dir_to_print=refbasedir 00234 if refbasedir!=testbasedir: 00235 dir_to_print="%s and %s" %(refbasedir,testbasedir) 00236 print "* Directory: %s " %dir_to_print 00237 refname=os.path.basename(ref) 00238 testname=os.path.basename(test) 00239 print " o %s" %refname 00240 print " o %s" %testname 00241 00242 #is_ok=ask_ok("Is that ok?") 00243 #if not is_ok: 00244 #print "Manual input needed then!" 00245 #exit(2) 00246 00247 00248 return ref_filenames,test_filenames 00249 00250 00251 #-------------------------------------------------------------------------------
def ValidationMatrix::get_roofiles_in_dir | ( | directory | ) |
Definition at line 189 of file ValidationMatrix.py.
00189 : 00190 print directory 00191 files_list = filter(lambda s: s.endswith(".root"), os.listdir(directory)) 00192 files_list_path=map(lambda s: os.path.join(directory,s), files_list) 00193 00194 return files_list_path 00195 00196 #------------------------------------------------------------------------------- 00197
def ValidationMatrix::guess_blacklists | ( | samples, | |
ver1, | |||
ver2, | |||
hlt | |||
) |
Build a blacklist for each sample accordind to a set of rules
Definition at line 145 of file ValidationMatrix.py.
00146 : 00147 """Build a blacklist for each sample accordind to a set of rules 00148 """ 00149 blacklists={} 00150 for sample in samples: 00151 blacklists[sample]="FED@1,AlcaBeamMonitor@1,Physics@1,Info@-1,HLT@1,AlCaReco@1" 00152 00153 # HLT 00154 if hlt: #HLT 00155 blacklists[sample]+=",AlCaEcalPi0@2" 00156 if not search("2010+|2011+",ver1): 00157 print "We are treating MC files for the HLT" 00158 for pattern,blist in definitions.hlt_mc_pattern_blist_pairs: 00159 blacklists[sample]=add_to_blacklist(blacklists[sample],pattern,sample,blist) 00160 # print 'HLT '+pattern 00161 # print 'HLT '+sample 00162 # print 'HLT '+blacklists[sample] 00163 else: 00164 print "We are treating Data files for the HLT" 00165 # at the moment it does not make sense since hlt is ran already 00166 00167 else: #RECO 00168 #Monte Carlo 00169 if not search("2010+|2011+",ver1): 00170 print "We are treating MC files" 00171 00172 for pattern,blist in definitions.mc_pattern_blist_pairs: 00173 blacklists[sample]=add_to_blacklist(blacklists[sample],pattern,sample,blist) 00174 # print "MC RECO" 00175 #print blacklists[sample] 00176 00177 # Data 00178 else: 00179 print "We are treating Data files:" 00180 blacklists[sample]+=",By__Lumi__Section@-1,AlCaReco@1" 00181 for pattern,blist in definitions.data_pattern_blist_pairs: 00182 blacklists[sample]=add_to_blacklist(blacklists[sample],pattern,ver1,blist) 00183 # print "DATA RECO: %s %s %s -->%s" %( ver1, pattern, blist, blacklists[sample]) 00184 00185 00186 return blacklists 00187 00188 #-------------------------------------------------------------------------------
def ValidationMatrix::guess_params | ( | ref_filenames, | |
test_filenames | |||
) |
Definition at line 66 of file ValidationMatrix.py.
00067 : 00068 00069 if len(ref_filenames)*len(test_filenames)==0: 00070 print "Empty reference and test filenames lists!" 00071 return [],"","" 00072 00073 samples=[] 00074 ref_versions=[] 00075 test_versions=[] 00076 00077 for ref, test in zip(map(os.path.basename,ref_filenames),map(os.path.basename,test_filenames)): 00078 00079 ref_sample=name2sample(ref) 00080 ref_version=name2version(ref) 00081 test_sample=name2sample(test) 00082 test_version=name2version(test) 00083 00084 if ref_sample!=test_sample: 00085 print "Files %s and %s do not seem to be relative to the same sample." %(ref, test) 00086 exit(2) 00087 00088 # Slightly modify for data 00089 if search("20[01]",ref_version)!=None: 00090 ref_sample+=ref_version.split("_")[-1] 00091 samples.append(ref_sample) 00092 00093 # append the versions 00094 ref_versions.append(ref_version) 00095 test_versions.append(test_version) 00096 00097 # Check if ref and test versions are always the same. 00098 ref_versions=list(set(ref_versions)) 00099 test_versions=list(set(test_versions)) 00100 00101 #for versions in ref_versions,test_versions: 00102 #if len(versions)!=1: 00103 #print "More than one kind of CMSSW version selected (%s)" %versions 00104 #exit(2) 00105 00106 cmssw_version1=ref_versions[0] 00107 cmssw_version2=test_versions[0] 00108 00109 return samples,cmssw_version1,cmssw_version2 00110 00111 00112 #-------------------------------------------------------------------------------
def ValidationMatrix::name2run | ( | filename | ) |
Definition at line 52 of file ValidationMatrix.py.
def ValidationMatrix::name2runskim | ( | filename | ) |
Definition at line 56 of file ValidationMatrix.py.
def ValidationMatrix::name2sample | ( | filename | ) |
Definition at line 44 of file ValidationMatrix.py.
def ValidationMatrix::name2version | ( | filename | ) |
Definition at line 48 of file ValidationMatrix.py.
string ValidationMatrix::action = "store" |
string ValidationMatrix::all_samples = "" |
Definition at line 444 of file ValidationMatrix.py.
ValidationMatrix::argv = sys.argv |
Definition at line 26 of file ValidationMatrix.py.
Definition at line 461 of file ValidationMatrix.py.
string ValidationMatrix::dest = "ref_samples" |
Definition at line 460 of file ValidationMatrix.py.
string ValidationMatrix::help = "The samples that act as reference (comma separated list)" |
Definition at line 462 of file ValidationMatrix.py.
ValidationMatrix::hlt = False |
Definition at line 452 of file ValidationMatrix.py.
string ValidationMatrix::in_dir = "" |
Definition at line 447 of file ValidationMatrix.py.
int ValidationMatrix::n_processes = 1 |
Definition at line 445 of file ValidationMatrix.py.
int ValidationMatrix::n_threads = 1 |
Definition at line 448 of file ValidationMatrix.py.
string ValidationMatrix::out_dir = "" |
Definition at line 446 of file ValidationMatrix.py.
Referenced by HtrXmlPattern::HtrXmlPattern().
tuple ValidationMatrix::parser = OptionParser(usage="usage: %prog [options]") |
Definition at line 456 of file ValidationMatrix.py.
string ValidationMatrix::ref_samples = "" |
Definition at line 442 of file ValidationMatrix.py.
int ValidationMatrix::run = 1 |
Definition at line 449 of file ValidationMatrix.py.
string ValidationMatrix::stat_test = "Chi2" |
Definition at line 450 of file ValidationMatrix.py.
string ValidationMatrix::test_samples = "" |
Definition at line 443 of file ValidationMatrix.py.
float ValidationMatrix::test_threshold = 0.00001 |
Definition at line 451 of file ValidationMatrix.py.