kept the same client interface:tb changed when fixing error codes/exceptions, modified multi print, fixed roi bug in indexing to sls

This commit is contained in:
maliakal_d 2018-10-31 14:30:30 +01:00
parent 3d40d5d058
commit aec8c031de
8 changed files with 238 additions and 357 deletions

View File

@ -1,9 +1,9 @@
Path: slsDetectorPackage/slsDetectorServers/eigerDetectorServer
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repsitory UUID: 92fc837eb490650d91c2283943cbd729b2e36567
Revision: 6
Repsitory UUID: 3d40d5d0585931f7f4a42912dea82d26ca2b3ad0
Revision: 7
Branch: refactor
Last Changed Author: Dhanya_Thattil
Last Changed Rev: 4131
Last Changed Date: 2018-10-29 17:14:27.000000002 +0100 ./Beb.c
Last Changed Author: Erik_Frojdh
Last Changed Rev: 4154
Last Changed Date: 2018-10-30 12:17:09.000000002 +0100 ./FebInterface.c

View File

@ -1,6 +1,6 @@
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
#define GITREPUUID "92fc837eb490650d91c2283943cbd729b2e36567"
#define GITAUTH "Dhanya_Thattil"
#define GITREV 0x4131
#define GITDATE 0x20181029
#define GITREPUUID "3d40d5d0585931f7f4a42912dea82d26ca2b3ad0"
#define GITAUTH "Erik_Frojdh"
#define GITREV 0x4154
#define GITDATE 0x20181030
#define GITBRANCH "refactor"

View File

@ -151,18 +151,11 @@ std::string multiSlsDetector::getErrorMessage(int &critical, int detPos) {
if ((multiMask & (1 << idet)) || (detPos >= 0)) {
// append detector id
// sprintf(sNumber, "%ld", idet);
retval.append("Detector " + std::to_string(idet) +
std::string(":\n"));
// get sls det error mask
slsMask = detectors[idet]->getErrorMask();
#ifdef VERYVERBOSE
// append sls det error mask
// sprintf(sNumber, "0x%lx", slsMask);
retval.append("Error Mask " + std::to_string(slsMask) +
std::string("\n"));
#endif
// get the error critical level
if ((slsMask > 0xFFFFFFFF) | critical)
@ -207,10 +200,9 @@ bool multiSlsDetector::getAcquiringFlag() const {
bool multiSlsDetector::isAcquireReady() {
if (thisMultiDetector->acquiringFlag) {
std::cout << "Acquire has already started. "
FILE_LOG(logWARNING) << "Acquire has already started. "
"If previous acquisition terminated unexpectedly, "
"reset busy flag to restart.(sls_detector_put busy 0)"
<< std::endl;
"reset busy flag to restart.(sls_detector_put busy 0)";
return FAIL;
}
thisMultiDetector->acquiringFlag = true;
@ -329,10 +321,9 @@ void multiSlsDetector::initSharedMemory(bool verify) {
thisMultiDetector =
(sharedMultiSlsDetector *)sharedMemory->OpenSharedMemory(sz);
if (verify && thisMultiDetector->shmversion != MULTI_SHMVERSION) {
cprintf(RED,
"Multi shared memory (%d) version mismatch "
"(expected 0x%x but got 0x%x)\n",
detId, MULTI_SHMVERSION, thisMultiDetector->shmversion);
FILE_LOG(logERROR) << "Multi shared memory (" << detId << ") version mismatch "
"(expected 0x" << std::hex << MULTI_SHMVERSION <<
" but got 0x" << thisMultiDetector->shmversion << std::dec;
throw SharedMemoryException();
}
}
@ -443,8 +434,8 @@ void multiSlsDetector::setHostname(const char *name, int detPos) {
// multi
// this check is there only to allow the previous detsizechan command
if (thisMultiDetector->numberOfDetectors) {
cprintf(RED, "Warning: There are already detector(s) in shared memory."
"Freeing Shared memory now.\n");
FILE_LOG(logWARNING) << "There are already detector(s) in shared memory."
"Freeing Shared memory now.";
freeSharedMemory();
setupMultiDetector();
}
@ -471,15 +462,13 @@ void multiSlsDetector::addMultipleDetectors(const char *name) {
}
void multiSlsDetector::addSlsDetector(std::string s) {
#ifdef VERBOSE
std::cout << "Adding detector " << s << std::endl;
#endif
FILE_LOG(logDEBUG1) << "Adding detector " << s;
for (auto &d : detectors) {
if (d->getHostname() == s) {
std::cout << "Detector " << s
FILE_LOG(logWARNING) << "Detector " << s
<< "already part of the multiDetector!" << std::endl
<< "Remove it before adding it back in a new position!"
<< std::endl;
<< "Remove it before adding it back in a new position!";
return;
}
}
@ -491,8 +480,8 @@ void multiSlsDetector::addSlsDetector(std::string s) {
// get type by connecting
detectorType type = slsDetector::getDetectorType(s.c_str(), DEFAULT_PORTNO);
if (type == GENERIC) {
std::cout << "Could not connect to Detector " << s
<< " to determine the type!" << std::endl;
FILE_LOG(logERROR) << "Could not connect to Detector " << s
<< " to determine the type!";
setErrorMask(getErrorMask() | MULTI_DETECTORS_NOT_ADDED);
appendNotAddedList(s.c_str());
return;
@ -595,11 +584,8 @@ void multiSlsDetector::setDetectorOffset(dimension d, int off, int detPos) {
}
void multiSlsDetector::updateOffsets() {
// cannot paralllize due to slsdetector calling this via parentdet->
#ifdef VERBOSE
std::cout << std::endl
<< "Updating Multi-Detector Offsets" << std::endl;
#endif
FILE_LOG(logDEBUG1) << "Updating Multi-Detector Offsets";
int offsetX = 0, offsetY = 0, numX = 0, numY = 0;
int maxChanX = thisMultiDetector->maxNumberOfChannelsPerDetector[X];
int maxChanY = thisMultiDetector->maxNumberOfChannelsPerDetector[Y];
@ -619,43 +605,27 @@ void multiSlsDetector::updateOffsets() {
thisMultiDetector->numberOfChannelInclGapPixels[Y] = 0;
for (size_t idet = 0; idet < detectors.size(); ++idet) {
#ifdef VERBOSE
std::cout << "offsetX:" << offsetX << " prevChanX:" << prevChanX
<< " "
"offsetY:"
<< offsetY << " prevChanY:" << prevChanY << std::endl;
std::cout << "offsetX_gp:" << offsetX_gp
<< " "
"prevChanX_gp:"
<< prevChanX_gp
<< " "
"offsetY_gp:"
<< offsetY_gp
<< " "
"prevChanY_gp:"
<< prevChanY_gp << std::endl;
#endif
// std::cout<<" totalchan:"<<
// detectors[idet]->getTotalNumberOfChannels(Y)
//<<" maxChanY:"<<maxChanY<<std::endl;
FILE_LOG(logDEBUG1) << "offsetX:" << offsetX << " prevChanX:" << prevChanX <<
" offsetY:" << offsetY << " prevChanY:" << prevChanY <<
" offsetX_gp:" << offsetX_gp << " prevChanX_gp:" << prevChanX_gp <<
" offsetY_gp:" << offsetY_gp << " prevChanY_gp:" << prevChanY_gp;
// incrementing in both direction
if (firstTime) {
// incrementing in both directions
firstTime = false;
if ((maxChanX > 0) &&
((offsetX + detectors[idet]->getTotalNumberOfChannels(X)) >
maxChanX))
std::cout << "\nDetector[" << idet
((offsetX + detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) {
FILE_LOG(logWARNING) << "\nDetector[" << idet
<< "] exceeds maximum channels "
"allowed for complete detector set in X dimension!"
<< std::endl;
"allowed for complete detector set in X dimension!";
}
if ((maxChanY > 0) &&
((offsetY + detectors[idet]->getTotalNumberOfChannels(Y)) >
maxChanY))
std::cout << "\nDetector[" << idet
((offsetY + detectors[idet]->getTotalNumberOfChannels(Y)) > maxChanY)) {
FILE_LOG(logERROR) << "\nDetector[" << idet
<< "] exceeds maximum channels "
"allowed for complete detector set in Y dimension!"
<< std::endl;
"allowed for complete detector set in Y dimension!";
}
prevChanX = detectors[idet]->getTotalNumberOfChannels(X);
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
prevChanX_gp =
@ -670,9 +640,7 @@ void multiSlsDetector::updateOffsets() {
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
++thisMultiDetector->numberOfDetector[X];
++thisMultiDetector->numberOfDetector[Y];
#ifdef VERBOSE
std::cout << "incrementing in both direction" << std::endl;
#endif
FILE_LOG(logDEBUG1) << "incrementing in both direction";
}
// incrementing in y direction
@ -689,20 +657,18 @@ void multiSlsDetector::updateOffsets() {
numY_gp +=
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
++thisMultiDetector->numberOfDetector[Y];
#ifdef VERBOSE
std::cout << "incrementing in y direction" << std::endl;
#endif
FILE_LOG(logDEBUG1) << "incrementing in y direction";
}
// incrementing in x direction
else {
if ((maxChanX > 0) &&
((offsetX + prevChanX +
detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX))
std::cout << "\nDetector[" << idet
detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) {
FILE_LOG(logDEBUG1) << "\nDetector[" << idet
<< "] exceeds maximum channels "
"allowed for complete detector set in X dimension!"
<< std::endl;
"allowed for complete detector set in X dimension!";
}
offsetY = 0;
offsetY_gp = 0;
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
@ -720,9 +686,7 @@ void multiSlsDetector::updateOffsets() {
numX_gp +=
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
++thisMultiDetector->numberOfDetector[X];
#ifdef VERBOSE
std::cout << "incrementing in x direction" << std::endl;
#endif
FILE_LOG(logDEBUG1) << "incrementing in x direction";
}
double bytesperchannel =
@ -734,11 +698,9 @@ void multiSlsDetector::updateOffsets() {
detectors[idet]->setDetectorOffset(
Y, (bytesperchannel >= 1.0) ? offsetY_gp : offsetY);
#ifdef VERBOSE
std::cout << "Detector[" << idet << "] has offsets ("
FILE_LOG(logDEBUG1) << "Detector[" << idet << "] has offsets ("
<< detectors[idet]->getDetectorOffset(X) << ", "
<< detectors[idet]->getDetectorOffset(Y) << ")" << std::endl;
#endif
<< detectors[idet]->getDetectorOffset(Y) << ")";
// offsetY has been reset sometimes and offsetX the first time,
// but remember the highest values
if (numX > thisMultiDetector->numberOfChannel[X])
@ -750,19 +712,15 @@ void multiSlsDetector::updateOffsets() {
if (numY_gp > thisMultiDetector->numberOfChannelInclGapPixels[Y])
thisMultiDetector->numberOfChannelInclGapPixels[Y] = numY_gp;
}
#ifdef VERBOSE
std::cout << "Number of Channels in X direction:"
<< thisMultiDetector->numberOfChannel[X] << std::endl;
std::cout << "Number of Channels in Y direction:"
<< thisMultiDetector->numberOfChannel[Y] << std::endl
<< std::endl;
std::cout << "Number of Channels in X direction with Gap Pixels:"
<< thisMultiDetector->numberOfChannelInclGapPixels[X]
<< std::endl;
std::cout << "Number of Channels in Y direction with Gap Pixels:"
<< thisMultiDetector->numberOfChannelInclGapPixels[Y] << std::endl
<< std::endl;
#endif
FILE_LOG(logDEBUG1) << "\n\tNumber of Channels in X direction:" <<
thisMultiDetector->numberOfChannel[X] <<
"\n\tNumber of Channels in Y direction:" <<
thisMultiDetector->numberOfChannel[Y] <<
"\n\tNumber of Channels in X direction with Gap Pixels:" <<
thisMultiDetector->numberOfChannelInclGapPixels[X] <<
"\n\tNumber of Channels in Y direction with Gap Pixels:" <<
thisMultiDetector->numberOfChannelInclGapPixels[Y];
thisMultiDetector->numberOfChannels =
thisMultiDetector->numberOfChannel[0] *
thisMultiDetector->numberOfChannel[1];
@ -853,7 +811,7 @@ int multiSlsDetector::readConfigurationFile(const std::string &fname) {
char *args[100];
char myargs[100][1000];
std::cout << "Loading configuration file: " << fname << std::endl;
FILE_LOG(logINFO) << "Loading configuration file: " << fname;
std::ifstream input_file;
input_file.open(fname, std::ios_base::in);
@ -863,10 +821,7 @@ int multiSlsDetector::readConfigurationFile(const std::string &fname) {
getline(input_file, current_line);
if (current_line.find('#') != std::string::npos)
current_line.erase(current_line.find('#'));
#ifdef VERBOSE
std::cout << "current_line after removing comments:" << current_line
<< std::endl;
#endif
FILE_LOG(logDEBUG1) << "current_line after removing comments:\n\t" << current_line;
if (current_line.length() > 1) {
std::istringstream line_stream(current_line);
int n_arguments = 0;
@ -882,17 +837,15 @@ int multiSlsDetector::readConfigurationFile(const std::string &fname) {
}
input_file.close();
} else {
std::cout << "Error opening configuration file " << fname
<< " for reading" << std::endl;
FILE_LOG(logERROR) << "Could not openconfiguration file " << fname << " for reading";
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);
return FAIL;
}
if (getErrorMask()) {
int c;
cprintf(RED,
"\n----------------\n Error Messages\n----------------\n%s\n",
getErrorMessage(c).c_str());
FILE_LOG(logERROR) << "----------------\n Error Messages\n----------------";
FILE_LOG(logERROR) << getErrorMessage(c);
return FAIL;
}
return OK;
@ -915,14 +868,14 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
auto cmd = slsDetectorCommand(this);
// complete size of detector
std::cout << iline << " " << names[iline] << std::endl;
FILE_LOG(logINFO) << "Command to write: " << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION)
<< std::endl;
++iline;
// hostname of the detectors
std::cout << iline << " " << names[iline] << std::endl;
FILE_LOG(logINFO) << "Command to write: " << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION)
<< std::endl;
@ -941,20 +894,16 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
outfile << std::endl;
// other configurations
while (iline < names.size()) {
std::cout << iline << " " << names[iline] << std::endl;
FILE_LOG(logINFO) << "Command to write:" << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " "
<< cmd.executeLine(1, args, GET_ACTION) << std::endl;
++iline;
}
outfile.close();
#ifdef VERBOSE
std::cout << "wrote " << iline << " lines to configuration file "
<< std::endl;
#endif
FILE_LOG(logDEBUG1) << "wrote " << iline << " lines to configuration file ";
} else {
std::cout << "Error opening configuration file " << fname
<< " for writing" << std::endl;
FILE_LOG(logERROR) << "Could not open configuration file " << fname << " for writing";
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);
ret = FAIL;
}
@ -1818,14 +1767,14 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
}
// multi
int i, xmin, xmax, ymin, ymax, channelX, channelY, idet, lastChannelX,
int xmin, xmax, ymin, ymax, channelX, channelY, idet, lastChannelX,
lastChannelY, index, offsetX, offsetY;
bool invalidroi = false;
int ndet = detectors.size();
ROI allroi[ndet][n];
int nroi[ndet];
for (i = 0; i < ndet; ++i)
for (int i = 0; i < ndet; ++i)
nroi[i] = 0;
if ((n < 0) || (roiLimits == NULL))
@ -1833,15 +1782,12 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
// ensures min < max
verifyMinMaxROI(n, roiLimits);
#ifdef VERBOSE
std::cout << "Setting ROI for " << n << "rois:" << std::endl;
for (i = 0; i < n; ++i)
std::cout << i << ":" << roiLimits[i].xmin << "\t" << roiLimits[i].xmax
<< "\t" << roiLimits[i].ymin << "\t" << roiLimits[i].ymax
<< std::endl;
#endif
FILE_LOG(logDEBUG1) << "Setting ROI for " << n << "rois:";
for (int i = 0; i < n; ++i)
FILE_LOG(logDEBUG1) << i << ":" << roiLimits[i].xmin << "\t" << roiLimits[i].xmax
<< "\t" << roiLimits[i].ymin << "\t" << roiLimits[i].ymax;
// for each roi
for (i = 0; i < n; ++i) {
for (int i = 0; i < n; ++i) {
xmin = roiLimits[i].xmin;
xmax = roiLimits[i].xmax;
ymin = roiLimits[i].ymin;
@ -1849,13 +1795,11 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
// check roi max values
idet = decodeNChannel(xmax, ymax, channelX, channelY);
#ifdef VERBOSE
std::cout << "Decoded Channel max vals: " << std::endl;
std::cout << "det:" << idet << "\t" << xmax << "\t" << ymax << "\t"
<< channelX << "\t" << channelY << std::endl;
#endif
FILE_LOG(logDEBUG1) << "Decoded Channel max vals: " << std::endl <<
"det:" << idet << "\t" << xmax << "\t" << ymax << "\t" <<
channelX << "\t" << channelY;
if (idet == -1) {
std::cout << "invalid roi" << std::endl;
FILE_LOG(logERROR) << "invalid roi";
continue;
}
@ -1867,13 +1811,11 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
while (ymin <= ymax) {
// get offset for each detector
idet = decodeNChannel(xmin, ymin, channelX, channelY);
#ifdef VERBOSE
std::cout << "Decoded Channel min vals: " << std::endl;
std::cout << "det:" << idet << "\t" << xmin << "\t" << ymin
<< "\t" << channelX << "\t" << channelY << std::endl;
#endif
FILE_LOG(logDEBUG1) << "Decoded Channel min vals: " << std::endl <<
"det:" << idet << "\t" << xmin << "\t" << ymin <<
"\t" << channelX << "\t" << channelY;
if (idet < 0 || idet >= (int)detectors.size()) {
std::cout << "invalid roi" << std::endl;
FILE_LOG(logDEBUG1) << "invalid roi";
invalidroi = true;
break;
}
@ -1896,10 +1838,8 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
if ((offsetY + lastChannelY) >= ymax)
lastChannelY = ymax - offsetY;
#ifdef VERBOSE
std::cout << "lastChannelX:" << lastChannelX << "\t"
<< "lastChannelY:" << lastChannelY << std::endl;
#endif
FILE_LOG(logDEBUG1) << "lastChannelX:" << lastChannelX << "\t" <<
"lastChannelY:" << lastChannelY;
// creating the list of roi for corresponding detector
index = nroi[idet];
@ -1913,10 +1853,7 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
if ((lastChannelY + offsetY) == ymax)
ymin = ymax + 1;
#ifdef VERBOSE
std::cout << "nroi[idet]:" << nroi[idet] << "\tymin:" << ymin
<< std::endl;
#endif
FILE_LOG(logDEBUG1) << "nroi[idet]:" << nroi[idet] << "\tymin:" << ymin;
}
if (invalidroi)
break;
@ -1927,22 +1864,19 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
}
}
#ifdef VERBOSE
std::cout << "Setting ROI :" << std::endl;
for (i = 0; i < detectors.size(); ++i) {
std::cout << "detector " << i << std::endl;
FILE_LOG(logDEBUG1) << "Setting ROI :";
for (size_t i = 0; i < detectors.size(); ++i) {
FILE_LOG(logDEBUG1) << "detector " << i;
for (int j = 0; j < nroi[i]; ++j) {
std::cout << allroi[i][j].xmin << "\t" << allroi[i][j].xmax << "\t"
<< allroi[i][j].ymin << "\t" << allroi[i][j].ymax
<< std::endl;
FILE_LOG(logDEBUG1) << allroi[i][j].xmin << "\t" << allroi[i][j].xmax << "\t"
<< allroi[i][j].ymin << "\t" << allroi[i][j].ymax;
}
}
#endif
// settings the rois for each detector
std::vector<int> r;
for (size_t idet = 0; idet < detectors.size(); ++idet) {
r.push_back(detectors[idet]->setROI(nroi[i], allroi[i]));
r.push_back(detectors[idet]->setROI(nroi[idet], allroi[idet]));
}
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
}
@ -1968,15 +1902,12 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
for (size_t idet = 0; idet < detectors.size(); ++idet) {
temp = detectors[idet]->getROI(index);
if (temp) {
//#ifdef VERBOSE
if (index)
std::cout << "detector " << idet << ":" << std::endl;
//#endif
if (index) {
FILE_LOG(logINFO) << "detector " << idet << ":";
}
for (j = 0; j < index; ++j) {
//#ifdef VERBOSE
std::cout << temp[j].xmin << "\t" << temp[j].xmax << "\t"
<< temp[j].ymin << "\t" << temp[j].ymax << std::endl;
//#endif
FILE_LOG(logINFO) << temp[j].xmin << "\t" << temp[j].xmax << "\t"
<< temp[j].ymin << "\t" << temp[j].ymax;
int x = detectors[idet]->getDetectorOffset(X);
int y = detectors[idet]->getDetectorOffset(Y);
roiLimits[n].xmin = temp[j].xmin + x;
@ -1992,14 +1923,12 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
if (!n)
return NULL;
#ifdef VERBOSE
std::cout << "ROI :" << std::endl;
FILE_LOG(logDEBUG1) << "ROI :" << std::endl;
for (int j = 0; j < n; ++j) {
std::cout << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t"
<< roiLimits[j].ymin << "\t" << roiLimits[j].ymax
<< std::endl;
FILE_LOG(logDEBUG1) << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t"
<< roiLimits[j].ymin << "\t" << roiLimits[j].ymax;
}
#endif
// combine all the adjacent rois in x direction
for (i = 0; i < n; ++i) {
@ -2033,15 +1962,11 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
}
}
#ifdef VERBOSE
std::cout << "Combined along x axis Getting ROI :" << std::endl;
std::cout << "detector " << i << std::endl;
FILE_LOG(logDEBUG1) << "Combined along x axis Getting ROI :\ndetector " << i;
for (int j = 0; j < n; ++j) {
std::cout << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t"
<< roiLimits[j].ymin << "\t" << roiLimits[j].ymax
<< std::endl;
FILE_LOG(logDEBUG1) << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t"
<< roiLimits[j].ymin << "\t" << roiLimits[j].ymax;
}
#endif
// combine all the adjacent rois in y direction
for (i = 0; i < n; ++i) {
@ -2094,10 +2019,10 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
}
n = num;
std::cout << "\nxmin\txmax\tymin\tymax" << std::endl;
FILE_LOG(logDEBUG1) << "\nxmin\txmax\tymin\tymax";
for (i = 0; i < n; ++i)
std::cout << retval[i].xmin << "\t" << retval[i].xmax << "\t"
<< retval[i].ymin << "\t" << retval[i].ymax << std::endl;
FILE_LOG(logDEBUG1) << retval[i].xmin << "\t" << retval[i].xmax << "\t"
<< retval[i].ymin << "\t" << retval[i].ymax;
return retval;
}
@ -2689,7 +2614,7 @@ int multiSlsDetector::resetFramesCaught(int detPos) {
int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
if (destroy) {
cprintf(MAGENTA, "Going to destroy data sockets\n");
FILE_LOG(logINFO) << "Going to destroy data sockets";
// close socket
zmqSocket.clear();
@ -2698,7 +2623,7 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
return OK;
}
cprintf(MAGENTA, "Going to create data sockets\n");
FILE_LOG(logINFO) << "Going to create data sockets";
size_t numSockets = detectors.size();
size_t numSocketsPerDetector = 1;
@ -2717,11 +2642,10 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
->getClientStreamingIP()
.c_str(),
portnum));
printf("Zmq Client[%lu] at %s\n", iSocket,
zmqSocket.back()->GetZmqServerAddress());
FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at " <<
zmqSocket.back()->GetZmqServerAddress();
} catch (...) {
cprintf(RED, "Error: Could not create Zmq socket on port %d\n",
portnum);
FILE_LOG(logERROR) << "Could not create Zmq socket on port " << portnum;
createReceivingDataSockets(true);
return FAIL;
}
@ -2756,8 +2680,7 @@ void multiSlsDetector::readFrameFromReceiver() {
} else {
// to remember the list it connected to, to disconnect later
connectList[i] = false;
cprintf(RED, "Error: Could not connect to socket %s\n",
zmqSocket[i]->GetZmqServerAddress());
FILE_LOG(logERROR) << "Could not connect to socket " << zmqSocket[i]->GetZmqServerAddress();
runningList[i] = false;
}
}
@ -2822,18 +2745,14 @@ void multiSlsDetector::readFrameFromReceiver() {
nPixelsX = doc["shape"][0].GetUint();
nPixelsY = doc["shape"][1].GetUint();
#ifdef VERBOSE
cprintf(BLUE,
"(Debug) One Time Header Info:\n"
"size: %u\n"
"multisize: %u\n"
"dynamicRange: %u\n"
"bytesPerPixel: %f\n"
"nPixelsX: %u\n"
"nPixelsY: %u\n",
size, multisize, dynamicRange, bytesPerPixel,
nPixelsX, nPixelsY);
#endif
FILE_LOG(logDEBUG1) <<
"One Time Header Info:"
"\n\tsize: " << size <<
"\n\tmultisize: " << multisize <<
"\n\tdynamicRange: " << dynamicRange <<
"\n\tbytesPerPixel: " << bytesPerPixel <<
"\n\tnPixelsX: " << nPixelsX <<
"\n\tnPixelsY: " << nPixelsY;
}
// each time, parse rest of header
currentFileName = doc["fname"].GetString();
@ -2845,24 +2764,17 @@ void multiSlsDetector::readFrameFromReceiver() {
coordX = doc["column"].GetUint();
if (eiger)
coordY = (nY - 1) - coordY;
// std::cout << "X:" << doc["row"].GetUint() <<"
// Y:"<<doc["column"].GetUint();
flippedDataX = doc["flippedDataX"].GetUint();
#ifdef VERBOSE
cprintf(BLUE,
"(Debug) Header Info:\n"
"currentFileName: %s\n"
"currentAcquisitionIndex: %lu\n"
"currentFrameIndex: %lu\n"
"currentFileIndex: %lu\n"
"currentSubFrameIndex: %u\n"
"coordX: %u\n"
"coordY: %u\n"
"flippedDataX: %u\n",
currentFileName.c_str(), currentAcquisitionIndex,
currentFrameIndex, currentFileIndex,
currentSubFrameIndex, coordX, coordY, flippedDataX);
#endif
FILE_LOG(logDEBUG1) <<
"Header Info:"
"\n\tcurrentFileName: " << currentFileName <<
"\n\tcurrentAcquisitionIndex: " << currentAcquisitionIndex <<
"\n\tcurrentFrameIndex: " << currentFrameIndex <<
"\n\tcurrentFileIndex: " << currentFileIndex <<
"\n\tcurrentSubFrameIndex: " << currentSubFrameIndex <<
"\n\tcoordX: " << coordX <<
"\n\tcoordY: " << coordY <<
"\n\tflippedDataX: " << flippedDataX;
}
// DATA
@ -2875,15 +2787,13 @@ void multiSlsDetector::readFrameFromReceiver() {
uint32_t yoffset = coordY * nPixelsY;
uint32_t singledetrowoffset = nPixelsX * bytesPerPixel;
uint32_t rowoffset = nX * singledetrowoffset;
#ifdef VERBOSE
cprintf(BLUE,
"(Debug) Multi Image Info:\n"
"xoffset: %u\n"
"yoffset: %u\n"
"singledetrowoffset: %u\n"
"rowoffset: %u\n",
xoffset, yoffset, singledetrowoffset, rowoffset);
#endif
FILE_LOG(logDEBUG1) <<
"Multi Image Info:"
"\n\txoffset: " << xoffset <<
"\n\tyoffset: " << yoffset <<
"\n\tsingledetrowoffset: " << singledetrowoffset <<
"\n\trowoffset: " << rowoffset;
if (eiger && flippedDataX) {
for (uint32_t i = 0; i < nPixelsY; ++i) {
memcpy(((char *)multiframe) +
@ -3288,9 +3198,7 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
int iline = 0;
if (level == 2) {
#ifdef VERBOSE
std::cout << "config file read" << std::endl;
#endif
FILE_LOG(logDEBUG1) << "config file read";
fname = fname1 + std::string(".det");
} else
fname = fname1;
@ -3303,14 +3211,9 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
sargval = "0";
getline(infile, str);
iline++;
#ifdef VERBOSE
std::cout << str << std::endl;
#endif
FILE_LOG(logDEBUG1) << str;
if (str.find('#') != std::string::npos) {
#ifdef VERBOSE
std::cout << "Line is a comment " << std::endl;
std::cout << str << std::endl;
#endif
FILE_LOG(logDEBUG1) << "Line is a comment \n" << str;
continue;
} else {
std::istringstream ssstr(str);
@ -3320,9 +3223,7 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
// if (ssstr.good()) {
strcpy(myargs[iargval], sargname.c_str());
args[iargval] = myargs[iargval];
#ifdef VERBOSE
std::cout << args[iargval] << std::endl;
#endif
FILE_LOG(logDEBUG1) << args[iargval];
iargval++;
// }
skip = 0;
@ -3340,12 +3241,10 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
infile.close();
} else {
std::cout << "Error opening " << fname << " for reading" << std::endl;
FILE_LOG(logERROR) << "Error opening " << fname << " for reading";
return FAIL;
}
#ifdef VERBOSE
std::cout << "Read " << iline << " lines" << std::endl;
#endif
FILE_LOG(logDEBUG1) << "Read " << iline << " lines";
if (getErrorMask())
return FAIL;
@ -3457,14 +3356,11 @@ int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) {
}
outfile.close();
} else {
std::cout << "Error opening parameters file " << fname1
<< " for writing" << std::endl;
FILE_LOG(logERROR) << "Could not open parameters file " << fname1 << " for writing";
return FAIL;
}
#ifdef VERBOSE
std::cout << "wrote " << iv << " lines to " << fname1 << std::endl;
#endif
FILE_LOG(logDEBUG1) << "wrote " << iv << " lines to " << fname1;
return OK;
}
@ -3515,13 +3411,8 @@ int multiSlsDetector::setTotalProgress() {
totalProgress = nm * nf * nc * ns;
#ifdef VERBOSE
std::cout << "nm " << nm << std::endl;
std::cout << "nf " << nf << std::endl;
std::cout << "nc " << nc << std::endl;
std::cout << "ns " << ns << std::endl;
std::cout << "Set total progress " << totalProgress << std::endl;
#endif
FILE_LOG(logDEBUG1) << "nm " << nm << " nf " << nf << " nc " << nc << " ns " << ns;
FILE_LOG(logDEBUG1) << "Set total progress " << totalProgress << std::endl;
return totalProgress;
}
@ -3553,10 +3444,8 @@ int multiSlsDetector::acquire() {
if (isAcquireReady() == FAIL)
return FAIL;
#ifdef VERBOSE
struct timespec begin, end;
clock_gettime(CLOCK_REALTIME, &begin);
#endif
// in the real time acquisition loop, processing thread will wait for a post
// each time
@ -3601,7 +3490,7 @@ int multiSlsDetector::acquire() {
if (receiver) {
std::lock_guard<std::mutex> lock(mg);
if (startReceiver() == FAIL) {
std::cout << "Start receiver failed " << std::endl;
FILE_LOG(logERROR) << "Start receiver failed ";
stopReceiver();
thisMultiDetector->stoppedFlag = 1;
break;
@ -3651,13 +3540,11 @@ int multiSlsDetector::acquire() {
sem_destroy(&sem_newRTAcquisition);
sem_destroy(&sem_endRTAcquisition);
#ifdef VERBOSE
clock_gettime(CLOCK_REALTIME, &end);
std::cout << "Elapsed time for acquisition:"
FILE_LOG(logDEBUG1) << "Elapsed time for acquisition:"
<< ((end.tv_sec - begin.tv_sec) +
(end.tv_nsec - begin.tv_nsec) / 1000000000.0)
<< " seconds" << std::endl;
#endif
<< " seconds";
setAcquiringFlag(false);
@ -3688,8 +3575,7 @@ void multiSlsDetector::processData() {
// to exit acquire by typing q
if (kbhit() != 0) {
if (fgetc(stdin) == 'q') {
std::cout << "Caught the command to stop acquisition"
<< std::endl;
FILE_LOG(logINFO) << "Caught the command to stop acquisition";
stopAcquisition();
}
}

View File

@ -648,16 +648,19 @@ void slsDetector::disconnectControl() {
controlSocket->Disconnect();
}
void slsDetector::connectDataError() {
FILE_LOG(logERROR) << "Cannot connect to receiver";
setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER));
}
int slsDetector::connectData() {
if (dataSocket) {
if (dataSocket->Connect() >= 0)
return OK;
else {
FILE_LOG(logERROR) << "Cannot connect to receiver";
setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER));
return FAIL;}
connectDataError();
return FAIL;
}
}
return UNDEFINED;
}

View File

@ -353,6 +353,11 @@ public:
*/
void disconnectControl();
/**
* Could not connect to receiver, log error
*/
void connectDataError();
/**
* Connect to the data port
* @returns OK, FAIL or undefined

View File

@ -14,22 +14,33 @@ void ClientInterface::SetSocket(MySocketTCP *socket) {
}
int ClientInterface::Client_GetMesage(char* mess) {
void ClientInterface::Client_Receive(int& ret, char* mess, void* retval, int sizeOfRetval) {
// get result of operation
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
bool unrecognizedFunction = false;
if (ret == FAIL) {
bool created = false;
int ret = OK;
// allocate mess if null
if (!mess){
created = true;
mess = new char[MAX_STR_LENGTH];
memset(mess, 0, MAX_STR_LENGTH);
}
// get error message
mySocket->ReceiveDataOnly(mess,MAX_STR_LENGTH);
cprintf(RED, "%s %d returned error: %s", type.c_str(), index, mess);
if(strstr(mess,"Unrecognized Function")!=NULL)
ret = FAIL;
// unrecognized function, do not ask for retval
if(strstr(mess,"Unrecognized Function") != NULL)
unrecognizedFunction = true;
// delete allocated mess
if (created)
delete [] mess;
return ret;
}
// get retval
if (!unrecognizedFunction)
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
}
@ -37,18 +48,10 @@ int ClientInterface::Client_Send(int fnum,
void* args, int sizeOfArgs,
void* retval, int sizeOfRetval,
char* mess) {
int ret = FAIL;
mySocket->SendDataOnly(&fnum,sizeof(fnum));
mySocket->SendDataOnly(args, sizeOfArgs);
int ret = FAIL;
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret == FAIL) {
if (Client_GetMesage(mess) == FAIL)
return FAIL;
}
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
Client_Receive(ret, mess, retval, sizeOfRetval);
return ret;
}

View File

@ -34,23 +34,23 @@ public:
void SetSocket(MySocketTCP *socket);
/**
* Get message from server
* Print appropriate message
* Check for Unrecognized function in message and return fail if it does
* to prevent getting retval from the server afterwards
* @param mess message
* @returns FAIL if unrecognized function found in message, else OK
* Receive ret, mess or retval from Server
* @param ret result of operation
* @param mess pointer to message
* @param retval poitner to retval
* @param sizeOfRetval size of retval
*/
int Client_GetMesage(char* mess = 0);
void Client_Receive(int& ret, char* mess, void* retval, int sizeOfRetval);
/**
* Send Arguments to server and get result back
* Send Arguments to server and receives result back
* @param fnum function enum to determine what parameter
* @param args pointer to arguments
* @param sizeOfArgs argument size
* @param retval pointer to return value
* @param sizeOfRetval return value size
* @param mess pointer to message if message required externally
* @returns sucess of operation
*/
int Client_Send(int fnum,
void* args, int sizeOfArgs,

View File

@ -150,7 +150,7 @@ public:
sockfd.fd = socket(AF_INET, getProtocol(),0); //tcp
if (sockfd.fd < 0) {
cprintf(RED, "Can not create socket\n");
FILE_LOG(logERROR) << "Can not create socket";
sockfd.fd =-1;
throw SocketException();
}
@ -173,7 +173,7 @@ public:
int val=1;
if (setsockopt(sockfd.fd,SOL_SOCKET,SO_REUSEADDR,
&val,sizeof(int)) == -1) {
cprintf(RED, "setsockopt REUSEADDR failed\n");
FILE_LOG(logERROR) << "setsockopt REUSEADDR failed";
sockfd.fd =-1;
throw SocketException();
}
@ -192,10 +192,8 @@ public:
"Could not get rx socket receive buffer size";
} else if (ret_size >= real_size) {
actual_udp_socket_buffer_size = ret_size;
#ifdef VEBOSE
FILE_LOG(logINFO) << "[Port " << port_number << "] "
FILE_LOG(logDEBUG1) << "[Port " << port_number << "] "
"UDP rx socket buffer size is sufficient (" << ret_size << ")";
#endif
}
// not sufficient, enhance size
@ -244,7 +242,7 @@ public:
if(bind(sockfd.fd,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
cprintf(RED, "Can not bind socket\n");
FILE_LOG(logERROR) << "Can not bind socket";
sockfd.fd =-1;
throw SocketException();
}
@ -313,7 +311,7 @@ public:
case UDP:
return SOCK_DGRAM;
default:
cprintf(RED, "unknown protocol %d\n", p);
FILE_LOG(logERROR) << "unknown protocol: " << p;
return -1;
}
};
@ -365,74 +363,70 @@ public:
if(is_a_server && protocol==TCP){ //server tcp; the server will wait for the clients connection
if (sockfd.fd>0) {
if ((sockfd.newfd = accept(sockfd.fd,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) {
cprintf(RED, "Error: with server accept, connection refused\n");
FILE_LOG(logERROR) << "with server accept, connection refused";
switch(errno) {
case EWOULDBLOCK:
printf("ewouldblock eagain\n");
FILE_LOG(logERROR) << "ewouldblock eagain";
break;
case EBADF:
printf("ebadf\n");
FILE_LOG(logERROR) << "ebadf";
break;
case ECONNABORTED:
printf("econnaborted\n");
FILE_LOG(logERROR) << "econnaborted";
break;
case EFAULT:
printf("efault\n");
FILE_LOG(logERROR) << "efault";
break;
case EINTR:
printf("eintr\n");
FILE_LOG(logERROR) << "eintr";
break;
case EINVAL:
printf("einval\n");
FILE_LOG(logERROR) << "einval";
break;
case EMFILE:
printf("emfile\n");
FILE_LOG(logERROR) << "emfile";
break;
case ENFILE:
printf("enfile\n");
FILE_LOG(logERROR) << "enfile";
break;
case ENOTSOCK:
printf("enotsock\n");
FILE_LOG(logERROR) << "enotsock";
break;
case EOPNOTSUPP:
printf("eOPNOTSUPP\n");
FILE_LOG(logERROR) << "eOPNOTSUPP";
break;
case ENOBUFS:
printf("ENOBUFS\n");
FILE_LOG(logERROR) << "ENOBUFS";
break;
case ENOMEM:
printf("ENOMEM\n");
FILE_LOG(logERROR) << "ENOMEM";
break;
case ENOSR:
printf("ENOSR\n");
FILE_LOG(logERROR) << "ENOSR";
break;
case EPROTO:
printf("EPROTO\n");
FILE_LOG(logERROR) << "EPROTO";
break;
default:
printf("unknown error\n");
FILE_LOG(logERROR) << "unknown error";
}
}
else{
inet_ntop(AF_INET, &(clientAddress.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
#ifdef VERY_VERBOSE
cout << "client connected "<< sockfd.newfd << endl;
#endif
FILE_LOG(logDEBUG1) << "client connected " << sockfd.newfd;
}
}
#ifdef VERY_VERBOSE
cout << "fd " << sockfd.newfd << endl;
#endif
FILE_LOG(logDEBUG1) << "fd " << sockfd.newfd;
return sockfd.newfd;
} else {
if (sockfd.fd<=0)
sockfd.fd = socket(AF_INET, getProtocol(),0);
// SetTimeOut(10);
if (sockfd.fd < 0){
cprintf(RED, "Can not create socket\n");
FILE_LOG(logERROR) << "Can not create socket";
} else {
if(connect(sockfd.fd,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
cprintf(RED, "Can not connect to socket\n");
FILE_LOG(logERROR) << "Can not connect to socket";
return -1;
}
}
@ -470,13 +464,13 @@ public:
tout.tv_usec = 0;
if(::setsockopt(sockfd.fd, SOL_SOCKET, SO_RCVTIMEO,
&tout, sizeof(struct timeval)) <0) {
cprintf(RED, "Error in setsockopt SO_RCVTIMEO %d\n", 0);
FILE_LOG(logERROR) << "setsockopt SO_RCVTIMEO " << 0;
}
tout.tv_sec = ts;
tout.tv_usec = 0;
if(::setsockopt(sockfd.fd, SOL_SOCKET, SO_SNDTIMEO,
&tout, sizeof(struct timeval)) < 0) {
cprintf(RED, "Error in setsockopt SO_SNDTIMEO %d\n", ts);
FILE_LOG(logERROR) << "setsockopt SO_SNDTIMEO " << ts;
}
return 0;
};
@ -508,7 +502,6 @@ public:
sa = (struct sockaddr_in *)(iap->ifa_addr);
inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, buf_len);
if (ip==std::string(buf)) {
//printf("%s\n", iap->ifa_name);
strcpy(buf,iap->ifa_name);
break;
}
@ -615,17 +608,17 @@ public:
// get host info into res
int errcode = getaddrinfo (hostname, NULL, &hints, res);
if (errcode != 0) {
cprintf (RED,"Error: Could not convert %s hostname to internet address (zmq):"
"%s\n", hostname, gai_strerror(errcode));
FILE_LOG(logERROR) << "Could not convert hostname (" << hostname << ") to internet address (zmq):" <<
gai_strerror(errcode);
} else {
if (*res == NULL) {
cprintf (RED,"Error: Could not convert %s hostname to internet address (zmq): "
"gettaddrinfo returned null\n", hostname);
FILE_LOG(logERROR) << "Could not converthostname (" << hostname << ") to internet address (zmq):"
"gettaddrinfo returned null";
} else{
return 0;
}
}
cprintf(RED, "Error: Could not convert hostname to internet address\n");
FILE_LOG(logERROR) << "Could not convert hostname to internet address";
return 1;
};
@ -643,7 +636,7 @@ public:
freeaddrinfo(res);
return 0;
}
cprintf(RED, "Error: Could not convert internet address to ip string\n");
FILE_LOG(logERROR) << "Could not convert internet address to ip string";
return 1;
}
@ -697,7 +690,7 @@ public:
continue;
if(nsent != nsending){
if(nsent && (nsent != -1))
cprintf(RED,"Incomplete Packet size %d\n",nsent);
FILE_LOG(logERROR) << "Incomplete Packet size " << nsent;
break;
}
length-=nsent;
@ -709,16 +702,13 @@ public:
//normal
nsending=packet_size;
while(1){
#ifdef VERYVERBOSE
cprintf(BLUE,"%d gonna listen\n", portno); fflush(stdout);
#endif
nsent = recvfrom(sockfd.fd,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
//break out of loop only if read one packets size or read didnt work (cuz of shutdown)
if(nsent<=0 || nsent == packet_size)
break;
//incomplete packets or header packets ignored and read buffer again
if(nsent != packet_size && nsent != header_packet_size)
cprintf(RED,"%d Incomplete Packet size %d\n", portno, nsent);
FILE_LOG(logERROR) << portno << ": Incomplete Packet size " << nsent;
}
//nsent = 1040;
if(nsent > 0)total_sent+=nsent;
@ -727,9 +717,7 @@ public:
default:
;
}
#ifdef VERY_VERBOSE
cout << "sent "<< total_sent << " Bytes" << endl;
#endif
FILE_LOG(logDEBUG1) << "sent " << total_sent << " Bytes";
return total_sent;
}
@ -740,9 +728,7 @@ public:
* @returns size of data sent
*/
int SendDataOnly(void *buf, int length) {
#ifdef VERY_VERBOSE
cout << "want to send "<< length << " Bytes" << endl;
#endif
FILE_LOG(logDEBUG1) << "want to send " << length << " Bytes";
if (buf==NULL) return -1;
total_sent=0;
@ -757,7 +743,7 @@ public:
nsending = (length>packet_size) ? packet_size:length;
nsent = write(tcpfd,(char*)buf+total_sent,nsending);
if(is_a_server && nsent < 0) {
cprintf(BG_RED, "Error writing to socket. Possible client socket crash\n");
FILE_LOG(logERROR) << "Could not write to socket. Possible client socket crash";
break;
}
if(!nsent) break;
@ -779,9 +765,7 @@ public:
default:
;
}
#ifdef VERY_VERBOSE
cout << "sent "<< total_sent << " Bytes" << endl;
#endif
FILE_LOG(logDEBUG1) << "sent "<< total_sent << " Bytes";
return total_sent;
}