diff --git a/slsReceiverSoftware/include/BinaryFile.h b/slsReceiverSoftware/include/BinaryFile.h index f8b5ab223..7b6e8e0b7 100644 --- a/slsReceiverSoftware/include/BinaryFile.h +++ b/slsReceiverSoftware/include/BinaryFile.h @@ -1,20 +1,19 @@ +#pragma once /************************************************ * @file BinaryFile.h * @short sets/gets properties for the binary file, * creates/closes the file and writes data to it ***********************************************/ -#ifndef BINARY_FILE_H -#define BINARY_FILE_H /** *@short sets/gets properties for the binary file, creates/closes the file and writes data to it */ - #include "File.h" +#include "BinaryFileStatic.h" #include -class BinaryFile : private virtual slsReceiverDefs, public File { +class BinaryFile : private virtual slsReceiverDefs, public File, public BinaryFileStatic { public: /** @@ -27,14 +26,15 @@ class BinaryFile : private virtual slsReceiverDefs, public File { * @param findex pointer to file index * @param frindexenable pointer to frame index enable * @param owenable pointer to over write enable + * @param maxf max frames per file * @param dindex pointer to detector index * @param nunits pointer to number of theads/ units per detector * @param nf pointer to number of frames * @param dr dynamic range - * @param maxf max frames per file */ BinaryFile(int ind, 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 maxf); + bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, + uint64_t* nf, uint32_t* dr); /** * Destructor @@ -46,12 +46,6 @@ class BinaryFile : private virtual slsReceiverDefs, public File { */ void PrintMembers(); - /** - * Set Max frames per file - * @param maxf maximum frames per file - */ - void SetMaxFramesPerFile(uint32_t maxf); - /** * Create file * @param fnum current frame index to include in file name @@ -59,6 +53,19 @@ class BinaryFile : private virtual slsReceiverDefs, public File { */ int CreateFile(uint64_t fnum); + /** + * Create master file + * @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 ap acquisition period + * @returns OK or FAIL + */ + int CreateMasterFile(bool en, uint32_t size, + uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap); + /** * Close Current File */ @@ -78,59 +85,6 @@ class BinaryFile : private virtual slsReceiverDefs, public File { */ int WriteToFile(char* buffer, int buffersize, uint64_t fnum); - /** - * Create File Name in format fpath/fnameprefix_fx_dy_z.raw, - * where x is fnum, y is (dindex * numunits + unitindex) and z is findex - * @param fpath file path - * @param fnameprefix file name prefix (includes scan and position variables) - * @param findex file index - * @param frindexenable frame index enable - * @param fnum frame number index - * @param dindex readout index - * @param numunits number of units per readout. eg. eiger has 2 udp units per readout - * @param unitindex unit index - * @returns complete file name created - */ - static std::string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable, - uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0); - - /** - * Create File - * @param fd file pointer - * @param owenable overwrite enable - * @param fname complete file name - * @returns OK or FAIL - */ - static int CreateDataFile(FILE*& fd, bool owenable, std::string fname); - - /** - * Close File - * @param fd file pointer - */ - static void CloseDataFile(FILE*& fd); - - /** - * Write data to file - * @param fd file pointer - * @param buf buffer to write from - * @param bsize size of buffer - * @param fnum current image number - * @returns number of elements written - */ - static int WriteDataFile(FILE* fd, char* buf, int bsize, uint64_t fnum); - - /** - * Create master file - * @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 ap acquisition period - * @returns OK or FAIL - */ - int CreateMasterFile(bool en, uint32_t size, - uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap); private: @@ -141,38 +95,7 @@ class BinaryFile : private virtual slsReceiverDefs, public File { */ fileFormat GetFileType(); - /** - * Create file names for master file - * @param fpath file path - * @param fnameprefix file name prefix (includes scan and position variables) - * @param findex file index - */ - void CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex); - /* - * Close master file - */ - void CloseMasterDataFile(); - - /** - * Create master files - * @param owenable overwrite enable - * @param tengigaEnable ten giga enable - * @param imageSize image size - * @param nPixelsX number of pixels in x direction - * @param nPixelsY number of pixels in y direction - * @param acquisitionTime acquisition time - * @param acquisitionPeriod acquisition period - * @returns OK or FAIL - */ - int CreateMasterDataFile(bool owenable, - bool tengigaEnable, uint32_t imageSize, uint32_t nPixelsX, uint32_t nPixelsY, - uint64_t acquisitionTime, uint64_t acquisitionPeriod); - - - - /** Maximum frames per file */ - uint32_t maxFramesPerFile; /** File Descriptor */ FILE* filefd; @@ -180,6 +103,8 @@ class BinaryFile : private virtual slsReceiverDefs, public File { /** Master File Descriptor */ static FILE* masterfd; + /** Number of frames in file */ + uint32_t numFramesInFile; + }; -#endif diff --git a/slsReceiverSoftware/include/BinaryFileStatic.h b/slsReceiverSoftware/include/BinaryFileStatic.h new file mode 100644 index 000000000..5cbc2b8ce --- /dev/null +++ b/slsReceiverSoftware/include/BinaryFileStatic.h @@ -0,0 +1,193 @@ +#pragma once +/************************************************ + * @file BinaryFileStatic.h + * @short creating, closing, writing and reading + * from binary files + ***********************************************/ +/** + *@short creating, closing, writing and reading from binary files + */ + + +#include "ansi.h" + +#include +#include +#include +using namespace std; + + +class BinaryFileStatic { + + public: + + /** Constructor */ + BinaryFileStatic(){}; + /** Destructor */ + virtual ~BinaryFileStatic(){}; + + /** + * Create File Name in format fpath/fnameprefix_fx_dy_z.raw, + * where x is fnum, y is (dindex * numunits + unitindex) and z is findex + * @param fpath file path + * @param fnameprefix file name prefix (includes scan and position variables) + * @param findex file index + * @param frindexenable frame index enable + * @param fnum frame number index + * @param dindex readout index + * @param numunits number of units per readout. eg. eiger has 2 udp units per readout + * @param unitindex unit index + * @returns complete file name created + */ + static std::string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable, + uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0) + { + ostringstream osfn; + osfn << fpath << "/" << fnameprefix; + if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex); + if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum; + osfn << "_" << findex; + osfn << ".raw"; + return osfn.str(); + } + + /** + * Create file names for master file + * @param fpath file path + * @param fnameprefix file name prefix (includes scan and position variables) + * @param findex file index + * @returns master file name + */ + string CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex) + { + ostringstream osfn; + osfn << fpath << "/" << fnameprefix; + osfn << "_master"; + osfn << "_" << findex; + osfn << ".raw"; + return osfn.str(); + } + + /** + * Close File + * @param fd file pointer + */ + static void CloseDataFile(FILE*& fd) + { + if (fd) + fclose(fd); + fd = 0; + } + + /** + * Write data to file + * @param fd file pointer + * @param buf buffer to write from + * @param bsize size of buffer + * @param fnum current image number + * @returns number of elements written + */ + static int WriteDataFile(FILE* fd, char* buf, int bsize, uint64_t fnum) + { + if (!fd) + return 0; + return fwrite(buf, 1, bsize, fd); + } + + + /** + * Create master files + * @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 acquisitionTime acquisition time + * @param acquisitionPeriod acquisition period + * @param version version of software for binary writing + * @returns 0 for success and 1 for fail + */ + static int CreateMasterDataFile(FILE*& fd, string fname, bool owenable, + uint32_t dr, bool tenE, uint32_t size, uint32_t nPixelsX, uint32_t nPixelsY, uint64_t nf, + uint64_t acquisitionTime, uint64_t acquisitionPeriod, double version) + { + if(!owenable){ + if (NULL == (fd = fopen((const char *) fname.c_str(), "wx"))){ + cprintf(RED,"Error in creating binary master file %s\n",fname.c_str()); + fd = 0; + return 1; + } + }else if (NULL == (fd = fopen((const char *) fname.c_str(), "w"))){ + cprintf(RED,"Error in creating binary master file %s\n",fname.c_str()); + fd = 0; + return 1; + } + time_t t = time(0); + char message[MAX_STR_LENGTH]; + sprintf(message, + "Version\t\t: %.1f\n" + "Dynamic Range\t: %d\n" + "Ten Giga\t: %d\n" + "Image Size\t: %d bytes\n" + "x\t\t: %d pixels\n" + "y\t\t: %d pixels\n" + "Total Frames\t: %lld\n" + "Exptime (ns)\t: %lld\n" + "Period (ns)\t: %lld\n" + "Timestamp\t: %s\n\n", + version, + dr, + tenE, + size, + nPixelsX, + nPixelsY, + (long long int)nf, + (long long int)acquisitionTime, + (long long int)acquisitionPeriod, + ctime(&t)); + if (strlen(message) > MAX_STR_LENGTH) { + cprintf(BG_RED,"Master File Size %d is greater than max str size %d\n", + (int)strlen(message), MAX_STR_LENGTH); + return 1; + } + + if (fwrite((void*)message, 1, strlen(message), fd) != strlen(message)) + return 1; + + BinaryFileStatic::CloseDataFile(fd); + return 0; + } + + + /** + * Create File + * @param fd file pointer + * @param owenable overwrite enable + * @param fname complete file name + * @param filebuffersize file buffer size + * @returns 0 for success and 1 for fail + */ + static int CreateDataFile(FILE*& fd, bool owenable, std::string fname, size_t filebuffersize) + { + if(!owenable){ + if (NULL == (fd = fopen((const char *) fname.c_str(), "wx"))){ + FILE_LOG(logERROR) << "Could not create/overwrite file" << fname; + fd = 0; + return 1; + } + }else if (NULL == (fd = fopen((const char *) fname.c_str(), "w"))){ + FILE_LOG(logERROR) << "Could not create file" << fname; + fd = 0; + return 1; + } + //setting file buffer size to 16mb + setvbuf(fd,NULL,_IOFBF,filebuffersize); + return 0; + } + +}; + diff --git a/slsReceiverSoftware/include/DataProcessor.h b/slsReceiverSoftware/include/DataProcessor.h index c0359f557..0a9f5a5e1 100644 --- a/slsReceiverSoftware/include/DataProcessor.h +++ b/slsReceiverSoftware/include/DataProcessor.h @@ -1,11 +1,10 @@ +#pragma once /************************************************ * @file DataProcessor.h * @short creates data processor thread that * pulls pointers to memory addresses from fifos * and processes data stored in them & writes them to file ***********************************************/ -#ifndef DATAPROCESSOR_H -#define DATAPROCESSOR_H /** *@short creates & manages a data processor thread each */ @@ -165,7 +164,6 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject { void CloseFiles(); - void CreateFinalFile(); private: @@ -301,4 +299,3 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject { }; -#endif diff --git a/slsReceiverSoftware/include/DataStreamer.h b/slsReceiverSoftware/include/DataStreamer.h index ef1936e04..b8a748771 100644 --- a/slsReceiverSoftware/include/DataStreamer.h +++ b/slsReceiverSoftware/include/DataStreamer.h @@ -1,9 +1,8 @@ +#pragma once /************************************************ * @file DataStreamer.h * @short streams data from receiver via ZMQ ***********************************************/ -#ifndef DATASTREAMER_H -#define DATASTREAMER_H /** *@short creates & manages a data streamer thread each */ @@ -87,4 +86,3 @@ class DataStreamer : private virtual slsReceiverDefs, public ThreadObject { static pthread_mutex_t Mutex; }; -#endif diff --git a/slsReceiverSoftware/include/Fifo.h b/slsReceiverSoftware/include/Fifo.h index 180aaa6b9..de627472e 100644 --- a/slsReceiverSoftware/include/Fifo.h +++ b/slsReceiverSoftware/include/Fifo.h @@ -1,11 +1,10 @@ +#pragma once /************************************************ * @file Fifo.h * @short constructs the fifo structure * which is a circular buffer with pointers to * parts of allocated memory ***********************************************/ -#ifndef FIFO_H -#define FIFO_H /** *@short constructs the fifo structure */ @@ -84,5 +83,3 @@ class Fifo : private virtual slsReceiverDefs { CircularFifo* fifoFree; }; - -#endif diff --git a/slsReceiverSoftware/include/File.h b/slsReceiverSoftware/include/File.h index 08d08828b..3d4d8d21e 100644 --- a/slsReceiverSoftware/include/File.h +++ b/slsReceiverSoftware/include/File.h @@ -1,10 +1,9 @@ +#pragma once /************************************************ * @file File.h * @short sets/gets properties for the file, * creates/closes the file and writes data to it ***********************************************/ -#ifndef FILE_H -#define FILE_H /** *@short sets/gets properties for the file, creates/closes the file and writes data to it */ @@ -28,13 +27,14 @@ class File : private virtual slsReceiverDefs { * @param findex pointer to file index * @param frindexenable pointer to frame index enable * @param owenable pointer to over write enable + * @param maxf max frames per file * @param dindex pointer to detector index * @param nunits pointer to number of theads/ units per detector * @param nf pointer to number of images in acquisition * @param dr dynamic range */ File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, - bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr); + bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr); /** * Destructor @@ -74,6 +74,12 @@ class File : private virtual slsReceiverDefs { void GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t*& findex, bool*& frindexenable, bool*& owenable, int*& dindex, int*& nunits, uint64_t*& nf, uint32_t*& dr); + /** + * Set Max frames per file + * @param maxf maximum frames per file + */ + void SetMaxFramesPerFile(uint32_t maxf); + /** * Create file * @param fnum current frame index to include in file name @@ -125,16 +131,6 @@ class File : private virtual slsReceiverDefs { return OK; } - - // Binary specific - /** - * Set Max frames per file - * @param maxf maximum frames per file - */ - virtual void SetMaxFramesPerFile(uint32_t maxf) { - cprintf(RED,"This is a generic function SetMaxFramesPerFile that should be overloaded by a derived class\n"); - } - // HDf5 specific /** * Set Number of pixels @@ -145,9 +141,7 @@ class File : private virtual slsReceiverDefs { cprintf(RED,"This is a generic function SetNumberofPixels that should be overloaded by a derived class\n"); } - virtual void CreateFinalFile(){ - ; - } + protected: @@ -184,6 +178,9 @@ class File : private virtual slsReceiverDefs { /** Over write enable */ bool* overWriteEnable; + /** Maximum frames per file */ + uint32_t maxFramesPerFile; + /** Detector Index */ int* detIndex; @@ -200,4 +197,3 @@ class File : private virtual slsReceiverDefs { std::string currentFileName; }; -#endif diff --git a/slsReceiverSoftware/include/GeneralData.h b/slsReceiverSoftware/include/GeneralData.h index 5c6edf908..15b38e7dd 100644 --- a/slsReceiverSoftware/include/GeneralData.h +++ b/slsReceiverSoftware/include/GeneralData.h @@ -1,9 +1,8 @@ +#pragma once /************************************************ * @file GeneralData.h * @short abstract for setting/getting properties of detector data ***********************************************/ -#ifndef GENERAL_DATA_H -#define GENERAL_DATA_H /** *@short abstract for setting/getting properties of detector data */ @@ -429,7 +428,7 @@ private: packetsPerFrame = 256; imageSize = dataSize*packetsPerFrame; frameIndexMask = 0xffffff; - maxFramesPerFile = EIGER_MAX_FRAMES_PER_FILE; + maxFramesPerFile = 5;//EIGER_MAX_FRAMES_PER_FILE; fifoBufferSize = imageSize; fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + FILE_FRAME_HEADER_SIZE; defaultFifoDepth = 100; @@ -511,5 +510,3 @@ private: } }; - -#endif diff --git a/slsReceiverSoftware/include/HDF5File.h b/slsReceiverSoftware/include/HDF5File.h index d0f84784c..85dd99363 100644 --- a/slsReceiverSoftware/include/HDF5File.h +++ b/slsReceiverSoftware/include/HDF5File.h @@ -1,18 +1,17 @@ +#ifdef HDF5C +#pragma once /************************************************ * @file HDF5File.h * @short sets/gets properties for the HDF5 file, * creates/closes the file and writes data to it ***********************************************/ -//#define HDF5C -//#ifdef HDF5C -#ifndef HDF5_FILE_H -#define HDF5_FILE_H /** *@short sets/gets properties for the HDF5 file, creates/closes the file and writes data to it */ #include "File.h" +#include "HDF5FileStatic.h" #include "H5Cpp.h" #ifndef H5_NO_NAMESPACE using namespace H5; @@ -20,7 +19,7 @@ #include -class HDF5File : private virtual slsReceiverDefs, public File { +class HDF5File : private virtual slsReceiverDefs, public File, public HDF5FileStatic { public: /** @@ -33,6 +32,7 @@ class HDF5File : private virtual slsReceiverDefs, public File { * @param findex pointer to file index * @param frindexenable pointer to frame index enable * @param owenable pointer to over write enable + * @param maxf max frames per file * @param dindex pointer to detector index * @param nunits pointer to number of theads/ units per detector * @param nf pointer to number of frames @@ -41,8 +41,8 @@ class HDF5File : private virtual slsReceiverDefs, public File { * @param ny number of pixels in y direction */ HDF5File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, - bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, - int nx, int ny); + bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, + uint32_t nx, uint32_t ny); /** * Destructor @@ -100,169 +100,13 @@ class HDF5File : private virtual slsReceiverDefs, public File { int CreateMasterFile(bool en, uint32_t size, uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap); - - - - //*** static functions *** - - /** - * Create File Name in format fpath/fnameprefix_fx_dy_z.raw, - * where x is fnum, y is (dindex * numunits + unitindex) and z is findex - * @param fpath file path - * @param fnameprefix file name prefix (includes scan and position variables) - * @param findex file index - * @param frindexenable frame index enable - * @param fnum frame number index - * @param dindex readout index - * @param numunits number of units per readout. eg. eiger has 2 udp units per readout - * @param unitindex unit index - * @returns complete file name created - */ - static std::string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable, - uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0); - - /** - * Create master file name - * @param fpath file path - * @param fnameprefix file name prefix (includes scan and position variables) - * @param findex file index - * @returns master file name - */ - static std::string CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex); - - /** - * Create virtual file name - * @param fpath file path - * @param fnameprefix file name prefix (includes scan and position variables) - * @param fnum current frame number - * @param findex file index - * @param frindexenable frame index enable - * @param fnum frame number index - * @returns virtual file name - */ - static std::string CreateVirtualFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable, - uint64_t fnum); - - /** - * Close File - * @param ind index for debugging - * @param fd file pointer - * @param dp dataspace pointer - * @param ds dataset pointer - */ - - static void CloseDataFile(int ind, H5File*& fd, DataSpace*& dp, DataSet*& ds); - - /* - * Close master file - */ - void CloseMasterDataFile(); - - /* - * Close virtual file - */ - void CloseVirtualDataFile(); - - /** - * Write data to file - * @param ind object index for debugging - * @param buf buffer to write from - * @param numImages number of images - * @param nx number of pixels in x direction - * @param ny number of pixels in y direction - * @param fnum current image number - * @param dspace dataspace pointer - * @param dset dataset pointer - * @param dtype datatype - * @returns OK or FAIL - */ - static int WriteDataFile(int ind, char* buf, uint64_t numImages, int nx, int ny, uint64_t fnum, - DataSpace* dspace, DataSet* dset, DataType dtype); - - /** - * 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 acquisitionTime acquisition time - * @param acquisitionPeriod acquisition period - * @returns OK or FAIL - */ - int CreateMasterDataFile(std::string fname, bool owenable, - uint32_t dr, bool tenE, uint32_t size, uint32_t nx, uint32_t ny, uint64_t nf, - uint64_t acquisitionTime, uint64_t acquisitionPeriod); - /** * Create Virtual File * @param fnum frame number */ int CreateVirtualFile(uint64_t fnum); - /** - * Create File - * @param ind object index for debugging - * @param owenable overwrite enable - * @param numf number of images - * @param fname complete file name - * @param frindexenable frame index enable - * @param fnum current image number - * @param nx number of pixels in x dir - * @param ny number of pixels in y dir - * @param dtype data type - * @param fd file pointer - * @param dspace dataspace pointer - * @param dset dataset pointer - * @returns OK or FAIL - */ - static int CreateDataFile(int ind, bool owenable, uint64_t numf, std::string fname, bool frindexenable, uint64_t fnum, int nx, int ny, - DataType dtype, H5File*& fd, DataSpace*& dspace, DataSet*& dset); - /** - * Create virtual file - * @param virtualfname virtual file name - * @param virtualDatasetname virtual dataset name - * @param srcDatasetname source dataset name - * @param numFiles number of files - * @param fileNames array of file names - * @param owenable overwrite enable - * @param fnum current frame number - * @param dtype datatype - * @param srcNDimx source number of objects in x dimension (Number of images) - * @param srcNDimy source number of objects in y dimension (Number of pixels in y dir) - * @param srcNDimz source number of objects in z dimension (Number of pixels in x dir) - * @param dstNDimx destination number of objects in x dimension (Number of images) - * @param dstNDimy destination number of objects in y dimension (Number of pixels in y dir) - * @param dstNDimz destination number of objects in z dimension (Number of pixels in x dir) - * @returns OK or FAIL - */ - static int CreateVirtualDataFile(std::string virtualfname, std::string virtualDatasetname, std::string srcDatasetname, - int numFiles, std::string fileNames[], bool owenable, uint64_t fnum, hid_t dtype, - int srcNDimx, int srcNDimy, int srcNDimz, int dstNDimx, int dstNDimy, int dstNDimz); - - /** - * Copy file to another file (mainly to view virutal files in hdfviewer) - * @param owenable overwrite enable - * @param oldFileName file name including path of file to copy - * @param oldDatasetName dataset name to copy - * @param newFileName file name including path of file to copy to - * @param newDatasetName dataset name to copy to - * @param nDimx Number of objects in x dimension - * @param nDimy Number of objects in y dimension - * @param nDimz Number of objects in z dimension - * @param dataType data type - * @returns OK or FAIL - */ - template - static int CopyVirtualFile(bool owenable, std::string oldFileName, std::string oldDatasetName, - std::string newFileName, std::string newDatasetName, int nDimx, int nDimy, int nDimz, T datatype); - - - void CreateFinalFile(); private: /** @@ -301,12 +145,13 @@ class HDF5File : private virtual slsReceiverDefs, public File { DataType datatype; /** Number of pixels in x direction */ - int nPixelsX; + uint32_t nPixelsX; /** Number of pixels in y direction */ - int nPixelsY; + uint32_t nPixelsY; + + /** Number of frames in file */ + uint32_t numFramesInFile; }; - -//#endif #endif diff --git a/slsReceiverSoftware/include/HDF5FileStatic.h b/slsReceiverSoftware/include/HDF5FileStatic.h new file mode 100644 index 000000000..245c3d41f --- /dev/null +++ b/slsReceiverSoftware/include/HDF5FileStatic.h @@ -0,0 +1,536 @@ +#ifdef HDF5C +#pragma once +/************************************************ + * @file HDF5FileStatic.h + * @short creating, closing, writing and reading + * from HDF5 files + ***********************************************/ +/** + *@short creating, closing, writing and reading from HDF5 files + */ + +#include "H5Cpp.h" +#ifndef H5_NO_NAMESPACE +using namespace H5; +#endif +#include "ansi.h" + + +#include +#include +#include //malloc +#include +using namespace std; + + +class HDF5FileStatic { + +public: + + /** Constructor */ + HDF5FileStatic(){}; + /** Destructor */ + virtual ~HDF5FileStatic(){}; + + /** + * Create File Name in format fpath/fnameprefix_fx_dy_z.raw, + * where x is fnum, y is (dindex * numunits + unitindex) and z is findex + * @param fpath file path + * @param fnameprefix file name prefix (includes scan and position variables) + * @param findex file index + * @param frindexenable frame index enable + * @param fnum frame number index + * @param dindex readout index + * @param numunits number of units per readout. eg. eiger has 2 udp units per readout + * @param unitindex unit index + * @returns complete file name created + */ + static string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable, + uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0) + { + ostringstream osfn; + osfn << fpath << "/" << fnameprefix; + if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex); + if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum; + osfn << "_" << findex; + osfn << ".h5"; + return osfn.str(); + } + + /** + * Create master file name + * @param fpath file path + * @param fnameprefix file name prefix (includes scan and position variables) + * @param findex file index + * @returns master file name + */ + static string CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex) + { + ostringstream osfn; + osfn << fpath << "/" << fnameprefix; + osfn << "_master"; + osfn << "_" << findex; + osfn << ".h5"; + return osfn.str(); + } + + /** + * Create virtual file name + * @param fpath file path + * @param fnameprefix file name prefix (includes scan and position variables) + * @param fnum current frame number + * @param findex file index + * @param frindexenable frame index enable + * @param fnum frame number index + * @returns virtual file name + */ + static string CreateVirtualFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable, + uint64_t fnum) + { + ostringstream osfn; + osfn << fpath << "/" << fnameprefix; + osfn << "_virtual"; + if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum; + osfn << "_" << findex; + osfn << ".h5"; + return osfn.str(); + } + + /** + * Close File + * @param ind index for debugging + * @param fd file pointer + * @param dp dataspace pointer + * @param ds dataset pointer + */ + + static void CloseDataFile(int ind, H5File*& fd, DataSpace*& dp, DataSet*& ds) + { + try { + Exception::dontPrint(); //to handle errors + if(dp) {delete dp; dp = 0;} + if(ds) {delete ds; ds = 0;} + if(fd) {delete fd; fd = 0;} + } catch(Exception error) { + cprintf(RED,"Error in closing HDF5 handles\n"); + error.printError(); + } + } + + /* + * Close master file + * @param fd master hdf5 file object + */ + static void CloseMasterDataFile(H5File*& fd) + { + try { + Exception::dontPrint(); //to handle errors + if(fd) {delete fd; fd = 0;} + } catch(Exception error) { + cprintf(RED,"Error in closing master HDF5 handles\n"); + error.printError(); + } + } + + /* + * Close virtual file + * (in C because H5Pset_virtual doesnt exist yet in C++) + * @param fd virtual hdf5 file handle + */ + static void CloseVirtualDataFile(hid_t& fd) + { + if(fd) { + if (H5Fclose(fd) < 0 ) + cprintf(RED,"Error in closing virtual HDF5 handles\n"); + fd = 0; + } + } + + /** + * Write data to file + * @param ind object index for debugging + * @param buf buffer to write from + * @param nDimx image number in file (imagenumber%maxframesinfile) + * @param nDimy number of pixels in y direction + * @param nDimz number of pixels in x direction + * @param dspace dataspace pointer + * @param dset dataset pointer + * @param dtype datatype + * @returns 0 for success and 1 for fail + */ + static int WriteDataFile(int ind, char* buf, + uint64_t nDimx, uint32_t nDimy, uint32_t nDimz, + DataSpace* dspace, DataSet* dset, DataType dtype) + { + hsize_t count[3] = {1, nDimy, nDimz}; + hsize_t start[3] = {nDimx, 0, 0}; + hsize_t dims2[2] = {nDimy, nDimz}; + try{ + Exception::dontPrint(); //to handle errors + + dspace->selectHyperslab( H5S_SELECT_SET, count, start); + DataSpace memspace(2,dims2); + dset->write(buf, dtype, memspace, *dspace); + memspace.close(); + } + catch(Exception error){ + cprintf(RED,"Error in writing to file in object %d\n",ind); + error.printError(); + return 1; + } + return 0; + } + + + /** + * 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 acquisitionTime acquisition time + * @param acquisitionPeriod acquisition period + * @param version version of software for hdf5 writing + * @returns 0 for success and 1 for fail + */ + static int CreateMasterDataFile(H5File*& fd, string fname, bool owenable, + uint32_t dr, bool tenE, uint32_t size, uint32_t nPixelsx, uint32_t nPixelsy, uint64_t nf, + uint64_t acquisitionTime, uint64_t acquisitionPeriod, double version) + { + try { + Exception::dontPrint(); //to handle errors + + FileAccPropList flist; + flist.setFcloseDegree(H5F_CLOSE_STRONG); + if(!owenable) + fd = new H5File( fname.c_str(), H5F_ACC_EXCL, NULL, flist ); + else + fd = new H5File( fname.c_str(), H5F_ACC_TRUNC, NULL, flist ); + + //variables + DataSpace dataspace = DataSpace (H5S_SCALAR); + Attribute attribute; + DataSet dataset; + int iValue=0; + double dValue=0; + StrType strdatatype(PredType::C_S1,256); + + //create attributes + //version + dValue=version; + attribute = fd->createAttribute("version",PredType::NATIVE_DOUBLE, dataspace); + attribute.write(PredType::NATIVE_DOUBLE, &dValue); + + //Create a group in the file + Group group1( fd->createGroup( "entry" ) ); + Group group2( group1.createGroup("data") ); + Group group3( group1.createGroup("instrument") ); + Group group4( group3.createGroup("beam") ); + Group group5( group3.createGroup("detector") ); + Group group6( group1.createGroup("sample") ); + + //Dynamic Range + dataset = group5.createDataSet ( "dynamic range", PredType::NATIVE_INT, dataspace ); + dataset.write ( &dr, PredType::NATIVE_INT); + attribute = dataset.createAttribute("unit",strdatatype, dataspace); + attribute.write(strdatatype, string("bits")); + + //Ten Giga + iValue = tenE; + 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); + attribute = dataset.createAttribute("unit",strdatatype, dataspace); + attribute.write(strdatatype, string("bytes")); + + //x + dataset = group5.createDataSet ( "number of pixels in x axis", PredType::NATIVE_INT, dataspace ); + dataset.write ( &nPixelsx, PredType::NATIVE_INT); + + //y + dataset = group5.createDataSet ( "number of pixels in y axis", PredType::NATIVE_INT, dataspace ); + dataset.write ( &nPixelsy, PredType::NATIVE_INT); + + //Total Frames + dataset = group5.createDataSet ( "total frames", PredType::STD_U64LE, dataspace ); + dataset.write ( &nf, PredType::STD_U64LE); + + //Exptime + dataset = group5.createDataSet ( "exposure time", PredType::STD_U64LE, dataspace ); + dataset.write ( &acquisitionTime, PredType::STD_U64LE); + attribute = dataset.createAttribute("unit",strdatatype, dataspace); + attribute.write(strdatatype, string("ns")); + + //Period + dataset = group5.createDataSet ( "acquisition period", PredType::STD_U64LE, dataspace ); + dataset.write ( &acquisitionPeriod, PredType::STD_U64LE); + attribute = dataset.createAttribute("unit",strdatatype, dataspace); + attribute.write(strdatatype, string("ns")); + + //Timestamp + time_t t = time(0); + dataset = group5.createDataSet ( "timestamp", strdatatype, dataspace ); + dataset.write ( string(ctime(&t)), strdatatype ); + + fd->close(); + + } catch(Exception error) { + cprintf(RED,"Error in creating master HDF5 handles\n"); + error.printError(); + return 1; + } + return 0; + } + + + + /** + * Create File + * @param ind object index for debugging + * @param owenable overwrite enable + * @param numf number of images + * @param fname complete file name + * @param frindexenable frame index enable + * @param fnum current image number + * @param nx number of pixels in x dir + * @param ny number of pixels in y dir + * @param dtype data type + * @param fd file pointer + * @param dspace dataspace pointer + * @param dset dataset pointer + * @param version version of software for hdf5 writing + * @param maxchunkedimages maximum chunked images + * @returns 0 for success and 1 for fail + */ + static int CreateDataFile(int ind, bool owenable, string fname, bool frindexenable, + uint64_t fnum, uint64_t nDimx, uint32_t nDimy, uint32_t nDimz, + DataType dtype, H5File*& fd, DataSpace*& dspace, DataSet*& dset, + double version, uint64_t maxchunkedimages) + { + try { + Exception::dontPrint(); //to handle errors + + //file + FileAccPropList fapl; + fapl.setFcloseDegree(H5F_CLOSE_STRONG); + if(!owenable) + fd = new H5File( fname.c_str(), H5F_ACC_EXCL, NULL,fapl ); + else + fd = new H5File( fname.c_str(), H5F_ACC_TRUNC, NULL, fapl ); + + //attributes - version + double dValue=version; + DataSpace dataspace_attr = DataSpace (H5S_SCALAR); + Attribute attribute = fd->createAttribute("version",PredType::NATIVE_DOUBLE, dataspace_attr); + attribute.write(PredType::NATIVE_DOUBLE, &dValue); + + //dataspace + hsize_t srcdims[3] = {nDimx, nDimy, nDimz}; + dspace = new DataSpace (3,srcdims); + + //dataset name + ostringstream osfn; + osfn << "/data"; + if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum; + string dsetname = osfn.str(); + + //dataset + //chunked dataset if greater than max_chunked_images + if(nDimx > maxchunkedimages){ + DSetCreatPropList plist; + hsize_t chunk_dims[3] ={maxchunkedimages, nDimy, nDimz}; + plist.setChunk(3, chunk_dims); + dset = new DataSet (fd->createDataSet(dsetname.c_str(), dtype, *dspace, plist)); + }else + dset = new DataSet (fd->createDataSet(dsetname.c_str(), dtype, *dspace)); + + } + catch(Exception error){ + cprintf(RED,"Error in creating HDF5 handles in object %d\n",ind); + error.printError(); + fd->close(); + return 1; + } + return 0; + } + + + + /** + * Create virtual file + * (in C because H5Pset_virtual doesnt exist yet in C++) + * @param virtualfname virtual file name + * @param virtualDatasetname virtual dataset name + * @param srcDatasetname source dataset name + * @param numFiles number of files + * @param fileNames array of file names + * @param owenable overwrite enable + * @param fnum current frame number + * @param dtype datatype + * @param srcNDimx source number of objects in x dimension (Number of images) + * @param srcNDimy source number of objects in y dimension (Number of pixels in y dir) + * @param srcNDimz source number of objects in z dimension (Number of pixels in x dir) + * @param dstNDimx destination number of objects in x dimension (Number of images) + * @param dstNDimy destination number of objects in y dimension (Number of pixels in y dir) + * @param dstNDimz destination number of objects in z dimension (Number of pixels in x dir) + * @param version version of software for hdf5 writing + * @returns 0 for success and 1 for fail + */ + static int CreateVirtualDataFile(hid_t& fd, string virtualfname, string virtualDatasetname, string srcDatasetname, + int numFiles, string fileNames[], bool owenable, uint64_t fnum, hid_t dtype, + uint64_t srcNDimx, uint32_t srcNDimy, uint32_t srcNDimz, + uint64_t dstNDimx, uint32_t dstNDimy, uint32_t dstNDimz, double version) + { + + //file + hid_t dfal = H5Pcreate (H5P_FILE_ACCESS); + if (dfal >= 0) { + if (H5Pset_fclose_degree (dfal, H5F_CLOSE_STRONG) >= 0) { + if(!owenable) fd = H5Fcreate( virtualfname.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, dfal); + else fd = H5Fcreate( virtualfname.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, dfal); + if (fd >= 0) { + + //attributes - version + hid_t dataspace_attr = H5Screate (H5S_SCALAR); + if (dataspace_attr >= 0) { + hid_t attrid = H5Acreate2 (fd, "version", H5T_NATIVE_DOUBLE, dataspace_attr, H5P_DEFAULT, H5P_DEFAULT); + if (attrid >= 0) { + double attr_data = version; + if (H5Awrite (attrid, H5T_NATIVE_DOUBLE, &attr_data) >= 0) { + if (H5Aclose (attrid) >= 0) { + + //dataspace + hsize_t vdsdims[3] = {dstNDimx, dstNDimy, dstNDimz}; + hid_t vdsDataspace = H5Screate_simple(3, vdsdims ,NULL); + if (vdsDataspace >= 0) { + hsize_t srcdims[3] = {srcNDimx, srcNDimy, srcNDimz}; + hid_t srcDataspace = H5Screate_simple(3, srcdims, NULL); + if (srcDataspace >= 0) { + + //fill values + hid_t dcpl = H5Pcreate (H5P_DATASET_CREATE); + if (dcpl >= 0) { + int fill_value = -1; + if (H5Pset_fill_value (dcpl, dtype, &fill_value) >= 0) { + + //hyperslab + hsize_t offset[3]={0,0,0},count[3]={srcNDimx,srcNDimy, srcNDimz}; + bool error = false; + for (int i = 0; i < numFiles; i++) { + //cout<<"("<= dstNDimz){ + offset[2] = 0; + offset[1] += srcNDimy; + } + } + if (!error) { + + //dataset + hid_t vdsdataset = H5Dcreate2 (fd, virtualDatasetname.c_str(), dtype, vdsDataspace, H5P_DEFAULT, dcpl, H5P_DEFAULT); + if (vdsdataset >= 0){ + + H5Sclose(vdsDataspace); + H5Sclose(srcDataspace); + H5Dclose(vdsdataset); + H5Fclose(fd); + return 0; + + } else cprintf(RED, "could not create virtual dataset in virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not map files in virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not fill values in virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not create dcpl in virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not create source dataspace in virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not create virtual dataspace in virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not close attribute in virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not write attribute in virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not create attribute in virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not create dataspace for attribute in virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not create virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not set strong file close degree for virtual file %s\n", virtualfname.c_str()); + } else cprintf(RED, "could not create dfal for virtual file %s\n", virtualfname.c_str()); + + H5Fclose(fd); + return 1; + } + + + /** + * Copy file to another file (mainly to view virutal files in hdfviewer) + * @param owenable overwrite enable + * @param oldFileName file name including path of file to copy + * @param oldDatasetName dataset name to copy + * @param newFileName file name including path of file to copy to + * @param newDatasetName dataset name to copy to + * @param nDimx Number of objects in x dimension + * @param nDimy Number of objects in y dimension + * @param nDimz Number of objects in z dimension + * @param dataType data type + * @returns 0 for success and 1 for fail + */ + template + static int CopyVirtualFile(bool owenable, string oldFileName, string oldDatasetName, + string newFileName, string newDatasetName, + uint64_t nDimx, uint32_t nDimy, uint32_t nDimz, T datatype) + { + + T *data_out = (T*)malloc(sizeof(T)*(nDimx*nDimy*nDimz)); + + H5File* oldfd; + H5File* newfd; + try { + Exception::dontPrint(); //to handle errors + + //open old file + oldfd = new H5File( oldFileName.c_str(), H5F_ACC_RDONLY); + DataSet oldDataset = oldfd->openDataSet( oldDatasetName.c_str()); + //read dataset + oldDataset.read( data_out, datatype); + //new file + FileAccPropList fapl; + fapl.setFcloseDegree(H5F_CLOSE_STRONG); + if(!owenable) + newfd = new H5File( newFileName.c_str(), H5F_ACC_EXCL, NULL,fapl ); + else + newfd = new H5File( newFileName.c_str(), H5F_ACC_TRUNC, NULL, fapl ); + //dataspace and dataset + hsize_t dims[3] = {nDimx, nDimy, nDimz}; + DataSpace* newDataspace = new DataSpace (3,dims); + DataSet* newDataset = new DataSet( newfd->createDataSet(newDatasetName.c_str(), datatype, *newDataspace)); + //write and close + newDataset->write(data_out,datatype); + newDataspace->close(); + newDataset->close(); + newfd->close(); + oldDataset.close(); + oldfd->close(); + } catch(Exception error){ + cprintf(RED,"Error in copying virtual files\n"); + error.printError(); + free(data_out); + oldfd->close(); + newfd->close(); + return 1; + } + free(data_out); + return 0; + } +}; +#endif diff --git a/slsReceiverSoftware/include/Listener.h b/slsReceiverSoftware/include/Listener.h index 36b8c80f9..68b9e6685 100644 --- a/slsReceiverSoftware/include/Listener.h +++ b/slsReceiverSoftware/include/Listener.h @@ -1,11 +1,10 @@ +#pragma once /************************************************ * @file Listener.h * @short creates the listener thread that * listens to udp sockets, writes data to memory * & puts pointers to their memory addresses into fifos ***********************************************/ -#ifndef LISTENER_H -#define LISTENER_H /** *@short creates & manages a listener thread each */ @@ -244,4 +243,3 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject { }; -#endif diff --git a/slsReceiverSoftware/include/MySocketTCP.h b/slsReceiverSoftware/include/MySocketTCP.h index 31f56d453..7846967a7 100644 --- a/slsReceiverSoftware/include/MySocketTCP.h +++ b/slsReceiverSoftware/include/MySocketTCP.h @@ -1,10 +1,4 @@ - -#ifndef MY_SOCKET_TCP_H -#define MY_SOCKET_TCP_H - - - - +#pragma once /** * * @libdoc The MySocketTCP class provides a simple interface for creating and sending/receiving data over a TCP socket. @@ -13,11 +7,7 @@ * @author Ian Johnson * @version 1.0 */ - - - //version 1.0, base development, Ian 19/01/09 - /* Modified by anna on 19.01.2009 */ /* canceled SetupParameters() and varaibles intialized in the constructors' headers; @@ -38,8 +28,6 @@ added a function which really does not close the socket between send/receive (senddataonly, receivedataonly) */ - - /* Modified by Anna on 31.10.2012 developed and @@ -76,4 +64,4 @@ class MySocketTCP: public genericSocket { }; -#endif + diff --git a/slsReceiverSoftware/include/RestHelper.h b/slsReceiverSoftware/include/RestHelper.h index d789448ab..d384b31dc 100644 --- a/slsReceiverSoftware/include/RestHelper.h +++ b/slsReceiverSoftware/include/RestHelper.h @@ -1,3 +1,4 @@ +#pragma once /** * @file RestHelper.h * @author Leonardo Sala diff --git a/slsReceiverSoftware/include/ThreadObject.h b/slsReceiverSoftware/include/ThreadObject.h index d6b0d9813..fab511154 100644 --- a/slsReceiverSoftware/include/ThreadObject.h +++ b/slsReceiverSoftware/include/ThreadObject.h @@ -1,9 +1,8 @@ +#pragma once /************************************************ * @file ThreadObject.h * @short creates/destroys a thread ***********************************************/ -#ifndef THREADOBJECT_H -#define THREADOBJECT_H /** *@short creates/destroys a thread */ @@ -108,4 +107,3 @@ class ThreadObject : private virtual slsReceiverDefs { }; -#endif diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 7a62bae33..1e0b83630 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -1,12 +1,9 @@ -//#ifdef UDP_BASE_IMPLEMENTATION -#ifndef UDP_BASE_IMPLEMENTATION_H -#define UDP_BASE_IMPLEMENTATION_H +#pragma once /********************************************//** * @file UDPBaseImplementation.h * @short does all the functions for a receiver, set/get parameters, start/stop etc. ***********************************************/ - //#include "sls_receiver_defs.h" #include "UDPInterface.h" //#include @@ -666,8 +663,3 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter private: }; - - -#endif - -//#endif diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index d63364d9a..cd75d0166 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -1,6 +1,4 @@ -#ifndef UDPINTERFACE_H -#define UDPINTERFACE_H - +#pragma once /*********************************************** * @file UDPInterface.h * @short Base class with all the functions for the UDP inteface of the receiver @@ -609,5 +607,3 @@ class UDPInterface { private: }; - -#endif /* #ifndef UDPINTERFACE_H */ diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index 14296f648..3fa6cb88f 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -1,6 +1,5 @@ //#ifdef REST -#ifndef UDP_REST_IMPLEMENTATION_H -#define UDP_REST_IMPLEMENTATION_H +#pragma once /********************************************//** * @file UDPRESTImplementation.h * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -150,7 +149,4 @@ private: }; - -#endif - //#endif /*REST*/ diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 3f8b4c24a..6ff7e4c0f 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -1,6 +1,4 @@ -//#ifdef UDP_BASE_IMPLEMENTATION -#ifndef UDP_STANDARD_IMPLEMENTATION_H -#define UDP_STANDARD_IMPLEMENTATION_H +#pragma once /********************************************//** * @file UDPBaseImplementation.h * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -286,7 +284,3 @@ private: }; - -#endif - -//#endif diff --git a/slsReceiverSoftware/include/UDPStandardImplementation_copy.h b/slsReceiverSoftware/include/UDPStandardImplementation_copy.h index 57c7fa916..392740972 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation_copy.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation_copy.h @@ -1,6 +1,4 @@ -//#ifdef UDP_BASE_IMPLEMENTATION -#ifndef UDP_STANDARD_IMPLEMENTATION_H -#define UDP_STANDARD_IMPLEMENTATION_H +#pragma once /********************************************//** * @file UDPBaseImplementation.h * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -868,6 +866,4 @@ private: }; -#endif - //#endif diff --git a/slsReceiverSoftware/include/circularFifo.h b/slsReceiverSoftware/include/circularFifo.h index 1d6fd427d..a5740e657 100644 --- a/slsReceiverSoftware/include/circularFifo.h +++ b/slsReceiverSoftware/include/circularFifo.h @@ -1,19 +1,11 @@ +#pragma once /* CircularFifo.h -* Not any company's property but Public-Domain -* Do with source-code as you will. No requirement to keep this -* header if need to use it/change it/ or do whatever with it -* -* Note that there is No guarantee that this code will work -* and I take no responsibility for this code and any problems you -* might get if using it. The code is highly platform dependent! -* * Code & platform dependent issues with it was originally * published at http://www.kjellkod.cc/threadsafecircularqueue * 2009-11-02 -* @author Kjell Hedstr�m, hedstrom@kjellkod.cc */ - -#ifndef CIRCULARFIFO_H_ -#define CIRCULARFIFO_H_ +* @author Kjell Hedstr�m, hedstrom@kjellkod.cc +* modified by the sls detetor group +* */ //#include "sls_receiver_defs.h" #include @@ -157,4 +149,3 @@ unsigned int CircularFifo::increment(unsigned int idx_) const return idx_; } -#endif /* CIRCULARFIFO_H_ */ diff --git a/slsReceiverSoftware/include/dummyUDPInterface.h b/slsReceiverSoftware/include/dummyUDPInterface.h index 5cba675cc..6ef03ac97 100644 --- a/slsReceiverSoftware/include/dummyUDPInterface.h +++ b/slsReceiverSoftware/include/dummyUDPInterface.h @@ -1,5 +1,4 @@ -#ifndef DUMMYUDPINTERFACE_H -#define DUMMYUDPINTERFACE_H +#pragma once /*********************************************** * @file UDPInterface.h @@ -433,4 +432,3 @@ bool dataCompression; int e10G; }; -#endif /* #ifndef DUMMYUDPINTERFACE_H */ diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index d58f46e77..18593f40d 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -1,11 +1,4 @@ - -#ifndef GENERIC_SOCKET_H -#define GENERIC_SOCKET_H - - -#include "ansi.h" - - +#pragma once /** * * @libdoc genericSocket provides some functions to open/close sockets both TCP and UDP @@ -14,11 +7,7 @@ * @author Anna Bergamaschi * @version 0.0 */ - - - //version 1.0, base development, Ian 19/01/09 - /* Modified by anna on 19.01.2009 */ /* canceled SetupParameters() and varaibles intialized in the constructors' headers; @@ -39,6 +28,8 @@ added a function which really does not close the socket between send/receive (senddataonly, receivedataonly) */ +#include "ansi.h" + #ifdef __CINT__ //class sockaddr_in; class socklen_t; @@ -731,4 +722,3 @@ enum communicationProtocol{ // pthread_mutex_t mp; }; -#endif diff --git a/slsReceiverSoftware/include/logger.h b/slsReceiverSoftware/include/logger.h index b27e5cf48..2517fde5f 100644 --- a/slsReceiverSoftware/include/logger.h +++ b/slsReceiverSoftware/include/logger.h @@ -1,5 +1,4 @@ -#ifndef __LOG_H__ -#define __LOG_H__ +#pragma once #include #include @@ -242,5 +241,3 @@ inline void Output2FILE::Output(const std::string& msg, TLogLevel level) #endif // _WIN32 - -#endif //__LOG_H__ diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index ce73bcf1e..9ce1c35f9 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -1,5 +1,4 @@ -#ifndef RECEIVER_DEFS_H -#define RECEIVER_DEFS_H +#pragma once #include "sls_receiver_defs.h" #include @@ -36,131 +35,3 @@ #define DUMMY_PACKET_VALUE 0xFFFFFFFF - - -/* -//binary -#define FILE_BUF_SIZE (16*1024*1024) //16mb -#define FILE_HEADER_BUNCHID_OFFSET 8 - -//hdf5 -#ifdef HDF5C -#define HDF5_WRITER_VERSION 1.0 -#define MAX_CHUNKED_IMAGES 1 -#define MAX_IMAGES_IN_DATASET 1000 -#endif - - -#define HEADER_SIZE_NUM_TOT_PACKETS 4 -#define ALL_MASK_32 0xFFFFFFFF - - - -//gottard -#define GOTTHARD_FIFO_SIZE 25000 //cannot be less than max jobs per thread = 1000 -#define GOTTHARD_PIXELS_IN_ROW 1280 -#define GOTTHARD_PIXELS_IN_COL 1 -#define GOTTHARD_PACKETS_PER_FRAME 2 -#define GOTTHARD_ONE_PACKET_SIZE 1286 -#define GOTTHARD_ONE_DATA_SIZE 1280 -#define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2 -#define GOTTHARD_DATA_BYTES (GOTTHARD_ONE_DATA_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1280*2 -#define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE -#define GOTTHARD_FRAME_INDEX_OFFSET 1 -#define GOTTHARD_PACKET_INDEX_MASK 0x1 - - -//short gotthard -#define GOTTHARD_SHORT_PIXELS_IN_ROW 256 -#define GOTTHARD_SHORT_PIXELS_IN_COL 1 -#define GOTTHARD_SHORT_PACKETS_PER_FRAME 1 -#define GOTTHARD_SHORT_ONE_PACKET_SIZE 518 -#define GOTTHARD_SHORT_ONE_DATA_SIZE 512 -#define GOTTHARD_SHORT_BUFFER_SIZE (GOTTHARD_SHORT_ONE_PACKET_SIZE*GOTTHARD_SHORT_PACKETS_PER_FRAME)//518*1 -#define GOTTHARD_SHORT_DATABYTES (GOTTHARD_SHORT_ONE_DATA_SIZE*GOTTHARD_SHORT_PACKETS_PER_FRAME) //512*1 -#define GOTTHARD_SHORT_FRAME_INDEX_MASK 0xFFFFFFFF -#define GOTTHARD_SHORT_FRAME_INDEX_OFFSET 0 -#define GOTTHARD_SHORT_PACKET_INDEX_MASK 0 - - -//propix -#define PROPIX_FIFO_SIZE 25000 //cannot be less than max jobs per thread = 1000 -#define PROPIX_PIXELS_IN_ROW 22 -#define PROPIX_PIXELS_IN_COL 22 -#define PROPIX_PACKETS_PER_FRAME 2 -#define PROPIX_ONE_PACKET_SIZE 1286 -#define PROPIX_ONE_DATA_SIZE 1280 -#define PROPIX_BUFFER_SIZE (PROPIX_ONE_PACKET_SIZE*PROPIX_PACKETS_PER_FRAME) //1286*2 -#define PROPIX_DATABYTES_PER_PIXEL 2 -//#define PROPIX_DATA_BYTES (1280*PROPIX_PACKETS_PER_FRAME) //1280*2 -#define PROPIX_DATA_BYTES (PROPIX_PIXELS_IN_ROW * PROPIX_PIXELS_IN_COL * PROPIX_DATABYTES_PER_PIXEL) //22 * 22 * 2 -#define PROPIX_FRAME_INDEX_MASK 0xFFFFFFFE -#define PROPIX_FRAME_INDEX_OFFSET 1 -#define PROPIX_PACKET_INDEX_MASK 0x1 - - -//moench -#define MOENCH_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 -#define MOENCH_BYTES_IN_ONE_ROW (MOENCH_PIXELS_IN_ONE_ROW*2) -#define MOENCH_BYTES_PER_ADC (40*2) -#define MOENCH_PIXELS_IN_ONE_ROW 160 -#define MOENCH_PACKETS_PER_FRAME 40 -#define MOENCH_ONE_PACKET_SIZE 1286 -#define MOENCH_ONE_DATA_SIZE 1280 -#define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40 -#define MOENCH_DATA_BYTES (MOENCH_ONE_DATA_SIZE*MOENCH_PACKETS_PER_FRAME) //1280*40 -#define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00 -#define MOENCH_FRAME_INDEX_OFFSET 8 -#define MOENCH_PACKET_INDEX_MASK 0xFF - - -//jungfrau -#define JFRAU_FIFO_SIZE 2500 -#define JFRAU_PIXELS_IN_ONE_ROW (256*4) -#define JFRAU_PIXELS_IN_ONE_COL (256) -#define JFRAU_BYTES_IN_ONE_ROW (JFRAU_PIXELS_IN_ONE_ROW*2) -#define JFRAU_PACKETS_PER_FRAME 128 -#define JFRAU_HEADER_LENGTH 22 -#define JFRAU_ONE_DATA_SIZE 8192 -#define JFRAU_ONE_PACKET_SIZE (JFRAU_HEADER_LENGTH+JFRAU_ONE_DATA_SIZE) //8214 -#define JFRAU_BUFFER_SIZE (JFRAU_ONE_PACKET_SIZE*JFRAU_PACKETS_PER_FRAME) //8214*128 -#define JFRAU_DATA_BYTES (JFRAU_ONE_DATA_SIZE*JFRAU_PACKETS_PER_FRAME) //8192*128 -#define JFRAU_FRAME_INDEX_MASK 0xffffff //mask after using struct (48 bit) -#define JFRAU_FRAME_INDEX_OFFSET 0x0 //Not Applicable, use struct -#define JFRAU_PACKET_INDEX_MASK 0x0 //Not Applicable, use struct - - -//jungrau chip test board -#define JCTB_FIFO_SIZE 2500 -#define JCTB_PIXELS_IN_ONE_ROW 32 -#define JCTB_BYTES_IN_ONE_ROW (JCTB_PIXELS_IN_ONE_ROW*2) -#define JCTB_BYTES_PER_ADC (2) -#define JCTB_PACKETS_PER_FRAME 1 -#define JCTB_ONE_PACKET_SIZE 8224 -#define JCTB_BUFFER_SIZE (JCTB_ONE_PACKET_SIZE*40) -#define JCTB_DATA_BYTES (8192*JCTB_PACKETS_PER_FRAME) -#define JCTB_FRAME_INDEX_MASK 0xFFFFFFFF -#define JCTB_FRAME_INDEX_OFFSET 6+8 -#define JCTB_PACKET_INDEX_MASK 0xFFFFFFFF - - -//eiger -#define EIGER_FIFO_SIZE 100 -#define EIGER_PIXELS_IN_ONE_ROW (256*2) -#define EIGER_PIXELS_IN_ONE_COL (256) -#define EIGER_PORTS_PER_READOUT 2 -#define EIGER_HEADER_PACKET_LENGTH 48 -#define EIGER_ONE_GIGA_CONSTANT 16 -#define EIGER_TEN_GIGA_CONSTANT 4 -#define EIGER_ONE_GIGA_ONE_PACKET_SIZE 1040 -#define EIGER_ONE_GIGA_ONE_DATA_SIZE 1024 -#define EIGER_TEN_GIGA_ONE_PACKET_SIZE 4112 -#define EIGER_TEN_GIGA_ONE_DATA_SIZE 4096 -#define EIGER_DATA_PACKET_HEADER_SIZE 8 -#define EIGER_FRAME_INDEX_MASK 0xFFFFFFFF //32 bit for now -#define EIGER_FRAME_INDEX_OFFSET 0 -#define EIGER_PACKET_INDEX_MASK 0x0 - - -*/ -#endif diff --git a/slsReceiverSoftware/include/slsReceiver.h b/slsReceiverSoftware/include/slsReceiver.h index e76ea7d1b..959387405 100644 --- a/slsReceiverSoftware/include/slsReceiver.h +++ b/slsReceiverSoftware/include/slsReceiver.h @@ -1,9 +1,9 @@ +#pragma once /********************************************//** * @file slsReceiver.h * @short creates the UDP and TCP class objects ***********************************************/ -#ifndef SLS_RECEIVER_H -#define SLS_RECEIVER_H + #include "slsReceiverTCPIPInterface.h" @@ -87,5 +87,3 @@ class slsReceiver : private virtual slsReceiverDefs { UDPInterface* udp_interface; }; - -#endif diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index be08b963a..56783767a 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -1,9 +1,8 @@ +#pragma once /********************************************//** * @file slsReceiverTCPIPInterface.h * @short interface between receiver and client ***********************************************/ -#ifndef SLS_RECEIVER_TCP_IP_INTERFACE_H -#define SLS_RECEIVER_TCP_IP_INTERFACE_H #include "sls_receiver_defs.h" @@ -332,6 +331,3 @@ protected: /** Socket */ MySocketTCP* mySock; }; - - -#endif diff --git a/slsReceiverSoftware/include/slsReceiverUsers.h b/slsReceiverSoftware/include/slsReceiverUsers.h index eea403560..59ddce4da 100644 --- a/slsReceiverSoftware/include/slsReceiverUsers.h +++ b/slsReceiverSoftware/include/slsReceiverUsers.h @@ -1,5 +1,4 @@ -#ifndef SLS_RECEIVER_USERS_H -#define SLS_RECEIVER_USERS_H +#pragma once #include #include @@ -11,11 +10,7 @@ class slsReceiver; @short Class for implementing the SLS data receiver in the users application. Callbacks can be defined for processing and/or saving data */ /** - - @libdoc slsReceiverUsers is a class that can be instantiated in the users software to receive the data from the detectors. Callbacks can be defined for processing and/or saving data - - ***********************************************/ class slsReceiverUsers { @@ -87,5 +82,3 @@ public: slsReceiver* receiver; }; - -#endif diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index f9ceb4e52..d44e9c6f3 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -1,5 +1,4 @@ -#ifndef SLS_RECEIVER_DEFS_H -#define SLS_RECEIVER_DEFS_H +#pragma once #ifdef __CINT__ @@ -215,5 +214,3 @@ protected: }; #endif ; -#endif -; diff --git a/slsReceiverSoftware/include/sls_receiver_funcs.h b/slsReceiverSoftware/include/sls_receiver_funcs.h index e3d354718..cee7d4cbd 100644 --- a/slsReceiverSoftware/include/sls_receiver_funcs.h +++ b/slsReceiverSoftware/include/sls_receiver_funcs.h @@ -1,10 +1,10 @@ +#pragma once /** @internal function indexes to call on the server All set functions with argument -1 work as get, when possible */ -#ifndef SLS_RECEIVER_FUNCS_H -#define SLS_RECEIVER_FUNCS_H + enum { //General functions @@ -62,5 +62,3 @@ enum { /* Always append functions hereafter!!! */ }; -#endif -/** @endinternal */ diff --git a/slsReceiverSoftware/include/utilities.h b/slsReceiverSoftware/include/utilities.h index b28d4f32c..6f7c4db96 100644 --- a/slsReceiverSoftware/include/utilities.h +++ b/slsReceiverSoftware/include/utilities.h @@ -1,3 +1,4 @@ +#pragma once #include #include #include diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index dac6d1454..ff4ba17f5 100644 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -8,18 +8,17 @@ #include "receiver_defs.h" #include -#include -#include using namespace std; FILE* BinaryFile::masterfd = 0; BinaryFile::BinaryFile(int ind, 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 maxf): - File(ind, nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr), - maxFramesPerFile(maxf), - filefd(0) + bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr): + + File(ind, nd, fname, fpath, findex, frindexenable, owenable, maxf, dindex, nunits, nf, dr), + filefd(0), + numFramesInFile(0) { #ifdef VERBOSE PrintMembers(); @@ -33,21 +32,20 @@ BinaryFile::~BinaryFile() { void BinaryFile::PrintMembers() { File::PrintMembers(); printf("Max Frames Per File: %d\n",maxFramesPerFile); + printf("Number of Frames in File: %d\n",numFramesInFile); } slsReceiverDefs::fileFormat BinaryFile::GetFileType() { return BINARY; } -void BinaryFile::SetMaxFramesPerFile(uint32_t maxf) { - maxFramesPerFile = maxf; -} int BinaryFile::CreateFile(uint64_t fnum) { - currentFileName = CreateFileName(filePath, fileNamePrefix, *fileIndex, + numFramesInFile = 0; + currentFileName = BinaryFileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex, *frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index); - if (CreateDataFile(filefd, *overWriteEnable, currentFileName) == FAIL) + if (BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE) == FAIL) return FAIL; printf("%d Binary File created: %s\n", index, currentFileName.c_str()); @@ -55,17 +53,22 @@ int BinaryFile::CreateFile(uint64_t fnum) { } void BinaryFile::CloseCurrentFile() { - CloseDataFile(filefd); + BinaryFileStatic::CloseDataFile(filefd); } void BinaryFile::CloseAllFiles() { - CloseDataFile(filefd); + BinaryFileStatic::CloseDataFile(filefd); if (master && (*detIndex==0)) - CloseMasterDataFile(); + BinaryFileStatic::CloseDataFile(masterfd); } int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum) { - if (WriteDataFile(filefd, buffer, buffersize, fnum) == buffersize) + if (numFramesInFile >= maxFramesPerFile) { + CloseCurrentFile(); + CreateFile(fnum); + } + numFramesInFile++; + if (BinaryFileStatic::WriteDataFile(filefd, buffer, buffersize, fnum) == buffersize) return OK; cprintf(RED,"%d Error: Write to file failed for image number %lld\n", index, (long long int)fnum); return FAIL; @@ -75,119 +78,13 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum) { int BinaryFile::CreateMasterFile(bool en, uint32_t size, uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) { if (master && (*detIndex==0)) { - CreateMasterFileName(filePath, fileNamePrefix, *fileIndex); - return CreateMasterDataFile(*overWriteEnable,en, size, nx, ny, at, ap); + masterFileName = BinaryFileStatic::CreateMasterFileName(filePath, fileNamePrefix, *fileIndex); + printf("Master File: %s\n", masterFileName.c_str()); + return BinaryFileStatic::CreateMasterDataFile(masterfd, masterFileName, *overWriteEnable, + *dynamicRange, en, size, nx, ny, *numImages, + at, ap, BINARY_WRITER_VERSION); } return OK; } -/*** static function ***/ -string BinaryFile::CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, - bool frindexenable, uint64_t fnum, int dindex, int numunits, int unitindex) { - ostringstream osfn; - osfn << fpath << "/" << fnameprefix; - if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex); - if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum; - osfn << "_" << findex; - osfn << ".raw"; - return osfn.str(); -} -/*** static function ***/ -int BinaryFile::CreateDataFile(FILE*& fd, bool owenable, string fname) { - if(!owenable){ - if (NULL == (fd = fopen((const char *) fname.c_str(), "wx"))){ - FILE_LOG(logERROR) << "Could not create/overwrite file" << fname; - fd = 0; - return FAIL; - } - }else if (NULL == (fd = fopen((const char *) fname.c_str(), "w"))){ - FILE_LOG(logERROR) << "Could not create file" << fname; - fd = 0; - return FAIL; - } - //setting file buffer size to 16mb - setvbuf(fd,NULL,_IOFBF,FILE_BUFFER_SIZE); - return OK; -} - -/*** static function ***/ -void BinaryFile::CloseDataFile(FILE*& fd) { - if (fd) - fclose(fd); - fd = 0; -} - -/*** static function ***/ -int BinaryFile::WriteDataFile(FILE* fd, char* buf, int bsize, uint64_t fnum) { - if (!fd) - return 0; - return fwrite(buf, 1, bsize, fd); -} - -void BinaryFile::CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex) { - ostringstream osfn; - osfn << fpath << "/" << fnameprefix; - osfn << "_master"; - osfn << "_" << findex; - osfn << ".raw"; - masterFileName = osfn.str(); - printf("Master HDF5 File: %s\n", masterFileName.c_str()); -} - -void BinaryFile::CloseMasterDataFile() { - if(masterfd) - delete masterfd; - masterfd = 0; -} - - -int BinaryFile::CreateMasterDataFile(bool owenable, - bool tengigaEnable, uint32_t imageSize, uint32_t nPixelsX, uint32_t nPixelsY, - uint64_t acquisitionTime, uint64_t acquisitionPeriod) { - if(!owenable){ - if (NULL == (masterfd = fopen((const char *) masterFileName.c_str(), "wx"))){ - cprintf(RED,"Error in creating binary master file %s\n",masterFileName.c_str()); - masterfd = 0; - return FAIL; - } - }else if (NULL == (masterfd = fopen((const char *) masterFileName.c_str(), "w"))){ - cprintf(RED,"Error in creating binary master file %s\n",masterFileName.c_str()); - masterfd = 0; - return FAIL; - } - time_t t = time(0); - char message[MAX_STR_LENGTH]; - sprintf(message, - "Version\t\t: %.1f\n" - "Dynamic Range\t: %d\n" - "Ten Giga\t: %d\n" - "Image Size\t: %d bytes\n" - "x\t\t: %d pixels\n" - "y\t\t: %d pixels\n" - "Total Frames\t: %lld\n" - "Exptime (ns)\t: %lld\n" - "Period (ns)\t: %lld\n" - "Timestamp\t: %s\n\n", - BINARY_WRITER_VERSION, - *dynamicRange, - tengigaEnable, - imageSize, - nPixelsX, - nPixelsY, - (long long int)*numImages, - (long long int)acquisitionTime, - (long long int)acquisitionPeriod, - ctime(&t)); - if (strlen(message) > MAX_STR_LENGTH) { - cprintf(BG_RED,"Master File Size %d is greater than max str size %d\n", - (int)strlen(message), MAX_STR_LENGTH); - return FAIL; - } - - if (fwrite((void*)message, 1, strlen(message), masterfd) != strlen(message)) - return FAIL; - - CloseDataFile(masterfd); - return OK; -} diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 4e1a53dec..3ed9355e6 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -212,12 +212,13 @@ void DataProcessor::SetupFileWriter(int* nd, char* fname, char* fpath, uint64_t* #ifdef HDF5C case HDF5: file = new HDF5File(index, nd, fname, fpath, findex, - frindexenable, owenable, dindex, nunits, nf, dr, generalData->nPixelsX, generalData->nPixelsY); + frindexenable, owenable, generalData->maxFramesPerFile, dindex, nunits, nf, dr, + generalData->nPixelsX, generalData->nPixelsY); break; #endif default: file = new BinaryFile(index, nd, fname, fpath, findex, - frindexenable, owenable, dindex, nunits, nf, dr, generalData->maxFramesPerFile); + frindexenable, owenable, generalData->maxFramesPerFile, dindex, nunits, nf, dr); break; } } @@ -292,8 +293,3 @@ void DataProcessor::ProcessAnImage(char* buf) { file->WriteToFile(buf, generalData->fifoBufferSize + FILE_FRAME_HEADER_SIZE, fnum-firstMeasurementIndex); } - -void DataProcessor::CreateFinalFile(){ - if(file->GetFileType() == HDF5) - file->CreateFinalFile(); -} diff --git a/slsReceiverSoftware/src/File.cpp b/slsReceiverSoftware/src/File.cpp index 7253de3a7..becd344b2 100644 --- a/slsReceiverSoftware/src/File.cpp +++ b/slsReceiverSoftware/src/File.cpp @@ -11,7 +11,7 @@ using namespace std; File::File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, - bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr): + bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr): index(ind), numDetX(nd[0]), numDetY(nd[1]), @@ -20,6 +20,7 @@ File::File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, fileIndex(findex), frameIndexEnable(frindexenable), overWriteEnable(owenable), + maxFramesPerFile(maxf), detIndex(dindex), numUnitsPerDetector(nunits), numImages(nf), @@ -42,6 +43,7 @@ void File::PrintMembers() { "File Index: %lld\n" "Frame Index Enable: %d\n" "Over Write Enable: %d\n" + "Max Frames Per File: %d\n" "Detector Index: %d\n" "Number of Units Per Detector: %d\n", index, @@ -50,6 +52,7 @@ void File::PrintMembers() { (long long int)*fileIndex, *frameIndexEnable, *overWriteEnable, + maxFramesPerFile, *detIndex, *numUnitsPerDetector); } @@ -70,3 +73,7 @@ void File::GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t* nf = numImages; dr = dynamicRange; } + +void File::SetMaxFramesPerFile(uint32_t maxf) { + maxFramesPerFile = maxf; +} diff --git a/slsReceiverSoftware/src/HDF5File.cpp b/slsReceiverSoftware/src/HDF5File.cpp index 0bfd5eddf..7b758c012 100644 --- a/slsReceiverSoftware/src/HDF5File.cpp +++ b/slsReceiverSoftware/src/HDF5File.cpp @@ -4,15 +4,12 @@ * creates/closes the file and writes data to it ***********************************************/ - -//#define HDF5C /*********************?????????????????* Need to remove this in the header file to o*************************************?????????????????????***/ -//#ifdef HDF5C +#pragma once #include "HDF5File.h" #include "receiver_defs.h" #include #include -#include //malloc using namespace std; @@ -21,15 +18,17 @@ H5File* HDF5File::masterfd = 0; hid_t HDF5File::virtualfd = 0; HDF5File::HDF5File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, - bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, - int nx, int ny): - File(ind, nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr), + bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, + uint32_t nx, uint32_t ny): + + File(ind, nd, fname, fpath, findex, frindexenable, owenable, maxf, dindex, nunits, nf, dr), filefd(0), dataspace(0), dataset(0), datatype(PredType::STD_U16LE), nPixelsX(nx), - nPixelsY(ny) + nPixelsY(ny), + numFramesInFile(0) { #ifdef VERBOSE PrintMembers(); @@ -66,12 +65,6 @@ slsReceiverDefs::fileFormat HDF5File::GetFileType() { void HDF5File::UpdateDataType() { switch(*dynamicRange){ - case 4: - datatype = PredType::STD_U8LE; - break; - case 8: - datatype = PredType::STD_U8LE; - break; case 16: datatype = PredType::STD_U16LE; break; @@ -79,22 +72,30 @@ void HDF5File::UpdateDataType() { datatype = PredType::STD_U32LE; break; default: - cprintf(BG_RED,"unknown dynamic range\n"); - datatype = PredType::STD_U16LE; + datatype = PredType::STD_U8LE; break; } } int HDF5File::CreateFile(uint64_t fnum) { - currentFileName = CreateFileName(filePath, fileNamePrefix, *fileIndex, + numFramesInFile = 0; + currentFileName = HDF5FileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex, *frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index); - UpdateDataType(); + //first time + if(!fnum) UpdateDataType(); - if (CreateDataFile(index, *overWriteEnable, *numImages, currentFileName, *frameIndexEnable, fnum, - ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), nPixelsY, - datatype, filefd, dataspace, dataset) == FAIL) + uint64_t framestosave = ((*numImages - fnum) > maxFramesPerFile) ? maxFramesPerFile : (*numImages-fnum); + + pthread_mutex_lock(&Mutex); + if (HDF5FileStatic::CreateDataFile(index, *overWriteEnable, currentFileName, *frameIndexEnable, + fnum, framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), + datatype, filefd, dataspace, dataset, + HDF5_WRITER_VERSION, MAX_CHUNKED_IMAGES) == FAIL) { + pthread_mutex_unlock(&Mutex); return FAIL; + } + pthread_mutex_unlock(&Mutex); printf("%d HDF5 File: %s\n", index, currentFileName.c_str()); //virtual file @@ -105,24 +106,39 @@ int HDF5File::CreateFile(uint64_t fnum) { } void HDF5File::CloseCurrentFile() { - CloseDataFile(index, filefd, dataspace, dataset); + pthread_mutex_lock(&Mutex); + HDF5FileStatic::CloseDataFile(index, filefd, dataspace, dataset); + if (master && (*detIndex==0)) { + HDF5FileStatic::CloseVirtualDataFile(virtualfd); + } + pthread_mutex_unlock(&Mutex); } void HDF5File::CloseAllFiles() { - CloseDataFile(index, filefd, dataspace, dataset); + pthread_mutex_lock(&Mutex); + HDF5FileStatic::CloseDataFile(index, filefd, dataspace, dataset); if (master && (*detIndex==0)) { - CloseMasterDataFile(); - CloseVirtualDataFile(); + HDF5FileStatic::CloseMasterDataFile(masterfd); + HDF5FileStatic::CloseVirtualDataFile(virtualfd); } + pthread_mutex_unlock(&Mutex); } int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum) { - - if (WriteDataFile(index, buffer + FILE_FRAME_HEADER_SIZE, *numImages, /** ignoring bunchid?????????? */ - ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), nPixelsY, fnum, - dataspace, dataset, datatype) == OK) + if (numFramesInFile >= maxFramesPerFile) {/**max *100?????????????*/ + CloseCurrentFile(); + CreateFile(fnum); + } + numFramesInFile++; + pthread_mutex_lock(&Mutex); + if (HDF5FileStatic::WriteDataFile(index, buffer + FILE_FRAME_HEADER_SIZE, /** ignoring bunchid?????????? */ + fnum%maxFramesPerFile, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), + dataspace, dataset, datatype) == OK) { + pthread_mutex_unlock(&Mutex); return OK; + } + pthread_mutex_unlock(&Mutex); cprintf(RED,"%d Error: Write to file failed\n", index); return FAIL; } @@ -131,9 +147,13 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum) { int HDF5File::CreateMasterFile(bool en, uint32_t size, uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) { if (master && (*detIndex==0)) { - masterFileName = CreateMasterFileName(filePath, fileNamePrefix, *fileIndex); + masterFileName = HDF5FileStatic::CreateMasterFileName(filePath, fileNamePrefix, *fileIndex); printf("Master File: %s\n", masterFileName.c_str()); - return CreateMasterDataFile(masterFileName, *overWriteEnable, *dynamicRange, en, size, nx, ny, *numImages, at, ap); + pthread_mutex_lock(&Mutex); + int ret = HDF5FileStatic::CreateMasterDataFile(masterfd, masterFileName, *overWriteEnable, + *dynamicRange, en, size, nx, ny, *numImages, at, ap, HDF5_WRITER_VERSION); + pthread_mutex_unlock(&Mutex); + return ret; } return OK; } @@ -143,14 +163,14 @@ int HDF5File::CreateVirtualFile(uint64_t fnum) { if (master && (*detIndex==0)) { //file name - string virtualFileName = CreateVirtualFileName(filePath, fileNamePrefix, *fileIndex, *frameIndexEnable, fnum); + string virtualFileName = HDF5FileStatic::CreateVirtualFileName(filePath, fileNamePrefix, *fileIndex, *frameIndexEnable, fnum); printf("Virtual File: %s\n", virtualFileName.c_str()); //source file names int numReadouts = numDetX * numDetY; string fileNames[numReadouts]; for (int i = 0; i < numReadouts; ++i) { - fileNames[i] = CreateFileName(filePath, fileNamePrefix, *fileIndex, + fileNames[i] = HDF5FileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex, *frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, i); #ifdef VERBOSE printf("%d: File Name: %s\n", i, fileNames[i].c_str()); @@ -167,7 +187,7 @@ int HDF5File::CreateVirtualFile(uint64_t fnum) { cdatatype = H5T_STD_U32LE; break; default: - cdatatype = H5T_STD_U16LE; + cdatatype = H5T_STD_U8LE; break; } @@ -183,425 +203,16 @@ int HDF5File::CreateVirtualFile(uint64_t fnum) { if (*frameIndexEnable) osfn << "_f" << setfill('0') << setw(12) << fnum; string virtualDatasetName = osfn.str(); + uint64_t framestosave = ((*numImages - fnum) > maxFramesPerFile) ? maxFramesPerFile : (*numImages-fnum); + //create virtual file - return CreateVirtualDataFile(virtualFileName, virtualDatasetName, srcDatasetName, + pthread_mutex_lock(&Mutex); + int ret = HDF5FileStatic::CreateVirtualDataFile(virtualfd, virtualFileName, virtualDatasetName, srcDatasetName, numReadouts, fileNames, *overWriteEnable, fnum, cdatatype, - *numImages, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), - *numImages, numDetY * nPixelsY, numDetX * ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX)); - } - return OK; -} - - -/*** static functions ***/ -string HDF5File::CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, - bool frindexenable, uint64_t fnum, int dindex, int numunits, int unitindex) { - ostringstream osfn; - osfn << fpath << "/" << fnameprefix; - if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex); - if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum; - osfn << "_" << findex; - osfn << ".h5"; - return osfn.str(); -} - - -string HDF5File::CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex) { - ostringstream osfn; - osfn << fpath << "/" << fnameprefix; - osfn << "_master"; - osfn << "_" << findex; - osfn << ".h5"; - return osfn.str(); -} - - -string HDF5File::CreateVirtualFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable, uint64_t fnum) { - ostringstream osfn; - osfn << fpath << "/" << fnameprefix; - osfn << "_virtual"; - if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum; - osfn << "_" << findex; - osfn << ".h5"; - return osfn.str(); -} - - -void HDF5File::CloseDataFile(int ind, H5File*& fd, DataSpace*& dp, DataSet*& ds) { - pthread_mutex_lock(&Mutex); - try { - Exception::dontPrint(); //to handle errors - if(dp) {delete dp; dp = 0;} - if(ds) {delete ds; ds = 0;} - if(fd) {delete fd; fd = 0;} - } catch(Exception error) { - cprintf(RED,"Error in closing HDF5 handles\n"); - error.printError(); - } - pthread_mutex_unlock(&Mutex); -} - - -void HDF5File::CloseMasterDataFile() { - pthread_mutex_lock(&Mutex); - try { - Exception::dontPrint(); //to handle errors - if(masterfd) {delete masterfd; masterfd = 0;} - } catch(Exception error) { - cprintf(RED,"Error in closing master HDF5 handles\n"); - error.printError(); - } - pthread_mutex_unlock(&Mutex); -} - - -/**(in C because H5Pset_virtual doesnt exist yet in C++)*/ -void HDF5File::CloseVirtualDataFile() { - pthread_mutex_lock(&Mutex); - if(virtualfd) { - if (H5Fclose(virtualfd) < 0 ) - cprintf(RED,"Error in closing virtual HDF5 handles\n"); - virtualfd = 0; - } - pthread_mutex_unlock(&Mutex); -} - - -int HDF5File::WriteDataFile(int ind, char* buf, uint64_t numImages, int nx, int ny, uint64_t fnum, - DataSpace* dspace, DataSet* dset, DataType dtype) { - pthread_mutex_lock(&Mutex); - hsize_t count[3] = {1,ny,nx}; - hsize_t start[3] = {fnum%numImages,0,0}; - hsize_t dims2[2]={ny,nx}; - try{ - Exception::dontPrint(); //to handle errors - - dspace->selectHyperslab( H5S_SELECT_SET, count, start); - DataSpace memspace(2,dims2); - dset->write(buf, dtype, memspace, *dspace); - memspace.close(); - } - catch(Exception error){ - cprintf(RED,"Error in writing to file in object %d\n",ind); - error.printError(); + framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), + framestosave, numDetY * nPixelsY, numDetX * ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),HDF5_WRITER_VERSION); pthread_mutex_unlock(&Mutex); - return FAIL; + return ret; } - pthread_mutex_unlock(&Mutex); return OK; } - - - - -int HDF5File::CreateMasterDataFile(string fname, bool owenable, - uint32_t dr, bool tenE, uint32_t size, uint32_t nx, uint32_t ny, uint64_t nf, - uint64_t acquisitionTime, uint64_t acquisitionPeriod) { - pthread_mutex_lock(&Mutex); - try { - Exception::dontPrint(); //to handle errors - - FileAccPropList flist; - flist.setFcloseDegree(H5F_CLOSE_STRONG); - if(!owenable) - masterfd = new H5File( fname.c_str(), H5F_ACC_EXCL, NULL, flist ); - else - masterfd = new H5File( fname.c_str(), H5F_ACC_TRUNC, NULL, flist ); - - //variables - DataSpace dataspace = DataSpace (H5S_SCALAR); - Attribute attribute; - DataSet dataset; - int iValue=0; - double dValue=0; - StrType strdatatype(PredType::C_S1,256); - - //create attributes - //version - dValue=HDF5_WRITER_VERSION; - attribute = masterfd->createAttribute("version",PredType::NATIVE_DOUBLE, dataspace); - attribute.write(PredType::NATIVE_DOUBLE, &dValue); - - //Create a group in the file - Group group1( masterfd->createGroup( "entry" ) ); - Group group2( group1.createGroup("data") ); - Group group3( group1.createGroup("instrument") ); - Group group4( group3.createGroup("beam") ); - Group group5( group3.createGroup("detector") ); - Group group6( group1.createGroup("sample") ); - - //Dynamic Range - dataset = group5.createDataSet ( "dynamic range", PredType::NATIVE_INT, dataspace ); - dataset.write ( &dr, PredType::NATIVE_INT); - attribute = dataset.createAttribute("unit",strdatatype, dataspace); - attribute.write(strdatatype, string("bits")); - - //Ten Giga - iValue = tenE; - 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); - attribute = dataset.createAttribute("unit",strdatatype, dataspace); - attribute.write(strdatatype, string("bytes")); - - //x - dataset = group5.createDataSet ( "number of pixels in x axis", PredType::NATIVE_INT, dataspace ); - dataset.write ( &nx, PredType::NATIVE_INT); - - //y - dataset = group5.createDataSet ( "number of pixels in y axis", PredType::NATIVE_INT, dataspace ); - dataset.write ( &ny, PredType::NATIVE_INT); - - //Total Frames - dataset = group5.createDataSet ( "total frames", PredType::STD_U64LE, dataspace ); - dataset.write ( &nf, PredType::STD_U64LE); - - //Exptime - dataset = group5.createDataSet ( "exposure time", PredType::STD_U64LE, dataspace ); - dataset.write ( &acquisitionTime, PredType::STD_U64LE); - attribute = dataset.createAttribute("unit",strdatatype, dataspace); - attribute.write(strdatatype, string("ns")); - - //Period - dataset = group5.createDataSet ( "acquisition period", PredType::STD_U64LE, dataspace ); - dataset.write ( &acquisitionPeriod, PredType::STD_U64LE); - attribute = dataset.createAttribute("unit",strdatatype, dataspace); - attribute.write(strdatatype, string("ns")); - - //Timestamp - time_t t = time(0); - dataset = group5.createDataSet ( "timestamp", strdatatype, dataspace ); - dataset.write ( string(ctime(&t)), strdatatype ); - - masterfd->close(); - - } catch(Exception error) { - cprintf(RED,"Error in creating master HDF5 handles\n"); - error.printError(); - pthread_mutex_unlock(&Mutex); - return FAIL; - } - pthread_mutex_unlock(&Mutex); - - return OK; -} - - - -int HDF5File::CreateDataFile(int ind, bool owenable, uint64_t numf, string fname, bool frindexenable, uint64_t fnum, int nx, int ny, - DataType dtype, H5File*& fd, DataSpace*& dspace, DataSet*& dset) { - pthread_mutex_lock(&Mutex); - try { - Exception::dontPrint(); //to handle errors - - //file - FileAccPropList fapl; - fapl.setFcloseDegree(H5F_CLOSE_STRONG); - if(!owenable) - fd = new H5File( fname.c_str(), H5F_ACC_EXCL, NULL,fapl ); - else - fd = new H5File( fname.c_str(), H5F_ACC_TRUNC, NULL, fapl ); - - //attributes - version - double dValue=HDF5_WRITER_VERSION; - DataSpace dataspace_attr = DataSpace (H5S_SCALAR); - Attribute attribute = fd->createAttribute("version",PredType::NATIVE_DOUBLE, dataspace_attr); - attribute.write(PredType::NATIVE_DOUBLE, &dValue); - - //dataspace - hsize_t srcdims[3] = {numf,ny,nx}; - dspace = new DataSpace (3,srcdims); - - //dataset name - ostringstream osfn; - osfn << "/data"; - if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum; - string dsetname = osfn.str(); - - //dataset - //chunked dataset if greater than max_chunked_images - if(numf > MAX_CHUNKED_IMAGES){ - DSetCreatPropList plist; - hsize_t chunk_dims[3] ={MAX_CHUNKED_IMAGES, ny, nx}; - plist.setChunk(3, chunk_dims); - dset = new DataSet (fd->createDataSet(dsetname.c_str(), dtype, *dspace, plist)); - }else - dset = new DataSet (fd->createDataSet(dsetname.c_str(), dtype, *dspace)); - - } - catch(Exception error){ - cprintf(RED,"Error in creating HDF5 handles in object %d\n",ind); - error.printError(); - fd->close(); - pthread_mutex_unlock(&Mutex); - return FAIL; - } - pthread_mutex_unlock(&Mutex); - return OK; -} - - - -/**(in C because H5Pset_virtual doesnt exist yet in C++)*/ -int HDF5File::CreateVirtualDataFile(string virtualfname, string virtualDatasetname, string srcDatasetname, - int numFiles, string fileNames[], bool owenable, uint64_t fnum, hid_t dtype, - int srcNDimx, int srcNDimy, int srcNDimz, int dstNDimx, int dstNDimy, int dstNDimz) { - - pthread_mutex_lock(&Mutex); - - //file - hid_t dfal = H5Pcreate (H5P_FILE_ACCESS); - if (dfal >= 0) { - if (H5Pset_fclose_degree (dfal, H5F_CLOSE_STRONG) >= 0) { - if(!owenable) virtualfd = H5Fcreate( virtualfname.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, dfal); - else virtualfd = H5Fcreate( virtualfname.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, dfal); - if (virtualfd >= 0) { - - //attributes - version - hid_t dataspace_attr = H5Screate (H5S_SCALAR); - if (dataspace_attr >= 0) { - hid_t attrid = H5Acreate2 (virtualfd, "version", H5T_NATIVE_DOUBLE, dataspace_attr, H5P_DEFAULT, H5P_DEFAULT); - if (attrid >= 0) { - double attr_data = HDF5_WRITER_VERSION; - if (H5Awrite (attrid, H5T_NATIVE_DOUBLE, &attr_data) >= 0) { - if (H5Aclose (attrid) >= 0) { - - //dataspace - hsize_t vdsdims[3] = {dstNDimx, dstNDimy, dstNDimz}; - hid_t vdsDataspace = H5Screate_simple(3, vdsdims ,NULL); - if (vdsDataspace >= 0) { - hsize_t srcdims[3] = {srcNDimx, srcNDimy, srcNDimz}; - hid_t srcDataspace = H5Screate_simple(3, srcdims, NULL); - if (srcDataspace >= 0) { - - //fill values - hid_t dcpl = H5Pcreate (H5P_DATASET_CREATE); - if (dcpl >= 0) { - int fill_value = -1; - if (H5Pset_fill_value (dcpl, dtype, &fill_value) >= 0) { - - //hyperslab - hsize_t offset[3]={0,0,0},count[3]={srcNDimx,srcNDimy, srcNDimz}; - bool error = false; - for (int i = 0; i < numFiles; i++) { - //cout<<"("<= (unsigned int) dstNDimz){ - offset[2] = 0; - offset[1] += srcNDimy; - } - } - if (!error) { - - //dataset - hid_t vdsdataset = H5Dcreate2 (virtualfd, virtualDatasetname.c_str(), dtype, vdsDataspace, H5P_DEFAULT, dcpl, H5P_DEFAULT); - if (vdsdataset >= 0){ - - H5Sclose(vdsDataspace); - H5Sclose(srcDataspace); - H5Dclose(vdsdataset); - H5Fclose(virtualfd); - - pthread_mutex_unlock(&Mutex); - return OK; - - } else cprintf(RED, "could not create virtual dataset in virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not map files in virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not fill values in virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not create dcpl in virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not create source dataspace in virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not create virtual dataspace in virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not close attribute in virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not write attribute in virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not create attribute in virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not create dataspace for attribute in virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not create virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not set strong file close degree for virtual file %s\n", virtualfname.c_str()); - } else cprintf(RED, "could not create dfal for virtual file %s\n", virtualfname.c_str()); - - - H5Fclose(virtualfd); - - pthread_mutex_unlock(&Mutex); - return FAIL; -} - - - - -template -int HDF5File::CopyVirtualFile(bool owenable, string oldFileName, string oldDatasetName, - string newFileName, string newDatasetName, int nDimx, int nDimy, int nDimz, T datatype) { - - T *data_out = (T*)malloc(sizeof(T)*(nDimx*nDimy*nDimz)); - - H5File* oldfd; - H5File* newfd; - pthread_mutex_lock(&Mutex); - try { - Exception::dontPrint(); //to handle errors - - //open old file - oldfd = new H5File( oldFileName.c_str(), H5F_ACC_RDONLY); - DataSet oldDataset = oldfd->openDataSet( oldDatasetName.c_str()); - //read dataset - oldDataset.read( data_out, datatype); - //new file - FileAccPropList fapl; - fapl.setFcloseDegree(H5F_CLOSE_STRONG); - if(!owenable) - newfd = new H5File( newFileName.c_str(), H5F_ACC_EXCL, NULL,fapl ); - else - newfd = new H5File( newFileName.c_str(), H5F_ACC_TRUNC, NULL, fapl ); - //dataspace and dataset - hsize_t dims[3] = {nDimx, nDimy, nDimz}; - DataSpace* newDataspace = new DataSpace (3,dims); - DataSet* newDataset = new DataSet( newfd->createDataSet(newDatasetName.c_str(), datatype, *newDataspace)); - //write and close - newDataset->write(data_out,datatype); - newDataspace->close(); - newDataset->close(); - newfd->close(); - oldDataset.close(); - oldfd->close(); - } catch(Exception error){ - cprintf(RED,"Error in copying virtual files\n"); - error.printError(); - free(data_out); - oldfd->close(); - newfd->close(); - pthread_mutex_unlock(&Mutex); - return FAIL; - } - free(data_out); - pthread_mutex_unlock(&Mutex); - return OK; -} - - - -void HDF5File::CreateFinalFile() { - if (master && (*detIndex==0)) { - CopyVirtualFile(*overWriteEnable, "/home/l_maliakal_d/Software/scratch/run_virtual_f000000000000_0.h5", - "virtual_data_f000000000000", - "/home/l_maliakal_d/Software/scratch/copy.h5", - "run_copy", - *numImages, numDetY * nPixelsY, numDetX * ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), - datatype); - } -} - -//#endif diff --git a/slsReceiverSoftware/src/Listener.cpp b/slsReceiverSoftware/src/Listener.cpp index 19374bf62..39ff4b3b1 100644 --- a/slsReceiverSoftware/src/Listener.cpp +++ b/slsReceiverSoftware/src/Listener.cpp @@ -303,9 +303,9 @@ uint32_t Listener::ListenToAnImage(char* buf) { numTotalPacketsCaught++; generalData->GetHeaderInfo(index,listeningPacket,fnum,pnum); lastCaughtFrameIndex = fnum; -//#ifdef VERBOSE +#ifdef VERBOSE if (!index && !pnum) cprintf(GREEN,"Listening %d: fnum:%lld, pnum:%d\n", index, (long long int)fnum, pnum); -//#endif +#endif if (!measurementStartedFlag) RecordFirstIndices(fnum); diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 74002efb7..ddd1b3a33 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -524,8 +524,6 @@ int UDPStandardImplementation::startReceiver(char *c) { cout << "Data will not be saved" << endl; cout << "Processor Ready ..." << endl; - //for(int i=0;iCreateFinalFile(); //status pthread_mutex_lock(&statusMutex); @@ -557,8 +555,6 @@ void UDPStandardImplementation::stopReceiver(){ usleep(5000); } - for(unsigned int i=0;iCreateFinalFile(); pthread_mutex_lock(&statusMutex); status = RUN_FINISHED;