From 7fcda636dcd84a6e346fa48552a9b4f625265ad9 Mon Sep 17 00:00:00 2001 From: lhdamiani Date: Tue, 14 Dec 2021 12:01:50 +0100 Subject: [PATCH] bit_depth defined via config file --- CMakeLists.txt | 2 +- core-buffer/include/BufferUtils.hpp | 2 ++ core-buffer/src/BufferUtils.cpp | 1 + eiger/sf-daq-4/config/eiger.json | 1 + eiger/sf-daq-4/control/start_daq.sh | 38 ++++++---------------- jf-assembler/src/main.cpp | 16 ++++----- std-det-writer/include/DetWriterConfig.hpp | 2 ++ std-det-writer/src/main.cpp | 9 ++--- std-stream-send/src/ZmqLiveSender.cpp | 18 +++++++--- std-stream-send/src/main.cpp | 11 +++---- std-udp-recv/include/UdpRecvConfig.hpp | 2 ++ std-udp-recv/src/main.cpp | 11 +++---- std-udp-sync/include/UdpSyncConfig.hpp | 4 ++- 13 files changed, 55 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d4662c..949c49d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ add_subdirectory( EXCLUDE_FROM_ALL) add_subdirectory("core-buffer") -#add_subdirectory("std-stream-send") +add_subdirectory("std-stream-send") add_subdirectory("std-udp-recv") add_subdirectory("std-udp-sync") #add_subdirectory("jf-buffer-writer") diff --git a/core-buffer/include/BufferUtils.hpp b/core-buffer/include/BufferUtils.hpp index 2aa7139..7e4c393 100644 --- a/core-buffer/include/BufferUtils.hpp +++ b/core-buffer/include/BufferUtils.hpp @@ -15,6 +15,7 @@ namespace BufferUtils const int image_height; const int image_width; const int start_udp_port; + const int bit_depth; friend std::ostream& operator <<(std::ostream& os, DetectorConfig const& det_config) @@ -23,6 +24,7 @@ namespace BufferUtils << det_config.detector_type << ' ' << det_config.n_modules << ' ' << det_config.start_udp_port << ' ' + << det_config.bit_depth << ' ' << det_config.image_height << ' ' << det_config.image_width << ' '; } diff --git a/core-buffer/src/BufferUtils.cpp b/core-buffer/src/BufferUtils.cpp index 314f3db..6d906c2 100644 --- a/core-buffer/src/BufferUtils.cpp +++ b/core-buffer/src/BufferUtils.cpp @@ -164,6 +164,7 @@ BufferUtils::DetectorConfig BufferUtils::read_json_config( config_parameters["n_modules"].GetInt(), config_parameters["image_height"].GetInt(), config_parameters["image_width"].GetInt(), + config_parameters["bit_depth"].GetInt(), config_parameters["start_udp_port"].GetInt(), }; } diff --git a/eiger/sf-daq-4/config/eiger.json b/eiger/sf-daq-4/config/eiger.json index 290eb7e..c970c19 100644 --- a/eiger/sf-daq-4/config/eiger.json +++ b/eiger/sf-daq-4/config/eiger.json @@ -4,5 +4,6 @@ "n_modules": 4, "image_height": 514, "image_width": 1030, + "bit_depth": 16, "start_udp_port": 50200 } diff --git a/eiger/sf-daq-4/control/start_daq.sh b/eiger/sf-daq-4/control/start_daq.sh index 61d663a..cc6b1c5 100755 --- a/eiger/sf-daq-4/control/start_daq.sh +++ b/eiger/sf-daq-4/control/start_daq.sh @@ -21,7 +21,6 @@ CONFIG_FILE='/home/hax_l/sf_daq_buffer/eiger/sf-daq-4/config/eiger.json' HELP_FLAG=0 # CONFIGURATION -BIT_DEPTH=16 N_MPI_EXEC=3 STREAM_NAME='streamvis' while getopts h:c:b:m: flag @@ -29,7 +28,6 @@ do case "${flag}" in h ) HELP_FLAG=${OPTARG};; c ) CONFIG_FILE=${OPTARG};; - b ) BIT_DEPTH=${OPTARG};; m ) N_MPIT_EXEC=${OPTARG};; s ) STREAMVIS=${OPTARG};; esac @@ -37,10 +35,9 @@ done # prints help and exits if (( ${HELP_FLAG} == 1 )); then - echo "Usage : $0 -h -c -b -s " + echo "Usage : $0 -h -c -s " echo " help_flag : show this help and exits." echo " config_file : detector configuration file." - echo " bit_depth : detector bit depth." echo " stream name : live stream name." exit fi @@ -74,16 +71,11 @@ 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 + while [ $COUNTER -lt ${N_UDP_RECVS} ]; do + ${BUILD_PATH}${UDP_RECV} ${CONFIG_FILE} ${COUNTER}& + let COUNTER=COUNTER+1 + sleep 0.5 + done else echo "Something went wrong while starting the ${UDP_RECV}..." exit @@ -115,13 +107,8 @@ fi 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 + ${BUILD_PATH}${EIGER_ASSEMBLER} ${CONFIG_FILE} & + sleep 0.5 else echo "Something went wrong while starting the ${EIGER_ASSEMBLER}..." exit @@ -135,12 +122,7 @@ fi echo "Starting the ${STD_STREAM_SEND}..." if [ -f "${BUILD_PATH}${STD_STREAM_SEND}" ]; then if [ -f "${CONFIG_FILE}" ]; then - if [ ${BIT_DEPTH} -ne 0 ]; then - ${BUILD_PATH}${STD_STREAM_SEND} ${CONFIG_FILE} ${BIT_DEPTH} ${STREAM_NAME} & - else - echo "Error: ${BIT_DEPTH} can't be zero..." - exit - fi + ${BUILD_PATH}${STD_STREAM_SEND} ${CONFIG_FILE} ${STREAM_NAME} & else echo "Something went wrong while starting the ${STD_STREAM_SEND}..." exit @@ -157,7 +139,7 @@ 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} & + mpiexec -n ${N_MPI_EXEC} ${BUILD_PATH}${STD_DET_WRITER} ${CONFIG_FILE} & sleep 0.5 else echo "Something went wrong while starting the ${STD_DET_WRITER}..." diff --git a/jf-assembler/src/main.cpp b/jf-assembler/src/main.cpp index 20ddd53..f78e2ef 100644 --- a/jf-assembler/src/main.cpp +++ b/jf-assembler/src/main.cpp @@ -24,28 +24,25 @@ using namespace assembler_config; int main (int argc, char *argv[]) { - if (argc != 3) { + if (argc != 2) { cout << endl; #ifndef USE_EIGER cout << "Usage: jf_assembler [detector_json_filename] " - " [bit_depth]" << endl; + << endl; #else cout << "Usage: eiger_assembler [detector_json_filename] " - " [bit_depth]" << endl; + << endl; #endif cout << "\tdetector_json_filename: detector config file path."; cout << endl; - cout << "\tbit_depth: bit depth of the image."; - cout << endl; exit(-1); } auto config = BufferUtils::read_json_config(string(argv[1])); - const int bit_depth = atoi(argv[2]); auto const stream_name = "assembler"; - const size_t IMAGE_N_BYTES = config.image_height * config.image_width * bit_depth / 8; + const size_t IMAGE_N_BYTES = config.image_height * config.image_width * config.bit_depth / 8; auto ctx = zmq_ctx_new(); zmq_ctx_set(ctx, ZMQ_IO_THREADS, ASSEMBLER_ZMQ_IO_THREADS); auto sender = BufferUtils::bind_socket( @@ -62,13 +59,14 @@ int main (int argc, char *argv[]) cout << " || n_modules: " << config.n_modules; cout << " || img width: " << config.image_width; cout << " || img height: " << config.image_height; + cout << " || bit_depth: " << config.bit_depth; cout << endl; #endif - const size_t FRAME_N_BYTES = MODULE_N_PIXELS * bit_depth / 8; + const size_t FRAME_N_BYTES = MODULE_N_PIXELS * config.bit_depth / 8; const size_t N_PACKETS_PER_FRAME = FRAME_N_BYTES / DATA_BYTES_PER_PACKET; - EigerAssembler assembler(config.n_modules, bit_depth, + EigerAssembler assembler(config.n_modules, config.bit_depth, config.image_width, config.image_height); #ifdef DEBUG_OUTPUT diff --git a/std-det-writer/include/DetWriterConfig.hpp b/std-det-writer/include/DetWriterConfig.hpp index 6efae60..f7efa15 100644 --- a/std-det-writer/include/DetWriterConfig.hpp +++ b/std-det-writer/include/DetWriterConfig.hpp @@ -19,12 +19,14 @@ struct DetWriterConfig { config_parameters["detector_name"].GetString(), config_parameters["image_height"].GetInt(), config_parameters["image_width"].GetInt(), + config_parameters["bit_depth"].GetInt(), }; } const std::string detector_name; const int image_height; const int image_width; + const int bit_depth; }; diff --git a/std-det-writer/src/main.cpp b/std-det-writer/src/main.cpp index bbd9b4e..9a4a7ca 100644 --- a/std-det-writer/src/main.cpp +++ b/std-det-writer/src/main.cpp @@ -18,19 +18,16 @@ using namespace live_writer_config; int main (int argc, char *argv[]) { - if (argc != 3) { + if (argc != 2) { cout << endl; - cout << "Usage: std_det_writer [detector_json_filename]" - " [bit_depth]" << endl; + cout << "Usage: std_det_writer [detector_json_filename]" << endl; cout << "\tdetector_json_filename: detector config file path." << endl; - cout << "\tbit_depth: bit depth of the incoming udp packets." << endl; cout << endl; exit(-1); } auto const config = DetWriterConfig::from_json_file(string(argv[1])); - const int bit_depth = atoi(argv[2]); MPI_Init(nullptr, nullptr); @@ -45,7 +42,7 @@ int main (int argc, char *argv[]) auto receiver = BufferUtils::connect_socket( ctx, config.detector_name, "writer_agent"); - const size_t IMAGE_N_BYTES = config.image_width * config.image_height * bit_depth / 8; + const size_t IMAGE_N_BYTES = config.image_width * config.image_height * config.bit_depth / 8; RamBuffer image_buffer(config.detector_name + "_assembler", sizeof(ImageMetadata), IMAGE_N_BYTES, 1, RAM_BUFFER_N_SLOTS); diff --git a/std-stream-send/src/ZmqLiveSender.cpp b/std-stream-send/src/ZmqLiveSender.cpp index f8b5039..a7da4f5 100644 --- a/std-stream-send/src/ZmqLiveSender.cpp +++ b/std-stream-send/src/ZmqLiveSender.cpp @@ -50,11 +50,21 @@ void ZmqLiveSender::send(const ImageMetadata& meta, const char *data, // TODO: Here we need to send to streamvis and live analysis metadata(probably need to operate still on them) and data(not every frame) header.AddMember("frame", meta.id, header_alloc); - header.AddMember("is_good_frame", meta.status, header_alloc); + header.AddMember("pulse_id", meta.id, header_alloc); + // image status convention 0 == good, 1 == frames missing, 2 == different ids + header.AddMember("is_good_frame", (meta.status == 0) ? 1 : 0, header_alloc); + header.AddMember("flip_data", true, header_alloc); - rapidjson::Value detector_name; - detector_name.SetString(det_name_.c_str(), header_alloc); - header.AddMember("detector_name", detector_name, header_alloc); + + #ifdef USE_EIGER + header.AddMember("detector_name", "Eiger", header_alloc); + #else + rapidjson::Value detector_name; + detector_name.SetString(det_name_.c_str(), header_alloc); + header.AddMember("detector_name", detector_name, header_alloc); + #endif + + header.AddMember("htype", "array-1.0", header_alloc); diff --git a/std-stream-send/src/main.cpp b/std-stream-send/src/main.cpp index 4e4f651..f56b164 100644 --- a/std-stream-send/src/main.cpp +++ b/std-stream-send/src/main.cpp @@ -7,6 +7,7 @@ #include "stream_config.hpp" #include "ZmqLiveSender.hpp" +#include using namespace std; using namespace stream_config; @@ -14,12 +15,11 @@ using namespace buffer_config; int main (int argc, char *argv[]) { - if (argc != 4) { + if (argc != 3) { cout << endl; cout << "Usage: std_stream_send [detector_json_filename]" - " [bit_depth] [stream_address]" << endl; + " [stream_address]" << endl; cout << "\tdetector_json_filename: detector config file path." << endl; - cout << "\tbit_depth: bit depth of the incoming udp packets." << endl; cout << "\tstream_address: address to bind the output stream." << endl; cout << endl; @@ -27,7 +27,6 @@ int main (int argc, char *argv[]) } auto config = BufferUtils::read_json_config(string(argv[1])); - const int bit_depth = atoi(argv[2]); const auto stream_address = string(argv[3]); auto ctx = zmq_ctx_new(); @@ -37,7 +36,7 @@ int main (int argc, char *argv[]) auto receiver_assembler = BufferUtils::connect_socket( ctx, config.detector_name, "assembler"); - const size_t IMAGE_N_BYTES = config.image_height * config.image_width * bit_depth / 8; + const size_t IMAGE_N_BYTES = config.image_height * config.image_width * config.bit_depth / 8; RamBuffer image_buffer(config.detector_name + "_assembler", sizeof(ImageMetadata), IMAGE_N_BYTES, @@ -52,7 +51,7 @@ int main (int argc, char *argv[]) // gets the image data char* dst_data = image_buffer.get_slot_data(meta.id); // sends the json metadata with the data - sender.send(meta, dst_data, IMAGE_N_BYTES); + sender.send(meta, dst_data , IMAGE_N_BYTES); } } diff --git a/std-udp-recv/include/UdpRecvConfig.hpp b/std-udp-recv/include/UdpRecvConfig.hpp index 847439b..c22a01b 100644 --- a/std-udp-recv/include/UdpRecvConfig.hpp +++ b/std-udp-recv/include/UdpRecvConfig.hpp @@ -19,6 +19,7 @@ struct UdpRecvConfig { config_parameters["detector_name"].GetString(), config_parameters["detector_type"].GetString(), config_parameters["n_modules"].GetInt(), + config_parameters["bit_depth"].GetInt(), config_parameters["start_udp_port"].GetInt(), }; } @@ -27,6 +28,7 @@ struct UdpRecvConfig { const std::string detector_type; const int n_modules; const int start_udp_port; + const int bit_depth; }; diff --git a/std-udp-recv/src/main.cpp b/std-udp-recv/src/main.cpp index c9dc862..4d83a90 100644 --- a/std-udp-recv/src/main.cpp +++ b/std-udp-recv/src/main.cpp @@ -18,21 +18,18 @@ using namespace BufferUtils; int main (int argc, char *argv[]) { - if (argc != 4) { + if (argc != 3) { cout << endl; - cout << "Usage: std_udp_recv [detector_json_filename] [module_id] " - "[bit_depth]"; + cout << "Usage: std_udp_recv [detector_json_filename] [module_id] "; cout << endl; cout << "\tdetector_json_filename: detector config file path." << endl; cout << "\tmodule_id: id of the module for this process." << endl; - cout << "\tbit_depth: bit depth of the incoming udp packets." << endl; cout << endl; exit(-1); } const auto config = UdpRecvConfig::from_json_file(string(argv[1])); const int module_id = atoi(argv[2]); - const int bit_depth = atoi(argv[3]); if (DETECTOR_TYPE != config.detector_type) { throw runtime_error("UDP recv version for " + DETECTOR_TYPE + @@ -40,7 +37,7 @@ int main (int argc, char *argv[]) { } const auto udp_port = config.start_udp_port + module_id; - const size_t FRAME_N_BYTES = MODULE_N_PIXELS * bit_depth / 8; + const size_t FRAME_N_BYTES = MODULE_N_PIXELS * config.bit_depth / 8; const size_t N_PACKETS_PER_FRAME = FRAME_N_BYTES / DATA_BYTES_PER_PACKET; FrameUdpReceiver receiver(udp_port, N_PACKETS_PER_FRAME); @@ -54,7 +51,7 @@ int main (int argc, char *argv[]) { ModuleFrame meta; meta.module_id = module_id; - meta.bit_depth = bit_depth; + meta.bit_depth = config.bit_depth; char* data = new char[FRAME_N_BYTES]; diff --git a/std-udp-sync/include/UdpSyncConfig.hpp b/std-udp-sync/include/UdpSyncConfig.hpp index 89d735a..293b600 100644 --- a/std-udp-sync/include/UdpSyncConfig.hpp +++ b/std-udp-sync/include/UdpSyncConfig.hpp @@ -17,12 +17,14 @@ struct UdpSyncConfig { return { config_parameters["detector_name"].GetString(), - config_parameters["n_modules"].GetInt() + config_parameters["n_modules"].GetInt(), + config_parameters["bit_depth"].GetInt() }; } const std::string detector_name; const int n_modules; + const int bit_depth; };