Merge branch 'master' of gitorious.psi.ch:sls_det_software/sls_receiver_software

This commit is contained in:
sala 2015-03-24 09:49:41 +01:00
commit 248848c666
8 changed files with 232 additions and 121 deletions

View File

@ -67,6 +67,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
//Frame indices and numbers caught //Frame indices and numbers caught
/**
* Returns the frame index at start of entire acquisition (including all scans)
*/
uint32_t getStartAcquisitionIndex();
/** /**
* Returns current Frame Index Caught for an entire acquisition (including all scans) * Returns current Frame Index Caught for an entire acquisition (including all scans)
*/ */
@ -288,9 +293,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
* @param c pointer to current file name * @param c pointer to current file name
* @param raw address of pointer, pointing to current frame to send to gui * @param raw address of pointer, pointing to current frame to send to gui
* @param fnum frame number for eiger as it is not in the packet * @param fnum frame number for eiger as it is not in the packet
* @param fstartind is the start index of the acquisition * @param startAcquisitionIndex is the start index of the acquisition
* @param startFrameIndex is the start index of the scan
*/ */
void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind); void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex);
/** /**
* Closes all files * Closes all files
* @param ithr thread index * @param ithr thread index
@ -479,6 +486,13 @@ protected:
unsigned char fnum[4]; unsigned char fnum[4];
unsigned char header_after[24]; unsigned char header_after[24];
} eiger_image_header; } eiger_image_header;
/** structure of an eiger image header*/
typedef struct
{
unsigned char header_before[35];
unsigned char fnum[4];
unsigned char header_after[9];
} eiger_image_header32;
/** structure of an eiger image header*/ /** structure of an eiger image header*/

View File

@ -240,6 +240,11 @@ class UDPInterface {
*/ */
virtual int getFramesCaught() = 0; virtual int getFramesCaught() = 0;
/**
* Returns the frame index at start of entire acquisition (including all scans)
*/
virtual uint32_t getStartAcquisitionIndex()=0;
/** /**
* Returns current Frame Index Caught for an entire acquisition (including all scans) * Returns current Frame Index Caught for an entire acquisition (including all scans)
*/ */
@ -328,9 +333,10 @@ class UDPInterface {
* @param c pointer to current file name * @param c pointer to current file name
* @param raw address of pointer, pointing to current frame to send to gui * @param raw address of pointer, pointing to current frame to send to gui
* @param fnum frame number for eiger as it is not in the packet * @param fnum frame number for eiger as it is not in the packet
* @param fstartind is the start index of the acquisition * @param startAcquisitionIndex is the start index of the acquisition
* @param startFrameIndex is the start index of the scan
*/ */
virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind ) = 0; virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex)=0;
/** set status to transmitting and /** set status to transmitting and
* when fifo is empty later, sets status to run_finished * when fifo is empty later, sets status to run_finished

View File

@ -89,6 +89,11 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI
//Frame indices and numbers caught //Frame indices and numbers caught
/**
* Returns the frame index at start of entire acquisition (including all scans)
*/
uint32_t getStartAcquisitionIndex();
/** /**
* Returns current Frame Index Caught for an entire acquisition (including all scans) * Returns current Frame Index Caught for an entire acquisition (including all scans)
*/ */
@ -300,8 +305,10 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI
* @param c pointer to current file name * @param c pointer to current file name
* @param raw address of pointer, pointing to current frame to send to gui * @param raw address of pointer, pointing to current frame to send to gui
* @param fnum frame number for eiger as it is not in the packet * @param fnum frame number for eiger as it is not in the packet
* @param startAcquisitionIndex is the start index of the acquisition
* @param startFrameIndex is the start index of the scan
*/ */
void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind); void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex);
/** /**
* Closes all files * Closes all files

View File

@ -68,6 +68,11 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
//Frame indices and numbers caught //Frame indices and numbers caught
/**
* Returns the frame index at start of entire acquisition (including all scans)
*/
//uint32_t getStartAcquisitionIndex();
/** /**
* Returns current Frame Index Caught for an entire acquisition (including all scans) * Returns current Frame Index Caught for an entire acquisition (including all scans)
*/ */
@ -290,8 +295,11 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
* @param c pointer to current file name * @param c pointer to current file name
* @param raw address of pointer, pointing to current frame to send to gui * @param raw address of pointer, pointing to current frame to send to gui
* @param fnum frame number for eiger as it is not in the packet * @param fnum frame number for eiger as it is not in the packet
* @param startAcquisitionIndex is the start index of the acquisition
* @param startFrameIndex is the start index of the scan
*/ */
void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind); void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex);
/** /**
* Closes all files * Closes all files
* @param ithr thread index * @param ithr thread index

View File

@ -155,6 +155,8 @@ int UDPBaseImplementation::getFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << "
int UDPBaseImplementation::getTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (totalPacketsCaught/packetsPerFrame);} int UDPBaseImplementation::getTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (totalPacketsCaught/packetsPerFrame);}
uint32_t UDPBaseImplementation::getStartAcquisitionIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startAcquisitionIndex;}
uint32_t UDPBaseImplementation::getStartFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startFrameIndex;} uint32_t UDPBaseImplementation::getStartFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startFrameIndex;}
uint32_t UDPBaseImplementation::getFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; uint32_t UDPBaseImplementation::getFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";
@ -642,17 +644,19 @@ void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ <
/** acquisition functions */ /** acquisition functions */
void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t& fstartind){ void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){
FILE_LOG(logDEBUG) << __AT__ << " starting"; FILE_LOG(logDEBUG) << __AT__ << " called";
//point to gui data //point to gui data
if (guiData == NULL) if (guiData == NULL){
guiData = latestData; guiData = latestData;
}
//copy data and filename //copy data and filename
strcpy(c,guiFileName); strcpy(c,guiFileName);
fnum = guiFrameNumber; fnum = guiFrameNumber;
fstartind = getStartFrameIndex(); startAcquisitionIndex = getStartAcquisitionIndex();
startFrameIndex = getStartFrameIndex();
//could not get gui data //could not get gui data
if(!guiDataReady){ if(!guiDataReady){
@ -662,12 +666,7 @@ void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32
else{ else{
*raw = guiData; *raw = guiData;
guiData = NULL; guiData = NULL;
pthread_mutex_lock(&dataReadyMutex);
guiDataReady = 0;
pthread_mutex_unlock(&dataReadyMutex);
if((nFrameToGui) && (writerthreads_mask)){ if((nFrameToGui) && (writerthreads_mask)){
/*if(nFrameToGui){*/
//release after getting data //release after getting data
sem_post(&smp); sem_post(&smp);
} }
@ -688,7 +687,7 @@ void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char
pthread_mutex_unlock(&dataReadyMutex); pthread_mutex_unlock(&dataReadyMutex);
} }
//random read or nth frame read, gui needs data now //random read or nth frame read, gui needs data now or it is the first frame
else{ else{
/* /*
//nth frame read, block current process if the guireader hasnt read it yet //nth frame read, block current process if the guireader hasnt read it yet

View File

@ -200,6 +200,11 @@ int UDPRESTImplementation::getTotalFramesCaught(){
return (totalPacketsCaught/packetsPerFrame); return (totalPacketsCaught/packetsPerFrame);
} }
uint32_t UDPRESTImplementation::getStartAcquisitionIndex(){
FILE_LOG(logDEBUG) << __AT__ << " called";
return startAcquisitionIndex;
}
uint32_t UDPRESTImplementation::getStartFrameIndex(){ uint32_t UDPRESTImplementation::getStartFrameIndex(){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
return startFrameIndex; return startFrameIndex;
@ -590,16 +595,19 @@ void UDPRESTImplementation::setupFifoStructure(){
/** acquisition functions */ /** acquisition functions */
void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){ void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
//point to gui data //point to gui data
if (guiData == NULL) if (guiData == NULL){
guiData = latestData; guiData = latestData;
}
//copy data and filename //copy data and filename
strcpy(c,guiFileName); strcpy(c,guiFileName);
fnum = guiFrameNumber; fnum = guiFrameNumber;
fstartind = getStartFrameIndex(); startAcquisitionIndex = getStartAcquisitionIndex();
startFrameIndex = getStartFrameIndex();
//could not get gui data //could not get gui data
if(!guiDataReady){ if(!guiDataReady){
@ -609,12 +617,7 @@ void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32
else{ else{
*raw = guiData; *raw = guiData;
guiData = NULL; guiData = NULL;
pthread_mutex_lock(&dataReadyMutex);
guiDataReady = 0;
pthread_mutex_unlock(&dataReadyMutex);
if((nFrameToGui) && (writerthreads_mask)){ if((nFrameToGui) && (writerthreads_mask)){
/*if(nFrameToGui){*/
//release after getting data //release after getting data
sem_post(&smp); sem_post(&smp);
} }

View File

@ -352,6 +352,8 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD
//int UDPStandardImplementation::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);} //int UDPStandardImplementation::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);}
//uint32_t UDPStandardImplementation::getStartAcquisitionIndex(){return startAcquisitionIndex;}
//uint32_t UDPStandardImplementation::getStartFrameIndex(){return startFrameIndex;} //uint32_t UDPStandardImplementation::getStartFrameIndex(){return startFrameIndex;}
/* /*
@ -868,32 +870,34 @@ void UDPStandardImplementation::setupFifoStructure(){
/** acquisition functions */ /** acquisition functions */
void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
//point to gui data //point to gui data
if (guiData == NULL){ if (guiData == NULL){
guiData = latestData; guiData = latestData;
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout <<"gui data not null anymore" << endl; cout << "gui data not null anymore" << endl;
#endif #endif
} }
//copy data and filename //copy data and filename
strcpy(c,guiFileName); strcpy(c,guiFileName);
fnum = guiFrameNumber; fnum = guiFrameNumber;
fstartind = getStartFrameIndex(); startAcquisitionIndex = getStartAcquisitionIndex();
startFrameIndex = getStartFrameIndex();
//could not get gui data //could not get gui data
if(!guiDataReady){ if(!guiDataReady){
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout<<"gui data not ready"<<endl; cout << "gui data not ready" << endl;
#endif #endif
*raw = NULL; *raw = NULL;
} }
//data ready, set guidata to receive new data //data ready, set guidata to receive new data
else{ else{
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout<<"gui data ready"<<endl; cout << "gui data ready" << endl;
#endif #endif
*raw = guiData; *raw = guiData;
guiData = NULL; guiData = NULL;
@ -903,14 +907,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui
pthread_mutex_unlock(&dataReadyMutex);*/ pthread_mutex_unlock(&dataReadyMutex);*/
if((nFrameToGui) && (writerthreads_mask)){ if((nFrameToGui) && (writerthreads_mask)){
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout<<"gonna post"<<endl; cout << "gonna post" << endl;
#endif #endif
/*if(nFrameToGui){*/ /*if(nFrameToGui){*/
//release after getting data //release after getting data
sem_post(&smp); sem_post(&smp);
} }
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout<<"done post"<<endl; cout << "done post" << endl;
#endif #endif
} }
} }
@ -921,25 +925,31 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui
void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){
FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " called";
#ifdef VERY_VERY_DEBUG
cout << "copyframe" << endl;
#endif
//random read when gui not ready , also command line doesnt have nthframetogui //random read when gui not ready , also command line doesnt have nthframetogui
//else guidata always null as guidataready is always 1 after 1st frame, and seccond data never gets copied
if((!nFrameToGui) && (!guiData)){ if((!nFrameToGui) && (!guiData)){
#ifdef VERY_VERY_DEBUG
cout << "doing nothing" << endl;
#endif
pthread_mutex_lock(&dataReadyMutex); pthread_mutex_lock(&dataReadyMutex);
guiDataReady=0; guiDataReady=0;
pthread_mutex_unlock(&dataReadyMutex); pthread_mutex_unlock(&dataReadyMutex);
} }
//random read or nth frame read, gui needs data now //random read or nth frame read, gui needs data now or it is the first frame
else{ else{
//cout <<"gui needs data now"<<endl; #ifdef VERY_VERY_DEBUG
/* cout << "gui needs data now or 1st frame" << endl;
//nth frame read, block current process if the guireader hasnt read it yet #endif
if(nFrameToGui)
sem_wait(&smp);
*/
pthread_mutex_lock(&dataReadyMutex); pthread_mutex_lock(&dataReadyMutex);
guiDataReady=0; guiDataReady=0;
#ifdef VERY_VERY_DEBUG
cout << "guidataready is 0, copying data" << endl;
#endif
//eiger //eiger
if(startbuf != NULL){ if(startbuf != NULL){
int offset = 0; int offset = 0;
@ -954,8 +964,7 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum,
for(int i=1000;i<1010;i=i+2) for(int i=1000;i<1010;i=i+2)
//cout<<"startbuf:"<<dec<<i<<hex<<":\t0x"<<htonl((uint32_t)(*((uint32_t*)(startbuf[1] + HEADER_SIZE_NUM_TOT_PACKETS+ EIGER_HEADER_LENGTH+8+ i))))<<endl; //cout<<"startbuf:"<<dec<<i<<hex<<":\t0x"<<htonl((uint32_t)(*((uint32_t*)(startbuf[1] + HEADER_SIZE_NUM_TOT_PACKETS+ EIGER_HEADER_LENGTH+8+ i))))<<endl;
cout<<"startbuf:"<<dec<<i<<hex<<":\t0x"<<((uint16_t)(*((uint16_t*)(startbuf[1] + 2+ 48+ j*1040+8+ i))))<<endl; cout<<"startbuf:"<<dec<<i<<hex<<":\t0x"<<((uint16_t)(*((uint16_t*)(startbuf[1] + 2+ 48+ j*1040+8+ i))))<<endl;
*/ */
guiFrameNumber = fnum; guiFrameNumber = fnum;
}else//other detectors }else//other detectors
@ -965,12 +974,18 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum,
strcpy(guiFileName,savefilename); strcpy(guiFileName,savefilename);
guiDataReady=1; guiDataReady=1;
pthread_mutex_unlock(&dataReadyMutex); pthread_mutex_unlock(&dataReadyMutex);
#ifdef VERY_VERY_DEBUG
cout << "guidataready = 1" << endl;
#endif
//nth frame read, block current process if the guireader hasnt read it yet //nth frame read, block current process if the guireader hasnt read it yet
if(nFrameToGui){ if(nFrameToGui){
//cout<<"waiting after copying"<<endl; #ifdef VERY_VERY_DEBUG
cout<<"waiting after copying"<<endl;
#endif
sem_wait(&smp); sem_wait(&smp);
//cout<<"done waiting"<<endl; #ifdef VERY_VERY_DEBUG
cout<<"done waiting"<<endl;
#endif
} }
} }
@ -1693,9 +1708,9 @@ int UDPStandardImplementation::startListening(){
expected = maxBufferSize - carryonBufferSize; expected = maxBufferSize - carryonBufferSize;
} }
//#ifdef VERDEBUG #ifdef EIGER_DEBUG
cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl;
//#endif #endif
/* /*
//start indices for each start of scan/acquisition - eiger does it before //start indices for each start of scan/acquisition - eiger does it before
@ -1871,7 +1886,8 @@ int UDPStandardImplementation::startWriting(){
} }
} }
//so that the first frame is always copied
guiData = latestData;
while((1<<ithread)&writerthreads_mask){ while((1<<ithread)&writerthreads_mask){
@ -1896,15 +1912,15 @@ int UDPStandardImplementation::startWriting(){
//last dummy packet //last dummy packet
if(numpackets == 0xFFFF){ if(numpackets == 0xFFFF){
//#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << "**LAST dummy packet" << endl; cout << "**LAST dummy packet" << endl;
//#endif #endif
stopWriting(ithread,wbuf); stopWriting(ithread,wbuf);
continue; continue;
} }
//#ifdef VERYDEBUG #ifdef VERYDEBUG
else cout <<"**NOT a dummy packet"<<endl; else cout <<"**NOT a dummy packet"<<endl;
//#endif #endif
@ -1913,8 +1929,11 @@ int UDPStandardImplementation::startWriting(){
tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum);
if(dynamicRange != 32) if(dynamicRange != 32)
tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1
else else{
cout << " 32 bit eiger could be "<< dec << htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum) << endl;
cout << " 32 bit eiger32 could be "<< dec << htonl(*(unsigned int*)((eiger_image_header32 *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum) << endl;
tempframenum = ((tempframenum / EIGER_32BIT_INITIAL_CONSTANT) + startFrameIndex)-1;//eiger 32 bit mode is a multiple of 17c. +startframeindex for scans tempframenum = ((tempframenum / EIGER_32BIT_INITIAL_CONSTANT) + startFrameIndex)-1;//eiger 32 bit mode is a multiple of 17c. +startframeindex for scans
}
}else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1))
tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset);
else else
@ -1928,10 +1947,10 @@ int UDPStandardImplementation::startWriting(){
currframenum = tempframenum; currframenum = tempframenum;
pthread_mutex_unlock(&progress_mutex); pthread_mutex_unlock(&progress_mutex);
} }
//#ifdef VERYDEBUG #ifdef VERYDEBUG
if(myDetectorType == EIGER) if(myDetectorType == EIGER)
cout << endl <<ithread << " tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; cout << endl <<ithread << " tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl;
//#endif #endif
//without datacompression: write datacall back, or write data, free fifo //without datacompression: write datacall back, or write data, free fifo
@ -1969,7 +1988,8 @@ int UDPStandardImplementation::startWriting(){
} }
else{ else{
//copy to gui //copy to gui
if(numpackets == packetsPerFrame * numJobsPerThread){ //only full frames if(numpackets >= packetsPerFrame){//min 1 frame, but neednt be
//if(numpackets == packetsPerFrame * numJobsPerThread){ //only full frames
copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS);
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout << ithread << " finished copying" << endl; cout << ithread << " finished copying" << endl;
@ -2108,12 +2128,20 @@ int i;
exit(-1); exit(-1);
} }
//free buffer
if(rc <= 0){
cout << ithread << "Discarding empty frame" << endl;
fifoFree[ithread]->push(buffer[ithread]);
#ifdef FIFO_DEBUG
cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread]));
#endif
}
//push the last buffer into fifo //push the last buffer into fifo
if(rc > 0){ else{
//eiger (incomplete frames) - throw away //eiger (incomplete frames) - throw away
if((myDetectorType == EIGER) && (rc < (bufferSize * numJobsPerThread)) ){ if((myDetectorType == EIGER) && (rc < (bufferSize * numJobsPerThread)) ){
if(rc == 266240) if(rc == 266240)
cout << ithread << " Start of detector: Received test frame of 266240 bytes." << endl; cprintf(GREEN, "%d Start of detector: Received test frame of 266240 bytes.\n",ithread);
cout << ithread << "Discarding incomplete frame" << endl; cout << ithread << "Discarding incomplete frame" << endl;
fifoFree[ithread]->push(buffer[ithread]); fifoFree[ithread]->push(buffer[ithread]);
#ifdef FIFO_DEBUG #ifdef FIFO_DEBUG
@ -2135,14 +2163,6 @@ int i;
#endif #endif
} }
} }
//free buffer
else{
cout << ithread << "Discarding empty frame" << endl;
fifoFree[ithread]->push(buffer[ithread]);
#ifdef FIFO_DEBUG
cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread]));
#endif
}
@ -2252,8 +2272,13 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){
//report //report
cprintf(GREEN, "Status: Run Finished\n"); cprintf(GREEN, "Status: Run Finished\n");
if(!totalPacketsCaught){
cprintf(RED, "Total Packets Caught:%d\n", totalPacketsCaught);
cprintf(RED, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame));
}else{
cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught); cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught);
cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame)); cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame));
}
//acquisition end //acquisition end
if (acquisitionFinishedCallBack) if (acquisitionFinishedCallBack)
acquisitionFinishedCallBack((totalPacketsCaught/packetsPerFrame), pAcquisitionFinished); acquisitionFinishedCallBack((totalPacketsCaught/packetsPerFrame), pAcquisitionFinished);

View File

@ -977,7 +977,9 @@ int slsReceiverTCPIPInterface::read_frame(){
int slsReceiverTCPIPInterface::moench_read_frame(){ int slsReceiverTCPIPInterface::moench_read_frame(){
ret=OK; ret=OK;
char fName[MAX_STR_LENGTH]=""; char fName[MAX_STR_LENGTH]="";
int arg = -1,i; int acquisitionIndex = -1;
int frameIndex= -1;
int i;
int bufferSize = MOENCH_BUFFER_SIZE; int bufferSize = MOENCH_BUFFER_SIZE;
@ -990,7 +992,8 @@ int slsReceiverTCPIPInterface::moench_read_frame(){
char* raw = new char[bufferSize]; char* raw = new char[bufferSize];
uint32_t startIndex=0; uint32_t startAcquisitionIndex=0;
uint32_t startFrameIndex=0;
uint32_t index = 0,bindex = 0, offset=0; uint32_t index = 0,bindex = 0, offset=0;
strcpy(mess,"Could not read frame\n"); strcpy(mess,"Could not read frame\n");
@ -1001,18 +1004,18 @@ int slsReceiverTCPIPInterface::moench_read_frame(){
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if(!receiverBase->getFramesCaught()){ if(!receiverBase->getFramesCaught()){
arg = -1; startAcquisitionIndex = -1;
cout<<"haven't caught any frame yet"<<endl; cout<<"haven't caught any frame yet"<<endl;
} }
else{ else{
ret = OK; ret = OK;
/*startIndex=receiverBase->getStartFrameIndex();*/ /*startIndex=receiverBase->getStartFrameIndex();*/
receiverBase->readFrame(fName,&raw,index,startIndex); receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex);
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if (raw == NULL){ if (raw == NULL){
arg = -1; startAcquisitionIndex = -1;
#ifdef VERBOSE #ifdef VERBOSE
cout<<"data not ready for gui yet"<<endl; cout<<"data not ready for gui yet"<<endl;
#endif #endif
@ -1044,7 +1047,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){
bindex = (*((uint32_t*)(((char*)origVal)+packetOffset))); bindex = (*((uint32_t*)(((char*)origVal)+packetOffset)));
if (bindex == 0xFFFFFFFF){ if (bindex == 0xFFFFFFFF){
cout << "Missing Packet,Not sending to gui" << endl; cout << "Missing Packet,Not sending to gui" << endl;
index = startIndex - 1; index = startAcquisitionIndex - 1;
break;//use continue and change index above if you want to display missing packets with 0 value anyway in gui break;//use continue and change index above if you want to display missing packets with 0 value anyway in gui
} }
@ -1088,16 +1091,28 @@ int slsReceiverTCPIPInterface::moench_read_frame(){
//check if same frame number //check if same frame number
} }
arg = index - startIndex; acquisitionIndex = index-startAcquisitionIndex;
if(acquisitionIndex == -1)
startFrameIndex = -1;
else
frameIndex = index-startFrameIndex;
#ifdef VERY_VERY_DEBUG
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
cout << "frameIndex calculated is:" << frameIndex << endl;
cout << "index:" << index << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
#endif
} }
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "\nstartIndex:" << startIndex << endl;
cout << "fName:" << fName << endl; cout << "fName:" << fName << endl;
cout << "index:" << arg << endl; cout << "acquisitionIndex:" << acquisitionIndex << endl;
if(retval==NULL)cout<<"retval is null"<<endl; cout << "frameIndex:" << frameIndex << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
#endif #endif
#endif #endif
@ -1115,7 +1130,8 @@ int slsReceiverTCPIPInterface::moench_read_frame(){
} }
else{ else{
socket->SendDataOnly(fName,MAX_STR_LENGTH); socket->SendDataOnly(fName,MAX_STR_LENGTH);
socket->SendDataOnly(&arg,sizeof(arg)); socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
socket->SendDataOnly(&frameIndex,sizeof(frameIndex));
socket->SendDataOnly(retval,MOENCH_DATA_BYTES); socket->SendDataOnly(retval,MOENCH_DATA_BYTES);
} }
//return ok/fail //return ok/fail
@ -1135,7 +1151,9 @@ int slsReceiverTCPIPInterface::moench_read_frame(){
int slsReceiverTCPIPInterface::gotthard_read_frame(){ int slsReceiverTCPIPInterface::gotthard_read_frame(){
ret=OK; ret=OK;
char fName[MAX_STR_LENGTH]=""; char fName[MAX_STR_LENGTH]="";
int arg = -1,i; int acquisitionIndex = -1;
int frameIndex= -1;
int i;
//retval is a full frame //retval is a full frame
@ -1161,7 +1179,8 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){
uint32_t index=0,index2=0; uint32_t index=0,index2=0;
uint32_t pindex=0,pindex2=0; uint32_t pindex=0,pindex2=0;
uint32_t bindex=0,bindex2=0; uint32_t bindex=0,bindex2=0;
uint32_t startIndex=0; uint32_t startAcquisitionIndex=0;
uint32_t startFrameIndex=0;
strcpy(mess,"Could not read frame\n"); strcpy(mess,"Could not read frame\n");
@ -1173,16 +1192,16 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if(!receiverBase->getFramesCaught()){ if(!receiverBase->getFramesCaught()){
arg=-1; startAcquisitionIndex=-1;
cout<<"haven't caught any frame yet"<<endl; cout<<"haven't caught any frame yet"<<endl;
}else{ }else{
ret = OK; ret = OK;
/*startIndex=receiverBase->getStartFrameIndex();*/ /*startIndex=receiverBase->getStartFrameIndex();*/
receiverBase->readFrame(fName,&raw,index,startIndex); receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex);
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if (raw == NULL){ if (raw == NULL){
arg = -1; startAcquisitionIndex = -1;
#ifdef VERBOSE #ifdef VERBOSE
cout<<"data not ready for gui yet"<<endl; cout<<"data not ready for gui yet"<<endl;
#endif #endif
@ -1216,7 +1235,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){
if(bindex != 0xFFFFFFFF) if(bindex != 0xFFFFFFFF)
memcpy((((char*)retval)+(GOTTHARD_SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, GOTTHARD_SHORT_DATABYTES); memcpy((((char*)retval)+(GOTTHARD_SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, GOTTHARD_SHORT_DATABYTES);
else{ else{
index = startIndex - 1; index = startAcquisitionIndex - 1;
cout << "Missing Packet,Not sending to gui" << endl; cout << "Missing Packet,Not sending to gui" << endl;
} }
} }
@ -1247,14 +1266,29 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){
}*/ }*/
} }
arg = (index - startIndex); acquisitionIndex = index-startAcquisitionIndex;
if(acquisitionIndex == -1)
startFrameIndex = -1;
else
frameIndex = index-startFrameIndex;
#ifdef VERY_VERY_DEBUG
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
cout << "frameIndex calculated is:" << frameIndex << endl;
cout << "index:" << index << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
#endif
} }
} }
#ifdef VERBOSE #ifdef VERBOSE
if(arg!=-1){ if(frameIndex!=-1){
cout << "fName:" << fName << endl; cout << "fName:" << fName << endl;
cout << "findex:" << arg << endl; cout << "acquisitionIndex:" << acquisitionIndex << endl;
cout << "frameIndex:" << frameIndex << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
} }
#endif #endif
@ -1275,7 +1309,8 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){
} }
else{ else{
socket->SendDataOnly(fName,MAX_STR_LENGTH); socket->SendDataOnly(fName,MAX_STR_LENGTH);
socket->SendDataOnly(&arg,sizeof(arg)); socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
socket->SendDataOnly(&frameIndex,sizeof(frameIndex));
socket->SendDataOnly(retval,GOTTHARD_DATA_BYTES); socket->SendDataOnly(retval,GOTTHARD_DATA_BYTES);
} }
@ -1297,7 +1332,9 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){
int slsReceiverTCPIPInterface::eiger_read_frame(){ int slsReceiverTCPIPInterface::eiger_read_frame(){
ret=OK; ret=OK;
char fName[MAX_STR_LENGTH]=""; char fName[MAX_STR_LENGTH]="";
int arg = -1,i; int acquisitionIndex = -1;
int frameIndex= -1;
int i;
uint32_t index=0; uint32_t index=0;
int frameSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE * packetsPerFrame; int frameSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE * packetsPerFrame;
@ -1309,7 +1346,8 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
char* raw = new char[frameSize]; char* raw = new char[frameSize];
char* origVal = new char[frameSize]; char* origVal = new char[frameSize];
char* retval = new char[dataSize]; char* retval = new char[dataSize];
uint32_t startIndex=0; uint32_t startAcquisitionIndex=0;
uint32_t startFrameIndex=0;
strcpy(mess,"Could not read frame\n"); strcpy(mess,"Could not read frame\n");
@ -1320,7 +1358,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if(!receiverBase->getFramesCaught()){ if(!receiverBase->getFramesCaught()){
arg=-1; startAcquisitionIndex=-1;
#ifdef VERBOSE #ifdef VERBOSE
cout<<"haven't caught any frame yet"<<endl; cout<<"haven't caught any frame yet"<<endl;
#endif #endif
@ -1329,13 +1367,13 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
else{ else{
ret = OK; ret = OK;
/** read a frame */ /** read a frame */
receiverBase->readFrame(fName,&raw,index,startIndex); receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex);
#ifdef VERBOSE #ifdef VERBOSE
cout << "index:" << dec << index << endl; cout << "index:" << dec << index << endl;
#endif #endif
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if (raw == NULL){ if (raw == NULL){
arg = -1; startAcquisitionIndex = -1;
#ifdef VERBOSE #ifdef VERBOSE
cout<<"data not ready for gui yet"<<endl; cout<<"data not ready for gui yet"<<endl;
#endif #endif
@ -1463,19 +1501,29 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
(*(((uint64_t*)retval)+i)) = temp; (*(((uint64_t*)retval)+i)) = temp;
*/ */
} }
arg = index-startIndex; acquisitionIndex = index-startAcquisitionIndex;
if(acquisitionIndex == -1)
startFrameIndex = -1;
else
frameIndex = index-startFrameIndex;
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout << "arg calculated is:"<<arg<<endl; cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
cout <<"index:"<<index<<" startindex:"<<startIndex<<endl; cout << "frameIndex calculated is:" << frameIndex << endl;
cout << "index:" << index << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
#endif #endif
} }
} }
#ifdef VERBOSE #ifdef VERBOSE
//if(arg!=-1){ if(frameIndex!=-1){
cout << "fName:" << fName << endl; cout << "fName:" << fName << endl;
cout << "findex:" << dec << arg << endl; cout << "acquisitionIndex:" << acquisitionIndex << endl;
//} cout << "frameIndex:" << frameIndex << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
}
#endif #endif
@ -1495,7 +1543,8 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){
} }
else{ else{
socket->SendDataOnly(fName,MAX_STR_LENGTH); socket->SendDataOnly(fName,MAX_STR_LENGTH);
socket->SendDataOnly(&arg,sizeof(arg)); socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
socket->SendDataOnly(&frameIndex,sizeof(frameIndex));
socket->SendDataOnly(retval,dataSize); socket->SendDataOnly(retval,dataSize);
} }