From e635ff035ca2d74e84d9d692248df86da3f3954a Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 14 Aug 2019 21:14:06 +0200 Subject: [PATCH] receiver master file includes quad, gap pixels enable, version updated for binary and hdf5, parallel, analog, digital, adc, dbitofset, dbitlist --- slsReceiverSoftware/include/BinaryFile.h | 13 +-- .../include/BinaryFileStatic.h | 67 ++++++++------- slsReceiverSoftware/include/DataProcessor.h | 11 +-- slsReceiverSoftware/include/File.h | 14 +--- slsReceiverSoftware/include/HDF5File.h | 13 +-- slsReceiverSoftware/include/HDF5FileStatic.h | 83 ++++++++++++------- slsReceiverSoftware/include/receiver_defs.h | 27 +++++- slsReceiverSoftware/src/BinaryFile.cpp | 9 +- slsReceiverSoftware/src/DataProcessor.cpp | 7 +- slsReceiverSoftware/src/HDF5File.cpp | 10 +-- .../src/slsReceiverImplementation.cpp | 28 ++++++- 11 files changed, 157 insertions(+), 125 deletions(-) diff --git a/slsReceiverSoftware/include/BinaryFile.h b/slsReceiverSoftware/include/BinaryFile.h index 1ac9ff8ab..6178d728c 100755 --- a/slsReceiverSoftware/include/BinaryFile.h +++ b/slsReceiverSoftware/include/BinaryFile.h @@ -58,19 +58,10 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi /** * Create master file * @param mfwenable master file write enable - * @param en ten giga enable - * @param size image size - * @param nx number of pixels in x direction - * @param ny number of pixels in y direction - * @param at acquisition time - * @param st sub exposure time - * @param sp sub period - * @param ap acquisition period + * @param attr master file attributes * @returns OK or FAIL */ - int CreateMasterFile(bool mfwenable, bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp, - uint64_t ap) override; + int CreateMasterFile(bool mfwenable, masterAttributes& attr) override; /** * Close Current File diff --git a/slsReceiverSoftware/include/BinaryFileStatic.h b/slsReceiverSoftware/include/BinaryFileStatic.h index 3fbd8c25a..132eb203d 100755 --- a/slsReceiverSoftware/include/BinaryFileStatic.h +++ b/slsReceiverSoftware/include/BinaryFileStatic.h @@ -97,26 +97,11 @@ class BinaryFileStatic { * @param fd pointer to file handle * @param fname master file name * @param owenable overwrite enable - * @param dr dynamic range - * @param tenE ten giga enable - * @param size image size - * @param nPixelsX number of pixels in x direction - * @param nPixelsY number of pixels in y direction - * @param nf number of images - * @param maxf maximum frames per file - * @param acquisitionTime acquisition time - * @param acquisitionPeriod acquisition period - * @param subexposuretime sub exposure time - * @param subperiod sub period - * @param version version of software for binary writing + * @param attr master file attributes * @returns 0 for success and 1 for fail */ static int CreateMasterDataFile(FILE*& fd, std::string fname, bool owenable, - uint32_t dr, bool tenE, uint32_t size, - uint32_t nPixelsX, uint32_t nPixelsY, uint64_t nf, - uint32_t maxf, - uint64_t acquisitionTime, uint64_t subexposuretime, - uint64_t subperiod, uint64_t acquisitionPeriod, double version) + masterAttributes& attr) { if(!owenable){ if (NULL == (fd = fopen((const char *) fname.c_str(), "wx"))){ @@ -135,17 +120,26 @@ class BinaryFileStatic { char message[MAX_MASTER_FILE_LENGTH]; sprintf(message, "Version : %.1f\n" + "Detector Type : %d\n" "Dynamic Range : %d\n" "Ten Giga : %d\n" "Image Size : %d bytes\n" - "row : %d pixels\n" - "col : %d pixels\n" - "Max. Frames Per File : %u\n" + "nPixelsX : %d pixels\n" + "nPixelsY : %d pixels\n" + "Max Frames Per File : %u\n" "Total Frames : %lld\n" "Exptime (ns) : %lld\n" "SubExptime (ns) : %lld\n" "SubPeriod(ns) : %lld\n" "Period (ns) : %lld\n" + "Gap Pixels Enable : %d\n" + "Quad Enable : %d\n" + "Parallel Flag : %d\n" + "Analog Flag : %d\n" + "Digital Flag : %d\n" + "ADC Mask : %d\n" + "Dbit Offset : %d\n" + "Dbit Bitset : %lld\n" "Timestamp : %s\n\n" "#Frame Header\n" @@ -164,18 +158,27 @@ class BinaryFileStatic { "Header Version : 1 byte\n" "Packets Caught Mask : 64 bytes\n" , - version, - dr, - tenE, - size, - nPixelsX, - nPixelsY, - maxf, - (long long int)nf, - (long long int)acquisitionTime, - (long long int)subexposuretime, - (long long int)subperiod, - (long long int)acquisitionPeriod, + attr.version, + attr.detectorType, + attr.dynamicRange, + attr.tenGiga, + attr.imageSize, + attr.nPixelsX, + attr.nPixelsY, + attr.maxFramesPerFile, + (long long int)attr.totalFrames, + (long long int)attr.exptimeNs, + (long long int)attr.subExptimeNs, + (long long int)attr.subPeriodNs, + (long long int)attr.periodNs, + attr.gapPixelsEnable, + attr.quadEnable, + attr.parallelFlag, + attr.analogFlag, + attr.digitalFlag, + attr.adcmask, + attr.dbitoffset, + (long long int)attr.dbitlist, ctime(&t)); if (strlen(message) > MAX_MASTER_FILE_LENGTH) { FILE_LOG(logERROR) << "Master File Size " << strlen(message) << diff --git a/slsReceiverSoftware/include/DataProcessor.h b/slsReceiverSoftware/include/DataProcessor.h index 9c5febfdb..d4fc0ef71 100755 --- a/slsReceiverSoftware/include/DataProcessor.h +++ b/slsReceiverSoftware/include/DataProcessor.h @@ -10,6 +10,7 @@ */ #include "ThreadObject.h" +#include "receiver_defs.h" class GeneralData; class Fifo; @@ -175,16 +176,10 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { /** * Create New File - * @param en ten giga enable - * @param nf number of frames - * @param at acquisition time - * @param st sub exposure time - * @param sp sub period - * @param ap acquisition period + * @param attr master file attributes * @returns OK or FAIL */ - int CreateNewFile(bool en, uint64_t nf, uint64_t at, uint64_t st, - uint64_t sp, uint64_t ap); + int CreateNewFile(masterAttributes& attr); /** * Closes files diff --git a/slsReceiverSoftware/include/File.h b/slsReceiverSoftware/include/File.h index 2a0dfb761..02a43c8e0 100755 --- a/slsReceiverSoftware/include/File.h +++ b/slsReceiverSoftware/include/File.h @@ -10,6 +10,7 @@ #include "sls_detector_defs.h" #include "logger.h" +#include "receiver_defs.h" #include @@ -109,19 +110,10 @@ class File : private virtual slsDetectorDefs { /** * Create master file * @param mfwenable master file write enable - * @param en ten giga enable - * @param size image size - * @param nx number of pixels in x direction - * @param ny number of pixels in y direction - * @param at acquisition time - * @param st sub exposure time - * @param sp sub period - * @param ap acquisition period + * @param attr master file attributes * @returns OK or FAIL */ - virtual int CreateMasterFile(bool mfwenable, bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, - uint64_t sp, uint64_t ap) = 0; + virtual int CreateMasterFile(bool mfwenable, masterAttributes& attr) = 0; // HDf5 specific /** diff --git a/slsReceiverSoftware/include/HDF5File.h b/slsReceiverSoftware/include/HDF5File.h index 0a93ed712..c3727109e 100755 --- a/slsReceiverSoftware/include/HDF5File.h +++ b/slsReceiverSoftware/include/HDF5File.h @@ -94,19 +94,10 @@ class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileSt /** * Create master file * @param mfwenable master file write enable - * @param en ten giga enable - * @param size image size - * @param nx number of pixels in x direction - * @param ny number of pixels in y direction - * @param at acquisition time - * @param st sub exposure time - * @param sp sub period - * @param ap acquisition period + * @param attr master file attributes * @returns OK or FAIL */ - int CreateMasterFile(bool mfwenable, bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp, - uint64_t ap); + int CreateMasterFile(bool mfwenable, masterAttributes& attr); /** * End of Acquisition diff --git a/slsReceiverSoftware/include/HDF5FileStatic.h b/slsReceiverSoftware/include/HDF5FileStatic.h index fc771ab99..d7f0ca915 100755 --- a/slsReceiverSoftware/include/HDF5FileStatic.h +++ b/slsReceiverSoftware/include/HDF5FileStatic.h @@ -291,26 +291,11 @@ public: * Create master file * @param fname master file name * @param owenable overwrite enable - * @param dr dynamic range - * @param tenE ten giga enable - * @param size image size - * @param nx number of pixels in x direction - * @param ny number of pixels in y direction - * @param nf number of images - * @param maxf maximum frames per file - * @param acquisitionTime acquisition time - * @param subexposuretime sub exposure time - * @param subperiod sub period - * @param acquisitionPeriod acquisition period - * @param version version of software for hdf5 writing + * @param attr master file attributes * @returns 0 for success and 1 for fail */ static int CreateMasterDataFile(H5File*& fd, std::string fname, bool owenable, - uint32_t dr, bool tenE, uint32_t size, - uint32_t nPixelsx, uint32_t nPixelsy, uint64_t nf, - uint32_t maxf, - uint64_t acquisitionTime, uint64_t subexposuretime, - uint64_t subperiod, uint64_t acquisitionPeriod, double version) + masterAttributes& attr) { try { Exception::dontPrint(); //to handle errors @@ -337,7 +322,7 @@ public: //create attributes //version - dValue=version; + dValue = attr.version; attribute = fd->createAttribute("version",PredType::NATIVE_DOUBLE, dataspace); attribute.write(PredType::NATIVE_DOUBLE, &dValue); @@ -351,61 +336,101 @@ public: //Dynamic Range dataset = group5.createDataSet ( "dynamic range", PredType::NATIVE_INT, dataspace ); - dataset.write ( &dr, PredType::NATIVE_INT); + dataset.write ( &(attr.dynamicRange), PredType::NATIVE_INT); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("bits")); //Ten Giga - iValue = tenE; + iValue = attr.tenGiga; dataset = group5.createDataSet ( "ten giga enable", PredType::NATIVE_INT, dataspace ); dataset.write ( &iValue, PredType::NATIVE_INT); //Image Size dataset = group5.createDataSet ( "image size", PredType::NATIVE_INT, dataspace ); - dataset.write ( &size, PredType::NATIVE_INT); + dataset.write ( &(attr.imageSize), PredType::NATIVE_INT); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("bytes")); //x dataset = group5.createDataSet ( "number of pixels in x axis", PredType::NATIVE_INT, dataspace ); - dataset.write ( &nPixelsx, PredType::NATIVE_INT); + dataset.write ( &(attr.nPixelsX), PredType::NATIVE_INT); //y dataset = group5.createDataSet ( "number of pixels in y axis", PredType::NATIVE_INT, dataspace ); - dataset.write ( &nPixelsy, PredType::NATIVE_INT); + dataset.write ( &(attr.nPixelsY), PredType::NATIVE_INT); //Maximum frames per file dataset = group5.createDataSet ( "maximum frames per file", PredType::NATIVE_INT, dataspace ); - dataset.write ( &maxf, PredType::NATIVE_INT); + dataset.write ( &(attr.maxFramesPerFile), PredType::NATIVE_INT); //Total Frames dataset = group5.createDataSet ( "total frames", PredType::STD_U64LE, dataspace ); - dataset.write ( &nf, PredType::STD_U64LE); + dataset.write ( &(attr.totalFrames), PredType::STD_U64LE); //Exptime dataset = group5.createDataSet ( "exposure time", PredType::STD_U64LE, dataspace ); - dataset.write ( &acquisitionTime, PredType::STD_U64LE); + dataset.write ( &(attr.exptimeNs), PredType::STD_U64LE); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("ns")); //SubExptime dataset = group5.createDataSet ( "sub exposure time", PredType::STD_U64LE, dataspace ); - dataset.write ( &subexposuretime, PredType::STD_U64LE); + dataset.write ( &(attr.subExptimeNs), PredType::STD_U64LE); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("ns")); //SubPeriod dataset = group5.createDataSet ( "sub period", PredType::STD_U64LE, dataspace ); - dataset.write ( &subperiod, PredType::STD_U64LE); + dataset.write ( &(attr.subPeriodNs), PredType::STD_U64LE); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("ns")); //Period dataset = group5.createDataSet ( "acquisition period", PredType::STD_U64LE, dataspace ); - dataset.write ( &acquisitionPeriod, PredType::STD_U64LE); + dataset.write ( &(attr.periodNs), PredType::STD_U64LE); attribute = dataset.createAttribute("unit",strdatatype, dataspace); attribute.write(strdatatype, std::string("ns")); + //Gap Pixels Enable + dataset = group5.createDataSet ( "gap pixels enable", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.gapPixelsEnable), PredType::NATIVE_INT); + + //Quad Enable + dataset = group5.createDataSet ( "quad enable", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.quadEnable), PredType::NATIVE_INT); + + //Gap Pixels Enable + dataset = group5.createDataSet ( "gap pixels enable", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.gapPixelsEnable), PredType::NATIVE_INT); + + //Quad Enable + dataset = group5.createDataSet ( "quad enable", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.quadEnable), PredType::NATIVE_INT); + + //Parallel Flag + dataset = group5.createDataSet ( "parallel flag", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.gapPixelsEnable), PredType::NATIVE_INT); + + //Analog Flag + dataset = group5.createDataSet ( "analog flag", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.quadEnable), PredType::NATIVE_INT); + + //Digital Flag + dataset = group5.createDataSet ( "digital flag", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.gapPixelsEnable), PredType::NATIVE_INT); + + //ADC Mask + dataset = group5.createDataSet ( "adc mask", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.quadEnable), PredType::NATIVE_INT); + + //Dbit Offset + dataset = group5.createDataSet ( "dbit offset", PredType::NATIVE_INT, dataspace ); + dataset.write ( &(attr.gapPixelsEnable), PredType::NATIVE_INT); + + // Dbit List + dataset = group5.createDataSet ( "dbit bitset list", PredType::STD_U64LE, dataspace ); + dataset.write ( &(attr.periodNs), PredType::STD_U64LE); + //Timestamp time_t t = time(0); dataset = group5.createDataSet ( "timestamp", strdatatype, dataspace ); diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index d1d004f87..2122ac88e 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -30,8 +30,8 @@ #define MAX_CHUNKED_IMAGES (1) //versions -#define HDF5_WRITER_VERSION (3.0) //1 decimal places -#define BINARY_WRITER_VERSION (3.0) //1 decimal places +#define HDF5_WRITER_VERSION (5.0) //1 decimal places +#define BINARY_WRITER_VERSION (5.0) //1 decimal places //parameters to calculate fifo depth @@ -49,3 +49,26 @@ #define STREAMER_PRIORITY (10) #define TCP_PRIORITY (10) +struct masterAttributes { + double version; + uint32_t detectorType; + uint32_t dynamicRange; + uint32_t tenGiga; + uint32_t imageSize; + uint32_t nPixelsX; + uint32_t nPixelsY; + uint32_t maxFramesPerFile; + uint64_t totalFrames; + uint64_t exptimeNs; + uint64_t subExptimeNs; + uint64_t subPeriodNs; + uint64_t periodNs; + uint32_t gapPixelsEnable; + uint32_t quadEnable; + uint32_t parallelFlag; + uint32_t analogFlag; + uint32_t digitalFlag; + uint32_t adcmask; + uint32_t dbitoffset; + uint64_t dbitlist; + }; \ No newline at end of file diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index 24923a9e9..78caee98f 100755 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -114,9 +114,7 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_ } -int BinaryFile::CreateMasterFile(bool mfwenable, bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp, - uint64_t ap) { +int BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) { //beginning of every acquisition numFramesInFile = 0; numActualPacketsInFile = 0; @@ -127,10 +125,9 @@ int BinaryFile::CreateMasterFile(bool mfwenable, bool en, uint32_t size, if(!(*silentMode)) { FILE_LOG(logINFO) << "Master File: " << masterFileName; } + attr.version = BINARY_WRITER_VERSION; return BinaryFileStatic::CreateMasterDataFile(masterfd, masterFileName, - *overWriteEnable, - *dynamicRange, en, size, nx, ny, *numImages, *maxFramesPerFile, - at, st, sp, ap, BINARY_WRITER_VERSION); + *overWriteEnable, attr); } return OK; } diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 766a3d72e..d9cd81f13 100755 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -248,15 +248,12 @@ void DataProcessor::SetupFileWriter(bool fwe, int* nd, uint32_t* maxf, } // only the first file -int DataProcessor::CreateNewFile(bool en, uint64_t nf, uint64_t at, uint64_t st, - uint64_t sp, uint64_t ap) { +int DataProcessor::CreateNewFile(masterAttributes& attr) { if (file == nullptr) return FAIL; file->CloseAllFiles(); file->resetSubFileIndex(); - if (file->CreateMasterFile(*masterFileWriteEnable, en, generalData->imageSize, - generalData->nPixelsX, generalData->nPixelsY, - at, st, sp, ap) == FAIL) + if (file->CreateMasterFile(*masterFileWriteEnable, attr) == FAIL) return FAIL; if (file->CreateFile() == FAIL) return FAIL; diff --git a/slsReceiverSoftware/src/HDF5File.cpp b/slsReceiverSoftware/src/HDF5File.cpp index c462a8520..ec1b07982 100755 --- a/slsReceiverSoftware/src/HDF5File.cpp +++ b/slsReceiverSoftware/src/HDF5File.cpp @@ -240,9 +240,7 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t } -int HDF5File::CreateMasterFile(bool mfwenable, bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t st, uint64_t sp, - uint64_t ap) { +int HDF5File::CreateMasterFile(bool mfwenable, masterAttributes& attr) { //beginning of every acquisition numFramesInFile = 0; @@ -257,11 +255,9 @@ int HDF5File::CreateMasterFile(bool mfwenable, bool en, uint32_t size, FILE_LOG(logINFO) << "Master File: " << masterFileName; } pthread_mutex_lock(&Mutex); + attr.version = HDF5_WRITER_VERSION; int ret = HDF5FileStatic::CreateMasterDataFile(masterfd, masterFileName, - *overWriteEnable, - *dynamicRange, en, size, nx, ny, *numImages, *maxFramesPerFile, - at, st, sp, ap, - HDF5_WRITER_VERSION); + *overWriteEnable, attr); pthread_mutex_unlock(&Mutex); return ret; } diff --git a/slsReceiverSoftware/src/slsReceiverImplementation.cpp b/slsReceiverSoftware/src/slsReceiverImplementation.cpp index a77b40da8..65bd9c989 100755 --- a/slsReceiverSoftware/src/slsReceiverImplementation.cpp +++ b/slsReceiverSoftware/src/slsReceiverImplementation.cpp @@ -1647,10 +1647,32 @@ int slsReceiverImplementation::CreateUDPSockets() { int slsReceiverImplementation::SetupWriter() { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; bool error = false; + masterAttributes attr; + attr.detectorType = myDetectorType; + attr.dynamicRange = dynamicRange; + attr.tenGiga = tengigaEnable; + attr.imageSize = generalData->imageSize; + attr.nPixelsX = generalData->nPixelsX; + attr.nPixelsY = generalData->nPixelsY; + attr.maxFramesPerFile = framesPerFile; + attr.totalFrames = numberOfFrames; + attr.exptimeNs = acquisitionTime; + attr.subExptimeNs = subExpTime; + attr.subPeriodNs = subPeriod; + attr.periodNs = acquisitionPeriod; + attr.gapPixelsEnable = gapPixelsEnable; + attr.quadEnable = quadEnable; + attr.parallelFlag = (readoutFlags & PARALLEL) ? 1 : 0; + attr.analogFlag = (readoutFlags == NORMAL_READOUT || readoutFlags & ANALOG_AND_DIGITAL) ? 1 : 0; + attr.digitalFlag = (readoutFlags & DIGITAL_ONLY || readoutFlags & ANALOG_AND_DIGITAL) ? 1 : 0; + attr.adcmask = adcEnableMask; + attr.dbitoffset = ctbDbitOffset; + attr.dbitlist = 0; + for (auto &i : ctbDbitList) { + attr.dbitlist |= (1 << i); + } for (unsigned int i = 0; i < dataProcessor.size(); ++i) - if (dataProcessor[i]->CreateNewFile( - tengigaEnable, numberOfFrames, acquisitionTime, subExpTime, - subPeriod, acquisitionPeriod) == FAIL) { + if (dataProcessor[i]->CreateNewFile(attr) == FAIL) { error = true; break; }