Merge branch 'developer' into jf_h5reader
All checks were successful
Build on RHEL8 / build (push) Successful in 4m37s
Build on RHEL9 / build (push) Successful in 5m6s

This commit is contained in:
hinger_v 2025-04-30 16:19:22 +02:00
commit ab2e290658
87 changed files with 1904 additions and 564 deletions

View File

@ -0,0 +1,29 @@
name: Build on RHEL8
on:
push:
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: "ubuntu-latest"
container:
image: gitea.psi.ch/detectors/rhel8-detectors-dev
steps:
- name: Clone repository
run: |
echo Cloning ${{ github.ref_name }}
git clone https://${{secrets.GITHUB_TOKEN}}@gitea.psi.ch/${{ github.repository }}.git --branch=${{ github.ref_name }} .
- name: Build library
run: |
mkdir build && cd build
cmake .. -DSLS_USE_PYTHON=ON -DSLS_USE_TESTS=ON
make -j 2
- name: C++ unit tests
working-directory: ${{gitea.workspace}}/build
run: ctest

View File

@ -0,0 +1,27 @@
name: Build on RHEL9
on:
push:
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: "ubuntu-latest"
container:
image: gitea.psi.ch/detectors/rhel9-detectors-dev
steps:
- uses: actions/checkout@v4
- name: Build library
run: |
mkdir build && cd build
cmake .. -DSLS_USE_PYTHON=ON -DSLS_USE_TESTS=ON
make -j 2
- name: C++ unit tests
working-directory: ${{gitea.workspace}}/build
run: ctest

View File

@ -1,4 +1,4 @@
name: CMake name: Native CMake Build
on: [push, pull_request] on: [push, pull_request]
@ -14,7 +14,13 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Configure and build using cmake name: Configure and build using cmake
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12
cache: 'pip'
- run: pip install pytest numpy
- uses: awalsh128/cache-apt-pkgs-action@latest - uses: awalsh128/cache-apt-pkgs-action@latest
with: with:
packages: libhdf5-dev qtbase5-dev qt5-qmake libqt5svg5-dev libpng-dev libtiff-dev packages: libhdf5-dev qtbase5-dev qt5-qmake libqt5svg5-dev libpng-dev libtiff-dev
@ -27,12 +33,15 @@ jobs:
- name: Build - name: Build
# Build your program with the given configuration # Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build -j2 --config ${{env.BUILD_TYPE}} run: cmake --build ${{github.workspace}}/build -j4 --config ${{env.BUILD_TYPE}}
- name: Test - name: C++ unit tests
working-directory: ${{github.workspace}}/build working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}} -j1 run: ctest -C ${{env.BUILD_TYPE}} -j1
- name: Python unit tests
working-directory: ${{github.workspace}}/build/bin
run: |
python -m pytest ${{github.workspace}}/python/tests

42
.github/workflows/conda_library.yaml vendored Normal file
View File

@ -0,0 +1,42 @@
name: Build slsdetlib
on: [pull_request]
jobs:
build:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, ] # macos-12, windows-2019]
python-version: ["3.12",]
runs-on: ${{ matrix.platform }}
# The setup-miniconda action needs this to activate miniconda
defaults:
run:
shell: "bash -l {0}"
steps:
- uses: actions/checkout@v4
- name: Get conda
uses: conda-incubator/setup-miniconda@v3.0.4
with:
python-version: ${{ matrix.python-version }}
channels: conda-forge
- name: Prepare
run: conda install conda-build conda-verify pytest anaconda-client
- name: Disable upload
run: conda config --set anaconda_upload no
- name: Build
run: conda build conda-recipes/main-library --output-folder build_output
- name: Upload all Conda packages
uses: actions/upload-artifact@v4
with:
name: conda-packages
path: build_output/** # Uploads all packages

42
.github/workflows/conda_python.yaml vendored Normal file
View File

@ -0,0 +1,42 @@
name: slsdet
on: [pull_request]
jobs:
build:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, ] # macos-12, windows-2019]
python-version: ["3.12",]
runs-on: ${{ matrix.platform }}
# The setup-miniconda action needs this to activate miniconda
defaults:
run:
shell: "bash -l {0}"
steps:
- uses: actions/checkout@v4
- name: Get conda
uses: conda-incubator/setup-miniconda@v3.0.4
with:
python-version: ${{ matrix.python-version }}
channels: conda-forge
- name: Prepare
run: conda install conda-build conda-verify pytest anaconda-client
- name: Disable upload
run: conda config --set anaconda_upload no
- name: Build
run: conda build conda-recipes/python-client --output-folder build_output
- name: Upload all Conda packages
uses: actions/upload-artifact@v4
with:
name: conda-packages
path: build_output/** # Uploads all packages

View File

@ -1,6 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-other # SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package # Copyright (C) 2021 Contributors to the SLS Detector Package
cmake_minimum_required(VERSION 3.14) cmake_minimum_required(VERSION 3.15)
project(slsDetectorPackage) project(slsDetectorPackage)
# Read VERSION file into project version # Read VERSION file into project version
@ -29,20 +29,44 @@ include(FetchContent)
option(SLS_FETCH_ZMQ_FROM_GITHUB "Fetch zmq from github" OFF) option(SLS_FETCH_ZMQ_FROM_GITHUB "Fetch zmq from github" OFF)
option(SLS_FETCH_PYBIND11_FROM_GITHUB "Fetch pybind11 from github" OFF) option(SLS_FETCH_PYBIND11_FROM_GITHUB "Fetch pybind11 from github" OFF)
# Allow FetchContent_Populate to be called with a single argument
# otherwise deprecated warning is issued
# Note: From cmake 3.28 we can pass EXCLUDE_FROM_ALL to FetchContent_Declare
# and avoid direct use of Populate
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30")
cmake_policy(SET CMP0169 OLD)
endif()
# Patch libzmq to set minimum cmake version to 3.15 to avoid warnings
# with newer cmake versions
# Patch is applied in the FetchContent_Declare
set(SLS_LIBZMQ_VERSION "4.3.4")
find_program(PATCH_EXECUTABLE patch)
if(NOT PATCH_EXECUTABLE)
message(FATAL_ERROR "The 'patch' tool is required for patching lib zeromq. Please install it.")
endif()
if(SLS_FETCH_ZMQ_FROM_GITHUB) if(SLS_FETCH_ZMQ_FROM_GITHUB)
# Opt in to pull down a zmq version from github instead of # Opt in to pull down a zmq version from github instead of
# using the bundled verison # using the bundled version
FetchContent_Declare( FetchContent_Declare(
libzmq libzmq
GIT_REPOSITORY https://github.com/zeromq/libzmq.git GIT_REPOSITORY https://github.com/zeromq/libzmq.git
GIT_TAG v4.3.4 GIT_TAG v${SLS_LIBZMQ_VERSION}
PATCH_COMMAND ${CMAKE_COMMAND} -E chdir <SOURCE_DIR> patch -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/libs/libzmq/libzmq_cmake_version.patch
UPDATE_DISCONNECTED 1
) )
else() else()
# Standard behaviour use libzmq included in this repo (libs/libzmq) # Standard behaviour use libzmq included in this repo (libs/libzmq)
FetchContent_Declare( FetchContent_Declare(
libzmq libzmq
URL ${CMAKE_CURRENT_SOURCE_DIR}/libs/libzmq/libzmq-4.3.4.tar.gz URL ${CMAKE_CURRENT_SOURCE_DIR}/libs/libzmq/libzmq-${SLS_LIBZMQ_VERSION}.tar.gz
URL_HASH MD5=cc20b769ac10afa352e5ed2769bb23b3 URL_HASH MD5=cc20b769ac10afa352e5ed2769bb23b3
PATCH_COMMAND ${CMAKE_COMMAND} -E chdir <SOURCE_DIR> patch -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/libs/libzmq/libzmq_cmake_version.patch
UPDATE_DISCONNECTED 1
) )
endif() endif()
@ -54,6 +78,11 @@ set(ENABLE_CPACK OFF CACHE BOOL "")
set(ENABLE_CLANG OFF CACHE BOOL "") set(ENABLE_CLANG OFF CACHE BOOL "")
set(ENABLE_CURVE OFF CACHE BOOL "") set(ENABLE_CURVE OFF CACHE BOOL "")
set(ENABLE_DRAFTS OFF CACHE BOOL "") set(ENABLE_DRAFTS OFF CACHE BOOL "")
set(ENABLE_PRECOMPILED OFF CACHE BOOL "")
set(WITH_DOC OFF CACHE BOOL "")
set(WITH_DOCS OFF CACHE BOOL "")
# Using GetProperties and Populate to be able to exclude zmq # Using GetProperties and Populate to be able to exclude zmq
# from install (not possible with FetchContent_MakeAvailable(libzmq)) # from install (not possible with FetchContent_MakeAvailable(libzmq))
@ -191,7 +220,7 @@ endif()
# to control options for the libraries # to control options for the libraries
if(NOT TARGET slsProjectOptions) if(NOT TARGET slsProjectOptions)
add_library(slsProjectOptions INTERFACE) add_library(slsProjectOptions INTERFACE)
target_compile_features(slsProjectOptions INTERFACE cxx_std_17) target_compile_features(slsProjectOptions INTERFACE cxx_std_17)
endif() endif()
if (NOT TARGET slsProjectWarnings) if (NOT TARGET slsProjectWarnings)
@ -304,7 +333,8 @@ if (SLS_USE_INTEGRATION_TESTS)
endif (SLS_USE_INTEGRATION_TESTS) endif (SLS_USE_INTEGRATION_TESTS)
if (SLS_USE_PYTHON) if (SLS_USE_PYTHON)
find_package (Python 3.8 COMPONENTS Interpreter Development) find_package (Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED)
set(PYBIND11_FINDPYTHON ON) # Needed for RH8
if(SLS_FETCH_PYBIND11_FROM_GITHUB) if(SLS_FETCH_PYBIND11_FROM_GITHUB)
FetchContent_Declare( FetchContent_Declare(
pybind11 pybind11
@ -329,9 +359,15 @@ if (SLS_USE_CTBGUI)
add_subdirectory(pyctbgui) add_subdirectory(pyctbgui)
endif(SLS_USE_CTBGUI) endif(SLS_USE_CTBGUI)
configure_file( .clang-tidy # Workaround for file note being copied to build directory
${CMAKE_BINARY_DIR}/.clang-tidy # when issuing a python -m build
) # TODO! Proper fix
if(EXISTS ".clang-tidy")
configure_file(.clang-tidy
${CMAKE_BINARY_DIR}/.clang-tidy
)
endif()
if (SLS_BUILD_EXAMPLES) if (SLS_BUILD_EXAMPLES)
add_subdirectory(sample) add_subdirectory(sample)

View File

@ -1,11 +0,0 @@
# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package
echo "|<-------- starting python build"
cd python
# copy VERSION into slsdet for installation
cp ../VERSION slsdet/VERSION
${PYTHON} setup.py install

View File

@ -1,8 +0,0 @@
python:
- 3.8
- 3.9
- 3.10
- 3.11
- 3.12
- 3.13

View File

@ -1,11 +0,0 @@
# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package
mkdir $PREFIX/lib
mkdir $PREFIX/bin
mkdir $PREFIX/include
cp build/bin/ctbGui $PREFIX/bin/.
cp build/bin/libctbRootLib.so $PREFIX/lib/.

View File

@ -1,125 +0,0 @@
package:
name: sls_detector_software
version: {{ environ.get('GIT_DESCRIBE_TAG', '') }}
source:
path: ..
build:
number: 0
binary_relocation: True
rpaths:
- lib/
requirements:
build:
- {{ compiler('c') }}
- {{compiler('cxx')}}
- cmake
- qt 5.*
- xorg-libx11
- xorg-libice
- xorg-libxext
- xorg-libsm
- xorg-libxau
- xorg-libxrender
- xorg-libxfixes
- {{ cdt('mesa-libgl-devel') }} # [linux]
- {{ cdt('mesa-libegl-devel') }} # [linux]
- {{ cdt('mesa-dri-drivers') }} # [linux]
- {{ cdt('libselinux') }} # [linux]
- {{ cdt('libxdamage') }} # [linux]
- {{ cdt('libxxf86vm') }} # [linux]
- expat
host:
- libstdcxx-ng
- libgcc-ng
- xorg-libx11
- xorg-libice
- xorg-libxext
- xorg-libsm
- xorg-libxau
- xorg-libxrender
- xorg-libxfixes
- expat
run:
- libstdcxx-ng
- libgcc-ng
outputs:
- name: slsdetlib
script: copy_lib.sh
requirements:
build:
- {{ compiler('c') }}
- {{compiler('cxx')}}
- libstdcxx-ng
- libgcc-ng
run:
- libstdcxx-ng
- libgcc-ng
- name: slsdet
script: build_pylib.sh
requirements:
build:
- python
- {{ compiler('c') }}
- {{compiler('cxx')}}
- {{ pin_subpackage('slsdetlib', exact=True) }}
- setuptools
- pybind11=2.13
host:
- python
- {{ pin_subpackage('slsdetlib', exact=True) }}
- setuptools
- pybind11=2.13
run:
- libstdcxx-ng
- libgcc-ng
- python
- numpy
- {{ pin_subpackage('slsdetlib', exact=True) }}
test:
imports:
- slsdet
- name: slsdetgui
script: copy_gui.sh
requirements:
build:
- {{ compiler('c') }}
- {{compiler('cxx')}}
- {{ pin_subpackage('slsdetlib', exact=True) }}
run:
- {{ pin_subpackage('slsdetlib', exact=True) }}
- qt 5.*
- expat
- name: moenchzmq
script: copy_moench.sh
requirements:
build:
- {{ compiler('c') }}
- {{compiler('cxx')}}
- {{ pin_subpackage('slsdetlib', exact=True) }}
run:
- {{ pin_subpackage('slsdetlib', exact=True) }}
- expat

View File

@ -1,3 +0,0 @@
# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package
ctest -j2

View File

@ -8,7 +8,7 @@ if [ ! -d "install" ]; then
mkdir install mkdir install
fi fi
cd build cd build
cmake .. \ cmake .. -G Ninja \
-DCMAKE_PREFIX_PATH=$CONDA_PREFIX \ -DCMAKE_PREFIX_PATH=$CONDA_PREFIX \
-DCMAKE_INSTALL_PREFIX=install \ -DCMAKE_INSTALL_PREFIX=install \
-DSLS_USE_TEXTCLIENT=ON \ -DSLS_USE_TEXTCLIENT=ON \
@ -18,7 +18,7 @@ cmake .. \
-DSLS_USE_TESTS=ON \ -DSLS_USE_TESTS=ON \
-DSLS_USE_PYTHON=OFF \ -DSLS_USE_PYTHON=OFF \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
-DSLS_USE_HDF5=OFF\ -DSLS_USE_HDF5=OFF \
NCORES=$(getconf _NPROCESSORS_ONLN) NCORES=$(getconf _NPROCESSORS_ONLN)
echo "Building using: ${NCORES} cores" echo "Building using: ${NCORES} cores"

View File

@ -0,0 +1,13 @@
c_compiler:
- gcc # [linux]
c_stdlib:
- sysroot # [linux]
cxx_compiler:
- gxx # [linux]
c_stdlib_version: # [linux]
- 2.17 # [linux]

View File

@ -4,7 +4,6 @@
mkdir -p $PREFIX/lib mkdir -p $PREFIX/lib
mkdir -p $PREFIX/bin mkdir -p $PREFIX/bin
mkdir -p $PREFIX/include/sls mkdir -p $PREFIX/include/sls
# mkdir $PREFIX/include/slsDetectorPackage
#Shared and static libraries #Shared and static libraries
cp build/install/lib/* $PREFIX/lib/ cp build/install/lib/* $PREFIX/lib/
@ -15,8 +14,10 @@ cp build/install/bin/sls_detector_acquire_zmq $PREFIX/bin/.
cp build/install/bin/sls_detector_get $PREFIX/bin/. cp build/install/bin/sls_detector_get $PREFIX/bin/.
cp build/install/bin/sls_detector_put $PREFIX/bin/. cp build/install/bin/sls_detector_put $PREFIX/bin/.
cp build/install/bin/sls_detector_help $PREFIX/bin/. cp build/install/bin/sls_detector_help $PREFIX/bin/.
cp build/install/bin/sls_detector $PREFIX/bin/.
cp build/install/bin/slsReceiver $PREFIX/bin/. cp build/install/bin/slsReceiver $PREFIX/bin/.
cp build/install/bin/slsMultiReceiver $PREFIX/bin/. cp build/install/bin/slsMultiReceiver $PREFIX/bin/.
cp build/install/bin/slsFrameSynchronizer $PREFIX/bin/.
cp build/install/include/sls/* $PREFIX/include/sls cp build/install/include/sls/* $PREFIX/include/sls

View File

@ -0,0 +1,77 @@
source:
path: ../..
{% set version = load_file_regex(load_file = 'VERSION', regex_pattern = '(\d+(?:\.\d+)*(?:[\+\w\.]+))').group(1) %}
package:
name: sls_detector_software
version: {{ version }}
build:
number: 0
binary_relocation: True
rpaths:
- lib/
requirements:
build:
- {{ compiler('c') }}
- {{ stdlib("c") }}
- {{ compiler('cxx') }}
- git
- cmake
- ninja
- qt 5.*
host:
- libstdcxx-ng
- libgcc-ng
- libgl-devel # [linux]
- libtiff
- zlib
run:
- libstdcxx-ng
- libgcc-ng
outputs:
- name: slsdetlib
script: copy_lib.sh
requirements:
build:
- {{ compiler('c') }}
- {{ stdlib("c") }}
- {{ compiler('cxx') }}
run:
- libstdcxx-ng
- libgcc-ng
- name: slsdetgui
script: copy_gui.sh
requirements:
build:
- {{ compiler('c') }}
- {{compiler('cxx')}}
- {{ pin_subpackage('slsdetlib', exact=True) }}
run:
- {{ pin_subpackage('slsdetlib', exact=True) }}
- qt 5.*
- name: moenchzmq
script: copy_moench.sh
requirements:
build:
- {{ compiler('c') }}
- {{compiler('cxx')}}
- {{ pin_subpackage('slsdetlib', exact=True) }}
run:
- {{ pin_subpackage('slsdetlib', exact=True) }}

View File

@ -0,0 +1,16 @@
python:
- 3.11
- 3.12
- 3.13
c_compiler:
- gcc # [linux]
c_stdlib:
- sysroot # [linux]
cxx_compiler:
- gxx # [linux]
c_stdlib_version: # [linux]
- 2.17 # [linux]

View File

@ -0,0 +1,45 @@
source:
path: ../..
{% set version = load_file_regex(load_file = 'VERSION', regex_pattern = '(\d+(?:\.\d+)*(?:[\+\w\.]+))').group(1) %}
package:
name: slsdet
version: {{ version }}
build:
number: 0
script:
- unset CMAKE_GENERATOR && {{ PYTHON }} -m pip install . -vv # [not win]
requirements:
build:
- python {{python}}
- {{ compiler('c') }}
- {{ stdlib("c") }}
- {{ compiler('cxx') }}
host:
- cmake
- ninja
- python {{python}}
- pip
- scikit-build-core
- pybind11 >=2.13.0
- fmt
- zeromq
- nlohmann_json
- catch2
run:
- python {{python}}
- numpy
test:
imports:
- slsdet
about:
summary: An example project built with pybind11 and scikit-build.
# license_file: LICENSE

View File

@ -54,6 +54,7 @@ set(SPHINX_SOURCE_FILES
src/serverdefaults.rst src/serverdefaults.rst
src/quick_start_guide.rst src/quick_start_guide.rst
src/troubleshooting.rst src/troubleshooting.rst
src/pattern.rst
src/receivers.rst src/receivers.rst
src/slsreceiver.rst src/slsreceiver.rst
src/udpheader.rst src/udpheader.rst

View File

@ -359,6 +359,7 @@ Chip Test Board
"Digital Flag": 0, "Digital Flag": 0,
"Digital Samples": 1000, "Digital Samples": 1000,
"Dbit Offset": 0, "Dbit Offset": 0,
"Dbit Reorder": 1,
"Dbit Bitset": 0, "Dbit Bitset": 0,
"Transceiver Mask": "0x3", "Transceiver Mask": "0x3",
"Transceiver Flag": 0, "Transceiver Flag": 0,

View File

@ -37,6 +37,7 @@ Welcome to slsDetectorPackage's documentation!
pyenums pyenums
pyexamples pyexamples
pyPatternGenerator pyPatternGenerator
pattern
.. toctree:: .. toctree::
:caption: Command line :caption: Command line

View File

@ -345,6 +345,9 @@ Chip Test Board
+-----------------------+-------------------------------------------------+ +-----------------------+-------------------------------------------------+
| Dbit Offset | Digital offset of valid data in bytes | | Dbit Offset | Digital offset of valid data in bytes |
+-----------------------+-------------------------------------------------+ +-----------------------+-------------------------------------------------+
| Dbit Reorder | Reorder such that it groups each signal (0-63) |
| | from all the different samples together |
+-----------------------+-------------------------------------------------+
| Dbit Bitset | Digital 64 bit mask of bits enabled in receiver | | Dbit Bitset | Digital 64 bit mask of bits enabled in receiver |
+-----------------------+-------------------------------------------------+ +-----------------------+-------------------------------------------------+
| Transceiver Mask | Mask of channels enabled in Transceiver | | Transceiver Mask | Mask of channels enabled in Transceiver |

122
docs/src/pattern.rst Normal file
View File

@ -0,0 +1,122 @@
Pattern
========================
This is a test and development feature implemented only for Ctb, Xilinx_Ctb and Mythen3.
A pattern is a sequence of 64-bit words which is executed using a clock on the FPGA. Each of the 64 bits is connected to a pin or internal signal of the FPGA. The purpose of a pattern is to provide a way to change these 64 signals with precise timing. Commands run by the detector server could manipulate the same signals as the pattern, but they cannot enforce a change in a specific clock cycle.
**Usage**
A pattern is written to memory on the FPGA using the patword command.
.. code-block::
patword 0x0000 0x000000000000000A
patword 0x0001 0x000000000000000B
patword 0x0002 0x000000000000000C
patword 0x0003 0x000000000000000D
patword 0x0004 0x000000000000000E
The example above writes a five-word pattern into FPGA memory. The first argument is the memory address, the second argument is the content to be written into this address. Before executing a pattern one has to set the address limits of the pattern:
.. code-block::
patlimits 0x0000 0x0004
This instructs the firmware to execute the commands from address 0 to 4 (including 0 and 4). The execution can be started from the pyctbgui or with the commands
.. code-block::
start [Ctb, Xilinx_Ctb]
patternstart [Mythen3]
The maximal number of patword addresses is 8192. However, it is possible to extend the length of the pattern sequence using loops and wait commands. Loops can be configured with the following commands:
.. code-block::
patloop 0 0x0001 0x0003
patnloop 0 7
The first argument of both commands is the ID of the loop. Ctb and Xilinx_Ctb can have 6 loops (ID 0-5), Mythen3 can have 4 loop definitions. The commands above configure the loop with ID 0 to run 7 times and jump from the patword with address 3 to the patword with address 1. Important: If patnloop is set to 1, the addresses 0x1-0x3 will execute exactly once; if it is set to 0, the pattern addresses will be skipped.
The same idea is used to introduce wait times. The example below causes the patword at address 0x0002 to be active for 9 clock cycles before the execution continues.
.. code-block::
patwait 0 0x0002
patwaittime 0 9
Waits can be placed inside a loop and loops can be nested.
**patioctrl**
The function of each bit in the sequence of 64-bit words depends on the connected detector and firmware version. Some of the 64 bits might connect directly to pads of a chip. The patioctrl command is used to configure the direction of some of these signals (not all of them !! See tables below). Signals where the corresponding bit in the argument of patioctrl is set to 1 will be driven from the FPGA.
**patsetbit and patmask**
The functions patsetbit and patmask can be used to ignore a specific bit of the pattern.
Example:
.. code-block::
patmask 0x0101
patsetbit 0x0001
Patmask configures bit 0 and 8 of the pattern to be set to their value in patsetbit. These bits will be ignored during pattern execution and will always be 0 (bit 8) and 1 (bit 0).
The mappings of bit positions in the pattern word to signals/pads of the FPGA are listed below for the three detector types where patterns are used. In the case of the two CTB's, connections of the signals to actual pads of a chip depend on the layout of the used detector adapter board. Therefore, each type of detector adapter board adds an additional mapping layer.
**CTB Pattern Bit Mapping**
.. table::
+----+---+------+----+----------+-------------------+----------------+
| 63 | 62| 61-57| 56 | 55-48 | 47-32 | 31-0 |
+----+---+------+----+----------+-------------------+----------------+
| A | D| --- | T | EXTIO | DO, stream source | DIO |
+----+---+------+----+----------+-------------------+----------------+
DIO: Driving the 32 FPGA pins corresponding to the lowest 32 bits of the patioctrl command. If bits in patioctrl are 0, the same bit positions in DIO will switch to input pins and connect to dbit sampling. Additionally, some of these 32 bits have an automatic override by detector-specific statemachines which is active whenever one of these statemachines is running (currently bits 7,8,11,14 and 20).
DO: Directly connected to 16 FPGA pins. Output only. Not influenced by patioctrl. Also connected to bit 47-32 in all Ctb dbit samples. All of them can be used as dbit sample trigger. In addition, every bit of DO can be selected as trigger for sending out a udp packet with samples to the receiver.
EXTIO: Similar to DIO, but not used as input to the fpga. With the corresponding patioctrl bits set to 0 these pins will switch to a high impedance mode and be ignored by the firmware.
T: trigger output
D: enable signal for digital sampling
A: adc enable
**Xilinx_CTB Pattern Bit Mapping**
.. table::
+-------+----------------+
| 63-32 | 31-0 |
+-------+----------------+
| --- | DIO |
+-------+----------------+
DIO: Driving the 32 FPGA pins corresponding to the lowest 32 bits of the patioctrl command. If bits in patioctrl are 0, the same bit positions in DIO will switch to input pins and connect to dbit sampling. Additionally, some of these 32 bits have an automatic override by detector-specific statemachines which is active whenever these sm's are running (currently bits 7,8,11,14 and 20).
**Mythen3 Pattern Bit Mapping**
.. table::
+-------+--------+-------+--------+------------+----------+----------+-----+-----+
| 63-33 | 32 | 31-25 | 24 | 23 | 22 | 21 | 20 | 19 |
+-------+--------+-------+--------+------------+----------+----------+-----+-----+
| --- | signARD| --- | CHSclk | cnt_rst | sto_rst | STATLOAD | STO | SIN |
+-------+--------+-------+--------+------------+----------+----------+-----+-----+
.. table::
+---------+-----+-------+-------+----+-------+---------+--------+
| 18 | 17 | 16-14 | 13 | 12 | 11 | 10 | 9-0 |
+---------+-----+-------+-------+----+-------+---------+--------+
| SR_MODE | clk | EN | PULSE | RD | CHSIN | ANAMode | TBLOAD |
+---------+-----+-------+-------+----+-------+---------+--------+
For Mythen3 the pattern word only connects to output pins of the FPGA when the pattern is running. Afterwards the signals will switch back to other logic in the FPGA. Both CTB's hold the last executed pattern word until a new pattern is started.

View File

@ -0,0 +1,18 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dd3d8eb9..c0187747 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,8 @@
# CMake build script for ZeroMQ
project(ZeroMQ)
-if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
- cmake_minimum_required(VERSION 3.0.2)
-else()
- cmake_minimum_required(VERSION 2.8.12)
-endif()
+cmake_minimum_required(VERSION 3.15)
+message(STATUS "Patched cmake version")
include(CheckIncludeFiles)
include(CheckCCompilerFlag)

View File

@ -12,5 +12,6 @@ slsDetectorPackage/8.0.1_rh8 stable cmake/3.15.5 Qt/5.12.10
slsDetectorPackage/8.0.2_rh7 stable cmake/3.15.5 Qt/5.12.10 slsDetectorPackage/8.0.2_rh7 stable cmake/3.15.5 Qt/5.12.10
slsDetectorPackage/8.0.2_rh8 stable cmake/3.15.5 Qt/5.12.10 slsDetectorPackage/8.0.2_rh8 stable cmake/3.15.5 Qt/5.12.10
slsDetectorPackage/9.0.0_rh8 stable cmake/3.15.5 Qt/5.12.10 slsDetectorPackage/9.0.0_rh8 stable cmake/3.15.5 Qt/5.12.10
slsDetectorPackage/9.1.0_rh8 stable cmake/3.15.5 Qt/5.12.10

View File

@ -22,6 +22,7 @@ class SignalsTab(QtWidgets.QWidget):
self.plotTab = None self.plotTab = None
self.legend: LegendItem | None = None self.legend: LegendItem | None = None
self.rx_dbitoffset = None self.rx_dbitoffset = None
self.rx_dbitreorder = None
self.rx_dbitlist = None self.rx_dbitlist = None
def refresh(self): def refresh(self):
@ -29,6 +30,7 @@ class SignalsTab(QtWidgets.QWidget):
self.updateDigitalBitEnable() self.updateDigitalBitEnable()
self.updateIOOut() self.updateIOOut()
self.getDBitOffset() self.getDBitOffset()
self.getDBitReorder()
def connect_ui(self): def connect_ui(self):
for i in range(Defines.signals.count): for i in range(Defines.signals.count):
@ -49,6 +51,7 @@ class SignalsTab(QtWidgets.QWidget):
partial(self.setIOOutRange, Defines.signals.half, Defines.signals.count)) partial(self.setIOOutRange, Defines.signals.half, Defines.signals.count))
self.view.lineEditPatIOCtrl.editingFinished.connect(self.setIOOutReg) self.view.lineEditPatIOCtrl.editingFinished.connect(self.setIOOutReg)
self.view.spinBoxDBitOffset.editingFinished.connect(self.setDbitOffset) self.view.spinBoxDBitOffset.editingFinished.connect(self.setDbitOffset)
self.view.checkBoxDBitReorder.stateChanged.connect(self.setDbitReorder)
def setup_ui(self): def setup_ui(self):
self.plotTab = self.mainWindow.plotTab self.plotTab = self.mainWindow.plotTab
@ -87,60 +90,79 @@ class SignalsTab(QtWidgets.QWidget):
self.legend.addItem(plot, name) self.legend.addItem(plot, name)
@recordOrApplyPedestal @recordOrApplyPedestal
def _processWaveformData(self, data, aSamples, dSamples, rx_dbitlist, isPlottedArray, rx_dbitoffset, romode, def _processWaveformData(self, data, aSamples, dSamples, rx_dbitreorder, rx_dbitlist, isPlottedArray, romode,
nADCEnabled): nADCEnabled):
"""
transform raw waveform data into a processed numpy array #transform raw waveform data into a processed numpy array
@param data: raw waveform data #@param data: raw waveform data
"""
dbitoffset = rx_dbitoffset start_digital_data = 0
if romode == 2: if romode == 2:
dbitoffset += nADCEnabled * 2 * aSamples start_digital_data += nADCEnabled * 2 * aSamples
digital_array = np.array(np.frombuffer(data, offset=dbitoffset, dtype=np.uint8)) digital_array = np.array(np.frombuffer(data, offset=start_digital_data, dtype=np.uint8))
nbitsPerDBit = dSamples if rx_dbitreorder:
if nbitsPerDBit % 8 != 0: samples_per_bit = np.empty((len(rx_dbitlist), dSamples), dtype=np.uint8) #stored per row all the corresponding signals of all samples
nbitsPerDBit += (8 - (dSamples % 8)) nbitsPerDBit = dSamples
offset = 0 if nbitsPerDBit % 8 != 0:
arr = [] nbitsPerDBit += (8 - (dSamples % 8))
for i in rx_dbitlist: bit_index = 0
# where numbits * numsamples is not a multiple of 8 for idx, i in enumerate(rx_dbitlist):
if offset % 8 != 0: # where numbits * numsamples is not a multiple of 8
offset += (8 - (offset % 8)) if bit_index % 8 != 0:
if not isPlottedArray[i]: bit_index += (8 - (bit_index % 8))
offset += nbitsPerDBit if not isPlottedArray[i]:
return None bit_index += nbitsPerDBit
waveform = np.zeros(dSamples) samples_per_bit[idx, :] = np.nan
for iSample in range(dSamples): continue
# all samples for digital bit together from slsReceiver for iSample in range(dSamples):
index = int(offset / 8) # all samples for digital bit together from slsReceiver
iBit = offset % 8 index = int(bit_index / 8)
bit = (digital_array[index] >> iBit) & 1 iBit = bit_index % 8
waveform[iSample] = bit bit = (digital_array[index] >> iBit) & 1
offset += 1 samples_per_bit[idx,iSample] = bit
arr.append(waveform) bit_index += 1
return samples_per_bit
else:
nbitsPerSample = len(rx_dbitlist) if len(rx_dbitlist) % 8 == 0 else len(rx_dbitlist) + (8 - (len(rx_dbitlist) % 8))
bits_per_sample = np.empty((dSamples, len(rx_dbitlist)), dtype=np.uint8) #store per row all selected bits of a sample
for iSample in range(dSamples):
bit_index = nbitsPerSample * iSample
for idx, i in enumerate(rx_dbitlist):
if not isPlottedArray[i]:
bit_index += 1
bits_per_sample[iSample, idx] = np.nan
return np.array(arr) index = int(bit_index/8)
iBit = idx % 8
bit = (digital_array[index] >> iBit) & 1
bits_per_sample[iSample, idx] = bit
bit_index += 1
return bits_per_sample.T.copy()
def processWaveformData(self, data, aSamples, dSamples): def processWaveformData(self, data, aSamples, dSamples):
"""
view function #view function
plots processed waveform data #plots processed waveform data
data: raw waveform data #data: raw waveform data
dsamples: digital samples #dsamples: digital samples
asamples: analog samples #asamples: analog samples
"""
self.refresh()
waveforms = {} waveforms = {}
isPlottedArray = {i: getattr(self.view, f"checkBoxBIT{i}Plot").isChecked() for i in self.rx_dbitlist} isPlottedArray = {i: getattr(self.view, f"checkBoxBIT{i}Plot").isChecked() for i in self.rx_dbitlist}
digital_array = self._processWaveformData(data, aSamples, dSamples, self.rx_dbitlist, isPlottedArray, digital_array = self._processWaveformData(data, aSamples, dSamples, self.rx_dbitreorder, self.rx_dbitlist, isPlottedArray,
self.rx_dbitoffset, self.mainWindow.romode.value, self.mainWindow.romode.value,
self.mainWindow.nADCEnabled) self.mainWindow.nADCEnabled)
irow = 0 irow = 0
for idx, i in enumerate(self.rx_dbitlist): for idx, i in enumerate(self.rx_dbitlist):
# bits enabled but not plotting # bits enabled but not plotting
waveform = digital_array[idx] waveform = digital_array[idx, :]
if waveform is None: if np.isnan(waveform[0]):
continue continue
self.mainWindow.digitalPlots[i].setData(waveform) self.mainWindow.digitalPlots[i].setData(waveform)
plotName = getattr(self.view, f"labelBIT{i}").text() plotName = getattr(self.view, f"labelBIT{i}").text()
@ -151,8 +173,10 @@ class SignalsTab(QtWidgets.QWidget):
irow += 1 irow += 1
else: else:
self.mainWindow.digitalPlots[i].setY(0) self.mainWindow.digitalPlots[i].setY(0)
return waveforms return waveforms
def initializeAllDigitalPlots(self): def initializeAllDigitalPlots(self):
self.mainWindow.plotDigitalWaveform = pg.plot() self.mainWindow.plotDigitalWaveform = pg.plot()
self.mainWindow.plotDigitalWaveform.addLegend(colCount=Defines.colCount) self.mainWindow.plotDigitalWaveform.addLegend(colCount=Defines.colCount)
@ -360,14 +384,25 @@ class SignalsTab(QtWidgets.QWidget):
self.view.spinBoxDBitOffset.setValue(self.rx_dbitoffset) self.view.spinBoxDBitOffset.setValue(self.rx_dbitoffset)
self.view.spinBoxDBitOffset.editingFinished.connect(self.setDbitOffset) self.view.spinBoxDBitOffset.editingFinished.connect(self.setDbitOffset)
def getDBitReorder(self):
self.view.checkBoxDBitReorder.stateChanged.disconnect()
self.rx_dbitreorder = self.det.rx_dbitreorder
self.view.checkBoxDBitReorder.setChecked(self.rx_dbitreorder)
self.view.checkBoxDBitReorder.stateChanged.connect(self.setDbitReorder)
def setDbitOffset(self): def setDbitOffset(self):
self.det.rx_dbitoffset = self.view.spinBoxDBitOffset.value() self.det.rx_dbitoffset = self.view.spinBoxDBitOffset.value()
def setDbitReorder(self):
self.det.rx_dbitreorder = self.view.checkBoxDBitReorder.isChecked()
def saveParameters(self) -> list: def saveParameters(self) -> list:
commands = [] commands = []
dblist = [str(i) for i in range(Defines.signals.count) if getattr(self.view, f"checkBoxBIT{i}DB").isChecked()] dblist = [str(i) for i in range(Defines.signals.count) if getattr(self.view, f"checkBoxBIT{i}DB").isChecked()]
if len(dblist) > 0: if len(dblist) > 0:
commands.append(f"rx_dbitlist {', '.join(dblist)}") commands.append(f"rx_dbitlist {', '.join(dblist)}")
commands.append(f"rx_dbitoffset {self.view.spinBoxDBitOffset.value()}") commands.append(f"rx_dbitoffset {self.view.spinBoxDBitOffset.value()}")
commands.append(f"rx_dbitreorder {self.view.checkBoxDBitReorder.isChecked()}")
commands.append(f"patioctrl {self.view.lineEditPatIOCtrl.text()}") commands.append(f"patioctrl {self.view.lineEditPatIOCtrl.text()}")
return commands return commands

View File

@ -6074,6 +6074,33 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QGridLayout" name="gridLayout_17"> <layout class="QGridLayout" name="gridLayout_17">
<item row="0" column="4">
<widget class="QSpinBox" name="spinBoxDBitOffset">
<property name="minimumSize">
<size>
<width>150</width>
<height>32</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>32</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="3"> <item row="0" column="3">
<widget class="QLabel" name="label_66"> <widget class="QLabel" name="label_66">
<property name="font"> <property name="font">
@ -6086,6 +6113,36 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="6">
<widget class="QCheckBox" name="checkBoxDBitReorder">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>DBit Reorder</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_48">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>IO Control Register:</string>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="lineEditPatIOCtrl"> <widget class="QLineEdit" name="lineEditPatIOCtrl">
<property name="sizePolicy"> <property name="sizePolicy">
@ -6133,50 +6190,18 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="4"> <item row="0" column="5">
<widget class="QSpinBox" name="spinBoxDBitOffset"> <spacer name="horizontalSpacer_22">
<property name="minimumSize"> <property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size> <size>
<width>150</width> <width>40</width>
<height>32</height> <height>20</height>
</size> </size>
</property> </property>
<property name="maximumSize"> </spacer>
<size>
<width>150</width>
<height>32</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_48">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>IO Control Register:</string>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>

33
pyproject.toml Normal file
View File

@ -0,0 +1,33 @@
[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "VERSION"
regex = '^(?P<version>\d+(?:\.\d+)*(?:[\.\+\w]+)?)$'
result = "{version}"
[build-system]
requires = [ "scikit-build-core>=0.10", "pybind11", "numpy",]
build-backend = "scikit_build_core.build"
[project]
name = "slsdet"
dynamic = ["version"]
[tool.cibuildwheel]
before-all = "uname -a"
[tool.scikit-build.build]
verbose = true
[tool.scikit-build.cmake]
build-type = "Release"
[tool.scikit-build.install]
components = [ "python",]
[tool.scikit-build.cmake.define]
SLS_USE_RECEIVER = "OFF"
SLS_USE_RECEIVER_BINARIES = "OFF"
SLS_USE_TEXTCLIENT = "OFF"
SLS_BUILD_SHARED_LIBRARIES = "OFF"
SLS_USE_PYTHON = "ON"
SLS_INSTALL_PYTHONEXT = "ON"

View File

@ -20,7 +20,7 @@ target_link_libraries(_slsdet PUBLIC
set_target_properties(_slsdet PROPERTIES set_target_properties(_slsdet PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/slsdet
) )
#Copy Python code #Copy Python code
@ -72,9 +72,18 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/../VERSION
if(SLS_INSTALL_PYTHONEXT) if(SLS_INSTALL_PYTHONEXT)
install(TARGETS _slsdet install(TARGETS _slsdet
EXPORT "${TARGETS_EXPORT_NAME}" EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/python LIBRARY DESTINATION slsdet
COMPONENT python
) )
install(
FILES ${PYTHON_FILES}
DESTINATION slsdet
COMPONENT python
)
install(
FILES ../VERSION
DESTINATION slsdet
COMPONENT python
)
install(FILES ${PYTHON_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/python/slsdet)
install(FILES ../VERSION DESTINATION ${CMAKE_INSTALL_PREFIX}/python/slsdet)
endif() endif()

View File

@ -1,77 +0,0 @@
# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package
"""
Setup file for slsdet
Build upon the pybind11 example found here: https://github.com/pybind/python_example
"""
import os
import sys
from setuptools import setup, find_packages
from pybind11.setup_helpers import Pybind11Extension, build_ext
def read_version():
try:
version_file = os.path.join(os.path.dirname(__file__), 'slsdet', 'VERSION')
with open(version_file, "r") as f:
return f.read().strip()
except:
raise RuntimeError("VERSION file not found in slsdet package from setup.py.")
__version__ = read_version()
def get_conda_path():
"""
Keep this a function if we need some fancier logic later
"""
print('Prefix: ', os.environ['CONDA_PREFIX'])
return os.environ['CONDA_PREFIX']
#TODO migrate to CMake build or fetch files from cmake?
ext_modules = [
Pybind11Extension(
'_slsdet',
['src/main.cpp',
'src/enums.cpp',
'src/current.cpp',
'src/detector.cpp',
'src/network.cpp',
'src/pattern.cpp',
'src/scan.cpp',
'src/duration.cpp',
'src/DurationWrapper.cpp',
'src/pedestal.cpp',
]
,
include_dirs=[
os.path.join(get_conda_path(), 'include'),
],
libraries=['SlsDetector', 'SlsSupport', 'SlsReceiver'],
library_dirs=[
os.path.join(get_conda_path(), 'lib'),
],
language='c++'
),
]
setup(
name='slsdet',
version=__version__,
author='Erik Frojdh',
author_email='erik.frojdh@psi.ch',
url='https://github.com/slsdetectorgroup/slsDetectorPackage',
description='Detector API for SLS Detector Group detectors',
long_description='',
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
package_data={
'slsdet': ['VERSION'],
},
ext_modules=ext_modules,
cmdclass={"build_ext": build_ext},
zip_safe=False,
)

View File

@ -14,7 +14,7 @@ from .pattern import Pattern, patternParameters
from .gaincaps import Mythen3GainCapsWrapper from .gaincaps import Mythen3GainCapsWrapper
from .PatternGenerator import PatternGenerator from .PatternGenerator import PatternGenerator
import _slsdet from . import _slsdet
xy = _slsdet.xy xy = _slsdet.xy
defs = _slsdet.slsDetectorDefs defs = _slsdet.slsDetectorDefs
@ -41,3 +41,6 @@ def read_version():
__version__ = read_version() __version__ = read_version()

View File

@ -4,7 +4,7 @@ from .detector import Detector, freeze
from .utils import element_if_equal from .utils import element_if_equal
from .dacs import DetectorDacs, NamedDacs from .dacs import DetectorDacs, NamedDacs
from .powers import DetectorPowers, NamedPowers from .powers import DetectorPowers, NamedPowers
import _slsdet from . import _slsdet
dacIndex = _slsdet.slsDetectorDefs.dacIndex dacIndex = _slsdet.slsDetectorDefs.dacIndex
from .detector_property import DetectorProperty from .detector_property import DetectorProperty

View File

@ -3,7 +3,7 @@
from .detector_property import DetectorProperty from .detector_property import DetectorProperty
from functools import partial from functools import partial
import numpy as np import numpy as np
import _slsdet from . import _slsdet
from .detector import freeze from .detector import freeze
dacIndex = _slsdet.slsDetectorDefs.dacIndex dacIndex = _slsdet.slsDetectorDefs.dacIndex
class Dac(DetectorProperty): class Dac(DetectorProperty):

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: LGPL-3.0-or-other # SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package # Copyright (C) 2021 Contributors to the SLS Detector Package
from _slsdet import CppDetectorApi from ._slsdet import CppDetectorApi
from _slsdet import slsDetectorDefs from ._slsdet import slsDetectorDefs
from _slsdet import IpAddr, MacAddr from ._slsdet import IpAddr, MacAddr
runStatus = slsDetectorDefs.runStatus runStatus = slsDetectorDefs.runStatus
timingMode = slsDetectorDefs.timingMode timingMode = slsDetectorDefs.timingMode
@ -15,7 +15,7 @@ defs = slsDetectorDefs
from .utils import element_if_equal, all_equal, get_set_bits, list_to_bitmask 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 .utils import Geometry, to_geo, element, reduce_time, is_iterable, hostname_list
from _slsdet import xy from ._slsdet import xy
from .gaincaps import Mythen3GainCapsWrapper from .gaincaps import Mythen3GainCapsWrapper
from . import utils as ut from . import utils as ut
from .proxy import JsonProxy, SlowAdcProxy, ClkDivProxy, MaxPhaseProxy, ClkFreqProxy, PatLoopProxy, PatNLoopProxy, PatWaitProxy, PatWaitTimeProxy from .proxy import JsonProxy, SlowAdcProxy, ClkDivProxy, MaxPhaseProxy, ClkFreqProxy, PatLoopProxy, PatNLoopProxy, PatWaitProxy, PatWaitTimeProxy
@ -3463,6 +3463,16 @@ class Detector(CppDetectorApi):
def rx_dbitoffset(self, value): def rx_dbitoffset(self, value):
ut.set_using_dict(self.setRxDbitOffset, value) ut.set_using_dict(self.setRxDbitOffset, value)
@property
@element
def rx_dbitreorder(self):
"""[Ctb] Reorder digital data to group together all samples per signal. Default is 1. Setting to 0 means 'do not reorder' and to keep what the board spits out, which is that all signals in a sample are grouped together."""
return self.getRxDbitReorder()
@rx_dbitreorder.setter
def rx_dbitreorder(self, value):
ut.set_using_dict(self.setRxDbitReorder, value)
@property @property
@element @element
def maxadcphaseshift(self): def maxadcphaseshift(self):

View File

@ -11,7 +11,7 @@ Created on Wed Dec 6 11:51:18 2017
from .detector import Detector from .detector import Detector
from .temperature import Temperature, DetectorTemperature from .temperature import Temperature, DetectorTemperature
from .dacs import DetectorDacs from .dacs import DetectorDacs
import _slsdet from . import _slsdet
dacIndex = _slsdet.slsDetectorDefs.dacIndex dacIndex = _slsdet.slsDetectorDefs.dacIndex
from .detector_property import DetectorProperty from .detector_property import DetectorProperty

View File

@ -15,8 +15,8 @@ if dt === detectorType.EIGER:
""" """
import _slsdet from . import _slsdet
for name, cls in _slsdet.slsDetectorDefs.__dict__.items(): for name, cls in _slsdet.slsDetectorDefs.__dict__.items():
if isinstance(cls, type): if isinstance(cls, type):
exec(f'{name} = {cls.__module__}.{cls.__qualname__}') exec(f'{name} = _slsdet.{cls.__qualname__}')

View File

@ -1,6 +1,6 @@
import _slsdet from . import _slsdet
gc = _slsdet.slsDetectorDefs.M3_GainCaps gc = _slsdet.slsDetectorDefs.M3_GainCaps

View File

@ -11,7 +11,7 @@ from .detector import Detector, freeze
# from .adcs import Adc, DetectorAdcs # from .adcs import Adc, DetectorAdcs
from .dacs import DetectorDacs from .dacs import DetectorDacs
import _slsdet from . import _slsdet
dacIndex = _slsdet.slsDetectorDefs.dacIndex dacIndex = _slsdet.slsDetectorDefs.dacIndex
from .detector_property import DetectorProperty from .detector_property import DetectorProperty

View File

@ -11,7 +11,7 @@ from .detector import Detector, freeze
# from .adcs import Adc, DetectorAdcs # from .adcs import Adc, DetectorAdcs
from .dacs import DetectorDacs from .dacs import DetectorDacs
import _slsdet from . import _slsdet
dacIndex = _slsdet.slsDetectorDefs.dacIndex dacIndex = _slsdet.slsDetectorDefs.dacIndex
from .detector_property import DetectorProperty from .detector_property import DetectorProperty

View File

@ -9,7 +9,7 @@ This file contains the specialization for the Moench detector
from .detector import Detector, freeze from .detector import Detector, freeze
from .dacs import DetectorDacs from .dacs import DetectorDacs
import _slsdet from . import _slsdet
dacIndex = _slsdet.slsDetectorDefs.dacIndex dacIndex = _slsdet.slsDetectorDefs.dacIndex
from .detector_property import DetectorProperty from .detector_property import DetectorProperty

View File

@ -11,7 +11,7 @@ from .detector import Detector, freeze
# from .adcs import Adc, DetectorAdcs # from .adcs import Adc, DetectorAdcs
from .dacs import DetectorDacs from .dacs import DetectorDacs
import _slsdet from . import _slsdet
dacIndex = _slsdet.slsDetectorDefs.dacIndex dacIndex = _slsdet.slsDetectorDefs.dacIndex
gc_enums = _slsdet.slsDetectorDefs.M3_GainCaps gc_enums = _slsdet.slsDetectorDefs.M3_GainCaps
from .detector_property import DetectorProperty from .detector_property import DetectorProperty

View File

@ -1,8 +1,8 @@
# SPDX-License-Identifier: LGPL-3.0-or-other # SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package # Copyright (C) 2021 Contributors to the SLS Detector Package
import _slsdet from . import _slsdet
from _slsdet import Pattern from ._slsdet import Pattern
class patternParameters(_slsdet.patternParameters): class patternParameters(_slsdet.patternParameters):

View File

@ -3,7 +3,7 @@
from .detector_property import DetectorProperty from .detector_property import DetectorProperty
from functools import partial from functools import partial
import numpy as np import numpy as np
import _slsdet from . import _slsdet
from .detector import freeze from .detector import freeze
dacIndex = _slsdet.slsDetectorDefs.dacIndex dacIndex = _slsdet.slsDetectorDefs.dacIndex
class Power(DetectorProperty): class Power(DetectorProperty):

View File

@ -3,7 +3,7 @@
from .utils import element_if_equal from .utils import element_if_equal
from .enums import dacIndex from .enums import dacIndex
from .defines import M3_MAX_PATTERN_LEVELS, MAX_PATTERN_LEVELS from .defines import M3_MAX_PATTERN_LEVELS, MAX_PATTERN_LEVELS
from _slsdet import slsDetectorDefs from ._slsdet import slsDetectorDefs
detectorType = slsDetectorDefs.detectorType detectorType = slsDetectorDefs.detectorType

View File

@ -6,7 +6,7 @@ but not directly used in controlling the detector
""" """
from collections import namedtuple from collections import namedtuple
import _slsdet #C++ lib from . import _slsdet #C++ lib
import functools import functools
import datetime as dt import datetime as dt
import pathlib import pathlib

View File

@ -1664,6 +1664,14 @@ void init_det(py::module &m) {
(void (Detector::*)(int, sls::Positions)) & (void (Detector::*)(int, sls::Positions)) &
Detector::setRxDbitOffset, Detector::setRxDbitOffset,
py::arg(), py::arg() = Positions{}); py::arg(), py::arg() = Positions{});
CppDetectorApi.def("getRxDbitReorder",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getRxDbitReorder,
py::arg() = Positions{});
CppDetectorApi.def("setRxDbitReorder",
(void (Detector::*)(bool, sls::Positions)) &
Detector::setRxDbitReorder,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def("setDigitalIODelay", CppDetectorApi.def("setDigitalIODelay",
(void (Detector::*)(uint64_t, int, sls::Positions)) & (void (Detector::*)(uint64_t, int, sls::Positions)) &
Detector::setDigitalIODelay, Detector::setDigitalIODelay,

View File

@ -1,3 +1,4 @@
#include <chrono>
#include "py_headers.h" #include "py_headers.h"
#include "DurationWrapper.h" #include "DurationWrapper.h"
@ -19,4 +20,25 @@ void init_duration(py::module &m) {
<< " count: " << self.count() << ")"; << " count: " << self.count() << ")";
return ss.str(); return ss.str();
}); });
m.def(
"test_return_DurationWrapper",
[]() {
DurationWrapper t(1.3);
return t;
},
R"(
Test function to return a DurationWrapper object. Ensures that the automatic conversion in typecaster.h works.
)");
m.def(
"test_duration_to_ns",
[](const std::chrono::nanoseconds t) {
//Duration wrapper is used to be able to convert from time in python to chrono::nanoseconds
//return count to have something to test
return t.count();
},
R"(
Test function convert DurationWrapper or number to chrono::ns. Ensures that the automatic conversion in typecaster.h works.
)"); // default value to test the default constructor
} }

View File

@ -54,11 +54,16 @@ template <> struct type_caster<std::chrono::nanoseconds> {
value = duration_cast<nanoseconds>(duration<double>(PyFloat_AsDouble(src.ptr()))); value = duration_cast<nanoseconds>(duration<double>(PyFloat_AsDouble(src.ptr())));
return true; return true;
} }
// If invoked with an int we assume it is nanoseconds and convert, same as in chrono.h
if (PyLong_Check(src.ptr())) {
value = duration_cast<nanoseconds>(duration<int64_t>(PyLong_AsLongLong(src.ptr())));
return true;
}
// Lastly if we were actually called with a DurationWrapper object we get // Lastly if we were actually called with a DurationWrapper object we get
// the number of nanoseconds and create a std::chrono::nanoseconds from it // the number of nanoseconds and create a std::chrono::nanoseconds from it
py::object py_cls = py::module::import("_slsdet").attr("DurationWrapper"); py::object py_cls = py::module::import("slsdet._slsdet").attr("DurationWrapper");
if (py::isinstance(src, py_cls)){ if (py::isinstance(src, py_cls)){
sls::DurationWrapper *cls = src.cast<sls::DurationWrapper *>(); sls::DurationWrapper *cls = src.cast<sls::DurationWrapper *>();
value = nanoseconds(cls->count()); value = nanoseconds(cls->count());
@ -77,7 +82,7 @@ template <> struct type_caster<std::chrono::nanoseconds> {
* set the count from chrono::nanoseconds and return * set the count from chrono::nanoseconds and return
*/ */
static handle cast(std::chrono::nanoseconds src, return_value_policy /* policy */, handle /* parent */) { static handle cast(std::chrono::nanoseconds src, return_value_policy /* policy */, handle /* parent */) {
py::object py_cls = py::module::import("_slsdet").attr("DurationWrapper"); py::object py_cls = py::module::import("slsdet._slsdet").attr("DurationWrapper");
py::object* obj = new py::object; py::object* obj = new py::object;
*obj = py_cls(); *obj = py_cls();
sls::DurationWrapper *dur = obj->cast<sls::DurationWrapper *>(); sls::DurationWrapper *dur = obj->cast<sls::DurationWrapper *>();

View File

@ -0,0 +1,58 @@
import pytest
from slsdet import DurationWrapper
#import the compiled extension to use test functions for the automatic conversion
from slsdet import _slsdet
def test_default_construction_of_DurationWrapper():
"""Test default construction of DurationWrapper"""
t = DurationWrapper()
assert t.count() == 0
assert t.total_seconds() == 0
def test_construction_of_DurationWrapper():
"""Test construction of DurationWrapper with total_seconds"""
t = DurationWrapper(5)
assert t.count() == 5e9
assert t.total_seconds() == 5
def test_set_count_on_DurationWrapper():
"""Test set_count on DurationWrapper"""
t = DurationWrapper()
t.set_count(10)
assert t.count() == 10
assert t.total_seconds() == 10e-9
t.set_count(0)
assert t.count() == 0
assert t.total_seconds() == 0
def test_return_a_DurationWrapper_from_cpp():
"""Test returning a DurationWrapper from C++"""
t = _slsdet.test_return_DurationWrapper()
assert t.count() == 1.3e9
assert t.total_seconds() == 1.3
def test_call_a_cpp_function_with_a_duration_wrapper():
"""C++ functions can accept a DurationWrapper"""
t = DurationWrapper(5)
assert _slsdet.test_duration_to_ns(t) == 5e9
def test_call_a_cpp_function_converting_number_to_DurationWrapper():
"""int and float can be converted to std::chrono::nanoseconds"""
assert _slsdet.test_duration_to_ns(0) == 0
assert _slsdet.test_duration_to_ns(3) == 3e9
assert _slsdet.test_duration_to_ns(1.3) == 1.3e9
assert _slsdet.test_duration_to_ns(10e-9) == 10
def test_call_a_cpp_function_with_datetime_timedelta():
"""datetime.timedelta can be converted to std::chrono::nanoseconds"""
import datetime
t = datetime.timedelta(seconds=5)
assert _slsdet.test_duration_to_ns(t) == 5e9
t = datetime.timedelta(seconds=0)
assert _slsdet.test_duration_to_ns(t) == 0
t = datetime.timedelta(seconds=1.3)
assert _slsdet.test_duration_to_ns(t) == 1.3e9

View File

@ -15,6 +15,7 @@
#include "loadPattern.h" #include "loadPattern.h"
#include <netinet/in.h> #include <netinet/in.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> // usleep #include <unistd.h> // usleep
#ifdef VIRTUAL #ifdef VIRTUAL
@ -2258,11 +2259,23 @@ void *start_timer(void *arg) {
int packetsPerFrame = ceil((double)imageSize / (double)dataSize); int packetsPerFrame = ceil((double)imageSize / (double)dataSize);
// Generate Data // Generate Data
char imageData[imageSize]; char *imageData = (char *)malloc(imageSize);
memset(imageData, 0, imageSize); memset(imageData, 0, imageSize);
if (imageData == NULL) {
LOG(logERROR, ("Can not allocate image Data RAM."
"Probable cause: Memory Leak.\n"));
return NULL;
}
/*
for (int i = 0; i < imageSize; i += sizeof(uint16_t)) { for (int i = 0; i < imageSize; i += sizeof(uint16_t)) {
*((uint16_t *)(imageData + i)) = i; *((uint16_t *)(imageData + i)) = i;
} }
*/
for (int i = 0; i < imageSize; i += 2 * sizeof(uint64_t)) {
*((uint64_t *)(imageData + i)) = 0xffffffffffffffff;
}
// Send data // Send data
uint64_t frameNr = 0; uint64_t frameNr = 0;
@ -2319,6 +2332,8 @@ void *start_timer(void *arg) {
setNextFrameNumber(frameNr + numFrames); setNextFrameNumber(frameNr + numFrames);
} }
free(imageData);
closeUDPSocket(0); closeUDPSocket(0);
sharedMemory_setStatus(IDLE); sharedMemory_setStatus(IDLE);

View File

@ -304,7 +304,7 @@ patternParameters *setChannelRegisterChip(int ichip, char *mask,
chanReg |= (0x1 << (3 + icounter)); chanReg |= (0x1 << (3 + icounter));
} }
} }
chanReg /= 2;
// deserialize // deserialize
if (chanReg & CHAN_REG_BAD_CHANNEL_MSK) { if (chanReg & CHAN_REG_BAD_CHANNEL_MSK) {
LOG(logINFOBLUE, LOG(logINFOBLUE,

View File

@ -80,7 +80,7 @@ _sd() {
local IS_PATH=0 local IS_PATH=0
local SLS_COMMANDS=" acquire activate adcclk adcenable adcenable10g adcindex adcinvert adclist adcname adcphase adcpipeline adcreg adcvpp apulse asamples autocompdisable badchannels blockingtrigger burstmode burstperiod bursts burstsl bustest cdsgain chipversion clearbit clearbusy clientversion clkdiv clkfreq clkphase collectionmode column compdisabletime confadc config configtransceiver counters currentsource dac dacindex daclist dacname dacvalues datastream dbitclk dbitphase dbitpipeline defaultdac defaultpattern delay delayl detectorserverversion detsize diodelay dpulse dr drlist dsamples execcommand exptime exptime1 exptime2 exptime3 extrastoragecells extsampling extsamplingsrc extsig fformat filtercells filterresistor findex firmwaretest firmwareversion fliprows flowcontrol10g fmaster fname foverwrite fpath framecounter frames framesl frametime free fwrite gaincaps gainmode gappixels gatedelay gatedelay1 gatedelay2 gatedelay3 gates getbit hardwareversion highvoltage hostname im_a im_b im_c im_d im_io imagetest initialchecks inj_ch interpolation interruptsubframe kernelversion lastclient led lock master maxadcphaseshift maxclkphaseshift maxdbitphaseshift measuredperiod measuredsubperiod moduleid nextframenumber nmod numinterfaces overflow packageversion parallel parameters partialreset patfname patioctrl patlimits patloop patloop0 patloop1 patloop2 patmask patnloop patnloop0 patnloop1 patnloop2 patsetbit pattern patternstart patwait patwait0 patwait1 patwait2 patwaittime patwaittime0 patwaittime1 patwaittime2 patword pedestalmode period periodl polarity port powerchip powerindex powerlist powername powervalues programfpga pulse pulsechip pulsenmove pumpprobe quad ratecorr readnrows readout readoutspeed readoutspeedlist rebootcontroller reg resetdacs resetfpga romode row runclk runtime rx_arping rx_clearroi rx_dbitlist rx_dbitoffset rx_discardpolicy rx_fifodepth rx_frameindex rx_framescaught rx_framesperfile rx_hostname rx_jsonaddheader rx_jsonpara rx_lastclient rx_lock rx_missingpackets rx_padding rx_printconfig rx_realudpsocksize rx_roi rx_silent rx_start rx_status rx_stop rx_tcpport rx_threads rx_udpsocksize rx_version rx_zmqfreq rx_zmqhwm rx_zmqip rx_zmqport rx_zmqstartfnum rx_zmqstream samples savepattern scan scanerrmsg selinterface serialnumber setbit settings settingslist settingspath signalindex signallist signalname sleep slowadc slowadcindex slowadclist slowadcname slowadcvalues start status stop stopport storagecell_delay storagecell_start subdeadtime subexptime sync syncclk temp_10ge temp_adc temp_control temp_dcdc temp_event temp_fpga temp_fpgaext temp_fpgafl temp_fpgafr temp_slowadc temp_sodl temp_sodr temp_threshold templist tempvalues tengiga threshold thresholdnotb timing timing_info_decoder timinglist timingsource top transceiverenable trigger triggers triggersl trimbits trimen trimval tsamples txdelay txdelay_frame txdelay_left txdelay_right type udp_cleardst udp_dstip udp_dstip2 udp_dstlist udp_dstmac udp_dstmac2 udp_dstport udp_dstport2 udp_firstdst udp_numdst udp_reconfigure udp_srcip udp_srcip2 udp_srcmac udp_srcmac2 udp_validate update updatedetectorserver updatekernel updatemode user v_a v_b v_c v_chip v_d v_io v_limit vchip_comp_adc vchip_comp_fe vchip_cs vchip_opa_1st vchip_opa_fd vchip_ref_comp_fe versions veto vetoalg vetofile vetophoton vetoref vetostream virtual vm_a vm_b vm_c vm_d vm_io zmqhwm zmqip zmqport " local SLS_COMMANDS=" acquire activate adcclk adcenable adcenable10g adcindex adcinvert adclist adcname adcphase adcpipeline adcreg adcvpp apulse asamples autocompdisable badchannels blockingtrigger burstmode burstperiod bursts burstsl bustest cdsgain chipversion clearbit clearbusy clientversion clkdiv clkfreq clkphase collectionmode column compdisabletime confadc config configtransceiver counters currentsource dac dacindex daclist dacname dacvalues datastream dbitclk dbitphase dbitpipeline defaultdac defaultpattern delay delayl detectorserverversion detsize diodelay dpulse dr drlist dsamples execcommand exptime exptime1 exptime2 exptime3 extrastoragecells extsampling extsamplingsrc extsig fformat filtercells filterresistor findex firmwaretest firmwareversion fliprows flowcontrol10g fmaster fname foverwrite fpath framecounter frames framesl frametime free fwrite gaincaps gainmode gappixels gatedelay gatedelay1 gatedelay2 gatedelay3 gates getbit hardwareversion highvoltage hostname im_a im_b im_c im_d im_io imagetest initialchecks inj_ch interpolation interruptsubframe kernelversion lastclient led lock master maxadcphaseshift maxclkphaseshift maxdbitphaseshift measuredperiod measuredsubperiod moduleid nextframenumber nmod numinterfaces overflow packageversion parallel parameters partialreset patfname patioctrl patlimits patloop patloop0 patloop1 patloop2 patmask patnloop patnloop0 patnloop1 patnloop2 patsetbit pattern patternstart patwait patwait0 patwait1 patwait2 patwaittime patwaittime0 patwaittime1 patwaittime2 patword pedestalmode period periodl polarity port powerchip powerindex powerlist powername powervalues programfpga pulse pulsechip pulsenmove pumpprobe quad ratecorr readnrows readout readoutspeed readoutspeedlist rebootcontroller reg resetdacs resetfpga romode row runclk runtime rx_arping rx_clearroi rx_dbitlist rx_dbitoffset rx_dbitreorder rx_discardpolicy rx_fifodepth rx_frameindex rx_framescaught rx_framesperfile rx_hostname rx_jsonaddheader rx_jsonpara rx_lastclient rx_lock rx_missingpackets rx_padding rx_printconfig rx_realudpsocksize rx_roi rx_silent rx_start rx_status rx_stop rx_tcpport rx_threads rx_udpsocksize rx_version rx_zmqfreq rx_zmqhwm rx_zmqip rx_zmqport rx_zmqstartfnum rx_zmqstream samples savepattern scan scanerrmsg selinterface serialnumber setbit settings settingslist settingspath signalindex signallist signalname sleep slowadc slowadcindex slowadclist slowadcname slowadcvalues start status stop stopport storagecell_delay storagecell_start subdeadtime subexptime sync syncclk temp_10ge temp_adc temp_control temp_dcdc temp_event temp_fpga temp_fpgaext temp_fpgafl temp_fpgafr temp_slowadc temp_sodl temp_sodr temp_threshold templist tempvalues tengiga threshold thresholdnotb timing timing_info_decoder timinglist timingsource top transceiverenable trigger triggers triggersl trimbits trimen trimval tsamples txdelay txdelay_frame txdelay_left txdelay_right type udp_cleardst udp_dstip udp_dstip2 udp_dstlist udp_dstmac udp_dstmac2 udp_dstport udp_dstport2 udp_firstdst udp_numdst udp_reconfigure udp_srcip udp_srcip2 udp_srcmac udp_srcmac2 udp_validate update updatedetectorserver updatekernel updatemode user v_a v_b v_c v_chip v_d v_io v_limit vchip_comp_adc vchip_comp_fe vchip_cs vchip_opa_1st vchip_opa_fd vchip_ref_comp_fe versions veto vetoalg vetofile vetophoton vetoref vetostream virtual vm_a vm_b vm_c vm_d vm_io zmqhwm zmqip zmqport "
__acquire() { __acquire() {
FCN_RETURN="" FCN_RETURN=""
return 0 return 0
@ -2088,6 +2088,15 @@ fi
fi fi
return 0 return 0
} }
__rx_dbitreorder() {
FCN_RETURN=""
if [[ ${IS_GET} -eq 0 ]]; then
if [[ "${cword}" == "2" ]]; then
FCN_RETURN="0 1"
fi
fi
return 0
}
__rx_discardpolicy() { __rx_discardpolicy() {
FCN_RETURN="" FCN_RETURN=""
if [[ ${IS_GET} -eq 0 ]]; then if [[ ${IS_GET} -eq 0 ]]; then

View File

@ -4,7 +4,7 @@
_sd() { _sd() {
local SLS_COMMANDS=" acquire activate adcclk adcenable adcenable10g adcindex adcinvert adclist adcname adcphase adcpipeline adcreg adcvpp apulse asamples autocompdisable badchannels blockingtrigger burstmode burstperiod bursts burstsl bustest cdsgain chipversion clearbit clearbusy clientversion clkdiv clkfreq clkphase collectionmode column compdisabletime confadc config configtransceiver counters currentsource dac dacindex daclist dacname dacvalues datastream dbitclk dbitphase dbitpipeline defaultdac defaultpattern delay delayl detectorserverversion detsize diodelay dpulse dr drlist dsamples execcommand exptime exptime1 exptime2 exptime3 extrastoragecells extsampling extsamplingsrc extsig fformat filtercells filterresistor findex firmwaretest firmwareversion fliprows flowcontrol10g fmaster fname foverwrite fpath framecounter frames framesl frametime free fwrite gaincaps gainmode gappixels gatedelay gatedelay1 gatedelay2 gatedelay3 gates getbit hardwareversion highvoltage hostname im_a im_b im_c im_d im_io imagetest initialchecks inj_ch interpolation interruptsubframe kernelversion lastclient led lock master maxadcphaseshift maxclkphaseshift maxdbitphaseshift measuredperiod measuredsubperiod moduleid nextframenumber nmod numinterfaces overflow packageversion parallel parameters partialreset patfname patioctrl patlimits patloop patloop0 patloop1 patloop2 patmask patnloop patnloop0 patnloop1 patnloop2 patsetbit pattern patternstart patwait patwait0 patwait1 patwait2 patwaittime patwaittime0 patwaittime1 patwaittime2 patword pedestalmode period periodl polarity port powerchip powerindex powerlist powername powervalues programfpga pulse pulsechip pulsenmove pumpprobe quad ratecorr readnrows readout readoutspeed readoutspeedlist rebootcontroller reg resetdacs resetfpga romode row runclk runtime rx_arping rx_clearroi rx_dbitlist rx_dbitoffset rx_discardpolicy rx_fifodepth rx_frameindex rx_framescaught rx_framesperfile rx_hostname rx_jsonaddheader rx_jsonpara rx_lastclient rx_lock rx_missingpackets rx_padding rx_printconfig rx_realudpsocksize rx_roi rx_silent rx_start rx_status rx_stop rx_tcpport rx_threads rx_udpsocksize rx_version rx_zmqfreq rx_zmqhwm rx_zmqip rx_zmqport rx_zmqstartfnum rx_zmqstream samples savepattern scan scanerrmsg selinterface serialnumber setbit settings settingslist settingspath signalindex signallist signalname sleep slowadc slowadcindex slowadclist slowadcname slowadcvalues start status stop stopport storagecell_delay storagecell_start subdeadtime subexptime sync syncclk temp_10ge temp_adc temp_control temp_dcdc temp_event temp_fpga temp_fpgaext temp_fpgafl temp_fpgafr temp_slowadc temp_sodl temp_sodr temp_threshold templist tempvalues tengiga threshold thresholdnotb timing timing_info_decoder timinglist timingsource top transceiverenable trigger triggers triggersl trimbits trimen trimval tsamples txdelay txdelay_frame txdelay_left txdelay_right type udp_cleardst udp_dstip udp_dstip2 udp_dstlist udp_dstmac udp_dstmac2 udp_dstport udp_dstport2 udp_firstdst udp_numdst udp_reconfigure udp_srcip udp_srcip2 udp_srcmac udp_srcmac2 udp_validate update updatedetectorserver updatekernel updatemode user v_a v_b v_c v_chip v_d v_io v_limit vchip_comp_adc vchip_comp_fe vchip_cs vchip_opa_1st vchip_opa_fd vchip_ref_comp_fe versions veto vetoalg vetofile vetophoton vetoref vetostream virtual vm_a vm_b vm_c vm_d vm_io zmqhwm zmqip zmqport " local SLS_COMMANDS=" acquire activate adcclk adcenable adcenable10g adcindex adcinvert adclist adcname adcphase adcpipeline adcreg adcvpp apulse asamples autocompdisable badchannels blockingtrigger burstmode burstperiod bursts burstsl bustest cdsgain chipversion clearbit clearbusy clientversion clkdiv clkfreq clkphase collectionmode column compdisabletime confadc config configtransceiver counters currentsource dac dacindex daclist dacname dacvalues datastream dbitclk dbitphase dbitpipeline defaultdac defaultpattern delay delayl detectorserverversion detsize diodelay dpulse dr drlist dsamples execcommand exptime exptime1 exptime2 exptime3 extrastoragecells extsampling extsamplingsrc extsig fformat filtercells filterresistor findex firmwaretest firmwareversion fliprows flowcontrol10g fmaster fname foverwrite fpath framecounter frames framesl frametime free fwrite gaincaps gainmode gappixels gatedelay gatedelay1 gatedelay2 gatedelay3 gates getbit hardwareversion highvoltage hostname im_a im_b im_c im_d im_io imagetest initialchecks inj_ch interpolation interruptsubframe kernelversion lastclient led lock master maxadcphaseshift maxclkphaseshift maxdbitphaseshift measuredperiod measuredsubperiod moduleid nextframenumber nmod numinterfaces overflow packageversion parallel parameters partialreset patfname patioctrl patlimits patloop patloop0 patloop1 patloop2 patmask patnloop patnloop0 patnloop1 patnloop2 patsetbit pattern patternstart patwait patwait0 patwait1 patwait2 patwaittime patwaittime0 patwaittime1 patwaittime2 patword pedestalmode period periodl polarity port powerchip powerindex powerlist powername powervalues programfpga pulse pulsechip pulsenmove pumpprobe quad ratecorr readnrows readout readoutspeed readoutspeedlist rebootcontroller reg resetdacs resetfpga romode row runclk runtime rx_arping rx_clearroi rx_dbitlist rx_dbitoffset rx_dbitreorder rx_discardpolicy rx_fifodepth rx_frameindex rx_framescaught rx_framesperfile rx_hostname rx_jsonaddheader rx_jsonpara rx_lastclient rx_lock rx_missingpackets rx_padding rx_printconfig rx_realudpsocksize rx_roi rx_silent rx_start rx_status rx_stop rx_tcpport rx_threads rx_udpsocksize rx_version rx_zmqfreq rx_zmqhwm rx_zmqip rx_zmqport rx_zmqstartfnum rx_zmqstream samples savepattern scan scanerrmsg selinterface serialnumber setbit settings settingslist settingspath signalindex signallist signalname sleep slowadc slowadcindex slowadclist slowadcname slowadcvalues start status stop stopport storagecell_delay storagecell_start subdeadtime subexptime sync syncclk temp_10ge temp_adc temp_control temp_dcdc temp_event temp_fpga temp_fpgaext temp_fpgafl temp_fpgafr temp_slowadc temp_sodl temp_sodr temp_threshold templist tempvalues tengiga threshold thresholdnotb timing timing_info_decoder timinglist timingsource top transceiverenable trigger triggers triggersl trimbits trimen trimval tsamples txdelay txdelay_frame txdelay_left txdelay_right type udp_cleardst udp_dstip udp_dstip2 udp_dstlist udp_dstmac udp_dstmac2 udp_dstport udp_dstport2 udp_firstdst udp_numdst udp_reconfigure udp_srcip udp_srcip2 udp_srcmac udp_srcmac2 udp_validate update updatedetectorserver updatekernel updatemode user v_a v_b v_c v_chip v_d v_io v_limit vchip_comp_adc vchip_comp_fe vchip_cs vchip_opa_1st vchip_opa_fd vchip_ref_comp_fe versions veto vetoalg vetofile vetophoton vetoref vetostream virtual vm_a vm_b vm_c vm_d vm_io zmqhwm zmqip zmqport "
__acquire() { __acquire() {
FCN_RETURN="" FCN_RETURN=""
return 0 return 0
@ -2012,6 +2012,15 @@ fi
fi fi
return 0 return 0
} }
__rx_dbitreorder() {
FCN_RETURN=""
if [[ ${IS_GET} -eq 0 ]]; then
if [[ "${cword}" == "2" ]]; then
FCN_RETURN="0 1"
fi
fi
return 0
}
__rx_discardpolicy() { __rx_discardpolicy() {
FCN_RETURN="" FCN_RETURN=""
if [[ ${IS_GET} -eq 0 ]]; then if [[ ${IS_GET} -eq 0 ]]; then

View File

@ -1412,6 +1412,18 @@ lock:
function: setDetectorLock function: setDetectorLock
input_types: [ bool ] input_types: [ bool ]
rx_dbitreorder:
help: "[0, 1]\n\t[Ctb] Reorder digital data such that it groups each signal (0-63) from all the different samples together . Default is 1. Setting to 0 means 'do not reorder' and to keep what the board spits out, which is that all signals in a sample are grouped together."
inherit_actions: INTEGER_COMMAND_VEC_ID
actions:
GET:
function: getRxDbitReorder
PUT:
function: setRxDbitReorder
input_types: [ bool ]
################# INTEGER_COMMAND_VEC_ID_GET ################# ################# INTEGER_COMMAND_VEC_ID_GET #################
master: master:

View File

@ -8305,6 +8305,48 @@ rx_dbitoffset:
help: "[n_bytes]\n\t[Ctb] Offset in bytes in digital data to skip in receiver." help: "[n_bytes]\n\t[Ctb] Offset in bytes in digital data to skip in receiver."
infer_action: true infer_action: true
template: true template: true
rx_dbitreorder:
actions:
GET:
args:
- arg_types: []
argc: 0
cast_input: []
check_det_id: false
convert_det_id: true
function: getRxDbitReorder
input: []
input_types: []
output:
- OutString(t)
require_det_id: true
store_result_in_t: true
PUT:
args:
- arg_types:
- bool
argc: 1
cast_input:
- true
check_det_id: false
convert_det_id: true
function: setRxDbitReorder
input:
- args[0]
input_types:
- bool
output:
- args.front()
require_det_id: true
store_result_in_t: false
command_name: rx_dbitreorder
function_alias: rx_dbitreorder
help: "[0, 1]\n\t[Ctb] Reorder digital data such that it groups each signal (0-63)\
\ from all the different samples together . Default is 1. Setting to 0 means 'do\
\ not reorder' and to keep what the board spits out, which is that all signals\
\ in a sample are grouped together."
infer_action: true
template: true
rx_discardpolicy: rx_discardpolicy:
actions: actions:
GET: GET:

View File

@ -1729,6 +1729,16 @@ class Detector {
/** [CTB] Set number of bytes of digital data to skip in the Receiver */ /** [CTB] Set number of bytes of digital data to skip in the Receiver */
void setRxDbitOffset(int value, Positions pos = {}); void setRxDbitOffset(int value, Positions pos = {});
/** [CTB] */
Result<bool> getRxDbitReorder(Positions pos = {}) const;
/** [CTB] Reorder digital data such that it groups each signal (0-63)
* from all the different samples together.
* Default is true. Setting to false means 'do not reorder' and to keep what
* the board spits out, which is that all signals in a sample are grouped
* together */
void setRxDbitReorder(bool reorder, Positions pos = {});
/** /**
* [CTB] Set Digital IO Delay * [CTB] Set Digital IO Delay
* cannot get * cannot get

View File

@ -23,7 +23,7 @@ typedef struct __attribute__((packed)) {
#ifdef __cplusplus #ifdef __cplusplus
class Pattern { class Pattern {
patternParameters *pat = new patternParameters{}; patternParameters *pat = new patternParameters{};
std::ostream& stream(std::ostream &os) const; std::ostream &stream(std::ostream &os) const;
public: public:
Pattern(); Pattern();

View File

@ -10700,6 +10700,68 @@ std::string Caller::rx_dbitoffset(int action) {
return os.str(); return os.str();
} }
std::string Caller::rx_dbitreorder(int action) {
std::ostringstream os;
// print help
if (action == slsDetectorDefs::HELP_ACTION) {
os << R"V0G0N([0, 1]
[Ctb] Reorder digital data such that it groups each signal (0-63) from all the different samples together . Default is 1. Setting to 0 means 'do not reorder' and to keep what the board spits out, which is that all signals in a sample are grouped together. )V0G0N"
<< std::endl;
return os.str();
}
// check if action and arguments are valid
if (action == slsDetectorDefs::GET_ACTION) {
if (1 && args.size() != 0) {
throw RuntimeError("Wrong number of arguments for action GET");
}
if (args.size() == 0) {
}
}
else if (action == slsDetectorDefs::PUT_ACTION) {
if (1 && args.size() != 1) {
throw RuntimeError("Wrong number of arguments for action PUT");
}
if (args.size() == 1) {
try {
StringTo<bool>(args[0]);
} catch (...) {
throw RuntimeError("Could not convert argument 0 to bool");
}
}
}
else {
throw RuntimeError("INTERNAL ERROR: Invalid action: supported actions "
"are ['GET', 'PUT']");
}
// generate code for each action
if (action == slsDetectorDefs::GET_ACTION) {
if (args.size() == 0) {
auto t = det->getRxDbitReorder(std::vector<int>{det_id});
os << OutString(t) << '\n';
}
}
if (action == slsDetectorDefs::PUT_ACTION) {
if (args.size() == 1) {
auto arg0 = StringTo<bool>(args[0]);
det->setRxDbitReorder(arg0, std::vector<int>{det_id});
os << args.front() << '\n';
}
}
return os.str();
}
std::string Caller::rx_discardpolicy(int action) { std::string Caller::rx_discardpolicy(int action) {
std::ostringstream os; std::ostringstream os;

View File

@ -236,6 +236,7 @@ class Caller {
std::string rx_clearroi(int action); std::string rx_clearroi(int action);
std::string rx_dbitlist(int action); std::string rx_dbitlist(int action);
std::string rx_dbitoffset(int action); std::string rx_dbitoffset(int action);
std::string rx_dbitreorder(int action);
std::string rx_discardpolicy(int action); std::string rx_discardpolicy(int action);
std::string rx_fifodepth(int action); std::string rx_fifodepth(int action);
std::string rx_frameindex(int action); std::string rx_frameindex(int action);
@ -582,6 +583,7 @@ class Caller {
{"rx_clearroi", &Caller::rx_clearroi}, {"rx_clearroi", &Caller::rx_clearroi},
{"rx_dbitlist", &Caller::rx_dbitlist}, {"rx_dbitlist", &Caller::rx_dbitlist},
{"rx_dbitoffset", &Caller::rx_dbitoffset}, {"rx_dbitoffset", &Caller::rx_dbitoffset},
{"rx_dbitreorder", &Caller::rx_dbitreorder},
{"rx_discardpolicy", &Caller::rx_discardpolicy}, {"rx_discardpolicy", &Caller::rx_discardpolicy},
{"rx_fifodepth", &Caller::rx_fifodepth}, {"rx_fifodepth", &Caller::rx_fifodepth},
{"rx_frameindex", &Caller::rx_frameindex}, {"rx_frameindex", &Caller::rx_frameindex},

View File

@ -2277,6 +2277,14 @@ void Detector::setRxDbitOffset(int value, Positions pos) {
pimpl->Parallel(&Module::setReceiverDbitOffset, pos, value); pimpl->Parallel(&Module::setReceiverDbitOffset, pos, value);
} }
Result<bool> Detector::getRxDbitReorder(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverDbitReorder, pos);
}
void Detector::setRxDbitReorder(bool reorder, Positions pos) {
pimpl->Parallel(&Module::setReceiverDbitReorder, pos, reorder);
}
void Detector::setDigitalIODelay(uint64_t pinMask, int delay, Positions pos) { void Detector::setDigitalIODelay(uint64_t pinMask, int delay, Positions pos) {
pimpl->Parallel(&Module::setDigitalIODelay, pos, pinMask, delay); pimpl->Parallel(&Module::setDigitalIODelay, pos, pinMask, delay);
} }

View File

@ -2509,6 +2509,15 @@ void Module::setReceiverDbitOffset(int value) {
sendToReceiver(F_SET_RECEIVER_DBIT_OFFSET, value, nullptr); sendToReceiver(F_SET_RECEIVER_DBIT_OFFSET, value, nullptr);
} }
bool Module::getReceiverDbitReorder() const {
return sendToReceiver<int>(F_GET_RECEIVER_DBIT_REORDER);
}
void Module::setReceiverDbitReorder(bool reorder) {
sendToReceiver(F_SET_RECEIVER_DBIT_REORDER, static_cast<int>(reorder),
nullptr);
}
void Module::setDigitalIODelay(uint64_t pinMask, int delay) { void Module::setDigitalIODelay(uint64_t pinMask, int delay) {
uint64_t args[]{pinMask, static_cast<uint64_t>(delay)}; uint64_t args[]{pinMask, static_cast<uint64_t>(delay)};
sendToDetector(F_DIGITAL_IO_DELAY, args, nullptr); sendToDetector(F_DIGITAL_IO_DELAY, args, nullptr);

View File

@ -510,6 +510,8 @@ class Module : public virtual slsDetectorDefs {
void setReceiverDbitList(std::vector<int> list); void setReceiverDbitList(std::vector<int> list);
int getReceiverDbitOffset() const; int getReceiverDbitOffset() const;
void setReceiverDbitOffset(int value); void setReceiverDbitOffset(int value);
bool getReceiverDbitReorder() const;
void setReceiverDbitReorder(bool value);
void setDigitalIODelay(uint64_t pinMask, int delay); void setDigitalIODelay(uint64_t pinMask, int delay);
bool getLEDEnable() const; bool getLEDEnable() const;
void setLEDEnable(bool enable); void setLEDEnable(bool enable);

View File

@ -243,10 +243,10 @@ size_t Pattern::load(const std::string &fname) {
return numPatWords; return numPatWords;
} }
std::ostream& Pattern::stream(std::ostream &os) const{ std::ostream &Pattern::stream(std::ostream &os) const {
for (uint32_t i = pat->limits[0]; i <= pat->limits[1]; ++i) { for (uint32_t i = pat->limits[0]; i <= pat->limits[1]; ++i) {
os << "patword " << ToStringHex(i, 4) << " " os << "patword " << ToStringHex(i, 4) << " "
<< ToStringHex(pat->word[i], 16) << std::endl; << ToStringHex(pat->word[i], 16) << std::endl;
} }
// patioctrl // patioctrl
@ -254,13 +254,12 @@ std::ostream& Pattern::stream(std::ostream &os) const{
// patlimits // patlimits
os << "patlimits " << ToStringHex(pat->limits[0], 4) << " " os << "patlimits " << ToStringHex(pat->limits[0], 4) << " "
<< ToStringHex(pat->limits[1], 4) << std::endl; << ToStringHex(pat->limits[1], 4) << std::endl;
for (size_t i = 0; i < MAX_PATTERN_LEVELS; ++i) { for (size_t i = 0; i < MAX_PATTERN_LEVELS; ++i) {
// patloop // patloop
os << "patloop " << i << " " os << "patloop " << i << " " << ToStringHex(pat->startloop[i], 4) << " "
<< ToStringHex(pat->startloop[i], 4) << " " << ToStringHex(pat->stoploop[i], 4) << std::endl;
<< ToStringHex(pat->stoploop[i], 4) << std::endl;
// patnloop // patnloop
os << "patnloop " << i << " " << pat->nloop[i] << std::endl; os << "patnloop " << i << " " << pat->nloop[i] << std::endl;
} }
@ -268,10 +267,10 @@ std::ostream& Pattern::stream(std::ostream &os) const{
for (size_t i = 0; i < MAX_PATTERN_LEVELS; ++i) { for (size_t i = 0; i < MAX_PATTERN_LEVELS; ++i) {
// patwait // patwait
os << "patwait " << i << " " << ToStringHex(pat->wait[i], 4) os << "patwait " << i << " " << ToStringHex(pat->wait[i], 4)
<< std::endl; << std::endl;
// patwaittime // patwaittime
os << "patwaittime " << i << " " << pat->waittime[i]; os << "patwaittime " << i << " " << pat->waittime[i];
if (i<MAX_PATTERN_LEVELS-1) if (i < MAX_PATTERN_LEVELS - 1)
os << std::endl; os << std::endl;
} }
return os; return os;

View File

@ -2568,6 +2568,22 @@ int InferAction::rx_dbitoffset() {
} }
} }
int InferAction::rx_dbitreorder() {
if (args.size() == 0) {
return slsDetectorDefs::GET_ACTION;
}
if (args.size() == 1) {
return slsDetectorDefs::PUT_ACTION;
}
else {
throw RuntimeError("Could not infer action: Wrong number of arguments");
}
}
int InferAction::rx_discardpolicy() { int InferAction::rx_discardpolicy() {
if (args.size() == 0) { if (args.size() == 0) {

View File

@ -193,6 +193,7 @@ class InferAction {
int rx_clearroi(); int rx_clearroi();
int rx_dbitlist(); int rx_dbitlist();
int rx_dbitoffset(); int rx_dbitoffset();
int rx_dbitreorder();
int rx_discardpolicy(); int rx_discardpolicy();
int rx_fifodepth(); int rx_fifodepth();
int rx_frameindex(); int rx_frameindex();
@ -527,6 +528,7 @@ class InferAction {
{"rx_clearroi", &InferAction::rx_clearroi}, {"rx_clearroi", &InferAction::rx_clearroi},
{"rx_dbitlist", &InferAction::rx_dbitlist}, {"rx_dbitlist", &InferAction::rx_dbitlist},
{"rx_dbitoffset", &InferAction::rx_dbitoffset}, {"rx_dbitoffset", &InferAction::rx_dbitoffset},
{"rx_dbitreorder", &InferAction::rx_dbitreorder},
{"rx_discardpolicy", &InferAction::rx_discardpolicy}, {"rx_discardpolicy", &InferAction::rx_discardpolicy},
{"rx_fifodepth", &InferAction::rx_fifodepth}, {"rx_fifodepth", &InferAction::rx_fifodepth},
{"rx_frameindex", &InferAction::rx_frameindex}, {"rx_frameindex", &InferAction::rx_frameindex},

View File

@ -445,23 +445,25 @@ TEST_CASE("rx_arping", "[.cmdcall][.rx]") {
Detector det; Detector det;
Caller caller(&det); Caller caller(&det);
auto prev_val = det.getRxArping(); auto prev_val = det.getRxArping();
{ if (det.getDestinationUDPIP()[0].str() != "127.0.0.1") {
std::ostringstream oss; {
caller.call("rx_arping", {"1"}, -1, PUT, oss); std::ostringstream oss;
REQUIRE(oss.str() == "rx_arping 1\n"); caller.call("rx_arping", {"1"}, -1, PUT, oss);
} REQUIRE(oss.str() == "rx_arping 1\n");
{ }
std::ostringstream oss; {
caller.call("rx_arping", {}, -1, GET, oss); std::ostringstream oss;
REQUIRE(oss.str() == "rx_arping 1\n"); caller.call("rx_arping", {}, -1, GET, oss);
} REQUIRE(oss.str() == "rx_arping 1\n");
{ }
std::ostringstream oss; {
caller.call("rx_arping", {"0"}, -1, PUT, oss); std::ostringstream oss;
REQUIRE(oss.str() == "rx_arping 0\n"); caller.call("rx_arping", {"0"}, -1, PUT, oss);
} REQUIRE(oss.str() == "rx_arping 0\n");
for (int i = 0; i != det.size(); ++i) { }
det.setRxArping(prev_val[i], {i}); for (int i = 0; i != det.size(); ++i) {
det.setRxArping(prev_val[i], {i});
}
} }
} }
@ -583,6 +585,9 @@ TEST_CASE("fpath", "[.cmdcall]") {
REQUIRE(oss.str() == "fpath /tmp\n"); REQUIRE(oss.str() == "fpath /tmp\n");
} }
for (int i = 0; i != det.size(); ++i) { for (int i = 0; i != det.size(); ++i) {
if (prev_val[i].empty()) {
continue;
}
det.setFilePath(prev_val[i], {i}); det.setFilePath(prev_val[i], {i});
} }
} }
@ -956,6 +961,37 @@ TEST_CASE("rx_dbitoffset", "[.cmdcall][.rx]") {
} }
} }
TEST_CASE("rx_dbitreorder", "[.cmdcall][.rx]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD ||
det_type == defs::XILINX_CHIPTESTBOARD) {
auto prev_val = det.getRxDbitReorder();
{
std::ostringstream oss;
caller.call("rx_dbitreorder", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_dbitreorder 0\n");
}
{
std::ostringstream oss;
caller.call("rx_dbitreorder", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_dbitreorder 1\n");
}
{
std::ostringstream oss;
caller.call("rx_dbitreorder", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_dbitreorder 1\n");
}
REQUIRE_THROWS(caller.call("rx_dbitreorder", {"15"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setRxDbitReorder(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("rx_dbitreorder", {}, -1, GET));
}
}
TEST_CASE("rx_jsonaddheader", "[.cmdcall][.rx]") { TEST_CASE("rx_jsonaddheader", "[.cmdcall][.rx]") {
Detector det; Detector det;
Caller caller(&det); Caller caller(&det);

View File

@ -3236,7 +3236,7 @@ TEST_CASE("reg", "[.cmdcall]") {
addr = 0x80; addr = 0x80;
} }
if (det_type == defs::GOTTHARD2) { if (det_type == defs::GOTTHARD2) {
addr = 0x20; addr = 0x298;
} }
std::string saddr = ToStringHex(addr); std::string saddr = ToStringHex(addr);
auto prev_val = det.readRegister(addr); auto prev_val = det.readRegister(addr);
@ -3292,7 +3292,7 @@ TEST_CASE("setbit", "[.cmdcall]") {
addr = 0x80; addr = 0x80;
} }
if (det_type == defs::GOTTHARD2) { if (det_type == defs::GOTTHARD2) {
addr = 0x20; addr = 0x298;
} }
std::string saddr = ToStringHex(addr); std::string saddr = ToStringHex(addr);
auto prev_val = det.readRegister(addr); auto prev_val = det.readRegister(addr);
@ -3322,7 +3322,7 @@ TEST_CASE("clearbit", "[.cmdcall]") {
addr = 0x80; addr = 0x80;
} }
if (det_type == defs::GOTTHARD2) { if (det_type == defs::GOTTHARD2) {
addr = 0x20; addr = 0x298;
} }
std::string saddr = ToStringHex(addr); std::string saddr = ToStringHex(addr);
auto prev_val = det.readRegister(addr); auto prev_val = det.readRegister(addr);
@ -3352,7 +3352,7 @@ TEST_CASE("getbit", "[.cmdcall]") {
addr = 0x80; addr = 0x80;
} }
if (det_type == defs::GOTTHARD2) { if (det_type == defs::GOTTHARD2) {
addr = 0x20; addr = 0x298;
} }
std::string saddr = ToStringHex(addr); std::string saddr = ToStringHex(addr);
auto prev_val = det.readRegister(addr); auto prev_val = det.readRegister(addr);

View File

@ -18,11 +18,16 @@ struct Data {
constexpr int shm_id = 10; constexpr int shm_id = 10;
TEST_CASE("Create SharedMemory read and write", "[detector]") { TEST_CASE("Create SharedMemory read and write", "[detector]") {
const char *env_p = std::getenv("SLSDETNAME");
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
SharedMemory<Data> shm(shm_id, -1); SharedMemory<Data> shm(shm_id, -1);
if (shm.exists()) {
shm.removeSharedMemory();
}
shm.createSharedMemory(); shm.createSharedMemory();
CHECK(shm.getName() == std::string("/slsDetectorPackage_detector_") + CHECK(shm.getName() == std::string("/slsDetectorPackage_detector_") +
std::to_string(shm_id)); std::to_string(shm_id) + env_name);
shm()->x = 3; shm()->x = 3;
shm()->y = 5.7; shm()->y = 5.7;
@ -90,10 +95,12 @@ TEST_CASE("Open two shared memories to the same place", "[detector]") {
} }
TEST_CASE("Move SharedMemory", "[detector]") { TEST_CASE("Move SharedMemory", "[detector]") {
const char *env_p = std::getenv("SLSDETNAME");
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
SharedMemory<Data> shm(shm_id, -1); SharedMemory<Data> shm(shm_id, -1);
CHECK(shm.getName() == std::string("/slsDetectorPackage_detector_") + CHECK(shm.getName() == std::string("/slsDetectorPackage_detector_") +
std::to_string(shm_id)); std::to_string(shm_id) + env_name);
shm.createSharedMemory(); shm.createSharedMemory();
shm()->x = 9; shm()->x = 9;
@ -104,15 +111,19 @@ TEST_CASE("Move SharedMemory", "[detector]") {
REQUIRE_THROWS( REQUIRE_THROWS(
shm()); // trying to access should throw instead of returning a nullptr shm()); // trying to access should throw instead of returning a nullptr
CHECK(shm2.getName() == std::string("/slsDetectorPackage_detector_") + CHECK(shm2.getName() == std::string("/slsDetectorPackage_detector_") +
std::to_string(shm_id)); std::to_string(shm_id) + env_name);
shm2.removeSharedMemory(); shm2.removeSharedMemory();
} }
TEST_CASE("Create several shared memories", "[detector]") { TEST_CASE("Create several shared memories", "[detector]") {
const char *env_p = std::getenv("SLSDETNAME");
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
constexpr int N = 5; constexpr int N = 5;
std::vector<SharedMemory<int>> v; std::vector<SharedMemory<int>> v;
v.reserve(N); v.reserve(N);
for (int i = 0; i != N; ++i) { for (int i = 0; i != N; ++i) {
std::cout << "i:" << i << std::endl;
v.emplace_back(shm_id + i, -1); v.emplace_back(shm_id + i, -1);
CHECK(v[i].exists() == false); CHECK(v[i].exists() == false);
v[i].createSharedMemory(); v[i].createSharedMemory();
@ -123,7 +134,7 @@ TEST_CASE("Create several shared memories", "[detector]") {
for (int i = 0; i != N; ++i) { for (int i = 0; i != N; ++i) {
CHECK(*v[i]() == i); CHECK(*v[i]() == i);
CHECK(v[i].getName() == std::string("/slsDetectorPackage_detector_") + CHECK(v[i].getName() == std::string("/slsDetectorPackage_detector_") +
std::to_string(i + shm_id)); std::to_string(i + shm_id) + env_name);
} }
for (int i = 0; i != N; ++i) { for (int i = 0; i != N; ++i) {
@ -133,8 +144,12 @@ TEST_CASE("Create several shared memories", "[detector]") {
} }
TEST_CASE("Create create a shared memory with a tag") { TEST_CASE("Create create a shared memory with a tag") {
const char *env_p = std::getenv("SLSDETNAME");
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
SharedMemory<int> shm(0, -1, "ctbdacs"); SharedMemory<int> shm(0, -1, "ctbdacs");
REQUIRE(shm.getName() == "/slsDetectorPackage_detector_0_ctbdacs"); REQUIRE(shm.getName() ==
"/slsDetectorPackage_detector_0" + env_name + "_ctbdacs");
} }
TEST_CASE("Create create a shared memory with a tag when SLSDETNAME is set") { TEST_CASE("Create create a shared memory with a tag when SLSDETNAME is set") {

View File

@ -218,6 +218,8 @@ int ClientInterface::functionTable(){
flist[F_RECEIVER_SET_TRANSCEIVER_MASK] = &ClientInterface::set_transceiver_mask; flist[F_RECEIVER_SET_TRANSCEIVER_MASK] = &ClientInterface::set_transceiver_mask;
flist[F_RECEIVER_SET_ROW] = &ClientInterface::set_row; flist[F_RECEIVER_SET_ROW] = &ClientInterface::set_row;
flist[F_RECEIVER_SET_COLUMN] = &ClientInterface::set_column; flist[F_RECEIVER_SET_COLUMN] = &ClientInterface::set_column;
flist[F_GET_RECEIVER_DBIT_REORDER] = &ClientInterface::get_dbit_reorder;
flist[F_SET_RECEIVER_DBIT_REORDER] = &ClientInterface::set_dbit_reorder;
for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) { for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) {
@ -1789,4 +1791,25 @@ int ClientInterface::set_column(Interface &socket) {
return socket.Send(OK); return socket.Send(OK);
} }
int ClientInterface::get_dbit_reorder(Interface &socket) {
if (detType != CHIPTESTBOARD && detType != XILINX_CHIPTESTBOARD)
functionNotImplemented();
int retval = impl()->getDbitReorder();
LOG(logDEBUG1) << "Dbit reorder retval: " << retval;
return socket.sendResult(retval);
}
int ClientInterface::set_dbit_reorder(Interface &socket) {
auto arg = socket.Receive<int>();
if (detType != CHIPTESTBOARD && detType != XILINX_CHIPTESTBOARD)
functionNotImplemented();
if (arg < 0) {
throw RuntimeError("Invalid dbit reorder: " + std::to_string(arg));
}
verifyIdle(socket);
LOG(logDEBUG1) << "Setting Dbit reorder: " << arg;
impl()->setDbitReorder(arg);
return socket.Send(OK);
}
} // namespace sls } // namespace sls

View File

@ -164,6 +164,8 @@ class ClientInterface : private virtual slsDetectorDefs {
int set_transceiver_mask(ServerInterface &socket); int set_transceiver_mask(ServerInterface &socket);
int set_row(ServerInterface &socket); int set_row(ServerInterface &socket);
int set_column(ServerInterface &socket); int set_column(ServerInterface &socket);
int get_dbit_reorder(ServerInterface &socket);
int set_dbit_reorder(ServerInterface &socket);
Implementation *impl() { Implementation *impl() {
if (receiver != nullptr) { if (receiver != nullptr) {

View File

@ -3,7 +3,7 @@
/************************************************ /************************************************
* @file DataProcessor.cpp * @file DataProcessor.cpp
* @short creates data processor thread that * @short creates data processor thread that
* pulls pointers to memory addresses from fifos * pulls pointers to memory addresses from fifos
* and processes data stored in them & writes them to file * and processes data stored in them & writes them to file
***********************************************/ ***********************************************/
@ -23,6 +23,7 @@
#include <cerrno> #include <cerrno>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <numeric>
namespace sls { namespace sls {
@ -71,12 +72,6 @@ void DataProcessor::SetStreamingStartFnum(uint32_t value) {
void DataProcessor::SetFramePadding(bool enable) { framePadding = enable; } void DataProcessor::SetFramePadding(bool enable) { framePadding = enable; }
void DataProcessor::SetCtbDbitList(std::vector<int> value) {
ctbDbitList = value;
}
void DataProcessor::SetCtbDbitOffset(int value) { ctbDbitOffset = value; }
void DataProcessor::SetQuadEnable(bool value) { quadEnable = value; } void DataProcessor::SetQuadEnable(bool value) { quadEnable = value; }
void DataProcessor::SetFlipRows(bool fd) { void DataProcessor::SetFlipRows(bool fd) {
@ -213,8 +208,9 @@ std::string DataProcessor::CreateVirtualFile(
"Skipping virtual hdf5 file since rx_roi is enabled."); "Skipping virtual hdf5 file since rx_roi is enabled.");
} }
bool gotthard25um = bool gotthard25um = ((generalData->detType == GOTTHARD ||
(generalData->detType == GOTTHARD2 && (numModX * numModY) == 2); generalData->detType == GOTTHARD2) &&
(numModX * numModY) == 2);
// 0 for infinite files // 0 for infinite files
uint32_t framesPerFile = uint32_t framesPerFile =
@ -299,7 +295,7 @@ void DataProcessor::ThreadExecution() {
memImage->data); memImage->data);
} catch (const std::exception &e) { } catch (const std::exception &e) {
fifo->FreeAddress(buffer); fifo->FreeAddress(buffer);
return; throw RuntimeError(e.what());
} }
// stream (if time/freq to stream) or free // stream (if time/freq to stream) or free
@ -332,6 +328,7 @@ void DataProcessor::StopProcessing(char *buf) {
void DataProcessor::ProcessAnImage(sls_receiver_header &header, size_t &size, void DataProcessor::ProcessAnImage(sls_receiver_header &header, size_t &size,
size_t &firstImageIndex, char *data) { size_t &firstImageIndex, char *data) {
uint64_t fnum = header.detHeader.frameNumber; uint64_t fnum = header.detHeader.frameNumber;
LOG(logDEBUG1) << "DataProcessing " << index << ": fnum:" << fnum; LOG(logDEBUG1) << "DataProcessing " << index << ": fnum:" << fnum;
currentFrameIndex = fnum; currentFrameIndex = fnum;
@ -355,9 +352,16 @@ void DataProcessor::ProcessAnImage(sls_receiver_header &header, size_t &size,
if (framePadding && nump < generalData->packetsPerFrame) if (framePadding && nump < generalData->packetsPerFrame)
PadMissingPackets(header, data); PadMissingPackets(header, data);
// rearrange ctb digital bits (if ctbDbitlist is not empty) // rearrange ctb digital bits
if (!ctbDbitList.empty()) { if (!generalData->ctbDbitList.empty()) {
RearrangeDbitData(size, data); ArrangeDbitData(size, data);
} else if (generalData->ctbDbitReorder) {
std::vector<int> ctbDbitList(64);
std::iota(ctbDbitList.begin(), ctbDbitList.end(), 0);
generalData->SetctbDbitList(ctbDbitList);
ArrangeDbitData(size, data);
} else if (generalData->ctbDbitOffset > 0) {
RemoveTrailingBits(size, data);
} }
// 'stream Image' check has to be done here before crop image // 'stream Image' check has to be done here before crop image
@ -519,11 +523,53 @@ void DataProcessor::PadMissingPackets(sls_receiver_header header, char *data) {
} }
} }
void DataProcessor::RemoveTrailingBits(size_t &size, char *data) {
if (!(generalData->detType == slsDetectorDefs::CHIPTESTBOARD ||
generalData->detType == slsDetectorDefs::XILINX_CHIPTESTBOARD)) {
throw std::runtime_error("behavior undefined for detector " +
std::to_string(generalData->detType));
}
const size_t nAnalogDataBytes = generalData->GetNumberOfAnalogDatabytes();
const size_t nDigitalDataBytes = generalData->GetNumberOfDigitalDatabytes();
const size_t nTransceiverDataBytes =
generalData->GetNumberOfTransceiverDatabytes();
const size_t ctbDbitOffset = generalData->ctbDbitOffset;
const size_t ctbDigitalDataBytes = nDigitalDataBytes - ctbDbitOffset;
// no digital data
if (ctbDigitalDataBytes == 0) {
LOG(logWARNING)
<< "No digital data for call back, yet ctbDbitOffset is non zero.";
return;
}
// update size and copy data
memmove(data + nAnalogDataBytes, data + nAnalogDataBytes + ctbDbitOffset,
ctbDigitalDataBytes + nTransceiverDataBytes);
size = nAnalogDataBytes + ctbDigitalDataBytes + nTransceiverDataBytes;
}
/** ctb specific */ /** ctb specific */
void DataProcessor::RearrangeDbitData(size_t &size, char *data) { void DataProcessor::ArrangeDbitData(size_t &size, char *data) {
int nAnalogDataBytes = generalData->GetNumberOfAnalogDatabytes();
int nDigitalDataBytes = generalData->GetNumberOfDigitalDatabytes(); if (!(generalData->detType == slsDetectorDefs::CHIPTESTBOARD ||
int nTransceiverDataBytes = generalData->GetNumberOfTransceiverDatabytes(); generalData->detType == slsDetectorDefs::XILINX_CHIPTESTBOARD)) {
throw std::runtime_error("behavior undefined for detector " +
std::to_string(generalData->detType));
}
const size_t nAnalogDataBytes = generalData->GetNumberOfAnalogDatabytes();
const size_t nDigitalDataBytes = generalData->GetNumberOfDigitalDatabytes();
const size_t nTransceiverDataBytes =
generalData->GetNumberOfTransceiverDatabytes();
const size_t ctbDbitOffset = generalData->ctbDbitOffset;
const bool ctbDbitReorder = generalData->ctbDbitReorder;
const auto ctbDbitList = generalData->ctbDbitList;
// TODO! (Erik) Refactor and add tests // TODO! (Erik) Refactor and add tests
int ctbDigitalDataBytes = nDigitalDataBytes - ctbDbitOffset; int ctbDigitalDataBytes = nDigitalDataBytes - ctbDbitOffset;
@ -534,47 +580,101 @@ void DataProcessor::RearrangeDbitData(size_t &size, char *data) {
return; return;
} }
char *source = (data + nAnalogDataBytes + ctbDbitOffset);
const int numDigitalSamples = (ctbDigitalDataBytes / sizeof(uint64_t)); const int numDigitalSamples = (ctbDigitalDataBytes / sizeof(uint64_t));
// const int numResult8Bits = ceil((numDigitalSamples * ctbDbitList.size()) int totalNumBytes =
// / 8.00); 0; // number of bytes for selected digital data given by dtbDbitList
int numBitsPerDbit = numDigitalSamples;
if ((numBitsPerDbit % 8) != 0) // store each selected bit from all samples consecutively
numBitsPerDbit += (8 - (numDigitalSamples % 8)); if (ctbDbitReorder) {
const int totalNumBytes = (numBitsPerDbit / 8) * ctbDbitList.size(); size_t numBitsPerDbit =
std::vector<uint8_t> result(totalNumBytes); numDigitalSamples; // num bits per selected digital
// Bit for all samples
if ((numBitsPerDbit % 8) != 0)
numBitsPerDbit += (8 - (numDigitalSamples % 8));
totalNumBytes = (numBitsPerDbit / 8) * ctbDbitList.size();
}
// store all selected bits from one sample consecutively
else {
size_t numBitsPerSample =
ctbDbitList.size(); // num bits for all selected bits per sample
if ((numBitsPerSample % 8) != 0)
numBitsPerSample += (8 - (numBitsPerSample % 8));
totalNumBytes = (numBitsPerSample / 8) * numDigitalSamples;
}
std::vector<uint8_t> result(totalNumBytes, 0);
uint8_t *dest = &result[0]; uint8_t *dest = &result[0];
auto *source = (uint64_t *)(data + nAnalogDataBytes + ctbDbitOffset); if (ctbDbitReorder) {
// loop through digital bit enable vector
// loop through digital bit enable vector int bitoffset = 0;
int bitoffset = 0; for (auto bi : ctbDbitList) {
for (auto bi : ctbDbitList) { // where numbits * numDigitalSamples is not a multiple of 8
// where numbits * numDigitalSamples is not a multiple of 8 if (bitoffset != 0) {
if (bitoffset != 0) {
bitoffset = 0;
++dest;
}
// loop through the frame digital data
for (auto *ptr = source; ptr < (source + numDigitalSamples);) {
// get selected bit from each 8 bit
uint8_t bit = (*ptr++ >> bi) & 1;
*dest |= bit << bitoffset;
++bitoffset;
// extract destination in 8 bit batches
if (bitoffset == 8) {
bitoffset = 0; bitoffset = 0;
++dest; ++dest;
} }
uint8_t byte_index = bi / 8;
// loop through the frame digital data
for (auto *ptr = source + byte_index;
ptr < (source + 8 * numDigitalSamples); ptr += 8) {
// get selected bit from each 8 bit
uint8_t bit = (*ptr >> bi % 8) & 1;
*dest |= bit << bitoffset; // stored as least significant
++bitoffset;
// extract destination in 8 bit batches
if (bitoffset == 8) {
bitoffset = 0;
++dest;
}
}
}
} else {
// loop through the digital data
int bitoffset = 0;
for (auto *ptr = source; ptr < (source + 8 * numDigitalSamples);
ptr += 8) {
// where bit enable vector size is not a multiple of 8
if (bitoffset != 0) {
bitoffset = 0;
++dest;
}
// loop through digital bit enable vector
for (auto bi : ctbDbitList) {
// get selected bit from each 64 bit
uint8_t byte_index = bi / 8;
uint8_t bit = (*(ptr + byte_index) >> (bi % 8)) & 1;
*dest |= bit << bitoffset;
++bitoffset;
// extract destination in 8 bit batches
if (bitoffset == 8) {
bitoffset = 0;
++dest;
}
}
} }
} }
size = totalNumBytes * sizeof(uint8_t) + nAnalogDataBytes +
nTransceiverDataBytes;
// check if size changed, if so move transceiver data to avoid gap in memory
if (size != nAnalogDataBytes + nDigitalDataBytes + nTransceiverDataBytes)
memmove(data + nAnalogDataBytes + totalNumBytes * sizeof(uint8_t),
data + nAnalogDataBytes + nDigitalDataBytes,
nTransceiverDataBytes);
// copy back to memory and update size // copy back to memory and update size
memcpy(data + nAnalogDataBytes, result.data(), memcpy(data + nAnalogDataBytes, result.data(),
totalNumBytes * sizeof(uint8_t)); totalNumBytes * sizeof(uint8_t));
size = totalNumBytes * sizeof(uint8_t) + nAnalogDataBytes + ctbDbitOffset +
nTransceiverDataBytes;
LOG(logDEBUG1) << "totalNumBytes: " << totalNumBytes LOG(logDEBUG1) << "totalNumBytes: " << totalNumBytes
<< " nAnalogDataBytes:" << nAnalogDataBytes << " nAnalogDataBytes:" << nAnalogDataBytes
<< " ctbDbitOffset:" << ctbDbitOffset << " ctbDbitOffset:" << ctbDbitOffset

View File

@ -45,8 +45,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
void SetStreamingTimerInMs(uint32_t value); void SetStreamingTimerInMs(uint32_t value);
void SetStreamingStartFnum(uint32_t value); void SetStreamingStartFnum(uint32_t value);
void SetFramePadding(bool enable); void SetFramePadding(bool enable);
void SetCtbDbitList(std::vector<int> value);
void SetCtbDbitOffset(int value);
void SetQuadEnable(bool value); void SetQuadEnable(bool value);
void SetFlipRows(bool fd); void SetFlipRows(bool fd);
void SetNumberofTotalFrames(uint64_t value); void SetNumberofTotalFrames(uint64_t value);
@ -91,6 +89,20 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
size_t &, void *), size_t &, void *),
void *arg); void *arg);
protected:
/**
* Align corresponding digital bits together (CTB only if ctbDbitlist is not
* empty)
* set variable reorder to true if data should be rearranged such that
* it groups each signal (0-63) from all the different samples together
*/
void ArrangeDbitData(size_t &size, char *data);
/**
* remove trailing bits in digital data stream
*/
void RemoveTrailingBits(size_t &size, char *data);
private: private:
void RecordFirstIndex(uint64_t fnum); void RecordFirstIndex(uint64_t fnum);
@ -137,12 +149,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
void PadMissingPackets(sls_receiver_header header, char *data); void PadMissingPackets(sls_receiver_header header, char *data);
/**
* Align corresponding digital bits together (CTB only if ctbDbitlist is not
* empty)
*/
void RearrangeDbitData(size_t &size, char *data);
void CropImage(size_t &size, char *data); void CropImage(size_t &size, char *data);
static const std::string typeName; static const std::string typeName;
@ -162,10 +168,8 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
uint32_t streamingTimerInMs; uint32_t streamingTimerInMs;
uint32_t streamingStartFnum; uint32_t streamingStartFnum;
uint32_t currentFreqCount{0}; uint32_t currentFreqCount{0};
struct timespec timerbegin {}; struct timespec timerbegin{};
bool framePadding; bool framePadding;
std::vector<int> ctbDbitList;
int ctbDbitOffset;
std::atomic<bool> startedFlag{false}; std::atomic<bool> startedFlag{false};
std::atomic<uint64_t> firstIndex{0}; std::atomic<uint64_t> firstIndex{0};
bool quadEnable{false}; bool quadEnable{false};

View File

@ -52,6 +52,9 @@ class GeneralData {
uint32_t nAnalogSamples{0}; uint32_t nAnalogSamples{0};
uint32_t nDigitalSamples{0}; uint32_t nDigitalSamples{0};
uint32_t nTransceiverSamples{0}; uint32_t nTransceiverSamples{0};
std::vector<int> ctbDbitList{};
int ctbDbitOffset{0};
bool ctbDbitReorder{false};
slsDetectorDefs::readoutMode readoutType{slsDetectorDefs::ANALOG_ONLY}; slsDetectorDefs::readoutMode readoutType{slsDetectorDefs::ANALOG_ONLY};
uint32_t adcEnableMaskOneGiga{BIT32_MASK}; uint32_t adcEnableMaskOneGiga{BIT32_MASK};
uint32_t adcEnableMaskTenGiga{BIT32_MASK}; uint32_t adcEnableMaskTenGiga{BIT32_MASK};
@ -60,8 +63,8 @@ class GeneralData {
slsDetectorDefs::frameDiscardPolicy frameDiscardMode{ slsDetectorDefs::frameDiscardPolicy frameDiscardMode{
slsDetectorDefs::NO_DISCARD}; slsDetectorDefs::NO_DISCARD};
GeneralData(){}; GeneralData() {};
virtual ~GeneralData(){}; virtual ~GeneralData() {};
// Returns the pixel depth in byte, 4 bits being 0.5 byte // Returns the pixel depth in byte, 4 bits being 0.5 byte
float GetPixelDepth() { return float(dynamicRange) / 8; } float GetPixelDepth() { return float(dynamicRange) / 8; }
@ -148,6 +151,18 @@ class GeneralData {
virtual void SetTransceiverEnableMask(int n) { virtual void SetTransceiverEnableMask(int n) {
ThrowGenericError("SetTransceiverEnableMask"); ThrowGenericError("SetTransceiverEnableMask");
}; };
virtual void SetctbDbitOffset(const int n) {
ThrowGenericError("SetctbDbitOffset");
};
virtual void SetctbDbitList(const std::vector<int> &value) {
ThrowGenericError("SetctbDbitList");
};
virtual void SetctbDbitReorder(const bool reorder) {
ThrowGenericError("SetctbDbitReorder");
};
}; };
class EigerData : public GeneralData { class EigerData : public GeneralData {
@ -387,6 +402,7 @@ class ChipTestBoardData : public GeneralData {
framesPerFile = CTB_MAX_FRAMES_PER_FILE; framesPerFile = CTB_MAX_FRAMES_PER_FILE;
fifoDepth = 2500; fifoDepth = 2500;
standardheader = true; standardheader = true;
ctbDbitReorder = true;
UpdateImageSize(); UpdateImageSize();
}; };
@ -412,6 +428,12 @@ class ChipTestBoardData : public GeneralData {
UpdateImageSize(); UpdateImageSize();
}; };
void SetctbDbitOffset(const int value) { ctbDbitOffset = value; }
void SetctbDbitList(const std::vector<int> &value) { ctbDbitList = value; }
void SetctbDbitReorder(const bool value) { ctbDbitReorder = value; }
void SetOneGigaAdcEnableMask(int n) { void SetOneGigaAdcEnableMask(int n) {
adcEnableMaskOneGiga = n; adcEnableMaskOneGiga = n;
UpdateImageSize(); UpdateImageSize();
@ -443,6 +465,7 @@ class ChipTestBoardData : public GeneralData {
nDigitalBytes = 0; nDigitalBytes = 0;
nTransceiverBytes = 0; nTransceiverBytes = 0;
int nAnalogChans = 0, nDigitalChans = 0, nTransceiverChans = 0; int nAnalogChans = 0, nDigitalChans = 0, nTransceiverChans = 0;
uint64_t digital_bytes_reserved = 0;
// analog channels (normal, analog/digital readout) // analog channels (normal, analog/digital readout)
if (readoutType == slsDetectorDefs::ANALOG_ONLY || if (readoutType == slsDetectorDefs::ANALOG_ONLY ||
@ -461,7 +484,12 @@ class ChipTestBoardData : public GeneralData {
readoutType == slsDetectorDefs::ANALOG_AND_DIGITAL || readoutType == slsDetectorDefs::ANALOG_AND_DIGITAL ||
readoutType == slsDetectorDefs::DIGITAL_AND_TRANSCEIVER) { readoutType == slsDetectorDefs::DIGITAL_AND_TRANSCEIVER) {
nDigitalChans = NCHAN_DIGITAL; nDigitalChans = NCHAN_DIGITAL;
nDigitalBytes = (sizeof(uint64_t) * nDigitalSamples); // allocate enough memory to support reordering of digital bits
uint32_t num_bytes_per_bit = (nDigitalSamples % 8 == 0)
? nDigitalSamples / 8
: nDigitalSamples / 8 + 1;
digital_bytes_reserved = 64 * num_bytes_per_bit;
nDigitalBytes = sizeof(uint64_t) * nDigitalSamples;
LOG(logDEBUG1) << "Number of Digital Channels:" << nDigitalChans LOG(logDEBUG1) << "Number of Digital Channels:" << nDigitalChans
<< " Databytes: " << nDigitalBytes; << " Databytes: " << nDigitalBytes;
} }
@ -480,7 +508,7 @@ class ChipTestBoardData : public GeneralData {
nPixelsX = nAnalogChans + nDigitalChans + nTransceiverChans; nPixelsX = nAnalogChans + nDigitalChans + nTransceiverChans;
dataSize = tengigaEnable ? 8144 : UDP_PACKET_DATA_BYTES; dataSize = tengigaEnable ? 8144 : UDP_PACKET_DATA_BYTES;
packetSize = headerSizeinPacket + dataSize; packetSize = headerSizeinPacket + dataSize;
imageSize = nAnalogBytes + nDigitalBytes + nTransceiverBytes; imageSize = nAnalogBytes + digital_bytes_reserved + nTransceiverBytes;
packetsPerFrame = ceil((double)imageSize / (double)dataSize); packetsPerFrame = ceil((double)imageSize / (double)dataSize);
LOG(logDEBUG1) << "Total Number of Channels:" << nPixelsX LOG(logDEBUG1) << "Total Number of Channels:" << nPixelsX
@ -512,6 +540,7 @@ class XilinxChipTestBoardData : public GeneralData {
dataSize = 8144; dataSize = 8144;
packetSize = headerSizeinPacket + dataSize; packetSize = headerSizeinPacket + dataSize;
tengigaEnable = true; tengigaEnable = true;
ctbDbitReorder = true;
UpdateImageSize(); UpdateImageSize();
}; };
@ -537,6 +566,12 @@ class XilinxChipTestBoardData : public GeneralData {
UpdateImageSize(); UpdateImageSize();
}; };
void SetctbDbitOffset(const int value) { ctbDbitOffset = value; }
void SetctbDbitList(const std::vector<int> &value) { ctbDbitList = value; }
void SetctbDbitReorder(const bool value) { ctbDbitReorder = value; }
void SetOneGigaAdcEnableMask(int n) { void SetOneGigaAdcEnableMask(int n) {
adcEnableMaskOneGiga = n; adcEnableMaskOneGiga = n;
UpdateImageSize(); UpdateImageSize();
@ -563,6 +598,7 @@ class XilinxChipTestBoardData : public GeneralData {
nDigitalBytes = 0; nDigitalBytes = 0;
nTransceiverBytes = 0; nTransceiverBytes = 0;
int nAnalogChans = 0, nDigitalChans = 0, nTransceiverChans = 0; int nAnalogChans = 0, nDigitalChans = 0, nTransceiverChans = 0;
uint64_t digital_bytes_reserved = 0;
// analog channels (normal, analog/digital readout) // analog channels (normal, analog/digital readout)
if (readoutType == slsDetectorDefs::ANALOG_ONLY || if (readoutType == slsDetectorDefs::ANALOG_ONLY ||
@ -580,7 +616,11 @@ class XilinxChipTestBoardData : public GeneralData {
readoutType == slsDetectorDefs::ANALOG_AND_DIGITAL || readoutType == slsDetectorDefs::ANALOG_AND_DIGITAL ||
readoutType == slsDetectorDefs::DIGITAL_AND_TRANSCEIVER) { readoutType == slsDetectorDefs::DIGITAL_AND_TRANSCEIVER) {
nDigitalChans = NCHAN_DIGITAL; nDigitalChans = NCHAN_DIGITAL;
nDigitalBytes = (sizeof(uint64_t) * nDigitalSamples); uint32_t num_bytes_per_bit = (nDigitalSamples % 8 == 0)
? nDigitalSamples / 8
: nDigitalSamples / 8 + 1;
digital_bytes_reserved = 64 * num_bytes_per_bit;
nDigitalBytes = sizeof(uint64_t) * nDigitalSamples;
LOG(logDEBUG1) << "Number of Digital Channels:" << nDigitalChans LOG(logDEBUG1) << "Number of Digital Channels:" << nDigitalChans
<< " Databytes: " << nDigitalBytes; << " Databytes: " << nDigitalBytes;
} }
@ -598,7 +638,7 @@ class XilinxChipTestBoardData : public GeneralData {
} }
nPixelsX = nAnalogChans + nDigitalChans + nTransceiverChans; nPixelsX = nAnalogChans + nDigitalChans + nTransceiverChans;
imageSize = nAnalogBytes + nDigitalBytes + nTransceiverBytes; imageSize = nAnalogBytes + digital_bytes_reserved + nTransceiverBytes;
packetsPerFrame = ceil((double)imageSize / (double)dataSize); packetsPerFrame = ceil((double)imageSize / (double)dataSize);
LOG(logDEBUG1) << "Total Number of Channels:" << nPixelsX LOG(logDEBUG1) << "Total Number of Channels:" << nPixelsX

View File

@ -200,8 +200,6 @@ void Implementation::SetupDataProcessor(int i) {
dataProcessor[i]->SetStreamingTimerInMs(streamingTimerInMs); dataProcessor[i]->SetStreamingTimerInMs(streamingTimerInMs);
dataProcessor[i]->SetStreamingStartFnum(streamingStartFnum); dataProcessor[i]->SetStreamingStartFnum(streamingStartFnum);
dataProcessor[i]->SetFramePadding(framePadding); dataProcessor[i]->SetFramePadding(framePadding);
dataProcessor[i]->SetCtbDbitList(ctbDbitList);
dataProcessor[i]->SetCtbDbitOffset(ctbDbitOffset);
dataProcessor[i]->SetQuadEnable(quadEnable); dataProcessor[i]->SetQuadEnable(quadEnable);
dataProcessor[i]->SetFlipRows(flipRows); dataProcessor[i]->SetFlipRows(flipRows);
dataProcessor[i]->SetNumberofTotalFrames(numberOfTotalFrames); dataProcessor[i]->SetNumberofTotalFrames(numberOfTotalFrames);
@ -990,9 +988,11 @@ void Implementation::StartMasterWriter() {
? 1 ? 1
: 0; : 0;
masterAttributes.digitalSamples = generalData->nDigitalSamples; masterAttributes.digitalSamples = generalData->nDigitalSamples;
masterAttributes.dbitoffset = ctbDbitOffset; masterAttributes.dbitoffset = generalData->ctbDbitOffset;
masterAttributes.dbitreorder = generalData->ctbDbitReorder;
masterAttributes.dbitlist = 0; masterAttributes.dbitlist = 0;
for (auto &i : ctbDbitList) {
for (auto &i : generalData->ctbDbitList) {
masterAttributes.dbitlist |= (static_cast<uint64_t>(1) << i); masterAttributes.dbitlist |= (static_cast<uint64_t>(1) << i);
} }
masterAttributes.transceiverSamples = masterAttributes.transceiverSamples =
@ -1748,22 +1748,29 @@ void Implementation::setTenGigaADCEnableMask(uint32_t mask) {
LOG(logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); LOG(logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame);
} }
std::vector<int> Implementation::getDbitList() const { return ctbDbitList; } std::vector<int> Implementation::getDbitList() const {
return generalData->ctbDbitList;
void Implementation::setDbitList(const std::vector<int> &v) {
ctbDbitList = v;
for (const auto &it : dataProcessor)
it->SetCtbDbitList(ctbDbitList);
LOG(logINFO) << "Dbit list: " << ToString(ctbDbitList);
} }
int Implementation::getDbitOffset() const { return ctbDbitOffset; } void Implementation::setDbitList(const std::vector<int> &v) {
generalData->SetctbDbitList(v);
LOG(logINFO) << "Dbit list: " << ToString(v);
}
int Implementation::getDbitOffset() const { return generalData->ctbDbitOffset; }
void Implementation::setDbitOffset(const int s) { void Implementation::setDbitOffset(const int s) {
ctbDbitOffset = s; generalData->SetctbDbitOffset(s);
for (const auto &it : dataProcessor) LOG(logINFO) << "Dbit offset: " << s;
it->SetCtbDbitOffset(ctbDbitOffset); }
LOG(logINFO) << "Dbit offset: " << ctbDbitOffset;
bool Implementation::getDbitReorder() const {
return generalData->ctbDbitReorder;
}
void Implementation::setDbitReorder(const bool reorder) {
generalData->SetctbDbitReorder(reorder);
LOG(logINFO) << "Dbit reorder: " << reorder;
} }
uint32_t Implementation::getTransceiverEnableMask() const { uint32_t Implementation::getTransceiverEnableMask() const {

View File

@ -252,6 +252,10 @@ class Implementation : private virtual slsDetectorDefs {
int getDbitOffset() const; int getDbitOffset() const;
/* [Ctb] */ /* [Ctb] */
void setDbitOffset(const int s); void setDbitOffset(const int s);
bool getDbitReorder() const;
/* [Ctb] */
void setDbitReorder(const bool reorder);
uint32_t getTransceiverEnableMask() const; uint32_t getTransceiverEnableMask() const;
/* [Ctb] */ /* [Ctb] */
void setTransceiverEnableMask(const uint32_t mask); void setTransceiverEnableMask(const uint32_t mask);
@ -366,8 +370,6 @@ class Implementation : private virtual slsDetectorDefs {
int thresholdEnergyeV{-1}; int thresholdEnergyeV{-1};
std::array<int, 3> thresholdAllEnergyeV = {{-1, -1, -1}}; std::array<int, 3> thresholdAllEnergyeV = {{-1, -1, -1}};
std::vector<int64_t> rateCorrections; std::vector<int64_t> rateCorrections;
std::vector<int> ctbDbitList;
int ctbDbitOffset{0};
// callbacks // callbacks
void (*startAcquisitionCallBack)(const startCallbackHeader, void (*startAcquisitionCallBack)(const startCallbackHeader,

View File

@ -551,6 +551,13 @@ void MasterAttributes::WriteHDF5DbitOffset(H5::H5File *fd, H5::Group *group) {
dataset.write(&dbitoffset, H5::PredType::NATIVE_INT); dataset.write(&dbitoffset, H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5DbitReorder(H5::H5File *fd, H5::Group *group) {
H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR);
H5::DataSet dataset = group->createDataSet(
"Dbit Reorder", H5::PredType::NATIVE_INT, dataspace);
dataset.write(&dbitreorder, H5::PredType::NATIVE_INT);
}
void MasterAttributes::WriteHDF5DbitList(H5::H5File *fd, H5::Group *group) { void MasterAttributes::WriteHDF5DbitList(H5::H5File *fd, H5::Group *group) {
H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR);
H5::DataSet dataset = group->createDataSet( H5::DataSet dataset = group->createDataSet(
@ -744,6 +751,8 @@ void MasterAttributes::GetCtbBinaryAttributes(
w->Uint(digitalSamples); w->Uint(digitalSamples);
w->Key("Dbit Offset"); w->Key("Dbit Offset");
w->Uint(dbitoffset); w->Uint(dbitoffset);
w->Key("Dbit Reorder");
w->Uint(dbitreorder);
w->Key("Dbit Bitset"); w->Key("Dbit Bitset");
w->Uint64(dbitlist); w->Uint64(dbitlist);
w->Key("Transceiver Mask"); w->Key("Transceiver Mask");
@ -766,6 +775,7 @@ void MasterAttributes::WriteCtbHDF5Attributes(H5::H5File *fd,
MasterAttributes::WriteHDF5DigitalFlag(fd, group); MasterAttributes::WriteHDF5DigitalFlag(fd, group);
MasterAttributes::WriteHDF5DigitalSamples(fd, group); MasterAttributes::WriteHDF5DigitalSamples(fd, group);
MasterAttributes::WriteHDF5DbitOffset(fd, group); MasterAttributes::WriteHDF5DbitOffset(fd, group);
MasterAttributes::WriteHDF5DbitReorder(fd, group);
MasterAttributes::WriteHDF5DbitList(fd, group); MasterAttributes::WriteHDF5DbitList(fd, group);
MasterAttributes::WriteHDF5TransceiverMask(fd, group); MasterAttributes::WriteHDF5TransceiverMask(fd, group);
MasterAttributes::WriteHDF5TransceiverFlag(fd, group); MasterAttributes::WriteHDF5TransceiverFlag(fd, group);
@ -791,6 +801,8 @@ void MasterAttributes::GetXilinxCtbBinaryAttributes(
w->Uint(digitalSamples); w->Uint(digitalSamples);
w->Key("Dbit Offset"); w->Key("Dbit Offset");
w->Uint(dbitoffset); w->Uint(dbitoffset);
w->Key("Dbit Reorder");
w->Uint(dbitreorder);
w->Key("Dbit Bitset"); w->Key("Dbit Bitset");
w->Uint64(dbitlist); w->Uint64(dbitlist);
w->Key("Transceiver Mask"); w->Key("Transceiver Mask");
@ -812,6 +824,7 @@ void MasterAttributes::WriteXilinxCtbHDF5Attributes(H5::H5File *fd,
MasterAttributes::WriteHDF5DigitalFlag(fd, group); MasterAttributes::WriteHDF5DigitalFlag(fd, group);
MasterAttributes::WriteHDF5DigitalSamples(fd, group); MasterAttributes::WriteHDF5DigitalSamples(fd, group);
MasterAttributes::WriteHDF5DbitOffset(fd, group); MasterAttributes::WriteHDF5DbitOffset(fd, group);
MasterAttributes::WriteHDF5DbitReorder(fd, group);
MasterAttributes::WriteHDF5DbitList(fd, group); MasterAttributes::WriteHDF5DbitList(fd, group);
MasterAttributes::WriteHDF5TransceiverMask(fd, group); MasterAttributes::WriteHDF5TransceiverMask(fd, group);
MasterAttributes::WriteHDF5TransceiverFlag(fd, group); MasterAttributes::WriteHDF5TransceiverFlag(fd, group);

View File

@ -51,6 +51,7 @@ class MasterAttributes {
uint32_t analogSamples{0}; uint32_t analogSamples{0};
uint32_t digital{0}; uint32_t digital{0};
uint32_t digitalSamples{0}; uint32_t digitalSamples{0};
uint32_t dbitreorder{1};
uint32_t dbitoffset{0}; uint32_t dbitoffset{0};
uint64_t dbitlist{0}; uint64_t dbitlist{0};
uint32_t transceiverMask{0}; uint32_t transceiverMask{0};
@ -104,6 +105,7 @@ class MasterAttributes {
void WriteHDF5DigitalSamples(H5::H5File *fd, H5::Group *group); void WriteHDF5DigitalSamples(H5::H5File *fd, H5::Group *group);
void WriteHDF5DbitOffset(H5::H5File *fd, H5::Group *group); void WriteHDF5DbitOffset(H5::H5File *fd, H5::Group *group);
void WriteHDF5DbitList(H5::H5File *fd, H5::Group *group); void WriteHDF5DbitList(H5::H5File *fd, H5::Group *group);
void WriteHDF5DbitReorder(H5::H5File *fd, H5::Group *group);
void WriteHDF5TransceiverMask(H5::H5File *fd, H5::Group *group); void WriteHDF5TransceiverMask(H5::H5File *fd, H5::Group *group);
void WriteHDF5TransceiverFlag(H5::H5File *fd, H5::Group *group); void WriteHDF5TransceiverFlag(H5::H5File *fd, H5::Group *group);
void WriteHDF5TransceiverSamples(H5::H5File *fd, H5::Group *group); void WriteHDF5TransceiverSamples(H5::H5File *fd, H5::Group *group);

View File

@ -146,8 +146,21 @@ void GetData(slsDetectorDefs::sls_receiver_header &header,
// header->packetsMask.to_string().c_str(), // header->packetsMask.to_string().c_str(),
((uint8_t)(*((uint8_t *)(dataPointer)))), imageSize); ((uint8_t)(*((uint8_t *)(dataPointer)))), imageSize);
// if data is modified, eg ROI and size is reduced // // example of how to use roi or modify data that is later written to file
imageSize = 26000; // slsDetectorDefs::ROI roi{0, 10, 0, 20};
// int width = roi.xmax - roi.xmin;
// int height = roi.ymax - roi.ymin;
// uint8_t *destPtr = (uint8_t *)dataPointer;
// for (int irow = roi.ymin; irow < roi.ymax; ++irow) {
// memcpy(destPtr,
// ((uint8_t *)(dataPointer + irow * callbackHeader.shape.x +
// roi.xmin)),
// width);
// destPtr += width;
// }
// memcpy((uint8_t*)dataPointer, (uint8_t*)dataPointer
// // setting roi for eg. changes size
// imageSize = width * height;
} }
/** /**

View File

@ -19,8 +19,8 @@ namespace sls {
// files // files
// versions // versions
#define HDF5_WRITER_VERSION (6.6) // 1 decimal places #define HDF5_WRITER_VERSION (6.7) // 1 decimal places
#define BINARY_WRITER_VERSION (7.2) // 1 decimal places #define BINARY_WRITER_VERSION (7.3) // 1 decimal places
#define MAX_FRAMES_PER_FILE 20000 #define MAX_FRAMES_PER_FILE 20000
#define SHORT_MAX_FRAMES_PER_FILE 100000 #define SHORT_MAX_FRAMES_PER_FILE 100000

View File

@ -3,6 +3,9 @@
target_sources(tests PRIVATE target_sources(tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/test-GeneralData.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-GeneralData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-CircularFifo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-CircularFifo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-ArrangeDataBasedOnBitList.cpp
) )
target_include_directories(tests PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src>") target_include_directories(tests PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src>")
message(STATUS "Resolved path: ${CMAKE_CURRENT_SOURCE_DIR}/../src")

View File

@ -0,0 +1,411 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2025 Contributors to the SLS Detector Package
/************************************************
* @file test-ArrangeDataBasedOnBitList.cpp
* @short test case for DataProcessor rearrange functions,
***********************************************/
#include "DataProcessor.h"
#include "GeneralData.h"
#include "catch.hpp"
#include <vector>
namespace sls {
// dummy GeneralData class for testing
class GeneralDataTest : public GeneralData {
public:
GeneralDataTest() { detType = slsDetectorDefs::CHIPTESTBOARD; }
int GetNumberOfAnalogDatabytes() { return nAnalogBytes; };
int GetNumberOfDigitalDatabytes() { return nDigitalBytes; };
int GetNumberOfTransceiverDatabytes() { return nTransceiverBytes; };
void SetNumberOfAnalogDatabytes(int value) { nAnalogBytes = value; }
void SetNumberOfDigitalDatabytes(int value) { nDigitalBytes = value; }
void SetNumberOfTransceiverDatabytes(int value) {
nTransceiverBytes = value;
}
void SetCtbDbitOffset(const int value) { ctbDbitOffset = value; }
void SetCtbDbitList(const std::vector<int> &value) { ctbDbitList = value; }
void SetCtbDbitReorder(const bool value) { ctbDbitReorder = value; }
private:
int nAnalogBytes{};
int nDigitalBytes{};
int nTransceiverBytes{};
};
// dummy DataProcessor class for testing
class DataProcessorTest : public DataProcessor {
public:
DataProcessorTest() : DataProcessor(0) {};
~DataProcessorTest() {};
void ArrangeDbitData(size_t &size, char *data) {
DataProcessor::ArrangeDbitData(size, data);
}
void RemoveTrailingBits(size_t &size, char *data) {
DataProcessor::RemoveTrailingBits(size, data);
}
};
/**
* test fixture for Testing,
* num_analog_bytes = 1 byte has a value of 125
* num_transceiver_bytes = 2 both bytes have a value of 125
* num_digital_bytes is variable and is defined by number of samples
* default num sample is 5
* all bytes in digital data take a value of 255
*/
class DataProcessorTestFixture {
public:
DataProcessorTestFixture() {
// setup Test Fixture
dataprocessor = new DataProcessorTest;
generaldata = new GeneralDataTest;
generaldata->SetNumberOfAnalogDatabytes(num_analog_bytes);
generaldata->SetNumberOfTransceiverDatabytes(num_transceiver_bytes);
generaldata->SetNumberOfDigitalDatabytes(num_digital_bytes +
num_random_offset_bytes);
dataprocessor->SetGeneralData(generaldata);
}
~DataProcessorTestFixture() {
delete[] data;
delete dataprocessor;
delete generaldata;
}
size_t get_size() const {
return num_analog_bytes + num_digital_bytes + num_transceiver_bytes +
num_random_offset_bytes;
}
void set_num_samples(const size_t value) {
num_samples = value;
num_digital_bytes = num_samples * 8; // 64 (8 bytes) per sample
generaldata->SetNumberOfDigitalDatabytes(num_digital_bytes +
num_random_offset_bytes);
}
void set_random_offset_bytes(const size_t value) {
num_random_offset_bytes = value;
generaldata->SetNumberOfDigitalDatabytes(num_digital_bytes +
num_random_offset_bytes);
}
void set_data() {
delete[] data;
uint64_t max_bytes_per_bit =
num_samples % 8 == 0 ? num_samples / 8 : num_samples / 8 + 1;
uint64_t reserved_size =
get_size() - num_digital_bytes + max_bytes_per_bit * 64;
data = new char[reserved_size];
// set testing data
memset(data, dummy_value, num_analog_bytes); // set to dummy value
memset(data + num_analog_bytes, 0,
num_random_offset_bytes); // set to zero
memset(data + num_analog_bytes + num_random_offset_bytes, 0xFF,
num_digital_bytes); // all digital bits are one
memset(data + num_digital_bytes + num_analog_bytes +
num_random_offset_bytes,
dummy_value,
num_transceiver_bytes); // set to dummy value
}
DataProcessorTest *dataprocessor;
GeneralDataTest *generaldata;
const size_t num_analog_bytes = 1;
const size_t num_transceiver_bytes = 2;
const char dummy_value = static_cast<char>(125);
size_t num_digital_bytes = 40; // num_samples * 8 = 5 * 8 = 40
size_t num_random_offset_bytes = 0;
size_t num_samples = 5;
char *data = nullptr;
};
TEST_CASE_METHOD(DataProcessorTestFixture, "Remove Trailing Bits",
"[.dataprocessor][.bitoffset]") {
const size_t num_random_offset_bytes = 3;
set_random_offset_bytes(num_random_offset_bytes);
set_data();
generaldata->SetCtbDbitOffset(num_random_offset_bytes);
size_t expected_size = get_size() - num_random_offset_bytes;
char *expected_data = new char[expected_size];
memset(expected_data, dummy_value, num_analog_bytes); // set to 125
memset(expected_data + num_analog_bytes, 0xFF,
num_digital_bytes); // set to 1
memset(expected_data + num_digital_bytes + num_analog_bytes, dummy_value,
num_transceiver_bytes); // set to 125
size_t size = get_size();
dataprocessor->RemoveTrailingBits(size, data);
CHECK(size == expected_size);
CHECK(memcmp(data, expected_data, expected_size) == 0);
delete[] expected_data;
}
// parametric test tested with num_samples = 5, num_samples = 10, num_samples =
// 8
TEST_CASE_METHOD(DataProcessorTestFixture, "Reorder all",
"[.dataprocessor][.reorder]") {
// parameters: num_samples, expected_num_digital_bytes,
// expected_digital_part
auto parameters = GENERATE(
std::make_tuple(5, 64, std::vector<uint8_t>{0b00011111}),
std::make_tuple(10, 2 * 64, std::vector<uint8_t>{0xFF, 0b00000011}),
std::make_tuple(8, 64, std::vector<uint8_t>{0xFF}));
size_t num_samples, expected_num_digital_bytes;
std::vector<uint8_t> expected_digital_part;
std::tie(num_samples, expected_num_digital_bytes, expected_digital_part) =
parameters;
// set number of samples for test fixture -> create data
set_num_samples(num_samples);
set_data();
std::vector<int> bitlist(64);
std::iota(bitlist.begin(), bitlist.end(), 0);
generaldata->SetCtbDbitList(bitlist);
generaldata->SetCtbDbitReorder(true); // set reorder to true
const size_t expected_size =
num_analog_bytes + num_transceiver_bytes + expected_num_digital_bytes;
// create expected data
char *expected_data = new char[expected_size];
memset(expected_data, dummy_value, num_analog_bytes); // set to 125
for (size_t bit = 0; bit < 64; ++bit) {
memcpy(expected_data + num_analog_bytes +
expected_digital_part.size() * bit,
expected_digital_part.data(), expected_digital_part.size());
}
memset(expected_data + expected_num_digital_bytes + num_analog_bytes,
dummy_value,
num_transceiver_bytes); // set to 125
size_t size = get_size();
dataprocessor->ArrangeDbitData(size, data); // call reorder
CHECK(size == expected_size);
CHECK(memcmp(data, expected_data, expected_size) == 0);
delete[] expected_data;
}
TEST_CASE_METHOD(DataProcessorTestFixture,
"Reorder all and remove trailing bits",
"[.dataprocessor][.reorder]") {
// set number of samples for test fixture -> create data
const size_t num_random_offset_bytes = 3;
set_random_offset_bytes(num_random_offset_bytes);
set_data();
std::vector<int> bitlist(64);
std::iota(bitlist.begin(), bitlist.end(), 0);
generaldata->SetCtbDbitList(bitlist);
generaldata->SetCtbDbitOffset(num_random_offset_bytes);
generaldata->SetCtbDbitReorder(true); // set reorder to true
const size_t expected_num_digital_bytes = 64;
std::vector<uint8_t> expected_digital_part{0b00011111};
const size_t expected_size =
num_analog_bytes + num_transceiver_bytes + expected_num_digital_bytes;
// create expected data
char *expected_data = new char[expected_size];
memset(expected_data, dummy_value, num_analog_bytes); // set to 125
for (size_t bit = 0; bit < 64; ++bit) {
memcpy(expected_data + num_analog_bytes +
expected_digital_part.size() * bit,
expected_digital_part.data(), expected_digital_part.size());
}
memset(expected_data + expected_num_digital_bytes + num_analog_bytes,
dummy_value,
num_transceiver_bytes); // set to 125
size_t size = get_size();
dataprocessor->ArrangeDbitData(size, data); // call reorder
CHECK(size == expected_size);
CHECK(memcmp(data, expected_data, expected_size) == 0);
delete[] expected_data;
}
TEST_CASE_METHOD(DataProcessorTestFixture, "Arrange bitlist with reorder false",
"[.dataprocessor][.retrievebitlist]") {
// parameters: num_samples, bitlist, expected_num_digital_bytes,
// expected_digital_part
auto parameters = GENERATE(
std::make_tuple(5, std::vector<int>{1, 4, 5}, 5,
std::vector<uint8_t>{0b00000111}),
std::make_tuple(5, std::vector<int>{1, 5, 3, 7, 8, 50, 42, 60, 39}, 10,
std::vector<uint8_t>{0xFF, 0b00000001}),
std::make_tuple(5, std::vector<int>{1, 5, 3, 7, 8, 50, 42, 60}, 5,
std::vector<uint8_t>{0xFF}));
size_t num_samples, expected_num_digital_bytes;
std::vector<uint8_t> expected_digital_part;
std::vector<int> bitlist;
std::tie(num_samples, bitlist, expected_num_digital_bytes,
expected_digital_part) = parameters;
generaldata->SetCtbDbitList(bitlist);
generaldata->SetCtbDbitReorder(false);
set_num_samples(num_samples);
set_data();
size_t expected_size =
num_analog_bytes + num_transceiver_bytes + expected_num_digital_bytes;
// create expected data
char *expected_data = new char[expected_size];
memset(expected_data, dummy_value, num_analog_bytes);
for (size_t sample = 0; sample < num_samples; ++sample) {
memcpy(expected_data + num_analog_bytes +
expected_digital_part.size() * sample,
expected_digital_part.data(), expected_digital_part.size());
}
memset(expected_data + expected_num_digital_bytes + num_analog_bytes,
dummy_value, num_transceiver_bytes);
size_t size = get_size();
dataprocessor->ArrangeDbitData(size, data);
CHECK(size == expected_size);
CHECK(memcmp(data, expected_data, expected_size) == 0);
delete[] expected_data;
}
TEST_CASE_METHOD(DataProcessorTestFixture, "Arrange bitlist with reorder true",
"[.dataprocessor][.retrievebitlist]") {
// parameters: num_samples, bitlist, expected_num_digital_bytes,
// expected_digital_part
auto parameters = GENERATE(
std::make_tuple(5, std::vector<int>{1, 4, 5}, 3,
std::vector<uint8_t>{0b00011111}),
std::make_tuple(10, std::vector<int>{1, 4, 5}, 6,
std::vector<uint8_t>{0xFF, 0b00000011}),
std::make_tuple(8, std::vector<int>{1, 5, 3, 7, 8, 50, 42, 60, 39}, 9,
std::vector<uint8_t>{0xFF}));
size_t num_samples, expected_num_digital_bytes;
std::vector<uint8_t> expected_digital_part;
std::vector<int> bitlist;
std::tie(num_samples, bitlist, expected_num_digital_bytes,
expected_digital_part) = parameters;
generaldata->SetCtbDbitList(bitlist);
generaldata->SetCtbDbitReorder(true);
set_num_samples(num_samples);
set_data();
size_t expected_size =
num_analog_bytes + num_transceiver_bytes + expected_num_digital_bytes;
// create expected data
char *expected_data = new char[expected_size];
memset(expected_data, dummy_value, num_analog_bytes);
for (size_t sample = 0; sample < bitlist.size(); ++sample) {
memcpy(expected_data + num_analog_bytes +
expected_digital_part.size() * sample,
expected_digital_part.data(), expected_digital_part.size());
}
memset(expected_data + expected_num_digital_bytes + num_analog_bytes,
dummy_value, num_transceiver_bytes);
size_t size = get_size();
dataprocessor->ArrangeDbitData(size, data);
CHECK(size == expected_size);
CHECK(memcmp(data, expected_data, expected_size) == 0);
delete[] expected_data;
}
TEST_CASE_METHOD(DataProcessorTestFixture,
"Arrange bitlist and remove trailing bits",
"[.dataprocessor][.retrievebitlist]") {
size_t num_random_offset_bytes = 3;
std::vector<int> bitlist{1, 4, 5};
set_random_offset_bytes(num_random_offset_bytes);
set_data();
generaldata->SetCtbDbitList(bitlist);
generaldata->SetCtbDbitReorder(false);
generaldata->SetCtbDbitOffset(num_random_offset_bytes);
std::vector<uint8_t> expected_digital_part{0b00000111};
const size_t expected_num_digital_bytes = 5;
size_t expected_size =
num_analog_bytes + num_transceiver_bytes + expected_num_digital_bytes;
// create expected data
char *expected_data = new char[expected_size];
memset(expected_data, dummy_value, num_analog_bytes);
for (size_t sample = 0; sample < num_samples; ++sample) {
memcpy(expected_data + num_analog_bytes +
expected_digital_part.size() * sample,
expected_digital_part.data(), expected_digital_part.size());
}
memset(expected_data + expected_num_digital_bytes + num_analog_bytes,
dummy_value, num_transceiver_bytes);
size_t size = get_size();
dataprocessor->ArrangeDbitData(size, data);
CHECK(size == expected_size);
CHECK(memcmp(data, expected_data, expected_size) == 0);
delete[] expected_data;
}
} // namespace sls

View File

@ -410,6 +410,8 @@ enum detFuncs {
F_RECEIVER_SET_TRANSCEIVER_MASK, F_RECEIVER_SET_TRANSCEIVER_MASK,
F_RECEIVER_SET_ROW, F_RECEIVER_SET_ROW,
F_RECEIVER_SET_COLUMN, F_RECEIVER_SET_COLUMN,
F_GET_RECEIVER_DBIT_REORDER,
F_SET_RECEIVER_DBIT_REORDER,
NUM_REC_FUNCTIONS NUM_REC_FUNCTIONS
}; };
@ -816,7 +818,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_RECEIVER_SET_TRANSCEIVER_MASK: return "F_RECEIVER_SET_TRANSCEIVER_MASK"; case F_RECEIVER_SET_TRANSCEIVER_MASK: return "F_RECEIVER_SET_TRANSCEIVER_MASK";
case F_RECEIVER_SET_ROW: return "F_RECEIVER_SET_ROW"; case F_RECEIVER_SET_ROW: return "F_RECEIVER_SET_ROW";
case F_RECEIVER_SET_COLUMN: return "F_RECEIVER_SET_COLUMN"; case F_RECEIVER_SET_COLUMN: return "F_RECEIVER_SET_COLUMN";
case F_GET_RECEIVER_DBIT_REORDER: return "F_GET_RECEIVER_DBIT_REORDER";
case F_SET_RECEIVER_DBIT_REORDER: return "F_SET_RECEIVER_DBIT_REORDER";
case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS"; case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS";
default: return "Unknown Function"; default: return "Unknown Function";

View File

@ -5,8 +5,8 @@
#define APIRECEIVER "developer 0x241122" #define APIRECEIVER "developer 0x241122"
#define APICTB "developer 0x250310" #define APICTB "developer 0x250310"
#define APIGOTTHARD2 "developer 0x250310" #define APIGOTTHARD2 "developer 0x250310"
#define APIMYTHEN3 "developer 0x250310"
#define APIMOENCH "developer 0x250310" #define APIMOENCH "developer 0x250310"
#define APIEIGER "developer 0x250310" #define APIEIGER "developer 0x250310"
#define APIXILINXCTB "developer 0x250311" #define APIXILINXCTB "developer 0x250311"
#define APIJUNGFRAU "developer 0x250318" #define APIJUNGFRAU "developer 0x250318"
#define APIMYTHEN3 "developer 0x250409"

View File

@ -4,7 +4,7 @@
This file is used to start up simulators, receivers and run all the tests on them and finally kill the simulators and receivers. This file is used to start up simulators, receivers and run all the tests on them and finally kill the simulators and receivers.
''' '''
import argparse import argparse
import os, sys, subprocess, time, colorama, signal import os, sys, subprocess, time, colorama
from colorama import Fore from colorama import Fore
from slsdet import Detector, detectorType, detectorSettings from slsdet import Detector, detectorType, detectorSettings
@ -23,23 +23,9 @@ def Log(color, message):
def checkIfProcessRunning(processName): def checkIfProcessRunning(processName):
cmd = "ps -ef | grep " + processName cmd = f"pgrep -f {processName}"
print(cmd) res = subprocess.getoutput(cmd)
res=subprocess.getoutput(cmd) return bool(res.strip())
print(res)
# eg. of output
#l_user 250506 243295 0 14:38 pts/5 00:00:00 /bin/sh -c ps -ef | grep slsReceiver
#l_user 250508 250506 0 14:38 pts/5 00:00:00 grep slsReceiver
print('how many')
cmd = "ps -ef | grep " + processName + " | wc -l"
print(cmd)
res=subprocess.getoutput(cmd)
print(res)
if res == '2':
return False
return True
def killProcess(name): def killProcess(name):
@ -52,7 +38,7 @@ def killProcess(name):
print('process not running : ' + name) print('process not running : ' + name)
def killAllStaleProcesses(): def killAllStaleProcesses(fp):
killProcess('eigerDetectorServer_virtual') killProcess('eigerDetectorServer_virtual')
killProcess('jungfrauDetectorServer_virtual') killProcess('jungfrauDetectorServer_virtual')
killProcess('mythen3DetectorServer_virtual') killProcess('mythen3DetectorServer_virtual')
@ -62,9 +48,9 @@ def killAllStaleProcesses():
killProcess('xilinx_ctbDetectorServer_virtual') killProcess('xilinx_ctbDetectorServer_virtual')
killProcess('slsReceiver') killProcess('slsReceiver')
killProcess('slsMultiReceiver') killProcess('slsMultiReceiver')
cleanSharedmemory() cleanSharedmemory(fp)
def cleanup(name): def cleanup(name, fp):
''' '''
kill both servers, receivers and clean shared memory kill both servers, receivers and clean shared memory
''' '''
@ -72,9 +58,9 @@ def cleanup(name):
killProcess(name + 'DetectorServer_virtual') killProcess(name + 'DetectorServer_virtual')
killProcess('slsReceiver') killProcess('slsReceiver')
killProcess('slsMultiReceiver') killProcess('slsMultiReceiver')
cleanSharedmemory() cleanSharedmemory(fp)
def cleanSharedmemory(): def cleanSharedmemory(fp):
Log(Fore.GREEN, 'Cleaning up shared memory...') Log(Fore.GREEN, 'Cleaning up shared memory...')
try: try:
p = subprocess.run(['sls_detector_get', 'free'], stdout=fp, stderr=fp) p = subprocess.run(['sls_detector_get', 'free'], stdout=fp, stderr=fp)
@ -87,8 +73,8 @@ def startProcessInBackground(name):
# in background and dont print output # in background and dont print output
p = subprocess.Popen(name.split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, restore_signals=False) p = subprocess.Popen(name.split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, restore_signals=False)
Log(Fore.GREEN, 'Starting up ' + name + ' ...') Log(Fore.GREEN, 'Starting up ' + name + ' ...')
except: except Exception as e:
Log(Fore.RED, 'Could not start ' + name) Log(Fore.RED, f'Could not start {name}:{e}')
raise raise
def startServer(name): def startServer(name):
@ -139,14 +125,19 @@ def loadConfig(name, rx_hostname, settingsdir):
def startCmdTests(name, fp, fname): def startCmdTests(name, fp, fname):
Log(Fore.GREEN, 'Cmd Tests for ' + name) Log(Fore.GREEN, 'Cmd Tests for ' + name)
cmd = 'tests --abort [.cmdcall] -s -o ' + fname cmd = 'tests --abort [.cmdcall] -s -o ' + fname
p = subprocess.run(cmd.split(), stdout=fp, stderr=fp, check=True, text=True) try:
p.check_returncode() subprocess.run(cmd.split(), stdout=fp, stderr=fp, check=True, text=True)
except subprocess.CalledProcessError as e:
pass
with open (fname, 'r') as f: with open (fname, 'r') as f:
for line in f: for line in f:
if "FAILED" in line: if "FAILED" in line:
msg = 'Cmd tests failed for ' + name + '!!!' msg = 'Cmd tests failed for ' + name + '!!!'
sys.stdout = original_stdout
Log(Fore.RED, msg) Log(Fore.RED, msg)
Log(Fore.RED, line)
sys.stdout = fp
raise Exception(msg) raise Exception(msg)
Log(Fore.GREEN, 'Cmd Tests successful for ' + name) Log(Fore.GREEN, 'Cmd Tests successful for ' + name)
@ -154,14 +145,18 @@ def startCmdTests(name, fp, fname):
def startGeneralTests(fp, fname): def startGeneralTests(fp, fname):
Log(Fore.GREEN, 'General Tests') Log(Fore.GREEN, 'General Tests')
cmd = 'tests --abort -s -o ' + fname cmd = 'tests --abort -s -o ' + fname
p = subprocess.run(cmd.split(), stdout=fp, stderr=fp, check=True, text=True) try:
p.check_returncode() subprocess.run(cmd.split(), stdout=fp, stderr=fp, check=True, text=True)
except subprocess.CalledProcessError as e:
pass
with open (fname, 'r') as f: with open (fname, 'r') as f:
for line in f: for line in f:
if "FAILED" in line: if "FAILED" in line:
msg = 'General tests failed !!!' msg = 'General tests failed !!!'
Log(Fore.RED, msg) sys.stdout = original_stdout
Log(Fore.RED, msg + '\n' + line)
sys.stdout = fp
raise Exception(msg) raise Exception(msg)
Log(Fore.GREEN, 'General Tests successful') Log(Fore.GREEN, 'General Tests successful')
@ -170,12 +165,10 @@ def startGeneralTests(fp, fname):
# parse cmd line for rx_hostname and settingspath using the argparse library # parse cmd line for rx_hostname and settingspath using the argparse library
parser = argparse.ArgumentParser(description = 'automated tests with the virtual detector servers') parser = argparse.ArgumentParser(description = 'automated tests with the virtual detector servers')
parser.add_argument('rx_hostname', help = 'hostname/ip of the current machine') parser.add_argument('rx_hostname', nargs='?', default='localhost', help = 'hostname/ip of the current machine')
parser.add_argument('settingspath', help = 'Relative or absolut path to the settingspath') parser.add_argument('settingspath', nargs='?', default='../../settingsdir', help = 'Relative or absolut path to the settingspath')
parser.add_argument('-s', '--servers', help='Detector servers to run', nargs='*') parser.add_argument('-s', '--servers', help='Detector servers to run', nargs='*')
args = parser.parse_args() args = parser.parse_args()
if args.rx_hostname == 'localhost':
raise RuntimeException('Cannot use localhost for rx_hostname for the tests (fails for rx_arping for eg.)')
if args.servers is None: if args.servers is None:
servers = [ servers = [
@ -203,46 +196,59 @@ Log(Fore.BLUE, '\nLog File: ' + fname)
with open(fname, 'w') as fp: with open(fname, 'w') as fp:
# general tests # general tests
file_results = prefix_fname + '_results_general.txt' file_results = prefix_fname + '_results_general.txt'
Log(Fore.BLUE, 'General tests (results: ' + file_results + ')') Log(Fore.BLUE, 'General tests (results: ' + file_results + ')')
sys.stdout = fp sys.stdout = fp
sys.stderr = fp sys.stderr = fp
Log(Fore.BLUE, 'General tests (results: ' + file_results + ')') Log(Fore.BLUE, 'General tests (results: ' + file_results + ')')
startGeneralTests(fp, file_results)
killAllStaleProcesses() try:
startGeneralTests(fp, file_results)
killAllStaleProcesses(fp)
for server in servers: testError = False
try: for server in servers:
# print to terminal for progress try:
sys.stdout = original_stdout # print to terminal for progress
sys.stderr = original_stderr sys.stdout = original_stdout
file_results = prefix_fname + '_results_cmd_' + server + '.txt' sys.stderr = original_stderr
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')') file_results = prefix_fname + '_results_cmd_' + server + '.txt'
sys.stdout = fp Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
sys.stderr = fp sys.stdout = fp
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')') sys.stderr = fp
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
# cmd tests for det
cleanup(server) # cmd tests for det
startServer(server) cleanup(server, fp)
startReceiver(server) startServer(server)
loadConfig(server, args.rx_hostname, args.settingspath) startReceiver(server)
startCmdTests(server, fp, file_results) loadConfig(server, args.rx_hostname, args.settingspath)
cleanup(server) startCmdTests(server, fp, file_results)
except: cleanup(server, fp)
Log(Fore.RED, 'Exception caught. Cleaning up.')
cleanup(server) except Exception as e:
sys.stdout = original_stdout # redirect to terminal
sys.stderr = original_stderr sys.stdout = original_stdout
Log(Fore.RED, 'Cmd tests failed for ' + server + '!!!') sys.stderr = original_stderr
raise Log(Fore.RED, f'Exception caught while testing {server}. Cleaning up...')
testError = True
break
# redirect to terminal
sys.stdout = original_stdout
sys.stderr = original_stderr
if not testError:
Log(Fore.GREEN, 'Passed all tests for virtual detectors \n' + str(servers))
Log(Fore.GREEN, 'Passed all tests for virtual detectors \n' + str(servers)) except Exception as e:
# redirect to terminal
sys.stdout = original_stdout
sys.stderr = original_stderr
Log(Fore.RED, f'Exception caught with general testing. Cleaning up...')
cleanSharedmemory(sys.stdout)
# redirect to terminal
sys.stdout = original_stdout
sys.stderr = original_stderr
Log(Fore.GREEN, 'Passed all tests for virtual detectors \n' + str(servers) + '\nYayyyy! :) ')

View File

@ -5,7 +5,12 @@ Script to update VERSION file with semantic versioning if provided as an argumen
""" """
import sys import sys
import re import os
from packaging.version import Version, InvalidVersion
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
def get_version(): def get_version():
@ -14,23 +19,24 @@ def get_version():
return "0.0.0" return "0.0.0"
version = sys.argv[1] version = sys.argv[1]
# Validate that the version argument matches semantic versioning format (X.Y.Z) try:
if not re.match(r'^\d+\.\d+\.\d+$', version): v = Version(version) # normalizcheck if version follows PEP 440 specification
print("Error: Version argument must be in semantic versioning format (X.Y.Z)") #replace -
return version.replace("-", ".")
except InvalidVersion as e:
print(f"Invalid version {version}. Version format must follow semantic versioning format of python PEP 440 version identification specification.")
sys.exit(1) sys.exit(1)
return version
def write_version_to_file(version): def write_version_to_file(version):
with open("VERSION", "w") as version_file: version_file_path = os.path.join(SCRIPT_DIR, "VERSION")
with open(version_file_path, "w") as version_file:
version_file.write(version) version_file.write(version)
print(f"Version {version} written to VERSION file.") print(f"Version {version} written to VERSION file.")
# Main script # Main script
if __name__ == "__main__": if __name__ == "__main__":
version = get_version() version = get_version()
write_version_to_file(version) write_version_to_file(version)