mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 03:10:02 +02:00
Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer
This commit is contained in:
commit
ec9f360c75
@ -38,6 +38,7 @@ option (SLS_USE_HDF5 "HDF5 File format" OFF)
|
|||||||
option (SLS_USE_TEXTCLIENT "Text Client" OFF)
|
option (SLS_USE_TEXTCLIENT "Text Client" OFF)
|
||||||
option (SLS_USE_RECEIVER "Receiver" OFF)
|
option (SLS_USE_RECEIVER "Receiver" OFF)
|
||||||
option (SLS_USE_GUI "GUI" OFF)
|
option (SLS_USE_GUI "GUI" OFF)
|
||||||
|
option (SLS_USE_MYTHEN302_CTB_RECEIVER "Mythen302 CTB Receiver" OFF)
|
||||||
option (SLS_USE_TESTS "TESTS" ON)
|
option (SLS_USE_TESTS "TESTS" ON)
|
||||||
option (SLS_USE_INTEGRATION_TESTS "Integration Tests" ON)
|
option (SLS_USE_INTEGRATION_TESTS "Integration Tests" ON)
|
||||||
option(SLS_USE_SANITIZER "Sanitizers for debugging" OFF)
|
option(SLS_USE_SANITIZER "Sanitizers for debugging" OFF)
|
||||||
@ -137,6 +138,7 @@ if (SLS_USE_TEXTCLIENT)
|
|||||||
add_subdirectory(slsDetectorSoftware)
|
add_subdirectory(slsDetectorSoftware)
|
||||||
endif (SLS_USE_TEXTCLIENT)
|
endif (SLS_USE_TEXTCLIENT)
|
||||||
|
|
||||||
|
|
||||||
if (SLS_USE_RECEIVER)
|
if (SLS_USE_RECEIVER)
|
||||||
if (SLS_USE_HDF5)
|
if (SLS_USE_HDF5)
|
||||||
find_package(HDF5 1.10 COMPONENTS CXX REQUIRED)
|
find_package(HDF5 1.10 COMPONENTS CXX REQUIRED)
|
||||||
@ -174,4 +176,3 @@ if(SLS_MASTER_PROJECT)
|
|||||||
# Generate and install package config file and version
|
# Generate and install package config file and version
|
||||||
include(cmake/package_config.cmake)
|
include(cmake/package_config.cmake)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
50
cmk.sh
50
cmk.sh
@ -8,6 +8,7 @@ RECEIVER=0
|
|||||||
GUI=0
|
GUI=0
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
PYTHON=0
|
PYTHON=0
|
||||||
|
SPECIAL_RECEIVER_TYPE=0
|
||||||
|
|
||||||
|
|
||||||
CLEAN=0
|
CLEAN=0
|
||||||
@ -16,7 +17,7 @@ CMAKE_PRE=""
|
|||||||
CMAKE_POST=""
|
CMAKE_POST=""
|
||||||
|
|
||||||
usage() { echo -e "
|
usage() { echo -e "
|
||||||
Usage: $0 [-c] [-b] [-p] [e] [t] [r] [g] [-h] [-d <HDF5 directory>] [-j]
|
Usage: $0 [-c] [-b] [-p] [e] [t] [r] [g] [-h] [-d <HDF5 directory>] [-j] <Number of threads> [-s] <Special Receiver Type>
|
||||||
-[no option]: only make
|
-[no option]: only make
|
||||||
-c: Clean
|
-c: Clean
|
||||||
-b: Builds/Rebuilds CMake files normal mode
|
-b: Builds/Rebuilds CMake files normal mode
|
||||||
@ -28,6 +29,7 @@ Usage: $0 [-c] [-b] [-p] [e] [t] [r] [g] [-h] [-d <HDF5 directory>] [-j]
|
|||||||
-g: Build/Rebuilds only gui
|
-g: Build/Rebuilds only gui
|
||||||
-j: Number of threads to compile through
|
-j: Number of threads to compile through
|
||||||
-e: Debug mode
|
-e: Debug mode
|
||||||
|
-s: Special Receiver Type (1-Mythen302)
|
||||||
|
|
||||||
Rebuild when you switch to a new build and compile in parallel:
|
Rebuild when you switch to a new build and compile in parallel:
|
||||||
./cmk.sh -bj5
|
./cmk.sh -bj5
|
||||||
@ -63,7 +65,7 @@ For rebuilding only certain sections
|
|||||||
|
|
||||||
" ; exit 1; }
|
" ; exit 1; }
|
||||||
|
|
||||||
while getopts ":bpchd:j:trge" opt ; do
|
while getopts ":bpchd:j:trges:" opt ; do
|
||||||
case $opt in
|
case $opt in
|
||||||
b)
|
b)
|
||||||
echo "Building of CMake files Required"
|
echo "Building of CMake files Required"
|
||||||
@ -110,6 +112,10 @@ while getopts ":bpchd:j:trge" opt ; do
|
|||||||
echo "Compiling Options: Debug"
|
echo "Compiling Options: Debug"
|
||||||
DEBUG=1
|
DEBUG=1
|
||||||
;;
|
;;
|
||||||
|
s)
|
||||||
|
echo "Special Receiver Type: $OPTARG"
|
||||||
|
SPECIAL_RECEIVER_TYPE=$OPTARG
|
||||||
|
;;
|
||||||
\?)
|
\?)
|
||||||
echo "Invalid option: -$OPTARG"
|
echo "Invalid option: -$OPTARG"
|
||||||
usage
|
usage
|
||||||
@ -123,30 +129,36 @@ while getopts ":bpchd:j:trge" opt ; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
#special receiver type
|
||||||
|
if [ $SPECIAL_RECEIVER_TYPE -eq 1 ]; then
|
||||||
|
CMAKE_POST+=" -DSLS_USE_MYTHEN302_CTB_RECEIVER=ON "
|
||||||
|
echo "Enabling Compile Option: Mythen302 CTB Receiver"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#python
|
||||||
if [ $PYTHON -eq 1 ]; then
|
if [ $PYTHON -eq 1 ]; then
|
||||||
CMAKE_POST+=" -DSLS_USE_PYTHON=ON "
|
CMAKE_POST+=" -DSLS_USE_PYTHON=ON "
|
||||||
echo "Enabling Compile Option: Python"
|
echo "Enabling Compile Option: Python"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ $TEXTCLIENT -eq 0 ] && [ $RECEIVER -eq 0 ] && [ $GUI -eq 0 ]; then
|
if [ $TEXTCLIENT -eq 0 ] && [ $RECEIVER -eq 0 ] && [ $GUI -eq 0 ]; then
|
||||||
#CMAKE_POST+=" -DSLS_USE_TEXTCLIENT=ON -DSLS_USE_RECEIVER=ON -DSLS_USE_GUI=ON "
|
#CMAKE_POST+=" -DSLS_USE_TEXTCLIENT=ON -DSLS_USE_RECEIVER=ON -DSLS_USE_GUI=ON "
|
||||||
CMAKE_POST+=" -DSLS_USE_TEXTCLIENT=ON -DSLS_USE_RECEIVER=ON -DSLS_USE_GUI=OFF "
|
CMAKE_POST+=" -DSLS_USE_TEXTCLIENT=ON -DSLS_USE_RECEIVER=ON -DSLS_USE_GUI=OFF "
|
||||||
echo "Enabling Compile Option: TextClient, Receiver and GUI"
|
echo "Enabling Compile Option: TextClient, Receiver and GUI"
|
||||||
else
|
else
|
||||||
if [ $TEXTCLIENT -eq 1 ]; then
|
if [ $TEXTCLIENT -eq 1 ]; then
|
||||||
CMAKE_POST+=" -DSLS_USE_TEXTCLIENT=ON "
|
CMAKE_POST+=" -DSLS_USE_TEXTCLIENT=ON "
|
||||||
echo "Enabling Compile Option: TextClient"
|
echo "Enabling Compile Option: TextClient"
|
||||||
fi
|
fi
|
||||||
if [ $RECEIVER -eq 1 ]; then
|
if [ $RECEIVER -eq 1 ]; then
|
||||||
CMAKE_POST+=" -DSLS_USE_RECEIVER=ON "
|
CMAKE_POST+=" -DSLS_USE_RECEIVER=ON "
|
||||||
echo "Enabling Compile Option: Receiver"
|
echo "Enabling Compile Option: Receiver"
|
||||||
fi
|
fi
|
||||||
if [ $GUI -eq 1 ]; then
|
if [ $GUI -eq 1 ]; then
|
||||||
CMAKE_POST+=" -DSLS_USE_GUI=ON "
|
CMAKE_POST+=" -DSLS_USE_GUI=ON "
|
||||||
echo "Enabling Compile Option: GUI"
|
echo "Enabling Compile Option: GUI"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,9 +61,20 @@ set_target_properties(slsReceiverShared PROPERTIES
|
|||||||
PUBLIC_HEADER "${PUBLICHEADERS}"
|
PUBLIC_HEADER "${PUBLICHEADERS}"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(slsReceiver
|
|
||||||
src/main.cpp
|
if (SLS_USE_MYTHEN302_CTB_RECEIVER)
|
||||||
)
|
add_executable(slsReceiver
|
||||||
|
src/mainCustomized.cpp
|
||||||
|
)
|
||||||
|
add_definitions(
|
||||||
|
-DMYTHEN302
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
add_executable(slsReceiver
|
||||||
|
src/main.cpp
|
||||||
|
)
|
||||||
|
endif (SLS_USE_MYTHEN302_CTB_RECEIVER)
|
||||||
|
|
||||||
set_target_properties(slsReceiver PROPERTIES
|
set_target_properties(slsReceiver PROPERTIES
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||||
)
|
)
|
||||||
|
164
slsReceiverSoftware/src/mainCustomized.cpp
Executable file
164
slsReceiverSoftware/src/mainCustomized.cpp
Executable file
@ -0,0 +1,164 @@
|
|||||||
|
/* A simple server in the internet domain using TCP
|
||||||
|
The port number is passed as an argument */
|
||||||
|
|
||||||
|
#include "sls_detector_defs.h"
|
||||||
|
#include "slsReceiverUsers.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string.h>
|
||||||
|
#include <signal.h> //SIGINT
|
||||||
|
#include <cstdlib> //system
|
||||||
|
#include <sys/types.h> //wait
|
||||||
|
#include <sys/wait.h> //wait
|
||||||
|
#include <unistd.h> //usleep
|
||||||
|
#include <syscall.h>
|
||||||
|
#include <map>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
|
bool keeprunning;
|
||||||
|
int ctbOffset = 0;
|
||||||
|
|
||||||
|
void sigInterruptHandler(int p){
|
||||||
|
keeprunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MYTHEN302
|
||||||
|
void GetData(char* metadata, char* datapointer, uint32_t& datasize, void* p) {
|
||||||
|
// remove the offset in datasize
|
||||||
|
int offset = ctbOffset * sizeof(uint64_t);
|
||||||
|
datasize -= offset;
|
||||||
|
|
||||||
|
constexpr int dynamicRange = 24;
|
||||||
|
constexpr int numSamples = 32 * 3; // 32 channels * 3 counters = 96
|
||||||
|
constexpr int numCounters = numSamples * 2; // 2 strips
|
||||||
|
// validate datasize
|
||||||
|
{
|
||||||
|
FILE_LOG(logDEBUG) << "Datasize after removing offset:" << datasize;
|
||||||
|
const double dataNumSamples =
|
||||||
|
((double)datasize / (double)sizeof(uint64_t)) / (double)dynamicRange; // 2304 / 24 = 96
|
||||||
|
if (dataNumSamples - numSamples) {
|
||||||
|
FILE_LOG(logERROR) << "Number of samples do not match, Expected "
|
||||||
|
<< numSamples << ", got " << dataNumSamples;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// source
|
||||||
|
uint64_t* source = (uint64_t*)datapointer;
|
||||||
|
// remove the offset from source
|
||||||
|
source += offset;
|
||||||
|
// destination
|
||||||
|
auto result = new int[numCounters];
|
||||||
|
auto destStrip0 = result;
|
||||||
|
auto destStrip1 = result + numSamples;
|
||||||
|
constexpr int bit_index0 = 6;
|
||||||
|
constexpr int bit_index1 = 17;
|
||||||
|
constexpr int mask0 = (1 << bit_index0);
|
||||||
|
constexpr int mask1 = (1 << bit_index1);
|
||||||
|
|
||||||
|
for (int j = 0; j < numSamples; ++j) {
|
||||||
|
for (int i = 0; i < dynamicRange; ++i) {
|
||||||
|
int bit0 = (*source & mask0) >> bit_index0;
|
||||||
|
int bit1 = (*source++ & mask1) >> bit_index1;
|
||||||
|
*destStrip0 |= bit0 << i;
|
||||||
|
*destStrip1 |= bit1 << i;
|
||||||
|
}
|
||||||
|
destStrip0++;
|
||||||
|
destStrip1++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the size to be written to file & overwrite data in memory
|
||||||
|
datasize = numCounters * sizeof(int);
|
||||||
|
memcpy(datapointer, (char*)result, datasize);
|
||||||
|
FILE_LOG(logDEBUG) << "Modified Size: " << datasize;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
// options
|
||||||
|
std::map<std::string, std::string> configuration_map;
|
||||||
|
//parse command line for config
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{"ctb_offset", required_argument, nullptr, 'o'},
|
||||||
|
{nullptr, 0, nullptr, 0}
|
||||||
|
};
|
||||||
|
//initialize global optind variable (required when instantiating multiple receivers in the same process)
|
||||||
|
optind = 1;
|
||||||
|
// getopt_long stores the option index here.
|
||||||
|
int option_index = 0;
|
||||||
|
int c = 0;
|
||||||
|
while ( c != -1 ) {
|
||||||
|
c = getopt_long (argc, argv, "hvf:t:o:", long_options, &option_index);
|
||||||
|
// Detect the end of the options.
|
||||||
|
if (c == -1)
|
||||||
|
break;
|
||||||
|
switch(c) {
|
||||||
|
case 'o':
|
||||||
|
sscanf(optarg, "%d", &ctbOffset);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef MYTHEN302
|
||||||
|
FILE_LOG(logINFOGREEN) << "Mythen 302 Receiver";
|
||||||
|
FILE_LOG(logINFO) << "CTB Offset: " << ctbOffset;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
keeprunning = true;
|
||||||
|
FILE_LOG(logINFOBLUE) << "Created [ Tid: " << syscall(SYS_gettid) << " ]";
|
||||||
|
|
||||||
|
// Catch signal SIGINT to close files and call destructors properly
|
||||||
|
struct sigaction sa;
|
||||||
|
sa.sa_flags = 0; // no flags
|
||||||
|
sa.sa_handler = sigInterruptHandler; // handler function
|
||||||
|
sigemptyset(&sa.sa_mask); // dont block additional signals during invocation
|
||||||
|
// of handler
|
||||||
|
if (sigaction(SIGINT, &sa, nullptr) == -1) {
|
||||||
|
FILE_LOG(logERROR) << "Could not set handler function for SIGINT";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if socket crash, ignores SISPIPE, prevents global signal handler
|
||||||
|
// subsequent read/write to socket gives error - must handle locally
|
||||||
|
struct sigaction asa;
|
||||||
|
asa.sa_flags=0; // no flags
|
||||||
|
asa.sa_handler=SIG_IGN; // handler function
|
||||||
|
sigemptyset(&asa.sa_mask); // dont block additional signals during invocation of handler
|
||||||
|
if (sigaction(SIGPIPE, &asa, nullptr) == -1) {
|
||||||
|
FILE_LOG(logERROR) << "Could not set handler function for SIGPIPE";
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = slsDetectorDefs::OK;
|
||||||
|
slsReceiverUsers *receiver = new slsReceiverUsers(argc, argv, ret);
|
||||||
|
if(ret==slsDetectorDefs::FAIL){
|
||||||
|
delete receiver;
|
||||||
|
FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//register callbacks
|
||||||
|
receiver->registerCallBackRawDataModifyReady(GetData, NULL);
|
||||||
|
|
||||||
|
//start tcp server thread
|
||||||
|
if (receiver->start() == slsDetectorDefs::FAIL){
|
||||||
|
delete receiver;
|
||||||
|
FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE_LOG(logINFO) << "Ready ... ";
|
||||||
|
FILE_LOG(logINFO) << "[ Press \'Ctrl+c\' to exit ]";
|
||||||
|
while(keeprunning)
|
||||||
|
pause();
|
||||||
|
|
||||||
|
delete receiver;
|
||||||
|
FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
|
||||||
|
FILE_LOG(logINFO) << "Exiting Receiver";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -44,13 +44,16 @@ slsReceiver::slsReceiver(int argc, char *argv[]):
|
|||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
while ( c != -1 ){
|
while ( c != -1 ){
|
||||||
c = getopt_long (argc, argv, "hvf:t:", long_options, &option_index);
|
c = getopt_long (argc, argv, "hvf:t:o:", long_options, &option_index);
|
||||||
|
|
||||||
// Detect the end of the options.
|
// Detect the end of the options.
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch(c){
|
switch(c){
|
||||||
|
// reserved for ctb receiver users
|
||||||
|
case 'o':
|
||||||
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
sscanf(optarg, "%d", &tcpip_port_no);
|
sscanf(optarg, "%d", &tcpip_port_no);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user