format and removed nullptr check before delete

This commit is contained in:
Erik Frojdh 2019-01-21 11:18:27 +01:00
parent b74aed91dc
commit d2ed245d1d

View File

@ -2,20 +2,20 @@
#include "SharedMemory.h" #include "SharedMemory.h"
#include "ZmqSocket.h" #include "ZmqSocket.h"
#include "detectorData.h" #include "detectorData.h"
#include "file_utils.h"
#include "logger.h" #include "logger.h"
#include "multiSlsDetectorClient.h" #include "multiSlsDetectorClient.h"
#include "slsDetectorCommand.h"
#include "slsDetector.h" #include "slsDetector.h"
#include "slsDetectorCommand.h"
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"
#include "file_utils.h"
#include "string_utils.h" #include "string_utils.h"
#include <cstring>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <rapidjson/document.h> //json header in zmq stream #include <rapidjson/document.h> //json header in zmq stream
#include <sstream> #include <sstream>
#include <cstring>
#include <sys/ipc.h> #include <sys/ipc.h>
#include <sys/shm.h> #include <sys/shm.h>
#include <sys/types.h> #include <sys/types.h>
@ -27,7 +27,7 @@
#include <vector> #include <vector>
multiSlsDetector::multiSlsDetector(int id, bool verify, bool update) multiSlsDetector::multiSlsDetector(int id, bool verify, bool update)
: detId(id){ : detId(id) {
setupMultiDetector(verify, update); setupMultiDetector(verify, update);
} }
@ -45,8 +45,6 @@ void multiSlsDetector::setupMultiDetector(bool verify, bool update) {
updateUserdetails(); updateUserdetails();
} }
template <typename RT, typename... CT> template <typename RT, typename... CT>
std::vector<RT> multiSlsDetector::serialCall(RT (slsDetector::*somefunc)(CT...), std::vector<RT> multiSlsDetector::serialCall(RT (slsDetector::*somefunc)(CT...),
typename NonDeduced<CT>::type... Args) { typename NonDeduced<CT>::type... Args) {
@ -202,8 +200,8 @@ bool multiSlsDetector::getAcquiringFlag() const {
bool multiSlsDetector::isAcquireReady() { bool multiSlsDetector::isAcquireReady() {
if (thisMultiDetector->acquiringFlag) { if (thisMultiDetector->acquiringFlag) {
FILE_LOG(logWARNING) << "Acquire has already started. " FILE_LOG(logWARNING) << "Acquire has already started. "
"If previous acquisition terminated unexpectedly, " "If previous acquisition terminated unexpectedly, "
"reset busy flag to restart.(sls_detector_put busy 0)"; "reset busy flag to restart.(sls_detector_put busy 0)";
return FAIL; return FAIL;
} }
thisMultiDetector->acquiringFlag = true; thisMultiDetector->acquiringFlag = true;
@ -323,8 +321,8 @@ void multiSlsDetector::initSharedMemory(bool verify) {
(sharedMultiSlsDetector *)sharedMemory->OpenSharedMemory(sz); (sharedMultiSlsDetector *)sharedMemory->OpenSharedMemory(sz);
if (verify && thisMultiDetector->shmversion != MULTI_SHMVERSION) { if (verify && thisMultiDetector->shmversion != MULTI_SHMVERSION) {
FILE_LOG(logERROR) << "Multi shared memory (" << detId << ") version mismatch " FILE_LOG(logERROR) << "Multi shared memory (" << detId << ") version mismatch "
"(expected 0x" << std::hex << MULTI_SHMVERSION << "(expected 0x"
" but got 0x" << thisMultiDetector->shmversion << std::dec; << std::hex << MULTI_SHMVERSION << " but got 0x" << thisMultiDetector->shmversion << std::dec;
throw SharedMemoryException(); throw SharedMemoryException();
} }
} }
@ -359,7 +357,7 @@ void multiSlsDetector::initializeDetectorStructure() {
thisMultiDetector->numberOfChannelInclGapPixels[Y] = 0; thisMultiDetector->numberOfChannelInclGapPixels[Y] = 0;
thisMultiDetector->maxNumberOfChannelsPerDetector[X] = 0; thisMultiDetector->maxNumberOfChannelsPerDetector[X] = 0;
thisMultiDetector->maxNumberOfChannelsPerDetector[Y] = 0; thisMultiDetector->maxNumberOfChannelsPerDetector[Y] = 0;
for (int64_t & i : thisMultiDetector->timerValue) { for (int64_t &i : thisMultiDetector->timerValue) {
i = 0; i = 0;
} }
@ -432,7 +430,7 @@ void multiSlsDetector::setHostname(const char *name, int detPos) {
// this check is there only to allow the previous detsizechan command // this check is there only to allow the previous detsizechan command
if (thisMultiDetector->numberOfDetectors) { if (thisMultiDetector->numberOfDetectors) {
FILE_LOG(logWARNING) << "There are already detector(s) in shared memory." FILE_LOG(logWARNING) << "There are already detector(s) in shared memory."
"Freeing Shared memory now."; "Freeing Shared memory now.";
freeSharedMemory(); freeSharedMemory();
setupMultiDetector(); setupMultiDetector();
} }
@ -458,14 +456,14 @@ void multiSlsDetector::addMultipleDetectors(const char *name) {
updateOffsets(); updateOffsets();
} }
void multiSlsDetector::addSlsDetector(const std::string& hostname) { void multiSlsDetector::addSlsDetector(const std::string &hostname) {
FILE_LOG(logDEBUG1) << "Adding detector " << hostname; FILE_LOG(logDEBUG1) << "Adding detector " << hostname;
for (auto &d : detectors) { for (auto &d : detectors) {
if (d->getHostname() == hostname) { if (d->getHostname() == hostname) {
FILE_LOG(logWARNING) << "Detector " << hostname FILE_LOG(logWARNING) << "Detector " << hostname
<< "already part of the multiDetector!" << std::endl << "already part of the multiDetector!" << std::endl
<< "Remove it before adding it back in a new position!"; << "Remove it before adding it back in a new position!";
return; return;
} }
} }
@ -478,7 +476,7 @@ void multiSlsDetector::addSlsDetector(const std::string& hostname) {
detectorType type = slsDetector::getDetectorTypeAsEnum(hostname.c_str(), DEFAULT_PORTNO); detectorType type = slsDetector::getDetectorTypeAsEnum(hostname.c_str(), DEFAULT_PORTNO);
if (type == GENERIC) { if (type == GENERIC) {
FILE_LOG(logERROR) << "Could not connect to Detector " << hostname FILE_LOG(logERROR) << "Could not connect to Detector " << hostname
<< " to determine the type!"; << " to determine the type!";
setErrorMask(getErrorMask() | MULTI_DETECTORS_NOT_ADDED); setErrorMask(getErrorMask() | MULTI_DETECTORS_NOT_ADDED);
appendNotAddedList(hostname.c_str()); appendNotAddedList(hostname.c_str());
return; return;
@ -517,7 +515,6 @@ std::string multiSlsDetector::getDetectorTypeAsString(int detPos) {
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
int multiSlsDetector::getNumberOfDetectors() const { int multiSlsDetector::getNumberOfDetectors() const {
return detectors.size(); return detectors.size();
} }
@ -601,10 +598,7 @@ void multiSlsDetector::updateOffsets() {
thisMultiDetector->numberOfChannelInclGapPixels[Y] = 0; thisMultiDetector->numberOfChannelInclGapPixels[Y] = 0;
for (size_t idet = 0; idet < detectors.size(); ++idet) { for (size_t idet = 0; idet < detectors.size(); ++idet) {
FILE_LOG(logDEBUG1) << "offsetX:" << offsetX << " prevChanX:" << prevChanX << 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;
" offsetY:" << offsetY << " prevChanY:" << prevChanY <<
" offsetX_gp:" << offsetX_gp << " prevChanX_gp:" << prevChanX_gp <<
" offsetY_gp:" << offsetY_gp << " prevChanY_gp:" << prevChanY_gp;
// incrementing in both direction // incrementing in both direction
if (firstTime) { if (firstTime) {
@ -613,14 +607,14 @@ void multiSlsDetector::updateOffsets() {
if ((maxChanX > 0) && if ((maxChanX > 0) &&
((offsetX + detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) { ((offsetX + detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) {
FILE_LOG(logWARNING) << "\nDetector[" << idet FILE_LOG(logWARNING) << "\nDetector[" << idet
<< "] exceeds maximum channels " << "] exceeds maximum channels "
"allowed for complete detector set in X dimension!"; "allowed for complete detector set in X dimension!";
} }
if ((maxChanY > 0) && if ((maxChanY > 0) &&
((offsetY + detectors[idet]->getTotalNumberOfChannels(Y)) > maxChanY)) { ((offsetY + detectors[idet]->getTotalNumberOfChannels(Y)) > maxChanY)) {
FILE_LOG(logERROR) << "\nDetector[" << idet FILE_LOG(logERROR) << "\nDetector[" << idet
<< "] exceeds maximum channels " << "] exceeds maximum channels "
"allowed for complete detector set in Y dimension!"; "allowed for complete detector set in Y dimension!";
} }
prevChanX = detectors[idet]->getTotalNumberOfChannels(X); prevChanX = detectors[idet]->getTotalNumberOfChannels(X);
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y); prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
@ -662,8 +656,8 @@ void multiSlsDetector::updateOffsets() {
((offsetX + prevChanX + ((offsetX + prevChanX +
detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) { detectors[idet]->getTotalNumberOfChannels(X)) > maxChanX)) {
FILE_LOG(logDEBUG1) << "\nDetector[" << idet FILE_LOG(logDEBUG1) << "\nDetector[" << idet
<< "] exceeds maximum channels " << "] exceeds maximum channels "
"allowed for complete detector set in X dimension!"; "allowed for complete detector set in X dimension!";
} }
offsetY = 0; offsetY = 0;
offsetY_gp = 0; offsetY_gp = 0;
@ -695,8 +689,8 @@ void multiSlsDetector::updateOffsets() {
Y, (bytesperchannel >= 1.0) ? offsetY_gp : offsetY); Y, (bytesperchannel >= 1.0) ? offsetY_gp : offsetY);
FILE_LOG(logDEBUG1) << "Detector[" << idet << "] has offsets (" FILE_LOG(logDEBUG1) << "Detector[" << idet << "] has offsets ("
<< detectors[idet]->getDetectorOffset(X) << ", " << detectors[idet]->getDetectorOffset(X) << ", "
<< detectors[idet]->getDetectorOffset(Y) << ")"; << detectors[idet]->getDetectorOffset(Y) << ")";
// offsetY has been reset sometimes and offsetX the first time, // offsetY has been reset sometimes and offsetX the first time,
// but remember the highest values // but remember the highest values
if (numX > thisMultiDetector->numberOfChannel[X]) if (numX > thisMultiDetector->numberOfChannel[X])
@ -708,14 +702,7 @@ void multiSlsDetector::updateOffsets() {
if (numY_gp > thisMultiDetector->numberOfChannelInclGapPixels[Y]) if (numY_gp > thisMultiDetector->numberOfChannelInclGapPixels[Y])
thisMultiDetector->numberOfChannelInclGapPixels[Y] = numY_gp; thisMultiDetector->numberOfChannelInclGapPixels[Y] = numY_gp;
} }
FILE_LOG(logDEBUG1) << "\n\tNumber of Channels in X direction:" << 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->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->numberOfChannels =
thisMultiDetector->numberOfChannel[0] * thisMultiDetector->numberOfChannel[0] *
@ -790,7 +777,7 @@ int multiSlsDetector::exitServer(int detPos) {
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL; return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
} }
int multiSlsDetector::execCommand(const std::string& cmd, int detPos) { int multiSlsDetector::execCommand(const std::string &cmd, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->execCommand(cmd); return detectors[detPos]->execCommand(cmd);
@ -840,7 +827,7 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
"threaded"}; "threaded"};
char *args[100]; char *args[100];
for (auto & arg : args) { for (auto &arg : args) {
arg = new char[1000]; arg = new char[1000];
} }
int ret = OK, ret1 = OK; int ret = OK, ret1 = OK;
@ -892,7 +879,7 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
ret = FAIL; ret = FAIL;
} }
for (auto & arg : args) { for (auto &arg : args) {
delete[] arg; delete[] arg;
} }
@ -972,7 +959,7 @@ std::string multiSlsDetector::getSettingsDir(int detPos) {
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
std::string multiSlsDetector::setSettingsDir(const std::string& directory, std::string multiSlsDetector::setSettingsDir(const std::string &directory,
int detPos) { int detPos) {
if (detPos >= 0) if (detPos >= 0)
return detectors[detPos]->setSettingsDir(directory); return detectors[detPos]->setSettingsDir(directory);
@ -981,7 +968,7 @@ std::string multiSlsDetector::setSettingsDir(const std::string& directory,
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
int multiSlsDetector::loadSettingsFile(const std::string& fname, int detPos) { int multiSlsDetector::loadSettingsFile(const std::string &fname, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->loadSettingsFile(fname); return detectors[detPos]->loadSettingsFile(fname);
@ -992,7 +979,7 @@ int multiSlsDetector::loadSettingsFile(const std::string& fname, int detPos) {
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL; return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
} }
int multiSlsDetector::saveSettingsFile(const std::string& fname, int detPos) { int multiSlsDetector::saveSettingsFile(const std::string &fname, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->saveSettingsFile(fname); return detectors[detPos]->saveSettingsFile(fname);
@ -1530,7 +1517,7 @@ uint32_t multiSlsDetector::clearBit(uint32_t addr, int n, int detPos) {
return -1; return -1;
} }
std::string multiSlsDetector::setDetectorMAC(const std::string& detectorMAC, int detPos) { std::string multiSlsDetector::setDetectorMAC(const std::string &detectorMAC, int detPos) {
// single // single
if (detPos >= 0) if (detPos >= 0)
return detectors[detPos]->setDetectorMAC(detectorMAC); return detectors[detPos]->setDetectorMAC(detectorMAC);
@ -1551,7 +1538,7 @@ std::string multiSlsDetector::getDetectorMAC(int detPos) {
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
std::string multiSlsDetector::setDetectorIP(const std::string& detectorIP, int detPos) { std::string multiSlsDetector::setDetectorIP(const std::string &detectorIP, int detPos) {
// single // single
if (detPos >= 0) if (detPos >= 0)
return detectors[detPos]->setDetectorIP(detectorIP); return detectors[detPos]->setDetectorIP(detectorIP);
@ -1572,7 +1559,7 @@ std::string multiSlsDetector::getDetectorIP(int detPos) {
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
std::string multiSlsDetector::setReceiver(const std::string& receiver, int detPos) { std::string multiSlsDetector::setReceiver(const std::string &receiver, int detPos) {
// single // single
if (detPos >= 0) if (detPos >= 0)
return detectors[detPos]->setReceiver(receiver); return detectors[detPos]->setReceiver(receiver);
@ -1593,7 +1580,7 @@ std::string multiSlsDetector::getReceiver(int detPos) {
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
std::string multiSlsDetector::setReceiverUDPIP(const std::string& udpip, int detPos) { std::string multiSlsDetector::setReceiverUDPIP(const std::string &udpip, int detPos) {
// single // single
if (detPos >= 0) if (detPos >= 0)
return detectors[detPos]->setReceiverUDPIP(udpip); return detectors[detPos]->setReceiverUDPIP(udpip);
@ -1614,7 +1601,7 @@ std::string multiSlsDetector::getReceiverUDPIP(int detPos) {
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
std::string multiSlsDetector::setReceiverUDPMAC(const std::string& udpmac, int detPos) { std::string multiSlsDetector::setReceiverUDPMAC(const std::string &udpmac, int detPos) {
// single // single
if (detPos >= 0) if (detPos >= 0)
return detectors[detPos]->setReceiverUDPMAC(udpmac); return detectors[detPos]->setReceiverUDPMAC(udpmac);
@ -1683,7 +1670,7 @@ void multiSlsDetector::setClientDataStreamingInPort(int i, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
detectors[detPos]->setClientStreamingPort(i); detectors[detPos]->setClientStreamingPort(i);
} }
// multi // multi
else { else {
@ -1721,7 +1708,7 @@ void multiSlsDetector::setReceiverDataStreamingOutPort(int i, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
detectors[detPos]->setReceiverStreamingPort(i); detectors[detPos]->setReceiverStreamingPort(i);
} }
// multi // multi
else { else {
@ -1753,20 +1740,20 @@ int multiSlsDetector::getReceiverStreamingPort(int detPos) {
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
void multiSlsDetector::setClientDataStreamingInIP(const std::string& ip, void multiSlsDetector::setClientDataStreamingInIP(const std::string &ip,
int detPos) { int detPos) {
if (ip.length()) { if (ip.length()) {
int prev_streaming = enableDataStreamingToClient(-1); int prev_streaming = enableDataStreamingToClient(-1);
// single // single
if (detPos >= 0) { if (detPos >= 0) {
detectors[detPos]->setClientStreamingIP(ip); detectors[detPos]->setClientStreamingIP(ip);
} }
// multi // multi
else { else {
for (auto &d : detectors) { for (auto &d : detectors) {
d->setClientStreamingIP(ip); d->setClientStreamingIP(ip);
} }
} }
if (prev_streaming) { if (prev_streaming) {
@ -1787,19 +1774,19 @@ std::string multiSlsDetector::getClientStreamingIP(int detPos) {
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
void multiSlsDetector::setReceiverDataStreamingOutIP(const std::string& ip, void multiSlsDetector::setReceiverDataStreamingOutIP(const std::string &ip,
int detPos) { int detPos) {
if (ip.length()) { if (ip.length()) {
int prev_streaming = enableDataStreamingFromReceiver(-1, detPos); int prev_streaming = enableDataStreamingFromReceiver(-1, detPos);
// single // single
if (detPos >= 0) { if (detPos >= 0) {
detectors[detPos]->setReceiverStreamingIP(ip); detectors[detPos]->setReceiverStreamingIP(ip);
} }
// multi // multi
else { else {
for (auto &d : detectors) { for (auto &d : detectors) {
d->setReceiverStreamingIP(ip); d->setReceiverStreamingIP(ip);
} }
} }
@ -1831,7 +1818,7 @@ int multiSlsDetector::setDetectorNetworkParameter(networkParameter index, int de
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
std::string multiSlsDetector::setAdditionalJsonHeader(const std::string& jsonheader, int detPos) { std::string multiSlsDetector::setAdditionalJsonHeader(const std::string &jsonheader, int detPos) {
// single // single
if (detPos >= 0) if (detPos >= 0)
return detectors[detPos]->setAdditionalJsonHeader(jsonheader); return detectors[detPos]->setAdditionalJsonHeader(jsonheader);
@ -2029,7 +2016,7 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
FILE_LOG(logDEBUG1) << "Setting ROI for " << n << "rois:"; FILE_LOG(logDEBUG1) << "Setting ROI for " << n << "rois:";
for (int i = 0; i < n; ++i) for (int i = 0; i < n; ++i)
FILE_LOG(logDEBUG1) << i << ":" << roiLimits[i].xmin << "\t" << roiLimits[i].xmax FILE_LOG(logDEBUG1) << i << ":" << roiLimits[i].xmin << "\t" << roiLimits[i].xmax
<< "\t" << roiLimits[i].ymin << "\t" << roiLimits[i].ymax; << "\t" << roiLimits[i].ymin << "\t" << roiLimits[i].ymax;
// for each roi // for each roi
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
xmin = roiLimits[i].xmin; xmin = roiLimits[i].xmin;
@ -2039,9 +2026,8 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
// check roi max values // check roi max values
idet = decodeNChannel(xmax, ymax, channelX, channelY); idet = decodeNChannel(xmax, ymax, channelX, channelY);
FILE_LOG(logDEBUG1) << "Decoded Channel max vals: " << std::endl << FILE_LOG(logDEBUG1) << "Decoded Channel max vals: " << std::endl
"det:" << idet << "\t" << xmax << "\t" << ymax << "\t" << << "det:" << idet << "\t" << xmax << "\t" << ymax << "\t" << channelX << "\t" << channelY;
channelX << "\t" << channelY;
if (idet == -1) { if (idet == -1) {
FILE_LOG(logERROR) << "invalid roi"; FILE_LOG(logERROR) << "invalid roi";
continue; continue;
@ -2055,9 +2041,8 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
while (ymin <= ymax) { while (ymin <= ymax) {
// get offset for each detector // get offset for each detector
idet = decodeNChannel(xmin, ymin, channelX, channelY); idet = decodeNChannel(xmin, ymin, channelX, channelY);
FILE_LOG(logDEBUG1) << "Decoded Channel min vals: " << std::endl << FILE_LOG(logDEBUG1) << "Decoded Channel min vals: " << std::endl
"det:" << idet << "\t" << xmin << "\t" << ymin << << "det:" << idet << "\t" << xmin << "\t" << ymin << "\t" << channelX << "\t" << channelY;
"\t" << channelX << "\t" << channelY;
if (idet < 0 || idet >= (int)detectors.size()) { if (idet < 0 || idet >= (int)detectors.size()) {
FILE_LOG(logDEBUG1) << "invalid roi"; FILE_LOG(logDEBUG1) << "invalid roi";
invalidroi = true; invalidroi = true;
@ -2082,8 +2067,8 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
if ((offsetY + lastChannelY) >= ymax) if ((offsetY + lastChannelY) >= ymax)
lastChannelY = ymax - offsetY; lastChannelY = ymax - offsetY;
FILE_LOG(logDEBUG1) << "lastChannelX:" << lastChannelX << "\t" << FILE_LOG(logDEBUG1) << "lastChannelX:" << lastChannelX << "\t"
"lastChannelY:" << lastChannelY; << "lastChannelY:" << lastChannelY;
// creating the list of roi for corresponding detector // creating the list of roi for corresponding detector
index = nroi[idet]; index = nroi[idet];
@ -2113,7 +2098,7 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
FILE_LOG(logDEBUG1) << "detector " << i; FILE_LOG(logDEBUG1) << "detector " << i;
for (int j = 0; j < nroi[i]; ++j) { for (int j = 0; j < nroi[i]; ++j) {
FILE_LOG(logDEBUG1) << allroi[i][j].xmin << "\t" << allroi[i][j].xmax << "\t" FILE_LOG(logDEBUG1) << allroi[i][j].xmin << "\t" << allroi[i][j].xmax << "\t"
<< allroi[i][j].ymin << "\t" << allroi[i][j].ymax; << allroi[i][j].ymin << "\t" << allroi[i][j].ymax;
} }
} }
@ -2151,7 +2136,7 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
} }
for (j = 0; j < index; ++j) { for (j = 0; j < index; ++j) {
FILE_LOG(logINFO) << temp[j].xmin << "\t" << temp[j].xmax << "\t" FILE_LOG(logINFO) << temp[j].xmin << "\t" << temp[j].xmax << "\t"
<< temp[j].ymin << "\t" << temp[j].ymax; << temp[j].ymin << "\t" << temp[j].ymax;
int x = detectors[idet]->getDetectorOffset(X); int x = detectors[idet]->getDetectorOffset(X);
int y = detectors[idet]->getDetectorOffset(Y); int y = detectors[idet]->getDetectorOffset(Y);
roiLimits[n].xmin = temp[j].xmin + x; roiLimits[n].xmin = temp[j].xmin + x;
@ -2170,10 +2155,9 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
FILE_LOG(logDEBUG1) << "ROI :" << std::endl; FILE_LOG(logDEBUG1) << "ROI :" << std::endl;
for (int j = 0; j < n; ++j) { for (int j = 0; j < n; ++j) {
FILE_LOG(logDEBUG1) << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t" FILE_LOG(logDEBUG1) << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t"
<< roiLimits[j].ymin << "\t" << roiLimits[j].ymax; << roiLimits[j].ymin << "\t" << roiLimits[j].ymax;
} }
// combine all the adjacent rois in x direction // combine all the adjacent rois in x direction
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
// since the ones combined are replaced by -1 // since the ones combined are replaced by -1
@ -2209,7 +2193,7 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
FILE_LOG(logDEBUG1) << "Combined along x axis Getting ROI :\ndetector " << i; FILE_LOG(logDEBUG1) << "Combined along x axis Getting ROI :\ndetector " << i;
for (int j = 0; j < n; ++j) { for (int j = 0; j < n; ++j) {
FILE_LOG(logDEBUG1) << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t" FILE_LOG(logDEBUG1) << roiLimits[j].xmin << "\t" << roiLimits[j].xmax << "\t"
<< roiLimits[j].ymin << "\t" << roiLimits[j].ymax; << roiLimits[j].ymin << "\t" << roiLimits[j].ymax;
} }
// combine all the adjacent rois in y direction // combine all the adjacent rois in y direction
@ -2266,7 +2250,7 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
FILE_LOG(logDEBUG1) << "\nxmin\txmax\tymin\tymax"; FILE_LOG(logDEBUG1) << "\nxmin\txmax\tymin\tymax";
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
FILE_LOG(logDEBUG1) << retval[i].xmin << "\t" << retval[i].xmax << "\t" FILE_LOG(logDEBUG1) << retval[i].xmin << "\t" << retval[i].xmax << "\t"
<< retval[i].ymin << "\t" << retval[i].ymax; << retval[i].ymin << "\t" << retval[i].ymax;
return retval; return retval;
} }
@ -2471,7 +2455,7 @@ int multiSlsDetector::setStoragecellStart(int pos, int detPos) {
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
int multiSlsDetector::programFPGA(const std::string& fname, int detPos) { int multiSlsDetector::programFPGA(const std::string &fname, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->programFPGA(fname); return detectors[detPos]->programFPGA(fname);
@ -2619,7 +2603,7 @@ int multiSlsDetector::exitReceiver(int detPos) {
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL; return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
} }
int multiSlsDetector::execReceiverCommand(const std::string& cmd, int detPos) { int multiSlsDetector::execReceiverCommand(const std::string &cmd, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->execReceiverCommand(cmd); return detectors[detPos]->execReceiverCommand(cmd);
@ -2641,7 +2625,7 @@ std::string multiSlsDetector::getFilePath(int detPos) {
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
std::string multiSlsDetector::setFilePath(const std::string& path, int detPos) { std::string multiSlsDetector::setFilePath(const std::string &path, int detPos) {
if (path.empty()) if (path.empty())
return getFilePath(detPos); return getFilePath(detPos);
@ -2666,7 +2650,7 @@ std::string multiSlsDetector::getFileName(int detPos) {
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
std::string multiSlsDetector::setFileName(const std::string& fname, int detPos) { std::string multiSlsDetector::setFileName(const std::string &fname, int detPos) {
if (fname.empty()) if (fname.empty())
return getFileName(detPos); return getFileName(detPos);
@ -2858,7 +2842,7 @@ int multiSlsDetector::resetFramesCaught(int detPos) {
int multiSlsDetector::createReceivingDataSockets(const bool destroy) { int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
if (destroy) { if (destroy) {
FILE_LOG(logINFO) << "Going to destroy data sockets"; FILE_LOG(logINFO) << "Going to destroy data sockets";
// close socket // close socket
zmqSocket.clear(); zmqSocket.clear();
@ -2867,7 +2851,7 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
return OK; return OK;
} }
FILE_LOG(logINFO) << "Going to create data sockets"; FILE_LOG(logINFO) << "Going to create data sockets";
size_t numSockets = detectors.size(); size_t numSockets = detectors.size();
size_t numSocketsPerDetector = 1; size_t numSocketsPerDetector = 1;
@ -2878,7 +2862,7 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
for (size_t iSocket = 0; iSocket < numSockets; ++iSocket) { for (size_t iSocket = 0; iSocket < numSockets; ++iSocket) {
uint32_t portnum = (detectors[iSocket / numSocketsPerDetector] uint32_t portnum = (detectors[iSocket / numSocketsPerDetector]
->getClientStreamingPort()); ->getClientStreamingPort());
portnum += (iSocket % numSocketsPerDetector); portnum += (iSocket % numSocketsPerDetector);
try { try {
zmqSocket.push_back(sls::make_unique<ZmqSocket>( zmqSocket.push_back(sls::make_unique<ZmqSocket>(
@ -2886,8 +2870,7 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
->getClientStreamingIP() ->getClientStreamingIP()
.c_str(), .c_str(),
portnum)); portnum));
FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at " << FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at " << zmqSocket.back()->GetZmqServerAddress();
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;
createReceivingDataSockets(true); createReceivingDataSockets(true);
@ -2924,7 +2907,7 @@ void multiSlsDetector::readFrameFromReceiver() {
} else { } else {
// to remember the list it connected to, to disconnect later // to remember the list it connected to, to disconnect later
connectList[i] = false; connectList[i] = false;
FILE_LOG(logERROR) << "Could not connect to socket " << zmqSocket[i]->GetZmqServerAddress(); FILE_LOG(logERROR) << "Could not connect to socket " << zmqSocket[i]->GetZmqServerAddress();
runningList[i] = false; runningList[i] = false;
} }
} }
@ -2989,14 +2972,9 @@ void multiSlsDetector::readFrameFromReceiver() {
nPixelsX = doc["shape"][0].GetUint(); nPixelsX = doc["shape"][0].GetUint();
nPixelsY = doc["shape"][1].GetUint(); nPixelsY = doc["shape"][1].GetUint();
FILE_LOG(logDEBUG1) << FILE_LOG(logDEBUG1) << "One Time Header Info:"
"One Time Header Info:" "\n\tsize: "
"\n\tsize: " << size << << size << "\n\tmultisize: " << multisize << "\n\tdynamicRange: " << dynamicRange << "\n\tbytesPerPixel: " << bytesPerPixel << "\n\tnPixelsX: " << nPixelsX << "\n\tnPixelsY: " << nPixelsY;
"\n\tmultisize: " << multisize <<
"\n\tdynamicRange: " << dynamicRange <<
"\n\tbytesPerPixel: " << bytesPerPixel <<
"\n\tnPixelsX: " << nPixelsX <<
"\n\tnPixelsY: " << nPixelsY;
} }
// each time, parse rest of header // each time, parse rest of header
currentFileName = doc["fname"].GetString(); currentFileName = doc["fname"].GetString();
@ -3009,16 +2987,9 @@ void multiSlsDetector::readFrameFromReceiver() {
if (eiger) if (eiger)
coordY = (nY - 1) - coordY; coordY = (nY - 1) - coordY;
flippedDataX = doc["flippedDataX"].GetUint(); flippedDataX = doc["flippedDataX"].GetUint();
FILE_LOG(logDEBUG1) << FILE_LOG(logDEBUG1) << "Header Info:"
"Header Info:" "\n\tcurrentFileName: "
"\n\tcurrentFileName: " << currentFileName << << currentFileName << "\n\tcurrentAcquisitionIndex: " << currentAcquisitionIndex << "\n\tcurrentFrameIndex: " << currentFrameIndex << "\n\tcurrentFileIndex: " << currentFileIndex << "\n\tcurrentSubFrameIndex: " << currentSubFrameIndex << "\n\tcoordX: " << coordX << "\n\tcoordY: " << coordY << "\n\tflippedDataX: " << flippedDataX;
"\n\tcurrentAcquisitionIndex: " << currentAcquisitionIndex <<
"\n\tcurrentFrameIndex: " << currentFrameIndex <<
"\n\tcurrentFileIndex: " << currentFileIndex <<
"\n\tcurrentSubFrameIndex: " << currentSubFrameIndex <<
"\n\tcoordX: " << coordX <<
"\n\tcoordY: " << coordY <<
"\n\tflippedDataX: " << flippedDataX;
} }
// DATA // DATA
@ -3031,12 +3002,9 @@ void multiSlsDetector::readFrameFromReceiver() {
uint32_t yoffset = coordY * nPixelsY; uint32_t yoffset = coordY * nPixelsY;
uint32_t singledetrowoffset = nPixelsX * bytesPerPixel; uint32_t singledetrowoffset = nPixelsX * bytesPerPixel;
uint32_t rowoffset = nX * singledetrowoffset; uint32_t rowoffset = nX * singledetrowoffset;
FILE_LOG(logDEBUG1) << FILE_LOG(logDEBUG1) << "Multi Image Info:"
"Multi Image Info:" "\n\txoffset: "
"\n\txoffset: " << xoffset << << xoffset << "\n\tyoffset: " << yoffset << "\n\tsingledetrowoffset: " << singledetrowoffset << "\n\trowoffset: " << rowoffset;
"\n\tyoffset: " << yoffset <<
"\n\tsingledetrowoffset: " << singledetrowoffset <<
"\n\trowoffset: " << rowoffset;
if (eiger && flippedDataX) { if (eiger && flippedDataX) {
for (uint32_t i = 0; i < nPixelsY; ++i) { for (uint32_t i = 0; i < nPixelsY; ++i) {
@ -3111,12 +3079,9 @@ void multiSlsDetector::readFrameFromReceiver() {
zmqSocket[i]->Disconnect(); zmqSocket[i]->Disconnect();
// free resources // free resources
if (image != nullptr) delete[] image;
delete[] image; delete[] multiframe;
if (multiframe != nullptr) delete[] multigappixels;
delete[] multiframe;
if (multigappixels != nullptr)
delete[] multigappixels;
} }
int multiSlsDetector::processImageWithGapPixels(char *image, char *&gpImage) { int multiSlsDetector::processImageWithGapPixels(char *image, char *&gpImage) {
@ -3350,7 +3315,7 @@ int multiSlsDetector::setReceiverSilentMode(int i, int detPos) {
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
int multiSlsDetector::setCTBPattern(const std::string& fname, int detPos) { int multiSlsDetector::setCTBPattern(const std::string &fname, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setCTBPattern(fname); return detectors[detPos]->setCTBPattern(fname);
@ -3456,7 +3421,8 @@ int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1,
iline++; iline++;
FILE_LOG(logDEBUG1) << str; FILE_LOG(logDEBUG1) << str;
if (str.find('#') != std::string::npos) { if (str.find('#') != std::string::npos) {
FILE_LOG(logDEBUG1) << "Line is a comment \n" << str; FILE_LOG(logDEBUG1) << "Line is a comment \n"
<< str;
continue; continue;
} else { } else {
std::istringstream ssstr(str); std::istringstream ssstr(str);
@ -3578,7 +3544,7 @@ int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) {
//Workaround to bo able to suplly ecexuteLine with char** //Workaround to bo able to suplly ecexuteLine with char**
const int n_arguments = 1; const int n_arguments = 1;
char buffer[1000]; //TODO! this should not be hardcoded! char buffer[1000]; //TODO! this should not be hardcoded!
char *args[n_arguments] = { buffer }; char *args[n_arguments] = {buffer};
std::string outfname; std::string outfname;
if (level == 2) { if (level == 2) {
@ -3591,7 +3557,7 @@ int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) {
outfile.open(outfname.c_str(), std::ios_base::out); outfile.open(outfname.c_str(), std::ios_base::out);
if (outfile.is_open()) { if (outfile.is_open()) {
auto cmd = slsDetectorCommand(this); auto cmd = slsDetectorCommand(this);
for (auto & name : names) { for (auto &name : names) {
sls::strcpy_safe(buffer, name.c_str()); //this is... sls::strcpy_safe(buffer, name.c_str()); //this is...
outfile << name << " " << cmd.executeLine(n_arguments, args, GET_ACTION) outfile << name << " " << cmd.executeLine(n_arguments, args, GET_ACTION)
<< std::endl; << std::endl;
@ -3652,7 +3618,7 @@ int multiSlsDetector::setTotalProgress() {
totalProgress = nm * nf * nc * ns; totalProgress = nm * nf * nc * ns;
FILE_LOG(logDEBUG1) << "nm " << nm << " nf " << nf << " nc " << nc << " ns " << ns; FILE_LOG(logDEBUG1) << "nm " << nm << " nf " << nf << " nc " << nc << " ns " << ns;
FILE_LOG(logDEBUG1) << "Set total progress " << totalProgress << std::endl; FILE_LOG(logDEBUG1) << "Set total progress " << totalProgress << std::endl;
return totalProgress; return totalProgress;
} }
@ -3783,9 +3749,9 @@ int multiSlsDetector::acquire() {
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
FILE_LOG(logDEBUG1) << "Elapsed time for acquisition:" FILE_LOG(logDEBUG1) << "Elapsed time for acquisition:"
<< ((end.tv_sec - begin.tv_sec) + << ((end.tv_sec - begin.tv_sec) +
(end.tv_nsec - begin.tv_nsec) / 1000000000.0) (end.tv_nsec - begin.tv_nsec) / 1000000000.0)
<< " seconds"; << " seconds";
setAcquiringFlag(false); setAcquiringFlag(false);