예제 #1
0
    def __init__(self, filename):
        self.st = ST.ST()  # 由符号名找到索引
        self.keys = []  # 由索引找到符号名
        self.file = open(filename)
        for i in self.file.readlines():
            # 第一遍扫描通过读入字符串来构造索引
            a = i.split(' ')
            for j in range(len(a)):
                if not self.st.contains(a[j]):
                    self.st.put(a[j], self.st.size())
        print "Done Reading " + filename

        self.keys = [0] * self.st.size()
        for stringName in self.st.keys():  #把所有的keys放到
            self.keys[self.st.get(stringName)] = stringName

        self.G = graph.Graph(self.st.size())  #第二次扫描
        self.file1 = open(filename)
        for i in self.file1.readlines():
            a = i.split(' ')
            v = self.st.get(a[0])
            for i in range(len(a)):
                w = self.st.get(a[i])
                self.G.addEdge(v, w)
예제 #2
0
    try:
        fp = open(name, "r")
    except:
        print('Error on opening file\n')
        quit()

    content = fp.readlines()

    for line in content:
        strlist = line.split()
        g.insVertex(strlist[0], strlist[1], st)


#main:

st = ST.ST()

name = 'file.txt'

read_file(name, st)

g = GRAPH.GRAPH(st.getDimention())
loadGraph(name, st, g)

timePass = []
for i in range(g.getVertexNum()):
    timePass.append(0)

timeEnd = []
for i in range(g.getVertexNum()):
    timeEnd.append(0)
예제 #3
0
def run():
    while (1):
        try:
            with socket.socket(socket.AF_INET,
                               socket.SOCK_STREAM) as s:  #Set up socket
                s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,
                             1)  #Make sure socket can reuse the address
                s.bind((HOST, PORT))  #Bind the address and port to this socket
                print("Listening at " + HOST + ":" + str(PORT))
                s.listen(1)
                global conn
                global SPT
                global HRTools
                global TTP
                global STProc
                global CTProc
                global COProc
                global HRSTProc
                conn, addr = s.accept()  #Accept an incoming client connection

                with conn:
                    print("Connected by:", addr)

                    while (1):
                        lock = Lock()
                        data = (conn.recv(1024)).decode()
                        print(data)
                        if not data: break
                        if (
                                data == "START0"
                        ):  #If the start signal from the client is recieved for default tools
                            SPT = SP_TOOLS()
                            sendToHost("DONE", lock)
                            strt = 1
                        if (data == "START1"):
                            HRTools = ST()
                            sendToHost("DONE", lock)
                            strt = 2
                        if (strt == 1):
                            print(data)
                            if (
                                    data[:2] == "PC"
                            ):  #If the first two characters are PC, then start the pulse counter
                                if (
                                        isinstance(COProc, Process)
                                ):  #If the process already exists, kill it to prevent multiple processes forming
                                    COProc.terminate()
                                print("starting counter")
                                mode = int(data[2])
                                window = float(data[3:])
                                COProc = Process(target=counter,
                                                 args=(
                                                     window,
                                                     mode,
                                                     lock,
                                                 ))  #Pulse counter process
                                COProc.start()
                            if (
                                    data == "ST"
                            ):  #If the client has activated the single channel inter rising edge timer
                                if (isinstance(STProc, Process)):
                                    STProc.terminate()
                                STProc = Process(target=ST_MOD, args=(lock, ))
                                STProc.start()
                            if (data[:2] == "CT"):  #Coincidence timer
                                if (isinstance(CTProc, Process)):
                                    CTProc.terminate()
                                mode = data[2]
                                CTProc = Process(target=CT_MOD,
                                                 args=(
                                                     lock,
                                                     mode,
                                                 ))
                                CTProc.start()
                            if (data[:2] == "PG"):  #Signal generator
                                PG_MOD(
                                    json.loads(data[2:])
                                )  #Deserialize the incoming data and call the pulse generator function
                            if (data[:2] == "TT"):  #Time tagger

                                if (
                                        data[2] == "0"
                                ):  #If the first argument is zero, then stop the time tagger and kill its child process
                                    if (isinstance(TTP, Process)):
                                        print("Stopping time tagger")
                                        SPT.TT_reset()
                                        TTP.terminate()
                                else:
                                    if (
                                            isinstance(TTP, Process)
                                    ):  #If the child process already exists then kill it and start it again
                                        TTP.terminate()
                                    time = float(data[3:])
                                    TTP = Process(target=TT_MOD,
                                                  args=(time, lock))
                                    TTP.start()

                            if (data[:3] == "iDD"):  #Input delay configuration
                                vals = json.loads(
                                    data[3:]
                                )  #Deserialize the incoming delay configuration
                                DD_IDELAY(
                                    vals[0], vals[1], vals[2]
                                )  #And pass it to the delay configuration function
                            if (data == "XX"):
                                if (
                                        not (COProc is None)
                                ):  # If the process already exists, kill it to prevent multiple processes forming
                                    COProc.terminate()
                                if (not (CTProc is None)):
                                    CTProc.terminate()
                                if (not (STProc is None)):
                                    STProc.terminate()
                                if (
                                        not (TTP is None)
                                ):  # If the child process already exists then kill it and start it again
                                    TTP.terminate()
                                strt = 0
                        if (strt == 2):
                            if (data == "ST"
                                ):  # High resolution inter rising edge timer
                                if (isinstance(HRSTProc, Process)):
                                    HRSTProc.terminate()
                                HRSTProc = Process(target=HRST_start,
                                                   args=(lock, ))
                                HRSTProc.start()
                            if (data[:2] == "DD"):
                                dels = json.loads(data[2:])
                                HRST_change_delay(dels)
                            if (data[:2] == "STOP"):
                                if (not (HRSTProc is None)):
                                    HRSTProc.terminate()
                            if (data == "XX"):
                                if (not (HRSTProc is None)):
                                    HRSTProc.terminate()
                                strt = 0

        except Exception as e:
            print("Something happened " + str(e))
예제 #4
0
 def __init__(self, d):
     self.d = d
     self.st1 = ST.ST()