Compare commits

..

66 Commits

Author SHA1 Message Date
13ec32c79a With corrections 2022-03-28 14:30:45 +02:00
039e1fd829 merge fix with developer 2022-03-28 10:26:28 +02:00
fc41d4313f Merge pull request #414 from slsdetectorgroup/specialfile
Specialfile
2022-03-28 10:22:46 +02:00
4bd4364a3a minor. binaries in 2022-03-28 10:21:19 +02:00
4b697dd9db binaries in 2022-03-28 09:47:43 +02:00
6470277e43 use s_ischr.. not s_isblk 2022-03-28 09:47:32 +02:00
2453390cc3 merge fix 2022-03-28 09:11:32 +02:00
fa694dbc4c Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer 2022-03-25 18:21:12 +01:00
ea1222ac5b Solved problem in photon finder 2022-03-25 18:20:32 +01:00
4cce1dbd7f added missing files 2022-03-25 15:13:08 +01:00
1710177af4 Merge branch 'dacnames' of github.com:slsdetectorgroup/slsDetectorPackage into dacnames 2022-03-25 15:10:47 +01:00
5c79a1a1e8 Moved to class implementation 2022-03-25 15:08:50 +01:00
83d76267f9 Merge pull request #411 from slsdetectorgroup/numudp
num udp interfaces in shm
2022-03-25 12:13:47 +01:00
9ff43efdc5 Merge branch 'developer' into numudp 2022-03-25 10:50:51 +01:00
21c21a423d update release 2022-03-25 08:18:29 +01:00
e479b7d4be updated releasetxt 2022-03-25 08:17:12 +01:00
8f0398681e updated releasetxt 2022-03-25 08:15:57 +01:00
b112cf81c4 fixed daclist setter 2022-03-24 17:46:20 +01:00
589124845a working implementation 2022-03-24 17:40:44 +01:00
1e564a1b33 binaries in. fixed 2022-03-24 12:33:19 +01:00
5fe10c19a1 binarie sin 2022-03-24 09:26:29 +01:00
de5c298d99 Merge pull request #373 from slsdetectorgroup/ghdf5
Gotthard25um: virtual hdf5 image
2022-03-23 12:08:40 +01:00
2a1f6dc544 Merge pull request #371 from slsdetectorgroup/g225gui
Gotthard25um: gui image
2022-03-23 12:06:27 +01:00
fc21a6763d fix and minor removing comments 2022-03-23 12:03:51 +01:00
fd8e1b2ef7 merge fix 2022-03-23 11:42:16 +01:00
0803f1bc1f help in cmdline, fixed get for daclist in python 2022-03-23 11:27:52 +01:00
9995b74217 added setdaclist in cmd line 2022-03-23 10:53:29 +01:00
2823451c9d Hacky implementation 2022-03-22 16:45:02 +01:00
0f4bcf3a9d test if special file when updating kernel(solution: reboot only), --force-delete-normal-file used to force delete bfin fpga drive if normal file and create proper device tree 2022-03-22 16:44:12 +01:00
74d55db3f0 Merge pull request #398 from slsdetectorgroup/rxacqIndices
Receiver frame indices and progress
2022-03-22 11:23:07 +01:00
2b35101b17 moved shm numUdpInterfaces initialization up front, moved updating this value in DetectorImpl::setHostname to DetectorImpl::addModule for more readability, renamed getNumberofUdpInterfaces to an updateNumberofUdpInterfaces as the shm was being updated and is used only in setHostname, everywhere else getNumberofUdpInterfaces is replaced by getNumberofUdpInterfacesFromShm 2022-03-22 10:23:22 +01:00
f538b8b10b binaries in 2022-03-21 15:52:19 +01:00
fb012aa9e9 Merge branch 'specialfile' of github.com:slsdetectorgroup/slsDetectorPackage into specialfile 2022-03-21 15:51:39 +01:00
82bad7fec6 special file check fix 2022-03-21 15:46:34 +01:00
717922f380 Merge branch 'developer' into specialfile 2022-03-21 14:27:28 +01:00
dffac3014e Merge branch 'developer' into g225gui 2022-03-18 12:12:44 +01:00
586149f3e7 Merge branch 'developer' into ghdf5 2022-03-18 12:12:25 +01:00
088dd2c9f8 merge fix 2022-03-18 12:12:08 +01:00
89395bd990 merge fix 2022-03-18 12:11:40 +01:00
3144f40068 bianries in after merge 2022-03-18 12:10:59 +01:00
adbd2b853d binaries in 2022-03-17 17:00:28 +01:00
0e6d92118f compile fix 2022-03-17 16:57:08 +01:00
3796182eb1 check if drive is a normal file or special block file 2022-03-17 13:43:55 +01:00
570651a9f8 minor 2022-03-17 13:09:54 +01:00
afbc414afe works for both g25 and normal 2022-03-17 13:08:40 +01:00
ca0aa7144c hdf5 for g25um 2022-03-17 12:53:32 +01:00
3e5b8840b4 wip 2022-03-17 12:21:29 +01:00
f1da831e10 Merge branch 'developer' into ghdf5 2022-03-17 12:18:20 +01:00
06281ccae9 firmware reverses slave channels 2022-03-17 12:11:51 +01:00
509946d964 Merge branch 'developer' into g225gui 2022-03-17 11:52:30 +01:00
95f9da9d70 Merge branch 'developer' into rxacqIndices 2022-03-17 11:30:01 +01:00
d80006a024 Merge branch 'developer' into rxacqIndices 2022-03-17 09:03:32 +01:00
c1895c4bc8 Merge branch 'developer' into rxacqIndices 2022-03-17 08:48:15 +01:00
4db34effda fixed tests 2022-02-24 11:57:00 +01:00
5a5d4eadf1 minor 2022-02-24 11:27:29 +01:00
b9016fad12 reverting to normal command parsing for missing packets 2022-02-24 11:26:17 +01:00
a1ee681135 - framescaught and frameindex now returns a vector for each port
- progress looks at activated or enabled ports, so progress does not stagnate
- (eiger) disable datastreaming also for virtual servers only for 10g
- missing packets also takes care of disabled ports
2022-02-24 11:15:03 +01:00
8eb5c19187 Merge branch 'developer' into ghdf5 2022-02-14 08:26:36 +01:00
a1888bf7c9 Merge branch 'developer' into g225gui 2022-02-11 16:24:36 +01:00
f2cca765be wip 2022-02-10 16:59:25 +01:00
5b4cc53f8c Merge branch 'developer' into ghdf5 2022-02-07 15:11:01 +01:00
251f07a9ae Merge branch 'developer' into g225gui 2022-02-07 15:10:42 +01:00
f228fde6f7 including stride and block for selecting hyperslab 2022-02-07 14:01:19 +01:00
20f3fb19af g25 option passed to hdf5 2022-02-04 15:09:18 +01:00
cfe627d348 gotthardu25 image reconstruction in gui 2022-02-04 14:47:52 +01:00
753387c34c gotthard type can only have max 2 modules 2022-02-04 13:29:42 +01:00
51 changed files with 1461 additions and 1403 deletions

View File

@ -47,10 +47,16 @@ This document describes the differences between v7.0.0 and v6.x.x
- 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)
- framescaught and frameindex now returns a vector for each port
- progress looks at activated or enabled ports, so progress does not stagnate
- (eiger) disable datastreaming also for virtual servers only for 10g
- missing packets also takes care of disabled ports
- 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)
- ctb: can set names for all the dacs
- fpga/kernel programming, checks if drive is a special file and not a normal file
- gotthard 25 um image reconstructed in gui and virtual hdf5 (firmware updated for slave to reverse channels)
2. Resolved Issues
==================

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

@ -1,43 +1,45 @@
# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package
from .detector import Detector
from .detector import Detector, freeze
from .utils import element_if_equal
from .dacs import DetectorDacs
from .dacs import DetectorDacs, NamedDacs
import _slsdet
dacIndex = _slsdet.slsDetectorDefs.dacIndex
from .detector_property import DetectorProperty
class CtbDacs(DetectorDacs):
"""
Ctb dacs
"""
_dacs = [('dac0', dacIndex(0), 0, 4000, 1400),
('dac1', dacIndex(1), 0, 4000, 1200),
('dac2', dacIndex(2), 0, 4000, 900),
('dac3', dacIndex(3), 0, 4000, 1050),
('dac4', dacIndex(4), 0, 4000, 1400),
('dac5', dacIndex(5), 0, 4000, 655),
('dac6', dacIndex(6), 0, 4000, 2000),
('dac7', dacIndex(7), 0, 4000, 1400),
('dac8', dacIndex(8), 0, 4000, 850),
('dac9', dacIndex(9), 0, 4000, 2000),
('dac10', dacIndex(10), 0, 4000, 2294),
('dac11', dacIndex(11), 0, 4000, 983),
('dac12', dacIndex(12), 0, 4000, 1475),
('dac13', dacIndex(13), 0, 4000, 1200),
('dac14', dacIndex(14), 0, 4000, 1600),
('dac15', dacIndex(15), 0, 4000, 1455),
('dac16', dacIndex(16), 0, 4000, 0),
('dac17', dacIndex(17), 0, 4000, 1000),
]
_dacnames = [_d[0] for _d in _dacs]
# class CtbDacs(DetectorDacs):
# """
# Ctb dacs
# """
# _dacs = [('dac0', dacIndex(0), 0, 4000, 1400),
# ('dac1', dacIndex(1), 0, 4000, 1200),
# ('dac2', dacIndex(2), 0, 4000, 900),
# ('dac3', dacIndex(3), 0, 4000, 1050),
# ('dac4', dacIndex(4), 0, 4000, 1400),
# ('dac5', dacIndex(5), 0, 4000, 655),
# ('dac6', dacIndex(6), 0, 4000, 2000),
# ('dac7', dacIndex(7), 0, 4000, 1400),
# ('dac8', dacIndex(8), 0, 4000, 850),
# ('dac9', dacIndex(9), 0, 4000, 2000),
# ('dac10', dacIndex(10), 0, 4000, 2294),
# ('dac11', dacIndex(11), 0, 4000, 983),
# ('dac12', dacIndex(12), 0, 4000, 1475),
# ('dac13', dacIndex(13), 0, 4000, 1200),
# ('dac14', dacIndex(14), 0, 4000, 1600),
# ('dac15', dacIndex(15), 0, 4000, 1455),
# ('dac16', dacIndex(16), 0, 4000, 0),
# ('dac17', dacIndex(17), 0, 4000, 1000),
# ]
# _dacnames = [_d[0] for _d in _dacs]
from .utils import element
@freeze
class Ctb(Detector):
def __init__(self, id = 0):
super().__init__(id)
self._frozen = False
self._dacs = CtbDacs(self)
# self._dacs = CtbDacs(self)
self._dacs = NamedDacs(self)
@property
def dacs(self):

View File

@ -36,6 +36,79 @@ class Dac(DetectorProperty):
dacstr = ''.join([f'{item:5d}' for item in self.get()])
return f'{self.__name__:15s}:{dacstr}'
class NamedDacs:
"""
New implementation of the detector dacs. Used at the momen for
Ctb but should replace the old one for all detectors
"""
_frozen = False
_direct_access = ['_detector', '_current', '_dacnames']
def __init__(self, detector):
self._detector = detector
self._current = 0
self._dacnames = [n.replace(" ", "") for n in detector.getDacNames()]
# # Populate the dacs
for i,name in enumerate(self._dacnames):
#name, enum, low, high, default, detector
setattr(self, name, Dac(name, dacIndex(i), 0, 4000, 1000, detector))
self._frozen = True
# def __getattr__(self, name):
# return self.__getattribute__('_' + name)
def __setattr__(self, name, value):
if not self._frozen:
#durining init we need to be able to set up the class
super().__setattr__(name, value)
else:
#Later we restrict us to manipulate dacs and a few fields
if name in self._direct_access:
super().__setattr__(name, value)
elif name in self._dacnames:
return self.__getattribute__(name).__setitem__(slice(None, None, None), value)
else:
raise AttributeError(f'Dac not found: {name}')
def __next__(self):
if self._current >= len(self._dacnames):
self._current = 0
raise StopIteration
else:
self._current += 1
return self.__getattribute__(self._dacnames[self._current-1])
# return self.__getattr__(self._dacnames[self._current-1])
def __iter__(self):
return self
def __repr__(self):
r_str = ['========== DACS =========']
r_str += [repr(dac) for dac in self]
return '\n'.join(r_str)
def get_asarray(self):
"""
Read the dacs into a numpy array with dimensions [ndacs, nmodules]
"""
dac_array = np.zeros((len(self._dacnames), len(self._detector)))
for i, _d in enumerate(self):
dac_array[i,:] = _d[:]
return dac_array
def to_array(self):
return self.get_asarray()
def set_from_array(self, dac_array):
"""
Set the dacs from an numpy array with dac values. [ndacs, nmodules]
"""
dac_array = dac_array.astype(np.int)
for i, _d in enumerate(self):
_d[:] = dac_array[i]
def from_array(self, dac_array):
self.set_from_array(dac_array)
class DetectorDacs:
_dacs = []
@ -50,7 +123,7 @@ class DetectorDacs:
# Index to support iteration
self._current = 0
# Populate the dacs
# Name the attributes?
for _d in self._dacs:
setattr(self, '_'+_d[0], Dac(*_d, detector))
@ -59,6 +132,9 @@ class DetectorDacs:
def __getattr__(self, name):
return self.__getattribute__('_' + name)
@property
def dacnames(self):
return [_d[0] for _d in _dacs]
def __setattr__(self, name, value):
if name in self._dacnames:

View File

@ -599,7 +599,7 @@ class Detector(CppDetectorApi):
@property
@element
def rx_framescaught(self):
"""Number of frames caught by receiver."""
"""Number of frames caught by each port in receiver."""
return self.getFramesCaught()
@property
@ -1571,8 +1571,16 @@ class Detector(CppDetectorApi):
@property
def daclist(self):
"""Gets the list of enums for every dac for this detector."""
return self.getDacList()
"""
List of enums for every dac for this detector.
:setter: Only implemented for Chiptestboard
"""
return self.getDacNames()
@daclist.setter
def daclist(self, value):
self.setDacNames(value)
@property
def dacvalues(self):
@ -1918,7 +1926,7 @@ class Detector(CppDetectorApi):
@property
@element
def rx_frameindex(self):
"""Current frame index received in receiver during acquisition."""
"""Current frame index received for each port in receiver during acquisition."""
return self.getRxCurrentFrameIndex()
@property

View File

@ -493,13 +493,17 @@ void init_det(py::module &m) {
Detector::getReceiverStatus,
py::arg() = Positions{})
.def("getFramesCaught",
(Result<int64_t>(Detector::*)(sls::Positions) const) &
(Result<std::vector<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("getRxCurrentFrameIndex",
(Result<std::vector<int64_t>>(Detector::*)(sls::Positions) const) &
Detector::getRxCurrentFrameIndex,
py::arg() = Positions{})
.def("getNextFrameNumber",
(Result<uint64_t>(Detector::*)(sls::Positions) const) &
Detector::getNextFrameNumber,
@ -1423,6 +1427,19 @@ void init_det(py::module &m) {
(void (Detector::*)(bool, sls::Positions)) &
Detector::setLEDEnable,
py::arg(), py::arg() = Positions{})
.def("setDacNames",
(void (Detector::*)(const std::vector<std::string>)) &
Detector::setDacNames,
py::arg())
.def("getDacNames", (std::vector<std::string>(Detector::*)() const) &
Detector::getDacNames)
.def("getDacIndex",
(defs::dacIndex(Detector::*)(const std::string &)) &
Detector::getDacIndex,
py::arg())
.def("getDacName",
(std::string(Detector::*)(defs::dacIndex)) & Detector::getDacName,
py::arg())
.def("setPattern",
(void (Detector::*)(const std::string &, sls::Positions)) &
Detector::setPattern,
@ -1527,9 +1544,10 @@ void init_det(py::module &m) {
Detector::setAdditionalJsonParameter,
py::arg(), py::arg(), py::arg() = Positions{})
.def("programFPGA",
(void (Detector::*)(const std::string &, sls::Positions)) &
(void (Detector::*)(const std::string &, const bool,
sls::Positions)) &
Detector::programFPGA,
py::arg(), py::arg() = Positions{})
py::arg(), py::arg(), py::arg() = Positions{})
.def("resetFPGA",
(void (Detector::*)(sls::Positions)) & Detector::resetFPGA,
py::arg() = Positions{})
@ -1656,9 +1674,5 @@ void init_det(py::module &m) {
Detector::getMeasurementTime,
py::arg() = Positions{})
.def("getUserDetails",
(std::string(Detector::*)() const) & Detector::getUserDetails)
.def("getRxCurrentFrameIndex",
(Result<uint64_t>(Detector::*)(sls::Positions) const) &
Detector::getRxCurrentFrameIndex,
py::arg() = Positions{});
(std::string(Detector::*)() const) & Detector::getUserDetails);
}

View File

@ -429,10 +429,15 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
for (ic = -(clusterSize / 2); ic < (clusterSize / 2) + 1;
ic++) {
if ((iy + ir) >= iy && (iy + ir) < ny &&
(ix + ic) >= ix && (ix + ic) < nx) {
if ((iy + ir) >= 0 && (iy + ir) < ny &&
(ix + ic) >= 0 && (ix + ic) < nx) {
if ((iy + ir) >= iy && (ix + ic) >= ix ) {
val[(iy + ir) * nx + ix + ic] =
subtractPedestal(data, ix + ic, iy + ir, cm);
}
v = &(val[(iy + ir) * nx + ix + ic]);
tot += *v;
if (ir <= 0 && ic <= 0)
@ -443,9 +448,9 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
tl += *v;
if (ir >= 0 && ic >= 0)
tr += *v;
if (*v > max) {
if (*v > max) //{
max = *v;
}
//}
}
}
}
@ -513,12 +518,19 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
for (ic = -(clusterSize / 2);
ic < (clusterSize / 2) + 1; ic++) {
if ((iy + ir) >= 0 && (iy + ir) < ny &&
(ix + ic) >= 0 && (ix + ic) < nx)
(ix + ic) >= 0 && (ix + ic) < nx) {
(clusters + nph)
->set_data(val[(iy + ir) * nx + ix + ic],
ic, ir);
if (val[(iy + ir) * nx + ix + ic]>max)
good=0;
}
}
}
if (good==0) {
(clusters + nph)->print();
cout << max << " " << val[iy * nx + ix] << endl;
}
good = 1;
if (eMin > 0 && tot < eMin)
good = 0;

View File

@ -216,14 +216,18 @@ class single_photon_hit {
// int ix, iy;
printf("***************\n");
printf("** %d %d **\n",x,y);
for (int iy = 0; iy < dy; iy++) {
for (int ix = 0; ix < dx; ix++) {
printf("%d \t", data[ix + iy * dx]);
}
printf("\n");
}
printf("***************\n");
}
/**
assign the value to the element of the cluster matrix, with relative
coordinates where the center of the cluster is (0,0) \param v value to be

View File

@ -91,8 +91,10 @@ class qDrawPlot : public QWidget, private Ui::PlotObject {
void Update2dPlot();
void Update1dXYRange();
void Update2dXYRange();
void rearrangeGotthard25data(double *data);
static const int NUM_PEDESTAL_FRAMES = 20;
static const int NUM_GOTTHARD25_CHANS = 1280;
sls::Detector *det;
slsDetectorDefs::detectorType detType;
@ -164,4 +166,5 @@ class qDrawPlot : public QWidget, private Ui::PlotObject {
uint32_t pixelMask{0};
uint32_t gainMask{0};
int gainOffset{0};
bool gotthard25;
};

View File

@ -80,6 +80,10 @@ void qDrawPlot::SetupWidgetWindow() {
fileSaveName = "Image";
}
gotthard25 = ((detType == slsDetectorDefs::GOTTHARD2 ||
detType == slsDetectorDefs::GOTTHARD) &&
det->size() == 2);
SetupPlots();
SetDataCallBack(true);
det->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack),
@ -807,6 +811,11 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex,
isGainDataExtracted = false;
}
// gotthard25um rearranging
if (gotthard25) {
rearrangeGotthard25data(rawData);
}
// title and frame index titles
plotTitle =
plotTitlePrefix + QString(data->fileName.c_str()).section('/', -1);
@ -1145,6 +1154,18 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size,
}
}
void qDrawPlot::rearrangeGotthard25data(double *data) {
const int nChans = NUM_GOTTHARD25_CHANS;
double temp[nChans * 2] = {0.0};
for (int i = 0; i != nChans; ++i) {
// master module
temp[i * 2] = data[i];
// slave module
temp[i * 2 + 1] = data[nChans + i];
}
memcpy(data, temp, nChans * 2 * sizeof(double));
}
void qDrawPlot::UpdatePlot() {
std::lock_guard<std::mutex> lock(mPlots);
LOG(logDEBUG) << "Update Plot";

View File

@ -2448,15 +2448,17 @@ void *start_timer(void *arg) {
}
int skipData = 0;
int tgEnable = send_to_ten_gig;
if (!eiger_virtual_activate ||
(!eiger_virtual_left_datastream && !eiger_virtual_right_datastream)) {
(tgEnable &&
(!eiger_virtual_left_datastream && !eiger_virtual_right_datastream))) {
skipData = 1;
LOG(logWARNING, ("Not sending Left and Right datastream\n"));
}
if (!eiger_virtual_left_datastream) {
if (tgEnable && !eiger_virtual_left_datastream) {
LOG(logWARNING, ("Not sending Left datastream\n"));
}
if (!eiger_virtual_right_datastream) {
if (tgEnable && !eiger_virtual_right_datastream) {
LOG(logWARNING, ("Not sending Right datastream\n"));
}
@ -2466,7 +2468,6 @@ void *start_timer(void *arg) {
int dr = eiger_dynamicrange;
double bytesPerPixel = (double)dr / 8.00;
int tgEnable = send_to_ten_gig;
int datasize = (tgEnable ? 4096 : 1024);
int packetsize = datasize + sizeof(sls_detector_header);
int maxPacketsPerFrame = (tgEnable ? 4 : 16) * dr;
@ -2672,14 +2673,16 @@ void *start_timer(void *arg) {
}
}
}
if (eiger_virtual_left_datastream && i >= startval &&
i <= endval) {
if ((!tgEnable ||
(tgEnable && eiger_virtual_left_datastream)) &&
i >= startval && i <= endval) {
usleep(eiger_virtual_transmission_delay_left);
sendUDPPacket(iRxEntry, 0, packetData, packetsize);
LOG(logDEBUG1, ("Sent left packet: %d\n", i));
}
if (eiger_virtual_right_datastream && i >= startval &&
i <= endval) {
if ((!tgEnable ||
(tgEnable && eiger_virtual_right_datastream)) &&
i >= startval && i <= endval) {
usleep(eiger_virtual_transmission_delay_right);
sendUDPPacket(iRxEntry, 1, packetData2, packetsize);
LOG(logDEBUG1, ("Sent right packet: %d\n", i));

View File

@ -26,10 +26,12 @@ int preparetoCopyProgram(char *mess, char *functionType, FILE **fd,
uint64_t fsize);
int eraseAndWriteToFlash(char *mess, enum PROGRAM_INDEX index,
char *functionType, char *clientChecksum,
ssize_t fsize);
ssize_t fsize, int forceDeleteNormalFile);
int getDrive(char *mess, enum PROGRAM_INDEX index);
/** Notify fpga not to touch flash, open src and flash drive to write */
int openFileForFlash(char *mess, FILE **flashfd, FILE **srcfd);
int openFileForFlash(char *mess, enum PROGRAM_INDEX index, FILE **flashfd, FILE **srcfd,
int forceDeleteNormalFile);
int checkNormalFile(char *mess, enum PROGRAM_INDEX index, int forceDeleteNormalFile);
int eraseFlash(char *mess);
/* write from tmp file to flash */
int writeToFlash(char *mess, ssize_t fsize, FILE *flashfd, FILE *srcfd);

View File

@ -285,7 +285,8 @@ int update_detector_server(int);
int receive_program(int file_des, enum PROGRAM_INDEX index);
void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
char *functionType, uint64_t filesize,
char *checksum, char *serverName);
char *checksum, char *serverName,
int forceDeleteNormalFile);
void receive_program_default(int file_des, enum PROGRAM_INDEX index,
char *functionType, uint64_t filesize,
char *checksum, char *serverName);

View File

@ -7,6 +7,7 @@
#include "slsDetectorServer_defs.h"
#include <string.h>
#include <sys/stat.h>
#include <sys/sysinfo.h>
#include <unistd.h> // usleep
@ -38,6 +39,9 @@
#define CMD_GET_AMD_FLASH "dmesg | grep Amd"
#define CMD_CREATE_DEVICE_FILE_PART1 "mknod"
#define CMD_CREATE_DEVICE_FILE_PART2 "c 90 6"
#define FLASH_BUFFER_MEMORY_SIZE (128 * 1024) // 500 KB
// clang-format on
@ -274,7 +278,8 @@ int allowUpdate(char *mess, char *functionType) {
getKernelVersion(retvals);
snprintf(mess, MAX_STR_LENGTH,
"Could not update %s. Kernel version %s is too old to "
"update the Amd flash/ root directory. Most likely, blackfin needs rescue or replacement. Please contact us.\n",
"update the Amd flash/ root directory. Most likely, blackfin "
"needs rescue or replacement. Please contact us.\n",
functionType, retvals);
LOG(logERROR, (mess));
return FAIL;
@ -319,7 +324,7 @@ int preparetoCopyProgram(char *mess, char *functionType, FILE **fd,
int eraseAndWriteToFlash(char *mess, enum PROGRAM_INDEX index,
char *functionType, char *clientChecksum,
ssize_t fsize) {
ssize_t fsize, int forceDeleteNormalFile) {
memset(messageType, 0, sizeof(messageType));
strcpy(messageType, functionType);
@ -330,7 +335,8 @@ int eraseAndWriteToFlash(char *mess, enum PROGRAM_INDEX index,
FILE *flashfd = NULL;
FILE *srcfd = NULL;
if (openFileForFlash(mess, &flashfd, &srcfd) == FAIL) {
if (openFileForFlash(mess, index, &flashfd, &srcfd, forceDeleteNormalFile) ==
FAIL) {
return FAIL;
}
@ -434,7 +440,8 @@ int getDrive(char *mess, enum PROGRAM_INDEX index) {
return OK;
}
int openFileForFlash(char *mess, FILE **flashfd, FILE **srcfd) {
int openFileForFlash(char *mess, enum PROGRAM_INDEX index, FILE **flashfd, FILE **srcfd,
int forceDeleteNormalFile) {
// open src file
*srcfd = fopen(TEMP_PROG_FILE_NAME, "r");
if (*srcfd == NULL) {
@ -447,6 +454,11 @@ int openFileForFlash(char *mess, FILE **flashfd, FILE **srcfd) {
}
LOG(logDEBUG1, ("Temp file ready for reading\n"));
if (checkNormalFile(mess, index, forceDeleteNormalFile) == FAIL) {
fclose(*srcfd);
return FAIL;
}
// open flash drive for writing
*flashfd = fopen(flashDriveName, "w");
if (*flashfd == NULL) {
@ -462,6 +474,95 @@ int openFileForFlash(char *mess, FILE **flashfd, FILE **srcfd) {
return OK;
}
int checkNormalFile(char *mess, enum PROGRAM_INDEX index, int forceDeleteNormalFile) {
#ifndef VIRTUAL
// check if its a normal file or special file
struct stat buf;
if (stat(flashDriveName, &buf) == -1) {
sprintf(mess,
"Could not %s. Unable to find the flash drive %s\n",
messageType, flashDriveName);
LOG(logERROR, (mess));
return FAIL;
}
// zero = normal file (not char special drive file)
if (!S_ISCHR(buf.st_mode)) {
// kernel memory is not permanent
if (index != PROGRAM_FPGA) {
sprintf(mess,
"Could not %s. The flash drive found is a normal file. "
"Reboot board using 'rebootcontroller' command to load "
"proper device tree\n",
messageType);
LOG(logERROR, (mess));
return FAIL;
}
// user does not allow to fix it (default)
if (forceDeleteNormalFile == 0) {
sprintf(mess,
"Could not %s. The flash drive %s found for fpga programming is a normal file. To "
"fix this (by deleting this file, creating the flash drive and proceeding with "
"programming), re-run the programming command 'programfpga' with parameter "
"'--force-delete-normal-file'\n",
messageType, flashDriveName);
LOG(logERROR, (mess));
return FAIL;
}
// fpga memory stays after a reboot, user allowed to fix it
LOG(logWARNING, ("Flash drive invalidated (normal file). Fixing it...\n"));
// user allows to fix it, so force delete normal file
char cmd[MAX_STR_LENGTH] = {0};
char retvals[MAX_STR_LENGTH] = {0};
if (snprintf(cmd, MAX_STR_LENGTH, "rm %s", flashDriveName) >=
MAX_STR_LENGTH) {
sprintf(mess,
"Could not update %s. Command to delete normal file %s is "
"too long\n",
messageType, flashDriveName);
LOG(logERROR, (mess));
return FAIL;
}
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
snprintf(
mess, MAX_STR_LENGTH,
"Could not update %s. (could not delete normal file %s: %s)\n",
messageType, flashDriveName, retvals);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\tDeleted Normal File (%s)\n", flashDriveName));
// create special drive
if (snprintf(cmd, MAX_STR_LENGTH, "%s %s %s",
CMD_CREATE_DEVICE_FILE_PART1, flashDriveName,
CMD_CREATE_DEVICE_FILE_PART2) >= MAX_STR_LENGTH) {
sprintf(mess,
"Could not update %s. Command to create special file %s is "
"too long\n",
messageType, flashDriveName);
LOG(logERROR, (mess));
return FAIL;
}
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
snprintf(
mess, MAX_STR_LENGTH,
"Could not update %s. (could not create special file %s: %s)\n",
messageType, flashDriveName, retvals);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\tSpecial File created (%s)\n", flashDriveName));
} else {
LOG(logINFO, ("\tValidated flash drive (not a normal file)\n"));
}
#endif
return OK;
}
int eraseFlash(char *mess) {
LOG(logINFO, ("\tErasing Flash...\n"));

View File

@ -8,6 +8,7 @@
#include <string.h>
#include <unistd.h> // usleep
#include <sys/stat.h>
/* global variables */
@ -146,6 +147,30 @@ int getDrive(char *mess, enum PROGRAM_INDEX index) {
}
int openFileForFlash(char *mess, FILE **flashfd) {
#ifndef VIRTUAL
// check if its a normal file or special file
struct stat buf;
if (stat(flashDriveName, &buf) == -1) {
sprintf(mess,
"Could not %s. Unable to find the flash drive %s\n",
messageType, flashDriveName);
LOG(logERROR, (mess));
return FAIL;
}
// zero = normal file (not char drive special file)
if (!S_ISCHR(buf.st_mode)) {
// memory is not permanent
sprintf(mess,
"Could not %s. The flash drive found is a normal file. "
"Reboot board using 'rebootcontroller' command to load "
"proper device tree\n",
messageType);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\tValidated flash drive (not a normal file)\n"));
#endif
*flashfd = fopen(flashDriveName, "w");
if (*flashfd == NULL) {
sprintf(mess,

View File

@ -4003,7 +4003,8 @@ int check_version(int file_des) {
usleep(3 * 1000 * 1000);
if (!isInitCheckDone()) {
ret = FAIL;
strcpy(mess, "Server Initialization still not done done in server. Unexpected.\n");
strcpy(mess, "Server Initialization still not done done in server. "
"Unexpected.\n");
LOG(logERROR, (mess));
}
}
@ -9220,25 +9221,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);
@ -9460,6 +9444,15 @@ int receive_program(int file_des, enum PROGRAM_INDEX index) {
LOG(logINFO, ("\tServer Name: %s\n", serverName));
}
#if !defined(GOTTHARD2D) && !defined(MYTHEN3D) && !defined(EIGERD)
int forceDeleteNormalFile = 0;
if (receiveData(file_des, &forceDeleteNormalFile,
sizeof(forceDeleteNormalFile), INT32) < 0)
return printSocketReadError();
LOG(logINFO,
("\tForce Delete Normal File flag? %s\n", (forceDeleteNormalFile ? "Y" : "N")));
#endif
// in same folder as current process (will also work for virtual then
// with write permissions)
{
@ -9484,7 +9477,7 @@ int receive_program(int file_des, enum PROGRAM_INDEX index) {
checksum, serverName);
#else
receive_program_via_blackfin(file_des, index, functionType,
filesize, checksum, serverName);
filesize, checksum, serverName, forceDeleteNormalFile);
#endif
}
@ -9500,7 +9493,7 @@ int receive_program(int file_des, enum PROGRAM_INDEX index) {
void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
char *functionType, uint64_t filesize,
char *checksum, char *serverName) {
char *checksum, char *serverName, int forceDeleteNormalFile) {
#if !defined(JUNGFRAUD) && !defined(CHIPTESTBOARDD) && !defined(MOENCHD) && \
!defined(GOTTHARDD)
@ -9599,7 +9592,7 @@ void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
case PROGRAM_FPGA:
case PROGRAM_KERNEL:
ret = eraseAndWriteToFlash(mess, index, functionType, checksum,
totalsize);
totalsize, forceDeleteNormalFile);
break;
case PROGRAM_SERVER:
ret = moveBinaryFile(mess, serverName, TEMP_PROG_FILE_NAME,
@ -9802,12 +9795,16 @@ int set_top(int file_des) {
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);
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"));
sprintf(mess, "Could not set %s\n",
(arg == 1 ? "Top" : "Bottom"));
LOG(logERROR, (mess));
} else {
int retval = -1;

View File

@ -7,6 +7,7 @@ set(SOURCES
src/CmdProxy.cpp
src/CmdParser.cpp
src/Pattern.cpp
src/CtbConfig.cpp
)
add_library(slsDetectorObject OBJECT

View File

@ -592,12 +592,17 @@ class Detector {
/** Options: IDLE, TRANSMITTING, RUNNING */
Result<defs::runStatus> getReceiverStatus(Positions pos = {}) const;
Result<int64_t> getFramesCaught(Positions pos = {}) const;
/** Gets the number of frames caught for each port in receiver. */
Result<std::vector<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 frame index for each port in receiver. */
Result<std::vector<int64_t>>
getRxCurrentFrameIndex(Positions pos = {}) const;
/** [Eiger][Jungfrau][Moench][CTB] */
Result<uint64_t> getNextFrameNumber(Positions pos = {}) const;
@ -699,60 +704,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 +757,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 +816,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 +824,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;
@ -1028,15 +1015,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;
@ -1628,6 +1613,14 @@ class Detector {
/** [CTB] Default is enabled. */
void setLEDEnable(bool enable, Positions pos = {});
void setDacNames(const std::vector<std::string> names);
std::vector<std::string> getDacNames() const;
defs::dacIndex getDacIndex(const std::string& name);
std::string getDacName(defs::dacIndex i);
///@}
/** @name Pattern */
@ -1762,10 +1755,13 @@ class Detector {
/** [Jungfrau][Gotthard][CTB][Moench][Mythen3][Gotthard2]
* Advanced user Function!
* Program firmware from command line, after which detector controller is
* rebooted. [Jungfrau][CTB][Moench] fname is a pof file (full path) \n
* [Mythen3][Gotthard2] fname is an rbf file (full path)
* rebooted. forceDeleteNormalFile is true, if normal file found
* in device tree, it must be deleted, a new device drive created and
* programming continued.[Jungfrau][CTB][Moench] fname is a pof file (full
* path) \n [Mythen3][Gotthard2] fname is an rbf file (full path)
*/
void programFPGA(const std::string &fname, Positions pos = {});
void programFPGA(const std::string &fname, const bool forceDeleteNormalFile,
Positions pos = {});
/** [Jungfrau][CTB][Moench] Advanced user Function! */
void resetFPGA(Positions pos = {});
@ -1931,7 +1927,6 @@ class Detector {
*/
std::string getUserDetails() const;
Result<uint64_t> getRxCurrentFrameIndex(Positions pos = {}) const;
///@}
private:

View File

@ -1056,11 +1056,10 @@ std::string CmdProxy::TemperatureValues(int action) {
std::string CmdProxy::Dac(int action) {
std::ostringstream os;
os << cmd << ' ';
auto type = det->getDetectorType().squash();
// dac indices only for ctb
if (args.size() > 0 && action != defs::HELP_ACTION) {
if (is_int(args[0]) &&
det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
if (is_int(args[0]) && type != defs::CHIPTESTBOARD) {
throw sls::RuntimeError(
"Dac indices can only be used for chip test board. Use daclist "
"to get list of dac names for current detector.");
@ -1077,7 +1076,14 @@ std::string CmdProxy::Dac(int action) {
if (args.empty())
WrongNumberOfParameters(1); // This prints slightly wrong
defs::dacIndex dacIndex = StringTo<defs::dacIndex>(args[0]);
defs::dacIndex dacIndex{};
//TODO! Remove if
if (type == defs::CHIPTESTBOARD && !is_int(args[0])) {
dacIndex = det->getDacIndex(args[0]);
} else {
dacIndex = StringTo<defs::dacIndex>(args[0]);
}
bool mV = false;
if (args.size() == 2) {
@ -1095,7 +1101,11 @@ std::string CmdProxy::Dac(int action) {
if (args.empty())
WrongNumberOfParameters(1); // This prints slightly wrong
defs::dacIndex dacIndex = StringTo<defs::dacIndex>(args[0]);
defs::dacIndex dacIndex{};
if (type == defs::CHIPTESTBOARD && !is_int(args[0]))
dacIndex = det->getDacIndex(args[0]);
else
dacIndex = StringTo<defs::dacIndex>(args[0]);
bool mV = false;
if (args.size() == 3) {
if ((args[2] != "mv") && (args[2] != "mV")) {
@ -1115,6 +1125,41 @@ std::string CmdProxy::Dac(int action) {
return os.str();
}
std::string CmdProxy::DacList(const int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == slsDetectorDefs::HELP_ACTION) {
os << "\n\t[dacname1 dacname2 .. dacname18] \n\t\t[ChipTestBoard] Set "
"the list of dac names for this detector.\n\t\t[All] Gets the "
"list "
"of "
"dac names for every dac for this detector."
<< '\n';
} else if (action == slsDetectorDefs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto t = det->getDacNames();
os << sls::ToString(t) << '\n';
} else if (action == slsDetectorDefs::PUT_ACTION) {
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
throw sls::RuntimeError("This detector already has fixed dac "
"names. Cannot change them.");
}
if (det_id != -1) {
throw sls::RuntimeError("Cannot configure dacnames at module level");
}
if (args.size() != 18) {
WrongNumberOfParameters(18);
}
det->setDacNames(args);
os << ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::DacValues(int action) {
std::ostringstream os;
os << cmd << ' ';
@ -1134,13 +1179,15 @@ std::string CmdProxy::DacValues(int action) {
WrongNumberOfParameters(1);
}
auto t = det->getDacList();
auto names = det->getDacNames();
auto name_it = names.begin();
os << '[';
auto it = t.cbegin();
os << ToString(*it) << ' ';
os << ToString(*name_it++) << ' ';
os << OutString(det->getDAC(*it++, mv, std::vector<int>{det_id}))
<< (!args.empty() ? " mV" : "");
while (it != t.cend()) {
os << ", " << ToString(*it) << ' ';
os << ", " << ToString(*name_it++) << ' ';
os << OutString(det->getDAC(*it++, mv, std::vector<int>{det_id}))
<< (!args.empty() ? " mV" : "");
}
@ -1274,40 +1321,6 @@ std::string CmdProxy::DetectorStatus(int action) {
return os.str();
}
std::string CmdProxy::RxMissingPackets(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "Number of missing packets for each port in receiver. If "
"negative, they are packets in excess. "
<< '\n';
} else if (action == defs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto mp = det->getNumMissingPackets(std::vector<int>{det_id});
/*
auto tmp = det->getNumMissingPackets(std::vector<int>{det_id});
// convert to signed missing packets (to get excess)
Result<std::vector<int64_t>> mp(tmp.size());
for (unsigned int i = 0; i < mp.size(); ++i) {
mp[i] = static_cast<int64_t>(tmp[i]);
}
OR
Result<std::vector<int64_t>> tmp;
for (auto val : tmp) {
mp.push_back(static_cast<int64_t>(val));
}
*/
os << OutString(mp) << '\n';
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("Cannot put");
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::Scan(int action) {
std::ostringstream os;
os << cmd << ' ';
@ -1484,7 +1497,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 +1517,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 +1530,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 +1553,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 +1566,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 +1606,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) {
throw sls::RuntimeError(
"Cannot add multiple receivers at module level");
}
if (det_id != -1) {
throw sls::RuntimeError(
"Cannot add multiple receivers for multiple modules at module level");
"Cannot add multiple receivers 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';
}
}
// multiple arguments (single rxr each) (for both: each module and RR)
else {
det->setRxHostname(args, {det_id});
det->setRxHostname(args);
os << ToString(args) << '\n';
}
}
// single argument
else {
// multiple receivers concatenated with +
if (args[0].find('+') != std::string::npos) {
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) {
if (det_id != -1) {
throw sls::RuntimeError(
"Cannot add multiple receivers at RR level");
"Cannot add multiple receivers at module level");
}
det->setRxHostname(t, {det_id});
auto t = sls::split(args[0], '+');
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';
}
}
@ -2887,19 +2879,31 @@ std::string CmdProxy::ProgramFpga(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[fname.pof | fname.rbf (full path)]\n\t[Jungfrau][Ctb][Moench] "
"Programs FPGA from pof file (full path). Then, detector "
"controller is rebooted \n\t[Mythen3][Gotthard2] Programs FPGA "
"from rbf file (full path). Then, detector controller is "
"rebooted."
os << "[fname.pof | fname.rbf (full "
"path)][(opitonal)--force-delete-normal-file]\n\t[Jungfrau][Ctb]["
"Moench] Programs FPGA from pof file (full path). Then, detector "
"controller is rebooted. \n\t\tUse --force-delete-normal-file "
"argument, if normal file found in device tree, it must be "
"deleted, a new device drive created and programming "
"continued.\n\t[Mythen3][Gotthard2] Programs FPGA from rbf file "
"(full path). Then, detector controller is rebooted."
<< '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError("Cannot get");
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
bool forceDeteleNormalFile = false;
if (args.size() == 2) {
if (args[1] != "--force-delete-normal-file") {
throw sls::RuntimeError(
"Could not scan second argument. Did you "
"mean --force-delete-normal-file?");
}
forceDeteleNormalFile = true;
} else if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->programFPGA(args[0], std::vector<int>{det_id});
det->programFPGA(args[0], forceDeteleNormalFile,
std::vector<int>{det_id});
os << "successful\n";
} else {
throw sls::RuntimeError("Unknown 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) { \
@ -909,7 +837,7 @@ class CmdProxy {
/* dacs */
{"dac", &CmdProxy::Dac},
{"daclist", &CmdProxy::daclist},
{"daclist", &CmdProxy::DacList},
{"dacvalues", &CmdProxy::DacValues},
{"resetdacs", &CmdProxy::ResetDacs},
{"defaultdac", &CmdProxy::DefaultDac},
@ -932,7 +860,8 @@ class CmdProxy {
{"rx_status", &CmdProxy::ReceiverStatus},
{"status", &CmdProxy::DetectorStatus},
{"rx_framescaught", &CmdProxy::rx_framescaught},
{"rx_missingpackets", &CmdProxy::RxMissingPackets},
{"rx_missingpackets", &CmdProxy::rx_missingpackets},
{"rx_frameindex", &CmdProxy::rx_frameindex},
{"nextframenumber", &CmdProxy::nextframenumber},
{"trigger", &CmdProxy::Trigger},
{"scan", &CmdProxy::Scan},
@ -1158,8 +1087,7 @@ class CmdProxy {
{"framecounter", &CmdProxy::framecounter},
{"runtime", &CmdProxy::runtime},
{"frametime", &CmdProxy::frametime},
{"user", &CmdProxy::UserDetails},
{"rx_frameindex", &CmdProxy::rx_frameindex}
{"user", &CmdProxy::UserDetails}
};
@ -1196,6 +1124,7 @@ class CmdProxy {
std::string TemperatureValues(int action);
/* dacs */
std::string Dac(int action);
std::string DacList(int action);
std::string DacValues(int action);
std::string ResetDacs(int action);
std::string DefaultDac(int action);
@ -1354,7 +1283,7 @@ class CmdProxy {
"interfaces must be set to 2. slsReceiver and slsDetectorGui "
"does not handle.");
INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(
INTEGER_COMMAND_VEC_ID_GET(
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] "
@ -1537,10 +1466,6 @@ class CmdProxy {
/* dacs */
GET_COMMAND_NOID(
daclist, getDacList,
"\n\tGets the list of commands for every dac for this detector.");
/* on chip dacs */
INTEGER_USER_IND_COMMAND(
vchip_comp_fe, getOnChipDAC, setOnChipDAC, StringTo<int>,
@ -1612,11 +1537,15 @@ class CmdProxy {
"to IDLE or STOPPED. Goes to stop server.");
GET_COMMAND(rx_framescaught, getFramesCaught,
"\n\tNumber of frames caught by receiver.");
"\n\tNumber of frames caught by each port in 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. If "
"negative, they are packets in excess. ");
GET_COMMAND(rx_frameindex, getRxCurrentFrameIndex,
"\n\tCurrent frame index received for each port in receiver "
"during acquisition.");
INTEGER_COMMAND_VEC_ID(
nextframenumber, getNextFrameNumber, setNextFrameNumber,
@ -1689,14 +1618,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 +1634,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,7 +1663,7 @@ class CmdProxy {
"valid. If not configured, it will throw with error message "
"requesting missing udp information.");
GET_COMMAND_RX(rx_printconfig, printRxConfiguration,
GET_COMMAND(rx_printconfig, printRxConfiguration,
"\n\tPrints the receiver configuration.");
INTEGER_COMMAND_VEC_ID(
@ -1771,7 +1700,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 "
@ -1896,7 +1825,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 +1833,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 +1843,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. "
@ -2334,10 +2263,6 @@ class CmdProxy {
"ns|us|ms|s]\n\t[Jungfrau][Mythen3][Gotthard2][Moench]["
"CTB] Timestamp at a frame start."
"\n\t[Gotthard2] not in burst and auto mode.");
GET_COMMAND(
rx_frameindex, getRxCurrentFrameIndex,
"\n\tCurrent frame index received in receiver during acquisition.");
};
} // namespace sls

View File

@ -0,0 +1,72 @@
#include "CtbConfig.h"
#include "SharedMemory.h"
#include "sls/ToString.h"
#include "sls/string_utils.h"
#include <algorithm>
#include <fstream>
#include <sstream>
namespace sls {
CtbConfig::CtbConfig(){
for (size_t i=0; i!=num_dacs; ++i){
setDacName(i, "dac"+ToString(i));
}
}
void CtbConfig::check_index(size_t i) const {
if (!(i < num_dacs)) {
std::ostringstream oss;
oss << "DAC index is too large needs to be below " << num_dacs;
throw RuntimeError(oss.str());
}
}
void CtbConfig::check_size(const std::string &name) const {
if (name.empty())
throw RuntimeError("Name needs to be at least one character");
// dacname_length -1 to account for \0 termination
if (!(name.size() < (name_length - 1))) {
std::ostringstream oss;
oss << "Length of name needs to be less than " << name_length - 1
<< " chars";
throw RuntimeError(oss.str());
}
}
void CtbConfig::setDacName(size_t index, const std::string &name) {
check_index(index);
check_size(name);
char *dst = &dacnames[index * name_length];
memset(dst, '\0', name_length);
memcpy(dst, &name[0], name.size());
}
void CtbConfig::setDacNames(const std::vector<std::string>& names){
for (size_t i = 0; i!=num_dacs; ++i){
setDacName(i, names[i]);
}
}
std::string CtbConfig::getDacName(size_t index) const {
return dacnames + index * name_length;
}
std::vector<std::string> CtbConfig::getDacNames() const {
std::vector<std::string> names;
for (size_t i = 0; i != num_dacs; ++i)
names.push_back(getDacName(i));
return names;
}
const char* CtbConfig::shm_tag(){
return shm_tag_;
}
} // namespace sls

View File

@ -0,0 +1,31 @@
#pragma once
#include <string>
#include <vector>
namespace sls {
class CtbConfig {
static constexpr size_t name_length = 20;
static constexpr size_t num_dacs = 18;
static constexpr const char* shm_tag_ = "ctbdacs";
char dacnames[name_length * num_dacs]{};
void check_index(size_t i) const;
void check_size(const std::string &name) const;
public:
CtbConfig();
CtbConfig(const CtbConfig&) = default;
CtbConfig(CtbConfig&&) = default;
CtbConfig& operator=(const CtbConfig&) = default;
~CtbConfig() = default;
void setDacNames(const std::vector<std::string> &names);
void setDacName(size_t index, const std::string &name);
std::string getDacName(size_t index) const;
std::vector<std::string> getDacNames() const;
static const char* shm_tag();
};
} // namespace sls

View File

@ -7,6 +7,7 @@
#include "CmdProxy.h"
#include "DetectorImpl.h"
#include "Module.h"
#include "CtbConfig.h"
#include "sls/Pattern.h"
#include "sls/container_utils.h"
#include "sls/file_utils.h"
@ -21,6 +22,7 @@
namespace sls {
void freeSharedMemory(int detectorIndex, int moduleIndex) {
// single module
if (moduleIndex >= 0) {
SharedMemory<sharedModule> moduleShm(detectorIndex, moduleIndex);
@ -44,6 +46,11 @@ void freeSharedMemory(int detectorIndex, int moduleIndex) {
SharedMemory<sharedModule> moduleShm(detectorIndex, i);
moduleShm.RemoveSharedMemory();
}
// Ctb configuration
SharedMemory<CtbConfig> ctbShm(detectorIndex, -1, CtbConfig::shm_tag());
if (ctbShm.IsExisting())
ctbShm.RemoveSharedMemory();
}
using defs = slsDetectorDefs;
@ -829,7 +836,7 @@ Result<defs::runStatus> Detector::getReceiverStatus(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverStatus, pos);
}
Result<int64_t> Detector::getFramesCaught(Positions pos) const {
Result<std::vector<int64_t>> Detector::getFramesCaught(Positions pos) const {
return pimpl->Parallel(&Module::getFramesCaughtByReceiver, pos);
}
@ -838,6 +845,11 @@ Detector::getNumMissingPackets(Positions pos) const {
return pimpl->Parallel(&Module::getNumMissingPackets, pos);
}
Result<std::vector<int64_t>>
Detector::getRxCurrentFrameIndex(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverCurrentFrameIndex, pos);
}
Result<uint64_t> Detector::getNextFrameNumber(Positions pos) const {
return pimpl->Parallel(&Module::getNextFrameNumber, pos);
}
@ -871,7 +883,7 @@ Result<std::string> Detector::getScanErrorMessage(Positions pos) const {
Result<int> Detector::getNumberofUDPInterfaces(Positions pos) const {
// also called by vetostream (for gotthard2)
return pimpl->getNumberofUDPInterfaces(pos);
return pimpl->Parallel(&Module::getNumberofUDPInterfacesFromShm, pos);
}
void Detector::setNumberofUDPInterfaces(int n, Positions pos) {
@ -977,81 +989,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 +1061,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 +1111,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);
}
}
@ -1366,13 +1350,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);
@ -1767,7 +1751,7 @@ Result<defs::streamingInterface> Detector::getVetoStream(Positions pos) const {
// 3gbe
auto r3 = pimpl->Parallel(&Module::getVetoStream, pos);
// 10gbe (debugging interface) opens 2nd udp interface in receiver
auto r10 = pimpl->getNumberofUDPInterfaces(pos);
auto r10 = getNumberofUDPInterfaces(pos);
Result<defs::streamingInterface> res(r3.size());
for (unsigned int i = 0; i < res.size(); ++i) {
@ -1789,7 +1773,7 @@ void Detector::setVetoStream(defs::streamingInterface interface,
pimpl->Parallel(&Module::setVetoStream, pos, LOW_LATENCY_LINK);
// 10gbe (debugging interface) opens 2nd udp interface in receiver
int old_numinterfaces = pimpl->getNumberofUDPInterfaces(pos).tsquash(
int old_numinterfaces = getNumberofUDPInterfaces(pos).tsquash(
"retrieved inconsistent number of udp interfaces");
int numinterfaces =
(((interface & defs::streamingInterface::ETHERNET_10GB) ==
@ -2090,6 +2074,42 @@ void Detector::setLEDEnable(bool enable, Positions pos) {
pimpl->Parallel(&Module::setLEDEnable, pos, enable);
}
void Detector::setDacNames(const std::vector<std::string> names) {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named dacs only for CTB");
pimpl->setCtbDacNames(names);
}
std::vector<std::string> Detector::getDacNames() const {
std::vector<std::string> names;
auto type = getDetectorType().squash();
if (type == defs::CHIPTESTBOARD)
return pimpl->getCtbDacNames();
for (const auto &index : getDacList())
names.push_back(ToString(index));
return names;
}
defs::dacIndex Detector::getDacIndex(const std::string &name) {
auto type = getDetectorType().squash();
if (type == defs::CHIPTESTBOARD) {
auto names = getDacNames();
auto it = std::find(names.begin(), names.end(), name);
if (it == names.end())
throw RuntimeError("Dacname not found");
return static_cast<defs::dacIndex>(it - names.begin());
}
return StringTo<defs::dacIndex>(name);
}
std::string Detector::getDacName(defs::dacIndex i) {
auto type = getDetectorType().squash();
if (type == defs::CHIPTESTBOARD)
return pimpl->getCtbDacName(i);
return ToString(i);
}
// Pattern
void Detector::setPattern(const std::string &fname, Positions pos) {
@ -2210,10 +2230,11 @@ void Detector::setAdditionalJsonParameter(const std::string &key,
// Advanced
void Detector::programFPGA(const std::string &fname, Positions pos) {
void Detector::programFPGA(const std::string &fname,
const bool forceDeleteNormalFile, Positions pos) {
LOG(logINFO) << "Updating Firmware...";
std::vector<char> buffer = pimpl->readProgrammingFile(fname);
pimpl->Parallel(&Module::programFPGA, pos, buffer);
pimpl->Parallel(&Module::programFPGA, pos, buffer, forceDeleteNormalFile);
rebootController(pos);
}
@ -2258,7 +2279,7 @@ void Detector::updateFirmwareAndServer(const std::string &sname,
LOG(logINFO) << "Updating Firmware and Detector Server (with tftp)...";
LOG(logINFO) << "Updating Detector Server (via tftp)...";
pimpl->Parallel(&Module::copyDetectorServer, pos, sname, hostname);
programFPGA(fname, pos);
programFPGA(fname, false, pos);
}
void Detector::updateFirmwareAndServer(const std::string &sname,
@ -2269,7 +2290,7 @@ void Detector::updateFirmwareAndServer(const std::string &sname,
std::vector<char> buffer = readBinaryFile(sname, "Update Detector Server");
std::string filename = sls::getFileNameFromFilePath(sname);
pimpl->Parallel(&Module::updateDetectorServer, pos, buffer, filename);
programFPGA(fname, pos);
programFPGA(fname, false, pos);
}
Result<bool> Detector::getUpdateMode(Positions pos) const {
@ -2378,12 +2399,8 @@ Result<ns> Detector::getMeasurementTime(Positions pos) const {
std::string Detector::getUserDetails() const { return pimpl->getUserDetails(); }
Result<uint64_t> Detector::getRxCurrentFrameIndex(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverCurrentFrameIndex, pos);
}
std::vector<int> Detector::getPortNumbers(int start_port) {
int num_sockets_per_detector = pimpl->getNumberofUDPInterfaces({}).tsquash(
int num_sockets_per_detector = getNumberofUDPInterfaces({}).tsquash(
"Number of UDP Interfaces is not consistent among modules");
std::vector<int> res;
res.reserve(size());

View File

@ -32,7 +32,8 @@
namespace sls {
DetectorImpl::DetectorImpl(int detector_index, bool verify, bool update)
: detectorIndex(detector_index), shm(detector_index, -1) {
: detectorIndex(detector_index), shm(detector_index, -1),
ctb_shm(detector_index, -1, CtbConfig::shm_tag()) {
setupDetector(verify, update);
}
@ -44,6 +45,9 @@ void DetectorImpl::setupDetector(bool verify, bool update) {
if (update) {
updateUserdetails();
}
if (ctb_shm.IsExisting())
ctb_shm.OpenSharedMemory();
}
void DetectorImpl::setAcquiringFlag(bool flag) { shm()->acquiringFlag = flag; }
@ -74,6 +78,10 @@ void DetectorImpl::freeSharedMemory(int detectorIndex, int detPos) {
SharedMemory<sharedModule> moduleShm(detectorIndex, i);
moduleShm.RemoveSharedMemory();
}
SharedMemory<CtbConfig> ctbShm(detectorIndex, -1, CtbConfig::shm_tag());
if (ctbShm.IsExisting())
ctbShm.RemoveSharedMemory();
}
void DetectorImpl::freeSharedMemory() {
@ -86,6 +94,9 @@ void DetectorImpl::freeSharedMemory() {
// clear detector shm
shm.RemoveSharedMemory();
client_downstream = false;
if (ctb_shm.IsExisting())
ctb_shm.RemoveSharedMemory();
}
std::string DetectorImpl::getUserDetails() {
@ -246,13 +257,14 @@ void DetectorImpl::setHostname(const std::vector<std::string> &name) {
}
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);
}
// Here we know the detector type and can add ctb shared memory
// if needed, CTB dac names are only on detector level
if (shm()->detType == defs::CHIPTESTBOARD) {
if (ctb_shm.IsExisting())
ctb_shm.OpenSharedMemory();
else
ctb_shm.CreateSharedMemory();
}
}
@ -281,6 +293,13 @@ void DetectorImpl::addModule(const std::string &hostname) {
// get type by connecting
detectorType type = Module::getTypeFromDetector(host, port);
// gotthard cannot have more than 2 modules (50um=1, 25um=2
if ((type == GOTTHARD || type == GOTTHARD2) && modules.size() > 2) {
freeSharedMemory();
throw sls::RuntimeError("Gotthard cannot have more than 2 modules");
}
auto pos = modules.size();
modules.emplace_back(
sls::make_unique<Module>(type, detectorIndex, pos, false));
@ -288,11 +307,20 @@ void DetectorImpl::addModule(const std::string &hostname) {
modules[pos]->setControlPort(port);
modules[pos]->setStopPort(port + 1);
modules[pos]->setHostname(host, shm()->initialChecks);
// module type updated by now
shm()->detType = Parallel(&Module::getDetectorType, {})
.tsquash("Inconsistent detector types.");
// for moench and ctb
modules[pos]->updateNumberOfChannels();
// for eiger, jungfrau, gotthard2
modules[pos]->updateNumberofUDPInterfaces();
// update zmq port in case numudpinterfaces changed
int numInterfaces = modules[pos]->getNumberofUDPInterfacesFromShm();
modules[pos]->setClientStreamingPort(DEFAULT_ZMQ_CL_PORTNO +
pos * numInterfaces);
}
void DetectorImpl::updateDetectorSize() {
@ -1142,7 +1170,7 @@ int DetectorImpl::acquire() {
if (acquisition_finished != nullptr) {
int status = Parallel(&Module::getRunStatus, {}).squash(ERROR);
auto a = Parallel(&Module::getReceiverProgress, {});
double progress = (*std::min_element(a.begin(), a.end()));
double progress = (*std::max_element(a.begin(), a.end()));
acquisition_finished(progress, status, acqFinished_p);
}
@ -1361,10 +1389,6 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
return buffer;
}
sls::Result<int> DetectorImpl::getNumberofUDPInterfaces(Positions pos) const {
return Parallel(&Module::getNumberofUDPInterfaces, pos);
}
sls::Result<int> DetectorImpl::getDefaultDac(defs::dacIndex index,
defs::detectorSettings sett,
Positions pos) {
@ -1376,4 +1400,16 @@ void DetectorImpl::setDefaultDac(defs::dacIndex index, int defaultValue,
Parallel(&Module::setDefaultDac, pos, index, defaultValue, sett);
}
std::vector<std::string> DetectorImpl::getCtbDacNames() const {
return ctb_shm()->getDacNames();
}
void DetectorImpl::setCtbDacNames(const std::vector<std::string> &names) {
ctb_shm()->setDacNames(names);
}
std::string DetectorImpl::getCtbDacName(defs::dacIndex i) const {
return ctb_shm()->getDacName(static_cast<int>(i));
}
} // namespace sls

View File

@ -7,6 +7,8 @@
#include "sls/logger.h"
#include "sls/sls_detector_defs.h"
#include "CtbConfig.h"
class ZmqSocket;
class detectorData;
@ -291,7 +293,6 @@ class DetectorImpl : public virtual slsDetectorDefs {
*/
std::vector<char> readProgrammingFile(const std::string &fname);
sls::Result<int> getNumberofUDPInterfaces(Positions pos) const;
void setNumberofUDPInterfaces(int n, Positions pos);
sls::Result<int> getDefaultDac(defs::dacIndex index,
defs::detectorSettings sett,
@ -299,6 +300,11 @@ class DetectorImpl : public virtual slsDetectorDefs {
void setDefaultDac(defs::dacIndex index, int defaultValue,
defs::detectorSettings sett, Positions pos);
std::vector<std::string> getCtbDacNames() const;
std::string getCtbDacName(defs::dacIndex i) const;
void setCtbDacNames(const std::vector<std::string>& names);
private:
/**
* Creates/open shared memory, initializes detector structure and members
@ -382,6 +388,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
const int detectorIndex{0};
sls::SharedMemory<sharedDetector> shm{0, -1};
sls::SharedMemory<CtbConfig> ctb_shm{0, -1, CtbConfig::shm_tag()};
std::vector<std::unique_ptr<sls::Module>> modules;
/** data streaming (down stream) enabled in client (zmq sckets created) */

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) */
@ -211,8 +203,9 @@ class Module : public virtual slsDetectorDefs {
runStatus getRunStatus() const;
runStatus getReceiverStatus() const;
double getReceiverProgress() const;
int64_t getFramesCaughtByReceiver() const;
std::vector<int64_t> getFramesCaughtByReceiver() const;
std::vector<int64_t> getNumMissingPackets() const;
std::vector<int64_t> getReceiverCurrentFrameIndex() const;
uint64_t getNextFrameNumber() const;
void setNextFrameNumber(uint64_t value);
void sendSoftwareTrigger(const bool block);
@ -226,7 +219,7 @@ class Module : public virtual slsDetectorDefs {
* *
* ************************************************/
int getNumberofUDPInterfacesFromShm() const;
int getNumberofUDPInterfaces() const;
void updateNumberofUDPInterfaces();
void setNumberofUDPInterfaces(int n);
int getSelectedUDPInterface() const;
void selectUDPInterface(int n);
@ -244,21 +237,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 +269,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;
@ -339,8 +331,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;
@ -553,7 +545,8 @@ class Module : public virtual slsDetectorDefs {
* Advanced *
* *
* ************************************************/
void programFPGA(std::vector<char> buffer);
void programFPGA(std::vector<char> buffer,
const bool forceDeleteNormalFile);
void resetFPGA();
void copyDetectorServer(const std::string &fname,
const std::string &hostname);
@ -590,7 +583,6 @@ class Module : public virtual slsDetectorDefs {
int64_t getNumberOfFramesFromStart() const;
int64_t getActualTime() const;
int64_t getMeasurementTime() const;
uint64_t getReceiverCurrentFrameIndex() const;
private:
void checkArgs(const void *args, size_t args_size, void *retval,
@ -680,52 +672,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 +726,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
@ -778,7 +761,8 @@ class Module : public virtual slsDetectorDefs {
bool trimbits = true);
void sendProgram(bool blackfin, std::vector<char> buffer,
const int functionEnum, const std::string &functionType,
const std::string serverName = "");
const std::string serverName = "",
const bool forceDeleteNormalFile = false);
void simulatingActivityinDetector(const std::string &functionType,
const int timeRequired);

View File

@ -19,7 +19,6 @@
#include <fcntl.h> // O_CREAT, O_TRUNC..
#include <iostream>
#include <sstream>
// #include <stdio.h> // printf
#include <sys/mman.h> // shared memory
#include <sys/stat.h> // fstat
#include <unistd.h>
@ -36,11 +35,9 @@ namespace sls {
template <typename T> class SharedMemory {
public:
/**
* moduleid of -1 creates a detector only shared memory
*/
SharedMemory(int detectorId, int moduleIndex) {
name = ConstructSharedMemoryName(detectorId, moduleIndex);
//moduleid of -1 creates a detector only shared memory
SharedMemory(int detectorId, int moduleIndex, const std::string& tag = "") {
name = ConstructSharedMemoryName(detectorId, moduleIndex, tag);
}
/**
@ -103,11 +100,7 @@ template <typename T> class SharedMemory {
return ret;
}
/**
* Get shared memory name
*/
std::string GetName() const { return name; }
size_t size() const { return shmSize; }
/**
@ -133,8 +126,8 @@ template <typename T> class SharedMemory {
RemoveSharedMemory();
throw SharedMemoryError(msg);
}
shared_struct = MapSharedMemory();
new (shared_struct) T{};
LOG(logINFO) << "Shared memory created " << name;
}
@ -211,7 +204,7 @@ template <typename T> class SharedMemory {
* @param moduleIndex module id, -1 if a detector shared memory
* @returns shared memory name
*/
std::string ConstructSharedMemoryName(int detectorId, int moduleIndex) {
std::string ConstructSharedMemoryName(int detectorId, int moduleIndex, const std::string& tag) {
// using environment path
std::string sEnvPath;
@ -222,8 +215,12 @@ template <typename T> class SharedMemory {
}
std::stringstream ss;
if (moduleIndex < 0)
if (moduleIndex < 0){
ss << SHM_DETECTOR_PREFIX << detectorId << sEnvPath;
if (!tag.empty())
ss << "_" << tag;
}
else
ss << SHM_DETECTOR_PREFIX << detectorId << SHM_MODULE_PREFIX
<< moduleIndex << sEnvPath;
@ -293,15 +290,10 @@ template <typename T> class SharedMemory {
return 0;
}
/** Shared memory name */
std::string name;
/** File descriptor */
int fd{-1};
/** shm size */
size_t shmSize{0};
T *shared_struct{nullptr};
};

View File

@ -18,6 +18,7 @@ target_sources(tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/test-CmdParser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-Module.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-Pattern.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-CtbConfig.cpp
)
target_include_directories(tests PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src>")

View File

@ -93,13 +93,19 @@ TEST_CASE("rx_framescaught", "[.cmd][.rx]") {
CmdProxy proxy(&det);
// This ensures 0 caught frames
auto prev_val = det.getFileWrite();
det.setFileWrite(false); // avoid writing or error on file creation
det.startReceiver();
det.stopReceiver();
{
std::ostringstream oss;
proxy.Call("rx_framescaught", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_framescaught 0\n");
if (det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of interfaces") == 1) {
REQUIRE(oss.str() == "rx_framescaught [0]\n");
} else {
REQUIRE(oss.str() == "rx_framescaught [0, 0]\n");
}
}
// Currently disabled may activate if we have a stable env
@ -111,10 +117,15 @@ TEST_CASE("rx_framescaught", "[.cmd][.rx]") {
// proxy.Call("rx_framescaught", {}, -1, GET, oss);
// REQUIRE(oss.str() == "rx_framescaught 1\n");
// }
for (int i = 0; i != det.size(); ++i) {
det.setFileWrite(prev_val[i], {i});
}
}
TEST_CASE("rx_missingpackets", "[.cmd][.rx]") {
Detector det;
auto prev_val = det.getFileWrite();
det.setFileWrite(false); // avoid writing or error on file creation
CmdProxy proxy(&det);
{
@ -123,8 +134,12 @@ TEST_CASE("rx_missingpackets", "[.cmd][.rx]") {
det.stopReceiver();
std::ostringstream oss;
proxy.Call("rx_missingpackets", {}, -1, GET, oss);
std::string s = (oss.str()).erase(0, strlen("rx_missingpackets ["));
REQUIRE(std::stoi(s) > 0);
if (det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of interfaces") == 1) {
REQUIRE(oss.str() != "rx_missingpackets [0]\n");
} else {
REQUIRE(oss.str() != "rx_missingpackets [0, 0]\n");
}
}
{
// 0 missing packets (takes into account that acquisition is stopped)
@ -133,9 +148,25 @@ TEST_CASE("rx_missingpackets", "[.cmd][.rx]") {
det.stopReceiver();
std::ostringstream oss;
proxy.Call("rx_missingpackets", {}, -1, GET, oss);
std::string s = (oss.str()).erase(0, strlen("rx_missingpackets ["));
REQUIRE(std::stoi(s) == 0);
if (det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of interfaces") == 1) {
REQUIRE(oss.str() == "rx_missingpackets [0]\n");
} else {
REQUIRE(oss.str() == "rx_missingpackets [0, 0]\n");
}
}
for (int i = 0; i != det.size(); ++i) {
det.setFileWrite(prev_val[i], {i});
}
}
TEST_CASE("rx_frameindex", "[.cmd][.rx]") {
Detector det;
CmdProxy proxy(&det);
proxy.Call("rx_frameindex", {}, -1, GET);
// This is a get only command
REQUIRE_THROWS(proxy.Call("rx_frameindex", {"2"}, -1, PUT));
}
/* Network Configuration (Detector<->Receiver) */
@ -884,16 +915,3 @@ TEST_CASE("rx_jsonpara", "[.cmd][.rx]") {
}
/* Insignificant */
TEST_CASE("rx_frameindex", "[.cmd][.rx]") {
Detector det;
CmdProxy proxy(&det);
proxy.Call("rx_frameindex", {}, -1, GET);
// This is a get only command
REQUIRE_THROWS(proxy.Call("rx_frameindex", {"2"}, -1, PUT));
std::ostringstream oss;
proxy.Call("rx_frameindex", {}, 0, GET, oss);
std::string s = (oss.str()).erase(0, strlen("rx_frameindex "));
REQUIRE(std::stoi(s) >= 0);
}

View File

@ -590,13 +590,13 @@ TEST_CASE("master", "[.cmd]") {
}
{
std::ostringstream oss1;
proxy.Call("master", {"0"}, 0, PUT, oss3);
REQUIRE(oss3.str() == "master 0\n");
proxy.Call("master", {"0"}, 0, PUT, oss1);
REQUIRE(oss1.str() == "master 0\n");
}
{
std::ostringstream oss1;
proxy.Call("master", {"1"}, 0, PUT, oss3);
REQUIRE(oss3.str() == "master 1\n");
proxy.Call("master", {"1"}, 0, PUT, oss1);
REQUIRE(oss1.str() == "master 1\n");
}
REQUIRE_THROWS(proxy.Call("master", {"1"}, -1, PUT));
// set all to slaves, and then master

View File

@ -0,0 +1,59 @@
#include "catch.hpp"
#include <string>
#include <stdlib.h>
#include "SharedMemory.h"
#include "CtbConfig.h"
using namespace sls;
#include <fstream>
TEST_CASE("Default construction"){
static_assert(sizeof(CtbConfig) == 360); // 18*20
CtbConfig c;
auto names = c.getDacNames();
REQUIRE(names.size() == 18);
REQUIRE(names[0] == "dac0");
REQUIRE(names[1] == "dac1");
REQUIRE(names[2] == "dac2");
REQUIRE(names[3] == "dac3");
}
TEST_CASE("Set and get a single dac name"){
CtbConfig c;
c.setDacName(3, "vrf");
auto names = c.getDacNames();
REQUIRE(c.getDacName(3) == "vrf");
REQUIRE(names[3] == "vrf");
}
TEST_CASE("Set a name that is too large throws"){
CtbConfig c;
REQUIRE_THROWS(c.setDacName(3, "somestringthatisreallytolongforadatac"));
}
TEST_CASE("Length of dac name cannot be 0"){
CtbConfig c;
REQUIRE_THROWS(c.setDacName(1, ""));
}
TEST_CASE("Copy a CTB config"){
CtbConfig c1;
c1.setDacName(5, "somename");
auto c2 = c1;
//change the name on the first object
//to detecto shallow copy
c1.setDacName(5, "someothername");
REQUIRE(c2.getDacName(5) == "somename");
}
TEST_CASE("Move CtbConfig "){
CtbConfig c1;
c1.setDacName(3, "yetanothername");
CtbConfig c2(std::move(c1));
REQUIRE(c2.getDacName(3) == "yetanothername");
}

View File

@ -134,3 +134,31 @@ TEST_CASE("Create several shared memories", "[detector]") {
CHECK(v[i].IsExisting() == false);
}
}
TEST_CASE("Create create a shared memory with a tag"){
SharedMemory<int> shm(0, -1, "ctbdacs");
REQUIRE(shm.GetName() == "/slsDetectorPackage_detector_0_ctbdacs");
}
TEST_CASE("Create create a shared memory with a tag when SLSDETNAME is set"){
// if SLSDETNAME is already set we unset it but
// save the value
std::string old_slsdetname;
if (getenv(SHM_ENV_NAME))
old_slsdetname = getenv(SHM_ENV_NAME);
unsetenv(SHM_ENV_NAME);
setenv(SHM_ENV_NAME, "myprefix", 1);
SharedMemory<int> shm(0, -1, "ctbdacs");
REQUIRE(shm.GetName() == "/slsDetectorPackage_detector_0_myprefix_ctbdacs");
// Clean up after us
if (old_slsdetname.empty())
unsetenv(SHM_ENV_NAME);
else
setenv(SHM_ENV_NAME, old_slsdetname.c_str(), 1);
}

View File

@ -848,9 +848,13 @@ int ClientInterface::get_file_index(Interface &socket) {
}
int ClientInterface::get_frame_index(Interface &socket) {
uint64_t retval = impl()->getCurrentFrameIndex();
LOG(logDEBUG1) << "frame index:" << retval;
return socket.sendResult(retval);
auto retval = impl()->getCurrentFrameIndex();
LOG(logDEBUG1) << "frames index:" << sls::ToString(retval);
auto size = static_cast<int>(retval.size());
socket.Send(OK);
socket.Send(size);
socket.Send(retval);
return OK;
}
int ClientInterface::get_missing_packets(Interface &socket) {
@ -864,9 +868,13 @@ int ClientInterface::get_missing_packets(Interface &socket) {
}
int ClientInterface::get_frames_caught(Interface &socket) {
int64_t retval = impl()->getFramesCaught();
LOG(logDEBUG1) << "frames caught:" << retval;
return socket.sendResult(retval);
auto retval = impl()->getFramesCaught();
LOG(logDEBUG1) << "frames caught:" << sls::ToString(retval);
auto size = static_cast<int>(retval.size());
socket.Send(OK);
socket.Send(size);
socket.Send(retval);
return OK;
}
int ClientInterface::set_file_write(Interface &socket) {

View File

@ -52,19 +52,7 @@ DataProcessor::~DataProcessor() { DeleteFiles(); }
/** getters */
bool DataProcessor::GetStartedFlag() { return startedFlag_; }
uint64_t DataProcessor::GetNumFramesCaught() { return numFramesCaught_; }
uint64_t DataProcessor::GetNumCompleteFramesCaught() {
return numCompleteFramesCaught_;
}
uint64_t DataProcessor::GetCurrentFrameIndex() { return currentFrameIndex_; }
uint64_t DataProcessor::GetProcessedIndex() {
return currentFrameIndex_ - firstIndex_;
}
bool DataProcessor::GetStartedFlag() const { return startedFlag_; }
void DataProcessor::SetFifo(Fifo *fifo) { fifo_ = fifo; }
@ -72,7 +60,6 @@ void DataProcessor::ResetParametersforNewAcquisition() {
StopRunning();
startedFlag_ = false;
numFramesCaught_ = 0;
numCompleteFramesCaught_ = 0;
firstIndex_ = 0;
currentFrameIndex_ = 0;
firstStreamerFrame_ = true;
@ -213,12 +200,14 @@ void DataProcessor::CreateVirtualFile(
if (virtualFile_) {
delete virtualFile_;
}
virtualFile_ = new HDF5VirtualFile(hdf5Lib);
bool gotthard25um =
((detectorType_ == GOTTHARD || detectorType_ == GOTTHARD2) &&
(numModX * numModY) == 2);
virtualFile_ = new HDF5VirtualFile(hdf5Lib, gotthard25um);
uint64_t numImagesProcessed = GetProcessedIndex() + 1;
// maxframesperfile = 0 for infinite files
uint32_t framesPerFile =
((maxFramesPerFile == 0) ? numImagesProcessed + 1 : maxFramesPerFile);
((maxFramesPerFile == 0) ? numFramesCaught_ : maxFramesPerFile);
// TODO: assumption 1: create virtual file even if no data in other
// files (they exist anyway) assumption2: virtual file max frame index
@ -228,7 +217,7 @@ void DataProcessor::CreateVirtualFile(
filePath, fileNamePrefix, fileIndex, overWriteEnable, silentMode,
modulePos, numUnitsPerReadout, framesPerFile, numImages,
generalData_->nPixelsX, generalData_->nPixelsY, dynamicRange,
numImagesProcessed, numModX, numModY, dataFile_->GetPDataType(),
numFramesCaught_, numModX, numModY, dataFile_->GetPDataType(),
dataFile_->GetParameterNames(), dataFile_->GetParameterDataTypes());
}
@ -344,9 +333,6 @@ uint64_t DataProcessor::ProcessAnImage(char *buf) {
currentFrameIndex_ = fnum;
numFramesCaught_++;
uint32_t nump = header.packetNumber;
if (nump == generalData_->packetsPerFrame) {
numCompleteFramesCaught_++;
}
LOG(logDEBUG1) << "DataProcessing " << index << ": fnum:" << fnum;

View File

@ -36,13 +36,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
~DataProcessor() override;
bool GetStartedFlag();
uint64_t GetNumFramesCaught();
uint64_t GetNumCompleteFramesCaught();
/** (-1 if no frames have been caught */
uint64_t GetCurrentFrameIndex();
/** (-1 if no frames have been caught) */
uint64_t GetProcessedIndex();
bool GetStartedFlag() const;
void SetFifo(Fifo *f);
void ResetParametersforNewAcquisition();
@ -178,9 +172,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
/** Number of frames caught */
uint64_t numFramesCaught_{0};
/** Number of complete frames caught */
uint64_t numCompleteFramesCaught_{0};
/** Frame Number of latest processed frame number */
std::atomic<uint64_t> currentFrameIndex_{0};

View File

@ -5,8 +5,8 @@
#include <iomanip>
HDF5VirtualFile::HDF5VirtualFile(std::mutex *hdf5Lib)
: File(HDF5), hdf5Lib_(hdf5Lib) {}
HDF5VirtualFile::HDF5VirtualFile(std::mutex *hdf5Lib, bool g25)
: File(HDF5), hdf5Lib_(hdf5Lib), gotthard25um(g25) {}
HDF5VirtualFile::~HDF5VirtualFile() { CloseFile(); }
@ -73,12 +73,10 @@ void HDF5VirtualFile::CreateVirtualFile(
"version", PredType::NATIVE_DOUBLE, dataspace_attr);
attribute.write(PredType::NATIVE_DOUBLE, &dValue);
// virtual data dataspace
// virtual dataspace
hsize_t vdsDims[3] = {numImagesCaught, numModY * nDimy,
numModZ * nDimz};
DataSpace vdsDataSpace(3, vdsDims, nullptr);
// virtual parameter dataspace
hsize_t vdsDimsPara[2] = {numImagesCaught,
(unsigned int)numModY * numModZ};
DataSpace vdsDataSpacePara(2, vdsDimsPara, nullptr);
@ -91,37 +89,54 @@ void HDF5VirtualFile::CreateVirtualFile(
// property list for parameters (datatype)
std::vector<DSetCreatPropList> plistPara(paraSize);
// hyperslab
int numMajorHyperslab = numImagesCaught / maxFramesPerFile;
// hyperslab (files)
int numFiles = numImagesCaught / maxFramesPerFile;
if (numImagesCaught % maxFramesPerFile)
++numMajorHyperslab;
++numFiles;
uint64_t framesSaved = 0;
// loop through files
for (int hyperSlab = 0; hyperSlab < numMajorHyperslab; ++hyperSlab) {
for (int iFile = 0; iFile < numFiles; ++iFile) {
uint64_t nDimx =
((numImagesCaught - framesSaved) > maxFramesPerFile)
? maxFramesPerFile
: (numImagesCaught - framesSaved);
hsize_t start[3] = {framesSaved, 0, 0};
hsize_t count[3] = {nDimx, nDimy, nDimz};
hsize_t startPara[2] = {framesSaved, 0};
hsize_t countPara[2] = {nDimx, 1};
// loop through readouts
for (unsigned int i = 0; i < numModY * numModZ; ++i) {
// setect data hyperslabs
vdsDataSpace.selectHyperslab(H5S_SELECT_SET, count, start);
hsize_t startLocation[3] = {framesSaved, 0, 0};
hsize_t strideBetweenBlocks[3] = {1, 1, 1};
hsize_t numBlocks[3] = {nDimx, nDimy, nDimz};
hsize_t blockSize[3] = {1, 1, 1};
// select parameter hyperslabs
vdsDataSpacePara.selectHyperslab(H5S_SELECT_SET, countPara,
startPara);
hsize_t startLocationPara[2] = {framesSaved, 0};
hsize_t strideBetweenBlocksPara[3] = {1, 1};
hsize_t numBlocksPara[2] = {1, 1};
hsize_t blockSizePara[3] = {nDimx, 1};
// interleaving for g2
if (gotthard25um) {
strideBetweenBlocks[2] = 2;
}
for (unsigned int iReadout = 0; iReadout < numModY * numModZ;
++iReadout) {
// interleaving for g2 (startLocation is 0 and 1)
if (gotthard25um) {
startLocation[2] = iReadout;
}
vdsDataSpace.selectHyperslab(H5S_SELECT_SET, numBlocks,
startLocation, strideBetweenBlocks,
blockSize);
vdsDataSpacePara.selectHyperslab(
H5S_SELECT_SET, numBlocksPara, startLocationPara,
strideBetweenBlocksPara, blockSizePara);
// source file name
std::ostringstream os;
os << filePath << "/" << fileNamePrefix << "_d"
<< (modulePos * numUnitsPerReadout + i) << "_f" << hyperSlab
<< '_' << fileIndex << ".h5";
<< (modulePos * numUnitsPerReadout + iReadout) << "_f"
<< iFile << '_' << fileIndex << ".h5";
std::string srcFileName = os.str();
LOG(logDEBUG1) << srcFileName;
@ -138,25 +153,20 @@ void HDF5VirtualFile::CreateVirtualFile(
std::ostringstream osfn;
osfn << "/data";
if (numImages > 1)
osfn << "_f" << std::setfill('0') << std::setw(12)
<< hyperSlab;
osfn << "_f" << std::setfill('0') << std::setw(12) << iFile;
std::string srcDatasetName = osfn.str();
// source data dataspace
// source dataspace
hsize_t srcDims[3] = {nDimx, nDimy, nDimz};
hsize_t srcDimsMax[3] = {H5S_UNLIMITED, nDimy, nDimz};
DataSpace srcDataSpace(3, srcDims, srcDimsMax);
// source parameter dataspace
hsize_t srcDimsPara[1] = {nDimx};
hsize_t srcDimsMaxPara[1] = {H5S_UNLIMITED};
DataSpace srcDataSpacePara(1, srcDimsPara, srcDimsMaxPara);
// mapping of data property list
// mapping of property list
plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(),
srcDatasetName.c_str(), srcDataSpace);
// mapping of parameter property list
for (unsigned int p = 0; p < paraSize; ++p) {
plistPara[p].setVirtual(
vdsDataSpacePara, relative_srcFileName.c_str(),
@ -165,21 +175,23 @@ void HDF5VirtualFile::CreateVirtualFile(
// H5Sclose(srcDataspace);
// H5Sclose(srcDataspace_para);
start[2] += nDimz;
if (start[2] >= (numModZ * nDimz)) {
start[2] = 0;
start[1] += nDimy;
if (!gotthard25um) {
startLocation[2] += nDimz;
if (startLocation[2] >= (numModZ * nDimz)) {
startLocation[2] = 0;
startLocation[1] += nDimy;
}
startPara[1]++;
}
startLocationPara[1]++;
}
framesSaved += nDimx;
}
// data dataset
// datasets
dataSetName_ = "data";
DataSet vdsDataSet(fd_->createDataSet(dataSetName_.c_str(), dataType,
vdsDataSpace, plist));
// parameter dataset
for (unsigned int p = 0; p < paraSize; ++p) {
DataSet vdsDataSetPara(fd_->createDataSet(
parameterNames[p].c_str(), parameterDataTypes[p],

View File

@ -9,7 +9,7 @@
class HDF5VirtualFile : private virtual slsDetectorDefs, public File {
public:
HDF5VirtualFile(std::mutex *hdf5Lib);
HDF5VirtualFile(std::mutex *hdf5Lib, bool g25);
~HDF5VirtualFile();
std::array<std::string, 2> GetFileAndDatasetName() const override;
@ -30,4 +30,5 @@ class HDF5VirtualFile : private virtual slsDetectorDefs, public File {
H5File *fd_{nullptr};
std::string fileName_;
std::string dataSetName_;
bool gotthard25um;
};

View File

@ -453,51 +453,51 @@ void Implementation::setFramesPerFile(const uint32_t i) {
* ************************************************/
slsDetectorDefs::runStatus Implementation::getStatus() const { return status; }
uint64_t Implementation::getFramesCaught() const {
uint64_t min = -1;
uint32_t flagsum = 0;
for (const auto &it : dataProcessor) {
flagsum += it->GetStartedFlag();
min = std::min(min, it->GetNumCompleteFramesCaught());
std::vector<int64_t> Implementation::getFramesCaught() const {
std::vector<int64_t> numFramesCaught(numUDPInterfaces);
int index = 0;
for (const auto &it : listener) {
if (it->GetStartedFlag()) {
numFramesCaught[index] = it->GetNumCompleteFramesCaught();
}
// no data processed
if (flagsum != dataProcessor.size())
return 0;
return min;
++index;
}
return numFramesCaught;
}
uint64_t Implementation::getCurrentFrameIndex() const {
uint64_t max = 0;
uint32_t flagsum = 0;
std::vector<int64_t> Implementation::getCurrentFrameIndex() const {
std::vector<int64_t> frameIndex(numUDPInterfaces);
int index = 0;
for (const auto &it : listener) {
flagsum += it->GetStartedFlag();
max = std::max(max, it->GetCurrentFrameIndex());
if (it->GetStartedFlag()) {
frameIndex[index] = it->GetCurrentFrameIndex();
}
// no data processed
if (flagsum != listener.size())
return 0;
return max;
++index;
}
return frameIndex;
}
double Implementation::getProgress() const {
// get minimum of processed frame indices
uint64_t currentFrameIndex = 0;
uint32_t flagsum = 0;
if (!activated || (!detectorDataStream[0] && !detectorDataStream[1])) {
return 100.00;
}
// if disabled, considering only 1 port
double totalFrames = (double)(numberOfTotalFrames * listener.size());
if (!detectorDataStream[0] || !detectorDataStream[1]) {
totalFrames /= 2;
}
double progress = 0;
int index = 0;
for (const auto &it : listener) {
flagsum += it->GetStartedFlag();
currentFrameIndex = std::max(currentFrameIndex, it->GetListenedIndex());
if (detectorDataStream[index] && it->GetStartedFlag()) {
progress += (it->GetListenedIndex() + 1) / totalFrames;
}
// no data processed
if (flagsum != listener.size()) {
currentFrameIndex = -1;
++index;
}
return (100.00 *
((double)(currentFrameIndex + 1) / (double)numberOfTotalFrames));
progress *= 100;
return progress;
}
std::vector<int64_t> Implementation::getNumMissingPackets() const {
@ -627,7 +627,7 @@ void Implementation::stopReceiver() {
// print summary
uint64_t tot = 0;
for (int i = 0; i < numUDPInterfaces; i++) {
int nf = dataProcessor[i]->GetNumCompleteFramesCaught();
int nf = listener[i]->GetNumCompleteFramesCaught();
tot += nf;
std::string mpMessage = std::to_string(mp[i]);
if (mp[i] < 0) {

View File

@ -84,8 +84,8 @@ class Implementation : private virtual slsDetectorDefs {
* *
* ************************************************/
runStatus getStatus() const;
uint64_t getFramesCaught() const;
uint64_t getCurrentFrameIndex() const;
std::vector<int64_t> getFramesCaught() const;
std::vector<int64_t> getCurrentFrameIndex() const;
double getProgress() const;
std::vector<int64_t> getNumMissingPackets() const;
void setScan(slsDetectorDefs::scanParameters s);

View File

@ -36,12 +36,22 @@ Listener::~Listener() = default;
uint64_t Listener::GetPacketsCaught() const { return numPacketsCaught; }
uint64_t Listener::GetNumCompleteFramesCaught() const {
return numCompleteFramesCaught;
}
uint64_t Listener::GetLastFrameIndexCaught() const {
return lastCaughtFrameIndex;
}
int64_t Listener::GetNumMissingPacket(bool stoppedFlag,
uint64_t numPackets) const {
if (!activated) {
return 0;
}
if (!(*detectorDataStream)) {
return 0;
}
if (!stoppedFlag) {
return (numPackets - numPacketsCaught);
}
@ -53,11 +63,11 @@ int64_t Listener::GetNumMissingPacket(bool stoppedFlag,
numPacketsCaught;
}
bool Listener::GetStartedFlag() { return startedFlag; }
bool Listener::GetStartedFlag() const { return startedFlag; }
uint64_t Listener::GetCurrentFrameIndex() { return lastCaughtFrameIndex; }
uint64_t Listener::GetCurrentFrameIndex() const { return lastCaughtFrameIndex; }
uint64_t Listener::GetListenedIndex() {
uint64_t Listener::GetListenedIndex() const {
return lastCaughtFrameIndex - firstIndex;
}
@ -67,6 +77,7 @@ void Listener::ResetParametersforNewAcquisition() {
StopRunning();
startedFlag = false;
numPacketsCaught = 0;
numCompleteFramesCaught = 0;
firstIndex = 0;
currentFrameIndex = 0;
lastCaughtFrameIndex = 0;
@ -607,6 +618,9 @@ uint32_t Listener::ListenToAnImage(char *buf) {
// complete image
new_header->detHeader.packetNumber = numpackets; // number of packets caught
new_header->detHeader.frameNumber = currentFrameIndex;
if (numpackets == pperFrame) {
++numCompleteFramesCaught;
}
++currentFrameIndex;
return imageSize;
}

View File

@ -51,53 +51,19 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
*/
~Listener();
/**
* Get Packets caught
* @return Packets caught
*/
uint64_t GetPacketsCaught() const;
/**
* Get Last Frame index caught
* @return last frame index caught
*/
uint64_t GetNumCompleteFramesCaught() const;
uint64_t GetLastFrameIndexCaught() const;
/** Get number of missing packets, returns negative values in case to extra
* packet */
/** negative values in case of extra packets */
int64_t GetNumMissingPacket(bool stoppedFlag, uint64_t numPackets) const;
bool GetStartedFlag() const;
uint64_t GetCurrentFrameIndex() const;
uint64_t GetListenedIndex() const;
bool GetStartedFlag();
uint64_t GetCurrentFrameIndex();
/** (-1 if no frames have been caught) */
uint64_t GetListenedIndex();
/**
* Set Fifo pointer to the one given
* @param f address of Fifo pointer
*/
void SetFifo(Fifo *f);
/**
* Reset parameters for new acquisition
*/
void ResetParametersforNewAcquisition();
/**
* Set GeneralData pointer to the one given
* @param g address of GeneralData (Detector Data) pointer
*/
void SetGeneralData(GeneralData *g);
/**
* Creates UDP Sockets
*/
void CreateUDPSockets();
/**
* Shuts down and deletes UDP Sockets
*/
void ShutDownUDPSocket();
/**
@ -116,10 +82,6 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
void SetHardCodedPosition(uint16_t r, uint16_t c);
private:
/**
* Record First Acquisition Index
* @param fnum frame index to record
*/
void RecordFirstIndex(uint64_t fnum);
/**
@ -146,55 +108,25 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
*/
uint32_t ListenToAnImage(char *buf);
/**
* Print Fifo Statistics
*/
void PrintFifoStatistics();
/** type of thread */
static const std::string TypeName;
/** GeneralData (Detector Data) object */
GeneralData *generalData{nullptr};
/** Fifo structure */
Fifo *fifo;
// individual members
/** Detector Type */
detectorType myDetectorType;
/** Receiver Status */
std::atomic<runStatus> *status;
/** UDP Socket - Detector to Receiver */
std::unique_ptr<sls::UdpRxSocket> udpSocket{nullptr};
/** UDP Port Number */
uint32_t *udpPortNumber;
/** ethernet interface */
std::string *eth;
/** UDP Socket Buffer Size */
int *udpSocketBufferSize;
/** actual UDP Socket Buffer Size (double due to kernel bookkeeping) */
/** double due to kernel bookkeeping */
int *actualUDPSocketBufferSize;
/** frames per file */
uint32_t *framesPerFile;
/** frame discard policy */
frameDiscardPolicy *frameDiscardMode;
/** Activated/Deactivated */
bool *activated;
/** detector data stream */
bool *detectorDataStream;
/** Silent Mode */
bool *silentMode;
/** row hardcoded as 1D or 2d,
@ -209,15 +141,12 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
// acquisition start
/** Aquisition Started flag */
std::atomic<bool> startedFlag{false};
/** Frame Number of First Frame */
uint64_t firstIndex{0};
// for acquisition summary
/** Number of complete Packets caught */
std::atomic<uint64_t> numPacketsCaught{0};
/** Last Frame Index caught from udp network */
std::atomic<uint64_t> numCompleteFramesCaught{0};
std::atomic<uint64_t> lastCaughtFrameIndex{0};
// parameters to acquire image
@ -225,25 +154,16 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
* ( always check startedFlag for validity first)
*/
uint64_t currentFrameIndex{0};
/** True if there is a packet carry over from previous Image */
bool carryOverFlag{false};
/** Carry over packet buffer */
std::unique_ptr<char[]> carryOverPacket;
/** Listening buffer for one packet - might be removed when we can peek and
* eiger fnum is in header */
std::unique_ptr<char[]> listeningPacket;
/** if the udp socket is connected */
std::atomic<bool> udpSocketAlive{false};
// for print progress during acquisition
/** number of packets for statistic */
// for print progress during acquisition*/
uint32_t numPacketsStatistic{0};
/** number of images for statistic */
uint32_t numFramesStatistic{0};
/**

View File

@ -34,8 +34,8 @@ TEST_CASE("Push pop") {
for (size_t i = 0; i != vec.size(); ++i) {
fifo.push(p);
++p;
CHECK(fifo.getDataValue() == i + 1);
CHECK(fifo.getFreeValue() == 4 - i);
CHECK(fifo.getDataValue() == (int)(i + 1));
CHECK(fifo.getFreeValue() == (int)(4 - i));
}
CHECK(fifo.isEmpty() == false);
@ -44,8 +44,8 @@ TEST_CASE("Push pop") {
for (size_t i = 0; i != vec.size(); ++i) {
fifo.pop(p);
CHECK(*p == vec[i]);
CHECK(fifo.getDataValue() == 4 - i);
CHECK(fifo.getFreeValue() == i + 1);
CHECK(fifo.getDataValue() == (int)(4 - i));
CHECK(fifo.getFreeValue() == (int)(i + 1));
}
CHECK(fifo.isEmpty() == true);

View File

@ -6,10 +6,10 @@
#define APIRECEIVER 0x211124
#define APIGUI 0x211124
#define APICTB 0x220902
#define APIGOTTHARD 0x220902
#define APIGOTTHARD2 0x220902
#define APIJUNGFRAU 0x220902
#define APIMYTHEN3 0x220902
#define APIMOENCH 0x220902
#define APIEIGER 0x220902
#define APIEIGER 0x220324
#define APICTB 0x220328
#define APIGOTTHARD 0x220328
#define APIGOTTHARD2 0x220328
#define APIJUNGFRAU 0x220328
#define APIMYTHEN3 0x220328
#define APIMOENCH 0x220328