From 9f84bf71759d607b957bcf1fc88eb22c59d8378a Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 20 Sep 2018 18:10:10 +0200 Subject: [PATCH] gui: crashing when using roi fixed --- cmk.sh | 17 ++++++++++--- slsReceiverSoftware/include/DataStreamer.h | 4 +-- slsReceiverSoftware/include/GeneralData.h | 20 +++++++-------- .../include/UDPBaseImplementation.h | 6 ++--- slsReceiverSoftware/include/UDPInterface.h | 4 +-- .../include/UDPStandardImplementation.h | 2 +- slsReceiverSoftware/src/DataStreamer.cpp | 25 +++++++++++++------ .../src/UDPBaseImplementation.cpp | 14 +++++------ .../src/UDPStandardImplementation.cpp | 22 ++++++++-------- .../src/slsReceiverTCPIPInterface.cpp | 6 +++-- 10 files changed, 70 insertions(+), 50 deletions(-) diff --git a/cmk.sh b/cmk.sh index 5f150c845..7f4c7fda1 100755 --- a/cmk.sh +++ b/cmk.sh @@ -6,6 +6,7 @@ COMPILERTHREADS=0 TEXTCLIENT=0 RECEIVER=0 GUI=0 +DEBUG=0 CLEAN=0 @@ -24,6 +25,7 @@ Usage: $0 [-c] [-b] [-h] [-d ] [-j] -r: Build/Rebuilds only receiver -g: Build/Rebuilds only gui -j: Number of threads to compile through + -e: Debug mode For only make: ./cmk.sh @@ -53,7 +55,7 @@ For rebuilding only certain sections " ; exit 1; } -while getopts ":bchd:j:trg" opt ; do +while getopts ":bchd:j:trge" opt ; do case $opt in b) echo "Building of CMake files Required" @@ -90,7 +92,11 @@ while getopts ":bchd:j:trg" opt ; do echo "Compiling Options: GUI" GUI=1 REBUILD=1 - ;; + ;; + e) + echo "Compiling Options: Debug" + DEBUG=1 + ;; \?) echo "Invalid option: -$OPTARG" usage @@ -145,7 +151,12 @@ else fi fi -#CMAKE_POST+=" -DCMAKE_BUILD_TYPE=Debug " +#Debug +if [ $DEBUG -eq 1 ]; then + CMAKE_POST+=" -DCMAKE_BUILD_TYPE=Debug " + echo "Debug Option enabled" +fi + #hdf5 rebuild if [ $HDF5 -eq 1 ]; then diff --git a/slsReceiverSoftware/include/DataStreamer.h b/slsReceiverSoftware/include/DataStreamer.h index fb4f4520e..d939f203b 100644 --- a/slsReceiverSoftware/include/DataStreamer.h +++ b/slsReceiverSoftware/include/DataStreamer.h @@ -31,7 +31,7 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject { * @param ajh additional json header * @param sm pointer to silent mode */ - DataStreamer(int ind, Fifo*& f, uint32_t* dr, std::vector* r, + DataStreamer(int ind, Fifo*& f, uint32_t* dr, std::vector* r, uint64_t* fi, int* fd, char* ajh, bool* sm); /** @@ -175,7 +175,7 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject { uint32_t* dynamicRange; /** ROI */ - std::vector* roi; + std::vector* roi; /** adc Configured */ int adcConfigured; diff --git a/slsReceiverSoftware/include/GeneralData.h b/slsReceiverSoftware/include/GeneralData.h index 7add8f7e2..c0161e118 100644 --- a/slsReceiverSoftware/include/GeneralData.h +++ b/slsReceiverSoftware/include/GeneralData.h @@ -160,17 +160,17 @@ public: * Set ROI * @param i ROI */ - virtual void SetROI(std::vector i) { + virtual void SetROI(std::vector i) { cprintf(RED,"This is a generic function that should be overloaded by a derived class\n"); }; /** * Get Adc configured * @param index thread index for debugging purposes - * @param i ROI + * @param i pointer to a vector of ROI pointers * @returns adc configured */ - virtual const int GetAdcConfigured(int index, std::vector i) const{ + virtual const int GetAdcConfigured(int index, std::vector* i) const{ cprintf(RED,"This is a generic function that should be overloaded by a derived class\n"); return 0; }; @@ -323,7 +323,7 @@ private: * Set ROI * @param i ROI */ - virtual void SetROI(std::vector i) { + virtual void SetROI(std::vector i) { // all adcs if(!i.size()) { nPixelsX = 1280; @@ -364,23 +364,22 @@ private: /** * Get Adc configured * @param index thread index for debugging purposes - * @param i ROI + * @param i pointer to a vector of ROI * @returns adc configured */ - virtual const int GetAdcConfigured(int index, std::vector i) const{ + virtual const int GetAdcConfigured(int index, std::vector* i) const{ int adc = -1; // single adc - if(i.size()) { - + if(i->size()) { // gotthard can have only one adc per detector enabled (or all) // so just looking at the first roi is enough (more not possible at the moment) //if its for 1 adc or general - if ((i[0]->xmin == 0) && (i[0]->xmax == nChip * nChan)) + if ((i->at(0).xmin == 0) && (i->at(0).xmax == nChip * nChan)) adc = -1; else { //adc = mid value/numchans also for only 1 roi - adc = ((((i[0]->xmax) + (i[0]->xmin))/2)/ + adc = ((((i->at(0).xmax) + (i->at(0).xmin))/2)/ (nChan * nChipsPerAdc)); if((adc < 0) || (adc > 4)) { FILE_LOG(logWARNING) << index << ": Deleting ROI. " @@ -389,6 +388,7 @@ private: } } } + FILE_LOG(logINFO) << "Adc Configured: " << adc; return adc; }; diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index ddc616b1c..cafcd33bb 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -185,7 +185,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Get ROI * @return index of adc enabled, else -1 if all enabled */ - std::vector getROI() const; + std::vector getROI() const; /** * Get the Frequency of Frames Sent to GUI @@ -452,7 +452,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * @param i ROI * @return OK or FAIL */ - int setROI(const std::vector i); + int setROI(const std::vector i); /** * Set the Frequency of Frames Sent to GUI @@ -786,7 +786,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter //***acquisition parameters*** /* ROI */ - std::vector roi; + std::vector roi; /** Frequency of Frames sent to GUI */ uint32_t frameToGuiFrequency; /** Timer of Frames sent to GUI when frequency is 0 */ diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 859d887ed..3879abd7e 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -276,7 +276,7 @@ class UDPInterface { * Get ROI * @return index of adc enabled, else -1 if all enabled */ - virtual std::vector getROI() const = 0; + virtual std::vector getROI() const = 0; /** * Get the Frequency of Frames Sent to GUI @@ -541,7 +541,7 @@ class UDPInterface { * @param i ROI * @return OK or FAIL */ - virtual int setROI(const std::vector i) = 0; + virtual int setROI(const std::vector i) = 0; /** * Set the Frequency of Frames Sent to GUI diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 0f6d1a595..30f19a596 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -77,7 +77,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * @param i ROI * @return OK or FAIL */ - int setROI(const std::vector i); + int setROI(const std::vector i); /** * Set the Frequency of Frames Sent to GUI diff --git a/slsReceiverSoftware/src/DataStreamer.cpp b/slsReceiverSoftware/src/DataStreamer.cpp index 590a5fc85..724055c5a 100644 --- a/slsReceiverSoftware/src/DataStreamer.cpp +++ b/slsReceiverSoftware/src/DataStreamer.cpp @@ -15,7 +15,7 @@ const std::string DataStreamer::TypeName = "DataStreamer"; -DataStreamer::DataStreamer(int ind, Fifo*& f, uint32_t* dr, std::vector* r, +DataStreamer::DataStreamer(int ind, Fifo*& f, uint32_t* dr, std::vector* r, uint64_t* fi, int* fd, char* ajh, bool* sm) : ThreadObject(ind), runningFlag(0), @@ -89,8 +89,9 @@ void DataStreamer::ResetParametersforNewMeasurement(char* fname){ completeBuffer = 0; } if (roi->size()) { - if (generalData->myDetectorType == GOTTHARD) - adcConfigured = generalData->GetAdcConfigured(index, *roi); + if (generalData->myDetectorType == GOTTHARD) { + adcConfigured = generalData->GetAdcConfigured(index, roi); + } completeBuffer = new char[generalData->imageSizeComplete]; memset(completeBuffer, 0, generalData->imageSizeComplete); } @@ -214,11 +215,19 @@ void DataStreamer::ProcessAnImage(char* buf) { //shortframe gotthard if (completeBuffer) { - if (!SendHeader(header, (uint32_t)(*((uint32_t*)buf)), generalData->nPixelsXComplete, generalData->nPixelsYComplete, false)) + //disregarding the size modified from callback (always using imageSizeComplete + // instead of buf (32 bit) because gui needs imagesizecomplete and listener + //write imagesize + + if (!SendHeader(header, generalData->imageSizeComplete, + generalData->nPixelsXComplete, generalData->nPixelsYComplete, false)) cprintf(RED,"Error: Could not send zmq header for fnum %lld and streamer %d\n", (long long int) fnum, index); - memcpy(completeBuffer + ((generalData->imageSize) * adcConfigured), buf + FIFO_HEADER_NUMBYTES + sizeof(sls_receiver_header), (uint32_t)(*((uint32_t*)buf)) ); // new size possibly from callback + memcpy(completeBuffer + ((generalData->imageSize) * adcConfigured), + buf + FIFO_HEADER_NUMBYTES + sizeof(sls_receiver_header), + (uint32_t)(*((uint32_t*)buf)) ); + if (!zmqSocket->SendData(completeBuffer, generalData->imageSizeComplete)) cprintf(RED,"Error: Could not send zmq data for fnum %lld and streamer %d\n", (long long int) fnum, index); @@ -228,11 +237,13 @@ void DataStreamer::ProcessAnImage(char* buf) { //normal else { - if (!SendHeader(header, (uint32_t)(*((uint32_t*)buf)), generalData->nPixelsX, generalData->nPixelsY, false)) // new size possibly from callback + if (!SendHeader(header, (uint32_t)(*((uint32_t*)buf)), + generalData->nPixelsX, generalData->nPixelsY, false)) // new size possibly from callback cprintf(RED,"Error: Could not send zmq header for fnum %lld and streamer %d\n", (long long int) fnum, index); - if (!zmqSocket->SendData(buf + FIFO_HEADER_NUMBYTES + sizeof(sls_receiver_header), (uint32_t)(*((uint32_t*)buf)) )) // new size possibly from callback + if (!zmqSocket->SendData(buf + FIFO_HEADER_NUMBYTES + sizeof(sls_receiver_header), + (uint32_t)(*((uint32_t*)buf)) )) // new size possibly from callback cprintf(RED,"Error: Could not send zmq data for fnum %lld and streamer %d\n", (long long int) fnum, index); } diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index f5b690af4..f8e28cb71 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -81,8 +81,6 @@ void UDPBaseImplementation::initializeMembers(){ dataCompressionEnable = false; //***acquisition parameters*** - for (std::vector::const_iterator it = roi.begin(); it != roi.end(); ++it) - delete(*it); roi.clear(); frameToGuiFrequency = 0; frameToGuiTimerinMS = DEFAULT_STREAMING_TIMER_IN_MS; @@ -251,7 +249,7 @@ char *UDPBaseImplementation::getEthernetInterface() const{ /***acquisition parameters***/ -std::vector UDPBaseImplementation::getROI() const{ +std::vector UDPBaseImplementation::getROI() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return roi; } @@ -542,7 +540,7 @@ void UDPBaseImplementation::setEthernetInterface(const char* c){ /***acquisition parameters***/ -int UDPBaseImplementation::setROI(const std::vector i){ +int UDPBaseImplementation::setROI(const std::vector i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; roi = i; @@ -554,10 +552,10 @@ int UDPBaseImplementation::setROI(const std::vector i){ else { for (unsigned int i = 0; i < roi.size(); ++i) { sstm << "( " << - roi[i]->xmin << ", " << - roi[i]->xmax << ", " << - roi[i]->ymin << ", " << - roi[i]->ymax << " )"; + roi[i].xmin << ", " << + roi[i].xmax << ", " << + roi[i].ymin << ", " << + roi[i].ymax << " )"; } } std::string message = sstm.str(); diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 36964ba2f..93c81594a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -167,7 +167,7 @@ void UDPStandardImplementation::setFileWriteEnable(const bool b){ -int UDPStandardImplementation::setROI(const std::vector i) { +int UDPStandardImplementation::setROI(const std::vector i) { if (myDetectorType != GOTTHARD) { cprintf(RED, "Error: Can not set ROI for this detector\n"); return FAIL; @@ -180,10 +180,10 @@ int UDPStandardImplementation::setROI(const std::vector i else { for (unsigned int iloop = 0; iloop < i.size(); ++iloop) { if ( - (roi[iloop]->xmin != i[iloop]->xmin) || - (roi[iloop]->xmax != i[iloop]->xmax) || - (roi[iloop]->ymin != i[iloop]->ymin) || - (roi[iloop]->xmax != i[iloop]->xmax)) { + (roi[iloop].xmin != i[iloop].xmin) || + (roi[iloop].xmax != i[iloop].xmax) || + (roi[iloop].ymin != i[iloop].ymin) || + (roi[iloop].xmax != i[iloop].xmax)) { change = true; break; } @@ -217,10 +217,10 @@ int UDPStandardImplementation::setROI(const std::vector i else { for (unsigned int i = 0; i < roi.size(); ++i) { sstm << "( " << - roi[i]->xmin << ", " << - roi[i]->xmax << ", " << - roi[i]->ymin << ", " << - roi[i]->ymax << " )"; + roi[i].xmin << ", " << + roi[i].xmax << ", " << + roi[i].ymin << ", " << + roi[i].ymax << " )"; } } std::string message = sstm.str(); @@ -251,7 +251,6 @@ int UDPStandardImplementation::setDataStreamEnable(const bool enable) { if (enable) { for ( int i = 0; i < numThreads; ++i ) { try { - DataStreamer* s = new DataStreamer(i, fifo[i], &dynamicRange, &roi, &fileIndex, flippedData, additionalJsonHeader, &silentMode); dataStreamer.push_back(s); @@ -473,7 +472,6 @@ void UDPStandardImplementation::resetAcquisitionCount() { int UDPStandardImplementation::startReceiver(char *c) { cprintf(RESET,"\n"); FILE_LOG(logINFO) << "Starting Receiver"; - ResetParametersforNewMeasurement(); //listener @@ -733,7 +731,7 @@ int UDPStandardImplementation::SetupFifoStructure() { for (std::vector::const_iterator it = fifo.begin(); it != fifo.end(); ++it) delete(*it); fifo.clear(); - for ( int i = 0; i < numThreads; i++ ) { + for ( int i = 0; i < numThreads; ++i ) { //create fifo structure try { diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index aa6fd8fe4..ffa489851 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -888,13 +888,13 @@ int slsReceiverTCPIPInterface::set_roi() { if (mySock->ReceiveDataOnly(&nroi,sizeof(nroi)) < 0 ) return printSocketReadError(); - std::vector roiLimits; + std::vector roiLimits; int iloop = 0; for (iloop = 0; iloop < nroi; iloop++) { ROI temp; if ( mySock->ReceiveDataOnly(&temp,sizeof(ROI)) < 0 ) return printSocketReadError(); - roiLimits.push_back(&temp); + roiLimits.push_back(temp); } //does not exist @@ -925,6 +925,8 @@ int slsReceiverTCPIPInterface::set_roi() { if (ret == FAIL) mySock->SendDataOnly(mess,sizeof(mess)); + roiLimits.clear(); + // return ok/fail return ret; }