def getStreamConfigFixed (self, id): cfg = Config.getStreamConfigFixed (self, id) (cfg["DATA_HOST_0"], cfg["DATA_HOST_1"]) = self.config["DATA_HOST"].split(",") (cfg["DATA_MCAST_0"], cfg["DATA_MCAST_1"]) = self.config["DATA_MCAST"].split(",") (cfg["DATA_PORT_0"], cfg["DATA_PORT_1"]) = self.config["DATA_PORT"].split(",") (cfg["META_HOST_0"], cfg["META_HOST_1"]) = self.config["META_HOST"].split(",") (cfg["META_MCAST_0"], cfg["META_MCAST_1"]) = self.config["META_MCAST"].split(",") (cfg["META_PORT_0"], cfg["META_PORT_1"]) = self.config["META_PORT"].split(",") cfg["ADC_SAMPLE_RATE"] = self.config["ADC_SAMPLE_RATE"] (freq, bw, nchan) = self.config["SUBBAND_CONFIG_" + str(id)].split(":") # MeerKAT's convention is that the CFREQ is offset by chan_bw/2 chan_bw = float(bw) / float(nchan) cfg["FREQ"] = str(float(freq) - chan_bw / 2) cfg["BW"] = bw cfg["NCHAN"] = nchan cfg["NPOL"] = "2" (start_chan, end_chan) = self.config["SUBBAND_CHANS_" + str(id)].split(":") cfg["START_CHANNEL"] = start_chan cfg["END_CHANNEL"] = end_chan return cfg
def getStreamConfigFixed(self, id): cfg = Config.getStreamConfigFixed(self, id) (cfg["DATA_HOST_0"], cfg["DATA_HOST_1"]) = self.config["DATA_HOST_0"].split(",") (cfg["DATA_MCAST_0"], cfg["DATA_MCAST_1"]) = self.config["DATA_MCAST_0"].split(",") (cfg["DATA_PORT_0"], cfg["DATA_PORT_1"]) = self.config["DATA_PORT_0"].split(",") (cfg["META_HOST_0"], cfg["META_HOST_1"]) = self.config["META_HOST_0"].split(",") (cfg["META_MCAST_0"], cfg["META_MCAST_1"]) = self.config["META_MCAST_0"].split(",") (cfg["META_PORT_0"], cfg["META_PORT_1"]) = self.config["META_PORT_0"].split(",") cfg["ADC_SAMPLE_RATE"] = self.config["ADC_SAMPLE_RATE"] (freq, bw, nchan) = self.config["SUBBAND_CONFIG_" + cfg["STREAM_SUBBAND_ID"]].split(":") chan_bw = float(bw) / float(nchan) cfg["FREQ"] = str(float(freq) - chan_bw / 2) return cfg
def main (self): # open a listening socket to receive the data files to read hostname = getHostNameShort() # get the site configurationa config = Config() # prepare header using configuration file parameters fixed_config = config.getStreamConfigFixed(self.id) db_prefix = self.cfg["DATA_BLOCK_PREFIX"] db_id = self.cfg["RECEIVING_DATA_BLOCK"] num_stream = self.cfg["NUM_STREAM"] db_key = SMRBDaemon.getDBKey (db_prefix, stream_id, num_stream, db_id) cmd = "dada_diskdb -k " + db_key + " -z -s " + \ "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000000000000000.000000.dada" + \ "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000000000000000.000000.dada" + \ "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000034359738368.000000.dada" + \ "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000068719476736.000000.dada" + \ "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000103079215104.000000.dada" + \ "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000137438953472.000000.dada" + \ "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000171798691840.000000.dada" + \ "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000206158430208.000000.dada" + \ "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000240518168576.000000.dada" self.log (0, "cmd=" + cmd) (rval, lines) = self.system (cmd) self.log (0, "rval=" + str(rval)) for line in lines: self.log (0, line)
def getStreamConfigFixed(self, id): cfg = Config.getStreamConfigFixed(self, id) cfg["NPOL"] = Config.getStreamParam(self.config, "NPOL", str(id)) (cfg["DATA_HOST"], cfg["DATA_PORT"]) = self.config["STREAM_UDP_" + str(id)].split(":") cfg["UDP_NSAMP"] = "2048" return cfg
def getMuxedStreamConfigFixed(self, id): cfg = Config.getStreamConfigFixed(self, id) (cfg["DATA_HOST_0"], cfg["DATA_HOST_1"]) = self.config["DATA_HOST"].split(",") (cfg["DATA_MCAST_0"], cfg["DATA_MCAST_1"]) = self.config["DATA_MCAST"].split(",") (cfg["DATA_PORT_0"], cfg["DATA_PORT_1"]) = self.config["DATA_PORT"].split(",") (cfg["META_HOST_0"], cfg["META_HOST_1"]) = self.config["META_HOST"].split(",") (cfg["META_MCAST_0"], cfg["META_MCAST_1"]) = self.config["META_MCAST"].split(",") (cfg["META_PORT_0"], cfg["META_PORT_1"]) = self.config["META_PORT"].split(",") cfg["ADC_SAMPLE_RATE"] = self.config["ADC_SAMPLE_RATE"] (freq1, bw1, nchan1) = self.config["SUBBAND_CONFIG_0"].split(":") (freq2, bw2, nchan2) = self.config["SUBBAND_CONFIG_1"].split(":") freq = (float(freq1) + float(freq2)) / 2 bw = float(bw1) + float(bw2) nchan = int(nchan1) + int(nchan2) # MeerKAT's convention is that the CFREQ is offset by chan_bw/2 chan_bw = float(bw1) / float(nchan1) cfg["FREQ"] = str(float(freq) - chan_bw / 2) cfg["BW"] = str(bw) cfg["NCHAN"] = str(nchan) cfg["NPOL"] = "2" (start_chan1, end_chan1) = self.config["SUBBAND_CHANS_0"].split(":") (start_chan2, end_chan2) = self.config["SUBBAND_CHANS_1"].split(":") cfg["START_CHANNEL"] = start_chan1 cfg["END_CHANNEL"] = end_chan2 return cfg
def getMuxedStreamConfigFixed (self, id): cfg = Config.getStreamConfigFixed (self, id) (cfg["DATA_HOST_0"], cfg["DATA_HOST_1"]) = self.config["DATA_HOST"].split(",") (cfg["DATA_MCAST_0"], cfg["DATA_MCAST_1"]) = self.config["DATA_MCAST"].split(",") (cfg["DATA_PORT_0"], cfg["DATA_PORT_1"]) = self.config["DATA_PORT"].split(",") (cfg["META_HOST_0"], cfg["META_HOST_1"]) = self.config["META_HOST"].split(",") (cfg["META_MCAST_0"], cfg["META_MCAST_1"]) = self.config["META_MCAST"].split(",") (cfg["META_PORT_0"], cfg["META_PORT_1"]) = self.config["META_PORT"].split(",") cfg["ADC_SAMPLE_RATE"] = self.config["ADC_SAMPLE_RATE"] (freq1, bw1, nchan1) = self.config["SUBBAND_CONFIG_0"].split(":") (freq2, bw2, nchan2) = self.config["SUBBAND_CONFIG_1"].split(":") freq = (float(freq1) + float(freq2)) / 2 bw = float(bw1) + float(bw2) nchan = int(nchan1) + int(nchan2) # MeerKAT's convention is that the CFREQ is offset by chan_bw/2 chan_bw = float(bw1) / float(nchan1) cfg["FREQ"] = str(float(freq) - chan_bw / 2) cfg["BW"] = str(bw) cfg["NCHAN"] = str(nchan) cfg["NPOL"] = "2" (start_chan1, end_chan1) = self.config["SUBBAND_CHANS_0"].split(":") (start_chan2, end_chan2) = self.config["SUBBAND_CHANS_1"].split(":") cfg["START_CHANNEL"] = start_chan1 cfg["END_CHANNEL"] = end_chan2 return cfg
def getStreamConfigFixed(self, id): cfg = Config.getStreamConfigFixed(self, id) (cfg["DATA_HOST_0"], cfg["DATA_HOST_1"]) = self.config["DATA_HOST"].split(",") (cfg["DATA_MCAST_0"], cfg["DATA_MCAST_1"]) = self.config["DATA_MCAST"].split(",") (cfg["DATA_PORT_0"], cfg["DATA_PORT_1"]) = self.config["DATA_PORT"].split(",") (cfg["META_HOST_0"], cfg["META_HOST_1"]) = self.config["META_HOST"].split(",") (cfg["META_MCAST_0"], cfg["META_MCAST_1"]) = self.config["META_MCAST"].split(",") (cfg["META_PORT_0"], cfg["META_PORT_1"]) = self.config["META_PORT"].split(",") cfg["ADC_SAMPLE_RATE"] = self.config["ADC_SAMPLE_RATE"] (freq, bw, nchan) = self.config["SUBBAND_CONFIG_" + str(id)].split(":") # MeerKAT's convention is that the CFREQ is offset by chan_bw/2 chan_bw = float(bw) / float(nchan) cfg["FREQ"] = str(float(freq) - chan_bw / 2) cfg["BW"] = bw cfg["NCHAN"] = nchan cfg["NPOL"] = "2" (start_chan, end_chan) = self.config["SUBBAND_CHANS_" + str(id)].split(":") cfg["START_CHANNEL"] = start_chan cfg["END_CHANNEL"] = end_chan return cfg
def main (self): # open a listening socket to receive the data files to read hostname = getHostNameShort() # get the site configurationa config = Config() # prepare header using configuration file parameters fixed_config = config.getStreamConfigFixed(self.id) if DL > 1: self.log(1, "NBIT\t" + fixed_config["NBIT"]) self.log(1, "NDIM\t" + fixed_config["NDIM"]) self.log(1, "NCHAN\t" + fixed_config["NCHAN"]) self.log(1, "TSAMP\t" + fixed_config["TSAMP"]) self.log(1, "BW\t" + fixed_config["BW"]) self.log(1, "FREQ\t" + fixed_config["FREQ"]) self.log(1, "START_CHANNEL\t" + fixed_config["START_CHANNEL"]) self.log(1, "END_CHANNEL\t" + fixed_config["END_CHANNEL"]) self.log(1, "ReadDaemon::main self.list_obs()") list_xml_str = self.list_obs() list_xml = xmltodict.parse (list_xml_str) first_obs = list_xml['observation_list']['observation'][0] print str(first_obs) self.read_obs (first_obs) #self.log(1, "ReadDaemon::main " + str(xml)) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind((hostname, int(self.cfg["STREAM_READ_PORT"]) + int(self.id))) sock.listen(1) can_read = [sock] can_write = [] can_error = [] while not self.quit_event.isSet(): timeout = 1 did_read = [] did_write = [] did_error = [] try: # wait for some activity on the control socket self.log(3, "main: select") did_read, did_write, did_error = select.select(can_read, can_write, can_error, timeout) self.log(3, "main: read="+str(len(did_read))+" write="+ str(len(did_write))+" error="+str(len(did_error))) except select.error as e: if e[0] == errno.EINTR: self.log(0, "SIGINT received during select, exiting") self.quit_event.set() else: raise if (len(did_read) > 0): for handle in did_read: if (handle == sock): (new_conn, addr) = sock.accept() self.log(1, "main: accept connection from "+repr(addr)) # add the accepted connection to can_read can_read.append(new_conn) # an accepted connection must have generated some data else: message = handle.recv(4096).strip() self.log(3, "commandThread: message='" + str(message) +"'") xml = xmltodict.parse (message) self.log(3, DL, "commandThread: xml='" + str(xml) +"'") if (len(message) == 0): self.log(1, "commandThread: closing connection") handle.close() for i, x in enumerate(can_read): if (x == handle): del can_read[i] else: if xml['command'] == "list_obs": self.log (1, "command ["+xml['command'] + "]") self.list_obs () response = "OK" elif xml['command'] == "read_obs": self.log (1, "command ["+xml['command'] + "]") self.read_obs () response = "OK" else: self.log (-1, "unrecognized command ["+xml['command'] + "]") response = "FAIL" self.log(3, "-> " + response) xml_response = "<read_response>" + response + "</read_response>" handle.send (xml_response)
def main(self): # open a listening socket to receive the data files to read hostname = getHostNameShort() # get the site configurationa config = Config() # prepare header using configuration file parameters fixed_config = config.getStreamConfigFixed(self.id) if DL > 1: self.log(1, "NBIT\t" + fixed_config["NBIT"]) self.log(1, "NDIM\t" + fixed_config["NDIM"]) self.log(1, "NCHAN\t" + fixed_config["NCHAN"]) self.log(1, "TSAMP\t" + fixed_config["TSAMP"]) self.log(1, "BW\t" + fixed_config["BW"]) self.log(1, "FREQ\t" + fixed_config["FREQ"]) self.log(1, "START_CHANNEL\t" + fixed_config["START_CHANNEL"]) self.log(1, "END_CHANNEL\t" + fixed_config["END_CHANNEL"]) self.log(1, "ReadDaemon::main self.list_obs()") list_xml_str = self.list_obs() list_xml = xmltodict.parse(list_xml_str) first_obs = list_xml['observation_list']['observation'][0] print str(first_obs) self.read_obs(first_obs) #self.log(1, "ReadDaemon::main " + str(xml)) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind((hostname, int(self.cfg["STREAM_READ_PORT"]) + int(self.id))) sock.listen(1) can_read = [sock] can_write = [] can_error = [] while not self.quit_event.isSet(): timeout = 1 did_read = [] did_write = [] did_error = [] try: # wait for some activity on the control socket self.log(3, "main: select") did_read, did_write, did_error = select.select( can_read, can_write, can_error, timeout) self.log( 3, "main: read=" + str(len(did_read)) + " write=" + str(len(did_write)) + " error=" + str(len(did_error))) except select.error as e: if e[0] == errno.EINTR: self.log(0, "SIGINT received during select, exiting") self.quit_event.set() else: raise if (len(did_read) > 0): for handle in did_read: if (handle == sock): (new_conn, addr) = sock.accept() self.log(1, "main: accept connection from " + repr(addr)) # add the accepted connection to can_read can_read.append(new_conn) # an accepted connection must have generated some data else: message = handle.recv(4096).strip() self.log( 3, "commandThread: message='" + str(message) + "'") xml = xmltodict.parse(message) self.log(3, DL, "commandThread: xml='" + str(xml) + "'") if (len(message) == 0): self.log(1, "commandThread: closing connection") handle.close() for i, x in enumerate(can_read): if (x == handle): del can_read[i] else: if xml['command'] == "list_obs": self.log(1, "command [" + xml['command'] + "]") self.list_obs() response = "OK" elif xml['command'] == "read_obs": self.log(1, "command [" + xml['command'] + "]") self.read_obs() response = "OK" else: self.log( -1, "unrecognized command [" + xml['command'] + "]") response = "FAIL" self.log(3, "-> " + response) xml_response = "<read_response>" + response + "</read_response>" handle.send(xml_response)