mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 23:30:03 +02:00
cleaned up read config file slightly
This commit is contained in:
parent
e921dbb6a7
commit
c3289a973f
@ -277,23 +277,6 @@ int64_t multiSlsDetector::getId(idMode mode, int detPos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// slsDetector* multiSlsDetector::getSlsDetector(int detPos) {
|
|
||||||
// return detectors[detPos].get();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// slsDetector *multiSlsDetector::operator()(int detPos) const {
|
|
||||||
// return detectors[detPos].get();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// slsDetector* multiSlsDetector::operator[](int detPos) const {
|
|
||||||
// //Providing access to detectors with range checking
|
|
||||||
// //throw exception if out of range
|
|
||||||
// if (detPos >= 0 && detPos < (int)detectors.size())
|
|
||||||
// return detectors[detPos].get();
|
|
||||||
// else
|
|
||||||
// throw(std::range_error("Detector does not exist"));
|
|
||||||
// }
|
|
||||||
|
|
||||||
void multiSlsDetector::freeSharedMemory(int multiId, int detPos) {
|
void multiSlsDetector::freeSharedMemory(int multiId, int detPos) {
|
||||||
// single
|
// single
|
||||||
if (detPos >= 0) {
|
if (detPos >= 0) {
|
||||||
@ -584,16 +567,10 @@ void multiSlsDetector::addSlsDetector (std::string s) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int pos = (int)detectors.size();
|
int pos = (int)detectors.size();
|
||||||
detectors.push_back(sls::make_unique<slsDetector>(type, detId, pos, false));
|
detectors.push_back(sls::make_unique<slsDetector>(type, detId, pos, false));
|
||||||
|
|
||||||
|
|
||||||
thisMultiDetector->numberOfDetectors = detectors.size();
|
thisMultiDetector->numberOfDetectors = detectors.size();
|
||||||
|
|
||||||
detectors[pos]->setHostname(s.c_str()); // also updates client
|
detectors[pos]->setHostname(s.c_str()); // also updates client
|
||||||
|
|
||||||
thisMultiDetector->dataBytes += detectors[pos]->getDataBytes();
|
thisMultiDetector->dataBytes += detectors[pos]->getDataBytes();
|
||||||
thisMultiDetector->dataBytesInclGapPixels += detectors[pos]->getDataBytesInclGapPixels();
|
thisMultiDetector->dataBytesInclGapPixels += detectors[pos]->getDataBytesInclGapPixels();
|
||||||
thisMultiDetector->numberOfChannels += detectors[pos]->getTotalNumberOfChannels();
|
thisMultiDetector->numberOfChannels += detectors[pos]->getTotalNumberOfChannels();
|
||||||
@ -935,46 +912,31 @@ int multiSlsDetector::execCommand(std::string cmd, int detPos) {
|
|||||||
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
|
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int multiSlsDetector::readConfigurationFile(const std::string& fname) {
|
int multiSlsDetector::readConfigurationFile(const std::string& fname) {
|
||||||
freeSharedMemory();
|
freeSharedMemory();
|
||||||
setupMultiDetector();
|
setupMultiDetector();
|
||||||
|
|
||||||
// std::string ans;
|
char* args[100];
|
||||||
std::string str;
|
char myargs[100][1000];
|
||||||
std::ifstream infile;
|
|
||||||
int iargval;
|
|
||||||
int interrupt = 0;
|
|
||||||
char* args[1000];
|
|
||||||
|
|
||||||
char myargs[1000][1000];
|
|
||||||
|
|
||||||
std::string sargname, sargval;
|
|
||||||
int iline = 0;
|
|
||||||
std::cout << "config file name " << fname << std::endl;
|
std::cout << "config file name " << fname << std::endl;
|
||||||
|
|
||||||
|
std::ifstream infile;
|
||||||
infile.open(fname.c_str(), std::ios_base::in);
|
infile.open(fname.c_str(), std::ios_base::in);
|
||||||
if (infile.is_open()) {
|
if (infile.is_open()) {
|
||||||
|
std::string tmp_line;
|
||||||
while (infile.good() and interrupt == 0) {
|
while (infile.good()) {
|
||||||
sargname = "none";
|
getline(infile, tmp_line);
|
||||||
sargval = "0";
|
|
||||||
getline(infile, str);
|
|
||||||
++iline;
|
|
||||||
|
|
||||||
// remove comments that come after
|
// remove comments that come after
|
||||||
if (str.find('#') != std::string::npos)
|
if (tmp_line.find('#') != std::string::npos)
|
||||||
str.erase(str.find('#'));
|
tmp_line.erase(tmp_line.find('#'));
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout << "string:" << str << std::endl;
|
std::cout << "tmp_line after removing comments:" << tmp_line << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (str.length() < 2) {
|
if (tmp_line.length() > 1) {
|
||||||
#ifdef VERBOSE
|
std::istringstream ssstr(tmp_line);
|
||||||
std::cout << "Empty line or Comment " << std::endl;
|
int iargval = 0;
|
||||||
#endif
|
std::string sargname;
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
std::istringstream ssstr(str);
|
|
||||||
iargval = 0;
|
|
||||||
while (ssstr.good()) {
|
while (ssstr.good()) {
|
||||||
ssstr >> sargname;
|
ssstr >> sargname;
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -982,6 +944,7 @@ int multiSlsDetector::readConfigurationFile(const std::string& fname) {
|
|||||||
#endif
|
#endif
|
||||||
strcpy(myargs[iargval], sargname.c_str());
|
strcpy(myargs[iargval], sargname.c_str());
|
||||||
args[iargval] = myargs[iargval];
|
args[iargval] = myargs[iargval];
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout << "--" << iargval << " " << args[iargval] << std::endl;
|
std::cout << "--" << iargval << " " << args[iargval] << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -995,18 +958,13 @@ int multiSlsDetector::readConfigurationFile(const std::string& fname) {
|
|||||||
#endif
|
#endif
|
||||||
multiSlsDetectorClient(iargval, args, PUT_ACTION, this);
|
multiSlsDetectorClient(iargval, args, PUT_ACTION, this);
|
||||||
}
|
}
|
||||||
++iline;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
infile.close();
|
infile.close();
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Error opening configuration file " << fname << " for reading" << std::endl;
|
std::cout << "Error opening configuration file " << fname << " for reading" << std::endl;
|
||||||
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);
|
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
#ifdef VERBOSE
|
|
||||||
std::cout << "Read configuration file of " << iline << " lines" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (getErrorMask()) {
|
if (getErrorMask()) {
|
||||||
int c;
|
int c;
|
||||||
@ -1014,7 +972,6 @@ int multiSlsDetector::readConfigurationFile(const std::string& fname) {
|
|||||||
getErrorMessage(c).c_str());
|
getErrorMessage(c).c_str());
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user