virtual, master all works, still to do rewriting file in an acquisition

This commit is contained in:
Dhanya Maliakal
2017-02-21 15:13:59 +01:00
parent 2cd38fefcd
commit 9e21583331
17 changed files with 855 additions and 252 deletions

View File

@@ -21,6 +21,7 @@ class BinaryFile : private virtual slsReceiverDefs, public File {
* Constructor
* creates the File Writer
* @param ind self index
* @param nd pointer to number of detectors in each dimension
* @param fname pointer to file name prefix
* @param fpath pointer to file path
* @param findex pointer to file index
@@ -32,7 +33,7 @@ class BinaryFile : private virtual slsReceiverDefs, public File {
* @param dr dynamic range
* @param maxf max frames per file
*/
BinaryFile(int ind, char* fname, char* fpath, uint64_t* findex,
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);
/**
@@ -119,7 +120,7 @@ class BinaryFile : private virtual slsReceiverDefs, public File {
static int WriteDataFile(FILE* fd, char* buf, int bsize, uint64_t fnum);
/**
* Create common files
* Create master file
* @param en ten giga enable
* @param size image size
* @param nx number of pixels in x direction
@@ -128,7 +129,7 @@ class BinaryFile : private virtual slsReceiverDefs, public File {
* @param ap acquisition period
* @returns OK or FAIL
*/
int CreateCommonFiles(bool en, uint32_t size,
int CreateMasterFile(bool en, uint32_t size,
uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap);
@@ -140,32 +141,21 @@ class BinaryFile : private virtual slsReceiverDefs, public File {
*/
fileFormat GetFileType();
/** Maximum frames per file */
uint32_t maxFramesPerFile;
/** File Descriptor */
FILE* filefd;
/** Master File Descriptor */
static FILE* masterfd;
/**
* Create file names for master and virtual file
* @param m master file name
* 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 CreateCommonFileNames(std::string& m, char* fpath, char* fnameprefix, uint64_t findex);
void CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex);
/*
* Close master and virtual files
* Close master file
*/
void CloseCommonDataFiles();
void CloseMasterDataFile();
/**
* Create master and virtual files
* @param m master file name
* Create master files
* @param owenable overwrite enable
* @param tengigaEnable ten giga enable
* @param imageSize image size
@@ -175,11 +165,21 @@ class BinaryFile : private virtual slsReceiverDefs, public File {
* @param acquisitionPeriod acquisition period
* @returns OK or FAIL
*/
int CreateCommonDataFiles(std::string m, bool owenable,
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;
/** Master File Descriptor */
static FILE* masterfd;
};
#endif

View File

@@ -133,6 +133,7 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
/**
* Set up file writer object and call backs
* @param nd pointer to number of detectors in each dimension
* @param fname pointer to file name prefix
* @param fpath pointer to file path
* @param findex pointer to file index
@@ -144,7 +145,7 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
* @param dr dynamic range
* @param g address of GeneralData (Detector Data) pointer
*/
void SetupFileWriter(char* fname, char* fpath, uint64_t* findex,
void SetupFileWriter(int* nd, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, GeneralData* g = 0);
@@ -163,6 +164,9 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
*/
void CloseFiles();
void CreateFinalFile();
private:
/**

View File

@@ -22,6 +22,7 @@ class File : private virtual slsReceiverDefs {
* Constructor
* creates the File Writer
* @param ind self index
* @param nd pointer to number of detectors in each dimension
* @param fname pointer to file name prefix
* @param fpath pointer to file path
* @param findex pointer to file index
@@ -32,7 +33,7 @@ class File : private virtual slsReceiverDefs {
* @param nf pointer to number of images in acquisition
* @param dr dynamic range
*/
File(int ind, char* fname, char* fpath, uint64_t* findex,
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);
/**
@@ -59,6 +60,7 @@ class File : private virtual slsReceiverDefs {
/**
* Get Member Pointer Values before the object is destroyed
* @param nd pointer to number of detectors in each dimension
* @param fname pointer to file name prefix
* @param fpath pointer to file path
* @param findex pointer to file index
@@ -69,8 +71,8 @@ class File : private virtual slsReceiverDefs {
* @param nf pointer to number of images in acquisition
* @param dr dynamic range
*/
void GetMemberPointerValues(char*& fname, char*& fpath, uint64_t*& findex,
bool*& frindexenable, bool*& owenable, int*& dindex, int*& nunits, uint64_t*& nf, uint32_t* dr);
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);
/**
* Create file
@@ -108,7 +110,7 @@ class File : private virtual slsReceiverDefs {
}
/**
* Create common files
* Create master file
* @param en ten giga enable
* @param size image size
* @param nx number of pixels in x direction
@@ -117,9 +119,9 @@ class File : private virtual slsReceiverDefs {
* @param ap acquisition period
* @returns OK or FAIL
*/
virtual int CreateCommonFiles(bool en, uint32_t size,
virtual int CreateMasterFile(bool en, uint32_t size,
uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) {
cprintf(RED,"This is a generic function CreateCommonFiles that should be overloaded by a derived class\n");
cprintf(RED,"This is a generic function CreateMasterFile that should be overloaded by a derived class\n");
return OK;
}
@@ -143,7 +145,9 @@ 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:
@@ -153,6 +157,15 @@ class File : private virtual slsReceiverDefs {
/** Self Index */
int index;
/** Number of Detectors in X dimension */
int numDetX;
/** Number of Detectors in Y dimension */
int numDetY;
/** Master File Name */
std::string masterFileName;
/** File Name Prefix */
char* fileNamePrefix;

View File

@@ -27,6 +27,7 @@ class HDF5File : private virtual slsReceiverDefs, public File {
* Constructor
* creates the File Writer
* @param ind self index
* @param nd pointer to number of detectors in each dimension
* @param fname pointer to file name prefix
* @param fpath pointer to file path
* @param findex pointer to file index
@@ -39,7 +40,7 @@ class HDF5File : private virtual slsReceiverDefs, public File {
* @param nx number of pixels in x direction
* @param ny number of pixels in y direction
*/
HDF5File(int ind, char* fname, char* fpath, uint64_t* findex,
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);
@@ -84,7 +85,25 @@ class HDF5File : private virtual slsReceiverDefs, public File {
* @param fnum current image number
* @returns OK or FAIL
*/
int WriteToFile(char* buffer, int bsize, uint64_t fnum);
int WriteToFile(char* buffer, 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);
//*** static functions ***
/**
* Create File Name in format fpath/fnameprefix_fx_dy_z.raw,
@@ -103,31 +122,46 @@ class HDF5File : private virtual slsReceiverDefs, public File {
uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0);
/**
* Create File
* @param ind object index for debugging
* @param owenable overwrite enable
* @param numf number of images
* @param fname complete file name
* @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
* 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 int CreateDataFile(int ind, bool owenable, uint64_t numf, std::string fname, uint64_t fnum, int nx, int ny,
DataType dtype, H5File*& fd, DataSpace*& dspace, DataSet*& dset);
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(H5File*& fd, DataSpace*& dp, DataSet*& ds);
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
@@ -146,19 +180,89 @@ class HDF5File : private virtual slsReceiverDefs, public File {
DataSpace* dspace, DataSet* dset, DataType dtype);
/**
* Create common files
* @param en ten giga enable
* 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 at acquisition time
* @param ap acquisition period
* @param nf number of images
* @param acquisitionTime acquisition time
* @param acquisitionPeriod acquisition period
* @returns OK or FAIL
*/
int CreateCommonFiles(bool en, uint32_t size,
uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap);
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 <typename T>
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:
/**
@@ -172,37 +276,7 @@ class HDF5File : private virtual slsReceiverDefs, public File {
*/
void UpdateDataType();
/**
* Create file names for master and virtual file
* @param m master file name
* @param v virtual file name
* @param fpath file path
* @param fnameprefix file name prefix (includes scan and position variables)
* @param findex file index
*/
void CreateCommonFileNames(std::string& m, std::string& v, char* fpath, char* fnameprefix, uint64_t findex);
/*
* Close master and virtual files
*/
void CloseCommonDataFiles();
/**
* Create master and virtual files
* @param m master file name
* @param v virtual file name
* @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 CreateCommonDataFiles(std::string m, std::string v, bool owenable,
bool tengigaEnable, uint32_t imageSize, uint32_t nPixelsX, uint32_t nPixelsY,
uint64_t acquisitionTime, uint64_t acquisitionPeriod);
/** mutex to update static items among objects (threads)*/
@@ -211,8 +285,8 @@ class HDF5File : private virtual slsReceiverDefs, public File {
/** Master File handle */
static H5File* masterfd;
/** Virtual File handle */
static H5File* virtualfd;
/** Virtual File handle ( only file name because code in C as H5Pset_virtual doesnt exist yet in C++) */
static hid_t virtualfd;
/** File handle */
H5File* filefd;
@@ -231,6 +305,7 @@ class HDF5File : private virtual slsReceiverDefs, public File {
/** Number of pixels in y direction */
int nPixelsY;
};
//#endif

View File

@@ -44,6 +44,19 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
*************************************************************************/
//**initial parameters***
/*
* Get multi detector size
* @return pointer to array of multi detector size in every dimension
*/
int* getMultiDetectorSize() const;
/*
* Get detector position id
* @return detector position id
*/
int getDetectorPositionId() const;
/*
* Get detector hostname
* @return NULL or hostname or NULL if uninitialized (max of 1000 characters)
@@ -245,6 +258,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
*/
void configure(map<string, string> config_map);
/*
* Set multi detector size
* @param pointer to array of multi detector size in every dimension
*/
void setMultiDetectorSize(const int* size);
/*
* Get flipped data across 'axis'
* @return if data is flipped across 'axis'
@@ -419,6 +438,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
*/
int setDetectorType(const detectorType d);
/**
* Set detector position id
* @param i position id
*/
void setDetectorPositionId(const int i);
/**
* Sets detector hostname (and corresponding detector variables in derived REST class)
* It is second function called by the client when connecting to receiver.
@@ -532,6 +557,10 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
//**detector parameters***
/** detector type */
detectorType myDetectorType;
/** Number of Detectors in each dimension direction */
int numDet[MAX_DIMENSIONS];
/*Detector Readout ID*/
int detID;
/** detector hostname */
char detHostname[MAX_STR_LENGTH];
/** Acquisition Period */

View File

@@ -104,6 +104,19 @@ class UDPInterface {
*************************************************************************/
//**initial/detector parameters***
/*
* Get multi detector size
* @return pointer to array of multi detector size in every dimension
*/
virtual int* getMultiDetectorSize() const = 0;
/*
* Get detector position id
* @return detector position id
*/
virtual int getDetectorPositionId() const = 0;
/*
* Get detector hostname
* @return hostname or NULL if uninitialized, must be released by calling function (max of 1000 characters)
@@ -304,6 +317,12 @@ class UDPInterface {
*/
virtual void configure(map<string, string> config_map) = 0;
/*
* Set multi detector size
* @param pointer to array of multi detector size in every dimension
*/
virtual void setMultiDetectorSize(const int* size) = 0;
/*
* Get flipped data across 'axis'
* @return if data is flipped across 'axis'
@@ -476,6 +495,12 @@ class UDPInterface {
*/
virtual int setDetectorType(const slsReceiverDefs::detectorType d) = 0;
/**
* Set detector position id
* @param i position id
*/
virtual void setDetectorPositionId(const int i) = 0;
/**
* Sets detector hostname (and corresponding detector variables in derived REST class)
* It is second function called by the client when connecting to receiver.

View File

@@ -140,6 +140,12 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
*/
int setDetectorType(const detectorType d);
/**
* Set detector position id and construct filewriter
* @param i position id
*/
void setDetectorPositionId(const int i);
/**
* Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans)
*/
@@ -244,10 +250,6 @@ private:
//*** Class Members ***
//*** detector parameters ***
/*Detector Readout ID*/
int detID;
//*** receiver parameters ***
/** Number of Threads */
int numThreads;

View File

@@ -4,6 +4,7 @@
#include "sls_receiver_defs.h"
#include <stdint.h>
#define MAX_DIMENSIONS 2
//socket
#define GOODBYE -200
#define RECEIVE_SOCKET_BUFFER_SIZE (100*1024*1024)

View File

@@ -221,7 +221,11 @@ private:
/** set file format */
int set_file_format();
/** set position id */
int set_detector_posid();
/** set multi detector size */
int set_multi_detector_size();
//General Functions
/** Locks Receiver */

View File

@@ -53,12 +53,12 @@ enum {
F_ACTIVATE, /** < activate/deactivate readout */
F_STREAM_DATA_FROM_RECEIVER, /**< stream data from receiver to client */
F_READ_RECEIVER_TIMER, /** < sets the timer between each data stream in receiver */
F_SET_FLIPPED_DATA_RECEIVER, /** < sets the enable to flip data across x/y axis (bottom/top) */
F_SET_RECEIVER_FILE_FORMAT, /** < sets the receiver file format */
F_SET_RECEIVER_FILE_FORMAT /** < sets the receiver file format */
F_SEND_RECEIVER_DETPOSID, /** < sets the detector position id in the reveiver */
F_SEND_RECEIVER_MULTIDETSIZE /** < sets the multi detector size to the receiver */
/* Always append functions hereafter!!! */
};