diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 82dc3cf0f..671a037f6 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -17,14 +17,13 @@ ID: $Id$ #include "postProcessingFuncs.h" #include "usersFunctions.h" #include "ThreadPool.h" +#include "ZmqSocket.h" #include #include #include #include #include -#include -#include //to scan json header in zmq stream using namespace std; @@ -272,11 +271,8 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) getNMods(); getMaxMods(); dataSocketsStarted = false; - for(int i=0;igetReceiver()); - cout<<"rx_hostname:"<h_addr)); + uint32_t portnum = DEFAULT_ZMQ_PORTNO + + (i/numSocketsPerDetector)*numSocketsPerDetector + (i%numSocketsPerDetector); + zmqSocket[i] = new ZmqSocket(detectors[i/numSocketsPerDetector]->getReceiver(), portnum); + if (zmqSocket[i]->IsError()) { + cprintf(RED, "Error: Could not create Zmq socket on port %d\n", portnum); + createReceivingDataSockets(true); + return FAIL; } - //add port - sprintf(dataSocketServerDetails[i],"%s:%d",dataSocketServerDetails[i],DEFAULT_ZMQ_PORTNO + - (i/numSocketsPerDetector)*numSocketsPerDetector + (i%numSocketsPerDetector));//using this instead of i in the offchance, detid doesnt start at 0 (shmget error) - - //create context - context[i] = zmq_ctx_new(); - //create socket - zmqsocket[i] = zmq_socket(context[i], ZMQ_PULL); - //connect socket - zmq_connect(zmqsocket[i], dataSocketServerDetails[i]); - //int hwmval = 10; - //zmq_setsockopt(zmqsocket[i],ZMQ_RCVHWM,&hwmval,sizeof(hwmval)); //set receive HIGH WATER MARK (8-9ms slower//should not drop last packets) - cout << "ZMQ Client[" << i << "] from " << dataSocketServerDetails[i] << endl; + printf("Zmq Client[%d] at %s\n",i, zmqSocket[i]->GetZmqServerAddress()); } dataSocketsStarted = true; @@ -5198,91 +5173,23 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy){ -int multiSlsDetector::getData(const int isocket, const bool masking, int* image, const int size, int &acqIndex, int &frameIndex, int &subframeIndex, string &filename){ +int multiSlsDetector::getData(const int isocket, const bool masking, int* image, const int size, + uint64_t &acqIndex, uint64_t &frameIndex, uint64_t &subframeIndex, string &filename){ - zmq_msg_t message; - - //scan header------------------------------------------------------------------- - zmq_msg_init (&message); - int len = zmq_msg_recv(&message, zmqsocket[isocket], 0); - if (len == -1) { - cprintf(BG_RED,"Could not read header for socket %d\n",isocket); - zmq_msg_close(&message); - cprintf(RED, "%d message null\n",isocket); + if (!zmqSocket[isocket]->ReceiveHeader(isocket, acqIndex, frameIndex, subframeIndex, filename)) return FAIL; - } - - // error if you print it - // cout << isocket << " header len:"<ReceiveData(isocket, image, size)) return FAIL; - } - //crappy image - if (len < size ) { - cprintf(RED,"Received weird packet size %d in socket for %d\n", len, isocket); - memset((char*)image,0xFF,size); - } - //actual image - else{ - //actual data - //cprintf(BLUE,"%d actual dataaa\n",isocket); - memcpy((char*)image,(char*)zmq_msg_data(&message),size); - - //jungfrau masking adcval - if(masking){ - int snel = size/sizeof(int); - for(unsigned int i=0;i