From 2e5f64d9bc480f0c49980f521a8edca1878e375e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 5 Oct 2017 15:59:07 +0200 Subject: [PATCH] gap pixels for 8, 16, 32 in receiver at udp level --- slsReceiverSoftware/include/BinaryFile.h | 3 +- slsReceiverSoftware/include/DataProcessor.h | 26 +++- slsReceiverSoftware/include/File.h | 13 +- slsReceiverSoftware/include/GeneralData.h | 14 +- slsReceiverSoftware/include/HDF5File.h | 3 +- slsReceiverSoftware/src/BinaryFile.cpp | 4 +- slsReceiverSoftware/src/DataProcessor.cpp | 122 +++++++++++++++++- slsReceiverSoftware/src/DataStreamer.cpp | 6 +- slsReceiverSoftware/src/File.cpp | 8 +- slsReceiverSoftware/src/HDF5File.cpp | 4 +- .../src/UDPStandardImplementation.cpp | 10 +- 11 files changed, 171 insertions(+), 42 deletions(-) diff --git a/slsReceiverSoftware/include/BinaryFile.h b/slsReceiverSoftware/include/BinaryFile.h index 449a5d436..3d1e46d0b 100644 --- a/slsReceiverSoftware/include/BinaryFile.h +++ b/slsReceiverSoftware/include/BinaryFile.h @@ -22,7 +22,6 @@ class BinaryFile : private virtual slsReceiverDefs, public File, public BinaryFi * creates the File Writer * @param ind self index * @param maxf max frames per file - * @param ppf packets per frame * @param nd pointer to number of detectors in each dimension * @param fname pointer to file name prefix * @param fpath pointer to file path @@ -35,7 +34,7 @@ class BinaryFile : private virtual slsReceiverDefs, public File, public BinaryFi * @param portno pointer to udp port number for logging * @param smode pointer to silent mode */ - BinaryFile(int ind, uint32_t maxf, const uint32_t* ppf, + BinaryFile(int ind, uint32_t maxf, int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno, bool* smode); diff --git a/slsReceiverSoftware/include/DataProcessor.h b/slsReceiverSoftware/include/DataProcessor.h index 0b5a71737..174b67827 100644 --- a/slsReceiverSoftware/include/DataProcessor.h +++ b/slsReceiverSoftware/include/DataProcessor.h @@ -28,12 +28,14 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject { * @param ftype pointer to file format type * @param fwenable pointer to file writer enable * @param dsEnable pointer to data stream enable + * @param gpEnable pointer to gap pixels enable + * @param dr pointer to dynamic range * @param freq pointer to streaming frequency * @param timer pointer to timer if streaming frequency is random * @param dataReadycb pointer to data ready call back function * @param pDataReadycb pointer to arguments of data ready call back function */ - DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dsEnable, + DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr, uint32_t* freq, uint32_t* timer, void (*dataReadycb)(uint64_t, uint32_t, uint32_t, uint64_t, uint64_t, uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t, uint8_t, uint8_t, char*, uint32_t, void*), @@ -200,6 +202,11 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject { */ void EndofAcquisition(uint64_t numf); + /** + * Update pixel dimensions in file writer + */ + void SetPixelDimension(); + private: @@ -269,6 +276,13 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject { */ bool CheckCount(); + /** + * Processing Function (inserting gap pixels) eiger specific + * @param buf pointer to image + * @param dr dynamic range + */ + void InsertGapPixels(char* buf, uint32_t dr); + /** type of thread */ static const std::string TypeName; @@ -307,6 +321,13 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject { /** File Write Enable */ bool* fileWriteEnable; + /** Gap Pixels Enable */ + bool* gapPixelsEnable; + + + /** Dynamic Range */ + uint32_t* dynamicRange; + /** Pointer to Streaming frequency, if 0, sending random images with a timer */ uint32_t* streamingFrequency; @@ -319,6 +340,9 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject { /** timer beginning stamp for random streaming */ struct timespec timerBegin; + /** temporary buffer for processing */ + char* tempBuffer; + //acquisition start diff --git a/slsReceiverSoftware/include/File.h b/slsReceiverSoftware/include/File.h index 955c10fc5..710d077b1 100644 --- a/slsReceiverSoftware/include/File.h +++ b/slsReceiverSoftware/include/File.h @@ -22,7 +22,6 @@ class File : private virtual slsReceiverDefs { * creates the File Writer * @param ind self index * @param maxf max frames per file - * @param ppf packets per frame * @param nd pointer to number of detectors in each dimension * @param fname pointer to file name prefix * @param fpath pointer to file path @@ -35,7 +34,7 @@ class File : private virtual slsReceiverDefs { * @param portno pointer to udp port number for logging * @param smode pointer to silent mode */ - File(int ind, uint32_t maxf, const uint32_t* ppf, + File(int ind, uint32_t maxf, int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno, bool* smode); @@ -84,12 +83,6 @@ class File : private virtual slsReceiverDefs { */ void SetMaxFramesPerFile(uint32_t maxf); - /** - * Set Packets per frame (called only for each generalData construction) - * @param ppf pointer to packets per frame - */ - void SetPacketsPerFrame(const uint32_t* ppf); - /** * Create file * @param fnum current frame index to include in file name @@ -172,10 +165,6 @@ class File : private virtual slsReceiverDefs { /** Maximum frames per file */ uint32_t maxFramesPerFile; - /** Packets per frame for logging */ - //pointer because value in generalData could change - const uint32_t* packetsPerFrame; - /** Master File Name */ std::string masterFileName; diff --git a/slsReceiverSoftware/include/GeneralData.h b/slsReceiverSoftware/include/GeneralData.h index 55e923990..bd452c31b 100644 --- a/slsReceiverSoftware/include/GeneralData.h +++ b/slsReceiverSoftware/include/GeneralData.h @@ -536,19 +536,19 @@ class EigerData : public GeneralData { /** * Enable Gap Pixels changes member variables * @param enable true if gap pixels enable, else false + * @param dr dynamic range */ void SetGapPixelsEnable(bool b, int dr) { switch((int)b) { case 1: - nPixelsX_Streamer = (256*2) + 3; - nPixelsY_Streamer = 256 + 1; - imageSize_Streamer = nPixelsX_Streamer * imageSize_Streamer * - ((double)dr/(double)NUM_BITS_IN_ONE_BYTE); + nPixelsX = (256 * 2) + 3; + nPixelsY = 256 + 1; + imageSize = nPixelsX * nPixelsY * ((double)dr/(double)NUM_BITS_IN_ONE_BYTE); break; default: - nPixelsX_Streamer = (256*2); - nPixelsY_Streamer = 256; - imageSize_Streamer = dataSize*packetsPerFrame; + nPixelsX = (256*2); + nPixelsY = 256; + imageSize = dataSize*packetsPerFrame; break; } }; diff --git a/slsReceiverSoftware/include/HDF5File.h b/slsReceiverSoftware/include/HDF5File.h index 4abae2f7e..200d5c0d2 100644 --- a/slsReceiverSoftware/include/HDF5File.h +++ b/slsReceiverSoftware/include/HDF5File.h @@ -28,7 +28,6 @@ class HDF5File : private virtual slsReceiverDefs, public File, public HDF5FileSt * creates the File Writer * @param ind self index * @param maxf max frames per file - * @param ppf packets per frame * @param nd pointer to number of detectors in each dimension * @param fname pointer to file name prefix * @param fpath pointer to file path @@ -43,7 +42,7 @@ class HDF5File : private virtual slsReceiverDefs, public File, public HDF5FileSt * @param ny number of pixels in y direction * @param smode pointer to silent mode */ - HDF5File(int ind, uint32_t maxf, const uint32_t* ppf, + HDF5File(int ind, uint32_t maxf, int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno, uint32_t nx, uint32_t ny, diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index 8de0d87de..a170a7479 100644 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -14,11 +14,11 @@ using namespace std; FILE* BinaryFile::masterfd = 0; -BinaryFile::BinaryFile(int ind, uint32_t maxf, const uint32_t* ppf, +BinaryFile::BinaryFile(int ind, uint32_t maxf, int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno, bool* smode): - File(ind, maxf, ppf, nd, fname, fpath, findex, owenable, dindex, nunits, nf, dr, portno, smode), + File(ind, maxf, nd, fname, fpath, findex, owenable, dindex, nunits, nf, dr, portno, smode), filefd(0), numFramesInFile(0), numActualPacketsInFile(0) diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 5d7131d8d..0bf1e7c7e 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -33,7 +33,7 @@ pthread_mutex_t DataProcessor::Mutex = PTHREAD_MUTEX_INITIALIZER; bool DataProcessor::SilentMode(false); -DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dsEnable, +DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr, uint32_t* freq, uint32_t* timer, void (*dataReadycb)(uint64_t, uint32_t, uint32_t, uint64_t, uint64_t, uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t, uint8_t, uint8_t, char*, uint32_t, void*), @@ -46,8 +46,11 @@ DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool* dataStreamEnable(dsEnable), fileFormatType(ftype), fileWriteEnable(fwenable), + gapPixelsEnable(gpEnable), + dynamicRange(dr), streamingFrequency(freq), streamingTimerInMs(timer), + tempBuffer(0), currentFreqCount(0), acquisitionStartedFlag(false), measurementStartedFlag(false), @@ -74,6 +77,7 @@ DataProcessor::DataProcessor(Fifo*& f, fileFormat* ftype, bool* fwenable, bool* DataProcessor::~DataProcessor() { if (file) delete file; + if (tempBuffer) delete [] tempBuffer; ThreadObject::DestroyThread(); NumberofDataProcessors--; } @@ -165,6 +169,15 @@ void DataProcessor::ResetParametersforNewMeasurement(){ numFramesCaught = 0; firstMeasurementIndex = 0; measurementStartedFlag = false; + + if (tempBuffer) { + delete [] tempBuffer; + tempBuffer = 0; + } + if (*gapPixelsEnable >= 0) { + tempBuffer = new char[generalData->imageSize]; + memset(tempBuffer, 0, generalData->imageSize); + } } @@ -194,7 +207,6 @@ void DataProcessor::SetGeneralData(GeneralData* g) { generalData->Print(); #endif if (file) { - file->SetPacketsPerFrame(&generalData->packetsPerFrame); file->SetMaxFramesPerFile(generalData->maxFramesPerFile); if (file->GetFileType() == HDF5) { file->SetNumberofPixels(generalData->nPixelsX, generalData->nPixelsY); @@ -240,14 +252,14 @@ void DataProcessor::SetupFileWriter(int* nd, char* fname, char* fpath, uint64_t* switch(*fileFormatType){ #ifdef HDF5C case HDF5: - file = new HDF5File(index, generalData->maxFramesPerFile, &generalData->packetsPerFrame, + file = new HDF5File(index, generalData->maxFramesPerFile, nd, fname, fpath, findex, owenable, dindex, nunits, nf, dr, portno, generalData->nPixelsX, generalData->nPixelsY, &SilentMode); break; #endif default: - file = new BinaryFile(index, generalData->maxFramesPerFile, &generalData->packetsPerFrame, + file = new BinaryFile(index, generalData->maxFramesPerFile, nd, fname, fpath, findex, owenable, dindex, nunits, nf, dr, portno, &SilentMode); break; @@ -358,6 +370,8 @@ void DataProcessor::ProcessAnImage(char* buf) { } } + if (*gapPixelsEnable && (*dynamicRange!=4)) + InsertGapPixels(buf + sizeof(sls_detector_header), *dynamicRange); if (*fileWriteEnable) file->WriteToFile(buf, generalData->imageSize + sizeof(sls_detector_header), fnum-firstMeasurementIndex, nump); @@ -424,3 +438,103 @@ bool DataProcessor::CheckCount() { return false; } + +void DataProcessor::SetPixelDimension() { + if (file) { + if (file->GetFileType() == HDF5) { + file->SetNumberofPixels(generalData->nPixelsX, generalData->nPixelsY); + } + } +} + + +/** eiger specific */ +void DataProcessor::InsertGapPixels(char* buf, uint32_t dr) { + + memset(tempBuffer, 0xFF, generalData->imageSize); + + const uint32_t nx = generalData->nPixelsX; + const uint32_t ny = generalData->nPixelsY; + const uint32_t npx = nx * ny; + + char* srcptr = 0; + char* dstptr = 0; + + const uint32_t b1px = generalData->imageSize / (npx); // not double as not dealing with 4 bit mode + const uint32_t b2px = 2 * b1px; + const uint32_t b1pxofst = (index ? b1px : 0); // left fpga (index 0) has no extra 1px offset, but right fpga has + const uint32_t b1chip = 256 * b1px; + const uint32_t b1line = (nx * b1px); + + // copying line by line + srcptr = buf; + dstptr = tempBuffer + b1line + b1pxofst; // left fpga (index 0) has no extra 1px offset, but right fpga has + for (int i = 0; i < (ny-1); ++i) { + memcpy(dstptr, srcptr, b1chip); + srcptr += b1chip; + dstptr += (b1chip + b2px); + memcpy(dstptr, srcptr, b1chip); + srcptr += b1chip; + dstptr += (b1chip + b1px); + } + + // vertical filling of values + { + char* srcgp1 = 0; char* srcgp2 = 0; char* srcgp3 = 0; + char* dstgp1 = 0; char* dstgp2 = 0; char* dstgp3 = 0; + const uint32_t b3px = 3 * b1px; + + srcptr = tempBuffer + b1line; + dstptr = tempBuffer + b1line; + + for (int i = 0; i < (ny-1); ++i) { + srcgp1 = srcptr + b1pxofst + b1chip - b1px; + dstgp1 = srcgp1 + b1px; + srcgp2 = srcgp1 + b3px; + dstgp2 = dstgp1 + b1px; + if (!index) { + srcgp3 = srcptr + b1line - b2px; + dstgp3 = srcgp3 + b1px; + } else { + srcgp3 = srcptr + b1px; + dstgp3 = srcptr; + } + switch (dr) { + case 8: + (*((uint8_t*)srcgp1)) = (*((uint8_t*)srcgp1))/2; (*((uint8_t*)dstgp1)) = (*((uint8_t*)srcgp1)); + (*((uint8_t*)srcgp2)) = (*((uint8_t*)srcgp2))/2; (*((uint8_t*)dstgp2)) = (*((uint8_t*)srcgp2)); + (*((uint8_t*)srcgp3)) = (*((uint8_t*)srcgp3))/2; (*((uint8_t*)dstgp3)) = (*((uint8_t*)srcgp3)); + break; + case 16: + (*((uint16_t*)srcgp1)) = (*((uint16_t*)srcgp1))/2; (*((uint16_t*)dstgp1)) = (*((uint16_t*)srcgp1)); + (*((uint16_t*)srcgp2)) = (*((uint16_t*)srcgp2))/2; (*((uint16_t*)dstgp2)) = (*((uint16_t*)srcgp2)); + (*((uint16_t*)srcgp3)) = (*((uint16_t*)srcgp3))/2; (*((uint16_t*)dstgp3)) = (*((uint16_t*)srcgp3)); + break; + default: + (*((uint32_t*)srcgp1)) = (*((uint32_t*)srcgp1))/2; (*((uint32_t*)dstgp1)) = (*((uint32_t*)srcgp1)); + (*((uint32_t*)srcgp2)) = (*((uint32_t*)srcgp2))/2; (*((uint32_t*)dstgp2)) = (*((uint32_t*)srcgp2)); + (*((uint32_t*)srcgp3)) = (*((uint32_t*)srcgp3))/2; (*((uint32_t*)dstgp3)) = (*((uint32_t*)srcgp3)); + break; + } + srcptr += b1line; + dstptr += b1line; + } + + } + + // horizontal filling of values + srcptr = tempBuffer + b1line; + dstptr = tempBuffer; + for (int i = 0; i < nx; ++i) { + switch (dr) { + case 8: (*((uint8_t*)srcptr)) = (*((uint8_t*)srcptr))/2; (*((uint8_t*)dstptr)) = (*((uint8_t*)srcptr)); break; + case 16:(*((uint16_t*)srcptr)) = (*((uint16_t*)srcptr))/2; (*((uint16_t*)dstptr)) = (*((uint16_t*)srcptr)); break; + default:(*((uint32_t*)srcptr)) = (*((uint32_t*)srcptr))/2; (*((uint32_t*)dstptr)) = (*((uint32_t*)srcptr)); break; + } + srcptr += b1px; + dstptr += b1px; + } + + memcpy(buf, tempBuffer, generalData->imageSize); + return; +} diff --git a/slsReceiverSoftware/src/DataStreamer.cpp b/slsReceiverSoftware/src/DataStreamer.cpp index 47be68a65..168eeff49 100644 --- a/slsReceiverSoftware/src/DataStreamer.cpp +++ b/slsReceiverSoftware/src/DataStreamer.cpp @@ -54,7 +54,7 @@ DataStreamer::DataStreamer(Fifo*& f, uint32_t* dr, int* sEnable) : DataStreamer::~DataStreamer() { CloseZmqSocket(); - if (completeBuffer) delete completeBuffer; + if (completeBuffer) delete [] completeBuffer; ThreadObject::DestroyThread(); NumberofDataStreamers--; } @@ -117,7 +117,7 @@ void DataStreamer::ResetParametersforNewMeasurement(char* fname){ measurementStartedFlag = false; strcpy(fileNametoStream, fname); if (completeBuffer) { - delete completeBuffer; + delete [] completeBuffer; completeBuffer = 0; } if (*shortFrameEnable >= 0) { @@ -253,6 +253,8 @@ void DataStreamer::ProcessAnImage(char* buf) { bprintf(RED,"Error: Could not send zmq data for fnum %lld and streamer %d\n", (long long int) fnum, index); } + + //normal else { diff --git a/slsReceiverSoftware/src/File.cpp b/slsReceiverSoftware/src/File.cpp index fa55c5357..0e8f4a4a9 100644 --- a/slsReceiverSoftware/src/File.cpp +++ b/slsReceiverSoftware/src/File.cpp @@ -10,13 +10,12 @@ using namespace std; -File::File(int ind, uint32_t maxf, const uint32_t* ppf, +File::File(int ind, uint32_t maxf, int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno, bool* smode): index(ind), maxFramesPerFile(maxf), - packetsPerFrame(ppf), numDetX(nd[0]), numDetY(nd[1]), fileNamePrefix(fname), @@ -44,7 +43,6 @@ void File::PrintMembers() { FILE_LOG(logINFO) << "\nGeneral Writer Variables:" << endl << "Index: " << index << endl << "Max Frames Per File: " << maxFramesPerFile << endl - << "Packets per Frame: " << *packetsPerFrame << endl << "Number of Detectors in x dir: " << numDetX << endl << "Number of Detectors in y dir: " << numDetY << endl << "File Name Prefix: " << fileNamePrefix << endl @@ -83,7 +81,3 @@ void File::SetMaxFramesPerFile(uint32_t maxf) { maxFramesPerFile = maxf; } - -void File::SetPacketsPerFrame(const uint32_t* ppf) { - packetsPerFrame = ppf; -} diff --git a/slsReceiverSoftware/src/HDF5File.cpp b/slsReceiverSoftware/src/HDF5File.cpp index ab17079ea..477922623 100644 --- a/slsReceiverSoftware/src/HDF5File.cpp +++ b/slsReceiverSoftware/src/HDF5File.cpp @@ -21,14 +21,14 @@ hid_t HDF5File::virtualfd = 0; -HDF5File::HDF5File(int ind, uint32_t maxf, const uint32_t* ppf, +HDF5File::HDF5File(int ind, uint32_t maxf, int* nd, char* fname, char* fpath, uint64_t* findex, bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno, uint32_t nx, uint32_t ny, bool* smode): - File(ind, maxf, ppf, nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr, portno, smode), + File(ind, maxf, nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr, portno, smode), filefd(0), dataspace(0), dataset(0), diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 57179a1b0..83a7d468d 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -117,6 +117,10 @@ int UDPStandardImplementation::setGapPixelsEnable(const bool b) { gapPixelsEnable = b; // side effects + generalData->SetGapPixelsEnable(b, dynamicRange); + // to update npixelsx, npixelsy in file writer + for (vector::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) + (*it)->SetPixelDimension(); numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure if (SetupFifoStructure() == FAIL) @@ -254,6 +258,10 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i) { //side effects generalData->SetDynamicRange(i,tengigaEnable); + generalData->SetGapPixelsEnable(gapPixelsEnable, dynamicRange); + // to update npixelsx, npixelsy in file writer + for (vector::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) + (*it)->SetPixelDimension(); numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure if (SetupFifoStructure() == FAIL) @@ -350,7 +358,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) { for ( int i=0; i < numThreads; ++i ) { listener.push_back(new Listener(myDetectorType, fifo[i], &status, &udpPortNum[i], eth, &activated, &numberOfFrames, &dynamicRange)); dataProcessor.push_back(new DataProcessor(fifo[i], &fileFormatType, - &fileWriteEnable, &dataStreamEnable, &frameToGuiFrequency, &frameToGuiTimerinMS, + &fileWriteEnable, &dataStreamEnable, &gapPixelsEnable, &dynamicRange, &frameToGuiFrequency, &frameToGuiTimerinMS, rawDataReadyCallBack,pRawDataReady)); if (Listener::GetErrorMask() || DataProcessor::GetErrorMask()) { FILE_LOG (logERROR) << "Error: Could not creates listener/dataprocessor threads (index:" << i << ")";