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