From aec8c031dee83a17174c316415c3bd314b31aa8e Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 31 Oct 2018 14:30:30 +0100 Subject: [PATCH] kept the same client interface:tb changed when fixing error codes/exceptions, modified multi print, fixed roi bug in indexing to sls --- .../eigerDetectorServer/gitInfo.txt | 10 +- .../eigerDetectorServer/gitInfoEiger.h | 8 +- .../multiSlsDetector/multiSlsDetector.cpp | 394 +++++++----------- .../slsDetector/slsDetector.cpp | 11 +- slsDetectorSoftware/slsDetector/slsDetector.h | 5 + slsSupportLib/include/ClientInterface.cpp | 57 +-- slsSupportLib/include/ClientInterface.h | 16 +- slsSupportLib/include/genericSocket.h | 94 ++--- 8 files changed, 238 insertions(+), 357 deletions(-) diff --git a/slsDetectorServers/eigerDetectorServer/gitInfo.txt b/slsDetectorServers/eigerDetectorServer/gitInfo.txt index f5bf1d811..77c57bbe4 100644 --- a/slsDetectorServers/eigerDetectorServer/gitInfo.txt +++ b/slsDetectorServers/eigerDetectorServer/gitInfo.txt @@ -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 diff --git a/slsDetectorServers/eigerDetectorServer/gitInfoEiger.h b/slsDetectorServers/eigerDetectorServer/gitInfoEiger.h index 7181daf9c..ad94fcc13 100644 --- a/slsDetectorServers/eigerDetectorServer/gitInfoEiger.h +++ b/slsDetectorServers/eigerDetectorServer/gitInfoEiger.h @@ -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" diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index da6f3f41f..c245aa820 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -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:"< 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 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(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:"< 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(); } } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 9670b8275..6f3358e70 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -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; } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index fb644839f..beda23779 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -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 diff --git a/slsSupportLib/include/ClientInterface.cpp b/slsSupportLib/include/ClientInterface.cpp index 92d3f89ee..cb427c980 100644 --- a/slsSupportLib/include/ClientInterface.cpp +++ b/slsSupportLib/include/ClientInterface.cpp @@ -14,22 +14,33 @@ void ClientInterface::SetSocket(MySocketTCP *socket) { } -int ClientInterface::Client_GetMesage(char* mess) { - bool created = false; - int ret = OK; - if (!mess){ - created = true; - mess = new char[MAX_STR_LENGTH]; - memset(mess, 0, MAX_STR_LENGTH); - } - 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; +void ClientInterface::Client_Receive(int& ret, char* mess, void* retval, int sizeOfRetval) { + // get result of operation + mySocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (created) - delete [] mess; - return ret; + bool unrecognizedFunction = false; + if (ret == FAIL) { + bool created = false; + // 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); + + // unrecognized function, do not ask for retval + if(strstr(mess,"Unrecognized Function") != NULL) + unrecognizedFunction = true; + // delete allocated mess + if (created) + delete [] mess; + } + // 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) { - - 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); - + int ret = FAIL; + mySocket->SendDataOnly(&fnum,sizeof(fnum)); + mySocket->SendDataOnly(args, sizeOfArgs); + Client_Receive(ret, mess, retval, sizeOfRetval); return ret; } diff --git a/slsSupportLib/include/ClientInterface.h b/slsSupportLib/include/ClientInterface.h index 049de62aa..ddc823167 100644 --- a/slsSupportLib/include/ClientInterface.h +++ b/slsSupportLib/include/ClientInterface.h @@ -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, diff --git a/slsSupportLib/include/genericSocket.h b/slsSupportLib/include/genericSocket.h index 7801757b6..e405abb90 100644 --- a/slsSupportLib/include/genericSocket.h +++ b/slsSupportLib/include/genericSocket.h @@ -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; }