From b9446f40d1ace10e396e91c9555af8093eb4a21e Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Tue, 4 Feb 2020 10:11:27 +0100 Subject: [PATCH] fmt and minor --- slsDetectorSoftware/src/DetectorImpl.cpp | 162 +++++++++++------------ 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index b9de65966..3ba4b5aca 100755 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -125,7 +125,6 @@ std::string DetectorImpl::getUserDetails() { return sstream.str(); } - bool DetectorImpl::getInitialChecks() const { return multi_shm()->initialChecks; } @@ -229,8 +228,7 @@ std::string DetectorImpl::exec(const char *cmd) { return result; } -void DetectorImpl::setVirtualDetectorServers(const int numdet, - const int port) { +void DetectorImpl::setVirtualDetectorServers(const int numdet, const int port) { std::vector hostnames; for (int i = 0; i < numdet; ++i) { // * 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]->setHostname(host, multi_shm()->initialChecks); // 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() { @@ -377,7 +377,8 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) { if (multi_shm()->multiDetectorType == EIGER) { numSocketsPerDetector = 2; } - if (Parallel(&slsDetector::getNumberofUDPInterfacesFromShm, {}).squash() == 2) { + if (Parallel(&slsDetector::getNumberofUDPInterfacesFromShm, {}).squash() == + 2) { numSocketsPerDetector = 2; } numSockets *= numSocketsPerDetector; @@ -389,7 +390,8 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) { try { zmqSocket.push_back(sls::make_unique( detectors[iSocket / numSocketsPerDetector] - ->getClientStreamingIP().str() + ->getClientStreamingIP() + .str() .c_str(), portnum)); FILE_LOG(logINFO) << "Zmq Client[" << iSocket << "] at " @@ -416,7 +418,9 @@ void DetectorImpl::readFrameFromReceiver() { bool gappixelsenable = false; bool quadEnable = 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()]; int numRunning = 0; @@ -443,7 +447,7 @@ void DetectorImpl::readFrameFromReceiver() { uint32_t size = 0, nPixelsX = 0, nPixelsY = 0, dynamicRange = 0; float bytesPerPixel = 0; // header info every header - std::string currentFileName = ""; + std::string currentFileName; uint64_t currentAcquisitionIndex = -1, currentFrameIndex = -1, currentFileIndex = -1; uint32_t currentSubFrameIndex = -1, coordX = -1, coordY = -1, @@ -579,8 +583,8 @@ void DetectorImpl::readFrameFromReceiver() { } } else { for (uint32_t i = 0; i < nPixelsY; ++i) { - memcpy((multiframe) + - ((yoffset + i) * rowoffset) + xoffset, + memcpy((multiframe) + ((yoffset + i) * rowoffset) + + xoffset, image + (i * singledetrowoffset), singledetrowoffset); } @@ -612,21 +616,22 @@ void DetectorImpl::readFrameFromReceiver() { << "\n\t nDetPixelsX: " << nDetPixelsX << "\n\t nDetPixelsY: " << nDetPixelsY << "\n\t databytes: " << n; - thisData = new detectorData( - getCurrentProgress(), currentFileName.c_str(), nDetPixelsX, - nDetPixelsY, multigappixels, n, dynamicRange, - currentFileIndex); + thisData = + new detectorData(getCurrentProgress(), currentFileName, + nDetPixelsX, nDetPixelsY, multigappixels, + n, dynamicRange, currentFileIndex); } // normal pixels else { - thisData = new detectorData( - getCurrentProgress(), currentFileName.c_str(), nDetPixelsX, - nDetPixelsY, multiframe, multisize, dynamicRange, - currentFileIndex); + thisData = + new detectorData(getCurrentProgress(), currentFileName, + nDetPixelsX, nDetPixelsY, multiframe, + multisize, dynamicRange, currentFileIndex); } - dataReady(thisData, currentFrameIndex, - ((dynamicRange == 32 && eiger) ? currentSubFrameIndex : -1), - pCallbackArg); + dataReady( + thisData, currentFrameIndex, + ((dynamicRange == 32 && eiger) ? currentSubFrameIndex : -1), + pCallbackArg); delete thisData; } @@ -668,7 +673,7 @@ void DetectorImpl::readFrameFromReceiver() { } int DetectorImpl::processImageWithGapPixels(char *image, char *&gpImage, - bool quadEnable) { + bool quadEnable) { // eiger 4 bit mode int nxb = multi_shm()->numberOfDetector.x * (512 + 3); //(divided by 2 already) @@ -817,7 +822,6 @@ bool DetectorImpl::enableDataStreamingToClient(int enable) { return client_downstream; } - void DetectorImpl::savePattern(const std::string &fname) { // std::ofstream outfile; // outfile.open(fname.c_str(), std::ios_base::out); @@ -836,7 +840,7 @@ void DetectorImpl::savePattern(const std::string &fname) { // } // // rest of pattern file // const std::vector commands{ - // "patioctrl", + // "patioctrl", // "patclkctrl", // "patlimits", // "patloop0", @@ -858,35 +862,36 @@ void DetectorImpl::savePattern(const std::string &fname) { // multiSlsDetectorClient(cmd, GET_ACTION, this, outfile); } - - -void DetectorImpl::registerAcquisitionFinishedCallback( - void (*func)(double, int, void *), void *pArg) { +void DetectorImpl::registerAcquisitionFinishedCallback(void (*func)(double, int, + void *), + void *pArg) { acquisition_finished = func; acqFinished_p = pArg; } -void DetectorImpl::registerDataCallback( - void (*userCallback)(detectorData *, uint64_t, uint32_t, void *), - void *pArg) { +void DetectorImpl::registerDataCallback(void (*userCallback)(detectorData *, + uint64_t, uint32_t, + void *), + void *pArg) { dataReady = userCallback; pCallbackArg = pArg; - enableDataStreamingToClient(dataReady == nullptr ? 0 : 1); + enableDataStreamingToClient(dataReady == nullptr ? 0 : 1); } double DetectorImpl::setTotalProgress() { int64_t nf = Parallel(&slsDetector::getNumberOfFramesFromShm, {}) - .tsquash("Inconsistent number of frames"); + .tsquash("Inconsistent number of frames"); int64_t nc = Parallel(&slsDetector::getNumberOfTriggersFromShm, {}) - .tsquash("Inconsistent number of triggers"); + .tsquash("Inconsistent number of triggers"); if (nf == 0 || nc == 0) { throw RuntimeError("Number of frames or triggers is 0"); } int ns = 1; if (multi_shm()->multiDetectorType == JUNGFRAU) { - ns = Parallel(&slsDetector::getNumberOfAdditionalStorageCellsFromShm, {}) - .tsquash("Inconsistent number of additional storage cells"); + ns = + Parallel(&slsDetector::getNumberOfAdditionalStorageCellsFromShm, {}) + .tsquash("Inconsistent number of additional storage cells"); ++ns; } @@ -905,8 +910,7 @@ void DetectorImpl::incrementProgress() { std::lock_guard lock(mp); progressIndex += 1; std::cout << std::fixed << std::setprecision(2) << std::setw(6) - << 100. * progressIndex / totalProgress - << " \%"; + << 100. * progressIndex / totalProgress << " \%"; std::cout << '\r' << std::flush; } @@ -914,8 +918,7 @@ void DetectorImpl::setCurrentProgress(int64_t i) { std::lock_guard lock(mp); progressIndex = (double)i; std::cout << std::fixed << std::setprecision(2) << std::setw(6) - << 100. * progressIndex / totalProgress - << " \%"; + << 100. * progressIndex / totalProgress << " \%"; std::cout << '\r' << std::flush; } @@ -929,21 +932,23 @@ int DetectorImpl::acquire() { struct timespec begin, end; clock_gettime(CLOCK_REALTIME, &begin); - // in the real time acquisition loop, processing thread will wait for a post - // each time + // in the real time acquisition loop, processing thread will wait for a + // post each time sem_init(&sem_newRTAcquisition, 1, 0); - // in the real time acquistion loop, main thread will wait for processing - // thread to be done each time (which in turn waits for receiver/ext - // process) + // in the real time acquistion loop, main thread will wait for + // processing thread to be done each time (which in turn waits for + // receiver/ext process) sem_init(&sem_endRTAcquisition, 1, 0); - bool receiver = Parallel(&slsDetector::getUseReceiverFlag, {}).squash(false); + bool receiver = + Parallel(&slsDetector::getUseReceiverFlag, {}).squash(false); progressIndex = 0; setJoinThreadFlag(false); // verify receiver is idle if (receiver) { - if (Parallel(&slsDetector::getReceiverStatus, {}).squash(ERROR) != IDLE) { + if (Parallel(&slsDetector::getReceiverStatus, {}).squash(ERROR) != + IDLE) { Parallel(&slsDetector::stopReceiver, {}); } } @@ -992,8 +997,7 @@ int DetectorImpl::acquire() { auto t = Parallel(&slsDetector::getRunStatus, {}); if (t.equal()) status = t.front(); - acquisition_finished(getCurrentProgress(), status, - acqFinished_p); + acquisition_finished(getCurrentProgress(), status, acqFinished_p); } sem_destroy(&sem_newRTAcquisition); @@ -1035,7 +1039,8 @@ void DetectorImpl::processData() { } } // get progress - caught = Parallel(&slsDetector::getFramesCaughtByReceiver, {0}).squash(); + caught = Parallel(&slsDetector::getFramesCaughtByReceiver, {0}) + .squash(); // updating progress if (caught != -1) { @@ -1077,28 +1082,27 @@ std::vector DetectorImpl::readProgrammingFile(const std::string &fname) { // validate type of file bool isPof = false; switch (multi_shm()->multiDetectorType) { - case JUNGFRAU: - case CHIPTESTBOARD: - if (fname.find(".pof") == std::string::npos) { - throw RuntimeError("Programming file must be a pof file."); - } - isPof = true; - break; - case MYTHEN3: - case GOTTHARD2: - if (fname.find(".rbf") == std::string::npos) { - throw RuntimeError("Programming file must be an rbf file."); - } - break; - default: - throw RuntimeError("Not implemented for this detector"); + case JUNGFRAU: + case CHIPTESTBOARD: + if (fname.find(".pof") == std::string::npos) { + throw RuntimeError("Programming file must be a pof file."); + } + isPof = true; + break; + case MYTHEN3: + case GOTTHARD2: + if (fname.find(".rbf") == std::string::npos) { + throw RuntimeError("Programming file must be an rbf file."); + } + break; + default: + throw RuntimeError("Not implemented for this detector"); } FILE_LOG(logINFO) << "Updating Firmware. This can take awhile. Please be patient..."; FILE_LOG(logDEBUG1) << "Programming FPGA with file name:" << fname; - size_t filesize = 0; // check if it exists struct stat st; @@ -1128,22 +1132,20 @@ std::vector DetectorImpl::readProgrammingFile(const std::string &fname) { // convert src to dst rawbin FILE_LOG(logDEBUG1) << "Converting " << fname << " to " << destfname; { - const int pofNumHeaderBytes = 0x11C; - const int pofNumPadding = 0x80; - const int pofFooterOfst = 0x1000000; - int dstFilePos = 0; + constexpr int pofNumHeaderBytes = 0x11C; + constexpr int pofFooterOfst = 0x1000000; + int dstFilePos = 0; if (isPof) { // Read header and discard for (int i = 0; i < pofNumHeaderBytes; ++i) { fgetc(src); } // Write 0xFF to destination 0x80 times (padding) - { - char c = 0xFF; - while (dstFilePos < pofNumPadding) { - write(dst, &c, 1); - ++dstFilePos; - } + constexpr int pofNumPadding{0x80}; + constexpr uint8_t c{0xFF}; + while (dstFilePos < pofNumPadding) { + write(dst, &c, sizeof(c)); + ++dstFilePos; } } // Swap bits from source and write to dest @@ -1156,12 +1158,11 @@ std::vector DetectorImpl::readProgrammingFile(const std::string &fname) { int s = fgetc(src); if (s < 0) { break; - } - // swap bits + } + // swap bits int d = 0; for (int i = 0; i < 8; ++i) { - d = d | - (((s & (1 << i)) >> i) << (7 - i)); + d = d | (((s & (1 << i)) >> i) << (7 - i)); } write(dst, &d, 1); ++dstFilePos; @@ -1171,7 +1172,6 @@ std::vector DetectorImpl::readProgrammingFile(const std::string &fname) { throw RuntimeError( "Could not convert programming file. EOF before end of flash"); } - } if (fclose(src) != 0) { throw RuntimeError("Program FPGA: Could not close source file");