diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 40c3ab54c..67443f21c 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -436,7 +436,7 @@ private: * @param numpackets is the number of packets * @param framenum current frame number */ - void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); + void writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum); /** * Its called for the first packet of a scan or acquistion @@ -469,8 +469,9 @@ private: * Called by startWriting() * @param ithread writing thread number * @param wbuffer writer buffer + * @param npackets number of packets */ - void handleWithoutDataCompression(int ithread, char* wbuffer); + void handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets); /** * data compression for each fifo output diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3f18ddea9..8e8c930b6 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -992,12 +992,8 @@ cout << "copyframe" << endl; #endif //eiger if(startbuf != NULL){ - int offset = 0; - int size = frameSize/EIGER_MAX_PORTS; - for(int j=0;jpop(wbuf[i]); #ifdef FIFO_DEBUG - cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); + cprintf(GREEN,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); #endif numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); #ifdef VERYDEBUG @@ -2070,18 +2071,23 @@ int UDPStandardImplementation::startWriting(){ if( 0x01 == (*(uint8_t*)(((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->header_confirm))){ //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans - if(!startdatapacket[i]) + if(!startdatapacket[i]){ + tempframenum[i] = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)+(startFrameIndex-1); - //next frame, leave +//#ifdef VERYVERBOSE + cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); +//#endif + }//next frame, leave else{ + cprintf(RED,"**missing packets and got header\n"); //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); //to decrement from packetsInFile to calculate packet loss numTotMissingPacketsInFile += numberofmissingpackets[i]; for(j=0;jnum4))); +#ifdef VERYVERBOSE + cprintf(GREEN,"** got current packet header of %d: %d lastpacketheader %d\n",i,currentpacketheader[i],lastpacketheader[i]); +#endif //same frame packet - continue building frame if(currentpacketheader[i] > lastpacketheader[i]){ //add missing packets @@ -2100,30 +2109,31 @@ int UDPStandardImplementation::startWriting(){ numTotMissingPacketsInFile += numberofmissingpackets[i]; for(j=0;jpush(buffer[ithread])); #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); @@ -2415,27 +2429,15 @@ void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; - int i,j; -#ifdef VERBOSE - cprintf(GREEN,"%d End of Acquisition\n",ithread); -#endif + cprintf(GREEN,"%d End of Acquisition for Writing Thread\n",ithread); + int i,j; //free fifo for(i=0;ipush(wbuffer[i]+j*onePacketSize)); + while(!fifoFree[i]->push(wbuffer[i])); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]+j*onePacketSize)); + cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); #endif - } - }else{ - while(!fifoFree[i]->push(wbuffer[i])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); -#endif - } } @@ -2497,10 +2499,10 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ -void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum){ +void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum){ FILE_LOG(logDEBUG) << __AT__ << " called"; - int packetsToSave, offset,lastpacket; + int packetsToSave, offset,lastpacket,i; uint32_t tempframenum = framenum; //file write @@ -2513,42 +2515,42 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(myDetectorType == EIGER){ int k = 0; if(dynamicRange != 32){ - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); }else{ k = 0; - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 256; - cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 512; - cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 768; - cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); } } #endif @@ -2559,9 +2561,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num //for progress and packet loss calculation(new files) if(myDetectorType == EIGER); else if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + tempframenum = (((((uint32_t)(*((uint32_t*)(buf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + tempframenum = ((((uint32_t)(*((uint32_t*)(buf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); if(numWriterThreads == 1) currframenum = tempframenum; @@ -2583,7 +2585,12 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(packetsToSave > numpackets) packetsToSave = numpackets; /**next time offset is still plus header length*/ - fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); + if(myDetectorType == EIGER) + for(i=0;i= maxPacketsPerFile){ - //for packet loss - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER);//because currframenum is the latest one for eiger - else if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) + //for packet loss, because currframenum is the latest one for eiger + if(myDetectorType != EIGER){ + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf[0] + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf[0] + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + } if(numWriterThreads == 1) currframenum = tempframenum; else{ @@ -2619,8 +2627,8 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(numWriterThreads > 1) pthread_mutex_unlock(&write_mutex); - - offset += (packetsToSave * onePacketSize); + if(myDetectorType != EIGER) + offset += (packetsToSave * onePacketSize); numpackets -= packetsToSave; } @@ -2643,17 +2651,19 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num -void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer){ - int i,npackets; +void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets){ + int i,j; if (cbAction < DO_EVERYTHING){ - npackets = (uint32_t)(*((uint32_t*)wbuffer)); - rawDataReadyCallBack(currframenum, wbuffer + HEADER_SIZE_NUM_TOT_PACKETS, npackets * onePacketSize, sfilefd, guiData,pRawDataReady); + if (myDetectorType == EIGER){ + for(i=0;i 0){ #ifdef WRITE_HEADERS @@ -2661,17 +2671,17 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* for (i = 0; i < packetsPerFrame; i++){ //overwriting frame number in header - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num1)) = currframenum; + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; //overwriting port number and dynamic range if (i<(packetsPerFrame/2)) - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num3)) = (dynamicRange<<2); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = (dynamicRange<<2); else - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = ((dynamicRange<<2)|(0x1)); #ifdef VERYDEBUG cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num4))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))); #endif } @@ -2681,19 +2691,19 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* for (i = 0; i < packetsPerFrame; i++){ if( (i < (packetsPerFrame/4)) || ((i > (packetsPerFrame/2)) && (i < (3*packetsPerFrame/4))) ){ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num4))); + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))); }else{ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num4))+(packetsPerFrame/4)); + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+(packetsPerFrame/4)); } #ifdef VERYDEBUG cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num2))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); #endif } @@ -2720,13 +2730,15 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(GREEN,"copied frame\n"); //#endif - for(i=0;inum3)) != 0xFF) - while(!fifoFree[i]->push(wbuffer+i*onePacketSize)); + for(i=0;inum3)) != 0xFF) + while(!fifoFree[i]->push(wbuffer[j+i*(packetsPerFrame/2)])); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer+i*onePacketSize)); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[j+i*(packetsPerFrame/2)])); #endif + } } } else{ @@ -2752,13 +2764,13 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* -void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ +void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf){ FILE_LOG(logDEBUG) << __AT__ << " called"; #if defined(MYROOT1) && defined(ALLFILE_DEBUG) writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); #endif - + int npackets = (uint32_t)(*((uint32_t*)wbuffer[0])); eventType thisEvent = PEDESTAL; int ndata; char* buff = 0;