Error handling with exceptions in slsDetector and multiSlsDetector (#14)

* less error mask

* removing error mask from slsDetector

* removed ErrorMask

* setonline, setreceiveornline bug fix
This commit is contained in:
Erik Fröjdh 2019-03-20 16:23:41 +01:00 committed by Dhanya Thattil
parent 9d489dc962
commit 03402d0e9e
9 changed files with 521 additions and 1407 deletions

View File

@ -16,16 +16,36 @@
using sls::RuntimeError; using sls::RuntimeError;
using sls::SharedMemoryError; using sls::SharedMemoryError;
using sls::SocketError; using sls::SocketError;
using sls::DetectorError;
int main() { int main() {
// const std::string hostname = "beb083"; const std::string hostname = "beb083";
// auto type = slsDetector::getTypeFromDetector(hostname); auto type = slsDetector::getTypeFromDetector(hostname);
// slsDetector d(type); slsDetector d(type);
// d.setHostname(hostname); d.setHostname(hostname);
// d.setReceiverHostname("mpc2408"); d.setOnline(true);
std::cout << "hostname: " << d.getHostname() << '\n';
d.setThresholdTemperature(50);
// try{
// d.setThresholdTemperature(50);
// }catch(const DetectorError &e){
// std::cout << "Caught: " << e.what() << '\n';
// }
// std::cout << "hostname: " << d.getHostname() << '\n'; // std::cout << "hostname: " << d.getHostname() << '\n';
// std::cout << "exptime: " << d.setDAC(-1, slsDetectorDefs::E_Vrf, 0) << '\n';
// slsDetector d2(type);
// std::cout << "Online: " << d2.getOnlineFlag() << '\n';
// d2.setHostname("beb55555");
// d2.setOnline(true);
// std::cout << "Online: " << d2.getOnlineFlag() << '\n';
// std::cout << "hostname: " << d2.getHostname() << '\n';
// std::cout << "port: " << d.getControlPort() << '\n'; // std::cout << "port: " << d.getControlPort() << '\n';
// d.setOnline(true); // d.setOnline(true);
// d.setReceiverOnline(true); // d.setReceiverOnline(true);

View File

@ -16,6 +16,7 @@ auto type_enum = slsDetectorDefs::detectorType::EIGER;
const std::string hostname = "beb083"; const std::string hostname = "beb083";
const std::string type_string = "Eiger"; const std::string type_string = "Eiger";
const std::string my_ip = "129.129.205.242"; const std::string my_ip = "129.129.205.242";
TEST_CASE("single EIGER detector no receiver basic set and get") { TEST_CASE("single EIGER detector no receiver basic set and get") {
//TODO! this test should take command line arguments for config //TODO! this test should take command line arguments for config
@ -195,13 +196,4 @@ TEST_CASE("Excersise all possible set timer functions") {
CHECK(d.setTimer(slsDetectorDefs::timerIndex::SUBFRAME_ACQUISITION_TIME) == subtime); CHECK(d.setTimer(slsDetectorDefs::timerIndex::SUBFRAME_ACQUISITION_TIME) == subtime);
} }
// TEST_CASE("ACQ") { // TEST_CASE()
// auto type = slsDetector::getTypeFromDetector(hostname);
// auto d = slsDetector(type);
// d.setHostname(hostname);
// d.setOnline(true);
// d.prepareAcquisition();
// d.startAcquisition();
// d.stopAcquisition();
// }

View File

@ -26,6 +26,8 @@
#include <future> #include <future>
#include <vector> #include <vector>
using sls::NotImplementedError;
using sls::RuntimeError;
using sls::SharedMemory; using sls::SharedMemory;
using sls::SharedMemoryError; using sls::SharedMemoryError;
@ -397,14 +399,6 @@ void multiSlsDetector::addSlsDetector(const std::string &hostname) {
// get type by connecting // get type by connecting
detectorType type = slsDetector::getTypeFromDetector(hostname.c_str(), DEFAULT_PORTNO); detectorType type = slsDetector::getTypeFromDetector(hostname.c_str(), DEFAULT_PORTNO);
if (type == GENERIC) {
FILE_LOG(logERROR) << "Could not connect to Detector " << hostname
<< " to determine the type!";
setErrorMask(getErrorMask() | MULTI_DETECTORS_NOT_ADDED);
appendNotAddedList(hostname.c_str());
return;
}
int pos = (int)detectors.size(); int pos = (int)detectors.size();
detectors.push_back(sls::make_unique<slsDetector>(type, multiId, pos, false)); detectors.push_back(sls::make_unique<slsDetector>(type, multiId, pos, false));
multi_shm()->numberOfDetectors = detectors.size(); multi_shm()->numberOfDetectors = detectors.size();
@ -759,19 +753,21 @@ int multiSlsDetector::readConfigurationFile(const std::string &fname) {
} }
int multiSlsDetector::writeConfigurationFile(const std::string &fname) { int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
//TODO! make exception safe!
const std::vector<std::string> names = {"detsizechan", "hostname", "outdir", const std::vector<std::string> names = {"detsizechan", "hostname", "outdir",
"threaded"}; "threaded"};
char *args[100];
for (auto &arg : args) {
arg = new char[1000];
}
int ret = OK, ret1 = OK; int ret = OK, ret1 = OK;
std::ofstream outfile; std::ofstream outfile;
size_t iline = 0; size_t iline = 0;
outfile.open(fname.c_str(), std::ios_base::out); outfile.open(fname.c_str(), std::ios_base::out);
if (outfile.is_open()) { if (outfile.is_open()) {
char *args[100];
for (auto &arg : args) {
arg = new char[1000];
}
auto cmd = slsDetectorCommand(this); auto cmd = slsDetectorCommand(this);
// complete size of detector // complete size of detector
@ -792,9 +788,6 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
for (size_t idet = 0; idet < detectors.size(); ++idet) { for (size_t idet = 0; idet < detectors.size(); ++idet) {
outfile << std::endl; outfile << std::endl;
ret1 = detectors[idet]->writeConfigurationFile(outfile, this); ret1 = detectors[idet]->writeConfigurationFile(outfile, this);
if (detectors[idet]->getErrorMask()) {
setErrorMask(getErrorMask() | (1 << idet));
}
if (ret1 == FAIL) { if (ret1 == FAIL) {
ret = FAIL; ret = FAIL;
} }
@ -811,28 +804,13 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
} }
outfile.close(); outfile.close();
FILE_LOG(logDEBUG1) << "wrote " << iline << " lines to configuration file "; FILE_LOG(logDEBUG1) << "wrote " << iline << " lines to configuration file ";
} else {
FILE_LOG(logERROR) << "Could not open configuration file " << fname << " for writing";
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);
ret = FAIL;
}
for (auto &arg : args) { for (auto &arg : args) {
delete[] arg; delete[] arg;
} }
} else {
return ret; throw RuntimeError("Could not open configuration file " + fname + " for writing");
}
std::string multiSlsDetector::getSettingsFile(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getSettingsFile();
} }
return ret;
// multi
auto r = serialCall(&slsDetector::getSettingsFile);
return sls::concatenateIfDifferent(r);
} }
slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int detPos) { slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int detPos) {
@ -858,7 +836,7 @@ multiSlsDetector::setSettings(detectorSettings isettings, int detPos) {
return (detectorSettings)sls::minusOneIfDifferent(r); return (detectorSettings)sls::minusOneIfDifferent(r);
} }
int multiSlsDetector::getThresholdEnergy(int detPos){ int multiSlsDetector::getThresholdEnergy(int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->getThresholdEnergy(); return detectors[detPos]->getThresholdEnergy();
@ -1072,7 +1050,6 @@ int multiSlsDetector::configureMAC(int detPos) {
int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t, int detPos) { int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
// error for setting values individually // error for setting values individually
// FIXME: what else? and error code // FIXME: what else? and error code
if (t != -1) { if (t != -1) {
@ -1081,16 +1058,11 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t, int detPos) {
case CYCLES_NUMBER: case CYCLES_NUMBER:
case STORAGE_CELL_NUMBER: case STORAGE_CELL_NUMBER:
case MEASUREMENTS_NUMBER: case MEASUREMENTS_NUMBER:
FILE_LOG(logERROR) throw RuntimeError("Cannot set number of frames, cycles,storage cells or measurements individually.");
<< "Cannot set number of frames, cycles, "
"storage cells or measurements individually.";
setErrorMask(getErrorMask() | MUST_BE_MULTI_CMD);
return multi_shm()->timerValue[index];
default: default:
break; break;
} }
} }
return detectors[detPos]->setTimer(index, t); return detectors[detPos]->setTimer(index, t);
} }
@ -1274,9 +1246,7 @@ int multiSlsDetector::setSpeed(speedVariable index, int value, int detPos) {
int multiSlsDetector::setDynamicRange(int dr, int detPos) { int multiSlsDetector::setDynamicRange(int dr, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
FILE_LOG(logERROR) << "Dynamic Range cannot be set individually"; throw RuntimeError("Dynamic Range cannot be set individually");
setErrorMask(getErrorMask() | MUST_BE_MULTI_CMD);
return -1;
} }
// multi // multi
@ -1421,12 +1391,11 @@ uint32_t multiSlsDetector::writeRegister(uint32_t addr, uint32_t val,
} }
// can't have different values // can't have different values
FILE_LOG(logERROR) << "Error: Different Values for function writeRegister " std::ostringstream ss;
"(write 0x" ss << "Error: Different Values for function writeRegister (write 0x"
<< std::hex << val << " to addr 0x" << std::hex << addr << std::hex << val << " to addr 0x" << std::hex << addr
<< std::dec << ")"; << std::dec << ")";
setErrorMask(getErrorMask() | MULTI_HAVE_DIFFERENT_VALUES); throw RuntimeError(ss.str());
return -1;
} }
uint32_t multiSlsDetector::readRegister(uint32_t addr, int detPos) { uint32_t multiSlsDetector::readRegister(uint32_t addr, int detPos) {
@ -1442,11 +1411,10 @@ uint32_t multiSlsDetector::readRegister(uint32_t addr, int detPos) {
} }
// can't have different values // can't have different values
FILE_LOG(logERROR) << "Error: Different Values for function readRegister " std::ostringstream ss;
"(read from 0x" ss << "Error: Different Values for function readRegister (read from 0x"
<< std::hex << addr << std::dec << ")"; << std::hex << addr << std::dec << ")";
setErrorMask(getErrorMask() | MULTI_HAVE_DIFFERENT_VALUES); throw RuntimeError(ss.str());
return -1;
} }
uint32_t multiSlsDetector::setBit(uint32_t addr, int n, int detPos) { uint32_t multiSlsDetector::setBit(uint32_t addr, int n, int detPos) {
@ -1462,12 +1430,12 @@ uint32_t multiSlsDetector::setBit(uint32_t addr, int n, int detPos) {
} }
// can't have different values // can't have different values
FILE_LOG(logERROR) << "Error: Different Values for function setBit " std::ostringstream ss;
ss << "Error: Different Values for function setBit "
"(set bit " "(set bit "
<< n << " to addr 0x" << std::hex << addr << std::dec << n << " to addr 0x" << std::hex << addr << std::dec
<< ")"; << ")";
setErrorMask(getErrorMask() | MULTI_HAVE_DIFFERENT_VALUES); throw RuntimeError(ss.str());
return -1;
} }
uint32_t multiSlsDetector::clearBit(uint32_t addr, int n, int detPos) { uint32_t multiSlsDetector::clearBit(uint32_t addr, int n, int detPos) {
@ -1483,12 +1451,10 @@ uint32_t multiSlsDetector::clearBit(uint32_t addr, int n, int detPos) {
} }
// can't have different values // can't have different values
FILE_LOG(logERROR) << "Error: Different Values for function clearBit " std::ostringstream ss;
"(clear bit " ss << "Error: Different Values for function clearBit (clear bit "
<< n << " to addr 0x" << std::hex << addr << std::dec << n << " to addr 0x" << std::hex << addr << std::dec << ")";
<< ")"; throw RuntimeError(ss.str());
setErrorMask(getErrorMask() | MULTI_HAVE_DIFFERENT_VALUES);
return -1;
} }
std::string multiSlsDetector::setDetectorMAC(const std::string &detectorMAC, int detPos) { std::string multiSlsDetector::setDetectorMAC(const std::string &detectorMAC, int detPos) {
@ -1955,10 +1921,7 @@ int multiSlsDetector::loadImageToDetector(imageType index,
int nch = multi_shm()->numberOfChannels; int nch = multi_shm()->numberOfChannels;
short int imageVals[nch]; short int imageVals[nch];
if (readDataFile(fname, imageVals, nch) < nch * (int)sizeof(short int)) { if (readDataFile(fname, imageVals, nch) < nch * (int)sizeof(short int)) {
FILE_LOG(logERROR) << "Could not open file or not enough data in file " throw RuntimeError("Could not open file or not enough data in file to load image to detector.");
"to load image to detector.";
setErrorMask(getErrorMask() | MULTI_OTHER_ERROR);
return -1;
} }
// send image to all // send image to all
@ -1994,11 +1957,8 @@ int multiSlsDetector::writeCounterBlockFile(const std::string &fname,
if (sls::allEqualTo(r, static_cast<int>(OK))) { if (sls::allEqualTo(r, static_cast<int>(OK))) {
if (writeDataFile(fname, nch, imageVals) < if (writeDataFile(fname, nch, imageVals) <
nch * (int)sizeof(short int)) { nch * (int)sizeof(short int)) {
FILE_LOG(logERROR) << "Could not open file to write or did not " throw RuntimeError("Could not open file to write or did not write enough data"
"write enough data in file " " in file to write counter block file from detector.");
"to wrte counter block file from detector.";
setErrorMask(getErrorMask() | MULTI_OTHER_ERROR);
return -1;
} }
return OK; return OK;
} }
@ -2400,9 +2360,7 @@ int multiSlsDetector::setAllTrimbits(int val, int detPos) {
int multiSlsDetector::enableGapPixels(int val, int detPos) { int multiSlsDetector::enableGapPixels(int val, int detPos) {
if (getDetectorTypeAsEnum() != EIGER) { if (getDetectorTypeAsEnum() != EIGER) {
if (val >= 0) { if (val >= 0) {
FILE_LOG(logERROR) << "Function (enableGapPixels) not implemented " throw NotImplementedError("Function (enableGapPixels) not implemented for this detector");
"for this detector";
setErrorMask(getErrorMask() | MULTI_OTHER_ERROR);
} }
return 0; return 0;
} }
@ -2410,10 +2368,7 @@ int multiSlsDetector::enableGapPixels(int val, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
if (val >= 0) { if (val >= 0) {
FILE_LOG(logERROR) << "Function (enableGapPixels) must be called " throw RuntimeError("Function (enableGapPixels) must be called from a multi detector level.");
"from a multi detector level.";
setErrorMask(getErrorMask() | MUST_BE_MULTI_CMD);
return -1;
} }
return detectors[detPos]->enableGapPixels(val); return detectors[detPos]->enableGapPixels(val);
} }
@ -2952,10 +2907,7 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
portnum += (iSocket % numSocketsPerDetector); portnum += (iSocket % numSocketsPerDetector);
try { try {
zmqSocket.push_back(sls::make_unique<ZmqSocket>( zmqSocket.push_back(sls::make_unique<ZmqSocket>(
detectors[iSocket / numSocketsPerDetector] detectors[iSocket / numSocketsPerDetector]->getClientStreamingIP().c_str(), portnum));
->getClientStreamingIP()
.c_str(),
portnum));
FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at " << zmqSocket.back()->GetZmqServerAddress(); FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at " << zmqSocket.back()->GetZmqServerAddress();
} catch (...) { } catch (...) {
FILE_LOG(logERROR) << "Could not create Zmq socket on port " << portnum; FILE_LOG(logERROR) << "Could not create Zmq socket on port " << portnum;
@ -3352,12 +3304,7 @@ int multiSlsDetector::enableDataStreamingToClient(int enable) {
// create data threads // create data threads
} else { } else {
if (createReceivingDataSockets() == FAIL) { if (createReceivingDataSockets() == FAIL) {
FILE_LOG(logERROR) throw RuntimeError("Could not create data threads in client.");
<< "Could not create data threads in client.";
detectors[0]->setErrorMask((detectors[0]->getErrorMask()) |
(DATA_STREAMING));
// only for the first det as theres no general one
setErrorMask(getErrorMask() | (1 << 0));
} }
} }
} }
@ -3414,25 +3361,19 @@ int multiSlsDetector::setPattern(const std::string &fname, int detPos) {
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setPattern(fname); return detectors[detPos]->setPattern(fname);
} }
// multi
int addr = 0;
FILE *fd = fopen(fname.c_str(), "r"); FILE *fd = fopen(fname.c_str(), "r");
if (fd == nullptr) { if (fd == nullptr) {
FILE_LOG(logERROR) << "Could not open file"; throw RuntimeError("multiSlsDetector::setPattern: Could not open file");
setErrorMask(getErrorMask() | MULTI_OTHER_ERROR); } else {
return -1; int addr{0};
} uint64_t word{0};
uint64_t word;
while (fread(&word, sizeof(word), 1, fd)) { while (fread(&word, sizeof(word), 1, fd)) {
serialCall(&slsDetector::setPatternWord, addr, word); serialCall(&slsDetector::setPatternWord, addr, word);
++addr; ++addr;
} }
fclose(fd); fclose(fd);
return addr; return addr;
}
} }
uint64_t multiSlsDetector::setPatternWord(int addr, uint64_t word, int detPos) { uint64_t multiSlsDetector::setPatternWord(int addr, uint64_t word, int detPos) {
@ -3505,40 +3446,30 @@ uint64_t multiSlsDetector::getPatternMask(int detPos) {
if (sls::allEqual(r)) { if (sls::allEqual(r)) {
return r.front(); return r.front();
} }
// should not have different values
throw RuntimeError("multiSlsDetector::getPatternMask: Error: Different Values returned)");
// can't have different values
FILE_LOG(logERROR) << "Error: Different Values returned)";
setErrorMask(getErrorMask() | MULTI_HAVE_DIFFERENT_VALUES);
return -1;
} }
int multiSlsDetector::setPatternBitMask(uint64_t mask, int detPos) { int multiSlsDetector::setPatternBitMask(uint64_t mask, int detPos) {
// single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setPatternBitMask(mask); return detectors[detPos]->setPatternBitMask(mask);
} }
// multi
auto r = parallelCall(&slsDetector::setPatternBitMask, mask); auto r = parallelCall(&slsDetector::setPatternBitMask, mask);
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL; return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
} }
uint64_t multiSlsDetector::getPatternBitMask(int detPos) { uint64_t multiSlsDetector::getPatternBitMask(int detPos) {
// single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->getPatternBitMask(); return detectors[detPos]->getPatternBitMask();
} }
// multi
auto r = parallelCall(&slsDetector::getPatternBitMask); auto r = parallelCall(&slsDetector::getPatternBitMask);
if (sls::allEqual(r)) { if (sls::allEqual(r)) {
return r.front(); return r.front();
} }
// can't have different values // should not have different values
FILE_LOG(logERROR) << "Error: Different Values returned)"; throw RuntimeError("multiSlsDetector::getPatternBitMask Different Values returned)");
setErrorMask(getErrorMask() | MULTI_HAVE_DIFFERENT_VALUES);
return -1;
} }
int multiSlsDetector::setLEDEnable(int enable, int detPos) { int multiSlsDetector::setLEDEnable(int enable, int detPos) {
@ -3612,7 +3543,6 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
// } // }
skip = 0; skip = 0;
} }
if (level != 2) { if (level != 2) {
if (std::string(args[0]) == std::string("trimbits")) { if (std::string(args[0]) == std::string("trimbits")) {
skip = 1; skip = 1;
@ -3627,24 +3557,15 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
infile.close(); infile.close();
} else { } else {
FILE_LOG(logERROR) << "Error opening " << fname << " for reading"; throw RuntimeError("Error opening " + fname + " for reading");
return FAIL;
} }
FILE_LOG(logDEBUG1) << "Read " << iline << " lines"; FILE_LOG(logDEBUG1) << "Read " << iline << " lines";
if (getErrorMask()) {
return FAIL;
}
return OK; return OK;
} }
int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) { int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) {
detectorType type = getDetectorTypeAsEnum(); detectorType type = getDetectorTypeAsEnum();
// std::string names[100];
std::vector<std::string> names; std::vector<std::string> names;
// int nvar = 0;
// common config // common config
names.emplace_back("fname"); names.emplace_back("fname");
names.emplace_back("index"); names.emplace_back("index");
@ -4026,16 +3947,3 @@ int multiSlsDetector::kbhit() {
select(STDIN_FILENO + 1, &fds, nullptr, nullptr, &tv); select(STDIN_FILENO + 1, &fds, nullptr, nullptr, &tv);
return FD_ISSET(STDIN_FILENO, &fds); return FD_ISSET(STDIN_FILENO, &fds);
} }
bool multiSlsDetector::isDetectorIndexOutOfBounds(int detPos) {
// position exceeds multi list size
if (detPos >= static_cast<int>(detectors.size())) {
FILE_LOG(logERROR) << "Position " << detPos
<< " is out of bounds with "
"a detector list of "
<< detectors.size();
setErrorMask(getErrorMask() | MULTI_POS_EXCEEDS_LIST);
return true;
}
return false;
}

View File

@ -108,11 +108,7 @@ struct sharedMultiSlsDetector {
bool receiver_upstream; bool receiver_upstream;
}; };
class multiSlsDetector : public virtual slsDetectorDefs, class multiSlsDetector : public virtual slsDetectorDefs {
public virtual errorDefs {
// private:
public: public:
/** /**
* Constructor * Constructor
@ -480,13 +476,6 @@ class multiSlsDetector : public virtual slsDetectorDefs,
*/ */
int writeConfigurationFile(const std::string &fname); int writeConfigurationFile(const std::string &fname);
/**
* Returns the trimfile or settings file name (Useless??)
* @param detPos -1 for all detectors in list or specific detector position
* @returns the trimfile or settings file name
*/
std::string getSettingsFile(int detPos = -1);
/** /**
* Get detector settings * Get detector settings
* @param detPos -1 for all detectors in list or specific detector position * @param detPos -1 for all detectors in list or specific detector position
@ -1841,11 +1830,6 @@ class multiSlsDetector : public virtual slsDetectorDefs,
*/ */
int acquire(); int acquire();
/**
* Returns true if detector position is out of bounds
*/
bool isDetectorIndexOutOfBounds(int detPos);
/** /**
* Combines data from all readouts and gives it to the gui * Combines data from all readouts and gives it to the gui
* or just gives progress of acquisition by polling receivers * or just gives progress of acquisition by polling receivers

File diff suppressed because it is too large Load Diff

View File

@ -122,9 +122,6 @@ struct sharedSlsDetector {
/** readout flags */ /** readout flags */
slsDetectorDefs::readOutFlags roFlags; slsDetectorDefs::readOutFlags roFlags;
/** name root of the output files */
char settingsFile[MAX_STR_LENGTH];
/** detector settings (standard, fast, etc.) */ /** detector settings (standard, fast, etc.) */
slsDetectorDefs::detectorSettings currentSettings; slsDetectorDefs::detectorSettings currentSettings;
@ -245,7 +242,7 @@ struct sharedSlsDetector {
bool receiver_overWriteEnable; bool receiver_overWriteEnable;
}; };
class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs { class slsDetector : public virtual slsDetectorDefs{
public: public:
/** /**
* Constructor called when creating new shared memory * Constructor called when creating new shared memory
@ -328,11 +325,6 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
*/ */
std::string getHostname() const; std::string getHostname() const;
/**
* Could not connect to receiver, log error
*/
void connectDataError();
/** /**
* Get detector type by connecting to the detector * Get detector type by connecting to the detector
* @returns detector tpe or GENERIC if failed * @returns detector tpe or GENERIC if failed
@ -343,13 +335,13 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
* Get Detector type from shared memory variable * Get Detector type from shared memory variable
* @returns detector type from shared memory variable * @returns detector type from shared memory variable
*/ */
detectorType getDetectorTypeAsEnum(); detectorType getDetectorTypeAsEnum() const;
/** /**
* Gets string version of detector type from shared memory variable * Gets string version of detector type from shared memory variable
* @returns string version of detector type from shared memory variable * @returns string version of detector type from shared memory variable
*/ */
std::string getDetectorTypeAsString(); std::string getDetectorTypeAsString() const;
/** /**
* Gets detector type from detector and set it in receiver * Gets detector type from detector and set it in receiver
@ -362,7 +354,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
* Returns the total number of channels from shared memory * Returns the total number of channels from shared memory
* @returns the total number of channels * @returns the total number of channels
*/ */
int getTotalNumberOfChannels(); int getTotalNumberOfChannels() const;
/** /**
* Update total number of channels (chiptestboard or moench) * Update total number of channels (chiptestboard or moench)
@ -375,7 +367,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
* @param d dimension d * @param d dimension d
* @returns the total number of channels in dimension d * @returns the total number of channels in dimension d
*/ */
int getTotalNumberOfChannels(dimension d); int getTotalNumberOfChannels(dimension d) const;
/** /**
* Returns the total number of channels of in dimension d including gap pixels * Returns the total number of channels of in dimension d including gap pixels
@ -384,40 +376,40 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
* @returns the total number of channels including gap pixels in dimension d * @returns the total number of channels including gap pixels in dimension d
* including gap pixels * including gap pixels
*/ */
int getTotalNumberOfChannelsInclGapPixels(dimension d); int getTotalNumberOfChannelsInclGapPixels(dimension d) const;
/** /**
* returns the number of channels per chip from shared memory (Mythen) * returns the number of channels per chip from shared memory (Mythen)
* @returns number of channels per chip * @returns number of channels per chip
*/ */
int getNChans(); int getNChans() const;
/** /**
* returns the number of channels per chip in dimension d from shared memory (Mythen) * returns the number of channels per chip in dimension d from shared memory (Mythen)
* @param d dimension d * @param d dimension d
* @returns number of channels per chip in dimension d * @returns number of channels per chip in dimension d
*/ */
int getNChans(dimension d); int getNChans(dimension d) const;
/** /**
* returns the number of chips per module from shared memory (Mythen) * returns the number of chips per module from shared memory (Mythen)
* @returns number of chips per module * @returns number of chips per module
*/ */
int getNChips(); int getNChips() const;
/** /**
* returns the number of chips per module in dimension d from shared memory (Mythen) * returns the number of chips per module in dimension d from shared memory (Mythen)
* @param d dimension d * @param d dimension d
* @returns number of chips per module in dimension d * @returns number of chips per module in dimension d
*/ */
int getNChips(dimension d); int getNChips(dimension d) const;
/** /**
* Get Detector offset from shared memory in dimension d * Get Detector offset from shared memory in dimension d
* @param d dimension d * @param d dimension d
* @returns offset in dimension d * @returns offset in dimension d
*/ */
int getDetectorOffset(dimension d); int getDetectorOffset(dimension d) const;
/** /**
* Set Detector offset in shared memory in dimension d * Set Detector offset in shared memory in dimension d
@ -536,12 +528,6 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
*/ */
int writeConfigurationFile(std::ofstream &outfile, multiSlsDetector *m); int writeConfigurationFile(std::ofstream &outfile, multiSlsDetector *m);
/**
* Returns the trimfile or settings file name (Useless??)
* @returns the trimfile or settings file name
*/
std::string getSettingsFile();
/** /**
* Get detector settings * Get detector settings
* @returns current settings * @returns current settings
@ -1106,7 +1092,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
* @param d axis across which data is flipped * @param d axis across which data is flipped
* @returns 1 for flipped, else 0 * @returns 1 for flipped, else 0
*/ */
int getFlippedData(dimension d = X); int getFlippedData(dimension d = X) const;
/** /**
* Sets the enable which determines if * Sets the enable which determines if

View File

@ -3418,7 +3418,7 @@ std::string slsDetectorCommand::cmdSettings(int narg, char *args[], int action,
else else
return std::string("failed"); return std::string("failed");
} }
return myDet->getSettingsFile(detPos); return std::string("Specify file name for geting settings file");
} else if (cmd == "trimval") { } else if (cmd == "trimval") {
if (action == PUT_ACTION) { if (action == PUT_ACTION) {
if (sscanf(args[1], "%d", &val)) if (sscanf(args[1], "%d", &val))

View File

@ -7,6 +7,8 @@
*@short exceptions defined *@short exceptions defined
*/ */
#include "logger.h"
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
@ -14,8 +16,15 @@ namespace sls{
struct RuntimeError : public std::runtime_error { struct RuntimeError : public std::runtime_error {
public: public:
RuntimeError(): runtime_error("SLS Detector Package Failed") {} RuntimeError(): runtime_error("SLS Detector Package Failed") {
RuntimeError(std::string msg): runtime_error(msg) {} FILE_LOG(logERROR) << "SLS Detector Package Failed";
}
RuntimeError(std::string msg): runtime_error(msg) {
FILE_LOG(logERROR) << msg;
}
RuntimeError(const char* msg): runtime_error(msg) {
FILE_LOG(logERROR) << msg;
}
}; };
struct SharedMemoryError : public RuntimeError { struct SharedMemoryError : public RuntimeError {

View File

@ -19,7 +19,7 @@ ClientSocket::ClientSocket(const bool isRx, const std::string &host, uint16_t po
hints.ai_flags |= AI_CANONNAME; hints.ai_flags |= AI_CANONNAME;
if (getaddrinfo(host.c_str(), NULL, &hints, &result) != 0) { if (getaddrinfo(host.c_str(), NULL, &hints, &result) != 0) {
std::string msg = "ClientSocket ERROR: decode host:" + host + " on port " + std::to_string(port) + "\n"; std::string msg = "ClientSocket cannot decode host:" + host + " on port " + std::to_string(port) + "\n";
throw SocketError(msg); throw SocketError(msg);
} }
@ -32,7 +32,7 @@ ClientSocket::ClientSocket(const bool isRx, const std::string &host, uint16_t po
if (::connect(getSocketId(), (struct sockaddr *)&serverAddr, sizeof(serverAddr)) != 0) { if (::connect(getSocketId(), (struct sockaddr *)&serverAddr, sizeof(serverAddr)) != 0) {
freeaddrinfo(result); freeaddrinfo(result);
std::string msg = "ClientSocket ERROR: cannot connect to host:" + host + " on port " + std::to_string(port) + "\n"; std::string msg = "ClientSocket: cannot connect to host:" + host + " on port " + std::to_string(port) + "\n";
FILE_LOG(logERROR) << msg; FILE_LOG(logERROR) << msg;
throw SocketError(msg); throw SocketError(msg);
} }
@ -57,6 +57,7 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
receiveData(mess, sizeof(mess)); receiveData(mess, sizeof(mess));
// cprintf(RED, "%s %d returned error: %s", type.c_str(), index, mess); // cprintf(RED, "%s %d returned error: %s", type.c_str(), index, mess);
cprintf(RED, "%s returned error: %s", (isReceiver ? "Receiver" : "Detector"), mess); cprintf(RED, "%s returned error: %s", (isReceiver ? "Receiver" : "Detector"), mess);
std::cout << "\n"; //needed to reset the color.
// unrecognized function, do not ask for retval // unrecognized function, do not ask for retval
if (strstr(mess, "Unrecognized Function") != nullptr) if (strstr(mess, "Unrecognized Function") != nullptr)