general function for returning first or concatenated string

This commit is contained in:
Erik Frojdh 2018-05-25 10:01:51 +02:00
parent e0c9805ee8
commit 228d624d8f
2 changed files with 42 additions and 21 deletions

View File

@ -639,7 +639,6 @@ string multiSlsDetector::sgetDetectorsType(int pos)
int multiSlsDetector::getDetectorId(int pos) int multiSlsDetector::getDetectorId(int pos)
{ {
#ifdef VERBOSE #ifdef VERBOSE
cout << "Getting detector ID " << pos << endl; cout << "Getting detector ID " << pos << endl;
#endif #endif
@ -653,7 +652,6 @@ int multiSlsDetector::getDetectorId(int pos)
int multiSlsDetector::setDetectorId(int ival, int pos) int multiSlsDetector::setDetectorId(int ival, int pos)
{ {
if (pos >= 0) { if (pos >= 0) {
addSlsDetector(ival, pos); addSlsDetector(ival, pos);
if (detectors[pos]) if (detectors[pos])
@ -666,7 +664,6 @@ int multiSlsDetector::setDetectorId(int ival, int pos)
int multiSlsDetector::addSlsDetector(const char* name, int pos) int multiSlsDetector::addSlsDetector(const char* name, int pos)
{ {
detectorType t = getDetectorType(string(name)); detectorType t = getDetectorType(string(name));
int online = 0; int online = 0;
slsDetector* s = NULL; slsDetector* s = NULL;
@ -3426,34 +3423,58 @@ int multiSlsDetector::exitServer()
return ival; return ival;
} }
/** returns the detector trimbit/settings directory */ std::string multiSlsDetector::callDetectors(std::string (slsDetector::*somefunc)())
string multiSlsDetector::getSettingsDir()
{ {
string concatenatedValue, firstValue;
string concatenatedDir, firstDir; bool valueNotSame = false;
bool dirNotSame = false;
for (int idet = 0; idet < thisMultiDetector->numberOfDetectors; ++idet) { for (int idet = 0; idet < thisMultiDetector->numberOfDetectors; ++idet) {
if (detectors[idet]) { if (detectors[idet]) {
string thisDir = detectors[idet]->getSettingsDir(); string thisValue = (detectors[idet]->*somefunc)();;
if (detectors[idet]->getErrorMask()) if (detectors[idet]->getErrorMask())
setErrorMask(getErrorMask() | (1 << idet)); setErrorMask(getErrorMask() | (1 << idet));
if (firstDir.empty()) { if (firstValue.empty()) {
concatenatedDir = thisDir; concatenatedValue = thisValue;
firstDir = thisDir; firstValue = thisValue;
} else { } else {
concatenatedDir += "+" + thisDir; concatenatedValue += "+" + thisValue;
} }
if (firstValue != thisValue)
if (firstDir != thisDir) valueNotSame = true;
dirNotSame = true;
} }
} }
if (dirNotSame) if (valueNotSame)
return concatenatedDir; return concatenatedValue;
else else
return firstDir; return firstValue;
}
/** returns the detector trimbit/settings directory */
string multiSlsDetector::getSettingsDir()
{
return callDetectors(&slsDetector::getSettingsDir);
// string concatenatedDir, firstDir;
// bool dirNotSame = false;
// for (int idet = 0; idet < thisMultiDetector->numberOfDetectors; ++idet) {
// if (detectors[idet]) {
// string thisDir = detectors[idet]->getSettingsDir();
// if (detectors[idet]->getErrorMask())
// setErrorMask(getErrorMask() | (1 << idet));
// if (firstDir.empty()) {
// concatenatedDir = thisDir;
// firstDir = thisDir;
// } else {
// concatenatedDir += "+" + thisDir;
// }
// if (firstDir != thisDir)
// dirNotSame = true;
// }
// }
// if (dirNotSame)
// return concatenatedDir;
// else
// return firstDir;
} }
/** sets the detector trimbit/settings directory \sa sharedSlsDetector */ /** sets the detector trimbit/settings directory \sa sharedSlsDetector */

View File

@ -1044,7 +1044,7 @@ class multiSlsDetector : public slsDetectorUtils {
std::string callDetectors(std::string(slsDetector::*somefunc)());
/** returns the detector trimbit/settings directory \sa sharedSlsDetector */ /** returns the detector trimbit/settings directory \sa sharedSlsDetector */
std::string getSettingsDir(); std::string getSettingsDir();