Compare commits

..

161 Commits

Author SHA1 Message Date
d81587646e merge from developer on commit b6db097800 to properly clear udp destination in fpga for jungfrau mainly 2022-09-02 09:57:11 +02:00
5508f0135d merge fix 2022-03-21 11:08:02 +01:00
f2b8aa9dbd Merge branch 'developer' into rr_rxr 2022-03-21 10:56:41 +01:00
3250dda7eb fix warning 2022-03-21 10:56:10 +01:00
e554099bd9 binaries in 2022-03-21 10:34:09 +01:00
001fcf03d9 merge fix 2022-03-21 10:32:49 +01:00
2fe24c108b Merge pull request #409 from slsdetectorgroup/serverhelpsize
Serverhelpsize
2022-03-18 12:09:08 +01:00
bbfe3b278f binaries in 2022-03-18 12:07:47 +01:00
c9fd8ba569 qip 2022-03-18 12:07:15 +01:00
faa4f09a82 qip 2022-03-18 12:03:34 +01:00
1ca2e61a85 qip 2022-03-18 12:02:53 +01:00
7fa51e2a8e check if size exceeds capacity in server command line help 2022-03-18 12:01:16 +01:00
4a663e9e50 Merge pull request #408 from slsdetectorgroup/metadataGeometry
Metadata geometry
2022-03-17 11:29:23 +01:00
b02dec8157 Merge branch 'developer' into metadataGeometry 2022-03-17 11:29:15 +01:00
c361b9517c Merge pull request #407 from slsdetectorgroup/stopfnum
Stopfnum
2022-03-17 11:28:32 +01:00
78823760b3 more checks in generate functions 2022-03-17 09:52:39 +01:00
561777dad6 fixed clang--format version 2022-03-17 09:02:40 +01:00
7b66466186 Merge branch 'developer' into metadataGeometry 2022-03-17 08:47:34 +01:00
ef1c52ddc1 merge conflict fix 2022-03-17 08:46:04 +01:00
7bd4b9d9d9 Merge pull request #397 from slsdetectorgroup/setmaster
Setmaster
2022-03-17 08:42:06 +01:00
39d3ee2b15 merge fix 2022-03-17 08:41:49 +01:00
401467c700 updated scripts and generated detector.cpp 2022-03-16 18:29:33 +01:00
c9769579e3 Merge pull request #388 from slsdetectorgroup/eiger12
eiger 12 bit mode
2022-03-16 16:50:41 +01:00
7663d4ef53 udpated release notes 2022-03-16 16:12:58 +01:00
9c1bc262e5 added geometry to master file 2022-03-16 16:09:50 +01:00
c17914e0a1 split MasterAtrributes into cpp 2022-03-16 15:49:06 +01:00
7d91a15834 Merge branch 'setmaster' of github.com:slsdetectorgroup/slsDetectorPackage into setmaster 2022-03-16 14:50:40 +01:00
43c46841c1 minor 2022-03-16 14:44:26 +01:00
fc6c6985e6 binary in 2022-03-16 13:26:28 +01:00
14c63810d6 minor 2022-03-16 13:23:23 +01:00
6f0eebfbb8 fix 2022-03-16 13:18:59 +01:00
c8bed64b91 Merge branch 'setmaster' of github.com:slsdetectorgroup/slsDetectorPackage into setmaster 2022-03-16 13:16:31 +01:00
e1762605e8 fix for eiger server actual detector 2022-03-16 13:16:25 +01:00
62fff64d87 eiger binary in 2022-03-16 12:51:53 +01:00
7a39822813 fixes for set top, masterin api 2022-03-16 12:49:22 +01:00
de9e83fd61 set slave for m3 virtual 2022-03-16 12:07:03 +01:00
80d31bbb10 added tests 2022-03-16 11:35:27 +01:00
45171d82a4 minor 2022-03-16 09:56:03 +01:00
9e050060f3 eiger binary in 2022-03-15 17:18:56 +01:00
ed5a1cdf1c eiger: get nextframenumber for 10g fixed (was connected to 1g registers for get), eiger/jungfrau/ctb/moench: if after a stop the next framenumbers are inconsistent, then it will get their max value andf set to +1 2022-03-15 17:17:28 +01:00
34588356e8 added top 2022-02-28 17:05:24 +01:00
b6d63a8381 master tests 2022-02-28 16:28:15 +01:00
dd8aebb0ab eiger server binaries 2022-02-28 14:56:40 +01:00
261ac78743 wip 2022-02-28 14:49:02 +01:00
0437bd0584 Wip 2022-02-28 12:28:03 +01:00
46578d1447 wip 2022-02-25 17:50:32 +01:00
5566cfd24f configuing master from command lineg 2022-02-25 16:03:11 +01:00
5869c25658 wip, top, master command line 2022-02-24 17:06:10 +01:00
0b7c202f98 datastream 10g Receiver (#401)
* datastream not updated when tengiga enabled in receiver
2022-02-24 16:16:48 +01:00
219318a52e wip, removed extra virutal server binaries for eiger, --ignore-config for command line 2022-02-23 17:31:46 +01:00
89edf58f41 wip, setmaster 2022-02-23 12:26:37 +01:00
ef3df36e55 merge fix 2022-02-23 11:40:50 +01:00
6d2302bcc1 Merge branch 'developer' into eiger12 2022-02-23 10:32:22 +01:00
939fc70284 bug fix in startDetector vector 2022-02-23 10:32:06 +01:00
6695b10354 binaries in 2022-02-23 10:30:05 +01:00
94adba72bf bugfix for 12bit to 16 bit expansion in server 2022-02-23 10:26:37 +01:00
1063e8b929 warnings 2022-02-23 10:09:06 +01:00
c9abeace8f warnings 2022-02-23 10:08:50 +01:00
5bfdbf59a2 warnings 2022-02-23 10:07:00 +01:00
1cd347a54d minor printing 2022-02-23 10:03:23 +01:00
76eb09eb04 binaries in 2022-02-23 09:59:41 +01:00
a936cc26cc bugfix, always 12 dr 2022-02-23 09:58:55 +01:00
92beb3aa2a bug fix from an earlier PR, slaves.begin() 2022-02-23 09:32:25 +01:00
543eb7bb60 merge fixed 2022-02-23 09:23:00 +01:00
2034362eca Merge pull request #396 from slsdetectorgroup/ctbupdate
updatemode
2022-02-23 09:16:00 +01:00
7245db5cc8 binaries in 2022-02-23 09:15:20 +01:00
8c4a4b7182 merge fix 2022-02-23 09:14:43 +01:00
11ad019d47 changing manual list size entry for allowed funcs in server update mode 2022-02-23 09:12:51 +01:00
e29d73251e Merge pull request #391 from slsdetectorgroup/missingsigned
signed num missing packets
2022-02-23 09:01:43 +01:00
c14fb92c16 hostname command failed when connecting to servers in update mode 2022-02-22 16:50:12 +01:00
e4b80703ae wip 2022-02-22 15:27:27 +01:00
2b2533f465 allowing setmaster for eiger 2022-02-22 15:23:04 +01:00
8f632db2a0 get number of missing packets now returns signed so negative numbers mean extra packets 2022-02-22 10:27:22 +01:00
daa536077d merge fix 2022-02-21 15:14:47 +01:00
bf1df92303 Merge pull request #390 from slsdetectorgroup/startmodular
startdetector
2022-02-21 15:14:01 +01:00
5e97bcde7f startdetector (non blocking) is allowed at modular level 2022-02-21 09:42:24 +01:00
aa7dee1011 release notes 2022-02-21 09:01:14 +01:00
54313af2f8 revert cmkae 2022-02-18 16:17:34 +01:00
ab302a5160 hdf5 works 2022-02-18 16:16:46 +01:00
7a607c6dd1 refactored 2022-02-18 16:08:04 +01:00
83ff4ab112 hdf5 doestn work yet, wip 2022-02-18 15:51:54 +01:00
fb631187fa binaries in 2022-02-18 14:29:46 +01:00
8770c9f6fb fix, wip 2022-02-18 14:27:50 +01:00
6e0d7b91bd wip, fix for dr 12 2022-02-18 14:19:21 +01:00
6433704086 fixed virtual server fake data for 12 bit mode 2022-02-18 13:21:21 +01:00
aea0efa1b6 Merge branch 'eiger12' of github.com:slsdetectorgroup/slsDetectorPackage into eiger12 2022-02-18 11:45:11 +01:00
8ffa2c1d65 dr>0 fix in server 2022-02-18 11:45:03 +01:00
47f9ab4027 binaries in 2022-02-18 11:39:42 +01:00
0d521b64b6 fix 2022-02-18 11:38:37 +01:00
0fb6c8b823 updating dr 12 in server, changing signature to get fail for getdynamicrange 2022-02-18 10:32:07 +01:00
d2731c77a3 gui 12 bit mode done 2022-02-17 17:33:16 +01:00
40a9dce7e0 vritual server sends 12 bit mode 2022-02-17 16:49:56 +01:00
2ba89b8a45 wip 2022-02-16 17:40:30 +01:00
4cfb35c176 receiver 12 bit, wip 2022-02-16 16:53:25 +01:00
4107938921 adding 12 bit mode for eiger, WIP 2022-02-16 15:03:25 +01:00
6d794cdf4b Merge pull request #386 from slsdetectorgroup/fwrite0
fwrite0
2022-02-15 15:52:02 +01:00
29cd944c11 file write disabled by default 2022-02-15 15:34:50 +01:00
e5ec218e5f Merge pull request #378 from slsdetectorgroup/localhost
localhostMac
2022-02-15 12:07:40 +01:00
0ac20a3bc8 Merge pull request #384 from slsdetectorgroup/ctbgui
Ctbgui
2022-02-15 11:06:48 +01:00
c38f292613 udp_srcip defaulted to 127.0.0.1 for virtual servers 2022-02-15 10:48:14 +01:00
faa9ecf97c allowing virtual servers to also have mac 0 2022-02-15 10:16:22 +01:00
6e32679def ctbgui compiles 2022-02-14 15:58:36 +01:00
649451f824 removing tiff from cmake 2022-02-14 15:46:37 +01:00
83a65f85ab allowing localhost for virtual server 2022-02-14 10:25:34 +01:00
fa929b138e Merge branch 'developer' into localhost 2022-02-11 16:24:11 +01:00
7eb9cb1840 Merge pull request #376 from slsdetectorgroup/datastreamFix
eiger datastream fix for 1g
2022-02-11 16:23:09 +01:00
7e5e9faf1c Merge branch 'developer' into datastreamFix 2022-02-11 16:22:55 +01:00
9a9a8ae836 Merge pull request #379 from slsdetectorgroup/m3gaincaps
M3gaincaps
2022-02-11 16:22:13 +01:00
e8ededc1d1 fixes 2022-02-09 11:56:57 +01:00
dc1fbb8ce4 updated release notes 2022-02-09 11:54:29 +01:00
2cf539c16e reg for m3 is reserved only for gaincaps and not settings. Fixed in set threshold and setall threshold 2022-02-09 11:53:18 +01:00
bcca99e38c clearer exceptions to help user fix the issue of localhost not getting mac address 2022-02-09 11:30:34 +01:00
abfa627246 binary in 2022-02-07 17:13:45 +01:00
f9a88b0f79 datastream is only for 10g for eiger atm, its mentioned in comments. accordingly handled in receiver. This is better solution, in case it was disabled in 10g, and not possible to set enable in 1g mode, which is given to the receiver 2022-02-07 17:10:31 +01:00
75f98b27a3 Merge pull request #375 from slsdetectorgroup/gettid
gettid
2022-02-07 15:09:07 +01:00
c9fbd7afdf fix for gettid() only after glibc 2.30 2022-02-07 15:05:57 +01:00
83e0599a37 Merge pull request #362 from slsdetectorgroup/eiger_datastream
Eiger datastream
2022-02-04 11:52:34 +01:00
b8de1955e3 binaries in 2022-02-04 10:50:44 +01:00
ac5d60155d swapping left and right for trasnmission delay to correspond to left and right of top 2022-02-04 10:49:28 +01:00
7535decd7f merge fix 2022-02-04 10:42:48 +01:00
8f2bacfd53 Merge branch 'arping' into eiger_datastream 2022-02-04 10:41:58 +01:00
771b1e7877 rx_arping for 10g mode (#359)
* test for rx_arping

* arping ip and interface from client interface

* apring thread added to thread ids

* clean code for thread for arping

* removing the assumption that udpip1 fill be updated along with udpip2

* review, replacing syscall(sys_gettid) with gettid()
2022-02-04 10:12:57 +01:00
e8cf366616 review, replacing syscall(sys_gettid) with gettid() 2022-02-04 09:51:49 +01:00
3350e3997e fixes fromreview 2022-02-04 08:19:46 +01:00
dae77a50e6 fixed moench copy for conda 2022-02-03 18:42:06 +01:00
bb5782eb92 Merge branch 'arping' into eiger_datastream 2022-02-03 15:26:15 +01:00
26faaa307b Merge branch 'developer' into arping 2022-02-03 15:26:00 +01:00
bc4cf95d0e merge fix 2022-02-03 13:03:40 +01:00
97417737b6 removing the assumption that udpip1 fill be updated along with udpip2 2022-02-03 12:53:07 +01:00
47c6954044 clean code for thread for arping 2022-02-03 12:14:29 +01:00
7af5d991d9 using ThreadObject, waiting for 1 sec 2022-02-03 10:59:52 +01:00
cace18e535 merge fix 2022-02-03 09:43:06 +01:00
1a1533cad8 binaries in 2022-02-02 16:35:41 +01:00
59085f7dc3 allow to get datastream and enable data stream for 1g 2022-02-02 16:32:35 +01:00
8f30394f63 datastream enabled allowed for 1g mode 2022-02-02 16:18:19 +01:00
f49e45ca6c Merge branch 'eiger_datastream' of github.com:slsdetectorgroup/slsDetectorPackage into eiger_datastream 2022-02-02 16:16:21 +01:00
ef1e41fc12 typo fix 2022-02-02 16:16:14 +01:00
d0f761b2ad binaries in 2022-02-02 15:30:32 +01:00
5825428779 receiver suimmary print out more clear when it is deactivated and exception when trying to disable data stream in 10g mode 2022-02-02 15:28:12 +01:00
0ed7d1e9b1 receiver suimmary print out more clear when it is deactivated and exception when trying to disable data stream in 10g mode 2022-02-02 15:27:37 +01:00
9168bc3ec9 eiger server: fix for datastream enabling wrong ports for bottom half module 2022-02-02 15:12:35 +01:00
158719e325 eiger and 2 udpinterfaces 2022-02-01 15:38:15 +01:00
2a63548f40 apring thread added to thread ids 2022-02-01 15:28:32 +01:00
bf83c9b3e2 arping ip and interface from client interface 2022-02-01 14:03:48 +01:00
c236cbf17b one therad is enough 2022-02-01 12:23:57 +01:00
ca8a1c046a wip, thread to start arping 2022-01-31 17:12:32 +01:00
a4cd4fd14a test for rx_arping 2022-01-31 12:02:09 +01:00
1c6369a5a8 binaries in 2021-11-26 11:57:53 +01:00
4012f139ec merge fix from 6.1.0 2021-11-26 10:59:23 +01:00
630b7cd539 fixed 2021-10-26 15:35:56 +02:00
3ebb3e7508 wip 2021-10-25 17:22:50 +02:00
a1c4eb6d05 wip 2021-10-25 12:33:02 +02:00
b9b5c623ec rx_hostname, port, port2, dstlist works 2021-10-25 11:10:12 +02:00
41dc8329ab first try on setrxhostname 2021-10-22 17:15:04 +02:00
c3499c0b93 Merge branch 'developer' into rr_rxr 2021-10-22 16:12:04 +02:00
578528eb59 merge fix 2021-10-19 14:54:39 +02:00
0658d1c843 merge fix 2021-10-08 09:50:36 +02:00
ce6dc589c8 merge fix 2021-09-30 16:07:30 +02:00
0b45fdfed8 merge fix 2021-09-28 16:09:51 +02:00
9217d9f22c Merge branch 'developer' into rr_rxr 2021-09-15 11:41:29 +02:00
7d4e2470a3 hacky version compiles 2021-09-13 15:45:46 +02:00
66 changed files with 3937 additions and 1805 deletions

View File

@ -1,7 +1,7 @@
SLS Detector Package Minor Release 6.1.0 released on 25.11.2021 SLS Detector Package Minor Release 7.0.0 released on 25.11.2021
=============================================================== ===============================================================
This document describes the differences between v6.1.0 and v6.0.0. This document describes the differences between v7.0.0 and v6.x.x
@ -28,9 +28,28 @@ This document describes the differences between v6.1.0 and v6.0.0.
- changed default vref of adc9257 to 2V for moench (from 1.33V) - changed default vref of adc9257 to 2V for moench (from 1.33V)
- moench and ctb - can set the starting frame number of next acquisition - moench and ctb - can set the starting frame number of next acquisition
- mythen server kernel check incompatible (cet timezone) - mythen server kernel check incompatible (cet timezone)
- m3 server crash (vthrehsold) - rx_arping
- rx_threadsids max is now 9 (breaking api)
- fixed datastream disabling for eiger. Its only available in 10g mode.
- m3 server crash (vthrehsold dac names were not provided)
- allow vtrim to be interpolated for Eiger settings - allow vtrim to be interpolated for Eiger settings
- m3 setThresholdEnergy and setAllThresholdEnergy was overwriting gaincaps with settings enum
- can set localhost with virtual server with minimum configuration: (hostname localhost, rx_hostname localhost, udp_dstip auto)
- increases the progress according to listened index. (not processed index)
- current frame index points to listened frame index (not processed index)
- when in discard partial frames or empty mode, the frame number doesnt increase by 1, it increases to that number (so its faster)
- file write disabled by default
- eiger 12 bit mode
- start non blocking acquisition at modular level
- connect master commands to api (allow set master for eiger)
--ignore-config command line
- command line argument 'master' mainly for virtual servers (also master/top for real eiger), only one virtual server for eiger, use command lines for master/top
- stop servers also check for errors at startup( in case it was running with an older version)
- hostname cmd failed when connecting to servers in update mode (ctb, moench, jungfrau, eiger)
- missingpackets signed (negative => extra packets)
- added geometry to metadata
- 10g eiger nextframenumber get fixed.
- stop, able to set nextframenumber to a consistent (max + 1) for all modules if different (eiger/ctb/jungfrau/moench)
2. Resolved Issues 2. Resolved Issues

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
#Copy the Moench executables #Copy the Moench executables
mkdir -p $PREFIX/bin mkdir -p $PREFIX/bin
cp build/install/bin/moench04ZmqProcess $PREFIX/bin/. cp build/install/bin/moench* $PREFIX/bin/.
cp build/install/bin/moenchZmqProcess $PREFIX/bin/.

View File

@ -34,7 +34,7 @@ add_executable(ctbGui
ctbAdcs.cpp ctbAdcs.cpp
ctbPattern.cpp ctbPattern.cpp
ctbAcquisition.cpp ctbAcquisition.cpp
${CMAKE_SOURCE_DIR}/slsDetectorCalibration/tiffIO.cpp ${CMAKE_SOURCE_DIR}/slsDetectorCalibration/tiffio/src/tiffIO.cpp
) )
@ -43,6 +43,7 @@ target_include_directories(ctbGui PRIVATE
${CMAKE_SOURCE_DIR}/slsDetectorCalibration/dataStructures ${CMAKE_SOURCE_DIR}/slsDetectorCalibration/dataStructures
${CMAKE_SOURCE_DIR}/slsDetectorCalibration/interpolations ${CMAKE_SOURCE_DIR}/slsDetectorCalibration/interpolations
${CMAKE_SOURCE_DIR}/slsDetectorCalibration/ ${CMAKE_SOURCE_DIR}/slsDetectorCalibration/
${CMAKE_SOURCE_DIR}/slsDetectorCalibration/tiffio/include/
) )
# Headders needed for ROOT dictionary generation # Headders needed for ROOT dictionary generation

View File

@ -0,0 +1,12 @@
hostname bchip258+
0:rx_hostname pc13784:1954+pc13784:1955+
udp_srcip 10.0.2.184
udp_dstip 10.0.2.1
0:0 udp_dstport 50000
0:1 udp_dstport 50001
#0:0 udp_dstlist port=50001
#0:1 udp_dstlist port=50002

View File

@ -6,49 +6,57 @@ sls::Detector class. The tool needs the libclang bindings
to be installed. to be installed.
When the Detector API is updated this file should be run When the Detector API is updated this file should be run
manually manually.
""" """
from clang import cindex from clang import cindex
import subprocess import subprocess
import argparse import argparse
import sys
import time
from pathlib import Path
from parse import system_include_paths, clang_format_version
REDC = '\033[91m'
GREENC = '\033[92m'
ENDC = '\033[0m'
def red(msg):
return f'{REDC}{msg}{ENDC}'
def green(msg):
return f'{GREENC}{msg}{ENDC}'
def check_clang_format_version(required_version):
if (ver := clang_format_version()) != required_version:
msg = red(f'Clang format version {required_version} required, detected: {ver}. Bye!')
print(msg)
sys.exit(1)
else:
msg = green(f'Found clang-format version {ver}')
print(msg)
def check_for_compile_commands_json(path):
# print(f"Looking for compile data base in: {path}")
compile_data_base_file = path/'compile_commands.json'
if not compile_data_base_file.exists():
msg = red(f"No compile_commands.json file found in {path}. Bye!")
print(msg)
sys.exit(1)
else:
msg = green(f'Found: {compile_data_base_file}')
print(msg)
from parse import system_include_paths
default_build_path = "/home/l_frojdh/sls/build/" default_build_path = "/home/l_frojdh/sls/build/"
fpath = "../../slsDetectorSoftware/src/Detector.cpp" fpath = "../../slsDetectorSoftware/src/Detector.cpp"
parser = argparse.ArgumentParser()
parser.add_argument(
"-p",
"--build_path",
help="Path to the build database",
type=str,
default=default_build_path,
)
cargs = parser.parse_args()
db = cindex.CompilationDatabase.fromDirectory(cargs.build_path)
index = cindex.Index.create()
args = db.getCompileCommands(fpath)
args = list(iter(args).__next__().arguments)[0:-1]
args = args + "-x c++ --std=c++11".split()
syspath = system_include_paths("clang++")
incargs = ["-I" + inc for inc in syspath]
args = args + incargs
tu = index.parse(fpath, args=args)
m = [] m = []
ag = [] ag = []
lines = [] lines = []
ag2 = [] ag2 = []
cn = [] cn = []
def get_arguments(node): def get_arguments(node):
@ -66,7 +74,7 @@ def get_arguments_with_default(node):
args = [] args = []
for arg in node.get_arguments(): for arg in node.get_arguments():
tokens = [t.spelling for t in arg.get_tokens()] tokens = [t.spelling for t in arg.get_tokens()]
print(tokens) # print(tokens)
if '=' in tokens: if '=' in tokens:
if arg.type.spelling == "sls::Positions": #TODO! automate if arg.type.spelling == "sls::Positions": #TODO! automate
args.append("py::arg() = Positions{}") args.append("py::arg() = Positions{}")
@ -111,33 +119,67 @@ def visit(node):
lines.append( lines.append(
f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})' f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})'
) )
if cargs.verbose:
print(f'&Detector::{child.spelling}{args})')
cn.append(child) cn.append(child)
for child in node.get_children(): for child in node.get_children():
visit(child) visit(child)
# .def("setRxHostname",
# (void (Detector::*)(const std::string &, Positions)) &
# Detector::setRxHostname,
# py::arg(), py::arg() = Positions{})
# .def("setRxHostname",
# (void (Detector::*)(const std::vector<std::string> &)) &
# Detector::setRxHostname,
# py::arg())
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-p",
"--build_path",
help="Path to the build database",
type=Path,
default=default_build_path,
)
parser.add_argument(
"-v",
"--verbose",
help="more output",
action='store_true',
)
cargs = parser.parse_args()
check_clang_format_version(12)
check_for_compile_commands_json(cargs.build_path)
visit(tu.cursor) print("Parsing functions in Detector.h - ", end = "", flush = True)
t0 = time.perf_counter()
#parse functions
db = cindex.CompilationDatabase.fromDirectory(cargs.build_path)
index = cindex.Index.create()
args = db.getCompileCommands(fpath)
args = list(iter(args).__next__().arguments)[0:-1]
args = args + "-x c++ --std=c++11".split()
syspath = system_include_paths("clang++")
incargs = ["-I" + inc for inc in syspath]
args = args + incargs
tu = index.parse(fpath, args=args)
visit(tu.cursor)
print(green('OK'))
print(f'Parsing took {time.perf_counter()-t0:.3f}s')
print("Read detector_in.cpp - ", end = "")
with open("../src/detector_in.cpp") as f:
data = f.read()
s = "".join(lines)
s += ";"
text = data.replace("[[FUNCTIONS]]", s)
warning = "/* WARINING This file is auto generated any edits might be overwritten without warning */\n\n"
print(green("OK"))
print("Writing to detector.cpp - ", end = "")
with open("../src/detector.cpp", "w") as f:
f.write(warning)
f.write(text)
print(green('OK'))
with open("../src/detector_in.cpp") as f: # run clang format on the output
data = f.read() print('Running clang format on generated source -', end = "")
s = "".join(lines) subprocess.run(["clang-format", "../src/detector.cpp", "-i"])
s += ";" print(green(" OK"))
text = data.replace("[[FUNCTIONS]]", s)
warning = "/* WARINING This file is auto generated any edits might be overwritten without warning */\n\n"
with open("../src/detector.cpp", "w") as f:
f.write(warning)
f.write(text)
# run clang format on the output
subprocess.run(["clang-format", "../src/detector.cpp", "-i"])
print("Changes since last commit:")
subprocess.run(['git', 'diff', '../src/detector.cpp'])

View File

@ -5,6 +5,12 @@ import subprocess
from subprocess import PIPE from subprocess import PIPE
import os import os
def clang_format_version():
p = subprocess.run(['clang-format', '--version'], capture_output = True)
ver = p.stdout.decode().split()[2]
major = int(ver.split('.')[0])
return major
def remove_comments(text): def remove_comments(text):
def replacer(match): def replacer(match):

View File

@ -258,7 +258,7 @@ class Detector(CppDetectorApi):
@element @element
def rx_threads(self): def rx_threads(self):
""" """
Get thread ids from the receiver in order of [parent, tcp, listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1]. Get thread ids from the receiver in order of [parent, tcp, listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1, arping].
Note Note
----- -----
@ -268,6 +268,17 @@ class Detector(CppDetectorApi):
""" """
return self.getRxThreadIds() return self.getRxThreadIds()
@property
@element
def rx_arping(self):
"""Starts a thread in slsReceiver to arping the interface it is listening every minute. Useful in 10G mode. """
return self.getRxArping()
@rx_arping.setter
def rx_arping(self, value):
ut.set_using_dict(self.setRxArping, value)
@property @property
@element @element
def dr(self): def dr(self):
@ -276,7 +287,7 @@ class Detector(CppDetectorApi):
Note Note
----- -----
[Eiger] Options: 4, 8, 16, 32. If set to 32, also sets clkdivider to 2 (quarter speed), else to 0 (full speed)\n [Eiger] Options: 4, 8, 12, 16, 32. If set to 32, also sets clkdivider to 2 (quarter speed), else to 0 (full speed)\n
[Mythen3] Options: 8, 16, 32 \n [Mythen3] Options: 8, 16, 32 \n
[Jungfrau][Gotthard][Ctb][Moench][Mythen3][Gotthard2] 16 [Jungfrau][Gotthard][Ctb][Moench][Mythen3][Gotthard2] 16
""" """
@ -1463,6 +1474,19 @@ class Detector(CppDetectorApi):
def trimval(self, value): def trimval(self, value):
ut.set_using_dict(self.setAllTrimbits, value) ut.set_using_dict(self.setAllTrimbits, value)
@property
@element
def master(self):
"""
[Eiger] Sets half module to master and others to slaves.\n
[Gotthard][Gotthard2][Mythen3][Eiger] Gets if the current module/ half module is master.
"""
return self.getMaster()
@master.setter
def master(self, value):
ut.set_using_dict(self.setMaster, value)
@property @property
@element @element
def lock(self): def lock(self):
@ -1900,7 +1924,7 @@ class Detector(CppDetectorApi):
@property @property
@element @element
def rx_missingpackets(self): def rx_missingpackets(self):
"""Gets the number of missing packets for each port in receiver.""" """Gets the number of missing packets for each port in receiver. Negative number denotes extra packets. """
return self.getNumMissingPackets() return self.getNumMissingPackets()
""" """
@ -1913,7 +1937,7 @@ class Detector(CppDetectorApi):
def datastream(self): def datastream(self):
""" """
datastream [left|right] [0, 1] datastream [left|right] [0, 1]
[Eiger] Enables or disables data streaming from left or/and right side of detector. 1 (enabled) by default. [Eiger] Enables or disables data streaming from left or/and right side of detector for 10GbE mode. 1 (enabled) by default.
""" """
result = {} result = {}
for port in [defs.LEFT, defs.RIGHT]: for port in [defs.LEFT, defs.RIGHT]:
@ -2115,6 +2139,21 @@ class Detector(CppDetectorApi):
""" """
return ut.reduce_time(self.getMeasuredSubFramePeriod()) return ut.reduce_time(self.getMeasuredSubFramePeriod())
@property
@element
def top(self):
"""[Eiger] Sets half module to top (1), else bottom.
Note
-----
Advanced Function!
"""
return self.getTop()
@top.setter
def top(self, value):
ut.set_using_dict(self.setTop, value)
""" """
------------------<<<Jungfrau specific>>>------------------------- ------------------<<<Jungfrau specific>>>-------------------------
""" """

View File

@ -1,8 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
/* WARINING This file is auto generated any edits might be overwritten without /* WARINING This file is auto generated any edits might be overwritten without
* warning */ * warning */
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include <pybind11/chrono.h> #include <pybind11/chrono.h>
#include <pybind11/operators.h> #include <pybind11/operators.h>
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
@ -173,6 +173,12 @@ void init_det(py::module &m) {
.def("setFlipRows", .def("setFlipRows",
(void (Detector::*)(bool, sls::Positions)) & Detector::setFlipRows, (void (Detector::*)(bool, sls::Positions)) & Detector::setFlipRows,
py::arg(), py::arg() = Positions{}) py::arg(), py::arg() = Positions{})
.def("getMaster",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getMaster,
py::arg() = Positions{})
.def("setMaster", (void (Detector::*)(bool, int)) & Detector::setMaster,
py::arg(), py::arg())
.def("isVirtualDetectorServer", .def("isVirtualDetectorServer",
(Result<bool>(Detector::*)(sls::Positions) const) & (Result<bool>(Detector::*)(sls::Positions) const) &
Detector::isVirtualDetectorServer, Detector::isVirtualDetectorServer,
@ -470,7 +476,9 @@ void init_det(py::module &m) {
(void (Detector::*)()) & Detector::clearAcquiringFlag) (void (Detector::*)()) & Detector::clearAcquiringFlag)
.def("startReceiver", (void (Detector::*)()) & Detector::startReceiver) .def("startReceiver", (void (Detector::*)()) & Detector::startReceiver)
.def("stopReceiver", (void (Detector::*)()) & Detector::stopReceiver) .def("stopReceiver", (void (Detector::*)()) & Detector::stopReceiver)
.def("startDetector", (void (Detector::*)()) & Detector::startDetector) .def("startDetector",
(void (Detector::*)(sls::Positions)) & Detector::startDetector,
py::arg() = Positions{})
.def("startDetectorReadout", .def("startDetectorReadout",
(void (Detector::*)()) & Detector::startDetectorReadout) (void (Detector::*)()) & Detector::startDetectorReadout)
.def("stopDetector", .def("stopDetector",
@ -488,11 +496,10 @@ void init_det(py::module &m) {
(Result<int64_t>(Detector::*)(sls::Positions) const) & (Result<int64_t>(Detector::*)(sls::Positions) const) &
Detector::getFramesCaught, Detector::getFramesCaught,
py::arg() = Positions{}) py::arg() = Positions{})
.def( .def("getNumMissingPackets",
"getNumMissingPackets", (Result<std::vector<int64_t>>(Detector::*)(sls::Positions) const) &
(Result<std::vector<uint64_t>>(Detector::*)(sls::Positions) const) & Detector::getNumMissingPackets,
Detector::getNumMissingPackets, py::arg() = Positions{})
py::arg() = Positions{})
.def("getNextFrameNumber", .def("getNextFrameNumber",
(Result<uint64_t>(Detector::*)(sls::Positions) const) & (Result<uint64_t>(Detector::*)(sls::Positions) const) &
Detector::getNextFrameNumber, Detector::getNextFrameNumber,
@ -765,9 +772,16 @@ void init_det(py::module &m) {
Detector::getRxLastClientIP, Detector::getRxLastClientIP,
py::arg() = Positions{}) py::arg() = Positions{})
.def("getRxThreadIds", .def("getRxThreadIds",
(Result<std::array<pid_t, 8>>(Detector::*)(sls::Positions) const) & (Result<std::array<pid_t, 9>>(Detector::*)(sls::Positions) const) &
Detector::getRxThreadIds, Detector::getRxThreadIds,
py::arg() = Positions{}) py::arg() = Positions{})
.def("getRxArping",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getRxArping,
py::arg() = Positions{})
.def("setRxArping",
(void (Detector::*)(bool, sls::Positions)) & Detector::setRxArping,
py::arg(), py::arg() = Positions{})
.def("getFileFormat", .def("getFileFormat",
(Result<defs::fileFormat>(Detector::*)(sls::Positions) const) & (Result<defs::fileFormat>(Detector::*)(sls::Positions) const) &
Detector::getFileFormat, Detector::getFileFormat,
@ -997,6 +1011,13 @@ void init_det(py::module &m) {
sls::Positions)) & sls::Positions)) &
Detector::setDataStream, Detector::setDataStream,
py::arg(), py::arg(), py::arg() = Positions{}) py::arg(), py::arg(), py::arg() = Positions{})
.def("getTop",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getTop,
py::arg() = Positions{})
.def("setTop",
(void (Detector::*)(bool, sls::Positions)) & Detector::setTop,
py::arg(), py::arg() = Positions{})
.def("getChipVersion", .def("getChipVersion",
(Result<double>(Detector::*)(sls::Positions) const) & (Result<double>(Detector::*)(sls::Positions) const) &
Detector::getChipVersion, Detector::getChipVersion,
@ -1255,10 +1276,6 @@ void init_det(py::module &m) {
(Result<std::array<ns, 3>>(Detector::*)(sls::Positions) const) & (Result<std::array<ns, 3>>(Detector::*)(sls::Positions) const) &
Detector::getGateDelayForAllGates, Detector::getGateDelayForAllGates,
py::arg() = Positions{}) py::arg() = Positions{})
.def("getMaster",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getMaster,
py::arg() = Positions{})
.def("getChipStatusRegister", .def("getChipStatusRegister",
(Result<int>(Detector::*)(sls::Positions) const) & (Result<int>(Detector::*)(sls::Positions) const) &
Detector::getChipStatusRegister, Detector::getChipStatusRegister,
@ -1547,7 +1564,7 @@ void init_det(py::module &m) {
Detector::getUpdateMode, Detector::getUpdateMode,
py::arg() = Positions{}) py::arg() = Positions{})
.def("setUpdateMode", .def("setUpdateMode",
(void (Detector::*)(bool, sls::Positions)) & (void (Detector::*)(const bool, sls::Positions)) &
Detector::setUpdateMode, Detector::setUpdateMode,
py::arg(), py::arg() = Positions{}) py::arg(), py::arg() = Positions{})
.def("readRegister", .def("readRegister",

View File

@ -97,6 +97,11 @@
<string>65535</string> <string>65535</string>
</property> </property>
</item> </item>
<item>
<property name="text">
<string>4095</string>
</property>
</item>
<item> <item>
<property name="text"> <property name="text">
<string>255</string> <string>255</string>

View File

@ -69,5 +69,11 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject {
enum { DYNAMIC, FORCE_SWITCH_G1, FORCE_SWITCH_G2, FIX_G1, FIX_G2, FIX_G0 }; enum { DYNAMIC, FORCE_SWITCH_G1, FORCE_SWITCH_G2, FIX_G1, FIX_G2, FIX_G0 };
bool isVisibleFixG0{false}; bool isVisibleFixG0{false};
enum { DYNAMICRANGE_32, DYNAMICRANGE_16, DYNAMICRANGE_8, DYNAMICRANGE_4 }; enum {
DYNAMICRANGE_32,
DYNAMICRANGE_16,
DYNAMICRANGE_12,
DYNAMICRANGE_8,
DYNAMICRANGE_4
};
}; };

View File

@ -1064,6 +1064,8 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size,
// mythen3 / gotthard2 debugging // mythen3 / gotthard2 debugging
int discardBits = numDiscardBits; int discardBits = numDiscardBits;
uint16_t temp = 0;
uint8_t *src = (uint8_t *)source;
switch (dr) { switch (dr) {
case 4: case 4:
@ -1083,6 +1085,19 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size,
} }
break; break;
case 12:
for (ichan = 0; ichan < size; ++ichan) {
temp = (*src++ & 0xFF);
temp |= ((*src & 0xF) << 8u);
dest[ichan] = (double)temp;
++ichan;
temp = ((*src++ & 0xF0) >> 4u);
temp |= ((*src++ & 0xFF) << 4u);
dest[ichan] = (double)temp;
}
break;
case 16: case 16:
if (detType == slsDetectorDefs::JUNGFRAU || if (detType == slsDetectorDefs::JUNGFRAU ||
detType == slsDetectorDefs::GOTTHARD2) { detType == slsDetectorDefs::GOTTHARD2) {

View File

@ -60,13 +60,19 @@ void qTabSettings::SetupWidgetWindow() {
QStandardItemModel *model = QStandardItemModel *model =
qobject_cast<QStandardItemModel *>(comboDynamicRange->model()); qobject_cast<QStandardItemModel *>(comboDynamicRange->model());
if (model) { if (model) {
QModelIndex index;
QStandardItem *item; QStandardItem *item;
index = int dr = DYNAMICRANGE_4;
model->index(DYNAMICRANGE_4, comboDynamicRange->modelColumn(), for (int i = 0; i != 2; ++i) {
comboDynamicRange->rootModelIndex()); // disable dr 4
item = model->itemFromIndex(index); QModelIndex index =
item->setEnabled(false); model->index(dr, comboDynamicRange->modelColumn(),
comboDynamicRange->rootModelIndex());
item = model->itemFromIndex(index);
item->setEnabled(false);
// disable dr 12
dr = DYNAMICRANGE_12;
}
} }
} else if (detType == slsDetectorDefs::EIGER) { } else if (detType == slsDetectorDefs::EIGER) {
lblDynamicRange->setEnabled(true); lblDynamicRange->setEnabled(true);
@ -305,6 +311,9 @@ void qTabSettings::GetDynamicRange() {
case 16: case 16:
comboDynamicRange->setCurrentIndex(DYNAMICRANGE_16); comboDynamicRange->setCurrentIndex(DYNAMICRANGE_16);
break; break;
case 12:
comboDynamicRange->setCurrentIndex(DYNAMICRANGE_12);
break;
case 8: case 8:
comboDynamicRange->setCurrentIndex(DYNAMICRANGE_8); comboDynamicRange->setCurrentIndex(DYNAMICRANGE_8);
break; break;
@ -333,6 +342,9 @@ void qTabSettings::SetDynamicRange(int index) {
case DYNAMICRANGE_16: case DYNAMICRANGE_16:
det->setDynamicRange(16); det->setDynamicRange(16);
break; break;
case DYNAMICRANGE_12:
det->setDynamicRange(12);
break;
case DYNAMICRANGE_8: case DYNAMICRANGE_8:
det->setDynamicRange(8); det->setDynamicRange(8);
break; break;

View File

@ -433,16 +433,21 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) { if (mapCSP0() == FAIL) {
LOG(logERROR, initError = FAIL;
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); strcpy(initErrorMessage,
exit(EXIT_FAILURE); "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
} LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
#endif #endif
}
initCheckDone = 1;
} }
/* set up detector */ /* set up detector */
@ -702,8 +707,16 @@ void resetPeripheral() {
} }
/* set parameters - dr, adcenablemask */ /* set parameters - dr, adcenablemask */
int setDynamicRange(int dr) {
if (dr == 16)
return OK;
return FAIL;
}
int setDynamicRange(int dr) { return DYNAMIC_RANGE; } int getDynamicRange(int *retval) {
*retval = DYNAMIC_RANGE;
return OK;
}
int setADCEnableMask(uint32_t mask) { int setADCEnableMask(uint32_t mask) {
if (mask == 0u) { if (mask == 0u) {

View File

@ -177,7 +177,7 @@ void Beb_AdjustIPChecksum(struct udp_header_type *ip) {
ip->ip_header_checksum[1] = ip_checksum & 0xff; ip->ip_header_checksum[1] = ip_checksum & 0xff;
} }
void Beb_GetModuleConfiguration(int *master, int *top, int *normal) { int Beb_GetModuleConfiguration(int *master, int *top, int *normal) {
*top = 0; *top = 0;
*master = 0; *master = 0;
// mapping new memory to read master top module configuration // mapping new memory to read master top module configuration
@ -187,6 +187,7 @@ void Beb_GetModuleConfiguration(int *master, int *top, int *normal) {
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd < 0) { if (fd < 0) {
LOG(logERROR, ("Module Configuration FAIL\n")); LOG(logERROR, ("Module Configuration FAIL\n"));
return FAIL;
} else { } else {
// read data // read data
ret = Beb_Read32(csp0base, BEB_CONFIG_RD_OFST); ret = Beb_Read32(csp0base, BEB_CONFIG_RD_OFST);
@ -202,6 +203,7 @@ void Beb_GetModuleConfiguration(int *master, int *top, int *normal) {
// close file pointer // close file pointer
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
} }
return OK;
} }
int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay) { int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay) {
@ -492,6 +494,11 @@ int Beb_SetDataStream(enum portPosition port, int enable) {
u_int32_t reg = XPAR_GPIO_P15_STREAMING_REG; u_int32_t reg = XPAR_GPIO_P15_STREAMING_REG;
u_int32_t mask = (port == LEFT ? XPAR_GPIO_LFT_STRM_DSBL_MSK u_int32_t mask = (port == LEFT ? XPAR_GPIO_LFT_STRM_DSBL_MSK
: XPAR_GPIO_RGHT_STRM_DSBL_MSK); : XPAR_GPIO_RGHT_STRM_DSBL_MSK);
// invert left/right if bottom
if (!Beb_top) {
mask = (port == LEFT ? XPAR_GPIO_RGHT_STRM_DSBL_MSK
: XPAR_GPIO_LFT_STRM_DSBL_MSK);
}
u_int32_t value = Beb_Read32(csp0base, reg); u_int32_t value = Beb_Read32(csp0base, reg);
// disabling in firmware // disabling in firmware
@ -529,6 +536,11 @@ int Beb_GetDataStream(enum portPosition port, int *retval) {
u_int32_t reg = XPAR_GPIO_P15_STREAMING_REG; u_int32_t reg = XPAR_GPIO_P15_STREAMING_REG;
u_int32_t mask = (port == LEFT ? XPAR_GPIO_LFT_STRM_DSBL_MSK u_int32_t mask = (port == LEFT ? XPAR_GPIO_LFT_STRM_DSBL_MSK
: XPAR_GPIO_RGHT_STRM_DSBL_MSK); : XPAR_GPIO_RGHT_STRM_DSBL_MSK);
// invert left/right if bottom
if (!Beb_top) {
mask = (port == LEFT ? XPAR_GPIO_RGHT_STRM_DSBL_MSK
: XPAR_GPIO_LFT_STRM_DSBL_MSK);
}
u_int32_t value = Beb_Read32(csp0base, reg); u_int32_t value = Beb_Read32(csp0base, reg);
// disabling in firmware // disabling in firmware
@ -682,6 +694,10 @@ int Beb_GetTransmissionDelayLeft() {
return Beb_deactivated_transmission_delay_left; return Beb_deactivated_transmission_delay_left;
} }
u_int32_t offset = TXM_DELAY_LEFT_OFFSET; u_int32_t offset = TXM_DELAY_LEFT_OFFSET;
// invert left/right if bottom
if (!Beb_top) {
offset = TXM_DELAY_RIGHT_OFFSET;
}
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) { if (fd <= 0) {
@ -706,6 +722,10 @@ int Beb_SetTransmissionDelayLeft(int value) {
return 1; return 1;
} }
u_int32_t offset = TXM_DELAY_LEFT_OFFSET; u_int32_t offset = TXM_DELAY_LEFT_OFFSET;
// invert left/right if bottom
if (!Beb_top) {
offset = TXM_DELAY_RIGHT_OFFSET;
}
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) { if (fd <= 0) {
@ -726,6 +746,10 @@ int Beb_GetTransmissionDelayRight() {
} }
u_int32_t offset = TXM_DELAY_RIGHT_OFFSET; u_int32_t offset = TXM_DELAY_RIGHT_OFFSET;
// invert left/right if bottom
if (!Beb_top) {
offset = TXM_DELAY_LEFT_OFFSET;
}
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) { if (fd <= 0) {
@ -750,6 +774,10 @@ int Beb_SetTransmissionDelayRight(int value) {
return 1; return 1;
} }
u_int32_t offset = TXM_DELAY_RIGHT_OFFSET; u_int32_t offset = TXM_DELAY_RIGHT_OFFSET;
// invert left/right if bottom
if (!Beb_top) {
offset = TXM_DELAY_LEFT_OFFSET;
}
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR);
if (fd <= 0) { if (fd <= 0) {
@ -836,11 +864,17 @@ void Beb_ResetFrameNumber() {
} }
int Beb_SetUpTransferParameters(short the_bit_mode) { int Beb_SetUpTransferParameters(short the_bit_mode) {
if (the_bit_mode != 4 && the_bit_mode != 8 && the_bit_mode != 16 && switch (the_bit_mode) {
the_bit_mode != 32) case 4:
case 8:
case 12:
case 16:
case 32:
Beb_bit_mode = the_bit_mode;
return 1;
default:
return 0; return 0;
Beb_bit_mode = the_bit_mode; }
return 1;
} }
int Beb_StopAcquisition() { int Beb_StopAcquisition() {
@ -1225,20 +1259,20 @@ int Beb_GetNextFrameNumber(uint64_t *retval, int tengigaEnable) {
else { else {
uint64_t left10g = uint64_t left10g =
Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_MSB_OFST); Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_MSB_OFST);
temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_LSB_OFST); temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_LSB_OFST);
left10g = ((left10g << 32) | temp) >> 16; left10g = ((left10g << 32) | temp) >> 16;
++left10g; // increment for firmware ++left10g; // increment for firmware
uint64_t right10g = uint64_t right10g =
Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_MSB_OFST); Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_MSB_OFST);
temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_LSB_OFST); temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_LSB_OFST);
right10g = ((right10g << 32) | temp) >> 16; right10g = ((right10g << 32) | temp) >> 16;
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
++right10g; // increment for firmware ++right10g; // increment for firmware
if (left10g != right10g) { if (left10g != right10g) {
LOG(logERROR, ("Retrieved inconsistent frame numbers from `0g left " LOG(logERROR, ("Retrieved inconsistent frame numbers from 10g left "
"%llu and right %llu\n", "%llu and right %llu\n",
(long long int)left10g, (long long int)right10g)); (long long int)left10g, (long long int)right10g));
*retval = (left10g > right10g) *retval = (left10g > right10g)

View File

@ -15,7 +15,7 @@ int Beb_SetHeaderData(uint64_t src_mac, uint32_t src_ip, uint16_t src_port,
uint64_t dst_mac, uint32_t dst_ip, uint16_t dst_port); uint64_t dst_mac, uint32_t dst_ip, uint16_t dst_port);
void Beb_AdjustIPChecksum(struct udp_header_type *ip); void Beb_AdjustIPChecksum(struct udp_header_type *ip);
void Beb_GetModuleConfiguration(int *master, int *top, int *normal); int Beb_GetModuleConfiguration(int *master, int *top, int *normal);
int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay); int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay);
void Beb_SetTopVariable(int val); void Beb_SetTopVariable(int val);

View File

@ -16,91 +16,31 @@ include_directories(
../../slsSupportLib/include ../../slsSupportLib/include
) )
add_executable(eigerDetectorServerMaster_virtual add_executable(eigerDetectorServer_virtual
${src} ${src}
) )
target_include_directories(eigerDetectorServerMaster_virtual target_include_directories(eigerDetectorServer_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
) )
target_compile_definitions(eigerDetectorServerMaster_virtual target_compile_definitions(eigerDetectorServer_virtual
PUBLIC EIGERD PCCOMPILE STOP_SERVER
PUBLIC VIRTUAL #VIRTUAL_9M
PUBLIC VIRTUAL_MASTER
)
target_link_libraries(eigerDetectorServerMaster_virtual
PUBLIC pthread rt slsProjectCSettings
)
set_target_properties(eigerDetectorServerMaster_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS eigerDetectorServerMaster_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
add_executable(eigerDetectorServerSlaveTop_virtual
${src}
)
target_include_directories(eigerDetectorServerSlaveTop_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(eigerDetectorServerSlaveTop_virtual
PUBLIC EIGERD PCCOMPILE STOP_SERVER
PUBLIC VIRTUAL #VIRTUAL_9M
PUBLIC VIRTUAL_TOP
)
target_link_libraries(eigerDetectorServerSlaveTop_virtual
PUBLIC pthread rt slsProjectCSettings
)
set_target_properties(eigerDetectorServerSlaveTop_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS eigerDetectorServerSlaveTop_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
add_executable(eigerDetectorServerSlaveBottom_virtual
${src}
)
target_include_directories(eigerDetectorServerSlaveBottom_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(eigerDetectorServerSlaveBottom_virtual
PUBLIC EIGERD PCCOMPILE STOP_SERVER PUBLIC EIGERD PCCOMPILE STOP_SERVER
PUBLIC VIRTUAL #VIRTUAL_9M PUBLIC VIRTUAL #VIRTUAL_9M
) )
target_link_libraries(eigerDetectorServerSlaveBottom_virtual target_link_libraries(eigerDetectorServer_virtual
PUBLIC pthread rt slsProjectCSettings PUBLIC pthread rt slsProjectCSettings
) )
set_target_properties(eigerDetectorServerSlaveBottom_virtual PROPERTIES set_target_properties(eigerDetectorServer_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
) )
install(TARGETS eigerDetectorServerSlaveBottom_virtual install(TARGETS eigerDetectorServer_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
) )
configure_file(config_eiger.txt ${CMAKE_BINARY_DIR}/bin/config_eiger.txt COPYONLY) configure_file(config_eiger.txt ${CMAKE_BINARY_DIR}/bin/config_eiger.txt COPYONLY)
configure_file(detid_eiger.txt ${CMAKE_BINARY_DIR}/bin/detid_eiger.txt COPYONLY) configure_file(detid_eiger.txt ${CMAKE_BINARY_DIR}/bin/detid_eiger.txt COPYONLY)

View File

@ -18,7 +18,7 @@
const unsigned int Feb_Control_leftAddress = 0x100; const unsigned int Feb_Control_leftAddress = 0x100;
const unsigned int Feb_Control_rightAddress = 0x200; const unsigned int Feb_Control_rightAddress = 0x200;
int Feb_Control_master = 0; int Feb_Control_master = -1;
int Feb_Control_normal = 0; int Feb_Control_normal = 0;
int Feb_Control_activated = 1; int Feb_Control_activated = 1;
@ -50,17 +50,16 @@ double ratemax = -1;
// setup // setup
void Feb_Control_activate(int activate) { Feb_Control_activated = activate; } void Feb_Control_activate(int activate) { Feb_Control_activated = activate; }
void Feb_Control_FebControl() { int Feb_Control_FebControl(int normal) {
Feb_Control_staticBits = Feb_Control_acquireNReadoutMode = Feb_Control_staticBits = 0;
Feb_Control_triggerMode = Feb_Control_externalEnableMode = Feb_Control_acquireNReadoutMode = 0;
Feb_Control_subFrameMode = 0; Feb_Control_triggerMode = 0;
Feb_Control_externalEnableMode = 0;
Feb_Control_subFrameMode = 0;
Feb_Control_trimbit_size = 263680; Feb_Control_trimbit_size = 263680;
Feb_Control_last_downloaded_trimbits = Feb_Control_last_downloaded_trimbits =
malloc(Feb_Control_trimbit_size * sizeof(int)); malloc(Feb_Control_trimbit_size * sizeof(int));
}
int Feb_Control_Init(int master, int normal) {
Feb_Control_master = master;
Feb_Control_normal = normal; Feb_Control_normal = normal;
Feb_Interface_SetAddress(Feb_Control_rightAddress, Feb_Control_leftAddress); Feb_Interface_SetAddress(Feb_Control_rightAddress, Feb_Control_leftAddress);
if (Feb_Control_activated) { if (Feb_Control_activated) {
@ -931,7 +930,10 @@ unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec) {
int Feb_Control_PrepareForAcquisition() { int Feb_Control_PrepareForAcquisition() {
LOG(logINFOBLUE, ("Preparing for Acquisition\n")); LOG(logINFOBLUE, ("Preparing for Acquisition\n"));
Feb_Control_PrintAcquisitionSetup(); if (!Feb_Control_PrintAcquisitionSetup()) {
LOG(logERROR, ("Could not prepare acquisition\n"));
return 0;
}
if (Feb_Control_Reset() == STATUS_ERROR) { if (Feb_Control_Reset() == STATUS_ERROR) {
LOG(logERROR, ("Trouble reseting daq or data stream\n")); LOG(logERROR, ("Trouble reseting daq or data stream\n"));
@ -988,20 +990,26 @@ int Feb_Control_PrepareForAcquisition() {
return 1; return 1;
} }
void Feb_Control_PrintAcquisitionSetup() { int Feb_Control_PrintAcquisitionSetup() {
time_t rawtime; time_t rawtime;
time(&rawtime); time(&rawtime);
struct tm *timeinfo = localtime(&rawtime); struct tm *timeinfo = localtime(&rawtime);
LOG(logINFO, int dr = 0;
("Starting an exposure: (%s)" if (!Feb_Control_GetDynamicRange(&dr)) {
"\t Dynamic range nbits: %d\n" LOG(logERROR, ("Could not print acquisition set up\n"));
"\t Trigger mode: 0x%x\n" return 0;
"\t Number of exposures: %d\n" }
"\t Exsposure time (if used): %f seconds.\n" LOG(logINFO, ("Starting an exposure: (%s)"
"\t Exsposure period (if used): %f seconds.\n\n", "\t Dynamic range nbits: %d\n"
asctime(timeinfo), Feb_Control_GetDynamicRange(), "\t Trigger mode: 0x%x\n"
Feb_Control_triggerMode, Feb_Control_GetNExposures(), "\t Number of exposures: %d\n"
Feb_Control_exposure_time_in_sec, Feb_Control_exposure_period_in_sec)); "\t Exsposure time (if used): %f seconds.\n"
"\t Exsposure period (if used): %f seconds.\n\n",
asctime(timeinfo), dr, Feb_Control_triggerMode,
Feb_Control_GetNExposures(), Feb_Control_exposure_time_in_sec,
Feb_Control_exposure_period_in_sec));
return 1;
} }
int Feb_Control_StartAcquisition() { int Feb_Control_StartAcquisition() {
@ -1169,49 +1177,106 @@ int Feb_Control_SoftwareTrigger(int block) {
} }
// parameters // parameters
int Feb_Control_SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo) { int Feb_Control_SetDynamicRange(int dr) {
static unsigned int everything_but_bit_mode = DAQ_STATIC_BIT_PROGRAM | static unsigned int everything_but_bit_mode = DAQ_STATIC_BIT_PROGRAM |
DAQ_STATIC_BIT_CHIP_TEST | DAQ_STATIC_BIT_CHIP_TEST |
DAQ_STATIC_BIT_ROTEST; DAQ_STATIC_BIT_ROTEST;
if (four_eight_sixteen_or_thirtytwo == 4) { switch (dr) {
case 4:
Feb_Control_staticBits = Feb_Control_staticBits =
DAQ_STATIC_BIT_M4 | DAQ_STATIC_BIT_M4 |
(Feb_Control_staticBits & (Feb_Control_staticBits &
everything_but_bit_mode); // leave test bits in currernt state everything_but_bit_mode); // leave test bits in currernt state
Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING;
} else if (four_eight_sixteen_or_thirtytwo == 8) { break;
case 8:
Feb_Control_staticBits = DAQ_STATIC_BIT_M8 | (Feb_Control_staticBits & Feb_Control_staticBits = DAQ_STATIC_BIT_M8 | (Feb_Control_staticBits &
everything_but_bit_mode); everything_but_bit_mode);
Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING;
} else if (four_eight_sixteen_or_thirtytwo == 16) { break;
case 12:
case 16:
Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits & Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits &
everything_but_bit_mode); everything_but_bit_mode);
Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING;
} else if (four_eight_sixteen_or_thirtytwo == 32) {
// disable 16 bit conversion if 12 bit mode (enable if 16 bit)
if (!Feb_Control_Disable16bitConversion(dr == 12))
return 0;
break;
case 32:
Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits & Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits &
everything_but_bit_mode); everything_but_bit_mode);
Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING;
} else { break;
LOG(logERROR, ("dynamic range (%d) not valid, not setting bit mode.\n", default:
four_eight_sixteen_or_thirtytwo)); LOG(logERROR,
("dynamic range (%d) not valid, not setting bit mode.\n", dr));
LOG(logINFO, ("Set dynamic range int must equal 4,8 16, or 32.\n")); LOG(logINFO, ("Set dynamic range int must equal 4,8 16, or 32.\n"));
return 0; return 0;
} }
LOG(logINFO, LOG(logINFO, ("Dynamic range set to %d\n", dr));
("Dynamic range set to %d\n", four_eight_sixteen_or_thirtytwo));
return 1; return 1;
} }
unsigned int Feb_Control_GetDynamicRange() { int Feb_Control_GetDynamicRange(int *retval) {
if (Feb_Control_subFrameMode & DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING) if (Feb_Control_subFrameMode & DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING) {
return 32; *retval = 32;
else if (DAQ_STATIC_BIT_M4 & Feb_Control_staticBits) } else if (DAQ_STATIC_BIT_M4 & Feb_Control_staticBits) {
return 4; *retval = 4;
else if (DAQ_STATIC_BIT_M8 & Feb_Control_staticBits) } else if (DAQ_STATIC_BIT_M8 & Feb_Control_staticBits) {
return 8; *retval = 8;
} else {
int disable16 = 0;
if (!Feb_Control_Get16bitConversionDisabled(&disable16)) {
LOG(logERROR, ("Could not get dynamic range (12 or 16 bit)\n"));
return 0;
}
if (disable16) {
*retval = 12;
} else {
*retval = 16;
}
}
return 16; return 1;
}
int Feb_Control_Disable16bitConversion(int disable) {
LOG(logINFO, ("%s 16 bit expansion\n", disable ? "Disabling" : "Enabling"));
unsigned int regval = 0;
if (!Feb_Control_ReadRegister(DAQ_REG_HRDWRE, &regval)) {
LOG(logERROR, ("Could not %s 16 bit expansion (bit mode)\n",
(disable ? "disable" : "enable")));
return 0;
}
if (disable) {
regval |= DAQ_REG_HRDWRE_DSBL_16BIT_MSK;
} else {
regval &= ~DAQ_REG_HRDWRE_DSBL_16BIT_MSK;
}
if (!Feb_Control_WriteRegister(DAQ_REG_HRDWRE, regval)) {
LOG(logERROR, ("Could not %s 16 bit expansion (bit mode)\n",
(disable ? "disable" : "enable")));
return 0;
}
return 1;
}
int Feb_Control_Get16bitConversionDisabled(int *ret) {
unsigned int regval = 0;
if (!Feb_Control_ReadRegister(DAQ_REG_HRDWRE, &regval)) {
LOG(logERROR, ("Could not get 16 bit expansion (bit mode)\n"));
return 0;
}
if (regval & DAQ_REG_HRDWRE_DSBL_16BIT_MSK) {
*ret = 1;
} else {
*ret = 0;
}
return 1;
} }
int Feb_Control_SetReadoutSpeed(unsigned int readout_speed) { int Feb_Control_SetReadoutSpeed(unsigned int readout_speed) {
@ -1490,9 +1555,8 @@ int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right) {
return 1; return 1;
} }
void Feb_Control_SetMasterVariable(int val) { Feb_Control_master = val; }
int Feb_Control_SetMaster(enum MASTERINDEX ind) { int Feb_Control_SetMaster(enum MASTERINDEX ind) {
uint32_t offset = DAQ_REG_HRDWRE; uint32_t offset = DAQ_REG_HRDWRE;
unsigned int addr[2] = {Feb_Control_leftAddress, Feb_Control_rightAddress}; unsigned int addr[2] = {Feb_Control_leftAddress, Feb_Control_rightAddress};
char *master_names[] = {MASTER_NAMES}; char *master_names[] = {MASTER_NAMES};
@ -1529,9 +1593,31 @@ int Feb_Control_SetMaster(enum MASTERINDEX ind) {
LOG(logINFOBLUE, ("%s Master flag to %s Feb\n", LOG(logINFOBLUE, ("%s Master flag to %s Feb\n",
(ind == MASTER_HARDWARE ? "Resetting" : "Overwriting"), (ind == MASTER_HARDWARE ? "Resetting" : "Overwriting"),
master_names[ind])); master_names[ind]));
return 1; return 1;
} }
int Feb_Control_SetMasterEffects(int master, int controlServer) {
int prevMaster = Feb_Control_master;
Feb_Control_master = master;
// change in master for 9m
if (controlServer && prevMaster != Feb_Control_master &&
!Feb_Control_normal) {
if (prevMaster) {
Feb_Control_CloseSerialCommunication();
}
if (Feb_Control_master) {
if (!Feb_Control_OpenSerialCommunication()) {
LOG(logERROR, ("Could not intitalize feb control serial "
"communication\n"));
return FAIL;
}
}
}
return OK;
}
int Feb_Control_SetQuad(int val) { int Feb_Control_SetQuad(int val) {
LOG(logINFO, ("Setting Quad to %d in Feb\n", val)); LOG(logINFO, ("Setting Quad to %d in Feb\n", val));
Feb_Control_quadMode = val; Feb_Control_quadMode = val;
@ -1554,7 +1640,10 @@ int Feb_Control_SetChipSignalsToTrimQuad(int enable) {
regval &= ~(DAQ_REG_HRDWRE_PROGRAM_MSK | DAQ_REG_HRDWRE_M8_MSK); regval &= ~(DAQ_REG_HRDWRE_PROGRAM_MSK | DAQ_REG_HRDWRE_M8_MSK);
} }
return Feb_Control_WriteRegister(DAQ_REG_HRDWRE, regval); if (!Feb_Control_WriteRegister(DAQ_REG_HRDWRE, regval)) {
LOG(logERROR, ("Could not set chip signals to trim quad\n"));
return 0;
}
} }
return 1; return 1;
} }
@ -1604,7 +1693,7 @@ int Feb_Control_WriteRegister(uint32_t offset, uint32_t data) {
for (int iloop = 0; iloop < 2; ++iloop) { for (int iloop = 0; iloop < 2; ++iloop) {
if (run[iloop]) { if (run[iloop]) {
LOG(logINFO, LOG(logDEBUG1,
("Writing 0x%x to %s 0x%x\n", data, side[iloop], actualOffset)); ("Writing 0x%x to %s 0x%x\n", data, side[iloop], actualOffset));
if (!Feb_Interface_WriteRegister(addr[iloop], actualOffset, data, 0, if (!Feb_Interface_WriteRegister(addr[iloop], actualOffset, data, 0,
0)) { 0)) {
@ -1612,6 +1701,18 @@ int Feb_Control_WriteRegister(uint32_t offset, uint32_t data) {
side[iloop], actualOffset)); side[iloop], actualOffset));
return 0; return 0;
} }
uint32_t regVal = 0;
if (!Feb_Interface_ReadRegister(addr[iloop], actualOffset,
&regVal)) {
LOG(logERROR, ("Could not read %s register\n", addr[iloop]));
return 0;
}
if (regVal != data) {
LOG(logERROR,
("Could not write %s register. Write 0x%x, read 0x%x\n",
addr[iloop], data, regVal));
return 0;
}
} }
} }
@ -1648,8 +1749,8 @@ int Feb_Control_ReadRegister(uint32_t offset, uint32_t *retval) {
side[iloop], actualOffset)); side[iloop], actualOffset));
return 0; return 0;
} }
LOG(logINFO, ("Read 0x%x from %s 0x%x\n", value[iloop], side[iloop], LOG(logDEBUG1, ("Read 0x%x from %s 0x%x\n", value[iloop],
actualOffset)); side[iloop], actualOffset));
*retval = value[iloop]; *retval = value[iloop];
// if not the other (left, not right OR right, not left), return the // if not the other (left, not right OR right, not left), return the
// value // value
@ -1824,7 +1925,11 @@ int64_t Feb_Control_Get_RateTable_Period_in_nsec() {
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec) { int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec) {
// period = exptime if 16bit, period = subexptime if 32 bit // period = exptime if 16bit, period = subexptime if 32 bit
int dr = Feb_Control_GetDynamicRange(); int dr = 0;
if (!Feb_Control_GetDynamicRange(&dr)) {
LOG(logERROR, ("Could not set rate correction tau\n"));
return 0;
}
double period_in_sec = double period_in_sec =
(double)(Feb_Control_GetSubFrameExposureTime()) / (double)1e9; (double)(Feb_Control_GetSubFrameExposureTime()) / (double)1e9;
if (dr == 16) if (dr == 16)

View File

@ -7,8 +7,7 @@
// setup // setup
void Feb_Control_activate(int activate); void Feb_Control_activate(int activate);
void Feb_Control_FebControl(); int Feb_Control_FebControl(int normal);
int Feb_Control_Init(int master, int normal);
int Feb_Control_OpenSerialCommunication(); int Feb_Control_OpenSerialCommunication();
void Feb_Control_CloseSerialCommunication(); void Feb_Control_CloseSerialCommunication();
int Feb_Control_CheckSetup(); int Feb_Control_CheckSetup();
@ -55,7 +54,7 @@ int Feb_Control_ResetChipPartially();
int Feb_Control_SendBitModeToBebServer(); int Feb_Control_SendBitModeToBebServer();
unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec); unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec);
int Feb_Control_PrepareForAcquisition(); int Feb_Control_PrepareForAcquisition();
void Feb_Control_PrintAcquisitionSetup(); int Feb_Control_PrintAcquisitionSetup();
int Feb_Control_StartAcquisition(); int Feb_Control_StartAcquisition();
int Feb_Control_StopAcquisition(); int Feb_Control_StopAcquisition();
int Feb_Control_IsReadyForTrigger(int *readyForTrigger); int Feb_Control_IsReadyForTrigger(int *readyForTrigger);
@ -63,8 +62,10 @@ int Feb_Control_SendSoftwareTrigger();
int Feb_Control_SoftwareTrigger(int block); int Feb_Control_SoftwareTrigger(int block);
// parameters // parameters
int Feb_Control_SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo); int Feb_Control_SetDynamicRange(int dr);
unsigned int Feb_Control_GetDynamicRange(); int Feb_Control_GetDynamicRange(int *retval);
int Feb_Control_Disable16bitConversion(int disable);
int Feb_Control_Get16bitConversionDisabled();
int Feb_Control_SetReadoutSpeed(unsigned int readout_speed); int Feb_Control_SetReadoutSpeed(unsigned int readout_speed);
int Feb_Control_SetReadoutMode(unsigned int readout_mode); int Feb_Control_SetReadoutMode(unsigned int readout_mode);
int Feb_Control_SetTriggerMode(unsigned int trigger_mode); int Feb_Control_SetTriggerMode(unsigned int trigger_mode);
@ -86,8 +87,8 @@ int Feb_Control_Get_Counter_Bit();
int Feb_Control_SetInterruptSubframe(int val); int Feb_Control_SetInterruptSubframe(int val);
int Feb_Control_GetInterruptSubframe(); int Feb_Control_GetInterruptSubframe();
int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right); int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right);
void Feb_Control_SetMasterVariable(int val);
int Feb_Control_SetMaster(enum MASTERINDEX ind); int Feb_Control_SetMaster(enum MASTERINDEX ind);
int Feb_Control_SetMasterEffects(int master, int controlServer);
int Feb_Control_SetQuad(int val); int Feb_Control_SetQuad(int val);
int Feb_Control_SetChipSignalsToTrimQuad(int enable); int Feb_Control_SetChipSignalsToTrimQuad(int enable);
int Feb_Control_SetReadNRows(int value); int Feb_Control_SetReadNRows(int value);

View File

@ -29,6 +29,8 @@
#define DAQ_REG_HRDWRE_OW_MASTER_MSK (0x00000001 << DAQ_REG_HRDWRE_OW_MASTER_OFST) #define DAQ_REG_HRDWRE_OW_MASTER_MSK (0x00000001 << DAQ_REG_HRDWRE_OW_MASTER_OFST)
#define DAQ_REG_HRDWRE_MASTER_OFST (4) #define DAQ_REG_HRDWRE_MASTER_OFST (4)
#define DAQ_REG_HRDWRE_MASTER_MSK (0x00000001 << DAQ_REG_HRDWRE_MASTER_OFST) #define DAQ_REG_HRDWRE_MASTER_MSK (0x00000001 << DAQ_REG_HRDWRE_MASTER_OFST)
#define DAQ_REG_HRDWRE_DSBL_16BIT_OFST (5)
#define DAQ_REG_HRDWRE_DSBL_16BIT_MSK (0x00000001 << DAQ_REG_HRDWRE_DSBL_16BIT_OFST)
#define DAQ_REG_HRDWRE_PROGRAM_OFST (30) #define DAQ_REG_HRDWRE_PROGRAM_OFST (30)
#define DAQ_REG_HRDWRE_PROGRAM_MSK (0x00000001 << DAQ_REG_HRDWRE_PROGRAM_OFST) #define DAQ_REG_HRDWRE_PROGRAM_MSK (0x00000001 << DAQ_REG_HRDWRE_PROGRAM_OFST)
#define DAQ_REG_HRDWRE_M8_OFST (31) #define DAQ_REG_HRDWRE_M8_OFST (31)

View File

@ -26,12 +26,17 @@ extern int updateFlag;
extern udpStruct udpDetails[MAX_UDP_DESTINATION]; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern int numUdpDestinations; extern int numUdpDestinations;
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
extern int ignoreConfigFileFlag;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
extern int isControlServer; extern int isControlServer;
extern void getMacAddressinString(char *cmac, int size, uint64_t mac); extern void getMacAddressinString(char *cmac, int size, uint64_t mac);
extern void getIpAddressinString(char *cip, uint32_t ip); extern void getIpAddressinString(char *cip, uint32_t ip);
// Variables that will be exported
int masterCommandLine = -1;
int topCommandLine = -1;
int initError = OK; int initError = OK;
int initCheckDone = 0; int initCheckDone = 0;
char initErrorMessage[MAX_STR_LENGTH]; char initErrorMessage[MAX_STR_LENGTH];
@ -226,6 +231,23 @@ int getModuleId(int *ret, char *mess) {
return getModuleIdInFile(ret, mess, ID_FILE); return getModuleIdInFile(ret, mess, ID_FILE);
} }
int updateModuleId() {
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return FAIL;
}
#ifdef VIRTUAL
eiger_virtual_module_id = modid;
#else
if (Beb_SetModuleId(modid) == FAIL) {
initError = FAIL;
strcpy(initErrorMessage, ("Could not get module id from the file"));
return FAIL;
}
#endif
return OK;
}
u_int64_t getDetectorMAC() { u_int64_t getDetectorMAC() {
char mac[255] = ""; char mac[255] = "";
u_int64_t res = 0; u_int64_t res = 0;
@ -305,46 +327,36 @@ u_int32_t getDetectorIP() {
void initControlServer() { void initControlServer() {
LOG(logINFOBLUE, ("Configuring Control server\n")); LOG(logINFOBLUE, ("Configuring Control server\n"));
if (!updateFlag && initError == OK) { if (!updateFlag && initError == OK) {
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE); if (updateModuleConfiguration() == FAIL) {
#ifdef VIRTUAL initCheckDone = 1;
eiger_virtual_module_id = modid;
#endif
if (initError == FAIL) {
return; return;
} }
getModuleConfiguration();
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink(); sharedMemory_lockLocalLink();
Feb_Control_SetMasterVariable(master);
Feb_Interface_FebInterface(); Feb_Interface_FebInterface();
Feb_Control_FebControl(); if (!Feb_Control_FebControl(normal)) {
// same addresses for top and bottom
if (!Feb_Control_Init(master, normal)) {
initError = FAIL; initError = FAIL;
sprintf(initErrorMessage, "Could not intitalize feb control\n"); sprintf(initErrorMessage,
"Could not intitalize eiger detector sever: feb control\n");
LOG(logERROR, (initErrorMessage)); LOG(logERROR, (initErrorMessage));
initCheckDone = 1; initCheckDone = 1;
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
return; return;
} }
// master of 9M, check high voltage serial communication to blackfin if (Feb_Control_SetMasterEffects(master, isControlServer) == FAIL) {
if (master && !normal) { initError = FAIL;
if (!Feb_Control_OpenSerialCommunication()) { sprintf(initErrorMessage, "Could not intitalize HV for eiger "
initError = FAIL; "detector server: feb control serial "
sprintf( "communication\n");
initErrorMessage, LOG(logERROR, (initErrorMessage));
"Could not intitalize feb control serial communication\n"); initCheckDone = 1;
LOG(logERROR, (initErrorMessage)); sharedMemory_unlockLocalLink();
initCheckDone = 1; return;
sharedMemory_unlockLocalLink();
return;
}
} }
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
LOG(logDEBUG1, ("Control server: FEB Initialization done\n")); LOG(logDEBUG1, ("Control server: FEB Initialization done\n"));
Beb_SetTopVariable(top); Beb_SetTopVariable(top);
Beb_Beb(); Beb_Beb();
Beb_SetModuleId(modid);
LOG(logDEBUG1, ("Control server: BEB Initialization done\n")); LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
#endif #endif
// also reads config file and deactivates // also reads config file and deactivates
@ -354,73 +366,126 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
// wait a few s (control server is setting top/master from config file/
// command line)
usleep(WAIT_STOP_SERVER_START);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
if (updateModuleConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
#ifdef VIRTUAL #ifdef VIRTUAL
LOG(logINFOBLUE, ("Configuring Stop server\n")); sharedMemory_setStop(0);
getModuleConfiguration(); // force top or master if in config file
sharedMemory_setStop(0); if (readConfigFile() == FAIL) {
// get top/master in virtual initCheckDone = 1;
readConfigFile(); return;
}
// force top or master if in command line
if (checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
#else #else
// wait a few s (control server is setting top/master from config file) // control server read config file and already set up master/top
usleep(WAIT_STOP_SERVER_START); sharedMemory_lockLocalLink();
LOG(logINFOBLUE, ("Configuring Stop server\n")); Feb_Interface_FebInterface();
// exit(-1); if (!Feb_Control_FebControl(normal)) {
getModuleConfiguration(); initError = FAIL;
sharedMemory_lockLocalLink(); sprintf(initErrorMessage, "Could not intitalize feb control\n");
Feb_Control_SetMasterVariable(master); LOG(logERROR, (initErrorMessage));
Feb_Interface_FebInterface(); initCheckDone = 1;
Feb_Control_FebControl(); sharedMemory_unlockLocalLink();
// same addresses for top and bottom return;
Feb_Control_Init(master, normal); }
sharedMemory_unlockLocalLink(); if (Feb_Control_SetMasterEffects(master, isControlServer) == FAIL) {
LOG(logDEBUG1, ("Stop server: FEB Initialization done\n")); initError = FAIL;
sprintf(initErrorMessage, "Could not intitalize HV for eiger "
"detector server: feb control serial "
"communication\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
sharedMemory_unlockLocalLink();
return;
}
sharedMemory_unlockLocalLink();
LOG(logDEBUG1, ("Stop server: FEB Initialization done\n"));
Beb_SetTopVariable(top);
Beb_Beb();
LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
#endif #endif
// client first connect (from shm) will activate // client first connect (from shm) will activate
if (setActivate(0) == FAIL) { if (setActivate(0) == FAIL) {
LOG(logERROR, ("Could not deactivate in stop server\n")); initError = FAIL;
strcpy(initErrorMessage, "Could not deactivate\n");
LOG(logERROR, (initErrorMessage));
}
} }
initCheckDone = 1;
} }
void getModuleConfiguration() { void checkVirtual9MFlag() {
if (initError == FAIL) {
return;
}
#ifdef VIRTUAL #ifdef VIRTUAL
#ifdef VIRTUAL_MASTER
master = 1;
top = 1;
#else
master = 0;
#ifdef VIRTUAL_TOP
top = 1;
#else
top = 0;
#endif
#endif
#ifdef VIRTUAL_9M #ifdef VIRTUAL_9M
normal = 0; normal = 0;
#else #else
normal = 1; normal = 1;
#endif #endif
#endif
}
#else int updateModuleConfiguration() {
Beb_GetModuleConfiguration(&master, &top, &normal); if (getModuleConfiguration(&master, &top, &normal) == FAIL) {
return FAIL;
}
#ifdef VIRTUAL
checkVirtual9MFlag();
#endif #endif
if (isControlServer) { if (isControlServer) {
LOG(logINFOBLUE, LOG(logINFOBLUE,
("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"), ("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"),
(master ? "MASTER" : "SLAVE"), (normal ? "NORMAL" : "SPECIAL"))); (master ? "MASTER" : "SLAVE"), (normal ? "NORMAL" : "SPECIAL")));
} }
return OK;
}
int getModuleConfiguration(int *m, int *t, int *n) {
if (initError == FAIL) {
return FAIL;
}
#ifdef VIRTUAL
*m = master;
*t = top;
*n = normal;
#else
if (Beb_GetModuleConfiguration(m, t, n) == FAIL) {
initError = FAIL;
strcpy(initErrorMessage, ("Could not get module configuration\n"));
LOG(logERROR, (initErrorMessage));
return FAIL;
}
#endif
LOG(logDEBUG,
("module config read: master:%d top:%d normal:%d\n", *m, *t, *n));
return OK;
} }
int readConfigFile() { int readConfigFile() {
if (initError == FAIL) { if (initError == FAIL) {
return initError; return initError;
} }
master = -1;
if (ignoreConfigFileFlag) {
LOG(logWARNING, ("Ignoring Config file\n"));
return OK;
}
#ifndef VIRTUAL
// if not found in config file, they will be reset to hardware settings
top = -1; top = -1;
master = -1;
#endif
const int fileNameSize = 128; const int fileNameSize = 128;
char fname[fileNameSize]; char fname[fileNameSize];
@ -471,91 +536,54 @@ int readConfigFile() {
// top command // top command
if (!strncmp(line, "top", strlen("top"))) { if (!strncmp(line, "top", strlen("top"))) {
int t = -1;
// cannot scan values // cannot scan values
if (sscanf(line, "%s %d", command, &top) != 2) { if (sscanf(line, "%s %d", command, &t) != 2) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not scan top commands from on-board server " "Could not scan top commands from on-board server "
"config file. Line:[%s].\n", "config file. Line:[%s].\n",
line); line);
break; break;
} }
#ifndef VIRTUAL if (t != 0 && t != 1) {
enum TOPINDEX ind = (top == 1 ? OW_TOP : OW_BOTTOM); sprintf(initErrorMessage,
if (!Beb_SetTop(ind)) { "Invalid top argument from on-board server "
sprintf( "config file. Line:[%s].\n",
initErrorMessage, line);
"Could not overwrite top to %d in Beb from on-board server "
"config file. Line:[%s].\n",
top, line);
break; break;
} }
sharedMemory_lockLocalLink(); if (setTop(t == 1 ? OW_TOP : OW_BOTTOM) == FAIL) {
if (!Feb_Control_SetTop(ind, 1, 1)) { sprintf(initErrorMessage,
sprintf( "Could not set top from config file. Line:[%s].\n",
initErrorMessage, line);
"Could not overwrite top to %d in Feb from on-board server "
"config file. Line:[%s].\n",
top, line);
sharedMemory_unlockLocalLink();
break; break;
} }
sharedMemory_unlockLocalLink();
// validate change
int actual_top = -1, temp = -1, temp2 = -1;
Beb_GetModuleConfiguration(&temp, &actual_top, &temp2);
if (actual_top != top) {
sprintf(initErrorMessage, "Could not set top to %d. Read %d\n",
top, actual_top);
break;
}
Beb_SetTopVariable(top);
#endif
} }
// master command // master command
else if (!strncmp(line, "master", strlen("master"))) { else if (!strncmp(line, "master", strlen("master"))) {
int m = -1;
// cannot scan values // cannot scan values
if (sscanf(line, "%s %d", command, &master) != 2) { if (sscanf(line, "%s %d", command, &m) != 2) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not scan master commands from on-board server " "Could not scan master commands from on-board server "
"config file. Line:[%s].\n", "config file. Line:[%s].\n",
line); line);
break; break;
} }
#ifndef VIRTUAL if (m != 0 && m != 1) {
enum MASTERINDEX ind = (master == 1 ? OW_MASTER : OW_SLAVE);
if (!Beb_SetMaster(ind)) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not overwrite master to %d in Beb from on-board " "Invalid master argument from on-board server "
"server "
"config file. Line:[%s].\n", "config file. Line:[%s].\n",
master, line); line);
break; break;
} }
sharedMemory_lockLocalLink(); if (setMaster(m == 1 ? OW_MASTER : OW_SLAVE) == FAIL) {
if (!Feb_Control_SetMaster(ind)) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not overwrite master to %d in Feb from on-board " "Could not set master from config file. Line:[%s].\n",
"server " line);
"config file. Line:[%s].\n",
master, line);
sharedMemory_unlockLocalLink();
break; break;
} }
sharedMemory_unlockLocalLink();
// validate change
int actual_master = -1, temp = -1, temp2 = -1;
Beb_GetModuleConfiguration(&actual_master, &temp, &temp2);
if (actual_master != master) {
sprintf(initErrorMessage,
"Could not set master to %d. Read %d\n", master,
actual_master);
break;
}
sharedMemory_lockLocalLink();
Feb_Control_SetMasterVariable(master);
sharedMemory_unlockLocalLink();
#endif
} }
// other commands // other commands
@ -576,8 +604,10 @@ int readConfigFile() {
LOG(logINFO, ("Successfully read config file\n")); LOG(logINFO, ("Successfully read config file\n"));
} }
#ifndef VIRTUAL
// reset to hardware settings if not in config file (if overwritten) // reset to hardware settings if not in config file (if overwritten)
resetToHardwareSettings(); resetToHardwareSettings();
#endif
return initError; return initError;
} }
@ -589,55 +619,56 @@ void resetToHardwareSettings() {
} }
// top not set in config file // top not set in config file
if (top == -1) { if (top == -1) {
if (!Beb_SetTop(TOP_HARDWARE)) { LOG(logINFO, ("Resetting Top to hardware settings\n"));
if (setTop(TOP_HARDWARE) == FAIL) {
initError = FAIL; initError = FAIL;
strcpy(initErrorMessage, strcpy(initErrorMessage,
"Could not reset Top flag to Beb hardware settings.\n"); "Could not reset Top flag to hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage)); LOG(logERROR, ("%s\n\n", initErrorMessage));
return; return;
} }
sharedMemory_lockLocalLink();
if (!Feb_Control_SetTop(TOP_HARDWARE, 1, 1)) {
initError = FAIL;
strcpy(initErrorMessage,
"Could not reset Top flag to Feb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
sharedMemory_unlockLocalLink();
return;
}
sharedMemory_unlockLocalLink();
int temp = -1, temp2 = -1;
Beb_GetModuleConfiguration(&temp, &top, &temp2);
Beb_SetTopVariable(top);
} }
// master not set in config file // master not set in config file
if (master == -1) { if (master == -1) {
if (!Beb_SetMaster(TOP_HARDWARE)) { LOG(logINFO, ("Resetting Master to hardware settings\n"));
if (setMaster(MASTER_HARDWARE) == FAIL) {
initError = FAIL; initError = FAIL;
strcpy(initErrorMessage, strcpy(initErrorMessage,
"Could not reset Master flag to Beb hardware settings.\n"); "Could not reset Master flag to hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage)); LOG(logERROR, ("%s\n\n", initErrorMessage));
return; return;
} }
sharedMemory_lockLocalLink();
if (!Feb_Control_SetMaster(TOP_HARDWARE)) {
initError = FAIL;
strcpy(initErrorMessage,
"Could not reset Master flag to Feb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
sharedMemory_unlockLocalLink();
return;
}
sharedMemory_unlockLocalLink();
int temp = -1, temp2 = -1;
Beb_GetModuleConfiguration(&master, &temp, &temp2);
sharedMemory_lockLocalLink();
Feb_Control_SetMasterVariable(master);
sharedMemory_unlockLocalLink();
} }
#endif #endif
} }
int checkCommandLineConfiguration() {
if (masterCommandLine != -1) {
LOG(logINFO, ("Setting %s from Command Line\n",
(masterCommandLine == 1 ? "Master" : "Slave")));
if (setMaster(masterCommandLine == 1 ? OW_MASTER : OW_SLAVE) == FAIL) {
initError = FAIL;
sprintf(initErrorMessage, "Could not set %s from command line.\n",
(masterCommandLine == 1 ? "Master" : "Slave"));
LOG(logERROR, (initErrorMessage));
return FAIL;
}
}
if (topCommandLine != -1) {
LOG(logINFO, ("Setting %s from Command Line\n",
(topCommandLine == 1 ? "Top" : "Bottom")));
if (setTop(topCommandLine == 1 ? OW_TOP : OW_BOTTOM) == FAIL) {
initError = FAIL;
sprintf(initErrorMessage, "Could not set %s from command line.\n",
(topCommandLine == 1 ? "Top" : "Bottom"));
LOG(logERROR, (initErrorMessage));
return FAIL;
}
}
return OK;
}
/* set up detector */ /* set up detector */
void allocateDetectorStructureMemory() { void allocateDetectorStructureMemory() {
@ -671,15 +702,29 @@ void allocateDetectorStructureMemory() {
} }
void setupDetector() { void setupDetector() {
allocateDetectorStructureMemory(); allocateDetectorStructureMemory();
// force top or master if in config file
if (readConfigFile() == FAIL)
return;
// force top or master if in command line
if (checkCommandLineConfiguration() == FAIL)
return;
LOG(logINFOBLUE,
("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"),
(master ? "MASTER" : "SLAVE"), (normal ? "NORMAL" : "SPECIAL")));
if (updateModuleId() == FAIL)
return;
LOG(logINFOBLUE, ("Setting Default Parameters\n"));
resetToDefaultDacs(0); resetToDefaultDacs(0);
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStatus(IDLE); sharedMemory_setStatus(IDLE);
setupUDPCommParameters(); setupUDPCommParameters();
#endif #endif
LOG(logINFOBLUE, ("Setting Default Parameters\n"));
// setting default measurement parameters // setting default measurement parameters
setNumFrames(DEFAULT_NUM_FRAMES); setNumFrames(DEFAULT_NUM_FRAMES);
setExpTime(DEFAULT_EXPTIME); setExpTime(DEFAULT_EXPTIME);
@ -719,14 +764,6 @@ void setupDetector() {
} }
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
#endif #endif
// force top or master if in config file
if (readConfigFile() == FAIL) {
return;
}
LOG(logINFOBLUE,
("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"),
(master ? "MASTER" : "SLAVE"), (normal ? "NORMAL" : "SPECIAL")));
if (setNumberofDestinations(numUdpDestinations) == FAIL) { if (setNumberofDestinations(numUdpDestinations) == FAIL) {
initError = FAIL; initError = FAIL;
strcpy(initErrorMessage, "Could not set number of udp destinations\n"); strcpy(initErrorMessage, "Could not set number of udp destinations\n");
@ -821,29 +858,38 @@ int readRegister(uint32_t offset, uint32_t *retval) {
/* set parameters - dr, roi */ /* set parameters - dr, roi */
int setDynamicRange(int dr) { int setDynamicRange(int dr) {
// setting dr if (dr <= 0) {
if (dr > 0) { return FAIL;
LOG(logDEBUG1, ("Setting dynamic range: %d\n", dr));
#ifndef VIRTUAL
sharedMemory_lockLocalLink();
if (Feb_Control_SetDynamicRange(dr)) {
if (!Beb_SetUpTransferParameters(dr)) {
LOG(logERROR, ("Could not set bit mode in the back end\n"));
sharedMemory_unlockLocalLink();
return eiger_dynamicrange;
}
}
sharedMemory_unlockLocalLink();
#endif
eiger_dynamicrange = dr;
} }
// getting dr #ifdef VIRTUAL
#ifndef VIRTUAL LOG(logINFO, ("Setting dynamic range: %d\n", dr));
#else
sharedMemory_lockLocalLink(); sharedMemory_lockLocalLink();
eiger_dynamicrange = Feb_Control_GetDynamicRange(); if (Feb_Control_SetDynamicRange(dr)) {
if (!Beb_SetUpTransferParameters(dr)) {
LOG(logERROR, ("Could not set bit mode in the back end\n"));
sharedMemory_unlockLocalLink();
return eiger_dynamicrange;
}
}
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
#endif #endif
return eiger_dynamicrange; eiger_dynamicrange = dr;
return OK;
}
int getDynamicRange(int *retval) {
#ifdef VIRTUAL
*retval = eiger_dynamicrange;
#else
sharedMemory_lockLocalLink();
if (!Feb_Control_GetDynamicRange(retval)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
#endif
return OK;
} }
/* parameters - readout */ /* parameters - readout */
@ -1158,6 +1204,7 @@ int setModule(sls_detector_module myMod, char *mess) {
// if quad, set M8 and PROGRAM manually // if quad, set M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(1)) { if (!Feb_Control_SetChipSignalsToTrimQuad(1)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
@ -1170,6 +1217,7 @@ int setModule(sls_detector_module myMod, char *mess) {
// if quad, reset M8 and PROGRAM manually // if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) { if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
@ -1179,6 +1227,7 @@ int setModule(sls_detector_module myMod, char *mess) {
// if quad, reset M8 and PROGRAM manually // if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) { if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
@ -1450,7 +1499,120 @@ int setHighVoltage(int val) {
/* parameters - timing, extsig */ /* parameters - timing, extsig */
int isMaster() { return master; } int setMaster(enum MASTERINDEX m) {
char *master_names[] = {MASTER_NAMES};
LOG(logINFOBLUE, ("Setting up Master flag as %s\n", master_names[m]));
#ifdef VIRTUAL
switch (m) {
case OW_MASTER:
master = 1;
break;
case OW_SLAVE:
master = 0;
break;
default:
// hardware settings (do nothing)
break;
}
#else
// need to set it only once via the control server
if (isControlServer) {
if (!Beb_SetMaster(m)) {
return FAIL;
}
sharedMemory_lockLocalLink();
if (!Feb_Control_SetMaster(m)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
}
// get and update master variable (cannot get from m, could be hardware)
if (isMaster(&master) == FAIL) {
return FAIL;
}
// verify for master and slave (not hardware)
if ((m == OW_MASTER && master == 0) || (m == OW_SLAVE && master == 1)) {
LOG(logERROR,
("could not set master/slave. Master value retrieved %d\n",
master));
return FAIL;
}
// feb variable and hv comms (9m)
sharedMemory_lockLocalLink();
if (Feb_Control_SetMasterEffects(master, isControlServer) == FAIL) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
#endif
return OK;
}
int isMaster(int *retval) {
int m = -1, t = -1, n = -1;
if (getModuleConfiguration(&m, &t, &n) == FAIL) {
return FAIL;
}
*retval = m;
return OK;
}
int setTop(enum TOPINDEX t) {
char *top_names[] = {TOP_NAMES};
LOG(logINFOBLUE, ("Setting up Top flag as %s\n", top_names[t]));
#ifdef VIRTUAL
switch (t) {
case OW_TOP:
top = 1;
break;
case OW_BOTTOM:
top = 0;
break;
default:
// hardware settings (do nothing)
break;
}
#else
if (!Beb_SetTop(t)) {
return FAIL;
}
sharedMemory_lockLocalLink();
if (!Feb_Control_SetTop(t, 1, 1)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
// get and update top variable(cannot get from t, could be hardware)
if (isTop(&top) == FAIL) {
return FAIL;
}
// verify for master and slave (not hardware)
if ((t == OW_TOP && top == 0) || (t == OW_BOTTOM && top == 1)) {
LOG(logERROR,
("could not set top/bottom. Top value retrieved %d\n", top));
return FAIL;
}
Beb_SetTopVariable(top);
#endif
return OK;
}
int isTop(int *retval) {
int m = -1, t = -1, n = -1;
if (getModuleConfiguration(&m, &t, &n) == FAIL) {
return FAIL;
}
*retval = t;
return OK;
}
void setTiming(enum timingMode arg) { void setTiming(enum timingMode arg) {
int ret = 0; int ret = 0;
@ -1923,7 +2085,8 @@ int setRateCorrection(
else if (custom_tau_in_nsec == -1) else if (custom_tau_in_nsec == -1)
custom_tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec(); custom_tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec();
int dr = Feb_Control_GetDynamicRange(); int dr = eiger_dynamicrange;
// get period = subexptime if 32bit , else period = exptime if 16 bit // get period = subexptime if 32bit , else period = exptime if 16 bit
int64_t actual_period = int64_t actual_period =
Feb_Control_GetSubFrameExposureTime(); // already in nsec Feb_Control_GetSubFrameExposureTime(); // already in nsec
@ -2105,6 +2268,9 @@ int setDataStream(enum portPosition port, int enable) {
LOG(logERROR, ("Invalid setDataStream enable argument: %d\n", enable)); LOG(logERROR, ("Invalid setDataStream enable argument: %d\n", enable));
return FAIL; return FAIL;
} }
LOG(logINFO,
("%s 10GbE %s datastream\n", (enable ? "Enabling" : "Disabling"),
(port == LEFT ? "left" : "right")));
#ifdef VIRTUAL #ifdef VIRTUAL
if (port == LEFT) { if (port == LEFT) {
eiger_virtual_left_datastream = enable; eiger_virtual_left_datastream = enable;
@ -2318,7 +2484,7 @@ void *start_timer(void *arg) {
const int maxRows = MAX_ROWS_PER_READOUT; const int maxRows = MAX_ROWS_PER_READOUT;
const int packetsPerFrame = (maxPacketsPerFrame * readNRows) / maxRows; const int packetsPerFrame = (maxPacketsPerFrame * readNRows) / maxRows;
LOG(logDEBUG1, LOG(logDEBUG,
(" dr:%d\n bytesperpixel:%f\n tgenable:%d\n datasize:%d\n " (" dr:%d\n bytesperpixel:%f\n tgenable:%d\n datasize:%d\n "
"packetsize:%d\n maxnumpackes:%d\n npixelsx:%d\n databytes:%d\n", "packetsize:%d\n maxnumpackes:%d\n npixelsx:%d\n databytes:%d\n",
dr, bytesPerPixel, tgEnable, datasize, packetsize, maxPacketsPerFrame, dr, bytesPerPixel, tgEnable, datasize, packetsize, maxPacketsPerFrame,
@ -2335,11 +2501,13 @@ void *start_timer(void *arg) {
npixels /= 2; npixels /= 2;
} }
LOG(logDEBUG1, LOG(logDEBUG1,
("pixels:%d pixelsperpacket:%d\n", npixels, pixelsPerPacket)); ("npixels:%d pixelsperpacket:%d\n", npixels, pixelsPerPacket));
uint8_t *src = (uint8_t *)imageData;
for (int i = 0; i < npixels; ++i) { for (int i = 0; i < npixels; ++i) {
if (i > 0 && i % pixelsPerPacket == 0) { if (i > 0 && i % pixelsPerPacket == 0) {
++pixelVal; ++pixelVal;
} }
switch (dr) { switch (dr) {
case 4: case 4:
*((uint8_t *)(imageData + i)) = *((uint8_t *)(imageData + i)) =
@ -2354,6 +2522,30 @@ void *start_timer(void *arg) {
*((uint8_t *)(imageData + i)) = *((uint8_t *)(imageData + i)) =
eiger_virtual_test_mode ? 0xFE : (uint8_t)pixelVal; eiger_virtual_test_mode ? 0xFE : (uint8_t)pixelVal;
break; break;
case 12:
if (eiger_virtual_test_mode) {
// first 12 bit pixel
// first 8 byte
*src++ = 0xFE;
// second 12bit pixel
++i;
// second 8 byte
*src++ = 0xEF;
// third byte
*src++ = 0xFF;
} else {
// first 12 bit pixel
// first 8 byte
*src++ = (uint8_t)(i & 0xFF);
// second 8 byte (first nibble)
*src = (uint8_t)((i++ >> 8u) & 0xF);
// second 12bit pixel
// second 8 byte (second nibble)
*src++ |= ((uint8_t)(i & 0xF) << 4u);
// third byte
*src++ = (uint8_t)((i >> 4u) & 0xFF);
}
break;
case 16: case 16:
*((uint16_t *)(imageData + i * sizeof(uint16_t))) = *((uint16_t *)(imageData + i * sizeof(uint16_t))) =
eiger_virtual_test_mode ? 0xFFE : (uint16_t)pixelVal; eiger_virtual_test_mode ? 0xFFE : (uint16_t)pixelVal;
@ -2430,9 +2622,27 @@ void *start_timer(void *arg) {
// fill data // fill data
int dstOffset = sizeof(sls_detector_header); int dstOffset = sizeof(sls_detector_header);
int dstOffset2 = sizeof(sls_detector_header); int dstOffset2 = sizeof(sls_detector_header);
{ if (dr == 12) {
for (int psize = 0; psize < datasize; psize += npixelsx) { // multiple of 768,1024,4096
int copysize = 256;
for (int psize = 0; psize < datasize; psize += copysize) {
memcpy(packetData + dstOffset, imageData + srcOffset,
copysize);
memcpy(packetData2 + dstOffset2, imageData + srcOffset2,
copysize);
srcOffset += copysize;
srcOffset2 += copysize;
dstOffset += copysize;
dstOffset2 += copysize;
// reached 1 row (quarter module)
if ((srcOffset % npixelsx) == 0) {
srcOffset += npixelsx;
srcOffset2 += npixelsx;
}
}
} else {
for (int psize = 0; psize < datasize; psize += npixelsx) {
if (dr == 32 && tgEnable == 0) { if (dr == 32 && tgEnable == 0) {
memcpy(packetData + dstOffset, memcpy(packetData + dstOffset,
imageData + srcOffset, npixelsx / 2); imageData + srcOffset, npixelsx / 2);
@ -2730,9 +2940,9 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
int calculateDataBytes() { int calculateDataBytes() {
if (send_to_ten_gig) if (send_to_ten_gig)
return setDynamicRange(-1) * ONE_GIGA_CONSTANT * TEN_GIGA_BUFFER_SIZE; return eiger_dynamicrange * ONE_GIGA_CONSTANT * TEN_GIGA_BUFFER_SIZE;
else else
return setDynamicRange(-1) * TEN_GIGA_CONSTANT * ONE_GIGA_BUFFER_SIZE; return eiger_dynamicrange * TEN_GIGA_CONSTANT * ONE_GIGA_BUFFER_SIZE;
} }
int getTotalNumberOfChannels() { int getTotalNumberOfChannels() {

View File

@ -5,7 +5,7 @@
#define LINKED_SERVER_NAME "eigerDetectorServer" #define LINKED_SERVER_NAME "eigerDetectorServer"
#define REQUIRED_FIRMWARE_VERSION (29) #define REQUIRED_FIRMWARE_VERSION (30)
// virtual ones renamed for consistency // virtual ones renamed for consistency
// real ones keep previous name for compatibility (already in production) // real ones keep previous name for compatibility (already in production)
#ifdef VIRTUAL #ifdef VIRTUAL

View File

@ -28,12 +28,16 @@ extern int updateFlag;
extern int checkModuleFlag; extern int checkModuleFlag;
extern udpStruct udpDetails[MAX_UDP_DESTINATION]; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
extern int ignoreConfigFileFlag;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
extern int isControlServer; extern int isControlServer;
extern void getMacAddressinString(char *cmac, int size, uint64_t mac); extern void getMacAddressinString(char *cmac, int size, uint64_t mac);
extern void getIpAddressinString(char *cip, uint32_t ip); extern void getIpAddressinString(char *cip, uint32_t ip);
// Variables that will be exported
int masterCommandLine = -1;
int initError = OK; int initError = OK;
int initCheckDone = 0; int initCheckDone = 0;
char initErrorMessage[MAX_STR_LENGTH]; char initErrorMessage[MAX_STR_LENGTH];
@ -69,6 +73,7 @@ int64_t burstPeriodReg = 0;
int filterResistor = 0; int filterResistor = 0;
int cdsGain = 0; int cdsGain = 0;
int detPos[2] = {}; int detPos[2] = {};
int master = 1;
int isInitCheckDone() { return initCheckDone; } int isInitCheckDone() { return initCheckDone; }
@ -295,6 +300,18 @@ void setModuleId(int modid) {
bus_r(MOD_ID_REG) | ((modid << MOD_ID_OFST) & MOD_ID_MSK)); bus_r(MOD_ID_REG) | ((modid << MOD_ID_OFST) & MOD_ID_MSK));
} }
int updateModuleId() {
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return FAIL;
}
#ifdef VIRTUAL
virtual_moduleid = modid;
#endif
setModuleId(modid);
return OK;
}
u_int64_t getDetectorMAC() { u_int64_t getDetectorMAC() {
#ifdef VIRTUAL #ifdef VIRTUAL
return 0; return 0;
@ -358,16 +375,27 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) { LOG(logINFOBLUE, ("Configuring Stop server\n"));
LOG(logERROR, if (mapCSP0() == FAIL) {
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); initError = FAIL;
exit(EXIT_FAILURE); strcpy(initErrorMessage,
} "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
// not reading config file (nothing of interest to stop server)
if (checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
#endif #endif
}
initCheckDone = 1;
} }
/* set up detector */ /* set up detector */
@ -480,15 +508,13 @@ void setupDetector() {
return; return;
} }
// set module id in register // master for virtual
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE); if (checkCommandLineConfiguration() == FAIL)
#ifdef VIRTUAL return;
virtual_moduleid = modid;
#endif if (updateModuleId() == FAIL) {
if (initError == FAIL) {
return; return;
} }
setModuleId(modid);
setBurstMode(DEFAULT_BURST_MODE); setBurstMode(DEFAULT_BURST_MODE);
setFilterResistor(DEFAULT_FILTER_RESISTOR); setFilterResistor(DEFAULT_FILTER_RESISTOR);
@ -600,6 +626,11 @@ int readConfigFile() {
return initError; return initError;
} }
if (ignoreConfigFileFlag) {
LOG(logWARNING, ("Ignoring Config file\n"));
return OK;
}
// require a sleep before and after the rst dac signal // require a sleep before and after the rst dac signal
usleep(INITIAL_STARTUP_WAIT); usleep(INITIAL_STARTUP_WAIT);
@ -924,6 +955,21 @@ int readConfigFile() {
return initError; return initError;
} }
int checkCommandLineConfiguration() {
if (masterCommandLine != -1) {
#ifdef VIRTUAL
master = masterCommandLine;
#else
initError = FAIL;
strcpy(initErrorMessage,
"Cannot set Master from command line for this detector. "
"Should have been caught before!\n");
return FAIL;
#endif
}
return OK;
}
/* firmware functions (resets) */ /* firmware functions (resets) */
void cleanFifos() { void cleanFifos() {
@ -952,7 +998,16 @@ void resetPeripheral() {
/* set parameters - dr, roi */ /* set parameters - dr, roi */
int setDynamicRange(int dr) { return DYNAMIC_RANGE; } int setDynamicRange(int dr) {
if (dr == 16)
return OK;
return FAIL;
}
int getDynamicRange(int *retval) {
*retval = DYNAMIC_RANGE;
return OK;
}
/* parameters - timer */ /* parameters - timer */
void setNumFrames(int64_t val) { void setNumFrames(int64_t val) {
@ -1442,6 +1497,11 @@ int setHighVoltage(int val) {
/* parameters - timing */ /* parameters - timing */
int isMaster(int *retval) {
*retval = master;
return OK;
}
void updatingRegisters() { void updatingRegisters() {
LOG(logINFO, ("\tUpdating registers\n")); LOG(logINFO, ("\tUpdating registers\n"));
// burst // burst
@ -1921,9 +1981,17 @@ int checkDetectorType() {
return -2; return -2;
} }
if ((abs(type - TYPE_GOTTHARD2_MODULE_VAL) > TYPE_TOLERANCE) && if (abs(type - TYPE_GOTTHARD2_25UM_MASTER_MODULE_VAL) <= TYPE_TOLERANCE) {
(abs(type - TYPE_GOTTHARD2_25UM_MASTER_MODULE_VAL) > TYPE_TOLERANCE) && LOG(logINFOBLUE, ("MASTER 25um Module\n"));
(abs(type - TYPE_GOTTHARD2_25UM_SLAVE_MODULE_VAL) > TYPE_TOLERANCE)) { master = 1;
} else if (abs(type - TYPE_GOTTHARD2_25UM_SLAVE_MODULE_VAL) <=
TYPE_TOLERANCE) {
master = 0;
LOG(logINFOBLUE, ("SLAVE 25um Module\n"));
} else if (abs(type - TYPE_GOTTHARD2_MODULE_VAL) <= TYPE_TOLERANCE) {
master = -1;
LOG(logINFOBLUE, ("50um Module\n"));
} else {
LOG(logERROR, LOG(logERROR,
("Wrong Module attached! Expected %d, %d or %d for Gotthard2, got " ("Wrong Module attached! Expected %d, %d or %d for Gotthard2, got "
"%d\n", "%d\n",

View File

@ -25,9 +25,11 @@ extern int debugflag;
extern int updateFlag; extern int updateFlag;
extern udpStruct udpDetails[MAX_UDP_DESTINATION]; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
extern int ignoreConfigFileFlag;
// Variables that will be exported // Variables that will be exported
int phaseShift = DEFAULT_PHASE_SHIFT; int phaseShift = DEFAULT_PHASE_SHIFT;
int masterCommandLine = -1;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
extern int isControlServer; extern int isControlServer;
@ -359,16 +361,28 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (mapCSP0() == FAIL) { if (!updateFlag && initError == OK) {
LOG(logERROR, usleep(CTRL_SRVR_INIT_TIME_US);
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); LOG(logINFOBLUE, ("Configuring Stop server\n"));
exit(EXIT_FAILURE); if (mapCSP0() == FAIL) {
} initError = FAIL;
strcpy(initErrorMessage,
"Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
#endif #endif
// to get master from file // to get master from file
readConfigFile(); if (readConfigFile() == FAIL ||
checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
}
initCheckDone = 1;
} }
/* set up detector */ /* set up detector */
@ -421,6 +435,13 @@ void setupDetector() {
setROI(rois); // set adcsyncreg, daqreg, chipofinterestreg, cleanfifos, setROI(rois); // set adcsyncreg, daqreg, chipofinterestreg, cleanfifos,
setGbitReadout(); setGbitReadout();
// no config file or not first time server
if (readConfigFile() == FAIL)
return;
if (checkCommandLineConfiguration() == FAIL)
return;
// master, slave (25um) // master, slave (25um)
setMasterSlaveConfiguration(); setMasterSlaveConfiguration();
@ -624,6 +645,16 @@ void setGbitReadout() {
} }
int readConfigFile() { int readConfigFile() {
if (initError == FAIL) {
return initError;
}
if (ignoreConfigFileFlag) {
LOG(logWARNING, ("Ignoring Config file\n"));
return OK;
}
const int fileNameSize = 128; const int fileNameSize = 128;
char fname[fileNameSize]; char fname[fileNameSize];
if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) { if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) {
@ -647,7 +678,6 @@ int readConfigFile() {
memset(key, 0, keySize); memset(key, 0, keySize);
char value[keySize]; char value[keySize];
memset(value, 0, keySize); memset(value, 0, keySize);
int scan = OK;
// keep reading a line // keep reading a line
while (fgets(line, lineSize, fd)) { while (fgets(line, lineSize, fd)) {
@ -667,19 +697,22 @@ int readConfigFile() {
master = 0; master = 0;
LOG(logINFOBLUE, ("\tSlave or No Master\n")); LOG(logINFOBLUE, ("\tSlave or No Master\n"));
} else { } else {
LOG(logERROR, initError = FAIL;
("\tCould not scan masterflags %s value from config file\n", sprintf(
value)); initErrorMessage,
scan = FAIL; "Could not scan masterflags %s value from config file\n",
break; value);
LOG(logERROR, (initErrorMessage))
fclose(fd);
return FAIL;
} }
// not first server since detector power on // not first server since detector power on
if (!detectorFirstServer) { if (!detectorFirstServer) {
LOG(logINFOBLUE, ("\tServer has been started up before. " LOG(logWARNING, ("\tServer has been started up before. "
"Ignoring rest of config file\n")); "Ignoring rest of config file\n"));
fclose(fd); fclose(fd);
return FAIL; return OK;
} }
} }
@ -688,11 +721,14 @@ int readConfigFile() {
// convert value to int // convert value to int
int ival = 0; int ival = 0;
if (sscanf(value, "%d", &ival) <= 0) { if (sscanf(value, "%d", &ival) <= 0) {
LOG(logERROR, ("\tCould not scan parameter %s value %s from " initError = FAIL;
"config file\n", sprintf(initErrorMessage,
key, value)); "Could not scan parameter %s value %s from "
scan = FAIL; "config file\n",
break; key, value);
LOG(logERROR, (initErrorMessage))
fclose(fd);
return FAIL;
} }
// set value // set value
if (!strcasecmp(key, "masterdefaultdelay")) if (!strcasecmp(key, "masterdefaultdelay"))
@ -710,16 +746,16 @@ int readConfigFile() {
else if (!strcasecmp(key, "startacqdelay")) else if (!strcasecmp(key, "startacqdelay"))
startacqdelay = ival; startacqdelay = ival;
else { else {
LOG(logERROR, initError = FAIL;
("\tCould not scan parameter %s from config file\n", key)); sprintf(initErrorMessage,
scan = FAIL; "Could not scan parameter %s from config file\n", key);
break; LOG(logERROR, (initErrorMessage))
fclose(fd);
return FAIL;
} }
} }
} }
fclose(fd); fclose(fd);
if (scan == FAIL)
exit(EXIT_FAILURE);
LOG(logINFOBLUE, LOG(logINFOBLUE,
("\tmasterdefaultdelay:%d\n" ("\tmasterdefaultdelay:%d\n"
@ -734,13 +770,28 @@ int readConfigFile() {
return OK; return OK;
} }
int checkCommandLineConfiguration() {
if (masterCommandLine != -1) {
#ifdef VIRTUAL
master = masterCommandLine;
#else
initError = FAIL;
strcpy(initErrorMessage,
"Cannot set Master from command line for this detector. "
"Should have been caught before!\n");
return FAIL;
#endif
}
return OK;
}
void setMasterSlaveConfiguration() { void setMasterSlaveConfiguration() {
LOG(logINFO, ("Reading Master Slave Configuration\n")); // not the first time its being read
if (!detectorFirstServer) {
// no config file or not first time server
if (readConfigFile() == FAIL)
return; return;
}
LOG(logINFO, ("Reading Master Slave Configuration\n"));
// master configuration // master configuration
if (master) { if (master) {
// master default delay set, so reset delay // master default delay set, so reset delay
@ -788,7 +839,16 @@ void setMasterSlaveConfiguration() {
/* set parameters - dr, roi */ /* set parameters - dr, roi */
int setDynamicRange(int dr) { return DYNAMIC_RANGE; } int setDynamicRange(int dr) {
if (dr == 16)
return OK;
return FAIL;
}
int getDynamicRange(int *retval) {
*retval = DYNAMIC_RANGE;
return OK;
}
int setROI(ROI arg) { int setROI(ROI arg) {
@ -1238,7 +1298,10 @@ int setHighVoltage(int val) {
/* parameters - timing, extsig */ /* parameters - timing, extsig */
int isMaster() { return master; } int isMaster(int *retval) {
*retval = master;
return OK;
}
void setTiming(enum timingMode arg) { void setTiming(enum timingMode arg) {
u_int32_t addr = EXT_SIGNAL_REG; u_int32_t addr = EXT_SIGNAL_REG;

View File

@ -28,6 +28,7 @@ extern int updateFlag;
extern udpStruct udpDetails[MAX_UDP_DESTINATION]; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern int numUdpDestinations; extern int numUdpDestinations;
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
extern int ignoreConfigFileFlag;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
extern int isControlServer; extern int isControlServer;
@ -392,19 +393,29 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) { LOG(logINFOBLUE, ("Configuring Stop server\n"));
LOG(logERROR, if (mapCSP0() == FAIL) {
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); initError = FAIL;
exit(EXIT_FAILURE); strcpy(initErrorMessage,
} "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
if (readConfigFile() == FAIL) {
initCheckDone = 1;
return;
}
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
// temp threshold and reset event (read by stop server) // temp threshold and reset event (read by stop server)
setThresholdTemperature(DEFAULT_TMP_THRSHLD); setThresholdTemperature(DEFAULT_TMP_THRSHLD);
setTemperatureEvent(0); setTemperatureEvent(0);
#endif #endif
}
initCheckDone = 1;
} }
/* set up detector */ /* set up detector */
@ -643,6 +654,11 @@ int readConfigFile() {
return initError; return initError;
} }
if (ignoreConfigFileFlag) {
LOG(logWARNING, ("Ignoring Config file\n"));
return OK;
}
const int fileNameSize = 128; const int fileNameSize = 128;
char fname[fileNameSize]; char fname[fileNameSize];
if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) { if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) {
@ -796,7 +812,16 @@ void resetPeripheral() {
/* set parameters - dr, roi */ /* set parameters - dr, roi */
int setDynamicRange(int dr) { return DYNAMIC_RANGE; } int setDynamicRange(int dr) {
if (dr == 16)
return OK;
return FAIL;
}
int getDynamicRange(int *retval) {
*retval = DYNAMIC_RANGE;
return OK;
}
void setADCInvertRegister(uint32_t val) { void setADCInvertRegister(uint32_t val) {
LOG(logINFO, ("Setting ADC Port Invert Reg to 0x%x\n", val)); LOG(logINFO, ("Setting ADC Port Invert Reg to 0x%x\n", val));
@ -1675,7 +1700,7 @@ int setReadNRows(int value) {
} }
if (isHardwareVersion2()) { if (isHardwareVersion2()) {
LOG(logERROR, ("Could not set number of rows. Only available for " LOG(logERROR, ("Could not set number of rows. Only available for "
"Hardware Board version 2.0.\n")); "Hardware Board version 2.0.\n"));
return FAIL; return FAIL;
} }
@ -2175,7 +2200,7 @@ int getFlipRows() {
void setFlipRows(int arg) { void setFlipRows(int arg) {
if (isHardwareVersion2()) { if (isHardwareVersion2()) {
LOG(logERROR, ("Could not set flip rows. Only available for " LOG(logERROR, ("Could not set flip rows. Only available for "
"Hardware Board version 2.0.\n")); "Hardware Board version 2.0.\n"));
return; return;
} }
if (arg >= 0) { if (arg >= 0) {

View File

@ -67,7 +67,13 @@ int defaultDacValues[NDAC] = DEFAULT_DAC_VALS;
int vLimit = 0; int vLimit = 0;
enum detectorSettings thisSettings = UNINITIALIZED; enum detectorSettings thisSettings = UNINITIALIZED;
int highvoltage = 0; int highvoltage = 0;
// getNumberofchannels return 0 for y in --update mode (virtual servers)
#ifdef VIRTUAL
int nSamples = DEFAULT_NUM_SAMPLES;
#else
int nSamples = 1; int nSamples = 1;
#endif
int detPos[2] = {0, 0}; int detPos[2] = {0, 0};
int isInitCheckDone() { return initCheckDone; } int isInitCheckDone() { return initCheckDone; }
@ -430,16 +436,22 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) { LOG(logINFOBLUE, ("Configuring Stop server\n"));
LOG(logERROR, if (mapCSP0() == FAIL) {
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); initError = FAIL;
exit(EXIT_FAILURE); strcpy(initErrorMessage,
} "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
#endif #endif
}
initCheckDone = 1;
} }
/* set up detector */ /* set up detector */
@ -700,7 +712,16 @@ void resetPeripheral() {
/* set parameters - dr, adcenablemask */ /* set parameters - dr, adcenablemask */
int setDynamicRange(int dr) { return DYNAMIC_RANGE; } int setDynamicRange(int dr) {
if (dr == 16)
return OK;
return FAIL;
}
int getDynamicRange(int *retval) {
*retval = DYNAMIC_RANGE;
return OK;
}
int setADCEnableMask(uint32_t mask) { int setADCEnableMask(uint32_t mask) {
if (mask == 0u) { if (mask == 0u) {

View File

@ -35,6 +35,9 @@ extern int isControlServer;
extern void getMacAddressinString(char *cmac, int size, uint64_t mac); extern void getMacAddressinString(char *cmac, int size, uint64_t mac);
extern void getIpAddressinString(char *cip, uint32_t ip); extern void getIpAddressinString(char *cip, uint32_t ip);
// Variables that will be exported
int masterCommandLine = -1;
int initError = OK; int initError = OK;
int initCheckDone = 0; int initCheckDone = 0;
char initErrorMessage[MAX_STR_LENGTH]; char initErrorMessage[MAX_STR_LENGTH];
@ -289,6 +292,18 @@ void setModuleId(int modid) {
bus_r(MOD_ID_REG) | ((modid << MOD_ID_OFST) & MOD_ID_MSK)); bus_r(MOD_ID_REG) | ((modid << MOD_ID_OFST) & MOD_ID_MSK));
} }
int updateModuleId() {
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return FAIL;
}
#ifdef VIRTUAL
virtual_moduleid = modid;
#endif
setModuleId(modid);
return OK;
}
u_int64_t getDetectorMAC() { u_int64_t getDetectorMAC() {
#ifdef VIRTUAL #ifdef VIRTUAL
return 0; return 0;
@ -352,16 +367,26 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) { LOG(logINFOBLUE, ("Configuring Stop server\n"));
LOG(logERROR, if (mapCSP0() == FAIL) {
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); initError = FAIL;
exit(EXIT_FAILURE); strcpy(initErrorMessage,
} "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
if (checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
#endif #endif
}
initCheckDone = 1;
} }
/* set up detector */ /* set up detector */
@ -407,6 +432,12 @@ void setupDetector() {
allocateDetectorStructureMemory(); allocateDetectorStructureMemory();
if (checkCommandLineConfiguration() == FAIL)
return;
if (updateModuleId() == FAIL)
return;
clkDivider[READOUT_C0] = DEFAULT_READOUT_C0; clkDivider[READOUT_C0] = DEFAULT_READOUT_C0;
clkDivider[READOUT_C1] = DEFAULT_READOUT_C1; clkDivider[READOUT_C1] = DEFAULT_READOUT_C1;
clkDivider[SYSTEM_C0] = DEFAULT_SYSTEM_C0; clkDivider[SYSTEM_C0] = DEFAULT_SYSTEM_C0;
@ -447,16 +478,6 @@ void setupDetector() {
setASICDefaults(); setASICDefaults();
setADIFDefaults(); setADIFDefaults();
// set module id in register
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
#ifdef VIRTUAL
virtual_moduleid = modid;
#endif
if (initError == FAIL) {
return;
}
setModuleId(modid);
// set trigger flow for m3 (for all timing modes) // set trigger flow for m3 (for all timing modes)
bus_w(FLOW_TRIGGER_REG, bus_r(FLOW_TRIGGER_REG) | FLOW_TRIGGER_MSK); bus_w(FLOW_TRIGGER_REG, bus_r(FLOW_TRIGGER_REG) | FLOW_TRIGGER_MSK);
@ -480,10 +501,6 @@ void setupDetector() {
setInitialExtSignals(); setInitialExtSignals();
// 10G UDP // 10G UDP
enableTenGigabitEthernet(1); enableTenGigabitEthernet(1);
getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return;
}
setSettings(DEFAULT_SETTINGS); setSettings(DEFAULT_SETTINGS);
// check module type attached if not in debug mode // check module type attached if not in debug mode
@ -700,6 +717,27 @@ void setADIFDefaults() {
ADIF_ADDTNL_OFST_MSK))); ADIF_ADDTNL_OFST_MSK)));
} }
int checkCommandLineConfiguration() {
if (masterCommandLine != -1) {
#ifdef VIRTUAL
if (masterCommandLine == 1) {
bus_w(SYSTEM_STATUS_REG,
bus_r(SYSTEM_STATUS_REG) & ~SYSTEM_STATUS_SLV_BRD_DTCT_MSK);
} else {
bus_w(SYSTEM_STATUS_REG,
bus_r(SYSTEM_STATUS_REG) | SYSTEM_STATUS_SLV_BRD_DTCT_MSK);
}
#else
initError = FAIL;
strcpy(initErrorMessage,
"Cannot set Master from command line for this detector. "
"Should have been caught before!\n");
return FAIL;
#endif
}
return OK;
}
/* firmware functions (resets) */ /* firmware functions (resets) */
void cleanFifos() { void cleanFifos() {
@ -729,46 +767,54 @@ void resetPeripheral() {
/* set parameters - dr, roi */ /* set parameters - dr, roi */
int setDynamicRange(int dr) { int setDynamicRange(int dr) {
if (dr > 0) { if (dr <= 0) {
uint32_t regval = 0; return FAIL;
switch (dr) {
/*case 1: TODO:Not implemented in firmware yet
regval = CONFIG_DYNAMIC_RANGE_1_VAL;
break;*/
case 8:
regval = CONFIG_DYNAMIC_RANGE_8_VAL;
break;
case 16:
regval = CONFIG_DYNAMIC_RANGE_16_VAL;
break;
case 32:
regval = CONFIG_DYNAMIC_RANGE_24_VAL;
break;
default:
LOG(logERROR, ("Invalid dynamic range %d\n", dr));
return -1;
}
// set it
bus_w(CONFIG_REG, bus_r(CONFIG_REG) & ~CONFIG_DYNAMIC_RANGE_MSK);
bus_w(CONFIG_REG, bus_r(CONFIG_REG) | regval);
updatePacketizing();
} }
uint32_t regval = 0;
switch (dr) {
/*case 1: TODO:Not implemented in firmware yet
regval = CONFIG_DYNAMIC_RANGE_1_VAL;
break;*/
case 8:
regval = CONFIG_DYNAMIC_RANGE_8_VAL;
break;
case 16:
regval = CONFIG_DYNAMIC_RANGE_16_VAL;
break;
case 32:
regval = CONFIG_DYNAMIC_RANGE_24_VAL;
break;
default:
LOG(logERROR, ("Invalid dynamic range %d\n", dr));
return -1;
}
// set it
bus_w(CONFIG_REG, bus_r(CONFIG_REG) & ~CONFIG_DYNAMIC_RANGE_MSK);
bus_w(CONFIG_REG, bus_r(CONFIG_REG) | regval);
updatePacketizing();
return OK;
}
int getDynamicRange(int *retval) {
uint32_t regval = bus_r(CONFIG_REG) & CONFIG_DYNAMIC_RANGE_MSK; uint32_t regval = bus_r(CONFIG_REG) & CONFIG_DYNAMIC_RANGE_MSK;
switch (regval) { switch (regval) {
/*case CONFIG_DYNAMIC_RANGE_1_VAL: TODO:Not implemented in firmware yet /*case CONFIG_DYNAMIC_RANGE_1_VAL: TODO:Not implemented in firmware yet
return 1;*/ return 1;*/
case CONFIG_DYNAMIC_RANGE_8_VAL: case CONFIG_DYNAMIC_RANGE_8_VAL:
return 8; *retval = 8;
break;
case CONFIG_DYNAMIC_RANGE_16_VAL: case CONFIG_DYNAMIC_RANGE_16_VAL:
return 16; *retval = 16;
break;
case CONFIG_DYNAMIC_RANGE_24_VAL: case CONFIG_DYNAMIC_RANGE_24_VAL:
return 32; *retval = 32;
break;
default: default:
LOG(logERROR, ("Invalid dynamic range %d read back\n", LOG(logERROR, ("Invalid dynamic range %d read back\n",
regval >> CONFIG_DYNAMIC_RANGE_OFST)); regval >> CONFIG_DYNAMIC_RANGE_OFST));
return -1; return FAIL;
} }
return OK;
} }
/* set parameters - readout */ /* set parameters - readout */
@ -1091,7 +1137,8 @@ void updatePacketizing() {
// 10g // 10g
if (tgEnable) { if (tgEnable) {
const int dr = setDynamicRange(-1); int dr = 0;
getDynamicRange(&dr);
packetsPerFrame = 1; packetsPerFrame = 1;
if (dr == 32 && ncounters > 1) { if (dr == 32 && ncounters > 1) {
packetsPerFrame = 2; packetsPerFrame = 2;
@ -1545,14 +1592,18 @@ int setHighVoltage(int val) {
/* parameters - timing */ /* parameters - timing */
int isMaster() { int isMaster(int *retval) {
return !((bus_r(SYSTEM_STATUS_REG) & SYSTEM_STATUS_SLV_BRD_DTCT_MSK) >> int slave = ((bus_r(SYSTEM_STATUS_REG) & SYSTEM_STATUS_SLV_BRD_DTCT_MSK) >>
SYSTEM_STATUS_SLV_BRD_DTCT_OFST); SYSTEM_STATUS_SLV_BRD_DTCT_OFST);
*retval = (slave == 0 ? 1 : 0);
return OK;
} }
void setTiming(enum timingMode arg) { void setTiming(enum timingMode arg) {
if (!isMaster() && arg == AUTO_TIMING) int master = 0;
isMaster(&master);
if (master && arg == AUTO_TIMING)
arg = TRIGGER_EXPOSURE; arg = TRIGGER_EXPOSURE;
uint32_t addr = CONFIG_REG; uint32_t addr = CONFIG_REG;
@ -2202,7 +2253,8 @@ void *start_timer(void *arg) {
const int imageSize = calculateDataBytes(); const int imageSize = calculateDataBytes();
const int tgEnable = enableTenGigabitEthernet(-1); const int tgEnable = enableTenGigabitEthernet(-1);
const int dr = setDynamicRange(-1); int dr = 0;
getDynamicRange(&dr);
int ncounters = __builtin_popcount(getCounterMask()); int ncounters = __builtin_popcount(getCounterMask());
int dataSize = 0; int dataSize = 0;
int packetsPerFrame = 0; int packetsPerFrame = 0;
@ -2523,7 +2575,8 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
int calculateDataBytes() { int calculateDataBytes() {
int numCounters = __builtin_popcount(getCounterMask()); int numCounters = __builtin_popcount(getCounterMask());
int dr = setDynamicRange(-1); int dr = 0;
getDynamicRange(&dr);
return (NCHAN_1_COUNTER * NCHIP * numCounters * ((double)dr / 8.00)); return (NCHAN_1_COUNTER * NCHIP * numCounters * ((double)dr / 8.00));
} }

View File

@ -97,6 +97,9 @@ u_int32_t getDetectorNumber();
#if defined(GOTTHARD2D) || defined(EIGERD) || defined(MYTHEN3D) #if defined(GOTTHARD2D) || defined(EIGERD) || defined(MYTHEN3D)
int getModuleId(int *ret, char *mess); int getModuleId(int *ret, char *mess);
#endif #endif
#if defined(EIGERD) || defined(MYTHEN3D) || defined(GOTTHARD2D)
int updateModuleId();
#endif
#if defined(GOTTHARD2D) || defined(MYTHEN3D) #if defined(GOTTHARD2D) || defined(MYTHEN3D)
void setModuleId(int modid); void setModuleId(int modid);
#endif #endif
@ -110,7 +113,11 @@ u_int32_t getBoardRevision();
void initControlServer(); void initControlServer();
void initStopServer(); void initStopServer();
#ifdef EIGERD #ifdef EIGERD
void getModuleConfiguration(); int updateModuleConfiguration();
int getModuleConfiguration(int *m, int *t, int *n);
#ifdef VIRTUAL
void checkVirtual9MFlag();
#endif
#endif #endif
// set up detector // set up detector
@ -137,6 +144,10 @@ void setADIFDefaults();
#if defined(GOTTHARD2D) || defined(EIGERD) || defined(JUNGFRAUD) #if defined(GOTTHARD2D) || defined(EIGERD) || defined(JUNGFRAUD)
int readConfigFile(); int readConfigFile();
#endif #endif
#if defined(GOTTHARDD) || defined(GOTTHARD2D) || defined(EIGERD) || \
defined(MYTHEN3D)
int checkCommandLineConfiguration();
#endif
#ifdef EIGERD #ifdef EIGERD
void resetToHardwareSettings(); void resetToHardwareSettings();
#endif #endif
@ -173,6 +184,7 @@ void setMasterSlaveConfiguration();
// parameters - dr, roi // parameters - dr, roi
int setDynamicRange(int dr); int setDynamicRange(int dr);
int getDynamicRange(int *retval);
#ifdef GOTTHARDD #ifdef GOTTHARDD
int setROI(ROI arg); int setROI(ROI arg);
ROI getROI(); ROI getROI();
@ -362,9 +374,16 @@ int getADC(enum ADCINDEX ind);
int setHighVoltage(int val); int setHighVoltage(int val);
// parameters - timing, extsig // parameters - timing, extsig
#if defined(MYTHEN3D) || defined(EIGERD) || defined(GOTTHARDD) #ifdef EIGERD
int isMaster(); int setMaster(enum MASTERINDEX m);
int setTop(enum TOPINDEX t);
int isTop(int *retval);
#endif #endif
#if defined(MYTHEN3D) || defined(EIGERD) || defined(GOTTHARDD) || \
defined(GOTTHARD2D)
int isMaster(int *retval);
#endif
#ifdef GOTTHARD2D #ifdef GOTTHARD2D
void updatingRegisters(); void updatingRegisters();
#endif #endif

View File

@ -245,6 +245,7 @@ int get_pattern(int);
int load_default_pattern(int); int load_default_pattern(int);
int get_all_threshold_energy(int); int get_all_threshold_energy(int);
int get_master(int); int get_master(int);
int set_master(int);
int get_csr(); int get_csr();
int set_gain_caps(int); int set_gain_caps(int);
int get_gain_caps(int); int get_gain_caps(int);
@ -289,4 +290,6 @@ void receive_program_default(int file_des, enum PROGRAM_INDEX index,
char *functionType, uint64_t filesize, char *functionType, uint64_t filesize,
char *checksum, char *serverName); char *checksum, char *serverName);
int get_update_mode(int); int get_update_mode(int);
int set_update_mode(int); int set_update_mode(int);
int get_top(int);
int set_top(int);

View File

@ -26,11 +26,19 @@ extern int sockfd;
extern int debugflag; extern int debugflag;
extern int updateFlag; extern int updateFlag;
extern int checkModuleFlag; extern int checkModuleFlag;
extern int ignoreConfigFileFlag;
// Global variables from slsDetectorFunctionList // Global variables from slsDetectorFunctionList
#ifdef GOTTHARDD #ifdef GOTTHARDD
extern int phaseShift; extern int phaseShift;
#endif #endif
#if defined(GOTTHARDD) || defined(GOTTHARD2D) || defined(EIGERD) || \
defined(MYTHEN3D)
extern int masterCommandLine;
#endif
#ifdef EIGERD
extern int topCommandLine;
#endif
void error(char *msg) { perror(msg); } void error(char *msg) { perror(msg); }
@ -48,26 +56,57 @@ int main(int argc, char *argv[]) {
updateFlag = 0; updateFlag = 0;
checkModuleFlag = 1; checkModuleFlag = 1;
int version = 0; int version = 0;
ignoreConfigFileFlag = 0;
#if defined(GOTTHARDD) || defined(GOTTHARD2D) || defined(EIGERD) || \
defined(MYTHEN3D)
masterCommandLine = -1;
#endif
#ifdef EIGERD
topCommandLine = -1;
#endif
// help message // help message
char helpMessage[MAX_STR_LENGTH]; const size_t helpMessageSize = 1200;
memset(helpMessage, 0, MAX_STR_LENGTH); char helpMessage[helpMessageSize];
sprintf( {
helpMessage, memset(helpMessage, 0, helpMessageSize);
"Usage: %s [arguments]\n" int len = snprintf(
"Possible arguments are:\n" helpMessage, helpMessageSize,
"\t-v, --version : Software version\n" "Usage: %s [arguments]\n"
"\t-p, --port <port> : TCP communication port with client. \n" "Possible arguments are:\n"
"\t-g, --nomodule : [Mythen3][Gotthard2] Generic or No " "\t-v, --version : Software version\n"
"Module mode. Skips detector type checks. \n" "\t-p, --port <port> : TCP communication port with client. "
"\t-f, --phaseshift <value> : [Gotthard] only. Sets phase shift. \n" "\n"
"\t-d, --devel : Developer mode. Skips firmware checks. \n" "\t-g, --nomodule : [Mythen3][Gotthard2] \n"
"\t-u, --update : Update mode. Skips firmware checks and " "\t Generic or No Module mode. Skips "
"initial detector setup. \n" "detector type checks. \n"
"\t-s, --stopserver : Stop server. Do not use as it is created " "\t-f, --phaseshift <value> : [Gotthard] only. Sets phase shift. \n"
"by " "\t-d, --devel : Developer mode. Skips firmware "
"control server \n\n", "checks. \n"
argv[0]); "\t-u, --update : Update mode. Skips firmware checks "
"and "
"initial detector setup. \n"
"\t-i, --ignore-config : "
"[Eiger][Jungfrau][Gotthard][Gotthard2] \n"
"\t Ignore config file. \n"
"\t-m, --master <master> : "
"[Eiger][Mythen3][Gotthard][Gotthard2] \n"
"\t Set Master to 0 or 1. Precedence "
"over "
"config file. Only for virtual servers except Eiger. \n"
"\t-t, --top <top> : [Eiger] Set Top to 0 or 1. "
"Precedence "
"over config file. \n"
"\t-s, --stopserver : Stop server. Do not use as it is "
"created "
"by control server \n\n",
argv[0]);
if (len >= (int)helpMessageSize) {
LOG(logERROR, ("Help for Server command line arguments size %d "
"exceed capacity of %d characters\n",
len, helpMessageSize));
}
}
// parse command line for config // parse command line for config
static struct option long_options[] = { static struct option long_options[] = {
@ -80,6 +119,9 @@ int main(int argc, char *argv[]) {
{"nomodule", no_argument, NULL, 'g'}, // generic {"nomodule", no_argument, NULL, 'g'}, // generic
{"devel", no_argument, NULL, 'd'}, {"devel", no_argument, NULL, 'd'},
{"update", no_argument, NULL, 'u'}, {"update", no_argument, NULL, 'u'},
{"ignore-config", no_argument, NULL, 'i'},
{"master", required_argument, NULL, 'm'},
{"top", required_argument, NULL, 't'},
{"stopserver", no_argument, NULL, 's'}, {"stopserver", no_argument, NULL, 's'},
{NULL, 0, NULL, 0}}; {NULL, 0, NULL, 0}};
@ -89,7 +131,8 @@ int main(int argc, char *argv[]) {
int c = 0; int c = 0;
while (c != -1) { while (c != -1) {
c = getopt_long(argc, argv, "hvp:f:gdus", long_options, &option_index); c = getopt_long(argc, argv, "hvp:f:gduim:t:s", long_options,
&option_index);
// Detect the end of the options // Detect the end of the options
if (c == -1) if (c == -1)
@ -160,6 +203,57 @@ int main(int argc, char *argv[]) {
isControlServer = 0; isControlServer = 0;
break; break;
case 'i':
#if defined(EIGERD) || defined(GOTTHARDD) || defined(GOTTHARD2D) || \
defined(JUNGFRAUD)
LOG(logINFO, ("Ignoring config file\n"));
ignoreConfigFileFlag = 1;
#else
LOG(logERROR, ("No server config files for this detector\n"));
exit(EXIT_FAILURE);
#endif
break;
case 'm':
#if (defined(MYTHEN3D) || defined(GOTTHARDD) || defined(GOTTHARD2D)) && \
!defined(VIRTUAL)
LOG(logERROR, ("Cannot set master via the detector server for this "
"detector\n"));
exit(EXIT_FAILURE);
#elif defined(GOTTHARDD) || defined(GOTTHARD2D) || defined(EIGERD) || \
defined(MYTHEN3D)
if (sscanf(optarg, "%d", &masterCommandLine) != 1) {
LOG(logERROR, ("Cannot scan master argument\n%s", helpMessage));
exit(EXIT_FAILURE);
}
if (masterCommandLine == 1) {
LOG(logINFO, ("Detector Master mode\n"));
} else {
LOG(logINFO, ("Detector Slave mode\n"));
}
#else
LOG(logERROR, ("No master implemented for this detector server\n"));
exit(EXIT_FAILURE);
#endif
break;
case 't':
#ifdef EIGERD
if (sscanf(optarg, "%d", &topCommandLine) != 1) {
LOG(logERROR, ("Cannot scan top argument\n%s", helpMessage));
exit(EXIT_FAILURE);
}
if (topCommandLine == 1) {
LOG(logINFO, ("Detector Top mode\n"));
} else {
LOG(logINFO, ("Detector Bottom mode\n"));
}
#else
LOG(logERROR, ("No top implemented for this detector server\n"));
exit(EXIT_FAILURE);
#endif
break;
case 'h': case 'h':
printf("%s", helpMessage); printf("%s", helpMessage);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

View File

@ -37,6 +37,8 @@ const enum detectorType myDetectorType = GOTTHARD2;
const enum detectorType myDetectorType = GENERIC; const enum detectorType myDetectorType = GENERIC;
#endif #endif
#define LOCALHOSTIP_INT 2130706433
// Global variables from communication_funcs // Global variables from communication_funcs
extern int lockStatus; extern int lockStatus;
extern uint32_t lastClientIP; extern uint32_t lastClientIP;
@ -52,6 +54,7 @@ int sockfd = 0;
int debugflag = 0; int debugflag = 0;
int updateFlag = 0; int updateFlag = 0;
int checkModuleFlag = 1; int checkModuleFlag = 1;
int ignoreConfigFileFlag = 0;
udpStruct udpDetails[MAX_UDP_DESTINATION]; udpStruct udpDetails[MAX_UDP_DESTINATION];
int numUdpDestinations = 1; int numUdpDestinations = 1;
@ -78,28 +81,32 @@ char scanErrMessage[MAX_STR_LENGTH] = "";
/* initialization functions */ /* initialization functions */
int updateModeAllowedFunction(int file_des) { int updateModeAllowedFunction(int file_des) {
unsigned int listsize = 19; enum detFuncs allowedFuncs[] = {F_EXEC_COMMAND,
enum detFuncs list[] = {F_EXEC_COMMAND, F_GET_DETECTOR_TYPE,
F_GET_DETECTOR_TYPE, F_GET_FIRMWARE_VERSION,
F_GET_FIRMWARE_VERSION, F_GET_SERVER_VERSION,
F_GET_SERVER_VERSION, F_GET_SERIAL_NUMBER,
F_GET_SERIAL_NUMBER, F_WRITE_REGISTER,
F_WRITE_REGISTER, F_READ_REGISTER,
F_READ_REGISTER, F_LOCK_SERVER,
F_LOCK_SERVER, F_GET_LAST_CLIENT_IP,
F_GET_LAST_CLIENT_IP, F_PROGRAM_FPGA,
F_PROGRAM_FPGA, F_RESET_FPGA,
F_RESET_FPGA, F_CHECK_VERSION,
F_CHECK_VERSION, F_COPY_DET_SERVER,
F_COPY_DET_SERVER, F_REBOOT_CONTROLLER,
F_REBOOT_CONTROLLER, F_GET_KERNEL_VERSION,
F_GET_KERNEL_VERSION, F_UPDATE_KERNEL,
F_UPDATE_KERNEL, F_UPDATE_DETECTOR_SERVER,
F_UPDATE_DETECTOR_SERVER, F_GET_UPDATE_MODE,
F_GET_UPDATE_MODE, F_SET_UPDATE_MODE,
F_SET_UPDATE_MODE}; F_GET_NUM_CHANNELS,
for (unsigned int i = 0; i < listsize; ++i) { F_GET_NUM_INTERFACES,
if ((unsigned int)fnum == list[i]) { F_ACTIVATE};
size_t allowedFuncsSize = sizeof(allowedFuncs) / sizeof(enum detFuncs);
for (unsigned int i = 0; i < allowedFuncsSize; ++i) {
if ((unsigned int)fnum == allowedFuncs[i]) {
return OK; return OK;
} }
} }
@ -119,10 +126,11 @@ int printSocketReadError() {
} }
void init_detector() { void init_detector() {
memset(udpDetails, 0, sizeof(udpDetails));
#ifdef VIRTUAL #ifdef VIRTUAL
LOG(logINFO, ("This is a VIRTUAL detector\n")); LOG(logINFO, ("This is a VIRTUAL detector\n"));
udpDetails[0].srcip = LOCALHOSTIP_INT;
#endif #endif
memset(udpDetails, 0, sizeof(udpDetails));
udpDetails[0].srcport = DEFAULT_UDP_SRC_PORTNO; udpDetails[0].srcport = DEFAULT_UDP_SRC_PORTNO;
udpDetails[0].dstport = DEFAULT_UDP_DST_PORTNO; udpDetails[0].dstport = DEFAULT_UDP_DST_PORTNO;
#ifdef EIGERD #ifdef EIGERD
@ -461,6 +469,9 @@ void function_table() {
flist[F_UPDATE_DETECTOR_SERVER] = &update_detector_server; flist[F_UPDATE_DETECTOR_SERVER] = &update_detector_server;
flist[F_GET_UPDATE_MODE] = &get_update_mode; flist[F_GET_UPDATE_MODE] = &get_update_mode;
flist[F_SET_UPDATE_MODE] = &set_update_mode; flist[F_SET_UPDATE_MODE] = &set_update_mode;
flist[F_SET_MASTER] = &set_master;
flist[F_GET_TOP] = &get_top;
flist[F_SET_TOP] = &set_top;
// check // check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -2808,6 +2819,9 @@ int set_dynamic_range(int file_des) {
#endif #endif
#if defined(EIGERD) || defined(MYTHEN3D) #if defined(EIGERD) || defined(MYTHEN3D)
case 8: case 8:
#ifdef EIGERD
case 12:
#endif
case 16: case 16:
case 32: case 32:
#endif #endif
@ -2815,14 +2829,25 @@ int set_dynamic_range(int file_des) {
defined(MOENCHD) || defined(GOTTHARD2D) defined(MOENCHD) || defined(GOTTHARD2D)
case 16: case 16:
#endif #endif
retval = setDynamicRange(dr); if (dr >= 0) {
LOG(logDEBUG1, ("Dynamic range: %d\n", retval)); ret = setDynamicRange(dr);
if (retval == -1) { if (ret == FAIL) {
ret = FAIL; sprintf(mess, "Could not set dynamic range to %d\n", dr);
sprintf(mess, "Could not get dynamic range.\n"); LOG(logERROR, (mess));
LOG(logERROR, (mess)); }
}
// get
if (ret == OK) {
ret = getDynamicRange(&retval);
if (ret == FAIL) {
strcpy(mess, "Could not get dynamic range\n");
LOG(logERROR, (mess));
} else {
LOG(logDEBUG1, ("Dynamic range: %d\n", retval));
validate(&ret, mess, dr, retval, "set dynamic range", DEC);
}
} }
validate(&ret, mess, dr, retval, "set dynamic range", DEC);
break; break;
default: default:
modeNotImplemented("Dynamic range", dr); modeNotImplemented("Dynamic range", dr);
@ -2932,7 +2957,7 @@ int enable_ten_giga(int file_des) {
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError(); return printSocketReadError();
LOG(logINFOBLUE, ("Setting 10GbE: %d\n", arg)); LOG(logDEBUG, ("Setting 10GbE: %d\n", arg));
#if defined(JUNGFRAUD) || defined(GOTTHARDD) || defined(GOTTHARD2D) #if defined(JUNGFRAUD) || defined(GOTTHARDD) || defined(GOTTHARD2D)
functionNotImplemented(); functionNotImplemented();
@ -3970,29 +3995,26 @@ int check_version(int file_des) {
return printSocketReadError(); return printSocketReadError();
// check software- firmware compatibility and basic tests // check software- firmware compatibility and basic tests
if (isControlServer) { LOG(logDEBUG1, ("Checking software-firmware compatibility and basic "
LOG(logDEBUG1, ("Checking software-firmware compatibility and basic " "test result\n"));
"test result\n"));
// check if firmware check is done // check if firmware check is done
if (!isInitCheckDone()) {
usleep(3 * 1000 * 1000);
if (!isInitCheckDone()) { if (!isInitCheckDone()) {
usleep(3 * 1000 * 1000); ret = FAIL;
if (!isInitCheckDone()) { strcpy(mess, "Server Initialization still not done done in server. Unexpected.\n");
ret = FAIL; LOG(logERROR, (mess));
strcpy(mess, "Firmware Software Compatibility Check (Server "
"Initialization) "
"still not done done in server. Unexpected.\n");
LOG(logERROR, (mess));
}
} }
// check firmware check result }
if (ret == OK) {
char *firmware_message = NULL; // check firmware check result
if (getInitResult(&firmware_message) == FAIL) { if (ret == OK) {
ret = FAIL; char *firmware_message = NULL;
strcpy(mess, firmware_message); if (getInitResult(&firmware_message) == FAIL) {
LOG(logERROR, (mess)); ret = FAIL;
} strcpy(mess, firmware_message);
LOG(logERROR, (mess));
} }
} }
@ -4643,11 +4665,17 @@ int set_read_n_rows(int file_des) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else { } else {
#ifdef EIGERD #ifdef EIGERD
int dr = setDynamicRange(GET_FLAG); int dr = 0;
ret = getDynamicRange(&dr);
int isTenGiga = enableTenGigabitEthernet(GET_FLAG); int isTenGiga = enableTenGigabitEthernet(GET_FLAG);
unsigned int maxnl = MAX_ROWS_PER_READOUT; unsigned int maxnl = MAX_ROWS_PER_READOUT;
unsigned int maxnp = (isTenGiga ? 4 : 16) * dr; unsigned int maxnp = (isTenGiga ? 4 : 16) * dr;
if ((arg * maxnp) % maxnl) { // get dr fail
if (ret == FAIL) {
strcpy(mess,
"Could not read n rows (failed to get dynamic range)\n");
LOG(logERROR, (mess));
} else if ((arg * maxnp) % maxnl) {
ret = FAIL; ret = FAIL;
sprintf(mess, sprintf(mess,
"Could not set number of rows to %d. For %d bit " "Could not set number of rows to %d. For %d bit "
@ -4855,12 +4883,15 @@ int is_udp_configured() {
LOG(logWARNING, ("%s", configureMessage)); LOG(logWARNING, ("%s", configureMessage));
return FAIL; return FAIL;
} }
// virtual: no check (can be eth name: lo, ip: 127.0.0.1)
#ifndef VIRTUAL
if (udpDetails[i].dstmac == 0) { if (udpDetails[i].dstmac == 0) {
sprintf(configureMessage, sprintf(configureMessage,
"udp destination mac not configured [entry:%d]\n", i); "udp destination mac not configured [entry:%d]\n", i);
LOG(logWARNING, ("%s", configureMessage)); LOG(logWARNING, ("%s", configureMessage));
return FAIL; return FAIL;
} }
#endif
#if defined(JUNGFRAUD) || defined(GOTTHARD2D) #if defined(JUNGFRAUD) || defined(GOTTHARD2D)
if (getNumberofUDPInterfaces() == 2) { if (getNumberofUDPInterfaces() == 2) {
if (udpDetails[i].srcip2 == 0) { if (udpDetails[i].srcip2 == 0) {
@ -4881,12 +4912,14 @@ int is_udp_configured() {
LOG(logWARNING, ("%s", configureMessage)); LOG(logWARNING, ("%s", configureMessage));
return FAIL; return FAIL;
} }
#ifndef VIRTUAL
if (udpDetails[i].dstmac2 == 0) { if (udpDetails[i].dstmac2 == 0) {
sprintf(configureMessage, sprintf(configureMessage,
"udp destination mac2 not configured [entry:%d]\n", i); "udp destination mac2 not configured [entry:%d]\n", i);
LOG(logWARNING, ("%s", configureMessage)); LOG(logWARNING, ("%s", configureMessage));
return FAIL; return FAIL;
} }
#endif
} }
#endif #endif
} }
@ -7100,7 +7133,10 @@ int get_receiver_parameters(int file_des) {
} }
// dynamic range // dynamic range
i32 = setDynamicRange(GET_FLAG); ret = getDynamicRange(&i32);
if (ret == FAIL) {
i32 = 0;
}
n += sendData(file_des, &i32, sizeof(i32), INT32); n += sendData(file_des, &i32, sizeof(i32), INT32);
if (n < 0) if (n < 0)
return printSocketReadError(); return printSocketReadError();
@ -8182,14 +8218,60 @@ int get_master(int file_des) {
LOG(logDEBUG1, ("Getting master\n")); LOG(logDEBUG1, ("Getting master\n"));
#if !defined(MYTHEN3D) && !defined(EIGERD) && !defined(GOTTHARDD) #if !defined(MYTHEN3D) && !defined(EIGERD) && !defined(GOTTHARDD) && \
!defined(GOTTHARD2D)
functionNotImplemented(); functionNotImplemented();
#else #else
retval = isMaster(); ret = isMaster(&retval);
if (ret == FAIL) {
strcpy(mess, "Could not get master\n");
LOG(logERROR, (mess));
}
#endif #endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
} }
int set_master(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int arg = -1;
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError();
LOG(logDEBUG1, ("Setting master: %u\n", (int)arg));
#ifndef EIGERD
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
if ((check_detector_idle("set master") == OK) &&
(arg != 0 && arg != 1)) {
ret = FAIL;
sprintf(mess, "Could not set master. Invalid argument %d.\n", arg);
LOG(logERROR, (mess));
} else {
ret = setMaster(arg == 1 ? OW_MASTER : OW_SLAVE);
if (ret == FAIL) {
strcpy(mess, "Could not set master\n");
LOG(logERROR, (mess));
} else {
int retval = 0;
ret = isMaster(&retval);
if (ret == FAIL) {
strcpy(mess, "Could not get master\n");
LOG(logERROR, (mess));
} else {
LOG(logDEBUG1, ("master retval: %u\n", retval));
validate(&ret, mess, arg, retval, "set master", DEC);
}
}
}
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}
int get_csr(int file_des) { int get_csr(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
@ -9138,8 +9220,25 @@ int clear_all_udp_dst(int file_des) {
if (check_detector_idle("clear all udp destinations") == OK) { if (check_detector_idle("clear all udp destinations") == OK) {
memset(udpDetails, 0, sizeof(udpDetails)); memset(udpDetails, 0, sizeof(udpDetails));
// minimum 1 destination in fpga // minimum 1 destination in fpga
numUdpDestinations = 1; int numdest = 1;
configure_mac(); // set number of destinations
#if defined(JUNGFRAUD) || defined(EIGERD)
if (setNumberofDestinations(numdest) == FAIL) {
ret = FAIL;
strcpy(mess, "Could not clear udp destinations to 1 entry.\n");
LOG(logERROR, (mess));
} else
#endif
{
numUdpDestinations = numdest;
LOG(logINFOBLUE, ("Number of UDP Destinations: %d\n",
numUdpDestinations));
ret = configureMAC();
if (ret == FAIL) {
strcpy(mess, "Could not clear all destinations in the fpga.\n");
LOG(logERROR, (mess));
}
}
} }
} }
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
@ -9662,5 +9761,67 @@ int set_update_mode(int file_des) {
} }
} }
return Server_SendResult(file_des, INT32, NULL, 0);
}
int get_top(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int retval = -1;
LOG(logDEBUG1, ("Getting top\n"));
#ifndef EIGERD
functionNotImplemented();
#else
// get only
ret = isTop(&retval);
if (ret == FAIL) {
strcpy(mess, "Could not get Top\n");
LOG(logERROR, (mess));
} else {
LOG(logDEBUG1, ("retval top: %d\n", retval));
}
#endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}
int set_top(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int arg = -1;
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError();
LOG(logDEBUG1, ("Setting top : %u\n", arg));
#ifndef EIGERD
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
if (arg != 0 && arg != 1) {
ret = FAIL;
sprintf(mess, "Could not set top mode. Invalid value: %d. Must be 0 or 1\n", arg);
LOG(logERROR, (mess));
} else {
ret = setTop(arg == 1 ? OW_TOP : OW_BOTTOM);
if (ret == FAIL) {
sprintf(mess, "Could not set %s\n", (arg == 1 ? "Top" : "Bottom"));
LOG(logERROR, (mess));
} else {
int retval = -1;
ret = isTop(&retval);
if (ret == FAIL) {
strcpy(mess, "Could not get Top mode\n");
LOG(logERROR, (mess));
} else {
LOG(logDEBUG1, ("retval top: %d\n", retval));
validate(&ret, mess, arg, retval, "set top mode", DEC);
}
}
}
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
} }

View File

@ -193,6 +193,12 @@ class Detector {
*/ */
void setFlipRows(bool value, Positions pos = {}); void setFlipRows(bool value, Positions pos = {});
/** [Eiger][Mythen3][Gotthard1] via stop server **/
Result<bool> getMaster(Positions pos = {}) const;
/** [Eiger] Set half module to master and the others to slaves */
void setMaster(bool value, int pos);
Result<bool> isVirtualDetectorServer(Positions pos = {}) const; Result<bool> isVirtualDetectorServer(Positions pos = {}) const;
///@} ///@}
@ -284,7 +290,7 @@ class Detector {
Result<int> getDynamicRange(Positions pos = {}) const; Result<int> getDynamicRange(Positions pos = {}) const;
/** /**
* [Eiger] Options: 4, 8, 16, 32. If i is 32, also sets clkdivider to 2, * [Eiger] Options: 4, 8, 12, 16, 32. If i is 32, also sets clkdivider to 2,
* else sets clkdivider to 1 \n [Mythen3] Options: 8, 16, 32 \n * else sets clkdivider to 1 \n [Mythen3] Options: 8, 16, 32 \n
* [Jungfrau][Gotthard][Ctb][Moench][Mythen3][Gotthard2] 16 * [Jungfrau][Gotthard][Ctb][Moench][Mythen3][Gotthard2] 16
*/ */
@ -567,7 +573,7 @@ class Detector {
/** Non blocking: start detector acquisition. Status changes to RUNNING or /** Non blocking: start detector acquisition. Status changes to RUNNING or
* WAITING and automatically returns to idle at the end of acquisition. * WAITING and automatically returns to idle at the end of acquisition.
[Mythen3] Master starts acquisition first */ [Mythen3] Master starts acquisition first */
void startDetector(); void startDetector(Positions pos = {});
/** [Mythen3] Non blocking: start detector readout of counters in chip. /** [Mythen3] Non blocking: start detector readout of counters in chip.
* Status changes to TRANSMITTING and automatically returns to idle at the * Status changes to TRANSMITTING and automatically returns to idle at the
@ -588,11 +594,9 @@ class Detector {
Result<int64_t> getFramesCaught(Positions pos = {}) const; Result<int64_t> getFramesCaught(Positions pos = {}) const;
/** Gets the number of missing packets for each port in receiver. /** Gets the number of missing packets for each port in receiver. Negative
* Troubleshoot: If they are large numbers, convert it to signed to get * number denotes extra packets. */
* number of access packets received */ Result<std::vector<int64_t>> getNumMissingPackets(Positions pos = {}) const;
Result<std::vector<uint64_t>>
getNumMissingPackets(Positions pos = {}) const;
/** [Eiger][Jungfrau][Moench][CTB] */ /** [Eiger][Jungfrau][Moench][CTB] */
Result<uint64_t> getNextFrameNumber(Positions pos = {}) const; Result<uint64_t> getNextFrameNumber(Positions pos = {}) const;
@ -695,48 +699,60 @@ class Detector {
/**[Jungfrau] Options 0-31 (or number of udp destinations) */ /**[Jungfrau] Options 0-31 (or number of udp destinations) */
void setFirstUDPDestination(const int value, Positions pos = {}); void setFirstUDPDestination(const int value, Positions pos = {});
Result<IpAddr> getDestinationUDPIP(Positions pos = {}) const; Result<IpAddr> getDestinationUDPIP(Positions pos = {},
const int rx_index = 0) const;
/** IP of the interface in receiver that the detector sends data to */ /** IP of the interface in receiver that the detector sends data to */
void setDestinationUDPIP(const IpAddr ip, Positions pos = {}); void setDestinationUDPIP(const IpAddr ip, Positions pos = {},
const int rx_index = 0);
/** [Jungfrau] bottom half \n [Gotthard2] veto debugging */ /** [Jungfrau] bottom half \n [Gotthard2] veto debugging */
Result<IpAddr> getDestinationUDPIP2(Positions pos = {}) const; Result<IpAddr> getDestinationUDPIP2(Positions pos = {},
const int rx_index = 0) const;
/** [Jungfrau] bottom half \n [Gotthard2] veto debugging */ /** [Jungfrau] bottom half \n [Gotthard2] veto debugging */
void setDestinationUDPIP2(const IpAddr ip, Positions pos = {}); void setDestinationUDPIP2(const IpAddr ip, Positions pos = {},
const int rx_index = 0);
Result<MacAddr> getDestinationUDPMAC(Positions pos = {}) const; Result<MacAddr> getDestinationUDPMAC(Positions pos = {},
const int rxIndex = 0) const;
/** Mac address of the receiver (destination) udp interface. Not mandatory /** Mac address of the receiver (destination) udp interface. Not mandatory
* to set as setDestinationUDPIP (udp_dstip) retrieves it from slsReceiver * to set as setDestinationUDPIP (udp_dstip) retrieves it from slsReceiver
* process but must be set if you use a custom receiver (not slsReceiver). * process but must be set if you use a custom receiver (not slsReceiver).
*/ */
void setDestinationUDPMAC(const MacAddr mac, Positions pos = {}); void setDestinationUDPMAC(const MacAddr mac, Positions pos = {},
const int rx_index = 0);
/** [Jungfrau] bottom half \n [Gotthard2] veto debugging */ /** [Jungfrau] bottom half \n [Gotthard2] veto debugging */
Result<MacAddr> getDestinationUDPMAC2(Positions pos = {}) const; Result<MacAddr> getDestinationUDPMAC2(Positions pos = {},
const int rx_index = 0) const;
/* [Jungfrau][Gotthard2] Mac address of the receiver (destination) udp /* [Jungfrau][Gotthard2] Mac address of the receiver (destination) udp
interface 2. \n Not mandatory to set as udp_dstip2 retrieves it from interface 2. \n Not mandatory to set as udp_dstip2 retrieves it from
slsReceiver process but must be set if you use a custom receiver (not slsReceiver process but must be set if you use a custom receiver (not
slsReceiver). \n [Jungfrau] bottom half \n [Gotthard2] veto debugging \n slsReceiver). \n [Jungfrau] bottom half \n [Gotthard2] veto debugging \n
*/ */
void setDestinationUDPMAC2(const MacAddr mac, Positions pos = {}); void setDestinationUDPMAC2(const MacAddr mac, Positions pos = {},
const int rx_index = 0);
Result<int> getDestinationUDPPort(Positions pos = {}) const; Result<int> getDestinationUDPPort(Positions pos = {},
const int rx_index = 0) const;
/** Default is 50001. \n If module_id is -1, ports for each module is /** Default is 50001. \n If module_id is -1, ports for each module is
* calculated (incremented by 1 if no 2nd interface) */ * calculated (incremented by 1 if no 2nd interface) */
void setDestinationUDPPort(int port, int module_id = -1); void setDestinationUDPPort(int port, int module_id = -1,
const int rxIndex = 0);
/** [Eiger] right port[Jungfrau] bottom half [Gotthard2] veto debugging */ /** [Eiger] right port[Jungfrau] bottom half [Gotthard2] veto debugging */
Result<int> getDestinationUDPPort2(Positions pos = {}) const; Result<int> getDestinationUDPPort2(Positions pos = {},
const int rx_index = 0) const;
/** [Eiger] right port[Jungfrau] bottom half [Gotthard2] veto debugging \n /** [Eiger] right port[Jungfrau] bottom half [Gotthard2] veto debugging \n
* Default is 50002. \n If module_id is -1, ports for each module is * Default is 50002. \n If module_id is -1, ports for each module is
* calculated (incremented by 1 if no 2nd interface)*/ * calculated (incremented by 1 if no 2nd interface)*/
void setDestinationUDPPort2(int port, int module_id = -1); void setDestinationUDPPort2(int port, int module_id = -1,
const int rxIndex = 0);
/** Reconfigures Detector with UDP destination. More for debugging as the /** Reconfigures Detector with UDP destination. More for debugging as the
* configuration is done automatically when the detector has sufficient UDP * configuration is done automatically when the detector has sufficient UDP
@ -748,7 +764,8 @@ class Detector {
* information */ * information */
void validateUDPConfiguration(Positions pos = {}); void validateUDPConfiguration(Positions pos = {});
Result<std::string> printRxConfiguration(Positions pos = {}) const; Result<std::string> printRxConfiguration(Positions pos = {},
const int rx_index = 0) const;
/** [Eiger][CTB][Moench][Mythen3] */ /** [Eiger][CTB][Moench][Mythen3] */
Result<bool> getTenGiga(Positions pos = {}) const; Result<bool> getTenGiga(Positions pos = {}) const;
@ -807,7 +824,8 @@ class Detector {
/** true when slsReceiver is used */ /** true when slsReceiver is used */
Result<bool> getUseReceiverFlag(Positions pos = {}) const; Result<bool> getUseReceiverFlag(Positions pos = {}) const;
Result<std::string> getRxHostname(Positions pos = {}) const; Result<std::string> getRxHostname(Positions pos = {},
const int rx_index = 0) const;
/** /**
* Sets receiver hostname or IP address for each module. \n Used for TCP * Sets receiver hostname or IP address for each module. \n Used for TCP
@ -815,20 +833,24 @@ class Detector {
* Also updates receiver with detector parameters. \n Also resets any prior * Also updates receiver with detector parameters. \n Also resets any prior
* receiver property (not on detector). \n receiver is receiver hostname or * receiver property (not on detector). \n receiver is receiver hostname or
* IP address, can include tcp port eg. hostname:port * IP address, can include tcp port eg. hostname:port
*
* rxIndex of -1 is rewritten as 0 (for backwards compatibility)
*/ */
void setRxHostname(const std::string &receiver, Positions pos = {}); void setRxHostname(const std::string &receiver, Positions pos = {}, const int rxIndex = 0);
/** multiple rx hostnames. Single element will set it for all */ /** - single element, assumes rxIndex is 0 (for backwards compatibility).
void setRxHostname(const std::vector<std::string> &name); * - muliple element with pos empty or -1, sets each element for each module (1:1 for backwards compatibility, rxIndex = 0)
* multiple element for specific position, each element for each RR rxr */
void setRxHostname(const std::vector<std::string> &name, Positions pos);
Result<int> getRxPort(Positions pos = {}) const; Result<int> getRxPort(Positions pos = {}, const int rx_index = 0) const;
/** TCP port for client-receiver communication. \n /** TCP port for client-receiver communication. \n
* Default is 1954. \n Must be different if multiple receivers on same pc. * Default is 1954. \n Must be different if multiple receivers on same pc.
* \n Must be first command to set a receiver parameter to be able to * \n Must be first command to set a receiver parameter to be able to
* communicate. \n Multi command will automatically increment port for * communicate. \n Multi command will automatically increment port for
* individual modules.*/ * individual modules.*/
void setRxPort(int port, int module_id = -1); void setRxPort(int port, int module_id = -1, const int rx_index = 0);
Result<int> getRxFifoDepth(Positions pos = {}) const; Result<int> getRxFifoDepth(Positions pos = {}) const;
@ -878,10 +900,18 @@ class Detector {
Result<sls::IpAddr> getRxLastClientIP(Positions pos = {}) const; Result<sls::IpAddr> getRxLastClientIP(Positions pos = {}) const;
/** Get thread ids from the receiver in order of [parent, tcp, listener 0, /** Get thread ids from the receiver in order of [parent, tcp, listener 0,
* processor 0, streamer 0, listener 1, processor 1, streamer 1]. If no * processor 0, streamer 0, listener 1, processor 1, streamer 1, arping]. If
* streamer yet or there is no second interface, it gives 0 in its place. */ * no streamer yet or there is no second interface, it gives 0 in its place.
*/
Result<std::array<pid_t, NUM_RX_THREAD_IDS>> Result<std::array<pid_t, NUM_RX_THREAD_IDS>>
getRxThreadIds(Positions pos = {}) const; getRxThreadIds(Positions pos = {}) const;
Result<bool> getRxArping(Positions pos = {}) const;
/** Starts a thread in slsReceiver to arping the interface it is listening
* every minute. Useful in 10G mode. */
void setRxArping(bool value, Positions pos = {});
///@} ///@}
/** @name File */ /** @name File */
@ -998,13 +1028,15 @@ class Detector {
*/ */
void setRxZmqPort(int port, int module_id = -1); void setRxZmqPort(int port, int module_id = -1);
Result<IpAddr> getRxZmqIP(Positions pos = {}) const; Result<IpAddr> getRxZmqIP(Positions pos = {},
const int rx_index = 0) const;
/** Zmq Ip Address from which data is to be streamed out of the receiver. \n /** Zmq Ip Address from which data is to be streamed out of the receiver. \n
* Also restarts receiver zmq streaming if enabled. \n Default is from * Also restarts receiver zmq streaming if enabled. \n Default is from
* rx_hostname. \n Modified only when using an intermediate process between * rx_hostname. \n Modified only when using an intermediate process between
* receiver. */ * receiver. */
void setRxZmqIP(const IpAddr ip, Positions pos = {}); void setRxZmqIP(const IpAddr ip, Positions pos = {},
const int rx_index = 0);
Result<int> getClientZmqPort(Positions pos = {}) const; Result<int> getClientZmqPort(Positions pos = {}) const;
@ -1139,12 +1171,18 @@ class Detector {
Result<bool> getDataStream(const defs::portPosition port, Result<bool> getDataStream(const defs::portPosition port,
Positions pos = {}) const; Positions pos = {}) const;
/** [Eiger] enable or disable data streaming from left or right of detector. /** [Eiger] enable or disable data streaming from left or right of detector
* Default: enabled * for 10GbE. Default: enabled
*/ */
void setDataStream(const defs::portPosition port, const bool enable, void setDataStream(const defs::portPosition port, const bool enable,
Positions pos = {}); Positions pos = {});
/** [Eiger] Advanced */
Result<bool> getTop(Positions pos = {}) const;
/** [Eiger] Advanced. Default is hardware default */
void setTop(bool value, Positions pos = {});
///@} ///@}
/** @name Jungfrau Specific */ /** @name Jungfrau Specific */
@ -1442,9 +1480,6 @@ class Detector {
* (internal gating). Gate index: 0-2, -1 for all */ * (internal gating). Gate index: 0-2, -1 for all */
Result<std::array<ns, 3>> getGateDelayForAllGates(Positions pos = {}) const; Result<std::array<ns, 3>> getGateDelayForAllGates(Positions pos = {}) const;
/** [Eiger][Mythen3][Gotthard1] via stop server **/
Result<bool> getMaster(Positions pos = {}) const;
// TODO! check if we really want to expose this !!!!! // TODO! check if we really want to expose this !!!!!
Result<int> getChipStatusRegister(Positions pos = {}) const; Result<int> getChipStatusRegister(Positions pos = {}) const;

View File

@ -1484,7 +1484,7 @@ std::string CmdProxy::UDPDestinationList(int action) {
} }
if (rx_id < 0 || rx_id >= MAX_UDP_DESTINATION) { if (rx_id < 0 || rx_id >= MAX_UDP_DESTINATION) {
throw sls::RuntimeError( throw sls::RuntimeError(
"Invalid receiver index to set round robin entry."); std::string("Invalid receiver index ") + std::to_string(rx_id) + std::string(" to set round robin entry."));
} }
auto t = getUdpEntry(); auto t = getUdpEntry();
det->setDestinationUDPList(t, det_id); det->setDestinationUDPList(t, det_id);
@ -1504,7 +1504,7 @@ std::string CmdProxy::UDPDestinationIP(int action) {
"rx_hostname." "rx_hostname."
<< '\n'; << '\n';
} else if (action == defs::GET_ACTION) { } else if (action == defs::GET_ACTION) {
auto t = det->getDestinationUDPIP(std::vector<int>{det_id}); auto t = det->getDestinationUDPIP(std::vector<int>{det_id}, rx_id);
if (!args.empty()) { if (!args.empty()) {
WrongNumberOfParameters(0); WrongNumberOfParameters(0);
} }
@ -1517,11 +1517,11 @@ std::string CmdProxy::UDPDestinationIP(int action) {
auto val = getIpFromAuto(); auto val = getIpFromAuto();
LOG(logINFO) << "Setting udp_dstip of detector " << det_id << " to " LOG(logINFO) << "Setting udp_dstip of detector " << det_id << " to "
<< val; << val;
det->setDestinationUDPIP(val, std::vector<int>{det_id}); det->setDestinationUDPIP(val, std::vector<int>{det_id}, rx_id);
os << val << '\n'; os << val << '\n';
} else { } else {
auto val = IpAddr(args[0]); auto val = IpAddr(args[0]);
det->setDestinationUDPIP(val, std::vector<int>{det_id}); det->setDestinationUDPIP(val, std::vector<int>{det_id}, rx_id);
os << args.front() << '\n'; os << args.front() << '\n';
} }
} else { } else {
@ -1540,7 +1540,7 @@ std::string CmdProxy::UDPDestinationIP2(int action) {
"\n\t[Gotthard2] veto debugging. " "\n\t[Gotthard2] veto debugging. "
<< '\n'; << '\n';
} else if (action == defs::GET_ACTION) { } else if (action == defs::GET_ACTION) {
auto t = det->getDestinationUDPIP2(std::vector<int>{det_id}); auto t = det->getDestinationUDPIP2(std::vector<int>{det_id}, rx_id);
if (!args.empty()) { if (!args.empty()) {
WrongNumberOfParameters(0); WrongNumberOfParameters(0);
} }
@ -1553,11 +1553,11 @@ std::string CmdProxy::UDPDestinationIP2(int action) {
auto val = getIpFromAuto(); auto val = getIpFromAuto();
LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id
<< " to " << val; << " to " << val;
det->setDestinationUDPIP2(val, std::vector<int>{det_id}); det->setDestinationUDPIP2(val, std::vector<int>{det_id}, rx_id);
os << val << '\n'; os << val << '\n';
} else { } else {
auto val = IpAddr(args[0]); auto val = IpAddr(args[0]);
det->setDestinationUDPIP2(val, std::vector<int>{det_id}); det->setDestinationUDPIP2(val, std::vector<int>{det_id}, rx_id);
os << args.front() << '\n'; os << args.front() << '\n';
} }
} else { } else {
@ -1593,33 +1593,54 @@ std::string CmdProxy::ReceiverHostname(int action) {
} }
// multiple arguments // multiple arguments
if (args.size() > 1) { if (args.size() > 1) {
// multiple in mulitple if (rx_id != -1) {
throw sls::RuntimeError(
"Cannot add multiple receivers at RR level");
}
// multiple arguments (multiple rxr each)// backwards compatibility
if (args[0].find('+') != std::string::npos) { if (args[0].find('+') != std::string::npos) {
throw sls::RuntimeError( if (det_id != -1) {
"Cannot add multiple receivers at module level"); throw sls::RuntimeError(
"Cannot add multiple receivers for multiple modules at module level");
}
for (int i = 0; i < (int)args.size(); ++i) {
auto t = sls::split(args[i], '+');
det->setRxHostname(t, {i});
os << ToString(t) << '\n';
}
} }
if (det_id != -1) { // multiple arguments (single rxr each) (for both: each module and RR)
throw sls::RuntimeError( else {
"Cannot add multiple receivers at module level"); det->setRxHostname(args, {det_id});
os << ToString(args) << '\n';
} }
det->setRxHostname(args);
os << ToString(args) << '\n';
} }
// single argument // single argument
else { else {
// multiple receivers concatenated with + // multiple receivers concatenated with +
if (args[0].find('+') != std::string::npos) { if (args[0].find('+') != std::string::npos) {
if (det_id != -1) {
throw sls::RuntimeError(
"Cannot add multiple receivers at module level");
}
auto t = sls::split(args[0], '+'); auto t = sls::split(args[0], '+');
det->setRxHostname(t); if (t.size() <= 0) {
os << ToString(t) << '\n'; throw sls::RuntimeError("Invalid argument for rx_hostname");
}
// single receiver
if (t.size() == 1) {
det->setRxHostname(t[0], std::vector<int>{det_id});
os << ToString(t[0]) << '\n';
}
// multiple receivers
else {
if (rx_id != -1) {
throw sls::RuntimeError(
"Cannot add multiple receivers at RR level");
}
det->setRxHostname(t, {det_id});
os << ToString(t) << '\n';
}
} }
// single receiver // single receiver
else { else {
det->setRxHostname(args[0], std::vector<int>{det_id}); det->setRxHostname(args[0], std::vector<int>{det_id}, rx_id);
os << ToString(args) << '\n'; os << ToString(args) << '\n';
} }
} }
@ -1804,7 +1825,9 @@ std::string CmdProxy::DataStream(int action) {
os << cmd << ' '; os << cmd << ' ';
if (action == defs::HELP_ACTION) { if (action == defs::HELP_ACTION) {
os << "[left|right] [0, 1]\n\t[Eiger] Enables or disables data " os << "[left|right] [0, 1]\n\t[Eiger] Enables or disables data "
"streaming from left or/and right side of detector. 1 (enabled) " "streaming from left or/and right side of detector for 10 GbE "
"mode. "
"1 (enabled) "
"by default." "by default."
<< '\n'; << '\n';
} else if (action == defs::GET_ACTION) { } else if (action == defs::GET_ACTION) {

View File

@ -185,8 +185,34 @@
return os.str(); \ return os.str(); \
} }
#define INTEGER_COMMAND_VEC_ID_RX(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
os << cmd << ' '; \
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
else if (action == slsDetectorDefs::GET_ACTION) { \
if (!args.empty()) { \
WrongNumberOfParameters(0); \
} \
auto t = det->GETFCN(std::vector<int>{det_id}, rx_id); \
os << OutString(t) << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() != 1) { \
WrongNumberOfParameters(1); \
} \
auto val = CONV(args[0]); \
det->SETFCN(val, std::vector<int>{det_id}, rx_id); \
os << args.front() << '\n'; \
} else { \
throw sls::RuntimeError("Unknown action"); \
} \
return os.str(); \
}
/** int or enum */ /** int or enum */
#define INTEGER_COMMAND_VEC_ID_GET(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \ #define INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(CMDNAME, GETFCN, SETFCN, CONV, \
HLPSTR) \
std::string CMDNAME(const int action) { \ std::string CMDNAME(const int action) { \
std::ostringstream os; \ std::ostringstream os; \
os << cmd << ' '; \ os << cmd << ' '; \
@ -211,6 +237,32 @@
return os.str(); \ return os.str(); \
} }
#define INTEGER_COMMAND_VEC_ID_P_RX_SINGLE_ID(CMDNAME, GETFCN, SETFCN, CONV, \
HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
os << cmd << ' '; \
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
else if (action == slsDetectorDefs::GET_ACTION) { \
if (!args.empty()) { \
WrongNumberOfParameters(0); \
} \
auto t = det->GETFCN(std::vector<int>{det_id}, rx_id); \
os << OutString(t) << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() != 1) { \
WrongNumberOfParameters(1); \
} \
auto val = CONV(args[0]); \
det->SETFCN(val, det_id, rx_id); \
os << args.front() << '\n'; \
} else { \
throw sls::RuntimeError("Unknown action"); \
} \
return os.str(); \
}
/** int or enum */ /** int or enum */
#define INTEGER_COMMAND_SINGLE_ID(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \ #define INTEGER_COMMAND_SINGLE_ID(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \
std::string CMDNAME(const int action) { \ std::string CMDNAME(const int action) { \
@ -461,6 +513,26 @@
return os.str(); \ return os.str(); \
} }
#define GET_COMMAND_RX(CMDNAME, GETFCN, HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
os << cmd << ' '; \
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
else if (action == slsDetectorDefs::GET_ACTION) { \
if (!args.empty()) { \
WrongNumberOfParameters(0); \
} \
auto t = det->GETFCN(std::vector<int>{det_id}); \
os << OutString(t) << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
throw sls::RuntimeError("Cannot put"); \
} else { \
throw sls::RuntimeError("Unknown action"); \
} \
return os.str(); \
}
/** get only no id (vector, not result) */ /** get only no id (vector, not result) */
#define GET_COMMAND_NOID(CMDNAME, GETFCN, HLPSTR) \ #define GET_COMMAND_NOID(CMDNAME, GETFCN, HLPSTR) \
std::string CMDNAME(const int action) { \ std::string CMDNAME(const int action) { \
@ -784,6 +856,7 @@ class CmdProxy {
{"trimen", &CmdProxy::TrimEnergies}, {"trimen", &CmdProxy::TrimEnergies},
{"gappixels", &CmdProxy::GapPixels}, {"gappixels", &CmdProxy::GapPixels},
{"fliprows", &CmdProxy::fliprows}, {"fliprows", &CmdProxy::fliprows},
{"master", &CmdProxy::master},
/* acquisition parameters */ /* acquisition parameters */
{"acquire", &CmdProxy::Acquire}, {"acquire", &CmdProxy::Acquire},
@ -903,6 +976,7 @@ class CmdProxy {
{"rx_lock", &CmdProxy::rx_lock}, {"rx_lock", &CmdProxy::rx_lock},
{"rx_lastclient", &CmdProxy::rx_lastclient}, {"rx_lastclient", &CmdProxy::rx_lastclient},
{"rx_threads", &CmdProxy::rx_threads}, {"rx_threads", &CmdProxy::rx_threads},
{"rx_arping", &CmdProxy::rx_arping},
/* File */ /* File */
{"fformat", &CmdProxy::fformat}, {"fformat", &CmdProxy::fformat},
@ -941,6 +1015,7 @@ class CmdProxy {
{"pulsechip", &CmdProxy::PulseChip}, {"pulsechip", &CmdProxy::PulseChip},
{"quad", &CmdProxy::Quad}, {"quad", &CmdProxy::Quad},
{"datastream", &CmdProxy::DataStream}, {"datastream", &CmdProxy::DataStream},
{"top", &CmdProxy::top},
/* Jungfrau Specific */ /* Jungfrau Specific */
{"chipversion", &CmdProxy::chipversion}, {"chipversion", &CmdProxy::chipversion},
@ -1108,7 +1183,6 @@ class CmdProxy {
/* acquisition parameters */ /* acquisition parameters */
std::string Acquire(int action); std::string Acquire(int action);
std::string Exptime(int action); std::string Exptime(int action);
std::string DynamicRange(int action);
std::string ReadoutSpeed(int action); std::string ReadoutSpeed(int action);
std::string Adcphase(int action); std::string Adcphase(int action);
std::string Dbitphase(int action); std::string Dbitphase(int action);
@ -1280,6 +1354,12 @@ class CmdProxy {
"interfaces must be set to 2. slsReceiver and slsDetectorGui " "interfaces must be set to 2. slsReceiver and slsDetectorGui "
"does not handle."); "does not handle.");
INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(
master, getMaster, setMaster, StringTo<int>,
"[0, 1]\n\t[Eiger] Sets half module to master and "
"others to slaves.\n\t[Gotthard][Gotthard2][Mythen3][Eiger] "
"Gets if the current module/ half module is master.");
/* acquisition parameters */ /* acquisition parameters */
INTEGER_COMMAND_SET_NOID_GET_ID( INTEGER_COMMAND_SET_NOID_GET_ID(
@ -1327,7 +1407,7 @@ class CmdProxy {
dr, getDynamicRange, setDynamicRange, StringTo<int>, dr, getDynamicRange, setDynamicRange, StringTo<int>,
"[value]\n\tDynamic Range or number of bits per " "[value]\n\tDynamic Range or number of bits per "
"pixel in detector.\n\t" "pixel in detector.\n\t"
"[Eiger] Options: 4, 8, 16, 32. If set to 32, also sets " "[Eiger] Options: 4, 8, 12, 16, 32. If set to 32, also sets "
"clkdivider to 2, else to 0.\n\t" "clkdivider to 2, else to 0.\n\t"
"[Mythen3] Options: 8, 16, 32\n\t" "[Mythen3] Options: 8, 16, 32\n\t"
"[Jungfrau][Gotthard][Ctb][Moench][Mythen3][Gotthard2] 16"); "[Jungfrau][Gotthard][Ctb][Moench][Mythen3][Gotthard2] 16");
@ -1515,7 +1595,7 @@ class CmdProxy {
"\n\tStops receiver listener for detector data packets and closes " "\n\tStops receiver listener for detector data packets and closes "
"current data file (if file write enabled)."); "current data file (if file write enabled).");
EXECUTE_SET_COMMAND_NOID( EXECUTE_SET_COMMAND(
start, startDetector, start, startDetector,
"\n\tStarts detector acquisition. Status changes to RUNNING or WAITING " "\n\tStarts detector acquisition. Status changes to RUNNING or WAITING "
"and automatically returns to idle at the end of acquisition. If the " "and automatically returns to idle at the end of acquisition. If the "
@ -1535,7 +1615,8 @@ class CmdProxy {
"\n\tNumber of frames caught by receiver."); "\n\tNumber of frames caught by receiver.");
GET_COMMAND(rx_missingpackets, getNumMissingPackets, GET_COMMAND(rx_missingpackets, getNumMissingPackets,
"\n\tNumber of missing packets for each port in receiver."); "\n\tNumber of missing packets for each port in receiver. "
"Negative number denotes extra packets.");
INTEGER_COMMAND_VEC_ID( INTEGER_COMMAND_VEC_ID(
nextframenumber, getNextFrameNumber, setNextFrameNumber, nextframenumber, getNextFrameNumber, setNextFrameNumber,
@ -1608,14 +1689,14 @@ class CmdProxy {
"[x:x:x:x:x:x]\n\t[Jungfrau] Mac address of the top " "[x:x:x:x:x:x]\n\t[Jungfrau] Mac address of the top "
"half or inner (source) udp interface. "); "half or inner (source) udp interface. ");
INTEGER_COMMAND_VEC_ID( INTEGER_COMMAND_VEC_ID_RX(
udp_dstmac, getDestinationUDPMAC, setDestinationUDPMAC, MacAddr, udp_dstmac, getDestinationUDPMAC, setDestinationUDPMAC, MacAddr,
"[x:x:x:x:x:x]\n\tMac address of the receiver (destination) udp " "[x:x:x:x:x:x]\n\tMac address of the receiver (destination) udp "
"interface. Not mandatory to set as udp_dstip retrieves it from " "interface. Not mandatory to set as udp_dstip retrieves it from "
"slsReceiver process, but must be set if you use a custom receiver " "slsReceiver process, but must be set if you use a custom receiver "
"(not slsReceiver)."); "(not slsReceiver).");
INTEGER_COMMAND_VEC_ID( INTEGER_COMMAND_VEC_ID_RX(
udp_dstmac2, getDestinationUDPMAC2, setDestinationUDPMAC2, MacAddr, udp_dstmac2, getDestinationUDPMAC2, setDestinationUDPMAC2, MacAddr,
"[x:x:x:x:x:x]\n\t[Jungfrau] Mac address of the receiver (destination) " "[x:x:x:x:x:x]\n\t[Jungfrau] Mac address of the receiver (destination) "
"udp interface 2. Not mandatory to set as udp_dstip2 retrieves it from " "udp interface 2. Not mandatory to set as udp_dstip2 retrieves it from "
@ -1624,14 +1705,14 @@ class CmdProxy {
"[Gotthard2] veto " "[Gotthard2] veto "
"debugging."); "debugging.");
INTEGER_COMMAND_VEC_ID_GET( INTEGER_COMMAND_VEC_ID_P_RX_SINGLE_ID(
udp_dstport, getDestinationUDPPort, setDestinationUDPPort, udp_dstport, getDestinationUDPPort, setDestinationUDPPort,
StringTo<int>, StringTo<int>,
"[n]\n\tPort number of the receiver (destination) udp " "[n]\n\tPort number of the receiver (destination) udp "
"interface. Default is 50001. \n\tIf multi command, ports for each " "interface. Default is 50001. \n\tIf multi command, ports for each "
"module is calculated (incremented by 1 if no 2nd interface)"); "module is calculated (incremented by 1 if no 2nd interface)");
INTEGER_COMMAND_VEC_ID_GET( INTEGER_COMMAND_VEC_ID_P_RX_SINGLE_ID(
udp_dstport2, getDestinationUDPPort2, setDestinationUDPPort2, udp_dstport2, getDestinationUDPPort2, setDestinationUDPPort2,
StringTo<int>, StringTo<int>,
"[n]\n\t[Jungfrau][Eiger][Gotthard2] Port number of the " "[n]\n\t[Jungfrau][Eiger][Gotthard2] Port number of the "
@ -1653,8 +1734,8 @@ class CmdProxy {
"valid. If not configured, it will throw with error message " "valid. If not configured, it will throw with error message "
"requesting missing udp information."); "requesting missing udp information.");
GET_COMMAND(rx_printconfig, printRxConfiguration, GET_COMMAND_RX(rx_printconfig, printRxConfiguration,
"\n\tPrints the receiver configuration."); "\n\tPrints the receiver configuration.");
INTEGER_COMMAND_VEC_ID( INTEGER_COMMAND_VEC_ID(
tengiga, getTenGiga, setTenGiga, StringTo<int>, tengiga, getTenGiga, setTenGiga, StringTo<int>,
@ -1690,7 +1771,7 @@ class CmdProxy {
/* Receiver Config */ /* Receiver Config */
INTEGER_COMMAND_VEC_ID_GET( INTEGER_COMMAND_VEC_ID_P_RX_SINGLE_ID(
rx_tcpport, getRxPort, setRxPort, StringTo<int>, rx_tcpport, getRxPort, setRxPort, StringTo<int>,
"[port]\n\tTCP port for client-receiver communication. Default is " "[port]\n\tTCP port for client-receiver communication. Default is "
"1954. Must be different if multiple receivers on same pc. Must be " "1954. Must be different if multiple receivers on same pc. Must be "
@ -1738,13 +1819,16 @@ class CmdProxy {
rx_lastclient, getRxLastClientIP, rx_lastclient, getRxLastClientIP,
"\n\tClient IP Address that last communicated with the receiver."); "\n\tClient IP Address that last communicated with the receiver.");
GET_COMMAND( GET_COMMAND(rx_threads, getRxThreadIds,
rx_threads, getRxThreadIds, "\n\tGet thread ids from the receiver in order of [parent, "
"\n\tGet thread ids from the receiver in order of [parent, tcp, " "tcp, listener 0, processor 0, streamer 0, listener 1, "
"listener 0, " "processor 1, streamer 1, arping]. If no streamer yet or there "
"processor 0, streamer 0, listener 1, processor 1, streamer 1]. If no " "is no second interface, it gives 0 in its place.");
"streamer yet or there is no second interface, it gives 0 in its "
"place."); INTEGER_COMMAND_VEC_ID(rx_arping, getRxArping, setRxArping, StringTo<int>,
"[0, 1]\n\tStarts a thread in slsReceiver to arping "
"the interface it is "
"listening to every minute. Useful in 10G mode.");
/* File */ /* File */
@ -1812,7 +1896,7 @@ class CmdProxy {
"default, which streams the first frame in an acquisition, " "default, which streams the first frame in an acquisition, "
"and then depending on the rx zmq frequency/ timer"); "and then depending on the rx zmq frequency/ timer");
INTEGER_COMMAND_VEC_ID_GET( INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(
rx_zmqport, getRxZmqPort, setRxZmqPort, StringTo<int>, rx_zmqport, getRxZmqPort, setRxZmqPort, StringTo<int>,
"[port]\n\tZmq port for data to be streamed out of the receiver. Also " "[port]\n\tZmq port for data to be streamed out of the receiver. Also "
"restarts receiver zmq streaming if enabled. Default is 30001. " "restarts receiver zmq streaming if enabled. Default is 30001. "
@ -1820,7 +1904,7 @@ class CmdProxy {
"client(gui). Must be different for every detector (and udp port). " "client(gui). Must be different for every detector (and udp port). "
"Multi command will automatically increment for individual modules."); "Multi command will automatically increment for individual modules.");
INTEGER_COMMAND_VEC_ID_GET( INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(
zmqport, getClientZmqPort, setClientZmqPort, StringTo<int>, zmqport, getClientZmqPort, setClientZmqPort, StringTo<int>,
"[port]\n\tZmq port in client(gui) or intermediate process for data to " "[port]\n\tZmq port in client(gui) or intermediate process for data to "
"be streamed to from receiver. Default connects to receiver zmq " "be streamed to from receiver. Default connects to receiver zmq "
@ -1830,7 +1914,7 @@ class CmdProxy {
"port). Multi command will automatically increment for individual " "port). Multi command will automatically increment for individual "
"modules."); "modules.");
INTEGER_COMMAND_VEC_ID( INTEGER_COMMAND_VEC_ID_RX(
rx_zmqip, getRxZmqIP, setRxZmqIP, IpAddr, rx_zmqip, getRxZmqIP, setRxZmqIP, IpAddr,
"[x.x.x.x]\n\tZmq Ip Address from which data is to be streamed out of " "[x.x.x.x]\n\tZmq Ip Address from which data is to be streamed out of "
"the receiver. Also restarts receiver zmq streaming if enabled. " "the receiver. Also restarts receiver zmq streaming if enabled. "
@ -1896,6 +1980,10 @@ class CmdProxy {
"start of acquisition. 0 complete reset, 1 partial reset. Default is " "start of acquisition. 0 complete reset, 1 partial reset. Default is "
"complete reset. Advanced function!"); "complete reset. Advanced function!");
INTEGER_COMMAND_VEC_ID(
top, getTop, setTop, StringTo<int>,
"[0, 1]\n\t[Eiger] Sets half module to top (1), else bottom.");
/* Jungfrau Specific */ /* Jungfrau Specific */
GET_COMMAND(chipversion, getChipVersion, GET_COMMAND(chipversion, getChipVersion,

View File

@ -298,6 +298,23 @@ void Detector::setFlipRows(bool value, Positions pos) {
pimpl->Parallel(&Module::setFlipRows, pos, value); pimpl->Parallel(&Module::setFlipRows, pos, value);
} }
Result<bool> Detector::getMaster(Positions pos) const {
return pimpl->Parallel(&Module::isMaster, pos);
}
void Detector::setMaster(bool master, int pos) {
// multi mod, set slaves first
if (master && size() > 1) {
if (pos == -1) {
throw RuntimeError("Master can be set only to a single module");
}
pimpl->Parallel(&Module::setMaster, {}, false);
pimpl->Parallel(&Module::setMaster, {pos}, master);
} else {
pimpl->Parallel(&Module::setMaster, {pos}, master);
}
}
Result<bool> Detector::isVirtualDetectorServer(Positions pos) const { Result<bool> Detector::isVirtualDetectorServer(Positions pos) const {
return pimpl->Parallel(&Module::isVirtualDetectorServer, pos); return pimpl->Parallel(&Module::isVirtualDetectorServer, pos);
} }
@ -387,7 +404,7 @@ void Detector::setDynamicRange(int value) {
std::vector<int> Detector::getDynamicRangeList() const { std::vector<int> Detector::getDynamicRangeList() const {
switch (getDetectorType().squash()) { switch (getDetectorType().squash()) {
case defs::EIGER: case defs::EIGER:
return std::vector<int>{4, 8, 16, 32}; return std::vector<int>{4, 8, 12, 16, 32};
case defs::MYTHEN3: case defs::MYTHEN3:
return std::vector<int>{8, 16, 32}; return std::vector<int>{8, 16, 32};
default: default:
@ -756,22 +773,24 @@ void Detector::startReceiver() { pimpl->Parallel(&Module::startReceiver, {}); }
void Detector::stopReceiver() { pimpl->Parallel(&Module::stopReceiver, {}); } void Detector::stopReceiver() { pimpl->Parallel(&Module::stopReceiver, {}); }
void Detector::startDetector() { void Detector::startDetector(Positions pos) {
auto detector_type = getDetectorType().squash(); auto detector_type = getDetectorType(pos).squash();
if (detector_type == defs::MYTHEN3 && size() > 1) { if (detector_type == defs::MYTHEN3 && size() > 1) {
auto is_master = getMaster(); std::vector<int> slaves(pos);
int masterPosition = 0; auto is_master = getMaster(pos);
std::vector<int> slaves; int masterPosition = -1;
for (int i = 0; i < size(); ++i) { for (unsigned int i = 0; i < is_master.size(); ++i) {
if (is_master[i]) if (is_master[i]) {
masterPosition = i; masterPosition = i;
else slaves.erase(slaves.begin() + i);
slaves.push_back(i); }
}
pimpl->Parallel(&Module::startAcquisition, pos);
if (masterPosition != -1) {
pimpl->Parallel(&Module::startAcquisition, {masterPosition});
} }
pimpl->Parallel(&Module::startAcquisition, slaves);
pimpl->Parallel(&Module::startAcquisition, {masterPosition});
} else { } else {
pimpl->Parallel(&Module::startAcquisition, {}); pimpl->Parallel(&Module::startAcquisition, pos);
} }
} }
@ -781,6 +800,25 @@ void Detector::startDetectorReadout() {
void Detector::stopDetector(Positions pos) { void Detector::stopDetector(Positions pos) {
pimpl->Parallel(&Module::stopAcquisition, pos); pimpl->Parallel(&Module::stopAcquisition, pos);
// validate consistent frame numbers
switch (getDetectorType().squash()) {
case defs::EIGER:
case defs::JUNGFRAU:
case defs::MOENCH:
case defs::CHIPTESTBOARD: {
auto res = getNextFrameNumber(pos);
if (!res.equal()) {
uint64_t maxVal = 0;
for (auto it : res) {
maxVal = std::max(maxVal, it);
}
setNextFrameNumber(maxVal + 1);
}
} break;
default:
break;
}
} }
Result<defs::runStatus> Detector::getDetectorStatus(Positions pos) const { Result<defs::runStatus> Detector::getDetectorStatus(Positions pos) const {
@ -795,7 +833,7 @@ Result<int64_t> Detector::getFramesCaught(Positions pos) const {
return pimpl->Parallel(&Module::getFramesCaughtByReceiver, pos); return pimpl->Parallel(&Module::getFramesCaughtByReceiver, pos);
} }
Result<std::vector<uint64_t>> Result<std::vector<int64_t>>
Detector::getNumMissingPackets(Positions pos) const { Detector::getNumMissingPackets(Positions pos) const {
return pimpl->Parallel(&Module::getNumMissingPackets, pos); return pimpl->Parallel(&Module::getNumMissingPackets, pos);
} }
@ -939,67 +977,81 @@ void Detector::setFirstUDPDestination(const int value, Positions pos) {
pimpl->Parallel(&Module::setFirstUDPDestination, pos, value); pimpl->Parallel(&Module::setFirstUDPDestination, pos, value);
} }
Result<IpAddr> Detector::getDestinationUDPIP(Positions pos) const { Result<IpAddr> Detector::getDestinationUDPIP(Positions pos,
return pimpl->Parallel(&Module::getDestinationUDPIP, pos); const int rx_index) const {
return pimpl->Parallel(&Module::getDestinationUDPIP, pos, rx_index);
} }
void Detector::setDestinationUDPIP(const IpAddr ip, Positions pos) { void Detector::setDestinationUDPIP(const IpAddr ip, Positions pos,
pimpl->Parallel(&Module::setDestinationUDPIP, pos, ip); const int rx_index) {
pimpl->Parallel(&Module::setDestinationUDPIP, pos, ip, rx_index);
} }
Result<IpAddr> Detector::getDestinationUDPIP2(Positions pos) const { Result<IpAddr> Detector::getDestinationUDPIP2(Positions pos,
return pimpl->Parallel(&Module::getDestinationUDPIP2, pos); const int rx_index) const {
return pimpl->Parallel(&Module::getDestinationUDPIP2, pos, rx_index);
} }
void Detector::setDestinationUDPIP2(const IpAddr ip, Positions pos) { void Detector::setDestinationUDPIP2(const IpAddr ip, Positions pos,
pimpl->Parallel(&Module::setDestinationUDPIP2, pos, ip); const int rx_index) {
pimpl->Parallel(&Module::setDestinationUDPIP2, pos, ip, rx_index);
} }
Result<MacAddr> Detector::getDestinationUDPMAC(Positions pos) const { Result<MacAddr> Detector::getDestinationUDPMAC(Positions pos,
return pimpl->Parallel(&Module::getDestinationUDPMAC, pos); const int rx_index) const {
return pimpl->Parallel(&Module::getDestinationUDPMAC, pos, rx_index);
} }
void Detector::setDestinationUDPMAC(const MacAddr mac, Positions pos) { void Detector::setDestinationUDPMAC(const MacAddr mac, Positions pos,
pimpl->Parallel(&Module::setDestinationUDPMAC, pos, mac); const int rx_index) {
pimpl->Parallel(&Module::setDestinationUDPMAC, pos, mac, rx_index);
} }
Result<MacAddr> Detector::getDestinationUDPMAC2(Positions pos) const { Result<MacAddr> Detector::getDestinationUDPMAC2(Positions pos,
return pimpl->Parallel(&Module::getDestinationUDPMAC2, pos); const int rx_index) const {
return pimpl->Parallel(&Module::getDestinationUDPMAC2, pos, rx_index);
} }
void Detector::setDestinationUDPMAC2(const MacAddr mac, Positions pos) { void Detector::setDestinationUDPMAC2(const MacAddr mac, Positions pos,
pimpl->Parallel(&Module::setDestinationUDPMAC2, pos, mac); const int rx_index) {
pimpl->Parallel(&Module::setDestinationUDPMAC2, pos, mac, rx_index);
} }
Result<int> Detector::getDestinationUDPPort(Positions pos) const { Result<int> Detector::getDestinationUDPPort(Positions pos,
return pimpl->Parallel(&Module::getDestinationUDPPort, pos); const int rx_index) const {
return pimpl->Parallel(&Module::getDestinationUDPPort, pos, rx_index);
} }
void Detector::setDestinationUDPPort(int port, int module_id) { void Detector::setDestinationUDPPort(int port, int module_id,
const int rx_index) {
if (module_id == -1) { if (module_id == -1) {
std::vector<int> port_list = getPortNumbers(port); std::vector<int> port_list = getPortNumbers(port);
for (int idet = 0; idet < size(); ++idet) { for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&Module::setDestinationUDPPort, {idet}, pimpl->Parallel(&Module::setDestinationUDPPort, {idet},
port_list[idet]); port_list[idet], rx_index);
} }
} else { } else {
pimpl->Parallel(&Module::setDestinationUDPPort, {module_id}, port); pimpl->Parallel(&Module::setDestinationUDPPort, {module_id}, port,
rx_index);
} }
} }
Result<int> Detector::getDestinationUDPPort2(Positions pos) const { Result<int> Detector::getDestinationUDPPort2(Positions pos,
return pimpl->Parallel(&Module::getDestinationUDPPort2, pos); const int rx_index) const {
return pimpl->Parallel(&Module::getDestinationUDPPort2, pos, rx_index);
} }
void Detector::setDestinationUDPPort2(int port, int module_id) { void Detector::setDestinationUDPPort2(int port, int module_id,
const int rx_index) {
if (module_id == -1) { if (module_id == -1) {
std::vector<int> port_list = getPortNumbers(port); std::vector<int> port_list = getPortNumbers(port);
for (int idet = 0; idet < size(); ++idet) { for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&Module::setDestinationUDPPort2, {idet}, pimpl->Parallel(&Module::setDestinationUDPPort2, {idet},
port_list[idet]); port_list[idet], rx_index);
} }
} else { } else {
pimpl->Parallel(&Module::setDestinationUDPPort2, {module_id}, port); pimpl->Parallel(&Module::setDestinationUDPPort2, {module_id}, port,
rx_index);
} }
} }
@ -1011,8 +1063,9 @@ void Detector::validateUDPConfiguration(Positions pos) {
pimpl->Parallel(&Module::validateUDPConfiguration, pos); pimpl->Parallel(&Module::validateUDPConfiguration, pos);
} }
Result<std::string> Detector::printRxConfiguration(Positions pos) const { Result<std::string> Detector::printRxConfiguration(Positions pos,
return pimpl->Parallel(&Module::printReceiverConfiguration, pos); const int rx_index) const {
return pimpl->Parallel(&Module::printReceiverConfiguration, pos, rx_index);
} }
Result<bool> Detector::getTenGiga(Positions pos) const { Result<bool> Detector::getTenGiga(Positions pos) const {
@ -1061,48 +1114,61 @@ Result<bool> Detector::getUseReceiverFlag(Positions pos) const {
return pimpl->Parallel(&Module::getUseReceiverFlag, pos); return pimpl->Parallel(&Module::getUseReceiverFlag, pos);
} }
Result<std::string> Detector::getRxHostname(Positions pos) const { Result<std::string> Detector::getRxHostname(Positions pos,
return pimpl->Parallel(&Module::getReceiverHostname, pos); const int rx_index) const {
return pimpl->Parallel(&Module::getReceiverHostname, pos, rx_index);
} }
void Detector::setRxHostname(const std::string &receiver, Positions pos) { // rr added using + at module level
pimpl->Parallel(&Module::setReceiverHostname, pos, receiver); void Detector::setRxHostname(const std::string &receiver, Positions pos,
const int rxIndex) {
// for backwards compatibility
if (rxIndex == -1) {
pimpl->Parallel(&Module::setReceiverHostname, pos, receiver, 0);
} else {
pimpl->Parallel(&Module::setReceiverHostname, pos, receiver, rxIndex);
}
updateRxRateCorrections(); updateRxRateCorrections();
} }
void Detector::setRxHostname(const std::vector<std::string> &name) { void Detector::setRxHostname(const std::vector<std::string> &name,
// set all to same rx_hostname Positions pos) {
if (name.size() == 1) { // multi module (backwards compatibility: every element for every module)
pimpl->Parallel(&Module::setReceiverHostname, {}, name[0]); if (name.size() > 1 && ((pos.empty() || pos[0] == -1))) {
} else {
if ((int)name.size() != size()) { if ((int)name.size() != size()) {
throw RuntimeError( throw RuntimeError(
"Receiver hostnames size " + std::to_string(name.size()) + "Receiver hostnames size " + std::to_string(name.size()) +
" does not match detector size " + std::to_string(size())); " does not match detector size " + std::to_string(size()));
} }
// set each rx_hostname
for (int idet = 0; idet < size(); ++idet) { for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&Module::setReceiverHostname, {idet}, name[idet]); pimpl->Parallel(&Module::setReceiverHostname, {idet}, name[idet],
0);
} }
} }
// setting rr for specific module (backwards compaibility: single element is
// only for 0th RR)
else {
pimpl->Parallel(&Module::setAllReceiverHostnames, {pos}, name);
}
updateRxRateCorrections(); updateRxRateCorrections();
} }
Result<int> Detector::getRxPort(Positions pos) const { Result<int> Detector::getRxPort(Positions pos, const int rx_index) const {
return pimpl->Parallel(&Module::getReceiverPort, pos); return pimpl->Parallel(&Module::getReceiverPort, pos, rx_index);
} }
void Detector::setRxPort(int port, int module_id) { void Detector::setRxPort(int port, int module_id, const int rx_index) {
if (module_id == -1) { if (module_id == -1) {
std::vector<int> port_list(size()); std::vector<int> port_list(size());
for (auto &it : port_list) { for (auto &it : port_list) {
it = port++; it = port++;
} }
for (int idet = 0; idet < size(); ++idet) { for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&Module::setReceiverPort, {idet}, port_list[idet]); pimpl->Parallel(&Module::setReceiverPort, {idet}, port_list[idet],
rx_index);
} }
} else { } else {
pimpl->Parallel(&Module::setReceiverPort, {module_id}, port); pimpl->Parallel(&Module::setReceiverPort, {module_id}, port, rx_index);
} }
} }
@ -1170,6 +1236,14 @@ Detector::getRxThreadIds(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverThreadIds, pos); return pimpl->Parallel(&Module::getReceiverThreadIds, pos);
} }
Result<bool> Detector::getRxArping(Positions pos) const {
return pimpl->Parallel(&Module::getRxArping, pos);
}
void Detector::setRxArping(bool value, Positions pos) {
pimpl->Parallel(&Module::setRxArping, pos, value);
}
// File // File
Result<defs::fileFormat> Detector::getFileFormat(Positions pos) const { Result<defs::fileFormat> Detector::getFileFormat(Positions pos) const {
@ -1292,13 +1366,13 @@ void Detector::setRxZmqPort(int port, int module_id) {
} }
} }
Result<IpAddr> Detector::getRxZmqIP(Positions pos) const { Result<IpAddr> Detector::getRxZmqIP(Positions pos, const int rx_index) const {
return pimpl->Parallel(&Module::getReceiverStreamingIP, pos); return pimpl->Parallel(&Module::getReceiverStreamingIP, pos, rx_index);
} }
void Detector::setRxZmqIP(const IpAddr ip, Positions pos) { void Detector::setRxZmqIP(const IpAddr ip, Positions pos, const int rx_index) {
bool previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(false); bool previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(false);
pimpl->Parallel(&Module::setReceiverStreamingIP, pos, ip); pimpl->Parallel(&Module::setReceiverStreamingIP, pos, ip, rx_index);
if (previouslyReceiverStreaming) { if (previouslyReceiverStreaming) {
setRxZmqDataStream(false, pos); setRxZmqDataStream(false, pos);
setRxZmqDataStream(true, pos); setRxZmqDataStream(true, pos);
@ -1478,6 +1552,14 @@ void Detector::setDataStream(const defs::portPosition port, const bool enable,
pimpl->Parallel(&Module::setDataStream, pos, port, enable); pimpl->Parallel(&Module::setDataStream, pos, port, enable);
} }
Result<bool> Detector::getTop(Positions pos) const {
return pimpl->Parallel(&Module::getTop, pos);
}
void Detector::setTop(bool value, Positions pos) {
pimpl->Parallel(&Module::setTop, pos, value);
}
// Jungfrau Specific // Jungfrau Specific
Result<double> Detector::getChipVersion(Positions pos) const { Result<double> Detector::getChipVersion(Positions pos) const {
return pimpl->Parallel(&Module::getChipVersion, pos); return pimpl->Parallel(&Module::getChipVersion, pos);
@ -1553,7 +1635,6 @@ std::vector<defs::gainMode> Detector::getGainModeList() const {
return std::vector<defs::gainMode>{ return std::vector<defs::gainMode>{
defs::DYNAMIC, defs::FORCE_SWITCH_G1, defs::FORCE_SWITCH_G2, defs::DYNAMIC, defs::FORCE_SWITCH_G1, defs::FORCE_SWITCH_G2,
defs::FIX_G1, defs::FIX_G2, defs::FIX_G0}; defs::FIX_G1, defs::FIX_G2, defs::FIX_G0};
break;
default: default:
throw RuntimeError("Gain mode is not implemented for this detector."); throw RuntimeError("Gain mode is not implemented for this detector.");
} }
@ -1798,10 +1879,6 @@ Detector::getGateDelayForAllGates(Positions pos) const {
return pimpl->Parallel(&Module::getGateDelayForAllGates, pos); return pimpl->Parallel(&Module::getGateDelayForAllGates, pos);
} }
Result<bool> Detector::getMaster(Positions pos) const {
return pimpl->Parallel(&Module::isMaster, pos);
}
Result<int> Detector::getChipStatusRegister(Positions pos) const { Result<int> Detector::getChipStatusRegister(Positions pos) const {
return pimpl->Parallel(&Module::getChipStatusRegister, pos); return pimpl->Parallel(&Module::getChipStatusRegister, pos);
} }

File diff suppressed because it is too large Load Diff

View File

@ -17,10 +17,15 @@
class ServerInterface; class ServerInterface;
#define MODULE_SHMAPIVERSION 0x190726 #define MODULE_SHMAPIVERSION 0x190726
#define MODULE_SHMVERSION 0x200402 #define MODULE_SHMVERSION 0x210913
namespace sls { namespace sls {
struct sharedReceiver {
char hostname[MAX_STR_LENGTH]{};
int tcpPort{};
};
/** /**
* @short structure allocated in shared memory to store Module settings for * @short structure allocated in shared memory to store Module settings for
* IPC and cache * IPC and cache
@ -45,8 +50,11 @@ struct sharedModule {
slsDetectorDefs::xy nChan; slsDetectorDefs::xy nChan;
slsDetectorDefs::xy nChip; slsDetectorDefs::xy nChip;
int nDacs; int nDacs;
char rxHostname[MAX_STR_LENGTH];
int rxTCPPort; /** receiver details for each module */
int numReceivers;
sharedReceiver receivers[MAX_UDP_DESTINATION];
/** if rxHostname and rxTCPPort can be connected to */ /** if rxHostname and rxTCPPort can be connected to */
bool useReceiverFlag; bool useReceiverFlag;
/** Listening tcp port from gui (only data) */ /** Listening tcp port from gui (only data) */
@ -120,6 +128,9 @@ class Module : public virtual slsDetectorDefs {
int setTrimEn(const std::vector<int> &energies = {}); int setTrimEn(const std::vector<int> &energies = {});
bool getFlipRows() const; bool getFlipRows() const;
void setFlipRows(bool value); void setFlipRows(bool value);
bool isMaster() const;
void setMaster(const bool master);
bool isVirtualDetectorServer() const; bool isVirtualDetectorServer() const;
/************************************************** /**************************************************
@ -184,6 +195,7 @@ class Module : public virtual slsDetectorDefs {
void setDBITPipeline(int value); void setDBITPipeline(int value);
int getReadNRows() const; int getReadNRows() const;
void setReadNRows(const int value); void setReadNRows(const int value);
/************************************************** /**************************************************
* * * *
* Acquisition * * Acquisition *
@ -200,7 +212,7 @@ class Module : public virtual slsDetectorDefs {
runStatus getReceiverStatus() const; runStatus getReceiverStatus() const;
double getReceiverProgress() const; double getReceiverProgress() const;
int64_t getFramesCaughtByReceiver() const; int64_t getFramesCaughtByReceiver() const;
std::vector<uint64_t> getNumMissingPackets() const; std::vector<int64_t> getNumMissingPackets() const;
uint64_t getNextFrameNumber() const; uint64_t getNextFrameNumber() const;
void setNextFrameNumber(uint64_t value); void setNextFrameNumber(uint64_t value);
void sendSoftwareTrigger(const bool block); void sendSoftwareTrigger(const bool block);
@ -232,21 +244,21 @@ class Module : public virtual slsDetectorDefs {
void clearUDPDestinations(); void clearUDPDestinations();
int getFirstUDPDestination() const; int getFirstUDPDestination() const;
void setFirstUDPDestination(const int value); void setFirstUDPDestination(const int value);
sls::IpAddr getDestinationUDPIP() const; sls::IpAddr getDestinationUDPIP(const int rxIndex) const;
void setDestinationUDPIP(const sls::IpAddr ip); void setDestinationUDPIP(const sls::IpAddr ip, const int rxIndex);
sls::IpAddr getDestinationUDPIP2() const; sls::IpAddr getDestinationUDPIP2(const int rxIndex) const;
void setDestinationUDPIP2(const sls::IpAddr ip); void setDestinationUDPIP2(const sls::IpAddr ip, const int rxIndex);
sls::MacAddr getDestinationUDPMAC() const; sls::MacAddr getDestinationUDPMAC(const int rxIndex) const;
void setDestinationUDPMAC(const sls::MacAddr mac); void setDestinationUDPMAC(const sls::MacAddr mac, const int rxIndex);
sls::MacAddr getDestinationUDPMAC2() const; sls::MacAddr getDestinationUDPMAC2(const int rxIndex) const;
void setDestinationUDPMAC2(const sls::MacAddr mac); void setDestinationUDPMAC2(const sls::MacAddr mac, const int rxIndex);
int getDestinationUDPPort() const; int getDestinationUDPPort(const int rxIndex) const;
void setDestinationUDPPort(int udpport); void setDestinationUDPPort(int udpport, const int rxIndex);
int getDestinationUDPPort2() const; int getDestinationUDPPort2(const int rxIndex) const;
void setDestinationUDPPort2(int udpport); void setDestinationUDPPort2(int udpport, const int rxIndex);
void reconfigureUDPDestination(); void reconfigureUDPDestination();
void validateUDPConfiguration(); void validateUDPConfiguration();
std::string printReceiverConfiguration(); std::string printReceiverConfiguration(const int rxIndex);
bool getTenGiga() const; bool getTenGiga() const;
void setTenGiga(bool value); void setTenGiga(bool value);
bool getTenGigaFlowControl() const; bool getTenGigaFlowControl() const;
@ -264,10 +276,11 @@ class Module : public virtual slsDetectorDefs {
* * * *
* ************************************************/ * ************************************************/
bool getUseReceiverFlag() const; bool getUseReceiverFlag() const;
std::string getReceiverHostname() const; std::string getReceiverHostname(const int rxIndex) const;
void setReceiverHostname(const std::string &receiver); void setAllReceiverHostnames(const std::vector<std::string> &receiver);
int getReceiverPort() const; void setReceiverHostname(const std::string &receiver, const int rxIndex);
int setReceiverPort(int port_number); int getReceiverPort(const int rxIndex) const;
void setReceiverPort(int port_number, const int rxIndex);
int getReceiverFifoDepth() const; int getReceiverFifoDepth() const;
void setReceiverFifoDepth(int n_frames); void setReceiverFifoDepth(int n_frames);
bool getReceiverSilentMode() const; bool getReceiverSilentMode() const;
@ -283,6 +296,8 @@ class Module : public virtual slsDetectorDefs {
void setReceiverLock(bool lock); void setReceiverLock(bool lock);
sls::IpAddr getReceiverLastClientIP() const; sls::IpAddr getReceiverLastClientIP() const;
std::array<pid_t, NUM_RX_THREAD_IDS> getReceiverThreadIds() const; std::array<pid_t, NUM_RX_THREAD_IDS> getReceiverThreadIds() const;
bool getRxArping() const;
void setRxArping(bool enable);
/************************************************** /**************************************************
* * * *
@ -324,8 +339,8 @@ class Module : public virtual slsDetectorDefs {
void setReceiverStreamingStartingFrame(int fnum); void setReceiverStreamingStartingFrame(int fnum);
int getReceiverStreamingPort() const; int getReceiverStreamingPort() const;
void setReceiverStreamingPort(int port); void setReceiverStreamingPort(int port);
sls::IpAddr getReceiverStreamingIP() const; sls::IpAddr getReceiverStreamingIP(const int rxIndex) const;
void setReceiverStreamingIP(const sls::IpAddr ip); void setReceiverStreamingIP(const sls::IpAddr ip, const int rxIndex);
int getClientStreamingPort() const; int getClientStreamingPort() const;
void setClientStreamingPort(int port); void setClientStreamingPort(int port);
sls::IpAddr getClientStreamingIP() const; sls::IpAddr getClientStreamingIP() const;
@ -363,6 +378,8 @@ class Module : public virtual slsDetectorDefs {
void setQuad(const bool enable); void setQuad(const bool enable);
bool getDataStream(const portPosition port) const; bool getDataStream(const portPosition port) const;
void setDataStream(const portPosition port, const bool enable); void setDataStream(const portPosition port, const bool enable);
bool getTop() const;
void setTop(bool value);
/************************************************** /**************************************************
* * * *
@ -454,7 +471,6 @@ class Module : public virtual slsDetectorDefs {
int64_t getGateDelay(int gateIndex) const; int64_t getGateDelay(int gateIndex) const;
void setGateDelay(int gateIndex, int64_t value); void setGateDelay(int gateIndex, int64_t value);
std::array<time::ns, 3> getGateDelayForAllGates() const; std::array<time::ns, 3> getGateDelayForAllGates() const;
bool isMaster() const;
int getChipStatusRegister() const; int getChipStatusRegister() const;
void setGainCaps(int caps); void setGainCaps(int caps);
int getGainCaps(); int getGainCaps();
@ -664,43 +680,52 @@ class Module : public virtual slsDetectorDefs {
Ret sendToDetectorStop(int fnum, const Arg &args) const; Ret sendToDetectorStop(int fnum, const Arg &args) const;
/** Send function parameters to receiver */ /** Send function parameters to receiver */
void sendToReceiver(int fnum, const void *args, size_t args_size, std::vector<int> getEntryList(const int rxIndex) const;
void *retval, size_t retval_size); void sendToReceiver(const int rxIndex, int fnum, const void *args,
size_t args_size, void *retval, size_t retval_size);
void sendToReceiver(int fnum, const void *args, size_t args_size, void sendToReceiver(const int rxIndex, int fnum, const void *args,
void *retval, size_t retval_size) const; size_t args_size, void *retval,
size_t retval_size) const;
template <typename Arg, typename Ret> template <typename Arg, typename Ret>
void sendToReceiver(int fnum, const Arg &args, Ret &retval); void sendToReceiver(const int rxIndex, int fnum, const Arg &args,
Ret &retval);
template <typename Arg, typename Ret> template <typename Arg, typename Ret>
void sendToReceiver(int fnum, const Arg &args, Ret &retval) const; void sendToReceiver(const int rxIndex, int fnum, const Arg &args,
Ret &retval) const;
template <typename Arg> template <typename Arg>
void sendToReceiver(int fnum, const Arg &args, std::nullptr_t); void sendToReceiver(const int rxIndex, int fnum, const Arg &args,
std::nullptr_t);
template <typename Arg> template <typename Arg>
void sendToReceiver(int fnum, const Arg &args, std::nullptr_t) const; void sendToReceiver(const int rxIndex, int fnum, const Arg &args,
std::nullptr_t) const;
template <typename Ret> template <typename Ret>
void sendToReceiver(int fnum, std::nullptr_t, Ret &retval); void sendToReceiver(const int rxIndex, int fnum, std::nullptr_t,
Ret &retval);
template <typename Ret> template <typename Ret>
void sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const; void sendToReceiver(const int rxIndex, int fnum, std::nullptr_t,
Ret &retval) const;
template <typename Ret> Ret sendToReceiver(int fnum); template <typename Ret> Ret sendToReceiver(const int rxIndex, int fnum);
template <typename Ret> Ret sendToReceiver(int fnum) const; template <typename Ret>
Ret sendToReceiver(const int rxIndex, int fnum) const;
void sendToReceiver(int fnum); void sendToReceiver(const int rxIndex, int fnum);
void sendToReceiver(int fnum) const; void sendToReceiver(const int rxIndex, int fnum) const;
template <typename Ret, typename Arg> template <typename Ret, typename Arg>
Ret sendToReceiver(int fnum, const Arg &args); Ret sendToReceiver(const int rxIndex, int fnum, const Arg &args);
template <typename Ret, typename Arg> template <typename Ret, typename Arg>
Ret sendToReceiver(int fnum, const Arg &args) const; Ret sendToReceiver(const int rxIndex, int fnum, const Arg &args) const;
/** Get Detector Type from Shared Memory /** Get Detector Type from Shared Memory
verify is if shm size matches existing one */ verify is if shm size matches existing one */
@ -718,7 +743,7 @@ class Module : public virtual slsDetectorDefs {
void checkReceiverVersionCompatibility(); void checkReceiverVersionCompatibility();
void setModule(sls_detector_module &module, bool trimbits = true); void setModule(sls_detector_module &module, bool trimbits = true);
int sendModule(sls_detector_module *myMod, sls::ClientSocket &client); int sendModule(sls_detector_module *myMod, sls::ClientSocket &client);
void updateReceiverStreamingIP(); void updateReceiverStreamingIP(const int rxIndex);
void updateRateCorrection(); void updateRateCorrection();
/** Template function to do linear interpolation between two points (Eiger /** Template function to do linear interpolation between two points (Eiger

View File

@ -629,4 +629,32 @@ TEST_CASE("datastream", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("datastream", {"1"}, -1, PUT)); REQUIRE_THROWS(proxy.Call("datastream", {"1"}, -1, PUT));
REQUIRE_THROWS(proxy.Call("datastream", {"left", "1"}, -1, PUT)); REQUIRE_THROWS(proxy.Call("datastream", {"left", "1"}, -1, PUT));
} }
}
TEST_CASE("top", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER) {
auto prev_val = det.getTop();
int numModulesTested = 1;
if (det.size() > 1) {
numModulesTested = 2;
}
for (int i = 0; i != numModulesTested; ++i) {
std::ostringstream oss1, oss2, oss3;
proxy.Call("top", {"1"}, i, PUT, oss1);
REQUIRE(oss1.str() == "top 1\n");
proxy.Call("top", {}, i, GET, oss2);
REQUIRE(oss2.str() == "top 1\n");
proxy.Call("top", {"0"}, i, PUT, oss3);
REQUIRE(oss3.str() == "top 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setTop(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("top", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("top", {"1"}, -1, PUT));
}
} }

View File

@ -385,6 +385,30 @@ TEST_CASE("rx_threads", "[.cmd][.rx]") {
REQUIRE_NOTHROW(proxy.Call("rx_threads", {}, -1, GET, oss)); REQUIRE_NOTHROW(proxy.Call("rx_threads", {}, -1, GET, oss));
} }
TEST_CASE("rx_arping", "[.cmd][.rx]") {
Detector det;
CmdProxy proxy(&det);
auto prev_val = det.getRxArping();
{
std::ostringstream oss;
proxy.Call("rx_arping", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "rx_arping 1\n");
}
{
std::ostringstream oss;
proxy.Call("rx_arping", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_arping 1\n");
}
{
std::ostringstream oss;
proxy.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});
}
}
/* File */ /* File */
TEST_CASE("fformat", "[.cmd]") { TEST_CASE("fformat", "[.cmd]") {

View File

@ -570,6 +570,46 @@ TEST_CASE("fliprows", "[.cmd]") {
} }
} }
TEST_CASE("master", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER || det_type == defs::MYTHEN3 || det_type == defs::GOTTHARD || det_type == defs::GOTTHARD2) {
REQUIRE_NOTHROW(proxy.Call("master", {}, -1, GET));
if (det_type == defs::EIGER) {
// get previous master
int prevMaster = 0;
{
auto previous = det.getMaster();
for (int i = 0; i != det.size(); ++i) {
if (previous[i] == 1) {
prevMaster = i;
break;
}
}
}
{
std::ostringstream oss1;
proxy.Call("master", {"0"}, 0, PUT, oss3);
REQUIRE(oss3.str() == "master 0\n");
}
{
std::ostringstream oss1;
proxy.Call("master", {"1"}, 0, PUT, oss3);
REQUIRE(oss3.str() == "master 1\n");
}
REQUIRE_THROWS(proxy.Call("master", {"1"}, -1, PUT));
// set all to slaves, and then master
for (int i = 0; i != det.size(); ++i) {
det.setMaster(0, {i});
}
det.setMaster(1, prevMaster);
}
} else {
REQUIRE_THROWS(proxy.Call("master", {}, -1, GET));
}
}
/* acquisition parameters */ /* acquisition parameters */
// acquire: not testing // acquire: not testing
@ -2126,6 +2166,41 @@ TEST_CASE("nextframenumber", "[.cmd]") {
proxy.Call("nextframenumber", {"1"}, -1, PUT, oss); proxy.Call("nextframenumber", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "nextframenumber 1\n"); REQUIRE(oss.str() == "nextframenumber 1\n");
} }
auto prev_timing =
det.getTimingMode().tsquash("inconsistent timing mode in test");
auto prev_frames =
det.getNumberOfFrames().tsquash("inconsistent #frames in test");
auto prev_exptime =
det.getExptime().tsquash("inconsistent exptime in test");
auto prev_period =
det.getPeriod().tsquash("inconsistent period in test");
det.setTimingMode(defs::AUTO_TIMING);
det.setNumberOfFrames(1);
det.setExptime(std::chrono::microseconds(200));
det.setPeriod(std::chrono::milliseconds(1));
det.startDetector();
std::this_thread::sleep_for(std::chrono::seconds(2));
auto currentfnum =
det.getNextFrameNumber().tsquash("inconsistent frame nr in test");
REQUIRE(currentfnum == 2);
if (det_type == defs::EIGER) {
auto prev_tengiga =
det.getTenGiga().tsquash("inconsistent ten giga enable");
det.setTenGiga(true);
det.setNextFrameNumber(1);
det.startDetector();
std::this_thread::sleep_for(std::chrono::seconds(2));
auto currentfnum = det.getNextFrameNumber().tsquash(
"inconsistent frame nr in test");
REQUIRE(currentfnum == 2);
det.setTenGiga(prev_tengiga);
}
det.setTimingMode(prev_timing);
det.setNumberOfFrames(prev_frames);
det.setExptime(prev_exptime);
det.setPeriod(prev_period);
for (int i = 0; i != det.size(); ++i) { for (int i = 0; i != det.size(); ++i) {
det.setNextFrameNumber(prev_sfnum[i], {i}); det.setNextFrameNumber(prev_sfnum[i], {i});
} }

View File

@ -12,6 +12,8 @@ set(SOURCES
src/DataProcessor.cpp src/DataProcessor.cpp
src/DataStreamer.cpp src/DataStreamer.cpp
src/Fifo.cpp src/Fifo.cpp
src/Arping.cpp
src/MasterAttributes.cpp
) )
set(PUBLICHEADERS set(PUBLICHEADERS

View File

@ -0,0 +1,120 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Arping.h"
#include <chrono>
#include <unistd.h>
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif
void Arping::SetInterfacesAndIps(const int index, const std::string &interface,
const std::string &ip) {
if (interface.empty() || ip.empty()) {
throw sls::RuntimeError("Could not arping. Interface name and ip not "
"set up for interface " +
std::to_string(index));
}
// create commands to arping
std::ostringstream os;
os << "arping -c 1 -U -I " << interface << " " << ip;
// to read error messages
os << " 2>&1";
std::string cmd = os.str();
commands[index] = cmd;
}
pid_t Arping::GetThreadId() const { return threadId; }
bool Arping::IsRunning() const { return runningFlag; }
void Arping::StartThread() {
TestCommands();
try {
t = std::thread(&Arping::ThreadExecution, this);
} catch (...) {
throw sls::RuntimeError("Could not start arping thread");
}
runningFlag = true;
}
void Arping::StopThread() {
runningFlag = false;
t.join();
}
void Arping::ThreadExecution() {
threadId = gettid();
LOG(logINFOBLUE) << "Created [ Arping Thread, Tid: " << threadId << " ]";
while (runningFlag) {
std::string error = ExecuteCommands();
// just print (was already tested at thread start)
if (!error.empty()) {
LOG(logERROR) << error;
}
// wait for 60s as long as thread not killed
int nsecs = 0;
while (runningFlag && nsecs != 60) {
std::this_thread::sleep_for(std::chrono::seconds(1));
++nsecs;
}
}
LOG(logINFOBLUE) << "Exiting [ Arping Thread, Tid: " << threadId << " ]";
threadId = 0;
}
void Arping::TestCommands() {
// atleast one interface must be set up
if (commands[0].empty()) {
throw sls::RuntimeError(
"Could not arping. Interface not set up in apring thread");
}
// test if arping commands throw an error
std::string error = ExecuteCommands();
if (!error.empty()) {
throw sls::RuntimeError(error);
}
}
std::string Arping::ExecuteCommands() {
for (auto cmd : commands) {
// empty if 2nd interface not enabled
if (cmd.empty())
continue;
LOG(logDEBUG) << "Executing Arping Command: " << cmd;
// execute command
FILE *sysFile = popen(cmd.c_str(), "r");
if (sysFile == NULL) {
std::ostringstream os;
os << "Could not Arping [" << cmd << " ] : Popen fail";
return os.str();
}
// copy output
char output[MAX_STR_LENGTH] = {0};
fgets(output, sizeof(output), sysFile);
output[sizeof(output) - 1] = '\0';
// check exit status of command
if (pclose(sysFile)) {
std::ostringstream os;
os << "Could not arping[" << cmd << "] : " << output;
return os.str();
} else {
LOG(logDEBUG) << output;
}
}
return std::string();
}

View File

@ -0,0 +1,35 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
/**
*@short creates/destroys an ARPing thread to arping the interfaces slsReceiver
is listening to.
*/
#include "receiver_defs.h"
#include "sls/logger.h"
#include <atomic>
#include <thread>
class Arping {
public:
void SetInterfacesAndIps(const int index, const std::string &interface,
const std::string &ip);
pid_t GetThreadId() const;
bool IsRunning() const;
void StartThread();
void StopThread();
private:
void TestCommands();
std::string ExecuteCommands();
void ThreadExecution();
std::vector<std::string> commands =
std::vector<std::string>(MAX_NUMBER_OF_LISTENING_THREADS);
std::atomic<bool> runningFlag{false};
std::thread t;
std::atomic<pid_t> threadId{0};
};

View File

@ -19,7 +19,6 @@
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
#include <vector> #include <vector>
@ -28,6 +27,12 @@ using sls::RuntimeError;
using sls::SocketError; using sls::SocketError;
using Interface = sls::ServerInterface; using Interface = sls::ServerInterface;
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif
ClientInterface::~ClientInterface() { ClientInterface::~ClientInterface() {
killTcpThread = true; killTcpThread = true;
LOG(logINFO) << "Shutting down TCP Socket on port " << portNumber; LOG(logINFO) << "Shutting down TCP Socket on port " << portNumber;
@ -41,7 +46,7 @@ ClientInterface::ClientInterface(int portNumber)
portNumber(portNumber > 0 ? portNumber : DEFAULT_PORTNO + 2), portNumber(portNumber > 0 ? portNumber : DEFAULT_PORTNO + 2),
server(portNumber) { server(portNumber) {
functionTable(); functionTable();
parentThreadId = syscall(SYS_gettid); parentThreadId = gettid();
tcpThread = tcpThread =
sls::make_unique<std::thread>(&ClientInterface::startTCPServer, this); sls::make_unique<std::thread>(&ClientInterface::startTCPServer, this);
} }
@ -76,7 +81,7 @@ void ClientInterface::registerCallBackRawDataModifyReady(
} }
void ClientInterface::startTCPServer() { void ClientInterface::startTCPServer() {
tcpThreadId = syscall(SYS_gettid); tcpThreadId = gettid();
LOG(logINFOBLUE) << "Created [ TCP server Tid: " << tcpThreadId << "]"; LOG(logINFOBLUE) << "Created [ TCP server Tid: " << tcpThreadId << "]";
LOG(logINFO) << "SLS Receiver starting TCP Server on port " << portNumber LOG(logINFO) << "SLS Receiver starting TCP Server on port " << portNumber
<< '\n'; << '\n';
@ -210,7 +215,8 @@ int ClientInterface::functionTable(){
flist[F_SET_RECEIVER_STREAMING_HWM] = &ClientInterface::set_streaming_hwm; flist[F_SET_RECEIVER_STREAMING_HWM] = &ClientInterface::set_streaming_hwm;
flist[F_RECEIVER_SET_ALL_THRESHOLD] = &ClientInterface::set_all_threshold; flist[F_RECEIVER_SET_ALL_THRESHOLD] = &ClientInterface::set_all_threshold;
flist[F_RECEIVER_SET_DATASTREAM] = &ClientInterface::set_detector_datastream; flist[F_RECEIVER_SET_DATASTREAM] = &ClientInterface::set_detector_datastream;
flist[F_GET_RECEIVER_ARPING] = &ClientInterface::get_arping;
flist[F_SET_RECEIVER_ARPING] = &ClientInterface::set_arping;
for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) { for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) {
LOG(logDEBUG1) << "function fnum: " << i << " (" << LOG(logDEBUG1) << "function fnum: " << i << " (" <<
@ -710,6 +716,7 @@ int ClientInterface::set_dynamic_range(Interface &socket) {
break; break;
*/ */
case 4: case 4:
case 12:
if (detType == EIGER) { if (detType == EIGER) {
exists = true; exists = true;
} }
@ -1398,9 +1405,13 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) {
if (detType == EIGER) { if (detType == EIGER) {
impl()->setEthernetInterface2(eth); impl()->setEthernetInterface2(eth);
} }
// update locally to use for arping
udpips[0] = arg.str();
// get mac address // get mac address
auto retval = sls::InterfaceNameToMac(eth); auto retval = sls::InterfaceNameToMac(eth);
if (retval == 0) { if (retval == 0 && arg.str() != LOCALHOST_IP) {
throw RuntimeError("Failed to get udp mac adddress to listen to (eth:" + throw RuntimeError("Failed to get udp mac adddress to listen to (eth:" +
eth + ", ip:" + arg.str() + ")\n"); eth + ", ip:" + arg.str() + ")\n");
} }
@ -1430,9 +1441,12 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) {
} }
impl()->setEthernetInterface2(eth); impl()->setEthernetInterface2(eth);
// update locally to use for arping
udpips[1] = arg.str();
// get mac address // get mac address
auto retval = sls::InterfaceNameToMac(eth); auto retval = sls::InterfaceNameToMac(eth);
if (retval == 0) { if (retval == 0 && arg.str() != LOCALHOST_IP) {
throw RuntimeError( throw RuntimeError(
"Failed to get udp mac adddress2 to listen to (eth:" + eth + "Failed to get udp mac adddress2 to listen to (eth:" + eth +
", ip:" + arg.str() + ")\n"); ", ip:" + arg.str() + ")\n");
@ -1697,3 +1711,20 @@ int ClientInterface::set_detector_datastream(Interface &socket) {
impl()->setDetectorDataStream(port, enable); impl()->setDetectorDataStream(port, enable);
return socket.Send(OK); return socket.Send(OK);
} }
int ClientInterface::get_arping(Interface &socket) {
auto retval = static_cast<int>(impl()->getArping());
LOG(logDEBUG1) << "arping thread status:" << retval;
return socket.sendResult(retval);
}
int ClientInterface::set_arping(Interface &socket) {
auto value = socket.Receive<int>();
if (value < 0) {
throw RuntimeError("Invalid arping value: " + std::to_string(value));
}
verifyIdle(socket);
LOG(logDEBUG1) << "Starting/ Killing arping thread:" << value;
impl()->setArping(value, udpips);
return socket.Send(OK);
}

View File

@ -163,6 +163,8 @@ class ClientInterface : private virtual slsDetectorDefs {
int set_streaming_hwm(sls::ServerInterface &socket); int set_streaming_hwm(sls::ServerInterface &socket);
int set_all_threshold(sls::ServerInterface &socket); int set_all_threshold(sls::ServerInterface &socket);
int set_detector_datastream(sls::ServerInterface &socket); int set_detector_datastream(sls::ServerInterface &socket);
int get_arping(sls::ServerInterface &socket);
int set_arping(sls::ServerInterface &socket);
Implementation *impl() { Implementation *impl() {
if (receiver != nullptr) { if (receiver != nullptr) {
@ -190,4 +192,6 @@ class ClientInterface : private virtual slsDetectorDefs {
pid_t parentThreadId{0}; pid_t parentThreadId{0};
pid_t tcpThreadId{0}; pid_t tcpThreadId{0};
std::vector<std::string> udpips =
std::vector<std::string>(MAX_NUMBER_OF_LISTENING_THREADS);
}; };

View File

@ -112,6 +112,7 @@ void HDF5DataFile::CreateFirstHDF5DataFile(
udpPortNumber_ = udpPortNumber; udpPortNumber_ = udpPortNumber;
switch (dynamicRange_) { switch (dynamicRange_) {
case 12:
case 16: case 16:
dataType_ = PredType::STD_U16LE; dataType_ = PredType::STD_U16LE;
break; break;
@ -248,8 +249,30 @@ void HDF5DataFile::WriteToFile(char *buffer, const int buffersize,
WriteParameterDatasets(currentFrameNumber, (sls_receiver_header *)(buffer)); WriteParameterDatasets(currentFrameNumber, (sls_receiver_header *)(buffer));
} }
void HDF5DataFile::Convert12to16Bit(uint16_t *dst, uint8_t *src) {
for (int i = 0; i < EIGER_NUM_PIXELS; ++i) {
*dst = (uint16_t)(*src++ & 0xFF);
*dst++ |= (uint16_t)((*src & 0xF) << 8u);
++i;
*dst = (uint16_t)((*src++ & 0xF0) >> 4u);
*dst++ |= (uint16_t)((*src++ & 0xFF) << 4u);
}
}
void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber, void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber,
char *buffer) { char *buffer) {
// expand 12 bit to 16 bits
char *revBuffer = buffer;
if (dynamicRange_ == 12) {
revBuffer = (char *)malloc(EIGER_16_BIT_IMAGE_SIZE);
if (revBuffer == nullptr) {
throw sls::RuntimeError("Could not allocate memory for 12 bit to "
"16 bit conversion in object " +
std::to_string(index_));
}
Convert12to16Bit((uint16_t *)revBuffer, (uint8_t *)buffer);
}
std::lock_guard<std::mutex> lock(*hdf5Lib_); std::lock_guard<std::mutex> lock(*hdf5Lib_);
uint64_t nDimx = uint64_t nDimx =
@ -266,9 +289,15 @@ void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber,
dataSpace_->selectHyperslab(H5S_SELECT_SET, count, start); dataSpace_->selectHyperslab(H5S_SELECT_SET, count, start);
DataSpace memspace(2, dims2); DataSpace memspace(2, dims2);
dataSet_->write(buffer, dataType_, memspace, *dataSpace_); dataSet_->write(revBuffer, dataType_, memspace, *dataSpace_);
memspace.close(); memspace.close();
if (dynamicRange_ == 12) {
free(revBuffer);
}
} catch (const Exception &error) { } catch (const Exception &error) {
if (dynamicRange_ == 12) {
free(revBuffer);
}
LOG(logERROR) << "Could not write to file in object " << index_; LOG(logERROR) << "Could not write to file in object " << index_;
error.printErrorStack(); error.printErrorStack();
throw sls::RuntimeError("Could not write to file in object " + throw sls::RuntimeError("Could not write to file in object " +

View File

@ -35,6 +35,7 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
private: private:
void CreateFile(); void CreateFile();
void Convert12to16Bit(uint16_t *dst, uint8_t *src);
void WriteDataFile(const uint64_t currentFrameNumber, char *buffer); void WriteDataFile(const uint64_t currentFrameNumber, char *buffer);
void WriteParameterDatasets(const uint64_t currentFrameNumber, void WriteParameterDatasets(const uint64_t currentFrameNumber,
sls_receiver_header *rheader); sls_receiver_header *rheader);
@ -72,4 +73,7 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
int detIndex_{0}; int detIndex_{0};
int numUnitsPerReadout_{0}; int numUnitsPerReadout_{0};
uint32_t udpPortNumber_{0}; uint32_t udpPortNumber_{0};
static const int EIGER_NUM_PIXELS{256 * 2 * 256};
static const int EIGER_16_BIT_IMAGE_SIZE{EIGER_NUM_PIXELS * 2};
}; };

View File

@ -107,6 +107,7 @@ void Implementation::SetupFifoStructure() {
* ************************************************/ * ************************************************/
void Implementation::setDetectorType(const detectorType d) { void Implementation::setDetectorType(const detectorType d) {
detType = d; detType = d;
switch (detType) { switch (detType) {
case GOTTHARD: case GOTTHARD:
@ -320,9 +321,33 @@ std::array<pid_t, NUM_RX_THREAD_IDS> Implementation::getThreadIds() const {
retval[id++] = 0; retval[id++] = 0;
} }
} }
retval[NUM_RX_THREAD_IDS - 1] = arping.GetThreadId();
return retval; return retval;
} }
bool Implementation::getArping() const { return arping.IsRunning(); }
pid_t Implementation::getArpingThreadId() const { return arping.GetThreadId(); }
void Implementation::setArping(const bool i,
const std::vector<std::string> ips) {
if (i != arping.IsRunning()) {
if (!i) {
arping.StopThread();
} else {
// setup interface
for (int i = 0; i != numUDPInterfaces; ++i) {
// ignore eiger with 2 interfaces (only udp port)
if (i == 1 && (numUDPInterfaces == 1 || detType == EIGER)) {
break;
}
arping.SetInterfacesAndIps(i, eth[i], ips[i]);
}
arping.StartThread();
}
}
}
/************************************************** /**************************************************
* * * *
* File Parameters * * File Parameters *
@ -610,25 +635,25 @@ void Implementation::stopReceiver() {
std::to_string(std::abs(mp[i])) + std::string(" (Extra)"); std::to_string(std::abs(mp[i])) + std::string(" (Extra)");
} }
std::string summary;
if (!activated) {
summary = "\n\tDeactivated Receiver";
} else if (!detectorDataStream[i]) {
summary = (i == 0 ? "\n\tDeactivated Left Port"
: "\n\tDeactivated Right Port");
} else {
std::ostringstream os;
os << "\n\tMissing Packets\t\t: " << mpMessage
<< "\n\tComplete Frames\t\t: " << nf
<< "\n\tLast Frame Caught\t: "
<< listener[i]->GetLastFrameIndexCaught();
summary = os.str();
}
TLogLevel lev = ((mp[i]) > 0) ? logINFORED : logINFOGREEN; TLogLevel lev = ((mp[i]) > 0) ? logINFORED : logINFOGREEN;
LOG(lev) << LOG(lev) << "Summary of Port " << udpPortNum[i] << summary;
// udp port number could be the second if selected interface is
// 2 for jungfrau
"Summary of Port " << udpPortNum[i]
<< "\n\tMissing Packets\t\t: " << mpMessage
<< "\n\tComplete Frames\t\t: " << nf
<< "\n\tLast Frame Caught\t: "
<< listener[i]->GetLastFrameIndexCaught();
}
if (!activated) {
LOG(logINFORED) << "Deactivated Receiver";
}
if (!detectorDataStream[0]) {
LOG(logINFORED) << "Deactivated Left Port";
}
if (!detectorDataStream[1]) {
LOG(logINFORED) << "Deactivated Right Port";
} }
// callback // callback
if (acquisitionFinishedCallBack) { if (acquisitionFinishedCallBack) {
try { try {
@ -759,6 +784,12 @@ void Implementation::SetupWriter() {
} }
masterAttributes->detType = detType; masterAttributes->detType = detType;
masterAttributes->timingMode = timingMode; masterAttributes->timingMode = timingMode;
xy nm{numModules.x, numModules.y};
if (quadEnable) {
nm.x = 1;
nm.y = 2;
}
masterAttributes->geometry = xy(nm.x, nm.y);
masterAttributes->imageSize = generalData->imageSize; masterAttributes->imageSize = generalData->imageSize;
masterAttributes->nPixels = masterAttributes->nPixels =
xy(generalData->nPixelsX, generalData->nPixelsY); xy(generalData->nPixelsX, generalData->nPixelsY);
@ -1441,6 +1472,21 @@ void Implementation::setTenGigaEnable(const bool b) {
generalData->SetTenGigaEnable(b); generalData->SetTenGigaEnable(b);
SetupFifoStructure(); SetupFifoStructure();
// datastream can be disabled/enabled only for Eiger 10GbE
if (detType == EIGER) {
if (!b) {
detectorDataStream[LEFT] = 1;
detectorDataStream[RIGHT] = 1;
} else {
detectorDataStream[LEFT] = detectorDataStream10GbE[LEFT];
detectorDataStream[RIGHT] = detectorDataStream10GbE[RIGHT];
}
LOG(logDEBUG) << "Detector datastream updated [Left: "
<< sls::ToString(detectorDataStream[LEFT])
<< ", Right: "
<< sls::ToString(detectorDataStream[RIGHT]) << "]";
}
} }
LOG(logINFO) << "Ten Giga: " << (tengigaEnable ? "enabled" : "disabled"); LOG(logINFO) << "Ten Giga: " << (tengigaEnable ? "enabled" : "disabled");
LOG(logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); LOG(logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame);
@ -1507,9 +1553,16 @@ bool Implementation::getDetectorDataStream(const portPosition port) const {
void Implementation::setDetectorDataStream(const portPosition port, void Implementation::setDetectorDataStream(const portPosition port,
const bool enable) { const bool enable) {
int index = (port == LEFT ? 0 : 1); int index = (port == LEFT ? 0 : 1);
detectorDataStream[index] = enable; detectorDataStream10GbE[index] = enable;
LOG(logINFO) << "Detector datastream (" << sls::ToString(port) LOG(logINFO) << "Detector 10GbE datastream (" << sls::ToString(port)
<< " Port): " << sls::ToString(detectorDataStream[index]); << " Port): " << sls::ToString(detectorDataStream10GbE[index]);
// update datastream for 10g
if (tengigaEnable) {
detectorDataStream[index] = detectorDataStream10GbE[index];
LOG(logDEBUG) << "Detector datastream updated ["
<< (index == 0 ? "Left" : "Right")
<< "] : " << sls::ToString(detectorDataStream[index]);
}
} }
int Implementation::getReadNRows() const { return readNRows; } int Implementation::getReadNRows() const { return readNRows; }

View File

@ -1,6 +1,7 @@
// 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
#pragma once #pragma once
#include "Arping.h"
#include "receiver_defs.h" #include "receiver_defs.h"
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include "sls/logger.h" #include "sls/logger.h"
@ -49,6 +50,9 @@ class Implementation : private virtual slsDetectorDefs {
void setFramePaddingEnable(const bool i); void setFramePaddingEnable(const bool i);
void setThreadIds(const pid_t parentTid, const pid_t tcpTid); void setThreadIds(const pid_t parentTid, const pid_t tcpTid);
std::array<pid_t, NUM_RX_THREAD_IDS> getThreadIds() const; std::array<pid_t, NUM_RX_THREAD_IDS> getThreadIds() const;
bool getArping() const;
pid_t getArpingThreadId() const;
void setArping(const bool i, const std::vector<std::string> ips);
/************************************************** /**************************************************
* * * *
@ -295,7 +299,7 @@ class Implementation : private virtual slsDetectorDefs {
std::string filePath{"/"}; std::string filePath{"/"};
std::string fileName{"run"}; std::string fileName{"run"};
uint64_t fileIndex{0}; uint64_t fileIndex{0};
bool fileWriteEnable{true}; bool fileWriteEnable{false};
bool masterFileWriteEnable{true}; bool masterFileWriteEnable{true};
bool overwriteEnable{true}; bool overwriteEnable{true};
uint32_t framesPerFile{0}; uint32_t framesPerFile{0};
@ -352,6 +356,7 @@ class Implementation : private virtual slsDetectorDefs {
bool quadEnable{false}; bool quadEnable{false};
bool activated{true}; bool activated{true};
std::array<bool, 2> detectorDataStream = {{true, true}}; std::array<bool, 2> detectorDataStream = {{true, true}};
std::array<bool, 2> detectorDataStream10GbE = {{true, true}};
int readNRows{0}; int readNRows{0};
int thresholdEnergyeV{-1}; int thresholdEnergyeV{-1};
std::array<int, 3> thresholdAllEnergyeV = {{-1, -1, -1}}; std::array<int, 3> thresholdAllEnergyeV = {{-1, -1, -1}};
@ -379,6 +384,7 @@ class Implementation : private virtual slsDetectorDefs {
std::vector<std::unique_ptr<DataProcessor>> dataProcessor; std::vector<std::unique_ptr<DataProcessor>> dataProcessor;
std::vector<std::unique_ptr<DataStreamer>> dataStreamer; std::vector<std::unique_ptr<DataStreamer>> dataStreamer;
std::vector<std::unique_ptr<Fifo>> fifo; std::vector<std::unique_ptr<Fifo>> fifo;
Arping arping;
std::mutex hdf5Lib; std::mutex hdf5Lib;
}; };

View File

@ -0,0 +1,676 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "MasterAttributes.h"
void MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
LOG(logERROR) << "WriteMasterBinaryAttributes should have been called "
"by a child class";
}
std::string MasterAttributes::GetBinaryMasterAttributes() {
time_t t = time(nullptr);
std::ostringstream oss;
oss << "Version : " << std::setprecision(2)
<< BINARY_WRITER_VERSION << '\n'
<< "TimeStamp : " << ctime(&t) << '\n'
<< "Detector Type : " << sls::ToString(detType) << '\n'
<< "Timing Mode : " << sls::ToString(timingMode) << '\n'
<< "Geometry : " << sls::ToString(geometry) << '\n'
<< "Image Size : " << imageSize << " bytes" << '\n'
<< "Pixels : " << sls::ToString(nPixels) << '\n'
<< "Max Frames Per File : " << maxFramesPerFile << '\n'
<< "Frame Discard Policy : " << sls::ToString(frameDiscardMode)
<< '\n'
<< "Frame Padding : " << framePadding << '\n'
<< "Scan Parameters : " << sls::ToString(scanParams) << '\n'
<< "Total Frames : " << totalFrames << '\n';
return oss.str();
};
void MasterAttributes::WriteBinaryAttributes(FILE *fd, std::string message) {
if (fwrite((void *)message.c_str(), 1, message.length(), fd) !=
message.length()) {
throw sls::RuntimeError(
"Master binary file incorrect number of bytes written to file");
}
};
void MasterAttributes::WriteFinalBinaryAttributes(FILE *fd) {
// adding few common parameters to the end
std::ostringstream oss;
if (!additionalJsonHeader.empty()) {
oss << "Additional Json Header : "
<< sls::ToString(additionalJsonHeader) << '\n';
}
oss << "Frames in File : " << framesInFile << '\n';
// adding sls_receiver header format
oss << '\n'
<< "#Frame Header" << '\n'
<< "Frame Number : 8 bytes" << '\n'
<< "SubFrame Number/ExpLength : 4 bytes" << '\n'
<< "Packet Number : 4 bytes" << '\n'
<< "Bunch ID : 8 bytes" << '\n'
<< "Timestamp : 8 bytes" << '\n'
<< "Module Id : 2 bytes" << '\n'
<< "Row : 2 bytes" << '\n'
<< "Column : 2 bytes" << '\n'
<< "Reserved : 2 bytes" << '\n'
<< "Debug : 4 bytes" << '\n'
<< "Round Robin Number : 2 bytes" << '\n'
<< "Detector Type : 1 byte" << '\n'
<< "Header Version : 1 byte" << '\n'
<< "Packets Caught Mask : 64 bytes" << '\n';
std::string message = oss.str();
// writing to file
if (fwrite((void *)message.c_str(), 1, message.length(), fd) !=
message.length()) {
throw sls::RuntimeError(
"Master binary file incorrect number of bytes written to file");
}
};
#ifdef HDF5C
void MasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
LOG(logERROR) << "WriteMasterHdf5Attributes should have been called "
"by a child class";
};
void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) {
char c[1024];
memset(c, 0, sizeof(c));
// clang-format off
// version
{
double version = BINARY_WRITER_VERSION;
DataSpace dataspace = DataSpace(H5S_SCALAR);
Attribute attribute = fd->createAttribute(
"Version", PredType::NATIVE_DOUBLE, dataspace);
attribute.write(PredType::NATIVE_DOUBLE, &version);
}
// timestamp
{
time_t t = time(nullptr);
StrType strdatatype(PredType::C_S1, 256);
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Timestamp", strdatatype, dataspace);
sls::strcpy_safe(c, std::string(ctime(&t)));
dataset.write(c, strdatatype);
}
// detector type
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Detector Type", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(detType));
dataset.write(c, strdatatype);
}
// timing mode
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Timing Mode", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(timingMode));
dataset.write(c, strdatatype);
}
//TODO: make this into an array?
// geometry x
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Geometry in x axis", PredType::NATIVE_INT, dataspace);
dataset.write(&geometry.x, PredType::NATIVE_INT);
}
// geometry y
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Geometry in y axis", PredType::NATIVE_INT, dataspace);
dataset.write(&geometry.y, PredType::NATIVE_INT);
}
// Image Size
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Image Size", PredType::NATIVE_INT, dataspace);
dataset.write(&imageSize, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
sls::strcpy_safe(c, "bytes");
attribute.write(strdatatype, c);
}
//TODO: make this into an array?
// npixels x
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of pixels in x axis", PredType::NATIVE_INT, dataspace);
dataset.write(&nPixels.x, PredType::NATIVE_INT);
}
// npixels y
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of pixels in y axis", PredType::NATIVE_INT, dataspace);
dataset.write(&nPixels.y, PredType::NATIVE_INT);
}
// Maximum frames per file
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Maximum frames per file", PredType::NATIVE_INT, dataspace);
dataset.write(&maxFramesPerFile, PredType::NATIVE_INT);
}
// Frame Discard Policy
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Frame Discard Policy", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(frameDiscardMode));
dataset.write(c, strdatatype);
}
// Frame Padding
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Frame Padding", PredType::NATIVE_INT, dataspace);
dataset.write(&framePadding, PredType::NATIVE_INT);
}
// Scan Parameters
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Scan Parameters", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(scanParams));
dataset.write(c, strdatatype);
}
// Total Frames
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Total Frames", PredType::STD_U64LE, dataspace);
dataset.write(&totalFrames, PredType::STD_U64LE);
}
};
void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) {
char c[1024];
memset(c, 0, sizeof(c));
// Total Frames in file
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Frames in File", PredType::STD_U64LE, dataspace);
dataset.write(&framesInFile, PredType::STD_U64LE);
}
// additional json header
if (!additionalJsonHeader.empty()) {
std::string json = sls::ToString(additionalJsonHeader);
StrType strdatatype(PredType::C_S1, json.length());
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Additional JSON Header", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(additionalJsonHeader));
dataset.write(c, strdatatype);
}
};
void MasterAttributes::WriteHDF5Exptime(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(exptime));
dataset.write(c, strdatatype);
};
void MasterAttributes::WriteHDF5Period(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Acquisition Period", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(period));
dataset.write(c, strdatatype);
};
void MasterAttributes::WriteHDF5DynamicRange(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dynamic Range", PredType::NATIVE_INT, dataspace);
dataset.write(&dynamicRange, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
char c[1024] = "bits";
attribute.write( strdatatype, c);
};
void MasterAttributes::WriteHDF5TenGiga(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Ten Giga Enable", PredType::NATIVE_INT, dataspace);
dataset.write(&tenGiga, PredType::NATIVE_INT);
};
#endif
void GotthardMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void GotthardMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
// Roi xmin
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"roi xmin", PredType::NATIVE_INT, dataspace);
dataset.write(&roi.xmin, PredType::NATIVE_INT);
}
// Roi xmax
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"roi xmax", PredType::NATIVE_INT, dataspace);
dataset.write(&roi.xmax, PredType::NATIVE_INT);
}
};
#endif
void JungfrauMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Number of UDP Interfaces : " << numUDPInterfaces << '\n'
<< "Number of rows : " << readNRows << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void JungfrauMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of UDP Interfaces", PredType::NATIVE_INT, dataspace);
dataset.write(&numUDPInterfaces, PredType::NATIVE_INT);
}
// readNRows
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of rows", PredType::NATIVE_INT, dataspace);
dataset.write(&readNRows, PredType::NATIVE_INT);
}
};
#endif
void EigerMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Dynamic Range : " << dynamicRange << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Threshold Energy : " << thresholdEnergyeV << '\n'
<< "SubExptime : " << sls::ToString(subExptime)
<< '\n'
<< "SubPeriod : " << sls::ToString(subPeriod)
<< '\n'
<< "Quad : " << quad << '\n'
<< "Number of rows : " << readNRows << '\n'
<< "Rate Corrections : " << sls::ToString(ratecorr)
<< '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void EigerMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5DynamicRange(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
char c[1024];
memset(c, 0, sizeof(c));
// threshold
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Threshold Energy", PredType::NATIVE_INT, dataspace);
dataset.write(&thresholdEnergyeV, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
sls::strcpy_safe(c, "eV");
attribute.write(strdatatype, c);
}
// SubExptime
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = group->createDataSet("Sub Exposure Time",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(subExptime));
dataset.write(c, strdatatype);
}
// SubPeriod
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Sub Period", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(subPeriod));
dataset.write(c, strdatatype);
}
// Quad
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Quad", PredType::NATIVE_INT, dataspace);
dataset.write(&quad, PredType::NATIVE_INT);
}
// readNRows
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of rows", PredType::NATIVE_INT, dataspace);
dataset.write(&readNRows, PredType::NATIVE_INT);
}
// Rate corrections
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset = group->createDataSet("Rate Corrections",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(ratecorr));
dataset.write(c, strdatatype);
}
};
#endif
void Mythen3MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Dynamic Range : " << dynamicRange << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Counter Mask : " << sls::ToStringHex(counterMask)
<< '\n'
<< "Exptime1 : " << sls::ToString(exptime1)
<< '\n'
<< "Exptime2 : " << sls::ToString(exptime2)
<< '\n'
<< "Exptime3 : " << sls::ToString(exptime3)
<< '\n'
<< "GateDelay1 : " << sls::ToString(gateDelay1)
<< '\n'
<< "GateDelay2 : " << sls::ToString(gateDelay2)
<< '\n'
<< "GateDelay3 : " << sls::ToString(gateDelay3)
<< '\n'
<< "Gates : " << gates << '\n'
<< "Threshold Energies : "
<< sls::ToString(thresholdAllEnergyeV) << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void Mythen3MasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5DynamicRange(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
char c[1024];
memset(c, 0, sizeof(c));
// Counter Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Counter Mask", PredType::STD_U32LE, dataspace);
dataset.write(&counterMask, PredType::STD_U32LE);
}
// Exptime1
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time1", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime1));
dataset.write(c, strdatatype);
}
// Exptime2
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time2", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime2));
dataset.write(c, strdatatype);
}
// Exptime3
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time3", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime3));
dataset.write(c, strdatatype);
}
// GateDelay1
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay1", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay1));
dataset.write(c, strdatatype);
}
// GateDelay2
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay2", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay2));
dataset.write(c, strdatatype);
}
// GateDelay3
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay3", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay3));
dataset.write(c, strdatatype);
}
// Gates
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Gates", PredType::STD_U32LE, dataspace);
dataset.write(&gates, PredType::STD_U32LE);
}
// Threshold Energies
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset = group->createDataSet("Threshold Energies",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(thresholdAllEnergyeV));
dataset.write(c, strdatatype);
}
};
#endif
void Gotthard2MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Burst Mode : " << sls::ToString(burstMode)
<< '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void Gotthard2MasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
// burst mode
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Burst Mode", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(burstMode));
dataset.write(c, strdatatype);
}
};
#endif
void MoenchMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "ADC Mask : " << sls::ToStringHex(adcmask)
<< '\n'
<< "Analog Samples : " << analogSamples << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void MoenchMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
// ADC Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"ADC Mask", PredType::NATIVE_INT, dataspace);
dataset.write(&adcmask, PredType::NATIVE_INT);
}
// Analog Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&analogSamples, PredType::NATIVE_INT);
}
};
#endif
void CtbMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "ADC Mask : " << sls::ToStringHex(adcmask)
<< '\n'
<< "Analog Flag : " << analog << '\n'
<< "Analog Samples : " << analogSamples << '\n'
<< "Digital Flag : " << digital << '\n'
<< "Digital Samples : " << digitalSamples << '\n'
<< "Dbit Offset : " << dbitoffset << '\n'
<< "Dbit Bitset : " << dbitlist << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C
void CtbMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
// ADC Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"ADC mMsk", PredType::NATIVE_INT, dataspace);
dataset.write(&adcmask, PredType::NATIVE_INT);
}
// Analog Flag
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Flag", PredType::NATIVE_INT, dataspace);
dataset.write(&analog, PredType::NATIVE_INT);
}
// Analog Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&analogSamples, PredType::NATIVE_INT);
}
// Digital Flag
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Digital Flag", PredType::NATIVE_INT, dataspace);
dataset.write(&digital, PredType::NATIVE_INT);
}
// Digital Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Digital Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&digitalSamples, PredType::NATIVE_INT);
}
// Dbit Offset
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dbit Offset", PredType::NATIVE_INT, dataspace);
dataset.write(&dbitoffset, PredType::NATIVE_INT);
}
// Dbit List
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dbit Bitset List", PredType::STD_U64LE, dataspace);
dataset.write(&dbitlist, PredType::STD_U64LE);
}
};
#endif

View File

@ -17,10 +17,12 @@ using namespace H5;
#include <chrono> #include <chrono>
using ns = std::chrono::nanoseconds; using ns = std::chrono::nanoseconds;
struct MasterAttributes { class MasterAttributes {
public:
// (before acquisition) // (before acquisition)
slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC}; slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC};
slsDetectorDefs::timingMode timingMode{slsDetectorDefs::AUTO_TIMING}; slsDetectorDefs::timingMode timingMode{slsDetectorDefs::AUTO_TIMING};
slsDetectorDefs::xy geometry{};
uint32_t imageSize{0}; uint32_t imageSize{0};
slsDetectorDefs::xy nPixels{}; slsDetectorDefs::xy nPixels{};
uint32_t maxFramesPerFile{0}; uint32_t maxFramesPerFile{0};
@ -63,701 +65,82 @@ struct MasterAttributes {
// Final Attributes (after acquisition) // Final Attributes (after acquisition)
uint64_t framesInFile{0}; uint64_t framesInFile{0};
MasterAttributes(){}; MasterAttributes() = default;
virtual ~MasterAttributes(){}; virtual ~MasterAttributes() = default;
virtual void WriteMasterBinaryAttributes(FILE *fd);
virtual void WriteMasterBinaryAttributes(FILE *fd) { std::string GetBinaryMasterAttributes();
LOG(logERROR) << "WriteMasterBinaryAttributes should have been called " void WriteBinaryAttributes(FILE *fd, std::string message);
"by a child class"; void WriteFinalBinaryAttributes(FILE *fd);
}
std::string GetBinaryMasterAttributes() {
time_t t = time(nullptr);
std::ostringstream oss;
oss << "Version : " << std::setprecision(2)
<< BINARY_WRITER_VERSION << '\n'
<< "TimeStamp : " << ctime(&t) << '\n'
<< "Detector Type : " << sls::ToString(detType) << '\n'
<< "Timing Mode : " << sls::ToString(timingMode)
<< '\n'
<< "Image Size : " << imageSize << " bytes" << '\n'
<< "Pixels : " << sls::ToString(nPixels) << '\n'
<< "Max Frames Per File : " << maxFramesPerFile << '\n'
<< "Frame Discard Policy : "
<< sls::ToString(frameDiscardMode) << '\n'
<< "Frame Padding : " << framePadding << '\n'
<< "Scan Parameters : " << sls::ToString(scanParams)
<< '\n'
<< "Total Frames : " << totalFrames << '\n';
return oss.str();
};
void WriteBinaryAttributes(FILE *fd, std::string message) {
if (fwrite((void *)message.c_str(), 1, message.length(), fd) !=
message.length()) {
throw sls::RuntimeError(
"Master binary file incorrect number of bytes written to file");
}
};
void WriteFinalBinaryAttributes(FILE *fd) {
// adding few common parameters to the end
std::ostringstream oss;
if (!additionalJsonHeader.empty()) {
oss << "Additional Json Header : "
<< sls::ToString(additionalJsonHeader) << '\n';
}
oss << "Frames in File : " << framesInFile << '\n';
// adding sls_receiver header format
oss << '\n'
<< "#Frame Header" << '\n'
<< "Frame Number : 8 bytes" << '\n'
<< "SubFrame Number/ExpLength : 4 bytes" << '\n'
<< "Packet Number : 4 bytes" << '\n'
<< "Bunch ID : 8 bytes" << '\n'
<< "Timestamp : 8 bytes" << '\n'
<< "Module Id : 2 bytes" << '\n'
<< "Row : 2 bytes" << '\n'
<< "Column : 2 bytes" << '\n'
<< "Reserved : 2 bytes" << '\n'
<< "Debug : 4 bytes" << '\n'
<< "Round Robin Number : 2 bytes" << '\n'
<< "Detector Type : 1 byte" << '\n'
<< "Header Version : 1 byte" << '\n'
<< "Packets Caught Mask : 64 bytes" << '\n';
std::string message = oss.str();
// writing to file
if (fwrite((void *)message.c_str(), 1, message.length(), fd) !=
message.length()) {
throw sls::RuntimeError(
"Master binary file incorrect number of bytes written to file");
}
};
#ifdef HDF5C #ifdef HDF5C
virtual void WriteMasterHDF5Attributes(H5File *fd, Group *group) { virtual void WriteMasterHDF5Attributes(H5File *fd, Group *group);
LOG(logERROR) << "WriteMasterHdf5Attributes should have been called " void WriteHDF5Attributes(H5File *fd, Group *group);
"by a child class"; void WriteFinalHDF5Attributes(H5File *fd, Group *group);
}; void WriteHDF5Exptime(H5File *fd, Group *group);
void WriteHDF5Period(H5File *fd, Group *group);
void WriteHDF5Attributes(H5File *fd, Group *group) { void WriteHDF5DynamicRange(H5File *fd, Group *group);
char c[1024]; void WriteHDF5TenGiga(H5File *fd, Group *group);
memset(c, 0, sizeof(c));
// clang-format off
// version
{
double version = BINARY_WRITER_VERSION;
DataSpace dataspace = DataSpace(H5S_SCALAR);
Attribute attribute = fd->createAttribute(
"Version", PredType::NATIVE_DOUBLE, dataspace);
attribute.write(PredType::NATIVE_DOUBLE, &version);
}
// timestamp
{
time_t t = time(nullptr);
StrType strdatatype(PredType::C_S1, 256);
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Timestamp", strdatatype, dataspace);
sls::strcpy_safe(c, std::string(ctime(&t)));
dataset.write(c, strdatatype);
}
// detector type
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Detector Type", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(detType));
dataset.write(c, strdatatype);
}
// timing mode
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Timing Mode", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(timingMode));
dataset.write(c, strdatatype);
}
// Image Size
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Image Size", PredType::NATIVE_INT, dataspace);
dataset.write(&imageSize, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
sls::strcpy_safe(c, "bytes");
attribute.write(strdatatype, c);
}
//TODO: make this into an array?
// x
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of pixels in x axis", PredType::NATIVE_INT, dataspace);
dataset.write(&nPixels.x, PredType::NATIVE_INT);
}
// y
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of pixels in y axis", PredType::NATIVE_INT, dataspace);
dataset.write(&nPixels.y, PredType::NATIVE_INT);
}
// Maximum frames per file
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Maximum frames per file", PredType::NATIVE_INT, dataspace);
dataset.write(&maxFramesPerFile, PredType::NATIVE_INT);
}
// Frame Discard Policy
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Frame Discard Policy", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(frameDiscardMode));
dataset.write(c, strdatatype);
}
// Frame Padding
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Frame Padding", PredType::NATIVE_INT, dataspace);
dataset.write(&framePadding, PredType::NATIVE_INT);
}
// Scan Parameters
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Scan Parameters", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(scanParams));
dataset.write(c, strdatatype);
}
// Total Frames
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Total Frames", PredType::STD_U64LE, dataspace);
dataset.write(&totalFrames, PredType::STD_U64LE);
}
};
void WriteFinalHDF5Attributes(H5File *fd, Group *group) {
char c[1024];
memset(c, 0, sizeof(c));
// Total Frames in file
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Frames in File", PredType::STD_U64LE, dataspace);
dataset.write(&framesInFile, PredType::STD_U64LE);
}
// additional json header
if (!additionalJsonHeader.empty()) {
std::string json = sls::ToString(additionalJsonHeader);
StrType strdatatype(PredType::C_S1, json.length());
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Additional JSON Header", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(additionalJsonHeader));
dataset.write(c, strdatatype);
}
};
void WriteHDF5Exptime(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(exptime));
dataset.write(c, strdatatype);
};
void WriteHDF5Period(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Acquisition Period", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(period));
dataset.write(c, strdatatype);
};
void WriteHDF5DynamicRange(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dynamic Range", PredType::NATIVE_INT, dataspace);
dataset.write(&dynamicRange, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
char c[1024] = "bits";
attribute.write( strdatatype, c);
};
void WriteHDF5TenGiga(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Ten Giga Enable", PredType::NATIVE_INT, dataspace);
dataset.write(&tenGiga, PredType::NATIVE_INT);
};
#endif #endif
}; };
// clang-format on
class GotthardMasterAttributes : public MasterAttributes { class GotthardMasterAttributes : public MasterAttributes {
public: public:
GotthardMasterAttributes(){}; GotthardMasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C #ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
// Roi xmin
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"roi xmin", PredType::NATIVE_INT, dataspace);
dataset.write(&roi.xmin, PredType::NATIVE_INT);
}
// Roi xmax
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"roi xmax", PredType::NATIVE_INT, dataspace);
dataset.write(&roi.xmax, PredType::NATIVE_INT);
}
};
#endif #endif
}; };
class JungfrauMasterAttributes : public MasterAttributes { class JungfrauMasterAttributes : public MasterAttributes {
public: public:
JungfrauMasterAttributes(){}; JungfrauMasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Number of UDP Interfaces : " << numUDPInterfaces << '\n'
<< "Number of rows : " << readNRows << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C #ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of UDP Interfaces", PredType::NATIVE_INT, dataspace);
dataset.write(&numUDPInterfaces, PredType::NATIVE_INT);
}
// readNRows
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of rows", PredType::NATIVE_INT, dataspace);
dataset.write(&readNRows, PredType::NATIVE_INT);
}
};
#endif #endif
}; };
class EigerMasterAttributes : public MasterAttributes { class EigerMasterAttributes : public MasterAttributes {
public: public:
EigerMasterAttributes(){}; EigerMasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Dynamic Range : " << dynamicRange << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Threshold Energy : " << thresholdEnergyeV << '\n'
<< "SubExptime : " << sls::ToString(subExptime)
<< '\n'
<< "SubPeriod : " << sls::ToString(subPeriod)
<< '\n'
<< "Quad : " << quad << '\n'
<< "Number of rows : " << readNRows << '\n'
<< "Rate Corrections : " << sls::ToString(ratecorr)
<< '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C #ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5DynamicRange(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
char c[1024];
memset(c, 0, sizeof(c));
// threshold
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Threshold Energy", PredType::NATIVE_INT, dataspace);
dataset.write(&thresholdEnergyeV, PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
sls::strcpy_safe(c, "eV");
attribute.write(strdatatype, c);
}
// SubExptime
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = group->createDataSet("Sub Exposure Time",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(subExptime));
dataset.write(c, strdatatype);
}
// SubPeriod
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Sub Period", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(subPeriod));
dataset.write(c, strdatatype);
}
// Quad
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Quad", PredType::NATIVE_INT, dataspace);
dataset.write(&quad, PredType::NATIVE_INT);
}
// readNRows
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Number of rows", PredType::NATIVE_INT, dataspace);
dataset.write(&readNRows, PredType::NATIVE_INT);
}
// Rate corrections
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset = group->createDataSet("Rate Corrections",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(ratecorr));
dataset.write(c, strdatatype);
}
};
#endif #endif
}; };
class Mythen3MasterAttributes : public MasterAttributes { class Mythen3MasterAttributes : public MasterAttributes {
public: public:
Mythen3MasterAttributes(){}; Mythen3MasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Dynamic Range : " << dynamicRange << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Counter Mask : " << sls::ToStringHex(counterMask)
<< '\n'
<< "Exptime1 : " << sls::ToString(exptime1)
<< '\n'
<< "Exptime2 : " << sls::ToString(exptime2)
<< '\n'
<< "Exptime3 : " << sls::ToString(exptime3)
<< '\n'
<< "GateDelay1 : " << sls::ToString(gateDelay1)
<< '\n'
<< "GateDelay2 : " << sls::ToString(gateDelay2)
<< '\n'
<< "GateDelay3 : " << sls::ToString(gateDelay3)
<< '\n'
<< "Gates : " << gates << '\n'
<< "Threshold Energies : "
<< sls::ToString(thresholdAllEnergyeV) << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C #ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5DynamicRange(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
char c[1024];
memset(c, 0, sizeof(c));
// Counter Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Counter Mask", PredType::STD_U32LE, dataspace);
dataset.write(&counterMask, PredType::STD_U32LE);
}
// Exptime1
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time1", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime1));
dataset.write(c, strdatatype);
}
// Exptime2
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time2", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime2));
dataset.write(c, strdatatype);
}
// Exptime3
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time3", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptime3));
dataset.write(c, strdatatype);
}
// GateDelay1
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay1", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay1));
dataset.write(c, strdatatype);
}
// GateDelay2
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay2", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay2));
dataset.write(c, strdatatype);
}
// GateDelay3
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay3", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelay3));
dataset.write(c, strdatatype);
}
// Gates
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Gates", PredType::STD_U32LE, dataspace);
dataset.write(&gates, PredType::STD_U32LE);
}
// Threshold Energies
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset = group->createDataSet("Threshold Energies",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(thresholdAllEnergyeV));
dataset.write(c, strdatatype);
}
};
#endif #endif
}; };
class Gotthard2MasterAttributes : public MasterAttributes { class Gotthard2MasterAttributes : public MasterAttributes {
public: public:
Gotthard2MasterAttributes(){}; Gotthard2MasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Burst Mode : " << sls::ToString(burstMode)
<< '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C #ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
// burst mode
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Burst Mode", strdatatype, dataspace);
char c[1024];
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(burstMode));
dataset.write(c, strdatatype);
}
};
#endif #endif
}; };
class MoenchMasterAttributes : public MasterAttributes { class MoenchMasterAttributes : public MasterAttributes {
public: public:
MoenchMasterAttributes(){}; MoenchMasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "ADC Mask : " << sls::ToStringHex(adcmask)
<< '\n'
<< "Analog Samples : " << analogSamples << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C #ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
// ADC Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"ADC Mask", PredType::NATIVE_INT, dataspace);
dataset.write(&adcmask, PredType::NATIVE_INT);
}
// Analog Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&analogSamples, PredType::NATIVE_INT);
}
};
#endif #endif
}; };
class CtbMasterAttributes : public MasterAttributes { class CtbMasterAttributes : public MasterAttributes {
public: public:
CtbMasterAttributes(){}; CtbMasterAttributes() = default;
void WriteMasterBinaryAttributes(FILE *fd) override;
void WriteMasterBinaryAttributes(FILE *fd) override {
std::ostringstream oss;
oss << MasterAttributes::GetBinaryMasterAttributes()
<< "Exptime : " << sls::ToString(exptime) << '\n'
<< "Period : " << sls::ToString(period) << '\n'
<< "Ten Giga : " << tenGiga << '\n'
<< "ADC Mask : " << sls::ToStringHex(adcmask)
<< '\n'
<< "Analog Flag : " << analog << '\n'
<< "Analog Samples : " << analogSamples << '\n'
<< "Digital Flag : " << digital << '\n'
<< "Digital Samples : " << digitalSamples << '\n'
<< "Dbit Offset : " << dbitoffset << '\n'
<< "Dbit Bitset : " << dbitlist << '\n';
std::string message = oss.str();
MasterAttributes::WriteBinaryAttributes(fd, message);
};
#ifdef HDF5C #ifdef HDF5C
void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { void WriteMasterHDF5Attributes(H5File *fd, Group *group) override;
MasterAttributes::WriteHDF5Attributes(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group);
// ADC Mask
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"ADC mMsk", PredType::NATIVE_INT, dataspace);
dataset.write(&adcmask, PredType::NATIVE_INT);
}
// Analog Flag
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Flag", PredType::NATIVE_INT, dataspace);
dataset.write(&analog, PredType::NATIVE_INT);
}
// Analog Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Analog Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&analogSamples, PredType::NATIVE_INT);
}
// Digital Flag
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Digital Flag", PredType::NATIVE_INT, dataspace);
dataset.write(&digital, PredType::NATIVE_INT);
}
// Digital Samples
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Digital Samples", PredType::NATIVE_INT, dataspace);
dataset.write(&digitalSamples, PredType::NATIVE_INT);
}
// Dbit Offset
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dbit Offset", PredType::NATIVE_INT, dataspace);
dataset.write(&dbitoffset, PredType::NATIVE_INT);
}
// Dbit List
{
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet(
"Dbit Bitset List", PredType::STD_U64LE, dataspace);
dataset.write(&dbitlist, PredType::STD_U64LE);
}
};
#endif #endif
}; };

View File

@ -11,10 +11,15 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <semaphore.h> #include <semaphore.h>
#include <sys/syscall.h>
#include <sys/wait.h> //wait #include <sys/wait.h> //wait
#include <unistd.h> #include <unistd.h>
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif
/** Define Colors to print data call back in different colors for different /** Define Colors to print data call back in different colors for different
* recievers */ * recievers */
#define PRINT_IN_COLOR(c, f, ...) \ #define PRINT_IN_COLOR(c, f, ...) \
@ -172,8 +177,7 @@ int main(int argc, char *argv[]) {
(!sscanf(argv[3], "%d", &withCallback)))) (!sscanf(argv[3], "%d", &withCallback))))
printHelp(); printHelp();
cprintf(BLUE, "Parent Process Created [ Tid: %ld ]\n", cprintf(BLUE, "Parent Process Created [ Tid: %ld ]\n", (long)gettid());
(long)syscall(SYS_gettid));
cprintf(RESET, "Number of Receivers: %d\n", numReceivers); cprintf(RESET, "Number of Receivers: %d\n", numReceivers);
cprintf(RESET, "Start TCP Port: %d\n", startTCPPort); cprintf(RESET, "Start TCP Port: %d\n", startTCPPort);
cprintf(RESET, "Callback Enable: %d\n", withCallback); cprintf(RESET, "Callback Enable: %d\n", withCallback);
@ -215,16 +219,14 @@ int main(int argc, char *argv[]) {
/** - if child process */ /** - if child process */
else if (pid == 0) { else if (pid == 0) {
cprintf(BLUE, "Child process %d [ Tid: %ld ]\n", i, cprintf(BLUE, "Child process %d [ Tid: %ld ]\n", i, (long)gettid());
(long)syscall(SYS_gettid));
std::unique_ptr<sls::Receiver> receiver = nullptr; std::unique_ptr<sls::Receiver> receiver = nullptr;
try { try {
receiver = sls::make_unique<sls::Receiver>(startTCPPort + i); receiver = sls::make_unique<sls::Receiver>(startTCPPort + i);
} catch (...) { } catch (...) {
LOG(logINFOBLUE) LOG(logINFOBLUE)
<< "Exiting Child Process [ Tid: " << syscall(SYS_gettid) << "Exiting Child Process [ Tid: " << gettid() << " ]";
<< " ]";
throw; throw;
} }
/** - register callbacks. remember to set file write enable to 0 /** - register callbacks. remember to set file write enable to 0
@ -254,7 +256,7 @@ int main(int argc, char *argv[]) {
sem_wait(&semaphore); sem_wait(&semaphore);
sem_destroy(&semaphore); sem_destroy(&semaphore);
cprintf(BLUE, "Exiting Child Process [ Tid: %ld ]\n", cprintf(BLUE, "Exiting Child Process [ Tid: %ld ]\n",
(long)syscall(SYS_gettid)); (long)gettid());
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
} }

View File

@ -14,9 +14,14 @@
#include <map> #include <map>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif
namespace sls { namespace sls {
Receiver::~Receiver() = default; Receiver::~Receiver() = default;
@ -68,8 +73,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
case 'v': case 'v':
std::cout << "SLS Receiver Version: " << GITBRANCH << " (0x" std::cout << "SLS Receiver Version: " << GITBRANCH << " (0x"
<< std::hex << APIRECEIVER << ")" << std::endl; << std::hex << APIRECEIVER << ")" << std::endl;
LOG(logINFOBLUE) LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]";
<< "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'h': case 'h':

View File

@ -8,9 +8,14 @@
#include <csignal> //SIGINT #include <csignal> //SIGINT
#include <semaphore.h> #include <semaphore.h>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif
sem_t semaphore; sem_t semaphore;
void sigInterruptHandler(int p) { sem_post(&semaphore); } void sigInterruptHandler(int p) { sem_post(&semaphore); }
@ -19,7 +24,7 @@ int main(int argc, char *argv[]) {
sem_init(&semaphore, 1, 0); sem_init(&semaphore, 1, 0);
LOG(logINFOBLUE) << "Created [ Tid: " << syscall(SYS_gettid) << " ]"; LOG(logINFOBLUE) << "Created [ Tid: " << gettid() << " ]";
// Catch signal SIGINT to close files and call destructors properly // Catch signal SIGINT to close files and call destructors properly
struct sigaction sa; struct sigaction sa;
@ -50,7 +55,7 @@ int main(int argc, char *argv[]) {
} catch (...) { } catch (...) {
// pass // pass
} }
LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]"; LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]";
LOG(logINFO) << "Exiting Receiver"; LOG(logINFO) << "Exiting Receiver";
return 0; return 0;
} }

View File

@ -8,9 +8,14 @@
#include "ThreadObject.h" #include "ThreadObject.h"
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include <iostream> #include <iostream>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif
ThreadObject::ThreadObject(int threadIndex, std::string threadType) ThreadObject::ThreadObject(int threadIndex, std::string threadType)
: index(threadIndex), type(threadType) { : index(threadIndex), type(threadType) {
LOG(logDEBUG) << type << " thread created: " << index; LOG(logDEBUG) << type << " thread created: " << index;
@ -39,7 +44,7 @@ void ThreadObject::StartRunning() { runningFlag = true; }
void ThreadObject::StopRunning() { runningFlag = false; } void ThreadObject::StopRunning() { runningFlag = false; }
void ThreadObject::RunningThread() { void ThreadObject::RunningThread() {
threadId = syscall(SYS_gettid); threadId = gettid();
LOG(logINFOBLUE) << "Created [ " << type << "Thread " << index LOG(logINFOBLUE) << "Created [ " << type << "Thread " << index
<< ", Tid: " << threadId << "]"; << ", Tid: " << threadId << "]";
while (!killThread) { while (!killThread) {

View File

@ -21,14 +21,6 @@ class ThreadObject : private virtual slsDetectorDefs {
protected: protected:
const int index{0}; const int index{0};
private:
std::atomic<bool> killThread{false};
std::atomic<bool> runningFlag{false};
std::thread threadObject;
sem_t semaphore;
const std::string type;
pid_t threadId{0};
public: public:
ThreadObject(int threadIndex, std::string threadType); ThreadObject(int threadIndex, std::string threadType);
virtual ~ThreadObject(); virtual ~ThreadObject();
@ -47,4 +39,11 @@ class ThreadObject : private virtual slsDetectorDefs {
* Then it exits the thread on its own if killThread is true * Then it exits the thread on its own if killThread is true
*/ */
void RunningThread(); void RunningThread();
std::atomic<bool> killThread{false};
std::atomic<bool> runningFlag{false};
std::thread threadObject;
sem_t semaphore;
const std::string type;
std::atomic<pid_t> threadId{0};
}; };

View File

@ -17,8 +17,8 @@
// files // files
// versions // versions
#define HDF5_WRITER_VERSION (6.3) // 1 decimal places #define HDF5_WRITER_VERSION (6.4) // 1 decimal places
#define BINARY_WRITER_VERSION (6.3) // 1 decimal places #define BINARY_WRITER_VERSION (6.4) // 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

@ -65,6 +65,8 @@
#define DEFAULT_DET_MAC2 "00:aa:bb:cc:dd:ff" #define DEFAULT_DET_MAC2 "00:aa:bb:cc:dd:ff"
#define DEFAULT_DET_IP2 "129.129.202.46" #define DEFAULT_DET_IP2 "129.129.202.46"
#define LOCALHOST_IP "127.0.0.1"
/** default maximum string length */ /** default maximum string length */
#define MAX_STR_LENGTH 1000 #define MAX_STR_LENGTH 1000
#define SHORT_STR_LENGTH 20 #define SHORT_STR_LENGTH 20
@ -73,7 +75,7 @@
#define DEFAULT_STREAMING_TIMER_IN_MS 500 #define DEFAULT_STREAMING_TIMER_IN_MS 500
#define NUM_RX_THREAD_IDS 8 #define NUM_RX_THREAD_IDS 9
#ifdef __cplusplus #ifdef __cplusplus
class slsDetectorDefs { class slsDetectorDefs {
@ -564,7 +566,7 @@ enum streamingInterface {
#ifdef __cplusplus #ifdef __cplusplus
}; };
//operators needed in ToString // operators needed in ToString
inline slsDetectorDefs::streamingInterface inline slsDetectorDefs::streamingInterface
operator|(const slsDetectorDefs::streamingInterface &a, operator|(const slsDetectorDefs::streamingInterface &a,
const slsDetectorDefs::streamingInterface &b) { const slsDetectorDefs::streamingInterface &b) {
@ -579,8 +581,6 @@ operator&(const slsDetectorDefs::streamingInterface &a,
static_cast<int32_t>(b)); static_cast<int32_t>(b));
}; };
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -258,6 +258,9 @@ enum detFuncs {
F_UPDATE_DETECTOR_SERVER, F_UPDATE_DETECTOR_SERVER,
F_GET_UPDATE_MODE, F_GET_UPDATE_MODE,
F_SET_UPDATE_MODE, F_SET_UPDATE_MODE,
F_SET_MASTER,
F_GET_TOP,
F_SET_TOP,
NUM_DET_FUNCTIONS, NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this RECEIVER_ENUM_START = 256, /**< detector function should not exceed this
@ -361,6 +364,8 @@ enum detFuncs {
F_SET_RECEIVER_STREAMING_HWM, F_SET_RECEIVER_STREAMING_HWM,
F_RECEIVER_SET_ALL_THRESHOLD, F_RECEIVER_SET_ALL_THRESHOLD,
F_RECEIVER_SET_DATASTREAM, F_RECEIVER_SET_DATASTREAM,
F_GET_RECEIVER_ARPING,
F_SET_RECEIVER_ARPING,
NUM_REC_FUNCTIONS NUM_REC_FUNCTIONS
}; };
@ -617,6 +622,9 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_UPDATE_DETECTOR_SERVER: return "F_UPDATE_DETECTOR_SERVER"; case F_UPDATE_DETECTOR_SERVER: return "F_UPDATE_DETECTOR_SERVER";
case F_GET_UPDATE_MODE: return "F_GET_UPDATE_MODE"; case F_GET_UPDATE_MODE: return "F_GET_UPDATE_MODE";
case F_SET_UPDATE_MODE: return "F_SET_UPDATE_MODE"; case F_SET_UPDATE_MODE: return "F_SET_UPDATE_MODE";
case F_SET_MASTER: return "F_SET_MASTER";
case F_GET_TOP: return "F_GET_TOP";
case F_SET_TOP: return "F_SET_TOP";
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";
@ -720,6 +728,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_SET_RECEIVER_STREAMING_HWM: return "F_SET_RECEIVER_STREAMING_HWM"; case F_SET_RECEIVER_STREAMING_HWM: return "F_SET_RECEIVER_STREAMING_HWM";
case F_RECEIVER_SET_ALL_THRESHOLD: return "F_RECEIVER_SET_ALL_THRESHOLD"; case F_RECEIVER_SET_ALL_THRESHOLD: return "F_RECEIVER_SET_ALL_THRESHOLD";
case F_RECEIVER_SET_DATASTREAM: return "F_RECEIVER_SET_DATASTREAM"; case F_RECEIVER_SET_DATASTREAM: return "F_RECEIVER_SET_DATASTREAM";
case F_GET_RECEIVER_ARPING: return "F_GET_RECEIVER_ARPING";
case F_SET_RECEIVER_ARPING: return "F_SET_RECEIVER_ARPING";
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

@ -1,15 +1,15 @@
// 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
/** API versions */ /** API versions */
#define GITBRANCH "developer" #define GITBRANCH "developer"
#define APILIB 0x211125 #define APILIB 0x211125
#define APIRECEIVER 0x211124 #define APIRECEIVER 0x211124
#define APIGUI 0x211124 #define APIGUI 0x211124
#define APICTB 0x220203 #define APICTB 0x220902
#define APIGOTTHARD 0x220203 #define APIGOTTHARD 0x220902
#define APIGOTTHARD2 0x220203 #define APIGOTTHARD2 0x220902
#define APIJUNGFRAU 0x220203 #define APIJUNGFRAU 0x220902
#define APIMYTHEN3 0x220203 #define APIMYTHEN3 0x220902
#define APIMOENCH 0x220202 #define APIMOENCH 0x220902
#define APIEIGER 0x220203 #define APIEIGER 0x220902