![]() |
![]() |
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 423 of file utils.py.
00424 : 00425 while True: 00426 ok = raw_input(prompt) 00427 if ok in ('y', 'ye', 'yes'): 00428 return True 00429 if ok in ('n', 'no'): 00430 return False 00431 retries = retries - 1 00432 if retries < 0: 00433 raise IOError('refusenik user') 00434 print complaint 00435 00436 #-------------------------------------------------------------------------------
def utils::get_relval_cmssw_version | ( | file | ) |
def utils::get_relval_id | ( | file | ) |
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 524 of file utils.py.
00525 : 00526 """Returns file with maximum version at a) beggining of the file, 00527 e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max.""" 00528 max_file = files[0] 00529 max_v = get_relval_version(files[0]) 00530 for file in files: 00531 file_v = get_relval_version(file) 00532 if file_v[1] > max_v[1] or ((file_v[1] == max_v[1]) and (file_v[0] > max_v[0])): 00533 max_file = file 00534 max_v = file_v 00535 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 517 of file utils.py.
00518 : 00519 """Returns tuple (CMSSW version, run version) for specified file.""" 00520 cmssw_version = re.findall('DQM_V(\d*)_', file) 00521 run_version = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-[\w\d]*_V\d*\w?(?:_[\w\d]*)?-v(\d*)__', file) 00522 if cmssw_version and run_version: 00523 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 486 of file utils.py.
00487 : 00488 """Returns tuple (CMSSW release, GR_R version) for specified RelValData file.""" 00489 cmssw_release = re.findall('(CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?)-', file) 00490 gr_r_version = re.findall('-(GR_R_\d*_V\d*\w?)(?:_RelVal)?_', file) 00491 if not gr_r_version: 00492 gr_r_version = re.findall('CMSSW_\d*_\d*_\d*(?:_[\w\d]*)?-(\w*)_RelVal_', file) 00493 if cmssw_release and gr_r_version: 00494 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 476 of file utils.py.
00477 : 00478 """Returns unique relvaldata ID for a given file.""" 00479 run_id = re.search('R\d{9}', file) 00480 run = re.search('_RelVal_([\w\d]*)-v\d__', file) 00481 if not run: 00482 run = re.search('GR_R_\d*_V\d*C?_([\w\d]*)-v\d__', file) 00483 if run_id and run: 00484 return (run_id.group(), run.group(1)) 00485 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 504 of file utils.py.
00505 : 00506 """Returns file with maximum version at a) beggining of the file, 00507 e.g. DQM_V000M b) at the end of run, e.g. _run2012-vM. M has to be max.""" 00508 max_file = files[0] 00509 max_v = get_relvaldata_version(files[0]) 00510 for file in files: 00511 file_v = get_relvaldata_version(file) 00512 if file_v[1] > max_v[1] or ((file_v[1] == max_v[1]) and (file_v[0] > max_v[0])): 00513 max_file = file 00514 max_v = file_v 00515 return max_file
def utils::get_relvaldata_version | ( | file | ) |
Returns tuple (CMSSW version, run version) for specified file.
Definition at line 495 of file utils.py.
00496 : 00497 """Returns tuple (CMSSW version, run version) for specified file.""" 00498 cmssw_version = re.findall('DQM_V(\d*)_', file) 00499 run_version = re.findall('_RelVal_[\w\d]*-v(\d)__', file) 00500 if not run_version: 00501 run_version = re.findall('GR_R_\d*_V\d*C?_[\w\d]*-v(\d)__', file) 00502 if cmssw_version and run_version: 00503 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 552 of file utils.py.
00553 : 00554 ## Select functions to use 00555 if is_relvaldata(files): 00556 is_relval_data = True 00557 get_cmssw_version = get_relvaldata_cmssw_version 00558 get_id = get_relvaldata_id 00559 get_max_version = get_relvaldata_max_version 00560 # print 'Pairing Data RelVal files.' 00561 else: 00562 is_relval_data = False 00563 get_cmssw_version = get_relval_cmssw_version 00564 get_id = get_relval_id 00565 get_max_version = get_relval_max_version 00566 # print 'Pairing Monte Carlo RelVal files.' 00567 00568 ## Divide files into groups 00569 versions_files = dict() 00570 for file in files: 00571 version = get_cmssw_version(file) 00572 if versions_files.has_key(version): 00573 versions_files[version].append(file) 00574 else: 00575 versions_files[version] = [file] 00576 00577 ## Print the division into groups 00578 if verbose: 00579 print '\nFound versions:' 00580 for version in versions_files: 00581 print '%s: %d files' % (str(version), len(versions_files[version])) 00582 00583 if len(versions_files.keys()) <= 1: 00584 print '\nFound too little versions, there is nothing to pair. Exiting...\n' 00585 exit() 00586 00587 ## Select two biggest groups. 00588 versions = versions_files.keys() 00589 sizes = [len(value) for value in versions_files.values()] 00590 v1 = versions[sizes.index(max(sizes))] 00591 versions.remove(v1) 00592 sizes.remove(max(sizes)) 00593 v2 = versions[sizes.index(max(sizes))] 00594 00595 ## Print two biggest groups. 00596 if verbose: 00597 print '\nPairing %s (%d files) and %s (%d files)' % (str(v1), 00598 len(versions_files[v1]), str(v2), len(versions_files[v2])) 00599 00600 ## Pairing two versions 00601 print '\nGot pairs:' 00602 pairs = [] 00603 for unique_id in set([get_id(file) for file in versions_files[v1]]): 00604 if is_relval_data: 00605 dataset_re = re.compile(unique_id[0]+'_') 00606 run_re = re.compile(unique_id[1]) 00607 c1_files = [file for file in versions_files[v1] if dataset_re.search(file) and run_re.search(file)] 00608 c2_files = [file for file in versions_files[v2] if dataset_re.search(file) and run_re.search(file)] 00609 else: 00610 dataset_re = re.compile(unique_id+'_') 00611 c1_files = [file for file in versions_files[v1] if dataset_re.search(file)] 00612 c2_files = [file for file in versions_files[v2] if dataset_re.search(file)] 00613 00614 if len(c1_files) > 0 and len(c2_files) > 0: 00615 first_file = get_max_version(c1_files) 00616 second_file = get_max_version(c2_files) 00617 print '%s\n%s\n' % (first_file, second_file) 00618 pairs.extend((first_file, second_file)) 00619 if verbose: 00620 print "Paired and got %d files.\n" % len(pairs) 00621 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 451 of file utils.py.
00452 : 00453 """ Fetch the WHOLE file, not in bunches... To be optimised. 00454 """ 00455 opener=build_opener(X509CertOpen()) 00456 datareq = Request(url) 00457 datareq.add_header('authenticated_wget', "The ultimate wgetter") 00458 bin_content=None 00459 try: 00460 filename=basename(url) 00461 print "Checking existence of file %s on disk..."%filename 00462 if not isfile("./%s"%filename): 00463 bin_content=opener.open(datareq).read() 00464 else: 00465 print "File %s exists, skipping.." %filename 00466 except ValueError: 00467 print "Error: Unknown url %s" %url 00468 00469 if bin_content!=None: 00470 ofile = open(filename, 'wb') 00471 ofile.write(bin_content) 00472 ofile.close() 00473 #-------------------------------------------------------------------------------
int utils::_log_level = 10 |
utils::theargv = sys.argv |