def create_contacts_file(file_name): """Creates contacts file""" # get paths path = Workspace.mkdir(file_name) pdb_file = Workspace.construct_file_path(path, file_name) contacts_file = Workspace.construct_file_path(path, 'contacts') if Workspace.file_exists(contacts_file, file_path_FLAG=True): return True try: with open(pdb_file, 'r') as file: pipe = subprocess.Popen([PROGRAM_PATH, COMMAND_ATOMS, ANNOTATED], stdin=file, stdout=subprocess.PIPE) with open(contacts_file, 'w') as fh: pipe2 = subprocess.Popen([ PROGRAM_PATH, COMMAND_CONTACTS, ANNOTATED, COMMAND_CONTACTS_DRAW, COMMAND_CONTACTS_SIH_DEPTH, COMMAND_CONTACTS_SIH_DEPTH_VAL, COMMAND_CONTACTS_STEP, COMMAND_CONTACTS_STEP_VAL ], stdin=pipe.stdout, stdout=fh) pipe2.wait() except Exception as e: logging.error("Creating contacts: {}".format(e)) return False logging.debug("Contacts file in {} has been created".format(path)) # return (True, None)ALPHA return True
def summarize(file_name, query): path = Workspace.mkdir(file_name) contacts_file = Workspace.construct_file_path(path, 'contacts') query = query.split(' ') try: file = open(contacts_file) pipe = subprocess.Popen( [PROGRAM_PATH, COMMAND_QUERY_CONTACTS, '--summarize-by-first'] + query, stdin=file, stdout=subprocess.PIPE) #stdout=subprocess.PIPE) summary = defaultdict(int) for line in iter(pipe.stdout.readline, ''): line = line.decode().strip() if not line: break data = line.split(" ") m = re.search('c<(.*?)>', data[0]) summary[m.group(1)] += float(data[2]) except Exception as e: logging.error(e) return False return summary
def handle_send_file(self, request): """Server PUT. Handles file transfering from client""" file_name = request[0].lower() file_size = request[1] logging.debug("Client: {}:{} requested a SENDFILE for: {} {}".format( self.port, self.host, file_name, file_size)) # Send back OK as ACK resp = "OK" self.conn.sendall(resp.encode()) logging.debug("Server: Response send to {}:{} response: {}".format( self.host, self.port, resp)) # Receive file # create file path path = Workspace.mkdir(file_name) filePath = Workspace.construct_file_path(path, file_name) # send file in slices of self._bufferSize bytes: # open file in read byte mode: fh = open(filePath, "wb") # write bytes flag is passed bytes_remaining = int(file_size) while bytes_remaining != 0: if (bytes_remaining >= self._bufferSize): # receive slab from client slab = self.conn.recv(self._bufferSize) fh.write(slab) sizeof_slab_received = len(slab) logging.debug( "Server: From {}:{} Bytes received: {} File: {}".format( self.host, self.port, sizeof_slab_received, file_name)) bytes_remaining -= int(sizeof_slab_received) else: #receive slab from server slab = self.conn.recv(bytes_remaining) fh.write(slab) sizeof_slab_received = len(slab) logging.debug( "Server: From {}:{} Bytes received: {} File: {}".format( self.host, self.port, sizeof_slab_received, file_name)) bytes_remaining -= int(sizeof_slab_received) fh.close() resp = "OK" self.conn.sendall(resp.encode()) logging.debug("Response send to {}:{} response: {}".format( self.host, self.port, resp))
def add_detached(self, name, title, x=None, y=None): with self.lock: if self.ws.has_key(name): raise Exception("A workspace with name '%s' already exists!" % name) root = gtk.Window(gtk.WINDOW_TOPLEVEL) root.set_title(title) # TODO: this needs to be more sophisticated root.connect("delete_event", lambda w, e: w.hide()) root.set_border_width(2) # create main frame frame = gtk.VBox(spacing=2) root.add(frame) ws = Workspace.Workspace(frame, name, title) # Some attributes we force on our children ws.logger = self.logger ws.parent = self self.detached.append(root) root.show_all() if x: root.move(x, y) self.count += 1 self.ws[name] = Bunch.Bunch(ws=ws, frame=frame, loc=None) return ws
def offline_preparation(abst_refinement): # Initialize workspace workspace = Workspace(num_vertices,num_refined_lasers,'region_partition/obstacles.json') events, segments, event_queue = workspace.prepare_workspace() #print('Number of endpoints: ', len(events)) print('Number of segments: ', len(segments)) events, segments = sweep_intersections(events, segments, event_queue) print('Number of events, ', len(events)) #for event in events: # print(event) #for segment in segments: # print(segment) refined_reg_V_rep_dict, refined_reg_H_rep_dict, lidar_config_dict = None, None, None # When measure time of partitioning workspace, turn abstract refinement off if abst_refinement == 'ON': abst_reg_V_rep, abst_reg_H_rep, refined_reg_V_rep_dict, refined_reg_H_rep_dict, lidar_config_dict \ = abstract_refinement_partition(workspace, events, segments) else: abst_reg_V_rep, abst_reg_H_rep = partition_regions(events, segments) lidar_config_dict = workspace.find_lidar_configuration(abst_reg_V_rep) #Add obstacles to regions obstacles = workspace.obstacles for obs in obstacles: abst_reg_V_rep.append([(v[0],v[1]) for v in obs]) A,b = vertices_to_polyhedron(obs) abst_reg_H_rep.append({'A':A,'b':b}) num_abst_reg = len(abst_reg_V_rep) print('Number of abstract regions = ', num_abst_reg) if(out_file and len(out_file) > 0): f = open(out_file,'a+') f.write('\t %6d'%num_abst_reg) f.close() return abst_reg_V_rep, abst_reg_H_rep, refined_reg_V_rep_dict, refined_reg_H_rep_dict, lidar_config_dict
def draw(file_name, query, ID, params): path = Workspace.mkdir(file_name) contacts_file = Workspace.construct_file_path(path, 'contacts') draw_file = Workspace.construct_file_path(path, 'draw' + str(ID)) query = query.split(' ') filters = list(params['query'].keys()) drawing = list() [drawing.extend([str(k), str(v)]) for k, v in params['drawing'].items()] # try: file = open(contacts_file) pipe = subprocess.Popen([ PROGRAM_PATH, COMMAND_QUERY_CONTACTS, COMMAND_QUERY_CONTACTS_GRAPHICS, ] + query + filters, stdin=file, stdout=subprocess.PIPE) #stdout=subprocess.PIPE) devnull = open(os.devnull, 'w') pipe2 = subprocess.Popen([ PROGRAM_PATH, COMMAND_DRAW, '--drawing-name', 'vcontacts_' + str(ID), COMMAND_DRAW_PYMOL, draw_file, ] + drawing, stdout=devnull, stdin=pipe.stdout) pipe2.wait() return True
def handle_file_check(self, request): """Server FILE. Check if servas has file""" file_name = request[0].lower() file_checksum = request[1] logging.debug("Client: {}:{} requested a CHECKFILE: {} {}".format( self.host, self.port, file_name, file_checksum)) # check if file exist in server dir if Workspace.file_check_checksum(file_name, file_checksum): self.send("OK") logging.debug("Server: Response send to {}:{} response: OK".format( self.host, self.port)) else: self.send("NOTFOUND") logging.debug( "Server: Response send to {}:{} response: NOTFOUND".format( self.host, self.port))
def addws(self, loc, name, title): with self.lock: if self.ws.has_key(name): raise Exception("A workspace with name '%s' already exists!" % name) frame = self.get_wsframe(loc) ws = Workspace.Workspace(frame, name, title) # Some attributes we force on our children ws.logger = self.logger ws.parent = self frame.show_all() self.count += 1 self.ws[name] = Bunch.Bunch(ws=ws, frame=frame, loc=loc) return ws
def __init__(self, *args): """ Initialize main Application window """ #Calling __init__ of super class QtGui.QMainWindow.__init__(self, *args) #Creating Application configuration object self.obj_appconfig = Appconfig() self.setGeometry(self.obj_appconfig._app_xpos, self.obj_appconfig._app_ypos, self.obj_appconfig._app_width, self.obj_appconfig._app_heigth) self.setWindowTitle(self.obj_appconfig._APPLICATION) #Init Workspace self.obj_workspace = Workspace.Workspace() #Init necessary components in sequence self.initActions() self.initView()
tree.Add( "/afs/cern.ch/user/d/demattia/public/TagAndProbe/TagAndProbe_Run2012A.root" ) tree.Add( "/afs/cern.ch/user/d/demattia/public/TagAndProbe/TagAndProbe_Run2012B.root" ) tree.Add( "/afs/cern.ch/user/d/demattia/public/TagAndProbe/TagAndProbe_Run2012C.root" ) tree.Add( "/afs/cern.ch/user/d/demattia/public/TagAndProbe/TagAndProbe_Run2012D.root" ) # Prepare the workspace ws = RooWorkspace("ws", "workspace") Workspace.buildPdf(ws, p) mass = ws.var("mass") sample = ws.cat("sample") simPdf = ws.pdf("simPdf") efficiency = ws.var("efficiency") meanB = ws.var("meanB") # prepare_datasets(ws, p) # Prepare datasets datasetAllMap = {} datasetPassMap = {} hAllMap = {} hPassMap = {} for ptBin1 in range(0, len(ptBinsX)):
total_refined_regions = 0 for i, refined_reg_H_rep_in_this_abst in refined_reg_H_rep_dict.items(): num_refined_reg = len(refined_reg_H_rep_in_this_abst) total_refined_regions += num_refined_reg print 'abstract regtion', i, '--> ', num_refined_reg, 'refined regions' print 'Total refined regions = ', total_refined_regions """ filename = './results/region10-15/abst_reg_H_rep.txt' with open(filename, 'rb') as inputFile: abs_reg_H_rep = pickle.load(inputFile) #print abs_reg_H_rep workspace = Workspace() #print workspace.abst_reg_obstacles abs_reg_H_rep_with_obstacles = abs_reg_H_rep + workspace.abst_reg_obstacles print '\n' print len(abs_reg_H_rep_with_obstacles) outputFileName = 'results/abst_reg_H_rep_with_obstacles.txt' with open(outputFileName, 'wb') as outputFile: pickle.dump(abs_reg_H_rep_with_obstacles, outputFile) outputFile.close() """ filename = './results/regions10-13/abst_reg_V_rep.txt' with open(filename, 'rb') as inputFile: abst_reg_V_rep = pickle.load(inputFile) for abst_reg in abst_reg_V_rep:
# Trigger efficiency for new trigger over old trigger oldTrigger = "HLT_L2DoubleMu23_NoVertex_v" newTrigger = "HLT_L2DoubleMu23_NoVertex_2Cha_Angle2p5_v" # Load the input file tree = ROOT.TChain("T") #tree.Add("/afs/cern.ch/user/d/demattia/public/TagAndProbe/TagAndProbe_ZMuMu.root") tree.Add("/afs/cern.ch/user/d/demattia/public/TagAndProbe/TagAndProbe_Run2012A.root") tree.Add("/afs/cern.ch/user/d/demattia/public/TagAndProbe/TagAndProbe_Run2012B.root") tree.Add("/afs/cern.ch/user/d/demattia/public/TagAndProbe/TagAndProbe_Run2012C.root") tree.Add("/afs/cern.ch/user/d/demattia/public/TagAndProbe/TagAndProbe_Run2012D.root") # Prepare the workspace ws = RooWorkspace("ws", "workspace") Workspace.buildPdf(ws, p) mass = ws.var("mass") sample = ws.cat("sample") simPdf = ws.pdf("simPdf") efficiency = ws.var("efficiency") meanB = ws.var("meanB") # prepare_datasets(ws, p) # Prepare datasets datasetAllMap = {} datasetPassMap = {} hAllMap = {} hPassMap = {} for ptBin1 in range(0, len(ptBinsX)):
def in_region(regions, x): ret = [] for idx, region in enumerate(regions): H = region['PolygonH']['A'] b = region['PolygonH']['b'] diff = H.dot(x.reshape((2, 1))) - b if (diff <= eps).all(): print(idx) ret.append(idx) return ret num_obstacles = 3 num_lasers = 8 workspace = Workspace(8, num_lasers, 'obstacles.json') num_integrators = 1 higher_deriv_bound = 1.0 grid_size = [0.05, 1.0] neighborhood_radius = 0.01 regions_passed = [] dir = 'NN20_grid_005/' with open(dir + 'symbolic_states', 'rb') as f: partitioner = pickle.load(f) # partitioner = StateSpacePartitioner(workspace, num_integrators, higher_deriv_bound, grid_size, neighborhood_radius) # partitioner.partition() for pt in pts:
Created on Thu Dec 13 20:46:20 2018 @author: Jessica Dozal """ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk import sys sys.path.append('../') import Workspace import PCAPtoPDMLController import Session import shutil import PCAP workspace = Workspace.Workspace('Workspace Name', '../') session = Session.Session("Session1", "original PDML", workspace.path) workspace.addSession(session) controller = PCAPtoPDMLController.PCAPtoPDMLController() pathPCAP = "test.pcap" pcap = PCAP.PCAP(pathPCAP, pathPCAP) controller.setPCAP(pcap) #controller.callConversion(workspace) from MainWindow import MainWindow window = MainWindow(workspace) #window.connect("destroy", Gtk.main_quit) window.maximize() window.show_all() shutil.rmtree(workspace.path + "/Session1")
def handle_get(self, request): """Function for handling client GET""" file_name = request[0] if Workspace.file_exists(file_name): # EXISTS resp = "OK" # OK self.conn.sendall(resp.encode()) logging.debug("Server: Response send to {}:{} response: {}".format( self.host, self.port, resp)) else: # NO FILE resp = "NOTFOUND" self.conn.sendall(resp.encode()) logging.debug("Server: Response send to {}:{} response: {}".format( self.host, self.port, resp)) return # Recieve query len querylen = self.conn.recv(self._bufferSize).decode() logging.debug( "Server: Query recieved len from {}:{} query len: {}".format( self.host, self.port, querylen)) # Send OK as ACK resp = "OK" self.conn.sendall(resp.encode()) logging.debug("Server: Response send to {}:{} response: {}".format( self.host, self.port, resp)) # Recieve query bytes_remaining = int(querylen) query = '' while bytes_remaining != 0: if (bytes_remaining >= self._bufferSize): # receive slab from client slab = self.conn.recv(self._bufferSize).decode() query += slab sizeof_slab_received = len(slab) logging.debug("Client: To {}:{} Bytes sent: {}".format( self.host, self.port, sizeof_slab_received)) bytes_remaining -= int(sizeof_slab_received) else: #receive slab from server slab = self.conn.recv(bytes_remaining).decode() query += slab sizeof_slab_received = len(slab) logging.debug("Client: To {}:{} Bytes sent: {}".format( self.host, self.port, sizeof_slab_received)) bytes_remaining -= int(sizeof_slab_received) logging.debug("Client: Query received from {}:{} query: {}".format( self.host, self.port, query)) success = Voronota.create_contacts_file(file_name) if not success: resp = "SERVERERROR" # Internal server error self.conn.sendall(resp.encode()) logging.debug("Server: Response send to {}:{} response: {}".format( self.host, self.port, resp)) query_dict = json.loads(query) query = query_dict['filter'] params = query_dict['params'] success = Voronota.draw(file_name, query, self.port, params) # if ClientErr: # resp = "BADQUERY" # Bad request # self.conn.sendall(resp.encode()) # logging.debug("Response send to {}:{} response: {}".format( # self.host, self.port, resp)) if not success: resp = "SERVERERROR" # Internal server error self.conn.sendall(resp.encode()) logging.debug("Server: Response send to {}:{} response: {}".format( self.host, self.port, resp)) draw_file = Workspace.construct_file_path(Workspace.mkdir(file_name), 'draw' + str(self.port)) # size = Workspace.get_file_size(draw_file) summary = Voronota.summarize(file_name, query) data = json.dumps({'path': draw_file, 'summary': summary}) resp = "OK " + str(len(data)) self.conn.sendall(resp.encode()) logging.debug( "Server: Response send to {}:{} (SIZE) response: {}".format( self.host, self.port, resp)) ack = self.conn.recv(self._bufferSize).decode() logging.debug("Client: ACK recieved from {}:{} ACK: {}".format( self.host, self.port, ack)) self.conn.sendall(data.encode()) logging.debug("Server: File has been sent to {}:{}".format( self.host, self.port))
def __init__(self): self.activeWorkspace = "Workspace1" self.workspace1 = Workspace.Workspace("workspace1") self.workspaceList = [self.workspace1]