From 16cc6769dd69ae7e8024606345acd7c138e18f5b Mon Sep 17 00:00:00 2001 From: Leonardo Hax Date: Thu, 30 Sep 2021 16:40:08 +0200 Subject: [PATCH] infrastructure scripts to perform acquisistions on xbl-daq-28 --- eiger/xbl-daq-28/5m.config | 116 ++++++++++++++----- eiger/xbl-daq-28/consume_assembler.py | 35 ++++++ eiger/xbl-daq-28/debug_packet.py | 19 ++-- eiger/xbl-daq-28/eiger.json | 8 ++ eiger/xbl-daq-28/kill_controls.sh | 54 +++++++++ eiger/xbl-daq-28/ping5m.sh | 0 eiger/xbl-daq-28/run_acquire.sh | 7 ++ eiger/xbl-daq-28/start_daq.sh | 157 ++++++++++++++++++++++++++ eiger/xbl-daq-28/start_requests.py | 42 +++++++ eiger/xbl-daq-28/start_udp_chain.sh | 96 ---------------- eiger/xbl-daq-28/test.par | 6 + 11 files changed, 405 insertions(+), 135 deletions(-) create mode 100644 eiger/xbl-daq-28/consume_assembler.py create mode 100644 eiger/xbl-daq-28/eiger.json create mode 100755 eiger/xbl-daq-28/kill_controls.sh mode change 100644 => 100755 eiger/xbl-daq-28/ping5m.sh create mode 100755 eiger/xbl-daq-28/run_acquire.sh create mode 100755 eiger/xbl-daq-28/start_daq.sh create mode 100644 eiger/xbl-daq-28/start_requests.py delete mode 100644 eiger/xbl-daq-28/start_udp_chain.sh create mode 100644 eiger/xbl-daq-28/test.par diff --git a/eiger/xbl-daq-28/5m.config b/eiger/xbl-daq-28/5m.config index c619214..a412723 100644 --- a/eiger/xbl-daq-28/5m.config +++ b/eiger/xbl-daq-28/5m.config @@ -1,42 +1,102 @@ detsize 2048 2560 -hostname BEB111+BEB070+BEB060+BEB042+BEB004+BEB120+BEB105+BEB121+BEB092+BEB091+BEB058+BEB059+BEB030+BEB038+BEB110+BEB115+BEB095+BEB094+BEB119+BEB055+ - -# +hostname beb058+beb059+ +#hostname BEB111+BEB070+ +#BEB060+BEB042+BEB004+BEB120+BEB105+BEB121+BEB092+BEB091+BEB058+BEB059+BEB030+BEB038+BEB110+BEB115+BEB095+BEB094+BEB119+BEB055+ udp_dstmac 9c:dc:71:47:e5:dc -udp_dstip 10.30.20.6 +udp_dstip 10.30.30.211 + +#udp_dstmac 9c:dc:71:47:e5:d0 +#udp_dstip 10.30.40.211 0:rx_tcpport 1980 0:udp_dstport 50000 0:udp_dstport2 50001 +0:udp_srcip 10.30.30.55 1:rx_tcpport 1981 1:udp_dstport 50002 1:udp_dstport2 50003 +1:udp_srcip 10.30.30.56 -2:rx_tcpport 1982 -2:udp_dstport 50004 -2:udp_dstport2 50005 -3:rx_tcpport 1983 -3:udp_dstport 50006 -3:udp_dstport2 50007 +#2:rx_tcpport 1982 +#2:udp_dstport 50004 +#2:udp_dstport2 50005 +#2:udp_srcip 10.30.30.52 +#3:rx_tcpport 1983 +#3:udp_dstport 50006 +#3:udp_dstport2 50007 +#3:udp_srcip 10.30.30.53 -4:rx_tcpport 1984 -4:udp_dstport 50008 -4:udp_dstport2 50009 -5:rx_tcpport 1985 -5:udp_dstport 50010 -5:udp_dstport2 50011 +#4:rx_tcpport 1984 +#4:udp_dstport 50008 +#4:udp_dstport2 50009 +#4:udp_srcip 10.30.30.54 +#5:rx_tcpport 1985 +#5:udp_dstport 50010 +#5:udp_dstport2 50011 +#5:udp_srcip 10.30.30.55 -6:rx_tcpport 1986 -6:udp_dstport 50012 -6:udp_dstport2 50013 -7:rx_tcpport 1987 -7:udp_dstport 50014 -7:udp_dstport2 50015 +#6:rx_tcpport 1986 +#6:udp_dstport 50012 +#6:udp_dstport2 50013 +#6:udp_srcip 10.30.30.56 +#7:rx_tcpport 1987 +#7:udp_dstport 50014 +#7:udp_dstport2 50015 +#7:udp_srcip 10.30.30.57 -8:rx_tcpport 1988 -8:udp_dstport 50016 -8:udp_dstport2 50017 -9:rx_tcpport 1989 -9:udp_dstport 50018 -9:udp_dstport2 50019 +#8:rx_tcpport 1988 +#8:udp_dstport 50016 +#8:udp_dstport2 50017 +#8:udp_srcip 10.30.30.58 +#9:rx_tcpport 1989 +#9:udp_dstport 50018 +#9:udp_dstport2 50019 +#9:udp_srcip 10.30.30.59 + +#10:rx_tcpport 1990 +#10:udp_dstport 50020 +#10:udp_dstport2 50021 +#10:udp_srcip 10.30.30.60 +#11:rx_tcpport 1991 +#11:udp_dstport 50022 +#11:udp_dstport 50023 +#11:udp_srcip 10.30.30.61 + +#12:rx_tcpport 1992 +#12:udp_dstport 50024 +#12:udp_dstport2 50025 +#12:udp_srcip 10.30.30.62 +#13:rx_tcpport 1993 +#13:udp_dstport 50026 +#13:udp_dstport2 50027 +#13:udp_srcip 10.30.30.63 + +#14:rx_tcpport 1994 +#14:udp_dstport 50028 +#14:udp_dstport2 50029 +#14:udp_srcip 10.30.30.64 +#15:rx_tcpport 1995 +#15:udp_dstport 50030 +#15:udp_dstport 50031 +#15:udp_srcip 10.30.30.65 + +#16:rx_tcpport 1996 +#16:udp_dstport 50032 +#16:udp_dstport2 50033 +#16:udp_srcip 10.30.30.66 +#17:rx_tcpport 1997 +#17:udp_dstport 50034 +#17:udp_dstport2 50035 +#17:udp_srcip 10.30.30.67 + +#18:rx_tcpport 1998 +#18:udp_dstport 50036 +#18:udp_dstport 50037 +#18:udp_srcip 10.30.30.68 +#19:rx_tcpport 1999 +#19:udp_dstport 50038 +#19:udp_dstport 50039 +#19:udp_srcip 10.30.30.69 + +tengiga 1 diff --git a/eiger/xbl-daq-28/consume_assembler.py b/eiger/xbl-daq-28/consume_assembler.py new file mode 100644 index 0000000..e160b3a --- /dev/null +++ b/eiger/xbl-daq-28/consume_assembler.py @@ -0,0 +1,35 @@ +import zmq +from _ctypes import Structure +from ctypes import c_uint64, c_uint16 + +class ImageMetadata(Structure): + _pack_ = 1 + _fields_ = [ + ("version", c_uint64), + ("id", c_uint64), + ("height", c_uint64), + ("width", c_uint64), + ("dtype", c_uint16), + ("encoding", c_uint16), + ("source_id", c_uint16), + ("status", c_uint16), + ("user_1", c_uint64), + ("user_2", c_uint64)] + + def as_dict(self): + return dict((f, getattr(self, f)) for f, _ in self._fields_) + + + + + +zmq_context = zmq.Context() +backend_socket = zmq_context.socket(zmq.SUB) +#backend_socket.setsockopt(zmq.RCVTIMEO, 100) +backend_socket.setsockopt_string(zmq.SUBSCRIBE, "") +backend_socket.connect("ipc:///tmp/std-daq-cSAXS.EG01V01-assembler") + +while True: + image_bytes = backend_socket.recv() + image_meta = ImageMetadata.from_buffer_copy(image_bytes) + print(f'Image received: {image_meta.id}') diff --git a/eiger/xbl-daq-28/debug_packet.py b/eiger/xbl-daq-28/debug_packet.py index 33e3721..5e2f404 100644 --- a/eiger/xbl-daq-28/debug_packet.py +++ b/eiger/xbl-daq-28/debug_packet.py @@ -1,5 +1,6 @@ import socket import numpy as np +import sys frame_header_dt = np.dtype( [ @@ -19,24 +20,20 @@ frame_header_dt = np.dtype( ] ) -hostnames = ['BEB111','BEB070','BEB060','BEB042','BEB004','BEB120','BEB105','BEB121','BEB092','BEB091','BEB058','BEB059','BEB030', 'BEB038','BEB110', 'BEB115', 'BEB095', 'BEB094', 'BEB119', 'BEB055'] +#ip = "10.30.40.211" +ip = sys.argv[1] -# ip = "10.30.20.6" -ips = [] -for hostname in hostnames: - ips.append(socket.gethostbyname('BEB111')) - -ports = list(range(50000, 50204, 1)) +ports = list(range(50000, 50004, 1)) sockets = [socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for i in range(len(ports))] for s, p in zip(sockets, ports): - print("IP:Port: ", ip, p) - s.bind((ip, p)) + print(ip,p) + s.bind((ip,p)) while True: for s in sockets: data, address = s.recvfrom(4096) h = np.frombuffer(data, count=1, dtype=frame_header_dt)[0] print( - f'[{h["Timestamp"]}] frame: {h["Frame Number"]}, pkt:{h["Packet Number"]}, explength:{h["SubFrame Number/ExpLength"]}, module id: {h["Module Id"]} ,row: {h["Row"]}, column: {h["Column"]}' - ) \ No newline at end of file + f'[{h["Timestamp"]}] frame: {h["Frame Number"]}, pkt:{h["Packet Number"]}, explength:{h["SubFrame Number/ExpLength"]}, module id: {h["Module Id"]} ,row: {h["Row"]}, column: {h["Column"]}' + ) diff --git a/eiger/xbl-daq-28/eiger.json b/eiger/xbl-daq-28/eiger.json new file mode 100644 index 0000000..d1c3eed --- /dev/null +++ b/eiger/xbl-daq-28/eiger.json @@ -0,0 +1,8 @@ +{ + "detector_name": "cSAXS.EG01V01", + "detector_type": "eiger", + "n_modules": 4, + "image_height": 514, + "image_width": 1030, + "start_udp_port": 50000 +} diff --git a/eiger/xbl-daq-28/kill_controls.sh b/eiger/xbl-daq-28/kill_controls.sh new file mode 100755 index 0000000..ebcd39d --- /dev/null +++ b/eiger/xbl-daq-28/kill_controls.sh @@ -0,0 +1,54 @@ +#!/bin/bash +UDP=0 +SYNC=0 +ASSEMBLER=0 +WRITER=0 +HELP_FLAG=0 +while getopts h:u:s:a:w: flag +do + case "${flag}" in + h ) HELP_FLAG=${OPTARG};; + u ) UDP=${OPTARG};; + s ) SYNC=${OPTARG};; + w ) WRITER=${OPTARG};; + a ) ASSEMBLER=${OPTARG};; + esac +done + +if (( ${UDP} == 0 )) && (( ${SYNC} == 0 )) && (( ${ASSEMBLER} == 0 )) && (( ${WRITER} == 0 )); then + echo "Nothing to do..." + exit +fi + +# prints help and exits +if (( ${HELP_FLAG} == 1 )); then + echo "Usage : $0 -u -s -a -h " + echo " udp : kill udp receivers." + echo " sync : kill sync." + echo " assembler : kill assembler." + echo " writer : kill writer." + echo " help_flag : show this help and exits." + exit +fi + +if (( ${UDP} == 1 )); then + echo "Killing upd recvs..." + ps aux | grep std_udp_recv | awk 'NR > 1 { print prev } { prev = $2 }' | xargs -I{} kill {} +fi + +if (( ${SYNC} == 1 )); then + echo "Killing sync..." + ps aux | grep std_udp_sync | awk 'NR > 1 { print prev } { prev = $2 }' | xargs -I{} kill {} +fi + +if (( ${ASSEMBLER} == 1 )); then + echo "Killing assembler..." + ps aux | grep eiger_assembler | awk 'NR > 1 { print prev } { prev = $2 }' | xargs -I{} kill {} +fi + +if (( ${WRITER} == 1 )); then + echo "Killing writer..." + ps aux | grep mpiexec | awk 'NR > 1 { print prev } { prev = $2 }' | xargs -I{} kill {} +fi + + diff --git a/eiger/xbl-daq-28/ping5m.sh b/eiger/xbl-daq-28/ping5m.sh old mode 100644 new mode 100755 diff --git a/eiger/xbl-daq-28/run_acquire.sh b/eiger/xbl-daq-28/run_acquire.sh new file mode 100755 index 0000000..07d75cd --- /dev/null +++ b/eiger/xbl-daq-28/run_acquire.sh @@ -0,0 +1,7 @@ +for i in {1..10} +do + echo "Acquire $i" + sls_detector_acquire + stat=`sls_detector_get status` + echo "$stat" +done diff --git a/eiger/xbl-daq-28/start_daq.sh b/eiger/xbl-daq-28/start_daq.sh new file mode 100755 index 0000000..ca37c79 --- /dev/null +++ b/eiger/xbl-daq-28/start_daq.sh @@ -0,0 +1,157 @@ +#!/bin/bash + +# conda activate +export PATH=/home/dbe/miniconda2/bin:$PATH +source /home/dbe/miniconda2/etc/profile.d/conda.sh +conda deactivate +conda activate sf-daq + +# path to build dir +BUILD_PATH='/home/dbe/git/sf_daq_buffer/build/' +# executables +UDP_RECV='std_udp_recv' +UDP_SYNC='std_udp_sync' +EIGER_ASSEMBLER='eiger_assembler' +STD_DET_WRITER='std_det_writer' + +# default config file +CONFIG_FILE='/home/dbe/git/sf_daq_buffer/eiger/xbl-daq-28/eiger.json' +DET_CONFIG_FILE='/home/dbe/git/sf_daq_buffer/eiger/xbl-daq-28/5m.config' +DET_PARAM_FILE='/home/dbe/git/sf_daq_buffer/eiger/xbl-daq-28/test.par' + +HELP_FLAG=0 + +# CONFIGURATION +BIT_DEPTH=16 +N_MPI_EXEC=3 +while getopts h:c:b:m: flag +do + case "${flag}" in + h ) HELP_FLAG=${OPTARG};; + c ) CONFIG_FILE=${OPTARG};; + b ) BIT_DEPTH=${OPTARG};; + m ) N_MPIT_EXEC=${OPTARG};; + esac +done + +# prints help and exits +if (( ${HELP_FLAG} == 1 )); then + echo "Usage : $0 -h -c -b " + echo " help_flag : show this help and exits." + echo " config_file : detector configuration file." + echo " bit_depth : detector bit depth." + exit +fi + +if [ -f "${CONFIG_FILE}" ]; then + N_UDP_RECVS="`cat ${CONFIG_FILE} | grep -P '"n_modules":' | grep -o '[0-9]\+'`" +else + echo "Something went wrong with the config file... ${CONFIG_FILE}..." + exit +fi + +if [ ${N_MPI_EXEC} -gt 0 ] +then + echo "Number of mpi writers: ${N_MPI_EXEC}." +else + echo "Something went wrong with the number of mpi writer processes..." + exit +fi + + + +if [ -f "${CONFIG_FILE}" ]; then + N_UDP_RECVS="`cat ${CONFIG_FILE} | grep -P '"n_modules":' | grep -o '[0-9]\+'`" +else + echo "Something went wrong with the config file... ${CONFIG_FILE}..." + exit +fi + +# Start the receivers +echo "Starting ${N_UDP_RECVS} udp receivers..." +COUNTER=0 +if [ -f "${BUILD_PATH}${UDP_RECV}" ]; then + if [ -f "${CONFIG_FILE}" ]; then + if [ ${BIT_DEPTH} -ne 0 ]; then + while [ $COUNTER -lt ${N_UDP_RECVS} ]; do + ${BUILD_PATH}${UDP_RECV} ${CONFIG_FILE} ${COUNTER} ${BIT_DEPTH} & + let COUNTER=COUNTER+1 + sleep 0.5 + done + else + echo "Error: ${BIT_DEPTH} can't be zero..." + exit + fi + else + echo "Something went wrong while starting the ${UDP_RECV}..." + exit + fi +else + echo "Error: ${UDP_RECV} wasn't found..." + exit +fi + + +# Start the std-udp-sync +echo "Starting the ${UDP_SYNC}..." +COUNTER=0 +if [ -f "${BUILD_PATH}${UDP_SYNC}" ]; then + if [ -f "${CONFIG_FILE}" ]; then + ${BUILD_PATH}${UDP_SYNC} ${CONFIG_FILE} & + sleep 0.5 + else + echo "Something went wrong while starting the ${UDP_SYNC}..." + exit + fi +else + echo "Error: ${UDP_SYNC} wasn't found..." + exit +fi + + +# Start the eiger assembler +echo "Starting the ${EIGER_ASSEMBLER}..." +if [ -f "${BUILD_PATH}${EIGER_ASSEMBLER}" ]; then + if [ -f "${CONFIG_FILE}" ]; then + if [ ${BIT_DEPTH} -ne 0 ]; then + ${BUILD_PATH}${EIGER_ASSEMBLER} ${CONFIG_FILE} ${BIT_DEPTH} & + sleep 0.5 + else + echo "Error: ${BIT_DEPTH} can't be zero..." + exit + fi + else + echo "Something went wrong while starting the ${EIGER_ASSEMBLER}..." + exit + fi +else + echo "Error: ${EIGER_ASSEMBLER} wasn't found..." + exit +fi + +# Start the eiger writer +echo "Starting the ${STD_DET_WRITER}..." +export PATH="/usr/lib64/mpich-3.2/bin:${PATH}"; +export LD_LIBRARY_PATH="/usr/lib64/mpich-3.2/lib:${LD_LIBRARY_PATH}"; + +if [ -f "${BUILD_PATH}${STD_DET_WRITER}" ]; then + if [ -f "${CONFIG_FILE}" ]; then + mpiexec -n ${N_MPI_EXEC} ${BUILD_PATH}${STD_DET_WRITER} ${CONFIG_FILE} ${BIT_DEPTH} & + sleep 0.5 + else + echo "Something went wrong while starting the ${STD_DET_WRITER}..." + exit + fi +else + echo "Error: ${STD_DET_WRITER} wasn't found..." + exit +fi + + +# prepares the detector +echo "Preparing the detector configuration for a default acquisition..."; +export PATH="/home/dbe/git/sf_daq_buffer/slsDetectorPackage/build/bin/:${PATH}"; +sls_detector_put config ${DET_CONFIG_FILE} +sls_detector_put parameters ${DET_PARAM_FILE} +sls_detector_put trimbits /home/dbe/git/sf_daq_buffer/eiger/test/eiger.sn000 +sls_detector_put dac vthreshold 2050 diff --git a/eiger/xbl-daq-28/start_requests.py b/eiger/xbl-daq-28/start_requests.py new file mode 100644 index 0000000..c0e7148 --- /dev/null +++ b/eiger/xbl-daq-28/start_requests.py @@ -0,0 +1,42 @@ +from datetime import datetime +import requests +import time +import json + +# writer agent endpoint +URL = "http://127.0.0.1:5000" +# type of write request +SYNC = "/write_sync" +ASYNC = "/write_async" +KILL = "/write_kill" +# details of request +n_images = 10 +n_acquisitions = 1 +headers = {'Content-type': 'application/json'} + +print("Performing sync aquisitions...") +for i in range(0,n_acquisitions): + output_file ='/home/dbe/git/sf_daq_buffer/eiger/xbl-daq-28/eiger_sync_%s_%s.h5' % (datetime.now().strftime("%H%M%S"), i) + data = {'sources':'eiger', 'n_images':n_images, 'output_file':output_file} + print("REQUEST: ", i) + print("DATA: ", data) + + r = requests.post(url = "http://127.0.0.1:5000/write_sync", json=data, headers=headers) + print("RESPONSE FROM REQUEST: ", r.text) + data = None + time.sleep(1) + +# time.sleep(3) +# print("Performing async aquisitions...") +# for i in range(0,n_acquisitions): +# output_file ='/home/hax_l/tests/eiger_async_%s_%s.h5' % (datetime.now().strftime("%H%M%S"), i) +# data = {'sources':'eiger', 'n_images':n_images, 'output_file':output_file} +# print("REQUEST: ", i) +# print("DATA: ", data) + +# r = requests.post(url = "http://127.0.0.1:5000/write_async", json=data, headers=headers) +# data = None +# time.sleep(1) + + +# #//TODO print("Testing kill aquisitions...") diff --git a/eiger/xbl-daq-28/start_udp_chain.sh b/eiger/xbl-daq-28/start_udp_chain.sh deleted file mode 100644 index 74da1ef..0000000 --- a/eiger/xbl-daq-28/start_udp_chain.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - -# path to build dir -BUILD_PATH='/home/dbe/git/sf_daq_buffer/build/' -# executables -UDP_RECV='std_udp_recv' -UDP_SYNC='std_udp_sync' -EIGER_ASSEMBLER='eiger_assembler' - -# default config file -# CONFIG_FILE='/home/dbe/git/sf_daq_buffer/eiger/xbl-daq-28/eiger-5M.json' -CONFIG_FILE='/home/dbe/git/sf_daq_buffer/eiger/xbl-daq-28/eiger-1M.json' - -HELP_FLAG=0 -BIT_DEPTH=16 -while getopts n:h:u:c:b: flag -do - case "${flag}" in - h ) HELP_FLAG=${OPTARG};; - c ) CONFIG_FILE=${OPTARG};; - b ) BIT_DEPTH=${OPTARG};; - esac -done - - -N_UDP_RECVS="`cat ${CONFIG_FILE} | grep -P '"n_modules":' | grep -o '[0-9]\+'`" - - -# prints help and exits -if (( ${HELP_FLAG} == 1 )); then - echo "Usage : $0 -n -c -h -u -c -b " - echo " n_udp_recvs : number of receivers." - echo " help_flag : show this help and exits." - echo " config_file : detector configuration file." - echo " bit_depth : detector bit depth." - exit -fi - -# Start the receivers -echo "Starting ${N_UDP_RECVS} udp receivers..." -COUNTER=0 -if [ -f "${UDP_RECV}" ]; then - if [ -f "${CONFIG_FILE}" ]; then - while [ $COUNTER -lt ${N_UDP_RECVS} ]; do - "${BUILD_PATH}${UDP_RECV} ${CONFIG_FILE} ${COUNTER} ${BIT_DEPTH}" & - let COUNTER=COUNTER+1 - sleep 0.5 - done - else - echo "Something went wrong while starting the ${UDP_RECV}..." - exit - fi -else - echo "Error: ${UDP_RECV} wasn't found..." - exit -fi - - -# Start the std-udp-sync -echo "Starting the ${UDP_SYNC}..." -COUNTER=0 -if [ -f "${UDP_SYNC}" ]; then - if [ -f "${CONFIG_FILE}" ]; then - if [ ${BIT_DEPTH} -ne 0 ]; then - "${BUILD_PATH}${UDP_SYNC} ${CONFIG_FILE} ${BIT_DEPTH}" & - sleep 0.5 - else - echo "Error: ${BIT_DEPTH} can't be zero..." - exit - fi - - else - echo "Something went wrong while starting the ${UDP_SYNC}..." - exit - fi -else - echo "Error: ${UDP_SYNC} wasn't found..." - exit -fi - - -# Start the eiger assembler -echo "Starting the ${EIGER_ASSEMBLER}..." -COUNTER=0 -if [ -f "${EIGER_ASSEMBLER}" ]; then - if [ -f "${CONFIG_FILE}" ]; then - "${BUILD_PATH}${EIGER_ASSEMBLER} ${CONFIG_FILE} ${BIT_DEPTH}" & - sleep 0.5 - else - echo "Something went wrong while starting the ${EIGER_ASSEMBLER}..." - exit - fi -else - echo "Error: ${EIGER_ASSEMBLER} wasn't found..." - exit -fi \ No newline at end of file diff --git a/eiger/xbl-daq-28/test.par b/eiger/xbl-daq-28/test.par new file mode 100644 index 0000000..f8cbc73 --- /dev/null +++ b/eiger/xbl-daq-28/test.par @@ -0,0 +1,6 @@ +frames 10 +exptime 0.01 +period 0.1 +dr 16 + +timing auto #in case this is trigger it waits forever