示例#1
0
文件: hist.py 项目: fscutti/SSDiLep
def __gen_hist__(plot_details,verbose=False):
    '''
    generate single histogram
    only runs on samples with an input file defined, 
    ie. does not loop through daughters
    not really designed to be called by analysers
    '''
    log.debug( 'in get_hist for %s' % plot_details.sample.name )

    ## add the details from the sample
    #plot_details += plot_details.sample.plot_details

    s = plot_details.sample
    vd = plot_details.var_details
    sel = plot_details.get_selector()
    weights = plot_details.get_weights()
    target_lumi = plot_details.target_lumi

    if not s.is_active(): 
        log.warn('failed to gen hist %s for sample: %s' % (vd.name,s.name) )
        return None
    
    ## create hist 
    h = plot_details.new_hist(s)
    h.samples = s
                
    ## initialise sample
    s.initialise()

    ## return empty hist if no events
    if not s.tree.GetEntries(): return h
    
    s.switch_on_branches()
    
    ## selection
    event_list = sel.select(s) if sel else None
   

    ## initialise variables 
    s.prepare( plot_details )
    
    ## process events
    entries = event_list.GetN() if sel else s.tree.GetEntries()
    for i in xrange(entries):
        ientry = event_list.GetEntry(i) if sel else i
        s.tree.GetEntry(ientry)
        
        ## calculate event weight
        weight = weights.weight() if weights else 1. 

        ## fill hists
        val = vd.var.calc_vals()[0]
        
        h.Fill(val,weight)
        frac = float(i)/float(entries) if entries else 0.0
        if verbose: utils.print_progress(frac,title = '%s: '%s.name)
    if verbose: utils.clear_progress()
    #s.style_hist(h)
    if target_lumi: s.scale_hist(h,target_lumi)
    return h
示例#2
0
def __gen_hist__(plot_details, verbose=False):
    '''
    generate single histogram
    only runs on samples with an input file defined, 
    ie. does not loop through daughters
    not really designed to be called by analysers
    '''
    log.debug('in get_hist for %s' % plot_details.sample.name)

    ## add the details from the sample
    #plot_details += plot_details.sample.plot_details

    s = plot_details.sample
    vd = plot_details.var_details
    sel = plot_details.get_selector()
    weights = plot_details.get_weights()
    target_lumi = plot_details.target_lumi

    if not s.is_active():
        log.warn('failed to gen hist %s for sample: %s' % (vd.name, s.name))
        return None

    ## create hist
    h = plot_details.new_hist(s)
    h.samples = s

    ## initialise sample
    s.initialise()

    ## return empty hist if no events
    if not s.tree.GetEntries(): return h

    s.switch_on_branches()

    ## selection
    event_list = sel.select(s) if sel else None

    ## initialise variables
    s.prepare(plot_details)

    ## process events
    entries = event_list.GetN() if sel else s.tree.GetEntries()
    for i in xrange(entries):
        ientry = event_list.GetEntry(i) if sel else i
        s.tree.GetEntry(ientry)

        ## calculate event weight
        weight = weights.weight() if weights else 1.

        ## fill hists
        val = vd.var.calc_vals()[0]

        h.Fill(val, weight)
        frac = float(i) / float(entries) if entries else 0.0
        if verbose: utils.print_progress(frac, title='%s: ' % s.name)
    if verbose: utils.clear_progress()
    #s.style_hist(h)
    if target_lumi: s.scale_hist(h, target_lumi)
    return h
for layer in manifest['fsLayers']:
	if expire <= time.time():
		request_auth_token()

	if layer['blobSum'] in dled:
		continue

	dled.add(layer['blobSum'])

	print('%s[*]%s Downloading layer %s%s%s...' % (Fore.GREEN, Fore.RESET, Fore.BLUE, layer['blobSum'], Fore.RESET))

	try:
		r = urllib.request.Request('https://registry.hub.docker.com/v2/%s/blobs/%s' % (fimage, layer['blobSum']))
		r.add_header('Authorization', 'Bearer ' + token)

		with urllib.request.urlopen(r) as u, open(fname, 'ab') as f:
			chunked_copy(fname, u, f)

	except urllib.error.HTTPError as err:
		clear_progress()
		print('%s[!]%s Failed to download layer %s%s%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, layer['blobSum'], Fore.RESET, err))
		sys.exit(-1)

	except OSError as err:
		clear_progress()
		print('%s[!]%s Failed to open file %s%s%s for writing: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, fname, Fore.RESET, err))
		sys.exit(-1)

print('%s[*]%s Rootfs archive for %s%s%s:%s%s%s saved to %s%s%s.' % (Fore.GREEN, Fore.RESET, Fore.YELLOW, image, Fore.RESET, Fore.YELLOW, tag, Fore.RESET, Fore.GREEN, fname, Fore.RESET))
示例#4
0
		# otherwise, fail miserably

		if not tgurl:
			print('%s[!]%s Failed to find a suitable rootfs specification in Dockerfile.' % (Fore.RED, Fore.RESET))
			sys.exit(-1)

except urllib.error.HTTPError as err:
	print('%s[!]%s Failed to fetch Dockerfile from %s%s%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, dfurl, Fore.RESET, err))
	sys.exit(-1)

# download rootfs archive

print('%s[*]%s Downloading archive %s%s%s...' % (Fore.GREEN, Fore.RESET, Fore.BLUE, tgurl, Fore.RESET))

try:
	with urllib.request.urlopen(tgurl) as u, open(fname, 'wb') as f:
		chunked_copy(fname, u, f)

except urllib.error.HTTPError as err:
	clear_progress()
	print('%s[!]%s Failed to download archive from %s%s%s: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, tgurl, Fore.RESET, err))
	sys.exit(-1)

except OSError as err:
	clear_progress()
	print('%s[!]%s Failed to open file %s%s%s for writing: %s' % (Fore.RED, Fore.RESET, Fore.BLUE, fname, Fore.RESET, err))
	sys.exit(-1)

print('%s[*]%s Rootfs archive for %s%s%s:%s%s%s saved to %s%s%s.' % (Fore.GREEN, Fore.RESET, Fore.YELLOW, image, Fore.RESET, Fore.YELLOW, tag, Fore.RESET, Fore.GREEN, fname, Fore.RESET))