format ColumnLimit changed to 100

This commit is contained in:
Erik Frojdh 2019-03-20 17:31:19 +01:00
parent 2a01688683
commit 83e43b1bcf
3 changed files with 650 additions and 634 deletions

View File

@ -2,5 +2,5 @@ BasedOnStyle: LLVM
IndentWidth: 4 IndentWidth: 4
UseTab: Never UseTab: Never
ColumnLimit: 0 ColumnLimit: 100
AlignConsecutiveAssignments: false AlignConsecutiveAssignments: false

View File

@ -32,8 +32,7 @@ using sls::SharedMemory;
using sls::SharedMemoryError; using sls::SharedMemoryError;
multiSlsDetector::multiSlsDetector(int multi_id, bool verify, bool update) multiSlsDetector::multiSlsDetector(int multi_id, bool verify, bool update)
: multiId(multi_id), : multiId(multi_id), multi_shm(multi_id, -1) {
multi_shm(multi_id, -1) {
setupMultiDetector(verify, update); setupMultiDetector(verify, update);
} }
@ -70,12 +69,11 @@ std::vector<RT> multiSlsDetector::serialCall(RT (slsDetector::*somefunc)(CT...)
} }
template <typename RT, typename... CT> template <typename RT, typename... CT>
std::vector<RT> std::vector<RT> multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...),
multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...), typename NonDeduced<CT>::type... Args) { typename NonDeduced<CT>::type... Args) {
std::vector<std::future<RT>> futures; std::vector<std::future<RT>> futures;
for (auto &d : detectors) { for (auto &d : detectors) {
futures.push_back( futures.push_back(std::async(std::launch::async, somefunc, d.get(), Args...));
std::async(std::launch::async, somefunc, d.get(), Args...));
} }
std::vector<RT> result; std::vector<RT> result;
result.reserve(detectors.size()); result.reserve(detectors.size());
@ -86,12 +84,11 @@ multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...), typename NonD
} }
template <typename RT, typename... CT> template <typename RT, typename... CT>
std::vector<RT> std::vector<RT> multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...) const,
multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...) const, typename NonDeduced<CT>::type... Args) const { typename NonDeduced<CT>::type... Args) const {
std::vector<std::future<RT>> futures; std::vector<std::future<RT>> futures;
for (auto &d : detectors) { for (auto &d : detectors) {
futures.push_back( futures.push_back(std::async(std::launch::async, somefunc, d.get(), Args...));
std::async(std::launch::async, somefunc, d.get(), Args...));
} }
std::vector<RT> result; std::vector<RT> result;
result.reserve(detectors.size()); result.reserve(detectors.size());
@ -101,8 +98,7 @@ multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...) const, typenam
return result; return result;
} }
int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int &channelX, int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int &channelX, int &channelY) {
int &channelY) {
channelX = -1; channelX = -1;
channelY = -1; channelY = -1;
// loop over // loop over
@ -111,17 +107,14 @@ int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int &channelX,
int y = detectors[i]->getDetectorOffset(Y); int y = detectors[i]->getDetectorOffset(Y);
// check x offset range // check x offset range
if ((offsetX >= x) && if ((offsetX >= x) &&
(offsetX < (offsetX < (x + detectors[i]->getTotalNumberOfChannelsInclGapPixels(X)))) {
(x + detectors[i]->getTotalNumberOfChannelsInclGapPixels(X)))) {
if (offsetY == -1) { if (offsetY == -1) {
channelX = offsetX - x; channelX = offsetX - x;
return i; return i;
} else { } else {
// check y offset range // check y offset range
if ((offsetY >= y) && if ((offsetY >= y) &&
(offsetY < (offsetY < (y + detectors[i]->getTotalNumberOfChannelsInclGapPixels(Y)))) {
(y + detectors[i]->getTotalNumberOfChannelsInclGapPixels(
Y)))) {
channelX = offsetX - x; channelX = offsetX - x;
channelY = offsetY - y; channelY = offsetY - y;
return i; return i;
@ -132,13 +125,9 @@ int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int &channelX,
return -1; return -1;
} }
void multiSlsDetector::setAcquiringFlag(bool flag) { void multiSlsDetector::setAcquiringFlag(bool flag) { multi_shm()->acquiringFlag = flag; }
multi_shm()->acquiringFlag = flag;
}
bool multiSlsDetector::getAcquiringFlag() const { bool multiSlsDetector::getAcquiringFlag() const { return multi_shm()->acquiringFlag; }
return multi_shm()->acquiringFlag;
}
bool multiSlsDetector::isAcquireReady() { bool multiSlsDetector::isAcquireReady() {
if (multi_shm()->acquiringFlag) { if (multi_shm()->acquiringFlag) {
@ -245,8 +234,7 @@ std::string multiSlsDetector::getUserDetails() {
sstream << d->getDetectorTypeAsString() << "+"; sstream << d->getDetectorTypeAsString() << "+";
} }
sstream << "\nPID: " << multi_shm()->lastPID sstream << "\nPID: " << multi_shm()->lastPID << "\nUser: " << multi_shm()->lastUser
<< "\nUser: " << multi_shm()->lastUser
<< "\nDate: " << multi_shm()->lastDate << std::endl; << "\nDate: " << multi_shm()->lastDate << std::endl;
return sstream.str(); return sstream.str();
@ -259,9 +247,11 @@ void multiSlsDetector::initSharedMemory(bool verify) {
} else { } else {
multi_shm.OpenSharedMemory(); multi_shm.OpenSharedMemory();
if (verify && multi_shm()->shmversion != MULTI_SHMVERSION) { if (verify && multi_shm()->shmversion != MULTI_SHMVERSION) {
FILE_LOG(logERROR) << "Multi shared memory (" << multiId << ") version mismatch " FILE_LOG(logERROR) << "Multi shared memory (" << multiId
<< ") version mismatch "
"(expected 0x" "(expected 0x"
<< std::hex << MULTI_SHMVERSION << " but got 0x" << multi_shm()->shmversion << std::dec; << std::hex << MULTI_SHMVERSION << " but got 0x"
<< multi_shm()->shmversion << std::dec;
throw SharedMemoryError("Shared memory version mismatch!"); throw SharedMemoryError("Shared memory version mismatch!");
} }
} }
@ -299,8 +289,7 @@ void multiSlsDetector::initializeMembers(bool verify) {
// get objects from single det shared memory (open) // get objects from single det shared memory (open)
for (int i = 0; i < multi_shm()->numberOfDetectors; i++) { for (int i = 0; i < multi_shm()->numberOfDetectors; i++) {
try { try {
detectors.push_back( detectors.push_back(sls::make_unique<slsDetector>(multiId, i, verify));
sls::make_unique<slsDetector>(multiId, i, verify));
} catch (...) { } catch (...) {
detectors.clear(); detectors.clear();
throw; throw;
@ -390,8 +379,8 @@ void multiSlsDetector::addSlsDetector(const std::string &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!"
<< "already part of the multiDetector!" << std::endl << std::endl
<< "Remove it before adding it back in a new position!"; << "Remove it before adding it back in a new position!";
return; return;
} }
@ -403,10 +392,8 @@ void multiSlsDetector::addSlsDetector(const std::string &hostname) {
detectors.push_back(sls::make_unique<slsDetector>(type, multiId, pos, false)); detectors.push_back(sls::make_unique<slsDetector>(type, multiId, pos, false));
multi_shm()->numberOfDetectors = detectors.size(); multi_shm()->numberOfDetectors = detectors.size();
multi_shm()->dataBytes += detectors[pos]->getDataBytes(); multi_shm()->dataBytes += detectors[pos]->getDataBytes();
multi_shm()->dataBytesInclGapPixels += multi_shm()->dataBytesInclGapPixels += detectors[pos]->getDataBytesInclGapPixels();
detectors[pos]->getDataBytesInclGapPixels(); multi_shm()->numberOfChannels += detectors[pos]->getTotalNumberOfChannels();
multi_shm()->numberOfChannels +=
detectors[pos]->getTotalNumberOfChannels();
detectors[pos]->setHostname(hostname); detectors[pos]->setHostname(hostname);
detectors[pos]->setOnline(true); detectors[pos]->setOnline(true);
@ -434,9 +421,7 @@ 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();
}
int multiSlsDetector::getNumberOfDetectors(dimension d) const { int multiSlsDetector::getNumberOfDetectors(dimension d) const {
return multi_shm()->numberOfDetector[d]; return multi_shm()->numberOfDetector[d];
@ -467,8 +452,7 @@ int multiSlsDetector::getTotalNumberOfChannels(dimension d, int detPos) {
return multi_shm()->numberOfChannel[d]; return multi_shm()->numberOfChannel[d];
} }
int multiSlsDetector::getTotalNumberOfChannelsInclGapPixels(dimension d, int multiSlsDetector::getTotalNumberOfChannelsInclGapPixels(dimension d, int detPos) {
int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->getTotalNumberOfChannelsInclGapPixels(d); return detectors[detPos]->getTotalNumberOfChannelsInclGapPixels(d);
@ -517,7 +501,10 @@ void multiSlsDetector::updateOffsets() {
multi_shm()->numberOfChannelInclGapPixels[Y] = 0; multi_shm()->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 << " offsetY:" << offsetY << " prevChanY:" << prevChanY << " offsetX_gp:" << offsetX_gp << " prevChanX_gp:" << prevChanX_gp << " offsetY_gp:" << offsetY_gp << " prevChanY_gp:" << prevChanY_gp; 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 // incrementing in both direction
if (firstTime) { if (firstTime) {
@ -537,16 +524,12 @@ void multiSlsDetector::updateOffsets() {
} }
prevChanX = detectors[idet]->getTotalNumberOfChannels(X); prevChanX = detectors[idet]->getTotalNumberOfChannels(X);
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y); prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
prevChanX_gp = prevChanX_gp = detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X); prevChanY_gp = detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
prevChanY_gp =
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
numX += detectors[idet]->getTotalNumberOfChannels(X); numX += detectors[idet]->getTotalNumberOfChannels(X);
numY += detectors[idet]->getTotalNumberOfChannels(Y); numY += detectors[idet]->getTotalNumberOfChannels(Y);
numX_gp += numX_gp += detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X); numY_gp += detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
numY_gp +=
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
++multi_shm()->numberOfDetector[X]; ++multi_shm()->numberOfDetector[X];
++multi_shm()->numberOfDetector[Y]; ++multi_shm()->numberOfDetector[Y];
FILE_LOG(logDEBUG1) << "incrementing in both direction"; FILE_LOG(logDEBUG1) << "incrementing in both direction";
@ -555,16 +538,13 @@ void multiSlsDetector::updateOffsets() {
// incrementing in y direction // incrementing in y direction
else if ((maxChanY == -1) || else if ((maxChanY == -1) ||
((maxChanY > 0) && ((offsetY + prevChanY + ((maxChanY > 0) && ((offsetY + prevChanY +
detectors[idet]->getTotalNumberOfChannels( detectors[idet]->getTotalNumberOfChannels(Y)) <= maxChanY))) {
Y)) <= maxChanY))) {
offsetY += prevChanY; offsetY += prevChanY;
offsetY_gp += prevChanY_gp; offsetY_gp += prevChanY_gp;
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y); prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
prevChanY_gp = prevChanY_gp = detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
numY += detectors[idet]->getTotalNumberOfChannels(Y); numY += detectors[idet]->getTotalNumberOfChannels(Y);
numY_gp += numY_gp += detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
// increment in y again only in the first column (else you double increment) // increment in y again only in the first column (else you double increment)
if (multi_shm()->numberOfDetector[X] == 1) if (multi_shm()->numberOfDetector[X] == 1)
++multi_shm()->numberOfDetector[Y]; ++multi_shm()->numberOfDetector[Y];
@ -574,8 +554,7 @@ void multiSlsDetector::updateOffsets() {
// incrementing in x direction // incrementing in x direction
else { else {
if ((maxChanX > 0) && if ((maxChanX > 0) &&
((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!";
@ -583,31 +562,25 @@ void multiSlsDetector::updateOffsets() {
offsetY = 0; offsetY = 0;
offsetY_gp = 0; offsetY_gp = 0;
prevChanY = detectors[idet]->getTotalNumberOfChannels(Y); prevChanY = detectors[idet]->getTotalNumberOfChannels(Y);
prevChanY_gp = prevChanY_gp = detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y);
numY = 0; // assuming symmetry with this statement. numY = 0; // assuming symmetry with this statement.
// whats on 1st column should be on 2nd column // whats on 1st column should be on 2nd column
numY_gp = 0; numY_gp = 0;
offsetX += prevChanX; offsetX += prevChanX;
offsetX_gp += prevChanX_gp; offsetX_gp += prevChanX_gp;
prevChanX = detectors[idet]->getTotalNumberOfChannels(X); prevChanX = detectors[idet]->getTotalNumberOfChannels(X);
prevChanX_gp = prevChanX_gp = detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
numX += detectors[idet]->getTotalNumberOfChannels(X); numX += detectors[idet]->getTotalNumberOfChannels(X);
numX_gp += numX_gp += detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X);
++multi_shm()->numberOfDetector[X]; ++multi_shm()->numberOfDetector[X];
FILE_LOG(logDEBUG1) << "incrementing in x direction"; FILE_LOG(logDEBUG1) << "incrementing in x direction";
} }
double bytesperchannel = double bytesperchannel = (double)detectors[idet]->getDataBytes() /
(double)detectors[idet]->getDataBytes() /
(double)(detectors[idet]->getTotalNumberOfChannels(X) * (double)(detectors[idet]->getTotalNumberOfChannels(X) *
detectors[idet]->getTotalNumberOfChannels(Y)); detectors[idet]->getTotalNumberOfChannels(Y));
detectors[idet]->setDetectorOffset( detectors[idet]->setDetectorOffset(X, (bytesperchannel >= 1.0) ? offsetX_gp : offsetX);
X, (bytesperchannel >= 1.0) ? offsetX_gp : offsetX); detectors[idet]->setDetectorOffset(Y, (bytesperchannel >= 1.0) ? offsetY_gp : offsetY);
detectors[idet]->setDetectorOffset(
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) << ", "
@ -627,15 +600,20 @@ void multiSlsDetector::updateOffsets() {
multi_shm()->numberOfChannelInclGapPixels[Y] = numY_gp; multi_shm()->numberOfChannelInclGapPixels[Y] = numY_gp;
} }
} }
FILE_LOG(logDEBUG1) << "\n\tNumber of Channels in X direction:" << multi_shm()->numberOfChannel[X] << "\n\tNumber of Channels in Y direction:" << multi_shm()->numberOfChannel[Y] << "\n\tNumber of Channels in X direction with Gap Pixels:" << multi_shm()->numberOfChannelInclGapPixels[X] << "\n\tNumber of Channels in Y direction with Gap Pixels:" << multi_shm()->numberOfChannelInclGapPixels[Y]; FILE_LOG(logDEBUG1) << "\n\tNumber of Channels in X direction:"
<< multi_shm()->numberOfChannel[X]
<< "\n\tNumber of Channels in Y direction:"
<< multi_shm()->numberOfChannel[Y]
<< "\n\tNumber of Channels in X direction with Gap Pixels:"
<< multi_shm()->numberOfChannelInclGapPixels[X]
<< "\n\tNumber of Channels in Y direction with Gap Pixels:"
<< multi_shm()->numberOfChannelInclGapPixels[Y];
multi_shm()->numberOfChannels = multi_shm()->numberOfChannels =
multi_shm()->numberOfChannel[0] * multi_shm()->numberOfChannel[0] * multi_shm()->numberOfChannel[1];
multi_shm()->numberOfChannel[1];
for (auto &d : detectors) { for (auto &d : detectors) {
d->updateMultiSize(multi_shm()->numberOfDetector[0], d->updateMultiSize(multi_shm()->numberOfDetector[0], multi_shm()->numberOfDetector[1]);
multi_shm()->numberOfDetector[1]);
} }
} }
@ -753,9 +731,8 @@ int multiSlsDetector::readConfigurationFile(const std::string &fname) {
} }
int multiSlsDetector::writeConfigurationFile(const std::string &fname) { int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
//TODO! make exception safe! // TODO! make exception safe!
const std::vector<std::string> names = {"detsizechan", "hostname", "outdir", const std::vector<std::string> names = {"detsizechan", "hostname", "outdir", "threaded"};
"threaded"};
int ret = OK, ret1 = OK; int ret = OK, ret1 = OK;
std::ofstream outfile; std::ofstream outfile;
@ -773,15 +750,13 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
// complete size of detector // complete size of detector
FILE_LOG(logINFO) << "Command to write: " << iline << " " << names[iline]; FILE_LOG(logINFO) << "Command to write: " << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str()); strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) << std::endl;
<< std::endl;
++iline; ++iline;
// hostname of the detectors // hostname of the detectors
FILE_LOG(logINFO) << "Command to write: " << iline << " " << names[iline]; FILE_LOG(logINFO) << "Command to write: " << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str()); strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) << std::endl;
<< std::endl;
++iline; ++iline;
// single detector configuration // single detector configuration
@ -798,8 +773,7 @@ int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
while (iline < names.size()) { while (iline < names.size()) {
FILE_LOG(logINFO) << "Command to write:" << iline << " " << names[iline]; FILE_LOG(logINFO) << "Command to write:" << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str()); strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) << std::endl;
<< cmd.executeLine(1, args, GET_ACTION) << std::endl;
++iline; ++iline;
} }
outfile.close(); outfile.close();
@ -824,8 +798,8 @@ slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int detPos) {
return (detectorSettings)sls::minusOneIfDifferent(r); return (detectorSettings)sls::minusOneIfDifferent(r);
} }
slsDetectorDefs::detectorSettings slsDetectorDefs::detectorSettings multiSlsDetector::setSettings(detectorSettings isettings,
multiSlsDetector::setSettings(detectorSettings isettings, int detPos) { int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setSettings(isettings); return detectors[detPos]->setSettings(isettings);
@ -850,10 +824,7 @@ int multiSlsDetector::getThresholdEnergy(int detPos) {
return -1; return -1;
} }
int multiSlsDetector::setThresholdEnergy(int e_eV, int multiSlsDetector::setThresholdEnergy(int e_eV, detectorSettings isettings, int tb, int detPos) {
detectorSettings isettings,
int tb,
int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setThresholdEnergy(e_eV, isettings, tb); return detectors[detPos]->setThresholdEnergy(e_eV, isettings, tb);
@ -878,8 +849,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);
} }
@ -1058,7 +1028,8 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t, int detPos) {
case CYCLES_NUMBER: case CYCLES_NUMBER:
case STORAGE_CELL_NUMBER: case STORAGE_CELL_NUMBER:
case MEASUREMENTS_NUMBER: case MEASUREMENTS_NUMBER:
throw RuntimeError("Cannot set number of frames, cycles,storage cells or measurements individually."); throw RuntimeError("Cannot set number of frames, cycles,storage cells or "
"measurements individually.");
default: default:
break; break;
} }
@ -1109,8 +1080,7 @@ double multiSlsDetector::setExposureTime(double t, bool inseconds, int detPos) {
return ((1E-9) * (double)tms); return ((1E-9) * (double)tms);
} }
double multiSlsDetector::setExposurePeriod(double t, bool inseconds, double multiSlsDetector::setExposurePeriod(double t, bool inseconds, int detPos) {
int detPos) {
if (!inseconds) { if (!inseconds) {
return setTimer(FRAME_PERIOD, (int64_t)t, detPos); return setTimer(FRAME_PERIOD, (int64_t)t, detPos);
} }
@ -1127,8 +1097,7 @@ double multiSlsDetector::setExposurePeriod(double t, bool inseconds,
return ((1E-9) * (double)tms); return ((1E-9) * (double)tms);
} }
double multiSlsDetector::setDelayAfterTrigger(double t, bool inseconds, double multiSlsDetector::setDelayAfterTrigger(double t, bool inseconds, int detPos) {
int detPos) {
if (!inseconds) { if (!inseconds) {
return setTimer(DELAY_AFTER_TRIGGER, (int64_t)t, detPos); return setTimer(DELAY_AFTER_TRIGGER, (int64_t)t, detPos);
} }
@ -1145,8 +1114,7 @@ double multiSlsDetector::setDelayAfterTrigger(double t, bool inseconds,
return ((1E-9) * (double)tms); return ((1E-9) * (double)tms);
} }
double multiSlsDetector::setSubFrameExposureTime(double t, bool inseconds, double multiSlsDetector::setSubFrameExposureTime(double t, bool inseconds, int detPos) {
int detPos) {
if (!inseconds) { if (!inseconds) {
return setTimer(SUBFRAME_ACQUISITION_TIME, (int64_t)t, detPos); return setTimer(SUBFRAME_ACQUISITION_TIME, (int64_t)t, detPos);
} else { } else {
@ -1163,8 +1131,7 @@ double multiSlsDetector::setSubFrameExposureTime(double t, bool inseconds,
} }
} }
double multiSlsDetector::setSubFrameExposureDeadTime(double t, bool inseconds, double multiSlsDetector::setSubFrameExposureDeadTime(double t, bool inseconds, int detPos) {
int detPos) {
if (!inseconds) { if (!inseconds) {
return setTimer(SUBFRAME_DEADTIME, (int64_t)t, detPos); return setTimer(SUBFRAME_DEADTIME, (int64_t)t, detPos);
} else { } else {
@ -1261,8 +1228,7 @@ int multiSlsDetector::setDynamicRange(int dr, int detPos) {
multi_shm()->numberOfChannels = 0; multi_shm()->numberOfChannels = 0;
for (auto &d : detectors) { for (auto &d : detectors) {
multi_shm()->dataBytes += d->getDataBytes(); multi_shm()->dataBytes += d->getDataBytes();
multi_shm()->dataBytesInclGapPixels += multi_shm()->dataBytesInclGapPixels += d->getDataBytesInclGapPixels();
d->getDataBytesInclGapPixels();
multi_shm()->numberOfChannels += d->getTotalNumberOfChannels(); multi_shm()->numberOfChannels += d->getTotalNumberOfChannels();
} }
@ -1275,8 +1241,7 @@ int multiSlsDetector::setDynamicRange(int dr, int detPos) {
setSpeed(CLOCK_DIVIDER, 2); setSpeed(CLOCK_DIVIDER, 2);
break; break;
case 16: case 16:
FILE_LOG(logINFO) FILE_LOG(logINFO) << "Setting Clock to Half Speed for Dynamic Range of 16";
<< "Setting Clock to Half Speed for Dynamic Range of 16";
setSpeed(CLOCK_DIVIDER, 1); setSpeed(CLOCK_DIVIDER, 1);
break; break;
default: default:
@ -1340,8 +1305,7 @@ int multiSlsDetector::getADC(dacIndex index, int detPos) {
} }
slsDetectorDefs::externalCommunicationMode slsDetectorDefs::externalCommunicationMode
multiSlsDetector::setExternalCommunicationMode(externalCommunicationMode pol, multiSlsDetector::setExternalCommunicationMode(externalCommunicationMode pol, int detPos) {
int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setExternalCommunicationMode(pol); return detectors[detPos]->setExternalCommunicationMode(pol);
@ -1353,16 +1317,14 @@ multiSlsDetector::setExternalCommunicationMode(externalCommunicationMode pol,
} }
slsDetectorDefs::externalSignalFlag slsDetectorDefs::externalSignalFlag
multiSlsDetector::setExternalSignalFlags(externalSignalFlag pol, multiSlsDetector::setExternalSignalFlags(externalSignalFlag pol, int signalindex, int detPos) {
int signalindex, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setExternalSignalFlags(pol, signalindex); return detectors[detPos]->setExternalSignalFlags(pol, signalindex);
} }
// multi // multi
auto r = auto r = parallelCall(&slsDetector::setExternalSignalFlags, pol, signalindex);
parallelCall(&slsDetector::setExternalSignalFlags, pol, signalindex);
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
@ -1377,8 +1339,7 @@ int multiSlsDetector::setReadOutFlags(readOutFlags flag, int detPos) {
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
uint32_t multiSlsDetector::writeRegister(uint32_t addr, uint32_t val, uint32_t multiSlsDetector::writeRegister(uint32_t addr, uint32_t val, int detPos) {
int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->writeRegister(addr, val); return detectors[detPos]->writeRegister(addr, val);
@ -1392,9 +1353,8 @@ uint32_t multiSlsDetector::writeRegister(uint32_t addr, uint32_t val,
// can't have different values // can't have different values
std::ostringstream ss; std::ostringstream ss;
ss << "Error: Different Values for function writeRegister (write 0x" ss << "Error: Different Values for function writeRegister (write 0x" << std::hex << val
<< std::hex << val << " to addr 0x" << std::hex << addr << " to addr 0x" << std::hex << addr << std::dec << ")";
<< std::dec << ")";
throw RuntimeError(ss.str()); throw RuntimeError(ss.str());
} }
@ -1412,8 +1372,8 @@ uint32_t multiSlsDetector::readRegister(uint32_t addr, int detPos) {
// can't have different values // can't have different values
std::ostringstream ss; std::ostringstream ss;
ss << "Error: Different Values for function readRegister (read from 0x" ss << "Error: Different Values for function readRegister (read from 0x" << std::hex << addr
<< std::hex << addr << std::dec << ")"; << std::dec << ")";
throw RuntimeError(ss.str()); throw RuntimeError(ss.str());
} }
@ -1433,8 +1393,7 @@ uint32_t multiSlsDetector::setBit(uint32_t addr, int n, int detPos) {
std::ostringstream ss; std::ostringstream ss;
ss << "Error: Different Values for function setBit " ss << "Error: Different Values for function setBit "
"(set bit " "(set bit "
<< n << " to addr 0x" << std::hex << addr << std::dec << n << " to addr 0x" << std::hex << addr << std::dec << ")";
<< ")";
throw RuntimeError(ss.str()); throw RuntimeError(ss.str());
} }
@ -1452,8 +1411,8 @@ uint32_t multiSlsDetector::clearBit(uint32_t addr, int n, int detPos) {
// can't have different values // can't have different values
std::ostringstream ss; std::ostringstream ss;
ss << "Error: Different Values for function clearBit (clear bit " ss << "Error: Different Values for function clearBit (clear bit " << n << " to addr 0x"
<< n << " to addr 0x" << std::hex << addr << std::dec << ")"; << std::hex << addr << std::dec << ")";
throw RuntimeError(ss.str()); throw RuntimeError(ss.str());
} }
@ -1687,8 +1646,7 @@ 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);
@ -1721,8 +1679,7 @@ 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);
@ -1788,7 +1745,8 @@ std::string multiSlsDetector::getAdditionalJsonHeader(int detPos) {
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
std::string multiSlsDetector::setAdditionalJsonParameter(const std::string &key, const std::string &value, int detPos) { std::string multiSlsDetector::setAdditionalJsonParameter(const std::string &key,
const std::string &value, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setAdditionalJsonParameter(key, value); return detectors[detPos]->setAdditionalJsonParameter(key, value);
@ -1907,9 +1865,7 @@ int multiSlsDetector::digitalTest(digitalTestMode mode, int ival, int detPos) {
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
int multiSlsDetector::loadImageToDetector(imageType index, int multiSlsDetector::loadImageToDetector(imageType index, const std::string &fname, int detPos) {
const std::string &fname,
int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->loadImageToDetector(index, fname); return detectors[detPos]->loadImageToDetector(index, fname);
@ -1921,21 +1877,20 @@ int multiSlsDetector::loadImageToDetector(imageType index,
int nch = multi_shm()->numberOfChannels; int nch = multi_shm()->numberOfChannels;
short int imageVals[nch]; short int imageVals[nch];
if (readDataFile(fname, imageVals, nch) < nch * (int)sizeof(short int)) { if (readDataFile(fname, imageVals, nch) < nch * (int)sizeof(short int)) {
throw RuntimeError("Could not open file or not enough data in file to load image to detector."); throw RuntimeError(
"Could not open file or not enough data in file to load image to detector.");
} }
// send image to all // send image to all
std::vector<int> r; std::vector<int> r;
for (size_t idet = 0; idet < detectors.size(); ++idet) { for (size_t idet = 0; idet < detectors.size(); ++idet) {
r.push_back(detectors[idet]->sendImageToDetector( r.push_back(detectors[idet]->sendImageToDetector(
index, index, imageVals + idet * detectors[idet]->getTotalNumberOfChannels()));
imageVals + idet * detectors[idet]->getTotalNumberOfChannels()));
} }
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL; return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
} }
int multiSlsDetector::writeCounterBlockFile(const std::string &fname, int multiSlsDetector::writeCounterBlockFile(const std::string &fname, int startACQ, int detPos) {
int startACQ, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->writeCounterBlockFile(fname, startACQ); return detectors[detPos]->writeCounterBlockFile(fname, startACQ);
@ -1949,14 +1904,12 @@ int multiSlsDetector::writeCounterBlockFile(const std::string &fname,
std::vector<int> r; std::vector<int> r;
for (size_t idet = 0; idet < detectors.size(); ++idet) { for (size_t idet = 0; idet < detectors.size(); ++idet) {
r.push_back(detectors[idet]->getCounterBlock( r.push_back(detectors[idet]->getCounterBlock(
imageVals + idet * detectors[idet]->getTotalNumberOfChannels(), imageVals + idet * detectors[idet]->getTotalNumberOfChannels(), startACQ));
startACQ));
} }
// write image if all ok // write image if all ok
if (sls::allEqualTo(r, static_cast<int>(OK))) { if (sls::allEqualTo(r, static_cast<int>(OK))) {
if (writeDataFile(fname, nch, imageVals) < if (writeDataFile(fname, nch, imageVals) < nch * (int)sizeof(short int)) {
nch * (int)sizeof(short int)) {
throw RuntimeError("Could not open file to write or did not write enough data" throw RuntimeError("Could not open file to write or did not write enough data"
" in file to write counter block file from detector."); " in file to write counter block file from detector.");
} }
@ -2010,8 +1963,8 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
} }
// multi // multi
int xmin = 0, xmax = 0, ymin = 0, ymax = 0, channelX = 0, channelY = 0, idet = 0, lastChannelX = 0, int xmin = 0, xmax = 0, ymin = 0, ymax = 0, channelX = 0, channelY = 0, idet = 0,
lastChannelY = 0, index = 0, offsetX = 0, offsetY = 0; lastChannelX = 0, lastChannelY = 0, index = 0, offsetX = 0, offsetY = 0;
bool invalidroi = false; bool invalidroi = false;
int ndet = detectors.size(); int ndet = detectors.size();
@ -2029,8 +1982,8 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
verifyMinMaxROI(n, roiLimits); verifyMinMaxROI(n, roiLimits);
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"
<< "\t" << roiLimits[i].ymin << "\t" << roiLimits[i].ymax; << 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) {
@ -2043,7 +1996,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" << channelX << "\t" << channelY; << "det:" << idet << "\t" << xmax << "\t" << ymax << "\t"
<< channelX << "\t" << channelY;
if (idet == -1) { if (idet == -1) {
FILE_LOG(logERROR) << "invalid roi"; FILE_LOG(logERROR) << "invalid roi";
continue; continue;
@ -2058,21 +2012,16 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[], int detPos) {
// 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 << "\t" << channelX << "\t" << channelY; << "det:" << idet << "\t" << xmin << "\t" << ymin << "\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;
break; break;
} }
// get last channel for each det in x and y dir // get last channel for each det in x and y dir
lastChannelX = lastChannelX = (detectors[idet]->getTotalNumberOfChannelsInclGapPixels(X)) - 1;
(detectors[idet]->getTotalNumberOfChannelsInclGapPixels( lastChannelY = (detectors[idet]->getTotalNumberOfChannelsInclGapPixels(Y)) - 1;
X)) -
1;
lastChannelY =
(detectors[idet]->getTotalNumberOfChannelsInclGapPixels(
Y)) -
1;
offsetX = detectors[idet]->getDetectorOffset(X); offsetX = detectors[idet]->getDetectorOffset(X);
offsetY = detectors[idet]->getDetectorOffset(Y); offsetY = detectors[idet]->getDetectorOffset(Y);
@ -2166,8 +2115,8 @@ slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) {
FILE_LOG(logINFO) << "detector " << idet << ":"; FILE_LOG(logINFO) << "detector " << idet << ":";
} }
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
<< temp[j].ymin << "\t" << temp[j].ymax; << "\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;
@ -2285,8 +2234,8 @@ 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
<< retval[i].ymin << "\t" << retval[i].ymax; << "\t" << retval[i].ymax;
} }
return retval; return retval;
} }
@ -2360,7 +2309,8 @@ int multiSlsDetector::setAllTrimbits(int val, int detPos) {
int multiSlsDetector::enableGapPixels(int val, int detPos) { int multiSlsDetector::enableGapPixels(int val, int detPos) {
if (getDetectorTypeAsEnum() != EIGER) { if (getDetectorTypeAsEnum() != EIGER) {
if (val >= 0) { if (val >= 0) {
throw NotImplementedError("Function (enableGapPixels) not implemented for this detector"); throw NotImplementedError(
"Function (enableGapPixels) not implemented for this detector");
} }
return 0; return 0;
} }
@ -2368,7 +2318,8 @@ int multiSlsDetector::enableGapPixels(int val, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
if (val >= 0) { if (val >= 0) {
throw RuntimeError("Function (enableGapPixels) must be called from a multi detector level."); throw RuntimeError(
"Function (enableGapPixels) must be called from a multi detector level.");
} }
return detectors[detPos]->enableGapPixels(val); return detectors[detPos]->enableGapPixels(val);
} }
@ -2711,8 +2662,7 @@ int multiSlsDetector::setReceiverFramesPerFile(int f, int detPos) {
} }
slsDetectorDefs::frameDiscardPolicy slsDetectorDefs::frameDiscardPolicy
multiSlsDetector::setReceiverFramesDiscardPolicy(frameDiscardPolicy f, multiSlsDetector::setReceiverFramesDiscardPolicy(frameDiscardPolicy f, int detPos) {
int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setReceiverFramesDiscardPolicy(f); return detectors[detPos]->setReceiverFramesDiscardPolicy(f);
@ -2745,8 +2695,7 @@ slsDetectorDefs::fileFormat multiSlsDetector::getFileFormat(int detPos) {
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
slsDetectorDefs::fileFormat multiSlsDetector::setFileFormat(fileFormat f, slsDetectorDefs::fileFormat multiSlsDetector::setFileFormat(fileFormat f, int detPos) {
int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setFileFormat(f); return detectors[detPos]->setFileFormat(f);
@ -2902,13 +2851,14 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
numSockets *= numSocketsPerDetector; numSockets *= numSocketsPerDetector;
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>(
detectors[iSocket / numSocketsPerDetector]->getClientStreamingIP().c_str(), portnum)); detectors[iSocket / numSocketsPerDetector]->getClientStreamingIP().c_str(),
FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at " << zmqSocket.back()->GetZmqServerAddress(); portnum));
FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at "
<< zmqSocket.back()->GetZmqServerAddress();
} catch (...) { } catch (...) {
FILE_LOG(logERROR) << "Could not create Zmq socket on port " << portnum; FILE_LOG(logERROR) << "Could not create Zmq socket on port " << portnum;
createReceivingDataSockets(true); createReceivingDataSockets(true);
@ -2923,10 +2873,8 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
void multiSlsDetector::readFrameFromReceiver() { void multiSlsDetector::readFrameFromReceiver() {
int nX = int nX = multi_shm()->numberOfDetector[X]; // to copy data in multi module
multi_shm()->numberOfDetector[X]; // to copy data in multi module int nY = multi_shm()->numberOfDetector[Y]; // for eiger, to reverse the data
int nY = multi_shm()
->numberOfDetector[Y]; // for eiger, to reverse the data
bool gappixelsenable = false; bool gappixelsenable = false;
bool eiger = false; bool eiger = false;
if (getDetectorTypeAsEnum() == EIGER) { if (getDetectorTypeAsEnum() == EIGER) {
@ -2945,7 +2893,8 @@ 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;
} }
} }
@ -2960,10 +2909,8 @@ void multiSlsDetector::readFrameFromReceiver() {
float bytesPerPixel = 0; float bytesPerPixel = 0;
// header info every header // header info every header
std::string currentFileName = ""; std::string currentFileName = "";
uint64_t currentAcquisitionIndex = -1, currentFrameIndex = -1, uint64_t currentAcquisitionIndex = -1, currentFrameIndex = -1, currentFileIndex = -1;
currentFileIndex = -1; uint32_t currentSubFrameIndex = -1, coordX = -1, coordY = -1, flippedDataX = -1;
uint32_t currentSubFrameIndex = -1, coordX = -1, coordY = -1,
flippedDataX = -1;
// wait for real time acquisition to start // wait for real time acquisition to start
bool running = true; bool running = true;
@ -2988,8 +2935,8 @@ void multiSlsDetector::readFrameFromReceiver() {
// HEADER // HEADER
{ {
rapidjson::Document doc; rapidjson::Document doc;
if (!zmqSocket[isocket]->ReceiveHeader( if (!zmqSocket[isocket]->ReceiveHeader(isocket, doc,
isocket, doc, SLS_DETECTOR_JSON_HEADER_VERSION)) { SLS_DETECTOR_JSON_HEADER_VERSION)) {
// parse error, version error or end of acquisition for // parse error, version error or end of acquisition for
// socket // socket
runningList[isocket] = false; runningList[isocket] = false;
@ -3012,9 +2959,13 @@ 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) << "One Time Header Info:" FILE_LOG(logDEBUG1)
<< "One Time Header Info:"
"\n\tsize: " "\n\tsize: "
<< size << "\n\tmultisize: " << multisize << "\n\tdynamicRange: " << dynamicRange << "\n\tbytesPerPixel: " << bytesPerPixel << "\n\tnPixelsX: " << nPixelsX << "\n\tnPixelsY: " << nPixelsY; << size << "\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();
@ -3028,9 +2979,16 @@ void multiSlsDetector::readFrameFromReceiver() {
coordY = (nY - 1) - coordY; coordY = (nY - 1) - coordY;
} }
flippedDataX = doc["flippedDataX"].GetUint(); flippedDataX = doc["flippedDataX"].GetUint();
FILE_LOG(logDEBUG1) << "Header Info:" FILE_LOG(logDEBUG1)
<< "Header Info:"
"\n\tcurrentFileName: " "\n\tcurrentFileName: "
<< currentFileName << "\n\tcurrentAcquisitionIndex: " << currentAcquisitionIndex << "\n\tcurrentFrameIndex: " << currentFrameIndex << "\n\tcurrentFileIndex: " << currentFileIndex << "\n\tcurrentSubFrameIndex: " << currentSubFrameIndex << "\n\tcoordX: " << coordX << "\n\tcoordY: " << coordY << "\n\tflippedDataX: " << flippedDataX; << currentFileName
<< "\n\tcurrentAcquisitionIndex: " << currentAcquisitionIndex
<< "\n\tcurrentFrameIndex: " << currentFrameIndex
<< "\n\tcurrentFileIndex: " << currentFileIndex
<< "\n\tcurrentSubFrameIndex: " << currentSubFrameIndex
<< "\n\tcoordX: " << coordX << "\n\tcoordY: " << coordY
<< "\n\tflippedDataX: " << flippedDataX;
} }
// DATA // DATA
@ -3045,23 +3003,20 @@ void multiSlsDetector::readFrameFromReceiver() {
uint32_t rowoffset = nX * singledetrowoffset; uint32_t rowoffset = nX * singledetrowoffset;
FILE_LOG(logDEBUG1) << "Multi Image Info:" FILE_LOG(logDEBUG1) << "Multi Image Info:"
"\n\txoffset: " "\n\txoffset: "
<< xoffset << "\n\tyoffset: " << yoffset << "\n\tsingledetrowoffset: " << singledetrowoffset << "\n\trowoffset: " << rowoffset; << xoffset << "\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) {
memcpy(((char *)multiframe) + memcpy(((char *)multiframe) +
((yoffset + (nPixelsY - 1 - i)) * ((yoffset + (nPixelsY - 1 - i)) * rowoffset) + xoffset,
rowoffset) + (char *)image + (i * singledetrowoffset), singledetrowoffset);
xoffset,
(char *)image + (i * singledetrowoffset),
singledetrowoffset);
} }
} else { } else {
for (uint32_t i = 0; i < nPixelsY; ++i) { for (uint32_t i = 0; i < nPixelsY; ++i) {
memcpy(((char *)multiframe) + memcpy(((char *)multiframe) + ((yoffset + i) * rowoffset) + xoffset,
((yoffset + i) * rowoffset) + xoffset, (char *)image + (i * singledetrowoffset), singledetrowoffset);
(char *)image + (i * singledetrowoffset),
singledetrowoffset);
} }
} }
} }
@ -3075,21 +3030,18 @@ void multiSlsDetector::readFrameFromReceiver() {
int n = processImageWithGapPixels(multiframe, multigappixels); int n = processImageWithGapPixels(multiframe, multigappixels);
nPixelsX = multi_shm()->numberOfChannelInclGapPixels[X]; nPixelsX = multi_shm()->numberOfChannelInclGapPixels[X];
nPixelsY = multi_shm()->numberOfChannelInclGapPixels[Y]; nPixelsY = multi_shm()->numberOfChannelInclGapPixels[Y];
thisData = new detectorData(getCurrentProgress(), thisData =
currentFileName.c_str(), nPixelsX, new detectorData(getCurrentProgress(), currentFileName.c_str(), nPixelsX,
nPixelsY, multigappixels, n, nPixelsY, multigappixels, n, dynamicRange, currentFileIndex);
dynamicRange, currentFileIndex);
} }
// normal pixels // normal pixels
else { else {
thisData = new detectorData(getCurrentProgress(), thisData = new detectorData(getCurrentProgress(), currentFileName.c_str(), nPixelsX,
currentFileName.c_str(), nPixelsX, nPixelsY, multiframe, multisize, dynamicRange,
nPixelsY, multiframe, multisize, currentFileIndex);
dynamicRange, currentFileIndex);
} }
dataReady(thisData, currentFrameIndex, dataReady(thisData, currentFrameIndex,
((dynamicRange == 32) ? currentSubFrameIndex : -1), ((dynamicRange == 32) ? currentSubFrameIndex : -1), pCallbackArg);
pCallbackArg);
delete thisData; delete thisData;
setCurrentProgress(currentAcquisitionIndex + 1); setCurrentProgress(currentAcquisitionIndex + 1);
} }
@ -3153,8 +3105,7 @@ int multiSlsDetector::processImageWithGapPixels(char *image, char *&gpImage) {
src = image; src = image;
dst = gpImage; dst = gpImage;
for (int row = 0; row < nychip; ++row) { // for each chip in a row for (int row = 0; row < nychip; ++row) { // for each chip in a row
for (int ichipy = 0; ichipy < b1chipy; for (int ichipy = 0; ichipy < b1chipy; ++ichipy) { // for each row in a chip
++ichipy) { // for each row in a chip
for (int col = 0; col < nxchip; ++col) { for (int col = 0; col < nxchip; ++col) {
memcpy(dst, src, b1chipx); memcpy(dst, src, b1chipx);
src += b1chipx; src += b1chipx;
@ -3174,8 +3125,7 @@ int multiSlsDetector::processImageWithGapPixels(char *image, char *&gpImage) {
int mod; int mod;
dst = gpImage; dst = gpImage;
for (int row = 0; row < nychip; ++row) { // for each chip in a row for (int row = 0; row < nychip; ++row) { // for each chip in a row
for (int ichipy = 0; ichipy < b1chipy; for (int ichipy = 0; ichipy < b1chipy; ++ichipy) { // for each row in a chip
++ichipy) { // for each row in a chip
for (int col = 0; col < nxchip; ++col) { for (int col = 0; col < nxchip; ++col) {
dst += b1chipx; dst += b1chipx;
mod = (col + 1) % 4; mod = (col + 1) % 4;
@ -3318,8 +3268,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable, int detPos) {
} }
// multi // multi
auto r = auto r = parallelCall(&slsDetector::enableDataStreamingFromReceiver, enable);
parallelCall(&slsDetector::enableDataStreamingFromReceiver, enable);
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
@ -3387,8 +3336,7 @@ uint64_t multiSlsDetector::setPatternWord(int addr, uint64_t word, int detPos) {
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
int multiSlsDetector::setPatternLoops(int level, int &start, int &stop, int &n, int multiSlsDetector::setPatternLoops(int level, int &start, int &stop, int &n, int detPos) {
int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setPatternLoops(level, start, stop, n); return detectors[detPos]->setPatternLoops(level, start, stop, n);
@ -3448,7 +3396,6 @@ uint64_t multiSlsDetector::getPatternMask(int detPos) {
} }
// should not have different values // should not have different values
throw RuntimeError("multiSlsDetector::getPatternMask: Error: Different Values returned)"); throw RuntimeError("multiSlsDetector::getPatternMask: Error: Different Values returned)");
} }
int multiSlsDetector::setPatternBitMask(uint64_t mask, int detPos) { int multiSlsDetector::setPatternBitMask(uint64_t mask, int detPos) {
@ -3494,8 +3441,7 @@ int multiSlsDetector::setDigitalIODelay(uint64_t pinMask, int delay, int detPos)
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL; return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
} }
int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1, int multiSlsDetector::retrieveDetectorSetup(const std::string &fname1, int level) {
int level) {
int skip = 0; int skip = 0;
std::string fname; std::string fname;
@ -3527,8 +3473,7 @@ 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" FILE_LOG(logDEBUG1) << "Line is a comment \n" << str;
<< str;
continue; continue;
} else { } else {
std::istringstream ssstr(str); std::istringstream ssstr(str);
@ -3647,9 +3592,9 @@ int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) {
break; break;
} }
//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;
@ -3665,9 +3610,8 @@ int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) {
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;
} }
outfile.close(); outfile.close();
} else { } else {
@ -3679,27 +3623,25 @@ int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) {
return OK; return OK;
} }
void multiSlsDetector::registerAcquisitionFinishedCallback( void multiSlsDetector::registerAcquisitionFinishedCallback(int (*func)(double, int, void *),
int (*func)(double, int, void *), void *pArg) { void *pArg) {
acquisition_finished = func; acquisition_finished = func;
acqFinished_p = pArg; acqFinished_p = pArg;
} }
void multiSlsDetector::registerMeasurementFinishedCallback(int (*func)(int, int, void multiSlsDetector::registerMeasurementFinishedCallback(int (*func)(int, int, void *),
void *),
void *pArg) { void *pArg) {
measurement_finished = func; measurement_finished = func;
measFinished_p = pArg; measFinished_p = pArg;
} }
void multiSlsDetector::registerProgressCallback(int (*func)(double, void *), void multiSlsDetector::registerProgressCallback(int (*func)(double, void *), void *pArg) {
void *pArg) {
progress_call = func; progress_call = func;
pProgressCallArg = pArg; pProgressCallArg = pArg;
} }
void multiSlsDetector::registerDataCallback( void multiSlsDetector::registerDataCallback(int (*userCallback)(detectorData *, int, int, void *),
int (*userCallback)(detectorData *, int, int, void *), void *pArg) { void *pArg) {
dataReady = userCallback; dataReady = userCallback;
pCallbackArg = pArg; pCallbackArg = pArg;
if (setReceiverOnline() == slsDetectorDefs::ONLINE_FLAG) { if (setReceiverOnline() == slsDetectorDefs::ONLINE_FLAG) {
@ -3743,8 +3685,7 @@ void multiSlsDetector::incrementProgress() {
std::lock_guard<std::mutex> lock(mp); std::lock_guard<std::mutex> lock(mp);
progressIndex++; progressIndex++;
std::cout << std::fixed << std::setprecision(2) << std::setw(6) std::cout << std::fixed << std::setprecision(2) << std::setw(6)
<< 100. * ((double)progressIndex) / ((double)totalProgress) << 100. * ((double)progressIndex) / ((double)totalProgress) << " \%";
<< " \%";
std::cout << '\r' << std::flush; std::cout << '\r' << std::flush;
} }
@ -3752,8 +3693,7 @@ void multiSlsDetector::setCurrentProgress(int i) {
std::lock_guard<std::mutex> lock(mp); std::lock_guard<std::mutex> lock(mp);
progressIndex = i; progressIndex = i;
std::cout << std::fixed << std::setprecision(2) << std::setw(6) std::cout << std::fixed << std::setprecision(2) << std::setw(6)
<< 100. * ((double)progressIndex) / ((double)totalProgress) << 100. * ((double)progressIndex) / ((double)totalProgress) << " \%";
<< " \%";
std::cout << '\r' << std::flush; std::cout << '\r' << std::flush;
} }
@ -3860,8 +3800,7 @@ int multiSlsDetector::acquire() {
} }
if (acquisition_finished) { if (acquisition_finished) {
acquisition_finished(getCurrentProgress(), getRunStatus(), acquisition_finished(getCurrentProgress(), getRunStatus(), acqFinished_p);
acqFinished_p);
} }
sem_destroy(&sem_newRTAcquisition); sem_destroy(&sem_newRTAcquisition);

File diff suppressed because it is too large Load Diff