adding exptime to receiver for file header

This commit is contained in:
Dhanya Maliakal 2016-11-14 11:57:34 +01:00
parent 45fc87240f
commit e6c7dfc440
6 changed files with 126 additions and 46 deletions

View File

@ -173,6 +173,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
*/
uint64_t getAcquisitionPeriod() const;
/**
* Get Acquisition Time
* @return acquisition time
*/
uint64_t getAcquisitionTime() const;
/*
* Get Number of Frames expected by receiver from detector
* The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented)
@ -343,6 +349,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
*/
int setAcquisitionPeriod(const uint64_t i);
/**
* Set Acquisition Time
* @param i acquisition time
* @return OK or FAIL
*/
int setAcquisitionTime(const uint64_t i);
/**
* Set Number of Frames expected by receiver from detector
* The data receiver status will change from running to idle when it gets this number of frames
@ -508,9 +521,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
/** Number of Packets per Frame*/
uint32_t packetsPerFrame;
/** Acquisition Period */
int64_t acquisitionPeriod;
uint64_t acquisitionPeriod;
/** Acquisition Time */
uint64_t acquisitionTime;
/** Frame Number */
int64_t numberOfFrames;
uint64_t numberOfFrames;
/** Dynamic Range */
uint32_t dynamicRange;
/** Ten Giga Enable*/

View File

@ -233,6 +233,12 @@ class UDPInterface {
*/
virtual uint64_t getAcquisitionPeriod() const = 0;
/**
* Get Acquisition Time
* @return acquisition time
*/
virtual uint64_t getAcquisitionTime() const = 0;
/*
* Get Number of Frames expected by receiver from detector
* The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented)
@ -399,6 +405,13 @@ class UDPInterface {
*/
virtual int setAcquisitionPeriod(const uint64_t i) = 0;
/**
* Set Acquisition Time
* @param i acquisition time
* @return OK or FAIL
*/
virtual int setAcquisitionTime(const uint64_t i) = 0;
/**
* Set Number of Frames expected by receiver from detector
* The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented)

View File

@ -128,6 +128,13 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
*/
int setAcquisitionPeriod(const uint64_t i);
/**
* Set Acquisition Time
* @param i acquisition time
* @return OK or FAIL
*/
int setAcquisitionTime(const uint64_t i);
/**
* Overridden method
* Set Number of Frames expected by receiver from detector
@ -608,7 +615,7 @@ private:
/** If file created successfully for all Writer Threads */
bool fileCreateSuccess;
const static int FILE_HEADER_SIZE = 500;
const static unsigned int FILE_HEADER_SIZE = 500;
char fileHeader[MAX_NUMBER_OF_WRITER_THREADS][FILE_HEADER_SIZE];
@ -705,7 +712,7 @@ private:
char guiFileName[MAX_NUMBER_OF_WRITER_THREADS][MAX_STR_LENGTH];
/** Number of packets copied to be sent to gui (others padded) */
int guiNumPackets[MAX_NUMBER_OF_WRITER_THREADS];
uint32_t guiNumPackets[MAX_NUMBER_OF_WRITER_THREADS];
/** Semaphore to synchronize Writer and GuiReader threads*/
sem_t writerGuiSemaphore[MAX_NUMBER_OF_WRITER_THREADS]; //datacompression, only first thread sends to gui

View File

@ -41,6 +41,7 @@ void UDPBaseImplementation::initializeMembers(){
strcpy(detHostname,"");
packetsPerFrame = 0;
acquisitionPeriod = 0;
acquisitionTime = 0;
numberOfFrames = 0;
dynamicRange = 16;
tengigaEnable = false;
@ -183,6 +184,8 @@ uint32_t UDPBaseImplementation::getDataStreamEnable() const{ FILE_LOG(logDEBUG)
uint64_t UDPBaseImplementation::getAcquisitionPeriod() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return acquisitionPeriod;}
uint64_t UDPBaseImplementation::getAcquisitionTime() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return acquisitionTime;}
uint64_t UDPBaseImplementation::getNumberOfFrames() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return numberOfFrames;}
uint32_t UDPBaseImplementation::getDynamicRange() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return dynamicRange;}
@ -360,6 +363,16 @@ int UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){
return OK;
}
int UDPBaseImplementation::setAcquisitionTime(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
acquisitionTime = i;
FILE_LOG(logINFO) << "Acquisition Time:" << (double)acquisitionTime/(1E9) << "s";
//overrridden child classes might return FAIL
return OK;
}
int UDPBaseImplementation::setNumberOfFrames(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";

View File

@ -299,9 +299,14 @@ int UDPStandardImplementation::setupFifoStructure(){
//random frame sent to gui, then frames per buffer depends on acquisition period
else{
//calculate 100ms/period to get frames to listen to at a time
if(!acquisitionPeriod)
i = SAMPLE_TIME_IN_NS;
else i = SAMPLE_TIME_IN_NS/acquisitionPeriod;
if(acquisitionPeriod)
i = SAMPLE_TIME_IN_NS/acquisitionPeriod;
else{
if(acquisitionTime)
i = SAMPLE_TIME_IN_NS/acquisitionTime;
else
i = SAMPLE_TIME_IN_NS;
}
//max frames to listen to at a time is limited by 1000
if (i > MAX_JOBS_PER_THREAD)
numberofJobsPerBuffer = MAX_JOBS_PER_THREAD;
@ -605,6 +610,23 @@ int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){
}
int UDPStandardImplementation::setAcquisitionTime(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " called";
acquisitionTime = i;
if(setupFifoStructure() == FAIL)
return FAIL;
FILE_LOG(logINFO) << "Acquisition Period: " << (double)acquisitionTime/(1E9) << "s";
if(myDetectorType == EIGER)
for(int i=0; i<MAX_NUMBER_OF_WRITER_THREADS; i++)
updateFileHeader(i);
return OK;
}
int UDPStandardImplementation::setNumberOfFrames(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " called";
@ -1136,7 +1158,7 @@ void UDPStandardImplementation::startReadout(){
currentReceivedInBuffer += udpSocket[i]->getCurrentTotalReceived();
//wait for all packets
if(totalP!=numberOfFrames*packetsPerFrame*numberofListeningThreads){
if((unsigned long long int)totalP!=numberOfFrames*packetsPerFrame*numberofListeningThreads){
//wait as long as there is change from prev totalP,
//and also change from received in buffer to previous value
@ -1611,25 +1633,27 @@ int UDPStandardImplementation::createNewFile(int ithread){
if(totalWritingPacketCount[ithread]){
if(numberofWriterThreads>1){
cprintf(BLUE,"\nThread:%d File:%s"
"\nLost:%d"
"\nLost:%lld"
"\tPackets:%lld"
"\tFrame#:%lld"
"\tPFrame#:%lld\n",
ithread,completeFileName[ithread],
( ((int)(currentFrameNumber[ithread]-frameNumberInPreviousFile[ithread])*packetsPerFrame) - totalPacketsInFile[ithread]),
totalPacketsInFile[ithread],currentFrameNumber[ithread],frameNumberInPreviousFile[ithread]
(long long int)(((currentFrameNumber[ithread]-frameNumberInPreviousFile[ithread])*packetsPerFrame) - totalPacketsInFile[ithread]),
(long long int)totalPacketsInFile[ithread],
(long long int)currentFrameNumber[ithread],
(long long int)frameNumberInPreviousFile[ithread]
);
}else{
cprintf(BLUE,"\nFile:%s"
"\nLost:%d"
"\nLost:%lld"
"\tPackets:%lld"
"\tFrame#:%lld"
"\tPFrame#:%lld\n",
completeFileName[ithread],
( ((int)(currentFrameNumber[ithread]-frameNumberInPreviousFile[ithread])*packetsPerFrame) - totalPacketsInFile[ithread]),
totalPacketsInFile[ithread],
currentFrameNumber[ithread],
frameNumberInPreviousFile[ithread]
(long long int)(((currentFrameNumber[ithread]-frameNumberInPreviousFile[ithread])*packetsPerFrame) - totalPacketsInFile[ithread]),
(long long int)totalPacketsInFile[ithread],
(long long int)currentFrameNumber[ithread],
(long long int)frameNumberInPreviousFile[ithread]
);
}
@ -1754,10 +1778,9 @@ void UDPStandardImplementation::startDataCallback(){
int oneframesize = oneDataSize * packetsPerFrame;
char* buffer = new char[packetsPerFrame*oneDataSize];
memset(buffer,0xFF,oneframesize);
int bufferoffset = 0;
int size = 0;
int offset = 0;
int currentfnum = 0;
uint32_t currentfnum = 0;
uint64_t fnum = 0;
uint32_t pnum = 0;
uint32_t snum = 0;
@ -2138,7 +2161,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int cSize, ch
//set fnum, pnum and deactivatedpacket label
eiger_packet_header_t* header;
eiger_packet_footer_t* footer;
int pnum=0;
uint32_t pnum=0;
//loop by each packet
for(int offset=fifoBufferHeaderSize;
offset<receivedSize;
@ -2169,9 +2192,8 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int cSize, ch
jfrau_packet_header_t* header;
int offset = fifoBufferHeaderSize;
int pnum = packetsPerFrame-1;
int currentpnum;
int currentfnum=-1;
uint32_t pnum = packetsPerFrame-1;
uint32_t currentpnum;
//read first packet
receivedSize=0;
@ -2294,7 +2316,6 @@ void UDPStandardImplementation::startFrameIndices(int ithread){
FILE_LOG(logDEBUG) << __AT__ << " called";
//determine startFrameIndex
jfrau_packet_header_t* header=0;
switch(myDetectorType){
case EIGER:
startFrameIndex = 0; //frame number always resets
@ -2790,25 +2811,25 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer){
if(totalWritingPacketCountFromLastCheck[ithread]){
if(numberofWriterThreads>1){
printf("Thread:%d"
"\tLost:%d"
"\tLost:%lld"
"\tPackets:%lld"
"\tFrame#:%lld"
"\tPFrame#r:%lld\n",
ithread,
( ((int)(currentFrameNumber[ithread]-frameNumberInPreviousCheck[ithread])*packetsPerFrame) - totalWritingPacketCountFromLastCheck[ithread]),
totalWritingPacketCountFromLastCheck[ithread],
currentFrameNumber[ithread],
frameNumberInPreviousCheck[ithread]
(long long int)(((currentFrameNumber[ithread]-frameNumberInPreviousCheck[ithread])*packetsPerFrame) - totalWritingPacketCountFromLastCheck[ithread]),
(long long int)totalWritingPacketCountFromLastCheck[ithread],
(long long int)currentFrameNumber[ithread],
(long long int)frameNumberInPreviousCheck[ithread]
);
}else{
printf("Lost:%d"
printf("Lost:%lld"
"\tPackets:%lld"
"\tFrame#:%lld"
"\tPFrame#:%lld\n",
( ((int)(currentFrameNumber[ithread]-frameNumberInPreviousCheck[ithread])*packetsPerFrame) - totalWritingPacketCountFromLastCheck[ithread]),
totalWritingPacketCountFromLastCheck[ithread],
currentFrameNumber[ithread],
frameNumberInPreviousCheck[ithread]
(long long int)(((currentFrameNumber[ithread]-frameNumberInPreviousCheck[ithread])*packetsPerFrame) - totalWritingPacketCountFromLastCheck[ithread]),
(long long int)totalWritingPacketCountFromLastCheck[ithread],
(long long int)currentFrameNumber[ithread],
(long long int)frameNumberInPreviousCheck[ithread]
);
}
}
@ -2969,14 +2990,14 @@ void UDPStandardImplementation::handleWithoutMissingPackets(int ithread, char* w
//Print packet loss and filenames
if(tempframenumber && (tempframenumber%(maxFramesPerFile/10)) == 0){
printf("Lost:%d"
printf("Lost:%lld"
"\tPackets:%lld"
"\tFrame#:%lld"
"\tPFrame#:%lld\n",
( ((int)(currentFrameNumber[ithread]-frameNumberInPreviousCheck[ithread])*packetsPerFrame) - totalWritingPacketCountFromLastCheck[ithread]),
totalWritingPacketCountFromLastCheck[ithread],
currentFrameNumber[ithread],
frameNumberInPreviousCheck[ithread]
(long long int)(((currentFrameNumber[ithread]-frameNumberInPreviousCheck[ithread])*packetsPerFrame) - totalWritingPacketCountFromLastCheck[ithread]),
(long long int)totalWritingPacketCountFromLastCheck[ithread],
(long long int)currentFrameNumber[ithread],
(long long int)frameNumberInPreviousCheck[ithread]
);
//reset counters for each new file
@ -3052,9 +3073,9 @@ void UDPStandardImplementation::writeFileWithoutCompression(int ithread, char* w
//second part to not check when there has been something written previously
if(numpackets &&(lastFrameNumberInFile[ithread]>=0)){
//get start frame (required to create new file at the right juncture)
uint64_t startframe =-1;
uint32_t pnum;
uint32_t snum;
uint64_t startframe = 0;
uint32_t pnum = 0;
uint32_t snum = 0;
//if(ithread) cout<<"getting start frame number"<<endl;
if(getFrameandPacketNumber(ithread, wbuffer + offset, startframe,pnum,snum) == FAIL){
//error in frame number sent by fpga
@ -3062,7 +3083,7 @@ void UDPStandardImplementation::writeFileWithoutCompression(int ithread, char* w
return;
}
//if(ithread) cout<<"done getting start frame number"<<endl;
if(startframe == lastFrameNumberInFile[ithread]){
if(startframe == (unsigned long long int)lastFrameNumberInFile[ithread]){
if(writeUptoFrameNumber(ithread, wbuffer, offset, startframe+1, numpackets, packetsWritten) == FAIL)
//weird frame number of zero from fpga
return;
@ -3163,6 +3184,7 @@ void UDPStandardImplementation::updateFileHeader(int ithread){
"x\t\t: %d pixels\n"
"y\t\t: %d pixels\n"
"Frames\t\t: %lld\n"
"Exptime (ns)\t: %lld\n"
"Period (ns)\t: %lld\n"
"Timestamp\t: %s\n\n"
@ -3184,10 +3206,11 @@ void UDPStandardImplementation::updateFileHeader(int ithread){
//only for eiger right now
EIGER_PIXELS_IN_ONE_ROW,EIGER_PIXELS_IN_ONE_COL,
(long long int)numberOfFrames,
(long long int)acquisitionTime,
(long long int)acquisitionPeriod,
ctime(&t));
if(strlen(fileHeader[ithread]) > FILE_HEADER_SIZE)
cprintf(BG_RED,"File Header Size %d is too small for fixed file header size %d\n",strlen(fileHeader[ithread]),FILE_HEADER_SIZE);
cprintf(BG_RED,"File Header Size %d is too small for fixed file header size %d\n",strlen(fileHeader[ithread]),(int)FILE_HEADER_SIZE);
}
@ -3395,7 +3418,7 @@ int UDPStandardImplementation::getFrameandPacketNumber(int ithread, char* wbuffe
framenumber = (uint32_t)(*( (uint64_t*) footer));
//error in frame number sent by fpga
if(!((uint32_t)(*( (uint64_t*) footer)))){
framenumber = -1;
framenumber = 0;
FILE_LOG(logERROR) << "Fifo "<< ithread << ": Frame Number is zero from firmware.";
return FAIL;
}

View File

@ -2439,7 +2439,14 @@ int slsReceiverTCPIPInterface::set_timer() {
ret = FAIL;
}
else{
if(index[0] == FRAME_PERIOD){
if(index[0] == ACQUISITION_TIME){
if(index[1]>=0){
ret = receiverBase->setAcquisitionTime(index[1]);
if(ret == FAIL)
strcpy(mess,"Could not allocate memory for listening fifo\n");
}
retval=receiverBase->getAcquisitionTime();
}else if(index[0] == FRAME_PERIOD){
if(index[1]>=0){
ret = receiverBase->setAcquisitionPeriod(index[1]);
if(ret == FAIL)
@ -2457,7 +2464,9 @@ int slsReceiverTCPIPInterface::set_timer() {
}
#ifdef VERYVERBOSE
if(ret!=FAIL){
if(index[0] == FRAME_PERIOD)
if(index[0] == ACQUISITION_TIME)
cout << "acquisition time:" << retval << endl;
else if(index[0] == FRAME_PERIOD)
cout << "acquisition period:" << retval << endl;
else
cout << "frame number:" << retval << endl;