diff --git a/README.md b/README.md index a646d587a..abee0e773 100755 --- a/README.md +++ b/README.md @@ -1,102 +1,233 @@ -### Note +## Dependencies +Before building from source make sure that you have the [software wiki](https://slsdetectorgroup.github.io/devdoc/dependencies.html) installed. If installing using conda, conda will manage the dependencies. Avoid also installing packages with pip. -Please do not update to any xxxx.xx.xx.dev0 tags. They are not releases, but tags for internal usage. -Use only releases with tags such as x.x.x or x.x.x-rcx. +## Documentaion +Detailed documentation can be found in the [software wiki](https://slsdetectorgroup.github.io/devdoc/index.html) and on the [official site](https://www.psi.ch/en/detectors/software). -### Documentation -##### 5.0.0 - Latest Release -Detailed documentation on the latest release can be found in the [software wiki](https://slsdetectorgroup.github.io/devdoc/index.html) and on the [official site](https://www.psi.ch/en/detectors/software). +## Installation -##### Older Releases -Documentation is found in the package. +### 1. Install binaries using conda +Conda is not only useful to manage python environments but can also +be used as a user space package manager. Dates in the tag (for eg. 2020.07.23.dev0) +are from the developer branch. Please use released tags for stability. + +We have three different packages available: +* **slsdetlib** shared libraries and command line utilities +* **slsdetgui** GUI +* **slsdet** Python bindings -### Binaries -Binaries for the slsDetectorPackage are available through conda. ``` -#Add conda channels +#Add channels for dependencies and our library conda config --add channels conda-forge conda config --add channels slsdetectorgroup conda config --set channel_priority strict -conda install slsdetlib #only shared lib and command line -conda install slsdet #python bindings (includes slsdetlib) -conda install slsdetgui #gui (includes qt4) - -#Install specific version -conda install slsdet=2020.03.02.dev0 #developer version from 3 March 2020 +#create and activate an environment with our library +#replace 6.1.1 with the required tag +conda create -n myenv slsdetlib=6.1.1 +conda activate myenv +#ready to use +sls_detector_get exptime +etc ... ``` -### Source code -One can also obtain the source code from this repository and compile. ``` -git clone https://github.com/slsdetectorgroup/slsDetectorPackage.git +# List available versions +# lib and binaries +conda search slsdetlib +# python +conda search slsdet +# gui +conda search slsdetgui +``` + +### 2. Build from source + +##### 2.1 Download Source Code from github +``` +git clone https://github.com/slsdetectorgroup/slsDetectorPackage.git --branch 7.0.0 +``` + +**Pybind for Python**
+* **v7.0.0+**: +pybind11 packaged into 'libs/pybind'. No longer a submodule. No need for "recursive" or "submodule update". + +* **Older versions**: + pybind11 is a submodule. Must be cloned using "recursive" and updated when switching between versions using the following commands. ``` -#### Dependencies +# clone using recursive to get pybind11 submodule +git clone --recursive https://github.com/slsdetectorgroup/slsDetectorPackage.git -Refer [this page](https://slsdetectorgroup.github.io/devdoc/dependencies.html) for dependencies. - - -#### Compilation - -Compiling can be done in two ways. Either with the convenience script -cmk.sh or directly with cmake for more control. - -**1. Compile using script cmk.sh**
- -These are mainly aimed at those not familiar with using ccmake and cmake. +# update submodule when switching between releases +cd slsDetectorPackage +git submodule update --init ``` - The binaries are generated in slsDetectorPackage/build/bin directory. - Usage: ./cmk.sh [-c] [-b] [-p] [e] [t] [r] [g] [s] [u] [i] [m] [n] [-h] [z] [-d ] [-l Install directory] [-k ] [-j ] - -[no option]: only make - -c: Clean - -b: Builds/Rebuilds CMake files normal mode - -p: Builds/Rebuilds Python API - -h: Builds/Rebuilds Cmake files with HDF5 package - -d: HDF5 Custom Directory - -k: CMake command - -l: Install directory - -t: Build/Rebuilds only text client - -r: Build/Rebuilds only receiver - -g: Build/Rebuilds only gui - -s: Simulator - -u: Chip Test Gui - -j: Number of threads to compile through - -e: Debug mode - -i: Builds tests - -m: Manuals - -n: Manuals without compiling doxygen (only rst) - -z: Moench zmq processor +##### 2.2 Build from source + + +###### Build using CMake + +``` +# outside slsDetecorPackage folder +mkdir build && cd build + +# configure & generate Makefiles using cmake +# by listing all your options (alternately use ccmake described below) +# cmake3 for some systems +cmake ../slsDetectorPackage -DCMAKE_INSTALL_PREFIX=/your/install/path + +# compiled to the build/bin directory +make -j12 #or whatever number of cores you are using to build + +# install headers and libs in /your/install/path directory +make install +``` + +Instead of the cmake command, one can use ccmake to get a list of options to configure and generate Makefiles at ease. + + +``` +# ccmake3 for some systems +ccmake .. + +# choose the options +# first press [c] - configure +# then press [g] - generate +``` + +|Example cmake options|Comment| +|---|---| +| -DSLS_USE_PYTHON=ON | Python | +| -DPython_FIND_VIRTUALENV=ONLY | Python from only the conda environment | +| -DZeroMQ_HINT=/usr/lib64 | Use system zmq instead | +| -DSLS_USE_GUI=ON | GUI | + + +###### Build using in-built cmk.sh script + +``` +The binaries are generated in slsDetectorPackage/build/bin directory. + +Usage: ./cmk.sh [-b] [-c] [-d ] [e] [g] [-h] [i] [-j ] +[-k ] [-l ] [m] [n] [-p] [-q ] +[r] [s] [t] [u] [z] +-[no option]: only make +-b: Builds/Rebuilds CMake files normal mode +-c: Clean +-d: HDF5 Custom Directory +-e: Debug mode +-g: Build/Rebuilds gui +-h: Builds/Rebuilds Cmake files with HDF5 package +-i: Builds tests +-j: Number of threads to compile through +-k: CMake command +-l: Install directory +-m: Manuals +-n: Manuals without compiling doxygen (only rst) +-p: Builds/Rebuilds Python API +-q: Zmq hint directory +-r: Build/Rebuilds only receiver +-s: Simulator +-t: Build/Rebuilds only text client +-u: Chip Test Gui +-z: Moench zmq processor - # get all options - ./cmk.sh -? +# display all options +./cmk.sh -? - # new build and compile in parallel: - ./cmk.sh -bj5 -``` - -**2. Compile without script**
-Use cmake to create out-of-source builds, by creating a build folder parallel to source directory. This would create a debug build with address sanitizers. -``` - $ mkdir build - $ cd build - $ cmake ../slsDetectorPackage -DCMAKE_BUILD_TYPE=Debug -DSLS_USE_SANITIZER=ON - $ make -j12 #or whatever number of threads wanted +# new build and compile in parallel (recommended basic option): +./cmk.sh -cbj5 + +# new build, python and compile in parallel: +./cmk.sh -cbpj5 + +#To use the system zmq (/usr/lib64) instead +./cmk.sh -cbj5 -q /usr/lib64 ``` -To install binaries using CMake +###### Build on old distributions + +If your linux distribution doesn't come with a C++11 compiler (gcc>4.8) then +it's possible to install a newer gcc using conda and build the slsDetectorPackage +using this compiler + ``` - git clone --recursive https://github.com/slsdetectorgroup/slsDetectorPackage.git - mkdir build && cd build - cmake ../slsDetectorPackage -DCMAKE_INSTALL_PREFIX=/your/install/path - make -j12 #or whatever number of cores you are using to build - make install +#Create an environment with the dependencies +conda create -n myenv gxx_linux-64 cmake zmq +conda activate myenv + +# outside slsDetecorPackage folder +mkdir build && cd build +cmake ../slsDetectorPackage -DCMAKE_PREFIX_PATH=$CONDA_PREFIX +make -j12 +``` + +###### Build slsDetectorGui (Qt5) + +1. Using pre-built binary on conda +``` +conda create -n myenv slsdetgui=7.0.0 +conda activate myenv +``` + +2. Using system installation on RHEL7 +``` +yum install qt5-qtbase-devel.x86_64 +yum install qt5-qtsvg-devel.x86_64 +``` + +3. Using conda +``` +#Add channels for dependencies and our library +conda config --add channels conda-forge +conda config --add channels slsdetectorgroup +conda config --set channel_priority strict + +# create environment to compile +# on rhel7 +conda create -n slsgui zeromq gxx_linux-64 gxx_linux-64 mesa-libgl-devel-cos6-x86_64 qt +# on fedora or newer systems +conda create -n slsgui zeromq qt + +# when using conda compilers, would also need libgl, but no need for it on fedora unless maybe using it with ROOT + +# activate environment +conda activate slsgui + +# compile with cmake outside slsDetecorPackage folder +mkdir build && cd build +cmake ../slsDetectorPackage -DSLS_USE_GUI=ON +make -j12 + +# or compile with cmk.sh +cd slsDetectorPackage +./cmk.sh -cbgj9 +``` + +###### Build documentation from package +The documentation for the slsDetectorPackage is build using a combination +of Doxygen, Sphinx and Breathe. The easiest way to install the dependencies +is to use conda + +``` +conda create -n myenv python sphinx_rtd_theme breathe +``` + +``` +# using cmake or ccmake to enable DSLS_BUILD_DOCS +# outside slsDetecorPackage folder +mkdir build && cd build +cmake ../slsDetectorPackage -DSLS_BUILD_DOCS=ON + +make docs # generate API docs and build Sphinx RST +make rst # rst only, saves time in case the API did not change ``` -### Support +## Support dhanya.thattil@psi.ch - erik.frojdh@psi.ch \ No newline at end of file + erik.frojdh@psi.ch diff --git a/RELEASE.txt b/RELEASE.txt index f10de5cfb..36162120c 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -1,36 +1,39 @@ -SLS Detector Package Minor Release 7.0.0.rc1 released on 12.12.2021 -=================================================================== +SLS Detector Package Major Release 7.x.x released on xx.xx.2023 +=============================================================== -This document describes the differences between v7.0.0.rc1 and v6.1.2 +This document describes the differences between v7.x.x and v7.0.0 CONTENTS -------- - 1. New, Changed or Resolved Features - 1.1. Compilation - 1.2. Callback - 1.3. Python - 1.4. Client - 1.5. Detector Server - 1.6. Simulator - 1.7. Receiver - 2. On-board Detector Server Compatibility - 3. Firmware Requirements - 4. Kernel Requirements - 5. Download, Documentation & Support + 1 New, Changed or Resolved Features + 1.1 Compilation + 1.2 Callback + 1.3 Python + 1.4 Client + 1.5 Detector Server + 1.6 Simulator + 1.7 Receiver + 1.8 Gui + 2 On-board Detector Server Compatibility + 3 Firmware Requirements + 4 Kernel Requirements + 5 Download, Documentation & Support -1. New or Changed Features -========================== +1 New, Changed or Resolved Features +===================================== + - moench being made compatible with jungfrau 2.0 boards (jungfrau structure, away from ctb) - eiger febl and feb in versions -2. On-board Detector Server Compatibility + +2 On-board Detector Server Compatibility ========================================== @@ -57,16 +60,16 @@ This document describes the differences between v7.0.0.rc1 and v6.1.2 -3. Firmware Requirements +3 Firmware Requirements ======================== - Eiger 17.02.2022 (v30) + Eiger 20.02.2023 (v31) Jungfrau 04.11.2022 (v1.4, HW v1.0) 03.11.2022 (v2.4, HW v2.0) - Mythen3 05.12.2022 (v1.4) + Mythen3 24.01.2023 (v1.4) Gotthard2 23.11.2022 (v0.3) @@ -106,22 +109,22 @@ This document describes the differences between v7.0.0.rc1 and v6.1.2 -4. Kernel Requirements +4 Kernel Requirements ====================== Blackfin - ======== + -------- Latest version: Fri Oct 29 00:00:00 2021 Older ones will work, but might have issues with programming firmware via the package. Nios - ==== + ----- Compatible version: Mon May 10 18:00:21 CEST 2021 Kernel Upgrade - ============== + --------------- Eiger via bit files Others via command @@ -134,7 +137,7 @@ This document describes the differences between v7.0.0.rc1 and v6.1.2 -5. Download, Documentation & Support +5 Download, Documentation & Support ==================================== Download @@ -190,6 +193,9 @@ This document describes the differences between v7.0.0.rc1 and v6.1.2 https://slsdetectorgroup.github.io/devdoc/udpheader.html https://slsdetectorgroup.github.io/devdoc/udpdetspec.html + slsReceiver Zmq Format: + https://slsdetectorgroup.github.io/devdoc/slsreceiver.html#zmq-json-header-format + TroubleShooting: https://slsdetectorgroup.github.io/devdoc/troubleshooting.html https://slsdetectorgroup.github.io/devdoc/troubleshooting.html#receiver-pc-tuning-options @@ -206,4 +212,3 @@ This document describes the differences between v7.0.0.rc1 and v6.1.2 dhanya.thattil@psi.ch erik.frojdh@psi.ch - diff --git a/cmk.sh b/cmk.sh index 8df13ac68..9ed267843 100755 --- a/cmk.sh +++ b/cmk.sh @@ -33,7 +33,7 @@ Usage: $0 [-b] [-c] [-d ] [e] [g] [-h] [i] [-j ` | + | | [From detector udp header] | + +--------------+----------------------------------------------+ + | timestamp | Timestamp with 10 MHz clock | + | | [From detector udp header] | + +--------------+----------------------------------------------+ + | modId | Module Id | + | | [From detector udp header] | + +--------------+----------------------------------------------+ + | row | Row number in detector | + | | [From detector udp header] | + +--------------+----------------------------------------------+ + | column | Column number in detector | + | | [From detector udp header] | + +--------------+----------------------------------------------+ + | detSpec2 | See :ref:`here` | + | | [From detector udp header] | + +--------------+----------------------------------------------+ + | detSpec3 | See :ref:`here` | + | | [From detector udp header] | + +--------------+----------------------------------------------+ + | detSpec4 | See :ref:`here` | + | | [From detector udp header] | + +--------------+----------------------------------------------+ + | detType | Detector type enum | + | detSpec3 | See :ref:`Detector enum` | + | | [From detector udp header] | + +--------------+----------------------------------------------+ + | version | Detector header version. At 2 | + | | [From detector udp header] | + +--------------+----------------------------------------------+ + | flipRows | 1 if rows should be flipped. | + | | Usually for Eiger bottom. | + +--------------+----------------------------------------------+ + | quad | 1 if its an Eiger quad. | + +--------------+----------------------------------------------+ + | addJsonHeader| Optional custom parameters that is required | + | | for processing code. | + +--------------+----------------------------------------------+ + + +SLS Receiver Header Format +-------------------------- + +It is 112 bytes and consists of: + * 48 bytes of the SLS Detector Header (described in :ref:`the current detector header `) + * 64 bytes of packet mask + +.. code-block:: cpp + + typedef struct { + uint64_t frameNumber; + uint32_t expLength; + uint32_t packetNumber; + uint64_t detSpec1; + uint64_t timestamp; + uint16_t modId; + uint16_t row; + uint16_t column; + uint16_t detSpec2; + uint32_t detSpec3; + uint16_t detSpec4; + uint8_t detType; + uint8_t version; + } sls_detector_header; + + struct sls_receiver_header { + sls_detector_header detHeader; /**< is the detector header */ + sls_bitset packetsMask; /**< is the packets caught bit mask */ + }; + + +.. note :: + + | The packetNumber in the SLS Receiver Header will be modified to number of packets caught by receiver for that frame. For eg. Jungfrau will have 128 packets per frame. If it is less, then this is a partial frame due to missing packets. + + | Furthermore, the bit mask will specify which packets have been received. + + + + File format -------------- @@ -117,8 +295,6 @@ Some file name examples: Each acquisition will create a master file that can be enabled/disabled using **fmaster**. This should have parameters relevant to the acquisition. -SLS Receiver Header consist of SLS Detector Header + 64 bytes of bitmask, altogether 112 bytes. The packetNumber in the sls detector header part, will be updated to number of packets caught by receiver for that frame. Furthermore, the bit mask will specify which packets have been received. - **Binary file format** This is the default file format. diff --git a/docs/src/udpheader.rst b/docs/src/udpheader.rst index 8b3999e70..04f3a5a6a 100644 --- a/docs/src/udpheader.rst +++ b/docs/src/udpheader.rst @@ -11,7 +11,7 @@ Current Version **v2.0 (slsDetectorPackage v7.0.0+)** -.. table:: <---------------------------------------------------- 8 bytes ----------------------------------------------------> +.. table:: <---------------------------------------------------- 8 bytes per row ---------------------------------------------> :align: center :widths: 30,30,30,15,15 diff --git a/examples/badchannel.txt b/examples/badchannel.txt new file mode 100644 index 000000000..1de3c6eb6 --- /dev/null +++ b/examples/badchannel.txt @@ -0,0 +1,6 @@ +0 +10, 30 +40:45 50:52 +1279 +# all bad channels are applied for all counters in deector + diff --git a/examples/virtual_ctb_moench.config b/examples/virtual_ctb_moench.config index e5c74c65e..3b6c35bde 100644 --- a/examples/virtual_ctb_moench.config +++ b/examples/virtual_ctb_moench.config @@ -1,18 +1,18 @@ # detector hostname hostname localhost:1910 -# receiver hostname -rx_hostname mpc1922:2010 - # udp destination ports udp_dstport 50010 -# udp destination ip from rx_hostname -udp_dstip auto - # udp source ip (same subnet as udp_dstip) udp_srcip 192.168.1.100 +# receiver hostname +rx_hostname mpc1922:2010 + +# udp destination ip from rx_hostname +udp_dstip auto + # output file directory fpath /tmp @@ -27,418 +27,7 @@ dbitclk 40 # patterns -patword 0x0000 0x0000000000000000 -patword 0x0001 0x0000000000000000 -patword 0x0002 0x0008000900080000 -patword 0x0003 0x0008000900080000 -patword 0x0004 0x0008000900080000 -patword 0x0005 0x0008000900080000 -patword 0x0006 0x0008000900080000 -patword 0x0007 0x0008000900080000 -patword 0x0008 0x0008000900080000 -patword 0x0009 0x0008000900080000 -patword 0x000a 0x0008000900080000 -patword 0x000b 0x0008000900080000 -patword 0x000c 0x0008000900080000 -patword 0x000d 0x0008000900080000 -patword 0x000e 0x0008000900080000 -patword 0x000f 0x0008000900080000 -patword 0x0010 0x0008000900080000 -patword 0x0011 0x0008000900080000 -patword 0x0012 0x0008000900080000 -patword 0x0013 0x0008000900080000 -patword 0x0014 0x0008000900080000 -patword 0x0015 0x0008000900080000 -patword 0x0016 0x0008400900080020 -patword 0x0017 0x0008400900080020 -patword 0x0018 0x0008599f0418503a -patword 0x0019 0x0008599f0418503a -patword 0x001a 0x0108599f0418503a -patword 0x001b 0x0108599f0418503a -patword 0x001c 0x0108599f0418503a -patword 0x001d 0x0108599f0418503a -patword 0x001e 0x0108599f0418503a -patword 0x001f 0x0108599f0418503a -patword 0x0020 0x0108599f0418503a -patword 0x0021 0x0108599f0418503a -patword 0x0022 0x0108599f0418503a -patword 0x0023 0x0108599f0418503a -patword 0x0024 0x0108599f0418503a -patword 0x0025 0x0108599f0418503a -patword 0x0026 0x0108599f0418503a -patword 0x0027 0x0108599f0418503a -patword 0x0028 0x0108599f0418503a -patword 0x0029 0x0108599f0418503a -patword 0x002a 0x0108599f0418503a -patword 0x002b 0x0108599f0418503a -patword 0x002c 0x0108599f0418503a -patword 0x002d 0x0108599f0418503a -patword 0x002e 0x0108599f0418503a -patword 0x002f 0x0108599f0418503a -patword 0x0030 0x0108599f0418503a -patword 0x0031 0x0108599f0418503a -patword 0x0032 0x0108599f0418503a -patword 0x0033 0x0108599f0418503a -patword 0x0034 0x0108599f0418503a -patword 0x0035 0x0108599f0418503a -patword 0x0036 0x0108599f0418503a -patword 0x0037 0x0108599f0418503a -patword 0x0038 0x0108599f0418503a -patword 0x0039 0x0108599f0418503a -patword 0x003a 0x0108599f0418503a -patword 0x003b 0x0108599f0418503a -patword 0x003c 0x0108599f0418503a -patword 0x003d 0x0108599f0418503a -patword 0x003e 0x0108599f0418503a -patword 0x003f 0x0108599f0418503a -patword 0x0040 0x0108599f0418503a -patword 0x0041 0x0108599f0418503a -patword 0x0042 0x0108599f0418503a -patword 0x0043 0x0108599f0418503a -patword 0x0044 0x0108599f0418503a -patword 0x0045 0x0108599f0418503a -patword 0x0046 0x0108599f0418503a -patword 0x0047 0x0108599f0418503a -patword 0x0048 0x0108599f0418503a -patword 0x0049 0x0108599f0418503a -patword 0x004a 0x0108599f0418503a -patword 0x004b 0x0108599f0418503a -patword 0x004c 0x0108599f0418503a -patword 0x004d 0x0108599f0418503a -patword 0x004e 0x0108599f0418503a -patword 0x004f 0x0108599f0418503a -patword 0x0050 0x0108599f0418503a -patword 0x0051 0x0108599f0418503a -patword 0x0052 0x0108599f0418503a -patword 0x0053 0x0108599f0418503a -patword 0x0054 0x0108599f0418503a -patword 0x0055 0x0108599f0418503a -patword 0x0056 0x0108599f0418503a -patword 0x0057 0x0108599f0418503a -patword 0x0058 0x0108599f0418503a -patword 0x0059 0x0108599f0418503a -patword 0x005a 0x0108599f0418503a -patword 0x005b 0x0108599f0418503a -patword 0x005c 0x0108599f0418503a -patword 0x005d 0x0108599f0418503a -patword 0x005e 0x0108599f0418503a -patword 0x005f 0x0108599f0418503a -patword 0x0060 0x0108599f0418503a -patword 0x0061 0x0108599f0418503a -patword 0x0062 0x0108599f0418503a -patword 0x0063 0x0108599f0418503a -patword 0x0064 0x0108599f0418503a -patword 0x0065 0x0108599f0418503a -patword 0x0066 0x0108599f0418503a -patword 0x0067 0x0108599f0418503a -patword 0x0068 0x0108599f0418503a -patword 0x0069 0x0108599f0418503a -patword 0x006a 0x0108599f0418503a -patword 0x006b 0x0108599f0418503a -patword 0x006c 0x0108599f0418503a -patword 0x006d 0x0108599f0418503a -patword 0x006e 0x0108599f0418503a -patword 0x006f 0x0108599f0418503a -patword 0x0070 0x0108599f0418503a -patword 0x0071 0x0108599f0418503a -patword 0x0072 0x0108599f0418503a -patword 0x0073 0x0108599f0418503a -patword 0x0074 0x0108599f0418503a -patword 0x0075 0x0108599f0418503a -patword 0x0076 0x0108599f0418503a -patword 0x0077 0x0108599f0418503a -patword 0x0078 0x0108599f0418503a -patword 0x0079 0x0108599f0418503a -patword 0x007a 0x0108599f0418503a -patword 0x007b 0x0108599f0418503a -patword 0x007c 0x0108599f0418503a -patword 0x007d 0x0108599f0418503a -patword 0x007e 0x010859960418503a -patword 0x007f 0x010859960418503a -patword 0x0080 0x010859960418503a -patword 0x0081 0x010859960418503a -patword 0x0082 0x010859960418503a -patword 0x0083 0x010859960418503a -patword 0x0084 0x010859960418503a -patword 0x0085 0x010859960418503a -patword 0x0086 0x010859960418503a -patword 0x0087 0x010859960418503a -patword 0x0088 0x010859960418503a -patword 0x0089 0x010859960418503a -patword 0x008a 0x010859960418503a -patword 0x008b 0x010859960418503a -patword 0x008c 0x010859960418503a -patword 0x008d 0x010859960418503a -patword 0x008e 0x010859960418503a -patword 0x008f 0x010859960418503a -patword 0x0090 0x010859960418503a -patword 0x0091 0x010859960418503a -patword 0x0092 0x010819960418501a -patword 0x0093 0x010819960418501a -patword 0x0094 0x010819960418501a -patword 0x0095 0x010819960418501a -patword 0x0096 0x030819960418501a -patword 0x0097 0x030819960418501a -patword 0x0098 0x030819960418501a -patword 0x0099 0x030819960418501a -patword 0x009a 0x030819960418501a -patword 0x009b 0x030819960418501a -patword 0x009c 0x030819960418501a -patword 0x009d 0x030819960418501a -patword 0x009e 0x030819960418501a -patword 0x009f 0x030819960418501a -patword 0x00a0 0x030819960418501a -patword 0x00a1 0x030819960418501a -patword 0x00a2 0x030819960418501a -patword 0x00a3 0x030819960418501a -patword 0x00a4 0x030819960418501a -patword 0x00a5 0x030819960418501a -patword 0x00a6 0x030819960418501a -patword 0x00a7 0x030819960418501a -patword 0x00a8 0x030819960418501a -patword 0x00a9 0x030819960418501a -patword 0x00aa 0x030819960418501a -patword 0x00ab 0x030819960418501a -patword 0x00ac 0x030819960008501a -patword 0x00ad 0x030819960008501a -patword 0x00ae 0x030819960008501a -patword 0x00af 0x030819960008501a -patword 0x00b0 0x030819960008501a -patword 0x00b1 0x030819960008501a -patword 0x00b2 0x030819960008501a -patword 0x00b3 0x030819960008501a -patword 0x00b4 0x030819960008501a -patword 0x00b5 0x030819960008501a -patword 0x00b6 0x030819960008501a -patword 0x00b7 0x030819960008501a -patword 0x00b8 0x030819960008501a -patword 0x00b9 0x030819960008501a -patword 0x00ba 0x030819960008501a -patword 0x00bb 0x030819960008501a -patword 0x00bc 0x030819960008501a -patword 0x00bd 0x030819960008501a -patword 0x00be 0x030819960008501a -patword 0x00bf 0x030819960008501a -patword 0x00c0 0x0308199f0008501a -patword 0x00c1 0x0308199f0008501a -patword 0x00c2 0x0308199f0008501a -patword 0x00c3 0x0308199f0008501a -patword 0x00c4 0x0308199f0008501a -patword 0x00c5 0x0308199f0008501a -patword 0x00c6 0x0308199f0008501a -patword 0x00c7 0x0308199f0008501a -patword 0x00c8 0x0308199f0008501a -patword 0x00c9 0x0308199f0008501a -patword 0x00ca 0x0308199f0008501a -patword 0x00cb 0x0308199f0008501a -patword 0x00cc 0x0308199f0008501a -patword 0x00cd 0x0308199f0008501a -patword 0x00ce 0x0308199f0008501a -patword 0x00cf 0x0308199f0008501a -patword 0x00d0 0x0308199f0008501a -patword 0x00d1 0x0308199f0008501a -patword 0x00d2 0x0308199f0008501a -patword 0x00d3 0x0308199f0008501a -patword 0x00d4 0x0308599f0008503a -patword 0x00d5 0x0308599f0008503a -patword 0x00d6 0x030c599f000850ba -patword 0x00d7 0x030c599f000850ba -patword 0x00d8 0x030c599f000850ba -patword 0x00d9 0x030c599f000850ba -patword 0x00da 0x030c599f000850ba -patword 0x00db 0x030c599f000850ba -patword 0x00dc 0x030c599f000850ba -patword 0x00dd 0x030c599f000850ba -patword 0x00de 0x030c599f000850ba -patword 0x00df 0x030c599f000850ba -patword 0x00e0 0x030c599f000850ba -patword 0x00e1 0x030c599f000850ba -patword 0x00e2 0x030c599f000850ba -patword 0x00e3 0x030c599f000850ba -patword 0x00e4 0x030c599f000850ba -patword 0x00e5 0x030c599f000850ba -patword 0x00e6 0x030c599f000850ba -patword 0x00e7 0x030c599f000850ba -patword 0x00e8 0x030c599f000850ba -patword 0x00e9 0x030c599f000850ba -patword 0x00ea 0x030c799f010858ba -patword 0x00eb 0x030c799f010858ba -patword 0x00ec 0x030c599f000850ba -patword 0x00ed 0x030c599f000850ba -patword 0x00ee 0x030c599f000850ba -patword 0x00ef 0x030c599f000850ba -patword 0x00f0 0x030c599f000850ba -patword 0x00f1 0x030c599f000850ba -patword 0x00f2 0x030c599f000850ba -patword 0x00f3 0x030c599f000850ba -patword 0x00f4 0x030c599f000850ba -patword 0x00f5 0x030c599f000850ba -patword 0x00f6 0x030c599f000850ba -patword 0x00f7 0x030c599f000850ba -patword 0x00f8 0x030c599f000850ba -patword 0x00f9 0x030c599f000850ba -patword 0x00fa 0x030c599f000850ba -patword 0x00fb 0x030c599f000850ba -patword 0x00fc 0x030c599f000850ba -patword 0x00fd 0x030c599f000850ba -patword 0x00fe 0x030c599f000850ba -patword 0x00ff 0x030c599f000850ba -patword 0x0100 0x030c599f000850ba -patword 0x0101 0x030c599f000850ba -patword 0x0102 0x030c599f400850ba -patword 0x0103 0x030c599f400850ba -patword 0x0104 0x030c599f600850ba -patword 0x0105 0x030c599f400850ba -patword 0x0106 0x030c599f400850ba -patword 0x0107 0x030c599f400850ba -patword 0x0108 0x870c599f682e50ba -patword 0x0109 0x870c599f482850ba -patword 0x010a 0x870c599f000e50ba -patword 0x010b 0x870c599f000850ba -patword 0x010c 0x870c599f000e50ba -patword 0x010d 0x870c599f000850ba -patword 0x010e 0x870c599f000e50ba -patword 0x010f 0x870c599f000850ba -patword 0x0110 0x870c599f000e50ba -patword 0x0111 0x870c599f000850ba -patword 0x0112 0x870c599f000e50ba -patword 0x0113 0x870c599f000850ba -patword 0x0114 0x870c599f000e50ba -patword 0x0115 0x870c599f000850ba -patword 0x0116 0x870c599f000e50ba -patword 0x0117 0x870c599f000850ba -patword 0x0118 0x870c599f000e50ba -patword 0x0119 0x870c599f000850ba -patword 0x011a 0x870c599f000e50ba -patword 0x011b 0x870c599f000850ba -patword 0x011c 0x870c599f000e50ba -patword 0x011d 0x870c599f000850ba -patword 0x011e 0x870c599f000e50ba -patword 0x011f 0x870c599f000850ba -patword 0x0120 0x870c599f000e50ba -patword 0x0121 0x870c599f000850ba -patword 0x0122 0x870c599f200e50ba -patword 0x0123 0x870c599f000850ba -patword 0x0124 0x870c599f000e50ba -patword 0x0125 0x870c599f000850ba -patword 0x0126 0x870c599f000e50ba -patword 0x0127 0x870c599f000850ba -patword 0x0128 0x870c599f000e50ba -patword 0x0129 0x870c599f000850ba -patword 0x012a 0x870c599f000e50ba -patword 0x012b 0x870c599f000850ba -patword 0x012c 0x870c599f000e50ba -patword 0x012d 0x870c599f000850ba -patword 0x012e 0x870c599f000e50ba -patword 0x012f 0x870c599f000850ba -patword 0x0130 0x870c599f000e50ba -patword 0x0131 0x870c599f000850ba -patword 0x0132 0x870c599f000e50ba -patword 0x0133 0x870c599f000850ba -patword 0x0134 0x870c599f000e50ba -patword 0x0135 0x870c599f000850ba -patword 0x0136 0x870c599f000e50ba -patword 0x0137 0x870c599f000850ba -patword 0x0138 0x870c599f000e50ba -patword 0x0139 0x870c599f000850ba -patword 0x013a 0x870c599f282e50ba -patword 0x013b 0x870c599f082850ba -patword 0x013c 0x870c599f000e50ba -patword 0x013d 0x870c599f000850ba -patword 0x013e 0x870c599f000e50ba -patword 0x013f 0x870c599f000850ba -patword 0x0140 0x870c599f000e50ba -patword 0x0141 0x870c599f000850ba -patword 0x0142 0x870c599f000e50ba -patword 0x0143 0x870c599f000850ba -patword 0x0144 0x870c599f000e50ba -patword 0x0145 0x870c599f000850ba -patword 0x0146 0x870c599f000e50ba -patword 0x0147 0x870c599f000850ba -patword 0x0148 0x870c599f000e50ba -patword 0x0149 0x870c599f000850ba -patword 0x014a 0x870c599f000e50ba -patword 0x014b 0x870c599f000850ba -patword 0x014c 0x870c599f000e50ba -patword 0x014d 0x870c599f000850ba -patword 0x014e 0x870c599f000e50ba -patword 0x014f 0x870c599f000850ba -patword 0x0150 0x870c599f000e50ba -patword 0x0151 0x870c599f000850ba -patword 0x0152 0x870c599f000e50ba -patword 0x0153 0x870c599f000850ba -patword 0x0154 0x870c599f200e50ba -patword 0x0155 0x870c599f000850ba -patword 0x0156 0x870c599f000e50ba -patword 0x0157 0x870c599f000850ba -patword 0x0158 0x870c599f000e50ba -patword 0x0159 0x870c599f000850ba -patword 0x015a 0x870c599f000e50ba -patword 0x015b 0x870c599f000850ba -patword 0x015c 0x870c599f000e50ba -patword 0x015d 0x870c599f000850ba -patword 0x015e 0x870c599f000e50ba -patword 0x015f 0x870c599f000850ba -patword 0x0160 0x870c599f000e50ba -patword 0x0161 0x870c599f000850ba -patword 0x0162 0x870c599f000e50ba -patword 0x0163 0x870c599f000850ba -patword 0x0164 0x870c599f000e50ba -patword 0x0165 0x870c599f000850ba -patword 0x0166 0x870c599f000e50ba -patword 0x0167 0x870c599f000850ba -patword 0x0168 0x870c599f000e50ba -patword 0x0169 0x870c599f000850ba -patword 0x016a 0x870c599f000e50ba -patword 0x016b 0x870c599f000850ba -patword 0x016c 0x070c599f000850ba -patword 0x016d 0x070c599f000850ba -patword 0x016e 0x000c599f000850ba -patword 0x016f 0x000c599f000850ba -patword 0x0170 0x0008599f200e503a -patword 0x0171 0x0008599f0008503a -patword 0x0172 0x0008599f200e503a -patword 0x0173 0x0008599f0008503a -patword 0x0174 0x0008599f0008503a -patword 0x0175 0x0008599f0008503a -patword 0x0176 0x0008599f0008503a -patword 0x0177 0x0008599f0008503a -patword 0x0178 0x0008599f0008503a -patword 0x0179 0x0008599f0008503a -patword 0x017a 0x0008599f0008503a -patword 0x017b 0x0008599f0008503a -patword 0x017c 0x0008599f0008503a -patword 0x017d 0x0008599f0008503a -patword 0x017e 0x0008599f0008503a -patword 0x017f 0x0008599f0008503a -patword 0x0180 0x0008599f0008503a -patword 0x0181 0x0008599f0008503a -patword 0x0182 0x0008599f0008503a -patword 0x0183 0x0008599f0008503a -patword 0x0184 0x0008599f0008503a -patword 0x0185 0x0008599f0008503a -patword 0x0186 0x0008599f0008503a -patword 0x0187 0x0008599f0008503a -patword 0x0188 0x0008599f0008503a -patword 0x0189 0x0008599f0008503a -patword 0x018a 0x0008599f0008503a -patword 0x018b 0x0008599f0008503a -patword 0x018c 0x0008599f0008503a -patword 0x018d 0x0008599f0008503a -patioctrl 0x8f0effff6dbffdbf -patlimits 0x0000 0x018c -patloop 0 0x013a 0x016b -patnloop 0 0x199 -patloop 1 0x0400 0x0400 -patnloop 1 0 -patloop 2 0x0400 0x0400 -patnloop 2 0 -patwait 0 0x00aa -patwaittime 0 10000 -patwait 1 0x0400 -patwaittime 1 0 -patwait 2 0x0400 -patwaittime 2 0 +pattern /tmp/pattern.pat # dacs dac 6 800 diff --git a/examples/virtual_eiger_1_half_module.config b/examples/virtual_eiger_1_half_module.config index fa815af3e..c88cd0fde 100644 --- a/examples/virtual_eiger_1_half_module.config +++ b/examples/virtual_eiger_1_half_module.config @@ -1,13 +1,13 @@ # detector hostname hostname localhost:1900 -# receiver hostname -rx_hostname mpc1922:2000 - # udp destination ports udp_dstport 50000 udp_dstport2 50001 +# receiver hostname +rx_hostname mpc1922:2000 + # udp destination ip from rx_hostname udp_dstip auto diff --git a/examples/virtual_eiger_2_half_modules.config b/examples/virtual_eiger_2_half_modules.config index f58270678..e4d1f5ed8 100644 --- a/examples/virtual_eiger_2_half_modules.config +++ b/examples/virtual_eiger_2_half_modules.config @@ -1,15 +1,15 @@ # detector hostname hostname localhost:1900+localhost:1902+ -# receiver hostname -rx_hostname mpc1922:2000+mpc1922:2001+ - # udp destination ports 0:udp_dstport 50000 0:udp_dstport2 50001 1:udp_dstport 50002 1:udp_dstport2 50003 +# receiver hostname +rx_hostname mpc1922:2000+mpc1922:2001+ + # udp destination ip from rx_hostname udp_dstip auto diff --git a/examples/virtual_gotthard.config b/examples/virtual_gotthard.config index c30957154..df4482d0b 100644 --- a/examples/virtual_gotthard.config +++ b/examples/virtual_gotthard.config @@ -1,18 +1,18 @@ # detector hostname hostname localhost:1904 -# receiver hostname -rx_hostname mpc1922:2004 - # udp destination ports udp_dstport 50004 -# udp destination ip from rx_hostname -udp_dstip auto - # udp source ip (same subnet as udp_dstip) udp_srcip 192.168.1.100 +# receiver hostname +rx_hostname mpc1922:2004 + +# udp destination ip from rx_hostname +udp_dstip auto + # output file directory fpath /tmp diff --git a/examples/virtual_gotthard2.config b/examples/virtual_gotthard2.config index 9e2456fe9..8ebf9326a 100644 --- a/examples/virtual_gotthard2.config +++ b/examples/virtual_gotthard2.config @@ -1,24 +1,12 @@ # detector hostname hostname localhost:1914 -# receiver hostname -rx_hostname mpc1922:2014 - # udp destination ports udp_dstport 50014 -# udp destination ip from rx_hostname -udp_dstip auto - # udp source ip (same subnet as udp_dstip) udp_srcip 192.168.1.100 -# output file directory -fpath /tmp - -# disable file writing -fwrite 0 - # enable 2nd interface for veto debugging # udp destination port for veto udp_dstport2 50015 @@ -27,6 +15,18 @@ udp_dstip2 auto # udp source ip (same subnet as udp_dstip) udp_srcip2 192.168.1.100 +# receiver hostname +rx_hostname mpc1922:2014 + +# udp destination ip from rx_hostname +udp_dstip auto + +# output file directory +fpath /tmp + +# disable file writing +fwrite 0 + # to enable 2nd interface for veto debugging numinterfaces 2 diff --git a/examples/virtual_jungfrau.config b/examples/virtual_jungfrau.config index c81b8d08c..4f7ed99f5 100644 --- a/examples/virtual_jungfrau.config +++ b/examples/virtual_jungfrau.config @@ -1,21 +1,21 @@ # detector hostname hostname localhost:1906 -# receiver hostname -rx_hostname mpc1922:2006 - # udp destination ports udp_dstport 50006 udp_dstport2 50007 -# udp destination ip from rx_hostname -udp_dstip auto -udp_dstip2 auto - # udp source ip (same subnet as udp_dstip) udp_srcip 192.168.1.100 udp_srcip2 192.168.1.100 +# receiver hostname +rx_hostname mpc1922:2006 + +# udp destination ip from rx_hostname +udp_dstip auto +udp_dstip2 auto + # output file directory fpath /tmp diff --git a/examples/virtual_jungfrau_4.config b/examples/virtual_jungfrau_4.config index 91e5b259f..021c2c4ae 100644 --- a/examples/virtual_jungfrau_4.config +++ b/examples/virtual_jungfrau_4.config @@ -4,13 +4,6 @@ detsize 2048 1024 # detector hostname virtual 4 1952 -# receiver hostname and tcpports -0:rx_tcpport 1970 -1:rx_tcpport 1971 -2:rx_tcpport 1972 -3:rx_tcpport 1973 -rx_hostname mpc1922 - # udp destination ports 0:udp_dstport2 50001 0:udp_dstport2 50002 @@ -21,14 +14,21 @@ rx_hostname mpc1922 3:udp_dstport 50007 3:udp_dstport2 50008 -# udp destination ip from rx_hostname -udp_dstip auto -udp_dstip2 auto - # udp source ip (same subnet as udp_dstip) udp_srcip 192.168.1.100 udp_srcip2 192.168.1.100 +# receiver hostname and tcpports +0:rx_tcpport 1970 +1:rx_tcpport 1971 +2:rx_tcpport 1972 +3:rx_tcpport 1973 +rx_hostname mpc1922 + +# udp destination ip from rx_hostname +udp_dstip auto +udp_dstip2 auto + # transmission delay frame 0:txndelay_frame 0 1:txndelay_frame 1 diff --git a/examples/virtual_moench.config b/examples/virtual_moench.config index be9adfb14..921f3a77c 100644 --- a/examples/virtual_moench.config +++ b/examples/virtual_moench.config @@ -1,18 +1,18 @@ # detector hostname hostname localhost:1908 -# receiver hostname -rx_hostname mpc1922:2008 - # udp destination ports udp_dstport 50008 -# udp destination ip from rx_hostname -udp_dstip auto - # udp source ip (same subnet as udp_dstip) udp_srcip 192.168.1.100 +# receiver hostname +rx_hostname mpc1922:2008 + +# udp destination ip from rx_hostname +udp_dstip auto + # output file directory fpath /tmp diff --git a/examples/virtual_mythen3.config b/examples/virtual_mythen3.config index 55bcfc625..02f5a672d 100644 --- a/examples/virtual_mythen3.config +++ b/examples/virtual_mythen3.config @@ -1,18 +1,18 @@ # detector hostname hostname localhost:1912 -# receiver hostname -rx_hostname mpc1922:2012 - # udp destination ports udp_dstport 50012 -# udp destination ip from rx_hostname -udp_dstip auto - # udp source ip (same subnet as udp_dstip) udp_srcip 192.168.1.100 +# receiver hostname +rx_hostname mpc1922:2012 + +# udp destination ip from rx_hostname +udp_dstip auto + # output file directory fpath /tmp diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 51bb92de7..ae05bbf99 100755 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -34,6 +34,7 @@ set( PYTHON_FILES slsdet/eiger.py slsdet/enums.py slsdet/errors.py + slsdet/gaincaps.py slsdet/gotthard.py slsdet/pattern.py slsdet/gotthard2.py diff --git a/python/scripts/compare_with_commandline.py b/python/scripts/compare_with_commandline.py index d4d68fab6..ef72bc0a6 100644 --- a/python/scripts/compare_with_commandline.py +++ b/python/scripts/compare_with_commandline.py @@ -2,7 +2,7 @@ # Copyright (C) 2021 Contributors to the SLS Detector Package import subprocess import locale -out = subprocess.run(['g', 'list'], stdout = subprocess.PIPE, encoding=locale.getpreferredencoding()) +out = subprocess.run(['sls_detector_get', 'list'], stdout = subprocess.PIPE, encoding=locale.getpreferredencoding()) cmd = out.stdout.splitlines() cmd.pop(0) @@ -99,7 +99,6 @@ intentionally_missing = [ 'temp_slowadc', 'temp_sodl', 'temp_sodr', - 'trigger', #use sendSoftwareTrigger 'update', #use updateServerAndFirmare 'udp_validate', #use validateUdpConfiguration 'udp_reconfigure', #use reconfigureUdpDestination diff --git a/python/slsdet/__init__.py b/python/slsdet/__init__.py index cf03a8a4e..09568cbd1 100755 --- a/python/slsdet/__init__.py +++ b/python/slsdet/__init__.py @@ -11,7 +11,7 @@ from .gotthard2 import Gotthard2 from .gotthard import Gotthard from .moench import Moench from .pattern import Pattern, patternParameters - +from .gaincaps import Mythen3GainCapsWrapper import _slsdet xy = _slsdet.xy diff --git a/python/slsdet/defines.py b/python/slsdet/defines.py index 4f86a03f3..244ce207e 100644 --- a/python/slsdet/defines.py +++ b/python/slsdet/defines.py @@ -26,6 +26,7 @@ SHORT_STR_LENGTH=20 MAX_PATTERN_LENGTH=0x2000 MAX_PATTERN_LEVELS=6 M3_MAX_PATTERN_LEVELS=3 +MAX_NUM_COUNTERS=3 DEFAULT_STREAMING_TIMER_IN_MS=500 NUM_RX_THREAD_IDS=9 MAX_NUM_PACKETS=512 diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 6148b72bd..d3dc29377 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -16,6 +16,7 @@ defs = slsDetectorDefs from .utils import element_if_equal, all_equal, get_set_bits, list_to_bitmask from .utils import Geometry, to_geo, element, reduce_time, is_iterable, hostname_list from _slsdet import xy +from .gaincaps import Mythen3GainCapsWrapper from . import utils as ut from .proxy import JsonProxy, SlowAdcProxy, ClkDivProxy, MaxPhaseProxy, ClkFreqProxy, PatLoopProxy, PatNLoopProxy, PatWaitProxy, PatWaitTimeProxy from .registers import Register, Adc_register @@ -231,7 +232,7 @@ class Detector(CppDetectorApi): """ [Jungfrau][Moench][Gotthard2][Myhten3][Gotthard][Ctb] Hardware version of detector. """ - return ut.lhex(self.getHardwareVersion()) + return self.getHardwareVersion() @property @element @@ -263,11 +264,17 @@ class Detector(CppDetectorApi): """Receiver version """ return self.getReceiverVersion() + @property + @element + def serialnumber(self): + """Jungfrau][Gotthard][Mythen3][Gotthard2][CTB][Moench] Serial number of detector """ + return ut.lhex(self.getSerialNumber()) + @property @element def rx_threads(self): """ - Get thread ids from the receiver in order of [parent, tcp, listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1, arping]. + Get kernel thread ids from the receiver in order of [parent, tcp, listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1, arping]. Note ----- @@ -451,6 +458,56 @@ class Detector(CppDetectorApi): def triggers(self, n_triggers): self.setNumberOfTriggers(n_triggers) + def resetdacs(self, use_hardware_values): + self.resetToDefaultDacs(use_hardware_values) + + def trigger(self): + self.sendSoftwareTrigger() + + def blockingtrigger(self): + self.sendSoftwareTrigger(True) + + @property + @element + def gaincaps(self): + """ + [Mythen3] Gain caps. Enum: M3_GainCaps \n + + Note + ---- + Options: M3_GainCaps, M3_C15sh, M3_C30sh, M3_C50sh, M3_C225ACsh, M3_C15pre + + Example + ------- + >>> d.gaincaps + C15pre, C30sh + >>> d.gaincaps = M3_GainCaps.M3_C30sh + >>> d.gaincaps + C30sh + >>> d.gaincaps = M3_GainCaps.M3_C30sh | M3_GainCaps.M3_C15sh + >>> d.gaincaps + C15sh, C30sh + """ + res = [Mythen3GainCapsWrapper(it) for it in self.getGainCaps()] + return res + + @gaincaps.setter + def gaincaps(self, caps): + #convert to int if called with Wrapper + if isinstance(caps, Mythen3GainCapsWrapper): + self.setGainCaps(caps.value) + elif isinstance(caps, dict): + corr = {} + for key, value in caps.items(): + if isinstance(value, Mythen3GainCapsWrapper): + corr[key] = value.value + else: + corr[key] = value + ut.set_using_dict(self.setGainCaps, corr) + else: + self.setGainCaps(caps) + + @property def exptime(self): """ @@ -498,7 +555,7 @@ class Detector(CppDetectorApi): @exptime.setter def exptime(self, t): - if self.type == detectorType.MYTHEN3 and is_iterable(t): + if self.type == detectorType.MYTHEN3 and is_iterable(t) and not isinstance(t,dict): for i, v in enumerate(t): if isinstance(v, int): v = float(v) @@ -507,8 +564,6 @@ class Detector(CppDetectorApi): ut.set_time_using_dict(self.setExptime, t) - - @property def period(self): """ @@ -647,6 +702,10 @@ class Detector(CppDetectorApi): """Start detector acquisition. Status changes to RUNNING or WAITING and automatically returns to idle at the end of acquisition.""" self.startDetector() + def clearbusy(self): + """If acquisition aborted during acquire command, use this to clear acquiring flag in shared memory before starting next acquisition""" + self.clearAcquiringFlag() + def rx_start(self): """Starts receiver listener for detector data packets and create a data file (if file write enabled).""" self.startReceiver() @@ -1563,6 +1622,20 @@ class Detector(CppDetectorApi): def trimval(self, value): ut.set_using_dict(self.setAllTrimbits, value) + @property + @element + def fliprows(self): + """ + [Eiger] flips rows paramater sent to slsreceiver to stream as json parameter to flip rows in gui. \n + [Jungfrau] flips rows in the detector itself. For bottom module and number of interfaces must be set to 2. slsReceiver and slsDetectorGui does not handle. + """ + return self.getFlipRows() + + @fliprows.setter + def fliprows(self, value): + ut.set_using_dict(self.setFlipRows, value) + + @property @element def master(self): @@ -1588,6 +1661,19 @@ class Detector(CppDetectorApi): def sync(self, value): ut.set_using_dict(self.setSynchronization, value) + @property + @element + def badchannels(self): + """ + [fname|none|0]\n\t[Gotthard2][Mythen3] Sets the bad channels (from file of bad channel numbers) to be masked out. None or 0 unsets all the badchannels.\n + [Mythen3] Also does trimming + """ + return self.getBadChannels() + + @badchannels.setter + def badchannels(self, value): + ut.set_using_dict(self.setBadChannels, value) + @property @element def lock(self): @@ -1696,6 +1782,11 @@ class Detector(CppDetectorApi): """Gets the list of timing modes (timingMode) for this detector.""" return self.getTimingModeList() + @property + def readoutspeedlist(self): + """List of readout speed levels implemented for this detector.""" + return self.getReadoutSpeedList() + @property def templist(self): """List of temperature enums (dacIndex) implemented for this detector.""" @@ -1797,25 +1888,24 @@ class Detector(CppDetectorApi): @property def versions(self): - if self.type == detectorType.EIGER: - return {'type': self.type, + version_list = {'type': self.type, 'package': self.packageversion, 'client': self.clientversion, - 'firmware (Beb)': self.firmwareversion, - 'firmware(Febl)': self.getFrontEndFirmwareVersion(slsDetectorDefs.fpgaPosition.FRONT_LEFT), - 'firmware (Febr)': self.getFrontEndFirmwareVersion(slsDetectorDefs.fpgaPosition.FRONT_RIGHT), 'detectorserver': self.detectorserverversion, - 'kernel': self.kernelversion, - 'receiver': self.rx_version} + 'kernel': self.kernelversion} - return {'type': self.type, - 'package': self.packageversion, - 'client': self.clientversion, - 'firmware': self.firmwareversion, - 'detectorserver': self.detectorserverversion, - 'hardware':self.hardwareversion, - 'kernel': self.kernelversion, - 'receiver': self.rx_version} + if self.type == detectorType.EIGER: + version_list ['firmware (Beb)'] = self.firmwareversion + version_list ['firmware(Febl)'] = self.getFrontEndFirmwareVersion(slsDetectorDefs.fpgaPosition.FRONT_LEFT) + version_list ['firmware (Febr)'] = self.getFrontEndFirmwareVersion(slsDetectorDefs.fpgaPosition.FRONT_RIGHT) + else: + version_list ['firmware'] = self.firmwareversion + version_list ['hardware'] = self.hardwareversion + + if self.use_receiver: + version_list ['receiver'] = self.rx_version + + return version_list @property def virtual(self): @@ -3103,6 +3193,17 @@ class Detector(CppDetectorApi): def dbitclk(self, value): ut.set_using_dict(self.setDBITClock, value) + @property + @element + def adcvpp(self): + """[Ctb][Moench] Vpp of ADC. [0 -> 1V | 1 -> 1.14V | 2 -> 1.33V | 3 -> 1.6V | 4 -> 2V] \n + Advanced User function!""" + return self.getADCVpp(False) + + @adcvpp.setter + def adcvpp(self, value): + ut.set_using_dict(self.setADCVpp, value, False) + @property @element def dbitpipeline(self): @@ -3713,6 +3814,23 @@ class Detector(CppDetectorApi): """ return self.getMeasuredCurrent(dacIndex.I_POWER_IO) + @property + def clkphase(self): + """ + [Gotthard2][Mythen3] Phase shift of all clocks. + + Example + ------- + >>> d.clkphase[0] = 20 + >>> d.clkphase + 0: 20 + 1: 10 + 2: 20 + 3: 10 + 4: 10 + 5: 5 + """ + return ClkPhaseProxy(self) @property def clkdiv(self): diff --git a/python/slsdet/gaincaps.py b/python/slsdet/gaincaps.py new file mode 100644 index 000000000..ab3acd381 --- /dev/null +++ b/python/slsdet/gaincaps.py @@ -0,0 +1,42 @@ + + +import _slsdet +gc = _slsdet.slsDetectorDefs.M3_GainCaps + + +class Mythen3GainCapsWrapper: + """Holds M3_GainCaps enums and facilitates printing""" + # 'M3_C10pre', 'M3_C15pre', 'M3_C15sh', 'M3_C225ACsh', 'M3_C30sh', 'M3_C50sh' + all_bits = gc.M3_C10pre | gc.M3_C15pre | gc.M3_C15sh | gc.M3_C225ACsh | gc.M3_C30sh | gc.M3_C50sh + all_caps = (gc.M3_C10pre, gc.M3_C15pre, gc.M3_C15sh, gc.M3_C225ACsh, gc.M3_C30sh, gc.M3_C50sh) + def __init__(self, value = 0): + self._validate(value) + self.value = value + + + def __eq__(self, other) -> bool: + if isinstance(other, Mythen3GainCapsWrapper): + return self.value == other.value + else: + return self.value == other + + + def __ne__(self, other) -> bool: + return not self.__eq__(other) + + def __str__(self) -> str: + s = ', '.join(str(c).rsplit('_', 1)[1] for c in self.all_caps if self.value & c) + return s + + def __repr__(self) -> str: + return self.__str__() + + def _validate(self, value): + """Check that only bits representing real capacitors are set""" + if isinstance(value, gc): + return True + elif isinstance(value, int): + if value & (~self.all_bits): + raise ValueError(f"The value: {value} is not allowed for Mythen3GainCapsWrapper") + else: + raise ValueError("GainCaps can only be initialized from int or M3_GainCaps enum") \ No newline at end of file diff --git a/python/slsdet/mythen3.py b/python/slsdet/mythen3.py index b018699df..369d6ac99 100644 --- a/python/slsdet/mythen3.py +++ b/python/slsdet/mythen3.py @@ -13,6 +13,7 @@ from .detector import Detector, freeze from .dacs import DetectorDacs import _slsdet dacIndex = _slsdet.slsDetectorDefs.dacIndex +gc_enums = _slsdet.slsDetectorDefs.M3_GainCaps from .detector_property import DetectorProperty @@ -62,4 +63,6 @@ class Mythen3(Detector): @property def dacs(self): - return self._dacs \ No newline at end of file + return self._dacs + + diff --git a/python/slsdet/proxy.py b/python/slsdet/proxy.py index a02a3267a..90c9f4523 100644 --- a/python/slsdet/proxy.py +++ b/python/slsdet/proxy.py @@ -4,6 +4,7 @@ from .utils import element_if_equal from .enums import dacIndex from .defines import M3_MAX_PATTERN_LEVELS, MAX_PATTERN_LEVELS from _slsdet import slsDetectorDefs +detectorType = slsDetectorDefs.detectorType def set_proxy_using_dict(func, key, value, unpack = False): @@ -87,7 +88,10 @@ class ClkDivProxy: def __repr__(self): rstr = '' - for i in range(6): + num_clocks = 6 + if self.det.type == detectorType.MYTHEN3: + num_clocks = 5 + for i in range(num_clocks): r = element_if_equal(self.__getitem__(i)) if isinstance(r, list): rstr += ' '.join(f'{item}' for item in r) @@ -96,10 +100,35 @@ class ClkDivProxy: return rstr.strip('\n') +class ClkPhaseProxy: + """ + Proxy class to allow for more intuitive reading clock phase + """ + def __init__(self, det): + self.det = det + + def __getitem__(self, key): + return element_if_equal(self.det.getClockPhase(key)) + + def __setitem__(self, key, value): + set_proxy_using_dict(self.det.setClockPhase, key, value) + + def __repr__(self): + rstr = '' + if self.det.type == detectorType.MYTHEN3: + num_clocks = 5 + for i in range(num_clocks): + r = element_if_equal(self.__getitem__(i)) + if isinstance(r, list): + rstr += ' '.join(f'{item}' for item in r) + else: + rstr += f'{i}: {r}\n' + + return rstr.strip('\n') class MaxPhaseProxy: """ - Proxy class to allow for more intuitive reading clockdivider + Proxy class to allow for more intuitive reading max clock phase shift """ def __init__(self, det): self.det = det @@ -109,7 +138,9 @@ class MaxPhaseProxy: def __repr__(self): rstr = '' - for i in range(5): + if self.det.type == detectorType.MYTHEN3: + num_clocks = 5 + for i in range(num_clocks): r = element_if_equal(self.__getitem__(i)) if isinstance(r, list): rstr += ' '.join(f'{item}' for item in r) @@ -120,7 +151,7 @@ class MaxPhaseProxy: class ClkFreqProxy: """ - Proxy class to allow for more intuitive reading clockdivider + Proxy class to allow for more intuitive reading clock frequency """ def __init__(self, det): self.det = det @@ -130,7 +161,9 @@ class ClkFreqProxy: def __repr__(self): rstr = '' - for i in range(5): + if self.det.type == detectorType.MYTHEN3: + num_clocks = 5 + for i in range(num_clocks): r = element_if_equal(self.__getitem__(i)) if isinstance(r, list): rstr += ' '.join(f'{item}' for item in r) diff --git a/python/src/detector.cpp b/python/src/detector.cpp index 708bfe0b3..9d7fba35e 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -224,6 +224,21 @@ void init_det(py::module &m) { (void (Detector::*)(const std::string &, sls::Positions)) & Detector::setBadChannels, py::arg(), py::arg() = Positions{}); + CppDetectorApi.def( + "getBadChannels", + (Result>(Detector::*)(sls::Positions) const) & + Detector::getBadChannels, + py::arg() = Positions{}); + CppDetectorApi.def( + "setBadChannels", + (void (Detector::*)(const std::vector, sls::Positions)) & + Detector::setBadChannels, + py::arg(), py::arg() = Positions{}); + CppDetectorApi.def( + "setBadChannels", + (void (Detector::*)(const std::vector>)) & + Detector::setBadChannels, + py::arg()); CppDetectorApi.def("isVirtualDetectorServer", (Result(Detector::*)(sls::Positions) const) & Detector::isVirtualDetectorServer, diff --git a/python/tests/test_m3gaincaps.py b/python/tests/test_m3gaincaps.py new file mode 100644 index 000000000..d1e5e4bcc --- /dev/null +++ b/python/tests/test_m3gaincaps.py @@ -0,0 +1,24 @@ +import pytest + +from slsdet import Mythen3GainCapsWrapper +from slsdet.enums import M3_GainCaps #this is the c++ enum + + +def test_comapre_with_int(): + c = Mythen3GainCapsWrapper(128) #C10pre + assert c == 128 + assert c != 5 + assert c != 1280 + +def test_compare_with_other(): + a = Mythen3GainCapsWrapper(128) + b = Mythen3GainCapsWrapper(1<<10) + c = Mythen3GainCapsWrapper(128) + assert a!=b + assert (a==b) == False + assert a==c + +def test_can_be_default_constructed(): + c = Mythen3GainCapsWrapper() + assert c == 0 + diff --git a/serverBin/ctbDetectorServerv7.0.0 b/serverBin/ctbDetectorServerv7.0.0 new file mode 120000 index 000000000..bc7dc05d2 --- /dev/null +++ b/serverBin/ctbDetectorServerv7.0.0 @@ -0,0 +1 @@ +../slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServerv7.0.0 \ No newline at end of file diff --git a/serverBin/eigerDetectorServerv7.0.0 b/serverBin/eigerDetectorServerv7.0.0 new file mode 120000 index 000000000..06272c8f6 --- /dev/null +++ b/serverBin/eigerDetectorServerv7.0.0 @@ -0,0 +1 @@ +../slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv7.0.0 \ No newline at end of file diff --git a/serverBin/gotthard2DetectorServerv7.0.0 b/serverBin/gotthard2DetectorServerv7.0.0 new file mode 120000 index 000000000..6e601d619 --- /dev/null +++ b/serverBin/gotthard2DetectorServerv7.0.0 @@ -0,0 +1 @@ +../slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServerv7.0.0 \ No newline at end of file diff --git a/serverBin/gotthardDetectorServerv7.0.0 b/serverBin/gotthardDetectorServerv7.0.0 new file mode 120000 index 000000000..d8d2d651e --- /dev/null +++ b/serverBin/gotthardDetectorServerv7.0.0 @@ -0,0 +1 @@ +../slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServerv7.0.0 \ No newline at end of file diff --git a/serverBin/jungfrauDetectorServerv7.0.0 b/serverBin/jungfrauDetectorServerv7.0.0 new file mode 120000 index 000000000..c91c000b3 --- /dev/null +++ b/serverBin/jungfrauDetectorServerv7.0.0 @@ -0,0 +1 @@ +../slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServerv7.0.0 \ No newline at end of file diff --git a/serverBin/moenchDetectorServerv7.0.0 b/serverBin/moenchDetectorServerv7.0.0 new file mode 120000 index 000000000..ea12c878c --- /dev/null +++ b/serverBin/moenchDetectorServerv7.0.0 @@ -0,0 +1 @@ +../slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServerv7.0.0 \ No newline at end of file diff --git a/serverBin/mythen3DetectorServerv7.0.0 b/serverBin/mythen3DetectorServerv7.0.0 new file mode 120000 index 000000000..f5fe23393 --- /dev/null +++ b/serverBin/mythen3DetectorServerv7.0.0 @@ -0,0 +1 @@ +../slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServerv7.0.0 \ No newline at end of file diff --git a/slsDetectorCalibration/dataStructures/jungfrauModuleData.h b/slsDetectorCalibration/dataStructures/jungfrauModuleData.h index ab7b7e463..272a8a831 100644 --- a/slsDetectorCalibration/dataStructures/jungfrauModuleData.h +++ b/slsDetectorCalibration/dataStructures/jungfrauModuleData.h @@ -40,20 +40,31 @@ class jungfrauModuleData : public slsDetectorData { out by a module i.e. using the slsReceiver (160x160 pixels, 40 packets 1286 large etc.) \param c crosstalk parameter for the output buffer - */ + */ +#ifndef ZMQ +#define off sizeof(jf_header) +#endif +#ifdef ZMQ +#define off 0 +#endif + + jungfrauModuleData() : slsDetectorData(1024, 512, - 1024* 512 * 2 + sizeof(jf_header)) { - + 1024* 512 * 2 + off) { + for (int ix = 0; ix < 1024; ix++) { for (int iy = 0; iy < 512; iy++) { - dataMap[iy][ix] = sizeof(jf_header) + (1024 * iy + ix) * 2; + dataMap[iy][ix] = off + (1024 * iy + ix) * 2; #ifdef HIGHZ dataMask[iy][ix] = 0x3fff; #endif } } + + + iframe = 0; // cout << "data struct created" << endl; }; diff --git a/slsDetectorCalibration/jungfrauExecutables/Makefile.rawdataprocess b/slsDetectorCalibration/jungfrauExecutables/Makefile.rawdataprocess new file mode 100644 index 000000000..d4fa773fc --- /dev/null +++ b/slsDetectorCalibration/jungfrauExecutables/Makefile.rawdataprocess @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: LGPL-3.0-or-other +# Copyright (C) 2021 Contributors to the SLS Detector Package +#module add CBFlib/0.9.5 +INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ -I../tiffio/include + +LDFLAG= ../tiffio/src/tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -pthread -lrt -ltiff -O3 -std=c++11 + +MAIN=jungfrauClusterFinder.cpp + + +all: jungfrauRawDataProcess + +jungfrauRawDataProcess: jungfrauRawDataProcess.cpp $(INCS) clean + g++ -o jungfrauRawDataProcess jungfrauRawDataProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DMODULE + +jungfrauRawDataProcessStrx: jungfrauRawDataProcess.cpp $(INCS) clean + g++ -o jungfrauRawDataProcessStrx jungfrauRawDataProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DJFSTRX + +jungfrauRawDataProcessStrxAldo: jungfrauRawDataProcess.cpp $(INCS) clean + g++ -o jungfrauRawDataProcessStrxAldo jungfrauRawDataProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DJFSTRX -DALDO + +jungfrauRawDataProcessStrxOld: jungfrauRawDataProcess.cpp $(INCS) clean + g++ -o jungfrauRawDataProcessStrxOld jungfrauRawDataProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DJFSTRXOLD + +jungfrauRawDataProcessStrxOldAldo: jungfrauRawDataProcess.cpp $(INCS) clean + g++ -o jungfrauRawDataProcessStrxOldAldo jungfrauRawDataProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DJFSTRXOLD -DALDO + + + +jungfrauClusterFinder: jungfrauClusterFinder.cpp $(INCS) clean + g++ -o jungfrauClusterFinder jungfrauClusterFinder.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL + + +jungfrauClusterFinderHighZ: jungfrauClusterFinder.cpp $(INCS) clean + g++ -o jungfrauClusterFinderHighZ jungfrauClusterFinder.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DHIGHZ + + + + +jungfrauMakeEta: jungfrauInterpolation.cpp $(INCS) clean + g++ -o jungfrauMakeEta jungfrauInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DFF + +jungfrauInterpolation: jungfrauInterpolation.cpp $(INCS) clean + g++ -o jungfrauInterpolation jungfrauInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) + +jungfrauNoInterpolation: jungfrauNoInterpolation.cpp $(INCS) clean + g++ -o jungfrauNoInterpolation jungfrauNoInterpolation.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) + +jungfrauPhotonCounter: jungfrauPhotonCounter.cpp $(INCS) clean + g++ -o jungfrauPhotonCounter jungfrauPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER + +jungfrauAnalog: jungfrauPhotonCounter.cpp $(INCS) clean + g++ -o jungfrauAnalog jungfrauPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DANALOG + +jungfrauPhotonCounterHighZ: jungfrauPhotonCounter.cpp $(INCS) clean + g++ -o jungfrauPhotonCounterHighZ jungfrauPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DHIGHZ + +jungfrauAnalogHighZ: jungfrauPhotonCounter.cpp $(INCS) clean + g++ -o jungfrauAnalogHighZ jungfrauPhotonCounter.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWRECEIVER -DANALOG -DHIGHZ + +clean: + rm -f jungfrauClusterFinder jungfrauMakeEta jungfrauInterpolation jungfrauNoInterpolation jungfrauPhotonCounter jungfrauAnalog + + diff --git a/slsDetectorCalibration/jungfrauExecutables/Makefile.zmq b/slsDetectorCalibration/jungfrauExecutables/Makefile.zmq index af60de798..007e8cfed 100644 --- a/slsDetectorCalibration/jungfrauExecutables/Makefile.zmq +++ b/slsDetectorCalibration/jungfrauExecutables/Makefile.zmq @@ -1,25 +1,19 @@ # SPDX-License-Identifier: LGPL-3.0-or-other # Copyright (C) 2021 Contributors to the SLS Detector Package -INCDIR= -I. -I../dataStructures ../tiffIO.cpp -I../ -I../interpolations/ -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ -I../../libs/rapidjson/ +INCDIR= -I. -I../dataStructures ../tiffio/src/tiffIO.cpp -I../ -I../interpolations/ -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ -I../../libs/rapidjson/ -I../tiffio/include LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -O3 -std=c++11 -Wall -L../../build/bin/ -lSlsSupport #-L../../bin -lhdf5 -L. #DESTDIR?=../bin -all: moenchZmqProcess moenchZmq04Process - #moenchZmqProcessCtbGui +all: jungfrauZmqProcess + #jungfrauZmqProcessCtbGui -moenchZmqProcess: moenchZmqProcess.cpp clean - g++ -o moenchZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP - -moenchZmq04Process: moenchZmqProcess.cpp clean - g++ -o moench04ZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DMOENCH04 - -#moenchZmqProcessCtbGui: moenchZmqProcess.cpp clean -# g++ -o moenchZmqProcessCtbGui moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DCTBGUI +jungfrauZmqProcess: jungfrauZmqProcess.cpp clean + g++ -o jungfrauZmqProcess jungfrauZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP clean: - rm -f moenchZmqProcess + rm -f jungfrauZmqProcess diff --git a/slsDetectorCalibration/jungfrauExecutables/Makefile.zmqrootdisp b/slsDetectorCalibration/jungfrauExecutables/Makefile.zmqrootdisp new file mode 100644 index 000000000..86db24343 --- /dev/null +++ b/slsDetectorCalibration/jungfrauExecutables/Makefile.zmqrootdisp @@ -0,0 +1,26 @@ +ROOTSYS=/opt/cern/v6/root +#/afs/psi.ch/project/sls_det_sof/roottware/root_v5.34.23_sl6_64bit + + + +LIBZMQDIR = $(PWD) +LIBZMQ = -L$(LIBZMQDIR) -lzmq +SHLIB_PATH=/opt/cern/v6/root/lib +CMAKE_PREFIX_PATH=/opt/cern/v6/root +DYLD_LIBRARY_PATH=/opt/cern/v6/root/lib + + +INCDIR= -I. -I../dataStructures ../tiffio/src/tiffIO.cpp -I../ -I../interpolations/ -I../../slsSupportLib/include/ -I../../slsReceiverSoftware/include/ -I../../libs/rapidjson/ -I../tiffio/include +LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -O3 -std=c++11 -Wall -L../../build/bin/ -lSlsSupport +#-L../../bin -lhdf5 -L. + + + +default: onlinedisp_zmq + +onlinedisp_zmq: onlinedisp_zmq.cpp onlinedisp_zmq.h +# flags from root-config --cflags --glibs + g++ -o onlinedisp_zmq onlinedisp_zmq.cpp -I. -I$(ROOTSYS)/include -Wall -g -lm -L. -lzmq -pthread -lrt -L$(ROOTSYS)/lib -lGui -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -m64 $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) + +#-lCint + diff --git a/slsDetectorCalibration/jungfrauExecutables/examples.txt b/slsDetectorCalibration/jungfrauExecutables/examples.txt new file mode 100644 index 000000000..b72d370e1 --- /dev/null +++ b/slsDetectorCalibration/jungfrauExecutables/examples.txt @@ -0,0 +1,10 @@ + + + sls_detector_put rx_jsonpara detectorMode counting + sls_detector_put rx_jsonpara frameMode newPedestal + sls_detector_put rx_jsonpara frameMode frame + sls_detector_put rx_jsonpara detectorMode analog + sls_detector_put rx_jsonpara threshold 150 + sls_detector_put rx_jsonpara threshold 0 + sls_detector_put rx_jsonpara threshold 300 + sls_detector_put rx_zmqhwm 50 diff --git a/slsDetectorCalibration/jungfrauExecutables/jungfrauRawDataProcess.cpp b/slsDetectorCalibration/jungfrauExecutables/jungfrauRawDataProcess.cpp new file mode 100644 index 000000000..1f574a49b --- /dev/null +++ b/slsDetectorCalibration/jungfrauExecutables/jungfrauRawDataProcess.cpp @@ -0,0 +1,418 @@ +// SPDX-License-Identifier: LGPL-3.0-or-other +// Copyright (C) 2021 Contributors to the SLS Detector Package +//#include "sls/ansi.h" +#include +#undef CORR + +#define C_GHOST 0.0004 + +#define CM_ROWS 50 + +#define RAWDATA + +#ifndef JFSTRX +#ifndef JFSTRXOLD +#ifndef MODULE +#include "jungfrauHighZSingleChipData.h" +#endif +#ifdef MODULE +#include "jungfrauModuleData.h" +#endif +#endif +#endif +#ifdef JFSTRX +#include "jungfrauLGADStrixelsData.h" +#endif +#ifdef JFSTRXOLD +#include "jungfrauStrixelsHalfModuleOldDesign.h" +#endif + +#include "multiThreadedCountingDetector.h" +#include "singlePhotonDetector.h" + +#include +#include +#include +#include + +#include +using namespace std; + +int main(int argc, char *argv[]) { + + if (argc < 5) { + cout << "Usage is " << argv[0] + << "indir outdir fname(no extension) fextension [runmin] [runmax] [pedfile (raw or tiff)] [threshold] " + "[nframes] [xmin xmax ymin ymax] [gainmap]" + << endl; + cout << "threshold <0 means analog; threshold=0 means cluster finder; " + "threshold>0 means photon counting" + << endl; + cout << "nframes <0 means sum everything; nframes=0 means one file per " + "run; nframes>0 means one file every nframes" + << endl; + return 1; + } + + int fifosize = 1000; + int nthreads = 10; + int csize = 3; + int nsigma = 5; + int nped = 10000; + + int cf = 0; + + +#ifndef JFSTRX +#ifndef JFSTRXOLD +#ifndef MODULE + jungfrauHighZSingleChipData *decoder = new jungfrauHighZSingleChipData(); + int nx = 256, ny = 256; +#endif +#ifdef MODULE + jungfrauModuleData *decoder = new jungfrauModuleData(); + int nx = 1024, ny = 512; + +#endif +#endif +#endif +#ifdef JFSTRX + cout << "bbb" << endl; + jungfrauLGADStrixelsData *decoder = new jungfrauLGADStrixelsData(); + int nx = 1024/5, ny = 512*5; +#endif +#ifdef JFSTRXOLD + cout << "ccc" << endl; + jungfrauStrixelsHalfModuleOldDesign *decoder = new jungfrauStrixelsHalfModuleOldDesign(); + int nx = 1024*3, ny = 512/3; +#endif + + + decoder->getDetectorSize(nx, ny); + + + + + + cout << "Detector size is " << nx << " " << ny << endl; + + + + + + + + + double *gainmap = NULL; + //float *gm; + + int ff, np; + // cout << " data size is " << dsize; + + ifstream filebin; + char *indir = argv[1]; + char *outdir = argv[2]; + char *fformat = argv[3]; + char *fext = argv[4]; + int runmin = 0; + + // cout << "argc is " << argc << endl; + if (argc >= 6) { + runmin = atoi(argv[5]); + } + + int runmax = runmin; + + if (argc >= 7) { + runmax = atoi(argv[6]); + } + + char *pedfile = NULL; + if (argc >= 8) { + pedfile = argv[7]; + } + double thr = 0; + double thr1 = 1; + + if (argc >= 9) { + thr = atof(argv[8]); + } + + int nframes = 0; + + if (argc >= 10) { + nframes = atoi(argv[9]); + } + + int xmin = 0, xmax = nx, ymin = 0, ymax = ny; + if (argc >= 14) { + xmin = atoi(argv[10]); + xmax = atoi(argv[11]); + ymin = atoi(argv[12]); + ymax = atoi(argv[13]); + } + + char *gainfname = NULL; + if (argc > 14) { + gainfname = argv[14]; + cout << "Gain map file name is: " << gainfname << endl; + } + + char ffname[10000]; + char fname[10000]; + char imgfname[10000]; + char cfname[10000]; + + std::time_t end_time; + + FILE *of = NULL; + cout << "input directory is " << indir << endl; + cout << "output directory is " << outdir << endl; + cout << "input file is " << fformat << endl; + cout << "runmin is " << runmin << endl; + cout << "runmax is " << runmax << endl; + if (pedfile) + cout << "pedestal file is " << pedfile << endl; + if (thr > 0) + cout << "threshold is " << thr << endl; + cout << "Nframes is " << nframes << endl; + + uint32_t nnx, nny; + + singlePhotonDetector *filter = new singlePhotonDetector( + decoder, csize, nsigma, 1, NULL, nped, 200, -1, -1, gainmap, NULL); + + if (gainfname) { + + if (filter->readGainMap(gainfname)) + cout << "using gain map " << gainfname << endl; + else + cout << "Could not open gain map " << gainfname << endl; + } else + thr = 0.15 * thr; + filter->newDataSet(); + //int dsize = decoder->getDataSize(); + + if (thr > 0) { + cout << "threshold is " << thr << endl; + filter->setThreshold(thr); + cf = 0; + + } else + cf = 1; + + filter->setROI(xmin, xmax, ymin, ymax); + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + + char *buff; + + // multiThreadedAnalogDetector *mt=new + // multiThreadedAnalogDetector(filter,nthreads,fifosize); + multiThreadedCountingDetector *mt = + new multiThreadedCountingDetector(filter, nthreads, fifosize); +#ifndef ANALOG + mt->setDetectorMode(ePhotonCounting); + cout << "Counting!" << endl; + if (thr > 0) { + cf = 0; + } +#endif +//{ +#ifdef ANALOG + mt->setDetectorMode(eAnalog); + cout << "Analog!" << endl; + cf = 0; + // thr1=thr; +#endif + // } + + mt->StartThreads(); + mt->popFree(buff); + + // cout << "mt " << endl; + + int ifr = 0; + + char froot[1000]; + double *ped=new double[nx * ny];//, *ped1; + + int pos,pos1; + + if (pedfile) { + + if (string(pedfile).find(".dat") != std::string::npos) { + pos1=string(pedfile).rfind("/"); + strcpy(froot,pedfile+pos1); + pos=string(froot).find(".dat"); + froot[pos]='\0'; + } + + cout << "PEDESTAL " << endl; + // sprintf(imgfname, "%s/pedestals.tiff", outdir); + + if (string(pedfile).find(".tif") == std::string::npos) { + sprintf(fname, "%s", pedfile); + cout << fname << endl; + std::time(&end_time); + //cout << "aaa" << std::ctime(&end_time) << endl; + + mt->setFrameMode(ePedestal); + // sprintf(fn,fformat,irun); + filebin.open((const char *)(fname), ios::in | ios::binary); + // //open file + if (filebin.is_open()) { + ff = -1; + while (decoder->readNextFrame(filebin, ff, np, buff)) { + // if (np == 40) { + if ((ifr+1) % 100 == 0) { + cout << " ****" << decoder->getValue(buff,20,20);// << endl; + } + mt->pushData(buff); + mt->nextThread(); + mt->popFree(buff); + ifr++; + if (ifr % 100 == 0) { + cout << " ****" << ifr << " " << ff << " " << np << endl; + } //else + //cout << ifr << " " << ff << " " << np << endl; + if (ifr>=1000) + break; + ff = -1; + } + filebin.close(); + while (mt->isBusy()) { + ; + } + + sprintf(imgfname, "%s/%s_ped.tiff", outdir, froot); + mt->writePedestal(imgfname); + sprintf(imgfname, "%s/%s_rms.tiff", outdir, froot); + mt->writePedestalRMS(imgfname); + + } else + cout << "Could not open pedestal file " << fname + << " for reading " << endl; + } else { + float *pp = ReadFromTiff(pedfile, nny, nnx); + if (pp && (int)nnx == nx && (int)nny == ny) { + for (int i = 0; i < nx * ny; i++) { + ped[i] = pp[i]; + } + delete[] pp; + mt->setPedestal(ped); + cout << "Pedestal set from tiff file " << pedfile << endl; + } else { + cout << "Could not open pedestal tiff file " << pedfile + << " for reading " << endl; + } + } + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + } + + ifr = 0; + int ifile = 0; + + mt->setFrameMode(eFrame); + + for (int irun = runmin; irun <= runmax; irun++) { + cout << "DATA "; + // sprintf(fn,fformat,irun); + sprintf(ffname, "%s/%s.%s", indir, fformat, fext); + sprintf(fname, (const char*)ffname, irun); + sprintf(ffname, "%s/%s.tiff", outdir, fformat); + sprintf(imgfname, (const char*)ffname, irun); + sprintf(ffname, "%s/%s.clust", outdir, fformat); + sprintf(cfname, (const char*)ffname, irun); + cout << fname << " "; + cout << imgfname << endl; + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + // cout << fname << " " << outfname << " " << imgfname << endl; + filebin.open((const char *)(fname), ios::in | ios::binary); + // //open file + ifile = 0; + if (filebin.is_open()) { + if (thr <= 0 && cf != 0) { // cluster finder + if (of == NULL) { + of = fopen(cfname, "w"); + if (of) { + mt->setFilePointer(of); + cout << "file pointer set " << endl; + } else { + cout << "Could not open " << cfname << " for writing " + << endl; + mt->setFilePointer(NULL); + return 1; + } + } + } + // //while read frame + ff = -1; + ifr = 0; + while (decoder->readNextFrame(filebin, ff, np, buff)) { + // if (np == 40) { + // //push + + if ((ifr+1) % 100 == 0) { + cout << " ****" << decoder->getValue(buff,20,20);// << endl; + } + mt->pushData(buff); + // // //pop + mt->nextThread(); + mt->popFree(buff); + + ifr++; + if (ifr % 100 == 0) + cout << " " << ifr << " " << ff << endl; + if (nframes > 0) { + if (ifr % nframes == 0) { + sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat, + ifile); + sprintf(imgfname, (const char*)ffname, irun); + mt->writeImage(imgfname, thr1); + mt->clearImage(); + ifile++; + } + } + // } else + // cout << ifr << " " << ff << " " << np << endl; + ff = -1; + } + cout << "--" << endl; + filebin.close(); + while (mt->isBusy()) { + ; + } + if (nframes >= 0) { + if (nframes > 0) { + sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat, ifile); + sprintf(imgfname, (const char*)ffname, irun); + } else { + sprintf(ffname, "%s/%s.tiff", outdir, fformat); + sprintf(imgfname, (const char*)ffname, irun); + } + cout << "Writing tiff to " << imgfname << " " << thr1 << endl; + mt->writeImage(imgfname, thr1); + mt->clearImage(); + if (of) { + fclose(of); + of = NULL; + mt->setFilePointer(NULL); + } + } + std::time(&end_time); + cout << std::ctime(&end_time) << endl; + } else + cout << "Could not open " << fname << " for reading " << endl; + } + if (nframes < 0) { + sprintf(ffname, "%s/%s.tiff", outdir, fformat); + strcpy(imgfname, ffname); + cout << "Writing tiff to " << imgfname << " " << thr1 << endl; + mt->writeImage(imgfname, thr1); + } + + return 0; +} diff --git a/slsDetectorCalibration/jungfrauExecutables/jungfrauZmqProcess.cpp b/slsDetectorCalibration/jungfrauExecutables/jungfrauZmqProcess.cpp index 7977e208d..994729355 100644 --- a/slsDetectorCalibration/jungfrauExecutables/jungfrauZmqProcess.cpp +++ b/slsDetectorCalibration/jungfrauExecutables/jungfrauZmqProcess.cpp @@ -1,28 +1,26 @@ // SPDX-License-Identifier: LGPL-3.0-or-other // Copyright (C) 2021 Contributors to the SLS Detector Package //#define WRITE_QUAD -#define DEVELOPER +//#define DEVELOPER #undef CORR +//#undef MOENCH04 + #define C_GHOST 0.0004 #define CM_ROWS 20 +#define ZMQ #include "sls/ZmqSocket.h" #include "sls/sls_detector_defs.h" -#ifndef RECT -#ifndef MOENCH04 -#include "moench03T1ZmqDataNew.h" -#endif -#ifdef MOENCH04 -#include "moench04CtbZmq10GbData.h" -#endif -#endif -#ifdef RECT -#include "moench03T1ZmqDataNewRect.h" -#endif +//#include "moench03T1ZmqDataNew.h" + +#include "jungfrauModuleData.h" + + #include "moench03CommonMode.h" #include "moench03GhostSummation.h" + #include "sls/tiffIO.h" #include #include @@ -57,983 +55,852 @@ using namespace std::chrono; //\"what\":\"nothing\" "); int main(int argc, char *argv[]) { - /** - * trial.o [socket ip] [starting port number] [send_socket ip] [send port - * number] - * - */ - FILE *of = NULL; - int fifosize = 5000; - int etabins = 1000, etabinsy = 1000; // nsubpix*2*100; - double etamin = -1, etamax = 2; - int nSubPixelsX = 2; - // int emin, emax; - int nSubPixelsY = 2; - // help - if (argc < 3) { - cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port " - "number] [send_socket ip] [send starting port number] " - "[nthreads] [nsubpix] [gainmap] [etafile]\n"); - return EXIT_FAILURE; - } + /** + * trial.o [socket ip] [starting port number] [send_socket ip] [send port + * number] + * + */ + FILE *of = NULL; + int fifosize = 500; + int etabins = 1000, etabinsy = 1000; // nsubpix*2*100; + double etamin = -1, etamax = 2; + int nSubPixelsX = 2; + int emin, emax; + int nSubPixelsY = 2; - // receive parameters - bool send = false; - char *socketip = argv[1]; - uint32_t portnum = atoi(argv[2]); - // send parameters if any - char *socketip2 = 0; - uint32_t portnum2 = 0; + // help + if (argc < 3) { + cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port " + "number] [send_socket ip] [send starting port number] " + "[nthreads] [nsubpix] [gainmap] [etafile]\n"); + return EXIT_FAILURE; + } - zmqHeader zHeader, outHeader; - zHeader.jsonversion = SLS_DETECTOR_JSON_HEADER_VERSION; - outHeader.jsonversion = SLS_DETECTOR_JSON_HEADER_VERSION; + // receive parameters + bool send = false; + char *socketip = argv[1]; + uint32_t portnum = atoi(argv[2]); + // send parameters if any + char *socketip2 = 0; + uint32_t portnum2 = 0; - uint32_t nSigma = 5; + sls::zmqHeader zHeader, outHeader; + zHeader.jsonversion = SLS_DETECTOR_JSON_HEADER_VERSION; + outHeader.jsonversion = SLS_DETECTOR_JSON_HEADER_VERSION; - int ok; + uint32_t nSigma = 5; - high_resolution_clock::time_point t1; - high_resolution_clock::time_point t2; - std::chrono::steady_clock::time_point begin, end, finished; - // time_t begin,end,finished; - int rms = 0; + int ok; - if (argc > 4) { - socketip2 = argv[3]; - portnum2 = atoi(argv[4]); - if (portnum2 > 0) - send = true; - } - cout << "\nrx socket ip : " << socketip << "\nrx port num : " << portnum; - if (send) { - cout << "\ntx socket ip : " << socketip2 - << "\ntx port num : " << portnum2; - } - int nthreads = 5; - if (argc > 5) - nthreads = atoi(argv[5]); + high_resolution_clock::time_point t1; + high_resolution_clock::time_point t2; + std::chrono::steady_clock::time_point begin, end, finished; + // time_t begin,end,finished; + int rms = 0; - cout << "Number of threads is: " << nthreads << endl; - if (argc > 6) { - nSubPixelsX = atoi(argv[6]); - nSubPixelsY = nSubPixelsX; + if (argc > 4) { + socketip2 = argv[3]; + portnum2 = atoi(argv[4]); + if (portnum2 > 0) + send = true; + } + cout << "\nrx socket ip : " << socketip << "\nrx port num : " << portnum; + if (send) { + cout << "\ntx socket ip : " << socketip2 + << "\ntx port num : " << portnum2; + } + int nthreads = 4; + if (argc > 5) + nthreads = atoi(argv[5]); + cout << "Number of threads is: " << nthreads << endl; + + if (argc > 6) { + nSubPixelsX = atoi(argv[6]); + nSubPixelsY = nSubPixelsX; #ifdef RECT - nSubPixelsX = 2; + nSubPixelsX = 2; #endif - } - cout << "Number of subpixels is: " << nSubPixelsX << " " << nSubPixelsY - << endl; + } + cout << "Number of subpixels is: " << nSubPixelsX << " " << nSubPixelsY + << endl; - char *gainfname = NULL; - if (argc > 7) { - gainfname = argv[7]; - cout << "Gain map file name is: " << gainfname << endl; - } + char *gainfname = NULL; + if (argc > 7) { + gainfname = argv[7]; + cout << "Gain map file name is: " << gainfname << endl; + } - char *etafname = NULL; - if (argc > 8) { - etafname = argv[8]; - cout << "Eta file name is: " << etafname << endl; - } + char *etafname = NULL; + if (argc > 8) { + etafname = argv[8]; + cout << "Eta file name is: " << etafname << endl; + } - // slsDetectorData *det=new moench03T1ZmqDataNew(); -#ifndef MOENCH04 - moench03T1ZmqDataNew *det = new moench03T1ZmqDataNew(); -#endif -#ifdef MOENCH04 - moench04CtbZmq10GbData *det = new moench04CtbZmq10GbData(); -#endif - cout << endl << " det" << endl; - int npx, npy; - det->getDetectorSize(npx, npy); + // slsDetectorData *det=new moench03T1ZmqDataNew(); - int send_something = 0; - int maxSize = npx * npy * 2; // 32*2*8192;//5000;//atoi(argv[3]); - int size = maxSize; // 32*2*5000; - // int multisize=size; - // int dataSize=size; - char dummybuff[size]; + jungfrauModuleData *det = new jungfrauModuleData(); + cout << endl << " det" << endl; + int npx, npy; + det->getDetectorSize(npx, npy); - moench03CommonMode *cm = NULL; - moench03GhostSummation *gs = NULL; + int send_something = 0; + + int maxSize = npx * npy * 2; // 32*2*8192;//5000;//atoi(argv[3]); + int size = maxSize+sizeof(int); // 32*2*5000; + // int multisize=size; + // int dataSize=size; + + char *dummybuff = new char[size]; + + moench03CommonMode *cm = NULL; + moench03GhostSummation *gs = NULL; #ifdef CORR - // int ncol_cm=CM_ROWS; - // double xt_ghost=C_GHOST; + // int ncol_cm=CM_ROWS; + // double xt_ghost=C_GHOST; - cm = new moench03CommonMode(CM_ROWS); - gs = new moench03GhostSummation(det, C_GHOST); + cm = new moench03CommonMode(CM_ROWS); + gs = new moench03GhostSummation(det, C_GHOST); #endif - double *gainmap = NULL; - float *gm; - double *gmap = NULL; + double *gainmap = NULL; + float *gm; + double *gmap = NULL; - uint32_t nnnx, nnny; - if (gainfname) { - gm = ReadFromTiff(gainfname, nnny, nnnx); - if (gm && nnnx == (uint)npx && nnny == (uint)npy) { - gmap = new double[npx * npy]; - for (int i = 0; i < npx * npy; i++) { - gmap[i] = gm[i]; - } - delete[] gm; - } else - cout << "Could not open gain map " << gainfname << endl; - } + uint32_t nnnx, nnny; + if (gainfname) { + gm = ReadFromTiff(gainfname, nnny, nnnx); + if (gm && nnnx == (uint)npx && nnny == (uint)npy) { + gmap = new double[npx * npy]; + for (int i = 0; i < npx * npy; i++) { + gmap[i] = gm[i]; + } + delete[] gm; + } else + cout << "Could not open gain map " << gainfname << endl; + } - // analogDetector *filter=new - // analogDetector(det,1,NULL,1000); + // analogDetector *filter=new + // analogDetector(det,1,NULL,1000); #ifndef INTERP - singlePhotonDetector *filter = new singlePhotonDetector( - det, 3, nSigma, 1, cm, 1000, 100, -1, -1, gainmap, gs); + singlePhotonDetector *filter = new singlePhotonDetector( + det, 3, nSigma, 1, cm, 1000, 0, -1, -1, gainmap, gs); - multiThreadedCountingDetector *mt = - new multiThreadedCountingDetector(filter, nthreads, fifosize); + multiThreadedCountingDetector *mt = + new multiThreadedCountingDetector(filter, nthreads, fifosize); - // multiThreadedAnalogDetector *mt=new - // multiThreadedAnalogDetector(filter,nthreads,fifosize); + // multiThreadedAnalogDetector *mt=new + // multiThreadedAnalogDetector(filter,nthreads,fifosize); #endif #ifdef INTERP - eta2InterpolationPosXY *interp = new eta2InterpolationPosXY( - npx, npy, nSubPixelsX, nSubPixelsY, etabins, etabinsy, etamin, etamax); + eta2InterpolationPosXY *interp = new eta2InterpolationPosXY( + npx, npy, nSubPixelsX, nSubPixelsY, etabins, etabinsy, etamin, etamax); - if (etafname) - interp->readFlatField(etafname); + if (etafname) + interp->readFlatField(etafname); - interpolatingDetector *filter = new interpolatingDetector( - det, interp, nSigma, 1, cm, 1000, 10, -1, -1, gainmap, gs); - multiThreadedInterpolatingDetector *mt = - new multiThreadedInterpolatingDetector(filter, nthreads, fifosize); + interpolatingDetector *filter = new interpolatingDetector( + det, interp, nSigma, 1, cm, 1000, 10, -1, -1, gainmap, gs); + multiThreadedInterpolatingDetector *mt = + new multiThreadedInterpolatingDetector(filter, nthreads, fifosize); #endif - char *buff; - mt->setFrameMode(eFrame); - mt->StartThreads(); - mt->popFree(buff); + char *buff; + mt->setFrameMode(eFrame); + mt->StartThreads(); + mt->popFree(buff); - ZmqSocket *zmqsocket = NULL; + sls::ZmqSocket *zmqsocket = NULL; +#ifdef NEWZMQ + // receive socket + try { +#endif + + zmqsocket = new sls::ZmqSocket(socketip, portnum); + +#ifdef NEWZMQ + } catch (...) { + cprintf(RED, + "Error: Could not create Zmq socket on port %d with ip %s\n", + portnum, socketip); + delete zmqsocket; + return EXIT_FAILURE; + } +#endif + + + + if (zmqsocket->Connect()) { + cprintf(RED, "Error: Could not connect to socket %s\n", + (zmqsocket->GetZmqServerAddress()).c_str()); + delete zmqsocket; + return EXIT_FAILURE; + } else + printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress().c_str()); + + // send socket + sls::ZmqSocket *zmqsocket2 = 0; + // cout << "zmq2 " << endl; + if (send) { #ifdef NEWZMQ // receive socket try { #endif - - zmqsocket = new ZmqSocket(socketip, portnum); + zmqsocket2 = new sls::ZmqSocket(portnum2, socketip2); #ifdef NEWZMQ } catch (...) { - cprintf(RED, - "Error: Could not create Zmq socket on port %d with ip %s\n", - portnum, socketip); - delete zmqsocket; - return EXIT_FAILURE; + cprintf(RED, + "Error: Could not create Zmq socket server on port %d and " + "ip %s\n", + portnum2, socketip2); + + send = false; } #endif -#ifndef NEWZMQ - if (zmqsocket->IsError()) { - cprintf(RED, - "Error: Could not create Zmq socket on port %d with ip %s\n", - portnum, socketip); - delete zmqsocket; - return EXIT_FAILURE; - } -#endif - if (zmqsocket->Connect()) { - cprintf(RED, "Error: Could not connect to socket %s\n", - (zmqsocket->GetZmqServerAddress()).c_str()); - delete zmqsocket; - return EXIT_FAILURE; + if (zmqsocket2->Connect()) { + cprintf(RED, "Error: Could not connect to socket %s\n", + zmqsocket2->GetZmqServerAddress().c_str()); + // delete zmqsocket2; + send = false; + // return EXIT_FAILURE; } else - printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress().c_str()); + printf("Zmq Client at %s\n", + zmqsocket2->GetZmqServerAddress().c_str()); + } - // send socket - ZmqSocket *zmqsocket2 = 0; - // cout << "zmq2 " << endl; - if (send) { -#ifdef NEWZMQ - // receive socket - try { -#endif - zmqsocket2 = new ZmqSocket(portnum2, socketip2); + // header variables + uint64_t acqIndex = -1; + uint64_t frameIndex = -1; + + uint64_t subframes = 0; + uint64_t insubframe = 0; + + double subnorm = 1; + uint64_t f0 = -1, nsubframes = 0, nnsubframe = 0; + uint64_t fileindex = -1; + string filename = ""; -#ifdef NEWZMQ - } catch (...) { - cprintf(RED, - "Error: Could not create Zmq socket server on port %d and " - "ip %s\n", - portnum2, socketip2); - // delete zmqsocket2; - // zmqsocket2=NULL; - // delete zmqsocket; - // return EXIT_FAILURE; - send = false; - } -#endif + int iframe = 0; + char ofname[10000]; -#ifndef NEWZMQ - if (zmqsocket2->IsError()) { - cprintf(RED, - "AAA Error: Could not create Zmq socket server on port %d " - "and ip %s\n", - portnum2, socketip2); - // delete zmqsocket2; - // delete zmqsocket; - // return EXIT_FAILURE; - send = false; - } + string fname; + // int length; + int *detimage = NULL; + int nnx, nny, nnsx, nnsy; + uint32_t packetNumber = 0; + uint64_t detSpec1 = 0; + uint64_t timestamp = 0; + int16_t modId = 0; + uint32_t expLength = 0; + uint16_t xCoord = 0; + uint16_t yCoord = 0; + // uint16_t zCoord = 0; + uint32_t detSpec3 = 0; + // uint32_t dr = 16; + // int16_t *dout;//=new int16_t [nnx*nny]; + uint32_t dr = 32; + int32_t *dout = NULL; //=new int32_t [nnx*nny]; + float *doutf = NULL; //=new int32_t [nnx*nny]; + uint16_t detSpec4 = 0; + uint8_t detType = 0; + uint8_t version = 0; + string additionalJsonHeader = ""; + + int32_t threshold = 0; + + int32_t xmin = 0, xmax = 400, ymin = 0, ymax = 400; + + string frameMode_s, detectorMode_s, intMode_s; + + // int resetFlat=0; + // int resetPed=0; + // int nsubPixels=1; + // int isPedestal=0; + // int isFlat=0; + int newFrame = 1; + detectorMode dMode = eAnalog; + frameMode fMode = eFrame; + double *ped; + + filter->getImageSize(nnx, nny, nnsx, nnsy); + + std::map addJsonHeader; + + while (1) { + + // cout << "+++++++++++++++++++++++++++++++LOOP" << endl; + // get header, (if dummy, fail is on parse error or end of acquisition) + + // rapidjson::Document doc; + if (!zmqsocket->ReceiveHeader(0, zHeader, + SLS_DETECTOR_JSON_HEADER_VERSION)) { + /* zmqsocket->CloseHeaderMessage();*/ + + // if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, + //subframeIndex, filename, fileindex)) { + cprintf(RED, "Got Dummy\n"); + // t1=high_resolution_clock::now(); + // time(&end); + // cout << "Measurement lasted " << difftime(end,begin) << endl; + + end = std::chrono::steady_clock::now(); + cout << "Measurement lasted " << (end - begin).count() * 0.000001 + << " ms" << endl; + + while (mt->isBusy()) { + ; + } // wait until all data are processed from the queues + usleep(100); + if (of) { + mt->setFilePointer(NULL); + fclose(of); + of = NULL; + } + if (newFrame > 0) { + cprintf(RED, "DIDn't receive any data!\n"); + if (send) { + + // zHeader.data = false; + outHeader.data = false; + // zmqsocket2->SendHeaderData(0, true, + // SLS_DETECTOR_JSON_HEADER_VERSION); + zmqsocket2->SendHeader(0, outHeader); + cprintf(RED, "Sent Dummy\n"); + } + } else { + send_something = 0; + if (fMode == ePedestal) { + sprintf(ofname, "%s_%ld_ped.tiff", fname.c_str(), + fileindex); + mt->writePedestal(ofname); + cout << "Writing pedestal to " << ofname << endl; + if (rms) { + sprintf(ofname, "%s_%ld_var.tiff", fname.c_str(), + fileindex); + mt->writePedestalRMS(ofname); + } + send_something = 1; + } +#ifdef INTERP + else if (fMode == eFlat) { + mt->prepareInterpolation(ok); + sprintf(ofname, "%s_%ld_eta.tiff", fname.c_str(), + fileindex); + mt->writeFlatField(ofname); + cout << "Writing eta to " << ofname << endl; + send_something = 1; + } #endif - if (zmqsocket2->Connect()) { - cprintf(RED, "BBB Error: Could not connect to socket %s\n", - zmqsocket2->GetZmqServerAddress().c_str()); - // delete zmqsocket2; - send = false; - // return EXIT_FAILURE; - } else - printf("Zmq Client at %s\n", - zmqsocket2->GetZmqServerAddress().c_str()); + else { + if (subframes > 0) { + if (insubframe > 0) { + sprintf(ofname, "%s_sf%ld_%ld.tiff", fname.c_str(), + nnsubframe, fileindex); + // mt->writeImage(ofname); + doutf = new float[nnx * nny]; + if (subframes > 0 && insubframe != subframes && + insubframe > 0) + subnorm = + ((double)subframes) / ((double)insubframe); + else + subnorm = 1.; + for (int ix = 0; ix < nnx * nny; ix++) { + doutf[ix] = detimage[ix] * subnorm; + if (doutf[ix] < 0) + doutf[ix] = 0; + } + + cout << "Writing image to " << ofname << endl; + + WriteToTiff(doutf, ofname, nnx, nny); + + if (doutf) + delete[] doutf; + doutf = NULL; + + nsubframes++; + insubframe = 0; + send_something = 1; + } + } else { + sprintf(ofname, "%s_%ld.tiff", fname.c_str(), + fileindex); + mt->writeImage(ofname); + send_something = 1; + } + + cout << "Writing image to " << ofname << endl; + } + // cout << nns*nnx*nny*nns*dr/8 << " " << length << endl; + + if (send) { + + if (fMode == ePedestal) { + cprintf(MAGENTA, "Get pedestal!\n"); + nnsx = 1; + nnsy = 1; + + nnx = npx; + nny = npy; + // dout= new int16_t[nnx*nny*nns*nns]; + dout = new int32_t[nnx * nny * nnsx * nnsy]; + // cout << "get pedestal " << endl; + ped = mt->getPedestal(); + // cout << "got pedestal " << endl; + for (int ix = 0; ix < nnx * nny; ix++) { + + dout[ix] = ped[ix]; + + } + + } +#ifdef INTERP + else if (fMode == eFlat) { + int nbx, nby; + double emi = 0, ema = 1; + int *ff = mt->getFlatField(nbx, nby, emi, ema); + nnx = nbx; + nny = nby; + dout = new int32_t[nbx * nby]; + for (int ix = 0; ix < nbx * nby; ix++) { + dout[ix] = ff[ix]; + } + } +#endif + else { + detimage = mt->getImage(nnx, nny, nnsx, nnsy); + cprintf(MAGENTA, "Get image!\n"); + cout << nnx << " " << nny << " " << nnsx << " " << nnsy + << endl; + // nns=1; + // nnx=npx; + // nny=npy; + // nnx=nnx*nns; + // nny=nny*nns; + dout = new int32_t[nnx * nny]; + if (subframes > 0 && insubframe != subframes && + insubframe > 0) + subnorm = + ((double)subframes) / ((double)insubframe); + else + subnorm = 1.; + for (int ix = 0; ix < nnx * nny; ix++) { + // for (int iy=0; iy0 && subframes>0) || (subframes<=0) ){ + + if (send_something) { + + outHeader.data = true; + outHeader.dynamicRange = dr; + outHeader.fileIndex = fileindex; + outHeader.ndetx = 1; + outHeader.ndety = 1; + outHeader.npixelsx = nnx; + outHeader.npixelsy = nny; + outHeader.imageSize = nnx * nny * dr / 8; + outHeader.acqIndex = acqIndex; + outHeader.frameIndex = frameIndex; + outHeader.fname = fname; + outHeader.frameNumber = acqIndex; + outHeader.expLength = expLength; + outHeader.packetNumber = packetNumber; + outHeader.detSpec1 = detSpec1; + outHeader.timestamp = timestamp; + outHeader.modId = modId; + outHeader.row = xCoord; + outHeader.column = yCoord; + outHeader.detSpec3 = detSpec3; + outHeader.detSpec4 = detSpec4; + outHeader.detType = detType; + outHeader.version = version; + + zmqsocket2->SendHeader(0, outHeader); + zmqsocket2->SendData((char *)dout, nnx * nny * dr / 8); + cprintf(GREEN, "Sent Data\n"); + } + outHeader.data = false; + zmqsocket2->SendHeader(0, outHeader); + // zmqsocket2->SendHeaderData(0, true, + // SLS_DETECTOR_JSON_HEADER_VERSION); + cprintf(RED, "Sent Dummy\n"); + if (dout) + delete[] dout; + dout = NULL; + } + } + + mt->clearImage(); + + newFrame = 1; + + // time(&finished); + // cout << "Processing lasted " << difftime(finished,begin) << endl; + + finished = std::chrono::steady_clock::now(); + cout << "Processing lasted " + << (finished - begin).count() * 0.000001 << " ms" << endl; +#ifdef OPTIMIZE + return 0; +#endif + continue; // continue to not get out } - // header variables - uint64_t acqIndex = -1; - uint64_t frameIndex = -1; -#ifdef MOENCH_BRANCH - uint32_t subFrameIndex = -1; - int *flippedData = 0; -#endif + //#ifdef NEWZMQ + if (newFrame) { + begin = std::chrono::steady_clock::now(); - uint64_t subframes = 0; - // uint64_t isubframe=0; - uint64_t insubframe = 0; - double subnorm = 1; - uint64_t f0 = -1, nsubframes = 0, nnsubframe = 0; + size = zHeader.imageSize; // doc["size"].GetUint(); - uint64_t fileindex = -1; - string filename = ""; - // char* image = new char[size]; - // int* image = new int[(size/sizeof(int))](); - // uint32_t flippedDataX = -1; - // int *nph; - int iframe = 0; - char ofname[10000]; + // dynamicRange = zheader.dynamicRange; //doc["bitmode"].GetUint(); + // nPixelsX = zHeader.npixelsx; //doc["shape"][0].GetUint(); + // nPixelsY = zHeader.npixelsy;// doc["shape"][1].GetUint(); + filename = zHeader.fname; // doc["fname"].GetString(); + acqIndex = + zHeader + .acqIndex; // doc["acqIndex"].GetUint64(); + // frameIndex = + // zHeader.frameIndex;//doc["fIndex"].GetUint64(); + fileindex = zHeader.fileIndex; // doc["fileIndex"].GetUint64(); + expLength = zHeader.expLength; // doc["expLength"].GetUint(); + packetNumber = + zHeader.packetNumber; // doc["packetNumber"].GetUint(); + detSpec1 = zHeader.detSpec1; // doc["detSpec1"].GetUint(); + timestamp = zHeader.timestamp; // doc["timestamp"].GetUint(); + modId = zHeader.modId; // doc["modId"].GetUint(); + detSpec3 = zHeader.detSpec3; // doc["detSpec3"].GetUint(); + // detSpec4=r.detSpec4;//doc["detSpec4"].GetUint(); + detType = zHeader.detType; // doc["detType"].GetUint(); + version = zHeader.version; // doc["version"].GetUint(); + /*document["bitmode"].GetUint(); zHeader.dynamicRange - string fname; - // int length; - int *detimage = NULL; - int nnx, nny, nnsx, nnsy; - // uint32_t imageSize = 0, nPixelsX = 0, nPixelsY = 0, - // uint32_t dynamicRange = 0; - // infinite loop - uint32_t packetNumber = 0; - uint64_t bunchId = 0; - uint64_t timestamp = 0; - int16_t modId = 0; - uint32_t expLength = 0; - uint16_t xCoord = 0; - uint16_t yCoord = 0; - // uint16_t zCoord = 0; - uint32_t debug = 0; - // uint32_t dr = 16; - // int16_t *dout;//=new int16_t [nnx*nny]; - uint32_t dr = 32; - int32_t *dout = NULL; //=new int32_t [nnx*nny]; - float *doutf = NULL; //=new int32_t [nnx*nny]; - uint16_t roundRNumber = 0; - uint8_t detType = 0; - uint8_t version = 0; - string additionalJsonHeader = ""; - int32_t threshold = 0; + */ - int32_t xmin = 0, xmax = 400, ymin = 0, ymax = 400; + // strcpy(fname,filename.c_str()); + fname = filename; + addJsonHeader = zHeader.addJsonHeader; - string frameMode_s, detectorMode_s, intMode_s; - - // int resetFlat=0; - // int resetPed=0; - // int nsubPixels=1; - // int isPedestal=0; - // int isFlat=0; - int newFrame = 1; - detectorMode dMode = eAnalog; - frameMode fMode = eFrame; - double *ped; - - filter->getImageSize(nnx, nny, nnsx, nnsy); - - std::map addJsonHeader; - - while (1) { - - // cout << "+++++++++++++++++++++++++++++++LOOP" << endl; - // get header, (if dummy, fail is on parse error or end of acquisition) - - // rapidjson::Document doc; - if (!zmqsocket->ReceiveHeader(0, zHeader, - SLS_DETECTOR_JSON_HEADER_VERSION)) { - /* zmqsocket->CloseHeaderMessage();*/ - - // if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, - //subframeIndex, filename, fileindex)) { - cprintf(RED, "Got Dummy\n"); - // t1=high_resolution_clock::now(); - // time(&end); - // cout << "Measurement lasted " << difftime(end,begin) << endl; - - end = std::chrono::steady_clock::now(); - cout << "Measurement lasted " << (end - begin).count() * 0.000001 - << " ms" << endl; - - while (mt->isBusy()) { - ; - } // wait until all data are processed from the queues - - if (of) { - mt->setFilePointer(NULL); - fclose(of); - of = NULL; - } - if (newFrame > 0) { - cprintf(RED, "DIDn't receive any data!\n"); - if (send) { - - // zHeader.data = false; - outHeader.data = false; - // zmqsocket2->SendHeaderData(0, true, - // SLS_DETECTOR_JSON_HEADER_VERSION); - zmqsocket2->SendHeader(0, outHeader); - cprintf(RED, "Sent Dummy\n"); - } - } else { - send_something = 0; - if (fMode == ePedestal) { - sprintf(ofname, "%s_%ld_ped.tiff", fname.c_str(), - fileindex); - mt->writePedestal(ofname); - cout << "Writing pedestal to " << ofname << endl; - if (rms) { - sprintf(ofname, "%s_%ld_var.tiff", fname.c_str(), - fileindex); - mt->writePedestalRMS(ofname); - } - send_something = 1; - } + rms = 0; + fMode = eFrame; + frameMode_s = "frame"; + cprintf(MAGENTA, "Frame mode: "); + // if (doc.HasMember("frameMode")) { + if (addJsonHeader.find("frameMode") != addJsonHeader.end()) { + // if (doc["frameMode"].IsString()) { + frameMode_s = addJsonHeader.at( + "frameMode"); // doc["frameMode"].GetString(); + if (frameMode_s == "pedestal") { + fMode = ePedestal; + // isPedestal=1; + } else if (frameMode_s == "newPedestal") { + mt->newDataSet(); // resets pedestal + // cprintf(MAGENTA, "Resetting pedestal\n"); + fMode = ePedestal; + // isPedestal=1; + } else if (frameMode_s == "variance") { + mt->newDataSet(); // resets pedestal + // cprintf(MAGENTA, "Resetting pedestal\n"); + fMode = ePedestal; + // isPedestal=1; + rms = 1; + } else if (frameMode_s == "raw") { + // mt->newDataSet(); //resets pedestal + // cprintf(MAGENTA, "Resetting pedestal\n"); + fMode = eRaw; + // isPedestal=1; + } #ifdef INTERP - else if (fMode == eFlat) { - mt->prepareInterpolation(ok); - sprintf(ofname, "%s_%ld_eta.tiff", fname.c_str(), - fileindex); - mt->writeFlatField(ofname); - cout << "Writing eta to " << ofname << endl; - send_something = 1; - } -#endif - else { - if (subframes > 0) { - if (insubframe > 0) { - sprintf(ofname, "%s_sf%ld_%ld.tiff", fname.c_str(), - nnsubframe, fileindex); - // mt->writeImage(ofname); - doutf = new float[nnx * nny]; - if (subframes > 0 && insubframe != subframes && - insubframe > 0) - subnorm = - ((double)subframes) / ((double)insubframe); - else - subnorm = 1.; - for (int ix = 0; ix < nnx * nny; ix++) { - doutf[ix] = detimage[ix] * subnorm; - if (doutf[ix] < 0) - doutf[ix] = 0; - } + else if (frameMode_s == "flatfield") { + fMode = eFlat; + // isFlat=1; + } else if (frameMode_s == "newFlatfield") { + mt->resetFlatField(); + // isFlat=1; + cprintf(MAGENTA, "Resetting flatfield\n"); + fMode = eFlat; + } + //#endif + else { + // isPedestal=0; + // isFlat=0; + fMode = eFrame; + frameMode_s = "frame"; + } + //} + } + cprintf(MAGENTA, "%s\n", frameMode_s.c_str()); + mt->setFrameMode(fMode); - cout << "Writing image to " << ofname << endl; + // threshold=0; + cprintf(MAGENTA, "Threshold: "); + if (addJsonHeader.find("threshold") != addJsonHeader.end()) { + istringstream(addJsonHeader.at("threshold")) >> threshold; + } + mt->setThreshold(threshold); + cprintf(MAGENTA, "%d\n", threshold); + + cprintf(MAGENTA, "subframes: "); + if (addJsonHeader.find("subframes") != addJsonHeader.end()) { + istringstream(addJsonHeader.at("subframes")) >> subframes; + } + + cprintf(MAGENTA, "%d\n", subframes); + - WriteToTiff(doutf, ofname, nnx, nny); - if (doutf) - delete[] doutf; - doutf = NULL; - nsubframes++; - insubframe = 0; - send_something = 1; - } - } else { - sprintf(ofname, "%s_%ld.tiff", fname.c_str(), - fileindex); - mt->writeImage(ofname); - send_something = 1; - } + xmin = 0; + xmax = npx; + ymin = 0; + ymax = npy; + cprintf(MAGENTA, "ROI: "); - cout << "Writing image to " << ofname << endl; - } - // cout << nns*nnx*nny*nns*dr/8 << " " << length << endl; + if (addJsonHeader.find("roi") != addJsonHeader.end()) { + istringstream(addJsonHeader.at("roi")) >> xmin >> xmax >> + ymin >> ymax; + } - if (send) { - - if (fMode == ePedestal) { - cprintf(MAGENTA, "Get pedestal!\n"); - nnsx = 1; - nnsy = 1; - - nnx = npx; - nny = npy; - // dout= new int16_t[nnx*nny*nns*nns]; - dout = new int32_t[nnx * nny * nnsx * nnsy]; - // cout << "get pedestal " << endl; - ped = mt->getPedestal(); - // cout << "got pedestal " << endl; - for (int ix = 0; ix < nnx * nny; ix++) { - - dout[ix] = ped[ix]; - // if (ix<100*400) - // cout << ix << " " << ped[ix] << endl; - } - - } + cprintf(MAGENTA, "%d %d %d %d\n", xmin, xmax, ymin, ymax); + mt->setROI(xmin, xmax, ymin, ymax); + if (addJsonHeader.find("dynamicRange") != addJsonHeader.end()) { + istringstream(addJsonHeader.at("dynamicRange")) >> dr; + dr = 32; + } + dMode = eAnalog; + detectorMode_s = "analog"; + cprintf(MAGENTA, "Detector mode: "); + if (addJsonHeader.find("detectorMode") != addJsonHeader.end()) { + ; + detectorMode_s = addJsonHeader.at( + "detectorMode"); //=doc["detectorMode"].GetString(); #ifdef INTERP - else if (fMode == eFlat) { - int nb; - double emi = 0, ema = 1; - int *ff = mt->getFlatField(nb, emi, ema); - nnx = nb; - nny = nb; - dout = new int32_t[nb * nb]; - for (int ix = 0; ix < nb * nb; ix++) { - dout[ix] = ff[ix]; - } - } + if (detectorMode_s == "interpolating") { + dMode = eInterpolating; + mt->setInterpolation(interp); + } else #endif - else { - detimage = mt->getImage(nnx, nny, nnsx, nnsy); - cprintf(MAGENTA, "Get image!\n"); - cout << nnx << " " << nny << " " << nnsx << " " << nnsy - << endl; - // nns=1; - // nnx=npx; - // nny=npy; - // nnx=nnx*nns; - // nny=nny*nns; - dout = new int32_t[nnx * nny]; - if (subframes > 0 && insubframe != subframes && - insubframe > 0) - subnorm = - ((double)subframes) / ((double)insubframe); - else - subnorm = 1.; - for (int ix = 0; ix < nnx * nny; ix++) { - // for (int iy=0; iy0 && subframes>0) || (subframes<=0) ){ - - if (send_something) { - - // zmqsocket2->SendHeaderData (0, - // false,SLS_DETECTOR_JSON_HEADER_VERSION , dr, - // fileindex, 1,1,nnx,nny,nnx*nny*dr/8,acqIndex, - // frameIndex, fname,acqIndex,0 , packetNumber,bunchId, - // timestamp, modId,xCoord, yCoord, zCoord,debug, - // roundRNumber, detType, version, 0,0, - // 0,&additionalJsonHeader); - - outHeader.data = true; - outHeader.dynamicRange = dr; - outHeader.fileIndex = fileindex; - outHeader.ndetx = 1; - outHeader.ndety = 1; - outHeader.npixelsx = nnx; - outHeader.npixelsy = nny; - outHeader.imageSize = nnx * nny * dr / 8; - outHeader.acqIndex = acqIndex; - outHeader.frameIndex = frameIndex; - outHeader.fname = fname; - outHeader.frameNumber = acqIndex; - outHeader.expLength = expLength; - outHeader.packetNumber = packetNumber; - outHeader.bunchId = bunchId; - outHeader.timestamp = timestamp; - outHeader.modId = modId; - outHeader.row = xCoord; - outHeader.column = yCoord; - outHeader.debug = debug; - outHeader.roundRNumber = roundRNumber; - outHeader.detType = detType; - outHeader.version = version; - - zmqsocket2->SendHeader(0, outHeader); - zmqsocket2->SendData((char *)dout, nnx * nny * dr / 8); - cprintf(GREEN, "Sent Data\n"); - } - outHeader.data = false; - zmqsocket2->SendHeader(0, outHeader); - // zmqsocket2->SendHeaderData(0, true, - // SLS_DETECTOR_JSON_HEADER_VERSION); - cprintf(RED, "Sent Dummy\n"); - if (dout) - delete[] dout; - dout = NULL; - } - } - - mt->clearImage(); - - newFrame = 1; - - // time(&finished); - // cout << "Processing lasted " << difftime(finished,begin) << endl; - - finished = std::chrono::steady_clock::now(); - cout << "Processing lasted " - << (finished - begin).count() * 0.000001 << " ms" << endl; -#ifdef OPTIMIZE - return 0; -#endif - continue; // continue to not get out - } - - //#ifdef NEWZMQ - if (newFrame) { - begin = std::chrono::steady_clock::now(); - - size = zHeader.imageSize; // doc["size"].GetUint(); - - // dynamicRange = zheader.dynamicRange; //doc["bitmode"].GetUint(); - // nPixelsX = zHeader.npixelsx; //doc["shape"][0].GetUint(); - // nPixelsY = zHeader.npixelsy;// doc["shape"][1].GetUint(); - filename = zHeader.fname; // doc["fname"].GetString(); - acqIndex = - zHeader - .acqIndex; // doc["acqIndex"].GetUint64(); - // frameIndex = - // zHeader.frameIndex;//doc["fIndex"].GetUint64(); - fileindex = zHeader.fileIndex; // doc["fileIndex"].GetUint64(); - expLength = zHeader.expLength; // doc["expLength"].GetUint(); - packetNumber = - zHeader.packetNumber; // doc["packetNumber"].GetUint(); - bunchId = zHeader.bunchId; // doc["bunchId"].GetUint(); - timestamp = zHeader.timestamp; // doc["timestamp"].GetUint(); - modId = zHeader.modId; // doc["modId"].GetUint(); - debug = zHeader.debug; // doc["debug"].GetUint(); - // roundRNumber=r.roundRNumber;//doc["roundRNumber"].GetUint(); - detType = zHeader.detType; // doc["detType"].GetUint(); - version = zHeader.version; // doc["version"].GetUint(); - /*document["bitmode"].GetUint(); zHeader.dynamicRange - -document["fileIndex"].GetUint64(); zHeader.fileIndex - -document["detshape"][0].GetUint(); -zHeader.ndetx - -document["detshape"][1].GetUint(); -zHeader.ndety - -document["shape"][0].GetUint(); -zHeader.npixelsx - -document["shape"][1].GetUint(); -zHeader.npixelsy - -document["size"].GetUint(); zHeader.imageSize - -document["acqIndex"].GetUint64(); zHeader.acqIndex - -document["frameIndex"].GetUint64(); zHeader.frameIndex - -document["fname"].GetString(); zHeader.fname - -document["frameNumber"].GetUint64(); zHeader.frameNumber - -document["expLength"].GetUint(); zHeader.expLength - -document["packetNumber"].GetUint(); zHeader.packetNumber - -document["bunchId"].GetUint64(); zHeader.bunchId - -document["timestamp"].GetUint64(); zHeader.timestamp - -document["modId"].GetUint(); zHeader.modId - -document["row"].GetUint(); zHeader.row - -document["column"].GetUint(); zHeader.column - -document["reserved"].GetUint(); zHeader.reserved - -document["debug"].GetUint(); zHeader.debug - -document["roundRNumber"].GetUint(); zHeader.roundRNumber - -document["detType"].GetUint(); zHeader.detType - -document["version"].GetUint(); zHeader.version - -document["flippedDataX"].GetUint(); zHeader.flippedDataX - -document["quad"].GetUint(); zHeader.quad - -document["completeImage"].GetUint(); zHeader.completeImage - */ - // dataSize=size; - - // strcpy(fname,filename.c_str()); - fname = filename; - // cprintf(BLUE, "Header Info:\n" - // "size: %u\n" - // "multisize: %u\n" - // "dynamicRange: %u\n" - // "nPixelsX: %u\n" - // "nPixelsY: %u\n" - // "currentFileName: %s\n" - // "currentAcquisitionIndex: %lu\n" - // "currentFrameIndex: %lu\n" - // "currentFileIndex: %lu\n" - // "currentSubFrameIndex: %u\n" - // "xCoordX: %u\n" - // "yCoordY: %u\n" - // "zCoordZ: %u\n" - // "flippedDataX: %u\n" - // "packetNumber: %u\n" - // "bunchId: %u\n" - // "timestamp: %u\n" - // "modId: %u\n" - // "debug: %u\n" - // "roundRNumber: %u\n" - // "detType: %u\n" - // "version: %u\n", - // size, multisize, dynamicRange, nPixelsX, nPixelsY, - // filename.c_str(), acqIndex, - // frameIndex, fileindex, subFrameIndex, - // xCoord, yCoord,zCoord, - // flippedDataX, packetNumber, bunchId, timestamp, modId, - // debug, roundRNumber, detType, version); - - addJsonHeader = zHeader.addJsonHeader; - - /* Analog detector commands */ - // isPedestal=0; - // isFlat=0; - rms = 0; - fMode = eFrame; - frameMode_s = "frame"; - cprintf(MAGENTA, "Frame mode: "); - // if (doc.HasMember("frameMode")) { - if (addJsonHeader.find("frameMode") != addJsonHeader.end()) { - // if (doc["frameMode"].IsString()) { - frameMode_s = addJsonHeader.at( - "frameMode"); // doc["frameMode"].GetString(); - if (frameMode_s == "pedestal") { - fMode = ePedestal; - // isPedestal=1; - } else if (frameMode_s == "newPedestal") { - mt->newDataSet(); // resets pedestal - // cprintf(MAGENTA, "Resetting pedestal\n"); - fMode = ePedestal; - // isPedestal=1; - } else if (frameMode_s == "variance") { - mt->newDataSet(); // resets pedestal - // cprintf(MAGENTA, "Resetting pedestal\n"); - fMode = ePedestal; - // isPedestal=1; - rms = 1; - } + if (detectorMode_s == "counting") { + dMode = ePhotonCounting; #ifdef INTERP - else if (frameMode_s == "flatfield") { - fMode = eFlat; - // isFlat=1; - } else if (frameMode_s == "newFlatfield") { - mt->resetFlatField(); - // isFlat=1; - cprintf(MAGENTA, "Resetting flatfield\n"); - fMode = eFlat; - } - //#endif - else { - fMode = eFrame; - // isPedestal=0; - // isFlat=0; - fMode = eFrame; - frameMode_s = "frame"; - } - //} - } - cprintf(MAGENTA, "%s\n", frameMode_s.c_str()); - mt->setFrameMode(fMode); - - // threshold=0; - cprintf(MAGENTA, "Threshold: "); - if (addJsonHeader.find("threshold") != addJsonHeader.end()) { - istringstream(addJsonHeader.at("threshold")) >> threshold; - // threshold=atoi(addJsonHeader.at("threshold").c_str());//doc["frameMode"].GetString(); - } - // if (doc.HasMember("threshold")) { - // if (doc["threshold"].IsInt()) { - // threshold=doc["threshold"].GetInt(); - mt->setThreshold(threshold); - // } - // } - cprintf(MAGENTA, "%d\n", threshold); - - xmin = 0; - xmax = npx; - ymin = 0; - ymax = npy; - cprintf(MAGENTA, "ROI: "); - - if (addJsonHeader.find("roi") != addJsonHeader.end()) { - istringstream(addJsonHeader.at("roi")) >> xmin >> xmax >> - ymin >> ymax; - // if (doc.HasMember("roi")) { - // if (doc["roi"].IsArray()) { - // if (doc["roi"].Size() > 0 ) - // if (doc["roi"][0].IsInt()) - // xmin=doc["roi"][0].GetInt(); - - // if (doc["roi"].Size() > 1 ) - // if (doc["roi"][1].IsInt()) - // xmax=doc["roi"][1].GetInt(); - - // if (doc["roi"].Size() > 2 ) - // if (doc["roi"][2].IsInt()) - // ymin=doc["roi"][2].GetInt(); - - // if (doc["roi"].Size() > 3 ) - // if (doc["roi"][3].IsInt()) - // ymax=doc["roi"][3].GetInt(); - // } - } - - cprintf(MAGENTA, "%d %d %d %d\n", xmin, xmax, ymin, ymax); - mt->setROI(xmin, xmax, ymin, ymax); - if (addJsonHeader.find("dynamicRange") != addJsonHeader.end()) { - istringstream(addJsonHeader.at("dynamicRange")) >> dr; - dr = 32; - } - // if (doc.HasMember("dynamicRange")) { - // dr=doc["dynamicRange"].GetUint(); - // dr=32; - // } - - dMode = eAnalog; - detectorMode_s = "analog"; - cprintf(MAGENTA, "Detector mode: "); - if (addJsonHeader.find("detectorMode") != addJsonHeader.end()) { - ; - // if (doc.HasMember("detectorMode")) { - // if (doc["detectorMode"].IsString()) { - detectorMode_s = addJsonHeader.at( - "detectorMode"); //=doc["detectorMode"].GetString(); + mt->setInterpolation(NULL); +#endif + } else { + dMode = eAnalog; #ifdef INTERP - if (detectorMode_s == "interpolating") { - dMode = eInterpolating; - mt->setInterpolation(interp); - } else + mt->setInterpolation(NULL); #endif - if (detectorMode_s == "counting") { - dMode = ePhotonCounting; -#ifdef INTERP - mt->setInterpolation(NULL); -#endif - } else { - dMode = eAnalog; -#ifdef INTERP - mt->setInterpolation(NULL); -#endif - } - // } - } + } + // } + if (fMode == eRaw) { + detectorMode_s = "analog"; + dMode = eAnalog; + } + } - mt->setDetectorMode(dMode); - cprintf(MAGENTA, "%s\n", detectorMode_s.c_str()); + mt->setDetectorMode(dMode); + cprintf(MAGENTA, "%s\n", detectorMode_s.c_str()); - // cout << "done " << endl; + cout << "done " << endl; - // /* Single Photon Detector commands */ - // nSigma=5; - // if (doc.HasMember("nSigma")) { - // if (doc["nSigma"].IsInt()) - // nSigma=doc["nSigma"].GetInt(); - // mt->setNSigma(nSigma); - // } + /* Single Photon Detector commands */ + nSigma = 5; - // emin=-1; - // emax=-1; - // if (doc.HasMember("energyRange")) { - // if (doc["energyRange"].IsArray()) { - // if (doc["energyRange"].Size() > 0 ) - // if (doc["energyRange"][0].IsInt()) - // emin=doc["energyRange"][0].GetInt(); + if (addJsonHeader.find("nSigma") != addJsonHeader.end()) { + ; + istringstream(addJsonHeader.at("nSigma")) >> nSigma; + mt->setNSigma(nSigma); + } - // if (doc["energyRange"].Size() > 1 ) - // if (doc["energyRange"][1].IsInt()) - // emax=doc["energyRange"][1].GetUint(); - // } - // } - // if (doc.HasMember("eMin")) { - // if (doc["eMin"][1].IsInt()) - // emin=doc["eMin"].GetInt(); - // } - // if (doc.HasMember("eMax")) { - // if (doc["eMax"][1].IsInt()) - // emin=doc["eMax"].GetInt(); - // } - // mt->setEnergyRange(emin,emax); + emin = -1; + emax = -1; + if (addJsonHeader.find("energyRange") != addJsonHeader.end()) { + istringstream(addJsonHeader.at("energyRange")) >> emin >> emax; + } + if (addJsonHeader.find("eMin") != addJsonHeader.end()) { + istringstream(addJsonHeader.at("eMin")) >> emin; + } - // /* interpolating detector commands */ + if (addJsonHeader.find("eMax") != addJsonHeader.end()) { + istringstream(addJsonHeader.at("eMax")) >> emax; + } - // if (doc.HasMember("nSubPixels")) { - // if (doc["nSubPixels"].IsUint()) - // nSubPixels=doc["nSubPixels"].GetUint(); - // mt->setNSubPixels(nSubPixels); - // } + mt->setEnergyRange(emin, emax); - // threshold=0; - // cprintf(MAGENTA, "Subframes: "); - // subframes=0; - // //isubframe=0; - // insubframe=0; - // subnorm=1; - // f0=0; - // nnsubframe=0; - // if (doc.HasMember("subframes")) { - // if (doc["subframes"].IsInt()) { - // subframes=doc["subframes"].GetInt(); - // } - // } - // cprintf(MAGENTA, "%ld\n", subframes); + /* interpolating detector commands */ + // must set subpixels X and Y separately + // if (addJsonHeader.find("nSubPixels")!= addJsonHeader.end()) { + // istringstream(addJsonHeader.at("nSubPixels")) >> + // nSubPixels ; mt->setNSubPixels(nSubPixels); + // } - newFrame = 0; - /* zmqsocket->CloseHeaderMessage();*/ - } + threshold = 0; + cprintf(MAGENTA, "Subframes: "); + subframes = 0; + // isubframe=0; + insubframe = 0; + subnorm = 1; + f0 = 0; + nnsubframe = 0; + if (addJsonHeader.find("subframes") != addJsonHeader.end()) { + istringstream(addJsonHeader.at("subframes")) >> subframes; + } + + cprintf(MAGENTA, "%ld\n", subframes); + + newFrame = 0; + } #endif - // cout << "file" << endl; - // cout << "data " << endl; - if (of == NULL) { -#ifdef WRITE_QUAD - sprintf(ofname, "%s_%ld.clust2", filename.c_str(), fileindex); -#endif -#ifndef WRITE_QUAD - sprintf(ofname, "%s_%ld.clust", filename.c_str(), fileindex); -#endif - of = fopen(ofname, "w"); - if (of) { - mt->setFilePointer(of); - } else { - cout << "Could not open " << ofname << " for writing " << endl; - mt->setFilePointer(NULL); - } - } + frameIndex = zHeader.frameIndex; ////doc["fIndex"].GetUint64(); - // cout << "data" << endl; - // get data - // acqIndex = doc["acqIndex"].GetUint64(); + // subFrameIndex = doc["expLength"].GetUint(); - frameIndex = zHeader.frameIndex; ////doc["fIndex"].GetUint64(); + // detSpec1=doc["detSpec1"].GetUint(); + // timestamp=doc["timestamp"].GetUint(); + packetNumber = zHeader.packetNumber; // doc["packetNumber"].GetUint(); + // cout << acqIndex << " " << frameIndex << " " << subFrameIndex << " + // "<< detSpec1 << " " << timestamp << " " << packetNumber << endl; + // cprintf(GREEN, "frame\n"); + if (packetNumber >= 40) { + //*((int*)buff)=frameIndex; + if (insubframe == 0) + f0 = frameIndex; + memcpy(buff, &frameIndex, sizeof(int)); + // length = + zmqsocket->ReceiveData(0, buff + sizeof(int), size); - // subFrameIndex = doc["expLength"].GetUint(); + mt->setFilePointer(NULL); - // bunchId=doc["bunchId"].GetUint(); - // timestamp=doc["timestamp"].GetUint(); - packetNumber = zHeader.packetNumber; // doc["packetNumber"].GetUint(); - // cout << acqIndex << " " << frameIndex << " " << subFrameIndex << " - // "<< bunchId << " " << timestamp << " " << packetNumber << endl; - // cprintf(GREEN, "frame\n"); - if (packetNumber >= 40) { - //*((int*)buff)=frameIndex; - if (insubframe == 0) - f0 = frameIndex; - memcpy(buff, &frameIndex, sizeof(int)); - // length = - zmqsocket->ReceiveData(0, buff + sizeof(int), size); - mt->pushData(buff); - mt->nextThread(); - mt->popFree(buff); - insubframe++; - nsubframes = frameIndex + 1 - f0; - } else { - cprintf(RED, "Incomplete frame: received only %d packet\n", - packetNumber); - // length = - zmqsocket->ReceiveData(0, dummybuff, size); - } + mt->pushData(buff); + mt->nextThread(); + mt->popFree(buff); + insubframe++; + nsubframes = frameIndex + 1 - f0; + // cout << "insubframe " << insubframe << endl; + // cout << "nsubframes " << nsubframes << endl; + // cout << "f0 " << f0 << endl; + // cout << "frameIndex " << frameIndex << endl; - if (subframes > 0 && insubframe >= subframes && fMode == eFrame) { - while (mt->isBusy()) { - ; - } // wait until all data are processed from the queues - detimage = mt->getImage(nnx, nny, nnsx, nnsy); - cprintf(MAGENTA, "Get image!\n"); - dout = new int32_t[nnx * nny]; - doutf = new float[nnx * nny]; - if (subframes > 0 && insubframe != subframes && insubframe > 0) - subnorm = ((double)subframes) / ((double)insubframe); - else - subnorm = 1.; - for (int ix = 0; ix < nnx * nny; ix++) { - dout[ix] = detimage[ix] * subnorm; - if (dout[ix] < 0) - dout[ix] = 0; - doutf[ix] = dout[ix]; - } - sprintf(ofname, "%s_sf%ld_%ld.tiff", fname.c_str(), nnsubframe, - fileindex); + } else { + cprintf(RED, "Incomplete frame: received only %d packet\n", + packetNumber); + // length = + zmqsocket->ReceiveData(0, dummybuff, size); + } - cout << "Writing image to " << ofname << endl; + if (subframes > 0 && insubframe >= subframes && + (fMode == eFrame || fMode == eRaw)) { + while (mt->isBusy()) { + ; + } // wait until all data are processed from the queues + usleep(100); - WriteToTiff(doutf, ofname, nnx, nny); - nsubframes++; - insubframe = 0; - nnsubframe++; + detimage = mt->getImage(nnx, nny, nnsx, nnsy); - // zmqsocket2->SendHeaderData (0, - // false,SLS_DETECTOR_JSON_HEADER_VERSION , dr, fileindex, - // 1,1,nnx,nny,nnx*nny*dr/8,acqIndex, frameIndex, fname,acqIndex,0 - // , packetNumber,bunchId, timestamp, modId,xCoord, yCoord, - // zCoord,debug, roundRNumber, detType, version, 0,0, - // 0,&additionalJsonHeader); - zHeader.data = true; - zmqsocket2->SendHeader(0, zHeader); - zmqsocket2->SendData((char *)dout, nnx * nny * dr / 8); - cprintf(GREEN, "Sent subdata\n"); + cprintf(MAGENTA, "Get image!\n"); + dout = new int32_t[nnx * nny]; + doutf = new float[nnx * nny]; + if (subframes > 0 && insubframe != subframes && insubframe > 0) + subnorm = ((double)subframes) / ((double)insubframe); + else + subnorm = 1.; + for (int ix = 0; ix < nnx * nny; ix++) { + dout[ix] = detimage[ix] * subnorm; + if (dout[ix] < 0) + dout[ix] = 0; + doutf[ix] = dout[ix]; + } + sprintf(ofname, "%s_sf%ld_%ld.tiff", fname.c_str(), nnsubframe, + fileindex); - if (dout) - delete[] dout; - dout = NULL; + cout << "Writing image to " << ofname << endl; - if (doutf) - delete[] doutf; - doutf = NULL; + WriteToTiff(doutf, ofname, nnx, nny); + nsubframes++; + insubframe = 0; + nnsubframe++; - mt->clearImage(); - } + // zmqsocket2->SendHeaderData (0, + // false,SLS_DETECTOR_JSON_HEADER_VERSION , dr, fileindex, + // 1,1,nnx,nny,nnx*nny*dr/8,acqIndex, frameIndex, fname,acqIndex,0 + // , packetNumber,detSpec1, timestamp, modId,xCoord, yCoord, + // zCoord,detSpec3, detSpec4, detType, version, 0,0, + // 0,&additionalJsonHeader); - iframe++; + // zmqsocket2->SendHeaderData (0, + // false,SLS_DETECTOR_JSON_HEADER_VERSION , dr, fileindex, + // 1,1,nnx,nny,nnx*nny*dr/8,acqIndex, frameIndex, fname,acqIndex,0 + // , packetNumber,detSpec1, timestamp, modId,xCoord, yCoord, + // zCoord,detSpec3, detSpec4, detType, version, 0,0, + // 0,&additionalJsonHeader); - } // exiting infinite loop + outHeader.data = true; + outHeader.dynamicRange = dr; + outHeader.fileIndex = fileindex; + outHeader.ndetx = 1; + outHeader.ndety = 1; + outHeader.npixelsx = nnx; + outHeader.npixelsy = nny; + outHeader.imageSize = nnx * nny * dr / 8; + outHeader.acqIndex = acqIndex; + outHeader.frameIndex = frameIndex; + outHeader.fname = fname; + outHeader.frameNumber = acqIndex; + outHeader.expLength = expLength; + outHeader.packetNumber = packetNumber; + outHeader.detSpec1 = detSpec1; + outHeader.timestamp = timestamp; + outHeader.modId = modId; + outHeader.row = xCoord; + outHeader.column = yCoord; + outHeader.detSpec3 = detSpec3; + outHeader.detSpec4 = detSpec4; + outHeader.detType = detType; + outHeader.version = version; - delete zmqsocket; - if (send) - delete zmqsocket2; + zmqsocket2->SendHeader(0, outHeader); + zmqsocket2->SendData((char *)dout, nnx * nny * dr / 8); + cprintf(GREEN, "Sent subdata\n"); - cout << "Goodbye" << endl; - return 0; + if (dout) + delete[] dout; + dout = NULL; + + if (doutf) + delete[] doutf; + doutf = NULL; + + mt->clearImage(); + } + + iframe++; + + } // exiting infinite loop + + delete zmqsocket; + if (send) + delete zmqsocket2; + + cout << "Goodbye" << endl; + return 0; } diff --git a/slsDetectorCalibration/jungfrauExecutables/onlinedisp_zmq.cpp b/slsDetectorCalibration/jungfrauExecutables/onlinedisp_zmq.cpp new file mode 100644 index 000000000..d63105080 --- /dev/null +++ b/slsDetectorCalibration/jungfrauExecutables/onlinedisp_zmq.cpp @@ -0,0 +1,679 @@ +#include "onlinedisp_zmq.h" +bool hasallpede; +TH1F * his102;TH1F * his101; +int processedf; +sls::zmqHeader zHeader; +#define PEDEFNAME "current_pede.dat" +#define NPRO 50 +#define NPRI 50 + +//#define JFSTRX +#ifdef JFSTRX +#include "jungfrauLGADStrixelsData.h" +#else +#include "jungfrauModuleData.h" +#endif + + + +int main(int argc, char* argv[]) +{ + goout=1; + hasallpede=false; + dophotonmap=true; if ((argc<3)) {printf("USAGE: command photon_energy_(peakinADC) [rx_ip] [port] \n"); return -1 ;} + else { + phene=atoi(argv[1]); + if (phene<0) dophotonmap=false; + threshold=float (phene/2); + printf( " \n"); + printf( "phene %d \n",phene); + } + + if (argc>=3) { + strcpy(serverip,argv[2]); + printf("ip is %s ",serverip); + } + + portnum=30001; + if (argc>=4 ){ portnum= atoi(argv[3]); + } + printf(", port number is %d ",portnum); printf(". \n"); + + +#ifdef JFSTRX + cout << "JFSTRX" << endl; + jungfrauLGADStrixelsData *decoder = new jungfrauLGADStrixelsData(); + nx = 1024/5; ny= 512*5; +#else + nx = 1024; ny= 512; +#endif + + + + + gain_flag=false; + pede_flag=false; + bw_flag=false; + + HDraw_every=20; + fixranges=false; + + + hchptr = (short*) malloc(NCH*sizeof(short)); + + startsocket(); //create and connect ZMQ + + for (ipx=0;ipxgetValue((char*)(hchptr),279,130)<SetOption("colz"); + his2000= new TH2F("his2000","2d gain ",nx,-0.5,nx-0.5,ny,-0.5,ny-0.5); + his2000->GetZaxis()->SetRangeUser(0,4); + + if (dophotonmap) { + his3000= new TH2F("his3000"," photon map ",nx,-0.5,nx-0.5,ny,-0.5,ny-0.5); + } + else { + his3000= new TH2F("his3000"," raw adc ",nx,-0.5,nx-0.5,ny,-0.5,ny-0.5); + } + + his4500= new TH2F("his45000","L vs R",101,-50,500,101,-50,500); + hchip=new TH1I*[8]; + for (i=0;i<8;i++) { + sprintf(hname,"hchip%d",i); + hchip[i] = new TH1I(hname,hname,NBIN,MIN_POS,MAX_POS); + } + + cout <<"end of histo booking" <Clear(); + A4->Divide(4,2,0.005,0.005); + if (A5==NULL) A5 = new TCanvas("A5","Plotting Canvas Photon Map",750,300,1000,600); + if (A6==NULL) A6 = new TCanvas("A6","Plotting Canvas LvsR",650,250,650,660); + + gSystem->ProcessEvents(); + int running=0; + char runc[15]="*\\-/|"; + printhelp(); + + + + while (1==1) { // loop on streamed frames + + if(!zmqSocket->ReceiveHeader(0,zHeader, SLS_DETECTOR_JSON_HEADER_VERSION)){ + cout<< "Receiver stopped, waiting for new stream" << endl; + zmqSocket->Disconnect(); + zmqSocket->Connect(); + } + else { + + // if (((icount++)%10)==0) cout <<"recived frameindex "<ReceiveData(0, (char *)(&image_data), NCH*2); + } + + { + + framesinstream++; + running++; + + fill1Ds=true; //alway fill 1d and LR plots + //if (((framesinstream%(int(HDraw_every)))==(int (HDraw_every)-1))) {fill1Ds=true;}else{fill1Ds=false;} + if (((framesinstream%(HDraw_every))==(HDraw_every)-1)) {show2Ds=true;}else{show2Ds=false;} + if (((framesinstream%NPRI)==NPRI-1)) { cout<<"\r "<<"frame (from start): "<Reset(); + his2000->Reset(); + if (!dophotonmap) his3000->Reset(); //FOR RAW ADC DISPLAY + } + + + if ((fill1Ds)or(show2Ds)or(dophotonmap)) { // do something, otherwise skip to the next + processedf++; + + for (i=0 ;i>14) & 0x3;} else {gain=0;} + if (pede_flag){ + + if (gain_flag) + { + if ((gain==0)||(!hasallpede)) adcpedecorr=(adcvalue&0x3fff)*fgaind[i]-fpeded[i]*fgaind[i]; + + if ((gain==1)&&hasallpede) adcpedecorr=(fpedeG1d[i]*fgaind[i]+G1Poffset-adcvalue*fgaind[i])*30.0; + if ((gain==3)&&hasallpede) adcpedecorr=(fpedeG2d[i]*fgaind[i]+G2Poffset-adcvalue*fgaind[i])*340.0; + } + else + + { + + if ((gain==0)||(!hasallpede)) adcpedecorr=(adcvalue&0x3fff)-fpeded[i]; + if ((gain==1)&&hasallpede) adcpedecorr=(fpedeG1d[i]+G1Poffset-adcvalue)*30.0; + if ((gain==3)&&hasallpede) adcpedecorr=(fpedeG2d[i]+G2Poffset-adcvalue)*340.0; + } + + + } else {adcpedecorr=float (adcvalue);} //end of if pede + + + + + if ((adcpedecorr>threshold)&&(pede_flag)) hchptr[(i)]= hchptr[(i)]+(int)((adcpedecorr+threshold)/phene); + + + if (fill1Ds) { + if (((i%1024)<1004)&&((i%1024)>20)&&((i/1024)>20)) { //skip the pix near guardring for PH plots + ichip= i/(256*256*4)*4+((i/256)%4) ; + + hchip[ichip]->Fill(adcpedecorr,1); + + if (((i%256)<253)&&((i%256)>2)) his4500->Fill(adcpedecorrold,adcpedecorr,1); + adcpedecorrold=adcpedecorr; + + + } + }//if (fill1Ds) + + + + + if ((show2Ds)) { + factor=2.0; + value=adcpedecorr; + if ((i%256==0)||(i%256==255)) value=int(value/factor); + if ((i/1024==255)||(i/1024==256)||(i/1024==767)||(i/1024==768)) value=int(value/factor); + + his1000->Fill(float(i%1024),float(int (i/1024)),value); + + if (!dophotonmap) his3000->Fill(float(i%1024),float(int (i/1024)) ,adcvalue); + + his2000->Fill(float(i%1024),float(int (i/1024)) ,gain); + + value=(int)(hchptr[i]); + + if ((i%256==0)||(i%256==255)) value=int(value/factor); + if ((i/1024==255)||(i/1024==256)||(i/1024==767)||(i/1024==768)) value=int(value/factor); + if (dophotonmap) his3000->Fill(float(i%1024),float(int (i/1024)),float(value)); + + } + }// for (i=0 ;iProcessEvents(); + + + } + + + + + + }// end of infinite loop + + rootapp->Run(); + nonblock(NB_DISABLE); + return 0; + + +} +void processifp(int ifp){ + + if (ifp!=0){ + c=fgetc(stdin); + if (c=='s') {if (goout==0){goout=1;}else {myloop();}} + if (c=='S') SetRanges(); + if (c=='+') { HDraw_every=HDraw_every*0.8;cout<< endl <<"Drawing every "<< HDraw_every<<" frames "<SetOption("surf2z"); + if (c=='C') his1000->SetOption("colz"); + + if (c=='q') exit(0); + if (c=='r') historeset(); + if (c=='R') axisreset(); + } + +} +void loadallpede(){ + cout <<"not implemented "<< endl; + // hasallpede=true; + + // system("./sls_detector_put setbit 0x5d 12 "); //setting to FSG1 ; + + // loadpede(); + // loadpede(); + // for (i=0;iReceiveHeader(0,zHeader, SLS_DETECTOR_JSON_HEADER_VERSION)){ + return; + } + + cout <<"received frameindex "<ReceiveData(0, (char *)(&image_data), NCH*2); + framesinstream++;nframes++; + for (ipx=0;ipxProcessEvents(); + usleep(5000); + + } +} +void printhelp(){ + cout<< endl << "s=start/pause| p/n=getnewpede/raw | o/O=read/save pede | n=nopede(raw) | r/R=rst His/Axis | +/- = faster/slower ref. |q=exit | U/C sUrf2/Colz " <Reset(); + his3000->Reset(); + for (i=0;i<8;i++) { + hchip[i]->Reset(); + + } + Plot2DHistos(); + Plot1DHistos(); + +} + +void SetRanges() { + string str; + std::cin.clear(); + //cin.ignore(std::numeric_limits::max(), '\n'); + + cout<< endl; + cout<< " adc min " <> adcmin; + cout<< " adc max " <> adcmax; + cout<< " p.map min " <> pmmin; + cout<< " p.map max " <> pmmax; + + fixranges=true; + + + +} + + +void axisreset(){ + fixranges=false; + his1000->GetXaxis()->UnZoom(); + + his1000->GetYaxis()->UnZoom(); + his1000->GetZaxis()->UnZoom(); + his2000->GetXaxis()->UnZoom(); + his2000->GetYaxis()->UnZoom(); + + his3000->GetZaxis()->UnZoom(); + + for (i=0;i<8;i++) { + hchip[i]->GetXaxis()->UnZoom(); + hchip[i]->GetYaxis()->UnZoom(); + } + + his4500->GetXaxis()->UnZoom(); + his4500->GetYaxis()->UnZoom(); + his4500->GetZaxis()->UnZoom(); + + Plot2DHistos(); + Plot1DHistos(); + + +} + + + + + +void nonblock(int state) +{ + struct termios ttystate; + //get the terminal state + tcgetattr(STDIN_FILENO, &ttystate); + if (state==NB_ENABLE) + { + //turn off canonical mode + ttystate.c_lflag &= ~ICANON; + //minimum of number input read. + ttystate.c_cc[VMIN] = 1; + } + else if (state==NB_DISABLE) + { //turn on canonical mode + ttystate.c_lflag |= ICANON; + } + //set the terminal attributes. + tcsetattr(STDIN_FILENO, TCSANOW, &ttystate); +} + + +void LoadPaletteFalse(){ + const Int_t NRGBs = 5; + const Int_t NCont = 90; + + Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; + Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; + Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; + Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; + TColor::CreateGradientColorTable(NRGBs, stops, red,green, blue, NCont); + gStyle->SetNumberContours(NCont); + TColor::CreateGradientColorTable(NRGBs, stops, red,green ,blue, NCont); + gStyle->SetNumberContours(NCont); + +} +void LoadPaletteBW(float gammatune){ + + vgamma=vgamma*gammatune; + cout<< "gamma is "<SetNumberContours(NCont); + + + + // TColor::SetPalette(52,0,1); + +} + +void Plot1DHistos(void){ + + if (hchip[0]->GetXaxis()->GetLast()!=oldh0xlast){ + oldh0xlast=hchip[0]->GetXaxis()->GetLast(); + oldh0xfirst=hchip[0]->GetXaxis()->GetFirst(); + for (int ipad=1; ipad<8;ipad++) { + hchip[ipad]->GetXaxis()->SetRange(oldh0xfirst,oldh0xlast); + + + } + } + + + for (int ipad=0; ipad<8;ipad++) { + A4->cd(ipad+1); + gStyle->SetOptStat(1); gPad->SetLogy(); + hchip[ipad%4+(1-int(ipad/4))*4]->Draw(); + + } + A4->cd(); + A4->Update(); +} + + +void Plot2DHistos(void){ + gStyle->SetOptStat(0); + A3->cd(); + + // if (bw_flag) LoadPaletteBW(1.0); + + if (fixranges) { + + his1000->GetZaxis()->SetRangeUser(float(adcmin),float(adcmax)); + his3000->GetZaxis()->SetRangeUser(float(pmmin),float(pmmax)); + + + } + + his1000->SetMinimum(-200); + his1000->Draw(); + + A3->Update(); + A2->cd(); + // if (bw_flag) LoadPaletteFalse(); + his2000->GetXaxis()->SetRange(his1000->GetXaxis()->GetFirst(),his1000->GetXaxis()->GetLast()); + his2000->GetYaxis()->SetRange(his1000->GetYaxis()->GetFirst(),his1000->GetYaxis()->GetLast()); + + his2000->Draw("colz"); + A2->Update(); + A5->cd(); + + his3000->GetXaxis()->SetRange(his1000->GetXaxis()->GetFirst(),his1000->GetXaxis()->GetLast()); + his3000->GetYaxis()->SetRange(his1000->GetYaxis()->GetFirst(),his1000->GetYaxis()->GetLast()); + his3000->Draw("colz"); + A5->Update(); + + A6->cd(); + his4500->Draw("colz"); + A6->Update(); + + + +} + + +void startsocket(void) { + + + + + try { + zmqSocket = new sls::ZmqSocket(serverip, portnum); + + } catch (...) { + cprintf(RED, + "Error: Could not create Zmq socket on port %d with ip %s\n", + portnum, serverip); + delete zmqSocket; + return; + } + zmqSocket->SetReceiveHighWaterMark(3); + zmqSocket->SetReceiveBuffer(1024*1024); + zmqSocket->Connect(); + + + cout<<"Zmq Client[] "<< zmqSocket->GetZmqServerAddress()<~ZmqSocket (); + + + + haveconnection=false; + + + + +} +void savepede(void) { + + int pfd; + + pfd=open(PEDEFNAME,O_CREAT|O_WRONLY, 0666); + if (pfd==-1) perror("open pede file"); + + write(pfd,fpeded,2*NCH*sizeof(float)); + write(pfd,fpedeG1d,2*NCH*sizeof(float)); + write(pfd,fpedeG2d,2*NCH*sizeof(float)); + close(pfd); + +} + +void readpede(void) { + + int pfd; + + pfd=open(PEDEFNAME,O_RDONLY); + if (pfd==-1) perror("open pede file"); + + read(pfd,fpeded,NCH*2*sizeof(float)); + read(pfd,fpedeG1d,NCH*2*sizeof(float)); + read(pfd,fpedeG2d,NCH*2*sizeof(float)); + + close(pfd); + pede_flag=true; + hasallpede=true; + +} + diff --git a/slsDetectorCalibration/jungfrauExecutables/onlinedisp_zmq.h b/slsDetectorCalibration/jungfrauExecutables/onlinedisp_zmq.h new file mode 100644 index 000000000..100bac801 --- /dev/null +++ b/slsDetectorCalibration/jungfrauExecutables/onlinedisp_zmq.h @@ -0,0 +1,204 @@ + +/**************************************************************************/ +/* Header files section needs cleanup */ +/**************************************************************************/ +#include +#include +#include +#include "sls/ZmqSocket.h" + +#include "sls/tiffIO.h" +#include +#include +#include /* exit() */ +#include /* memset(), memcpy() */ +#include /* uname() */ +#include +#include /* socket(), bind(), + listen(), accept() */ +#include +#include +#include +#include +#include +#include +#include /* fork(), write(), close() */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //json header in zmq stream +#include +#define NTHREADS 2 + +#include +#include +#include // time_t + +using namespace std; +using namespace std::chrono; +using namespace sls; + +#include "TCanvas.h" +#include "TH1F.h" +#include "TF1.h" +#include "TH2F.h" +#include "TMath.h" +#include "TFile.h" +#include "TStyle.h" +#include "TSystem.h" +#include "TTimer.h" +#include "TProfile.h" +#include "TColor.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sls/ansi.h" +#define SLS_DETECTOR_JSON_HEADER_VERSION 0x4 + +#define PI 3.14159265 + +#define FALSE 0 +#define OFFSET 0 +#define NBIN 500 +#define MIN_POS -500.5 // 400.5 +#define MAX_POS 3499.5 //-100.5 + + +#define NCH 524288 +// #define NCH 262144 in case of half_frames + +char serverip[256]; +int portnum; +FILE * sfilefd; + +short* hchptr; // photon counted map "histogram" +int value; +float factor=1.84; +int npacket=0; +int totalnpacket=0; +float vgamma; + +struct sockaddr_in serveraddr; +struct sockaddr_in clientaddr; +struct in_addr inadr; +struct hostent *server; + +int i=0; +int ipx=0; +bool haveconnection; + + +TStyle *gStyle; +TApplication* rootapp; +TCanvas *A2; +TCanvas *A3; +TCanvas *A4; +TCanvas *A5; +TCanvas *A6; + +TH1I **hchip; +TH2F **h4500chip; +short image_data[NCH*2]; +short imaged[NCH*2]; +float fpeded[NCH*2]; +float fpedeG2d[NCH*2]; +float fpedeG1d[NCH*2]; +short ipeded[NCH*2]; +short pcimaged[NCH*2]; + +float fgaind[NCH*2]; + + +float adcpedecorr,adcpedecorrold; + +bool gain_flag; +bool bw_flag; +bool fill2Ds; +bool show2Ds; +bool fill1Ds; +bool pede_flag; +bool dophotonmap; + +int nx, ny; +int nframes; +int goout; +int framesinstream; +int ifp; +float threshold; +int phene; +int adcvalue; +int gain; +int ichip; +int frameIndex_old; + +char pedefilename[128]; +int framenum,bunchid; + +TH2F* his1000; +TH2F* his2000; +TH2F* his3000; +TH2F* his4500; +TH1I* hproj; +TH1I* hchcum; + + +using namespace std; +void printhelp(void); +void processifp(int ifp); +void historeset(void); +void SetRanges(void); +void startsocket(void); +void stopsocket(void); +void axisreset(void); +int kbhit(void); +void myloop(void); +void loadpede(void); +void loadallpede(void); +void loadgain(void); +void nonblock(int state); +void LoadPaletteFalse(void); +void LoadPaletteBW(float); +void Plot1DHistos(void); +void Plot2DHistos(void); +void savepede(void); +void readpede(void); +int findinterpoindex(int startindex); +int findclumax(int startindex); +void tryconnect(void) ; + +#define NB_ENABLE 1 +#define NB_DISABLE 0 +char c; +int HDraw_every; + + +float oldh0xfirst,oldh0xlast; +int idx; +int GXPoffset,G1Poffset,G2Poffset; +int ix,iy; +int adcmin,adcmax; +int pmmin,pmmax; //min/mnx for the photon map +bool fixranges; + + +sls::ZmqSocket *zmqSocket= NULL; diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index d02ef306d..3dd42244e 100644 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -59,6 +59,7 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { void ClonePlot(); void SavePlot(); void SetGapPixels(bool enable); + void UpdatePlot(); protected: void resizeEvent(QResizeEvent *event); @@ -67,7 +68,6 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { void Zoom1DGainPlot(const QRectF &rect); void Zoom2DGainPlot(const QRectF &rect); void SetSaveFileName(QString val); - void UpdatePlot(); signals: void AcquireFinishedSignal(); diff --git a/slsDetectorGui/include/qTabPlot.h b/slsDetectorGui/include/qTabPlot.h index 3e57eb24a..77cefc0df 100644 --- a/slsDetectorGui/include/qTabPlot.h +++ b/slsDetectorGui/include/qTabPlot.h @@ -47,6 +47,7 @@ class qTabPlot : public QWidget, private Ui::TabPlotObject { private: void SetupWidgetWindow(); void Initialization(); + bool VerifyGapPixelsAllowed(); void Select1DPlot(bool enable); void GetGapPixels(); void GetStreamingFrequency(); @@ -60,7 +61,8 @@ class qTabPlot : public QWidget, private Ui::TabPlotObject { Detector *det; qDrawPlot *plot; - bool is1d; + bool is1d{false}; + bool isGapPixelsAllowed{false}; /** default plot and axis titles */ static QString defaultPlotTitle; diff --git a/slsDetectorGui/src/qTabDataOutput.cpp b/slsDetectorGui/src/qTabDataOutput.cpp index 1aca7b61a..2ec1575a3 100644 --- a/slsDetectorGui/src/qTabDataOutput.cpp +++ b/slsDetectorGui/src/qTabDataOutput.cpp @@ -180,8 +180,10 @@ void qTabDataOutput::BrowseOutputDir() { LOG(logDEBUG) << "Browsing output directory"; QString directory = QFileDialog::getExistingDirectory( this, tr("Choose Output Directory "), dispOutputDir->text()); - if (!directory.isEmpty()) + if (!directory.isEmpty()) { dispOutputDir->setText(directory); + ForceSetOutputDir(); + } } void qTabDataOutput::SetOutputDir(bool force) { diff --git a/slsDetectorGui/src/qTabPlot.cpp b/slsDetectorGui/src/qTabPlot.cpp index 1d3c9bcbf..75d873137 100644 --- a/slsDetectorGui/src/qTabPlot.cpp +++ b/slsDetectorGui/src/qTabPlot.cpp @@ -16,7 +16,7 @@ QString qTabPlot::defaultImageYAxisTitle("Pixel"); QString qTabPlot::defaultImageZAxisTitle("Intensity"); qTabPlot::qTabPlot(QWidget *parent, Detector *detector, qDrawPlot *p) - : QWidget(parent), det(detector), plot(p), is1d(false) { + : QWidget(parent), det(detector), plot(p) { setupUi(this); SetupWidgetWindow(); LOG(logDEBUG) << "Plot ready"; @@ -57,11 +57,7 @@ void qTabPlot::SetupWidgetWindow() { chkGainPlot1D->setChecked(true); plot->EnableGainPlot(true); break; - case slsDetectorDefs::EIGER: - chkGapPixels->setEnabled(true); - break; case slsDetectorDefs::JUNGFRAU: - chkGapPixels->setEnabled(true); chkGainPlot->setEnabled(true); chkGainPlot->setChecked(true); plot->EnableGainPlot(true); @@ -74,6 +70,8 @@ void qTabPlot::SetupWidgetWindow() { default: break; } + isGapPixelsAllowed = VerifyGapPixelsAllowed(); + chkGapPixels->setEnabled(isGapPixelsAllowed); Select1DPlot(is1d); Initialization(); @@ -200,6 +198,29 @@ void qTabPlot::Initialization() { connect(dispZMax, SIGNAL(editingFinished()), this, SLOT(isZMaxModified())); } +bool qTabPlot::VerifyGapPixelsAllowed() { + try { + switch (det->getDetectorType().squash()) { + case slsDetectorDefs::JUNGFRAU: + return true; + case slsDetectorDefs::EIGER: + if (det->getQuad().squash(false)) { + return true; + } + // full modules + if (det->getModuleGeometry().y % 2 == 0) { + return true; + } + return false; + default: + return false; + } + } + CATCH_DISPLAY("Could not verify if gap pixels allowed.", + "qTabPlot::VerifyGapPixelsAllowed") + return false; +} + void qTabPlot::Select1DPlot(bool enable) { LOG(logDEBUG) << "Selecting " << (enable ? "1" : "2") << "D Plot"; is1d = enable; @@ -492,6 +513,7 @@ void qTabPlot::SetXYRange() { } plot->SetXYRangeChanged(disablezoom, xyRange, isRange); + plot->UpdatePlot(); emit DisableZoomSignal(disablezoom); } @@ -629,6 +651,7 @@ void qTabPlot::SetZRange() { zRange[1] = val; } plot->SetZRange(zRange, isZRange); + plot->UpdatePlot(); } void qTabPlot::GetStreamingFrequency() { @@ -775,15 +798,10 @@ void qTabPlot::Refresh() { boxFrequency->setEnabled(true); GetStreamingFrequency(); GetHwm(); - // gain plot, gap pixels enable + // gain plot switch (det->getDetectorType().squash()) { - case slsDetectorDefs::EIGER: - chkGapPixels->setEnabled(true); - GetGapPixels(); - break; case slsDetectorDefs::JUNGFRAU: chkGainPlot->setEnabled(true); - chkGapPixels->setEnabled(true); GetGapPixels(); break; case slsDetectorDefs::MOENCH: @@ -795,6 +813,11 @@ void qTabPlot::Refresh() { default: break; } + // gap pixels + if (isGapPixelsAllowed) { + chkGapPixels->setEnabled(true); + GetGapPixels(); + } } else { boxFrequency->setEnabled(false); chkGainPlot->setEnabled(false); diff --git a/slsDetectorServers/compileAllServers.sh b/slsDetectorServers/compileAllServers.sh index c79f4dc5b..fe48f61fd 100644 --- a/slsDetectorServers/compileAllServers.sh +++ b/slsDetectorServers/compileAllServers.sh @@ -3,12 +3,12 @@ # empty branch = developer branch in updateAPIVersion.sh branch="" -det_list=("ctbDetectorServer" - "gotthardDetectorServer" - "gotthard2DetectorServer" - "jungfrauDetectorServer" - "mythen3DetectorServer" - "moenchDetectorServer" +det_list=("ctbDetectorServer + gotthardDetectorServer + gotthard2DetectorServer + jungfrauDetectorServer + mythen3DetectorServer + moenchDetectorServer" ) usage="\nUsage: compileAllServers.sh [server|all(opt)] [branch(opt)]. \n\tNo arguments mean all servers with 'developer' branch. \n\tNo 'branch' input means 'developer branch'" @@ -25,9 +25,11 @@ elif [ $# -eq 1 ] || [ $# -eq 2 ]; then else # only one server # arg not in list - if [[ $det_list != *$1* ]]; then + echo $det_list | grep -w -q $1 + #if [[ $det_list != *$1* ]]; then + if ! [[ $? ]] ; then echo -e "Invalid argument 1: $1. $usage" - return -1 + return 1 fi declare -a det=("${1}") #echo "Compiling only $1" @@ -37,14 +39,14 @@ elif [ $# -eq 1 ] || [ $# -eq 2 ]; then # arg in list if [[ $det_list == *$2* ]]; then echo -e "Invalid argument 2: $2. $usage" - return -1 + return 1 fi branch+=$2 #echo "with branch $branch" fi else echo -e "Too many arguments.$usage" - return -1 + return 1 fi declare -a deterror=("OK" "OK" "OK" "OK" "OK" "OK") diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer deleted file mode 100755 index 358e111d6..000000000 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and /dev/null differ diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index a55b61a28..dddb324f8 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -99,7 +99,7 @@ void basictests() { #endif if (mapCSP0() == FAIL) { strcpy(initErrorMessage, - "Could not map to memory. Dangerous to continue.\n"); + "Could not map to memory. Cannot proceed. Check Firmware.\n"); LOG(logERROR, (initErrorMessage)); initError = FAIL; return; @@ -109,8 +109,10 @@ void basictests() { if ((!debugflag) && (!updateFlag) && ((checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL))) { - strcpy(initErrorMessage, "Could not pass basic tests of FPGA and bus. " - "Dangerous to continue.\n"); + sprintf(initErrorMessage, + "Could not pass basic tests of FPGA and bus. Cannot proceed. " + "Check Firmware. (Firmware version:0x%llx) \n", + getFirmwareVersion()); LOG(logERROR, ("%s\n\n", initErrorMessage)); initError = FAIL; return; @@ -446,7 +448,7 @@ void initStopServer() { if (mapCSP0() == FAIL) { initError = FAIL; strcpy(initErrorMessage, - "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"); + "Stop Server: Map Fail. Cannot proceed. Check Firmware.\n"); LOG(logERROR, (initErrorMessage)); initCheckDone = 1; return; diff --git a/slsDetectorServers/eigerDetectorServer/Beb.c b/slsDetectorServers/eigerDetectorServer/Beb.c index 4b7ae520d..82d82f697 100644 --- a/slsDetectorServers/eigerDetectorServer/Beb.c +++ b/slsDetectorServers/eigerDetectorServer/Beb.c @@ -1106,7 +1106,9 @@ int Beb_SetDetectorPosition(int pos[]) { int posRight[2] = {Beb_top ? pos[X] + 1 : pos[X], pos[Y]}; if (Beb_quadEnable) { - posRight[Y] = 1; // right is next row + posLeft[Y] = 1; // left is next row + posLeft[X] = 0; // left same first row + posRight[Y] = 0; // right same first row posRight[X] = 0; // right same first column } diff --git a/slsDetectorServers/eigerDetectorServer/CMakeLists.txt b/slsDetectorServers/eigerDetectorServer/CMakeLists.txt index 39f0aea23..ddba9e4a4 100644 --- a/slsDetectorServers/eigerDetectorServer/CMakeLists.txt +++ b/slsDetectorServers/eigerDetectorServer/CMakeLists.txt @@ -25,7 +25,7 @@ target_include_directories(eigerDetectorServer_virtual ) target_compile_definitions(eigerDetectorServer_virtual - PUBLIC EIGERD PCCOMPILE STOP_SERVER + PUBLIC EIGERD PCCOMPILE STOP_SERVER #TEST_MOD_GEOMETRY PUBLIC VIRTUAL #VIRTUAL_9M ) diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.c b/slsDetectorServers/eigerDetectorServer/FebControl.c index b2ba2cd85..c10aa881f 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.c +++ b/slsDetectorServers/eigerDetectorServer/FebControl.c @@ -1240,19 +1240,16 @@ int Feb_Control_GetDynamicRange(int *retval) { int Feb_Control_Disable16bitConversion(int disable) { LOG(logINFO, ("%s 16 bit expansion\n", disable ? "Disabling" : "Enabling")); + + uint32_t bitmask = DAQ_REG_HRDWRE_DSBL_16BIT_MSK; unsigned int regval = 0; - if (!Feb_Control_ReadRegister(DAQ_REG_HRDWRE, ®val)) { - LOG(logERROR, ("Could not %s 16 bit expansion (bit mode)\n", - (disable ? "disable" : "enable"))); - return 0; - } if (disable) { - regval |= DAQ_REG_HRDWRE_DSBL_16BIT_MSK; + regval |= bitmask; } else { - regval &= ~DAQ_REG_HRDWRE_DSBL_16BIT_MSK; + regval &= ~bitmask; } - if (!Feb_Control_WriteRegister(DAQ_REG_HRDWRE, regval)) { + if (!Feb_Control_WriteRegister_BitMask(DAQ_REG_HRDWRE, regval, bitmask)) { LOG(logERROR, ("Could not %s 16 bit expansion (bit mode)\n", (disable ? "disable" : "enable"))); return 0; @@ -1262,11 +1259,12 @@ int Feb_Control_Disable16bitConversion(int disable) { int Feb_Control_Get16bitConversionDisabled(int *ret) { unsigned int regval = 0; - if (!Feb_Control_ReadRegister(DAQ_REG_HRDWRE, ®val)) { + if (!Feb_Control_ReadRegister_BitMask(DAQ_REG_HRDWRE, ®val, + DAQ_REG_HRDWRE_DSBL_16BIT_MSK)) { LOG(logERROR, ("Could not get 16 bit expansion (bit mode)\n")); return 0; } - if (regval & DAQ_REG_HRDWRE_DSBL_16BIT_MSK) { + if (regval) { *ret = 1; } else { *ret = 0; @@ -1667,6 +1665,15 @@ int Feb_Control_GetReadNRows() { } int Feb_Control_WriteRegister(uint32_t offset, uint32_t data) { + return Feb_Control_WriteRegister_BitMask(offset, data, BIT32_MSK); +} + +int Feb_Control_ReadRegister(uint32_t offset, uint32_t *retval) { + return Feb_Control_ReadRegister_BitMask(offset, retval, BIT32_MASK); +} + +int Feb_Control_WriteRegister_BitMask(uint32_t offset, uint32_t data, + uint32_t bitmask) { uint32_t actualOffset = offset; char side[2][10] = {"right", "left"}; unsigned int addr[2] = {Feb_Control_rightAddress, Feb_Control_leftAddress}; @@ -1690,24 +1697,41 @@ int Feb_Control_WriteRegister(uint32_t offset, uint32_t data) { for (int iloop = 0; iloop < 2; ++iloop) { if (run[iloop]) { - LOG(logDEBUG1, - ("Writing 0x%x to %s 0x%x\n", data, side[iloop], actualOffset)); - if (!Feb_Interface_WriteRegister(addr[iloop], actualOffset, data, 0, - 0)) { - LOG(logERROR, ("Could not write 0x%x to %s addr 0x%x\n", data, + LOG(logDEBUG1, ("Writing 0x%x to %s 0x%x (mask:0x%x)\n", data, + side[iloop], actualOffset, bitmask)); + + uint32_t writeVal = 0; + if (!Feb_Interface_ReadRegister(addr[iloop], actualOffset, + &writeVal)) { + LOG(logERROR, ("Could not read %s addr 0x%x register\n", side[iloop], actualOffset)); return 0; } - uint32_t regVal = 0; - if (!Feb_Interface_ReadRegister(addr[iloop], actualOffset, - ®Val)) { - LOG(logERROR, ("Could not read %s register\n", addr[iloop])); + // set only the bits in the mask + writeVal &= ~(bitmask); + writeVal |= (data & bitmask); + + LOG(logDEBUG1, ("writing 0x%x to 0x%x\n", writeVal, actualOffset)); + if (!Feb_Interface_WriteRegister(addr[iloop], actualOffset, + writeVal, 0, 0)) { + LOG(logERROR, ("Could not write 0x%x to %s addr 0x%x\n", + writeVal, side[iloop], actualOffset)); return 0; } - if (regVal != data) { + writeVal &= bitmask; + + uint32_t readVal = 0; + if (!Feb_Interface_ReadRegister(addr[iloop], actualOffset, + &readVal)) { + return 0; + } + readVal &= bitmask; + + if (writeVal != readVal) { LOG(logERROR, - ("Could not write %s register. Write 0x%x, read 0x%x\n", - addr[iloop], data, regVal)); + ("Could not write %s addr 0x%x register. Wrote " + "0x%x, read 0x%x (mask:0x%x)\n", + side[iloop], actualOffset, writeVal, readVal, bitmask)); return 0; } } @@ -1716,7 +1740,8 @@ int Feb_Control_WriteRegister(uint32_t offset, uint32_t data) { return 1; } -int Feb_Control_ReadRegister(uint32_t offset, uint32_t *retval) { +int Feb_Control_ReadRegister_BitMask(uint32_t offset, uint32_t *retval, + uint32_t bitmask) { uint32_t actualOffset = offset; char side[2][10] = {"right", "left"}; unsigned int addr[2] = {Feb_Control_rightAddress, Feb_Control_leftAddress}; @@ -1746,8 +1771,9 @@ int Feb_Control_ReadRegister(uint32_t offset, uint32_t *retval) { side[iloop], actualOffset)); return 0; } - LOG(logDEBUG1, ("Read 0x%x from %s 0x%x\n", value[iloop], - side[iloop], actualOffset)); + value[iloop] &= bitmask; + LOG(logDEBUG1, ("Read 0x%x from %s 0x%x (mask:0x%x)\n", + value[iloop], side[iloop], actualOffset, bitmask)); *retval = value[iloop]; // if not the other (left, not right OR right, not left), return the // value @@ -1758,7 +1784,7 @@ int Feb_Control_ReadRegister(uint32_t offset, uint32_t *retval) { } // Inconsistent values when reading both registers if ((run[0] & run[1]) & (value[0] != value[1])) { - LOG(logERROR, ("Inconsistent values read from %s 0x%x and %s 0x%x\n", + LOG(logERROR, ("Inconsistent values read from %s: 0x%x and %s: 0x%x\n", side[0], value[0], side[1], value[1])); return 0; } diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.h b/slsDetectorServers/eigerDetectorServer/FebControl.h index ffda63837..e5ca463b1 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.h +++ b/slsDetectorServers/eigerDetectorServer/FebControl.h @@ -95,7 +95,10 @@ int Feb_Control_SetReadNRows(int value); int Feb_Control_GetReadNRows(); int Feb_Control_WriteRegister(uint32_t offset, uint32_t data); int Feb_Control_ReadRegister(uint32_t offset, uint32_t *retval); - +int Feb_Control_WriteRegister_BitMask(uint32_t offset, uint32_t data, + uint32_t bitmask); +int Feb_Control_ReadRegister_BitMask(uint32_t offset, uint32_t *retval, + uint32_t bitmask); // pulsing int Feb_Control_Pulse_Pixel(int npulses, int x, int y); int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos); diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer deleted file mode 100755 index e3ccdd2fb..000000000 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer and /dev/null differ diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 8c77ea483..6d0ec7eb2 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -882,12 +882,15 @@ int setDynamicRange(int dr) { LOG(logINFO, ("Setting dynamic range: %d\n", dr)); #else sharedMemory_lockLocalLink(); - if (Feb_Control_SetDynamicRange(dr)) { - if (!Beb_SetUpTransferParameters(dr)) { - LOG(logERROR, ("Could not set bit mode in the back end\n")); - sharedMemory_unlockLocalLink(); - return eiger_dynamicrange; - } + if (!Feb_Control_SetDynamicRange(dr)) { + LOG(logERROR, ("Could not set dynamic range in feb\n")); + sharedMemory_unlockLocalLink(); + return FAIL; + } + if (!Beb_SetUpTransferParameters(dr)) { + LOG(logERROR, ("Could not set bit mode in the back end\n")); + sharedMemory_unlockLocalLink(); + return eiger_dynamicrange; } sharedMemory_unlockLocalLink(); #endif @@ -1475,6 +1478,12 @@ int setHighVoltage(int val) { sharedMemory_unlockLocalLink(); return -3; } + // need to read the file twice to get the proper value + if (!Feb_Control_GetHighVoltage(&eiger_highvoltage)) { + LOG(logERROR, ("Could not read high voltage\n")); + sharedMemory_unlockLocalLink(); + return -3; + } sharedMemory_unlockLocalLink(); // tolerance of 5 @@ -2685,6 +2694,10 @@ void *start_timer(void *arg) { header->modId = eiger_virtual_module_id; header->row = row; header->column = colLeft; + if (eiger_virtual_quad_mode) { + header->row = 1; // left is next row + header->column = 0; // left same first column + } char packetData2[packetsize]; memset(packetData2, 0, packetsize); @@ -2693,11 +2706,11 @@ void *start_timer(void *arg) { header->version = SLS_DETECTOR_HEADER_VERSION; header->frameNumber = frameNr + iframes; header->packetNumber = i; - header->modId = eiger_virtual_module_id; + header->modId = eiger_virtual_module_id + 1; header->row = row; header->column = colRight; if (eiger_virtual_quad_mode) { - header->row = 1; // right is next row + header->row = 0; // right is next row header->column = 0; // right same first column } diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h index cca94c3fd..f37e98448 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h @@ -5,7 +5,7 @@ #define LINKED_SERVER_NAME "eigerDetectorServer" -#define REQUIRED_FIRMWARE_VERSION (30) +#define REQUIRED_FIRMWARE_VERSION (31) // virtual ones renamed for consistency // real ones keep previous name for compatibility (already in production) #ifdef VIRTUAL @@ -137,6 +137,7 @@ enum MASTERINDEX { MASTER_HARDWARE, OW_MASTER, OW_SLAVE }; #define UDP_HEADER_MAX_FRAME_VALUE (0xFFFFFFFFFFFF) #define BIT16_MASK (0xFFFF) +#define BIT32_MSK (0xFFFFFFFF) #define DAC_MIN_MV (0) #define DAC_MAX_MV (2048) diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer deleted file mode 100755 index 78b879a00..000000000 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and /dev/null differ diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 7b1162277..886d947ee 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -93,7 +93,7 @@ void basictests() { #endif if (mapCSP0() == FAIL) { strcpy(initErrorMessage, - "Could not map to memory. Dangerous to continue.\n"); + "Could not map to memory. Cannot proceed. Check Firmware.\n"); LOG(logERROR, (initErrorMessage)); initError = FAIL; return; @@ -105,8 +105,8 @@ void basictests() { (checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL))) { sprintf(initErrorMessage, - "Could not pass basic tests of FPGA and bus. Dangerous to " - "continue. (Firmware version:0x%llx) \n", + "Could not pass basic tests of FPGA and bus. Cannot proceed. " + "Check Firmware. (Firmware version:0x%llx) \n", getFirmwareVersion()); LOG(logERROR, ("%s\n\n", initErrorMessage)); initError = FAIL; @@ -396,7 +396,7 @@ void initStopServer() { if (mapCSP0() == FAIL) { initError = FAIL; strcpy(initErrorMessage, - "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"); + "Stop Server: Map Fail. Cannot proceed. Check Firmware.\n"); LOG(logERROR, (initErrorMessage)); initCheckDone = 1; return; diff --git a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer deleted file mode 100755 index 4c383a6cf..000000000 Binary files a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer and /dev/null differ diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index c56930140..ebdca8fa0 100644 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -87,7 +87,7 @@ void basictests() { #endif if (mapCSP0() == FAIL) { strcpy(initErrorMessage, - "Could not map to memory. Dangerous to continue.\n"); + "Could not map to memory. Cannot proceed. Check Firmware.\n"); LOG(logERROR, (initErrorMessage)); initError = FAIL; } @@ -97,7 +97,7 @@ void basictests() { ((checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL))) { strcpy(initErrorMessage, "Could not pass basic tests of FPGA and bus. " - "Dangerous to continue.\n"); + "Cannot proceed. Check Firmware.\n"); LOG(logERROR, ("%s\n\n", initErrorMessage)); initError = FAIL; return; @@ -381,7 +381,7 @@ void initStopServer() { if (mapCSP0() == FAIL) { initError = FAIL; strcpy(initErrorMessage, - "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"); + "Stop Server: Map Fail. Cannot proceed. Check Firmware.\n"); LOG(logERROR, (initErrorMessage)); initCheckDone = 1; return; diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer deleted file mode 100755 index 1123d7fd9..000000000 Binary files a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer and /dev/null differ diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index e7d474840..62ea6fe04 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -82,7 +82,7 @@ void basictests() { #endif if (mapCSP0() == FAIL) { strcpy(initErrorMessage, - "Could not map to memory. Dangerous to continue.\n"); + "Could not map to memory. Cannot proceed. Check Firmware.\n"); LOG(logERROR, (initErrorMessage)); initError = FAIL; } @@ -91,8 +91,10 @@ void basictests() { if ((!debugflag) && (!updateFlag) && ((checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL))) { - strcpy(initErrorMessage, "Could not pass basic tests of FPGA and bus. " - "Dangerous to continue.\n"); + sprintf(initErrorMessage, + "Could not pass basic tests of FPGA and bus. Cannot proceed. " + "Check Firmware. (Firmware version:0x%llx) \n", + getFirmwareVersion()); LOG(logERROR, ("%s\n\n", initErrorMessage)); initError = FAIL; return; @@ -428,7 +430,7 @@ void initStopServer() { if (mapCSP0() == FAIL) { initError = FAIL; strcpy(initErrorMessage, - "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"); + "Stop Server: Map Fail. Cannot proceed. Check Firmware.\n"); LOG(logERROR, (initErrorMessage)); initCheckDone = 1; return; @@ -2798,6 +2800,7 @@ int softwareTrigger(int block) { LOG(logINFO, ("Sending Software Trigger\n")); bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_SOFTWARE_TRIGGER_MSK); + bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_SOFTWARE_TRIGGER_MSK); #ifndef VIRTUAL // block till frame is sent out diff --git a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer deleted file mode 100755 index 81e65b905..000000000 Binary files a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer and /dev/null differ diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index a49e08ea0..56af23ead 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -82,8 +82,8 @@ void basictests() { #endif if (mapCSP0() == FAIL) { strcpy(initErrorMessage, - "Could not map to memory. Dangerous to continue.\n"); - LOG(logERROR, (initErrorMessage)); + "Could not map to memory. Cannot proceed. Check Firmware.\n"); + LOG(logERROR, ("%s\n\n", initErrorMessage)); initError = FAIL; } #ifndef VIRTUAL @@ -91,8 +91,10 @@ void basictests() { if ((!debugflag) && (!updateFlag) && ((checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL))) { - strcpy(initErrorMessage, "Could not pass basic tests of FPGA and bus. " - "Dangerous to continue.\n"); + sprintf(initErrorMessage, + "Could not pass basic tests of FPGA and bus. Cannot proceed. " + "Check Firmware. (Firmware version:0x%llx) \n", + getFirmwareVersion()); LOG(logERROR, ("%s\n\n", initErrorMessage)); initError = FAIL; return; @@ -432,7 +434,7 @@ void initStopServer() { if (mapCSP0() == FAIL) { initError = FAIL; strcpy(initErrorMessage, - "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"); + "Stop Server: Map Fail. Cannot proceed. Check Firmware.\n"); LOG(logERROR, (initErrorMessage)); initCheckDone = 1; return; diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer deleted file mode 100755 index 9570f432d..000000000 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and /dev/null differ diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 215c06ba2..ee8ee9bc5 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -89,7 +89,7 @@ void basictests() { #endif if (mapCSP0() == FAIL) { strcpy(initErrorMessage, - "Could not map to memory. Dangerous to continue.\n"); + "Could not map to memory. Cannot proceed. Check Firmware.\n"); LOG(logERROR, (initErrorMessage)); initError = FAIL; } @@ -99,8 +99,10 @@ void basictests() { ((validateKernelVersion(KERNEL_DATE_VRSN) == FAIL) || (checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL))) { - strcpy(initErrorMessage, "Could not pass basic tests of FPGA and bus. " - "Dangerous to continue.\n"); + sprintf(initErrorMessage, + "Could not pass basic tests of FPGA and bus. Cannot proceed. " + "Check Firmware. (Firmware version:0x%llx) \n", + getFirmwareVersion()); LOG(logERROR, ("%s\n\n", initErrorMessage)); initError = FAIL; return; @@ -388,7 +390,7 @@ void initStopServer() { if (mapCSP0() == FAIL) { initError = FAIL; strcpy(initErrorMessage, - "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"); + "Stop Server: Map Fail. Cannot proceed. Check Firmware. \n"); LOG(logERROR, (initErrorMessage)); initCheckDone = 1; return; diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h index 51ae59c2d..e9e020ca0 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h @@ -3,7 +3,7 @@ #pragma once #include "sls/sls_detector_defs.h" -#define REQRD_FRMWRE_VRSN (0x221205) +#define REQRD_FRMWRE_VRSN (0x230124) #define KERNEL_DATE_VRSN "Mon May 10 18:00:21 CEST 2021" #define ID_FILE "detid_mythen3.txt" @@ -57,10 +57,10 @@ #define DEFAULT_TRIMBIT_VALUE (0) #define DEFAULT_COUNTER_DISABLED_VTH_VAL (2800) -#define DEFAULT_READOUT_C0 (12) //(083333333) // rdo_clk, 83.33 MHz -#define DEFAULT_READOUT_C1 (12) //(083333333) // rdo_smp_clk, 83.33 MHz -#define DEFAULT_SYSTEM_C0 (20) //(050000000) // run_clk, 20 MHz -#define DEFAULT_SYSTEM_C1 (8) //(125000000) // str_clk, 125 MHz const +#define DEFAULT_READOUT_C0 (10) //(100000000) // rdo_clk, 100 MHz +#define DEFAULT_READOUT_C1 (10) //(100000000) // rdo_smp_clk, 100 MHz +#define DEFAULT_SYSTEM_C0 (10) //(100000000) // run_clk, 100 MHz +#define DEFAULT_SYSTEM_C1 (6) //(166666666) // str_clk, 166 MHz const #define DEFAULT_SYSTEM_C2 (5) //(200000000) // smp_clk, 200 MHz const #define DEFAULT_TRIMMING_RUN_CLKDIV (40) // (25000000) // 25 MHz diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index c9e2c803e..86b311c02 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -548,8 +548,8 @@ int M_nofunc(int file_des) { ret = FAIL; memset(mess, 0, sizeof(mess)); - sprintf(mess, "Unrecognized Function enum %d. Please do not proceed.\n", - fnum); + sprintf(mess, "%s Function enum %d. Please do not proceed.\n", + UNRECOGNIZED_FNUM_ENUM, fnum); LOG(logERROR, (mess)); return Server_SendResult(file_des, OTHER, NULL, 0); } @@ -5087,11 +5087,20 @@ int set_source_udp_mac(int file_des) { if (Server_VerifyLock() == OK) { if (check_detector_idle("configure mac") == OK) { if (udpDetails[0].srcmac != arg) { - for (int iRxEntry = 0; iRxEntry != MAX_UDP_DESTINATION; - ++iRxEntry) { - udpDetails[iRxEntry].srcmac = arg; + // multicast (LSB of first octet = 1) + if ((arg >> 40) & 0x1) { + ret = FAIL; + sprintf(mess, + "Cannot set source mac address. Must be a unicast " + "address (LSB of first octet should be 0)."); + LOG(logERROR, (mess)); + } else { + for (int iRxEntry = 0; iRxEntry != MAX_UDP_DESTINATION; + ++iRxEntry) { + udpDetails[iRxEntry].srcmac = arg; + } + configure_mac(); } - configure_mac(); } } } @@ -5953,7 +5962,7 @@ int set_clock_divider(int file_des) { #endif modeNotImplemented("clock index (divider set)", args[0]); } - + // TODO: if value between to set and num clocks, msg = "cannot set" enum CLKINDEX c = 0; int val = args[1]; if (ret == OK) { diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index fbcd40a73..9d5c47061 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -225,6 +225,17 @@ class Detector { */ void setBadChannels(const std::string &fname, Positions pos = {}); + /** [Gotthard2][Mythen3] */ + Result> getBadChannels(Positions pos = {}) const; + + /** [Gotthard2][Mythen3] Empty list resets bad channel list */ + void setBadChannels(const std::vector list, Positions pos = {}); + + /** [Gotthard2][Mythen3] Size of list should match number of modules. Each + * value is at module level and can start at 0. Empty vector resets bad + * channel list. */ + void setBadChannels(const std::vector> list); + Result isVirtualDetectorServer(Positions pos = {}) const; ///@} @@ -937,9 +948,10 @@ class Detector { /** Client IP Address that last communicated with the receiver */ Result getRxLastClientIP(Positions pos = {}) const; - /** Get thread ids from the receiver in order of [parent, tcp, listener 0, - * processor 0, streamer 0, listener 1, processor 1, streamer 1, arping]. If - * no streamer yet or there is no second interface, it gives 0 in its place. + /** Get kernel thread ids from the receiver in order of [parent, tcp, + * listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1, + * arping]. If no streamer yet or there is no second interface, it gives 0 + * in its place. */ Result> getRxThreadIds(Positions pos = {}) const; @@ -1469,8 +1481,9 @@ class Detector { Result getADCConfiguration(const int chipIndex, const int adcIndex, Positions pos = {}) const; - /** [Gotthard2] configures one chip at a time for specific adc, chipIndex - * and adcIndex is -1 for all */ + /** [Gotthard2] configures one chip at a time for specific adc, chipIndex. + * -1 for all. Setting specific chip index not implemented in hardware yet + */ void setADCConfiguration(const int chipIndex, const int adcIndex, const int value, Positions pos = {}); diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index f39d5dbcd..04bc5b62c 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -7,6 +7,7 @@ #include "sls/ToString.h" #include "sls/bit_utils.h" #include "sls/container_utils.h" +#include "sls/file_utils.h" #include "sls/logger.h" #include "sls/sls_detector_defs.h" @@ -278,7 +279,12 @@ std::string CmdProxy::Versions(int action) { auto t = det->getFirmwareVersion(std::vector{det_id}); os << "\nType : " << OutString(det->getDetectorType()) << "\nRelease : " << det->getPackageVersion() << std::hex - << "\nClient : " << det->getClientVersion(); + << "\nClient : " << det->getClientVersion() + << "\nServer : " + << OutString(det->getDetectorServerVersion(std::vector{det_id})) + << "\nKernel : " + << OutString(det->getKernelVersion({std::vector{det_id}})); + if (eiger) { os << "\nFirmware (Beb) : " << OutString(det->getFirmwareVersion(std::vector{det_id})); @@ -291,16 +297,11 @@ std::string CmdProxy::Versions(int action) { } else { os << "\nFirmware : " << OutStringHex( - det->getFirmwareVersion(std::vector{det_id})); - } - os << "\nServer : " - << OutString( - det->getDetectorServerVersion(std::vector{det_id})); - if (!eiger) - os << "\nHardware : " + det->getFirmwareVersion(std::vector{det_id})) + << "\nHardware : " << OutString(det->getHardwareVersion(std::vector{det_id})); - os << "\nKernel : " - << OutString(det->getKernelVersion({std::vector{det_id}})); + } + if (det->getUseReceiverFlag().squash(true)) { os << "\nReceiver : " << OutString(det->getReceiverVersion(std::vector{det_id})); @@ -557,9 +558,9 @@ std::string CmdProxy::BadChannels(int action) { std::ostringstream os; os << cmd << ' '; if (action == defs::HELP_ACTION) { - os << "[fname]\n\t[Gotthard2][Mythen3] Sets the bad channels (from " - "file of bad channel numbers) to be masked out." - "\n\t[Mythen3] Also does trimming" + os << "[fname|none|0]\n\t[Gotthard2][Mythen3] Sets the bad channels " + "(from file of bad channel numbers) to be masked out. None or 0 " + "unsets all the badchannels.\n\t[Mythen3] Also does trimming" << '\n'; } else if (action == defs::GET_ACTION) { if (args.size() != 1) { @@ -568,10 +569,25 @@ std::string CmdProxy::BadChannels(int action) { det->getBadChannels(args[0], std::vector{det_id}); os << "successfully retrieved" << '\n'; } else if (action == defs::PUT_ACTION) { - if (args.size() != 1) { + bool parse = false; + if (args.size() == 0) { WrongNumberOfParameters(1); + } else if (args.size() == 1) { + if (args[0] == "none" || args[0] == "0") { + det->setBadChannels(std::vector{}, + std::vector{det_id}); + } else if (args[0].find(".") != std::string::npos) { + det->setBadChannels(args[0], std::vector{det_id}); + } else { + parse = true; + } + } + // parse multi args or single one with range or single value + if (parse || args.size() > 1) { + // get channels + auto list = getChannelsFromStringList(args); + det->setBadChannels(list, std::vector{det_id}); } - det->setBadChannels(args[0], std::vector{det_id}); os << "successfully loaded" << '\n'; } else { throw RuntimeError("Unknown action"); @@ -1481,7 +1497,7 @@ std::string CmdProxy::Trigger(int action) { /* Network Configuration (Detector<->Receiver) */ -IpAddr CmdProxy::getIpFromAuto() { +IpAddr CmdProxy::getDstIpFromAuto() { std::string rxHostname = det->getRxHostname(std::vector{det_id}).squash("none"); // Hostname could be ip try to decode otherwise look up the hostname @@ -1492,6 +1508,21 @@ IpAddr CmdProxy::getIpFromAuto() { return val; } +IpAddr CmdProxy::getSrcIpFromAuto() { + if (det->getDetectorType().squash() == defs::GOTTHARD) { + throw RuntimeError( + "Cannot use 'auto' for udp_srcip for GotthardI Detector."); + } + std::string hostname = + det->getHostname(std::vector{det_id}).squash("none"); + // Hostname could be ip try to decode otherwise look up the hostname + auto val = IpAddr{hostname}; + if (val == 0) { + val = HostnameToIp(hostname.c_str()); + } + return val; +} + UdpDestination CmdProxy::getUdpEntry() { UdpDestination udpDestination{}; udpDestination.entry = rx_id; @@ -1502,7 +1533,7 @@ UdpDestination CmdProxy::getUdpEntry() { std::string value = it.substr(pos + 1); if (key == "ip") { if (value == "auto") { - auto val = getIpFromAuto(); + auto val = getDstIpFromAuto(); LOG(logINFO) << "Setting udp_dstip of detector " << det_id << " to " << val; udpDestination.ip = val; @@ -1511,7 +1542,7 @@ UdpDestination CmdProxy::getUdpEntry() { } } else if (key == "ip2") { if (value == "auto") { - auto val = getIpFromAuto(); + auto val = getDstIpFromAuto(); LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id << " to " << val; udpDestination.ip2 = val; @@ -1586,8 +1617,9 @@ std::string CmdProxy::UDPSourceIP(int action) { os << "[x.x.x.x] or auto\n\tIp address of the detector (source) udp " "interface. Must be same subnet as destination udp " "ip.\n\t[Eiger] Set only for 10G. For 1G, detector will replace " - "with its own DHCP IP address. If 'auto' used, then ip is set to " - "ip of rx_hostname." + "with its own DHCP IP address. \n\tOne can also set this to " + "'auto' for 1 GbE data and virtual detectors. It will set to IP " + "of detector. Not available for GotthardI" << '\n'; } else if (action == defs::GET_ACTION) { auto t = det->getSourceUDPIP(std::vector{det_id}); @@ -1601,7 +1633,7 @@ std::string CmdProxy::UDPSourceIP(int action) { } IpAddr val; if (args[0] == "auto") { - val = getIpFromAuto(); + val = getSrcIpFromAuto(); LOG(logINFO) << "Setting udp_srcip of detector " << det_id << " to " << val; } else { @@ -1624,8 +1656,9 @@ std::string CmdProxy::UDPSourceIP2(int action) { "of the " "detector (source) udp interface 2. Must be same subnet as " "destination udp ip2.\n\t [Jungfrau][Moench] top half or inner " - "interface\n\t [Gotthard2] veto debugging. If 'auto' used, then " - "ip is set to ip of rx_hostname." + "interface\n\t [Gotthard2] veto debugging. \n\tOne can also set " + "this to 'auto' for 1 GbE data and virtual detectors. It will " + "set to IP of detector." << '\n'; } else if (action == defs::GET_ACTION) { auto t = det->getSourceUDPIP2(std::vector{det_id}); @@ -1639,7 +1672,7 @@ std::string CmdProxy::UDPSourceIP2(int action) { } IpAddr val; if (args[0] == "auto") { - val = getIpFromAuto(); + val = getSrcIpFromAuto(); LOG(logINFO) << "Setting udp_srcip2 of detector " << det_id << " to " << val; } else { @@ -1673,7 +1706,7 @@ std::string CmdProxy::UDPDestinationIP(int action) { WrongNumberOfParameters(1); } if (args[0] == "auto") { - auto val = getIpFromAuto(); + auto val = getDstIpFromAuto(); LOG(logINFO) << "Setting udp_dstip of detector " << det_id << " to " << val; det->setDestinationUDPIP(val, std::vector{det_id}); @@ -1710,7 +1743,7 @@ std::string CmdProxy::UDPDestinationIP2(int action) { WrongNumberOfParameters(1); } if (args[0] == "auto") { - auto val = getIpFromAuto(); + auto val = getDstIpFromAuto(); LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id << " to " << val; det->setDestinationUDPIP2(val, std::vector{det_id}); @@ -2381,7 +2414,7 @@ std::string CmdProxy::ConfigureADC(int action) { std::ostringstream os; os << cmd << ' '; if (action == defs::HELP_ACTION) { - os << "[chip index 0-10, -1 for all] [adc index 0-31, -1 for all] [12 " + os << "[chip index 0-9, -1 for all] [adc index 0-31, -1 for all] [7 " "bit configuration value in hex]\n\t[Gotthard2] Sets " "configuration for specific chip and adc, but configures 1 chip " "(all adcs for that chip) at a time." @@ -2860,6 +2893,8 @@ std::string CmdProxy::PatternLoopAddresses(int action) { if (cmd != "patlimits") { GetLevelAndUpdateArgIndex(action, "patloop", level, iArg, nGetArgs, nPutArgs); + if (cmd != "patloop0" && cmd != "patloop1" && cmd != "patloop2") + os << level << ' '; } if (action == defs::GET_ACTION) { auto t = @@ -2899,6 +2934,8 @@ std::string CmdProxy::PatternLoopCycles(int action) { int level = -1, iArg = 0, nGetArgs = 0, nPutArgs = 1; GetLevelAndUpdateArgIndex(action, "patnloop", level, iArg, nGetArgs, nPutArgs); + if (cmd != "patnloop0" && cmd != "patnloop1" && cmd != "patnloop2") + os << level << ' '; if (action == defs::GET_ACTION) { auto t = det->getPatternLoopCycles(level, std::vector{det_id}); os << OutString(t) << '\n'; @@ -2933,6 +2970,8 @@ std::string CmdProxy::PatternWaitAddress(int action) { int level = -1, iArg = 0, nGetArgs = 0, nPutArgs = 1; GetLevelAndUpdateArgIndex(action, "patwait", level, iArg, nGetArgs, nPutArgs); + if (cmd != "patwait0" && cmd != "patwait1" && cmd != "patwait2") + os << level << ' '; if (action == defs::GET_ACTION) { auto t = det->getPatternWaitAddr(level, std::vector{det_id}); os << OutStringHex(t, 4) << '\n'; @@ -2966,6 +3005,9 @@ std::string CmdProxy::PatternWaitTime(int action) { int level = -1, iArg = 0, nGetArgs = 0, nPutArgs = 1; GetLevelAndUpdateArgIndex(action, "patwaittime", level, iArg, nGetArgs, nPutArgs); + if (cmd != "patwaittime0" && cmd != "patwaittime1" && + cmd != "patwaittime2") + os << level << ' '; if (action == defs::GET_ACTION) { auto t = det->getPatternWaitTime(level, std::vector{det_id}); os << OutString(t) << '\n'; diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 340919bc5..2d2332e2b 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -1155,7 +1155,8 @@ class CmdProxy { std::string Scan(int action); std::string Trigger(int action); /* Network Configuration (Detector<->Receiver) */ - IpAddr getIpFromAuto(); + IpAddr getDstIpFromAuto(); + IpAddr getSrcIpFromAuto(); UdpDestination getUdpEntry(); std::string UDPDestinationList(int action); std::string UDPSourceIP(int action); @@ -1782,11 +1783,12 @@ class CmdProxy { rx_lastclient, getRxLastClientIP, "\n\tClient IP Address that last communicated with the receiver."); - GET_COMMAND(rx_threads, getRxThreadIds, - "\n\tGet thread ids from the receiver in order of [parent, " - "tcp, listener 0, processor 0, streamer 0, listener 1, " - "processor 1, streamer 1, arping]. If no streamer yet or there " - "is no second interface, it gives 0 in its place."); + GET_COMMAND( + rx_threads, getRxThreadIds, + "\n\tGet kernel thread ids from the receiver in order of [parent, " + "tcp, listener 0, processor 0, streamer 0, listener 1, " + "processor 1, streamer 1, arping]. If no streamer yet or there " + "is no second interface, it gives 0 in its place."); INTEGER_COMMAND_VEC_ID(rx_arping, getRxArping, setRxArping, StringTo, "[0, 1]\n\tStarts a thread in slsReceiver to arping " diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 890d08c5f..00b8cadcb 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -351,6 +351,29 @@ void Detector::setBadChannels(const std::string &fname, Positions pos) { pimpl->setBadChannels(fname, pos); } +Result> Detector::getBadChannels(Positions pos) const { + return pimpl->Parallel(&Module::getBadChannels, pos); +} + +void Detector::setBadChannels(const std::vector> list) { + + if (list.size() != static_cast(size())) { + std::stringstream ss; + ss << "Number of bad channel sets (" << list.size() + << ") needs to match the number of modules (" << size() << ")"; + throw RuntimeError(ss.str()); + } + + for (int idet = 0; idet < size(); ++idet) { + // TODO! Call in parallel since loading trimbits is slow? + pimpl->Parallel(&Module::setBadChannels, {idet}, list[idet]); + } +} + +void Detector::setBadChannels(const std::vector list, Positions pos) { + pimpl->setBadChannels(list, pos); +} + Result Detector::isVirtualDetectorServer(Positions pos) const { return pimpl->Parallel(&Module::isVirtualDetectorServer, pos); } diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index ae26db0b6..09647c5a0 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -253,14 +253,15 @@ void DetectorImpl::setVirtualDetectorServers(const int numdet, const int port) { } void DetectorImpl::setHostname(const std::vector &name) { - // this check is there only to allow the previous detsizechan command - if (shm()->totalNumberOfModules != 0) { + // do not free always to allow the previous detsize/ initialchecks command + if (shm.exists() && shm()->totalNumberOfModules != 0) { LOG(logWARNING) << "There are already module(s) in shared memory." "Freeing Shared memory now."; - bool initialChecks = shm()->initialChecks; freeSharedMemory(); + } + // could be called after freeing shm from API + if (!shm.exists()) { setupDetector(); - shm()->initialChecks = initialChecks; } for (const auto &hostname : name) { addModule(hostname); @@ -342,28 +343,32 @@ void DetectorImpl::updateDetectorSize() { "updating detector size. "); } - int maxx = shm()->numberOfChannels.x; - int maxy = shm()->numberOfChannels.y; int nModx = 0, nMody = 0; // 1d, add modules along x axis if (modSize.y == 1) { - if (maxx == 0) { - maxx = modSize.x * size(); + int detSizeX = shm()->numberOfChannels.x; + int maxChanX = modSize.x * size(); + // user given detsizex used only within max value + if (detSizeX > 1 && detSizeX <= maxChanX) { + maxChanX = detSizeX; } - nModx = maxx / modSize.x; + nModx = maxChanX / modSize.x; nMody = size() / nModx; - if ((maxx % modSize.x) > 0) { + if ((maxChanX % modSize.x) > 0) { ++nMody; } } // 2d, add modules along y axis (due to eiger top/bottom) else { - if (maxy == 0) { - maxy = modSize.y * size(); + int detSizeY = shm()->numberOfChannels.y; + int maxChanY = modSize.y * size(); + // user given detsizey used only within max value + if (detSizeY > 1 && detSizeY <= maxChanY) { + maxChanY = detSizeY; } - nMody = maxy / modSize.y; + nMody = maxChanY / modSize.y; nModx = size() / nMody; - if ((maxy % modSize.y) > 0) { + if ((maxChanY % modSize.y) > 0) { ++nModx; } } @@ -518,19 +523,18 @@ void DetectorImpl::setTransmissionDelay(int step) { f.get(); } -int DetectorImpl::destroyReceivingDataSockets() { +void DetectorImpl::destroyReceivingDataSockets() { LOG(logINFO) << "Going to destroy data sockets"; // close socket zmqSocket.clear(); client_downstream = false; LOG(logINFO) << "Destroyed Receiving Data Socket(s)"; - return OK; } -int DetectorImpl::createReceivingDataSockets() { +void DetectorImpl::createReceivingDataSockets() { if (client_downstream) { - return OK; + return; } LOG(logINFO) << "Going to create data sockets"; @@ -557,24 +561,22 @@ int DetectorImpl::createReceivingDataSockets() { int hwm = shm()->zmqHwm; if (hwm >= 0) { zmqSocket[iSocket]->SetReceiveHighWaterMark(hwm); - if (zmqSocket[iSocket]->GetReceiveHighWaterMark() != hwm) { - throw ZmqSocketError("Could not set zmq rcv hwm to " + - std::to_string(hwm)); - } + // need not reconnect. cannot be connected (detector idle) } LOG(logINFO) << "Zmq Client[" << iSocket << "] at " << zmqSocket.back()->GetZmqServerAddress() << "[hwm: " << zmqSocket.back()->GetReceiveHighWaterMark() << "]"; - } catch (...) { - LOG(logERROR) << "Could not create Zmq socket on port " << portnum; + } catch (std::exception &e) { destroyReceivingDataSockets(); - return FAIL; + std::ostringstream oss; + oss << "Could not create zmq sub socket on port " << portnum; + oss << " [" << e.what() << ']'; + throw RuntimeError(oss.str()); } } client_downstream = true; LOG(logINFO) << "Receiving Data Socket(s) created"; - return OK; } void DetectorImpl::readFrameFromReceiver() { @@ -1114,9 +1116,7 @@ void DetectorImpl::setDataStreamingToClient(bool enable) { destroyReceivingDataSockets(); // create data threads } else { - if (createReceivingDataSockets() == FAIL) { - throw RuntimeError("Could not create data threads in client."); - } + createReceivingDataSockets(); } } @@ -1149,11 +1149,7 @@ void DetectorImpl::setClientStreamingHwm(const int limit) { if (limit >= 0) { for (auto &it : zmqSocket) { it->SetReceiveHighWaterMark(limit); - if (it->GetReceiveHighWaterMark() != limit) { - shm()->zmqHwm = -1; - throw ZmqSocketError("Could not set zmq rcv hwm to " + - std::to_string(limit)); - } + // need not reconnect. cannot be connected (detector idle) } LOG(logINFO) << "Setting Client Zmq socket rcv hwm to " << limit; } @@ -1231,8 +1227,7 @@ int DetectorImpl::acquire() { // let the progress thread (no callback) know acquisition is done if (dataReady == nullptr) { setJoinThreadFlag(true); - } - if (receiver) { + } else if (receiver) { while (numZmqRunning != 0) { Parallel(&Module::restreamStopFromReceiver, {}); std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -1322,6 +1317,7 @@ void DetectorImpl::processData(bool receiver) { } // only update progress else { + LOG(logINFO) << "Type 'q' and hit enter to stop acquisition"; double progress = 0; printProgress(progress); @@ -1778,6 +1774,10 @@ void DetectorImpl::setBadChannels(const std::string &fname, Positions pos) { if (list.empty()) { throw RuntimeError("Bad channel file is empty."); } + setBadChannels(list, pos); +} + +void DetectorImpl::setBadChannels(const std::vector list, Positions pos) { // update to multi values if multi modules if (isAllPositions(pos)) { @@ -1794,20 +1794,24 @@ void DetectorImpl::setBadChannels(const std::string &fname, Positions pos) { " out of bounds."); } int ch = badchannel % nchan; - int imod = badchannel / nchan; - if (imod >= (int)modules.size()) { + size_t imod = badchannel / nchan; + if (imod >= modules.size()) { throw RuntimeError("Invalid bad channel list. " + std::to_string(badchannel) + " out of bounds."); } - - if ((int)badchannels.size() != imod + 1) { + if (badchannels.size() != imod + 1) { badchannels.push_back(std::vector{}); } badchannels[imod].push_back(ch); } - for (int imod = 0; imod != (int)modules.size(); ++imod) { - Parallel(&Module::setBadChannels, {imod}, badchannels[imod]); + for (size_t imod = 0; imod != modules.size(); ++imod) { + // add empty vector if no bad channels in this module + if (badchannels.size() != imod + 1) { + badchannels.push_back(std::vector{}); + } + Parallel(&Module::setBadChannels, {static_cast(imod)}, + badchannels[imod]); } } else if (pos.size() != 1) { diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index 21f8dcdd8..8bb14b47a 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -306,6 +306,7 @@ class DetectorImpl : public virtual slsDetectorDefs { void getBadChannels(const std::string &fname, Positions pos) const; void setBadChannels(const std::string &fname, Positions pos); + void setBadChannels(const std::vector list, Positions pos); std::vector getCtbDacNames() const; std::string getCtbDacName(defs::dacIndex i) const; @@ -348,8 +349,8 @@ class DetectorImpl : public virtual slsDetectorDefs { void updateDetectorSize(); - int destroyReceivingDataSockets(); - int createReceivingDataSockets(); + void destroyReceivingDataSockets(); + void createReceivingDataSockets(); /** * Reads frames from receiver through a constant socket diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 30a5e0656..9039c0608 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -76,7 +76,7 @@ void Module::setHostname(const std::string &hostname, initialDetectorServerChecks(); checkDetectorVersionCompatibility(); LOG(logINFO) << "Module Version Compatibility - Success"; - } catch (const DetectorError &e) { + } catch (const RuntimeError &e) { if (!initialChecks) { LOG(logWARNING) << "Bypassing Initial Checks at your own risk!"; } else { @@ -876,26 +876,25 @@ void Module::startReadout() { } void Module::stopAcquisition() { - // get status before stopping acquisition - runStatus s = ERROR, r = ERROR; - bool zmqstreaming = false; + + // get det status before stopping acq + runStatus detStatus = ERROR; try { - if (shm()->useReceiverFlag && getReceiverStreaming()) { - zmqstreaming = true; - s = getRunStatus(); - r = getReceiverStatus(); - } + detStatus = getRunStatus(); } catch (...) { - // if receiver crashed, stop detector in any case - zmqstreaming = false; } sendToDetectorStop(F_STOP_ACQUISITION); shm()->stoppedFlag = true; - // if rxr streaming and acquisition finished, restream dummy stop packet - if (zmqstreaming && (s == IDLE) && (r == IDLE)) { - restreamStopFromReceiver(); + // restream dummy header, if rxr streaming and det idle before stop + try { + if (shm()->useReceiverFlag && getReceiverStreaming()) { + if (detStatus == IDLE && getReceiverStatus() == IDLE) { + restreamStopFromReceiver(); + } + } + } catch (...) { } } diff --git a/slsDetectorSoftware/src/Pattern.cpp b/slsDetectorSoftware/src/Pattern.cpp index 4592c06f0..67b6d120b 100644 --- a/slsDetectorSoftware/src/Pattern.cpp +++ b/slsDetectorSoftware/src/Pattern.cpp @@ -9,7 +9,15 @@ namespace sls { -Pattern::Pattern() = default; +Pattern::Pattern() { + // initialize pattern addresses + for (int i = 0; i != MAX_PATTERN_LEVELS; ++i) { + pat->startloop[i] = MAX_PATTERN_LENGTH - 1; + pat->stoploop[i] = MAX_PATTERN_LENGTH - 1; + pat->wait[i] = MAX_PATTERN_LENGTH - 1; + } +} + Pattern::~Pattern() { delete pat; } Pattern::Pattern(const Pattern &other) { diff --git a/slsDetectorSoftware/src/SharedMemory.h b/slsDetectorSoftware/src/SharedMemory.h index e31fc5fb9..880e7e89f 100644 --- a/slsDetectorSoftware/src/SharedMemory.h +++ b/slsDetectorSoftware/src/SharedMemory.h @@ -33,7 +33,7 @@ namespace sls { template class SharedMemory { static constexpr int NAME_MAX_LENGTH = 255; std::string name; - T *shared_struct{}; + T *shared_struct{nullptr}; public: // moduleid of -1 creates a detector only shared memory @@ -64,8 +64,18 @@ template class SharedMemory { unmapSharedMemory(); } - T *operator()() { return shared_struct; } - const T *operator()() const { return shared_struct; } + T *operator()() { + if (shared_struct) + return shared_struct; + throw SharedMemoryError(getNoShmAccessMessage()); + } + + const T *operator()() const { + if (shared_struct) + return shared_struct; + throw SharedMemoryError(getNoShmAccessMessage()); + } + std::string getName() const { return name; } bool exists() { @@ -204,6 +214,11 @@ template class SharedMemory { throw SharedMemoryError(msg); } } + + const char *getNoShmAccessMessage() const { + return ("No shared memory to access. Create it first with " + "hostname or config command."); + }; }; } // namespace sls diff --git a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp index fbe801ba1..1be0fb46c 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp @@ -702,11 +702,11 @@ TEST_CASE("confadc", "[.cmd]") { } } - REQUIRE_THROWS(proxy.Call("confadc", {"11", "2", "0x3ff"}, -1, + REQUIRE_THROWS(proxy.Call("confadc", {"11", "2", "0x7f"}, -1, PUT)); // invalid chip index - REQUIRE_THROWS(proxy.Call("confadc", {"-1", "10", "0x3ff"}, -1, + REQUIRE_THROWS(proxy.Call("confadc", {"-1", "32", "0x7f"}, -1, PUT)); // invalid adc index - REQUIRE_THROWS(proxy.Call("confadc", {"-1", "10", "0x1fff"}, -1, + REQUIRE_THROWS(proxy.Call("confadc", {"-1", "10", "0x80"}, -1, PUT)); // invalid value { std::ostringstream oss; @@ -718,10 +718,11 @@ TEST_CASE("confadc", "[.cmd]") { proxy.Call("confadc", {"2", "3"}, -1, GET, oss); REQUIRE(oss.str() == "confadc 0x11\n"); } + for (int i = 0; i != ndet; ++i) { for (int j = 0; j != nchip; ++j) { for (int k = 0; k != nadc; ++k) { - det.setADCConfiguration(j, k, prev_val[i][j][k], {i}); + det.setADCConfiguration(-1, k, prev_val[i][j][k], {i}); } } } diff --git a/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp b/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp index 623d9fdcb..6d055e5c6 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-pattern.cpp @@ -181,12 +181,14 @@ TEST_CASE("patloop", "[.cmd]") { { std::ostringstream oss; proxy.Call("patloop", {sLoop, "0x20", "0x5c"}, -1, PUT, oss); - REQUIRE(oss.str() == "patloop [0x0020, 0x005c]\n"); + REQUIRE(oss.str() == + "patloop " + sLoop + " [0x0020, 0x005c]\n"); } { std::ostringstream oss; proxy.Call("patloop", {sLoop}, -1, GET, oss); - REQUIRE(oss.str() == "patloop [0x0020, 0x005c]\n"); + REQUIRE(oss.str() == + "patloop " + sLoop + " [0x0020, 0x005c]\n"); } for (int iDet = 0; iDet != det.size(); ++iDet) { det.setPatternLoopAddresses(iLoop, prev_val[iDet][0], @@ -227,12 +229,12 @@ TEST_CASE("patnloop", "[.cmd]") { { std::ostringstream oss; proxy.Call("patnloop", {sLoop, "5"}, -1, PUT, oss); - REQUIRE(oss.str() == "patnloop 5\n"); + REQUIRE(oss.str() == "patnloop " + sLoop + " 5\n"); } { std::ostringstream oss; proxy.Call("patnloop", {sLoop}, -1, GET, oss); - REQUIRE(oss.str() == "patnloop 5\n"); + REQUIRE(oss.str() == "patnloop " + sLoop + " 5\n"); } for (int iDet = 0; iDet != det.size(); ++iDet) { det.setPatternLoopCycles(iLoop, prev_val[iDet], {iDet}); @@ -272,12 +274,12 @@ TEST_CASE("patwait", "[.cmd]") { { std::ostringstream oss; proxy.Call("patwait", {sLoop, "0x5c"}, -1, PUT, oss); - REQUIRE(oss.str() == "patwait 0x005c\n"); + REQUIRE(oss.str() == "patwait " + sLoop + " 0x005c\n"); } { std::ostringstream oss; proxy.Call("patwait", {sLoop}, -1, GET, oss); - REQUIRE(oss.str() == "patwait 0x005c\n"); + REQUIRE(oss.str() == "patwait " + sLoop + " 0x005c\n"); } for (int iDet = 0; iDet != det.size(); ++iDet) { det.setPatternWaitAddr(iLoop, prev_val[iDet], {iDet}); @@ -317,12 +319,12 @@ TEST_CASE("patwaittime", "[.cmd]") { { std::ostringstream oss; proxy.Call("patwaittime", {sLoop, "8589936640"}, -1, PUT, oss); - REQUIRE(oss.str() == "patwaittime 8589936640\n"); + REQUIRE(oss.str() == "patwaittime " + sLoop + " 8589936640\n"); } { std::ostringstream oss; proxy.Call("patwaittime", {sLoop}, -1, GET, oss); - REQUIRE(oss.str() == "patwaittime 8589936640\n"); + REQUIRE(oss.str() == "patwaittime " + sLoop + " 8589936640\n"); } for (int iDet = 0; iDet != det.size(); ++iDet) { det.setPatternWaitTime(iLoop, prev_val[iDet], {iDet}); diff --git a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp index 8431a5700..3e57da61d 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp @@ -145,7 +145,8 @@ TEST_CASE("rx_missingpackets", "[.cmd][.rx]") { REQUIRE(oss.str() != "rx_missingpackets [0, 0]\n"); } } - { + auto det_type = det.getDetectorType().squash(); + if (det_type != defs::CHIPTESTBOARD && det_type != defs::MOENCH) { // 0 missing packets (takes into account that acquisition is stopped) det.startReceiver(); det.startDetector(); diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 72387362f..52fb179f7 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -517,8 +517,19 @@ TEST_CASE("gappixels", "[.cmd]") { CmdProxy proxy(&det); auto det_type = det.getDetectorType().squash(); - if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH || - det_type == defs::EIGER) { + // test eiger(quad or full module only) + bool gapPixelTest = false; + if (det_type == defs:: || det_type == defs::MOENCH) + gapPixelTest = true; + else if (det_type == defs::EIGER) { + bool quad = det.getQuad().squash(false); + bool fullModule = (det.getModuleGeometry().y % 2 == 0); + if (quad || fullModule) { + gapPixelTest = true; + } + } + + if (gapPixelTest) { auto prev_val = det.getGapPixelsinCallback(); { std::ostringstream oss; @@ -637,6 +648,8 @@ TEST_CASE("badchannels", "[.cmd]") { auto det_type = det.getDetectorType().squash(); if (det_type == defs::GOTTHARD2 || det_type == defs::MYTHEN3) { + auto prev = det.getBadChannels(); + REQUIRE_THROWS(proxy.Call("badchannels", {}, -1, GET)); std::string fname_put = @@ -649,6 +662,51 @@ TEST_CASE("badchannels", "[.cmd]") { std::vector expected = {0, 12, 15, 40, 41, 42, 43, 44, 1279}; REQUIRE(list == expected); + REQUIRE_NOTHROW(proxy.Call("badchannels", {"none"}, 0, PUT)); + REQUIRE_NOTHROW(proxy.Call("badchannels", {fname_get}, 0, GET)); + list = getChannelsFromFile(fname_get); + REQUIRE(list.empty()); + + REQUIRE_NOTHROW(proxy.Call("badchannels", {fname_put}, 0, PUT)); + + REQUIRE_NOTHROW(proxy.Call("badchannels", {"0"}, 0, PUT)); + REQUIRE_NOTHROW(proxy.Call("badchannels", {fname_get}, 0, GET)); + list = getChannelsFromFile(fname_get); + REQUIRE(list.empty()); + + REQUIRE_NOTHROW(proxy.Call("badchannels", {"12"}, 0, PUT)); + REQUIRE_NOTHROW(proxy.Call("badchannels", {fname_get}, 0, GET)); + list = getChannelsFromFile(fname_get); + expected = {12}; + REQUIRE(list == expected); + + REQUIRE_NOTHROW(proxy.Call( + "badchannels", {"0", "12,", "15", "43", "40:45", "1279"}, 0, PUT)); + REQUIRE_NOTHROW(proxy.Call("badchannels", {fname_get}, 0, GET)); + list = getChannelsFromFile(fname_get); + expected = {0, 12, 15, 40, 41, 42, 43, 44, 1279}; + REQUIRE(list == expected); + + REQUIRE_NOTHROW(proxy.Call("badchannels", {"40:45"}, 0, PUT)); + REQUIRE_NOTHROW(proxy.Call("badchannels", {fname_get}, 0, GET)); + list = getChannelsFromFile(fname_get); + expected = {40, 41, 42, 43, 44}; + REQUIRE(list == expected); + + REQUIRE_NOTHROW(proxy.Call("badchannels", {"5,6,7"}, 0, PUT)); + REQUIRE_NOTHROW(proxy.Call("badchannels", {fname_get}, 0, GET)); + list = getChannelsFromFile(fname_get); + expected = {5, 6, 7}; + REQUIRE(list == expected); + + REQUIRE_NOTHROW(proxy.Call("badchannels", {"1:5,6,7"}, 0, PUT)); + REQUIRE_NOTHROW(proxy.Call("badchannels", {fname_get}, 0, GET)); + list = getChannelsFromFile(fname_get); + expected = {1, 2, 3, 4, 6, 7}; + REQUIRE(list == expected); + + det.setBadChannels(prev); + } else { REQUIRE_THROWS(proxy.Call("badchannels", {}, -1, GET)); } @@ -1216,7 +1274,7 @@ TEST_CASE("clkphase", "[.cmd]") { } std::string s_deg_val = "15"; if (det_type == defs::MYTHEN3) { - s_deg_val = "15"; + s_deg_val = "14"; } else if (det_type == defs::GOTTHARD2) { s_deg_val = "23"; } diff --git a/slsDetectorSoftware/tests/test-SharedMemory.cpp b/slsDetectorSoftware/tests/test-SharedMemory.cpp index 2ddd6167f..5ba3c20a2 100644 --- a/slsDetectorSoftware/tests/test-SharedMemory.cpp +++ b/slsDetectorSoftware/tests/test-SharedMemory.cpp @@ -101,7 +101,8 @@ TEST_CASE("Move SharedMemory", "[detector]") { shm2 = std::move(shm); // shm is now a moved from object! CHECK(shm2()->x == 9); - CHECK(shm() == nullptr); + REQUIRE_THROWS( + shm()); // trying to access should throw instead of returning a nullptr CHECK(shm2.getName() == std::string("/slsDetectorPackage_detector_") + std::to_string(shm_id)); shm2.removeSharedMemory(); diff --git a/slsReceiverSoftware/src/Arping.cpp b/slsReceiverSoftware/src/Arping.cpp index 3431737f5..98c2c2993 100644 --- a/slsReceiverSoftware/src/Arping.cpp +++ b/slsReceiverSoftware/src/Arping.cpp @@ -4,6 +4,8 @@ #include "Arping.h" #include +#include +#include #include namespace sls { @@ -18,7 +20,7 @@ Arping::Arping() {} Arping::~Arping() { if (IsRunning()) { - StopThread(); + StopProcess(); } } @@ -33,59 +35,66 @@ void Arping::SetInterfacesAndIps(const int index, const std::string &interface, // create commands to arping std::ostringstream os; os << "arping -c 1 -U -I " << interface << " " << ip; - // to read error messages - os << " 2>&1"; std::string cmd = os.str(); commands[index] = cmd; } -pid_t Arping::GetThreadId() const { return threadId; } +pid_t Arping::GetProcessId() const { return childPid; } bool Arping::IsRunning() const { return runningFlag; } -void Arping::StartThread() { +void Arping::StartProcess() { TestCommands(); - try { - t = std::thread(&Arping::ThreadExecution, this); - } catch (...) { - throw RuntimeError("Could not start arping thread"); + + // to prevent zombies from child processes being killed + signal(SIGCHLD, SIG_IGN); + + // Needs to be a fork and udp socket deleted after Listening threads + // done running to prevent udp socket cannot bind because of popen + // that forks + childPid = fork(); + // child process + if (childPid == 0) { + LOG(logINFOBLUE) << "Created [ Arping Process, Tid: " << gettid() + << " ]"; + ProcessExecution(); + } + // parent process + else if (childPid > 0) { + runningFlag = true; + } + // error + else { + throw RuntimeError("Could not start arping Process"); } - runningFlag = true; } -void Arping::StopThread() { +void Arping::StopProcess() { + LOG(logINFOBLUE) << "Exiting [ Arping Process ]"; + + if (kill(childPid, SIGTERM)) { + throw RuntimeError("Could not kill the arping Process"); + } runningFlag = false; - t.join(); } -void Arping::ThreadExecution() { - threadId = gettid(); - LOG(logINFOBLUE) << "Created [ Arping Thread, Tid: " << threadId << " ]"; - - while (runningFlag) { +void Arping::ProcessExecution() { + while (true) { std::string error = ExecuteCommands(); - // just print (was already tested at thread start) + // just print (was already tested at Process start) if (!error.empty()) { LOG(logERROR) << error; } - - // wait for 60s as long as thread not killed - int nsecs = 0; - while (runningFlag && nsecs != 60) { - std::this_thread::sleep_for(std::chrono::seconds(1)); - ++nsecs; - } + const auto interval = std::chrono::seconds(60); + std::this_thread::sleep_for(interval); } - - LOG(logINFOBLUE) << "Exiting [ Arping Thread, Tid: " << threadId << " ]"; - threadId = 0; } void Arping::TestCommands() { // atleast one interface must be set up if (commands[0].empty()) { throw RuntimeError( - "Could not arping. Interface not set up in apring thread"); + "Could not arping. Interface not set up in arping Process"); } // test if arping commands throw an error std::string error = ExecuteCommands(); @@ -101,7 +110,7 @@ std::string Arping::ExecuteCommands() { if (cmd.empty()) continue; - LOG(logDEBUG) << "Executing Arping Command: " << cmd; + LOG(logDEBUG1) << "Executing Arping Command: " << cmd; // execute command FILE *sysFile = popen(cmd.c_str(), "r"); diff --git a/slsReceiverSoftware/src/Arping.h b/slsReceiverSoftware/src/Arping.h index 4a4571605..bd6ea21a6 100644 --- a/slsReceiverSoftware/src/Arping.h +++ b/slsReceiverSoftware/src/Arping.h @@ -2,15 +2,15 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package #pragma once /** - *@short creates/destroys an ARPing thread to arping the interfaces slsReceiver -is listening to. + *@short creates/destroys an ARPing child process to arping the interfaces +slsReceiver is listening to. */ #include "receiver_defs.h" #include "sls/logger.h" #include -#include +#include namespace sls { @@ -22,21 +22,20 @@ class Arping { void SetInterfacesAndIps(const int index, const std::string &interface, const std::string &ip); - pid_t GetThreadId() const; + pid_t GetProcessId() const; bool IsRunning() const; - void StartThread(); - void StopThread(); + void StartProcess(); + void StopProcess(); private: void TestCommands(); std::string ExecuteCommands(); - void ThreadExecution(); + void ProcessExecution(); std::vector commands = std::vector(MAX_NUMBER_OF_LISTENING_THREADS); std::atomic runningFlag{false}; - std::thread t; - std::atomic threadId{0}; + std::atomic childPid{0}; }; } // namespace sls diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index b01e5b33a..7dbea2135 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -234,8 +234,7 @@ int ClientInterface::decodeFunction(Interface &socket) { socket.Receive(fnum); socket.setFnum(fnum); if (fnum <= NUM_DET_FUNCTIONS || fnum >= NUM_REC_FUNCTIONS) { - throw RuntimeError("Unrecognized Function enum " + - std::to_string(fnum) + "\n"); + throw RuntimeError(UNRECOGNIZED_FNUM_ENUM + std::to_string(fnum)); } else { LOG(logDEBUG1) << "calling function fnum: " << fnum << " (" << getFunctionNameFromEnum((enum detFuncs)fnum) << ")"; @@ -320,164 +319,121 @@ int ClientInterface::setup_receiver(Interface &socket) { auto arg = socket.Receive(); LOG(logDEBUG) << ToString(arg); - // if object exists, verify unlocked and idle, else only verify lock - // (connecting first time) - if (receiver != nullptr) { - verifyIdle(socket); - } - - // basic setup - setDetectorType(arg.detType); - impl()->setDetectorSize(arg.numberOfModule); - impl()->setModulePositionId(arg.moduleIndex); - impl()->setDetectorHostname(arg.hostname); - - // udp setup - // update retvals only if detmac is not the same as in detector MacAddr retvals[2]; - if (arg.udp_dstip != 0) { - MacAddr r = setUdpIp(IpAddr(arg.udp_dstip)); - MacAddr detMac{arg.udp_dstmac}; - if (detMac != r) { - retvals[0] = r; + try { + // if object exists, verify unlocked and idle, else only verify lock + // (connecting first time) + if (receiver != nullptr) { + verifyIdle(socket); } - } - if (arg.udp_dstip2 != 0) { - MacAddr r = setUdpIp2(IpAddr(arg.udp_dstip2)); - MacAddr detMac{arg.udp_dstmac2}; - if (detMac != r) { - retvals[1] = r; - } - } - impl()->setUDPPortNumber(arg.udp_dstport); - impl()->setUDPPortNumber2(arg.udp_dstport2); - if (detType == JUNGFRAU || detType == MOENCH || detType == GOTTHARD2) { - try { - impl()->setNumberofUDPInterfaces(arg.udpInterfaces); - } catch (const RuntimeError &e) { - throw RuntimeError("Failed to set number of interfaces to " + - std::to_string(arg.udpInterfaces)); - } - } - impl()->setUDPSocketBufferSize(0); - // acquisition parameters - impl()->setNumberOfFrames(arg.frames); - impl()->setNumberOfTriggers(arg.triggers); - if (detType == GOTTHARD2) { - impl()->setNumberOfBursts(arg.bursts); - } - if (detType == JUNGFRAU) { - impl()->setNumberOfAdditionalStorageCells(arg.additionalStorageCells); - } - if (detType == CHIPTESTBOARD) { - try { + // basic setup + setDetectorType(arg.detType); + impl()->setDetectorSize(arg.numberOfModule); + impl()->setModulePositionId(arg.moduleIndex); + impl()->setDetectorHostname(arg.hostname); + + // udp setup + // update retvals only if detmac is not the same as in detector + if (arg.udp_dstip != 0) { + MacAddr r = setUdpIp(IpAddr(arg.udp_dstip)); + MacAddr detMac{arg.udp_dstmac}; + if (detMac != r) { + retvals[0] = r; + } + } + if (arg.udp_dstip2 != 0) { + MacAddr r = setUdpIp2(IpAddr(arg.udp_dstip2)); + MacAddr detMac{arg.udp_dstmac2}; + if (detMac != r) { + retvals[1] = r; + } + } + + impl()->setUDPPortNumber(arg.udp_dstport); + impl()->setUDPPortNumber2(arg.udp_dstport2); + if (detType == JUNGFRAU || detType == MOENCH || detType == GOTTHARD2) { + impl()->setNumberofUDPInterfaces(arg.udpInterfaces); + } + impl()->setUDPSocketBufferSize(0); + + // acquisition parameters + impl()->setNumberOfFrames(arg.frames); + impl()->setNumberOfTriggers(arg.triggers); + if (detType == GOTTHARD2) { + impl()->setNumberOfBursts(arg.bursts); + } + if (detType == JUNGFRAU) { + impl()->setNumberOfAdditionalStorageCells( + arg.additionalStorageCells); + } + + if (detType == CHIPTESTBOARD) { impl()->setNumberofAnalogSamples(arg.analogSamples); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set num analog samples to " + - std::to_string(arg.analogSamples) + - " due to fifo structure memory allocation."); } - } - if (detType == CHIPTESTBOARD) { - try { + if (detType == CHIPTESTBOARD) { impl()->setNumberofDigitalSamples(arg.digitalSamples); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set num digital samples to " + - std::to_string(arg.analogSamples) + - " due to fifo structure memory allocation."); } - } - if (detType != MYTHEN3) { - impl()->setAcquisitionTime(std::chrono::nanoseconds(arg.expTimeNs)); - } - impl()->setAcquisitionPeriod(std::chrono::nanoseconds(arg.periodNs)); - if (detType == EIGER) { - impl()->setSubExpTime(std::chrono::nanoseconds(arg.subExpTimeNs)); - impl()->setSubPeriod(std::chrono::nanoseconds(arg.subExpTimeNs) + - std::chrono::nanoseconds(arg.subDeadTimeNs)); - impl()->setActivate(static_cast(arg.activate)); - impl()->setDetectorDataStream(LEFT, arg.dataStreamLeft); - impl()->setDetectorDataStream(RIGHT, arg.dataStreamRight); - try { + if (detType != MYTHEN3) { + impl()->setAcquisitionTime(std::chrono::nanoseconds(arg.expTimeNs)); + } + impl()->setAcquisitionPeriod(std::chrono::nanoseconds(arg.periodNs)); + if (detType == EIGER) { + impl()->setSubExpTime(std::chrono::nanoseconds(arg.subExpTimeNs)); + impl()->setSubPeriod(std::chrono::nanoseconds(arg.subExpTimeNs) + + std::chrono::nanoseconds(arg.subDeadTimeNs)); + impl()->setActivate(static_cast(arg.activate)); + impl()->setDetectorDataStream(LEFT, arg.dataStreamLeft); + impl()->setDetectorDataStream(RIGHT, arg.dataStreamRight); impl()->setQuad(arg.quad == 0 ? false : true); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set quad to " + - std::to_string(arg.quad) + - " due to fifo strucutre memory allocation"); + impl()->setThresholdEnergy(arg.thresholdEnergyeV[0]); } - impl()->setThresholdEnergy(arg.thresholdEnergyeV[0]); - } - if (detType == EIGER || detType == JUNGFRAU || detType == MOENCH) { - impl()->setReadNRows(arg.readNRows); - } - if (detType == MYTHEN3) { - std::array val; - for (int i = 0; i < 3; ++i) { - val[i] = arg.thresholdEnergyeV[i]; + if (detType == EIGER || detType == JUNGFRAU || detType == MOENCH) { + impl()->setReadNRows(arg.readNRows); } - impl()->setThresholdEnergy(val); - } - if (detType == EIGER || detType == MYTHEN3) { - try { + if (detType == MYTHEN3) { + std::array val; + for (int i = 0; i < 3; ++i) { + val[i] = arg.thresholdEnergyeV[i]; + } + impl()->setThresholdEnergy(val); + } + if (detType == EIGER || detType == MYTHEN3) { impl()->setDynamicRange(arg.dynamicRange); - } catch (const RuntimeError &e) { - throw RuntimeError( - "Could not set dynamic range. Could not allocate " - "memory for fifo or could not start listening/writing threads"); } - } - impl()->setTimingMode(arg.timMode); - if (detType == EIGER || detType == CHIPTESTBOARD || detType == MYTHEN3) { - try { + impl()->setTimingMode(arg.timMode); + if (detType == EIGER || detType == CHIPTESTBOARD || detType == MYTHEN3) { impl()->setTenGigaEnable(arg.tenGiga); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set 10GbE."); } - } - if (detType == CHIPTESTBOARD) { - try { + if (detType == CHIPTESTBOARD) { impl()->setReadoutMode(arg.roMode); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set read out mode " - "due to fifo memory allocation."); - } - } - if (detType == CHIPTESTBOARD) { - try { impl()->setADCEnableMask(arg.adcMask); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set adc enable mask " - "due to fifo memory allcoation"); - } - try { impl()->setTenGigaADCEnableMask(arg.adc10gMask); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set 10Gb adc enable mask " - "due to fifo memory allcoation"); } - } - if (detType == GOTTHARD) { - try { + if (detType == GOTTHARD) { impl()->setDetectorROI(arg.roi); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set ROI"); } + if (detType == MYTHEN3) { + impl()->setCounterMask(arg.countermask); + impl()->setAcquisitionTime1( + std::chrono::nanoseconds(arg.expTime1Ns)); + impl()->setAcquisitionTime2( + std::chrono::nanoseconds(arg.expTime2Ns)); + impl()->setAcquisitionTime3( + std::chrono::nanoseconds(arg.expTime3Ns)); + impl()->setGateDelay1(std::chrono::nanoseconds(arg.gateDelay1Ns)); + impl()->setGateDelay2(std::chrono::nanoseconds(arg.gateDelay2Ns)); + impl()->setGateDelay3(std::chrono::nanoseconds(arg.gateDelay3Ns)); + impl()->setNumberOfGates(arg.gates); + } + if (detType == GOTTHARD2) { + impl()->setBurstMode(arg.burstType); + } + impl()->setScan(arg.scanParams); + } catch (std::exception &e) { + throw RuntimeError("Could not setup receiver [" + + std::string(e.what()) + ']'); } - if (detType == MYTHEN3) { - impl()->setCounterMask(arg.countermask); - impl()->setAcquisitionTime1(std::chrono::nanoseconds(arg.expTime1Ns)); - impl()->setAcquisitionTime2(std::chrono::nanoseconds(arg.expTime2Ns)); - impl()->setAcquisitionTime3(std::chrono::nanoseconds(arg.expTime3Ns)); - impl()->setGateDelay1(std::chrono::nanoseconds(arg.gateDelay1Ns)); - impl()->setGateDelay2(std::chrono::nanoseconds(arg.gateDelay2Ns)); - impl()->setGateDelay3(std::chrono::nanoseconds(arg.gateDelay3Ns)); - impl()->setNumberOfGates(arg.gates); - } - if (detType == GOTTHARD2) { - impl()->setBurstMode(arg.burstType); - } - impl()->setScan(arg.scanParams); return socket.sendResult(retvals); } @@ -501,13 +457,10 @@ void ClientInterface::setDetectorType(detectorType arg) { detType = GENERIC; receiver = make_unique(arg); detType = arg; - } catch (std::exception &e) { - std::ostringstream os; - os << "Could not set detector type in the receiver. "; - os << e.what(); - throw RuntimeError(os.str()); + } catch (const std::exception &e) { + throw RuntimeError("Could not set detector type in the receiver. [" + + std::string(e.what()) + ']'); } - // callbacks after (in setdetectortype, the object is reinitialized) if (startAcquisitionCallBack != nullptr) impl()->registerCallBackStartAcquisition(startAcquisitionCallBack, @@ -535,8 +488,8 @@ int ClientInterface::set_detector_roi(Interface &socket) { verifyIdle(socket); try { impl()->setDetectorROI(arg); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set ROI"); + } catch (const std::exception &e) { + throw RuntimeError("Could not set ROI [" + std::string(e.what()) + ']'); } return socket.Send(OK); } @@ -615,10 +568,10 @@ int ClientInterface::set_num_analog_samples(Interface &socket) { } try { impl()->setNumberofAnalogSamples(value); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set num analog samples to " + - std::to_string(value) + - " due to fifo structure memory allocation."); + } catch (const std::exception &e) { + throw RuntimeError("Could not set number of analog samples to " + + std::to_string(value) + " [" + + std::string(e.what()) + ']'); } return socket.Send(OK); } @@ -631,11 +584,12 @@ int ClientInterface::set_num_digital_samples(Interface &socket) { } try { impl()->setNumberofDigitalSamples(value); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set num digital samples to " + - std::to_string(value) + - " due to fifo structure memory allocation."); + } catch (const std::exception &e) { + throw RuntimeError("Could not set number of digital samples to " + + std::to_string(value) + " [" + + std::string(e.what()) + ']'); } + return socket.Send(OK); } @@ -742,9 +696,9 @@ int ClientInterface::set_dynamic_range(Interface &socket) { } else { try { impl()->setDynamicRange(dr); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not allocate memory for fifo or " - "could not start listening/writing threads"); + } catch (const std::exception &e) { + throw RuntimeError("Could not set dynamic range [" + + std::string(e.what()) + ']'); } } } @@ -780,7 +734,12 @@ int ClientInterface::get_status(Interface &socket) { int ClientInterface::start_receiver(Interface &socket) { if (impl()->getStatus() == IDLE) { LOG(logDEBUG1) << "Starting Receiver"; - impl()->startReceiver(); + try { + impl()->startReceiver(); + } catch (const std::exception &e) { + throw RuntimeError("Could not start reciever [" + + std::string(e.what()) + ']'); + } } return socket.Send(OK); } @@ -790,12 +749,16 @@ int ClientInterface::stop_receiver(Interface &socket) { if (impl()->getStatus() == RUNNING) { LOG(logDEBUG1) << "Stopping Receiver"; impl()->setStoppedFlag(static_cast(arg)); - impl()->stopReceiver(); + try { + impl()->stopReceiver(); + } catch (const std::exception &e) { + throw RuntimeError("Could not stop receiver [" + + std::string(e.what()) + ']'); + } } auto s = impl()->getStatus(); if (s != IDLE) - throw RuntimeError("Could not stop receiver. It as it is: " + - ToString(s)); + throw RuntimeError("Could not stop receiver. Status: " + ToString(s)); return socket.Send(OK); } @@ -810,7 +773,12 @@ int ClientInterface::set_file_dir(Interface &socket) { throw RuntimeError("Receiver path needs to be absolute path"); LOG(logDEBUG1) << "Setting file path: " << fpath; - impl()->setFilePath(fpath); + try { + impl()->setFilePath(fpath); + } catch (const std::exception &e) { + throw RuntimeError("Could not set file path [" + std::string(e.what()) + + ']'); + } return socket.Send(OK); } @@ -892,7 +860,12 @@ int ClientInterface::set_file_write(Interface &socket) { } verifyIdle(socket); LOG(logDEBUG1) << "Setting File write enable:" << enable; - impl()->setFileWriteEnable(enable); + try { + impl()->setFileWriteEnable(enable); + } catch (const std::exception &e) { + throw RuntimeError("Could not enable/disable file write [" + + std::string(e.what()) + ']'); + } return socket.Send(OK); } @@ -946,8 +919,9 @@ int ClientInterface::enable_tengiga(Interface &socket) { LOG(logDEBUG1) << "Setting 10GbE:" << val; try { impl()->setTenGigaEnable(val); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set 10GbE."); + } catch (const std::exception &e) { + throw RuntimeError("Could not set 10GbE. [" + + std::string(e.what()) + ']'); } } int retval = impl()->getTenGigaEnable(); @@ -963,9 +937,9 @@ int ClientInterface::set_fifo_depth(Interface &socket) { LOG(logDEBUG1) << "Setting fifo depth:" << value; try { impl()->setFifoDepth(value); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set fifo depth due to fifo structure " - "memory allocation."); + } catch (const std::exception &e) { + throw RuntimeError("Could not set fifo depth [" + + std::string(e.what()) + ']'); } } int retval = impl()->getFifoDepth(); @@ -1000,10 +974,12 @@ int ClientInterface::set_streaming(Interface &socket) { LOG(logDEBUG1) << "Setting data stream enable:" << index; try { impl()->setDataStreamEnable(index); - } catch (const RuntimeError &e) { + } catch (const std::exception &e) { throw RuntimeError("Could not set data stream enable to " + - std::to_string(index)); + std::to_string(index) + " [" + + std::string(e.what()) + ']'); } + return socket.Send(OK); } @@ -1062,7 +1038,12 @@ int ClientInterface::set_file_format(Interface &socket) { } verifyIdle(socket); LOG(logDEBUG1) << "Setting file format:" << f; - impl()->setFileFormat(f); + try { + impl()->setFileFormat(f); + } catch (const std::exception &e) { + throw RuntimeError("Could not set file format to " + ToString(f) + + " [" + std::string(e.what()) + ']'); + } auto retval = impl()->getFileFormat(); validate(f, retval, "set file format", DEC); @@ -1183,7 +1164,13 @@ int ClientInterface::set_udp_socket_buffer_size(Interface &socket) { "Receiver socket buffer size exceeded max (INT_MAX/2)"); } LOG(logDEBUG1) << "Setting UDP Socket Buffer size: " << size; - impl()->setUDPSocketBufferSize(size); + try { + impl()->setUDPSocketBufferSize(size); + } catch (const std::exception &e) { + throw RuntimeError("Could not set udp socket buffer size to " + + std::to_string(size) + " [" + + std::string(e.what()) + ']'); + } } int retval = impl()->getUDPSocketBufferSize(); if (size != 0) @@ -1262,9 +1249,9 @@ int ClientInterface::set_readout_mode(Interface &socket) { LOG(logDEBUG1) << "Setting readout mode: " << arg; try { impl()->setReadoutMode(arg); - } catch (const RuntimeError &e) { - throw RuntimeError( - "Could not set read out mode due to fifo memory allocation."); + } catch (const std::exception &e) { + throw RuntimeError("Could not set read out mode [" + + std::string(e.what()) + ']'); } } auto retval = impl()->getReadoutMode(); @@ -1280,10 +1267,11 @@ int ClientInterface::set_adc_mask(Interface &socket) { LOG(logDEBUG1) << "Setting 1Gb ADC enable mask: " << arg; try { impl()->setADCEnableMask(arg); - } catch (const RuntimeError &e) { - throw RuntimeError( - "Could not set adc enable mask due to fifo memory allcoation"); + } catch (const std::exception &e) { + throw RuntimeError("Could not set adc enable mask [" + + std::string(e.what()) + ']'); } + auto retval = impl()->getADCEnableMask(); if (retval != arg) { std::ostringstream os; @@ -1347,10 +1335,10 @@ int ClientInterface::set_quad_type(Interface &socket) { LOG(logDEBUG1) << "Setting quad:" << quadEnable; try { impl()->setQuad(quadEnable == 0 ? false : true); - } catch (const RuntimeError &e) { + } catch (const std::exception &e) { throw RuntimeError("Could not set quad to " + - std::to_string(quadEnable) + - " due to fifo strucutre memory allocation"); + std::to_string(quadEnable) + " [" + + std::string(e.what()) + ']'); } } int retval = impl()->getQuad() ? 1 : 0; @@ -1486,10 +1474,12 @@ int ClientInterface::set_num_interfaces(Interface &socket) { LOG(logDEBUG1) << "Setting Number of UDP Interfaces:" << arg; try { impl()->setNumberofUDPInterfaces(arg); - } catch (const RuntimeError &e) { - throw RuntimeError("Failed to set number of interfaces to " + - std::to_string(arg)); + } catch (const std::exception &e) { + throw RuntimeError("Could not set number of interfaces to " + + std::to_string(arg) + " [" + std::string(e.what()) + + ']'); } + return socket.Send(OK); } @@ -1499,10 +1489,11 @@ int ClientInterface::set_adc_mask_10g(Interface &socket) { LOG(logDEBUG1) << "Setting 10Gb ADC enable mask: " << arg; try { impl()->setTenGigaADCEnableMask(arg); - } catch (const RuntimeError &e) { - throw RuntimeError( - "Could not set 10Gb adc enable mask due to fifo memory allcoation"); + } catch (const std::exception &e) { + throw RuntimeError("Could not set 10Gb adc enable mask [" + + std::string(e.what()) + ']'); } + auto retval = impl()->getTenGigaADCEnableMask(); if (retval != arg) { std::ostringstream os; @@ -1518,7 +1509,12 @@ int ClientInterface::set_counter_mask(Interface &socket) { auto arg = socket.Receive(); verifyIdle(socket); LOG(logDEBUG1) << "Setting counters: " << arg; - impl()->setCounterMask(arg); + try { + impl()->setCounterMask(arg); + } catch (const std::exception &e) { + throw RuntimeError("Could not set counter mask [" + + std::string(e.what()) + ']'); + } return socket.Send(OK); } @@ -1714,7 +1710,12 @@ int ClientInterface::set_arping(Interface &socket) { } verifyIdle(socket); LOG(logDEBUG1) << "Starting/ Killing arping thread:" << value; - impl()->setArping(value, udpips); + try { + impl()->setArping(value, udpips); + } catch (const std::exception &e) { + throw RuntimeError("Could not start/kill arping thread [" + + std::string(e.what()) + ']'); + } return socket.Send(OK); } @@ -1732,9 +1733,11 @@ int ClientInterface::set_receiver_roi(Interface &socket) { verifyIdle(socket); try { impl()->setReceiverROI(arg); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set ReceiverROI"); + } catch (const std::exception &e) { + throw RuntimeError("Could not set Receiver ROI [" + + std::string(e.what()) + ']'); } + return socket.Send(OK); } @@ -1746,9 +1749,11 @@ int ClientInterface::set_receiver_roi_metadata(Interface &socket) { verifyIdle(socket); try { impl()->setReceiverROIMetadata(arg); - } catch (const RuntimeError &e) { - throw RuntimeError("Could not set ReceiverROI metadata"); + } catch (const std::exception &e) { + throw RuntimeError("Could not set ReceiverROI metadata [" + + std::string(e.what()) + ']'); } + return socket.Send(OK); } diff --git a/slsReceiverSoftware/src/DataStreamer.cpp b/slsReceiverSoftware/src/DataStreamer.cpp index 2ad48ce92..8ade0941a 100644 --- a/slsReceiverSoftware/src/DataStreamer.cpp +++ b/slsReceiverSoftware/src/DataStreamer.cpp @@ -87,19 +87,18 @@ void DataStreamer::CreateZmqSockets(uint32_t port, const IpAddr ip, int hwm) { std::string sip = ip.str(); try { zmqSocket = new ZmqSocket(portnum, (ip != 0 ? sip.c_str() : nullptr)); + // set if custom if (hwm >= 0) { zmqSocket->SetSendHighWaterMark(hwm); - if (zmqSocket->GetSendHighWaterMark() != hwm) { - throw RuntimeError( - "Could not set zmq send high water mark to " + - std::to_string(hwm)); - } + // needed, or HWL is not taken + zmqSocket->Rebind(); } - } catch (...) { - LOG(logERROR) << "Could not create Zmq socket on port " << portnum - << " for Streamer " << index; - throw; + } catch (std::exception &e) { + std::ostringstream oss; + oss << "Could not create zmq pub socket on port " << portnum; + oss << " [" << e.what() << ']'; + throw RuntimeError(oss.str()); } LOG(logINFO) << index << " Streamer: Zmq Server started at " << zmqSocket->GetZmqServerAddress() diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index dbbc7505b..abfc86a37 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -78,11 +78,12 @@ void Implementation::SetupFifoStructure() { try { fifo.push_back( sls::make_unique(i, datasize, generalData->fifoDepth)); - } catch (...) { + } catch (const std::exception &e) { fifo.clear(); generalData->fifoDepth = 0; - throw RuntimeError("Could not allocate memory for fifo structure " + - std::to_string(i) + ". FifoDepth is now 0."); + std::ostringstream oss; + oss << e.what() << ". Fifo depth is now 0"; + throw RuntimeError(oss.str()); } // set the listener & dataprocessor threads to point to the right fifo if (listener.size()) @@ -165,12 +166,10 @@ void Implementation::setDetectorType(const detectorType d) { SetupListener(i); dataProcessor.push_back(sls::make_unique(i)); SetupDataProcessor(i); - } catch (...) { + } catch (const std::exception &e) { listener.clear(); dataProcessor.clear(); - throw RuntimeError( - "Could not create listener/dataprocessor threads (index:" + - std::to_string(i) + ")"); + throw; } } @@ -212,6 +211,7 @@ void Implementation::SetupDataStreamer(int i) { streamingHwm); dataStreamer[i]->SetAdditionalJsonHeader(additionalJsonHeader); dataStreamer[i]->SetFileIndex(fileIndex); + dataStreamer[i]->SetQuadEnable(quadEnable); dataStreamer[i]->SetFlipRows(flipRows); dataStreamer[i]->SetNumberofPorts(numPorts); dataStreamer[i]->SetQuadEnable(quadEnable); @@ -351,19 +351,21 @@ std::array Implementation::getThreadIds() const { retval[id++] = 0; } } - retval[NUM_RX_THREAD_IDS - 1] = arping.GetThreadId(); + retval[NUM_RX_THREAD_IDS - 1] = arping.GetProcessId(); return retval; } bool Implementation::getArping() const { return arping.IsRunning(); } -pid_t Implementation::getArpingThreadId() const { return arping.GetThreadId(); } +pid_t Implementation::getArpingProcessId() const { + return arping.GetProcessId(); +} void Implementation::setArping(const bool i, const std::vector ips) { if (i != arping.IsRunning()) { if (!i) { - arping.StopThread(); + arping.StopProcess(); } else { // setup interface for (int i = 0; i != generalData->numUDPInterfaces; ++i) { @@ -374,7 +376,7 @@ void Implementation::setArping(const bool i, } arping.SetInterfacesAndIps(i, eth[i], ips[i]); } - arping.StartThread(); + arping.StartProcess(); } } } @@ -665,8 +667,9 @@ void Implementation::startReceiver() { startAcquisitionCallBack(filePath, fileName, fileIndex, imageSize, pStartAcquisition); } catch (const std::exception &e) { - throw RuntimeError("Start Acquisition Callback Error: " + - std::string(e.what())); + std::ostringstream oss; + oss << "Start Acquisition Callback Error: " << e.what(); + throw RuntimeError(oss.str()); } if (rawDataReadyCallBack != nullptr) { LOG(logINFO) << "Data Write has been defined externally"; @@ -713,6 +716,10 @@ void Implementation::stopReceiver() { std::this_thread::sleep_for(std::chrono::milliseconds(5)); } + // delete the udp sockets + for (const auto &it : listener) + it->DeleteUDPSocket(); + if (fileWriteEnable && modulePos == 0) { // master and virtual file (hdf5) StartMasterWriter(); @@ -777,8 +784,9 @@ void Implementation::stopReceiver() { status = IDLE; LOG(logINFO) << "Receiver Stopped"; LOG(logINFO) << "Status: " << ToString(status); - throw RuntimeError("Acquisition Finished Callback Error: " + - std::string(e.what())); + std::ostringstream oss; + oss << "Acquisition Finished Callback Error: " << e.what(); + throw RuntimeError(oss.str()); } } } @@ -859,7 +867,7 @@ void Implementation::CreateUDPSockets() { } } catch (const RuntimeError &e) { shutDownUDPSockets(); - throw RuntimeError("Could not create UDP Socket(s)."); + throw; } LOG(logDEBUG) << "UDP socket(s) created successfully."; } @@ -879,7 +887,9 @@ void Implementation::SetupWriter() { shutDownUDPSockets(); for (const auto &it : dataProcessor) it->CloseFiles(); - throw RuntimeError("Could not create first data file."); + std::ostringstream oss; + oss << "Could not set up writer: " << e.what(); + throw RuntimeError(oss.str()); } } @@ -968,10 +978,9 @@ void Implementation::StartMasterWriter() { } } #endif - } catch (std::exception &e) { + } catch (const std::exception &e) { // ignore it and just print it - LOG(logWARNING) << "Caught exception when handling virtual hdf5 file [" - << e.what() << "]"; + LOG(logWARNING) << "Error creating master/virtualfiles: " << e.what(); } } @@ -1032,12 +1041,10 @@ void Implementation::setNumberofUDPInterfaces(const int n) { SetupListener(i); dataProcessor.push_back(sls::make_unique(i)); SetupDataProcessor(i); - } catch (...) { + } catch (const std::exception &e) { listener.clear(); dataProcessor.clear(); - throw RuntimeError( - "Could not create listener/dataprocessor threads (index:" + - std::to_string(i) + ")"); + throw; } // streamer threads @@ -1045,16 +1052,14 @@ void Implementation::setNumberofUDPInterfaces(const int n) { try { dataStreamer.push_back(sls::make_unique(i)); SetupDataStreamer(i); - } catch (...) { + } catch (const std::exception &e) { if (dataStreamEnable) { dataStreamer.clear(); dataStreamEnable = false; for (const auto &it : dataProcessor) it->SetDataStreamEnable(dataStreamEnable); } - throw RuntimeError( - "Could not create datastreamer threads (index:" + - std::to_string(i) + ")"); + throw; } } } @@ -1165,12 +1170,12 @@ void Implementation::setDataStreamEnable(const bool enable) { try { dataStreamer.push_back(sls::make_unique(i)); SetupDataStreamer(i); - } catch (...) { + } catch (const std::exception &e) { dataStreamer.clear(); dataStreamEnable = false; for (const auto &it : dataProcessor) it->SetDataStreamEnable(dataStreamEnable); - throw RuntimeError("Could not set data stream enable."); + throw; } } SetThreadPriorities(); diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index a9ebd660f..3dc3b3cda 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -54,7 +54,7 @@ class Implementation : private virtual slsDetectorDefs { void setThreadIds(const pid_t parentTid, const pid_t tcpTid); std::array getThreadIds() const; bool getArping() const; - pid_t getArpingThreadId() const; + pid_t getArpingProcessId() const; void setArping(const bool i, const std::vector ips); ROI getReceiverROI() const; void setReceiverROI(const ROI arg); @@ -323,7 +323,7 @@ class Implementation : private virtual slsDetectorDefs { // acquisition std::atomic status{IDLE}; - bool stoppedFlag{false}; + std::atomic stoppedFlag{false}; scanParameters scanParams{}; // network configuration (UDP) diff --git a/slsReceiverSoftware/src/Listener.cpp b/slsReceiverSoftware/src/Listener.cpp index bd0c07a2b..14b387d36 100644 --- a/slsReceiverSoftware/src/Listener.cpp +++ b/slsReceiverSoftware/src/Listener.cpp @@ -148,30 +148,34 @@ void Listener::RecordFirstIndex(uint64_t fnum) { } void Listener::CreateUDPSocket(int &actualSize) { - if (disabledPort) { - return; - } - uint32_t packetSize = generalData->packetSize; - if (generalData->detType == GOTTHARD2 && index != 0) { - packetSize = generalData->vetoPacketSize; - } - try { + if (disabledPort) { + return; + } + uint32_t packetSize = generalData->packetSize; + if (generalData->detType == GOTTHARD2 && index != 0) { + packetSize = generalData->vetoPacketSize; + } + udpSocket = nullptr; udpSocket = make_unique( udpPortNumber, packetSize, (eth.length() ? InterfaceNameToIp(eth).str().c_str() : nullptr), generalData->udpSocketBufferSize); LOG(logINFO) << index << ": UDP port opened at port " << udpPortNumber; - } catch (...) { - throw RuntimeError("Could not create UDP socket on port " + - std::to_string(udpPortNumber)); + + udpSocketAlive = true; + + // doubled due to kernel bookkeeping (could also be less due to + // permissions) + actualSize = udpSocket->getBufferSize(); + + } catch (std::exception &e) { + std::ostringstream oss; + oss << "Could not create UDP socket on port " << udpPortNumber << " [" + << e.what() << ']'; + throw RuntimeError(oss.str()); } - - udpSocketAlive = true; - - // doubled due to kernel bookkeeping (could also be less due to permissions) - actualSize = udpSocket->getBufferSize(); } void Listener::ShutDownUDPSocket() { @@ -184,6 +188,13 @@ void Listener::ShutDownUDPSocket() { } } +void Listener::DeleteUDPSocket() { + if (udpSocket) { + udpSocket.reset(); + LOG(logINFO) << "Closed UDP port " << udpPortNumber; + } +} + void Listener::CreateDummySocketForUDPSocketBufferSize(int s, int &actualSize) { // custom setup (s != 0) // default setup at startup (s = 0) diff --git a/slsReceiverSoftware/src/Listener.h b/slsReceiverSoftware/src/Listener.h index 8ebeee35f..5b50e53f6 100644 --- a/slsReceiverSoftware/src/Listener.h +++ b/slsReceiverSoftware/src/Listener.h @@ -50,6 +50,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { void ResetParametersforNewAcquisition(); void CreateUDPSocket(int &actualSize); void ShutDownUDPSocket(); + void DeleteUDPSocket(); /** to set & get actual buffer size */ void CreateDummySocketForUDPSocketBufferSize(int s, int &actualSize); diff --git a/slsSupportLib/include/sls/ZmqSocket.h b/slsSupportLib/include/sls/ZmqSocket.h index 77cd54f9a..3537f1f35 100644 --- a/slsSupportLib/include/sls/ZmqSocket.h +++ b/slsSupportLib/include/sls/ZmqSocket.h @@ -31,6 +31,11 @@ namespace sls { // #define ZMQ_DETAIL #define ROIVERBOSITY +// high water mark for gui +#define DEFFAULT_LOW_ZMQ_HWM (25) +#define DEFAULT_LOW_ZMQ_HWM_BUFFERSIZE (1024 * 1024) // 1MB +#define DEFAULT_ZMQ_BUFFERSIZE (-1) // os default + /** zmq header structure */ struct zmqHeader { /** true if incoming data, false if end of acquisition */ @@ -108,15 +113,29 @@ class ZmqSocket { /** Returns high water mark for outbound messages */ int GetSendHighWaterMark(); - /** Sets high water mark for outbound messages. Default 1000 (zmqlib) */ + /** Sets high water mark for outbound messages. Default 1000 (zmqlib). Also + * changes send buffer size depending on hwm. Must rebind. */ void SetSendHighWaterMark(int limit); /** Returns high water mark for inbound messages */ int GetReceiveHighWaterMark(); - /** Sets high water mark for inbound messages. Default 1000 (zmqlib) */ + /** Sets high water mark for inbound messages. Default 1000 (zmqlib). Also + * changes receiver buffer size depending on hwm. Must reconnect */ void SetReceiveHighWaterMark(int limit); + /** Gets kernel buffer for outbound messages. Default 0 (os) */ + int GetSendBuffer(); + + /** Sets kernel buffer for outbound messages. Default 0 (os) */ + void SetSendBuffer(int limit); + + /** Gets kernel buffer for inbound messages. Default 0 (os) */ + int GetReceiveBuffer(); + + /** Sets kernel buffer for inbound messages. Default 0 (os) */ + void SetReceiveBuffer(int limit); + /** * Returns Port Number * @returns Port Number @@ -129,6 +148,9 @@ class ZmqSocket { */ std::string GetZmqServerAddress() { return sockfd.serverAddress; } + /** unbinds and rebind, to apply changes of HWM */ + void Rebind(); + /** * Connect client socket to server socket * @returns 1 for fail, 0 for success diff --git a/slsSupportLib/include/sls/container_utils.h b/slsSupportLib/include/sls/container_utils.h index 08fa534d6..650c05b7c 100644 --- a/slsSupportLib/include/sls/container_utils.h +++ b/slsSupportLib/include/sls/container_utils.h @@ -148,6 +148,18 @@ Squash(const Container &c, typename Container::value_type default_value = {}) { return default_value; } +template +typename std::enable_if::value, bool>::type +removeDuplicates(T &c) { + auto containerSize = c.size(); + std::sort(c.begin(), c.end()); + c.erase(std::unique(c.begin(), c.end()), c.end()); + if (c.size() != containerSize) { + return true; + } + return false; +} + } // namespace sls #endif // CONTAINER_UTILS_H diff --git a/slsSupportLib/include/sls/file_utils.h b/slsSupportLib/include/sls/file_utils.h index 5f0bc5967..010fc640c 100644 --- a/slsSupportLib/include/sls/file_utils.h +++ b/slsSupportLib/include/sls/file_utils.h @@ -50,6 +50,8 @@ ssize_t getFileSize(FILE *fd, const std::string &prependErrorString); std::string getFileNameFromFilePath(const std::string &fpath); +std::vector getChannelsFromStringList(const std::vector list); + /** File can have # for comments. * Channels can be separated by spaces, commas * and ranges provided using ':', eg. 23:29 diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index 0fedd9fff..c776bed75 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -10,6 +10,8 @@ *@short functions indices to call on server (detector/receiver) */ +#define UNRECOGNIZED_FNUM_ENUM "Unrecognized Function enum" + enum detFuncs { F_EXEC_COMMAND = 0, F_GET_DETECTOR_TYPE, diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index d134475fe..d947a3e35 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -1,6 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-other // Copyright (C) 2021 Contributors to the SLS Detector Package /** API versions */ +<<<<<<< HEAD #define RELEASE "developer" #define APILIB "developer 0x221213" #define APIRECEIVER "developer 0x221213" @@ -11,3 +12,15 @@ #define APIMOENCH "developer 0x221215" #define APIGOTTHARD "developer 0x230117" #define APIMYTHEN3 "developer 0x230117" +======= +#define RELEASE "7.0.0" +#define APICTB "7.0.0 0x230222" +#define APIGOTTHARD "7.0.0 0x230222" +#define APIGOTTHARD2 "7.0.0 0x230222" +#define APIJUNGFRAU "7.0.0 0x230222" +#define APIMYTHEN3 "7.0.0 0x230222" +#define APIMOENCH "7.0.0 0x230222" +#define APIEIGER "7.0.0 0x230222" +#define APILIB "7.0.0 0x230223" +#define APIRECEIVER "7.0.0 0x230222" +>>>>>>> 7.0.0.rc diff --git a/slsSupportLib/src/ClientSocket.cpp b/slsSupportLib/src/ClientSocket.cpp index 866314372..117e7621c 100644 --- a/slsSupportLib/src/ClientSocket.cpp +++ b/slsSupportLib/src/ClientSocket.cpp @@ -4,6 +4,7 @@ #include "sls/logger.h" #include "sls/sls_detector_defs.h" #include "sls/sls_detector_exceptions.h" +#include "sls/sls_detector_funcs.h" #include #include #include @@ -76,9 +77,7 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) { try { Receive(&ret, sizeof(ret)); if (ret == slsDetectorDefs::FAIL) { - char mess[MAX_STR_LENGTH]{}; - // get error message - Receive(mess, sizeof(mess)); + std::string mess = readErrorMessage(); // Do we need to know hostname here? // In that case save it??? if (socketType == "Receiver") { @@ -107,6 +106,9 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) { std::string ClientSocket::readErrorMessage() { std::string error_msg(MAX_STR_LENGTH, '\0'); Receive(&error_msg[0], error_msg.size()); + if (error_msg.find(UNRECOGNIZED_FNUM_ENUM) != std::string::npos) { + error_msg.insert(0, "Software version mismatch. "); + } return error_msg; } diff --git a/slsSupportLib/src/UdpRxSocket.cpp b/slsSupportLib/src/UdpRxSocket.cpp index c7634544c..1ef7b2d7c 100644 --- a/slsSupportLib/src/UdpRxSocket.cpp +++ b/slsSupportLib/src/UdpRxSocket.cpp @@ -27,15 +27,18 @@ UdpRxSocket::UdpRxSocket(int port, ssize_t packet_size, const char *hostname, const std::string portname = std::to_string(port); if (getaddrinfo(hostname, portname.c_str(), &hints, &res)) { throw RuntimeError("Failed at getaddrinfo with " + - std::string(hostname)); + std::string(hostname) + " [" + + std::string(strerror(errno)) + ']'); } sockfd_ = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (sockfd_ == -1) { - throw RuntimeError("Failed to create UDP RX socket"); + throw RuntimeError("Failed to create UDP RX socket [" + + std::string(strerror(errno)) + ']'); } if (bind(sockfd_, res->ai_addr, res->ai_addrlen) == -1) { close(sockfd_); - throw RuntimeError("Failed to bind UDP RX socket"); + throw RuntimeError("Failed to bind UDP RX socket [" + + std::string(strerror(errno)) + ']'); } freeaddrinfo(res); @@ -74,13 +77,15 @@ int UdpRxSocket::getBufferSize() const { int ret = 0; socklen_t optlen = sizeof(ret); if (getsockopt(sockfd_, SOL_SOCKET, SO_RCVBUF, &ret, &optlen) == -1) - throw RuntimeError("Could not get socket buffer size"); + throw RuntimeError("Could not get socket buffer size [" + + std::string(strerror(errno)) + ']'); return ret; } void UdpRxSocket::setBufferSize(int size) { if (setsockopt(sockfd_, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size))) - throw RuntimeError("Could not set socket buffer size"); + throw RuntimeError("Could not set socket buffer size [" + + std::string(strerror(errno)) + ']'); } void UdpRxSocket::Shutdown() { diff --git a/slsSupportLib/src/ZmqSocket.cpp b/slsSupportLib/src/ZmqSocket.cpp index 2711a2b3e..c4c024179 100644 --- a/slsSupportLib/src/ZmqSocket.cpp +++ b/slsSupportLib/src/ZmqSocket.cpp @@ -102,6 +102,16 @@ void ZmqSocket::SetSendHighWaterMark(int limit) { PrintError(); throw ZmqSocketError("Could not set ZMQ_SNDHWM"); } + if (GetSendHighWaterMark() != limit) { + throw ZmqSocketError("Could not set ZMQ_SNDHWM to " + + std::to_string(limit)); + } + + int bufsize = DEFAULT_ZMQ_BUFFERSIZE; + if (limit < DEFFAULT_LOW_ZMQ_HWM) { + bufsize = DEFAULT_LOW_ZMQ_HWM_BUFFERSIZE; + } + SetSendBuffer(bufsize); } int ZmqSocket::GetReceiveHighWaterMark() { @@ -110,7 +120,7 @@ int ZmqSocket::GetReceiveHighWaterMark() { if (zmq_getsockopt(sockfd.socketDescriptor, ZMQ_RCVHWM, &value, &value_size)) { PrintError(); - throw ZmqSocketError("Could not get ZMQ_SNDHWM"); + throw ZmqSocketError("Could not get ZMQ_RCVHWM"); } return value; } @@ -119,7 +129,77 @@ void ZmqSocket::SetReceiveHighWaterMark(int limit) { if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_RCVHWM, &limit, sizeof(limit))) { PrintError(); - throw ZmqSocketError("Could not set ZMQ_SNDHWM"); + throw ZmqSocketError("Could not set ZMQ_RCVHWM"); + } + if (GetReceiveHighWaterMark() != limit) { + throw ZmqSocketError("Could not set ZMQ_RCVHWM to " + + std::to_string(limit)); + } + int bufsize = DEFAULT_ZMQ_BUFFERSIZE; + if (limit < DEFFAULT_LOW_ZMQ_HWM) { + bufsize = DEFAULT_LOW_ZMQ_HWM_BUFFERSIZE; + } + SetReceiveBuffer(bufsize); +} + +int ZmqSocket::GetSendBuffer() { + int value = 0; + size_t value_size = sizeof(value); + if (zmq_getsockopt(sockfd.socketDescriptor, ZMQ_SNDBUF, &value, + &value_size)) { + PrintError(); + throw ZmqSocketError("Could not get ZMQ_SNDBUF"); + } + return value; +} + +void ZmqSocket::SetSendBuffer(int limit) { + if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_SNDBUF, &limit, + sizeof(limit))) { + PrintError(); + throw ZmqSocketError("Could not set ZMQ_SNDBUF"); + } + if (GetSendBuffer() != limit) { + throw ZmqSocketError("Could not set ZMQ_SNDBUF to " + + std::to_string(limit)); + } +} + +int ZmqSocket::GetReceiveBuffer() { + int value = 0; + size_t value_size = sizeof(value); + if (zmq_getsockopt(sockfd.socketDescriptor, ZMQ_RCVBUF, &value, + &value_size)) { + PrintError(); + throw ZmqSocketError("Could not get ZMQ_RCVBUF"); + } + return value; +} + +void ZmqSocket::SetReceiveBuffer(int limit) { + if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_RCVBUF, &limit, + sizeof(limit))) { + PrintError(); + throw ZmqSocketError("Could not set ZMQ_RCVBUF"); + } + if (GetReceiveBuffer() != limit) { + throw ZmqSocketError("Could not set ZMQ_RCVBUF to " + + std::to_string(limit)); + } +} + +void ZmqSocket::Rebind() { // the purpose is to apply HWL changes, which are + // frozen at bind, which is in the constructor. + + // unbbind + if (zmq_unbind(sockfd.socketDescriptor, sockfd.serverAddress.c_str())) { + PrintError(); + throw ZmqSocketError("Could not unbind socket"); + } + // bind address + if (zmq_bind(sockfd.socketDescriptor, sockfd.serverAddress.c_str())) { + PrintError(); + throw ZmqSocketError("Could not bind socket"); } } diff --git a/slsSupportLib/src/file_utils.cpp b/slsSupportLib/src/file_utils.cpp index 36a28c853..15fb3a1c3 100644 --- a/slsSupportLib/src/file_utils.cpp +++ b/slsSupportLib/src/file_utils.cpp @@ -2,6 +2,7 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package #include "sls/file_utils.h" #include "sls/ToString.h" +#include "sls/container_utils.h" #include "sls/logger.h" #include "sls/sls_detector_exceptions.h" @@ -165,6 +166,63 @@ ssize_t getFileSize(FILE *fd, const std::string &prependErrorString) { return fileSize; } +std::vector +getChannelsFromStringList(const std::vector list) { + std::vector channels; + for (auto line : list) { + + // replace comma with space + std::replace_if( + begin(line), end(line), [](char c) { return (c == ','); }, ' '); + + // split line (delim space) + std::vector vec = split(line, ' '); + + // for every channel separated by space + for (auto it : vec) { + // find range and replace with sequence of x to y + auto result = it.find(':'); + if (result != std::string::npos) { + try { + int istart = StringTo(it.substr(0, result)); + int istop = StringTo( + it.substr(result + 1, it.length() - result - 1)); + LOG(logDEBUG1) << "istart:" << istart << " istop:" << istop; + std::vector range(istop - istart); + std::generate(range.begin(), range.end(), + [n = istart]() mutable { return n++; }); + for (auto range_it : range) { + channels.push_back(range_it); + } + } catch (std::exception &e) { + throw RuntimeError( + "Could not load channels. Invalid channel range: " + + it); + } + } + + // else convert to int + else { + int ival = 0; + try { + ival = StringTo(it); + } catch (std::exception &e) { + throw RuntimeError( + "Could not load channels. Invalid channel number: " + + it); + } + channels.push_back(ival); + } + } + } + + if (removeDuplicates(channels)) { + LOG(logWARNING) << "Removed duplicates from channel file"; + } + LOG(logDEBUG1) << "list:" << ToString(channels); + return channels; +} + std::vector getChannelsFromFile(const std::string &fname) { // read bad channels file std::ifstream input_file(fname); @@ -172,73 +230,19 @@ std::vector getChannelsFromFile(const std::string &fname) { throw RuntimeError("Could not open bad channels file " + fname + " for reading"); } - std::vector list; + std::vector lines; for (std::string line; std::getline(input_file, line);) { // ignore comments if (line.find('#') != std::string::npos) { line.erase(line.find('#')); } - - // replace comma with space - std::replace_if( - begin(line), end(line), [](char c) { return (c == ','); }, ' '); - - // replace x:y with a sequence of x to y - auto result = line.find(':'); - while (result != std::string::npos) { - auto start = line.rfind(' ', result); - if (start == std::string::npos) { - start = 0; - } else - ++start; - int istart = StringTo(line.substr(start, result - start)); - - auto stop = line.find(' ', result); - if (stop == std::string::npos) { - stop = line.length(); - } - int istop = - StringTo(line.substr(result + 1, stop - result - 1)); - - std::vector v(istop - istart); - std::generate(v.begin(), v.end(), - [n = istart]() mutable { return n++; }); - line.replace(start, stop - start, ToString(v)); - - LOG(logDEBUG1) << line; - result = line.find(':'); - } - - // remove punctuations including [ and ] - line.erase(std::remove_if(begin(line), end(line), ispunct), end(line)); - - LOG(logDEBUG) << "\nline: [" << line << ']'; - - // split line (delim space) and push to list - std::vector vec = split(line, ' '); - for (auto it : vec) { - int ival = 0; - try { - ival = StringTo(it); - } catch (std::exception &e) { - throw RuntimeError("Could not load channels from file. Invalid " - "channel number: " + - it); - } - list.push_back(ival); + // ignore empty lines + if (line.empty()) { + continue; } + lines.push_back(line); } - - // remove duplicates from list - auto listSize = list.size(); - std::sort(list.begin(), list.end()); - list.erase(unique(list.begin(), list.end()), list.end()); - if (list.size() != listSize) { - LOG(logWARNING) << "Removed duplicates from channel file"; - } - - LOG(logDEBUG1) << "list:" << ToString(list); - return list; + return getChannelsFromStringList(lines); } std::string getAbsolutePathFromCurrentProcess(const std::string &fname) { diff --git a/slsSupportLib/tests/test-container_utils.cpp b/slsSupportLib/tests/test-container_utils.cpp index ea98c084a..b70c8b476 100644 --- a/slsSupportLib/tests/test-container_utils.cpp +++ b/slsSupportLib/tests/test-container_utils.cpp @@ -136,4 +136,18 @@ TEST_CASE("compare a vector of arrays", "[support]") { CHECK(minusOneIfDifferent(vec1) == arr); } +TEST_CASE("remove duplicates from vector") { + std::vector v{5, 6, 5, 3}; + auto r = removeDuplicates(v); + CHECK(r == true); // did indeed remove elements + CHECK(v == std::vector{3, 5, 6}); +} + +TEST_CASE("remove duplicated empty vector") { + std::vector v; + auto r = removeDuplicates(v); + CHECK(r == false); // no elements to remove + CHECK(v == std::vector{}); +} + } // namespace sls