CMS 3D CMS Logo

Functions | Variables

ValidationMatrix Namespace Reference

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"
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

Function Documentation

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 len(blacklists[sample]) >0:
00294     command+= '-B %s ' %blacklists[sample]
00295   print "\nExecuting --  %s" %command
00296 
00297   process=Popen(filter(lambda x: len(x)>0,command.split(" ")))
00298   process.name=sample
00299 
00300 #--------------------------------------------------------------------------------

def ValidationMatrix::check_root_files (   names_list)

Definition at line 113 of file ValidationMatrix.py.

00114                                 :
00115   for name in names_list:
00116     if not name.endswith(".root"):
00117       print "File %s does not seem to be a rootfile. Please check."
00118       return False
00119   return True
00120 
00121 #-------------------------------------------------------------------------------

def ValidationMatrix::count_alive_processes (   p_list)

Definition at line 267 of file ValidationMatrix.py.

00268                                  :
00269   return len(filter(lambda p: p.returncode==None,p_list))
00270 
00271 #-------------------------------------------------------------------------------

def ValidationMatrix::do_comparisons_threaded (   options)

Definition at line 301 of file ValidationMatrix.py.

00302                                     :
00303 
00304   n_processes= int(options.n_processes)
00305 
00306   ref_filenames=[]
00307   test_filenames=[]
00308   
00309   if len(options.all_samples)>0:
00310     ref_filenames,test_filenames=get_filenames_from_pool(options.all_samples)  
00311   else:
00312     ref_filenames,test_filenames=get_clean_fileanames(options.ref_samples,options.test_samples)
00313  
00314   # make the paths absolute
00315   ref_filenames=map(os.path.abspath,ref_filenames)
00316   test_filenames=map(os.path.abspath,test_filenames)
00317   
00318   samples,cmssw_version1,cmssw_version2=guess_params(ref_filenames,test_filenames)
00319   
00320   if len(samples)==0:
00321     print "No Samples found... Quitting"
00322     return 0
00323   
00324 #  blacklists=guess_blacklists(samples,cmssw_version1,cmssw_version2,options.hlt)
00325 
00326   # Launch the single comparisons
00327   original_dir=os.getcwd()
00328 
00329   outdir=options.out_dir
00330   if len(outdir)==0:
00331     print "Creating automatic outdir:",
00332     outdir="%sVS%s" %(cmssw_version1,cmssw_version2)
00333     print outdir
00334   if len(options.input_dir)==0:
00335     print "Creating automatic indir:",
00336     options.input_dir=outdir
00337     print options.input_dir
00338   
00339   if not os.path.exists(outdir):
00340     os.mkdir(outdir)
00341   os.chdir(outdir)  
00342   
00343   # adjust the number of threads
00344   n_comparisons=len(ref_filenames)
00345   if n_comparisons < n_processes:
00346     print "Less comparisons than possible processes: reducing n processes to",
00347     n_processes=n_comparisons
00348   #elif n_processes/n_comparisons == 0:
00349     #print "More comparisons than possible processes, can be done in N rounds: reducing n processes to",    
00350     #original_nprocesses=n_processes
00351     #first=True
00352     #n_bunches=0
00353     #while first or n_processes > original_nprocesses:
00354       #n_processes=n_comparisons/2
00355       #if n_comparisons%2 !=0:
00356         #n_processes+=1
00357       #first=False
00358       
00359     #print n_processes
00360   print n_processes
00361   
00362   # Test if we treat data
00363   skim_name=""
00364   if search("20[01]",cmssw_version1)!=None:
00365     skim_name=cmssw_version1.split("_")[-1]
00366     
00367   running_subprocesses=[]
00368   process_counter=0
00369   print ref_filenames
00370 
00371   ## Compare all pairs of root files
00372   pool = Pool(n_processes)
00373   args_iterable = [list(args) + [options] for args in zip(samples, ref_filenames, test_filenames)]
00374   pool.map(call_compare_using_files, args_iterable)
00375 
00376   # move the pickles on the top, hack
00377   os.system("mv */*pkl .")
00378   
00379   os.chdir("..")
#-------------------------------------------------------------------------------
def ValidationMatrix::do_html (   options)

Definition at line 408 of file ValidationMatrix.py.

00409                     :
00410 
00411   if options.reports:
00412     print "Preparing reports for the single files..."
00413     do_reports(options.input_dir)
00414   # Do the summary page
00415   aggregation_rules={}
00416   aggregation_rules_twiki={}
00417   # check which aggregation rules are to be used
00418   if options.hlt:
00419     print "Aggregating directories according to HLT rules"
00420     aggregation_rules=definitions.aggr_pairs_dict['HLT']
00421     aggregation_rules_twiki=definitions.aggr_pairs_twiki_dict['HLT']
00422   else:
00423     aggregation_rules=definitions.aggr_pairs_dict['reco']
00424     aggregation_rules_twiki=definitions.aggr_pairs_twiki_dict['reco']
00425   table_html = make_summary_table(options.input_dir,aggregation_rules,aggregation_rules_twiki)
00426 
00427   # create summary html file
00428   ofile = open("RelMonSummary.html","w")
00429   ofile.write(table_html)
00430   ofile.close()
00431 
00432 #-------------------------------------------------------------------------------

def ValidationMatrix::do_reports (   indir)

Definition at line 380 of file ValidationMatrix.py.

00381                      :
00382   print indir
00383   os.chdir(indir)
00384   pkl_list=filter(lambda x:".pkl" in x, os.listdir("./"))
00385   running_subprocesses=[]
00386   n_processes=int(options.n_processes)
00387   process_counter=0
00388   for pklfilename in pkl_list:
00389     command = "compare_using_files.py " 
00390     command+= "-R "
00391     if options.do_pngs:
00392       command+= " -p "
00393     command+= "-P %s " %pklfilename
00394     command+= "-o %s " %pklfilename[:-4]
00395     print "Executing %s" %command
00396     process=Popen(filter(lambda x: len(x)>0,command.split(" ")))
00397     process_counter+=1
00398     # add it to the list
00399     running_subprocesses.append(process)   
00400     if process_counter>=n_processes:
00401       process_counter=0
00402       for p in running_subprocesses:
00403         #print "Waiting for %s" %p.name
00404         p.wait()
00405         
00406   os.chdir("..")
00407   
#-------------------------------------------------------------------------------
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.

00053                       :
00054   namebase=os.path.basename(filename)
00055   return namebase.split("__")[0].split("_")[2]  

def ValidationMatrix::name2runskim (   filename)

Definition at line 56 of file ValidationMatrix.py.

00057                           :
00058   run=name2run(filename)
00059   skim=name2version(filename).split("_")[-1]
00060   # remove skim version
00061   if "-v" in skim:
00062     skim = skim[:skim.rfind('-v')]
00063   return "%s_%s"%(run,skim)
00064 
00065 #-------------------------------------------------------------------------------  

def ValidationMatrix::name2sample (   filename)

Definition at line 44 of file ValidationMatrix.py.

00045                          :
00046   namebase=os.path.basename(filename)
00047   return namebase.split("__")[1]

def ValidationMatrix::name2version (   filename)

Definition at line 48 of file ValidationMatrix.py.

00049                           :
00050   namebase=os.path.basename(filename)
00051   return namebase.split("__")[2]
  

Variable Documentation

string ValidationMatrix::action = "store"

Definition at line 453 of file ValidationMatrix.py.

Definition at line 438 of file ValidationMatrix.py.

Definition at line 26 of file ValidationMatrix.py.

Definition at line 455 of file ValidationMatrix.py.

string ValidationMatrix::dest = "ref_samples"

Definition at line 454 of file ValidationMatrix.py.

string ValidationMatrix::help = "The samples that act as reference (comma separated list)"

Definition at line 456 of file ValidationMatrix.py.

Definition at line 446 of file ValidationMatrix.py.

Definition at line 441 of file ValidationMatrix.py.

Definition at line 439 of file ValidationMatrix.py.

Definition at line 442 of file ValidationMatrix.py.

Definition at line 440 of file ValidationMatrix.py.

Referenced by HtrXmlPattern::HtrXmlPattern().

tuple ValidationMatrix::parser = OptionParser(usage="usage: %prog [options]")

Definition at line 450 of file ValidationMatrix.py.

Definition at line 436 of file ValidationMatrix.py.

Definition at line 443 of file ValidationMatrix.py.

string ValidationMatrix::stat_test = "Chi2"

Definition at line 444 of file ValidationMatrix.py.

Definition at line 437 of file ValidationMatrix.py.

Definition at line 445 of file ValidationMatrix.py.