From 22f73b0273ac467134abb7196ffcbcb8b6fa0de1 Mon Sep 17 00:00:00 2001 From: lhdamiani Date: Fri, 5 Mar 2021 16:47:18 +0100 Subject: [PATCH] controls scripts of eiger and debug msgs --- core-buffer/include/eiger.hpp | 4 +- core-buffer/src/BufferUtils.cpp | 8 ++-- core-buffer/src/RamBuffer.cpp | 38 +++++++++------- eiger/config/eiger.json | 7 ++- eiger/control/kill_controls.sh | 46 +++++++++++++++++++ eiger/control/start_assembler.sh | 46 +++++++++++++++++++ eiger/control/start_stream.sh | 48 ++++++++++++++++++++ eiger/control/start_udp_recvs.sh | 55 +++++++++++++++++++++++ eiger/start_eiger_server.sh | 36 +++++++++++---- jf-assembler/src/ZmqPulseSyncReceiver.cpp | 2 +- jf-assembler/src/main.cpp | 12 +++++ 11 files changed, 268 insertions(+), 34 deletions(-) create mode 100755 eiger/control/kill_controls.sh create mode 100755 eiger/control/start_assembler.sh create mode 100755 eiger/control/start_stream.sh create mode 100755 eiger/control/start_udp_recvs.sh diff --git a/core-buffer/include/eiger.hpp b/core-buffer/include/eiger.hpp index d51562d..ce14859 100644 --- a/core-buffer/include/eiger.hpp +++ b/core-buffer/include/eiger.hpp @@ -24,8 +24,8 @@ struct det_packet { uint64_t timestamp; uint16_t moduleID; - uint16_t row; - uint16_t column; + uint16_t xCoord; + uint16_t yCoord; uint16_t reserved; uint32_t debug; diff --git a/core-buffer/src/BufferUtils.cpp b/core-buffer/src/BufferUtils.cpp index bd71471..a3ba89b 100644 --- a/core-buffer/src/BufferUtils.cpp +++ b/core-buffer/src/BufferUtils.cpp @@ -157,15 +157,13 @@ BufferUtils::DetectorConfig BufferUtils::read_json_config( rapidjson::Document config_parameters; config_parameters.ParseStream(isw); - BufferUtils::DetectorConfig det_config = { + return { config_parameters["streamvis_stream"].GetString(), config_parameters["streamvis_rate"].GetInt(), config_parameters["live_stream"].GetString(), config_parameters["live_rate"].GetInt(), - // config_parameters["pedestal_file"].GetString(), - "", - // config_parameters["gain_file"].GetString(), - "", + config_parameters["pedestal_file"].GetString(), + config_parameters["gain_file"].GetString(), config_parameters["detector_name"].GetString(), config_parameters["n_modules"].GetInt(), config_parameters["start_udp_port"].GetInt(), diff --git a/core-buffer/src/RamBuffer.cpp b/core-buffer/src/RamBuffer.cpp index 85cb980..e5a2414 100644 --- a/core-buffer/src/RamBuffer.cpp +++ b/core-buffer/src/RamBuffer.cpp @@ -44,19 +44,6 @@ RamBuffer::RamBuffer( meta_buffer_ = (ModuleFrame *) buffer_; // Image buffer start right after metadata buffer. image_buffer_ = (char*)buffer_ + (meta_bytes_ * n_slots_); - - #ifdef DEBUG_OUTPUT - using namespace date; - cout << " [" << std::chrono::system_clock::now(); - cout << "] [RamBuffer::RamBuffer] :"; - cout << " Details of rambuffer:"; - cout << "n_modules: " << n_modules_; - cout << " || meta_bytes: " << meta_bytes_; - cout << " || image_bytes: " << image_bytes_; - cout << " || buffer_bytes: " << buffer_bytes_; - cout << " || n_slots: " << n_slots_; - cout << endl; - #endif } RamBuffer::~RamBuffer() @@ -124,9 +111,22 @@ void RamBuffer::assemble_image( auto is_pulse_init = false; auto is_good_image = true; + // for each module it collects the metadata from each frame for (int i_module=0; i_module < n_modules_; i_module++) { ModuleFrame *frame_meta = src_meta + i_module; + #ifdef DEBUG_OUTPUT + using namespace date; + cout << " [" << std::chrono::system_clock::now(); + cout << "] [RamBuffer::assemble_image] :"; + cout << "module_id: " << i_module; + cout << " || frame index: " << frame_meta->frame_index; + cout << " || row: " << frame_meta->row; + cout << " || column: " << frame_meta->column; + cout << " || n_recv_packets: " << frame_meta->n_recv_packets; + cout << endl; + #endif + auto is_good_frame = frame_meta->n_recv_packets == N_PACKETS_PER_FRAME; @@ -142,6 +142,7 @@ void RamBuffer::assemble_image( #endif continue; } + // in the first module will enter here and define image metadata if (!is_pulse_init) { if (frame_meta->frame_index != pulse_id) { stringstream err_msg; @@ -160,11 +161,18 @@ void RamBuffer::assemble_image( throw runtime_error(err_msg.str()); } - + image_meta.pulse_id = frame_meta->pulse_id; image_meta.frame_index = frame_meta->frame_index; image_meta.daq_rec = frame_meta->daq_rec; - + #ifdef DEBUG_OUTPUT + using namespace date; + cout << " [" << std::chrono::system_clock::now(); + cout << "] [RamBuffer::assemble_image] :"; + cout << " Defining image_meta"; + cout << " || image_meta.frame_index " << image_meta.frame_index; + cout << endl; + #endif is_pulse_init = 1; } diff --git a/eiger/config/eiger.json b/eiger/config/eiger.json index a156c27..ba946bc 100644 --- a/eiger/config/eiger.json +++ b/eiger/config/eiger.json @@ -3,7 +3,10 @@ "streamvis_rate": 10, "live_stream": "tcp://0.0.0.0:9106", "live_rate": 10, + "pedestal_file": "", + "gain_file": "", "detector_name": "eiger", - "n_modules": 1, - "start_udp_port": 50200 + "n_modules": 2, + "start_udp_port": 50200, + "buffer_folder": "" } diff --git a/eiger/control/kill_controls.sh b/eiger/control/kill_controls.sh new file mode 100755 index 0000000..0cbf590 --- /dev/null +++ b/eiger/control/kill_controls.sh @@ -0,0 +1,46 @@ +#!/bin/bash +UDP=0 +STREAM=0 +ASSEMBLER=0 +HELP_FLAG=0 +while getopts h:u:s:a: flag +do + case "${flag}" in + h ) HELP_FLAG=${OPTARG};; + u ) UDP=${OPTARG};; + s ) STREAM=${OPTARG};; + a ) ASSEMBLER=${OPTARG};; + esac +done + +if (( ${UDP} == 0 )) && (( ${STREAM} == 0 )) && (( ${ASSEMBLER} == 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 " stream : kill stream." + echo " assembler : kill assembler." + echo " help_flag : show this help and exits." + exit +fi + +if (( ${UDP} == 1 )); then + echo "Killing upd recvs..." + ps aux | grep eiger_udp_recv | awk 'NR > 1 { print prev } { prev = $2 }' | xargs -I{} kill {} +fi + +if (( ${STREAM} == 1 )); then + echo "Killing stream..." + ps aux | grep eiger_stream | awk 'NR > 1 { print prev } { prev = $2 }' | xargs -I{} kill {} +fi + +if (( ${ASSEMBLER} == 1 )); then + echo "Killing stream..." + ps aux | grep eiger_assembler | awk 'NR > 1 { print prev } { prev = $2 }' | xargs -I{} kill {} +fi + + diff --git a/eiger/control/start_assembler.sh b/eiger/control/start_assembler.sh new file mode 100755 index 0000000..7fedc65 --- /dev/null +++ b/eiger/control/start_assembler.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +MAKE_FLAG=0 +ASSEMBLER='/home/hax_l/software/sf_daq_buffer/build/eiger_assembler' +CONFIG_FILE='/home/hax_l/software/sf_daq_buffer/eiger/config/eiger.json' +BUILD_PATH='/home/hax_l/software/sf_daq_buffer/build' +NAME='eiger_assembler' +HELP_FLAG=0 +while getopts m:h:c: flag +do + case "${flag}" in + m ) MAKE_FLAG=${OPTARG};; + h ) HELP_FLAG=${OPTARG};; + c ) CONFIG_FILE=${OPTARG};; + esac +done + +# prints help and exits +if (( ${HELP_FLAG} == 1 )); then + echo "Usage : $0 -c -m -h " + echo " config_file : detector configuration file." + echo " make_flag : compile code before running." + echo " help_flag : show this help and exits." + exit +fi + +# compiles the sf_buffer_daq +if (( ${MAKE_FLAG} == 1 )); then + echo "Compile flag detected..." + set -e + cd ${BUILD_PATH} && make +fi + +# proceeds to start the receivers +echo "Starting the ${NAME} (config file: ${CONFIG_FILE})" +if [ -f "${ASSEMBLER}" ]; then + if [ -f "${CONFIG_FILE}" ]; then + ${ASSEMBLER} ${CONFIG_FILE} & + else + echo "Something went wrong with the config file..." + exit + fi +else + echo "Something went wrong with the assembler executable..." + exit +fi diff --git a/eiger/control/start_stream.sh b/eiger/control/start_stream.sh new file mode 100755 index 0000000..f0f3791 --- /dev/null +++ b/eiger/control/start_stream.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +MAKE_FLAG=0 +STREAM='/home/hax_l/software/sf_daq_buffer/build/eiger_stream' +CONFIG_FILE='/home/hax_l/software/sf_daq_buffer/eiger/config/eiger.json' +BUILD_PATH='/home/hax_l/software/sf_daq_buffer/build' +STREAM_NAME='eiger' +HELP_FLAG=0 +while getopts m:h:n:c: flag +do + case "${flag}" in + m ) MAKE_FLAG=${OPTARG};; + h ) HELP_FLAG=${OPTARG};; + n ) STREAM_NAME=${OPTARG};; + c ) CONFIG_FILE=${OPTARG};; + esac +done + +# prints help and exits +if (( ${HELP_FLAG} == 1 )); then + echo "Usage : $0 -c -n -m -h " + echo " config_file : detector configuration file." + echo " stream_name : stream name." + echo " make_flag : compile code before running." + echo " help_flag : show this help and exits." + exit +fi + +# compiles the sf_buffer_daq +if (( ${MAKE_FLAG} == 1 )); then + echo "Compile flag detected..." + set -e + cd ${BUILD_PATH} && make +fi + +# proceeds to start the receivers +echo "Starting stream name ${STREAM_NAME} (config file: ${CONFIG_FILE})" +if [ -f "${STREAM}" ]; then + if [ -f "${CONFIG_FILE}" ]; then + ${STREAM} ${CONFIG_FILE} ${STREAM_NAME} & + else + echo "Something went wrong with the config file..." + exit + fi +else + echo "Something went wrong with the stream executable..." + exit +fi diff --git a/eiger/control/start_udp_recvs.sh b/eiger/control/start_udp_recvs.sh new file mode 100755 index 0000000..8702984 --- /dev/null +++ b/eiger/control/start_udp_recvs.sh @@ -0,0 +1,55 @@ +#!/bin/bash +N_UDP_RECVS=4 +MAKE_FLAG=0 +UDP_RECV='/home/hax_l/software/sf_daq_buffer/build/eiger_udp_recv' +CONFIG_FILE='/home/hax_l/software/sf_daq_buffer/eiger/config/eiger.json' +BUILD_PATH='/home/hax_l/software/sf_daq_buffer/build' +HELP_FLAG=0 +while getopts p:n:m:h:u:c: flag +do + case "${flag}" in + p ) PORT=${OPTARG};; + n ) N_UDP_RECVS=${OPTARG};; + m ) MAKE_FLAG=${OPTARG};; + h ) HELP_FLAG=${OPTARG};; + u ) UDP_RECV=${OPTARG};; + c ) CONFIG_FILE=${OPTARG};; + esac +done + +# prints help and exits +if (( ${HELP_FLAG} == 1 )); then + echo "Usage : $0 -n -c -h -u -c " + echo " n_udp_recvs : number of receivers." + echo " compile_flag : compile code before running." + echo " help_flag : show this help and exits." + echo " udp_executable : executable for the udp receivers." + echo " config_file : detector configuration file." + exit +fi + +# compiles the sf_buffer_daq +if (( ${MAKE_FLAG} == 1 )); then + echo "Compile flag detected..." + set -e + cd ${BUILD_PATH} && make +fi + +# proceeds to 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 4 ]; do + ${UDP_RECV} ${CONFIG_FILE} ${COUNTER} & + let COUNTER=COUNTER+1 + sleep 0.5 + done + else + echo "Something went wrong with the udp recv executable..." + exit + fi +else + echo "Something went wrong with the udp recv executable..." + exit +fi diff --git a/eiger/start_eiger_server.sh b/eiger/start_eiger_server.sh index c4ae154..0f41e93 100755 --- a/eiger/start_eiger_server.sh +++ b/eiger/start_eiger_server.sh @@ -1,21 +1,39 @@ #!/bin/bash -# usage ./start_eiger_detector.sh Eiger 1 -if [ $# -lt 1 ] + +# default port 2050 and 2052 +if [ $# -eq 0 ] then + PORT=2050 + PORT_SLAVE=2052 +elif [ $# -eq 1 ] +then + PORT=$1 + PORT_SLAVE=$(( $1 + 2 )) +else echo "Usage : $0 " - echo " tcp port : optional, default 2000" + echo " tcp port : optional, default 2050" exit fi SLS_DET_PACKAGE_PATH='/home/hax_l/software/sf_daq_buffer/slsDetectorPackage/build/bin/' -PORT=2050 -if [ $# == 2 ] -then - PORT=$1 + + +echo "Starting the master eiger virtual detector at port ${PORT}..." + +if [ -f "${SLS_DET_PACKAGE_PATH}eigerDetectorServerMaster_virtual" ]; then + ${SLS_DET_PACKAGE_PATH}eigerDetectorServerMaster_virtual -p ${PORT} & +else + echo "Eiger master was not found at ${SLS_DET_PACKAGE_PATH}." + exit fi -echo "Starting the server..." +echo "Starting the slave bottom eiger virtual detector at port ${PORT_SLAVE}..." -echo ${SLS_DET_PACKAGE_PATH}eigerDetectorServerMaster_virtual -p ${PORT} +if [ -f "${SLS_DET_PACKAGE_PATH}eigerDetectorServerSlaveBottom_virtual" ]; then + ${SLS_DET_PACKAGE_PATH}eigerDetectorServerSlaveBottom_virtual -p ${PORT} & +else + echo "Eiger slave bottom was not found at ${SLS_DET_PACKAGE_PATH}." + exit +fi diff --git a/jf-assembler/src/ZmqPulseSyncReceiver.cpp b/jf-assembler/src/ZmqPulseSyncReceiver.cpp index 33490fd..09da30c 100644 --- a/jf-assembler/src/ZmqPulseSyncReceiver.cpp +++ b/jf-assembler/src/ZmqPulseSyncReceiver.cpp @@ -57,7 +57,7 @@ PulseAndSync ZmqPulseSyncReceiver::get_next_pulse_id() const using namespace date; cout << " [" << std::chrono::system_clock::now(); cout << "] [ZmqPulseSyncReceiver::get_next_pulse_id] modules_in_sync true"; - cout << "] returning pulses[0]"; + cout << "] returning pulses[0] (frame index):" << pulses[0]; cout << endl; #endif return {pulses[0], 0}; diff --git a/jf-assembler/src/main.cpp b/jf-assembler/src/main.cpp index 32cae0e..6d5b0a7 100644 --- a/jf-assembler/src/main.cpp +++ b/jf-assembler/src/main.cpp @@ -5,6 +5,8 @@ #include #include +#include "date.h" +#include #include "assembler_config.hpp" #include "ZmqPulseSyncReceiver.hpp" @@ -40,6 +42,16 @@ int main (int argc, char *argv[]) AssemblerStats stats(config.detector_name, ASSEMBLER_STATS_MODULO); ImageMetadata meta; + + #ifdef DEBUG_OUTPUT + using namespace date; + cout << " [" << std::chrono::system_clock::now(); + cout << "] [Assembler] :"; + cout << " Details of Assembler:"; + cout << "detector_name: " << config.detector_name; + cout << "n_modules: " << config.n_modules; + #endif + while (true) { auto pulse_and_sync = receiver.get_next_pulse_id(); ram_buffer.assemble_image(pulse_and_sync.pulse_id, meta);