Compare commits

..

1 Commits

Author SHA1 Message Date
e229cd0ba7 removed Makefile for moench and integrated the build in CMake 2022-01-24 16:09:18 +01:00
119 changed files with 5158 additions and 10034 deletions

View File

@ -275,7 +275,6 @@ if(SLS_BUILD_DOCS)
endif(SLS_BUILD_DOCS)
if(SLS_USE_MOENCH)
add_subdirectory(slsDetectorCalibration/tiffio)
add_subdirectory(slsDetectorCalibration/moenchExecutables)
endif(SLS_USE_MOENCH)

View File

@ -1,7 +1,7 @@
SLS Detector Package Minor Release 7.0.0 released on 25.11.2021
SLS Detector Package Minor Release 6.1.0 released on 25.11.2021
===============================================================
This document describes the differences between v7.0.0 and v6.x.x
This document describes the differences between v6.1.0 and v6.0.0.
@ -21,35 +21,9 @@ This document describes the differences between v7.0.0 and v6.x.x
- Fixed minor warnings (will fix commandline print of excess packets for missing packets)
- ctb slow adcs and any other adcs (other than temp) goes to the control Server
- number of udp interfaces is 2 for Eiger (CHANGE IN API??)
- added module id for virtual servers into the udp header
- refactoring (rxr)
- fixed patsetbit and patsetmask for moench
- changed default vref of adc9257 to 2V for moench (from 1.33V)
- moench and ctb - can set the starting frame number of next acquisition
- mythen server kernel check incompatible (cet timezone)
- 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
- 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

View File

@ -1,6 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package
#Copy the Moench executables
mkdir -p $PREFIX/bin
cp build/install/bin/moench* $PREFIX/bin/.
cp build/install/bin/moench04ZmqProcess $PREFIX/bin/.
cp build/install/bin/moenchZmqProcess $PREFIX/bin/.

View File

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

View File

@ -21,10 +21,9 @@ fi
if [ -f "$infile" ]
then
dir=$(dirname $infile)
gcc -DINFILE="\"$infile\"" -DOUTFILE="\"$outfile\"" -DOUTFILEBIN="\"$outfilebin\"" -o $exe generator.c -I$dir;
gcc -DINFILE="\"$infile\"" -DOUTFILE="\"$outfile\"" -DOUTFILEBIN="\"$outfilebin\"" -o $exe generator.c ;
echo compiling
echo gcc -DINFILE="\"$infile\"" -DOUTFILE="\"$outfile\"" -DOUTFILEBIN="\"$outfilebin\"" -o $exe generator.c -I$dir;
echo gcc -DINFILE="\"$infile\"" -DOUTFILE="\"$outfile\"" -DOUTFILEBIN="\"$outfilebin\"" -o $exe generator.c ;
$exe ;
echo cleaning
rm $exe

View File

@ -1,12 +0,0 @@
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

@ -3,33 +3,33 @@
### edit with hostname or IP address of your detector
############################################
#hostname bchip181+
hostname bchip119.psi.ch
hostname bchip181+
#############################################
### edit with hostname or 1Gbs IP address of your server
############################################
rx_hostname mpc2011:1777
rx_hostname mpc2011
#############################################
### edit with 10 Gbs IP of your server
############################################
udp_dstip 10.1.2.102
udp_dstip 10.1.1.102
#############################################
### edit with any number in the subnet of your server (first 3 numbers as above)
############################################
udp_srcip 10.1.2.19
udp_dstport 32000
udp_srcip 10.1.1.19
udp_dstport 32411
#############################################
### edit with 10 Gbs IP of your server
############################################
rx_zmqip 10.1.2.102
rx_zmqport 77000
rx_zmqip 10.1.1.102
rx_zmqport 50003
#############################################
### edit with 1 Gbs IP of PC where you will run the GUI
############################################
zmqip 129.129.202.132
zmqport 77001
zmqip 129.129.202.98
zmqport 50001
@ -38,7 +38,7 @@ rx_zmqstream 1
frames 1000
frames 100000
period 0.0006
exptime 0.00035
@ -62,9 +62,3 @@ highvoltage 90
#adcreg 0x14 0x40
frames 10
period 0.1
rx_jsonpara subframes 1
rx_jsonpara frameMode raw
rx_jsonpara detectorMode analog

File diff suppressed because it is too large Load Diff

View File

@ -13,8 +13,8 @@ import subprocess
from parse import remove_comments
allow_bitwise_op = ["streamingInterface", "M3_GainCaps"]
allow_bitwise_op = ["M3_GainCaps"]
allow_bitwise_op = ["streamingInterface"]
op_key = {"operator|": "|",
"operator&" : "&"}

View File

@ -6,57 +6,49 @@ sls::Detector class. The tool needs the libclang bindings
to be installed.
When the Detector API is updated this file should be run
manually.
manually
"""
from clang import cindex
import subprocess
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/"
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 = []
ag = []
lines = []
ag2 = []
cn = []
def get_arguments(node):
@ -74,7 +66,7 @@ def get_arguments_with_default(node):
args = []
for arg in node.get_arguments():
tokens = [t.spelling for t in arg.get_tokens()]
# print(tokens)
print(tokens)
if '=' in tokens:
if arg.type.spelling == "sls::Positions": #TODO! automate
args.append("py::arg() = Positions{}")
@ -119,67 +111,33 @@ def visit(node):
lines.append(
f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})'
)
if cargs.verbose:
print(f'&Detector::{child.spelling}{args})')
cn.append(child)
for child in node.get_children():
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)
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')
visit(tu.cursor)
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'))
# run clang format on the output
print('Running clang format on generated source -', end = "")
subprocess.run(["clang-format", "../src/detector.cpp", "-i"])
print(green(" OK"))
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"
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,12 +5,6 @@ import subprocess
from subprocess import PIPE
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 replacer(match):

View File

@ -258,7 +258,7 @@ class Detector(CppDetectorApi):
@element
def rx_threads(self):
"""
Get thread ids from the receiver in order of [parent, tcp, listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1, arping].
Get thread ids from the receiver in order of [parent, tcp, listener 0, processor 0, streamer 0, listener 1, processor 1, streamer 1].
Note
-----
@ -268,17 +268,6 @@ class Detector(CppDetectorApi):
"""
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
@element
def dr(self):
@ -287,7 +276,7 @@ class Detector(CppDetectorApi):
Note
-----
[Eiger] Options: 4, 8, 12, 16, 32. If set to 32, also sets clkdivider to 2 (quarter speed), else to 0 (full speed)\n
[Eiger] Options: 4, 8, 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
[Jungfrau][Gotthard][Ctb][Moench][Mythen3][Gotthard2] 16
"""
@ -605,7 +594,7 @@ class Detector(CppDetectorApi):
@property
@element
def nextframenumber(self):
"""[Eiger][Jungfrau][Moench][CTB] Next frame number. Stopping acquisition might result in different frame numbers for different modules. """
"""[Eiger][Jungfrau] Next frame number. Stopping acquisition might result in different frame numbers for different modules. """
return self.getNextFrameNumber()
@nextframenumber.setter
@ -1474,19 +1463,6 @@ class Detector(CppDetectorApi):
def trimval(self, 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
@element
def lock(self):
@ -1924,7 +1900,7 @@ class Detector(CppDetectorApi):
@property
@element
def rx_missingpackets(self):
"""Gets the number of missing packets for each port in receiver. Negative number denotes extra packets. """
"""Gets the number of missing packets for each port in receiver."""
return self.getNumMissingPackets()
"""
@ -1937,7 +1913,7 @@ class Detector(CppDetectorApi):
def datastream(self):
"""
datastream [left|right] [0, 1]
[Eiger] Enables or disables data streaming from left or/and right side of detector for 10GbE mode. 1 (enabled) by default.
[Eiger] Enables or disables data streaming from left or/and right side of detector. 1 (enabled) by default.
"""
result = {}
for port in [defs.LEFT, defs.RIGHT]:
@ -2139,21 +2115,6 @@ class Detector(CppDetectorApi):
"""
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>>>-------------------------
"""

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

View File

@ -273,8 +273,7 @@ void init_enums(py::module &m) {
slsDetectorDefs::timingSourceType::TIMING_EXTERNAL)
.export_values();
py::enum_<slsDetectorDefs::M3_GainCaps>(Defs, "M3_GainCaps",
py::arithmetic())
py::enum_<slsDetectorDefs::M3_GainCaps>(Defs, "M3_GainCaps")
.value("M3_C10pre", slsDetectorDefs::M3_GainCaps::M3_C10pre)
.value("M3_C15sh", slsDetectorDefs::M3_GainCaps::M3_C15sh)
.value("M3_C30sh", slsDetectorDefs::M3_GainCaps::M3_C30sh)

View File

@ -10,7 +10,7 @@
#include "pedestalSubtraction.h"
#include "slsDetectorData.h"
#include "slsInterpolation.h"
#include "sls/tiffIO.h"
#include "tiffIO.h"
#include <pthread.h>
#ifdef ROOTSPECTRUM

View File

@ -2,9 +2,49 @@
// Copyright (C) 2021 Contributors to the SLS Detector Package
#ifndef MOENCH03T1RECDATANEW_H
#define MOENCH03T1RECDATANEW_H
#include "sls/sls_detector_defs.h"
#include "slsDetectorData.h"
//#define VERSION_V2
/**
@short structure for a Detector Packet or Image Header
@li frameNumber is the frame number
@li expLength is the subframe number (32 bit eiger) or real time exposure
time in 100ns (others)
@li packetNumber is the packet number
@li bunchId is the bunch id from beamline
@li timestamp is the time stamp with 10 MHz clock
@li modId is the unique module id (unique even for left, right, top, bottom)
@li xCoord is the x coordinate in the complete detector system
@li yCoord is the y coordinate in the complete detector system
@li zCoord is the z coordinate in the complete detector system
@li debug is for debugging purposes
@li roundRNumber is the round robin set number
@li detType is the detector type see :: detectorType
@li version is the version number of this structure format
*/
typedef struct {
uint64_t frameNumber; /**< is the frame number */
uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time
exposure time in 100ns (others) */
uint32_t packetNumber; /**< is the packet number */
uint64_t bunchId; /**< is the bunch id from beamline */
uint64_t timestamp; /**< is the time stamp with 10 MHz clock */
uint16_t modId; /**< is the unique module id (unique even for left, right,
top, bottom) */
uint16_t xCoord; /**< is the x coordinate in the complete detector system */
uint16_t yCoord; /**< is the y coordinate in the complete detector system */
uint16_t zCoord; /**< is the z coordinate in the complete detector system */
uint32_t debug; /**< is for debugging purposes */
uint16_t roundRNumber; /**< is the round robin set number */
uint8_t detType; /**< is the detector type see :: detectorType */
uint8_t version; /**< is the version number of this structure format */
#ifndef VERSION_V1
uint64_t
packetCaught[8]; /**< is the version number of this structure format */
#endif
} sls_detector_header;
class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
private:
@ -16,9 +56,6 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
double ghost[200][25];
// Single point of definition if we need to customize
using header = sls::defs::sls_receiver_header;
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read
@ -27,7 +64,8 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
*/
moench03T1ReceiverDataNew(int ns = 5000)
: slsDetectorData<uint16_t>(400, 400, ns * 2 * 32 + sizeof(header)),
: slsDetectorData<uint16_t>(400, 400,
ns * 2 * 32 + sizeof(sls_detector_header)),
nSamples(ns) {
int nadc = 32;
@ -62,15 +100,15 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
} else {
row = 200 + i / sc_width;
}
dataMap[row][col] = sizeof(header) +
dataMap[row][col] = sizeof(sls_detector_header) +
(nadc * i + iadc) * 2; //+16*(ip+1);
#ifdef HIGHZ
dataMask[row][col] = 0x3fff; // invert data
#endif
if (dataMap[row][col] < 0 ||
dataMap[row][col] >= nSamples * 2 * 32)
std::cout << "Error: pointer " << dataMap[row][col]
<< " out of range " << std::endl;
cout << "Error: pointer " << dataMap[row][col]
<< " out of range " << endl;
}
}
}
@ -82,13 +120,13 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
ghost[iy][ix] = 0.;
int ipacket;
uint ibyte;
int ibyte;
int ii = 0;
for (ibyte = 0; ibyte < sizeof(header) / 2; ibyte++) {
for (ibyte = 0; ibyte < sizeof(sls_detector_header) / 2; ibyte++) {
xmap[ibyte] = -1;
ymap[ibyte] = -1;
}
int off = sizeof(header) / 2;
int off = sizeof(sls_detector_header) / 2;
for (ipacket = 0; ipacket < npackets; ipacket++) {
for (ibyte = 0; ibyte < 8192 / 2; ibyte++) {
i = ipacket * 8208 / 2 + ibyte;
@ -123,7 +161,20 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
required as double
*/
double getValue(char *data, int ix, int iy = 0) override {
virtual double getValue(char *data, int ix, int iy = 0) {
/* cout << " x "<< ix << " y"<< iy << " val " << getChannel(data, ix,
* iy)<< endl;*/
/* double val=0, vout=getChannel(data, ix, iy); */
/* int x1=ix%25; */
/* for (int ix=0; ix<16; ix++) { */
/* for (int ii=0; ii<2; ii++) { */
/* val+=getChannel(data,x1+25*ix,iy); */
/* val+=getChannel(data,x1+25*ix,399-iy); */
/* } */
/* } */
/* vout+=0.0008*val-6224; */
/* return vout; //(double)getChannel(data, ix, iy);
*/
uint16_t val = getChannel(data, ix, iy) & 0x3fff;
return val;
};
@ -174,9 +225,17 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
*/
/* class jfrau_packet_header_t { */
/* public: */
/* unsigned char reserved[4]; */
/* unsigned char packetNumber[1]; */
/* unsigned char frameNumber[3]; */
/* unsigned char bunchid[8]; */
/* }; */
int getFrameNumber(char *buff) {
return ((header *)buff)->detHeader.frameNumber;
}
return ((sls_detector_header *)buff)->frameNumber;
}; //*((int*)(buff+5))&0xffffff;};
/**
@ -188,22 +247,68 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
*/
int getPacketNumber(char *buff) {
return ((header *)buff)->detHeader.packetNumber;
}
return ((sls_detector_header *)buff)->packetNumber;
} //((*(((int*)(buff+4))))&0xff)+1;};
char *readNextFrame(std::ifstream &filebin) override {
/* /\** */
/* Loops over a memory slot until a complete frame is found (i.e. all
* packets 0 to nPackets, same frame number). purely virtual func */
/* \param data pointer to the memory to be analyzed */
/* \param ndata reference to the amount of data found for the frame, in
* case the frame is incomplete at the end of the memory slot */
/* \param dsize size of the memory slot to be analyzed */
/* \returns pointer to the beginning of the last good frame (might be
* incomplete if ndata smaller than dataSize), or NULL if no frame is found
*/
/* *\/ */
/* virtual char *findNextFrame(char *data, int &ndata, int
* dsize){ndata=dsize; setDataSize(dsize); return data;}; */
/* /\** */
/* Loops over a file stream until a complete frame is found (i.e. all
* packets 0 to nPackets, same frame number). Can be overloaded for
* different kind of detectors! */
/* \param filebin input file stream (binary) */
/* \returns pointer to the begin of the last good frame, NULL if no
* frame is found or last frame is incomplete */
/* *\/ */
/* virtual char *readNextFrame(ifstream &filebin){ */
/* // int afifo_length=0; */
/* uint16_t *afifo_cont; */
/* int ib=0; */
/* if (filebin.is_open()) { */
/* afifo_cont=new uint16_t[dataSize/2]; */
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
/* ib+=2; */
/* if (ib==dataSize) break; */
/* } */
/* if (ib>0) { */
/* iframe++; */
/* // cout << ib << "-" << endl; */
/* return (char*)afifo_cont; */
/* } else { */
/* delete [] afifo_cont; */
/* return NULL; */
/* } */
/* } */
/* return NULL; */
/* }; */
virtual char *readNextFrame(ifstream &filebin) {
int ff = -1, np = -1;
return readNextFrame(filebin, ff, np);
}
};
// not present in base class
virtual char *readNextFrame(std::ifstream &filebin, int &ff) {
virtual char *readNextFrame(ifstream &filebin, int &ff) {
int np = -1;
return readNextFrame(filebin, ff, np);
};
// not present in base class
virtual char *readNextFrame(std::ifstream &filebin, int &ff, int &np) {
virtual char *readNextFrame(ifstream &filebin, int &ff, int &np) {
char *data = new char[dataSize];
char *d = readNextFrame(filebin, ff, np, data);
if (d == NULL) {
@ -213,10 +318,18 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
return data;
}
// not present in base class
virtual char *readNextFrame(std::ifstream &filebin, int &ff, int &np,
virtual char *readNextFrame(ifstream &filebin, int &ff, int &np,
char *data) {
char *retval = 0;
int nd;
int fnum = -1;
np = 0;
int pn;
// cout << dataSize << endl;
if (ff >= 0)
fnum = ff;
if (filebin.is_open()) {
if (filebin.read(data, dataSize)) {
ff = getFrameNumber(data);
@ -224,8 +337,8 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
return data;
}
}
return nullptr;
}
return NULL;
};
/**
@ -239,7 +352,7 @@ class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
found
*/
char *findNextFrame(char *data, int &ndata, int dsize) override {
virtual char *findNextFrame(char *data, int &ndata, int dsize) {
if (dsize < dataSize)
ndata = dsize;
else

View File

@ -29,7 +29,7 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
moench03T1ZmqDataNew(int ns = 5000, int oo = 2 * 2)
: slsDetectorData<uint16_t>(400, 400, ns * 32 * 2 + oo), nSamples(ns),
offset(oo), xtalk(0.00021) {
std::cout << "M0.3" << std::endl;
cout << "M0.3" << endl;
int nadc = 32;
int sc_width = 25;
int sc_height = 200;
@ -70,8 +70,8 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
dataMap[row][col] =
(nadc * i + iadc) * 2 + offset; //+16*(ip+1);
if (dataMap[row][col] < 0 || dataMap[row][col] >= dataSize)
std::cout << "Error: pointer " << dataMap[row][col]
<< " out of range " << std::endl;
cout << "Error: pointer " << dataMap[row][col]
<< " out of range " << endl;
}
}
}
@ -260,17 +260,17 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
/* return NULL; */
/* }; */
virtual char *readNextFrame(std::ifstream &filebin) {
virtual char *readNextFrame(ifstream &filebin) {
int ff = -1, np = -1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(std::ifstream &filebin, int &ff) {
virtual char *readNextFrame(ifstream &filebin, int &ff) {
int np = -1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(std::ifstream &filebin, int &ff, int &np) {
virtual char *readNextFrame(ifstream &filebin, int &ff, int &np) {
char *data = new char[32 * 2 * nSamples];
char *d = readNextFrame(filebin, ff, np, data);
if (d == NULL) {
@ -280,7 +280,7 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
return data;
}
virtual char *readNextFrame(std::ifstream &filebin, int &ff, int &np,
virtual char *readNextFrame(ifstream &filebin, int &ff, int &np,
char *data) {
// char *retval=0;
// int nd;

View File

@ -3,9 +3,50 @@
#ifndef MOENCH04ZMQ10GBDATA_H
#define MOENCH04ZMQ10GBDATA_H
#include "slsDetectorData.h"
#include "sls/sls_detector_defs.h"
using namespace std;
#ifndef SLS_DETECTOR_HEADER
#define SLS_DETECTOR_HEADER
//#define VERSION_V2
/**
@short structure for a Detector Packet or Image Header
@li frameNumber is the frame number
@li expLength is the subframe number (32 bit eiger) or real time exposure
time in 100ns (others)
@li packetNumber is the packet number
@li bunchId is the bunch id from beamline
@li timestamp is the time stamp with 10 MHz clock
@li modId is the unique module id (unique even for left, right, top, bottom)
@li xCoord is the x coordinate in the complete detector system
@li yCoord is the y coordinate in the complete detector system
@li zCoord is the z coordinate in the complete detector system
@li debug is for debugging purposes
@li roundRNumber is the round robin set number
@li detType is the detector type see :: detectorType
@li version is the version number of this structure format
*/
typedef struct {
uint64_t frameNumber; /**< is the frame number */
uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time
exposure time in 100ns (others) */
uint32_t packetNumber; /**< is the packet number */
uint64_t bunchId; /**< is the bunch id from beamline */
uint64_t timestamp; /**< is the time stamp with 10 MHz clock */
uint16_t modId; /**< is the unique module id (unique even for left, right,
top, bottom) */
uint16_t xCoord; /**< is the x coordinate in the complete detector system */
uint16_t yCoord; /**< is the y coordinate in the complete detector system */
uint16_t zCoord; /**< is the z coordinate in the complete detector system */
uint32_t debug; /**< is for debugging purposes */
uint16_t roundRNumber; /**< is the round robin set number */
uint8_t detType; /**< is the detector type see :: detectorType */
uint8_t version; /**< is the version number of this structure format */
uint64_t
packetCaught[8]; /**< is the version number of this structure format */
} sls_detector_header;
#endif
class moench04CtbZmq10GbData : public slsDetectorData<uint16_t> {
private:
@ -27,40 +68,67 @@ class moench04CtbZmq10GbData : public slsDetectorData<uint16_t> {
// moench04CtbZmq10GbData(int nas=5000, int nds=0):
// slsDetectorData<uint16_t>(400, 400, nas*2*32+nds*8), aSamples(nas),
// dSamples(nds), nadc(32), sc_width(25), sc_height(200) {
#ifndef RAWDATA
moench04CtbZmq10GbData(int nas = 5000, int nds = 0)
: slsDetectorData<uint16_t>(400, 400,
(nas > 0) && (nds > 0)
? max(nas, nds) * (32 * 2 + 8)
: nas * 32 * 2 + nds * 8),
nadc(32), sc_width(25), sc_height(200), aSamples(nas), dSamples(nds) {
int off = 0;
#endif
#ifdef RAWDATA
moench04CtbZmq10GbData(int nas = 5000, int nds = 0)
: slsDetectorData<uint16_t>(400, 400,
#ifdef RAWDATA
sizeof(slsDetectorDefs::sls_receiver_header) +
#endif
sizeof(sls_detector_header) +
((nas > 0) && (nds > 0)
? max(nas, nds) * (32 * 2 + 8)
: nas * 32 * 2 + nds * 8)),
nadc(32), sc_width(25), sc_height(200), aSamples(nas), dSamples(nds) {
#ifdef RAWDATA
off=sizeof(slsDetectorDefs::sls_receiver_header);
#endif
#ifndef RAWDATA
#ifndef CTB
off=sizeof(int);
#endif
#ifdef CTB
off=0;
#endif
nadc(32), sc_width(25), sc_height(200), aSamples(nas),
dSamples(nds) {
int off = sizeof(sls_detector_header);
cout << "hh" << dataSize << endl;
cout << sizeof(sls_detector_header) +
((nas > 0) && (nds > 0) ? max(nas, nds) * (32 * 2 + 8)
: nas * 32 * 2 + nds * 8)
<< endl;
#endif
/* int ds; */
/* if (nas && nds) */
/* if (nds>nas) */
/* ds=nds*(32*2+8); */
/* else */
/* ds=nas*(32*2+8); */
/* else */
/* ds=nas*32*2+nds*8; */
/* new slsDetectorData<uint16_t>(400, 400, ds); */
cout << "off is " << off << endl;
if (off>0)
cout << "M04 RAW DATA NEW " << endl;
else
cout << "M04 ZMQ DATA NEW " << endl;
int adc_nr[32] = {9, 8, 11, 10, 13, 12, 15, 14, 1, 0, 3,
2, 5, 4, 7, 6, 23, 22, 21, 20, 19, 18,
17, 16, 31, 30, 29, 28, 27, 26, 25, 24};
/*
iadc=ptr%32
isample=ptr/32
col=(adc_nr[iadc]%16)*25+isample%25
if (adc_nr[iadc]<16)
row=199-isample/25;
else
row=200+isample/25
adc0 col(9*25..10*25-1) row(199..0)
adc1 col(8*25..9*25-1) row(199..0)
adc2 col(11*25..12*25-1) row(199..0)
adc3 col(10*25..11*25-1) row(199..0)
adc4 col(13*25..14*25-1) row(199..0)
adc5 col(12*25..13*25-1) row(199..0)
adc6 col(15*25..16*25-1) row(199..0)
adc7 col(14*25..15*25-1) row(199..0)
adc8 col(1*25..2*25-1) row(199..0)
*/
int row, col;
@ -100,11 +168,39 @@ class moench04CtbZmq10GbData : public slsDetectorData<uint16_t> {
}
}
/* for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){ */
/* xmap[ibyte]=-1; */
/* ymap[ibyte]=-1; */
/* } */
/* int off=sizeof(sls_detector_header)/2; */
/* for (ibyte=0; ibyte<dataSize; ibyte++) { */
/* for (ipacket=0; ipacket<npackets; ipacket++) { */
/* for (ibyte=0; ibyte< 8192/2; ibyte++) { */
/* i=ipacket*8208/2+ibyte; */
/* isample=ii/nadc; */
/* if (isample<nSamples) { */
/* iadc=ii%nadc; */
/* adc4 = (int)iadc/4; */
/* ix=isample%sc_width; */
/* iy=isample/sc_width; */
/* if (adc4%2==0) { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2-1-iy; */
/* } else { */
/* xmap[i+off]=adc_nr[iadc]+ix; */
/* ymap[i+off]=ny/2+iy; */
/* } */
/* } */
/* ii++; */
/* // } */
/* } */
/* } */
iframe = 0;
// cout << "data struct created" << endl;
}
}
int getGain(char *data, int x, int y) {
// int aoff=aSamples*2*32;
@ -157,12 +253,10 @@ class moench04CtbZmq10GbData : public slsDetectorData<uint16_t> {
/* unsigned char bunchid[8]; */
/* }; */
int getFrameNumber(char *buff) {
#ifdef RAWDATA
return ((slsDetectorDefs::sls_receiver_header *)buff)->detHeader.frameNumber;
#endif
return (int)(*buff);
};
int getFrameNumber(char *buff) {
return ((sls_detector_header *)buff)->frameNumber;
}; //*((int*)(buff+5))&0xffffff;};
/**
@ -174,15 +268,76 @@ class moench04CtbZmq10GbData : public slsDetectorData<uint16_t> {
*/
int getPacketNumber(char *buff) {
#ifdef RAWDATA
return ((slsDetectorDefs::sls_receiver_header *)buff)->detHeader.packetNumber;
return ((sls_detector_header *)buff)->packetNumber;
} //((*(((int*)(buff+4))))&0xff)+1;};
#endif
return 0;
}
#ifndef RAWDATA
int getFrameNumber(char *buff) {
return iframe;
}; //((sls_detector_header*)buff)->frameNumber;};//*((int*)(buff+5))&0xffffff;};
#endif
/**
Returns the packet number for the given dataset. purely virtual func
\param buff pointer to the dataset
\returns packet number number
*/
// int getPacketNumber(char *buff){return
// ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;};
/* /\** */
/* Loops over a memory slot until a complete frame is found (i.e.
* all packets 0 to nPackets, same frame number). purely virtual func */
/* \param data pointer to the memory to be analyzed */
/* \param ndata reference to the amount of data found for the
* frame, in case the frame is incomplete at the end of the memory slot
*/
/* \param dsize size of the memory slot to be analyzed */
/* \returns pointer to the beginning of the last good frame (might
* be incomplete if ndata smaller than dataSize), or NULL if no frame is
* found */
/* *\/ */
/* virtual char *findNextFrame(char *data, int &ndata, int
* dsize){ndata=dsize; setDataSize(dsize); return data;}; */
/* /\** */
/* Loops over a file stream until a complete frame is found (i.e.
* all packets 0 to nPackets, same frame number). Can be overloaded for
* different kind of detectors! */
/* \param filebin input file stream (binary) */
/* \returns pointer to the begin of the last good frame, NULL if no
* frame is found or last frame is incomplete */
/* *\/ */
/* virtual char *readNextFrame(ifstream &filebin){ */
/* // int afifo_length=0; */
/* uint16_t *afifo_cont; */
/* int ib=0; */
/* if (filebin.is_open()) { */
/* afifo_cont=new uint16_t[dataSize/2]; */
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
/* ib+=2; */
/* if (ib==dataSize) break; */
/* } */
/* if (ib>0) { */
/* iframe++; */
/* // cout << ib << "-" << endl; */
/* return (char*)afifo_cont; */
/* } else { */
/* delete [] afifo_cont; */
/* return NULL; */
/* } */
/* } */
/* return NULL; */
/* }; */
virtual char *readNextFrame(ifstream & filebin) {
int ff = -1, np = -1;
return readNextFrame(filebin, ff, np);
@ -203,12 +358,11 @@ class moench04CtbZmq10GbData : public slsDetectorData<uint16_t> {
return data;
}
#ifndef RAWDATA
virtual char *readNextFrame(ifstream & filebin, int &ff, int &np,
char *data) {
// char *retval=0;
#ifndef RAWDATA
// int nd;
// int fnum = -1;
np = 0;
@ -226,13 +380,19 @@ class moench04CtbZmq10GbData : public slsDetectorData<uint16_t> {
}
}
return NULL;
};
#endif
#ifdef RAWDATA
//int nd;
virtual char *readNextFrame(ifstream & filebin, int &ff, int &np,
char *data) {
char *retval = 0;
int nd;
int fnum = -1;
np = 0;
//int pn;
int pn;
// cout << dataSize << endl;
if (ff >= 0)
@ -246,9 +406,9 @@ class moench04CtbZmq10GbData : public slsDetectorData<uint16_t> {
}
}
return NULL;
};
#endif
};
/**
@ -273,4 +433,3 @@ class moench04CtbZmq10GbData : public slsDetectorData<uint16_t> {
};
#endif

View File

@ -1,216 +0,0 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#ifndef MOENCHDATA_H
#define MOENCHDATA_H
#include "slsDetectorData.h"
#include "sls/sls_detector_defs.h"
using namespace std;
class moenchData : public slsDetectorData<uint16_t> {
private:
int iframe;
int nadc;
int sc_width;
int sc_height;
const int aSamples;
const int dSamples;
int off;
int *adc_nr;
int *ibit;
public:
/**
Implements the slsReceiverData structure for the moench02 prototype read
out by a module i.e. using the slsReceiver (160x160 pixels, 40 packets
1286 large etc.) \param c crosstalk parameter for the output buffer
*/
moenchData(int off, int nadc_i, int *adc_nr_in, int *ibit_in, int nas = 5000, int nds = 0, int nx_i=400, int ny_i=400)
: nadc(nadc_i), slsDetectorData<uint16_t>(nx_i, ny_i,off+((nas > 0) && (nds > 0)
? max(nas, nds) * (nadc_i * 2 + 8)
: nas * nadc_i * 2 + nds * 8)),
sc_width(25), sc_height(200), aSamples(nas), dSamples(nds) {
adc_nr=new int[nadc];
if (ibit_in)
ibit=new int[nadc];
else
ibit=NULL;
for (iadc=0; iadc<nadc; iadc++) {
adc_nr[iadc]=adc_nr_in[iadc];
if (ibit)
ibit[iadc]=ibit_in[iadc];
}
int row, col;
int iadc;
int i;
for (int is = 0; is < aSamples; is++) {
for (iadc = 0; iadc < nadc; iadc++) {
i = is;
// adc4=(int)iadc/4;
if (i < sc_width * sc_height) {
// for (int i=0; i<sc_width*sc_height; i++) {
col = (adc_nr[iadc] % 16) * sc_width + (i % sc_width);
// if (adc4%2==0) {
if (iadc < 16) {
row = 199 - i / sc_width;
} else {
row = 200 + i / sc_width;
}
if (nds > 0)
dataMap[row][col] =
((nadc + 4) * i + iadc) * 2 + off; //+16*(ip+1);
else
dataMap[row][col] =
(nadc * i + iadc) * 2 + off; //+16*(ip+1);
if (dataMap[row][col] < 0 ||
dataMap[row][col] >= aSamples * 2 * 32 + off)
cout << "Error: pointer " << dataMap[row][col]
<< " out of range " << endl;
}
}
}
iframe = 0;
}
virtual int getGain(char *data, int x, int y) {
// int aoff=aSamples*2*32;
if (ibit) {
int irow;
int isc = x / sc_width;
int icol = x % sc_width;
if (y < 200)
irow = sc_height - 1 - y;
else {
irow = y - sc_height;
isc++;
}
int isample = irow * sc_width + icol;
uint64_t sample;
char *ptr;
if (isc < 0 || isc >= 32)
return 0;
if (ibit[isc] < 0 || ibit[isc] >= 64)
return 0;
if (dSamples > isample) {
ptr = data + 32 * (isample + 1) + 8 * isample;
sample = *((uint64_t *)ptr);
if (sample & (1 << ibit[isc]))
return 1;
}
}
return 0;
}
/**
Returns the frame number for the given dataset. Purely virtual func.
\param buff pointer to the dataset
\returns frame number
*/
int getFrameNumber(char *buff) {
return (int* buff)[0];
};
/**
Returns the packet number for the given dataset. purely virtual func
\param buff pointer to the dataset
\returns packet number number
*/
int getPacketNumber(char *buff) {
return 0;
}
virtual char *readNextFrame(ifstream & filebin) {
int ff = -1, np = -1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream & filebin, int &ff) {
int np = -1;
return readNextFrame(filebin, ff, np);
};
virtual char *readNextFrame(ifstream & filebin, int &ff, int &np) {
char *data = new char[dataSize];
char *d = readNextFrame(filebin, ff, np, data);
if (d == NULL) {
delete[] data;
data = NULL;
}
return data;
}
virtual char *readNextFrame(ifstream & filebin, int &ff, int &np,
char *data) {
char *retval = 0;
int nd;
int fnum = -1;
np = 0;
int pn;
// cout << dataSize << endl;
//if (ff >= 0)
// fnum = ff;
if (filebin.is_open()) {
if (filebin.read(data, dataSize)) {
ff = getFrameNumber(data);
np = getPacketNumber(data);
return data;
}
}
return NULL;
};
/**
Loops over a memory slot until a complete frame is found (i.e. all
packets 0 to nPackets, same frame number). purely virtual func \param
data pointer to the memory to be analyzed \param ndata reference to
the amount of data found for the frame, in case the frame is
incomplete at the end of the memory slot \param dsize size of the
memory slot to be analyzed \returns pointer to the beginning of the
last good frame (might be incomplete if ndata smaller than dataSize),
or NULL if no frame is found
*/
virtual char *findNextFrame(char *data, int &ndata, int dsize) {
if (dsize < dataSize)
ndata = dsize;
else
ndata = dataSize;
return data;
}
};
#endif

View File

@ -4,8 +4,11 @@
#define SLSDETECTORDATA_H
#include <fstream>
#include <inttypes.h>
#include <iostream>
using namespace std;
template <class dataType> class slsDetectorData {
protected:
@ -26,11 +29,13 @@ template <class dataType> class slsDetectorData {
public:
/**
General slsDetectors data structure. Works for data acquired using the
General slsDetectors data structure. Works for data acquired using the
slsDetectorReceiver. Can be generalized to other detectors (many virtual
funcs).
Constructor (no error checking if datasize and offsets are compatible!)
Constructor (no error checking if datasize and offsets are compatible!)
\param npx number of pixels in the x direction
\param npy number of pixels in the y direction (1 for strips)
\param dsize size of the data
@ -40,26 +45,309 @@ template <class dataType> class slsDetectorData {
is inversion is required) \param dROI Array of size nx*ny. The elements are
1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL
(default) means all 1s.
*/
slsDetectorData(int npx, int npy, int dsize, int **dMap = NULL,
dataType **dMask = NULL, int **dROI = NULL);
dataType **dMask = NULL, int **dROI = NULL)
: nx(npx), ny(npy), dataSize(dsize), orderedData(NULL), isOrdered(0) {
virtual ~slsDetectorData();
int el = dsize / sizeof(dataType);
xmap = new int[el];
ymap = new int[el];
orderedData = new dataType *[ny];
dataMap = new int *[ny];
dataMask = new dataType *[ny];
dataROIMask = new int *[ny];
for (int i = 0; i < ny; i++) {
dataMap[i] = new int[nx];
orderedData[i] = new dataType[nx];
dataMask[i] = new dataType[nx];
dataROIMask[i] = new int[nx];
for (int j = 0; j < nx; j++)
dataROIMask[i][j] = 1;
}
for (int ip = 0; ip < el; ip++) {
xmap[ip] = -1;
ymap[ip] = -1;
}
setDataMap(dMap);
setDataMask(dMask);
setDataROIMask(dROI);
}
virtual ~slsDetectorData() {
for (int i = 0; i < ny; i++) {
delete[] dataMap[i];
delete[] dataMask[i];
delete[] dataROIMask[i];
delete[] orderedData[i];
}
delete[] dataMap;
delete[] dataMask;
delete[] dataROIMask;
delete[] orderedData;
delete[] xmap;
delete[] ymap;
};
// Virtual functions
virtual int getPointer(int ix, int iy) { return dataMap[iy][ix]; };
virtual void getPixel(int ip, int &x, int &y);
virtual dataType **getData(char *ptr, int dsize = -1);
virtual double **getImage(char *ptr, int dsize = -1);
virtual dataType getChannel(char *data, int ix, int iy = 0);
/**
defines the data map (as offset) - no error checking if datasize and
offsets are compatible! \param dMap array of size nx*ny storing the
pointers to the data in the dataset (as offset). If NULL (default),the
data are arranged as if read out row by row
(dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);)
*/
void setDataMap(int **dMap = NULL) {
int ip = 0;
int ix, iy;
if (dMap == NULL) {
for (iy = 0; iy < ny; iy++) {
for (ix = 0; ix < nx; ix++) {
dataMap[iy][ix] = (iy * nx + ix) * sizeof(dataType);
}
}
} else {
// cout << "set dmap "<< dataMap << " " << dMap << endl;
for (iy = 0; iy < ny; iy++) {
// cout << iy << endl;
for (ix = 0; ix < nx; ix++) {
dataMap[iy][ix] = dMap[iy][ix];
// cout << ix << " " << iy << endl;
/*ip=dataMap[ix][iy]/sizeof(dataType);
xmap[ip]=ix;
ymap[ip]=iy;Annaa*/
}
}
}
for (iy = 0; iy < ny; iy++) {
for (ix = 0; ix < nx; ix++) {
ip = dataMap[iy][ix] / sizeof(dataType);
xmap[ip] = ix;
ymap[ip] = iy;
}
}
// cout << "nx:" <<nx << " ny:" << ny << endl;
};
/**
defines the data mask i.e. the polarity of the data
\param dMask Array of size nx*ny storing the polarity of the data in the
dataset (should be 0 if no inversion is required, 0xffffffff is inversion
is required)
*/
void setDataMask(dataType **dMask = NULL) {
if (dMask != NULL) {
for (int iy = 0; iy < ny; iy++)
for (int ix = 0; ix < nx; ix++)
dataMask[iy][ix] = dMask[iy][ix];
} else {
for (int iy = 0; iy < ny; iy++)
for (int ix = 0; ix < nx; ix++)
dataMask[iy][ix] = 0;
}
};
/**
defines the region of interest and/or the bad channels mask
\param dROI Array of size nx*ny. The lements are 1s if the channel is
good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all
1s.
*/
void setDataROIMask(int **dROI = NULL) {
if (dROI != NULL) {
for (int iy = 0; iy < ny; iy++)
for (int ix = 0; ix < nx; ix++)
dataROIMask[iy][ix] = dROI[iy][ix];
} else {
for (int iy = 0; iy < ny; iy++)
for (int ix = 0; ix < nx; ix++)
dataROIMask[iy][ix] = 1;
}
};
/**
Define bad channel or roi mask for a single channel
\param ix channel x coordinate
\param iy channel y coordinate (1 for strips)
\param i 1 if pixel is good (or in the roi), 0 if bad
\returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range
*/
int setGood(int ix, int iy, int i = 1) {
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny)
dataROIMask[iy][ix] = i;
return isGood(ix, iy);
};
/**
Define bad channel or roi mask for a single channel
\param ix channel x coordinate
\param iy channel y coordinate (1 for strips)
\returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range
*/
int isGood(int ix, int iy) {
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny)
return dataROIMask[iy][ix];
else
return -1;
};
/**
Returns detector size in x,y
\param npx reference to number of channels in x
\param npy reference to number of channels in y (will be 1 for strips)
\returns total number of channels
*/
int getDetectorSize(int &npx, int &npy) {
npx = nx;
npy = ny;
return nx * ny;
};
/** Returns the size of the data frame */
int getDataSize() { return dataSize; };
/** changes the size of the data frame */
int setDataSize(int d) {
dataSize = d;
return dataSize;
};
virtual void getPixel(int ip, int &x, int &y) {
x = xmap[ip];
y = ymap[ip];
};
virtual dataType **getData(char *ptr, int dsize = -1) {
int el = dsize / sizeof(dataType);
// dataType **data;
int ix, iy;
// data=new dataType*[ny];
// for(int i = 0; i < ny; i++) {
// data[i]=new dataType[nx];
// }
isOrdered = 0;
if (dsize <= 0 || dsize > dataSize)
dsize = dataSize;
for (int ip = 0; ip < (el); ip++) {
getPixel(ip, ix, iy);
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny) {
// data[iy][ix]=getChannel(ptr,ix,iy);
orderedData[iy][ix] = *(ptr + ip); // getChannel(ptr,ix,iy);
}
}
isOrdered = 1;
return orderedData;
}
void newFrame() { isOrdered = 0; };
virtual double **getImage(char *ptr, int dsize = -1) {
double **data;
int ix, iy;
data = new double *[ny];
for (int i = 0; i < ny; i++) {
data[i] = new double[nx];
}
int el = dsize / sizeof(dataType);
if (dsize <= 0 || dsize > dataSize)
dsize = dataSize;
for (int ip = 0; ip < el; ip++) {
getPixel(ip, ix, iy);
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny) {
data[iy][ix] = getValue(ptr, ix, iy);
}
}
return data;
};
/**
Returns the value of the selected channel for the given dataset. Virtual
function, can be overloaded. \param data pointer to the dataset
(including headers etc) \param ix pixel number in the x direction \param
iy pixel number in the y direction \returns data for the selected
channel, with inversion if required
*/
virtual dataType getChannel(char *data, int ix, int iy = 0) {
dataType m = 0, d = 0;
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny && dataMap[iy][ix] >= 0 &&
dataMap[iy][ix] < dataSize) {
// cout << ix << " " << iy << " " ;
// cout << dataMap[ix][iy] << " " << (void*)data << " " <<
// dataSize<< endl;
m = dataMask[iy][ix];
if (isOrdered == 0)
d = *((dataType *)(data + getPointer(ix, iy)));
else
d = orderedData[iy][ix];
}
return d ^ m;
};
virtual int getGain(char *data, int ix, int iy = 0) { return 0; };
/**
Returns the value of the selected channel for the given dataset. Virtual
function, can be overloaded. \param data pointer to the dataset
(including headers etc) \param ix pixel number in the x direction \param
iy pixel number in the y direction \returns data for the selected
channel, with inversion if required or -1 if its a missing packet
*/
virtual int getChannelwithMissingPackets(char *data, int ix, int iy) {
return 0;
};
/**
Returns the value of the selected channel for the given dataset as
double. \param data pointer to the dataset (including headers etc) \param
ix pixel number in the x direction \param iy pixel number in the y
direction \returns data for the selected channel, with inversion if
required as double
*/
virtual double getValue(char *data, int ix, int iy = 0) {
/* cout << " x "<< ix << " y"<< iy << " val " << getChannel(data, ix,
* iy)<< endl;*/
return (double)getChannel(data, ix, iy);
};
virtual int getFrameNumber(char *buff) = 0;
/**
Returns the frame number for the given dataset. Purely virtual func.
\param buff pointer to the dataset
\returns frame number
*/
virtual int getFrameNumber(char *buff) = 0;
/**
Returns the packet number for the given dataset. purely virtual func
\param buff pointer to the dataset
\returns packet number number
virtual int getPacketNumber(char *buff)=0;
*/
/**
Loops over a memory slot until a complete frame is found (i.e. all
packets 0 to nPackets, same frame number). purely virtual func \param
data pointer to the memory to be analyzed \param ndata reference to the
@ -72,276 +360,16 @@ template <class dataType> class slsDetectorData {
*/
virtual char *findNextFrame(char *data, int &ndata, int dsize) = 0;
//Returns a pointer to the next complete frame, if none found nullptr
//data needs to be deallocated by caller
virtual char *readNextFrame(std::ifstream &filebin) = 0;
//END Virtual functions
/**
defines the data map (as offset) - no error checking if datasize and
offsets are compatible! \param dMap array of size nx*ny storing the
pointers to the data in the dataset (as offset). If NULL (default),the
data are arranged as if read out row by row
(dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);)
*/
void setDataMap(int **dMap = NULL);
/**
defines the data mask i.e. the polarity of the data
\param dMask Array of size nx*ny storing the polarity of the data in the
dataset (should be 0 if no inversion is required, 0xffffffff is inversion
is required)
Loops over a file stream until a complete frame is found (i.e. all packets
0 to nPackets, same frame number). Can be overloaded for different kind of
detectors! \param filebin input file stream (binary) \returns pointer to
the begin of the last good frame, NULL if no frame is found or last frame
is incomplete
*/
void setDataMask(dataType **dMask = NULL);
/**
defines the region of interest and/or the bad channels mask
\param dROI Array of size nx*ny. The ements are 1s if the channel is
good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all
1s.
*/
void setDataROIMask(int **dROI = NULL);
/**
Define bad channel or roi mask for a single channel
\param ix channel x coordinate
\param iy channel y coordinate (1 for strips)
\param i 1 if pixel is good (or in the roi), 0 if bad
\returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range
*/
int setGood(int ix, int iy, int i = 1);
// returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range
int isGood(int ix, int iy);
// returns total number of channels, outparam npx and npy x,y dimensions
int getDetectorSize(int &npx, int &npy);
/** Returns the size of the data frame */
int getDataSize() { return dataSize; };
/** changes the size of the data frame */
int setDataSize(int d) {
dataSize = d;
return dataSize;
};
void newFrame() { isOrdered = 0; };
/**
Returns the value of the selected channel for the given dataset. Virtual
function, can be overloaded. \param data pointer to the dataset
(including headers etc) \param ix pixel number in the x direction \param
iy pixel number in the y direction \returns data for the selected
channel, with inversion if required
*/
};
template <typename dataType>
slsDetectorData<dataType>::slsDetectorData(int npx, int npy, int dsize,
int **dMap, dataType **dMask,
int **dROI)
: nx(npx), ny(npy), dataSize(dsize), orderedData(NULL), isOrdered(0) {
int el = dsize / sizeof(dataType);
xmap = new int[el];
ymap = new int[el];
orderedData = new dataType *[ny];
dataMap = new int *[ny];
dataMask = new dataType *[ny];
dataROIMask = new int *[ny];
for (int i = 0; i < ny; i++) {
dataMap[i] = new int[nx];
orderedData[i] = new dataType[nx];
dataMask[i] = new dataType[nx];
dataROIMask[i] = new int[nx];
for (int j = 0; j < nx; j++)
dataROIMask[i][j] = 1;
}
for (int ip = 0; ip < el; ip++) {
xmap[ip] = -1;
ymap[ip] = -1;
}
setDataMap(dMap);
setDataMask(dMask);
setDataROIMask(dROI);
}
template <typename dataType> slsDetectorData<dataType>::~slsDetectorData() {
for (int i = 0; i < ny; i++) {
delete[] dataMap[i];
delete[] dataMask[i];
delete[] dataROIMask[i];
delete[] orderedData[i];
}
delete[] dataMap;
delete[] dataMask;
delete[] dataROIMask;
delete[] orderedData;
delete[] xmap;
delete[] ymap;
}
template <typename dataType>
void slsDetectorData<dataType>::setDataMap(int **dMap) {
int ip = 0;
int ix, iy;
if (dMap == NULL) {
for (iy = 0; iy < ny; iy++) {
for (ix = 0; ix < nx; ix++) {
dataMap[iy][ix] = (iy * nx + ix) * sizeof(dataType);
}
}
} else {
// cout << "set dmap "<< dataMap << " " << dMap << endl;
for (iy = 0; iy < ny; iy++) {
// cout << iy << endl;
for (ix = 0; ix < nx; ix++) {
dataMap[iy][ix] = dMap[iy][ix];
// cout << ix << " " << iy << endl;
/*ip=dataMap[ix][iy]/sizeof(dataType);
xmap[ip]=ix;
ymap[ip]=iy;Annaa*/
}
}
}
for (iy = 0; iy < ny; iy++) {
for (ix = 0; ix < nx; ix++) {
ip = dataMap[iy][ix] / sizeof(dataType);
xmap[ip] = ix;
ymap[ip] = iy;
}
}
// cout << "nx:" <<nx << " ny:" << ny << endl;
}
template <typename dataType>
void slsDetectorData<dataType>::setDataMask(dataType **dMask) {
if (dMask != NULL) {
for (int iy = 0; iy < ny; iy++)
for (int ix = 0; ix < nx; ix++)
dataMask[iy][ix] = dMask[iy][ix];
} else {
for (int iy = 0; iy < ny; iy++)
for (int ix = 0; ix < nx; ix++)
dataMask[iy][ix] = 0;
}
}
template <typename dataType>
void slsDetectorData<dataType>::setDataROIMask(int **dROI) {
if (dROI != NULL) {
for (int iy = 0; iy < ny; iy++)
for (int ix = 0; ix < nx; ix++)
dataROIMask[iy][ix] = dROI[iy][ix];
} else {
for (int iy = 0; iy < ny; iy++)
for (int ix = 0; ix < nx; ix++)
dataROIMask[iy][ix] = 1;
}
}
template <typename dataType>
int slsDetectorData<dataType>::setGood(int ix, int iy, int i) {
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny)
dataROIMask[iy][ix] = i;
return isGood(ix, iy);
}
template <typename dataType>
int slsDetectorData<dataType>::isGood(int ix, int iy) {
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny)
return dataROIMask[iy][ix];
else
return -1;
};
template <typename dataType>
int slsDetectorData<dataType>::getDetectorSize(int &npx, int &npy) {
npx = nx;
npy = ny;
return nx * ny;
}
template <typename dataType>
void slsDetectorData<dataType>::getPixel(int ip, int &x, int &y) {
x = xmap[ip];
y = ymap[ip];
}
template <typename dataType>
dataType **slsDetectorData<dataType>::getData(char *ptr, int dsize) {
int el = dsize / sizeof(dataType);
// dataType **data;
int ix, iy;
// data=new dataType*[ny];
// for(int i = 0; i < ny; i++) {
// data[i]=new dataType[nx];
// }
isOrdered = 0;
if (dsize <= 0 || dsize > dataSize)
dsize = dataSize;
for (int ip = 0; ip < (el); ip++) {
getPixel(ip, ix, iy);
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny) {
// data[iy][ix]=getChannel(ptr,ix,iy);
orderedData[iy][ix] = *(ptr + ip); // getChannel(ptr,ix,iy);
}
}
isOrdered = 1;
return orderedData;
}
template <typename dataType>
double **slsDetectorData<dataType>::getImage(char *ptr, int dsize) {
double **data;
int ix, iy;
data = new double *[ny];
for (int i = 0; i < ny; i++) {
data[i] = new double[nx];
}
int el = dsize / sizeof(dataType);
if (dsize <= 0 || dsize > dataSize)
dsize = dataSize;
for (int ip = 0; ip < el; ip++) {
getPixel(ip, ix, iy);
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny) {
data[iy][ix] = getValue(ptr, ix, iy);
}
}
return data;
}
template <typename dataType>
dataType slsDetectorData<dataType>::getChannel(char *data, int ix, int iy) {
dataType m = 0, d = 0;
if (ix >= 0 && ix < nx && iy >= 0 && iy < ny && dataMap[iy][ix] >= 0 &&
dataMap[iy][ix] < dataSize) {
m = dataMask[iy][ix];
if (isOrdered == 0)
d = *((dataType *)(data + getPointer(ix, iy)));
else
d = orderedData[iy][ix];
}
return d ^ m;
virtual char *readNextFrame(ifstream &filebin) = 0;
};
#endif

View File

@ -149,7 +149,7 @@ class interpolatingDetector : public singlePhotonDetector {
{
nph = addFrame(data, val, 1);
if (interp)
return interp->getFlatFieldDistribution();
return interp->getFlatField();
else
return NULL;
};

View File

@ -238,96 +238,96 @@ class eta2InterpolationBase : public virtual etaInterpolationBase {
// cout <<"******"<< etax << " " << etay << endl;
return addToFlatFieldDistribution(etax, etay);
return addToFlatField(etax, etay);
}
/* virtual int addToFlatField(double totquad, int quad, double *cl, */
/* double &etax, double &etay) { */
/* double cc[2][2]; */
/* int xoff = 0, yoff = 0; */
virtual int addToFlatField(double totquad, int quad, double *cl,
double &etax, double &etay) {
double cc[2][2];
int xoff = 0, yoff = 0;
/* switch (quad) { */
/* case BOTTOM_LEFT: */
/* xoff = 0; */
/* yoff = 0; */
/* break; */
/* case BOTTOM_RIGHT: */
/* xoff = 1; */
/* yoff = 0; */
/* break; */
/* case TOP_LEFT: */
/* xoff = 0; */
/* yoff = 1; */
/* break; */
/* case TOP_RIGHT: */
/* xoff = 1; */
/* yoff = 1; */
/* break; */
/* default:; */
/* } */
/* cc[0][0] = cl[xoff + 3 * yoff]; */
/* cc[1][0] = cl[(yoff + 1) * 3 + xoff]; */
/* cc[0][1] = cl[yoff * 3 + xoff + 1]; */
/* cc[1][1] = cl[(yoff + 1) * 3 + xoff + 1]; */
switch (quad) {
case BOTTOM_LEFT:
xoff = 0;
yoff = 0;
break;
case BOTTOM_RIGHT:
xoff = 1;
yoff = 0;
break;
case TOP_LEFT:
xoff = 0;
yoff = 1;
break;
case TOP_RIGHT:
xoff = 1;
yoff = 1;
break;
default:;
}
cc[0][0] = cl[xoff + 3 * yoff];
cc[1][0] = cl[(yoff + 1) * 3 + xoff];
cc[0][1] = cl[yoff * 3 + xoff + 1];
cc[1][1] = cl[(yoff + 1) * 3 + xoff + 1];
/* /\* cout << cl[0] << " " << cl[1] << " " << cl[2] << endl; *\/ */
/* /\* cout << cl[3] << " " << cl[4] << " " << cl[5] << endl; *\/ */
/* /\* cout << cl[6] << " " << cl[7] << " " << cl[8] << endl; *\/ */
/* /\* cout <<"******"<<totquad << " " << quad << endl; *\/ */
/* /\* cout << cc[0][0]<< " " << cc[0][1] << endl; *\/ */
/* /\* cout << cc[1][0]<< " " << cc[1][1] << endl; *\/ */
/* // calcMyEta(totquad,quad,cl,etax, etay); */
/* calcEta(totquad, cc, etax, etay); */
/* cout << cl[0] << " " << cl[1] << " " << cl[2] << endl; */
/* cout << cl[3] << " " << cl[4] << " " << cl[5] << endl; */
/* cout << cl[6] << " " << cl[7] << " " << cl[8] << endl; */
/* cout <<"******"<<totquad << " " << quad << endl; */
/* cout << cc[0][0]<< " " << cc[0][1] << endl; */
/* cout << cc[1][0]<< " " << cc[1][1] << endl; */
// calcMyEta(totquad,quad,cl,etax, etay);
calcEta(totquad, cc, etax, etay);
/* // cout <<"******"<< etax << " " << etay << endl; */
// cout <<"******"<< etax << " " << etay << endl;
/* return addToFlatFieldDistribution(etax, etay); */
/* } */
return addToFlatField(etax, etay);
}
//////////////////////////////////////////////////////////////////////////////////////
/* virtual int addToFlatField(double *cluster, double &etax, double &etay) { */
/* double sDum[2][2]; */
/* double tot, totquad; */
/* // int corner; */
/* // corner= */
/* calcQuad(cluster, tot, totquad, sDum); */
virtual int addToFlatField(double *cluster, double &etax, double &etay) {
double sDum[2][2];
double tot, totquad;
// int corner;
// corner=
calcQuad(cluster, tot, totquad, sDum);
/* // double xpos_eta,ypos_eta; */
/* // double dX,dY; */
// double xpos_eta,ypos_eta;
// double dX,dY;
/* calcEta(totquad, sDum, etax, etay); */
calcEta(totquad, sDum, etax, etay);
/* return addToFlatField(etax, etay); */
/* }; */
return addToFlatField(etax, etay);
};
/* virtual int addToFlatField(int *cluster, double &etax, double &etay) { */
/* double sDum[2][2]; */
/* double tot, totquad; */
/* // int corner; */
/* // corner= */
/* calcQuad(cluster, tot, totquad, sDum); */
virtual int addToFlatField(int *cluster, double &etax, double &etay) {
double sDum[2][2];
double tot, totquad;
// int corner;
// corner=
calcQuad(cluster, tot, totquad, sDum);
/* // double xpos_eta,ypos_eta; */
/* // double dX,dY; */
// double xpos_eta,ypos_eta;
// double dX,dY;
/* calcEta(totquad, sDum, etax, etay); */
calcEta(totquad, sDum, etax, etay);
/* return addToFlatField(etax, etay); */
/* }; */
return addToFlatField(etax, etay);
};
/* virtual int addToFlatFieldDistribution(double etax, double etay) { */
/* #ifdef MYROOT1 */
/* heta->Fill(etax, etay); */
/* #endif */
/* #ifndef MYROOT1 */
/* int ex, ey; */
/* ex = (etax - etamin) / etastepX; */
/* ey = (etay - etamin) / etastepY; */
/* if (ey < nbetaY && ex < nbetaX && ex >= 0 && ey >= 0) */
/* heta[ey * nbetaX + ex]++; */
/* #endif */
/* return 0; */
/* }; */
virtual int addToFlatField(double etax, double etay) {
#ifdef MYROOT1
heta->Fill(etax, etay);
#endif
#ifndef MYROOT1
int ex, ey;
ex = (etax - etamin) / etastepX;
ey = (etay - etamin) / etastepY;
if (ey < nbetaY && ex < nbetaX && ex >= 0 && ey >= 0)
heta[ey * nbetaX + ex]++;
#endif
return 0;
};
virtual int *getInterpolatedImage() {
int ipx, ipy;

View File

@ -205,44 +205,44 @@ class eta3InterpolationBase : public virtual etaInterpolationBase {
double &etay) {
calcEta3(cl, etax, etay, totquad);
return addToFlatFieldDistribution(etax, etay);
return addToFlatField(etax, etay);
}
/* virtual int addToFlatField(double totquad, int quad, double *cl, */
/* double &etax, double &etay) { */
virtual int addToFlatField(double totquad, int quad, double *cl,
double &etax, double &etay) {
/* calcEta3(cl, etax, etay, totquad); */
/* return addToFlatField(etax, etay); */
/* } */
calcEta3(cl, etax, etay, totquad);
return addToFlatField(etax, etay);
}
//////////////////////////////////////////////////////////////////////////////////////
/* virtual int addToFlatField(double *cluster, double &etax, double &etay) { */
/* double totquad; */
/* calcEta3(cluster, etax, etay, totquad); */
/* return addToFlatField(etax, etay); */
/* }; */
virtual int addToFlatField(double *cluster, double &etax, double &etay) {
double totquad;
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax, etay);
};
/* virtual int addToFlatField(int *cluster, double &etax, double &etay) { */
virtual int addToFlatField(int *cluster, double &etax, double &etay) {
/* double totquad; */
double totquad;
/* calcEta3(cluster, etax, etay, totquad); */
/* return addToFlatField(etax, etay); */
/* }; */
calcEta3(cluster, etax, etay, totquad);
return addToFlatField(etax, etay);
};
/* virtual int addToFlatField(double etax, double etay) { */
/* #ifdef MYROOT1 */
/* heta->Fill(etax, etay); */
/* #endif */
/* #ifndef MYROOT1 */
/* int ex, ey; */
/* ex = (etax - etamin) / etastepX; */
/* ey = (etay - etamin) / etastepY; */
/* if (ey < nbetaY && ex < nbetaX && ex >= 0 && ey >= 0) */
/* heta[ey * nbetaX + ex]++; */
/* #endif */
/* return 0; */
/* }; */
virtual int addToFlatField(double etax, double etay) {
#ifdef MYROOT1
heta->Fill(etax, etay);
#endif
#ifndef MYROOT1
int ex, ey;
ex = (etax - etamin) / etastepX;
ey = (etay - etamin) / etastepY;
if (ey < nbetaY && ex < nbetaX && ex >= 0 && ey >= 0)
heta[ey * nbetaX + ex]++;
#endif
return 0;
};
/* protected: */

View File

@ -3,7 +3,7 @@
#ifndef ETA_INTERPOLATION_ADAPTIVEBINS_H
#define ETA_INTERPOLATION_ADAPTIVEBINS_H
#include "sls/tiffIO.h"
#include "tiffIO.h"
#include <cmath>
//#include "etaInterpolationBase.h"
#include "etaInterpolationPosXY.h"

View File

@ -10,7 +10,7 @@
#include <TTree.h>
#endif
#include "slsInterpolation.h"
#include "sls/tiffIO.h"
#include "tiffIO.h"
#include <cmath>
class etaInterpolationBase : public slsInterpolation {
@ -128,7 +128,7 @@ class etaInterpolationBase : public slsInterpolation {
return NULL;
};
void *readFlatField(const char *imgname, double emin = 1, double emax = 0) {
int readFlatField(const char *imgname, double emin = 1, double emax = 0) {
if (emax >= 1)
etamax = emax;
if (emin <= 0)
@ -169,9 +169,9 @@ class etaInterpolationBase : public slsInterpolation {
}
}
delete[] gm;
return heta;
return 1;
}
return NULL;
return 0;
};
float *gethhx() {
@ -183,17 +183,12 @@ class etaInterpolationBase : public slsInterpolation {
// hhy->Scale((double)nSubPixels);
return hhy;
};
virtual int addToFlatFieldDistribution(double etax, double etay) {
#ifdef MYROOT1
heta->Fill(etax, etay);
#endif
#ifndef MYROOT1
virtual int addToFlatField(double etax, double etay) {
int ex, ey;
ex = (etax - etamin) / etastepX;
ey = (etay - etamin) / etastepY;
if (ey < nbetaY && ex < nbetaX && ex >= 0 && ey >= 0)
heta[ey * nbetaX + ex]++;
#endif
return 0;
};

View File

@ -3,7 +3,7 @@
#ifndef ETA_INTERPOLATION_CLEVER_ADAPTIVEBINS_H
#define ETA_INTERPOLATION_CLEVER_ADAPTIVEBINS_H
#include "sls/tiffIO.h"
#include "tiffIO.h"
#include <cmath>
//#include "etaInterpolationBase.h"
#include "etaInterpolationAdaptiveBins.h"

View File

@ -3,7 +3,7 @@
#ifndef ETA_INTERPOLATION_POSXY_H
#define ETA_INTERPOLATION_POSXY_H
//#include "sls/tiffIO.h"
//#include "tiffIO.h"
#include "eta2InterpolationBase.h"
#include "eta3InterpolationBase.h"
#include "etaInterpolationBase.h"

View File

@ -3,7 +3,7 @@
#ifndef ETA_INTERPOLATION_RANDOMBINS_H
#define ETA_INTERPOLATION_RANDOMBINS_H
#include "sls/tiffIO.h"
#include "tiffIO.h"
//#include "etaInterpolationBase.h"
#include "etaInterpolationPosXY.h"
#include <algorithm>

View File

@ -78,20 +78,20 @@ class noInterpolation : public slsInterpolation {
};
//////////////////////////////////////////////////////////////////////////////////////
/* virtual int addToFlatField(double *cluster, double &etax, double &etay) { */
/* return 0; */
/* }; */
virtual int addToFlatField(double *cluster, double &etax, double &etay) {
return 0;
};
/* virtual int addToFlatField(int *cluster, double &etax, double &etay) { */
/* return 0; */
/* }; */
virtual int addToFlatField(int *cluster, double &etax, double &etay) {
return 0;
};
virtual int addToFlatFieldDistribution(double etax, double etay) { return 0; };
virtual int addToFlatField(double etax, double etay) { return 0; };
/* virtual int addToFlatField(double totquad, int quad, double *cl, */
/* double &etax, double &etay) { */
/* return 0; */
/* }; */
virtual int addToFlatField(double totquad, int quad, double *cl,
double &etax, double &etay) {
return 0;
};
virtual int addToFlatField(double totquad, int quad, int *cl, double &etax,
double &etay) {

View File

@ -5,7 +5,7 @@
#include <cstdlib>
#ifndef MY_TIFF_IO_H
#include "sls/tiffIO.h"
#include "tiffIO.h"
#endif
#ifndef DEF_QUAD
@ -175,31 +175,29 @@ class slsInterpolation {
return hint;
};
//virtual int addToFlatField(double *cluster, double &etax, double &etay) = 0;
//virtual int addToFlatField(int *cluster, double &etax, double &etay) = 0;
virtual int addToFlatField(double *cluster, double &etax, double &etay) = 0;
virtual int addToFlatField(int *cluster, double &etax, double &etay) = 0;
virtual int addToFlatField(double totquad, int quad, int *cl, double &etax,
double &etay) = 0;
//virtual int addToFlatField(double totquad, int quad, double *cluster,
// double &etax, double &etay) = 0;
virtual int addToFlatFieldDistribution(double etax, double etay) = 0;
virtual int addToFlatField(double totquad, int quad, double *cluster,
double &etax, double &etay) = 0;
virtual int addToFlatField(double etax, double etay) = 0;
virtual int *getFlatFieldDistribution() { return NULL; };
virtual int *setFlatField(int *h, int nbx = -1, int nby = -1,
double emin = -1,
virtual int *getFlatField() { return NULL; };
virtual int *setFlatField(int *h, int nb = -1, double emin = -1,
double emax = -1) {
return NULL;
};
virtual void *writeFlatField(const char *imgname) { return NULL; };
virtual void *readFlatField(const char *imgname,
double emin = 1, double emax = 0) {
virtual void *readFlatField(const char *imgname, int nb = -1,
double emin = 1, double emax = 0) {
return NULL;
};
virtual int *getFlatField(int &nbx, int &nby, double &emin, double &emax) {
nbx = 0;
nby=0;
virtual int *getFlatField(int &nb, double &emin, double &emax) {
nb = 0;
emin = 0;
emax = 0;
return getFlatFieldDistribution();
return getFlatField();
};
virtual void resetFlatField() = 0;

View File

@ -23,7 +23,7 @@
#endif
#include "moench03CommonMode.h"
#include "moench03GhostSummation.h"
#include "sls/tiffIO.h"
#include "tiffIO.h"
#include <fstream>
#include <iomanip>
#include <sstream>

View File

@ -20,7 +20,7 @@ class commonModeSubtractionColumn : public commonModeSubtraction {
mean2[iroi] += val * val;
nCm[iroi]++;
if (nCm[iroi] > rows)
std::cout << "Too many pixels added " << nCm[iroi] << std::endl;
cout << "Too many pixels added " << nCm[iroi] << endl;
/* if (ix==10 && iy<20) */
/* cout << " ** "<<val << " " << mean[iroi] << " " <<
* nCm[iroi] << " " << getCommonMode(ix, iy) << endl; */

View File

@ -1,52 +1,57 @@
# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package
find_package(TIFF REQUIRED)
set(MOENCH_EXECUTABLES)
#Moench ZMQ
add_executable(moench03ZmqProcess moenchZmqProcess.cpp)
target_compile_definitions(moench03ZmqProcess PRIVATE NEWZMQ INTERP)
list(APPEND MOENCH_EXECUTABLES moench03ZmqProcess)
#Moench HighZ ZMQ
add_executable(moenchHighZZmqProcess moenchZmqProcess.cpp)
target_compile_definitions(moenchHighZZmqProcess PRIVATE NEWZMQ INTERP HIGHZ)
list(APPEND MOENCH_EXECUTABLES moenchHighZZmqProcess)
add_executable(moenchZmqProcess moenchZmqProcess.cpp ../tiffIO.cpp)
target_compile_definitions(moenchZmqProcess PRIVATE NEWZMQ INTERP)
list(APPEND MOENCH_EXECUTABLES moenchZmqProcess)
#Moench04 ZMQ
add_executable(moench04ZmqProcess moenchZmqProcess.cpp)
add_executable(moench04ZmqProcess moenchZmqProcess.cpp ../tiffIO.cpp)
target_compile_definitions(moench04ZmqProcess PRIVATE NEWZMQ INTERP MOENCH04)
list(APPEND MOENCH_EXECUTABLES moench04ZmqProcess)
#OFFLINE Processing?
add_executable(moench03RawDataProcess moenchRawDataProcess.cpp)
target_compile_definitions(moench03RawDataProcess PRIVATE)
list(APPEND MOENCH_EXECUTABLES moench03RawDataProcess)
add_executable(moenchClusterFinder moench03ClusterFinder.cpp ../tiffIO.cpp)
target_compile_definitions(moenchClusterFinder PRIVATE SAVE_ALL NEWRECEIVER)
list(APPEND MOENCH_EXECUTABLES moenchClusterFinder)
add_executable(moenchHighZRawDataProcess moenchRawDataProcess.cpp)
target_compile_definitions(moenchHighZRawDataProcess PRIVATE HIGHZ)
list(APPEND MOENCH_EXECUTABLES moenchHighZRawDataProcess)
add_executable(moenchClusterFinderHighZ moench03ClusterFinder.cpp ../tiffIO.cpp)
target_compile_definitions(moenchClusterFinderHighZ PRIVATE SAVE_ALL NEWRECEIVER HIGHZ)
list(APPEND MOENCH_EXECUTABLES moenchClusterFinderHighZ)
add_executable(moench04RawDataProcess moenchRawDataProcess.cpp)
target_compile_definitions(moench04RawDataProcess PRIVATE MOENCH04)
list(APPEND MOENCH_EXECUTABLES moench04RawDataProcess)
add_executable(moenchMakeEta moench03Interpolation.cpp ../tiffIO.cpp)
target_compile_definitions(moenchMakeEta PRIVATE FF)
list(APPEND MOENCH_EXECUTABLES moenchMakeEta)
#interpolation stuff
add_executable(moench03MakeEta moench03Interpolation.cpp)
target_compile_definitions(moench03MakeEta PRIVATE FF)
list(APPEND MOENCH_EXECUTABLES moench03MakeEta)
add_executable(moench03Interpolation moench03Interpolation.cpp)
add_executable(moenchInterpolation moench03Interpolation.cpp ../tiffIO.cpp)
#no compile defs
list(APPEND MOENCH_EXECUTABLES moench03Interpolation)
list(APPEND MOENCH_EXECUTABLES moenchInterpolation)
add_executable(moench03NoInterpolation moench03NoInterpolation.cpp)
add_executable(moenchNoInterpolation moench03NoInterpolation.cpp ../tiffIO.cpp)
#no compile defs
list(APPEND MOENCH_EXECUTABLES moench03NoInterpolation)
list(APPEND MOENCH_EXECUTABLES moenchNoInterpolation)
add_executable(moenchPhotonCounter moenchPhotonCounter.cpp ../tiffIO.cpp)
target_compile_definitions(moenchPhotonCounter PRIVATE NEWRECEIVER)
list(APPEND MOENCH_EXECUTABLES moenchPhotonCounter)
add_executable(moenchAnalog moenchPhotonCounter.cpp ../tiffIO.cpp)
target_compile_definitions(moenchAnalog PRIVATE NEWRECEIVER ANALOG)
list(APPEND MOENCH_EXECUTABLES moenchAnalog)
add_executable(moenchPhotonCounterHighZ moenchPhotonCounter.cpp ../tiffIO.cpp)
target_compile_definitions(moenchPhotonCounterHighZ PRIVATE NEWRECEIVER HIGHZ)
list(APPEND MOENCH_EXECUTABLES moenchPhotonCounterHighZ)
add_executable(moenchAnalogHighZ moenchPhotonCounter.cpp ../tiffIO.cpp)
target_compile_definitions(moenchAnalogHighZ PRIVATE NEWRECEIVER ANALOG HIGHZ)
list(APPEND MOENCH_EXECUTABLES moenchAnalogHighZ)
foreach(exe ${MOENCH_EXECUTABLES})
@ -56,7 +61,6 @@ foreach(exe ${MOENCH_EXECUTABLES})
../dataStructures
../interpolations
../../slsReceiverSoftware/include/
../../slsSupportLib/include/
)
target_link_libraries(${exe}
@ -64,11 +68,10 @@ foreach(exe ${MOENCH_EXECUTABLES})
slsSupportStatic
${ZeroMQ_LIBRARIES}
pthread
tiffio
TIFF::TIFF
PRIVATE
slsProjectWarnings
slsProjectOptions
)
@ -80,6 +83,8 @@ foreach(exe ${MOENCH_EXECUTABLES})
endif()
endforeach(exe ${MOENCH_EXECUTABLES})
install(TARGETS ${MOENCH_EXECUTABLES} DESTINATION bin)

View File

@ -0,0 +1,219 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
//#include "sls/ansi.h"
#include <iostream>
//#include "moench03T1ZmqData.h"
#ifdef NEWRECEIVER
#ifndef RECT
#include "moench03T1ReceiverDataNew.h"
#endif
#ifdef RECT
#include "moench03T1ReceiverDataNewRect.h"
#endif
#endif
#ifdef CSAXS_FP
#include "moench03T1ReceiverData.h"
#endif
#ifdef OLDDATA
#include "moench03Ctb10GbT1Data.h"
#endif
#ifdef REORDERED
#include "moench03T1ReorderedData.h"
#endif
// #include "interpolatingDetector.h"
//#include "etaInterpolationPosXY.h"
// #include "linearInterpolation.h"
// #include "noInterpolation.h"
#include "multiThreadedAnalogDetector.h"
#include "singlePhotonDetector.h"
//#include "interpolatingDetector.h"
#include <fstream>
#include <map>
#include <stdio.h>
#include <sys/stat.h>
#include <ctime>
using namespace std;
int main(int argc, char *argv[]) {
if (argc < 6) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax "
<< endl;
return 1;
}
int p = 10000;
int fifosize = 1000;
int nthreads = 1;
int nsubpix = 25;
int etabins = nsubpix * 10;
double etamin = -1, etamax = 2;
int csize = 3;
int nx = 400, ny = 400;
int save = 1;
int nsigma = 5;
int nped = 1000;
int ndark = 100;
int ok;
int iprog = 0;
#ifdef NEWRECEIVER
#ifdef RECT
cout << "Should be rectangular!" << endl;
#endif
moench03T1ReceiverDataNew *decoder = new moench03T1ReceiverDataNew();
cout << "RECEIVER DATA WITH ONE HEADER!" << endl;
#endif
#ifdef CSAXS_FP
moench03T1ReceiverData *decoder = new moench03T1ReceiverData();
cout << "RECEIVER DATA WITH ALL HEADERS!" << endl;
#endif
#ifdef OLDDATA
moench03Ctb10GbT1Data *decoder = new moench03Ctb10GbT1Data();
cout << "OLD RECEIVER DATA!" << endl;
#endif
#ifdef REORDERED
moench03T1ReorderedData *decoder = new moench03T1ReorderedData();
cout << "REORDERED DATA!" << endl;
#endif
decoder->getDetectorSize(nx, ny);
cout << "nx " << nx << " ny " << ny << endl;
// moench03T1ZmqData *decoder=new moench03T1ZmqData();
singlePhotonDetector *filter =
new singlePhotonDetector(decoder, csize, nsigma, 1, 0, nped, 200);
// char tit[10000];
cout << "filter " << endl;
// filter->readPedestals("/scratch/ped_100.tiff");
// interp->readFlatField("/scratch/eta_100.tiff",etamin,etamax);
// cout << "filter "<< endl;
int size = 327680; ////atoi(argv[3]);
int *image;
// int* image =new int[327680/sizeof(int)];
filter->newDataSet();
int ff, np;
int dsize = decoder->getDataSize();
cout << " data size is " << dsize;
char data[dsize];
ifstream filebin;
char *indir = argv[1];
char *outdir = argv[2];
char *fformat = argv[3];
int runmin = atoi(argv[4]);
int runmax = atoi(argv[5]);
char fname[10000];
char outfname[10000];
char imgfname[10000];
char pedfname[10000];
// strcpy(pedfname,argv[6]);
char fn[10000];
std::time_t end_time;
FILE *of = NULL;
cout << "input directory is " << indir << endl;
cout << "output directory is " << outdir << endl;
cout << "fileformat is " << fformat << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char *buff;
multiThreadedAnalogDetector *mt =
new multiThreadedAnalogDetector(filter, nthreads, fifosize);
mt->setDetectorMode(ePhotonCounting);
mt->setFrameMode(eFrame);
mt->StartThreads();
mt->popFree(buff);
cout << "mt " << endl;
int ifr = 0;
for (int irun = runmin; irun < runmax; irun++) {
sprintf(fn, fformat, irun);
sprintf(fname, "%s/%s.raw", indir, fn);
sprintf(outfname, "%s/%s.clust", outdir, fn);
sprintf(imgfname, "%s/%s.tiff", outdir, fn);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
if (filebin.is_open()) {
of = fopen(outfname, "w");
if (of) {
mt->setFilePointer(of);
// cout << "file pointer set " << endl;
} else {
cout << "Could not open " << outfname << " for writing "
<< endl;
mt->setFilePointer(NULL);
return 1;
}
// //while read frame
ff = -1;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
// cout << "*"<<ifr++<<"*"<<ff<< endl;
// cout << ff << " " << np << endl;
// //push
// for (int ix=0; ix<400; ix++)
// for (int iy=0; iy<400; iy++) {
// if (decoder->getChannel(buff, ix, iy)<3000 ||
// decoder->getChannel(buff, ix, iy)>8000) {
// cout << ifr << " " << ff << " " << ix << " " << iy <<
// " " << decoder->getChannel(buff, ix, iy) << endl ;
// }
// }
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ifr++;
if (ifr % 10000 == 0)
cout << ifr << " " << ff << endl;
ff = -1;
}
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
while (mt->isBusy()) {
;
} // wait until all data are processed from the queues
if (of)
fclose(of);
mt->writeImage(imgfname);
mt->clearImage();
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
} else
cout << "Could not open " << fname << " for reading " << endl;
}
return 0;
}

View File

@ -47,6 +47,7 @@ int main(int argc, char *argv[]) {
#endif
int iarg = 4;
char infname[10000];
char fname[10000];
char outfname[10000];
#ifndef FF
iarg = 4;
@ -73,17 +74,18 @@ int main(int argc, char *argv[]) {
int etabins = 1000; // nsubpix*2*100;
double etamin = -1, etamax = 2;
// double etamin=-0.1, etamax=1.1;
// double eta3min = -2, eta3max = 2;
double eta3min = -2, eta3max = 2;
int quad;
double sum, totquad;
double sDum[2][2];
double etax, etay;
// double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y;
double etax, etay, int_x, int_y;
double eta3x, eta3y, int3_x, int3_y, noint_x, noint_y;
int ok;
int f0 = -1;
int ix, iy, isx, isy;
int nframes = 0, lastframe = -1;
//double d_x, d_y, res = 5, xx, yy;
int nph = 0, totph = 0;
//badph = 0,
double d_x, d_y, res = 5, xx, yy;
int nph = 0, badph = 0, totph = 0;
FILE *f = NULL;
#ifdef DOUBLE_SPH
@ -94,8 +96,7 @@ int main(int argc, char *argv[]) {
single_photon_hit cl(3, 3);
#endif
//int f0 = -1;
// int nSubPixels = nsubpix;
int nSubPixels = nsubpix;
#ifndef NOINTERPOLATION
eta2InterpolationPosXY *interp =
new eta2InterpolationPosXY(NC, NR, nsubpix, etabins, etamin, etamax);
@ -108,12 +109,7 @@ int main(int argc, char *argv[]) {
#endif
#ifndef FF
int quad;
#ifndef NOINTERPOLATION
char fname[10000];
int ok;
double int_x, int_y;
int *img;
cout << "read ff " << argv[2] << endl;
sprintf(fname, "%s", argv[2]);
interp->readFlatField(fname);
@ -125,6 +121,7 @@ int main(int argc, char *argv[]) {
cout << "Will write eta file " << argv[2] << endl;
#endif
int *img;
float *totimg = new float[NC * NR * nsubpix * nsubpix];
for (ix = 0; ix < NC; ix++) {
for (iy = 0; iy < NR; iy++) {
@ -152,7 +149,7 @@ int main(int argc, char *argv[]) {
if (f) {
cout << infname << endl;
nframes = 0;
//f0 = -1;
f0 = -1;
while (cl.read(f)) {
totph++;
@ -160,21 +157,14 @@ int main(int argc, char *argv[]) {
lastframe = cl.iframe;
// cout << cl.iframe << endl;
// f0=cl.iframe;
// if (nframes == 0)
// f0 = lastframe;
if (nframes == 0)
f0 = lastframe;
nframes++;
}
// quad=interp->calcQuad(cl.get_cluster(), sum, totquad, sDum);
#ifndef FF
quad = interp->calcEta(cl.get_cluster(), etax, etay, sum,
totquad, sDum);
#endif
#ifdef FF
interp->calcEta(cl.get_cluster(), etax, etay, sum,
totquad, sDum);
#endif
if (sum > cmin && totquad / sum > 0.8 && totquad / sum < 1.2 &&
if (sum > cmin && totquad / sum > 0.8 && totquad / sum < 1.2 &&
sum < cmax) {
nph++;
// if (sum>200 && sum<580) {
@ -209,7 +199,7 @@ int main(int argc, char *argv[]) {
// if (cl.x>50)
// #endif
// if (etax!=0 && etay!=0 && etax!=1 && etay!=1)
interp->addToFlatFieldDistribution(etax, etay);
interp->addToFlatField(etax, etay);
// if (etax==0 || etay==0) cout << cl.x << " " << cl.y <<
// endl;
@ -252,9 +242,9 @@ int main(int argc, char *argv[]) {
}
}
}
// cout << "Read " << nframes << " frames (first frame: " << f0
// << " last frame: " << lastframe << " delta:" << lastframe - f0
// << ") nph=" << nph << endl;
cout << "Read " << nframes << " frames (first frame: " << f0
<< " last frame: " << lastframe << " delta:" << lastframe - f0
<< ") nph=" << nph << endl;
interp->clearInterpolatedImage();
#endif

View File

@ -2,33 +2,43 @@
// Copyright (C) 2021 Contributors to the SLS Detector Package
//#include "sls/ansi.h"
#include <iostream>
#undef CORR
#define CORR
#define C_GHOST 0.0004
#define CM_ROWS 50
#define RAWDATA
//#define VERSION_V1
#ifndef MOENCH04
//#include "moench03T1ZmqData.h"
#ifdef NEWRECEIVER
#ifndef RECT
#include "moench03T1ReceiverDataNew.h"
#endif
#endif
#ifdef RECT
#include "moench03T1ReceiverDataNewRect.h"
#endif
#ifdef MOENCH04
#include "moench04CtbZmq10GbData.h"
#endif
#ifdef CSAXS_FP
#include "moench03T1ReceiverData.h"
#endif
#ifdef OLDDATA
#include "moench03Ctb10GbT1Data.h"
#endif
// #include "interpolatingDetector.h"
//#include "etaInterpolationPosXY.h"
// #include "linearInterpolation.h"
// #include "noInterpolation.h"
#include "multiThreadedCountingDetector.h"
//#include "multiThreadedAnalogDetector.h"
#include "moench03CommonMode.h"
#include "moench03GhostSummation.h"
#include "singlePhotonDetector.h"
//#include "interpolatingDetector.h"
#include <fstream>
#include <map>
@ -42,7 +52,7 @@ int main(int argc, char *argv[]) {
if (argc < 4) {
cout << "Usage is " << argv[0]
<< "indir outdir fname(no extension) [runmin] [runmax] [pedfile (raw or tiff)] [threshold] "
<< "indir outdir fname [runmin] [runmax] [pedfile] [threshold] "
"[nframes] [xmin xmax ymin ymax] [gainmap]"
<< endl;
cout << "threshold <0 means analog; threshold=0 means cluster finder; "
@ -54,39 +64,55 @@ int main(int argc, char *argv[]) {
return 1;
}
int p = 10000;
int fifosize = 1000;
int nthreads = 10;
int nsubpix = 25;
int etabins = nsubpix * 10;
double etamin = -1, etamax = 2;
int csize = 3;
int save = 1;
int nsigma = 5;
int nped = 10000;
int ndark = 100;
int ok;
int iprog = 0;
int cf = 0;
#ifdef NEWRECEIVER
#ifdef RECT
cout << "Should be rectangular but now it will crash! No data structure defined!" << endl;
cout << "Should be rectangular!" << endl;
#endif
#ifndef MOENCH04
moench03T1ReceiverDataNew *decoder = new moench03T1ReceiverDataNew();
cout << "MOENCH03!" << endl;
cout << "RECEIVER DATA WITH ONE HEADER!" << endl;
#endif
#ifdef MOENCH04
moench04CtbZmq10GbData *decoder = new moench04CtbZmq10GbData();
cout << "MOENCH04!" << endl;
#ifdef CSAXS_FP
moench03T1ReceiverData *decoder = new moench03T1ReceiverData();
cout << "RECEIVER DATA WITH ALL HEADERS!" << endl;
#endif
#ifdef OLDDATA
moench03Ctb10GbT1Data *decoder = new moench03Ctb10GbT1Data();
cout << "OLD RECEIVER DATA!" << endl;
#endif
int nx = 400, ny = 400;
decoder->getDetectorSize(nx, ny);
#ifdef CORR
int ncol_cm = CM_ROWS;
double xt_ghost = C_GHOST;
#endif
moench03CommonMode *cm = NULL;
moench03GhostSummation *gs;
double *gainmap = NULL;
//float *gm;
float *gm;
int size = 327680; ////atoi(argv[3]);
int *image;
// int* image =new int[327680/sizeof(int)];
int ff, np;
// cout << " data size is " << dsize;
@ -143,6 +169,7 @@ int main(int argc, char *argv[]) {
char fname[10000];
char imgfname[10000];
char cfname[10000];
char fn[10000];
std::time_t end_time;
@ -159,6 +186,19 @@ int main(int argc, char *argv[]) {
cout << "Nframes is " << nframes << endl;
uint32_t nnx, nny;
double *gmap;
// if (gainfname) {
// gm=ReadFromTiff(gainfname, nny, nnx);
// if (gm && nnx==nx && nny==ny) {
// gmap=new double[nx*ny];
// for (int i=0; i<nx*ny; i++) {
// gmap[i]=gm[i];
// }
// delete gm;
// } else
// cout << "Could not open gain map " << gainfname << endl;
// }
#ifdef CORR
cout << "Applying common mode " << ncol_cm << endl;
@ -180,15 +220,21 @@ int main(int argc, char *argv[]) {
} else
thr = 0.15 * thr;
filter->newDataSet();
//int dsize = decoder->getDataSize();
int dsize = decoder->getDataSize();
char data[dsize];
//#ifndef ANALOG
if (thr > 0) {
cout << "threshold is " << thr << endl;
//#ifndef ANALOG
filter->setThreshold(thr);
//#endif
cf = 0;
} else
cf = 1;
//#endif
filter->setROI(xmin, xmax, ymin, ymax);
std::time(&end_time);
@ -223,7 +269,7 @@ int main(int argc, char *argv[]) {
int ifr = 0;
double *ped=new double[nx * ny];//, *ped1;
double ped[nx * ny], *ped1;
if (pedfile) {
@ -231,10 +277,10 @@ int main(int argc, char *argv[]) {
sprintf(imgfname, "%s/pedestals.tiff", outdir);
if (string(pedfile).find(".tif") == std::string::npos) {
sprintf(fname, "%s", pedfile);
sprintf(fname, "%s.raw", pedfile);
cout << fname << endl;
std::time(&end_time);
//cout << "aaa" << std::ctime(&end_time) << endl;
cout << "aaa" << std::ctime(&end_time) << endl;
mt->setFrameMode(ePedestal);
// sprintf(fn,fformat,irun);
@ -264,12 +310,18 @@ int main(int argc, char *argv[]) {
<< " for reading " << endl;
} else {
float *pp = ReadFromTiff(pedfile, nny, nnx);
if (pp && (int)nnx == nx && (int)nny == ny) {
if (pp && nnx == nx && nny == ny) {
for (int i = 0; i < nx * ny; i++) {
ped[i] = pp[i];
}
delete[] pp;
mt->setPedestal(ped);
// ped1=mt->getPedestal();
// for (int i=0; i<nx*ny; i++) {
// cout << ped[i]<<"/"<<ped1[i] << " " ;
// }
cout << "Pedestal set from tiff file " << pedfile << endl;
} else {
cout << "Could not open pedestal tiff file " << pedfile
@ -290,11 +342,11 @@ int main(int argc, char *argv[]) {
cout << "DATA ";
// sprintf(fn,fformat,irun);
sprintf(ffname, "%s/%s.raw", indir, fformat);
sprintf(fname, (const char*)ffname, irun);
sprintf(fname, ffname, irun);
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
sprintf(imgfname, (const char*)ffname, irun);
sprintf(imgfname, ffname, irun);
sprintf(ffname, "%s/%s.clust", outdir, fformat);
sprintf(cfname, (const char*)ffname, irun);
sprintf(cfname, ffname, irun);
cout << fname << " ";
cout << imgfname << endl;
std::time(&end_time);
@ -323,10 +375,13 @@ int main(int argc, char *argv[]) {
ifr = 0;
while (decoder->readNextFrame(filebin, ff, np, buff)) {
if (np == 40) {
// cout << "*"<<ifr++<<"*"<<ff<< endl;
// cout << ff << " " << np << endl;
// //push
mt->pushData(buff);
// // //pop
mt->nextThread();
// // // cout << " " << (void*)buff;
mt->popFree(buff);
ifr++;
@ -334,9 +389,15 @@ int main(int argc, char *argv[]) {
cout << ifr << " " << ff << endl;
if (nframes > 0) {
if (ifr % nframes == 0) {
// The name has an additional "_fXXXXX" at the end,
// where "XXXXX" is the initial frame number of the
// image (0,1000,2000...)
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat,
ifile);
sprintf(imgfname, (const char*)ffname, irun);
sprintf(imgfname, ffname, irun);
// cout << "Writing tiff to " << imgfname << " " <<
// thr1 << endl;
mt->writeImage(imgfname, thr1);
mt->clearImage();
ifile++;
@ -348,16 +409,18 @@ int main(int argc, char *argv[]) {
}
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
while (mt->isBusy()) {
;
}
if (nframes >= 0) {
if (nframes > 0) {
sprintf(ffname, "%s/%s_f%05d.tiff", outdir, fformat, ifile);
sprintf(imgfname, (const char*)ffname, irun);
sprintf(imgfname, ffname, irun);
} else {
sprintf(ffname, "%s/%s.tiff", outdir, fformat);
sprintf(imgfname, (const char*)ffname, irun);
sprintf(imgfname, ffname, irun);
}
cout << "Writing tiff to " << imgfname << " " << thr1 << endl;
mt->writeImage(imgfname, thr1);

View File

@ -1,9 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
//#define WRITE_QUAD
//#define DEVELOPER
#define DEVELOPER
#undef CORR
//#undef MOENCH04
#undef MOENCH04
#define C_GHOST 0.0004
@ -11,21 +11,21 @@
#include "sls/ZmqSocket.h"
#include "sls/sls_detector_defs.h"
#ifndef RECT
#ifndef MOENCH04
//#ifndef RECT
#include "moench03T1ZmqDataNew.h"
//#endif
//#ifdef RECT
//#include "moench03T1ZmqDataNewRect.h"
//#endif
#endif
#ifdef MOENCH04
#include "moench04CtbZmq10GbData.h"
#endif
#endif
#ifdef RECT
#include "moench03T1ZmqDataNewRect.h"
#endif
#include "moench03CommonMode.h"
#include "moench03GhostSummation.h"
#include "sls/tiffIO.h"
#include "tiffIO.h"
#include <fstream>
#include <iomanip>
#include <sstream>
@ -156,7 +156,7 @@ int main(int argc, char *argv[]) {
int send_something = 0;
int maxSize = npx * npy * 2; // 32*2*8192;//5000;//atoi(argv[3]);
int size = maxSize+sizeof(int); // 32*2*5000;
int size = maxSize; // 32*2*5000;
// int multisize=size;
// int dataSize=size;
@ -305,10 +305,10 @@ int main(int argc, char *argv[]) {
// header variables
uint64_t acqIndex = -1;
uint64_t frameIndex = -1;
// #ifdef MOENCH_BRANCH
// uint32_t subFrameIndex = -1;
// int *flippedData = 0;
// #endif
#ifdef MOENCH_BRANCH
uint32_t subFrameIndex = -1;
int *flippedData = 0;
#endif
uint64_t subframes = 0;
// uint64_t isubframe=0;
@ -502,13 +502,13 @@ int main(int argc, char *argv[]) {
}
#ifdef INTERP
else if (fMode == eFlat) {
int nbx, nby;
int nb;
double emi = 0, ema = 1;
int *ff = mt->getFlatField(nbx, nby, emi, ema);
nnx = nbx;
nny = nby;
dout = new int32_t[nbx * nby];
for (int ix = 0; ix < nbx * nby; ix++) {
int *ff = mt->getFlatField(nb, emi, ema);
nnx = nb;
nny = nb;
dout = new int32_t[nb * nb];
for (int ix = 0; ix < nb * nb; ix++) {
dout[ix] = ff[ix];
}
}

View File

@ -182,10 +182,10 @@ class threadedAnalogDetector {
interp->prepareInterpolation(ok);
}
virtual int *getFlatFieldDistribution() {
virtual int *getFlatField() {
slsInterpolation *interp = (det)->getInterpolation();
if (interp)
return interp->getFlatFieldDistribution();
return interp->getFlatField();
else
return NULL;
}
@ -208,19 +208,19 @@ class threadedAnalogDetector {
return NULL;
}
void *readFlatField(const char *imgname, double emin = 1,
void *readFlatField(const char *imgname, int nb = -1, double emin = 1,
double emax = 0) {
slsInterpolation *interp = (det)->getInterpolation();
if (interp)
return interp->readFlatField(imgname, emin, emax);
return interp->readFlatField(imgname, nb, emin, emax);
return NULL;
}
virtual int *getFlatField(int &nbx, int &nby, double &emi, double &ema) {
virtual int *getFlatField(int &nb, double emi, double ema) {
slsInterpolation *interp = (det)->getInterpolation();
int *ff = NULL;
if (interp) {
ff = interp->getFlatField(nbx, nby, emi, ema);
ff = interp->getFlatField(nb, emi, ema);
}
return ff;
}

View File

@ -25,10 +25,10 @@ class multiThreadedInterpolatingDetector
// }
}
virtual int *getFlatFieldDistribution() { return (dets[0])->getFlatFieldDistribution(); }
virtual int *getFlatField() { return (dets[0])->getFlatField(); }
virtual int *getFlatField(int &nbx, int &nby, double &emi, double &ema) {
return (dets[0])->getFlatField(nbx, nby, emi, ema);
virtual int *getFlatField(int &nb, double emi, double ema) {
return (dets[0])->getFlatField(nb, emi, ema);
}
virtual int *setFlatField(int *h = NULL, int nb = -1, double emin = 1,
@ -40,9 +40,9 @@ class multiThreadedInterpolatingDetector
return dets[0]->writeFlatField(imgname);
};
void *readFlatField(const char *imgname, double emin = 1,
void *readFlatField(const char *imgname, int nb = -1, double emin = 1,
double emax = 0) {
return (dets[0])->readFlatField(imgname, emin, emax);
return (dets[0])->readFlatField(imgname, nb, emin, emax);
};
/* virtual int setNSubPixels(int ns) { return

View File

@ -1,12 +1,26 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "sls/tiffIO.h"
#ifndef MY_TIFF_IO_H
#include "tiffIO.h"
#endif
#include <iostream>
#include <tiffio.h>
using namespace std;
// #undef cbf_failnez
// #define cbf_failnez(x)
// {
// int err;
// err = (x);
// if (err) {
// fprintf(stderr,"\nCBFlib fatal error %x \n",err);
// exit(-1);
// }
// }
void *WriteToTiff(float *imgData, const char *imgname, int nrow, int ncol) {
constexpr uint32_t sampleperpixel = 1;
int sampleperpixel = 1;
// unsigned char * buff=NULL;
// tsize_t linebytes;
// cout << "--" <<endl;
TIFF *tif = TIFFOpen(imgname, "w");
if (tif) {
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, ncol);
@ -17,32 +31,50 @@ void *WriteToTiff(float *imgData, const char *imgname, int nrow, int ncol) {
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
// linebytes = sampleperpixel*ncol;
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP,
TIFFDefaultStripSize(tif, ncol * sampleperpixel));
for (int irow = 0; irow < nrow; irow++) {
TIFFWriteScanline(tif, &imgData[irow * ncol], irow, 0);
}
TIFFClose(tif);
} else {
std::cout << "could not open file " << imgname << " for writing\n";
}
return nullptr;
}
} else
cout << "could not open file " << imgname << " for writing " << endl;
return NULL;
};
float *ReadFromTiff(const char *imgname, uint32_t &nrow, uint32_t &ncol) {
// unsigned char * buff=NULL;
TIFF *tif = TIFFOpen(imgname, "r");
if (tif) {
uint32_t bps;
uint32_t sampleperpixel = 1;
// tsize_t linebytes;
uint32_t imagelength;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &ncol);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &nrow);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, sampleperpixel);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, &bps);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
float *imgData = new float[ncol * nrow];
for (uint32_t irow = 0; irow < nrow; ++irow) {
// linebytes = sampleperpixel*ncol;
// TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif,
// ncol*sampleperpixel));
for (uint32_t irow = 0; irow < nrow; irow++) {
// tiffreadscanline(tif, buf, row);
TIFFReadScanline(tif, &imgData[irow * ncol], irow);
}
TIFFClose(tif);
return imgData;
} else {
std::cout << "could not open file " << imgname << " for reading\n";
return nullptr;
}
}
} else
cout << "could not open file " << imgname << " for reading " << endl;
return NULL;
};

View File

@ -0,0 +1,35 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#ifndef MY_TIFF_IO_H
#define MY_TIFF_IO_H
#include <fstream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
/*****************************************************************************/
//
// CBFlib must be installed to use this program
//
/*****************************************************************************/
#include <tiffio.h>
#undef cbf_failnez
#define cbf_failnez(x) \
{ \
int err; \
err = (x); \
if (err) { \
fprintf(stderr, "\nCBFlib fatal error %x \n", err); \
exit(-1); \
} \
}
void *WriteToTiff(float *imgData, const char *imgname, int nrow, int ncol);
float *ReadFromTiff(const char *imgname, uint32_t &nrow, uint32_t &ncol);
#endif

View File

@ -1,14 +0,0 @@
find_package(TIFF REQUIRED)
add_library(tiffio STATIC src/tiffIO.cpp)
target_include_directories(tiffio PUBLIC include/)
target_link_libraries(tiffio
PUBLIC
TIFF::TIFF
PRIVATE
slsProjectWarnings
slsProjectOptions
)
if(SLS_USE_TESTS)
add_subdirectory(tests)
endif()

View File

@ -1,16 +0,0 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
#include <cstdint>
//Write 32bit float data to tiff file
//Always returns nullptr, prints message on failure
void *WriteToTiff(float *imgData, const char *imgname, int nrow, int ncol);
//Read 32bit float data from tiff file, returns pointer to data and sets
//image dimensions in the out parameters nrow, ncol.
//Returns nullptr on failure
//The caller is responsible to deallocate the memory that the returned
//pointer points to.
float *ReadFromTiff(const char *imgname, uint32_t &nrow, uint32_t &ncol);

View File

@ -1,5 +0,0 @@
# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package
target_sources(tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/test-tiffio.cpp
)

View File

@ -1,54 +0,0 @@
#include "catch.hpp"
#include "sls/tiffIO.h"
#include <cstdio>
#include <ftw.h>
#include <iostream>
#include <vector>
/* Call-back to the 'remove()' function called by nftw() */
static int remove_callback(const char *pathname,
__attribute__((unused)) const struct stat *sbuf,
__attribute__((unused)) int type,
__attribute__((unused)) struct FTW *ftwb) {
return remove(pathname);
}
TEST_CASE("Write and read back data from tiff file") {
std::vector<float> data{1, 2, 3, 4, 5, 6, 7, 8, 9};
/* Create the temporary directory */
char tmp[] = "/tmp/tmpdir.XXXXXX";
char *tmp_dirname = mkdtemp(tmp);
if (tmp_dirname == NULL) {
perror("tempdir: error: Could not create tmp directory");
CHECK(false);
}
std::string fname = std::string(tmp_dirname) + std::string("/test.tif");
std::cout << "Writing to: " << fname<< '\n';
WriteToTiff(data.data(), fname.c_str(), 3, 3);
//Readback
uint32_t nrow, ncol;
float* ptr = ReadFromTiff(fname.c_str(), nrow, ncol);
CHECK(nrow == 3);
CHECK(ncol == 3);
uint32_t size = nrow*ncol;
for (uint32_t i = 0; i!=size; ++i){
CHECK(data[i] == ptr[i]);
}
delete[] ptr;
/* Delete the temporary directory */
if (nftw(tmp_dirname, remove_callback, FOPEN_MAX,
FTW_DEPTH | FTW_MOUNT | FTW_PHYS) == -1) {
perror("tempdir: error: ");
exit(EXIT_FAILURE);
}
}

View File

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

View File

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

View File

@ -1064,8 +1064,6 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size,
// mythen3 / gotthard2 debugging
int discardBits = numDiscardBits;
uint16_t temp = 0;
uint8_t *src = (uint8_t *)source;
switch (dr) {
case 4:
@ -1085,19 +1083,6 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size,
}
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:
if (detType == slsDetectorDefs::JUNGFRAU ||
detType == slsDetectorDefs::GOTTHARD2) {

View File

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

View File

@ -165,9 +165,11 @@
#define PATTERN_OUT_LSB_REG (0x20 << MEM_MAP_SHIFT)
#define PATTERN_OUT_MSB_REG (0x21 << MEM_MAP_SHIFT)
/* Frame number of next acquisition register (64 bit register) */
#define NEXT_FRAME_NUMB_LOCAL_LSB_REG (0x22 << MEM_MAP_SHIFT)
#define NEXT_FRAME_NUMB_LOCAL_MSB_REG (0x23 << MEM_MAP_SHIFT)
/* Frames From Start 64 bit RO register TODO */
//#define FRAMES_FROM_START_LSB_REG (0x22 << MEM_MAP_SHIFT) // Not
// used in FW #define FRAMES_FROM_START_MSB_REG (0x23 <<
// MEM_MAP_SHIFT)
//// Not used in FW
/* Frames From Start PG 64 bit RO register. Reset using CONTROL_CRST. TODO */
#define FRAMES_FROM_START_PG_LSB_REG (0x24 << MEM_MAP_SHIFT)

View File

@ -45,6 +45,7 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL
pthread_t pthread_virtual_tid;
int64_t virtual_currentFrameNumber = 2;
#endif
// 1g readout
@ -433,21 +434,16 @@ void initControlServer() {
}
void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) {
initError = FAIL;
strcpy(initErrorMessage,
"Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
#ifdef VIRTUAL
sharedMemory_setStop(0);
#endif
usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) {
LOG(logERROR,
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE);
}
initCheckDone = 1;
#ifdef VIRTUAL
sharedMemory_setStop(0);
#endif
}
/* set up detector */
@ -585,7 +581,6 @@ void setupDetector() {
LOG(logERROR, ("%s\n\n", initErrorMessage));
initError = FAIL;
}
setNextFrameNumber(DEFAULT_STARTING_FRAME_NUMBER);
}
int updateDatabytesandAllocateRAM() {
@ -707,16 +702,8 @@ void resetPeripheral() {
}
/* set parameters - dr, adcenablemask */
int setDynamicRange(int dr) {
if (dr == 16)
return OK;
return FAIL;
}
int getDynamicRange(int *retval) {
*retval = DYNAMIC_RANGE;
return OK;
}
int setDynamicRange(int dr) { return DYNAMIC_RANGE; }
int setADCEnableMask(uint32_t mask) {
if (mask == 0u) {
@ -911,24 +898,6 @@ int getReadoutMode() {
}
/* parameters - timer */
int setNextFrameNumber(uint64_t value) {
LOG(logINFO,
("Setting next frame number: %llu\n", (long long unsigned int)value));
setU64BitReg(value, NEXT_FRAME_NUMB_LOCAL_LSB_REG,
NEXT_FRAME_NUMB_LOCAL_MSB_REG);
#ifndef VIRTUAL
// for 1g udp interface
setUDPFrameNumber(value);
#endif
return OK;
}
int getNextFrameNumber(uint64_t *retval) {
*retval = getU64BitReg(NEXT_FRAME_NUMB_LOCAL_LSB_REG,
NEXT_FRAME_NUMB_LOCAL_MSB_REG);
return OK;
}
void setNumFrames(int64_t val) {
if (val > 0) {
LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
@ -1523,8 +1492,6 @@ enum timingMode getTiming() {
/* configure mac */
int getNumberofUDPInterfaces() { return 1; }
void calcChecksum(udp_header *udp) {
int count = IP_HEADER_SIZE;
long int sum = 0;
@ -2031,14 +1998,11 @@ void *start_timer(void *arg) {
}
// Send data
uint64_t frameNr = 0;
getNextFrameNumber(&frameNr);
// loop over number of frames
for (int iframes = 0; iframes != numFrames; ++iframes) {
for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// check if manual stop
if (sharedMemory_getStop() == 1) {
setNextFrameNumber(frameNr + iframes + 1);
break;
}
@ -2057,7 +2021,7 @@ void *start_timer(void *arg) {
sls_detector_header *header = (sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType;
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = frameNr + iframes;
header->frameNumber = virtual_currentFrameNumber;
header->packetNumber = i;
header->modId = 0;
header->row = detPos[X];
@ -2070,18 +2034,19 @@ void *start_timer(void *arg) {
sendUDPPacket(0, 0, packetData, packetSize);
}
LOG(logINFO, ("Sent frame: %d [%lld]\n", iframes, frameNr + iframes));
LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr,
(long long unsigned int)virtual_currentFrameNumber));
clock_gettime(CLOCK_REALTIME, &end);
int64_t timeNs =
((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec));
// sleep for (period - exptime)
if (iframes < numFrames) { // if there is a next frame
if (frameNr < numFrames) { // if there is a next frame
if (periodNs > timeNs) {
usleep((periodNs - timeNs) / 1000);
}
}
setNextFrameNumber(frameNr + numFrames);
++virtual_currentFrameNumber;
}
closeUDPSocket(0);

View File

@ -108,24 +108,21 @@ enum CLKINDEX { RUN_CLK, ADC_CLK, SYNC_CLK, DBIT_CLK, NUM_CLOCKS };
#define I2C_SHUNT_RESISTER_OHMS (0.005)
/** Default Parameters */
#define DEFAULT_DATA_BYTES (NCHIP * NCHAN * NUM_BITS_PER_PIXEL)
#define DEFAULT_STARTING_FRAME_NUMBER (1)
#define DEFAULT_NUM_SAMPLES (1)
#define DEFAULT_NUM_FRAMES (1)
#define DEFAULT_EXPTIME (0)
#define DEFAULT_NUM_CYCLES (1)
#define DEFAULT_PERIOD (1 * 1000 * 1000) // ns
#define DEFAULT_DELAY (0)
#define DEFAULT_HIGH_VOLTAGE (0)
#define DEFAULT_VLIMIT (-100)
#define DEFAULT_TIMING_MODE (AUTO_TIMING)
#define DEFAULT_TX_UDP_PORT (0x7e9a)
#define DEFAULT_RUN_CLK (200) // 40
#define DEFAULT_ADC_CLK (40) // 20
#define DEFAULT_SYNC_CLK (40) // 20
#define DEFAULT_DBIT_CLK (200)
#define UDP_HEADER_MAX_FRAME_VALUE (0xFFFFFFFFFFFF)
#define DEFAULT_DATA_BYTES (NCHIP * NCHAN * NUM_BITS_PER_PIXEL)
#define DEFAULT_NUM_SAMPLES (1)
#define DEFAULT_NUM_FRAMES (1)
#define DEFAULT_EXPTIME (0)
#define DEFAULT_NUM_CYCLES (1)
#define DEFAULT_PERIOD (1 * 1000 * 1000) // ns
#define DEFAULT_DELAY (0)
#define DEFAULT_HIGH_VOLTAGE (0)
#define DEFAULT_VLIMIT (-100)
#define DEFAULT_TIMING_MODE (AUTO_TIMING)
#define DEFAULT_TX_UDP_PORT (0x7e9a)
#define DEFAULT_RUN_CLK (200) // 40
#define DEFAULT_ADC_CLK (40) // 20
#define DEFAULT_SYNC_CLK (40) // 20
#define DEFAULT_DBIT_CLK (200)
#define HIGHVOLTAGE_MIN (60)
#define HIGHVOLTAGE_MAX (200) // min dac val

View File

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

View File

@ -16,31 +16,91 @@ include_directories(
../../slsSupportLib/include
)
add_executable(eigerDetectorServer_virtual
add_executable(eigerDetectorServerMaster_virtual
${src}
)
target_include_directories(eigerDetectorServer_virtual
target_include_directories(eigerDetectorServerMaster_virtual
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(eigerDetectorServer_virtual
target_compile_definitions(eigerDetectorServerMaster_virtual
PUBLIC EIGERD PCCOMPILE STOP_SERVER
PUBLIC VIRTUAL #VIRTUAL_9M
PUBLIC VIRTUAL_MASTER
)
target_link_libraries(eigerDetectorServer_virtual
target_link_libraries(eigerDetectorServerMaster_virtual
PUBLIC pthread rt slsProjectCSettings
)
set_target_properties(eigerDetectorServer_virtual PROPERTIES
set_target_properties(eigerDetectorServerMaster_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS eigerDetectorServer_virtual
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 VIRTUAL #VIRTUAL_9M
)
target_link_libraries(eigerDetectorServerSlaveBottom_virtual
PUBLIC pthread rt slsProjectCSettings
)
set_target_properties(eigerDetectorServerSlaveBottom_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
install(TARGETS eigerDetectorServerSlaveBottom_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
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)

View File

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

View File

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

View File

@ -29,8 +29,6 @@
#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_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_MSK (0x00000001 << DAQ_REG_HRDWRE_PROGRAM_OFST)
#define DAQ_REG_HRDWRE_M8_OFST (31)

View File

@ -26,17 +26,12 @@ extern int updateFlag;
extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern int numUdpDestinations;
extern const enum detectorType myDetectorType;
extern int ignoreConfigFileFlag;
// Global variable from communication_funcs.c
extern int isControlServer;
extern void getMacAddressinString(char *cmac, int size, uint64_t mac);
extern void getIpAddressinString(char *cip, uint32_t ip);
// Variables that will be exported
int masterCommandLine = -1;
int topCommandLine = -1;
int initError = OK;
int initCheckDone = 0;
char initErrorMessage[MAX_STR_LENGTH];
@ -93,7 +88,6 @@ int eiger_virtual_read_n_rows = 256;
int eiger_virtual_interrupt_subframe = 0;
int eiger_virtual_left_datastream = 1;
int eiger_virtual_right_datastream = 1;
int eiger_virtual_module_id = 0;
#endif
int defaultDacValues[NDAC] = DEFAULT_DAC_VALS;
@ -231,23 +225,6 @@ int getModuleId(int *ret, char *mess) {
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() {
char mac[255] = "";
u_int64_t res = 0;
@ -327,36 +304,47 @@ u_int32_t getDetectorIP() {
void initControlServer() {
LOG(logINFOBLUE, ("Configuring Control server\n"));
if (!updateFlag && initError == OK) {
if (updateModuleConfiguration() == FAIL) {
initCheckDone = 1;
#ifndef VIRTUAL
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
#else
getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
#endif
if (initError == FAIL) {
return;
}
getModuleConfiguration();
#ifndef VIRTUAL
sharedMemory_lockLocalLink();
Feb_Control_SetMasterVariable(master);
Feb_Interface_FebInterface();
if (!Feb_Control_FebControl(normal)) {
Feb_Control_FebControl();
// same addresses for top and bottom
if (!Feb_Control_Init(master, normal)) {
initError = FAIL;
sprintf(initErrorMessage,
"Could not intitalize eiger detector sever: feb control\n");
sprintf(initErrorMessage, "Could not intitalize feb control\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
sharedMemory_unlockLocalLink();
return;
}
if (Feb_Control_SetMasterEffects(master, isControlServer) == FAIL) {
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;
// master of 9M, check high voltage serial communication to blackfin
if (master && !normal) {
if (!Feb_Control_OpenSerialCommunication()) {
initError = FAIL;
sprintf(
initErrorMessage,
"Could not intitalize feb control serial communication\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
sharedMemory_unlockLocalLink();
return;
}
}
sharedMemory_unlockLocalLink();
LOG(logDEBUG1, ("Control server: FEB Initialization done\n"));
Beb_SetTopVariable(top);
Beb_Beb();
Beb_SetModuleId(modid);
LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
#endif
// also reads config file and deactivates
@ -366,126 +354,73 @@ void initControlServer() {
}
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
sharedMemory_setStop(0);
// force top or master if in config file
if (readConfigFile() == FAIL) {
initCheckDone = 1;
return;
}
// force top or master if in command line
if (checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
LOG(logINFOBLUE, ("Configuring Stop server\n"));
getModuleConfiguration();
sharedMemory_setStop(0);
// get top/master in virtual
readConfigFile();
#else
// control server read config file and already set up master/top
sharedMemory_lockLocalLink();
Feb_Interface_FebInterface();
if (!Feb_Control_FebControl(normal)) {
initError = FAIL;
sprintf(initErrorMessage, "Could not intitalize feb control\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
sharedMemory_unlockLocalLink();
return;
}
if (Feb_Control_SetMasterEffects(master, isControlServer) == FAIL) {
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"));
// wait a few s (control server is setting top/master from config file)
usleep(WAIT_STOP_SERVER_START);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
// exit(-1);
getModuleConfiguration();
sharedMemory_lockLocalLink();
Feb_Control_SetMasterVariable(master);
Feb_Interface_FebInterface();
Feb_Control_FebControl();
// same addresses for top and bottom
Feb_Control_Init(master, normal);
sharedMemory_unlockLocalLink();
LOG(logDEBUG1, ("Stop server: FEB Initialization done\n"));
#endif
// client first connect (from shm) will activate
if (setActivate(0) == FAIL) {
initError = FAIL;
strcpy(initErrorMessage, "Could not deactivate\n");
LOG(logERROR, (initErrorMessage));
}
// client first connect (from shm) will activate
if (setActivate(0) == FAIL) {
LOG(logERROR, ("Could not deactivate in stop server\n"));
}
initCheckDone = 1;
}
void checkVirtual9MFlag() {
void getModuleConfiguration() {
if (initError == FAIL) {
return;
}
#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
normal = 0;
#else
normal = 1;
#endif
#endif
}
int updateModuleConfiguration() {
if (getModuleConfiguration(&master, &top, &normal) == FAIL) {
return FAIL;
}
#ifdef VIRTUAL
checkVirtual9MFlag();
#else
Beb_GetModuleConfiguration(&master, &top, &normal);
#endif
if (isControlServer) {
LOG(logINFOBLUE,
("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"),
(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() {
if (initError == FAIL) {
return initError;
}
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;
master = -1;
#endif
top = -1;
const int fileNameSize = 128;
char fname[fileNameSize];
@ -536,54 +471,91 @@ int readConfigFile() {
// top command
if (!strncmp(line, "top", strlen("top"))) {
int t = -1;
// cannot scan values
if (sscanf(line, "%s %d", command, &t) != 2) {
if (sscanf(line, "%s %d", command, &top) != 2) {
sprintf(initErrorMessage,
"Could not scan top commands from on-board server "
"config file. Line:[%s].\n",
line);
break;
}
if (t != 0 && t != 1) {
sprintf(initErrorMessage,
"Invalid top argument from on-board server "
"config file. Line:[%s].\n",
line);
#ifndef VIRTUAL
enum TOPINDEX ind = (top == 1 ? OW_TOP : OW_BOTTOM);
if (!Beb_SetTop(ind)) {
sprintf(
initErrorMessage,
"Could not overwrite top to %d in Beb from on-board server "
"config file. Line:[%s].\n",
top, line);
break;
}
if (setTop(t == 1 ? OW_TOP : OW_BOTTOM) == FAIL) {
sprintf(initErrorMessage,
"Could not set top from config file. Line:[%s].\n",
line);
sharedMemory_lockLocalLink();
if (!Feb_Control_SetTop(ind, 1, 1)) {
sprintf(
initErrorMessage,
"Could not overwrite top to %d in Feb from on-board server "
"config file. Line:[%s].\n",
top, line);
sharedMemory_unlockLocalLink();
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
else if (!strncmp(line, "master", strlen("master"))) {
int m = -1;
// cannot scan values
if (sscanf(line, "%s %d", command, &m) != 2) {
if (sscanf(line, "%s %d", command, &master) != 2) {
sprintf(initErrorMessage,
"Could not scan master commands from on-board server "
"config file. Line:[%s].\n",
line);
break;
}
if (m != 0 && m != 1) {
#ifndef VIRTUAL
enum MASTERINDEX ind = (master == 1 ? OW_MASTER : OW_SLAVE);
if (!Beb_SetMaster(ind)) {
sprintf(initErrorMessage,
"Invalid master argument from on-board server "
"Could not overwrite master to %d in Beb from on-board "
"server "
"config file. Line:[%s].\n",
line);
master, line);
break;
}
if (setMaster(m == 1 ? OW_MASTER : OW_SLAVE) == FAIL) {
sharedMemory_lockLocalLink();
if (!Feb_Control_SetMaster(ind)) {
sprintf(initErrorMessage,
"Could not set master from config file. Line:[%s].\n",
line);
"Could not overwrite master to %d in Feb from on-board "
"server "
"config file. Line:[%s].\n",
master, line);
sharedMemory_unlockLocalLink();
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
@ -604,10 +576,8 @@ int readConfigFile() {
LOG(logINFO, ("Successfully read config file\n"));
}
#ifndef VIRTUAL
// reset to hardware settings if not in config file (if overwritten)
resetToHardwareSettings();
#endif
return initError;
}
@ -619,56 +589,55 @@ void resetToHardwareSettings() {
}
// top not set in config file
if (top == -1) {
LOG(logINFO, ("Resetting Top to hardware settings\n"));
if (setTop(TOP_HARDWARE) == FAIL) {
if (!Beb_SetTop(TOP_HARDWARE)) {
initError = FAIL;
strcpy(initErrorMessage,
"Could not reset Top flag to hardware settings.\n");
"Could not reset Top flag to Beb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
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
if (master == -1) {
LOG(logINFO, ("Resetting Master to hardware settings\n"));
if (setMaster(MASTER_HARDWARE) == FAIL) {
if (!Beb_SetMaster(TOP_HARDWARE)) {
initError = FAIL;
strcpy(initErrorMessage,
"Could not reset Master flag to hardware settings.\n");
"Could not reset Master flag to Beb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
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
}
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 */
void allocateDetectorStructureMemory() {
@ -702,29 +671,15 @@ void allocateDetectorStructureMemory() {
}
void setupDetector() {
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);
#ifdef VIRTUAL
sharedMemory_setStatus(IDLE);
setupUDPCommParameters();
#endif
LOG(logINFOBLUE, ("Setting Default Parameters\n"));
// setting default measurement parameters
setNumFrames(DEFAULT_NUM_FRAMES);
setExpTime(DEFAULT_EXPTIME);
@ -764,6 +719,14 @@ void setupDetector() {
}
sharedMemory_unlockLocalLink();
#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) {
initError = FAIL;
strcpy(initErrorMessage, "Could not set number of udp destinations\n");
@ -858,38 +821,29 @@ int readRegister(uint32_t offset, uint32_t *retval) {
/* set parameters - dr, roi */
int setDynamicRange(int dr) {
if (dr <= 0) {
return FAIL;
}
#ifdef VIRTUAL
LOG(logINFO, ("Setting dynamic range: %d\n", dr));
#else
sharedMemory_lockLocalLink();
if (Feb_Control_SetDynamicRange(dr)) {
if (!Beb_SetUpTransferParameters(dr)) {
LOG(logERROR, ("Could not set bit mode in the back end\n"));
sharedMemory_unlockLocalLink();
return eiger_dynamicrange;
// setting dr
if (dr > 0) {
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;
return OK;
}
int getDynamicRange(int *retval) {
#ifdef VIRTUAL
*retval = eiger_dynamicrange;
#else
sharedMemory_lockLocalLink();
if (!Feb_Control_GetDynamicRange(retval)) {
sharedMemory_unlockLocalLink();
return FAIL;
#endif
eiger_dynamicrange = dr;
}
// getting dr
#ifndef VIRTUAL
sharedMemory_lockLocalLink();
eiger_dynamicrange = Feb_Control_GetDynamicRange();
sharedMemory_unlockLocalLink();
#endif
return OK;
return eiger_dynamicrange;
}
/* parameters - readout */
@ -1204,7 +1158,6 @@ int setModule(sls_detector_module myMod, char *mess) {
// if quad, set M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(1)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
@ -1217,7 +1170,6 @@ int setModule(sls_detector_module myMod, char *mess) {
// if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
@ -1227,7 +1179,6 @@ int setModule(sls_detector_module myMod, char *mess) {
// if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
@ -1499,120 +1450,7 @@ int setHighVoltage(int val) {
/* parameters - timing, extsig */
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;
}
int isMaster() { return master; }
void setTiming(enum timingMode arg) {
int ret = 0;
@ -1662,7 +1500,6 @@ enum timingMode getTiming() {
}
/* configure mac */
int getNumberofUDPInterfaces() { return 2; }
int getNumberofDestinations(int *retval) {
#ifdef VIRTUAL
@ -2085,8 +1922,7 @@ int setRateCorrection(
else if (custom_tau_in_nsec == -1)
custom_tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec();
int dr = eiger_dynamicrange;
int dr = Feb_Control_GetDynamicRange();
// get period = subexptime if 32bit , else period = exptime if 16 bit
int64_t actual_period =
Feb_Control_GetSubFrameExposureTime(); // already in nsec
@ -2268,9 +2104,6 @@ int setDataStream(enum portPosition port, int enable) {
LOG(logERROR, ("Invalid setDataStream enable argument: %d\n", enable));
return FAIL;
}
LOG(logINFO,
("%s 10GbE %s datastream\n", (enable ? "Enabling" : "Disabling"),
(port == LEFT ? "left" : "right")));
#ifdef VIRTUAL
if (port == LEFT) {
eiger_virtual_left_datastream = enable;
@ -2484,7 +2317,7 @@ void *start_timer(void *arg) {
const int maxRows = MAX_ROWS_PER_READOUT;
const int packetsPerFrame = (maxPacketsPerFrame * readNRows) / maxRows;
LOG(logDEBUG,
LOG(logDEBUG1,
(" dr:%d\n bytesperpixel:%f\n tgenable:%d\n datasize:%d\n "
"packetsize:%d\n maxnumpackes:%d\n npixelsx:%d\n databytes:%d\n",
dr, bytesPerPixel, tgEnable, datasize, packetsize, maxPacketsPerFrame,
@ -2501,13 +2334,11 @@ void *start_timer(void *arg) {
npixels /= 2;
}
LOG(logDEBUG1,
("npixels:%d pixelsperpacket:%d\n", npixels, pixelsPerPacket));
uint8_t *src = (uint8_t *)imageData;
("pixels:%d pixelsperpacket:%d\n", npixels, pixelsPerPacket));
for (int i = 0; i < npixels; ++i) {
if (i > 0 && i % pixelsPerPacket == 0) {
++pixelVal;
}
switch (dr) {
case 4:
*((uint8_t *)(imageData + i)) =
@ -2522,30 +2353,6 @@ void *start_timer(void *arg) {
*((uint8_t *)(imageData + i)) =
eiger_virtual_test_mode ? 0xFE : (uint8_t)pixelVal;
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:
*((uint16_t *)(imageData + i * sizeof(uint16_t))) =
eiger_virtual_test_mode ? 0xFFE : (uint16_t)pixelVal;
@ -2600,7 +2407,6 @@ void *start_timer(void *arg) {
header->version = SLS_DETECTOR_HEADER_VERSION;
header->frameNumber = frameNr + iframes;
header->packetNumber = i;
header->modId = eiger_virtual_module_id;
header->row = row;
header->column = colLeft;
@ -2611,7 +2417,6 @@ void *start_timer(void *arg) {
header->version = SLS_DETECTOR_HEADER_VERSION;
header->frameNumber = frameNr + iframes;
header->packetNumber = i;
header->modId = eiger_virtual_module_id;
header->row = row;
header->column = colRight;
if (eiger_virtual_quad_mode) {
@ -2622,27 +2427,9 @@ void *start_timer(void *arg) {
// fill data
int dstOffset = sizeof(sls_detector_header);
int dstOffset2 = sizeof(sls_detector_header);
if (dr == 12) {
// 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) {
memcpy(packetData + dstOffset,
imageData + srcOffset, npixelsx / 2);
@ -2940,9 +2727,9 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
int calculateDataBytes() {
if (send_to_ten_gig)
return eiger_dynamicrange * ONE_GIGA_CONSTANT * TEN_GIGA_BUFFER_SIZE;
return setDynamicRange(-1) * ONE_GIGA_CONSTANT * TEN_GIGA_BUFFER_SIZE;
else
return eiger_dynamicrange * TEN_GIGA_CONSTANT * ONE_GIGA_BUFFER_SIZE;
return setDynamicRange(-1) * TEN_GIGA_CONSTANT * ONE_GIGA_BUFFER_SIZE;
}
int getTotalNumberOfChannels() {

View File

@ -5,7 +5,7 @@
#define LINKED_SERVER_NAME "eigerDetectorServer"
#define REQUIRED_FIRMWARE_VERSION (30)
#define REQUIRED_FIRMWARE_VERSION (29)
// virtual ones renamed for consistency
// real ones keep previous name for compatibility (already in production)
#ifdef VIRTUAL
@ -43,7 +43,7 @@ enum DACINDEX {
#define DAC_NAMES \
"VSvP", "Vtrim", "Vrpreamp", "Vrshaper", "VSvN", "Vtgstv", "Vcmp_ll", \
"Vcmp_lr", "Vcal", "Vcmp_rl", "rxb_rb", "rxb_lb", "Vcmp_rr", "Vcp", \
"Vcn", "Vishaper", "Vthreshold"
"Vcn", "Vishaper"
#define DEFAULT_DAC_VALS \
{ \
0, /* VSvP */ \

View File

@ -28,16 +28,12 @@ extern int updateFlag;
extern int checkModuleFlag;
extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern const enum detectorType myDetectorType;
extern int ignoreConfigFileFlag;
// Global variable from communication_funcs.c
extern int isControlServer;
extern void getMacAddressinString(char *cmac, int size, uint64_t mac);
extern void getIpAddressinString(char *cip, uint32_t ip);
// Variables that will be exported
int masterCommandLine = -1;
int initError = OK;
int initCheckDone = 0;
char initErrorMessage[MAX_STR_LENGTH];
@ -45,7 +41,6 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL
pthread_t pthread_virtual_tid;
int64_t virtual_currentFrameNumber = 2;
int virtual_moduleid = 0;
#endif
enum detectorSettings thisSettings = UNINITIALIZED;
@ -73,7 +68,6 @@ int64_t burstPeriodReg = 0;
int filterResistor = 0;
int cdsGain = 0;
int detPos[2] = {};
int master = 1;
int isInitCheckDone() { return initCheckDone; }
@ -107,9 +101,8 @@ void basictests() {
}
// does check only if flag is 0 (by default), set by command line
if ((!debugflag) && (!updateFlag) &&
((validateKernelVersion(KERNEL_DATE_VRSN) == FAIL) ||
(checkType() == FAIL) || (testFpga() == FAIL) ||
(testBus() == FAIL))) {
((validateKernelVersion(KERNEL_DATE_VRSN) == FAIL) || (checkType() == FAIL) ||
(testFpga() == FAIL) || (testBus() == FAIL))) {
sprintf(initErrorMessage,
"Could not pass basic tests of FPGA and bus. Dangerous to "
"continue. (Firmware version:0x%llx) \n",
@ -300,18 +293,6 @@ void setModuleId(int modid) {
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() {
#ifdef VIRTUAL
return 0;
@ -375,27 +356,16 @@ void initControlServer() {
}
void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
if (mapCSP0() == FAIL) {
initError = FAIL;
strcpy(initErrorMessage,
"Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
#ifdef VIRTUAL
sharedMemory_setStop(0);
// not reading config file (nothing of interest to stop server)
if (checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
#endif
usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) {
LOG(logERROR,
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE);
}
initCheckDone = 1;
#ifdef VIRTUAL
sharedMemory_setStop(0);
#endif
}
/* set up detector */
@ -508,13 +478,12 @@ void setupDetector() {
return;
}
// master for virtual
if (checkCommandLineConfiguration() == FAIL)
return;
if (updateModuleId() == FAIL) {
// set module id in register
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return;
}
setModuleId(modid);
setBurstMode(DEFAULT_BURST_MODE);
setFilterResistor(DEFAULT_FILTER_RESISTOR);
@ -626,11 +595,6 @@ int readConfigFile() {
return initError;
}
if (ignoreConfigFileFlag) {
LOG(logWARNING, ("Ignoring Config file\n"));
return OK;
}
// require a sleep before and after the rst dac signal
usleep(INITIAL_STARTUP_WAIT);
@ -955,21 +919,6 @@ int readConfigFile() {
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) */
void cleanFifos() {
@ -998,16 +947,7 @@ void resetPeripheral() {
/* set parameters - dr, roi */
int setDynamicRange(int dr) {
if (dr == 16)
return OK;
return FAIL;
}
int getDynamicRange(int *retval) {
*retval = DYNAMIC_RANGE;
return OK;
}
int setDynamicRange(int dr) { return DYNAMIC_RANGE; }
/* parameters - timer */
void setNumFrames(int64_t val) {
@ -1497,11 +1437,6 @@ int setHighVoltage(int val) {
/* parameters - timing */
int isMaster(int *retval) {
*retval = master;
return OK;
}
void updatingRegisters() {
LOG(logINFO, ("\tUpdating registers\n"));
// burst
@ -1981,17 +1916,9 @@ int checkDetectorType() {
return -2;
}
if (abs(type - TYPE_GOTTHARD2_25UM_MASTER_MODULE_VAL) <= TYPE_TOLERANCE) {
LOG(logINFOBLUE, ("MASTER 25um Module\n"));
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 {
if ((abs(type - TYPE_GOTTHARD2_MODULE_VAL) > TYPE_TOLERANCE) &&
(abs(type - TYPE_GOTTHARD2_25UM_MASTER_MODULE_VAL) > TYPE_TOLERANCE) &&
(abs(type - TYPE_GOTTHARD2_25UM_SLAVE_MODULE_VAL) > TYPE_TOLERANCE)) {
LOG(logERROR,
("Wrong Module attached! Expected %d, %d or %d for Gotthard2, got "
"%d\n",
@ -2156,56 +2083,40 @@ int setReadoutSpeed(int val) {
case G2_108MHZ:
LOG(logINFOBLUE, ("Setting readout speed to 108 MHz\n"));
if (setClockDivider(READOUT_C0, SPEED_108_CLKDIV_0) == FAIL) {
LOG(logERROR, ("Could not set readout speed to 108 MHz. Failed to "
"set readout clk 0 to %d\n",
SPEED_108_CLKDIV_0));
LOG(logERROR, ("Could not set readout speed to 108 MHz. Failed to set readout clk 0 to %d\n", SPEED_108_CLKDIV_0));
return FAIL;
}
if (setClockDivider(READOUT_C1, SPEED_108_CLKDIV_1) == FAIL) {
LOG(logERROR, ("Could not set readout speed to 108 MHz. Failed to "
"set readout clk 1 to %d\n",
SPEED_108_CLKDIV_1));
LOG(logERROR, ("Could not set readout speed to 108 MHz. Failed to set readout clk 1 to %d\n", SPEED_108_CLKDIV_1));
return FAIL;
}
if (setPhase(READOUT_C1, SPEED_108_CLKPHASE_DEG_1, 1) == FAIL) {
LOG(logERROR, ("Could not set readout speed to 108 MHz. Failed to "
"set clk phase 1 %d deg\n",
SPEED_108_CLKPHASE_DEG_1));
LOG(logERROR, ("Could not set readout speed to 108 MHz. Failed to set clk phase 1 %d deg\n", SPEED_108_CLKPHASE_DEG_1));
return FAIL;
}
setDBITPipeline(SPEED_144_DBIT_PIPELINE);
if (getDBITPipeline() != SPEED_144_DBIT_PIPELINE) {
LOG(logERROR, ("Could not set readout speed to 108 MHz. Failed to "
"set dbitpipeline to %d \n",
SPEED_144_DBIT_PIPELINE));
LOG(logERROR, ("Could not set readout speed to 108 MHz. Failed to set dbitpipeline to %d \n", SPEED_144_DBIT_PIPELINE));
return FAIL;
}
break;
case G2_144MHZ:
LOG(logINFOBLUE, ("Setting readout speed to 144 MHz\n"));
if (setClockDivider(READOUT_C0, SPEED_144_CLKDIV_0) == FAIL) {
LOG(logERROR, ("Could not set readout speed to 144 MHz. Failed to "
"set readout clk 0 to %d\n",
SPEED_144_CLKDIV_0));
LOG(logERROR, ("Could not set readout speed to 144 MHz. Failed to set readout clk 0 to %d\n", SPEED_144_CLKDIV_0));
return FAIL;
}
if (setClockDivider(READOUT_C1, SPEED_144_CLKDIV_1) == FAIL) {
LOG(logERROR, ("Could not set readout speed to 144 MHz. Failed to "
"set readout clk 1 to %d\n",
SPEED_144_CLKDIV_1));
LOG(logERROR, ("Could not set readout speed to 144 MHz. Failed to set readout clk 1 to %d\n", SPEED_144_CLKDIV_1));
return FAIL;
}
if (setPhase(READOUT_C1, SPEED_144_CLKPHASE_DEG_1, 1) == FAIL) {
LOG(logERROR, ("Could not set readout speed to 144 MHz. Failed to "
"set clk phase 1 %d deg\n",
SPEED_144_CLKPHASE_DEG_1));
LOG(logERROR, ("Could not set readout speed to 144 MHz. Failed to set clk phase 1 %d deg\n", SPEED_144_CLKPHASE_DEG_1));
return FAIL;
}
setDBITPipeline(SPEED_144_DBIT_PIPELINE);
if (getDBITPipeline() != SPEED_144_DBIT_PIPELINE) {
LOG(logERROR, ("Could not set readout speed to 144 MHz. Failed to "
"set dbitpipeline to %d \n",
SPEED_144_DBIT_PIPELINE));
LOG(logERROR, ("Could not set readout speed to 144 MHz. Failed to set dbitpipeline to %d \n", SPEED_144_DBIT_PIPELINE));
return FAIL;
}
break;
@ -3094,7 +3005,7 @@ void *start_timer(void *arg) {
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = virtual_currentFrameNumber;
header->packetNumber = 0;
header->modId = virtual_moduleid;
header->modId = 0;
header->row = detPos[X];
header->column = detPos[Y];
// fill data

View File

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

View File

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

View File

@ -165,9 +165,11 @@
#define PATTERN_OUT_LSB_REG (0x20 << MEM_MAP_SHIFT)
#define PATTERN_OUT_MSB_REG (0x21 << MEM_MAP_SHIFT)
/* Frame number of next acquisition register (64 bit register) */
#define NEXT_FRAME_NUMB_LOCAL_LSB_REG (0x22 << MEM_MAP_SHIFT)
#define NEXT_FRAME_NUMB_LOCAL_MSB_REG (0x23 << MEM_MAP_SHIFT)
/* Frames From Start 64 bit RO register TODO */
//#define FRAMES_FROM_START_LSB_REG (0x22 << MEM_MAP_SHIFT) // Not
// used in FW #define FRAMES_FROM_START_MSB_REG (0x23 <<
// MEM_MAP_SHIFT)
//// Not used in FW
/* Frames From Start PG 64 bit RO register. Reset using CONTROL_CRST. TODO */
#define FRAMES_FROM_START_PG_LSB_REG (0x24 << MEM_MAP_SHIFT)

View File

@ -43,6 +43,7 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL
pthread_t pthread_virtual_tid;
int64_t virtual_currentFrameNumber = 2;
#endif
// 1g readout
@ -67,13 +68,7 @@ int defaultDacValues[NDAC] = DEFAULT_DAC_VALS;
int vLimit = 0;
enum detectorSettings thisSettings = UNINITIALIZED;
int highvoltage = 0;
// getNumberofchannels return 0 for y in --update mode (virtual servers)
#ifdef VIRTUAL
int nSamples = DEFAULT_NUM_SAMPLES;
#else
int nSamples = 1;
#endif
int detPos[2] = {0, 0};
int isInitCheckDone() { return initCheckDone; }
@ -436,22 +431,16 @@ void initControlServer() {
}
void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
if (mapCSP0() == FAIL) {
initError = FAIL;
strcpy(initErrorMessage,
"Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
#ifdef VIRTUAL
sharedMemory_setStop(0);
#endif
usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) {
LOG(logERROR,
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE);
}
initCheckDone = 1;
#ifdef VIRTUAL
sharedMemory_setStop(0);
#endif
}
/* set up detector */
@ -580,7 +569,6 @@ void setupDetector() {
setFrequency(ADC_CLK, DEFAULT_ADC_CLK);
setFrequency(DBIT_CLK, DEFAULT_DBIT_CLK);
setPhase(ADC_CLK, DEFAULT_ADC_PHASE_DEG, 1);
setNextFrameNumber(DEFAULT_STARTING_FRAME_NUMBER);
}
int updateDatabytesandAllocateRAM() {
@ -712,16 +700,7 @@ void resetPeripheral() {
/* set parameters - dr, adcenablemask */
int setDynamicRange(int dr) {
if (dr == 16)
return OK;
return FAIL;
}
int getDynamicRange(int *retval) {
*retval = DYNAMIC_RANGE;
return OK;
}
int setDynamicRange(int dr) { return DYNAMIC_RANGE; }
int setADCEnableMask(uint32_t mask) {
if (mask == 0u) {
@ -821,24 +800,6 @@ uint32_t getADCInvertRegister() {
}
/* parameters - timer */
int setNextFrameNumber(uint64_t value) {
LOG(logINFO,
("Setting next frame number: %llu\n", (long long unsigned int)value));
setU64BitReg(value, NEXT_FRAME_NUMB_LOCAL_LSB_REG,
NEXT_FRAME_NUMB_LOCAL_MSB_REG);
#ifndef VIRTUAL
// for 1g udp interface
setUDPFrameNumber(value);
#endif
return OK;
}
int getNextFrameNumber(uint64_t *retval) {
*retval = getU64BitReg(NEXT_FRAME_NUMB_LOCAL_LSB_REG,
NEXT_FRAME_NUMB_LOCAL_MSB_REG);
return OK;
}
void setNumFrames(int64_t val) {
if (val > 0) {
LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
@ -1196,8 +1157,6 @@ enum timingMode getTiming() {
/* configure mac */
int getNumberofUDPInterfaces() { return 1; }
void calcChecksum(udp_header *udp) {
int count = IP_HEADER_SIZE;
long int sum = 0;
@ -1703,14 +1662,11 @@ void *start_timer(void *arg) {
}
// Send data
uint64_t frameNr = 0;
getNextFrameNumber(&frameNr);
// loop over number of frames
for (int iframes = 0; iframes != numFrames; ++iframes) {
for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// check if manual stop
if (sharedMemory_getStop() == 1) {
setNextFrameNumber(frameNr + iframes + 1);
break;
}
@ -1728,7 +1684,7 @@ void *start_timer(void *arg) {
sls_detector_header *header = (sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType;
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = frameNr + iframes;
header->frameNumber = virtual_currentFrameNumber;
header->packetNumber = i;
header->modId = 0;
header->row = detPos[X];
@ -1741,18 +1697,19 @@ void *start_timer(void *arg) {
sendUDPPacket(0, 0, packetData, packetSize);
}
LOG(logINFO, ("Sent frame: %d [%lld]\n", iframes, frameNr + iframes));
LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr,
(long long unsigned int)virtual_currentFrameNumber));
clock_gettime(CLOCK_REALTIME, &end);
int64_t timeNs =
((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec));
// sleep for (period - exptime)
if (iframes < numFrames) { // if there is a next frame
if (frameNr < numFrames) { // if there is a next frame
if (periodNs > timeNs) {
usleep((periodNs - timeNs) / 1000);
}
}
setNextFrameNumber(frameNr + numFrames);
++virtual_currentFrameNumber;
}
closeUDPSocket(0);

View File

@ -78,19 +78,18 @@ enum CLKINDEX { RUN_CLK, ADC_CLK, SYNC_CLK, DBIT_CLK, NUM_CLOCKS };
#define NCHANS_PER_ADC (25)
/** Default Parameters */
#define DEFAULT_PATTERN_FILE ("DefaultPattern_moench.txt")
#define DEFAULT_STARTING_FRAME_NUMBER (1)
#define DEFAULT_DATA_BYTES (NCHIP * NCHAN * NUM_BITS_PER_PIXEL)
#define DEFAULT_NUM_SAMPLES (5000)
#define DEFAULT_EXPTIME (0)
#define DEFAULT_NUM_FRAMES (1)
#define DEFAULT_NUM_CYCLES (1)
#define DEFAULT_PERIOD (1 * 1000 * 1000) // ns
#define DEFAULT_DELAY (0)
#define DEFAULT_HIGH_VOLTAGE (0)
#define DEFAULT_VLIMIT (-100)
#define DEFAULT_TIMING_MODE (AUTO_TIMING)
#define DEFAULT_TX_UDP_PORT (0x7e9a)
#define DEFAULT_PATTERN_FILE ("DefaultPattern_moench.txt")
#define DEFAULT_DATA_BYTES (NCHIP * NCHAN * NUM_BITS_PER_PIXEL)
#define DEFAULT_NUM_SAMPLES (5000)
#define DEFAULT_EXPTIME (0)
#define DEFAULT_NUM_FRAMES (1)
#define DEFAULT_NUM_CYCLES (1)
#define DEFAULT_PERIOD (1 * 1000 * 1000) // ns
#define DEFAULT_DELAY (0)
#define DEFAULT_HIGH_VOLTAGE (0)
#define DEFAULT_VLIMIT (-100)
#define DEFAULT_TIMING_MODE (AUTO_TIMING)
#define DEFAULT_TX_UDP_PORT (0x7e9a)
#define DEFAULT_RUN_CLK_AT_STARTUP (200) // 40
#define DEFAULT_ADC_CLK_AT_STARTUP (40) // 20
@ -105,8 +104,6 @@ enum CLKINDEX { RUN_CLK, ADC_CLK, SYNC_CLK, DBIT_CLK, NUM_CLOCKS };
#define DEFAULT_PIPELINE (15)
#define DEFAULT_SETTINGS (G4_HIGHGAIN)
#define UDP_HEADER_MAX_FRAME_VALUE (0xFFFFFFFFFFFF)
// settings
#define DEFAULT_PATMASK (0x00000C800000800AULL)
#define G1_HIGHGAIN_PATSETBIT (0x00000C0000008008ULL)

View File

@ -35,9 +35,6 @@ extern int isControlServer;
extern void getMacAddressinString(char *cmac, int size, uint64_t mac);
extern void getIpAddressinString(char *cip, uint32_t ip);
// Variables that will be exported
int masterCommandLine = -1;
int initError = OK;
int initCheckDone = 0;
char initErrorMessage[MAX_STR_LENGTH];
@ -45,7 +42,6 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL
pthread_t pthread_virtual_tid;
int64_t virtual_currentFrameNumber = 2;
int virtual_moduleid = 0;
#endif
enum detectorSettings thisSettings = UNINITIALIZED;
@ -292,18 +288,6 @@ void setModuleId(int modid) {
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() {
#ifdef VIRTUAL
return 0;
@ -367,26 +351,16 @@ void initControlServer() {
}
void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
if (mapCSP0() == FAIL) {
initError = FAIL;
strcpy(initErrorMessage,
"Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
#ifdef VIRTUAL
sharedMemory_setStop(0);
if (checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
#endif
usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) {
LOG(logERROR,
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE);
}
initCheckDone = 1;
#ifdef VIRTUAL
sharedMemory_setStop(0);
#endif
}
/* set up detector */
@ -432,12 +406,6 @@ void setupDetector() {
allocateDetectorStructureMemory();
if (checkCommandLineConfiguration() == FAIL)
return;
if (updateModuleId() == FAIL)
return;
clkDivider[READOUT_C0] = DEFAULT_READOUT_C0;
clkDivider[READOUT_C1] = DEFAULT_READOUT_C1;
clkDivider[SYSTEM_C0] = DEFAULT_SYSTEM_C0;
@ -478,6 +446,13 @@ void setupDetector() {
setASICDefaults();
setADIFDefaults();
// set module id in register
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return;
}
setModuleId(modid);
// set trigger flow for m3 (for all timing modes)
bus_w(FLOW_TRIGGER_REG, bus_r(FLOW_TRIGGER_REG) | FLOW_TRIGGER_MSK);
@ -501,6 +476,13 @@ void setupDetector() {
setInitialExtSignals();
// 10G UDP
enableTenGigabitEthernet(1);
#ifdef VIRTUAL
enableTenGigabitEthernet(0);
#endif
getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return;
}
setSettings(DEFAULT_SETTINGS);
// check module type attached if not in debug mode
@ -717,27 +699,6 @@ void setADIFDefaults() {
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) */
void cleanFifos() {
@ -767,54 +728,46 @@ void resetPeripheral() {
/* set parameters - dr, roi */
int setDynamicRange(int dr) {
if (dr <= 0) {
return FAIL;
if (dr > 0) {
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();
}
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;
switch (regval) {
/*case CONFIG_DYNAMIC_RANGE_1_VAL: TODO:Not implemented in firmware yet
return 1;*/
case CONFIG_DYNAMIC_RANGE_8_VAL:
*retval = 8;
break;
return 8;
case CONFIG_DYNAMIC_RANGE_16_VAL:
*retval = 16;
break;
return 16;
case CONFIG_DYNAMIC_RANGE_24_VAL:
*retval = 32;
break;
return 32;
default:
LOG(logERROR, ("Invalid dynamic range %d read back\n",
regval >> CONFIG_DYNAMIC_RANGE_OFST));
return FAIL;
return -1;
}
return OK;
}
/* set parameters - readout */
@ -1137,8 +1090,7 @@ void updatePacketizing() {
// 10g
if (tgEnable) {
int dr = 0;
getDynamicRange(&dr);
const int dr = setDynamicRange(-1);
packetsPerFrame = 1;
if (dr == 32 && ncounters > 1) {
packetsPerFrame = 2;
@ -1592,18 +1544,14 @@ int setHighVoltage(int val) {
/* parameters - timing */
int isMaster(int *retval) {
int slave = ((bus_r(SYSTEM_STATUS_REG) & SYSTEM_STATUS_SLV_BRD_DTCT_MSK) >>
SYSTEM_STATUS_SLV_BRD_DTCT_OFST);
*retval = (slave == 0 ? 1 : 0);
return OK;
int isMaster() {
return !((bus_r(SYSTEM_STATUS_REG) & SYSTEM_STATUS_SLV_BRD_DTCT_MSK) >>
SYSTEM_STATUS_SLV_BRD_DTCT_OFST);
}
void setTiming(enum timingMode arg) {
int master = 0;
isMaster(&master);
if (master && arg == AUTO_TIMING)
if (!isMaster() && arg == AUTO_TIMING)
arg = TRIGGER_EXPOSURE;
uint32_t addr = CONFIG_REG;
@ -1771,8 +1719,6 @@ int getExtSignal(int signalIndex) {
}
}
int getNumberofUDPInterfaces() { return 1; }
int configureMAC() {
uint32_t srcip = udpDetails[0].srcip;
@ -2253,8 +2199,7 @@ void *start_timer(void *arg) {
const int imageSize = calculateDataBytes();
const int tgEnable = enableTenGigabitEthernet(-1);
int dr = 0;
getDynamicRange(&dr);
const int dr = setDynamicRange(-1);
int ncounters = __builtin_popcount(getCounterMask());
int dataSize = 0;
int packetsPerFrame = 0;
@ -2335,7 +2280,7 @@ void *start_timer(void *arg) {
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = virtual_currentFrameNumber;
header->packetNumber = i;
header->modId = virtual_moduleid;
header->modId = 0;
header->row = detPos[X];
header->column = detPos[Y];
@ -2575,8 +2520,7 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
int calculateDataBytes() {
int numCounters = __builtin_popcount(getCounterMask());
int dr = 0;
getDynamicRange(&dr);
int dr = setDynamicRange(-1);
return (NCHAN_1_COUNTER * NCHIP * numCounters * ((double)dr / 8.00));
}

View File

@ -95,7 +95,7 @@ enum DACINDEX {
#define DAC_NAMES \
"vcassh", "vth2", "vrshaper", "vrshaper_n", "vipre_out", "vth3", "vth1", \
"vicin", "vcas", "vrpreamp", "vcal_n", "vipre", "vishaper", "vcal_p", \
"vtrim", "vdcsh", "vthreshold"
"vtrim", "vdcsh"
#define DEFAULT_DAC_VALS \
{ \
1200, /* casSh */ \

View File

@ -4,11 +4,25 @@
#include <inttypes.h>
uint32_t getUDPPacketNumber();
uint64_t getUDPFrameNumber();
void setUDPFrameNumber(uint64_t fnum);
/**
* Get current udp packet number
*/
uint32_t getUDPPacketNumber();
/**
* Get current udp frame number
*/
uint64_t getUDPFrameNumber();
/**
* Called for each UDP packet header creation
* @param buffer pointer to header
* @param id module id
*/
void createUDPPacketHeader(char *buffer, uint16_t id);
/**
* fill up the udp packet with data till its full
* @param buffer pointer to memory
*/
int fillUDPPacket(char *buffer);

View File

@ -97,9 +97,6 @@ u_int32_t getDetectorNumber();
#if defined(GOTTHARD2D) || defined(EIGERD) || defined(MYTHEN3D)
int getModuleId(int *ret, char *mess);
#endif
#if defined(EIGERD) || defined(MYTHEN3D) || defined(GOTTHARD2D)
int updateModuleId();
#endif
#if defined(GOTTHARD2D) || defined(MYTHEN3D)
void setModuleId(int modid);
#endif
@ -113,11 +110,7 @@ u_int32_t getBoardRevision();
void initControlServer();
void initStopServer();
#ifdef EIGERD
int updateModuleConfiguration();
int getModuleConfiguration(int *m, int *t, int *n);
#ifdef VIRTUAL
void checkVirtual9MFlag();
#endif
void getModuleConfiguration();
#endif
// set up detector
@ -144,10 +137,6 @@ void setADIFDefaults();
#if defined(GOTTHARD2D) || defined(EIGERD) || defined(JUNGFRAUD)
int readConfigFile();
#endif
#if defined(GOTTHARDD) || defined(GOTTHARD2D) || defined(EIGERD) || \
defined(MYTHEN3D)
int checkCommandLineConfiguration();
#endif
#ifdef EIGERD
void resetToHardwareSettings();
#endif
@ -184,7 +173,6 @@ void setMasterSlaveConfiguration();
// parameters - dr, roi
int setDynamicRange(int dr);
int getDynamicRange(int *retval);
#ifdef GOTTHARDD
int setROI(ROI arg);
ROI getROI();
@ -225,8 +213,7 @@ int getReadoutMode();
int selectStoragecellStart(int pos);
int getMaxStoragecellStart();
#endif
#if defined(JUNGFRAUD) || defined(EIGERD) || defined(MOENCHD) || \
defined(CHIPTESTBOARDD)
#if defined(JUNGFRAUD) || defined(EIGERD)
int setNextFrameNumber(uint64_t value);
int getNextFrameNumber(uint64_t *value);
#endif
@ -374,16 +361,9 @@ int getADC(enum ADCINDEX ind);
int setHighVoltage(int val);
// parameters - timing, extsig
#ifdef EIGERD
int setMaster(enum MASTERINDEX m);
int setTop(enum TOPINDEX t);
int isTop(int *retval);
#if defined(MYTHEN3D) || defined(EIGERD) || defined(GOTTHARDD)
int isMaster();
#endif
#if defined(MYTHEN3D) || defined(EIGERD) || defined(GOTTHARDD) || \
defined(GOTTHARD2D)
int isMaster(int *retval);
#endif
#ifdef GOTTHARD2D
void updatingRegisters();
#endif
@ -407,8 +387,8 @@ void calcChecksum(mac_conf *mac, int sourceip, int destip);
#endif
#if defined(JUNGFRAUD) || defined(GOTTHARD2D)
void setNumberofUDPInterfaces(int val);
#endif
int getNumberofUDPInterfaces();
#endif
#if defined(JUNGFRAUD) || defined(EIGERD)
int getNumberofDestinations(int *retval);

View File

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

View File

@ -32,11 +32,6 @@ uint64_t udpFrameNumber = 0;
uint32_t getUDPPacketNumber() { return udpPacketNumber; }
uint64_t getUDPFrameNumber() { return udpFrameNumber; }
void setUDPFrameNumber(uint64_t fnum) {
LOG(logINFO, ("Setting next frame number also for 1g to %lld\n", fnum));
// this gets incremented before setting it
udpFrameNumber = fnum - 1;
}
void createUDPPacketHeader(char *buffer, uint16_t id) {
memset(buffer, 0, sizeof(sls_detector_header));

View File

@ -74,14 +74,8 @@ int getTimeFromString(char *buf, time_t *result) {
// remove timezone as strptime cannot validate timezone despite
// documentation (for blackfin)
LOG(logDEBUG, ("kernel v %s\n", buffer));
char timezone[8] = {0};
strcpy(timezone, "CEST");
const char *timezone = {"CEST"};
char *res = strstr(buffer, timezone);
// remove CET as well
if (res == NULL) {
strcpy(timezone, "CET");
res = strstr(buffer, timezone);
}
if (res != NULL) {
size_t cestPos = res - buffer;
size_t pos = cestPos + strlen(timezone) + 1;
@ -669,4 +663,4 @@ int deleteFile(char *mess, char *fname, char *errorPrefix) {
("\tFile does not exist anyway: %s (%s)\n", fullname, errorPrefix));
}
return OK;
}
}

View File

@ -26,19 +26,11 @@ extern int sockfd;
extern int debugflag;
extern int updateFlag;
extern int checkModuleFlag;
extern int ignoreConfigFileFlag;
// Global variables from slsDetectorFunctionList
#ifdef GOTTHARDD
extern int phaseShift;
#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); }
@ -56,57 +48,26 @@ int main(int argc, char *argv[]) {
updateFlag = 0;
checkModuleFlag = 1;
int version = 0;
ignoreConfigFileFlag = 0;
#if defined(GOTTHARDD) || defined(GOTTHARD2D) || defined(EIGERD) || \
defined(MYTHEN3D)
masterCommandLine = -1;
#endif
#ifdef EIGERD
topCommandLine = -1;
#endif
// help message
const size_t helpMessageSize = 1200;
char helpMessage[helpMessageSize];
{
memset(helpMessage, 0, helpMessageSize);
int len = snprintf(
helpMessage, helpMessageSize,
"Usage: %s [arguments]\n"
"Possible arguments are:\n"
"\t-v, --version : Software version\n"
"\t-p, --port <port> : TCP communication port with client. "
"\n"
"\t-g, --nomodule : [Mythen3][Gotthard2] \n"
"\t Generic or No Module mode. Skips "
"detector type checks. \n"
"\t-f, --phaseshift <value> : [Gotthard] only. Sets phase shift. \n"
"\t-d, --devel : Developer mode. Skips firmware "
"checks. \n"
"\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));
}
}
char helpMessage[MAX_STR_LENGTH];
memset(helpMessage, 0, MAX_STR_LENGTH);
sprintf(
helpMessage,
"Usage: %s [arguments]\n"
"Possible arguments are:\n"
"\t-v, --version : Software version\n"
"\t-p, --port <port> : TCP communication port with client. \n"
"\t-g, --nomodule : [Mythen3][Gotthard2] Generic or No "
"Module mode. Skips detector type checks. \n"
"\t-f, --phaseshift <value> : [Gotthard] only. Sets phase shift. \n"
"\t-d, --devel : Developer mode. Skips firmware checks. \n"
"\t-u, --update : Update mode. Skips firmware checks and "
"initial detector setup. \n"
"\t-s, --stopserver : Stop server. Do not use as it is created "
"by "
"control server \n\n",
argv[0]);
// parse command line for config
static struct option long_options[] = {
@ -119,9 +80,6 @@ int main(int argc, char *argv[]) {
{"nomodule", no_argument, NULL, 'g'}, // generic
{"devel", no_argument, NULL, 'd'},
{"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'},
{NULL, 0, NULL, 0}};
@ -131,8 +89,7 @@ int main(int argc, char *argv[]) {
int c = 0;
while (c != -1) {
c = getopt_long(argc, argv, "hvp:f:gduim:t:s", long_options,
&option_index);
c = getopt_long(argc, argv, "hvp:f:gdus", long_options, &option_index);
// Detect the end of the options
if (c == -1)
@ -203,57 +160,6 @@ int main(int argc, char *argv[]) {
isControlServer = 0;
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':
printf("%s", helpMessage);
exit(EXIT_SUCCESS);

View File

@ -37,8 +37,6 @@ const enum detectorType myDetectorType = GOTTHARD2;
const enum detectorType myDetectorType = GENERIC;
#endif
#define LOCALHOSTIP_INT 2130706433
// Global variables from communication_funcs
extern int lockStatus;
extern uint32_t lastClientIP;
@ -54,7 +52,6 @@ int sockfd = 0;
int debugflag = 0;
int updateFlag = 0;
int checkModuleFlag = 1;
int ignoreConfigFileFlag = 0;
udpStruct udpDetails[MAX_UDP_DESTINATION];
int numUdpDestinations = 1;
@ -81,32 +78,28 @@ char scanErrMessage[MAX_STR_LENGTH] = "";
/* initialization functions */
int updateModeAllowedFunction(int file_des) {
enum detFuncs allowedFuncs[] = {F_EXEC_COMMAND,
F_GET_DETECTOR_TYPE,
F_GET_FIRMWARE_VERSION,
F_GET_SERVER_VERSION,
F_GET_SERIAL_NUMBER,
F_WRITE_REGISTER,
F_READ_REGISTER,
F_LOCK_SERVER,
F_GET_LAST_CLIENT_IP,
F_PROGRAM_FPGA,
F_RESET_FPGA,
F_CHECK_VERSION,
F_COPY_DET_SERVER,
F_REBOOT_CONTROLLER,
F_GET_KERNEL_VERSION,
F_UPDATE_KERNEL,
F_UPDATE_DETECTOR_SERVER,
F_GET_UPDATE_MODE,
F_SET_UPDATE_MODE,
F_GET_NUM_CHANNELS,
F_GET_NUM_INTERFACES,
F_ACTIVATE};
size_t allowedFuncsSize = sizeof(allowedFuncs) / sizeof(enum detFuncs);
for (unsigned int i = 0; i < allowedFuncsSize; ++i) {
if ((unsigned int)fnum == allowedFuncs[i]) {
unsigned int listsize = 19;
enum detFuncs list[] = {F_EXEC_COMMAND,
F_GET_DETECTOR_TYPE,
F_GET_FIRMWARE_VERSION,
F_GET_SERVER_VERSION,
F_GET_SERIAL_NUMBER,
F_WRITE_REGISTER,
F_READ_REGISTER,
F_LOCK_SERVER,
F_GET_LAST_CLIENT_IP,
F_PROGRAM_FPGA,
F_RESET_FPGA,
F_CHECK_VERSION,
F_COPY_DET_SERVER,
F_REBOOT_CONTROLLER,
F_GET_KERNEL_VERSION,
F_UPDATE_KERNEL,
F_UPDATE_DETECTOR_SERVER,
F_GET_UPDATE_MODE,
F_SET_UPDATE_MODE};
for (unsigned int i = 0; i < listsize; ++i) {
if ((unsigned int)fnum == list[i]) {
return OK;
}
}
@ -126,11 +119,10 @@ int printSocketReadError() {
}
void init_detector() {
memset(udpDetails, 0, sizeof(udpDetails));
#ifdef VIRTUAL
LOG(logINFO, ("This is a VIRTUAL detector\n"));
udpDetails[0].srcip = LOCALHOSTIP_INT;
#endif
memset(udpDetails, 0, sizeof(udpDetails));
udpDetails[0].srcport = DEFAULT_UDP_SRC_PORTNO;
udpDetails[0].dstport = DEFAULT_UDP_DST_PORTNO;
#ifdef EIGERD
@ -469,9 +461,6 @@ void function_table() {
flist[F_UPDATE_DETECTOR_SERVER] = &update_detector_server;
flist[F_GET_UPDATE_MODE] = &get_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
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -2819,9 +2808,6 @@ int set_dynamic_range(int file_des) {
#endif
#if defined(EIGERD) || defined(MYTHEN3D)
case 8:
#ifdef EIGERD
case 12:
#endif
case 16:
case 32:
#endif
@ -2829,25 +2815,14 @@ int set_dynamic_range(int file_des) {
defined(MOENCHD) || defined(GOTTHARD2D)
case 16:
#endif
if (dr >= 0) {
ret = setDynamicRange(dr);
if (ret == FAIL) {
sprintf(mess, "Could not set dynamic range to %d\n", dr);
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);
}
retval = setDynamicRange(dr);
LOG(logDEBUG1, ("Dynamic range: %d\n", retval));
if (retval == -1) {
ret = FAIL;
sprintf(mess, "Could not get dynamic range.\n");
LOG(logERROR, (mess));
}
validate(&ret, mess, dr, retval, "set dynamic range", DEC);
break;
default:
modeNotImplemented("Dynamic range", dr);
@ -2957,7 +2932,7 @@ int enable_ten_giga(int file_des) {
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError();
LOG(logDEBUG, ("Setting 10GbE: %d\n", arg));
LOG(logINFOBLUE, ("Setting 10GbE: %d\n", arg));
#if defined(JUNGFRAUD) || defined(GOTTHARDD) || defined(GOTTHARD2D)
functionNotImplemented();
@ -3995,26 +3970,29 @@ int check_version(int file_des) {
return printSocketReadError();
// check software- firmware compatibility and basic tests
LOG(logDEBUG1, ("Checking software-firmware compatibility and basic "
"test result\n"));
if (isControlServer) {
LOG(logDEBUG1, ("Checking software-firmware compatibility and basic "
"test result\n"));
// check if firmware check is done
if (!isInitCheckDone()) {
usleep(3 * 1000 * 1000);
// check if firmware check is done
if (!isInitCheckDone()) {
ret = FAIL;
strcpy(mess, "Server Initialization still not done done in server. Unexpected.\n");
LOG(logERROR, (mess));
usleep(3 * 1000 * 1000);
if (!isInitCheckDone()) {
ret = FAIL;
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;
if (getInitResult(&firmware_message) == FAIL) {
ret = FAIL;
strcpy(mess, firmware_message);
LOG(logERROR, (mess));
// check firmware check result
if (ret == OK) {
char *firmware_message = NULL;
if (getInitResult(&firmware_message) == FAIL) {
ret = FAIL;
strcpy(mess, firmware_message);
LOG(logERROR, (mess));
}
}
}
@ -4433,10 +4411,9 @@ int set_next_frame_number(int file_des) {
if (receiveData(file_des, &arg, sizeof(arg), INT64) < 0)
return printSocketReadError();
LOG(logDEBUG1, ("Setting next frame number to %llu\n", arg));
LOG(logINFO, ("Setting next frame number to %llu\n", arg));
#if (!defined(EIGERD)) && (!defined(JUNGFRAUD)) && (!defined(MOENCHD)) && \
(!defined(CHIPTESTBOARDD))
#if (!defined(EIGERD)) && (!defined(JUNGFRAUD))
functionNotImplemented();
#else
// only set
@ -4446,7 +4423,7 @@ int set_next_frame_number(int file_des) {
sprintf(mess, "Could not set next frame number. Cannot be 0.\n");
LOG(logERROR, (mess));
}
#if (defined(EIGERD)) || (defined(MOENCHD)) || (defined(CHIPTESTBOARDD))
#ifdef EIGERD
else if (arg > UDP_HEADER_MAX_FRAME_VALUE) {
ret = FAIL;
#ifdef VIRTUAL
@ -4466,18 +4443,16 @@ int set_next_frame_number(int file_des) {
else {
ret = setNextFrameNumber(arg);
if (ret == FAIL) {
sprintf(
mess, "Could not set next frame number. %s\n",
(myDetectorType == EIGER ? "Failed to map address" : ""));
sprintf(mess, "Could not set next frame number. Failed to "
"map address.\n");
LOG(logERROR, (mess));
}
if (ret == OK) {
uint64_t retval = 0;
ret = getNextFrameNumber(&retval);
if (ret == FAIL) {
sprintf(mess, "Could not set next frame number. %s\n",
(myDetectorType == EIGER ? "Failed to map address"
: ""));
sprintf(mess, "Could not get next frame number. Failed "
"to map address.\n");
LOG(logERROR, (mess));
} else if (ret == -2) {
sprintf(mess, "Inconsistent next frame number from "
@ -4514,15 +4489,14 @@ int get_next_frame_number(int file_des) {
LOG(logDEBUG1, ("Getting next frame number \n"));
#if (!defined(EIGERD)) && (!defined(JUNGFRAUD)) && (!defined(MOENCHD)) && \
(!defined(CHIPTESTBOARDD))
#if (!defined(EIGERD)) && (!defined(JUNGFRAUD))
functionNotImplemented();
#else
// get
ret = getNextFrameNumber(&retval);
if (ret == FAIL) {
sprintf(mess, "Could not set next frame number. %s\n",
(myDetectorType == EIGER ? "Failed to map address" : ""));
sprintf(mess, "Could not get next frame number. Failed to map "
"address.\n");
LOG(logERROR, (mess));
} else if (ret == -2) {
sprintf(mess, "Inconsistent next frame number from left and right "
@ -4665,17 +4639,11 @@ int set_read_n_rows(int file_des) {
LOG(logERROR, (mess));
} else {
#ifdef EIGERD
int dr = 0;
ret = getDynamicRange(&dr);
int dr = setDynamicRange(GET_FLAG);
int isTenGiga = enableTenGigabitEthernet(GET_FLAG);
unsigned int maxnl = MAX_ROWS_PER_READOUT;
unsigned int maxnp = (isTenGiga ? 4 : 16) * dr;
// 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) {
if ((arg * maxnp) % maxnl) {
ret = FAIL;
sprintf(mess,
"Could not set number of rows to %d. For %d bit "
@ -4757,22 +4725,19 @@ void calculate_and_set_position() {
LOG(logERROR, (mess));
return;
}
// calculating new position
int modulePorts[2] = {1, 1};
// position does change for eiger and jungfrau (2 interfaces)
#if defined(EIGERD)
modulePorts[1] = getNumberofUDPInterfaces(); // horz
#elif defined(JUNGFRAUD)
modulePorts[0] = getNumberofUDPInterfaces(); // vert
int maxy = maxydet;
// position does not change for gotthard2 (2 interfaces)
#ifdef JUNGFRAUD
maxy *= getNumberofUDPInterfaces();
#endif
int maxy = maxydet * modulePorts[0];
int pos[2] = {0, 0};
// row
pos[0] = (detectorId % maxy);
// col for horiz. udp ports
pos[1] = (detectorId / maxy) * modulePorts[1];
pos[1] = (detectorId / maxy);
#ifdef EIGERD
pos[1] *= 2;
#endif
LOG(logDEBUG, ("Setting Positions (%d,%d)\n", pos[0], pos[1]));
if (setDetectorPosition(pos) == FAIL) {
ret = FAIL;
@ -4883,15 +4848,12 @@ int is_udp_configured() {
LOG(logWARNING, ("%s", configureMessage));
return FAIL;
}
// virtual: no check (can be eth name: lo, ip: 127.0.0.1)
#ifndef VIRTUAL
if (udpDetails[i].dstmac == 0) {
sprintf(configureMessage,
"udp destination mac not configured [entry:%d]\n", i);
LOG(logWARNING, ("%s", configureMessage));
return FAIL;
}
#endif
#if defined(JUNGFRAUD) || defined(GOTTHARD2D)
if (getNumberofUDPInterfaces() == 2) {
if (udpDetails[i].srcip2 == 0) {
@ -4912,14 +4874,12 @@ int is_udp_configured() {
LOG(logWARNING, ("%s", configureMessage));
return FAIL;
}
#ifndef VIRTUAL
if (udpDetails[i].dstmac2 == 0) {
sprintf(configureMessage,
"udp destination mac2 not configured [entry:%d]\n", i);
LOG(logWARNING, ("%s", configureMessage));
return FAIL;
}
#endif
}
#endif
}
@ -5360,16 +5320,7 @@ int set_num_interfaces(int file_des) {
LOG(logINFO, ("Setting number of interfaces: %d\n", arg));
#if !defined(JUNGFRAUD) && !defined(GOTTHARD2D)
// fixed number of udp interfaces
int num_interfaces = getNumberofUDPInterfaces();
if (arg != num_interfaces) {
ret = FAIL;
sprintf(mess,
"Could not set number of interfaces. Invalid value: %d. Must "
"be %d\n",
arg, num_interfaces);
LOG(logERROR, (mess));
}
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
@ -5429,9 +5380,12 @@ int get_num_interfaces(int file_des) {
int retval = -1;
LOG(logDEBUG1, ("Getting number of udp interfaces\n"));
#if !defined(JUNGFRAUD) && !defined(GOTTHARD2D)
retval = 1;
#else
// get only
retval = getNumberofUDPInterfaces();
#endif
LOG(logDEBUG1, ("Number of udp interfaces retval: %u\n", retval));
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}
@ -6929,7 +6883,11 @@ int get_receiver_parameters(int file_des) {
// sending real detector parameters
// udp interfaces
#if defined(JUNGFRAUD) || defined(GOTTHARD2D)
i32 = getNumberofUDPInterfaces();
#else
i32 = 1;
#endif
n += sendData(file_des, &i32, sizeof(i32), INT32);
if (n < 0)
return printSocketReadError();
@ -7133,10 +7091,7 @@ int get_receiver_parameters(int file_des) {
}
// dynamic range
ret = getDynamicRange(&i32);
if (ret == FAIL) {
i32 = 0;
}
i32 = setDynamicRange(GET_FLAG);
n += sendData(file_des, &i32, sizeof(i32), INT32);
if (n < 0)
return printSocketReadError();
@ -8218,60 +8173,14 @@ int get_master(int file_des) {
LOG(logDEBUG1, ("Getting master\n"));
#if !defined(MYTHEN3D) && !defined(EIGERD) && !defined(GOTTHARDD) && \
!defined(GOTTHARD2D)
#if !defined(MYTHEN3D) && !defined(EIGERD) && !defined(GOTTHARDD)
functionNotImplemented();
#else
ret = isMaster(&retval);
if (ret == FAIL) {
strcpy(mess, "Could not get master\n");
LOG(logERROR, (mess));
}
retval = isMaster();
#endif
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) {
ret = OK;
memset(mess, 0, sizeof(mess));
@ -9220,25 +9129,8 @@ int clear_all_udp_dst(int file_des) {
if (check_detector_idle("clear all udp destinations") == OK) {
memset(udpDetails, 0, sizeof(udpDetails));
// minimum 1 destination in fpga
int numdest = 1;
// 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));
}
}
numUdpDestinations = 1;
configure_mac();
}
}
return Server_SendResult(file_des, INT32, NULL, 0);
@ -9761,67 +9653,5 @@ 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);
}

View File

@ -193,12 +193,6 @@ class Detector {
*/
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;
///@}
@ -290,7 +284,7 @@ class Detector {
Result<int> getDynamicRange(Positions pos = {}) const;
/**
* [Eiger] Options: 4, 8, 12, 16, 32. If i is 32, also sets clkdivider to 2,
* [Eiger] Options: 4, 8, 16, 32. If i is 32, also sets clkdivider to 2,
* else sets clkdivider to 1 \n [Mythen3] Options: 8, 16, 32 \n
* [Jungfrau][Gotthard][Ctb][Moench][Mythen3][Gotthard2] 16
*/
@ -573,7 +567,7 @@ class Detector {
/** Non blocking: start detector acquisition. Status changes to RUNNING or
* WAITING and automatically returns to idle at the end of acquisition.
[Mythen3] Master starts acquisition first */
void startDetector(Positions pos = {});
void startDetector();
/** [Mythen3] Non blocking: start detector readout of counters in chip.
* Status changes to TRANSMITTING and automatically returns to idle at the
@ -594,15 +588,17 @@ class Detector {
Result<int64_t> getFramesCaught(Positions pos = {}) const;
/** Gets the number of missing packets for each port in receiver. Negative
* number denotes extra packets. */
Result<std::vector<int64_t>> getNumMissingPackets(Positions pos = {}) const;
/** Gets the number of missing packets for each port in receiver.
* Troubleshoot: If they are large numbers, convert it to signed to get
* number of access packets received */
Result<std::vector<uint64_t>>
getNumMissingPackets(Positions pos = {}) const;
/** [Eiger][Jungfrau][Moench][CTB] */
/** [Eiger][Jungfrau] */
Result<uint64_t> getNextFrameNumber(Positions pos = {}) const;
/** [Eiger][Jungfrau][Moench][CTB] Stopping acquisition might result in
* different frame numbers for different modules.*/
/** [Eiger][Jungfrau] Stopping acquisition might result in different frame
* numbers for different modules.*/
void setNextFrameNumber(uint64_t value, Positions pos = {});
/** [Eiger][Mythen3] Sends an internal software trigger to the detector
@ -699,60 +695,48 @@ class Detector {
/**[Jungfrau] Options 0-31 (or number of udp destinations) */
void setFirstUDPDestination(const int value, Positions pos = {});
Result<IpAddr> getDestinationUDPIP(Positions pos = {},
const int rx_index = 0) const;
Result<IpAddr> getDestinationUDPIP(Positions pos = {}) const;
/** IP of the interface in receiver that the detector sends data to */
void setDestinationUDPIP(const IpAddr ip, Positions pos = {},
const int rx_index = 0);
void setDestinationUDPIP(const IpAddr ip, Positions pos = {});
/** [Jungfrau] bottom half \n [Gotthard2] veto debugging */
Result<IpAddr> getDestinationUDPIP2(Positions pos = {},
const int rx_index = 0) const;
Result<IpAddr> getDestinationUDPIP2(Positions pos = {}) const;
/** [Jungfrau] bottom half \n [Gotthard2] veto debugging */
void setDestinationUDPIP2(const IpAddr ip, Positions pos = {},
const int rx_index = 0);
void setDestinationUDPIP2(const IpAddr ip, Positions pos = {});
Result<MacAddr> getDestinationUDPMAC(Positions pos = {},
const int rxIndex = 0) const;
Result<MacAddr> getDestinationUDPMAC(Positions pos = {}) const;
/** Mac address of the receiver (destination) udp interface. Not mandatory
* to set as setDestinationUDPIP (udp_dstip) retrieves it from slsReceiver
* process but must be set if you use a custom receiver (not slsReceiver).
*/
void setDestinationUDPMAC(const MacAddr mac, Positions pos = {},
const int rx_index = 0);
void setDestinationUDPMAC(const MacAddr mac, Positions pos = {});
/** [Jungfrau] bottom half \n [Gotthard2] veto debugging */
Result<MacAddr> getDestinationUDPMAC2(Positions pos = {},
const int rx_index = 0) const;
Result<MacAddr> getDestinationUDPMAC2(Positions pos = {}) const;
/* [Jungfrau][Gotthard2] Mac address of the receiver (destination) udp
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). \n [Jungfrau] bottom half \n [Gotthard2] veto debugging \n
*/
void setDestinationUDPMAC2(const MacAddr mac, Positions pos = {},
const int rx_index = 0);
void setDestinationUDPMAC2(const MacAddr mac, Positions pos = {});
Result<int> getDestinationUDPPort(Positions pos = {},
const int rx_index = 0) const;
Result<int> getDestinationUDPPort(Positions pos = {}) const;
/** Default is 50001. \n If module_id is -1, ports for each module is
* calculated (incremented by 1 if no 2nd interface) */
void setDestinationUDPPort(int port, int module_id = -1,
const int rxIndex = 0);
void setDestinationUDPPort(int port, int module_id = -1);
/** [Eiger] right port[Jungfrau] bottom half [Gotthard2] veto debugging */
Result<int> getDestinationUDPPort2(Positions pos = {},
const int rx_index = 0) const;
Result<int> getDestinationUDPPort2(Positions pos = {}) const;
/** [Eiger] right port[Jungfrau] bottom half [Gotthard2] veto debugging \n
* Default is 50002. \n If module_id is -1, ports for each module is
* calculated (incremented by 1 if no 2nd interface)*/
void setDestinationUDPPort2(int port, int module_id = -1,
const int rxIndex = 0);
void setDestinationUDPPort2(int port, int module_id = -1);
/** Reconfigures Detector with UDP destination. More for debugging as the
* configuration is done automatically when the detector has sufficient UDP
@ -764,8 +748,7 @@ class Detector {
* information */
void validateUDPConfiguration(Positions pos = {});
Result<std::string> printRxConfiguration(Positions pos = {},
const int rx_index = 0) const;
Result<std::string> printRxConfiguration(Positions pos = {}) const;
/** [Eiger][CTB][Moench][Mythen3] */
Result<bool> getTenGiga(Positions pos = {}) const;
@ -824,8 +807,7 @@ class Detector {
/** true when slsReceiver is used */
Result<bool> getUseReceiverFlag(Positions pos = {}) const;
Result<std::string> getRxHostname(Positions pos = {},
const int rx_index = 0) const;
Result<std::string> getRxHostname(Positions pos = {}) const;
/**
* Sets receiver hostname or IP address for each module. \n Used for TCP
@ -833,24 +815,20 @@ class Detector {
* Also updates receiver with detector parameters. \n Also resets any prior
* receiver property (not on detector). \n receiver is receiver hostname or
* 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 = {}, const int rxIndex = 0);
void setRxHostname(const std::string &receiver, Positions pos = {});
/** - single element, assumes rxIndex is 0 (for backwards compatibility).
* - 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);
/** multiple rx hostnames. Single element will set it for all */
void setRxHostname(const std::vector<std::string> &name);
Result<int> getRxPort(Positions pos = {}, const int rx_index = 0) const;
Result<int> getRxPort(Positions pos = {}) const;
/** TCP port for client-receiver communication. \n
* 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
* communicate. \n Multi command will automatically increment port for
* individual modules.*/
void setRxPort(int port, int module_id = -1, const int rx_index = 0);
void setRxPort(int port, int module_id = -1);
Result<int> getRxFifoDepth(Positions pos = {}) const;
@ -900,18 +878,10 @@ class Detector {
Result<sls::IpAddr> getRxLastClientIP(Positions pos = {}) const;
/** Get thread ids from the receiver in order of [parent, tcp, listener 0,
* processor 0, streamer 0, listener 1, processor 1, streamer 1, arping]. If
* no streamer yet or there is no second interface, it gives 0 in its place.
*/
* processor 0, streamer 0, listener 1, processor 1, streamer 1]. If no
* streamer yet or there is no second interface, it gives 0 in its place. */
Result<std::array<pid_t, NUM_RX_THREAD_IDS>>
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 */
@ -1028,15 +998,13 @@ class Detector {
*/
void setRxZmqPort(int port, int module_id = -1);
Result<IpAddr> getRxZmqIP(Positions pos = {},
const int rx_index = 0) const;
Result<IpAddr> getRxZmqIP(Positions pos = {}) const;
/** 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
* rx_hostname. \n Modified only when using an intermediate process between
* receiver. */
void setRxZmqIP(const IpAddr ip, Positions pos = {},
const int rx_index = 0);
void setRxZmqIP(const IpAddr ip, Positions pos = {});
Result<int> getClientZmqPort(Positions pos = {}) const;
@ -1171,18 +1139,12 @@ class Detector {
Result<bool> getDataStream(const defs::portPosition port,
Positions pos = {}) const;
/** [Eiger] enable or disable data streaming from left or right of detector
* for 10GbE. Default: enabled
/** [Eiger] enable or disable data streaming from left or right of detector.
* Default: enabled
*/
void setDataStream(const defs::portPosition port, const bool enable,
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 */
@ -1480,6 +1442,9 @@ class Detector {
* (internal gating). Gate index: 0-2, -1 for all */
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 !!!!!
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) {
throw sls::RuntimeError(
std::string("Invalid receiver index ") + std::to_string(rx_id) + std::string(" to set round robin entry."));
"Invalid receiver index to set round robin entry.");
}
auto t = getUdpEntry();
det->setDestinationUDPList(t, det_id);
@ -1504,7 +1504,7 @@ std::string CmdProxy::UDPDestinationIP(int action) {
"rx_hostname."
<< '\n';
} else if (action == defs::GET_ACTION) {
auto t = det->getDestinationUDPIP(std::vector<int>{det_id}, rx_id);
auto t = det->getDestinationUDPIP(std::vector<int>{det_id});
if (!args.empty()) {
WrongNumberOfParameters(0);
}
@ -1517,11 +1517,11 @@ std::string CmdProxy::UDPDestinationIP(int action) {
auto val = getIpFromAuto();
LOG(logINFO) << "Setting udp_dstip of detector " << det_id << " to "
<< val;
det->setDestinationUDPIP(val, std::vector<int>{det_id}, rx_id);
det->setDestinationUDPIP(val, std::vector<int>{det_id});
os << val << '\n';
} else {
auto val = IpAddr(args[0]);
det->setDestinationUDPIP(val, std::vector<int>{det_id}, rx_id);
det->setDestinationUDPIP(val, std::vector<int>{det_id});
os << args.front() << '\n';
}
} else {
@ -1540,7 +1540,7 @@ std::string CmdProxy::UDPDestinationIP2(int action) {
"\n\t[Gotthard2] veto debugging. "
<< '\n';
} else if (action == defs::GET_ACTION) {
auto t = det->getDestinationUDPIP2(std::vector<int>{det_id}, rx_id);
auto t = det->getDestinationUDPIP2(std::vector<int>{det_id});
if (!args.empty()) {
WrongNumberOfParameters(0);
}
@ -1553,11 +1553,11 @@ std::string CmdProxy::UDPDestinationIP2(int action) {
auto val = getIpFromAuto();
LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id
<< " to " << val;
det->setDestinationUDPIP2(val, std::vector<int>{det_id}, rx_id);
det->setDestinationUDPIP2(val, std::vector<int>{det_id});
os << val << '\n';
} else {
auto val = IpAddr(args[0]);
det->setDestinationUDPIP2(val, std::vector<int>{det_id}, rx_id);
det->setDestinationUDPIP2(val, std::vector<int>{det_id});
os << args.front() << '\n';
}
} else {
@ -1593,54 +1593,33 @@ std::string CmdProxy::ReceiverHostname(int action) {
}
// multiple arguments
if (args.size() > 1) {
if (rx_id != -1) {
throw sls::RuntimeError(
"Cannot add multiple receivers at RR level");
}
// multiple arguments (multiple rxr each)// backwards compatibility
// multiple in mulitple
if (args[0].find('+') != std::string::npos) {
if (det_id != -1) {
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';
}
throw sls::RuntimeError(
"Cannot add multiple receivers at module level");
}
// multiple arguments (single rxr each) (for both: each module and RR)
else {
det->setRxHostname(args, {det_id});
os << ToString(args) << '\n';
if (det_id != -1) {
throw sls::RuntimeError(
"Cannot add multiple receivers at module level");
}
det->setRxHostname(args);
os << ToString(args) << '\n';
}
// single argument
else {
// multiple receivers concatenated with +
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], '+');
if (t.size() <= 0) {
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';
}
det->setRxHostname(t);
os << ToString(t) << '\n';
}
// single receiver
else {
det->setRxHostname(args[0], std::vector<int>{det_id}, rx_id);
det->setRxHostname(args[0], std::vector<int>{det_id});
os << ToString(args) << '\n';
}
}
@ -1825,9 +1804,7 @@ std::string CmdProxy::DataStream(int action) {
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[left|right] [0, 1]\n\t[Eiger] Enables or disables data "
"streaming from left or/and right side of detector for 10 GbE "
"mode. "
"1 (enabled) "
"streaming from left or/and right side of detector. 1 (enabled) "
"by default."
<< '\n';
} else if (action == defs::GET_ACTION) {

View File

@ -185,34 +185,8 @@
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 */
#define INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(CMDNAME, GETFCN, SETFCN, CONV, \
HLPSTR) \
#define INTEGER_COMMAND_VEC_ID_GET(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
os << cmd << ' '; \
@ -237,32 +211,6 @@
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 */
#define INTEGER_COMMAND_SINGLE_ID(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \
std::string CMDNAME(const int action) { \
@ -513,26 +461,6 @@
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) */
#define GET_COMMAND_NOID(CMDNAME, GETFCN, HLPSTR) \
std::string CMDNAME(const int action) { \
@ -856,7 +784,6 @@ class CmdProxy {
{"trimen", &CmdProxy::TrimEnergies},
{"gappixels", &CmdProxy::GapPixels},
{"fliprows", &CmdProxy::fliprows},
{"master", &CmdProxy::master},
/* acquisition parameters */
{"acquire", &CmdProxy::Acquire},
@ -976,7 +903,6 @@ class CmdProxy {
{"rx_lock", &CmdProxy::rx_lock},
{"rx_lastclient", &CmdProxy::rx_lastclient},
{"rx_threads", &CmdProxy::rx_threads},
{"rx_arping", &CmdProxy::rx_arping},
/* File */
{"fformat", &CmdProxy::fformat},
@ -1015,7 +941,6 @@ class CmdProxy {
{"pulsechip", &CmdProxy::PulseChip},
{"quad", &CmdProxy::Quad},
{"datastream", &CmdProxy::DataStream},
{"top", &CmdProxy::top},
/* Jungfrau Specific */
{"chipversion", &CmdProxy::chipversion},
@ -1183,6 +1108,7 @@ class CmdProxy {
/* acquisition parameters */
std::string Acquire(int action);
std::string Exptime(int action);
std::string DynamicRange(int action);
std::string ReadoutSpeed(int action);
std::string Adcphase(int action);
std::string Dbitphase(int action);
@ -1354,12 +1280,6 @@ class CmdProxy {
"interfaces must be set to 2. slsReceiver and slsDetectorGui "
"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 */
INTEGER_COMMAND_SET_NOID_GET_ID(
@ -1407,7 +1327,7 @@ class CmdProxy {
dr, getDynamicRange, setDynamicRange, StringTo<int>,
"[value]\n\tDynamic Range or number of bits per "
"pixel in detector.\n\t"
"[Eiger] Options: 4, 8, 12, 16, 32. If set to 32, also sets "
"[Eiger] Options: 4, 8, 16, 32. If set to 32, also sets "
"clkdivider to 2, else to 0.\n\t"
"[Mythen3] Options: 8, 16, 32\n\t"
"[Jungfrau][Gotthard][Ctb][Moench][Mythen3][Gotthard2] 16");
@ -1595,7 +1515,7 @@ class CmdProxy {
"\n\tStops receiver listener for detector data packets and closes "
"current data file (if file write enabled).");
EXECUTE_SET_COMMAND(
EXECUTE_SET_COMMAND_NOID(
start, startDetector,
"\n\tStarts detector acquisition. Status changes to RUNNING or WAITING "
"and automatically returns to idle at the end of acquisition. If the "
@ -1615,15 +1535,13 @@ class CmdProxy {
"\n\tNumber of frames caught by receiver.");
GET_COMMAND(rx_missingpackets, getNumMissingPackets,
"\n\tNumber of missing packets for each port in receiver. "
"Negative number denotes extra packets.");
"\n\tNumber of missing packets for each port in receiver.");
INTEGER_COMMAND_VEC_ID(
nextframenumber, getNextFrameNumber, setNextFrameNumber,
StringTo<uint64_t>,
"[n_value]\n\t[Eiger][Jungfrau][Moench][CTB] Next frame number. "
"Stopping acquisition might result in different frame numbers for "
"different modules.");
INTEGER_COMMAND_VEC_ID(nextframenumber, getNextFrameNumber,
setNextFrameNumber, StringTo<uint64_t>,
"[n_value]\n\t[Eiger][Jungfrau] Next frame number. "
"Stopping acquisition might result in "
"different frame numbers for different modules.");
GET_COMMAND(scanerrmsg, getScanErrorMessage,
"\n\tGets Scan error message if scan ended in error for non "
@ -1689,14 +1607,14 @@ class CmdProxy {
"[x:x:x:x:x:x]\n\t[Jungfrau] Mac address of the top "
"half or inner (source) udp interface. ");
INTEGER_COMMAND_VEC_ID_RX(
INTEGER_COMMAND_VEC_ID(
udp_dstmac, getDestinationUDPMAC, setDestinationUDPMAC, MacAddr,
"[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 "
"slsReceiver process, but must be set if you use a custom receiver "
"(not slsReceiver).");
INTEGER_COMMAND_VEC_ID_RX(
INTEGER_COMMAND_VEC_ID(
udp_dstmac2, getDestinationUDPMAC2, setDestinationUDPMAC2, MacAddr,
"[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 "
@ -1705,14 +1623,14 @@ class CmdProxy {
"[Gotthard2] veto "
"debugging.");
INTEGER_COMMAND_VEC_ID_P_RX_SINGLE_ID(
INTEGER_COMMAND_VEC_ID_GET(
udp_dstport, getDestinationUDPPort, setDestinationUDPPort,
StringTo<int>,
"[n]\n\tPort number of the receiver (destination) udp "
"interface. Default is 50001. \n\tIf multi command, ports for each "
"module is calculated (incremented by 1 if no 2nd interface)");
INTEGER_COMMAND_VEC_ID_P_RX_SINGLE_ID(
INTEGER_COMMAND_VEC_ID_GET(
udp_dstport2, getDestinationUDPPort2, setDestinationUDPPort2,
StringTo<int>,
"[n]\n\t[Jungfrau][Eiger][Gotthard2] Port number of the "
@ -1734,8 +1652,8 @@ class CmdProxy {
"valid. If not configured, it will throw with error message "
"requesting missing udp information.");
GET_COMMAND_RX(rx_printconfig, printRxConfiguration,
"\n\tPrints the receiver configuration.");
GET_COMMAND(rx_printconfig, printRxConfiguration,
"\n\tPrints the receiver configuration.");
INTEGER_COMMAND_VEC_ID(
tengiga, getTenGiga, setTenGiga, StringTo<int>,
@ -1771,7 +1689,7 @@ class CmdProxy {
/* Receiver Config */
INTEGER_COMMAND_VEC_ID_P_RX_SINGLE_ID(
INTEGER_COMMAND_VEC_ID_GET(
rx_tcpport, getRxPort, setRxPort, StringTo<int>,
"[port]\n\tTCP port for client-receiver communication. Default is "
"1954. Must be different if multiple receivers on same pc. Must be "
@ -1819,16 +1737,13 @@ class CmdProxy {
rx_lastclient, getRxLastClientIP,
"\n\tClient IP Address that last communicated with the receiver.");
GET_COMMAND(rx_threads, getRxThreadIds,
"\n\tGet thread ids from the receiver in order of [parent, "
"tcp, listener 0, processor 0, streamer 0, listener 1, "
"processor 1, streamer 1, arping]. If no streamer yet or there "
"is no second interface, it gives 0 in its place.");
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.");
GET_COMMAND(
rx_threads, getRxThreadIds,
"\n\tGet thread ids from the receiver in order of [parent, tcp, "
"listener 0, "
"processor 0, streamer 0, listener 1, processor 1, streamer 1]. If no "
"streamer yet or there is no second interface, it gives 0 in its "
"place.");
/* File */
@ -1896,7 +1811,7 @@ class CmdProxy {
"default, which streams the first frame in an acquisition, "
"and then depending on the rx zmq frequency/ timer");
INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(
INTEGER_COMMAND_VEC_ID_GET(
rx_zmqport, getRxZmqPort, setRxZmqPort, StringTo<int>,
"[port]\n\tZmq port for data to be streamed out of the receiver. Also "
"restarts receiver zmq streaming if enabled. Default is 30001. "
@ -1904,7 +1819,7 @@ class CmdProxy {
"client(gui). Must be different for every detector (and udp port). "
"Multi command will automatically increment for individual modules.");
INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(
INTEGER_COMMAND_VEC_ID_GET(
zmqport, getClientZmqPort, setClientZmqPort, StringTo<int>,
"[port]\n\tZmq port in client(gui) or intermediate process for data to "
"be streamed to from receiver. Default connects to receiver zmq "
@ -1914,7 +1829,7 @@ class CmdProxy {
"port). Multi command will automatically increment for individual "
"modules.");
INTEGER_COMMAND_VEC_ID_RX(
INTEGER_COMMAND_VEC_ID(
rx_zmqip, getRxZmqIP, setRxZmqIP, IpAddr,
"[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. "
@ -1980,10 +1895,6 @@ class CmdProxy {
"start of acquisition. 0 complete reset, 1 partial reset. Default is "
"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 */
GET_COMMAND(chipversion, getChipVersion,

View File

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

View File

@ -245,15 +245,6 @@ void DetectorImpl::setHostname(const std::vector<std::string> &name) {
addModule(hostname);
}
updateDetectorSize();
// update zmq port (especially for eiger)
int numInterfaces = modules[0]->getNumberofUDPInterfaces();
if (numInterfaces == 2) {
for (size_t i = 0; i < modules.size(); ++i) {
modules[i]->setClientStreamingPort(DEFAULT_ZMQ_CL_PORTNO +
i * numInterfaces);
}
}
}
void DetectorImpl::addModule(const std::string &hostname) {
@ -411,25 +402,31 @@ int DetectorImpl::createReceivingDataSockets() {
}
LOG(logINFO) << "Going to create data sockets";
size_t numUDPInterfaces =
Parallel(&Module::getNumberofUDPInterfacesFromShm, {}).squash(1);
// gotthard2 second interface is only for veto debugging (not in gui)
if (shm()->detType == GOTTHARD2) {
numUDPInterfaces = 1;
size_t numSockets = modules.size();
size_t numSocketsPerModule = 1;
if (shm()->detType == EIGER) {
numSocketsPerModule = 2;
}
size_t numSockets = modules.size() * numUDPInterfaces;
// gotthard2 second interface is only for veto debugging
else if (shm()->detType != GOTTHARD2) {
if (Parallel(&Module::getNumberofUDPInterfacesFromShm, {}).squash() ==
2) {
numSocketsPerModule = 2;
}
}
numSockets *= numSocketsPerModule;
for (size_t iSocket = 0; iSocket < numSockets; ++iSocket) {
uint32_t portnum =
(modules[iSocket / numUDPInterfaces]->getClientStreamingPort());
portnum += (iSocket % numUDPInterfaces);
(modules[iSocket / numSocketsPerModule]->getClientStreamingPort());
portnum += (iSocket % numSocketsPerModule);
try {
zmqSocket.push_back(
sls::make_unique<ZmqSocket>(modules[iSocket / numUDPInterfaces]
->getClientStreamingIP()
.str()
.c_str(),
portnum));
zmqSocket.push_back(sls::make_unique<ZmqSocket>(
modules[iSocket / numSocketsPerModule]
->getClientStreamingIP()
.str()
.c_str(),
portnum));
// set high water mark
int hwm = shm()->zmqHwm;
if (hwm >= 0) {
@ -463,9 +460,13 @@ void DetectorImpl::readFrameFromReceiver() {
int nDetPixelsX = 0;
int nDetPixelsY = 0;
bool quadEnable = false;
// to flip image
bool eiger = false;
bool numInterfaces = 1;
// gotthard2 second interface is veto debugging
if (shm()->detType != GOTTHARD2) {
numInterfaces = Parallel(&Module::getNumberofUDPInterfacesFromShm, {})
.squash(); // cannot pick up from zmq
}
std::vector<bool> runningList(zmqSocket.size());
std::vector<bool> connectList(zmqSocket.size());
numZmqRunning = 0;
@ -541,9 +542,10 @@ void DetectorImpl::readFrameFromReceiver() {
// shape
nPixelsX = zHeader.npixelsx;
nPixelsY = zHeader.npixelsy;
// module shape (port)
// module shape
nX = zHeader.ndetx;
nY = zHeader.ndety;
nY *= numInterfaces;
nDetPixelsX = nX * nPixelsX;
nDetPixelsY = nY * nPixelsY;
// det type

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -629,32 +629,4 @@ TEST_CASE("datastream", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("datastream", {"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,30 +385,6 @@ TEST_CASE("rx_threads", "[.cmd][.rx]") {
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 */
TEST_CASE("fformat", "[.cmd]") {

View File

@ -570,46 +570,6 @@ 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 */
// acquire: not testing
@ -2147,8 +2107,7 @@ TEST_CASE("nextframenumber", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::EIGER || det_type == defs::JUNGFRAU ||
det_type == defs::MOENCH || det_type == defs::CHIPTESTBOARD) {
if (det_type == defs::EIGER || det_type == defs::JUNGFRAU) {
auto prev_sfnum = det.getNextFrameNumber();
REQUIRE_THROWS(proxy.Call("nextframenumber", {"0"}, -1, PUT));
{
@ -2166,41 +2125,6 @@ TEST_CASE("nextframenumber", "[.cmd]") {
proxy.Call("nextframenumber", {"1"}, -1, PUT, oss);
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) {
det.setNextFrameNumber(prev_sfnum[i], {i});
}

View File

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

View File

@ -1,120 +0,0 @@
// 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

@ -1,35 +0,0 @@
// 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,6 +19,7 @@
#include <memory>
#include <sstream>
#include <string>
#include <sys/syscall.h>
#include <unistd.h>
#include <vector>
@ -27,12 +28,6 @@ using sls::RuntimeError;
using sls::SocketError;
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() {
killTcpThread = true;
LOG(logINFO) << "Shutting down TCP Socket on port " << portNumber;
@ -46,7 +41,7 @@ ClientInterface::ClientInterface(int portNumber)
portNumber(portNumber > 0 ? portNumber : DEFAULT_PORTNO + 2),
server(portNumber) {
functionTable();
parentThreadId = gettid();
parentThreadId = syscall(SYS_gettid);
tcpThread =
sls::make_unique<std::thread>(&ClientInterface::startTCPServer, this);
}
@ -81,7 +76,7 @@ void ClientInterface::registerCallBackRawDataModifyReady(
}
void ClientInterface::startTCPServer() {
tcpThreadId = gettid();
tcpThreadId = syscall(SYS_gettid);
LOG(logINFOBLUE) << "Created [ TCP server Tid: " << tcpThreadId << "]";
LOG(logINFO) << "SLS Receiver starting TCP Server on port " << portNumber
<< '\n';
@ -215,8 +210,7 @@ int ClientInterface::functionTable(){
flist[F_SET_RECEIVER_STREAMING_HWM] = &ClientInterface::set_streaming_hwm;
flist[F_RECEIVER_SET_ALL_THRESHOLD] = &ClientInterface::set_all_threshold;
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++) {
LOG(logDEBUG1) << "function fnum: " << i << " (" <<
@ -323,7 +317,10 @@ int ClientInterface::setup_receiver(Interface &socket) {
// basic setup
setDetectorType(arg.detType);
impl()->setDetectorSize(arg.numberOfModule);
{
int msize[2] = {arg.numberOfModule.x, arg.numberOfModule.y};
impl()->setDetectorSize(msize);
}
impl()->setModulePositionId(arg.moduleIndex);
impl()->setDetectorHostname(arg.hostname);
@ -716,7 +713,6 @@ int ClientInterface::set_dynamic_range(Interface &socket) {
break;
*/
case 4:
case 12:
if (detType == EIGER) {
exists = true;
}
@ -848,7 +844,7 @@ int ClientInterface::get_file_index(Interface &socket) {
}
int ClientInterface::get_frame_index(Interface &socket) {
uint64_t retval = impl()->getCurrentFrameIndex();
uint64_t retval = impl()->getAcquisitionIndex();
LOG(logDEBUG1) << "frame index:" << retval;
return socket.sendResult(retval);
}
@ -1405,13 +1401,9 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) {
if (detType == EIGER) {
impl()->setEthernetInterface2(eth);
}
// update locally to use for arping
udpips[0] = arg.str();
// get mac address
auto retval = sls::InterfaceNameToMac(eth);
if (retval == 0 && arg.str() != LOCALHOST_IP) {
if (retval == 0) {
throw RuntimeError("Failed to get udp mac adddress to listen to (eth:" +
eth + ", ip:" + arg.str() + ")\n");
}
@ -1441,12 +1433,9 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) {
}
impl()->setEthernetInterface2(eth);
// update locally to use for arping
udpips[1] = arg.str();
// get mac address
auto retval = sls::InterfaceNameToMac(eth);
if (retval == 0 && arg.str() != LOCALHOST_IP) {
if (retval == 0) {
throw RuntimeError(
"Failed to get udp mac adddress2 to listen to (eth:" + eth +
", ip:" + arg.str() + ")\n");
@ -1711,20 +1700,3 @@ int ClientInterface::set_detector_datastream(Interface &socket) {
impl()->setDetectorDataStream(port, enable);
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,8 +163,6 @@ class ClientInterface : private virtual slsDetectorDefs {
int set_streaming_hwm(sls::ServerInterface &socket);
int set_all_threshold(sls::ServerInterface &socket);
int set_detector_datastream(sls::ServerInterface &socket);
int get_arping(sls::ServerInterface &socket);
int set_arping(sls::ServerInterface &socket);
Implementation *impl() {
if (receiver != nullptr) {
@ -192,6 +190,4 @@ class ClientInterface : private virtual slsDetectorDefs {
pid_t parentThreadId{0};
pid_t tcpThreadId{0};
std::vector<std::string> udpips =
std::vector<std::string>(MAX_NUMBER_OF_LISTENING_THREADS);
};

View File

@ -17,12 +17,11 @@
const std::string DataStreamer::TypeName = "DataStreamer";
DataStreamer::DataStreamer(int ind, Fifo *f, uint32_t *dr, ROI *r, uint64_t *fi,
bool fr, slsDetectorDefs::xy nm, bool *qe,
uint64_t *tot)
bool fr, int *nm, bool *qe, uint64_t *tot)
: ThreadObject(ind, TypeName), fifo(f), dynamicRange(dr), roi(r),
fileIndex(fi), flipRows(fr), quadEnable(qe), totalNumFrames(tot) {
numMods.x = nm.x;
numMods.y = nm.y;
numMods[0] = nm[0];
numMods[1] = nm[1];
LOG(logDEBUG) << "DataStreamer " << ind << " created";
}
@ -63,9 +62,9 @@ void DataStreamer::RecordFirstIndex(uint64_t fnum, char *buf) {
void DataStreamer::SetGeneralData(GeneralData *g) { generalData = g; }
void DataStreamer::SetNumberofModules(xy nm) {
numMods.x = nm.x;
numMods.y = nm.y;
void DataStreamer::SetNumberofModules(int *nm) {
numMods[0] = nm[0];
numMods[1] = nm[1];
}
void DataStreamer::SetFlipRows(bool fd) { flipRows = fd; }
@ -220,8 +219,8 @@ int DataStreamer::SendHeader(sls_receiver_header *rheader, uint32_t size,
zHeader.dynamicRange = *dynamicRange;
zHeader.fileIndex = *fileIndex;
zHeader.ndetx = numMods.x;
zHeader.ndety = numMods.y;
zHeader.ndetx = numMods[0];
zHeader.ndety = numMods[1];
zHeader.npixelsx = nx;
zHeader.npixelsy = ny;
zHeader.imageSize = size;

View File

@ -33,12 +33,12 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
* @param r roi
* @param fi pointer to file index
* @param fr flip rows
* @param nm number of modules in each dimension
* @param nm pointer to number of modules in each dimension
* @param qe pointer to quad Enable
* @param tot pointer to total number of frames
*/
DataStreamer(int ind, Fifo *f, uint32_t *dr, ROI *r, uint64_t *fi, bool fr,
xy nm, bool *qe, uint64_t *tot);
int *nm, bool *qe, uint64_t *tot);
/**
* Destructor
@ -65,9 +65,9 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
/**
* Set number of detectors
* @param nm number of modules/ports in both dimensions
* @param nm number of modules in both dimensions
*/
void SetNumberofModules(xy nm);
void SetNumberofModules(int *nm);
/**
* Set Flipped rows
@ -196,7 +196,7 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
char *completeBuffer{nullptr};
/** Number of Modules in X and Y dimension */
xy numMods{1, 1};
int numMods[2];
/** Quad Enable */
bool *quadEnable;

View File

@ -38,7 +38,7 @@ class GeneralData {
/** Header size of data saved into fifo buffer at a time*/
uint32_t fifoBufferHeaderSize{0};
uint32_t defaultFifoDepth{0};
uint32_t numUDPInterfaces{1};
uint32_t threadsPerReceiver{1};
uint32_t headerPacketSize{0};
/** Streaming (for ROI - mainly short Gotthard) */
uint32_t nPixelsXComplete{0};
@ -54,27 +54,10 @@ class GeneralData {
uint32_t vetoImageSize{0};
uint32_t vetoHsize{0};
uint32_t maxRowsPerReadout{0};
uint32_t dynamicRange{16};
bool tengigaEnable{false};
uint32_t nAnalogSamples{0};
uint32_t nDigitalSamples{0};
slsDetectorDefs::readoutMode readoutType{slsDetectorDefs::ANALOG_ONLY};
uint32_t adcEnableMaskOneGiga{BIT32_MASK};
uint32_t adcEnableMaskTenGiga{BIT32_MASK};
slsDetectorDefs::ROI roi{};
GeneralData(){};
virtual ~GeneralData(){};
// Returns the pixel depth in byte, 4 bits being 0.5 byte
float GetPixelDepth() { return float(dynamicRange) / 8; }
void ThrowGenericError(std::string msg) const {
throw sls::RuntimeError(
msg + std::string("SetROI is a generic function that should be "
"overloaded by a derived class"));
}
/**
* Get Header Infomation (frame number, packet number)
* @param index thread index for debugging purposes
@ -95,61 +78,94 @@ class GeneralData {
bunchId = -1;
}
/**
* Set ROI
* @param i ROI
*/
virtual void SetROI(slsDetectorDefs::ROI i) {
ThrowGenericError("SetROI");
LOG(logERROR) << "SetROI is a generic function that should be "
"overloaded by a derived class";
};
/**@returns adc configured */
/**
* Get Adc configured
* @param index thread index for debugging purposes
* @param i
* @returns adc configured
*/
virtual int GetAdcConfigured(int index, slsDetectorDefs::ROI i) const {
ThrowGenericError("GetAdcConfigured");
LOG(logERROR) << "GetAdcConfigured is a generic function that should "
"be overloaded by a derived class";
return 0;
};
virtual void SetDynamicRange(int dr) {
ThrowGenericError("SetDynamicRange");
/**
* Setting dynamic range changes member variables
* @param dr dynamic range
* @param tgEnable true if 10GbE is enabled, else false
*/
virtual void SetDynamicRange(int dr, bool tgEnable) {
LOG(logERROR) << "SetDynamicRange is a generic function that should be "
"overloaded by a derived class";
};
virtual void SetTenGigaEnable(bool tgEnable) {
ThrowGenericError("SetTenGigaEnable");
/**
* Setting ten giga enable changes member variables
* @param tgEnable true if 10GbE is enabled, else false
* @param dr dynamic range
*/
virtual void SetTenGigaEnable(bool tgEnable, int dr) {
LOG(logERROR) << "SetTenGigaEnable is a generic function that should "
"be overloaded by a derived class";
};
/**
* Set odd starting packet (gotthard)
* @param index thread index for debugging purposes
* @param packetData pointer to data
* @returns true or false for odd starting packet number
*/
virtual bool SetOddStartingPacket(int index, char *packetData) {
ThrowGenericError("SetOddStartingPacket");
LOG(logERROR) << "SetOddStartingPacket is a generic function that "
"should be overloaded by a derived class";
return false;
};
virtual void SetNumberofInterfaces(const int n) {
ThrowGenericError("SetNumberofInterfaces");
};
virtual void SetNumberofCounters(const int n) {
ThrowGenericError("SetNumberofCounters");
};
virtual int GetNumberOfAnalogDatabytes() {
ThrowGenericError("GetNumberOfAnalogDatabytes");
/**
* Set databytes (ctb, moench)
* @param a adc enable mask
* @param as analog number of samples
* @param ds digital number of samples
* @param t tengiga enable
* @param f readout flags
* @returns analog data bytes
*/
virtual int setImageSize(uint32_t a, uint32_t as, uint32_t ds, bool t,
slsDetectorDefs::readoutMode f) {
LOG(logERROR) << "setImageSize is a generic function that should be "
"overloaded by a derived class";
return 0;
};
virtual void SetNumberOfAnalogSamples(int n) {
ThrowGenericError("SetNumberOfAnalogSamples");
};
/**
* set number of interfaces (jungfrau)
* @param n number of interfaces
*/
virtual void SetNumberofInterfaces(const int n) {
LOG(logERROR) << "SetNumberofInterfaces is a generic function that "
"should be overloaded by a derived class";
}
virtual void SetNumberOfDigitalSamples(int n) {
ThrowGenericError("SetNumberOfDigitalSamples");
};
virtual void SetOneGigaAdcEnableMask(int n) {
ThrowGenericError("SetOneGigaAdcEnableMask");
};
virtual void SetTenGigaAdcEnableMask(int n) {
ThrowGenericError("SetTenGigaAdcEnableMask");
};
virtual void SetReadoutMode(slsDetectorDefs::readoutMode r) {
ThrowGenericError("SetReadoutMode");
};
/**
* set number of counters (mythen3)
* @param n number of counters
* @param dr dynamic range
* @param tgEnable ten giga enable
*/
virtual void SetNumberofCounters(const int n, const int dr, bool tgEnable) {
LOG(logERROR) << "SetNumberofCounters is a generic function that "
"should be overloaded by a derived class";
}
};
class GotthardData : public GeneralData {
@ -159,14 +175,23 @@ class GotthardData : public GeneralData {
const int nChipsPerAdc = 2;
public:
/** Constructor */
GotthardData() {
myDetectorType = slsDetectorDefs::GOTTHARD;
nPixelsX = 1280;
nPixelsY = 1;
headerSizeinPacket = 6;
headerSizeinPacket = 4;
dataSize = 1280;
packetSize = GOTTHARD_PACKET_SIZE;
packetsPerFrame = 2;
imageSize = dataSize * packetsPerFrame;
frameIndexMask = 0xFFFFFFFE;
frameIndexOffset = 1;
packetIndexMask = 1;
maxFramesPerFile = MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize =
FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
UpdateImageSize();
defaultFifoDepth = 50000;
};
/**
@ -194,7 +219,56 @@ class GotthardData : public GeneralData {
bunchId = -1;
}
/** @returns adc configured */
/**
* Set ROI
* @param i ROI
*/
void SetROI(slsDetectorDefs::ROI i) {
// all adcs
if (i.xmin == -1) {
nPixelsX = 1280;
dataSize = 1280;
packetSize = GOTTHARD_PACKET_SIZE;
packetsPerFrame = 2;
imageSize = dataSize * packetsPerFrame;
frameIndexMask = 0xFFFFFFFE;
frameIndexOffset = 1;
packetIndexMask = 1;
maxFramesPerFile = MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize = FIFO_HEADER_NUMBYTES +
sizeof(slsDetectorDefs::sls_receiver_header);
defaultFifoDepth = 50000;
nPixelsXComplete = 0;
nPixelsYComplete = 0;
imageSizeComplete = 0;
}
// single adc
else {
nPixelsX = 256;
dataSize = 512;
packetSize = 518;
packetsPerFrame = 1;
imageSize = dataSize * packetsPerFrame;
frameIndexMask = 0xFFFFFFFF;
frameIndexOffset = 0;
packetIndexMask = 0;
maxFramesPerFile = SHORT_MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize = FIFO_HEADER_NUMBYTES +
sizeof(slsDetectorDefs::sls_receiver_header);
defaultFifoDepth = 75000;
nPixelsXComplete = 1280;
nPixelsYComplete = 1;
imageSizeComplete = 1280 * 2;
}
};
/**
* Get Adc configured
* @param index thread index for debugging purposes
* @param i ROI
* @returns adc configured
*/
int GetAdcConfigured(int index, slsDetectorDefs::ROI i) const {
int adc = -1;
// single adc
@ -246,114 +320,99 @@ class GotthardData : public GeneralData {
}
return oddStartingPacket;
};
void SetROI(slsDetectorDefs::ROI i) {
roi = i;
UpdateImageSize();
};
private:
void UpdateImageSize() {
// all adcs
if (roi.xmin == -1) {
nPixelsX = 1280;
dataSize = 1280;
packetsPerFrame = 2;
frameIndexMask = 0xFFFFFFFE;
frameIndexOffset = 1;
packetIndexMask = 1;
maxFramesPerFile = MAX_FRAMES_PER_FILE;
nPixelsXComplete = 0;
nPixelsYComplete = 0;
imageSizeComplete = 0;
defaultFifoDepth = 50000;
} else {
nPixelsX = 256;
dataSize = 512;
packetsPerFrame = 1;
frameIndexMask = 0xFFFFFFFF;
frameIndexOffset = 0;
packetIndexMask = 0;
maxFramesPerFile = SHORT_MAX_FRAMES_PER_FILE;
nPixelsXComplete = 1280;
nPixelsYComplete = 1;
imageSizeComplete = 1280 * 2;
defaultFifoDepth = 75000;
}
imageSize = int(nPixelsX * nPixelsY * GetPixelDepth());
packetSize = headerSizeinPacket + dataSize;
packetsPerFrame = imageSize / dataSize;
};
};
class EigerData : public GeneralData {
public:
/** Constructor */
EigerData() {
myDetectorType = slsDetectorDefs::EIGER;
nPixelsX = (256 * 2);
nPixelsY = 256;
headerSizeinPacket = sizeof(slsDetectorDefs::sls_detector_header);
dataSize = 1024;
packetSize = headerSizeinPacket + dataSize;
packetsPerFrame = 256;
imageSize = dataSize * packetsPerFrame;
maxFramesPerFile = EIGER_MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize =
FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
numUDPInterfaces = 2;
defaultFifoDepth = 1000;
threadsPerReceiver = 2;
headerPacketSize = 40;
standardheader = true;
maxRowsPerReadout = 256;
UpdateImageSize();
};
void SetDynamicRange(int dr) {
dynamicRange = dr;
UpdateImageSize();
/**
* Setting dynamic range changes member variables
* @param dr dynamic range
* @param tgEnable true if 10GbE is enabled, else false
*/
void SetDynamicRange(int dr, bool tgEnable) {
packetsPerFrame = (tgEnable ? 4 : 16) * dr;
imageSize = dataSize * packetsPerFrame;
defaultFifoDepth = (dr == 32 ? 100 : 1000);
}
void SetTenGigaEnable(bool tgEnable) {
tengigaEnable = tgEnable;
UpdateImageSize();
};
private:
void UpdateImageSize() {
nPixelsX = (256 * 4) / numUDPInterfaces;
nPixelsY = 256;
dataSize = (tengigaEnable ? 4096 : 1024);
/**
* Setting ten giga enable changes member variables
* @param tgEnable true if 10GbE is enabled, else false
* @param dr dynamic range
*/
void SetTenGigaEnable(bool tgEnable, int dr) {
dataSize = (tgEnable ? 4096 : 1024);
packetSize = headerSizeinPacket + dataSize;
imageSize = int(nPixelsX * nPixelsY * GetPixelDepth());
packetsPerFrame = imageSize / dataSize;
defaultFifoDepth = (dynamicRange == 32 ? 100 : 1000);
packetsPerFrame = (tgEnable ? 4 : 16) * dr;
imageSize = dataSize * packetsPerFrame;
};
};
class JungfrauData : public GeneralData {
public:
/** Constructor */
JungfrauData() {
myDetectorType = slsDetectorDefs::JUNGFRAU;
nPixelsX = (256 * 4);
nPixelsY = 512;
headerSizeinPacket = sizeof(slsDetectorDefs::sls_detector_header);
dataSize = 8192;
packetSize = headerSizeinPacket + dataSize;
packetsPerFrame = 128;
imageSize = dataSize * packetsPerFrame;
maxFramesPerFile = JFRAU_MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize =
FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
defaultFifoDepth = 2500;
standardheader = true;
defaultUdpSocketBufferSize = (1000 * 1024 * 1024);
maxRowsPerReadout = 512;
UpdateImageSize();
};
/**
* set number of interfaces (jungfrau)
* @param n number of interfaces
*/
void SetNumberofInterfaces(const int n) {
numUDPInterfaces = n;
UpdateImageSize();
};
// 2 interfaces
if (n == 2) {
nPixelsY = 256;
packetsPerFrame = 64;
imageSize = dataSize * packetsPerFrame;
threadsPerReceiver = 2;
defaultUdpSocketBufferSize = (500 * 1024 * 1024);
private:
void UpdateImageSize() {
nPixelsX = (256 * 4);
nPixelsY = (256 * 2) / numUDPInterfaces;
imageSize = int(nPixelsX * nPixelsY * GetPixelDepth());
packetsPerFrame = imageSize / dataSize;
defaultUdpSocketBufferSize = (1000 * 1024 * 1024) / numUDPInterfaces;
}
// 1 interface
else {
nPixelsY = 512;
packetsPerFrame = 128;
imageSize = dataSize * packetsPerFrame;
threadsPerReceiver = 1;
defaultUdpSocketBufferSize = (1000 * 1024 * 1024);
}
};
};
@ -363,46 +422,39 @@ class Mythen3Data : public GeneralData {
const int NCHAN = 1280;
public:
/** Constructor */
Mythen3Data() {
myDetectorType = slsDetectorDefs::MYTHEN3;
ncounters = 3;
nPixelsX = (NCHAN * ncounters); // max 1280 channels x 3 counters
nPixelsY = 1;
headerSizeinPacket = sizeof(slsDetectorDefs::sls_detector_header);
dataSize = 7680;
packetSize = headerSizeinPacket + dataSize;
packetsPerFrame = 2;
imageSize = dataSize * packetsPerFrame;
maxFramesPerFile = MYTHEN3_MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize =
FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
defaultFifoDepth = 50000;
standardheader = true;
defaultUdpSocketBufferSize = (1000 * 1024 * 1024);
dynamicRange = 32;
tengigaEnable = true;
UpdateImageSize();
};
void SetDynamicRange(int dr) {
dynamicRange = dr;
UpdateImageSize();
};
void SetTenGigaEnable(bool tg) {
tengigaEnable = tg;
UpdateImageSize();
};
virtual void SetNumberofCounters(const int n) {
/**
* set number of counters (mythen3)
* @param n number of counters
* @param dr dynamic range
* @param tgEnable ten giga enable
*/
virtual void SetNumberofCounters(const int n, const int dr, bool tgEnable) {
ncounters = n;
UpdateImageSize();
};
private:
void UpdateImageSize() {
nPixelsX = (NCHAN * ncounters); // max 1280 channels x 3 counters
nPixelsX = NCHAN * ncounters;
LOG(logINFO) << "nPixelsX: " << nPixelsX;
imageSize = nPixelsX * nPixelsY * GetPixelDepth();
imageSize = nPixelsX * nPixelsY * ((double)dr / 8.00);
// 10g
if (tengigaEnable) {
if (dynamicRange == 32 && ncounters > 1) {
if (tgEnable) {
if (dr == 32 && n > 1) {
packetsPerFrame = 2;
} else {
packetsPerFrame = 1;
@ -411,7 +463,7 @@ class Mythen3Data : public GeneralData {
}
// 1g
else {
if (ncounters == 3) {
if (n == 3) {
dataSize = 768;
} else {
dataSize = 1280;
@ -427,25 +479,41 @@ class Mythen3Data : public GeneralData {
class Gotthard2Data : public GeneralData {
public:
/** Constructor */
Gotthard2Data() {
myDetectorType = slsDetectorDefs::GOTTHARD2;
nPixelsX = 128 * 10;
nPixelsY = 1;
headerSizeinPacket = sizeof(slsDetectorDefs::sls_detector_header);
dataSize = 2560; // 1280 channels * 2 bytes
packetSize = headerSizeinPacket + dataSize;
packetsPerFrame = 1;
imageSize = dataSize * packetsPerFrame;
maxFramesPerFile = GOTTHARD2_MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize =
FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
defaultFifoDepth = 50000;
standardheader = true;
defaultUdpSocketBufferSize = (1000 * 1024 * 1024);
vetoDataSize = 160;
vetoImageSize = vetoDataSize * packetsPerFrame;
vetoHsize = 16;
UpdateImageSize();
vetoPacketSize = vetoHsize + vetoDataSize;
};
/**
* set number of interfaces
* @param n number of interfaces
*/
void SetNumberofInterfaces(const int n) {
numUDPInterfaces = n;
UpdateImageSize();
// 2 interfaces (+veto)
if (n == 2) {
threadsPerReceiver = 2;
}
// 1 interface (data only)
else {
threadsPerReceiver = 1;
}
};
/**
@ -464,158 +532,134 @@ class Gotthard2Data : public GeneralData {
bunchId = *reinterpret_cast<uint64_t *>(packetData + 8);
packetNumber = 0;
};
private:
void UpdateImageSize() {
packetSize = headerSizeinPacket + dataSize;
imageSize = int(nPixelsX * nPixelsY * GetPixelDepth());
packetsPerFrame = imageSize / dataSize;
vetoPacketSize = vetoHsize + vetoDataSize;
vetoImageSize = vetoDataSize * packetsPerFrame;
defaultUdpSocketBufferSize = (1000 * 1024 * 1024) / numUDPInterfaces;
};
};
class ChipTestBoardData : public GeneralData {
private:
/** Number of digital channels */
const int NCHAN_DIGITAL = 64;
/** Number of bytes per analog channel */
const int NUM_BYTES_PER_ANALOG_CHANNEL = 2;
int nAnalogBytes = 0;
public:
/** Constructor */
ChipTestBoardData() {
myDetectorType = slsDetectorDefs::CHIPTESTBOARD;
nPixelsY = 1; // number of samples
nPixelsX = 36; // total number of channels
nPixelsY = 1; // number of samples
headerSizeinPacket = sizeof(slsDetectorDefs::sls_detector_header);
dataSize = UDP_PACKET_DATA_BYTES;
packetSize = headerSizeinPacket + dataSize;
// packetsPerFrame = 1;
imageSize = nPixelsX * nPixelsY * 2;
frameIndexMask = 0xFFFFFF; // 10g
frameIndexOffset = 8; // 10g
packetIndexMask = 0xFF; // 10g
packetsPerFrame =
ceil((double)imageSize / (double)UDP_PACKET_DATA_BYTES);
maxFramesPerFile = CTB_MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize =
FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
defaultFifoDepth = 2500;
standardheader = true;
UpdateImageSize();
};
public:
int GetNumberOfAnalogDatabytes() { return nAnalogBytes; };
void SetNumberOfAnalogSamples(int n) {
nAnalogSamples = n;
UpdateImageSize();
};
void SetNumberOfDigitalSamples(int n) {
nDigitalSamples = n;
UpdateImageSize();
};
void SetOneGigaAdcEnableMask(int n) {
adcEnableMaskOneGiga = n;
UpdateImageSize();
};
void SetTenGigaAdcEnableMask(int n) {
adcEnableMaskTenGiga = n;
UpdateImageSize();
};
void SetReadoutMode(slsDetectorDefs::readoutMode r) {
readoutType = r;
UpdateImageSize();
};
void SetTenGigaEnable(bool tg) {
tengigaEnable = tg;
UpdateImageSize();
};
private:
void UpdateImageSize() {
nAnalogBytes = 0;
int nDigitalBytes = 0;
int nAnalogChans = 0, nDigitalChans = 0;
/**
* Set databytes
* @param a adc enable mask
* @param as analog number of samples
* @param ds digital number of samples
* @param t tengiga enable
* @param f readout flags
* @returns analog data bytes
*/
int setImageSize(uint32_t a, uint32_t as, uint32_t ds, bool t,
slsDetectorDefs::readoutMode f) {
int nachans = 0, ndchans = 0;
int adatabytes = 0, ddatabytes = 0;
// analog channels (normal, analog/digital readout)
if (readoutType == slsDetectorDefs::ANALOG_ONLY ||
readoutType == slsDetectorDefs::ANALOG_AND_DIGITAL) {
uint32_t adcEnableMask =
(tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga);
nAnalogChans = __builtin_popcount(adcEnableMask);
if (f == slsDetectorDefs::ANALOG_ONLY ||
f == slsDetectorDefs::ANALOG_AND_DIGITAL) {
nachans = __builtin_popcount(a);
nAnalogBytes =
nAnalogChans * NUM_BYTES_PER_ANALOG_CHANNEL * nAnalogSamples;
LOG(logDEBUG1) << " Number of Analog Channels:" << nAnalogChans
<< " Databytes: " << nAnalogBytes;
adatabytes = nachans * NUM_BYTES_PER_ANALOG_CHANNEL * as;
LOG(logDEBUG1) << " Number of Analog Channels:" << nachans
<< " Databytes: " << adatabytes;
}
// digital channels
if (readoutType == slsDetectorDefs::DIGITAL_ONLY ||
readoutType == slsDetectorDefs::ANALOG_AND_DIGITAL) {
nDigitalChans = NCHAN_DIGITAL;
nDigitalBytes = (sizeof(uint64_t) * nDigitalSamples);
LOG(logDEBUG1) << "Number of Digital Channels:" << nDigitalChans
<< " Databytes: " << nDigitalBytes;
if (f == slsDetectorDefs::DIGITAL_ONLY ||
f == slsDetectorDefs::ANALOG_AND_DIGITAL) {
ndchans = NCHAN_DIGITAL;
ddatabytes = (sizeof(uint64_t) * ds);
LOG(logDEBUG1) << "Number of Digital Channels:" << ndchans
<< " Databytes: " << ddatabytes;
}
LOG(logDEBUG1) << "Total Number of Channels:" << nachans + ndchans
<< " Databytes: " << adatabytes + ddatabytes;
nPixelsX = nachans + ndchans;
nPixelsY = 1;
// 10G
if (t) {
dataSize = 8144;
}
// 1g udp (via fifo readout)
else {
dataSize = UDP_PACKET_DATA_BYTES;
}
nPixelsX = nAnalogChans + nDigitalChans;
dataSize = tengigaEnable ? 8144 : UDP_PACKET_DATA_BYTES;
packetSize = headerSizeinPacket + dataSize;
imageSize = nAnalogBytes + nDigitalBytes;
imageSize = adatabytes + ddatabytes;
packetsPerFrame = ceil((double)imageSize / (double)dataSize);
LOG(logDEBUG1) << "Total Number of Channels:" << nPixelsX
<< " Databytes: " << imageSize;
};
return adatabytes;
}
};
class MoenchData : public GeneralData {
private:
/** Number of bytes per analog channel */
const int NUM_BYTES_PER_ANALOG_CHANNEL = 2;
public:
/** Constructor */
MoenchData() {
myDetectorType = slsDetectorDefs::MOENCH;
nPixelsX = 32; // total number of channels
nPixelsY = 1; // number of samples
headerSizeinPacket = sizeof(slsDetectorDefs::sls_detector_header);
dataSize = UDP_PACKET_DATA_BYTES;
packetSize = headerSizeinPacket + dataSize;
// packetsPerFrame = 1;
imageSize = nPixelsX * nPixelsY * 2;
packetsPerFrame =
ceil((double)imageSize / (double)UDP_PACKET_DATA_BYTES);
frameIndexMask = 0xFFFFFF;
maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE;
fifoBufferHeaderSize =
FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header);
defaultFifoDepth = 2500;
standardheader = true;
UpdateImageSize();
};
void SetNumberOfAnalogSamples(int n) {
nAnalogSamples = n;
UpdateImageSize();
};
void SetOneGigaAdcEnableMask(int n) {
adcEnableMaskOneGiga = n;
UpdateImageSize();
};
void SetTenGigaAdcEnableMask(int n) {
adcEnableMaskTenGiga = n;
UpdateImageSize();
};
void SetTenGigaEnable(bool tg) {
tengigaEnable = tg;
UpdateImageSize();
};
private:
void UpdateImageSize() {
uint32_t adcEnableMask =
(tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga);
/**
* Set databytes
* @param a adc enable mask
* @param as analog number of samples
* @param ds digital number of samples
* @param t tengiga enable
* @param f readout flags
* @returns analog data bytes
*/
int setImageSize(uint32_t a, uint32_t as, uint32_t ds, bool t,
slsDetectorDefs::readoutMode f) {
// count number of channels in x, each adc has 25 channels each
int nchanTop = __builtin_popcount(adcEnableMask & 0xF0F0F0F0) * 25;
int nchanBot = __builtin_popcount(adcEnableMask & 0x0F0F0F0F) * 25;
int nchanTop = __builtin_popcount(a & 0xF0F0F0F0) * 25;
int nchanBot = __builtin_popcount(a & 0x0F0F0F0F) * 25;
nPixelsX = nchanTop > 0 ? nchanTop : nchanBot;
// if both top and bottom adcs enabled, rows = 2
@ -623,15 +667,25 @@ class MoenchData : public GeneralData {
if (nchanTop > 0 && nchanBot > 0) {
nrows = 2;
}
nPixelsY = nAnalogSamples / 25 * nrows;
nPixelsY = as / 25 * nrows;
LOG(logINFO) << "Number of Pixels: [" << nPixelsX << ", " << nPixelsY
<< "]";
dataSize = tengigaEnable ? 8144 : UDP_PACKET_DATA_BYTES;
packetSize = headerSizeinPacket + dataSize;
// 10G
if (t) {
dataSize = 8144;
}
// 1g udp (via fifo readout)
else {
dataSize = UDP_PACKET_DATA_BYTES;
}
imageSize = nPixelsX * nPixelsY * NUM_BYTES_PER_ANALOG_CHANNEL;
packetSize = headerSizeinPacket + dataSize;
packetsPerFrame = ceil((double)imageSize / (double)dataSize);
LOG(logDEBUG) << "Databytes: " << imageSize;
};
return imageSize;
}
};

Some files were not shown because too many files have changed in this diff Show More