def mondumper(): parser = argparse.ArgumentParser( description="Subcribe to a published log stream.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) cargs.subport(parser, default=9005) cargs.subaddr(parser) cargs.verbosity(parser) cargs.version(parser) args = parser.parse_args() eval("sslogger.setLevel(logging.%s)" % args.verbose) sub = subscribers.BasicMonSubscriber(port=args.sub_port, ip=args.sub_ip) sub.start() signal.alarm(0) print("Press `ctrl-C` to stop") last_uc_ev = 0 missed_counter = 0 while True: try: mon = sub.get_data() except KeyboardInterrupt: print("\nClosing listener") sub.close() break if mon is not None: print(mon) sub.close()
def writer(): import argparse parser = argparse.ArgumentParser( description=descr, formatter_class=argparse.ArgumentDefaultsHelpFormatter ) cargs.subport(parser, default=defaultport) cargs.subaddr(parser) cargs.filename(parser) cargs.version(parser) args = parser.parse_args() data_writer = writer_cls( args.filename, file_enumerator="date", port=args.sub_port, ip=args.sub_ip ) data_writer.start() running = True while running: ans = input("To stop type `yes`: \n") if ans == "yes": running = False try: print("Waiting for writer to write buffered data to file......") print("`Ctrl-C` will empty the buffers and close the file immediately.") data_writer.close() except KeyboardInterrupt: print() data_writer.close(hard=True)
def writer(): import argparse import asyncio parser = argparse.ArgumentParser( description=descr, formatter_class=argparse.ArgumentDefaultsHelpFormatter ) cargs.subport(parser, default=defaultport) cargs.subaddr(parser) cargs.filename(parser) cargs.version(parser) args = parser.parse_args() loop = asyncio.get_event_loop() data_writer = writer_cls( args.filename, file_enumerator="date", port=args.sub_port, ip=args.sub_ip, loop=loop, ) from ssdaq.core.utils import ( AsyncPrompt, async_interup_loop_cleanup, async_shut_down_loop, ) async def control_input(loop, data_writer): running = True prompt = AsyncPrompt(loop) while running: try: ans = await prompt("To stop type `yes`: \n") except asyncio.CancelledError: print("Exit") return if ans == "yes": running = False print("Waiting for writer to write buffered data to file......", flush=True) print( "`Ctrl-C` will empty the buffers and close the file immediately.", flush=True, ) close = loop.create_task(data_writer.close()) close.add_done_callback(lambda x: loop.stop()) task = loop.create_task(control_input(loop, data_writer)) try: loop.run_forever() except KeyboardInterrupt: print() if not task.cancelled(): task.cancel() try: loop.run_until_complete(data_writer.close(True)) except KeyboardInterrupt: print() async_interup_loop_cleanup(loop)
def mondumper1(): parser = argparse.ArgumentParser( description="Subcribe to a published log stream.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) cargs.subport(parser, default=9005) cargs.subaddr(parser) cargs.verbosity(parser) cargs.version(parser) args = parser.parse_args() eval("sslogger.setLevel(logging.%s)" % args.verbose) t = Terminal() sub = subscribers.BasicMonSubscriber(port=args.sub_port, ip=args.sub_ip) sub.start() signal.alarm(0) print("Press `ctrl-C` to stop") rdash = ReceiverStatusDash(t, "ReadoutAssembler", (0, 1)) triggdash = ReceiverStatusDash(t, "TriggerPacketReceiver", (30, 1)) timedash = ReceiverStatusDash(t, "TimestampReceiver", (0, 6)) logdash = ReceiverStatusDash(t, "LogReceiver", (30, 6)) mondash = ReceiverStatusDash(t, "MonitorReceiver", (0, 11)) teldash = ReceiverStatusDash(t, "TelDataReceiver", (30, 11)) rtcamim = ReceiverStatusDash(t, "RTCameraImagePublisher", (0, 17)) dashes = [rdash, timedash, triggdash, logdash, mondash, teldash, rtcamim] with t.fullscreen(): oldh = t.height oldw = t.width while True: try: mon = sub.get_data(timeout=1.0) except queue.Empty: mon = None except KeyboardInterrupt: print("\nClosing listener") sub.close() break if t.height != oldh or t.width != oldw: oldh = t.height oldw = t.width t.clear() for dash in dashes: dash.render(dash.last_mon) for dash in dashes: dash.render(mon) sub.close()
def triggerpatternviewer(): import argparse from ssdaq.utils import common_args as cargs parser = argparse.ArgumentParser( description="A trigger pattern viewer.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) cargs.subport(parser, default=None) cargs.subaddr(parser) cargs.verbosity(parser) cargs.version(parser) args = parser.parse_args() if args.sub_ip != "127.0.0.101" and args.sub_port is None: args.sub_port = 10026 else: args.sub_port = 9004 eval("sslogger.setLevel(logging.%s)" % args.verbose) plt = DynamicTRPlotter(ip=args.sub_ip, port=args.sub_port) plt.run()
def timestampdump(): def isValidTS(ts): if ts.time.HasField("seconds") and ts.time.HasField("pico_seconds"): return True else: return False def isSmaller(ts_last, ts_current): if (ts_last.time.seconds * 1e12 + ts_last.time.pico_seconds) <= ( ts_current.time.seconds * 1e12 + ts_current.time.pico_seconds): return True else: return False def get_deltat_in_ps(ts_last, ts_current): tlast = ts_last.time.seconds * 1e12 + ts_last.time.pico_seconds tcurr = ts_current.time.seconds * 1e12 + ts_current.time.pico_seconds return tcurr - tlast # myStats = {"fTrigger":0, "fCurrent_ts":data.TriggerMessage(), "fLast_ts":data.TriggerMessage()} def add_timestamp(ts, myStats): myStats["fTrigger"] += 1 myStats["fCurrent_ts"] = ts if not isValidTS(myStats["fLast_ts"]): myStats["fLast_ts"] = ts def get_frequency_in_Hz(myStats): if not (myStats["fTrigger"] or isValidTS(myStats["fLast_ts"]) or isValidTS(myStats["fCurrent_ts"])): return delt = get_deltat_in_ps(myStats["fLast_ts"], myStats["fCurrent_ts"]) * 1e-12 trig = myStats["fTrigger"] myStats["fTrigger"] = 0 myStats["fLast_ts"] = myStats["fCurrent_ts"] if delt <= 1e-12: return else: return trig / delt parser = argparse.ArgumentParser( description="Subcribe to a published timestamp stream.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) cargs.subport(parser, default=9003) cargs.subaddr(parser) cargs.verbosity(parser) cargs.version(parser) args = parser.parse_args() eval("sslogger.setLevel(logging.%s)" % args.verbose) sub = subscribers.BasicTimestampSubscriber(port=args.sub_port, ip=args.sub_ip) sub.start() signal.alarm(0) print("Press `ctrl-C` to stop") readout_stats = { "fTrigger": 0, "fCurrent_ts": data.TriggerMessage(), "fLast_ts": data.TriggerMessage(), } readout_counter_missed = 0 readout_counter_last = 0 readout_ts_smaller = 0 readout_freq = [] busy_stats = { "fTrigger": 0, "fCurrent_ts": data.TriggerMessage(), "fLast_ts": data.TriggerMessage(), } busy_counter_missed = 0 busy_counter_last = 0 busy_ts_smaller = 0 busy_freq = [] while True: try: tmsg = sub.get_data() except KeyboardInterrupt: print("\nClosing listener") sub.close() break if tmsg is not None: # print(tmsg.type,tmsg.event_counter) # print(tmsg.time.seconds, tmsg.time.pico_seconds) if tmsg.type == 1: # readout triggers only add_timestamp(tmsg, readout_stats) # check if events count up properly current_readout_counter = tmsg.event_counter if (readout_counter_last != 0 and readout_counter_last + 1 != current_readout_counter): readout_counter_missed += 1 print("# of missed readout events", readout_counter_missed) readout_counter_last = current_readout_counter # check for timing issues within the time stamps if isSmaller(readout_stats["fLast_ts"], readout_stats["fCurrent_ts"]): readout_ts_smaller += 1 print("# of readout timestamps smaller", readout_ts_smaller) # try something useful updatetime = 1 # how other do we want to calculate the frequency if (get_deltat_in_ps(readout_stats["fLast_ts"], readout_stats["fCurrent_ts"]) * 1e12) > updatetime: readout_frequency = get_frequency_in_Hz(readout_stats) readout_freq.append(readout_frequency) print("> Readout Frequency [Hz] =", readout_frequency) if tmsg.type == 2: # busy triggers (same logic as readout stuff) add_timestamp(tmsg, busy_stats) current_busy_counter = tmsg.event_counter if (busy_counter_last != 0 and busy_counter_last + 1 != current_busy_counter): busy_counter_missed += 1 print("# of missed busy events", busy_counter_missed) busy_counter_last = current_busy_counter if isSmaller(busy_stats["fLast_ts"], busy_stats["fCurrent_ts"]): busy_ts_smaller += 1 print("# of busy timestamps smaller", busy_ts_smaller) updatetime = 1 if (get_deltat_in_ps(busy_stats["fLast_ts"], busy_stats["fCurrent_ts"]) * 1e12) > updatetime: busy_frequency = get_frequency_in_Hz(busy_stats) busy_freq.append(busy_frequency) print("> Busy Frequency [Hz] =", busy_frequency) """ try: from matplotlib import pyplot as plt except ImportError: return plt.figure() plt.hist(readout_freq, 100, facecolor="g", alpha=0.75) plt.figtext(0.1,0.9,mean(readout_freq)) plt.show() """ sub.close() sub.join()
def triggerdump(): parser = argparse.ArgumentParser( description="Subcribe to a published trigger packet stream.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) cargs.subport(parser, default=9002) cargs.subaddr(parser) cargs.verbosity(parser) cargs.version(parser) parser.add_argument( "-r,--raw", dest="raw", action="store_true", help="if set then raw payloads are shown", ) parser.add_argument( "-p,--payload", dest="payload", action="store_false", help="if set no deserialized payloads are shown", ) args = parser.parse_args() eval("sslogger.setLevel(logging.%s)" % args.verbose) sub = subscribers.BasicTriggerSubscriber(port=args.sub_port, ip=args.sub_ip) sub.start() signal.alarm(0) print("Press `ctrl-C` to stop") last_uc_ev = 0 missed_counter = 0 last = 0 while True: try: trigger = sub.get_data() except KeyboardInterrupt: print("\nClosing listener") sub.close() break if trigger is not None: if args.raw: print("###############RAW################") print(trigger._raw_packet) print("###############RAW################") if args.payload: if last_uc_ev != 0 and last_uc_ev + 1 != trigger.uc_ev: missed_counter += 1 now = trigger.TACK print("##################################") print("#Data: {}".format(trigger.__class__.__name__)) for name, value in trigger._asdict().items(): if name == "trigg_union" or name == "trigg": print("# {}: {}".format(name, np.where(value)[0])) elif name == "trigg_phase": print("# {}: {}".format(name, int(np.log2(value)))) else: print("# {}: {}".format(name, value)) print("# Missed: {}".format(missed_counter)) print("# Frequency: {} {}Hz".format( *get_si_prefix(1.0 / ((now - last) * 1e-9)))) print("# dt: {} s".format((now - last) * 1e-9)) print("##################################") last = now last_uc_ev = trigger.uc_ev sub.close() sub.join()
def slowsignaldump(): parser = argparse.ArgumentParser( description="Start a simple Slow Signal readout listener.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) cargs.n_outputs(parser) cargs.subport(parser, default=9004) cargs.subaddr(parser) parser.add_argument( "-t", dest="tm_numb", nargs="?", type=int, help="Set target module number for which SS data is printed out", ) cargs.verbosity(parser) cargs.version(parser) args = parser.parse_args() eval("sslogger.setLevel(logging.%s)" % args.verbose) rsub = subscribers.SSReadoutSubscriber(port=args.sub_port, ip=args.sub_ip) rsub.start() readout_counter = np.zeros(32) n_modules_per_readout = [] n = 0 signal.alarm(0) print("Press `ctrl-C` to stop") last_tack = 0 while True: try: readout = rsub.get_data() except KeyboardInterrupt: print("\nClosing listener") rsub.close() break # if(n>0): # print('\033[7 A ') print("Readout number %d" % (readout.iro)) print("Timestamp %d ns" % (readout.time)) print("Timestamp %f s" % (readout.time * 1e-9)) print("Cpu timestamp {}".format( datetime.utcfromtimestamp(readout.cpu_t))) print("Cpu timestamp {}".format(readout.cpu_t)) print("Cpu timestamp {}".format(readout.cpu_t_s)) print("Cpu timestamp {}".format(readout.cpu_t_ns)) m = ~np.isnan(readout.data) print("Participating TMs: ", set(np.where(m)[0])) print("Number of participating TMs: ", len(set(np.where(m)[0]))) print("Amplitude sum: {} mV".format(np.nansum(readout.data.flatten()))) if readout.time - last_tack != 0: print("Rate {}{} Hz".format( *get_si_prefix(1.0 / (readout.time - last_tack) * 1e9))) else: print(readout.time, last_tack) last_tack = readout.time # print(readout.data) # n_modules_per_readout.append(np.sum(m)) # readout_counter[m] += 1 # m = readout_counter>0 if args.tm_numb: print(readout.data[args.tm_numb]) n += 1 if args.n_outputs != None and n >= args.n_outputs: break try: from matplotlib import pyplot as plt except ImportError: return # plt.figure() # plt.hist(n_modules_per_readout, 10, facecolor="g", alpha=0.75) # plt.show() rsub.close() rsub.join()
def mondumper(): import curses import asyncio from ssdaq.core.utils import ( AsyncPrompt, async_interup_loop_cleanup, async_shut_down_loop, ) parser = argparse.ArgumentParser( description="Subcribe to a published log stream.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) cargs.subport(parser, default=9005) cargs.subaddr(parser) cargs.verbosity(parser) cargs.version(parser) args = parser.parse_args() eval("sslogger.setLevel(logging.%s)" % args.verbose) # stdscr = curses.initscr() # curses.noecho() # curses.cbreak() t = Terminal() sub = subscribers.AsyncMonSubscriber(port=args.sub_port, ip=args.sub_ip) loop = asyncio.get_event_loop() # sub.start() print("Press `ctrl-C` to stop") rdash = ReceiverStatusDash(t, "ReadoutAssembler", (0, 1)) triggdash = ReceiverStatusDash(t, "TriggerPacketReceiver", (30, 1)) timedash = ReceiverStatusDash(t, "TimestampReceiver", (0, 6)) logdash = ReceiverStatusDash(t, "LogReceiver", (30, 6)) mondash = ReceiverStatusDash(t, "MonitorReceiver", (0, 11)) teldash = ReceiverStatusDash(t, "TelDataReceiver", (30, 11)) rtcamim = ReceiverStatusDash(t, "RTCameraImage", (0, 16)) dashes = [rdash, timedash, triggdash, logdash, mondash, teldash, rtcamim] async def control_task(loop, dashes, sub, t): prompt = AsyncPrompt(loop) oldh = t.height oldw = t.width while True: try: mon = await asyncio.wait_for(sub.get_data(), 1.0) except asyncio.TimeoutError: mon = None # sslogger.warn("{},{}".format(t.height,t.width)) if t.height != oldh or t.width != oldw: oldh = t.height oldw = t.width print(t.clear()) for dash in dashes: dash.render(dash.last_mon) # sslogger.error("HERE") for dash in dashes: dash.render(mon) # stdscr.refresh() with t.fullscreen(): main_task = loop.create_task(control_task(loop, dashes, sub, t)) try: loop.run_forever() except KeyboardInterrupt: # print('HERE') # klakslkd # curses.echo() loop.run_until_complete(sub.close())