mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-17 16:43:45 +01:00
more const more python
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user