From 5f82381b1e5677d2e41bee21fefbdbc31e954e3b Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Wed, 18 Jun 2014 16:35:34 +0200 Subject: [PATCH] eiger gui works and can read frames, other gui functionalities not implemented --- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 130 ++++- .../slsReceiver/slsReceiverTCPIPInterface.h | 3 + .../slsReceiver/slsReceiverUDPFunctions.cpp | 489 +++++++++++------- .../slsReceiver/slsReceiverUDPFunctions.h | 33 +- 4 files changed, 449 insertions(+), 206 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index c5fa0eab3..19f74baa8 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -1012,6 +1012,8 @@ int slsReceiverTCPIPInterface::read_frame(){ switch(myDetectorType){ case MOENCH: return moench_read_frame(); + case EIGER: + return eiger_read_frame(); default: return gotthard_read_frame(); } @@ -1036,7 +1038,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ char* raw = new char[bufferSize]; uint32_t startIndex=0; - int index = 0,bindex = 0, offset=0; + uint32_t index = 0,bindex = 0, offset=0; strcpy(mess,"Could not read frame\n"); @@ -1053,7 +1055,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ else{ ret = OK; startIndex=slsReceiverFunctions->getStartFrameIndex(); - slsReceiverFunctions->readFrame(fName,&raw); + slsReceiverFunctions->readFrame(fName,&raw,index); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1223,7 +1225,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ }else{ ret = OK; startIndex=slsReceiverFunctions->getStartFrameIndex(); - slsReceiverFunctions->readFrame(fName,&raw); + slsReceiverFunctions->readFrame(fName,&raw,index); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1334,6 +1336,128 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ + + + + + +int slsReceiverTCPIPInterface::eiger_read_frame(){ + ret=OK; + char fName[MAX_STR_LENGTH]=""; + int arg = -1,i; + uint32_t index=0; + + int bufferSize = EIGER_BUFFER_SIZE; + int onebuffersize = EIGER_BUFFER_SIZE/EIGER_PACKETS_PER_FRAME; + int onedatasize = EIGER_DATA_BYTES/EIGER_PACKETS_PER_FRAME; + int numpackets = EIGER_PACKETS_PER_FRAME; + + char* raw = new char[bufferSize]; + char* origVal = new char[bufferSize]; + char* retval = new char[EIGER_DATA_BYTES]; + + /* + //retval is a full frame + int rnel = bufferSize/(sizeof(int)); + int* retval = new int[rnel]; + int* origVal = new int[rnel]; + //all initialized to 0 + for(i=0;igetFramesCaught()){ + arg=-1; + cout<<"haven't caught any frame yet"<readFrame(fName,&raw, index); +#ifdef VERBOSE + cout << "index:" << dec << index << endl; +#endif + /**send garbage with -1 index to try again*/ + if (raw == NULL){ + arg = -1; +#ifdef VERBOSE + cout<<"data not ready for gui yet"<num2)&0xff)<<"\t\t"; + memcpy(retval+retindex ,origVal+copyindex ,onedatasize); + copyindex += 16+onedatasize; + retindex += onedatasize; + } + arg = index-1; + } + } + +#ifdef VERBOSE + if(arg!=-1){ + cout << "fName:" << fName << endl; + cout << "findex:" << arg << endl; + } +#endif + + + +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL){ + cout << "mess:" << mess << endl; + socket->SendDataOnly(mess,sizeof(mess)); + } + else{ + socket->SendDataOnly(fName,MAX_STR_LENGTH); + socket->SendDataOnly(&arg,sizeof(arg)); + socket->SendDataOnly(retval,EIGER_DATA_BYTES); + } + + delete [] retval; + delete [] origVal; + delete [] raw; + + return ret; +} + + int slsReceiverTCPIPInterface::set_read_frequency(){ ret=OK; int retval=-1; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index cc0d48752..94126d59f 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -162,6 +162,9 @@ private: /** moench specific read frame */ int moench_read_frame(); + /** eiger specific read frame */ + int eiger_read_frame(); + /** Sets the receiver to send every nth frame to gui, or only upon gui request */ int set_read_frequency(); diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index 18ba264a0..470a41efb 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -1,4 +1,4 @@ -/*#ifdef SLS_RECEIVER_UDP_FUNCTIONS*/ +#ifdef SLS_RECEIVER_UDP_FUNCTIONS /********************************************//** * @file slsReceiverUDPFunctions.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -34,7 +34,8 @@ slsReceiverUDPFunctions::slsReceiverUDPFunctions(): thread_started(0), eth(NULL), latestData(NULL), - guiFileName(NULL){ + guiFileName(NULL), + guiFrameNumber(0){ for(int i=0;inum2)&0xff)<<"\t\t"; + } + guiFrameNumber = fnum; + }else//other detectors + memcpy(latestData,buf,bufferSize); + + strcpy(guiFileName,savefilename); guiDataReady=1; pthread_mutex_unlock(&dataReadyMutex); @@ -1071,6 +1084,7 @@ int slsReceiverUDPFunctions::setupWriter(){ guiData = NULL; guiDataReady=0; strcpy(guiFileName,""); + guiFrameNumber = 0; cbAction = DO_EVERYTHING; pthread_mutex_lock(&status_mutex); @@ -1402,6 +1416,8 @@ void slsReceiverUDPFunctions::startReadout(){ //wait so that all packets which take time has arrived usleep(50000); + /********************************************/ + usleep(1000000); pthread_mutex_lock(&status_mutex); status = TRANSMITTING; pthread_mutex_unlock(&status_mutex); @@ -1528,7 +1544,7 @@ int slsReceiverUDPFunctions::startListening(){ //start indices for each start of scan/acquisition - eiger does it before - if((!measurementStarted) && (rc > 0)) + if((!measurementStarted) && (rc > 0) && (!ithread)) startFrameIndices(ithread); //problem in receiving or end of acquisition @@ -1620,11 +1636,11 @@ int slsReceiverUDPFunctions::startListening(){ (*((uint16_t*)(buffer[ithread]))) = packetcount; totalListeningFrameCount[ithread] += packetcount; #ifdef VERYDEBUG - if(!ithread) cout << "totalListeningFrameCount[" << ithread << "]:" << totalListeningFrameCount[ithread] << endl; + cout<push(buffer[ithread])); #ifdef VERYDEBUG - cout << "*** pushed into listening fifo" << endl; + if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; #endif } @@ -1652,8 +1668,6 @@ int slsReceiverUDPFunctions::startListening(){ - - int slsReceiverUDPFunctions::startWriting(){ int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE @@ -1664,16 +1678,17 @@ int slsReceiverUDPFunctions::startWriting(){ int numpackets, nf; uint32_t tempframenum; - char* wbuf[MAX_NUM_LISTENING_THREADS]; - char *data=new char[bufferSize]; - int iFrame = 0; + char* wbuf[packetsPerFrame+numListeningThreads];//interleaved + 2 ports header + char *d=new char[bufferSize]; int xmax=0,ymax=0; - int ret,i; + int ret,i,j; + int w_index=0; + int packetsPerThread = packetsPerFrame/numListeningThreads; while(1){ nf = 0; - iFrame = 0; + w_index = 0; if(myDetectorType == MOENCH){ xmax = MOENCH_PIXELS_IN_ONE_ROW-1; ymax = MOENCH_PIXELS_IN_ONE_ROW-1; @@ -1688,92 +1703,48 @@ int slsReceiverUDPFunctions::startWriting(){ } + + while((1<pop(wbuf[i]); - numpackets = (uint16_t)(*((uint16_t*)wbuf[0])); + for(i=0;ipop(wbuf[w_index+i]); + numpackets = (uint16_t)(*((uint16_t*)wbuf[w_index])); #ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; - cout << ithread << " *** popped from fifo " << numpackets << endl; + if((!w_index)||(!numpackets)) cout << ithread << " numpackets:" << dec << numpackets << endl; #endif + } - +#ifdef VERYDEBUG + cout << ithread << " numpackets:" << dec << numpackets << endl; + cout << ithread << " *** writer popped from fifo " << (void*) wbuf[w_index]<< endl; + cout << ithread << " *** writer popped from fifo " << (void*) wbuf[w_index+1]<< endl; +#endif //last dummy packet if(numpackets == 0xFFFF){ -#ifdef VERYDEBUG - cout << ithread << " **********************popped last dummy frame:" << (void*)wbuf[0] << endl; -#endif - - //free fifo - for(i=0;ipush(wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << " fifo freed:" << (void*)wbuf[i] << endl; -#endif - - - - //all threads need to close file, reset mask and exit loop - closeFile(ithread); - pthread_mutex_lock(&status_mutex); - writerthreads_mask^=(1<fnum); + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); if(numWriterThreads == 1) currframenum = tempframenum; @@ -1784,136 +1755,58 @@ int slsReceiverUDPFunctions::startWriting(){ pthread_mutex_unlock(&progress_mutex); } #ifdef VERYDEBUG - cout << endl <num2)&0xff)<<"\t\t"< 0){ - for(i=0;i 0){ - cout<<"numpackets:"<push(wbuf[i])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf[0]<findNextFrame(data,ndata,remainingsize)){ - np = ndata/onePacketSize; - - //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); - - //only for moench - if(commonModeSubtractionEnable){ - for(ix = xmin - 1; ix < xmax+1; ix++){ - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); - } - } - } - - - for(ix = xmin - 1; ix < xmax+1; ix++) - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); - if (nf>1000) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; - if (thisEvent==PHOTON_MAX) { - - iFrame=receiverdata[ithread]->getFrameNumber(buff); -#ifdef MYROOT1 - myTree[ithread]->Fill(); - //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; -#else - pthread_mutex_lock(&write_mutex); - if((enableFileWrite) && (sfilefd)) - singlePhotonDet[ithread]->writeCluster(sfilefd); - pthread_mutex_unlock(&write_mutex); -#endif - } - } - } - - nf++; -#ifndef ALLFILE - pthread_mutex_lock(&progress_mutex); - packetsInFile += packetsPerFrame; - packetsCaught += packetsPerFrame; - totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= maxPacketsPerFile) - createNewFile(); - pthread_mutex_unlock(&progress_mutex); - -#endif - if(!once){ - copyFrameToGui(buff); - once = 1; - } - } - - remainingsize -= ((buff + ndata) - data); - data = buff + ndata; - if(data > (wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS + numpackets * onePacketSize) ) - cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"< 0){ + for(i=0;ipush(wbuf[0])); + + if(myDetectorType == EIGER) { + //last packet + if((packetsPerThread-1)==(htonl(*(uint32_t*)((eiger_packet_header *)((uint32_t*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS)))->num2)&0xff)){ + copyFrameToGui(wbuf,currframenum); + for(j=0;jpush(wbuf[j+i])); + } + } + w_index = 0; + }else + w_index+=numListeningThreads; + } + else{ + //copy to gui + copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYVERBOSE + cout << ithread << " finished copying" << endl; +#endif + while(!fifoFree[0]->push(wbuf[0])); #ifdef VERYVERBOSE cout<<"buf freed:"<<(void*)wbuf[0]< 0){ pc = (rc/onePacketSize); #ifdef VERYDEBUG - cout << ithread << " *** last packetcount:" << packetcount << endl; + cout << ithread << " *** last packetcount:" << pc << endl; #endif (*((uint16_t*)(buffer[ithread]))) = pc; totalListeningFrameCount[ithread] += pc; @@ -2031,6 +1924,9 @@ int i; for(i=0;ipop(buffer[ithread]); (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; +#ifdef VERYDEBUG + cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; +#endif while(!fifo[ithread]->push(buffer[ithread])); #ifdef VERYDEBUG cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; @@ -2046,7 +1942,7 @@ int i; pthread_mutex_unlock(&(status_mutex)); #ifdef VERYDEBUG - cout << ithread << ": Frames listened to " << ((totalListeningFrameCount[ithread]/packetsPerFrame)/numListeningThreads) << endl; + cout << ithread << ": Frames listened to " << dec << ((totalListeningFrameCount[ithread]*numListeningThreads)/packetsPerFrame) << endl; #endif //waiting for all listening threads to be done, to print final count of frames listened to @@ -2061,7 +1957,7 @@ int i; t = 0; for(i=0;ipush(wbuffer[wIndex+j])); +#ifdef VERYDEBUG + cout << ithread << " fifo freed:" << (void*)wbuffer[wIndex+j] << endl; +#endif + } + + + //all threads need to close file, reset mask and exit loop + closeFile(ithread); + pthread_mutex_lock(&status_mutex); + writerthreads_mask^=(1< 1) pthread_mutex_unlock(&write_mutex); } +} + + + + + + + + + + + +void slsReceiverUDPFunctions::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ + +#if defined(MYROOT1) && defined(ALLFILE_DEBUG) + writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); +#endif + + eventType thisEvent = PEDESTAL; + int ndata; + char* buff = 0; + data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; + int remainingsize = npackets * onePacketSize; + int np; + int once = 0; + double tot, tl, tr, bl, br; + int xmin = 1, ymin = 1, ix, iy; + + + while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ + np = ndata/onePacketSize; + + //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); + + //only for moench + if(commonModeSubtractionEnable){ + for(ix = xmin - 1; ix < xmax+1; ix++){ + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); + } + } + } + + + for(ix = xmin - 1; ix < xmax+1; ix++) + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); + if (nf>1000) { + tot=0; + tl=0; + tr=0; + bl=0; + br=0; + if (thisEvent==PHOTON_MAX) { + receiverdata[ithread]->getFrameNumber(buff); + //iFrame=receiverdata[ithread]->getFrameNumber(buff); +#ifdef MYROOT1 + myTree[ithread]->Fill(); + //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; +#else + pthread_mutex_lock(&write_mutex); + if((enableFileWrite) && (sfilefd)) + singlePhotonDet[ithread]->writeCluster(sfilefd); + pthread_mutex_unlock(&write_mutex); +#endif + } + } + } + + nf++; +#ifndef ALLFILE + pthread_mutex_lock(&progress_mutex); + packetsInFile += packetsPerFrame; + packetsCaught += packetsPerFrame; + totalPacketsCaught += packetsPerFrame; + if(packetsInFile >= maxPacketsPerFile) + createNewFile(); + pthread_mutex_unlock(&progress_mutex); + +#endif + if(!once){ + copyFrameToGui(NULL,-1,buff); + once = 1; + } + } + + remainingsize -= ((buff + ndata) - data); + data = buff + ndata; + if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) + cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuffer[0]<