From 228d624d8f87d23e0db67e2e37629ae2c48ccf37 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 25 May 2018 10:01:51 +0200 Subject: [PATCH] general function for returning first or concatenated string --- .../multiSlsDetector/multiSlsDetector.cpp | 61 +++++++++++++------ .../multiSlsDetector/multiSlsDetector.h | 2 +- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 678a28e0d..936e18cf9 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -639,7 +639,6 @@ string multiSlsDetector::sgetDetectorsType(int pos) int multiSlsDetector::getDetectorId(int pos) { - #ifdef VERBOSE cout << "Getting detector ID " << pos << endl; #endif @@ -653,7 +652,6 @@ int multiSlsDetector::getDetectorId(int pos) int multiSlsDetector::setDetectorId(int ival, int pos) { - if (pos >= 0) { addSlsDetector(ival, pos); if (detectors[pos]) @@ -666,7 +664,6 @@ int multiSlsDetector::setDetectorId(int ival, int pos) int multiSlsDetector::addSlsDetector(const char* name, int pos) { - detectorType t = getDetectorType(string(name)); int online = 0; slsDetector* s = NULL; @@ -3426,34 +3423,58 @@ int multiSlsDetector::exitServer() return ival; } -/** returns the detector trimbit/settings directory */ -string multiSlsDetector::getSettingsDir() +std::string multiSlsDetector::callDetectors(std::string (slsDetector::*somefunc)()) { - - string concatenatedDir, firstDir; - bool dirNotSame = false; - + string concatenatedValue, firstValue; + bool valueNotSame = false; for (int idet = 0; idet < thisMultiDetector->numberOfDetectors; ++idet) { if (detectors[idet]) { - string thisDir = detectors[idet]->getSettingsDir(); + string thisValue = (detectors[idet]->*somefunc)();; if (detectors[idet]->getErrorMask()) setErrorMask(getErrorMask() | (1 << idet)); - if (firstDir.empty()) { - concatenatedDir = thisDir; - firstDir = thisDir; + if (firstValue.empty()) { + concatenatedValue = thisValue; + firstValue = thisValue; } else { - concatenatedDir += "+" + thisDir; + concatenatedValue += "+" + thisValue; } - - if (firstDir != thisDir) - dirNotSame = true; + if (firstValue != thisValue) + valueNotSame = true; } } - if (dirNotSame) - return concatenatedDir; + if (valueNotSame) + return concatenatedValue; 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 */ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 311e89bdf..2f8ec3a9b 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1044,7 +1044,7 @@ class multiSlsDetector : public slsDetectorUtils { - + std::string callDetectors(std::string(slsDetector::*somefunc)()); /** returns the detector trimbit/settings directory \sa sharedSlsDetector */ std::string getSettingsDir();