From 652d29f2d904b7ce91b9f7a4581b17d419f07b04 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 9 Sep 2016 17:51:36 +0200 Subject: [PATCH 01/42] almost done --- slsDetectorSoftware/Makefile | 7 +- .../multiSlsDetector/multiSlsDetector.cpp | 218 ++++++++++++++++-- .../multiSlsDetector/multiSlsDetector.h | 15 +- .../slsDetector/slsDetector.cpp | 165 +++++++++---- slsDetectorSoftware/slsDetector/slsDetector.h | 9 +- .../slsDetector/slsDetectorBase.h | 9 +- .../slsDetector/slsDetectorUtils.cpp | 48 +--- .../slsDetector/slsDetectorUtils.h | 19 +- .../slsDetectorAnalysis/postProcessing.cpp | 18 +- .../slsDetectorAnalysis/postProcessing.h | 18 +- slsDetectorSoftware/threadFiles/Task.h | 44 +++- .../threadFiles/ThreadPool.cpp | 60 +++-- slsDetectorSoftware/threadFiles/ThreadPool.h | 8 +- 13 files changed, 441 insertions(+), 197 deletions(-) diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile index 17422ee95..eb3708d50 100644 --- a/slsDetectorSoftware/Makefile +++ b/slsDetectorSoftware/Makefile @@ -18,6 +18,9 @@ INCLUDES?= -IcommonFiles -IslsDetector -I../slsReceiverSoftware/MySocketTCP -Ius SRC_CLNT=slsDetectorAnalysis/fileIO.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/angularConversion.cpp slsDetectorAnalysis/angularConversionStatic.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp slsDetectorAnalysis/postProcessingFuncs.cpp slsReceiverInterface/receiverInterface.cpp slsDetector/slsDetectorUsers.cpp threadFiles/CondVar.cpp threadFiles/Mutex.cpp threadFiles/ThreadPool.cpp #../slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp +LIBZMQDIR = ../slsReceiverSoftware/include +LIBZMQ = -L$(LIBZMQDIR) -Wl,-rpath=$(LIBZMQDIR) -lzmq + $(info ) $(info #######################################) $(info # Compiling slsDetectorSoftware #) @@ -66,14 +69,14 @@ gotthardVirtualServer: $(SRC_MYTHEN_SVC) %.o : %.cpp %.h Makefile - $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS) + $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread -lrt $(LIBZMQ) #$(FLAGS) package: $(OBJS) $(DESTDIR)/libSlsDetector.so $(DESTDIR)/libSlsDetector.a $(DESTDIR)/libSlsDetector.so: $(OBJS) - $(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread + $(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread -lrt $(LIBZMQ) $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) mv libSlsDetector.so $(DESTDIR) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index f902e24d7..36a37143f 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -267,28 +267,30 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) getNMods(); getMaxMods(); threadpool = 0; - if(createThreadPool() == FAIL) + zmqthreadpool = 0; + if(createThreadPool(&threadpool) == FAIL) exit(-1); } multiSlsDetector::~multiSlsDetector() { //removeSlsDetector(); - destroyThreadPool(); + destroyThreadPool(&threadpool); + destroyThreadPool(&zmqthreadpool); } -int multiSlsDetector::createThreadPool(){ - if(threadpool){ - threadpool->destroy_threadpool(); - threadpool=0; +int multiSlsDetector::createThreadPool(ThreadPool** t){ + if(*t){ + (ThreadPool*)(*t)->destroy_threadpool(); + *t=0; } if(thisMultiDetector->numberOfDetectors < 1){ cout << "No detectors attached to create threadpool" << endl; return OK; } - threadpool = new ThreadPool(thisMultiDetector->numberOfDetectors); - switch(threadpool->initialize_threadpool()){ + *t = new ThreadPool(thisMultiDetector->numberOfDetectors); + switch(((ThreadPool*)(*t))->initialize_threadpool()){ case 0: cerr << "Failed to initialize thread pool!" << endl; return FAIL; @@ -299,19 +301,19 @@ int multiSlsDetector::createThreadPool(){ break; default: #ifdef VERBOSE - cout << "Initialized Threadpool" << endl; + cout << "Initialized Threadpool " << *t << endl; #endif break; } return OK; } -void multiSlsDetector::destroyThreadPool(){ - if(threadpool){ - threadpool->destroy_threadpool(); - threadpool=0; +void multiSlsDetector::destroyThreadPool(ThreadPool** t){ + if(*t){ + (ThreadPool*)(*t)->destroy_threadpool(); + *t=0; #ifdef VERBOSE - cout<<"Destroyed Threadpool"<numberOfDetectors; @@ -1196,6 +1196,7 @@ slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) { threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=posmin; idetadd_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=posmin; idetadd_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ @@ -3318,6 +3321,7 @@ char* multiSlsDetector::setNetworkParameter(networkParameter p, string s){ threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=0; idetnumberOfDetectors; idet++){ if(detectors[idet]){ @@ -3926,6 +3930,7 @@ int multiSlsDetector::executeTrimming(trimMode mode, int par1, int par2, int imo threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=0; idetnumberOfDetectors; idet++){ if(detectors[idet]){ @@ -3977,6 +3982,7 @@ int multiSlsDetector::loadSettingsFile(string fname, int imod) { threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=0; idetnumberOfDetectors; idet++){ if(detectors[idet]){ @@ -4051,6 +4057,7 @@ int multiSlsDetector::setAllTrimbits(int val, int imod){ threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=0; idetnumberOfDetectors; idet++){ if(detectors[idet]){ @@ -4100,6 +4107,7 @@ int multiSlsDetector::loadCalibrationFile(string fname, int imod) { threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=0; idetnumberOfDetectors; idet++){ if(detectors[idet]){ @@ -4752,6 +4760,7 @@ int multiSlsDetector::startReceiver(){ threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ @@ -4813,6 +4822,7 @@ int multiSlsDetector::stopReceiver(){ threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ @@ -4948,7 +4958,173 @@ int multiSlsDetector::resetFramesCaught() { -int* multiSlsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){ +void multiSlsDetector::readFrameFromReceiver(){ + int value; + if(createThreadPool(&zmqthreadpool) == FAIL){ + cprintf(BG_RED,"Error: Could not create the zmq threads\n"); + return; + } + zmqthreadpool->setzeromqThread(); + + //determine number of half readouts and maxX and maxY + int maxX=0,maxY=0; + int numReadout = 1; + if(getDetectorsType() == EIGER){ + numReadout = 2; + maxX = thisMultiDetector->numberOfChannel[X]; + maxY = thisMultiDetector->numberOfChannel[Y]; + } + + //Note:num threads correspond to num detectors as task calls each slsdet + //(eiger udp ports/half readouts will have to do it serially) + + //start all socket tasks + volatile uint64_t runningMask = 0x0; + int slsdatabytes = 0, slsmaxchannels = 0, bytesperchannel = 0, slsmaxX = 0, slsmaxY=0; + if(!zmqthreadpool){ + cout << "Error in creating threadpool. Exiting" << endl; + return; + }else{ + for(int idet=0; idetnumberOfDetectors; idet++){ + if(detectors[idet]){ + sem_init(&sem_slswait[idet*numReadout],1,0); + sem_init(&sem_slsdone[idet*numReadout],1,0); + if(numReadout>1){ + sem_init(&sem_slswait[idet*numReadout+1],1,0); + sem_init(&sem_slsdone[idet*numReadout+1],1,0); + } + Task* task = new Task(new func00_t(&slsDetector::readFrameFromReceiver,detectors[idet])); + zmqthreadpool->add_task(task); + if(!slsdatabytes){ + slsdatabytes = detectors[idet]->getDataBytes(); + slsmaxchannels = detectors[idet]->getMaxNumberOfChannels(); + bytesperchannel = slsdatabytes/slsmaxchannels; + slsmaxX = detectors[idet]->getTotalNumberOfChannels(X); + slsmaxY = detectors[idet]->getTotalNumberOfChannels(Y); + } + //set mask + runningMask|=(1<<(idet*numReadout)); + if(numReadout>1) + runningMask|=(1<<(idet*numReadout+1)); + + } + } + } + + zmqthreadpool->startExecuting();//tell them to start + + + int nel=(thisMultiDetector->dataBytes)/sizeof(int); + + if(nel <= 0){ + cout << "Multislsdetector databytes not valid :" << thisMultiDetector->dataBytes << endl; + return; + } + int* multiframe=new int[nel]; + int* p = multiframe; + int idet,offsetY,offsetX; + int halfreadoutoffset = (slsmaxX/numReadout); + //after reconstruction + int framecount=0; + int nx =getTotalNumberOfChannels(slsDetectorDefs::X); + int ny =getTotalNumberOfChannels(slsDetectorDefs::Y); + + + + while(true){ + memset(((char*)multiframe),0x0,slsdatabytes*thisMultiDetector->numberOfDetectors); + + for(int ireadout=0; ireadoutnumberOfDetectors*numReadout; ++ireadout){ + idet = ireadout/numReadout; + + if(detectors[idet]){ + if((1 << ireadout) & runningMask){ + + + sem_post(&sem_slswait[ireadout]); //sls to continue + sem_wait(&sem_slsdone[ireadout]); //wait for sls to copy + + //this socket closed + if(slsframe[ireadout] == NULL){ + runningMask^=(1<offsetY[idet] + slsmaxY)) * maxX * bytesperchannel; + if(!(ireadout%numReadout)) offsetX = thisMultiDetector->offsetX[idet]; + else offsetX = thisMultiDetector->offsetX[idet] + halfreadoutoffset; + offsetX *= bytesperchannel; + cprintf(BLUE,"offsetx:%d offsety:%d maxx:%d slsmaxX:%d slsmaxY:%d bytesperchannel:%d\n", + offsetX,offsetY,maxX,slsmaxX,slsmaxY,bytesperchannel); + + cprintf(BLUE,"copying bytes:%d\n", (slsmaxX/numReadout)*bytesperchannel); + //itnerleaving with other detectors + for(int i=0;iwait_for_tasks_to_complete(); + destroyThreadPool(&zmqthreadpool); + delete[] multiframe; + + + + + + + + +/* int nel=(thisMultiDetector->dataBytes)/sizeof(int); if(nel <= 0){ cout << "Multislsdetector databytes not valid :" << thisMultiDetector->dataBytes << endl; @@ -5039,6 +5215,7 @@ int* multiSlsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex if((getDetectorsType() == EIGER) &&(complete ==FAIL)) acquisitionIndex = -1; return retval; + */ }; @@ -5468,6 +5645,7 @@ int multiSlsDetector::pulsePixel(int n,int x,int y) { threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=0; idetnumberOfDetectors; idet++){ if(detectors[idet]){ @@ -5504,6 +5682,7 @@ int multiSlsDetector::pulsePixelNMove(int n,int x,int y) { threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=0; idetnumberOfDetectors; idet++){ if(detectors[idet]){ @@ -5540,6 +5719,7 @@ int multiSlsDetector::pulseChip(int n) { threadpool->add_task(task); } } + threadpool->startExecuting(); threadpool->wait_for_tasks_to_complete(); for(int idet=0; idetnumberOfDetectors; idet++){ if(detectors[idet]){ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 07c4fe839..2c72b848a 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -245,10 +245,10 @@ class multiSlsDetector : public slsDetectorUtils { * Creates all the threads in the threadpool \returns OK or FAIL */ - int createThreadPool(); + int createThreadPool(ThreadPool** t); /** destroys all the threads in the threadpool */ - void destroyThreadPool(); + void destroyThreadPool(ThreadPool** t); /** frees the shared memory occpied by the sharedMultiSlsDetector structure */ int freeSharedMemory() ; @@ -1180,14 +1180,9 @@ class multiSlsDetector : public slsDetectorUtils { int resetFramesCaught(); /** - * Reads a frame from receiver - * @param fName file name of current frame() - * @param acquisitionIndex current acquisition index - * @param frameIndex current frame index (for each scan) - * @param subFrameIndex current sub frame index (for 32 bit mode for eiger) - /returns a frame read from recever + * Reads frames from receiver through a constant socket */ - int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex); + void readFrameFromReceiver(); /** Locks/Unlocks the connection to the receiver /param lock sets (1), usets (0), gets (-1) the lock @@ -1378,7 +1373,7 @@ class multiSlsDetector : public slsDetectorUtils { private: ThreadPool* threadpool; - + ThreadPool* zmqthreadpool; }; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 7565aeaf8..892c6a3a5 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -10,7 +10,7 @@ #include #include #include "gitInfoLib.h" - +#include int slsDetector::initSharedMemory(detectorType type, int id) { @@ -7145,58 +7145,125 @@ int slsDetector::resetFramesCaught(){ -int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){ - int fnum=F_READ_RECEIVER_FRAME; - int nel=thisDetector->dataBytes/sizeof(int); - int* retval=new int[nel]; - int ret=FAIL; - int n; - char mess[MAX_STR_LENGTH]="Nothing"; +void slsDetector::readFrameFromReceiver(){ - if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { -#ifdef VERBOSE - std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + //determine number of half readouts + int numReadout = 1; + if(thisDetector->myDetectorType == EIGER) numReadout = 2; + int readoutId = detId*numReadout; + volatile uint64_t runningMask = 0x0; - if (ret==FAIL) { - n= dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned: " << mess << " " << n << std::endl; - delete [] retval; - disconnectData(); - return NULL; - } else { - n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH); - n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); - n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex)); - if(thisDetector->myDetectorType == EIGER) - n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex)); - n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); + //server details + char hostname[numReadout][100]; + int portno[numReadout]; + int nel=(thisDetector->dataBytes/numReadout)/sizeof(int); + for(int i=0;idataBytes) { - std::cout<dataBytes << std::endl; - ret=FAIL; - delete [] retval; - disconnectData(); - return NULL; - } - - //jungfrau masking adcval - if(thisDetector->myDetectorType == JUNGFRAU){ - for(unsigned int i=0;islsframe[readoutId+i]=new int[nel]; } - return retval; + + + //loop though the half readouts to start sockets + void *context[numReadout]; + void *zmqsocket[numReadout]; + for(int i=0;isem_slswait[readoutId+idet]);//wait for it to be copied + + + //update indices + if(!idet) framecount++; //count only once + + // receive a message, this is a blocking function + len = zmq_msg_init (&message); /* is this required? Xiaoqiang didnt have it*/ + if(len) {cprintf(RED,"Failed to initialize message %d for %d\n",len,readoutId+idet); continue; }//error + len = zmq_msg_recv(&message, zmqsocket[idet], 0); + + //int size = zmq_msg_size (&message); + if (len <= 3 ) { + if(!len) cprintf(RED,"Received no data in socket for %d\n", readoutId+idet); + cout<slsframe[readoutId+idet] = NULL; + sem_post(&parentDet->sem_slsdone[readoutId+idet]);//let multi know is ready + + runningMask^=(1<dataBytes/numReadout){//hoow to solve this + memcpy((char*)(parentDet->slsframe[readoutId+idet]),(char*)zmq_msg_data(&message),thisDetector->dataBytes/numReadout); + //memcpy((char*)(parentDet->slsframe[readoutId+idet]),zmq_msg_data(&message[idet]),thisDetector->dataBytes); + //check header, if incorrect frame, copy somewhere and assign a blank subframe + //parentDet->slsframe[readoutId+idet] = (int*)zmq_msg_data(&message[idet]); + + //jungfrau masking adcval + if(thisDetector->myDetectorType == JUNGFRAU){ + for(unsigned int i=0;islsframe[readoutId+idet][i] = (parentDet->slsframe[readoutId+idet][i] & 0x3FFF3FFF); + } + } + //} + sem_post(&parentDet->sem_slsdone[readoutId+idet]);//let multi know is ready + + } + }//end of for loop + + if(!runningMask){ + break; + } + + } + zmq_msg_close(&message); + + + + //close socket + for(int i=0;islsframe[readoutId+i]; + } + }; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 673729b22..54d6b27e5 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1569,14 +1569,9 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int resetFramesCaught(); /** - * Reads a frame from receiver - * @param fName file name of current frame() - * @param acquisitionIndex current acquisition index - * @param frameIndex current frame index (for each scan) - * @param subFrameIndex current sub frame index (for 32 bit mode for eiger) - /returns a frame read from recever + * Reads frames from receiver through a constant socket */ - int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex); + void readFrameFromReceiver(); /** Locks/Unlocks the connection to the receiver /param lock sets (1), usets (0), gets (-1) the lock diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 62eb83006..9ccf313e5 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -507,14 +507,9 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef /** - * Reads a frame from receiver - * @param fName file name of current frame() - * @param acquisitionIndex current acquisition index - * @param frameIndex current frame index (for each scan) - * @param subFrameIndex current sub frame index (for 32 bit mode for eiger) - /returns a frame read from recever + * Reads frames from receiver through a constant socket */ - virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0; + virtual void readFrameFromReceiver()=0; /** Sets the read receiver frequency diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index d390c8398..a4e3030ff 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -72,10 +72,6 @@ int slsDetectorUtils::acquire(int delflag){ int multiframe = nc*nf; - pthread_mutex_lock(&mg); - acquiringDone = 0; - pthread_mutex_unlock(&mg); - // setTotalProgress(); //moved these 2 here for measurement change progressIndex=0; @@ -162,7 +158,6 @@ int slsDetectorUtils::acquire(int delflag){ if (*threadedProcessing) { - sem_init(&sem_queue,0,0); startThread(delflag); } #ifdef VERBOSE @@ -341,48 +336,13 @@ int slsDetectorUtils::acquire(int delflag){ //offline if(setReceiverOnline()==OFFLINE_FLAG){ - // wait until data processing thread has finished the data - pthread_mutex_lock(&mg); - acquiringDone = 1; - pthread_mutex_unlock(&mg); - if (*threadedProcessing) { - sem_wait(&sem_queue); - pthread_mutex_lock(&mg); - acquiringDone = 0; - pthread_mutex_unlock(&mg); + if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){ + if((*correctionMask)&(1< #include #include - +#include using namespace std; @@ -641,14 +641,9 @@ virtual int getReceiverCurrentFrameIndex()=0; virtual int resetFramesCaught()=0; /** - * Reads a frame from receiver - * @param fName file name of current frame() - * @param acquisitionIndex current acquisition index - * @param frameIndex current frame index (for each scan) - * @param subFrameIndex current sub frame index (for 32 bit mode for eiger) - /returns a frame read from recever + * Reads frames from receiver through a constant socket */ -virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0; +virtual void readFrameFromReceiver()=0; /** @@ -850,6 +845,14 @@ virtual int setReceiverFifoDepth(int i = -1)=0; int (*progress_call)(double,void*); void *pProgressCallArg; + public: + //data call back + //individual sls and multi + sem_t sem_slsdone[MAXDET]; + sem_t sem_slswait[MAXDET]; + int* slsframe[MAXDET]; + + }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 9fcb6c9c0..60db31654 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -7,6 +7,7 @@ #include "usersFunctions.h" #endif + //#define VERBOSE static void* startProcessData(void *n){ @@ -461,12 +462,7 @@ void* postProcessing::processData(int delflag) { } - /** IF detector acquisition is done, let the acquire() thread know to finish up and force join thread */ - if(acquiringDone){ - sem_post(&sem_queue); - // cout << "Sem posted" << endl; - } //else - // cout << "Sem not posted" << endl; + /* IF THERE ARE NO DATA look if acquisition is finished */ if (checkJoinThread()) { if (dataQueueSize()==0) { @@ -488,6 +484,14 @@ void* postProcessing::processData(int delflag) { else{ + + readFrameFromReceiver(); + + + + + +/* int progress = 0; char currentfName[MAX_STR_LENGTH]=""; int caught = -1; @@ -663,6 +667,8 @@ void* postProcessing::processData(int delflag) { } } +*/ + } return 0; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h index 90f00085a..546457fa1 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h @@ -17,7 +17,7 @@ #include #include #include -#include + class postProcessingFuncs; @@ -300,11 +300,7 @@ s /** data queue size */ int queuesize; - /** queue mutex */ - sem_t sem_queue; - /** set when detector finishes acquiring */ - int acquiringDone; /** @@ -333,18 +329,23 @@ s - private: double *fdata; - int (*dataReady)(detectorData*,int, int,void*); void *pCallbackArg; + detectorData *thisData; + private: + // double *fdata; + + // int (*dataReady)(detectorData*,int, int,void*); + // void *pCallbackArg; + int (*rawDataReady)(double*,int,void*); void *pRawDataArg; postProcessingFuncs *ppFun; - detectorData *thisData; + //detectorData *thisData; double *ang; @@ -374,4 +375,5 @@ s + #endif diff --git a/slsDetectorSoftware/threadFiles/Task.h b/slsDetectorSoftware/threadFiles/Task.h index e7f8f12f8..785298d46 100644 --- a/slsDetectorSoftware/threadFiles/Task.h +++ b/slsDetectorSoftware/threadFiles/Task.h @@ -16,6 +16,18 @@ using namespace std; class slsDetector; +template +class func00_t{ +public: + func00_t(_Ret (_Class::*fn)(),_Class* ptr): + m_fn(fn),m_ptr(ptr){} + ~func00_t() {} + void operator()() const {((m_ptr->*m_fn)());} +private: + _Class* m_ptr; + _Ret (_Class::*m_fn)(); +}; + template class func0_t{ public: @@ -94,27 +106,32 @@ private: class Task: public virtual slsDetectorDefs{ public: /* Return: int, Param: int */ - Task(func1_t * t): m1(t),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0){}; + Task(func1_t * t): m1(t),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; /* Return: int, Param: string,int */ - Task(func2_t * t): m1(0),m2(t),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0){}; + Task(func2_t * t): m1(0),m2(t),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; /* Return: string, Param: string */ - Task(func1_t * t): m1(0),m2(0),m3(t),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0){}; + Task(func1_t * t): m1(0),m2(0),m3(t),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; /* Return: char*, Param: char* */ - Task(func1_t * t): m1(0),m2(0),m3(0),m4(t),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0){}; + Task(func1_t * t): m1(0),m2(0),m3(0),m4(t),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; /* Return: detectorSettings, Param: int */ - Task(func1_t * t): m1(0),m2(0),m3(0),m4(0),m5(t),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0){}; + Task(func1_t * t): m1(0),m2(0),m3(0),m4(0),m5(t),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; /* Return: detectorSettings, Param: detectorSettings,int */ - Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(t),m7(0),m8(0),m9(0),m10(0),m11(0){}; + Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(t),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0){}; /* Return: int, Param: int,int */ - Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(t),m8(0),m9(0),m10(0),m11(0){}; + Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(t),m8(0),m9(0),m10(0),m11(0),m12(0){}; /* Return: int, Param: int,int */ - Task(func3_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(t),m9(0),m10(0),m11(0){}; + Task(func3_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(t),m9(0),m10(0),m11(0),m12(0){}; /* Return: int, Param: trimMode,int,int,int */ - Task(func4_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(t),m10(0),m11(0){}; - /* Return: int, Param: int */ - Task(func0_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(t),m11(0){}; + Task(func4_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(t),m10(0),m11(0),m12(0){}; + /* Return: int, Param: none */ + Task(func0_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(t),m11(0),m12(0){}; /* Return: char*, Param: networkParameter,string,string */ - Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(t){}; + Task(func2_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(t),m12(0){}; + /* Return: void, Param: none */ + Task(func00_t * t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(t){}; + + + ~Task(){} void operator()(){ @@ -129,6 +146,7 @@ public: else if(m9) (*m9)(); else if(m10) (*m10)(); else if(m11) (*m11)(); + else if(m12) (*m12)(); } private: @@ -154,6 +172,8 @@ private: func0_t * m10; /* Return: char*, Param: networkParameter,string,string */ func2_t * m11; + /* Return: void, Param: none */ + func00_t * m12; }; diff --git a/slsDetectorSoftware/threadFiles/ThreadPool.cpp b/slsDetectorSoftware/threadFiles/ThreadPool.cpp index 223983a73..347a15e31 100644 --- a/slsDetectorSoftware/threadFiles/ThreadPool.cpp +++ b/slsDetectorSoftware/threadFiles/ThreadPool.cpp @@ -7,8 +7,10 @@ ThreadPool::ThreadPool(int pool_size) : m_pool_size(pool_size){ #endif m_tasks_loaded = false; thread_started = false; + zmqthreadpool = false; current_thread_number = -1; number_of_ongoing_tasks = 0; + number_of_total_tasks = 0; } ThreadPool::~ThreadPool(){ @@ -34,6 +36,7 @@ int ThreadPool::initialize_threadpool(){ m_pool_state = STARTED; int ret = -1; sem_init(&semStart,1,0); + sem_init(&semDone,1,0); for (int i = 0; i < m_pool_size; i++) { pthread_t tid; thread_started = false; @@ -68,12 +71,15 @@ int ThreadPool::destroy_threadpool(){ for (int i = 0; i < m_pool_size; i++) { void* result; sem_post(&semStart); + sem_post(&semDone); ret = pthread_join(m_threads[i], &result); /*cout << "pthread_join() returned " << ret << ": " << strerror(errno) << endl;*/ m_task_cond_var.broadcast(); // try waking up a bunch of threads that are still waiting } sem_destroy(&semStart); + sem_destroy(&semDone); number_of_ongoing_tasks = 0; + number_of_total_tasks = 0; /* cout << m_pool_size << " threads exited from the thread pool" << endl;*/ return 0; } @@ -109,25 +115,28 @@ void* ThreadPool::execute_thread(){ /*cout << "Unlocking: " << pthread_self() << endl;*/ m_task_mutex.unlock(); + //if(zmqthreadpool) cout<<"***"<run(arg); /*cout << ithread <<" Done executing thread " << pthread_self() << endl;*/ - m_all_tasks_mutex.lock(); + m_task_mutex.lock(); number_of_ongoing_tasks--; - m_all_tasks_mutex.unlock(); + m_task_mutex.unlock(); + //if(zmqthreadpool) cout< m_tasks; volatile int m_pool_state; - Mutex m_all_tasks_mutex; - CondVar m_all_tasks_cond_var; bool m_tasks_loaded; bool thread_started; int current_thread_number; //volatile uint64_t tasks_done_mask; volatile int number_of_ongoing_tasks; + volatile int number_of_total_tasks; sem_t semStart; - + sem_t semDone; + bool zmqthreadpool; }; From 557eccb74db70419f5c3df318532e7f32741841b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 14 Sep 2016 10:42:51 +0200 Subject: [PATCH 02/42] almost there --- slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 36a37143f..64b65ab55 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5059,7 +5059,7 @@ void multiSlsDetector::readFrameFromReceiver(){ //eiger, so interleaving if(maxX){ - if(ireadout == 3){ + //if(ireadout == 3){ offsetY = (maxY - (thisMultiDetector->offsetY[idet] + slsmaxY)) * maxX * bytesperchannel; if(!(ireadout%numReadout)) offsetX = thisMultiDetector->offsetX[idet]; else offsetX = thisMultiDetector->offsetX[idet] + halfreadoutoffset; @@ -5077,7 +5077,7 @@ void multiSlsDetector::readFrameFromReceiver(){ } - }//end of ireadout + //}//end of ireadout } //no interleaving, just add to the end From 0f9a841c4a4a956a43b3be9d2ce1cf9b301ed9b2 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 15 Sep 2016 10:17:16 +0200 Subject: [PATCH 03/42] almost done --- .../multiSlsDetector/multiSlsDetector.cpp | 34 +++++++++++++------ .../slsDetector/slsDetector.cpp | 10 +++--- .../slsDetector/slsDetectorUtils.cpp | 7 +++- .../slsDetectorAnalysis/postProcessing.cpp | 7 ++-- .../slsDetectorAnalysis/postProcessing.h | 4 ++- 5 files changed, 44 insertions(+), 18 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 64b65ab55..f8090b989 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4969,10 +4969,13 @@ void multiSlsDetector::readFrameFromReceiver(){ //determine number of half readouts and maxX and maxY int maxX=0,maxY=0; int numReadout = 1; + bool checkbottom = false; + if(getDetectorsType() == EIGER){ numReadout = 2; maxX = thisMultiDetector->numberOfChannel[X]; maxY = thisMultiDetector->numberOfChannel[Y]; + checkbottom = true; } //Note:num threads correspond to num detectors as task calls each slsdet @@ -5031,6 +5034,7 @@ void multiSlsDetector::readFrameFromReceiver(){ + while(true){ memset(((char*)multiframe),0x0,slsdatabytes*thisMultiDetector->numberOfDetectors); @@ -5056,7 +5060,7 @@ void multiSlsDetector::readFrameFromReceiver(){ //assemble data - //eiger, so interleaving + //eiger, so interleaving between ports in one readout itself if(maxX){ //if(ireadout == 3){ @@ -5064,19 +5068,29 @@ void multiSlsDetector::readFrameFromReceiver(){ if(!(ireadout%numReadout)) offsetX = thisMultiDetector->offsetX[idet]; else offsetX = thisMultiDetector->offsetX[idet] + halfreadoutoffset; offsetX *= bytesperchannel; - cprintf(BLUE,"offsetx:%d offsety:%d maxx:%d slsmaxX:%d slsmaxY:%d bytesperchannel:%d\n", - offsetX,offsetY,maxX,slsmaxX,slsmaxY,bytesperchannel); + //cprintf(BLUE,"offsetx:%d offsety:%d maxx:%d slsmaxX:%d slsmaxY:%d bytesperchannel:%d\n", + // offsetX,offsetY,maxX,slsmaxX,slsmaxY,bytesperchannel); - cprintf(BLUE,"copying bytes:%d\n", (slsmaxX/numReadout)*bytesperchannel); + //cprintf(BLUE,"copying bytes:%d\n", (slsmaxX/numReadout)*bytesperchannel); //itnerleaving with other detectors - for(int i=0;ionlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -7181,7 +7181,7 @@ void slsDetector::readFrameFromReceiver(){ runningMask|=(1<<(i)); } - + cout<slsframe[readoutId+idet] = NULL; sem_post(&parentDet->sem_slsdone[readoutId+idet]);//let multi know is ready runningMask^=(1< #include #include - +#include class postProcessingFuncs; @@ -334,6 +334,8 @@ s void *pCallbackArg; detectorData *thisData; + sem_t dataThreadStartedSemaphore; + private: // double *fdata; From a821442b1a341ea899f4976b8369a206097616fd Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 15 Sep 2016 12:16:01 +0200 Subject: [PATCH 04/42] almosst --- .../multiSlsDetector/multiSlsDetector.cpp | 202 ++++-------------- .../multiSlsDetector/multiSlsDetector.h | 3 +- .../slsDetector/slsDetector.cpp | 53 ++--- slsDetectorSoftware/slsDetector/slsDetector.h | 3 +- .../slsDetector/slsDetectorBase.h | 3 +- .../slsDetector/slsDetectorUtils.cpp | 5 +- .../slsDetector/slsDetectorUtils.h | 6 +- .../slsDetectorAnalysis/postProcessing.cpp | 32 ++- 8 files changed, 98 insertions(+), 209 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index f8090b989..eb902d955 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4959,27 +4959,27 @@ int multiSlsDetector::resetFramesCaught() { void multiSlsDetector::readFrameFromReceiver(){ - int value; + //Note:num threads = (num slsDets = num tasks) + //so, half slsdet readouts read serially in each task (eiger udp ports) + + //create zmq threads if(createThreadPool(&zmqthreadpool) == FAIL){ cprintf(BG_RED,"Error: Could not create the zmq threads\n"); return; } - zmqthreadpool->setzeromqThread(); + zmqthreadpool->setzeromqThread(); //for debugging //determine number of half readouts and maxX and maxY int maxX=0,maxY=0; - int numReadout = 1; - bool checkbottom = false; - + int numReadoutPerDetector = 1; if(getDetectorsType() == EIGER){ - numReadout = 2; + numReadoutPerDetector = 2; maxX = thisMultiDetector->numberOfChannel[X]; maxY = thisMultiDetector->numberOfChannel[Y]; - checkbottom = true; } + int numReadouts = numReadoutPerDetector * thisMultiDetector->numberOfDetectors; + - //Note:num threads correspond to num detectors as task calls each slsdet - //(eiger udp ports/half readouts will have to do it serially) //start all socket tasks volatile uint64_t runningMask = 0x0; @@ -4990,11 +4990,13 @@ void multiSlsDetector::readFrameFromReceiver(){ }else{ for(int idet=0; idetnumberOfDetectors; idet++){ if(detectors[idet]){ - sem_init(&sem_slswait[idet*numReadout],1,0); - sem_init(&sem_slsdone[idet*numReadout],1,0); - if(numReadout>1){ - sem_init(&sem_slswait[idet*numReadout+1],1,0); - sem_init(&sem_slsdone[idet*numReadout+1],1,0); + sem_init(&sem_slswait[idet*numReadoutPerDetector],1,0); + sem_init(&sem_slsdone[idet*numReadoutPerDetector],1,0); + sem_init(&sem_multiwait[idet*numReadoutPerDetector],1,0); + if(numReadoutPerDetector>1){ + sem_init(&sem_slswait[idet*numReadoutPerDetector+1],1,0); + sem_init(&sem_slsdone[idet*numReadoutPerDetector+1],1,0); + sem_init(&sem_multiwait[idet*numReadoutPerDetector+1],1,0); } Task* task = new Task(new func00_t(&slsDetector::readFrameFromReceiver,detectors[idet])); zmqthreadpool->add_task(task); @@ -5006,19 +5008,21 @@ void multiSlsDetector::readFrameFromReceiver(){ slsmaxY = detectors[idet]->getTotalNumberOfChannels(Y); } //set mask - runningMask|=(1<<(idet*numReadout)); - if(numReadout>1) - runningMask|=(1<<(idet*numReadout+1)); + runningMask|=(1<<(idet*numReadoutPerDetector)); + if(numReadoutPerDetector>1) + runningMask|=(1<<(idet*numReadoutPerDetector+1)); } } } + zmqthreadpool->startExecuting(); //tell them to start + for(int i=0;istartExecuting();//tell them to start int nel=(thisMultiDetector->dataBytes)/sizeof(int); - if(nel <= 0){ cout << "Multislsdetector databytes not valid :" << thisMultiDetector->dataBytes << endl; return; @@ -5026,51 +5030,43 @@ void multiSlsDetector::readFrameFromReceiver(){ int* multiframe=new int[nel]; int* p = multiframe; int idet,offsetY,offsetX; - int halfreadoutoffset = (slsmaxX/numReadout); + int halfreadoutoffset = (slsmaxX/numReadoutPerDetector); //after reconstruction int framecount=0; int nx =getTotalNumberOfChannels(slsDetectorDefs::X); int ny =getTotalNumberOfChannels(slsDetectorDefs::Y); - - + //construct complete image and send to callback while(true){ - memset(((char*)multiframe),0x0,slsdatabytes*thisMultiDetector->numberOfDetectors); - - for(int ireadout=0; ireadoutnumberOfDetectors*numReadout; ++ireadout){ - idet = ireadout/numReadout; - + memset(((char*)multiframe),0x0,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory + for(int ireadout=0; ireadoutoffsetY[idet] + slsmaxY)) * maxX * bytesperchannel; - if(!(ireadout%numReadout)) offsetX = thisMultiDetector->offsetX[idet]; - else offsetX = thisMultiDetector->offsetX[idet] + halfreadoutoffset; + //the left half or right half + if(!(ireadout%numReadoutPerDetector)) + offsetX = thisMultiDetector->offsetX[idet]; + else + offsetX = thisMultiDetector->offsetX[idet] + halfreadoutoffset; offsetX *= bytesperchannel; //cprintf(BLUE,"offsetx:%d offsety:%d maxx:%d slsmaxX:%d slsmaxY:%d bytesperchannel:%d\n", // offsetX,offsetY,maxX,slsmaxX,slsmaxY,bytesperchannel); - //cprintf(BLUE,"copying bytes:%d\n", (slsmaxX/numReadout)*bytesperchannel); //itnerleaving with other detectors @@ -5078,21 +5074,16 @@ void multiSlsDetector::readFrameFromReceiver(){ if(((idet+1)%2) == 0){ for(int i=0;iwait_for_tasks_to_complete(); + for(int i=0;idataBytes)/sizeof(int); - if(nel <= 0){ - cout << "Multislsdetector databytes not valid :" << thisMultiDetector->dataBytes << endl; - acquisitionIndex = -1; - return NULL; - } - int n,complete=OK; - int i,k,offsetX, offsetY, maxX, maxY; double dr; - int* retval=new int[nel]; - int *retdet = NULL, *p=retval; - string fullFName=""; - string ext=""; - int index=-1,f_index=-1,p_index=-1,det_index=-1; - double sv0=-1,sv1=-1; - - if(getDetectorsType() == EIGER){ - maxX = thisMultiDetector->numberOfChannel[X]; - maxY = thisMultiDetector->numberOfChannel[Y]; - } - - - for (int id=0; idnumberOfDetectors; id++) { - if (detectors[id]) { - n=detectors[id]->getDataBytes(); - retdet=detectors[id]->readFrameFromReceiver(fName, acquisitionIndex, frameIndex, subFrameIndex); - if(detectors[id]->getErrorMask()) - setErrorMask(getErrorMask()|(1<getDataBytes(); - if(getDetectorsType() == EIGER){ - //cout << "fname:"<getMaxNumberOfChannels()<<" n:"<getMaxNumberOfChannels(); - k=(int)(detectors[id]->getMaxNumberOfChannels(X)*dr);//bit mode - //cout << "dr:"<offsetY[id] + detectors[id]->getMaxNumberOfChannels(Y))) * maxX)*dr);//bit mode - offsetX = (int)(thisMultiDetector->offsetX[id]*dr); - //cout << "offsetY"<slsframe[readoutId+i]=new int[nel]; } @@ -7172,69 +7171,51 @@ void slsDetector::readFrameFromReceiver(){ for(int i=0;isem_multiwait[readoutId+i]); //let multi know socket created } - cout<sem_slswait[readoutId+idet]);//wait for it to be copied - - //update indices - if(!idet) framecount++; //count only once + if(!idet) framecount++; //update indices, count only once // receive a message, this is a blocking function len = zmq_msg_init (&message); /* is this required? Xiaoqiang didnt have it*/ if(len) {cprintf(RED,"Failed to initialize message %d for %d\n",len,readoutId+idet); continue; }//error len = zmq_msg_recv(&message, zmqsocket[idet], 0); - //int size = zmq_msg_size (&message); + //end of socket if (len <= 3 ) { if(!len) cprintf(RED,"Received no data in socket for %d\n", readoutId+idet); //cout<slsframe[readoutId+idet] = NULL; - sem_post(&parentDet->sem_slsdone[readoutId+idet]);//let multi know is ready - + sem_post(&parentDet->sem_slsdone[readoutId+idet]); //let multi know is ready runningMask^=(1<dataBytes/numReadout){//hoow to solve this memcpy((char*)(parentDet->slsframe[readoutId+idet]),(char*)zmq_msg_data(&message),thisDetector->dataBytes/numReadout); - //memcpy((char*)(parentDet->slsframe[readoutId+idet]),zmq_msg_data(&message[idet]),thisDetector->dataBytes); - //check header, if incorrect frame, copy somewhere and assign a blank subframe - //parentDet->slsframe[readoutId+idet] = (int*)zmq_msg_data(&message[idet]); + //check header, if incorrect frame, copy somewhere and assign a blank subframe and also check size //jungfrau masking adcval if(thisDetector->myDetectorType == JUNGFRAU){ @@ -7244,29 +7225,23 @@ void slsDetector::readFrameFromReceiver(){ } //} sem_post(&parentDet->sem_slsdone[readoutId+idet]);//let multi know is ready - } }//end of for loop if(!runningMask){ break; } - } zmq_msg_close(&message); - - //close socket for(int i=0;islsframe[readoutId+i]; } - -}; +} diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 54d6b27e5..7ae8579fc 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1568,8 +1568,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int resetFramesCaught(); - /** - * Reads frames from receiver through a constant socket + /** Reads frames from receiver through a constant socket */ void readFrameFromReceiver(); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 9ccf313e5..8bbb145a3 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -506,8 +506,7 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef virtual int lockReceiver(int lock=-1)=0; - /** - * Reads frames from receiver through a constant socket + /** Reads frames from receiver through a constant socket */ virtual void readFrameFromReceiver()=0; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 792359f86..cc10d0c12 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -157,7 +157,8 @@ int slsDetectorUtils::acquire(int delflag){ if (*threadedProcessing) { - sem_init(&dataThreadStartedSemaphore,1,0); + if(dataReady) + sem_init(&dataThreadStartedSemaphore,1,0); startThread(delflag); } #ifdef VERBOSE @@ -171,6 +172,7 @@ int slsDetectorUtils::acquire(int delflag){ if(*threadedProcessing && dataReady) sem_wait(&dataThreadStartedSemaphore); + for(int im=0;im Date: Thu, 15 Sep 2016 17:15:55 +0200 Subject: [PATCH 05/42] works, need to do json header and send dataready --- .../multiSlsDetector/multiSlsDetector.cpp | 342 ++++++++++++------ .../multiSlsDetector/multiSlsDetector.h | 27 +- .../slsDetector/slsDetector.cpp | 103 ------ slsDetectorSoftware/slsDetector/slsDetector.h | 2 +- .../slsDetector/slsDetectorUtils.cpp | 1 + .../slsDetector/slsDetectorUtils.h | 8 - .../slsDetectorAnalysis/postProcessing.cpp | 182 +--------- 7 files changed, 247 insertions(+), 418 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index eb902d955..c33b5767d 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -23,6 +23,7 @@ ID: $Id$ #include #include #include +#include using namespace std; @@ -267,30 +268,28 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) getNMods(); getMaxMods(); threadpool = 0; - zmqthreadpool = 0; - if(createThreadPool(&threadpool) == FAIL) + if(createThreadPool() == FAIL) exit(-1); } multiSlsDetector::~multiSlsDetector() { //removeSlsDetector(); - destroyThreadPool(&threadpool); - destroyThreadPool(&zmqthreadpool); + destroyThreadPool(); } -int multiSlsDetector::createThreadPool(ThreadPool** t){ - if(*t){ - (ThreadPool*)(*t)->destroy_threadpool(); - *t=0; +int multiSlsDetector::createThreadPool(){ + if(threadpool){ + threadpool->destroy_threadpool(); + threadpool=0; } if(thisMultiDetector->numberOfDetectors < 1){ cout << "No detectors attached to create threadpool" << endl; return OK; } - *t = new ThreadPool(thisMultiDetector->numberOfDetectors); - switch(((ThreadPool*)(*t))->initialize_threadpool()){ + threadpool = new ThreadPool(thisMultiDetector->numberOfDetectors); + switch(threadpool->initialize_threadpool()){ case 0: cerr << "Failed to initialize thread pool!" << endl; return FAIL; @@ -301,19 +300,19 @@ int multiSlsDetector::createThreadPool(ThreadPool** t){ break; default: #ifdef VERBOSE - cout << "Initialized Threadpool " << *t << endl; + cout << "Initialized Threadpool " << threadpool << endl; #endif break; } return OK; } -void multiSlsDetector::destroyThreadPool(ThreadPool** t){ - if(*t){ - (ThreadPool*)(*t)->destroy_threadpool(); - *t=0; +void multiSlsDetector::destroyThreadPool(){ + if(threadpool){ + threadpool->destroy_threadpool(); + threadpool=0; #ifdef VERBOSE - cout<<"Destroyed Threadpool "<< *t << endl; + cout<<"Destroyed Threadpool "<< threadpool << endl; #endif } } @@ -394,7 +393,7 @@ int multiSlsDetector::addSlsDetector(int id, int pos) { //set offsets updateOffsets(); - if(createThreadPool(&threadpool) == FAIL) + if(createThreadPool() == FAIL) exit(-1); @@ -865,7 +864,7 @@ int multiSlsDetector::removeSlsDetector(int pos) { } updateOffsets(); - if(createThreadPool(&threadpool) == FAIL) + if(createThreadPool() == FAIL) exit(-1); return thisMultiDetector->numberOfDetectors; @@ -4957,17 +4956,113 @@ int multiSlsDetector::resetFramesCaught() { } +void* multiSlsDetector::startReceivingDataThread(void* this_pointer){ + ((multiSlsDetector*)this_pointer)->startReceivingData(); + return this_pointer; +} + + +void multiSlsDetector::startReceivingData(){ + + int ithread = currentThreadIndex; //set current thread value index + threadStarted = true; //let calling function know thread started and obtained current + + + int numReadoutPerDetector = 1; + bool jungfrau = false; + if(getDetectorsType() == EIGER){ + numReadoutPerDetector = 2; + }else if(getDetectorsType() == JUNGFRAU) + jungfrau = true; + + //server details + char hostname[100]; + int portno; + int singleDatabytes = detectors[ithread/numReadoutPerDetector]->getDataBytes(); + int nel=(singleDatabytes/numReadoutPerDetector)/sizeof(int); + portno = DEFAULT_ZMQ_PORTNO + (ithread); + sprintf(hostname, "%s%d", "tcp://127.0.0.1:",portno); + //cout << "ZMQ Client of " << ithread << " at " << hostname << endl; + singleframe[ithread]=new int[nel]; + + + //loop though the half readouts to start sockets + void *context; + void *zmqsocket; + context = zmq_ctx_new(); + zmqsocket = zmq_socket(context, ZMQ_PULL); + //zmq_setsockopt(zmqsocket, ZMQ_SUBSCRIBE, "", 0); // an empty string implies receiving any messages + zmq_connect(zmqsocket, hostname); // connect to publisher,the publisher server does not have to be started + pthread_mutex_lock(&ms); + receivingDataThreadMask|=(1<<(ithread)); + //cout<setzeromqThread(); //for debugging //determine number of half readouts and maxX and maxY int maxX=0,maxY=0; @@ -4980,125 +5075,131 @@ void multiSlsDetector::readFrameFromReceiver(){ int numReadouts = numReadoutPerDetector * thisMultiDetector->numberOfDetectors; - - //start all socket tasks - volatile uint64_t runningMask = 0x0; - int slsdatabytes = 0, slsmaxchannels = 0, bytesperchannel = 0, slsmaxX = 0, slsmaxY=0; - if(!zmqthreadpool){ - cout << "Error in creating threadpool. Exiting" << endl; - return; - }else{ - for(int idet=0; idetnumberOfDetectors; idet++){ - if(detectors[idet]){ - sem_init(&sem_slswait[idet*numReadoutPerDetector],1,0); - sem_init(&sem_slsdone[idet*numReadoutPerDetector],1,0); - sem_init(&sem_multiwait[idet*numReadoutPerDetector],1,0); - if(numReadoutPerDetector>1){ - sem_init(&sem_slswait[idet*numReadoutPerDetector+1],1,0); - sem_init(&sem_slsdone[idet*numReadoutPerDetector+1],1,0); - sem_init(&sem_multiwait[idet*numReadoutPerDetector+1],1,0); - } - Task* task = new Task(new func00_t(&slsDetector::readFrameFromReceiver,detectors[idet])); - zmqthreadpool->add_task(task); - if(!slsdatabytes){ - slsdatabytes = detectors[idet]->getDataBytes(); - slsmaxchannels = detectors[idet]->getMaxNumberOfChannels(); - bytesperchannel = slsdatabytes/slsmaxchannels; - slsmaxX = detectors[idet]->getTotalNumberOfChannels(X); - slsmaxY = detectors[idet]->getTotalNumberOfChannels(Y); - } - //set mask - runningMask|=(1<<(idet*numReadoutPerDetector)); - if(numReadoutPerDetector>1) - runningMask|=(1<<(idet*numReadoutPerDetector+1)); - - } + //create threads + /** Data Callback Threads */ + pthread_t receivingDataThreads[numReadouts]; + volatile uint64_t expectedMask = 0x0; + receivingDataThreadMask = 0x0; + currentThreadIndex = -1; + for(int i = 0; i < numReadouts; ++i){ + threadStarted = false; + currentThreadIndex = i; + sem_init(&sem_singlewait[i],1,0); + sem_init(&sem_singledone[i],1,0); + if(pthread_create(&receivingDataThreads[i], NULL,startReceivingDataThread, (void*) this)){ + cprintf(RED, "ERROR: Could not create receiving thread with index %d\n",i); + return; } + while(!threadStarted); + //cout << "Data Thread created successfully for " << i << endl; + expectedMask|=(1<startExecuting(); //tell them to start - for(int i=0;igetDataBytes(); + slsmaxchannels = detectors[0]->getMaxNumberOfChannels(); + bytesperchannel = slsdatabytes/slsmaxchannels; + slsmaxX = detectors[0]->getTotalNumberOfChannels(X); + slsmaxY = detectors[0]->getTotalNumberOfChannels(Y); + } int nel=(thisMultiDetector->dataBytes)/sizeof(int); if(nel <= 0){ - cout << "Multislsdetector databytes not valid :" << thisMultiDetector->dataBytes << endl; + cprintf(RED,"Error: Multislsdetector databytes not valid : %d\n", thisMultiDetector->dataBytes); return; } int* multiframe=new int[nel]; int* p = multiframe; int idet,offsetY,offsetX; int halfreadoutoffset = (slsmaxX/numReadoutPerDetector); - //after reconstruction int framecount=0; int nx =getTotalNumberOfChannels(slsDetectorDefs::X); int ny =getTotalNumberOfChannels(slsDetectorDefs::Y); + + + sem_post(&dataThreadStartedSemaphore); //let utils:acquire continue to start measurement/acquisition + //cprintf(BLUE,"all sockets created\n"); + + //construct complete image and send to callback while(true){ memset(((char*)multiframe),0x0,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory + + //post all of them to start + for(int ireadout=0; ireadoutoffsetY[idet] + slsmaxY)) * maxX * bytesperchannel; + //the left half or right half + if(!(ireadout%numReadoutPerDetector)) + offsetX = thisMultiDetector->offsetX[idet]; + else + offsetX = thisMultiDetector->offsetX[idet] + halfreadoutoffset; + offsetX *= bytesperchannel; + //cprintf(BLUE,"offsetx:%d offsety:%d maxx:%d slsmaxX:%d slsmaxY:%d bytesperchannel:%d\n", + // offsetX,offsetY,maxX,slsmaxX,slsmaxY,bytesperchannel); + // cprintf(BLUE,"copying bytes:%d\n", (slsmaxX/numReadoutPerDetector)*bytesperchannel); + //itnerleaving with other detectors + + //bottom + if(((idet+1)%2) == 0){ + for(int i=0;ioffsetY[idet] + slsmaxY)) * maxX * bytesperchannel; - //the left half or right half - if(!(ireadout%numReadoutPerDetector)) - offsetX = thisMultiDetector->offsetX[idet]; - else - offsetX = thisMultiDetector->offsetX[idet] + halfreadoutoffset; - offsetX *= bytesperchannel; - //cprintf(BLUE,"offsetx:%d offsety:%d maxx:%d slsmaxX:%d slsmaxY:%d bytesperchannel:%d\n", - // offsetX,offsetY,maxX,slsmaxX,slsmaxY,bytesperchannel); - //cprintf(BLUE,"copying bytes:%d\n", (slsmaxX/numReadout)*bytesperchannel); - //itnerleaving with other detectors - - //bottom - if(((idet+1)%2) == 0){ - for(int i=0;iwait_for_tasks_to_complete(); - for(int i=0;i #include #include "gitInfoLib.h" -#include int slsDetector::initSharedMemory(detectorType type, int id) { @@ -7145,108 +7144,6 @@ int slsDetector::resetFramesCaught(){ -void slsDetector::readFrameFromReceiver(){ - - //determine number of half readouts - int numReadout = 1; - if(thisDetector->myDetectorType == EIGER) numReadout = 2; - int readoutId = detId*numReadout; - volatile uint64_t runningMask = 0x0; - - //server details - char hostname[numReadout][100]; - int portno[numReadout]; - int nel=(thisDetector->dataBytes/numReadout)/sizeof(int); - for(int i=0;islsframe[readoutId+i]=new int[nel]; - } - - - //loop though the half readouts to start sockets - void *context[numReadout]; - void *zmqsocket[numReadout]; - for(int i=0;isem_multiwait[readoutId+i]); //let multi know socket created - } - - //receive msgs and let multi know - zmq_msg_t message; - int len,idet = 0; - int framecount=0; - - //read frame - while(true){ - for(int idet=0; idetsem_slswait[readoutId+idet]);//wait for it to be copied - - if(!idet) framecount++; //update indices, count only once - - // receive a message, this is a blocking function - len = zmq_msg_init (&message); /* is this required? Xiaoqiang didnt have it*/ - if(len) {cprintf(RED,"Failed to initialize message %d for %d\n",len,readoutId+idet); continue; }//error - len = zmq_msg_recv(&message, zmqsocket[idet], 0); - - //end of socket - if (len <= 3 ) { - if(!len) cprintf(RED,"Received no data in socket for %d\n", readoutId+idet); - //cout<slsframe[readoutId+idet] = NULL; - sem_post(&parentDet->sem_slsdone[readoutId+idet]); //let multi know is ready - runningMask^=(1<dataBytes/numReadout){//hoow to solve this - memcpy((char*)(parentDet->slsframe[readoutId+idet]),(char*)zmq_msg_data(&message),thisDetector->dataBytes/numReadout); - //check header, if incorrect frame, copy somewhere and assign a blank subframe and also check size - - //jungfrau masking adcval - if(thisDetector->myDetectorType == JUNGFRAU){ - for(unsigned int i=0;islsframe[readoutId+idet][i] = (parentDet->slsframe[readoutId+idet][i] & 0x3FFF3FFF); - } - } - //} - sem_post(&parentDet->sem_slsdone[readoutId+idet]);//let multi know is ready - } - }//end of for loop - - if(!runningMask){ - break; - } - } - zmq_msg_close(&message); - - //close socket - for(int i=0;islsframe[readoutId+i]; - } -} - - - - - int slsDetector::lockReceiver(int lock){ int fnum=F_LOCK_RECEIVER; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 7ae8579fc..58a5f7a61 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1570,7 +1570,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** Reads frames from receiver through a constant socket */ - void readFrameFromReceiver(); + void readFrameFromReceiver(){}; /** Locks/Unlocks the connection to the receiver /param lock sets (1), usets (0), gets (-1) the lock diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index cc10d0c12..cfae1c279 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -350,6 +350,7 @@ int slsDetectorUtils::acquire(int delflag){ pthread_mutex_lock(&mg); stopReceiver(); pthread_mutex_unlock(&mg); + // cout<<"***********receiver stopped"< 0){ -#ifdef VERY_VERY_DEBUG - if(acquiringDone == 1) cout << "acquiring seems to be done" << endl; -#endif - - - //IF GUI, check for last frames (counter upto 5) - if(dataReady){ - pthread_mutex_lock(&mg); - acquiringDone++; - pthread_mutex_unlock(&mg); -#ifdef VERY_VERY_DEBUG - cout << "acquiringDone :" << acquiringDone << endl; -#endif - } - - - //post to stopReceiver in acquire(), but continue reading frames - if (!dataReady || (acquiringDone >= 5)){ - if(!dataReady || (!nthframe) ||(!newData)){ -#ifdef VERY_VERY_DEBUG - cout << "gonna post for it to end" << endl; -#endif - sem_post(&sem_queue); -#ifdef VERY_VERY_DEBUG - cout << "Sem posted" << endl; -#endif - } - } - } - //random reads and for nthframe, checks if there is no new data - else if((!nthframe) ||(!newData)){ - //cout <<"cecking now" << endl; - if (checkJoinThread()){ - break; - } - } - - - - - - //for random reads, ask only if it has new data - if(!newData){ - if(caught > progress){ - newData = true; - - // If new data and acquiringDone>0 (= det acq over), reset to get more frames - if(dataReady && (acquiringDone > 0)){ - pthread_mutex_lock(&mg); - acquiringDone = 1; -#ifdef VERY_VERY_DEBUG - cout << "Keeping acquiringDone at 1 " << endl; -#endif - pthread_mutex_unlock(&mg); - } - - } - } - - - - if(newData){ -#ifdef VERY_VERY_DEBUG - cout << "new data" << endl; -#endif - //no gui - if (!dataReady){ - progress = caught; -#ifdef VERY_VERY_DEBUG - cout << "progress:" << progress << endl; -#endif - newData = false; -#ifdef VERY_VERY_DEBUG - cout << "newData set to false" << endl; -#endif - } - //gui - else{ - if(setReceiverOnline()==ONLINE_FLAG){ - //get data - strcpy(currentfName,""); - pthread_mutex_lock(&mg); - //int* receiverData = new int [getTotalNumberOfChannels()]; - int* receiverData = readFrameFromReceiver(currentfName,currentAcquisitionIndex,currentFrameIndex,currentSubFrameIndex); - pthread_mutex_unlock(&mg); - - //if detector returned null - if(setReceiverOnline()==OFFLINE_FLAG) - receiverData = NULL; - - //no data or wrong data for print out - if(receiverData == NULL){ - currentAcquisitionIndex = -1; - cout<<"****Detector Data returned is NULL***"< progress){ -#ifdef VERY_VERY_DEBUG - cout << "GOT data" << endl; -#endif - fdata = decodeData(receiverData); - delete [] receiverData; - if ((fdata) && (dataReady)){ - // cout << "DATAREADY 3" << endl; - thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentfName,nx,ny); - dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg); - delete thisData; - fdata = NULL; - progress = caught; -#ifdef VERY_VERY_DEBUG - cout << "progress:" << progress << endl; -#endif - newData = false; -#ifdef VERY_VERY_DEBUG - cout << "newData set to false" << endl; -#endif - } - } - } - } - } - - } -*/ - } return 0; From 1263e80d21689cb24187a7aeab3a38edcc9bd160 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 16 Sep 2016 12:49:27 +0200 Subject: [PATCH 06/42] done --- slsDetectorSoftware/commonFiles/error_defs.h | 4 +- .../multiSlsDetector/multiSlsDetector.cpp | 23 ++++++++++- .../multiSlsDetector/multiSlsDetector.h | 14 +++++-- .../slsDetector/slsDetector.cpp | 40 ++++++++++++++++--- slsDetectorSoftware/slsDetector/slsDetector.h | 14 +++++-- .../slsDetector/slsDetectorBase.h | 8 ++-- .../slsDetector/slsDetectorUtils.cpp | 29 ++++++++++++-- .../slsDetector/slsDetectorUtils.h | 15 ++++--- .../slsDetectorAnalysis/postProcessing.h | 1 - .../receiverInterface.cpp | 18 +++++++++ .../slsReceiverInterface/receiverInterface.h | 10 +++++ 11 files changed, 146 insertions(+), 30 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 89798faef..889a56240 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -61,6 +61,7 @@ using namespace std; #define DETECTOR_NETWORK_PARAMETER 0x0000000000400000ULL #define RATE_CORRECTION_NOT_32BIT 0x0000000000800000ULL #define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000001000000ULL +#define DATA_STREAMING_IN_RECEIVER 0x0000000002000000ULL // 0x00000000FFFFFFFFULL /** @short class returning all error messages for error mask */ @@ -198,7 +199,8 @@ public: if(slsErrorMask&RATE_CORRECTION_NO_TAU_PROVIDED) retval.append("Rate correction Deactivated. No default tau provided in file\n"); - + if(slsErrorMask&DATA_STREAMING_IN_RECEIVER) + retval.append("Could not set/reset Data Streaming in Receiver\n"); diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index c33b5767d..21b50a023 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -3352,6 +3352,7 @@ char* multiSlsDetector::setNetworkParameter(networkParameter p, string s){ } } + return getNetworkParameter(p); } @@ -5421,7 +5422,7 @@ int multiSlsDetector::calibratePedestal(int frames){ return ret; } -int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver,int i){ +int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){ int ret=-100, ret1; if(!getFromReceiver) @@ -5429,7 +5430,7 @@ int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver,int i){ for (int idet=0; idetnumberOfDetectors; idet++) { if (detectors[idet]) { - ret1=detectors[idet]->setReadReceiverFrequency(getFromReceiver,i); + ret1=detectors[idet]->setReadReceiverFrequency(getFromReceiver,freq); if(detectors[idet]->getErrorMask()) setErrorMask(getErrorMask()|(1<numberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setDataStreamingFromReceiver(enable); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; idet++) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index c9826390d..0c811894b 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1242,14 +1242,20 @@ class multiSlsDetector : public slsDetectorUtils { int calibratePedestal(int frames = 0); /** Sets the read receiver frequency - if Receiver read upon gui request, readRxrFrequency=0, + if data required from receiver randomly readRxrFrequency=0, else every nth frame to be sent to gui @param getFromReceiver is 1 if it should ask the receiver, - 0 if it can get it from multislsdetecter - @param i is the receiver read frequency + 0 if it can get it from multi structure + @param freq is the receiver read frequency /returns read receiver frequency */ - int setReadReceiverFrequency(int getFromReceiver, int i=-1); + int setReadReceiverFrequency(int getFromReceiver, int freq=-1); + + /** Enable or disable streaming data from receiver to client + * @param enable 0 to disable 1 to enable -1 to only get the value + * @returns data streaming + */ + int setDataStreamingFromReceiver(int enable=-1); /** updates the multidetector offsets */ void updateOffsets(); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 344d3081d..e50c85442 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -7431,18 +7431,18 @@ int64_t slsDetector::clearAllErrorMask(){ -int slsDetector::setReadReceiverFrequency(int getFromReceiver,int i){ +int slsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){ int fnum=F_READ_RECEIVER_FREQUENCY; int ret = FAIL; int retval=-1; - int arg = i; + int arg = freq; if(!getFromReceiver) return retval; if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "Sending read frequency to receiver " << arg << std::endl; + std::cout << "Sending read frequency to receiver " << arg << std::endl; #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum,retval,arg); @@ -7453,14 +7453,44 @@ int slsDetector::setReadReceiverFrequency(int getFromReceiver,int i){ updateReceiver(); } - if ((i > 0) && (retval != i)){ - cout << "could not set receiver read frequency:" << retval << endl; + if ((freq > 0) && (retval != freq)){ + cout << "could not set receiver read frequency to " << freq <<" Returned:" << retval << endl; setErrorMask((getErrorMask())|(RECEIVER_READ_FREQUENCY)); } return retval; } + +int slsDetector::setDataStreamingFromReceiver(int enable){ + int fnum=F_STREAM_DATA_FROM_RECEIVER; + int ret = FAIL; + int retval=-1; + int arg = enable; + + + if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "***************Sending Data Streaming in Receiver " << arg << std::endl; +#endif + if (connectData() == OK) + ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); + if(ret==FAIL) + retval = -1; + if(ret==FORCE_UPDATE) + updateReceiver(); + } + + if ((enable > 0) && (retval != enable)){ + cout << "could not set data streaming in receiver to " << enable <<" Returned:" << retval << endl; + setErrorMask((getErrorMask())|(RECEIVER_READ_FREQUENCY)); + } + return retval; +} + + + int slsDetector::enableReceiverCompression(int i){ int fnum=F_ENABLE_RECEIVER_COMPRESSION; int ret = FAIL; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 58a5f7a61..91f3ea91f 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1671,14 +1671,20 @@ class slsDetector : public slsDetectorUtils, public energyConversion { char* setDetectorNetworkParameter(networkParameter index, int delay); /** Sets the read receiver frequency - if Receiver read upon gui request, readRxrFrequency=0, + if data required from receiver randomly readRxrFrequency=0, else every nth frame to be sent to gui @param getFromReceiver is 1 if it should ask the receiver, - 0 if it can get it from multislsdetecter - @param i is the receiver read frequency + 0 if it can get it from multi structure + @param freq is the receiver read frequency /returns read receiver frequency */ - int setReadReceiverFrequency(int getFromReceiver, int i=-1); + int setReadReceiverFrequency(int getFromReceiver, int freq=-1); + + /** Enable or disable streaming data from receiver to client + * @param enable 0 to disable 1 to enable -1 to only get the value + * @returns data streaming + */ + int setDataStreamingFromReceiver(int enable=-1); /** enable/disable or get data compression in receiver * @param i is -1 to get, 0 to disable and 1 to enable diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 8bbb145a3..9ebfd25c0 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -512,14 +512,14 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef /** Sets the read receiver frequency - if Receiver read upon gui request, readRxrFrequency=0, + if data required from receiver randomly readRxrFrequency=0, else every nth frame to be sent to gui @param getFromReceiver is 1 if it should ask the receiver, - 0 if it can get it from multislsdetecter - @param i is the receiver read frequency + 0 if it can get it from multi structure + @param freq is the receiver read frequency /returns read receiver frequency */ - virtual int setReadReceiverFrequency(int getFromReceiver, int i=-1)=0; + virtual int setReadReceiverFrequency(int getFromReceiver, int freq=-1)=0; /** Sets the receiver to start any readout remaining in the fifo and * change status to transmitting. diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index cfae1c279..5abe7d8d9 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -8,7 +8,7 @@ #include #include #include - +#include //clock() using namespace std; slsDetectorUtils::slsDetectorUtils() { @@ -42,6 +42,8 @@ slsDetectorUtils::slsDetectorUtils() { int slsDetectorUtils::acquire(int delflag){ + struct timespec begin,end; + clock_gettime(CLOCK_REALTIME, &begin); //ensure acquire isnt started multiple times by same client if(getAcquiringFlag() == false) @@ -58,11 +60,25 @@ int slsDetectorUtils::acquire(int delflag){ }else{ //put receiver read frequency to random if no gui int ret = setReadReceiverFrequency(0); - if(ret>0 && (acquisition_finished == NULL)){ - std::cout << "Error: receiver read frequency is set to " << ret << " but should be > 0 only when using gui." << std::endl; + if(ret>0 && (dataReady == NULL)){ ret = setReadReceiverFrequency(1,0); - std::cout << "Current receiver read frequency: " << ret << std::endl; + std::cout << "No Data call back and hence receiver read frequency reset to " << ret <<" (Random)" << std::endl; } + + //start data streaming threads in receiver if enabled + ret = setDataStreamingFromReceiver(-1); + if(dataReady == NULL){ + if(ret){ + cout << "Disabling Data Streaming from Receiver" << endl; + setDataStreamingFromReceiver(0); //no call back but streaming enabled, then dont stream. + } + }else{ + if(*threadedProcessing && (!ret)){ + cout << "Enabling Data Streaming from Receiver" << endl; + setDataStreamingFromReceiver(1); //call back exists, threaded but streaming disabled, then stream. + } + } + } int nc=setTimer(CYCLES_NUMBER,-1); @@ -475,6 +491,7 @@ int slsDetectorUtils::acquire(int delflag){ #endif if(dataReady) sem_destroy(&dataThreadStartedSemaphore); + } @@ -502,6 +519,10 @@ int slsDetectorUtils::acquire(int delflag){ #endif setAcquiringFlag(false); + + clock_gettime(CLOCK_REALTIME, &end); + cprintf(BLUE,"Elapsed time:%f seconds\n",( end.tv_sec - begin.tv_sec ) + ( end.tv_nsec - begin.tv_nsec ) / 1000000000.0); + return OK; } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index d84503d59..929ce64ce 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -645,7 +645,6 @@ virtual int resetFramesCaught()=0; */ virtual void readFrameFromReceiver()=0; - /** Turns off the receiver server! */ @@ -688,14 +687,20 @@ virtual int setROI(int n=-1,ROI roiLimits[]=NULL)=0; virtual ROI* getROI(int &n)=0; /** Sets the read receiver frequency - if Receiver read upon gui request, readRxrFrequency=0, + if data required from receiver randomly readRxrFrequency=0, else every nth frame to be sent to gui @param getFromReceiver is 1 if it should ask the receiver, - 0 if it can get it from multislsdetecter - @param i is the receiver read frequency + 0 if it can get it from multi structure + @param freq is the receiver read frequency /returns read receiver frequency */ -virtual int setReadReceiverFrequency(int getFromReceiver, int i=-1)=0; +virtual int setReadReceiverFrequency(int getFromReceiver, int freq=-1)=0; + +/** Enable or disable streaming of data from receiver to client + * @param enable 0 to disable 1 to enable -1 to only get the value + * @returns data streaming +*/ +virtual int setDataStreamingFromReceiver(int enable=-1)=0; /** enable/disable or get data compression in receiver diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h index ae89471a9..dff44e5f8 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h @@ -338,7 +338,6 @@ s private: // double *fdata; - // int (*dataReady)(detectorData*,int, int,void*); // void *pCallbackArg; diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp index e5a5011a0..463d51a71 100644 --- a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp @@ -129,6 +129,24 @@ int receiverInterface::sendIntArray(int fnum, int64_t &retval, int64_t arg[2]){ +int receiverInterface::sendIntArray(int fnum, int &retval, int arg[2]){ + int args[2]; + int ret = slsDetectorDefs::FAIL; + char mess[100] = ""; + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->SendDataOnly(arg,sizeof(args)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==slsDetectorDefs::FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + + return ret; +} + + + int receiverInterface::getInt(int fnum, int64_t &retval){ int ret = slsDetectorDefs::FAIL; diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h index 27fbea6a1..11e433a08 100644 --- a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h @@ -95,6 +95,16 @@ public: */ int sendIntArray(int fnum, int64_t &retval, int64_t arg[2]); + + /** + * Send an integer to receiver + * @param fnum function enum to determine what parameter + * @param retval return value + * @param arg values to send + * \returns success of operation + */ + int sendIntArray(int fnum, int &retval, int arg[2]); + /** * Get an integer value from receiver * @param fnum function enum to determine what parameter From f517eb7a41d7f57aa594e0201365a6cf9f8e278a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 16 Sep 2016 17:19:37 +0200 Subject: [PATCH 07/42] included json example with dummy values --- slsDetectorSoftware/CMakeLists.txt | 6 +++ .../multiSlsDetector/multiSlsDetector.cpp | 47 +++++++++++++++---- .../slsDetector/slsDetectorUtils.cpp | 2 +- .../slsDetectorClient/CMakeLists.txt | 8 ++++ 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/slsDetectorSoftware/CMakeLists.txt b/slsDetectorSoftware/CMakeLists.txt index 5263ea204..69f395cc9 100644 --- a/slsDetectorSoftware/CMakeLists.txt +++ b/slsDetectorSoftware/CMakeLists.txt @@ -39,6 +39,12 @@ add_definitions( -DDACS_INT ) +add_library(zmq STATIC IMPORTED ) + +set_target_properties(zmq PROPERTIES + IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../slsReceiverSoftware/include/libzmq.a +) + add_library(slsDetectorStatic STATIC ${SOURCES} ${HEADERS} diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 21b50a023..5d613e080 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -24,6 +24,7 @@ ID: $Id$ #include #include #include +#include //to scan json header in zmq stream using namespace std; @@ -5012,16 +5013,44 @@ void multiSlsDetector::startReceivingData(){ if(!idet) framecount++; //update indices, count only once - // receive a message, this is a blocking function - len = zmq_msg_init (&message); /* is this required? Xiaoqiang didnt have it*/ - if(len) {cprintf(RED,"Failed to initialize message %d for %d\n",len,ithread); continue; } //error + + //scan header-------------------------------------------------------- + zmq_msg_init (&message); + len = zmq_msg_recv(&message, zmqsocket, 0); + if (len == -1) { + zmq_msg_close(&message); + cprintf(RED, "%d message null\n",ithread); + continue; + } + rapidjson::Document d; + d.Parse((char*)zmq_msg_data(&message)); + // htype is an array of strings + rapidjson::Value::Array htype = d["htype"].GetArray(); + for(int i=0; i< htype.Size(); i++) + cout << ithread << "htype: " << htype[i].GetString() << endl;/*print*/ + // shape is an array of ints + rapidjson::Value::Array shape = d["shape"].GetArray(); + cout << ithread << "shape: "; /*print*/ + for(int i=0; i< shape.Size(); i++) + cout << ithread << shape[i].GetInt() << " ";/*print*/ + cout << endl; + + cout << ithread << "type: " << d["type"].GetString() << endl;/*print*/ + // close the message + zmq_msg_close(&message); + + + //scan data-------------------------------------------------------- + zmq_msg_init (&message); len = zmq_msg_recv(&message, zmqsocket, 0); - //if(len<1024*256) - //cprintf(RED,"got less than planned for socket %d\n",ithread); + //last one + if(len<1024*256){ + cprintf(RED,"got less than planned for socket %d\n",ithread); //end of socket - if (len <= 3 ) { + //if (len <= 3 ) { if(!len) cprintf(RED,"Received no data in socket for %d\n", ithread); + zmq_msg_close(&message); //cout< Date: Mon, 19 Sep 2016 12:34:31 +0200 Subject: [PATCH 08/42] bug fixed, rapidjson parse error --- .../multiSlsDetector/multiSlsDetector.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 5d613e080..b8506ac2e 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5022,20 +5022,25 @@ void multiSlsDetector::startReceivingData(){ cprintf(RED, "%d message null\n",ithread); continue; } + + rapidjson::Document d; - d.Parse((char*)zmq_msg_data(&message)); + // d.Parse((char*)zmq_msg_data(&message)); + d.Parse( (char*)zmq_msg_data(&message), zmq_msg_size(&message)); + // htype is an array of strings rapidjson::Value::Array htype = d["htype"].GetArray(); for(int i=0; i< htype.Size(); i++) - cout << ithread << "htype: " << htype[i].GetString() << endl;/*print*/ + std::cout << ithread << "htype: " << htype[i].GetString() << std::endl; // shape is an array of ints rapidjson::Value::Array shape = d["shape"].GetArray(); - cout << ithread << "shape: "; /*print*/ + cout << ithread << "shape: "; for(int i=0; i< shape.Size(); i++) - cout << ithread << shape[i].GetInt() << " ";/*print*/ + cout << ithread << shape[i].GetInt() << " "; cout << endl; - cout << ithread << "type: " << d["type"].GetString() << endl;/*print*/ + cout << ithread << "type: " << d["type"].GetString() << endl; + // close the message zmq_msg_close(&message); @@ -5046,7 +5051,7 @@ void multiSlsDetector::startReceivingData(){ //last one if(len<1024*256){ - cprintf(RED,"got less than planned for socket %d\n",ithread); + cprintf(RED,"got less than planned for socket %d, length:%d\n",ithread,len); //end of socket //if (len <= 3 ) { if(!len) cprintf(RED,"Received no data in socket for %d\n", ithread); From 904d21d0be7d172eed5a11880dcec4c17fd61e5c Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 19 Sep 2016 17:21:23 +0200 Subject: [PATCH 09/42] only missing data left to be handled in zmqthread in receiver --- .../multiSlsDetector/multiSlsDetector.cpp | 91 ++++++++----------- .../multiSlsDetector/multiSlsDetector.h | 8 ++ 2 files changed, 48 insertions(+), 51 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index b8506ac2e..faad273d3 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4989,32 +4989,24 @@ void multiSlsDetector::startReceivingData(){ //loop though the half readouts to start sockets + zmq_msg_t message; + int len,idet = 0; void *context; void *zmqsocket; context = zmq_ctx_new(); zmqsocket = zmq_socket(context, ZMQ_PULL); - //zmq_setsockopt(zmqsocket, ZMQ_SUBSCRIBE, "", 0); // an empty string implies receiving any messages - zmq_connect(zmqsocket, hostname); // connect to publisher,the publisher server does not have to be started + zmq_connect(zmqsocket, hostname); // connect to publisher,the publisher server does not have to be started pthread_mutex_lock(&ms); receivingDataThreadMask|=(1<<(ithread)); - //cout< Date: Tue, 20 Sep 2016 10:42:43 +0200 Subject: [PATCH 10/42] done with eiger --- .../multiSlsDetector/multiSlsDetector.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index faad273d3..bdb813614 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5040,10 +5040,12 @@ void multiSlsDetector::startReceivingData(){ currentFrameIndex = d["fIndex"].GetInt(); currentSubFrameIndex = d["subfnum"].GetInt(); strcpy(currentFileName ,d["fname"].GetString()); - cout << ithread << "Acquisition index: " << currentAcquisitionIndex << endl; - cout << ithread << "Frame index: " << currentFrameIndex << endl; - cout << ithread << "Subframe index: " << currentSubFrameIndex << endl; - cout << ithread << "File name: " << currentFileName << endl; +#ifdef VERYVERBOSE + cout << "Acquisition index: " << currentAcquisitionIndex << endl; + cout << "Frame index: " << currentFrameIndex << endl; + cout << "Subframe index: " << currentSubFrameIndex << endl; + cout << "File name: " << currentFileName << endl; +#endif } // close the message zmq_msg_close(&message); @@ -5056,7 +5058,9 @@ void multiSlsDetector::startReceivingData(){ //end of socket ("end") if (len < 1024*256 ) { if(!len) cprintf(RED,"Received no data in socket for %d\n", ithread); +#ifdef VERYVERBOSE cprintf(RED,"End of socket for %d\n", ithread); +#endif zmq_msg_close(&message); singleframe[ithread] = NULL; pthread_mutex_lock(&ms); @@ -5158,7 +5162,7 @@ void multiSlsDetector::readFrameFromReceiver(){ //construct complete image and send to callback while(true){ - memset(((char*)multiframe),0x0,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory + memset(((char*)multiframe),0xFF,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory //post all of them to start for(int ireadout=0; ireadout Date: Tue, 20 Sep 2016 15:11:39 +0200 Subject: [PATCH 11/42] done for eiger, some checks for frameindex=-1,socket closing earlier than last socket etc --- .../multiSlsDetector/multiSlsDetector.cpp | 13 ++++++++----- .../multiSlsDetector/multiSlsDetector.h | 2 +- slsDetectorSoftware/slsDetector/slsDetector.cpp | 2 +- slsDetectorSoftware/slsDetector/slsDetector.h | 2 +- .../slsDetector/slsDetectorUsers.cpp | 4 +++- slsDetectorSoftware/slsDetector/slsDetectorUsers.h | 9 +++++++++ .../slsDetector/slsDetectorUtils.cpp | 6 +++--- slsDetectorSoftware/slsDetector/slsDetectorUtils.h | 2 +- 8 files changed, 27 insertions(+), 13 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index bdb813614..57a2a31b6 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5046,7 +5046,9 @@ void multiSlsDetector::startReceivingData(){ cout << "Subframe index: " << currentSubFrameIndex << endl; cout << "File name: " << currentFileName << endl; #endif + if(currentFrameIndex ==-1) cprintf(RED,"multi frame index -1!!\n"); } + // close the message zmq_msg_close(&message); @@ -5058,9 +5060,9 @@ void multiSlsDetector::startReceivingData(){ //end of socket ("end") if (len < 1024*256 ) { if(!len) cprintf(RED,"Received no data in socket for %d\n", ithread); -#ifdef VERYVERBOSE +//#ifdef VERYVERBOSE cprintf(RED,"End of socket for %d\n", ithread); -#endif +//#endif zmq_msg_close(&message); singleframe[ithread] = NULL; pthread_mutex_lock(&ms); @@ -5173,6 +5175,7 @@ void multiSlsDetector::readFrameFromReceiver(){ //get each frame for(int ireadout=0; ireadoutnumberOfDetectors; idet++) { if (detectors[idet]) { - ret1=detectors[idet]->setDataStreamingFromReceiver(enable); + ret1=detectors[idet]->enableDataStreamingFromReceiver(enable); if(detectors[idet]->getErrorMask()) setErrorMask(getErrorMask()|(1<setReadReceiverFrequency(1,n); } - +int slsDetectorUsers::enableDataStreamingFromReceiver(int i){ + return myDetector->enableDataStreamingFromReceiver(i); +} int64_t slsDetectorUsers::getModuleFirmwareVersion(){ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h index 24abc2fc4..214661384 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h @@ -450,6 +450,15 @@ class slsDetectorUsers virtual void finalizeDataset(double *a, double *v, double *e, int &np); + + /** + Enable data streaming from receiver (zmq) + \param i 1 to set, 0 to reset and -1 to get + \returns data streaming enable + */ + int enableDataStreamingFromReceiver(int i=-1); + + /** get get Module Firmware Version \returns id diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 2faedf547..00579353a 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -66,16 +66,16 @@ int slsDetectorUtils::acquire(int delflag){ } //start data streaming threads in receiver if enabled - ret = setDataStreamingFromReceiver(-1); + ret = enableDataStreamingFromReceiver(-1); if(dataReady == NULL){ if(ret){ cout << "Disabling Data Streaming from Receiver" << endl; - setDataStreamingFromReceiver(0); //no call back but streaming enabled, then dont stream. + enableDataStreamingFromReceiver(0); //no call back but streaming enabled, then dont stream. } }else{ if(*threadedProcessing && (!ret)){ cout << "Enabling Data Streaming from Receiver" << endl; - setDataStreamingFromReceiver(1); //call back exists, threaded but streaming disabled, then stream. + enableDataStreamingFromReceiver(1); //call back exists, threaded but streaming disabled, then stream. } } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 929ce64ce..b7ae08eff 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -700,7 +700,7 @@ virtual int setReadReceiverFrequency(int getFromReceiver, int freq=-1)=0; * @param enable 0 to disable 1 to enable -1 to only get the value * @returns data streaming */ -virtual int setDataStreamingFromReceiver(int enable=-1)=0; +virtual int enableDataStreamingFromReceiver(int enable=-1)=0; /** enable/disable or get data compression in receiver From d0501c31392df837ae681ee2bceeb66b1254c2aa Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 21 Sep 2016 16:37:29 +0200 Subject: [PATCH 12/42] creating and destroying sockets for each receiver start and stop in a single acquisition (to deal with scans etc) --- .../multiSlsDetector/multiSlsDetector.cpp | 359 +++++++++++------- .../multiSlsDetector/multiSlsDetector.h | 24 +- slsDetectorSoftware/slsDetector/slsDetector.h | 13 + .../slsDetector/slsDetectorUtils.cpp | 23 +- .../slsDetector/slsDetectorUtils.h | 12 + .../slsDetectorAnalysis/postProcessing.h | 1 - 6 files changed, 289 insertions(+), 143 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 57a2a31b6..ce4627cb0 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4958,17 +4958,111 @@ int multiSlsDetector::resetFramesCaught() { } +int multiSlsDetector::createReceivingDataThreads(bool destroy){ + + int numReadouts = thisMultiDetector->numberOfDetectors; + if(getDetectorsType() == EIGER) + numReadouts *= 2; + + //reset masks + killAllReceivingDataThreads = false; + pthread_mutex_lock(&ms); + receivingDataThreadMask = 0x0; + pthread_mutex_unlock(&(ms)); + + //destroy + if(destroy){ +#ifdef DEBUG + cout << "Destroying Receiving Data Thread(s)" << endl; +#endif + killAllReceivingDataThreads = true; + for(int i = 0; i < numReadouts; ++i){ + sem_post(&receivingDataSemaphore[i]); + pthread_join(receivingDataThreads[i],NULL); + sem_destroy(&receivingDataSemaphore[i]); + sem_destroy(&receivingDataSocketsCreatedSemaphore[i]); + sem_destroy(&sem_singlewait[i]); + sem_destroy(&sem_singledone[i]); + delete [] singleframe[i]; +#ifdef DEBUG + cout << "." << flush << endl; +#endif + } + killAllReceivingDataThreads = false; + threadStarted = false; + + cout << "Destroyed Receiving Data Thread(s)" << endl; + } + + //create + else{ +#ifdef DEBUG + cout << "Creating Receiving Data Thread(s)" << endl; +#endif + //reset current index + currentThreadIndex = -1; + + for(int i = 0; i < numReadouts; ++i){ + sem_init(&receivingDataSemaphore[i],1,0); + sem_init(&receivingDataSocketsCreatedSemaphore[i],1,0); + sem_init(&sem_singlewait[i],1,0); + sem_init(&sem_singledone[i],1,0); + threadStarted = false; + currentThreadIndex = i; + if(pthread_create(&receivingDataThreads[i], NULL,startReceivingDataThread, (void*) this)){ + cout << "Could not create receiving data thread with index " << i << endl; + return FAIL; + } + while(!threadStarted); +#ifdef DEBUG + cout << "." << flush << endl; +#endif + } + //cout << "Receiving Data Thread(s) created" << endl; + + for(int i=0;inumberOfDetectors; + if(getDetectorsType() == EIGER) + numReadouts *= 2; + + if(threadStarted){ + for(int i=0;istartReceivingData(); + ((multiSlsDetector*)this_pointer)->startReceivingDataThread(); return this_pointer; } -void multiSlsDetector::startReceivingData(){ +void multiSlsDetector::startReceivingDataThread(){ int ithread = currentThreadIndex; //set current thread value index threadStarted = true; //let calling function know thread started and obtained current - + //cout << ithread << " thread created" << endl; int numReadoutPerDetector = 1; bool jungfrau = false; @@ -4987,111 +5081,129 @@ void multiSlsDetector::startReceivingData(){ //cout << "ZMQ Client of " << ithread << " at " << hostname << endl; singleframe[ithread]=new int[nel]; - - //loop though the half readouts to start sockets - zmq_msg_t message; - int len,idet = 0; - void *context; - void *zmqsocket; - context = zmq_ctx_new(); - zmqsocket = zmq_socket(context, ZMQ_PULL); - zmq_connect(zmqsocket, hostname); // connect to publisher,the publisher server does not have to be started - pthread_mutex_lock(&ms); - receivingDataThreadMask|=(1<<(ithread)); - pthread_mutex_unlock(&ms); - - - //read frame + /* outer loop - loops once for each acquisition */ + //infinite loop, exited only at the end of acquire() while(true){ - sem_wait(&sem_singlewait[ithread]); //wait for it to be copied + zmq_msg_t message; + int len,idet = 0; + void *context; + void *zmqsocket; + context = zmq_ctx_new(); + zmqsocket = zmq_socket(context, ZMQ_PULL); + zmq_connect(zmqsocket, hostname); + //cprintf(BLUE,"%d ZMQ Client Socket at %s\n",ithread, hostname); + sem_post(&receivingDataSocketsCreatedSemaphore[ithread]); - //scan header------------------------------------------------------------------- - zmq_msg_init (&message); - len = zmq_msg_recv(&message, zmqsocket, 0); - if (len == -1) { - zmq_msg_close(&message); - cprintf(RED, "%d message null\n",ithread); - continue; - } - - // error if you print it - // cout << ithread << " header len:"<numberOfDetectors; - - //create threads - /** Data Callback Threads */ - pthread_t receivingDataThreads[numReadouts]; - volatile uint64_t expectedMask = 0x0; - receivingDataThreadMask = 0x0; - currentThreadIndex = -1; + //initializing variables strcpy(currentFileName,""); - for(int i = 0; i < numReadouts; ++i){ - threadStarted = false; - currentThreadIndex = i; - sem_init(&sem_singlewait[i],1,0); - sem_init(&sem_singledone[i],1,0); - if(pthread_create(&receivingDataThreads[i], NULL,startReceivingDataThread, (void*) this)){ - cprintf(RED, "ERROR: Could not create receiving thread with index %d\n",i); - return; - } - while(!threadStarted); - //cout << "Data Thread created successfully for " << i << endl; - expectedMask|=(1<getDataBytes(); @@ -5158,9 +5250,14 @@ void multiSlsDetector::readFrameFromReceiver(){ - sem_post(&dataThreadStartedSemaphore); //let utils:acquire continue to start measurement/acquisition + volatile uint64_t expectedMask = 0x0; + for(int i = 0; i < numReadouts; ++i) + expectedMask|=(1< Date: Wed, 5 Oct 2016 15:26:58 +0200 Subject: [PATCH 13/42] somewhere, but weird threads --- slsDetectorSoftware/commonFiles/error_defs.h | 6 +- .../multiSlsDetector/multiSlsDetector.cpp | 313 ++++++++---------- .../multiSlsDetector/multiSlsDetector.h | 10 - .../slsDetector/slsDetector.cpp | 2 +- slsDetectorSoftware/slsDetector/slsDetector.h | 5 - .../slsDetector/slsDetectorUtils.cpp | 23 +- .../slsDetector/slsDetectorUtils.h | 5 - .../slsDetectorAnalysis/postProcessing.h | 1 - 8 files changed, 145 insertions(+), 220 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 9500d3494..55c84218a 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -63,7 +63,7 @@ using namespace std; #define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000001000000ULL #define PROGRAMMING_ERROR 0x0000000002000000ULL #define RECEIVER_ACTIVATE 0x0000000004000000ULL -#define DATA_STREAMING_IN_RECEIVER 0x0000000008000000ULL +#define DATA_STREAMING 0x0000000008000000ULL // 0x00000000FFFFFFFFULL /** @short class returning all error messages for error mask */ @@ -207,8 +207,8 @@ public: if(slsErrorMask&RECEIVER_ACTIVATE) retval.append("Could not activate/deactivate receiver\n"); - if(slsErrorMask&DATA_STREAMING_IN_RECEIVER) - retval.append("Could not set/reset Data Streaming in Receiver\n"); + if(slsErrorMask&DATA_STREAMING) + retval.append("Could not set/reset Data Streaming\n"); diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index a83d91bd0..5d50eb644 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4981,9 +4981,6 @@ int multiSlsDetector::createReceivingDataThreads(bool destroy){ //reset masks killAllReceivingDataThreads = false; - pthread_mutex_lock(&ms); - receivingDataThreadMask = 0x0; - pthread_mutex_unlock(&(ms)); //destroy if(destroy){ @@ -4992,13 +4989,10 @@ int multiSlsDetector::createReceivingDataThreads(bool destroy){ #endif killAllReceivingDataThreads = true; for(int i = 0; i < numReadouts; ++i){ - sem_post(&receivingDataSemaphore[i]); + sem_post(&sem_singlewait[i]); pthread_join(receivingDataThreads[i],NULL); - sem_destroy(&receivingDataSemaphore[i]); - sem_destroy(&receivingDataSocketsCreatedSemaphore[i]); sem_destroy(&sem_singlewait[i]); sem_destroy(&sem_singledone[i]); - delete [] singleframe[i]; #ifdef DEBUG cout << "." << flush << endl; #endif @@ -5018,14 +5012,12 @@ int multiSlsDetector::createReceivingDataThreads(bool destroy){ currentThreadIndex = -1; for(int i = 0; i < numReadouts; ++i){ - sem_init(&receivingDataSemaphore[i],1,0); - sem_init(&receivingDataSocketsCreatedSemaphore[i],1,0); sem_init(&sem_singlewait[i],1,0); sem_init(&sem_singledone[i],1,0); threadStarted = false; currentThreadIndex = i; if(pthread_create(&receivingDataThreads[i], NULL,startReceivingDataThread, (void*) this)){ - cout << "Could not create receiving data thread with index " << i << endl; + cprintf(RED, "Could not create receiving data thread with index %d\n",i); return FAIL; } while(!threadStarted); @@ -5033,39 +5025,13 @@ int multiSlsDetector::createReceivingDataThreads(bool destroy){ cout << "." << flush << endl; #endif } - //cout << "Receiving Data Thread(s) created" << endl; - - for(int i=0;inumberOfDetectors; - if(getDetectorsType() == EIGER) - numReadouts *= 2; - - if(threadStarted){ - for(int i=0;istartReceivingDataThread(); @@ -5076,9 +5042,9 @@ void* multiSlsDetector::startReceivingDataThread(void* this_pointer){ void multiSlsDetector::startReceivingDataThread(){ int ithread = currentThreadIndex; //set current thread value index - threadStarted = true; //let calling function know thread started and obtained current //cout << ithread << " thread created" << endl; + //number of readouts int numReadoutPerDetector = 1; bool jungfrau = false; if(getDetectorsType() == EIGER){ @@ -5093,132 +5059,120 @@ void multiSlsDetector::startReceivingDataThread(){ int nel=(singleDatabytes/numReadoutPerDetector)/sizeof(int); portno = DEFAULT_ZMQ_PORTNO + (ithread); sprintf(hostname, "%s%d", "tcp://127.0.0.1:",portno); - //cout << "ZMQ Client of " << ithread << " at " << hostname << endl; - singleframe[ithread]=new int[nel]; + cout << "ZMQ Client of " << ithread << " at " << hostname << endl; - /* outer loop - loops once for each acquisition */ - //infinite loop, exited only at the end of acquire() + + //socket details + zmq_msg_t message; + void *context; + void *zmqsocket; + context = zmq_ctx_new(); + zmqsocket = zmq_socket(context, ZMQ_PULL); + zmq_connect(zmqsocket, hostname); + threadStarted = true; //let calling function know thread started and obtained current + + //initializations + singleframe[ithread]=new int[nel]; + int len,idet = 0; + + //infinite loop, exited only (if gui restarted/ enabledatastreaming called) while(true){ - zmq_msg_t message; - int len,idet = 0; - void *context; - void *zmqsocket; - context = zmq_ctx_new(); - zmqsocket = zmq_socket(context, ZMQ_PULL); - zmq_connect(zmqsocket, hostname); - //cprintf(BLUE,"%d ZMQ Client Socket at %s\n",ithread, hostname); - sem_post(&receivingDataSocketsCreatedSemaphore[ithread]); - /* inner loop - loop for each buffer */ - //enters at receiver start and exits at receiver stop - while((1 << ithread) & receivingDataThreadMask){ - - - sem_wait(&sem_singlewait[ithread]); //wait for it to be copied - - //scan header------------------------------------------------------------------- - zmq_msg_init (&message); - len = zmq_msg_recv(&message, zmqsocket, 0); - if (len == -1) { - zmq_msg_close(&message); - cprintf(RED, "%d message null\n",ithread); - continue; - } - - // error if you print it - // cout << ithread << " header len:"<= 0){ + //destroy data threads + if(threadStarted) + createReceivingDataThreads(true); + + //create data threads if enable is 1 + if(enable == 1) + if(createReceivingDataThreads() == FAIL){ + std::cout << "Could not create data threads in client. Aborting creating data threads in receiver" << std::endl; + //only for the first det as theres no general one + setErrorMask(getErrorMask()|(1<<0)); + detectors[0]->setErrorMask((detectors[0]->getErrorMask())|(DATA_STREAMING)); + return -1; + } + } + + + int ret=-100, ret1; for (int idet=0; idetnumberOfDetectors; idet++) { if (detectors[idet]) { ret1=detectors[idet]->enableDataStreamingFromReceiver(enable); @@ -5600,6 +5562,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ } } + return ret; } diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index e322d71b5..1bc3beeaf 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1191,11 +1191,6 @@ class multiSlsDetector : public slsDetectorUtils { */ int createReceivingDataThreads(bool destroy = false); - /** - * Start Receiving Data Threads - * @return OK or FAIL - */ - int startReceivingData(); /** Reads frames from receiver through a constant socket @@ -1401,15 +1396,10 @@ private: char currentFileName[MAX_STR_LENGTH]; pthread_t receivingDataThreads[MAXDET]; - sem_t receivingDataSemaphore[MAXDET]; /** Ensures if threads created successfully */ bool threadStarted; /** Current Thread Index*/ int currentThreadIndex; - /** Mask with each bit indicating status of each receiving data thread */ - volatile uint64_t receivingDataThreadMask; - /** Semaphore indicating socket created for each receiving data thread */ - sem_t receivingDataSocketsCreatedSemaphore[MAXDET]; /** Set to self-terminate data receiving threads waiting for semaphores */ bool killAllReceivingDataThreads; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 404f007e5..6c3901d6c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -7720,7 +7720,7 @@ int slsDetector::enableDataStreamingFromReceiver(int enable){ if ((enable > 0) && (retval != enable)){ cout << "could not set data streaming in receiver to " << enable <<" Returned:" << retval << endl; - setErrorMask((getErrorMask())|(RECEIVER_READ_FREQUENCY)); + setErrorMask((getErrorMask())|(DATA_STREAMING)); } return retval; } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 016361f8c..1f0cb7dfb 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1580,11 +1580,6 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int createReceivingDataThreads(bool destroy = false){}; - /** - * Start Receiving Data Threads - * @return OK or FAIL - */ - int startReceivingData(){}; /** Reads frames from receiver through a constant socket */ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 9731a3548..7faa528f9 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -172,22 +172,18 @@ int slsDetectorUtils::acquire(int delflag){ } - if (*threadedProcessing) { - sem_init(&dataThreadStartedSemaphore,1,0); + if (*threadedProcessing) startThread(delflag); - - if(dataReady) - createReceivingDataThreads(); - } #ifdef VERBOSE cout << " starting thread " << endl; #endif //resets frames caught in receiver if(receiver){ - resetFramesCaught(); + resetFramesCaught(); } + for(int im=0;im Date: Thu, 6 Oct 2016 08:44:00 +0200 Subject: [PATCH 14/42] somewhere --- .../multiSlsDetector/multiSlsDetector.cpp | 14 ++++++++++---- .../slsDetectorAnalysis/postProcessing.cpp | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 5d50eb644..6a88bbb51 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4974,11 +4974,15 @@ int multiSlsDetector::resetFramesCaught() { int multiSlsDetector::createReceivingDataThreads(bool destroy){ + if(!destroy) cprintf(MAGENTA,"Going to create data threads\n"); + else cprintf(MAGENTA,"Going to destroy data threads\n"); + int numReadouts = thisMultiDetector->numberOfDetectors; if(getDetectorsType() == EIGER) numReadouts *= 2; + //reset masks killAllReceivingDataThreads = false; @@ -5010,8 +5014,8 @@ int multiSlsDetector::createReceivingDataThreads(bool destroy){ #endif //reset current index currentThreadIndex = -1; - - for(int i = 0; i < numReadouts; ++i){ +cout<<"numreadouts:"<startReceivingDataThread(); + //((multiSlsDetector*)this_pointer)->startReceivingDataThread(); + while(true); + return this_pointer; } @@ -5042,7 +5048,7 @@ void* multiSlsDetector::startReceivingDataThread(void* this_pointer){ void multiSlsDetector::startReceivingDataThread(){ int ithread = currentThreadIndex; //set current thread value index - //cout << ithread << " thread created" << endl; + cprintf(BLUE,"thread created %d\n",ithread); //number of readouts int numReadoutPerDetector = 1; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 40f8029c1..5229ce89f 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -481,7 +481,7 @@ void* postProcessing::processData(int delflag) { } } //receiver - else{ + else{cprintf(RED,"In post processing threads\n"); if(dataReady){ @@ -517,7 +517,7 @@ void* postProcessing::processData(int delflag) { //cout<<"exiting from proccessing thread"< Date: Thu, 6 Oct 2016 13:49:40 +0200 Subject: [PATCH 15/42] looks done --- .../multiSlsDetector/multiSlsDetector.cpp | 69 +++++++++---------- .../multiSlsDetector/multiSlsDetector.h | 2 +- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 6a88bbb51..e868c0bed 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5014,13 +5014,12 @@ int multiSlsDetector::createReceivingDataThreads(bool destroy){ #endif //reset current index currentThreadIndex = -1; -cout<<"numreadouts:"<startReceivingDataThread(); - while(true); +void* multiSlsDetector::staticstartReceivingDataThread(void* this_pointer){ + ((multiSlsDetector*)this_pointer)->startReceivingDataThread(); + //while(true); return this_pointer; } @@ -5048,25 +5047,11 @@ void* multiSlsDetector::startReceivingDataThread(void* this_pointer){ void multiSlsDetector::startReceivingDataThread(){ int ithread = currentThreadIndex; //set current thread value index - cprintf(BLUE,"thread created %d\n",ithread); - - //number of readouts - int numReadoutPerDetector = 1; - bool jungfrau = false; - if(getDetectorsType() == EIGER){ - numReadoutPerDetector = 2; - }else if(getDetectorsType() == JUNGFRAU) - jungfrau = true; //server details - char hostname[100]; - int portno; - int singleDatabytes = detectors[ithread/numReadoutPerDetector]->getDataBytes(); - int nel=(singleDatabytes/numReadoutPerDetector)/sizeof(int); - portno = DEFAULT_ZMQ_PORTNO + (ithread); - sprintf(hostname, "%s%d", "tcp://127.0.0.1:",portno); - cout << "ZMQ Client of " << ithread << " at " << hostname << endl; - + char hostname[100] = "tcp://127.0.0.1:"; + int portno = DEFAULT_ZMQ_PORTNO + ithread; + sprintf(hostname,"%s%d",hostname,portno); //socket details zmq_msg_t message; @@ -5075,12 +5060,24 @@ void multiSlsDetector::startReceivingDataThread(){ context = zmq_ctx_new(); zmqsocket = zmq_socket(context, ZMQ_PULL); zmq_connect(zmqsocket, hostname); - threadStarted = true; //let calling function know thread started and obtained current + cout << "ZMQ Client of " << ithread << " at " << hostname << endl; + cprintf(BLUE,"%d Created socket\n",ithread); //initializations + int numReadoutPerDetector = 1; + bool jungfrau = false; + if(getDetectorsType() == EIGER){ + numReadoutPerDetector = 2; + }else if(getDetectorsType() == JUNGFRAU) + jungfrau = true; + int singleDatabytes = detectors[ithread/numReadoutPerDetector]->getDataBytes(); + int nel=(singleDatabytes/numReadoutPerDetector)/sizeof(int); singleframe[ithread]=new int[nel]; int len,idet = 0; + threadStarted = true; //let calling function know thread started and obtained current + + //infinite loop, exited only (if gui restarted/ enabledatastreaming called) while(true){ @@ -5151,33 +5148,33 @@ void multiSlsDetector::startReceivingDataThread(){ //#endif zmq_msg_close(&message); singleframe[ithread] = NULL; - sem_post(&sem_singledone[ithread]); //let multi know is ready - break; + //break; } - //actual data - //cout << ithread << "data " << endl; - memcpy((char*)(singleframe[ithread]),(char*)zmq_msg_data(&message),singleDatabytes/numReadoutPerDetector); + if(singleframe[ithread]!= NULL){ + //actual data + //cout << ithread << "data " << endl; + memcpy((char*)(singleframe[ithread]),(char*)zmq_msg_data(&message),singleDatabytes/numReadoutPerDetector); - //jungfrau masking adcval - if(jungfrau){ - for(unsigned int i=0;i Date: Thu, 6 Oct 2016 15:50:02 +0200 Subject: [PATCH 16/42] thread starting if rxr closed and others --- .../multiSlsDetector/multiSlsDetector.cpp | 38 ++++++++++--------- .../slsDetector/slsDetector.cpp | 3 ++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index e868c0bed..7f1a1af00 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5536,12 +5536,13 @@ int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ if(enable >= 0){ + //destroy data threads if(threadStarted) createReceivingDataThreads(true); - //create data threads if enable is 1 - if(enable == 1) + //create data threads + if(enable > 0){ if(createReceivingDataThreads() == FAIL){ std::cout << "Could not create data threads in client. Aborting creating data threads in receiver" << std::endl; //only for the first det as theres no general one @@ -5549,24 +5550,25 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ detectors[0]->setErrorMask((detectors[0]->getErrorMask())|(DATA_STREAMING)); return -1; } - } - - - int ret=-100, ret1; - for (int idet=0; idetnumberOfDetectors; idet++) { - if (detectors[idet]) { - ret1=detectors[idet]->enableDataStreamingFromReceiver(enable); - if(detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->enableDataStreamingFromReceiver(enable); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<timerValue[FRAME_NUMBER] << endl; std::cout << "dynamic range:" << thisDetector->dynamicRange << endl << endl; std::cout << "10GbE:" << thisDetector->tenGigaEnable << endl << endl; + std::cout << "dataStreaming:" << enableDataStreamingFromReceiver(-1) << endl << endl; /** enable compresison, */ #endif if(setDetectorType()!= GENERIC){ @@ -5579,6 +5580,8 @@ char* slsDetector::setReceiver(string receiverIP){ setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]); setDynamicRange(thisDetector->dynamicRange); activate(-1); + std::cout << "***********************************dataStreaming:" << parentDet->enableDataStreamingFromReceiver(-1) << endl << endl; + parentDet->enableDataStreamingFromReceiver(parentDet->enableDataStreamingFromReceiver(-1)); //set scan tag setUDPConnection(); if(thisDetector->myDetectorType == EIGER) From cce93ebbcfb1ad833a33e4b5878fc9dbb57ba9c5 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 7 Oct 2016 07:54:26 +0200 Subject: [PATCH 17/42] removing the check for receiver to update data threads upon configuration --- slsDetectorSoftware/slsDetector/slsDetector.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index d2e6189d9..0928984ab 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -5555,7 +5555,7 @@ char* slsDetector::setReceiver(string receiverIP){ std::cout << "frame number:" << thisDetector->timerValue[FRAME_NUMBER] << endl; std::cout << "dynamic range:" << thisDetector->dynamicRange << endl << endl; std::cout << "10GbE:" << thisDetector->tenGigaEnable << endl << endl; - std::cout << "dataStreaming:" << enableDataStreamingFromReceiver(-1) << endl << endl; + //std::cout << "dataStreaming:" << enableDataStreamingFromReceiver(-1) << endl << endl; /** enable compresison, */ #endif if(setDetectorType()!= GENERIC){ @@ -5580,8 +5580,8 @@ char* slsDetector::setReceiver(string receiverIP){ setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]); setDynamicRange(thisDetector->dynamicRange); activate(-1); - std::cout << "***********************************dataStreaming:" << parentDet->enableDataStreamingFromReceiver(-1) << endl << endl; - parentDet->enableDataStreamingFromReceiver(parentDet->enableDataStreamingFromReceiver(-1)); + //std::cout << "***********************************dataStreaming:" << parentDet->enableDataStreamingFromReceiver(-1) << endl << endl; + //parentDet->enableDataStreamingFromReceiver(parentDet->enableDataStreamingFromReceiver(-1)); //set scan tag setUDPConnection(); if(thisDetector->myDetectorType == EIGER) From b1dde586e114fe7203e0b408dfd9e6a8ef9f465c Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 7 Oct 2016 10:15:12 +0200 Subject: [PATCH 18/42] back to subscriber publisher --- slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 7f1a1af00..95b7f903b 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5058,7 +5058,7 @@ void multiSlsDetector::startReceivingDataThread(){ void *context; void *zmqsocket; context = zmq_ctx_new(); - zmqsocket = zmq_socket(context, ZMQ_PULL); + zmqsocket = zmq_socket(context, ZMQ_SUB); zmq_connect(zmqsocket, hostname); cout << "ZMQ Client of " << ithread << " at " << hostname << endl; cprintf(BLUE,"%d Created socket\n",ithread); From dc16d52d49af5b0960e9545d329e856f61c23c0e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 7 Oct 2016 10:21:22 +0200 Subject: [PATCH 19/42] switching off gui, and acqire should work --- .../multiSlsDetector/multiSlsDetector.cpp | 9 +++++---- slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 95b7f903b..3ec9a77f5 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5552,7 +5552,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ } } - + } int ret=-100, ret1; for (int idet=0; idetnumberOfDetectors; idet++) { if (detectors[idet]) { @@ -5566,9 +5566,10 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ } } - } - cprintf(BLUE,"threadStarted:%d\n",threadStarted); - return threadStarted; + if (ret < 0) + return -1; + else + return (ret & threadStarted); } int multiSlsDetector::enableReceiverCompression(int i){ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 7faa528f9..5dc4a835b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -73,7 +73,7 @@ int slsDetectorUtils::acquire(int delflag){ enableDataStreamingFromReceiver(0); //no call back but streaming enabled, then dont stream. } }else{ - if(*threadedProcessing && (!ret)){ + if(*threadedProcessing && (!ret || ret == -1)){ cout << "Enabling Data Streaming from Receiver" << endl; enableDataStreamingFromReceiver(1); //call back exists, threaded but streaming disabled, then stream. } From 1545d37f36c0e9c56c05dee1ec1cf959b296c8d7 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 7 Oct 2016 11:40:51 +0200 Subject: [PATCH 20/42] some changes for quitting gui and continuing with acquire from command line --- .../multiSlsDetector/multiSlsDetector.cpp | 54 ++++++++++--------- .../slsDetector/slsDetectorUtils.cpp | 14 +++-- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 3ec9a77f5..55440fb7a 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5058,7 +5058,7 @@ void multiSlsDetector::startReceivingDataThread(){ void *context; void *zmqsocket; context = zmq_ctx_new(); - zmqsocket = zmq_socket(context, ZMQ_SUB); + zmqsocket = zmq_socket(context, ZMQ_PULL); zmq_connect(zmqsocket, hostname); cout << "ZMQ Client of " << ithread << " at " << hostname << endl; cprintf(BLUE,"%d Created socket\n",ithread); @@ -5537,39 +5537,41 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ if(enable >= 0){ - //destroy data threads - if(threadStarted) - createReceivingDataThreads(true); + if(threadStarted != enable){ + //destroy data threads + if(threadStarted) + createReceivingDataThreads(true); - //create data threads - if(enable > 0){ - if(createReceivingDataThreads() == FAIL){ - std::cout << "Could not create data threads in client. Aborting creating data threads in receiver" << std::endl; - //only for the first det as theres no general one - setErrorMask(getErrorMask()|(1<<0)); - detectors[0]->setErrorMask((detectors[0]->getErrorMask())|(DATA_STREAMING)); - return -1; + //create data threads + if(enable > 0){ + if(createReceivingDataThreads() == FAIL){ + std::cout << "Could not create data threads in client. Aborting creating data threads in receiver" << std::endl; + //only for the first det as theres no general one + setErrorMask(getErrorMask()|(1<<0)); + detectors[0]->setErrorMask((detectors[0]->getErrorMask())|(DATA_STREAMING)); + return -1; + } } } } - int ret=-100, ret1; - for (int idet=0; idetnumberOfDetectors; idet++) { - if (detectors[idet]) { - ret1=detectors[idet]->enableDataStreamingFromReceiver(enable); - if(detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->enableDataStreamingFromReceiver(enable); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1< Date: Fri, 7 Oct 2016 11:56:04 +0200 Subject: [PATCH 21/42] locking improved --- .../slsDetector/slsDetectorUtils.cpp | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 5913dc7a9..f9a16fb38 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -69,24 +69,6 @@ int slsDetectorUtils::acquire(int delflag){ ret = enableDataStreamingFromReceiver(-1); cout<<"getting datastream:"< Date: Fri, 7 Oct 2016 12:45:34 +0200 Subject: [PATCH 22/42] increased delay to get framescaught from receiver for acquire form command line --- slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp | 3 ++- slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 276207b15..41d36c186 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -4485,7 +4485,8 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { if(!strcasecmp(args[1],"start")) myDet->startReceiver(); else if(!strcasecmp(args[1],"stop")){ - myDet->startReceiverReadout(); + //myDet->stopReceiver(); + // myDet->startReceiverReadout(); /*runStatus s = myDet->getReceiverStatus(); while(s != RUN_FINISHED){ usleep(50000); diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 5229ce89f..946a9e07e 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -494,7 +494,7 @@ void* postProcessing::processData(int delflag) { while(true){ cout.flush(); cout< Date: Fri, 7 Oct 2016 13:12:57 +0200 Subject: [PATCH 23/42] changed back the delay between framescaught --- slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 946a9e07e..5229ce89f 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -494,7 +494,7 @@ void* postProcessing::processData(int delflag) { while(true){ cout.flush(); cout< Date: Fri, 7 Oct 2016 13:16:12 +0200 Subject: [PATCH 24/42] ask only 1 for frames caught for 9m --- .../multiSlsDetector/multiSlsDetector.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 55440fb7a..cccb146dc 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4922,6 +4922,15 @@ slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus(){ int multiSlsDetector::getFramesCaughtByReceiver() { int ret=0,ret1=0; + + if (detectors[0]){ + ret =detectors[0]->getFramesCaughtByReceiver(); + if(detectors[0]->getErrorMask()) + setErrorMask(getErrorMask()|(1<<0)); + } + + return ret; + for (int i=0; inumberOfDetectors; i++) if (detectors[i]){ ret1+=detectors[i]->getFramesCaughtByReceiver(); From 4d1c6a19403b5e35c5a9b3b517fda828d43985c1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 7 Oct 2016 13:48:19 +0200 Subject: [PATCH 25/42] ask only 1 for frames caught for 9m --- .../multiSlsDetector/multiSlsDetector.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index cccb146dc..813d2ab05 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4923,13 +4923,15 @@ slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus(){ int multiSlsDetector::getFramesCaughtByReceiver() { int ret=0,ret1=0; - if (detectors[0]){ - ret =detectors[0]->getFramesCaughtByReceiver(); - if(detectors[0]->getErrorMask()) - setErrorMask(getErrorMask()|(1<<0)); + if(thisMultiDetector->numberOfDetectors>10) { + if (detectors[0]){ + ret =detectors[0]->getFramesCaughtByReceiver(); + if(detectors[0]->getErrorMask()) + setErrorMask(getErrorMask()|(1<<0)); + } + return ret; } - return ret; for (int i=0; inumberOfDetectors; i++) if (detectors[i]){ From 6751132466cecd5146b6dbbff2511016352b9d2f Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 7 Oct 2016 14:26:41 +0200 Subject: [PATCH 26/42] works --- slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index f9a16fb38..66b421b2a 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -65,10 +65,10 @@ int slsDetectorUtils::acquire(int delflag){ std::cout << "No Data call back and hence receiver read frequency reset to " << ret <<" (Random)" << std::endl; } - //start data streaming threads in receiver if enabled + //start/stop data streaming threads if threads in client enabled/disabled ret = enableDataStreamingFromReceiver(-1); - cout<<"getting datastream:"< Date: Fri, 7 Oct 2016 15:13:20 +0200 Subject: [PATCH 27/42] fixed bug that it does not display image 2 --- .../multiSlsDetector/multiSlsDetector.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 813d2ab05..9b6dd92ea 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5083,9 +5083,9 @@ void multiSlsDetector::startReceivingDataThread(){ jungfrau = true; int singleDatabytes = detectors[ithread/numReadoutPerDetector]->getDataBytes(); int nel=(singleDatabytes/numReadoutPerDetector)/sizeof(int); - singleframe[ithread]=new int[nel]; + int* image = new int[nel]; int len,idet = 0; - + singleframe[ithread]=NULL; threadStarted = true; //let calling function know thread started and obtained current @@ -5111,7 +5111,7 @@ void multiSlsDetector::startReceivingDataThread(){ // error if you print it // cout << ithread << " header len:"< Date: Tue, 18 Oct 2016 08:43:16 +0200 Subject: [PATCH 28/42] almost there --- .../multiSlsDetector/multiSlsDetector.cpp | 157 +++++++++++------- .../slsDetector/slsDetectorUtils.cpp | 17 +- .../slsDetector/slsDetectorUtils.h | 1 + 3 files changed, 110 insertions(+), 65 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 9b6dd92ea..b69d2103e 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5070,10 +5070,14 @@ void multiSlsDetector::startReceivingDataThread(){ void *zmqsocket; context = zmq_ctx_new(); zmqsocket = zmq_socket(context, ZMQ_PULL); + //int hwmval = 10; + //zmq_setsockopt(zmqsocket,ZMQ_RCVHWM,&hwmval,sizeof(hwmval)); //set receive HIGH WATER MARK (8-9ms slower) zmq_connect(zmqsocket, hostname); cout << "ZMQ Client of " << ithread << " at " << hostname << endl; cprintf(BLUE,"%d Created socket\n",ithread); - + /* + zmq_pollitem_t pollitem = {zmqsocket, 0 , ZMQ_POLLIN , 0}; +*/ //initializations int numReadoutPerDetector = 1; bool jungfrau = false; @@ -5086,6 +5090,7 @@ void multiSlsDetector::startReceivingDataThread(){ int* image = new int[nel]; int len,idet = 0; singleframe[ithread]=NULL; + int datavalue = 2; threadStarted = true; //let calling function know thread started and obtained current @@ -5102,82 +5107,112 @@ void multiSlsDetector::startReceivingDataThread(){ //scan header------------------------------------------------------------------- zmq_msg_init (&message); - len = zmq_msg_recv(&message, zmqsocket, 0); - if (len == -1) { - zmq_msg_close(&message); - cprintf(RED, "%d message null\n",ithread); - continue; + while(1){ + + len = zmq_msg_recv(&message, zmqsocket, ZMQ_DONTWAIT); + if(len>0) + break;//also comment out the next recv +/* + zmq_poll(&pollitem, 1, 0); + //received something, get out + if(pollitem.revents & ZMQ_POLLIN){ + pollitem.revents = 0; + break; + } +*/ + //received nothing + else if (receiverStoppedFlag){ + //one more chance if receiver stopped + datavalue--; + + if(!datavalue){ + //#ifdef VERYVERBOSE + cprintf(RED,"End of socket for %d\n", ithread); + //#endif + singleframe[ithread] = NULL; + break; + } + + //wait to check again only if receiver stopped + //usleep(4000); + } + usleep(4000); } - // error if you print it - // cout << ithread << " header len:"<0 && (dataReady == NULL)){ @@ -148,17 +149,21 @@ int slsDetectorUtils::acquire(int delflag){ if(receiver){ if(getReceiverStatus()!=IDLE) stopReceiver(); - if(setReceiverOnline()==OFFLINE_FLAG) + if(setReceiverOnline()==OFFLINE_FLAG){ *stoppedFlag=1; - + receiverStoppedFlag = 1; + } //multi detectors shouldnt have different receiver read frequencies enabled/disabled if(setReadReceiverFrequency(0) < 0){ std::cout << "Error: The receiver read frequency is invalid:" << setReadReceiverFrequency(0) << std::endl; - *stoppedFlag=1; + *stoppedFlag=1; + receiverStoppedFlag = 1; } - if(setReceiverOnline()==OFFLINE_FLAG) + if(setReceiverOnline()==OFFLINE_FLAG){ *stoppedFlag=1; + receiverStoppedFlag = 1; + } } @@ -291,6 +296,7 @@ int slsDetectorUtils::acquire(int delflag){ if(setReceiverOnline()==OFFLINE_FLAG){ stopReceiver(); *stoppedFlag=1; + receiverStoppedFlag = 1; pthread_mutex_unlock(&mg); break; } @@ -298,6 +304,7 @@ int slsDetectorUtils::acquire(int delflag){ if(startReceiver() == FAIL) { stopReceiver(); *stoppedFlag=1; + receiverStoppedFlag = 1; pthread_mutex_unlock(&mg); break; } @@ -344,6 +351,7 @@ int slsDetectorUtils::acquire(int delflag){ pthread_mutex_lock(&mg); //offline if(setReceiverOnline()==OFFLINE_FLAG){ + receiverStoppedFlag = 1; if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){ if((*correctionMask)&(1< Date: Tue, 18 Oct 2016 11:10:42 +0200 Subject: [PATCH 29/42] done --- .../multiSlsDetector/multiSlsDetector.cpp | 11 ++++------- slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp | 4 ++-- .../slsDetectorAnalysis/postProcessing.cpp | 5 +++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index b69d2103e..80a8bacc2 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5126,9 +5126,9 @@ void multiSlsDetector::startReceivingDataThread(){ datavalue--; if(!datavalue){ - //#ifdef VERYVERBOSE +#ifdef VERYVERBOSE cprintf(RED,"End of socket for %d\n", ithread); - //#endif +#endif singleframe[ithread] = NULL; break; } @@ -5602,7 +5602,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ } } - } + }else enable = threadStarted; int ret=-100, ret1; for (int idet=0; idetnumberOfDetectors; idet++) { if (detectors[idet]) { @@ -5616,10 +5616,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ } } - if(enable == -1) - return threadStarted; - else - return (threadStarted & ret); + return (threadStarted & ret); } int multiSlsDetector::enableReceiverCompression(int i){ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 0c93b917b..cdb726107 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -68,8 +68,8 @@ int slsDetectorUtils::acquire(int delflag){ //start/stop data streaming threads if threads in client enabled/disabled ret = enableDataStreamingFromReceiver(-1); - //cout<<"getting datastream:"< Date: Tue, 18 Oct 2016 12:08:11 +0200 Subject: [PATCH 30/42] trying --- .../multiSlsDetector/multiSlsDetector.cpp | 50 ++++++++++++++----- .../slsDetector/slsDetectorUtils.cpp | 16 +++--- .../slsDetector/slsDetectorUtils.h | 2 +- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 80a8bacc2..f17d733b4 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5090,7 +5090,7 @@ void multiSlsDetector::startReceivingDataThread(){ int* image = new int[nel]; int len,idet = 0; singleframe[ithread]=NULL; - int datavalue = 2; +/* int datavalue = 2;*/ threadStarted = true; //let calling function know thread started and obtained current @@ -5107,19 +5107,30 @@ void multiSlsDetector::startReceivingDataThread(){ //scan header------------------------------------------------------------------- zmq_msg_init (&message); + + //---- with end + len = zmq_msg_recv(&message, zmqsocket, 0); + if (len == -1) { + zmq_msg_close(&message); + cprintf(RED, "%d message null\n",ithread); + continue; + } + //---- + +/* while(1){ len = zmq_msg_recv(&message, zmqsocket, ZMQ_DONTWAIT); if(len>0) break;//also comment out the next recv -/* - zmq_poll(&pollitem, 1, 0); + + //zmq_poll(&pollitem, 1, 0); //received something, get out - if(pollitem.revents & ZMQ_POLLIN){ - pollitem.revents = 0; - break; - } -*/ + //if(pollitem.revents & ZMQ_POLLIN){ + // pollitem.revents = 0; + // break; + //}uncomment next recv + //received nothing else if (receiverStoppedFlag){ //one more chance if receiver stopped @@ -5139,14 +5150,16 @@ void multiSlsDetector::startReceivingDataThread(){ usleep(4000); } - if(datavalue){ + */ + + /*if(datavalue){ //len = zmq_msg_recv(&message, zmqsocket, 0); if (len == -1) { zmq_msg_close(&message); cprintf(RED, "%d message null\n",ithread); continue; } - +*/ // error if you print it // cout << ithread << " header len:"<0 && (dataReady == NULL)){ @@ -151,18 +151,18 @@ int slsDetectorUtils::acquire(int delflag){ stopReceiver(); if(setReceiverOnline()==OFFLINE_FLAG){ *stoppedFlag=1; - receiverStoppedFlag = 1; + /*receiverStoppedFlag = 1;*/ } //multi detectors shouldnt have different receiver read frequencies enabled/disabled if(setReadReceiverFrequency(0) < 0){ std::cout << "Error: The receiver read frequency is invalid:" << setReadReceiverFrequency(0) << std::endl; *stoppedFlag=1; - receiverStoppedFlag = 1; + /*receiverStoppedFlag = 1;*/ } if(setReceiverOnline()==OFFLINE_FLAG){ *stoppedFlag=1; - receiverStoppedFlag = 1; + /*receiverStoppedFlag = 1;*/ } } @@ -296,7 +296,7 @@ int slsDetectorUtils::acquire(int delflag){ if(setReceiverOnline()==OFFLINE_FLAG){ stopReceiver(); *stoppedFlag=1; - receiverStoppedFlag = 1; + /*receiverStoppedFlag = 1;*/ pthread_mutex_unlock(&mg); break; } @@ -304,7 +304,7 @@ int slsDetectorUtils::acquire(int delflag){ if(startReceiver() == FAIL) { stopReceiver(); *stoppedFlag=1; - receiverStoppedFlag = 1; + /*receiverStoppedFlag = 1;*/ pthread_mutex_unlock(&mg); break; } @@ -351,7 +351,7 @@ int slsDetectorUtils::acquire(int delflag){ pthread_mutex_lock(&mg); //offline if(setReceiverOnline()==OFFLINE_FLAG){ - receiverStoppedFlag = 1; + /* receiverStoppedFlag = 1;*/ if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){ if((*correctionMask)&(1< Date: Tue, 18 Oct 2016 12:12:08 +0200 Subject: [PATCH 31/42] trying --- slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index f17d733b4..68a251b2a 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5628,7 +5628,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ } } - }else enable = threadStarted; + }/*else enable = threadStarted;*/ int ret=-100, ret1; for (int idet=0; idetnumberOfDetectors; idet++) { if (detectors[idet]) { @@ -5641,7 +5641,10 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ ret=-1; } } - + ///* + if(enable == -1) + return threadStarted; + // */ return (threadStarted & ret); } From de5037ae2ba858b0dcc9d20afec8f5cdc3d9f14e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 18 Oct 2016 12:19:20 +0200 Subject: [PATCH 32/42] switched --- .../multiSlsDetector/multiSlsDetector.cpp | 29 +++++++++++------ .../slsDetector/slsDetectorUtils.cpp | 32 ++++++++++++++----- .../slsDetector/slsDetectorUtils.h | 4 ++- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 68a251b2a..1478ffbaf 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5090,7 +5090,9 @@ void multiSlsDetector::startReceivingDataThread(){ int* image = new int[nel]; int len,idet = 0; singleframe[ithread]=NULL; -/* int datavalue = 2;*/ +///* + int datavalue = 2; + // */ threadStarted = true; //let calling function know thread started and obtained current @@ -5108,6 +5110,7 @@ void multiSlsDetector::startReceivingDataThread(){ //scan header------------------------------------------------------------------- zmq_msg_init (&message); + /* //---- with end len = zmq_msg_recv(&message, zmqsocket, 0); if (len == -1) { @@ -5116,8 +5119,10 @@ void multiSlsDetector::startReceivingDataThread(){ continue; } //---- + */ + + -/* while(1){ len = zmq_msg_recv(&message, zmqsocket, ZMQ_DONTWAIT); @@ -5150,16 +5155,16 @@ void multiSlsDetector::startReceivingDataThread(){ usleep(4000); } - */ - /*if(datavalue){ + + if(datavalue){ //len = zmq_msg_recv(&message, zmqsocket, 0); if (len == -1) { zmq_msg_close(&message); cprintf(RED, "%d message null\n",ithread); continue; } -*/ + // error if you print it // cout << ithread << " header len:"<0 && (dataReady == NULL)){ @@ -151,18 +153,24 @@ int slsDetectorUtils::acquire(int delflag){ stopReceiver(); if(setReceiverOnline()==OFFLINE_FLAG){ *stoppedFlag=1; - /*receiverStoppedFlag = 1;*/ + ///* + receiverStoppedFlag = 0; + //*/ } //multi detectors shouldnt have different receiver read frequencies enabled/disabled if(setReadReceiverFrequency(0) < 0){ std::cout << "Error: The receiver read frequency is invalid:" << setReadReceiverFrequency(0) << std::endl; *stoppedFlag=1; - /*receiverStoppedFlag = 1;*/ + ///* + receiverStoppedFlag = 0; + //*/ } if(setReceiverOnline()==OFFLINE_FLAG){ *stoppedFlag=1; - /*receiverStoppedFlag = 1;*/ + ///* + receiverStoppedFlag = 0; + //*/ } } @@ -296,7 +304,9 @@ int slsDetectorUtils::acquire(int delflag){ if(setReceiverOnline()==OFFLINE_FLAG){ stopReceiver(); *stoppedFlag=1; - /*receiverStoppedFlag = 1;*/ + ///* + receiverStoppedFlag = 0; + //*/ pthread_mutex_unlock(&mg); break; } @@ -304,7 +314,9 @@ int slsDetectorUtils::acquire(int delflag){ if(startReceiver() == FAIL) { stopReceiver(); *stoppedFlag=1; - /*receiverStoppedFlag = 1;*/ + ///* + receiverStoppedFlag = 0; + //*/ pthread_mutex_unlock(&mg); break; } @@ -351,7 +363,9 @@ int slsDetectorUtils::acquire(int delflag){ pthread_mutex_lock(&mg); //offline if(setReceiverOnline()==OFFLINE_FLAG){ - /* receiverStoppedFlag = 1;*/ + ///* + receiverStoppedFlag = 0; + //*/ if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){ if((*correctionMask)&(1< Date: Tue, 18 Oct 2016 12:33:47 +0200 Subject: [PATCH 33/42] switched --- .../multiSlsDetector/multiSlsDetector.cpp | 1 - .../slsDetector/slsDetectorUtils.cpp | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 1478ffbaf..c3a94f77c 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5212,7 +5212,6 @@ void multiSlsDetector::startReceivingDataThread(){ //end of socket ("end") if (len < 1024*256 ) { /* - } if(!len) cprintf(RED,"Received no data in socket for %d\n", ithread); //#ifdef VERYVERBOSE cprintf(RED,"End of socket for %d\n", ithread); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index e475351dc..9011c300a 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -154,7 +154,7 @@ int slsDetectorUtils::acquire(int delflag){ if(setReceiverOnline()==OFFLINE_FLAG){ *stoppedFlag=1; ///* - receiverStoppedFlag = 0; + receiverStoppedFlag = 1; //*/ } //multi detectors shouldnt have different receiver read frequencies enabled/disabled @@ -162,14 +162,14 @@ int slsDetectorUtils::acquire(int delflag){ std::cout << "Error: The receiver read frequency is invalid:" << setReadReceiverFrequency(0) << std::endl; *stoppedFlag=1; ///* - receiverStoppedFlag = 0; + receiverStoppedFlag = 1; //*/ } if(setReceiverOnline()==OFFLINE_FLAG){ *stoppedFlag=1; ///* - receiverStoppedFlag = 0; + receiverStoppedFlag = 1; //*/ } } @@ -305,7 +305,7 @@ int slsDetectorUtils::acquire(int delflag){ stopReceiver(); *stoppedFlag=1; ///* - receiverStoppedFlag = 0; + receiverStoppedFlag = 1; //*/ pthread_mutex_unlock(&mg); break; @@ -315,7 +315,7 @@ int slsDetectorUtils::acquire(int delflag){ stopReceiver(); *stoppedFlag=1; ///* - receiverStoppedFlag = 0; + receiverStoppedFlag = 1; //*/ pthread_mutex_unlock(&mg); break; @@ -364,7 +364,7 @@ int slsDetectorUtils::acquire(int delflag){ //offline if(setReceiverOnline()==OFFLINE_FLAG){ ///* - receiverStoppedFlag = 0; + receiverStoppedFlag = 1; //*/ if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){ if((*correctionMask)&(1< Date: Tue, 18 Oct 2016 14:05:05 +0200 Subject: [PATCH 34/42] back --- .../multiSlsDetector/multiSlsDetector.cpp | 185 ++++++------------ .../slsDetector/slsDetectorUtils.cpp | 30 +-- .../slsDetector/slsDetectorUtils.h | 4 - 3 files changed, 63 insertions(+), 156 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index c3a94f77c..5023cb175 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5071,13 +5071,12 @@ void multiSlsDetector::startReceivingDataThread(){ context = zmq_ctx_new(); zmqsocket = zmq_socket(context, ZMQ_PULL); //int hwmval = 10; - //zmq_setsockopt(zmqsocket,ZMQ_RCVHWM,&hwmval,sizeof(hwmval)); //set receive HIGH WATER MARK (8-9ms slower) + //zmq_setsockopt(zmqsocket,ZMQ_RCVHWM,&hwmval,sizeof(hwmval)); //set receive HIGH WATER MARK (8-9ms slower//should not drop last packets) zmq_connect(zmqsocket, hostname); cout << "ZMQ Client of " << ithread << " at " << hostname << endl; cprintf(BLUE,"%d Created socket\n",ithread); - /* - zmq_pollitem_t pollitem = {zmqsocket, 0 , ZMQ_POLLIN , 0}; -*/ + + //initializations int numReadoutPerDetector = 1; bool jungfrau = false; @@ -5090,9 +5089,6 @@ void multiSlsDetector::startReceivingDataThread(){ int* image = new int[nel]; int len,idet = 0; singleframe[ithread]=NULL; -///* - int datavalue = 2; - // */ threadStarted = true; //let calling function know thread started and obtained current @@ -5109,146 +5105,87 @@ void multiSlsDetector::startReceivingDataThread(){ //scan header------------------------------------------------------------------- zmq_msg_init (&message); - - /* - //---- with end len = zmq_msg_recv(&message, zmqsocket, 0); if (len == -1) { + cprintf(BG_RED,"Could not read header for socket %d\n",ithread); zmq_msg_close(&message); cprintf(RED, "%d message null\n",ithread); continue; } - //---- - */ - - while(1){ - - len = zmq_msg_recv(&message, zmqsocket, ZMQ_DONTWAIT); - if(len>0) - break;//also comment out the next recv - - //zmq_poll(&pollitem, 1, 0); - //received something, get out - //if(pollitem.revents & ZMQ_POLLIN){ - // pollitem.revents = 0; - // break; - //}uncomment next recv - - //received nothing - else if (receiverStoppedFlag){ - //one more chance if receiver stopped - datavalue--; - - if(!datavalue){ + // error if you print it + // cout << ithread << " header len:"<numberOfDetectors; idet++) { if (detectors[idet]) { @@ -5651,10 +5588,10 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ ret=-1; } } - ///* + /* if(enable == -1) return threadStarted; - // */ + */ return (threadStarted & ret); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 9011c300a..8bb16fe0e 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -58,9 +58,6 @@ int slsDetectorUtils::acquire(int delflag){ if(!receiver){ setDetectorIndex(-1); }else{ - ///* - receiverStoppedFlag = 0; - //*/ //put receiver read frequency to random if no gui int ret = setReadReceiverFrequency(0); if(ret>0 && (dataReady == NULL)){ @@ -151,27 +148,16 @@ int slsDetectorUtils::acquire(int delflag){ if(receiver){ if(getReceiverStatus()!=IDLE) stopReceiver(); - if(setReceiverOnline()==OFFLINE_FLAG){ + if(setReceiverOnline()==OFFLINE_FLAG) *stoppedFlag=1; - ///* - receiverStoppedFlag = 1; - //*/ - } //multi detectors shouldnt have different receiver read frequencies enabled/disabled if(setReadReceiverFrequency(0) < 0){ std::cout << "Error: The receiver read frequency is invalid:" << setReadReceiverFrequency(0) << std::endl; *stoppedFlag=1; - ///* - receiverStoppedFlag = 1; - //*/ } - if(setReceiverOnline()==OFFLINE_FLAG){ + if(setReceiverOnline()==OFFLINE_FLAG) *stoppedFlag=1; - ///* - receiverStoppedFlag = 1; - //*/ - } } @@ -304,9 +290,6 @@ int slsDetectorUtils::acquire(int delflag){ if(setReceiverOnline()==OFFLINE_FLAG){ stopReceiver(); *stoppedFlag=1; - ///* - receiverStoppedFlag = 1; - //*/ pthread_mutex_unlock(&mg); break; } @@ -314,9 +297,6 @@ int slsDetectorUtils::acquire(int delflag){ if(startReceiver() == FAIL) { stopReceiver(); *stoppedFlag=1; - ///* - receiverStoppedFlag = 1; - //*/ pthread_mutex_unlock(&mg); break; } @@ -363,9 +343,6 @@ int slsDetectorUtils::acquire(int delflag){ pthread_mutex_lock(&mg); //offline if(setReceiverOnline()==OFFLINE_FLAG){ - ///* - receiverStoppedFlag = 1; - //*/ if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){ if((*correctionMask)&(1< Date: Tue, 18 Oct 2016 14:36:04 +0200 Subject: [PATCH 35/42] giving --- slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 5023cb175..0b67c8d70 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -514,6 +514,8 @@ string multiSlsDetector::setHostname(const char* name, int pos){ cout << "-----------------------------set online!" << endl; #endif setOnline(ONLINE_FLAG); + if(detectors[pos]->getErrorMask()) + setErrorMask(getErrorMask()|(1< Date: Tue, 18 Oct 2016 14:44:13 +0200 Subject: [PATCH 36/42] bugfix:seg fault for giving an error in gui if cannot connect to hostname --- .../multiSlsDetector/multiSlsDetector.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 0b67c8d70..b27d36aeb 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -514,8 +514,17 @@ string multiSlsDetector::setHostname(const char* name, int pos){ cout << "-----------------------------set online!" << endl; #endif setOnline(ONLINE_FLAG); - if(detectors[pos]->getErrorMask()) + if(pos>=0){ + if(detectors[pos]->getErrorMask()) setErrorMask(getErrorMask()|(1<numberOfDetectors; ip++) { + if (detectors[ip]) { + if(detectors[ip]->getErrorMask()) + setErrorMask(getErrorMask()|(1< Date: Tue, 18 Oct 2016 14:47:52 +0200 Subject: [PATCH 37/42] check for giving an error in gui if cannot connect to hostname --- slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index b27d36aeb..4c08eaac9 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -518,10 +518,12 @@ string multiSlsDetector::setHostname(const char* name, int pos){ if(detectors[pos]->getErrorMask()) setErrorMask(getErrorMask()|(1<numberOfDetectors); for (int ip=0; ipnumberOfDetectors; ip++) { if (detectors[ip]) { if(detectors[ip]->getErrorMask()) setErrorMask(getErrorMask()|(1< Date: Tue, 18 Oct 2016 14:50:25 +0200 Subject: [PATCH 38/42] check for giving an error in gui if cannot connect to hostname --- slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 4c08eaac9..1ecd04930 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -521,9 +521,10 @@ string multiSlsDetector::setHostname(const char* name, int pos){ cprintf(BLUE,"Checking all the detectors %d\n",thisMultiDetector->numberOfDetectors); for (int ip=0; ipnumberOfDetectors; ip++) { if (detectors[ip]) { - if(detectors[ip]->getErrorMask()) + if(detectors[ip]->getErrorMask()){ setErrorMask(getErrorMask()|(1< Date: Tue, 18 Oct 2016 15:03:44 +0200 Subject: [PATCH 39/42] check for giving an error in gui if cannot connect to hostname --- .../multiSlsDetector/multiSlsDetector.cpp | 14 -------------- slsDetectorSoftware/slsDetector/slsDetector.cpp | 2 ++ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 1ecd04930..5023cb175 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -514,20 +514,6 @@ string multiSlsDetector::setHostname(const char* name, int pos){ cout << "-----------------------------set online!" << endl; #endif setOnline(ONLINE_FLAG); - if(pos>=0){ - if(detectors[pos]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors); - for (int ip=0; ipnumberOfDetectors; ip++) { - if (detectors[ip]) { - if(detectors[ip]->getErrorMask()){ - setErrorMask(getErrorMask()|(1<hostname); + thisDetector->onlineFlag=OFFLINE_FLAG; #ifdef VERBOSE std::cout<< "offline!" << std::endl; #endif @@ -1253,6 +1254,7 @@ string slsDetector::checkOnline() { thisDetector->onlineFlag=ONLINE_FLAG; controlSocket->SetTimeOut(100); disconnectControl(); + thisDetector->onlineFlag=ONLINE_FLAG; #ifdef VERBOSE std::cout<< "online!" << std::endl; #endif From 028ba5787617385de792fcefab0fc5e6640d5c7f Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 18 Oct 2016 15:06:01 +0200 Subject: [PATCH 40/42] check for giving an error in gui if cannot connect to hostname --- .../multiSlsDetector/multiSlsDetector.cpp | 4 +++- slsDetectorSoftware/slsDetector/slsDetector.cpp | 10 ++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 5023cb175..bd9a7d4b2 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1037,8 +1037,10 @@ int multiSlsDetector::setOnline(int off) { for (int i=0; inumberOfDetectors; i++) { if (detectors[i]){ detectors[i]->setOnline(off); - if(detectors[i]->getErrorMask()) + if(detectors[i]->getErrorMask()){ setErrorMask(getErrorMask()|(1<hostname); - thisDetector->onlineFlag=OFFLINE_FLAG; -#ifdef VERBOSE +//#ifdef VERBOSE std::cout<< "offline!" << std::endl; -#endif +//#endif } else { thisDetector->onlineFlag=ONLINE_FLAG; controlSocket->SetTimeOut(100); disconnectControl(); - thisDetector->onlineFlag=ONLINE_FLAG; -#ifdef VERBOSE +//#ifdef VERBOSE std::cout<< "online!" << std::endl; -#endif +//#endif } } return retval; From f535e11bba16d6b31aea0a8f36f6c3a0dc0191b0 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 18 Oct 2016 15:31:48 +0200 Subject: [PATCH 41/42] check not done --- slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp | 4 +--- slsDetectorSoftware/slsDetector/slsDetector.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index bd9a7d4b2..5023cb175 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1037,10 +1037,8 @@ int multiSlsDetector::setOnline(int off) { for (int i=0; inumberOfDetectors; i++) { if (detectors[i]){ detectors[i]->setOnline(off); - if(detectors[i]->getErrorMask()){ + if(detectors[i]->getErrorMask()) setErrorMask(getErrorMask()|(1<hostname); -//#ifdef VERBOSE +#ifdef VERBOSE std::cout<< "offline!" << std::endl; -//#endif +#endif } else { thisDetector->onlineFlag=ONLINE_FLAG; controlSocket->SetTimeOut(100); disconnectControl(); -//#ifdef VERBOSE +#ifdef VERBOSE std::cout<< "online!" << std::endl; -//#endif +#endif } } return retval; From e49f97a03c8680312056cd1a72d1f6d7191daed6 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 19 Oct 2016 08:10:42 +0200 Subject: [PATCH 42/42] done showing error when detectors not added in sharedmemory due to connect failure --- slsDetectorSoftware/commonFiles/error_defs.h | 30 +++++++++++++++++-- .../multiSlsDetector/multiSlsDetector.cpp | 13 ++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 55c84218a..1db390581 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -14,12 +14,17 @@ using namespace std; #include "sls_detector_defs.h" - +#include +#include /** Error flags */ +/*Assumption: Only upto 63 detectors */ #define CRITICAL_ERROR_MASK 0xFFFFFFFF +#define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL + + #define CANNOT_CONNECT_TO_DETECTOR 0x8000000000000000ULL #define CANNOT_CONNECT_TO_RECEIVER 0x4000000000000000ULL #define COULDNOT_SET_CONTROL_PORT 0x2000000000000000ULL @@ -73,7 +78,9 @@ class errorDefs { public: /** Constructor */ - errorDefs():errorMask(0){}; + errorDefs():errorMask(0){ + strcpy(notAddedList,""); + }; /** Gets the error message * param errorMask error mask @@ -234,12 +241,31 @@ public: */ int64_t clearErrorMask(){errorMask=0;return errorMask;}; + /** Gets the not added detector list + /returns list + */ + char* getNotAddedList(){return notAddedList;}; + + /** Append the detector to not added detector list + * @param name append to the list + /returns list + */ + void appendNotAddedList(const char* name){strcat(notAddedList,name);strcat(notAddedList,"+");}; + + /** Clears not added detector list + /returns error mask + */ + void clearNotAddedList(){strcpy(notAddedList,"");}; + protected: /** Error Mask */ int64_t errorMask; + /** Detectors Not added List */ + char notAddedList[MAX_STR_LENGTH]; + }; #endif /* ERROR_DEFS_H_ */ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 5023cb175..17a09f232 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -655,7 +655,6 @@ int multiSlsDetector::setDetectorId(int ival, int pos){ int multiSlsDetector::addSlsDetector(const char *name, int pos) { - detectorType t=getDetectorType(string(name)); int online=0; slsDetector *s=NULL; @@ -695,6 +694,8 @@ int multiSlsDetector::addSlsDetector(const char *name, int pos) { t=slsDetector::getDetectorType(name, DEFAULT_PORTNO); if (t==GENERIC) { cout << "Detector " << name << "does not exist in shared memory and could not connect to it to determine the type (which is not specified)!" << endl; + setErrorMask(getErrorMask()|MULTI_DETECTORS_NOT_ADDED); + appendNotAddedList(name); return -1; } #ifdef VERBOSE @@ -4367,8 +4368,12 @@ int multiSlsDetector::readConfigurationFile(string const fname){ setNumberOfModules(-1); getMaxNumberOfModules(); - if (getErrorMask()) + if (getErrorMask()){ + int c; + cprintf(RED,"\n----------------\n Error Messages\n----------------\n%s\n", + getErrorMessage(c).c_str()); return FAIL; + } return OK; @@ -5472,6 +5477,9 @@ string multiSlsDetector::getErrorMessage(int &critical){ multiMask = getErrorMask(); if(multiMask){ + if(multiMask & MULTI_DETECTORS_NOT_ADDED) + retval.append("Detectors not added:\n"+string(getNotAddedList())+string("\n")); + for (int idet=0; idetnumberOfDetectors; idet++) { if (detectors[idet]) { //if the detector has error @@ -5502,6 +5510,7 @@ string multiSlsDetector::getErrorMessage(int &critical){ int64_t multiSlsDetector::clearAllErrorMask(){ clearErrorMask(); + clearNotAddedList(); for (int idet=0; idetnumberOfDetectors; idet++) if (detectors[idet]) detectors[idet]->clearErrorMask();