more const more python

This commit is contained in:
Erik Frojdh 2019-03-18 17:38:44 +01:00
parent 98655ee7e3
commit 43012e4f28
9 changed files with 65 additions and 297 deletions

View File

@ -63,7 +63,6 @@ class Detector:
@property
@error_handling
def busy(self):
"""
Checks the detector is acquiring. Can also be set but should only be used if the acquire fails and
@ -94,7 +93,6 @@ class Detector:
return self._api.getAcquiringFlag()
@busy.setter
@error_handling
def busy(self, value):
self._api.setAcquiringFlag(value)
@ -103,7 +101,6 @@ class Detector:
self._api.clearErrorMask()
@property
@error_handling
def client_version(self):
"""
:py:obj:`str` The date of commit for the client API version
@ -121,8 +118,7 @@ class Detector:
return v[2:]
@property
@error_handling
def detector_number(self):
def detectornumber(self):
"""
Get all detector numbers as a list. For Eiger the detector numbers
correspond to the beb numbers.
@ -137,7 +133,7 @@ class Detector:
>> [83, 98]
"""
return [self._api.getDetectorNumber(i) for i in range(self.n_modules)]
return self._api.getDetectorNumber()
@property
def detector_type(self):
@ -163,7 +159,6 @@ class Detector:
return element_if_equal(self._api.getDetectorType())
@property
@error_handling
def dynamic_range(self):
"""
:obj:`int`: Dynamic range of the detector.
@ -190,7 +185,6 @@ class Detector:
return self._api.getDynamicRange()
@dynamic_range.setter
@error_handling
def dynamic_range(self, dr):
if dr in self._detector_dynamic_range:
self._api.setDynamicRange(dr)
@ -199,18 +193,8 @@ class Detector:
raise DetectorValueError('Cannot set dynamic range to: {:d} availble options: '.format(dr),
self._detector_dynamic_range)
@property
def error_mask(self):
"""Read the error mask from the slsDetectorSoftware"""
return self._api.getErrorMask()
@property
def error_message(self):
"""Read the error message from the slsDetectorSoftware"""
return self._api.getErrorMessage()
@property
@error_handling
def exposure_time(self):
"""
:obj:`double` Exposure time in [s] of a single frame.
@ -218,7 +202,6 @@ class Detector:
return self._api.getExposureTime() / 1e9
@exposure_time.setter
@error_handling
def exposure_time(self, t):
ns_time = int(t * 1e9)
if ns_time <= 0:
@ -226,7 +209,6 @@ class Detector:
self._api.setExposureTime(ns_time)
@property
@error_handling
def file_index(self):
"""
:obj:`int` Index for frames and file names
@ -252,14 +234,12 @@ class Detector:
return self._api.getFileIndex()
@file_index.setter
@error_handling
def file_index(self, i):
if i < 0:
raise ValueError('Index needs to be positive')
self._api.setFileIndex(i)
@property
@error_handling
def file_name(self):
"""
:obj:`str`: Base file name for writing images
@ -285,12 +265,10 @@ class Detector:
return self._api.getFileName()
@file_name.setter
@error_handling
def file_name(self, fname):
self._api.setFileName(fname)
@property
@error_handling
def file_path(self):
"""
:obj:`str`: Path where images are written
@ -318,7 +296,6 @@ class Detector:
return fp
@file_path.setter
@error_handling
def file_path(self, path):
if os.path.exists(path) is True:
self._api.setFilePath(path)
@ -326,7 +303,6 @@ class Detector:
raise FileNotFoundError('File path does not exists')
@property
@error_handling
def file_write(self):
"""
:obj:`bool` If True write files to disk
@ -334,13 +310,11 @@ class Detector:
return self._api.getFileWrite()
@file_write.setter
@error_handling
def file_write(self, fwrite):
self._api.setFileWrite(fwrite)
@property
@error_handling
def file_overwrite(self):
"""
:obj:`bool` If true overwrite files on disk
@ -348,12 +322,10 @@ class Detector:
return self._api.getFileOverWrite()
@file_overwrite.setter
@error_handling
def file_overwrite(self, value):
self._api.setFileOverWrite(value)
@property
@error_handling
def file_padding(self):
"""
Pad files in the receiver
@ -362,12 +334,10 @@ class Detector:
return self._api.getReceiverPartialFramesPadding()
@file_padding.setter
@error_handling
def file_padding(self, value):
self._api.getReceiverPartialFramesPadding(value)
@property
@error_handling
def firmware_version(self):
"""
:py:obj:`int` Firmware version of the detector
@ -422,7 +392,6 @@ class Detector:
@property
@error_handling
def frame_discard_policy(self):
"""
Decides what the receiver does when packet loss occurs.
@ -433,7 +402,6 @@ class Detector:
return self._api.getReceiverFrameDiscardPolicy()
@frame_discard_policy.setter
@error_handling
def frame_discard_policy(self, policy):
self._api.setReceiverFramesDiscardPolicy(policy)
@ -476,7 +444,6 @@ class Detector:
return self._flippeddatax
@property
@error_handling
def high_voltage(self):
"""
High voltage applied to the sensor
@ -484,7 +451,6 @@ class Detector:
return self._api.getDac('vhighvoltage', -1)
@high_voltage.setter
@error_handling
def high_voltage(self, voltage):
voltage = int(voltage)
if voltage < 0 or voltage > 200:
@ -493,7 +459,6 @@ class Detector:
@property
@error_handling
def hostname(self):
"""
:obj:`list` of :obj:`str`: hostnames of all connected detectors
@ -514,7 +479,6 @@ class Detector:
@hostname.setter
@error_handling
def hostname(self, hn):
if isinstance(hn, str):
self._api.setHostname(hn)
@ -553,11 +517,10 @@ class Detector:
return size(*self._api.getImageSize())
@image_size.setter
@error_handling
def image_size(self, size):
self._api.setImageSize(*size)
@error_handling
def load_config(self, fname):
"""
Load detector configuration from a configuration file
@ -573,7 +536,7 @@ class Detector:
else:
raise FileNotFoundError('Cannot find configuration file')
@error_handling
def load_parameters(self, fname):
"""
Setup detector by executing commands in a parameters file
@ -596,7 +559,7 @@ class Detector:
else:
raise FileNotFoundError('Cannot find parameters file')
@error_handling
def load_trimbits(self, fname, idet=-1):
"""
Load trimbit file or files. Either called with detector number or -1
@ -628,7 +591,6 @@ class Detector:
@property
@error_handling
def lock(self):
"""Lock the detector to this client
@ -644,7 +606,6 @@ class Detector:
self._api.setServerLock(value)
@property
@error_handling
def lock_receiver(self):
"""Lock the receivers to this client
@ -661,7 +622,6 @@ class Detector:
self._api.setReceiverLock(value)
@property
@error_handling
def module_geometry(self):
"""
:obj:`namedtuple` Geometry(horizontal=nx, vertical=ny)
@ -687,7 +647,6 @@ class Detector:
return Geometry(horizontal=_t[0], vertical=_t[1])
@property
@error_handling
def n_frames(self):
"""
:obj:`int` Number of frames per acquisition
@ -695,7 +654,6 @@ class Detector:
return self._api.getNumberOfFrames()
@n_frames.setter
@error_handling
def n_frames(self, n):
if n >= 1:
self._api.setNumberOfFrames(n)
@ -704,23 +662,19 @@ class Detector:
' frames should be an integer greater than 0'.format(n))
@property
@error_handling
def frames_per_file(self):
return self._api.getReceiverFramesPerFile()
@frames_per_file.setter
@error_handling
def frames_per_file(self, n):
self._api.setReceiverFramesPerFile(n)
@property
@error_handling
def n_cycles(self):
"""Number of cycles for the measurement (exp*n_frames)*n_cycles"""
return self._api.getCycles()
@n_cycles.setter
@error_handling
def n_cycles(self, n_cycles):
if n_cycles > 0:
self._api.setCycles(n_cycles)
@ -728,7 +682,6 @@ class Detector:
raise DetectorValueError('Number of cycles must be positive')
@property
@error_handling
def n_measurements(self):
"""
Number of times to repeat the programmed measurement.
@ -756,7 +709,6 @@ class Detector:
return self._api.getNumberOfMeasurements()
@n_measurements.setter
@error_handling
def n_measurements(self, value):
if value > 0:
self._api.setNumberOfMeasurements(value)
@ -764,7 +716,6 @@ class Detector:
raise DetectorValueError('Number of measurements must be positive')
@property
@error_handling
def n_modules(self):
"""
:obj:`int` Number of (half)modules in the detector
@ -781,7 +732,6 @@ class Detector:
return self._api.getNumberOfDetectors()
@property
@error_handling
def online(self):
"""Online flag for the detector
@ -799,13 +749,11 @@ class Detector:
return self._api.getOnline()
@online.setter
@error_handling
def online(self, value):
self._api.setOnline(value)
@property
@error_handling
def last_client_ip(self):
"""Returns the ip address of the last client
that accessed the detector
@ -832,7 +780,6 @@ class Detector:
return self._api.getReceiverLastClientIP()
@property
@error_handling
def receiver_online(self):
"""
Online flag for the receiver. Is set together with detector.online when creating the detector object
@ -851,12 +798,10 @@ class Detector:
return self._api.getReceiverOnline()
@receiver_online.setter
@error_handling
def receiver_online(self, value):
self._api.setReceiverOnline(value)
@property
@error_handling
def receiver_version(self):
"""
:py:obj:`str` Receiver version as a string. [yearmonthday]
@ -901,7 +846,6 @@ class Detector:
self._api.resetFramesCaught()
@property
@error_handling
def period(self):
"""
:obj:`double` Period between start of frames. Set to 0 for the detector
@ -911,7 +855,6 @@ class Detector:
return _t / 1e9
@period.setter
@error_handling
def period(self, t):
ns_time = int(t * 1e9)
if ns_time < 0:
@ -919,7 +862,6 @@ class Detector:
self._api.setPeriod(ns_time)
@property
@error_handling
def rate_correction(self):
"""
:obj:`list` of :obj:`double` Rate correction for all modules.
@ -950,7 +892,6 @@ class Detector:
return self._api.getRateCorrection()
@rate_correction.setter
@error_handling
def rate_correction(self, tau_list):
if len(tau_list) != self.n_modules:
raise ValueError('List of tau needs the same length')
@ -958,7 +899,6 @@ class Detector:
@property
@error_handling
def readout_clock(self):
"""
Speed of the readout clock relative to the full speed
@ -984,7 +924,6 @@ class Detector:
return self._speed_names[speed]
@readout_clock.setter
@error_handling
def readout_clock(self, value):
speed = self._speed_int[value]
self._api.setReadoutClockSpeed(speed)
@ -994,7 +933,6 @@ class Detector:
return self._api.getReceiverCurrentFrameIndex()
@property
@error_handling
def rx_datastream(self):
"""
Zmq datastream from receiver. :py:obj:`True` if enabled and :py:obj:`False`
@ -1018,7 +956,6 @@ class Detector:
@property
@error_handling
def rx_hostname(self):
"""
Receiver hostname
@ -1028,13 +965,11 @@ class Detector:
@rx_hostname.setter
@error_handling
def rx_hostname(self, name):
self._api.setReceiverHostname(name)
@property
@error_handling
def rx_udpip(self):
"""
Receiver UDP ip
@ -1064,12 +999,10 @@ class Detector:
self._api.setReceiverUDPMAC(mac, -1)
@property
@error_handling
def rx_tcpport(self):
return self._api.getReceiverPort()
@rx_tcpport.setter
@error_handling
def rx_tcpport(self, ports):
if len(ports) != len(self):
raise ValueError('Number of ports: {} not equal to number of '
@ -1079,7 +1012,6 @@ class Detector:
self._api.setReceiverPort(i, p)
@property
@error_handling
def rx_zmqip(self):
"""
ip where the receiver streams data
@ -1093,8 +1025,7 @@ class Detector:
@property
@error_handling
def detector_mac(self):
def detectormac(self):
"""
Read detector mac address
"""
@ -1102,16 +1033,18 @@ class Detector:
return element_if_equal(mac)
@property
@error_handling
def detector_ip(self):
def detectorip(self):
"""
Read detector ip address
"""
ip = self._api.getNetworkParameter('detectorip')
return element_if_equal(ip)
return self._api.getDetectorIp(-1)
# @detectorip.setter
# def detectorip(self, ip):
@property
@error_handling
def client_zmqip(self):
"""
Ip address where the client listens to zmq stream
@ -1120,14 +1053,13 @@ class Detector:
return element_if_equal(ip)
@client_zmqip.setter
@error_handling
def client_zmqip(self, ip):
self._api.setNetworkParameter('client_zmqip', ip, -1)
@property
@error_handling
def rx_fifodepth(self):
"""
Fifo depth of receiver in number of frames
@ -1135,13 +1067,11 @@ class Detector:
return self._api.getReceiverFifoDepth()
@rx_fifodepth.setter
@error_handling
def rx_fifodepth(self, n_frames):
self._api.setReceiverFifoDepth(n_frames)
@property
@error_handling
def rx_udpsocksize(self):
"""
UDP buffer size
@ -1150,7 +1080,6 @@ class Detector:
return element_if_equal(buffer_size)
@property
@error_handling
def rx_jsonaddheader(self):
"""
UDP buffer size
@ -1159,20 +1088,17 @@ class Detector:
return element_if_equal(header)
@rx_jsonaddheader.setter
@error_handling
def rx_jsonaddheader(self, header):
self._api.setNetworkParameter('rx_jsonaddheader', header, -1)
@rx_udpsocksize.setter
@error_handling
def rx_udpsocksize(self, buffer_size):
self._api.setNetworkParameter('rx_udpsocksize', str(buffer_size), -1)
@property
@error_handling
def rx_realudpsocksize(self):
"""
UDP buffer size
@ -1182,7 +1108,6 @@ class Detector:
@property
@error_handling
def rx_zmqport(self):
"""
Return the receiver zmq ports.
@ -1200,7 +1125,6 @@ class Detector:
return [int(_p) for _p in _s]
@rx_zmqport.setter
@error_handling
def rx_zmqport(self, port):
if isinstance(port, Iterable):
for i, p in enumerate(port):
@ -1219,7 +1143,6 @@ class Detector:
return self._api.getUserDetails()
@property
@error_handling
def server_version(self):
"""
:py:obj:`int` On-board server version of the detector
@ -1227,7 +1150,6 @@ class Detector:
return hex(self._api.getServerVersion())
@property
@error_handling
def settings(self):
"""
Detector settings used to control for example calibration or gain
@ -1243,7 +1165,6 @@ class Detector:
return self._api.getSettings()
@settings.setter
@error_handling
def settings(self, s):
if s in self._settings:
self._api.setSettings(s)
@ -1253,7 +1174,6 @@ class Detector:
@property
@error_handling
def settings_path(self):
"""
The path where the slsDetectorSoftware looks for settings/trimbit files
@ -1261,7 +1181,6 @@ class Detector:
return self._api.getSettingsDir()
@settings_path.setter
@error_handling
def settings_path(self, path):
if os.path.isdir(path):
self._api.setSettingsDir(path)
@ -1269,7 +1188,6 @@ class Detector:
raise FileNotFoundError('Settings path does not exist')
@property
@error_handling
def status(self):
"""
:py:obj:`str` Status of the detector: idle, running,
@ -1324,7 +1242,6 @@ class Detector:
self._api.setThreadedProcessing(value)
@property
@error_handling
def threshold(self):
"""
Detector threshold in eV
@ -1332,7 +1249,6 @@ class Detector:
return self._api.getThresholdEnergy()
@threshold.setter
@error_handling
def threshold(self, eV):
self._api.setThresholdEnergy(eV)
@ -1426,7 +1342,7 @@ class Detector:
return []
return [int(_p)+i for _p in _s for i in range(2)]
@error_handling
def _provoke_error(self):
self._api.setErrorMask(1)
@ -1438,6 +1354,7 @@ class Detector:
"""
self._api.configureNetworkParameters()
def free_shared_memory(multi_id=0):
"""
Function to free the shared memory but do not initialize with new

View File

@ -4,6 +4,7 @@ import numpy as np
class DetectorProperty:
"""
Base class for a detector property that should be accessed by name and index
TODO! Calls are not in parallel and exposes object that can be passes around
"""
def __init__(self, get_func, set_func, nmod_func, name):
self.get = get_func

View File

@ -5,7 +5,12 @@ class ExperimentalDetector(multiDetectorApi):
def __init__(self):
super().__init__(0)
# @rx_udpip.setter
# def rx_udpip(self, ip):
# self._setReceiverUDPIP(ip, -1)
@property
def rx_udpip(self):
return self._getReceiverUDPIP(-1)
@rx_udpip.setter
def rx_udpip(self, ip):
self._setReceiverUDPIP(ip, -1)

View File

@ -130,23 +130,6 @@ class Detector {
return det.checkOnline();
}
void clearErrorMask() {
det.clearAllErrorMask();
}
int64_t getErrorMask() {
return det.getErrorMask();
}
void setErrorMask(const int64_t i) {
det.setErrorMask(i);
}
std::string getErrorMessage() {
//tmp would hold the number of critical errors, is and should this be used?
int tmp = 0;
return det.getErrorMessage(tmp);
}
bool getReceiverOnline() {
return det.setReceiverOnline();
}
@ -253,8 +236,8 @@ class Detector {
int64_t getClientVersion() { return det.getId(slsDetectorDefs::THIS_SOFTWARE_VERSION); }
int64_t getReceiverVersion() { return det.getId(slsDetectorDefs::RECEIVER_VERSION); }
int getDetectorNumber(int i) {
return det.getId(slsDetectorDefs::DETECTOR_SERIAL_NUMBER, i);
std::vector<int64_t> getDetectorNumber() {
return det.getDetectorNumber();
}
int getReadoutClockSpeed() {

View File

@ -239,12 +239,6 @@ PYBIND11_MODULE(_sls_detector, m)
.def("getReceiverCurrentFrameIndex", &Detector::getReceiverCurrentFrameIndex)
.def("getGapPixels", &Detector::getGapPixels)
.def("setGapPixels", &Detector::setGapPixels)
.def("clearErrorMask", &Detector::clearErrorMask)
.def("getErrorMask", &Detector::getErrorMask)
.def("setErrorMask", &Detector::setErrorMask)
.def("getErrorMessage", &Detector::getErrorMessage)
.def("getFlippedDataX", &Detector::getFlippedDataX)
.def("getFlippedDataY", &Detector::getFlippedDataY)
.def("setFlippedDataX", &Detector::setFlippedDataX)
@ -284,9 +278,10 @@ py::class_<multiSlsDetector> multiDetectorApi(m, "multiDetectorApi");
py::cpp_function(&multiSlsDetector::setAcquiringFlag))
.def_property_readonly("rx_tcpport",
py::cpp_function(&multiSlsDetector::getReceiverPort))
// .def_property_readonly("rx_udpip",
// py::cpp_function(&multiSlsDetector::getReceiverUDPIP), py::arg("det_id")=1)
// .def("_setReceiverUDPIP", &multiSlsDetector::setReceiverUDPIP)
.def_property_readonly("detectornumber",
py::cpp_function(&multiSlsDetector::getDetectorNumber))
.def("_getReceiverUDPIP", &multiSlsDetector::getReceiverUDPIP)
.def("_setReceiverUDPIP", &multiSlsDetector::setReceiverUDPIP)
;

View File

@ -83,7 +83,6 @@ multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...), typename NonD
return result;
}
//Const qualified version
template <typename RT, typename... CT>
std::vector<RT>
multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...) const, typename NonDeduced<CT>::type... Args) const {
@ -131,100 +130,8 @@ int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int &channelX,
return -1;
}
std::string multiSlsDetector::getErrorMessage(int &critical, int detPos) {
int64_t multiMask = 0, slsMask = 0;
std::string retval = "";
critical = 0;
size_t posmin = 0, posmax = detectors.size();
// single
if (detPos >= 0) {
slsMask = detectors[detPos]->getErrorMask();
posmin = (size_t)detPos;
posmax = posmin + 1;
}
multiMask = getErrorMask();
if (multiMask || slsMask) {
if (multiMask & MULTI_DETECTORS_NOT_ADDED) {
retval.append("Detectors not added:\n" +
std::string(getNotAddedList()) + std::string("\n"));
critical = 1;
}
if (multiMask & MULTI_HAVE_DIFFERENT_VALUES) {
retval.append(
"A previous multi detector command gave different values\n"
"Please check the console\n");
critical = 0;
}
if (multiMask & MULTI_CONFIG_FILE_ERROR) {
retval.append("Could not load Config File\n");
critical = 1;
}
if (multiMask & MULTI_POS_EXCEEDS_LIST) {
retval.append("Position exceeds multi detector list\n");
critical = 0;
}
if (multiMask & MUST_BE_MULTI_CMD) {
retval.append("Must be a multi detector level command.\n");
critical = 0;
}
if (multiMask & MULTI_OTHER_ERROR) {
retval.append("Some error occured from multi level.\n");
critical =
0; // FIXME: with exceptions/appropriate errors wherever used
}
for (size_t idet = posmin; idet < posmax; ++idet) {
// if the detector has error
if ((multiMask & (1 << idet)) || (detPos >= 0)) {
// append detector id
retval.append("Detector " + std::to_string(idet) +
std::string(":\n"));
// get sls det error mask
slsMask = detectors[idet]->getErrorMask();
// get the error critical level
if ((slsMask > 0xFFFFFFFF) | critical) {
critical = 1;
}
// append error message
retval.append(errorDefs::getErrorMessage(slsMask));
}
}
}
return retval;
}
int64_t multiSlsDetector::clearAllErrorMask(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->clearErrorMask();
}
// multi
clearErrorMask();
clearNotAddedList();
for (auto &d : detectors) {
d->clearErrorMask();
}
return getErrorMask();
}
void multiSlsDetector::setErrorMaskFromAllDetectors() {
for (size_t idet = 0; idet < detectors.size(); ++idet) {
if (detectors[idet]->getErrorMask()) {
setErrorMask(getErrorMask() | (1 << idet));
}
}
}
void multiSlsDetector::setAcquiringFlag(bool b) {
multi_shm()->acquiringFlag = b;
void multiSlsDetector::setAcquiringFlag(bool flag) {
multi_shm()->acquiringFlag = flag;
}
bool multiSlsDetector::getAcquiringFlag() const {
@ -269,6 +176,10 @@ int64_t multiSlsDetector::getId(idMode mode, int detPos) {
return sls::minusOneIfDifferent(r);
}
std::vector<int64_t> multiSlsDetector::getDetectorNumber(){
return parallelCall(&slsDetector::getId, slsDetectorDefs::DETECTOR_SERIAL_NUMBER);
}
void multiSlsDetector::freeSharedMemory(int multiId, int detPos) {
// single
if (detPos >= 0) {
@ -301,7 +212,6 @@ void multiSlsDetector::freeSharedMemory(int detPos) {
// multi
zmqSocket.clear();
clearAllErrorMask();
for (auto &d : detectors) {
d->freeSharedMemory();
}
@ -444,7 +354,7 @@ void multiSlsDetector::setHostname(const char *name, int detPos) {
addMultipleDetectors(name);
}
std::string multiSlsDetector::getHostname(int detPos) {
std::string multiSlsDetector::getHostname(int detPos) const {
// single
if (detPos >= 0) {
return detectors[detPos]->getHostname();
@ -781,45 +691,33 @@ std::vector<int> multiSlsDetector::getReceiverPort() const {
}
int multiSlsDetector::lockServer(int p, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->lockServer(p);
}
// multi
auto r = parallelCall(&slsDetector::lockServer, p);
return sls::minusOneIfDifferent(r);
}
std::string multiSlsDetector::getLastClientIP(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getLastClientIP();
}
// multi
auto r = parallelCall(&slsDetector::getLastClientIP);
return sls::concatenateIfDifferent(r);
}
int multiSlsDetector::exitServer(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->exitServer();
}
// multi
auto r = parallelCall(&slsDetector::exitServer);
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
}
int multiSlsDetector::execCommand(const std::string &cmd, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->execCommand(cmd);
}
// multi
auto r = parallelCall(&slsDetector::execCommand, cmd);
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
}
@ -846,14 +744,6 @@ int multiSlsDetector::readConfigurationFile(const std::string &fname) {
input_file.close();
} else {
FILE_LOG(logERROR) << "Could not openconfiguration file " << fname << " for reading";
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);
return FAIL;
}
if (getErrorMask()) {
int c;
FILE_LOG(logERROR) << "----------------\n Error Messages\n----------------";
FILE_LOG(logERROR) << getErrorMessage(c);
return FAIL;
}
return OK;
@ -1624,7 +1514,7 @@ std::string multiSlsDetector::setDetectorIP(const std::string &detectorIP, int d
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::getDetectorIP(int detPos) {
std::string multiSlsDetector::getDetectorIP(int detPos) const {
// single
if (detPos >= 0) {
return detectors[detPos]->getDetectorIP();

View File

@ -120,7 +120,9 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* one
* @param update true to update last user pid, date etc
*/
explicit multiSlsDetector(int multi_id = 0, bool verify = true, bool update = true);
explicit multiSlsDetector(int multi_id = 0,
bool verify = true,
bool update = true);
/**
* Destructor
@ -134,11 +136,11 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* one
* @param update true to update last user pid, date etc
*/
void setupMultiDetector(bool verify = true, bool update = true);
void setupMultiDetector(bool verify = true,
bool update = true);
/**
* Loop through the detectors serially
* and return a vector of results
* Loop through the detectors serially and return the result as a vector
*/
template <class CT>
struct NonDeduced { using type = CT; };
@ -146,20 +148,25 @@ class multiSlsDetector : public virtual slsDetectorDefs,
std::vector<RT> serialCall(RT (slsDetector::*somefunc)(CT...),
typename NonDeduced<CT>::type... Args);
//Const qualified version should be preferred for calling get methods
/**
* Loop through the detectors serially and return the result as a vector
* Const qualified version
*/
template <typename RT, typename... CT>
std::vector<RT> serialCall(RT (slsDetector::*somefunc)(CT...) const,
typename NonDeduced<CT>::type... Args) const;
/**
* Loop through the detectors in parallel threads
* and return a vector of results
* Loop through the detectors in parallel and return the result as a vector
*/
template <typename RT, typename... CT>
std::vector<RT> parallelCall(RT (slsDetector::*somefunc)(CT...),
typename NonDeduced<CT>::type... Args);
//Const qualified version should be preferred for calling get methods
/**
* Loop through the detectors in parallel and return the result as a vector
* Const qualified version
*/
template <typename RT, typename... CT>
std::vector<RT> parallelCall(RT (slsDetector::*somefunc)(CT...) const,
typename NonDeduced<CT>::type... Args) const;
@ -175,32 +182,11 @@ class multiSlsDetector : public virtual slsDetectorDefs,
*/
int decodeNChannel(int offsetX, int offsetY, int &channelX, int &channelY);
/**
* Checks error mask and returns error message and its severity if it exists
* @param critical is 1 if any of the messages is critical
* @param detPos -1 for all detectors in list or specific detector position
* @returns error message else an empty std::string
*/
std::string getErrorMessage(int &critical, int detPos = -1);
/**
* Clears error mask of both multi and sls
* @param detPos -1 for all detectors in list or specific detector position
* @returns error mask
*/
int64_t clearAllErrorMask(int detPos = -1);
/**
* Set Error Mask from all detectors
* if each had errors in the mask already
*/
void setErrorMaskFromAllDetectors();
/**
* Set acquiring flag in shared memory
* @param b acquiring flag
*/
void setAcquiringFlag(bool b = false);
void setAcquiringFlag(bool flag);
/**
* Get acquiring flag from shared memory
@ -239,6 +225,7 @@ class multiSlsDetector : public virtual slsDetectorDefs,
*/
int64_t getId(idMode mode, int detPos = -1);
std::vector<int64_t> getDetectorNumber();
/**
* Free shared memory from the command line
* avoiding creating the constructor classes and mapping
@ -277,7 +264,7 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* @returns concatenated hostnames of all detectors or hostname of specific
* one
*/
std::string getHostname(int detPos = -1);
std::string getHostname(int detPos = -1) const;
/**
* Appends detectors to the end of the list in shared memory
@ -890,7 +877,7 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* @param detPos -1 for all detectors in list or specific detector position
* @returns the detector IP address
*/
std::string getDetectorIP(int detPos = -1);
std::string getDetectorIP(int detPos = -1) const;
/**
* Validates and sets the receiver.

View File

@ -153,7 +153,7 @@ int slsDetector::checkReceiverVersionCompatibility() {
return ret;
}
int64_t slsDetector::getId(idMode mode) {
int64_t slsDetector::getId(idMode mode){
int arg = (int)mode;
int64_t retval = -1;
FILE_LOG(logDEBUG1) << "Getting id type " << mode;
@ -166,9 +166,6 @@ int64_t slsDetector::getId(idMode mode) {
int fnum = F_GET_RECEIVER_ID;
auto receiver = sls::ClientSocket(true, detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort);
ret = receiver.sendCommandThenRead(fnum, nullptr, 0, &retval, sizeof(retval));
if (ret == FAIL) {
setErrorMask((getErrorMask()) | (OTHER_ERROR_CODE));
}
}
if (ret == FORCE_UPDATE) {
ret = updateReceiver();
@ -180,13 +177,7 @@ int64_t slsDetector::getId(idMode mode) {
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = sls::ClientSocket(false, detector_shm()->hostname, detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
// handle ret
if (ret == FAIL) {
setErrorMask((getErrorMask()) | (OTHER_ERROR_CODE));
}
}
if (ret != FAIL) {
FILE_LOG(logDEBUG1) << "Id (" << mode << "): 0x" << std::hex << retval << std::dec;
}
@ -215,7 +206,7 @@ void slsDetector::setHostname(const std::string &hostname) {
updateDetector();
}
std::string slsDetector::getHostname() {
std::string slsDetector::getHostname() const {
return detector_shm()->hostname;
}
@ -920,8 +911,8 @@ int slsDetector::exitServer() {
int slsDetector::execCommand(const std::string &cmd) {
int fnum = F_EXEC_COMMAND;
int ret = FAIL;
char arg[MAX_STR_LENGTH] = {0};
char retval[MAX_STR_LENGTH] = {0};
char arg[MAX_STR_LENGTH] = {};
char retval[MAX_STR_LENGTH] = {};
sls::strcpy_safe(arg, cmd.c_str());
FILE_LOG(logDEBUG1) << "Sending command to detector " << arg;
@ -942,7 +933,6 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) {
int n = 0, i32 = 0;
int64_t i64 = 0;
char lastClientIP[INET_ADDRSTRLEN] = {0};
// auto client = sls::ClientSocket(false, detector_shm()->hostname, detector_shm()->controlPort);
n += client.receiveData(lastClientIP, sizeof(lastClientIP));
FILE_LOG(logDEBUG1) << "Updating detector last modified by " << lastClientIP;
@ -2341,7 +2331,7 @@ std::string slsDetector::setDetectorIP(const std::string &detectorIP) {
return std::string(detector_shm()->detectorIP);
}
std::string slsDetector::getDetectorIP() {
std::string slsDetector::getDetectorIP() const {
return std::string(detector_shm()->detectorIP);
}

View File

@ -323,7 +323,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
* Gets the hostname of detector
* @returns hostname
*/
std::string getHostname();
std::string getHostname() const;
/**
* Could not connect to receiver, log error
@ -810,7 +810,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
* Returns the detector IP address\sa sharedSlsDetector
* @returns the detector IP address
*/
std::string getDetectorIP();
std::string getDetectorIP() const;
/**
* Validates and sets the receiver.