diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 8caee7b71..82335f29f 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -19,78 +19,7 @@ class MySocketTCP; #define NCHIPSMAX 10 #define NCHANSMAX 65536 #define NDACSMAX 16 -/** - * parameter list that has to be initialized depending on the detector type - */ -struct detParameters { - int nChanX{0}; - int nChanY{0}; - int nChipX{0}; - int nChipY{0}; - int nDacs{0}; - int dynamicRange{0}; - int nGappixelsX{0}; - int nGappixelsY{0}; - detParameters(){} - detParameters(slsDetectorDefs::detectorType type){ - switch (type) { - case slsDetectorDefs::detectorType::GOTTHARD: - nChanX = 128; - nChanY = 1; - nChipX = 10; - nChipY = 1; - nDacs = 8; - dynamicRange = 16; - nGappixelsX = 0; - nGappixelsY = 0; - break; - case slsDetectorDefs::detectorType::JUNGFRAU: - nChanX = 256; - nChanY = 256; - nChipX = 4; - nChipY = 2; - nDacs = 8; - dynamicRange = 16; - nGappixelsX = 0; - nGappixelsY = 0; - break; - case slsDetectorDefs::detectorType::CHIPTESTBOARD: - nChanX = 36; - nChanY = 1; - nChipX = 1; - nChipY = 1; - nDacs = 24; - dynamicRange = 16; - nGappixelsX = 0; - nGappixelsY = 0; - break; - case slsDetectorDefs::detectorType::MOENCH: - nChanX = 32; - nChanY = 1; - nChipX = 1; - nChipY = 1; - nDacs = 8; - dynamicRange = 16; - nGappixelsX = 0; - nGappixelsY = 0; - break; - case slsDetectorDefs::detectorType::EIGER: - nChanX = 256; - nChanY = 256; - nChipX = 4; - nChipY = 1; - nDacs = 16; - dynamicRange = 16; - nGappixelsX = 6; - nGappixelsY = 1; - break; - default: - throw sls::RuntimeError("Unknown detector type! " + - slsDetectorDefs::detectorTypeToString(type)); - } - } -}; /** * @short structure allocated in shared memory to store detector settings for IPC and cache diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 8a25de884..2062e9451 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -15,6 +15,7 @@ #include #ifdef __cplusplus +#include "sls_detector_exceptions.h" #include #include #endif @@ -62,33 +63,6 @@ #define DEFAULT_STREAMING_TIMER_IN_MS 200 -/** - @short structure for a detector module - - should not be used by unexperienced users - - \see :: moduleRegisterBit ::chipRegisterBit :channelRegisterBit - - @li reg is the module register (e.g. dynamic range? see moduleRegisterBit) - @li dacs is the pointer to the array of dac values (in V) - @li adcs is the pointer to the array of adc values (in V) - @li chipregs is the pointer to the array of chip registers - @li chanregs is the pointer to the array of channel registers - @li gain is the module gain - @li offset is the module offset -*/ -typedef struct { - int serialnumber; /**< is the module serial number */ - int nchan; /**< is the number of channels on the module*/ - int nchip; /**< is the number of chips on the module */ - int ndac; /**< is the number of dacs on the module */ - int reg; /**< is the module register settings (gain level) */ - int iodelay; /**< iodelay */ - int tau; /**< tau */ - int eV; /**< threshold energy */ - int *dacs; /**< is the pointer to the array of the dac values (in V) */ - int *chanregs; /**< is the pointer to the array of the channel registers */ -} sls_detector_module; typedef char mystring[MAX_STR_LENGTH]; @@ -959,3 +933,133 @@ protected: }; #endif ; + +#ifdef __cplusplus +struct detParameters { + int nChanX{0}; + int nChanY{0}; + int nChipX{0}; + int nChipY{0}; + int nDacs{0}; + int dynamicRange{0}; + int nGappixelsX{0}; + int nGappixelsY{0}; + + detParameters() {} + detParameters(slsDetectorDefs::detectorType type) { + switch (type) { + case slsDetectorDefs::detectorType::GOTTHARD: + nChanX = 128; + nChanY = 1; + nChipX = 10; + nChipY = 1; + nDacs = 8; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::JUNGFRAU: + nChanX = 256; + nChanY = 256; + nChipX = 4; + nChipY = 2; + nDacs = 8; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::CHIPTESTBOARD: + nChanX = 36; + nChanY = 1; + nChipX = 1; + nChipY = 1; + nDacs = 24; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::MOENCH: + nChanX = 32; + nChanY = 1; + nChipX = 1; + nChipY = 1; + nDacs = 8; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::EIGER: + nChanX = 256; + nChanY = 256; + nChipX = 4; + nChipY = 1; + nDacs = 16; + dynamicRange = 16; + nGappixelsX = 6; + nGappixelsY = 1; + break; + default: + throw sls::RuntimeError( + "Unknown detector type! " + + slsDetectorDefs::detectorTypeToString(type)); + } + } +}; +#endif + +/** + @short structure for a detector module + + should not be used by unexperienced users + + \see :: moduleRegisterBit ::chipRegisterBit :channelRegisterBit + + @li reg is the module register (e.g. dynamic range? see moduleRegisterBit) + @li dacs is the pointer to the array of dac values (in V) + @li adcs is the pointer to the array of adc values (in V) + @li chipregs is the pointer to the array of chip registers + @li chanregs is the pointer to the array of channel registers + @li gain is the module gain + @li offset is the module offset +*/ +#ifdef __cplusplus +struct sls_detector_module { +#else +typedef struct { +#endif + int serialnumber; /**< is the module serial number */ + int nchan; /**< is the number of channels on the module*/ + int nchip; /**< is the number of chips on the module */ + int ndac; /**< is the number of dacs on the module */ + int reg; /**< is the module register settings (gain level) */ + int iodelay; /**< iodelay */ + int tau; /**< tau */ + int eV; /**< threshold energy */ + int *dacs; /**< is the pointer to the array of the dac values (in V) */ + int *chanregs; /**< is the pointer to the array of the channel registers */ + +#ifdef __cplusplus + + sls_detector_module() + : serialnumber(0), nchan(0), nchip(0), ndac(0), reg(0), iodelay(0), + tau(0), eV(0), dacs(nullptr), chanregs(nullptr) {} + sls_detector_module(slsDetectorDefs::detectorType type) { + detParameters parameters{type}; + int nch = parameters.nChanX * parameters.nChanY; + int nc = parameters.nChipX * parameters.nChipY; + int nd = parameters.nDacs; + + ndac = nd; + nchip = nc; + nchan = nch * nc; + dacs = new int[nd]; + chanregs = new int[nch * nc]; + } + ~sls_detector_module(){ + delete[] dacs; + delete[] chanregs; + } +}; +#else +} sls_detector_module; +#endif diff --git a/slsSupportLib/tests/CMakeLists.txt b/slsSupportLib/tests/CMakeLists.txt index 6164cc13d..dad82546a 100755 --- a/slsSupportLib/tests/CMakeLists.txt +++ b/slsSupportLib/tests/CMakeLists.txt @@ -5,4 +5,5 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-network_utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-string_utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-Timer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test-sls_detector_defs.cpp ) \ No newline at end of file diff --git a/slsSupportLib/tests/test-sls_detector_defs.cpp b/slsSupportLib/tests/test-sls_detector_defs.cpp new file mode 100644 index 000000000..4d9ba20c9 --- /dev/null +++ b/slsSupportLib/tests/test-sls_detector_defs.cpp @@ -0,0 +1,33 @@ +#include "catch.hpp" +#include "sls_detector_defs.h" +#include "slsDetector.h" + +using dt = slsDetectorDefs::detectorType; + +TEST_CASE("sls_detector_module default construction", "[support][new]") { + sls_detector_module m; + CHECK(m.serialnumber == 0); + CHECK(m.nchan == 0); + CHECK(m.nchip == 0); + CHECK(m.ndac == 0); + CHECK(m.reg == 0); + CHECK(m.iodelay == 0); + CHECK(m.tau == 0); + CHECK(m.eV == 0); + CHECK(m.dacs == nullptr); + CHECK(m.chanregs == nullptr); +} + +TEST_CASE("sls_detector_module from type", "[support][new]") { + sls_detector_module m(dt::EIGER); + CHECK(m.serialnumber == 0); + CHECK(m.nchan == 256*256*4); + CHECK(m.nchip == 4); + CHECK(m.ndac == 16); + CHECK(m.reg == 0); + CHECK(m.iodelay == 0); + CHECK(m.tau == 0); + CHECK(m.eV == 0); + CHECK(m.dacs != nullptr); + CHECK(m.chanregs != nullptr); +} \ No newline at end of file