fmt and minor

This commit is contained in:
Erik Frojdh 2020-02-04 10:11:27 +01:00
parent ec66079f65
commit b9446f40d1

View File

@ -125,7 +125,6 @@ std::string DetectorImpl::getUserDetails() {
return sstream.str(); return sstream.str();
} }
bool DetectorImpl::getInitialChecks() const { bool DetectorImpl::getInitialChecks() const {
return multi_shm()->initialChecks; return multi_shm()->initialChecks;
} }
@ -229,8 +228,7 @@ std::string DetectorImpl::exec(const char *cmd) {
return result; return result;
} }
void DetectorImpl::setVirtualDetectorServers(const int numdet, void DetectorImpl::setVirtualDetectorServers(const int numdet, const int port) {
const int port) {
std::vector<std::string> hostnames; std::vector<std::string> hostnames;
for (int i = 0; i < numdet; ++i) { for (int i = 0; i < numdet; ++i) {
// * 2 is for control and stop port // * 2 is for control and stop port
@ -290,7 +288,9 @@ void DetectorImpl::addSlsDetector(const std::string &hostname) {
detectors[pos]->setStopPort(port + 1); detectors[pos]->setStopPort(port + 1);
detectors[pos]->setHostname(host, multi_shm()->initialChecks); detectors[pos]->setHostname(host, multi_shm()->initialChecks);
// detector type updated by now // detector type updated by now
multi_shm()->multiDetectorType = Parallel(&slsDetector::getDetectorType, {}).tsquash("Inconsistent detector types."); multi_shm()->multiDetectorType =
Parallel(&slsDetector::getDetectorType, {})
.tsquash("Inconsistent detector types.");
} }
void DetectorImpl::updateDetectorSize() { void DetectorImpl::updateDetectorSize() {
@ -377,7 +377,8 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) {
if (multi_shm()->multiDetectorType == EIGER) { if (multi_shm()->multiDetectorType == EIGER) {
numSocketsPerDetector = 2; numSocketsPerDetector = 2;
} }
if (Parallel(&slsDetector::getNumberofUDPInterfacesFromShm, {}).squash() == 2) { if (Parallel(&slsDetector::getNumberofUDPInterfacesFromShm, {}).squash() ==
2) {
numSocketsPerDetector = 2; numSocketsPerDetector = 2;
} }
numSockets *= numSocketsPerDetector; numSockets *= numSocketsPerDetector;
@ -389,7 +390,8 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) {
try { try {
zmqSocket.push_back(sls::make_unique<ZmqSocket>( zmqSocket.push_back(sls::make_unique<ZmqSocket>(
detectors[iSocket / numSocketsPerDetector] detectors[iSocket / numSocketsPerDetector]
->getClientStreamingIP().str() ->getClientStreamingIP()
.str()
.c_str(), .c_str(),
portnum)); portnum));
FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at " FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at "
@ -416,7 +418,9 @@ void DetectorImpl::readFrameFromReceiver() {
bool gappixelsenable = false; bool gappixelsenable = false;
bool quadEnable = false; bool quadEnable = false;
bool eiger = false; bool eiger = false;
bool numInterfaces = Parallel(&slsDetector::getNumberofUDPInterfacesFromShm, {}).squash(); // cannot pick up from zmq bool numInterfaces =
Parallel(&slsDetector::getNumberofUDPInterfacesFromShm, {})
.squash(); // cannot pick up from zmq
bool runningList[zmqSocket.size()], connectList[zmqSocket.size()]; bool runningList[zmqSocket.size()], connectList[zmqSocket.size()];
int numRunning = 0; int numRunning = 0;
@ -443,7 +447,7 @@ void DetectorImpl::readFrameFromReceiver() {
uint32_t size = 0, nPixelsX = 0, nPixelsY = 0, dynamicRange = 0; uint32_t size = 0, nPixelsX = 0, nPixelsY = 0, dynamicRange = 0;
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, uint32_t currentSubFrameIndex = -1, coordX = -1, coordY = -1,
@ -579,8 +583,8 @@ void DetectorImpl::readFrameFromReceiver() {
} }
} else { } else {
for (uint32_t i = 0; i < nPixelsY; ++i) { for (uint32_t i = 0; i < nPixelsY; ++i) {
memcpy((multiframe) + memcpy((multiframe) + ((yoffset + i) * rowoffset) +
((yoffset + i) * rowoffset) + xoffset, xoffset,
image + (i * singledetrowoffset), image + (i * singledetrowoffset),
singledetrowoffset); singledetrowoffset);
} }
@ -612,19 +616,20 @@ void DetectorImpl::readFrameFromReceiver() {
<< "\n\t nDetPixelsX: " << nDetPixelsX << "\n\t nDetPixelsX: " << nDetPixelsX
<< "\n\t nDetPixelsY: " << nDetPixelsY << "\n\t nDetPixelsY: " << nDetPixelsY
<< "\n\t databytes: " << n; << "\n\t databytes: " << n;
thisData = new detectorData( thisData =
getCurrentProgress(), currentFileName.c_str(), nDetPixelsX, new detectorData(getCurrentProgress(), currentFileName,
nDetPixelsY, multigappixels, n, dynamicRange, nDetPixelsX, nDetPixelsY, multigappixels,
currentFileIndex); n, dynamicRange, currentFileIndex);
} }
// normal pixels // normal pixels
else { else {
thisData = new detectorData( thisData =
getCurrentProgress(), currentFileName.c_str(), nDetPixelsX, new detectorData(getCurrentProgress(), currentFileName,
nDetPixelsY, multiframe, multisize, dynamicRange, nDetPixelsX, nDetPixelsY, multiframe,
currentFileIndex); multisize, dynamicRange, currentFileIndex);
} }
dataReady(thisData, currentFrameIndex, dataReady(
thisData, currentFrameIndex,
((dynamicRange == 32 && eiger) ? currentSubFrameIndex : -1), ((dynamicRange == 32 && eiger) ? currentSubFrameIndex : -1),
pCallbackArg); pCallbackArg);
delete thisData; delete thisData;
@ -817,7 +822,6 @@ bool DetectorImpl::enableDataStreamingToClient(int enable) {
return client_downstream; return client_downstream;
} }
void DetectorImpl::savePattern(const std::string &fname) { void DetectorImpl::savePattern(const std::string &fname) {
// std::ofstream outfile; // std::ofstream outfile;
// outfile.open(fname.c_str(), std::ios_base::out); // outfile.open(fname.c_str(), std::ios_base::out);
@ -858,16 +862,16 @@ void DetectorImpl::savePattern(const std::string &fname) {
// multiSlsDetectorClient(cmd, GET_ACTION, this, outfile); // multiSlsDetectorClient(cmd, GET_ACTION, this, outfile);
} }
void DetectorImpl::registerAcquisitionFinishedCallback(void (*func)(double, int,
void *),
void DetectorImpl::registerAcquisitionFinishedCallback( void *pArg) {
void (*func)(double, int, void *), void *pArg) {
acquisition_finished = func; acquisition_finished = func;
acqFinished_p = pArg; acqFinished_p = pArg;
} }
void DetectorImpl::registerDataCallback( void DetectorImpl::registerDataCallback(void (*userCallback)(detectorData *,
void (*userCallback)(detectorData *, uint64_t, uint32_t, void *), uint64_t, uint32_t,
void *),
void *pArg) { void *pArg) {
dataReady = userCallback; dataReady = userCallback;
pCallbackArg = pArg; pCallbackArg = pArg;
@ -885,7 +889,8 @@ double DetectorImpl::setTotalProgress() {
int ns = 1; int ns = 1;
if (multi_shm()->multiDetectorType == JUNGFRAU) { if (multi_shm()->multiDetectorType == JUNGFRAU) {
ns = Parallel(&slsDetector::getNumberOfAdditionalStorageCellsFromShm, {}) ns =
Parallel(&slsDetector::getNumberOfAdditionalStorageCellsFromShm, {})
.tsquash("Inconsistent number of additional storage cells"); .tsquash("Inconsistent number of additional storage cells");
++ns; ++ns;
} }
@ -905,8 +910,7 @@ void DetectorImpl::incrementProgress() {
std::lock_guard<std::mutex> lock(mp); std::lock_guard<std::mutex> lock(mp);
progressIndex += 1; progressIndex += 1;
std::cout << std::fixed << std::setprecision(2) << std::setw(6) std::cout << std::fixed << std::setprecision(2) << std::setw(6)
<< 100. * progressIndex / totalProgress << 100. * progressIndex / totalProgress << " \%";
<< " \%";
std::cout << '\r' << std::flush; std::cout << '\r' << std::flush;
} }
@ -914,8 +918,7 @@ void DetectorImpl::setCurrentProgress(int64_t i) {
std::lock_guard<std::mutex> lock(mp); std::lock_guard<std::mutex> lock(mp);
progressIndex = (double)i; progressIndex = (double)i;
std::cout << std::fixed << std::setprecision(2) << std::setw(6) std::cout << std::fixed << std::setprecision(2) << std::setw(6)
<< 100. * progressIndex / totalProgress << 100. * progressIndex / totalProgress << " \%";
<< " \%";
std::cout << '\r' << std::flush; std::cout << '\r' << std::flush;
} }
@ -929,21 +932,23 @@ int DetectorImpl::acquire() {
struct timespec begin, end; struct timespec begin, end;
clock_gettime(CLOCK_REALTIME, &begin); clock_gettime(CLOCK_REALTIME, &begin);
// in the real time acquisition loop, processing thread will wait for a post // in the real time acquisition loop, processing thread will wait for a
// each time // post each time
sem_init(&sem_newRTAcquisition, 1, 0); sem_init(&sem_newRTAcquisition, 1, 0);
// in the real time acquistion loop, main thread will wait for processing // in the real time acquistion loop, main thread will wait for
// thread to be done each time (which in turn waits for receiver/ext // processing thread to be done each time (which in turn waits for
// process) // receiver/ext process)
sem_init(&sem_endRTAcquisition, 1, 0); sem_init(&sem_endRTAcquisition, 1, 0);
bool receiver = Parallel(&slsDetector::getUseReceiverFlag, {}).squash(false); bool receiver =
Parallel(&slsDetector::getUseReceiverFlag, {}).squash(false);
progressIndex = 0; progressIndex = 0;
setJoinThreadFlag(false); setJoinThreadFlag(false);
// verify receiver is idle // verify receiver is idle
if (receiver) { if (receiver) {
if (Parallel(&slsDetector::getReceiverStatus, {}).squash(ERROR) != IDLE) { if (Parallel(&slsDetector::getReceiverStatus, {}).squash(ERROR) !=
IDLE) {
Parallel(&slsDetector::stopReceiver, {}); Parallel(&slsDetector::stopReceiver, {});
} }
} }
@ -992,8 +997,7 @@ int DetectorImpl::acquire() {
auto t = Parallel(&slsDetector::getRunStatus, {}); auto t = Parallel(&slsDetector::getRunStatus, {});
if (t.equal()) if (t.equal())
status = t.front(); status = t.front();
acquisition_finished(getCurrentProgress(), status, acquisition_finished(getCurrentProgress(), status, acqFinished_p);
acqFinished_p);
} }
sem_destroy(&sem_newRTAcquisition); sem_destroy(&sem_newRTAcquisition);
@ -1035,7 +1039,8 @@ void DetectorImpl::processData() {
} }
} }
// get progress // get progress
caught = Parallel(&slsDetector::getFramesCaughtByReceiver, {0}).squash(); caught = Parallel(&slsDetector::getFramesCaughtByReceiver, {0})
.squash();
// updating progress // updating progress
if (caught != -1) { if (caught != -1) {
@ -1098,7 +1103,6 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
<< "Updating Firmware. This can take awhile. Please be patient..."; << "Updating Firmware. This can take awhile. Please be patient...";
FILE_LOG(logDEBUG1) << "Programming FPGA with file name:" << fname; FILE_LOG(logDEBUG1) << "Programming FPGA with file name:" << fname;
size_t filesize = 0; size_t filesize = 0;
// check if it exists // check if it exists
struct stat st; struct stat st;
@ -1128,9 +1132,8 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
// convert src to dst rawbin // convert src to dst rawbin
FILE_LOG(logDEBUG1) << "Converting " << fname << " to " << destfname; FILE_LOG(logDEBUG1) << "Converting " << fname << " to " << destfname;
{ {
const int pofNumHeaderBytes = 0x11C; constexpr int pofNumHeaderBytes = 0x11C;
const int pofNumPadding = 0x80; constexpr int pofFooterOfst = 0x1000000;
const int pofFooterOfst = 0x1000000;
int dstFilePos = 0; int dstFilePos = 0;
if (isPof) { if (isPof) {
// Read header and discard // Read header and discard
@ -1138,14 +1141,13 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
fgetc(src); fgetc(src);
} }
// Write 0xFF to destination 0x80 times (padding) // Write 0xFF to destination 0x80 times (padding)
{ constexpr int pofNumPadding{0x80};
char c = 0xFF; constexpr uint8_t c{0xFF};
while (dstFilePos < pofNumPadding) { while (dstFilePos < pofNumPadding) {
write(dst, &c, 1); write(dst, &c, sizeof(c));
++dstFilePos; ++dstFilePos;
} }
} }
}
// Swap bits from source and write to dest // Swap bits from source and write to dest
while (!feof(src)) { while (!feof(src)) {
// pof: exit early to discard footer // pof: exit early to discard footer
@ -1160,8 +1162,7 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
// swap bits // swap bits
int d = 0; int d = 0;
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
d = d | d = d | (((s & (1 << i)) >> i) << (7 - i));
(((s & (1 << i)) >> i) << (7 - i));
} }
write(dst, &d, 1); write(dst, &d, 1);
++dstFilePos; ++dstFilePos;
@ -1171,7 +1172,6 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
throw RuntimeError( throw RuntimeError(
"Could not convert programming file. EOF before end of flash"); "Could not convert programming file. EOF before end of flash");
} }
} }
if (fclose(src) != 0) { if (fclose(src) != 0) {
throw RuntimeError("Program FPGA: Could not close source file"); throw RuntimeError("Program FPGA: Could not close source file");