Classes | |
class | BinToBin |
class | BinToBin1percent |
class | Chi2 |
class | KS |
class | StatisticalTest |
class | unpickler |
Functions | |
def | ask_ok |
def | get_relval_cmssw_version |
def | get_relval_id |
def | get_relval_max_version |
def | get_relval_version |
------------------- Make files pairs: RelVal utils --------------------- | |
def | get_relvaldata_cmssw_version |
def | get_relvaldata_id |
----------------- Make files pairs: RelValData utils -------------------- | |
def | get_relvaldata_max_version |
def | get_relvaldata_version |
def | getNbins |
def | is_empty |
def | is_relvaldata |
------------------------- Make files pairs -------------------------- | |
def | is_sparse |
def | literal2root |
def | logger |
def | make_files_pairs |
def | profile2histo |
def | setTDRStyle |
def | wget |
Variables | |
int | _log_level = 10 |
theargv = sys.argv |
def utils::ask_ok | ( | prompt, | |
retries = 4 , |
|||
complaint = 'yes or no' |
|||
) |
Definition at line 405 of file utils.py.
00406 : 00407 while True: 00408 ok = raw_input(prompt) 00409 if ok in ('y', 'ye', 'yes'): 00410 return True 00411 if ok in ('n', 'no'): 00412 return False 00413 retries = retries - 1 00414 if retries < 0: 00415 raise IOError('refusenik user') 00416 print complaint 00417 00418 #-------------------------------------------------------------------------------
def utils::get_relval_cmssw_version | ( | file | ) |
def utils::get_relval_id | ( | file | ) |
Returns unique relval ID (dataset name) for a given file.
Definition at line 524 of file utils.py.
00525 : 00526 """Returns unique relval ID (dataset name) for a given file.""" 00527 dataset_name = re.findall('R\d{9}__([\w\d]*)__CMSSW_', file) 00528 run = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-[\w\d]*_V\d*\w?(?:_([\w\d]*))?-v\d*__', file) 00529 if run[0]: 00530 return (dataset_name[0], run[0]) 00531 else: 00532 return (dataset_name[0], '_V\d*\w?-v\d*__')
def utils::get_relval_max_version | ( | files | ) |
Returns file with maximum version at a) beggining of the file, e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max.
Definition at line 506 of file utils.py.
00507 : 00508 """Returns file with maximum version at a) beggining of the file, 00509 e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max.""" 00510 max_file = files[0] 00511 max_v = get_relval_version(files[0]) 00512 for file in files: 00513 file_v = get_relval_version(file) 00514 if file_v[1] > max_v[1] or ((file_v[1] == max_v[1]) and (file_v[0] > max_v[0])): 00515 max_file = file 00516 max_v = file_v 00517 return max_file
def utils::get_relval_version | ( | file | ) |
------------------- Make files pairs: RelVal utils ---------------------
Returns tuple (CMSSW version, run version) for specified file.
Definition at line 499 of file utils.py.
00500 : 00501 """Returns tuple (CMSSW version, run version) for specified file.""" 00502 cmssw_version = re.findall('DQM_V(\d*)_', file) 00503 run_version = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-[\w\d]*_V\d*\w?(?:_[\w\d]*)?-v(\d*)__', file) 00504 if cmssw_version and run_version: 00505 return (int(cmssw_version[0]), int(run_version[0]))
def utils::get_relvaldata_cmssw_version | ( | file | ) |
Returns tuple (CMSSW release, GR_R version) for specified RelValData file.
Definition at line 468 of file utils.py.
00469 : 00470 """Returns tuple (CMSSW release, GR_R version) for specified RelValData file.""" 00471 cmssw_release = re.findall('(CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?)-', file) 00472 gr_r_version = re.findall('-(GR_R_\d*_V\d*\w?)(?:_RelVal)?_', file) 00473 if not gr_r_version: 00474 gr_r_version = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-(\w*)_RelVal_', file) 00475 if cmssw_release and gr_r_version: 00476 return (cmssw_release[0], gr_r_version[0])
def utils::get_relvaldata_id | ( | file | ) |
----------------- Make files pairs: RelValData utils --------------------
Returns unique relvaldata ID for a given file.
Definition at line 458 of file utils.py.
00459 : 00460 """Returns unique relvaldata ID for a given file.""" 00461 run_id = re.search('R\d{9}', file) 00462 run = re.search('_RelVal_([\w\d]*)-v\d__', file) 00463 if not run: 00464 run = re.search('GR_R_\d*_V\d*C?_([\w\d]*)-v\d__', file) 00465 if run_id and run: 00466 return (run_id.group(), run.group(1)) 00467 return None
def utils::get_relvaldata_max_version | ( | files | ) |
Returns file with maximum version at a) beggining of the file, e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max.
Definition at line 486 of file utils.py.
00487 : 00488 """Returns file with maximum version at a) beggining of the file, 00489 e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max.""" 00490 max_file = files[0] 00491 max_v = get_relvaldata_version(files[0]) 00492 for file in files: 00493 file_v = get_relvaldata_version(file) 00494 if file_v[1] > max_v[1] or ((file_v[1] == max_v[1]) and (file_v[0] > max_v[0])): 00495 max_file = file 00496 max_v = file_v 00497 return max_file
def utils::get_relvaldata_version | ( | file | ) |
Returns tuple (CMSSW version, run version) for specified file.
Definition at line 477 of file utils.py.
00478 : 00479 """Returns tuple (CMSSW version, run version) for specified file.""" 00480 cmssw_version = re.findall('DQM_V(\d*)_', file) 00481 run_version = re.findall('_RelVal_[\w\d]*-v(\d)__', file) 00482 if not run_version: 00483 run_version = re.findall('GR_R_\d*_V\d*C?_[\w\d]*-v(\d)__', file) 00484 if cmssw_version and run_version: 00485 return (int(cmssw_version[0]), int(run_version[0]))
def utils::getNbins | ( | h | ) |
def utils::is_empty | ( | h | ) |
Definition at line 171 of file utils.py.
Referenced by DTSectColl::addTSTheta(), DEcompare< T >::get_ncand(), and DEcompare< T >::SortCollections().
def utils::is_relvaldata | ( | files | ) |
def utils::is_sparse | ( | h | ) |
Definition at line 179 of file utils.py.
00180 : 00181 filled_bins=0. 00182 nbins=h.GetNbinsX() 00183 for ibin in xrange(nbins): 00184 if h.GetBinContent(ibin)>0: 00185 filled_bins+=1 00186 #print "%s %s --> %s" %(filled_bins,nbins,filled_bins/nbins) 00187 if filled_bins/nbins < .5: 00188 return True 00189 else: 00190 return False 00191 00192 #-------------------------------------------------------------------------------
def utils::literal2root | ( | literal, | |
rootType | |||
) |
Definition at line 69 of file utils.py.
00070 : 00071 bitsarray = array.array('B') 00072 bitsarray.fromstring(literal.decode('hex')) 00073 00074 tbuffer=0 00075 try: 00076 tbuffer = TBufferFile(TBufferFile.kRead, len(bitsarray), bitsarray, False,0) 00077 except: 00078 print "could not transform to object array:" 00079 print [ i for i in bitsarray ] 00080 00081 # replace a couple of shortcuts with the real root class name 00082 if rootType == 'TPROF': 00083 rootType = 'TProfile' 00084 if rootType == 'TPROF2D': 00085 rootType = 'TProfile2D' 00086 00087 root_class=eval(rootType+'.Class()') 00088 00089 return tbuffer.ReadObject(root_class) 00090 00091 #-------------------------------------------------------------------------------
def utils::logger | ( | msg_level, | |
message | |||
) |
def utils::make_files_pairs | ( | files, | |
verbose = True |
|||
) |
Definition at line 538 of file utils.py.
00539 : 00540 ## Select functions to use 00541 if is_relvaldata(files): 00542 get_cmssw_version = get_relvaldata_cmssw_version 00543 get_id = get_relvaldata_id 00544 get_max_version = get_relvaldata_max_version 00545 # print 'Pairing Data RelVal files.' 00546 else: 00547 get_cmssw_version = get_relval_cmssw_version 00548 get_id = get_relval_id 00549 get_max_version = get_relval_max_version 00550 # print 'Pairing Monte Carlo RelVal files.' 00551 00552 ## Divide files into groups 00553 versions_files = dict() 00554 for file in files: 00555 version = get_cmssw_version(file) 00556 if versions_files.has_key(version): 00557 versions_files[version].append(file) 00558 else: 00559 versions_files[version] = [file] 00560 00561 ## Print the division into groups 00562 if verbose: 00563 print '\nFound versions:' 00564 for version in versions_files: 00565 print '%s: %d files' % (str(version), len(versions_files[version])) 00566 00567 ## Select two biggest groups. 00568 versions = versions_files.keys() 00569 sizes = [len(value) for value in versions_files.values()] 00570 v1 = versions[sizes.index(max(sizes))] 00571 versions.remove(v1) 00572 sizes.remove(max(sizes)) 00573 v2 = versions[sizes.index(max(sizes))] 00574 00575 ## Print two biggest groups. 00576 if verbose: 00577 print '\nPairing %s (%d files) and %s (%d files)' % (str(v1), 00578 len(versions_files[v1]), str(v2), len(versions_files[v2])) 00579 00580 ## Pairing two versions 00581 pairs = [] 00582 for unique_id in set([get_id(file) for file in versions_files[v1]]): 00583 dataset_re = re.compile(unique_id[0]+'_') 00584 run = re.compile(unique_id[1]) 00585 c1_files = [file for file in versions_files[v1] if dataset_re.search(file) and run.search(file)] 00586 c2_files = [file for file in versions_files[v2] if dataset_re.search(file) and run.search(file)] 00587 if len(c1_files) > 0 and len(c2_files) > 0: 00588 first_file = get_max_version(c1_files) 00589 second_file = get_max_version(c2_files) 00590 pairs.extend((first_file, second_file)) 00591 if verbose: 00592 print "\nPaired and got %d files.\n" % len(pairs) 00593 return pairs
def utils::profile2histo | ( | profile | ) |
Definition at line 220 of file utils.py.
00221 : 00222 if not profile.InheritsFrom("TH1"): 00223 return profile 00224 00225 bin_low_edges=[] 00226 n_bins=profile.GetNbinsX() 00227 00228 for ibin in xrange(1,n_bins+2): 00229 bin_low_edges.append(profile.GetBinLowEdge(ibin)) 00230 bin_low_edges=array.array('f',bin_low_edges) 00231 histo=TH1F(profile.GetName(),profile.GetTitle(),n_bins,bin_low_edges) 00232 for ibin in xrange(0,n_bins+1): 00233 histo.SetBinContent(ibin,profile.GetBinContent(ibin)) 00234 histo.SetBinError(ibin,profile.GetBinError(ibin)) 00235 00236 return histo 00237 #-------------------------------------------------------------------------------
def utils::setTDRStyle | ( | ) |
Definition at line 52 of file utils.py.
References plotscripts::tdrStyle.
Referenced by FlavourHistograms< T >::plot().
00052 : 00053 this_dir=dirname(this_module_name) 00054 this_dir_one_up=this_dir[:this_dir.rfind("/")+1] 00055 #this_dir_two_up=this_dir_one_up[:this_dir_one_up.rfind("/")+1] 00056 style_file='' 00057 if os.environ.has_key("RELMON_SA"): 00058 style_file=this_dir_one_up+"data/tdrstyle_mod.C" 00059 else: 00060 style_file="%s/src/Utilities/RelMon/data/tdrstyle_mod.C"%(os.environ["CMSSW_BASE"]) 00061 try: 00062 gROOT.ProcessLine(".L %s" %style_file) 00063 gROOT.ProcessLine("setTDRStyle()") 00064 except: 00065 "Print could not set the TDR style. File %s not found?" %style_file 00066 00067 00068 #-------------------------------------------------------------------------------
def utils::wget | ( | url | ) |
Fetch the WHOLE file, not in bunches... To be optimised.
Definition at line 433 of file utils.py.
00434 : 00435 """ Fetch the WHOLE file, not in bunches... To be optimised. 00436 """ 00437 opener=build_opener(X509CertOpen()) 00438 datareq = Request(url) 00439 datareq.add_header('authenticated_wget', "The ultimate wgetter") 00440 bin_content=None 00441 try: 00442 filename=basename(url) 00443 print "Checking existence of file %s on disk..."%filename 00444 if not isfile("./%s"%filename): 00445 bin_content=opener.open(datareq).read() 00446 else: 00447 print "File %s exists, skipping.." %filename 00448 except ValueError: 00449 print "Error: Unknown url %s" %url 00450 00451 if bin_content!=None: 00452 ofile = open(filename, 'wb') 00453 ofile.write(bin_content) 00454 ofile.close() 00455 #-------------------------------------------------------------------------------
int utils::_log_level = 10 |
utils::theargv = sys.argv |