mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 05:17:13 +02:00
virtual, master all works, still to do rewriting file in an acquisition
This commit is contained in:
@ -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
|
||||
|
@ -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:
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
@ -86,6 +87,24 @@ class HDF5File : private virtual slsReceiverDefs, public File {
|
||||
*/
|
||||
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,
|
||||
* where x is fnum, y is (dindex * numunits + unitindex) and z is findex
|
||||
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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 */
|
||||
|
@ -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!!! */
|
||||
};
|
||||
|
||||
|
@ -15,9 +15,9 @@ using namespace std;
|
||||
|
||||
FILE* BinaryFile::masterfd = 0;
|
||||
|
||||
BinaryFile::BinaryFile(int ind, char* fname, char* fpath, uint64_t* findex,
|
||||
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, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr),
|
||||
File(ind, nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr),
|
||||
maxFramesPerFile(maxf),
|
||||
filefd(0)
|
||||
{
|
||||
@ -27,6 +27,7 @@ BinaryFile::BinaryFile(int ind, char* fname, char* fpath, uint64_t* findex,
|
||||
}
|
||||
|
||||
BinaryFile::~BinaryFile() {
|
||||
CloseAllFiles();
|
||||
}
|
||||
|
||||
void BinaryFile::PrintMembers() {
|
||||
@ -59,8 +60,8 @@ void BinaryFile::CloseCurrentFile() {
|
||||
|
||||
void BinaryFile::CloseAllFiles() {
|
||||
CloseDataFile(filefd);
|
||||
if (master)
|
||||
CloseCommonDataFiles();
|
||||
if (master && (*detIndex==0))
|
||||
CloseMasterDataFile();
|
||||
}
|
||||
|
||||
int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum) {
|
||||
@ -71,15 +72,11 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum) {
|
||||
}
|
||||
|
||||
|
||||
int BinaryFile::CreateCommonFiles(bool en, uint32_t size,
|
||||
int BinaryFile::CreateMasterFile(bool en, uint32_t size,
|
||||
uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) {
|
||||
if (master) {
|
||||
string masterFileName="";
|
||||
CreateCommonFileNames(masterFileName, filePath, fileNamePrefix, *fileIndex);
|
||||
printf("Master HDF5 File: %s\n", masterFileName.c_str());
|
||||
//create common files
|
||||
return CreateCommonDataFiles(masterFileName, *overWriteEnable,
|
||||
en, size, nx, ny, at, ap);
|
||||
if (master && (*detIndex==0)) {
|
||||
CreateMasterFileName(filePath, fileNamePrefix, *fileIndex);
|
||||
return CreateMasterDataFile(*overWriteEnable,en, size, nx, ny, at, ap);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
@ -128,33 +125,34 @@ int BinaryFile::WriteDataFile(FILE* fd, char* buf, int bsize, uint64_t fnum) {
|
||||
return fwrite(buf, 1, bsize, fd);
|
||||
}
|
||||
|
||||
void BinaryFile::CreateCommonFileNames(string& m, char* fpath, char* fnameprefix, uint64_t findex) {
|
||||
void BinaryFile::CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex) {
|
||||
ostringstream osfn;
|
||||
osfn << fpath << "/" << fnameprefix;
|
||||
osfn << "_master";
|
||||
osfn << "_" << findex;
|
||||
osfn << ".raw";
|
||||
m = osfn.str();
|
||||
masterFileName = osfn.str();
|
||||
printf("Master HDF5 File: %s\n", masterFileName.c_str());
|
||||
}
|
||||
|
||||
void BinaryFile::CloseCommonDataFiles() {
|
||||
void BinaryFile::CloseMasterDataFile() {
|
||||
if(masterfd)
|
||||
delete masterfd;
|
||||
masterfd = 0;
|
||||
}
|
||||
|
||||
|
||||
int BinaryFile::CreateCommonDataFiles(string m, bool owenable,
|
||||
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 *) m.c_str(), "wx"))){
|
||||
cprintf(RED,"Error in creating binary master file %s\n",m.c_str());
|
||||
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 *) m.c_str(), "w"))){
|
||||
cprintf(RED,"Error in creating binary master file %s\n",m.c_str());
|
||||
}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;
|
||||
}
|
||||
@ -177,7 +175,7 @@ int BinaryFile::CreateCommonDataFiles(string m, bool owenable,
|
||||
imageSize,
|
||||
nPixelsX,
|
||||
nPixelsY,
|
||||
(long long int)numImages,
|
||||
(long long int)*numImages,
|
||||
(long long int)acquisitionTime,
|
||||
(long long int)acquisitionPeriod,
|
||||
ctime(&t));
|
||||
|
@ -175,32 +175,31 @@ void DataProcessor::SetGeneralData(GeneralData* g) {
|
||||
#ifdef VERY_VERBOSE
|
||||
generalData->Print();
|
||||
#endif
|
||||
if (!file) {
|
||||
cprintf(RED, "Error Calling SetGeneralData with no file object. Should not be here\n");
|
||||
return;
|
||||
}
|
||||
if (file) {
|
||||
if (file->GetFileType() == BINARY)
|
||||
file->SetMaxFramesPerFile(generalData->maxFramesPerFile);
|
||||
else if (file->GetFileType() == HDF5) {
|
||||
file->SetNumberofPixels(generalData->nPixelsX, generalData->nPixelsY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DataProcessor::SetFileFormat(const fileFormat f) {
|
||||
if (file->GetFileType() != f) {
|
||||
//remember the pointer values before they are destroyed
|
||||
int nd[MAX_DIMENSIONS];nd[0] = 0; nd[1] = 0;
|
||||
char* fname=0; char* fpath=0; uint64_t* findex=0; bool* frindexenable=0;
|
||||
bool* owenable=0; int* dindex=0; int* nunits=0; uint64_t* nf = 0; uint32_t* dr = 0;
|
||||
file->GetMemberPointerValues(fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr);
|
||||
file->GetMemberPointerValues(nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr);
|
||||
//create file writer with same pointers
|
||||
SetupFileWriter(fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr);
|
||||
SetupFileWriter(nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DataProcessor::SetupFileWriter(char* fname, char* fpath, uint64_t* findex,
|
||||
void DataProcessor::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)
|
||||
{
|
||||
if (g)
|
||||
@ -212,12 +211,12 @@ void DataProcessor::SetupFileWriter(char* fname, char* fpath, uint64_t* findex,
|
||||
switch(*fileFormatType){
|
||||
#ifdef HDF5C
|
||||
case HDF5:
|
||||
file = new HDF5File(index, fname, fpath, findex,
|
||||
file = new HDF5File(index, nd, fname, fpath, findex,
|
||||
frindexenable, owenable, dindex, nunits, nf, dr, generalData->nPixelsX, generalData->nPixelsY);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
file = new BinaryFile(index, fname, fpath, findex,
|
||||
file = new BinaryFile(index, nd, fname, fpath, findex,
|
||||
frindexenable, owenable, dindex, nunits, nf, dr, generalData->maxFramesPerFile);
|
||||
break;
|
||||
}
|
||||
@ -226,7 +225,7 @@ void DataProcessor::SetupFileWriter(char* fname, char* fpath, uint64_t* findex,
|
||||
|
||||
int DataProcessor::CreateNewFile(bool en, uint64_t nf, uint64_t at, uint64_t ap) {
|
||||
file->CloseAllFiles();
|
||||
if (file->CreateCommonFiles(en, generalData->imageSize, generalData->nPixelsX, generalData->nPixelsY,
|
||||
if (file->CreateMasterFile(en, generalData->imageSize, generalData->nPixelsX, generalData->nPixelsY,
|
||||
at, ap) == FAIL)
|
||||
return FAIL;
|
||||
if (file->CreateFile(currentFrameIndex) == FAIL)
|
||||
@ -288,7 +287,13 @@ void DataProcessor::ProcessAnImage(char* buf) {
|
||||
RecordFirstIndices(fnum);
|
||||
}
|
||||
|
||||
/** bunch id pass as well and then do what with it */
|
||||
if (fileWriteEnable && *callbackAction == DO_EVERYTHING)
|
||||
file->WriteToFile(buf + FIFO_HEADER_NUMBYTES, generalData->fifoBufferSize + FILE_FRAME_HEADER_SIZE, fnum-firstMeasurementIndex);
|
||||
file->WriteToFile(buf, generalData->fifoBufferSize + FILE_FRAME_HEADER_SIZE, fnum-firstMeasurementIndex);
|
||||
}
|
||||
|
||||
|
||||
void DataProcessor::CreateFinalFile(){
|
||||
if(file->GetFileType() == HDF5)
|
||||
file->CreateFinalFile();
|
||||
}
|
||||
|
@ -10,9 +10,11 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
File::File(int ind, char* fname, char* fpath, uint64_t* findex,
|
||||
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):
|
||||
index(ind),
|
||||
numDetX(nd[0]),
|
||||
numDetY(nd[1]),
|
||||
fileNamePrefix(fname),
|
||||
filePath(fpath),
|
||||
fileIndex(findex),
|
||||
@ -53,9 +55,11 @@ void File::PrintMembers() {
|
||||
}
|
||||
|
||||
|
||||
void File::GetMemberPointerValues(char*& fname, char*& fpath, uint64_t*& findex,
|
||||
bool*& frindexenable, bool*& owenable, int*& dindex, int*& nunits, uint64_t*& nf, uint32_t* dr)
|
||||
void File::GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t*& findex,
|
||||
bool*& frindexenable, bool*& owenable, int*& dindex, int*& nunits, uint64_t*& nf, uint32_t*& dr)
|
||||
{
|
||||
nd[0] = numDetX;
|
||||
nd[1] = numDetY;
|
||||
fname = fileNamePrefix;
|
||||
fpath = filePath;
|
||||
findex = fileIndex;
|
||||
|
@ -12,17 +12,18 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <stdlib.h> //malloc
|
||||
using namespace std;
|
||||
|
||||
|
||||
pthread_mutex_t HDF5File::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
H5File* HDF5File::masterfd = 0;
|
||||
H5File* HDF5File::virtualfd = 0;
|
||||
hid_t HDF5File::virtualfd = 0;
|
||||
|
||||
HDF5File::HDF5File(int ind, char* fname, char* fpath, uint64_t* findex,
|
||||
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, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr),
|
||||
File(ind, nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr),
|
||||
filefd(0),
|
||||
dataspace(0),
|
||||
dataset(0),
|
||||
@ -30,7 +31,6 @@ HDF5File::HDF5File(int ind, char* fname, char* fpath, uint64_t* findex,
|
||||
nPixelsX(nx),
|
||||
nPixelsY(ny)
|
||||
{
|
||||
printf("%d HDF5File constructor\n",index);
|
||||
#ifdef VERBOSE
|
||||
PrintMembers();
|
||||
#endif
|
||||
@ -38,7 +38,7 @@ HDF5File::HDF5File(int ind, char* fname, char* fpath, uint64_t* findex,
|
||||
|
||||
|
||||
HDF5File::~HDF5File() {
|
||||
printf("%d HDF5File destructor\n",index);
|
||||
CloseAllFiles();
|
||||
}
|
||||
|
||||
void HDF5File::PrintMembers() {
|
||||
@ -66,12 +66,22 @@ 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;
|
||||
case 32: datatype = PredType::STD_U32LE; break;
|
||||
default: cprintf(BG_RED,"unknown dynamic range\n");
|
||||
datatype = PredType::STD_U16LE; break;
|
||||
case 4:
|
||||
datatype = PredType::STD_U8LE;
|
||||
break;
|
||||
case 8:
|
||||
datatype = PredType::STD_U8LE;
|
||||
break;
|
||||
case 16:
|
||||
datatype = PredType::STD_U16LE;
|
||||
break;
|
||||
case 32:
|
||||
datatype = PredType::STD_U32LE;
|
||||
break;
|
||||
default:
|
||||
cprintf(BG_RED,"unknown dynamic range\n");
|
||||
datatype = PredType::STD_U16LE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,30 +89,37 @@ int HDF5File::CreateFile(uint64_t fnum) {
|
||||
currentFileName = CreateFileName(filePath, fileNamePrefix, *fileIndex,
|
||||
*frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index);
|
||||
|
||||
//create file
|
||||
UpdateDataType();
|
||||
if (CreateDataFile(index, *overWriteEnable, *numImages, currentFileName, fnum,
|
||||
|
||||
if (CreateDataFile(index, *overWriteEnable, *numImages, currentFileName, *frameIndexEnable, fnum,
|
||||
((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), nPixelsY,
|
||||
datatype, filefd, dataspace, dataset) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
printf("%d HDF5 File: %s\n", index, currentFileName.c_str());
|
||||
|
||||
//virtual file
|
||||
if (master && (*detIndex==0))
|
||||
return CreateVirtualFile(fnum);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void HDF5File::CloseCurrentFile() {
|
||||
CloseDataFile(filefd, dataspace, dataset);
|
||||
CloseDataFile(index, filefd, dataspace, dataset);
|
||||
}
|
||||
|
||||
void HDF5File::CloseAllFiles() {
|
||||
CloseDataFile(filefd, dataspace, dataset);
|
||||
if (master)
|
||||
CloseCommonDataFiles();
|
||||
CloseDataFile(index, filefd, dataspace, dataset);
|
||||
if (master && (*detIndex==0)) {
|
||||
CloseMasterDataFile();
|
||||
CloseVirtualDataFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum) {
|
||||
if (WriteDataFile(index, buffer, *numImages,
|
||||
|
||||
if (WriteDataFile(index, buffer + FILE_FRAME_HEADER_SIZE, *numImages, /** ignoring bunchid?????????? */
|
||||
((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), nPixelsY, fnum,
|
||||
dataspace, dataset, datatype) == OK)
|
||||
return OK;
|
||||
@ -111,20 +128,72 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum) {
|
||||
}
|
||||
|
||||
|
||||
int HDF5File::CreateCommonFiles(bool en, uint32_t size,
|
||||
int HDF5File::CreateMasterFile(bool en, uint32_t size,
|
||||
uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) {
|
||||
if (master) {
|
||||
string masterFileName="", virtualFileName="";
|
||||
CreateCommonFileNames(masterFileName, virtualFileName, filePath, fileNamePrefix, *fileIndex);
|
||||
printf("Master HDF5 File: %s\nVirtual HDF5 File: %s\n", masterFileName.c_str(), virtualFileName.c_str());
|
||||
//create common files
|
||||
return CreateCommonDataFiles(masterFileName, virtualFileName, *overWriteEnable,
|
||||
en, size, nx, ny, at, ap);
|
||||
if (master && (*detIndex==0)) {
|
||||
masterFileName = CreateMasterFileName(filePath, fileNamePrefix, *fileIndex);
|
||||
printf("Master File: %s\n", masterFileName.c_str());
|
||||
return CreateMasterDataFile(masterFileName, *overWriteEnable, *dynamicRange, en, size, nx, ny, *numImages, at, ap);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*** static function ***/
|
||||
|
||||
int HDF5File::CreateVirtualFile(uint64_t fnum) {
|
||||
if (master && (*detIndex==0)) {
|
||||
|
||||
//file name
|
||||
string virtualFileName = 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,
|
||||
*frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, i);
|
||||
#ifdef VERBOSE
|
||||
printf("%d: File Name: %s\n", i, fileNames[i].c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
//datatype
|
||||
hid_t cdatatype;
|
||||
switch(*dynamicRange){
|
||||
case 16:
|
||||
cdatatype = H5T_STD_U16LE;
|
||||
break;
|
||||
case 32:
|
||||
cdatatype = H5T_STD_U32LE;
|
||||
break;
|
||||
default:
|
||||
cdatatype = H5T_STD_U16LE;
|
||||
break;
|
||||
}
|
||||
|
||||
//source dataset name
|
||||
ostringstream osfn;
|
||||
osfn << "/data";
|
||||
if (*frameIndexEnable) osfn << "_f" << setfill('0') << setw(12) << fnum;
|
||||
string srcDatasetName = osfn.str();
|
||||
|
||||
//virtual dataset name
|
||||
osfn.str(""); osfn.clear();
|
||||
osfn << "/virtual_data";
|
||||
if (*frameIndexEnable) osfn << "_f" << setfill('0') << setw(12) << fnum;
|
||||
string virtualDatasetName = osfn.str();
|
||||
|
||||
//create virtual file
|
||||
return CreateVirtualDataFile(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;
|
||||
@ -136,59 +205,29 @@ string HDF5File::CreateFileName(char* fpath, char* fnameprefix, uint64_t findex,
|
||||
return osfn.str();
|
||||
}
|
||||
|
||||
/*** static function ***/
|
||||
int HDF5File::CreateDataFile(int ind, bool owenable, uint64_t numf, string fname, 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 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 );
|
||||
|
||||
//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
|
||||
char dsetname[100];
|
||||
hsize_t srcdims[3] = {numf,ny,nx};
|
||||
dspace = new DataSpace (3,srcdims);
|
||||
sprintf(dsetname, "/data_%012lld", (long long int)fnum);
|
||||
|
||||
//dataset
|
||||
//create 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, dtype, *dspace, plist));
|
||||
}else
|
||||
dset = new DataSet (fd->createDataSet(dsetname, 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;
|
||||
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();
|
||||
}
|
||||
|
||||
/*** static function ***/
|
||||
void HDF5File::CloseDataFile(H5File*& fd, DataSpace*& dp, DataSet*& ds) {
|
||||
|
||||
void HDF5File::CloseDataFile(int ind, H5File*& fd, DataSpace*& dp, DataSet*& ds) {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
try {
|
||||
Exception::dontPrint(); //to handle errors
|
||||
@ -202,7 +241,32 @@ void HDF5File::CloseDataFile(H5File*& fd, DataSpace*& dp, DataSet*& ds) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
|
||||
/*** static function ***/
|
||||
|
||||
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);
|
||||
@ -227,44 +291,22 @@ int HDF5File::WriteDataFile(int ind, char* buf, uint64_t numImages, int nx, int
|
||||
return OK;
|
||||
}
|
||||
|
||||
void HDF5File::CreateCommonFileNames(string& m, string& v, char* fpath, char* fnameprefix, uint64_t findex) {
|
||||
ostringstream osfn;
|
||||
osfn << fpath << "/" << fnameprefix;
|
||||
osfn << "_master";
|
||||
osfn << "_" << findex;
|
||||
osfn << ".h5";
|
||||
m = osfn.str();
|
||||
v.assign(m);
|
||||
v.replace(v.find("_master", 0), 7, "_virtual");
|
||||
}
|
||||
|
||||
void HDF5File::CloseCommonDataFiles() {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
try {
|
||||
Exception::dontPrint(); //to handle errors
|
||||
if(masterfd) {delete masterfd; masterfd = 0;}
|
||||
if(virtualfd) {delete virtualfd; virtualfd = 0;}
|
||||
} catch(Exception error) {
|
||||
cprintf(RED,"Error in closing common HDF5 handles\n");
|
||||
error.printError();
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
|
||||
|
||||
int HDF5File::CreateCommonDataFiles(string m, string v, bool owenable,
|
||||
bool tengigaEnable, uint32_t imageSize, uint32_t nPixelsX, uint32_t nPixelsY,
|
||||
|
||||
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
|
||||
Exception::dontPrint(); //to handle errors
|
||||
|
||||
FileAccPropList flist;
|
||||
flist.setFcloseDegree(H5F_CLOSE_STRONG);
|
||||
if(!owenable)
|
||||
masterfd = new H5File( m.c_str(), H5F_ACC_EXCL, NULL, flist );
|
||||
masterfd = new H5File( fname.c_str(), H5F_ACC_EXCL, NULL, flist );
|
||||
else
|
||||
masterfd = new H5File( m.c_str(), H5F_ACC_TRUNC, NULL, flist );
|
||||
masterfd = new H5File( fname.c_str(), H5F_ACC_TRUNC, NULL, flist );
|
||||
|
||||
//variables
|
||||
DataSpace dataspace = DataSpace (H5S_SCALAR);
|
||||
@ -290,37 +332,45 @@ int HDF5File::CreateCommonDataFiles(string m, string v, bool owenable,
|
||||
|
||||
//Dynamic Range
|
||||
dataset = group5.createDataSet ( "dynamic range", PredType::NATIVE_INT, dataspace );
|
||||
dataset.write ( dynamicRange, PredType::NATIVE_INT);
|
||||
dataset.write ( &dr, PredType::NATIVE_INT);
|
||||
attribute = dataset.createAttribute("unit",strdatatype, dataspace);
|
||||
attribute.write(strdatatype, string("bits"));
|
||||
|
||||
//Ten Giga
|
||||
iValue = tengigaEnable;
|
||||
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 ( &imageSize, PredType::NATIVE_INT);
|
||||
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);
|
||||
dataset.write ( &nx, PredType::NATIVE_INT);
|
||||
|
||||
//y
|
||||
dataset = group5.createDataSet ( "number of pixels in y axis", PredType::NATIVE_INT, dataspace );
|
||||
dataset.write ( &nPixelsY, PredType::NATIVE_INT);
|
||||
dataset.write ( &ny, PredType::NATIVE_INT);
|
||||
|
||||
//Total Frames
|
||||
dataset = group5.createDataSet ( "total frames", PredType::STD_U64LE, dataspace );
|
||||
dataset.write ( &numImages, PredType::STD_U64LE);
|
||||
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 );
|
||||
@ -329,7 +379,7 @@ int HDF5File::CreateCommonDataFiles(string m, string v, bool owenable,
|
||||
masterfd->close();
|
||||
|
||||
} catch(Exception error) {
|
||||
cprintf(RED,"Error in creating common HDF5 handles\n");
|
||||
cprintf(RED,"Error in creating master HDF5 handles\n");
|
||||
error.printError();
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return FAIL;
|
||||
@ -340,4 +390,218 @@ int HDF5File::CreateCommonDataFiles(string m, string v, bool owenable,
|
||||
}
|
||||
|
||||
|
||||
|
||||
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<<"("<<offset[0]<<","<<offset[1]<<","<<offset[2]<<")"<<endl;
|
||||
if (H5Sselect_hyperslab (vdsDataspace, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) {
|
||||
cprintf(RED,"could not select hyperslab\n");
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
if (H5Pset_virtual(dcpl, vdsDataspace, fileNames[i].c_str(), srcDatasetname.c_str(), srcDataspace) < 0) {
|
||||
cprintf(RED,"could not set mapping\n");
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
offset[2] += srcNDimz;
|
||||
if(offset[2] >= (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 <typename T>
|
||||
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
|
||||
|
@ -37,6 +37,9 @@ void UDPBaseImplementation::initializeMembers(){
|
||||
|
||||
FILE_LOG(logDEBUG) << "Info: Initializing base members";
|
||||
//**detector parameters***
|
||||
for (int i = 0; i < MAX_DIMENSIONS; ++i)
|
||||
numDet[i] = 0;
|
||||
detID = 0;
|
||||
myDetectorType = GENERIC;
|
||||
strcpy(detHostname,"");
|
||||
acquisitionPeriod = 0;
|
||||
@ -85,6 +88,10 @@ UDPBaseImplementation::~UDPBaseImplementation(){}
|
||||
*************************************************************************/
|
||||
|
||||
/**initial parameters***/
|
||||
int* UDPBaseImplementation::getMultiDetectorSize() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return (int*) numDet;}
|
||||
|
||||
int UDPBaseImplementation::getDetectorPositionId() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return detID;}
|
||||
|
||||
char *UDPBaseImplementation::getDetectorHostname() const{
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
@ -208,6 +215,23 @@ void UDPBaseImplementation::configure(map<string, string> config_map){
|
||||
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
|
||||
}
|
||||
|
||||
void UDPBaseImplementation::setMultiDetectorSize(const int* size) {
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
char message[100];
|
||||
strcpy(message, "Detector Size: (");
|
||||
for (int i = 0; i < MAX_DIMENSIONS; ++i) {
|
||||
if (myDetectorType == EIGER && (!i))
|
||||
numDet[i] = size[i]*2;
|
||||
else
|
||||
numDet[i] = size[i];
|
||||
sprintf(message,"%s%d",message,numDet[i]);
|
||||
if (i < MAX_DIMENSIONS-1 )
|
||||
strcat(message,",");
|
||||
}
|
||||
strcat(message,")");
|
||||
FILE_LOG(logINFO) << message;
|
||||
}
|
||||
|
||||
void UDPBaseImplementation::setFlippedData(int axis, int enable){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
if(axis<0 || axis>1) return;
|
||||
@ -445,6 +469,13 @@ int UDPBaseImplementation::setDetectorType(const detectorType d){
|
||||
return OK;
|
||||
}
|
||||
|
||||
void UDPBaseImplementation::setDetectorPositionId(const int i){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
detID = i;
|
||||
FILE_LOG(logINFO) << "Detector Position Id:" << detID;
|
||||
}
|
||||
|
||||
void UDPBaseImplementation::initialize(const char *c){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
|
@ -56,9 +56,6 @@ void UDPStandardImplementation::InitializeMembers() {
|
||||
UDPBaseImplementation::initializeMembers();
|
||||
acquisitionPeriod = SAMPLE_TIME_IN_NS;
|
||||
|
||||
//*** detector parameters ***
|
||||
detID = -1;
|
||||
|
||||
//*** receiver parameters ***
|
||||
numThreads = 1;
|
||||
numberofJobs = 1;
|
||||
@ -154,7 +151,7 @@ void UDPStandardImplementation::setFileName(const char c[]) {
|
||||
|
||||
if (strlen(c)) {
|
||||
strcpy(fileName, c); //automatically update fileName in Filewriter (pointer)
|
||||
int detindex = -1;
|
||||
/*int detindex = -1;
|
||||
string tempname(fileName);
|
||||
size_t uscore=tempname.rfind("_");
|
||||
if (uscore!=string::npos) {
|
||||
@ -165,7 +162,7 @@ void UDPStandardImplementation::setFileName(const char c[]) {
|
||||
}
|
||||
}
|
||||
if (detindex == -1)
|
||||
detID = 0;
|
||||
detID = 0;*/
|
||||
}
|
||||
FILE_LOG (logINFO) << "File name:" << fileName;
|
||||
}
|
||||
@ -437,8 +434,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
|
||||
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
|
||||
(*it)->SetGeneralData(generalData);
|
||||
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
|
||||
(*it)->SetupFileWriter(fileName, filePath, &fileIndex, &frameIndexEnable,
|
||||
&overwriteEnable, &detID, &numThreads, &numberOfFrames, &dynamicRange, generalData);
|
||||
(*it)->SetGeneralData(generalData);
|
||||
}
|
||||
FILE_LOG (logDEBUG) << " Detector type set to " << getDetectorType(d);
|
||||
return OK;
|
||||
@ -446,6 +442,19 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
|
||||
|
||||
|
||||
|
||||
|
||||
void UDPStandardImplementation::setDetectorPositionId(const int i){
|
||||
FILE_LOG(logDEBUG) << __AT__ << " starting";
|
||||
|
||||
detID = i;
|
||||
FILE_LOG(logINFO) << "Detector Position Id:" << detID;
|
||||
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
|
||||
(*it)->SetupFileWriter((int*)numDet, fileName, filePath, &fileIndex, &frameIndexEnable,
|
||||
&overwriteEnable, &detID, &numThreads, &numberOfFrames, &dynamicRange, generalData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UDPStandardImplementation::resetAcquisitionCount() {
|
||||
|
||||
|
||||
@ -515,6 +524,9 @@ int UDPStandardImplementation::startReceiver(char *c) {
|
||||
cout << "Data will not be saved" << endl;
|
||||
cout << "Processor Ready ..." << endl;
|
||||
|
||||
//for(int i=0;i<dataProcessor.size(); ++i)
|
||||
//dataProcessor[i]->CreateFinalFile();
|
||||
|
||||
//status
|
||||
pthread_mutex_lock(&statusMutex);
|
||||
status = RUNNING;
|
||||
@ -545,6 +557,9 @@ void UDPStandardImplementation::stopReceiver(){
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
for(unsigned int i=0;i<dataProcessor.size(); ++i)
|
||||
dataProcessor[i]->CreateFinalFile();
|
||||
|
||||
pthread_mutex_lock(&statusMutex);
|
||||
status = RUN_FINISHED;
|
||||
pthread_mutex_unlock(&(statusMutex));
|
||||
|
@ -263,7 +263,8 @@ int slsReceiverTCPIPInterface::function_table(){
|
||||
flist[F_READ_RECEIVER_TIMER] = &slsReceiverTCPIPInterface::set_read_receiver_timer;
|
||||
flist[F_SET_FLIPPED_DATA_RECEIVER] = &slsReceiverTCPIPInterface::set_flipped_data;
|
||||
flist[F_SET_RECEIVER_FILE_FORMAT] = &slsReceiverTCPIPInterface::set_file_format;
|
||||
|
||||
flist[F_SEND_RECEIVER_DETPOSID] = &slsReceiverTCPIPInterface::set_detector_posid;
|
||||
flist[F_SEND_RECEIVER_MULTIDETSIZE] = &slsReceiverTCPIPInterface::set_multi_detector_size;
|
||||
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
@ -2246,6 +2247,138 @@ int slsReceiverTCPIPInterface::set_file_format() {
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::set_detector_posid() {
|
||||
ret=OK;
|
||||
int retval=-1;
|
||||
int arg=-1;
|
||||
strcpy(mess,"Could not set detector position id\n");
|
||||
|
||||
|
||||
// receive arguments
|
||||
if(mySock->ReceiveDataOnly(&arg,sizeof(arg)) < 0 ){
|
||||
strcpy(mess,"Error reading from socket\n");
|
||||
ret = FAIL;
|
||||
}
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
if (ret==OK) {
|
||||
if (lockStatus==1 && mySock->differentClients==1){
|
||||
sprintf(mess,"Receiver locked by %s\n", mySock->lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
else if (receiverBase == NULL){
|
||||
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
|
||||
ret=FAIL;
|
||||
}
|
||||
else if(receiverBase->getStatus()!= IDLE){
|
||||
strcpy(mess,"Can not set position file id while receiver not idle\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret = FAIL;
|
||||
}
|
||||
else{
|
||||
if(arg >= 0)
|
||||
receiverBase->setDetectorPositionId(arg);
|
||||
retval=receiverBase->getDetectorPositionId();
|
||||
if(arg>=0 && retval!=arg)
|
||||
ret = FAIL;
|
||||
}
|
||||
}
|
||||
#ifdef VERYVERBOSE
|
||||
if(ret!=FAIL)
|
||||
cout << "Position Id:" << retval << endl;
|
||||
else
|
||||
cout << mess << endl;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(ret==OK && mySock->differentClients){
|
||||
FILE_LOG(logDEBUG) << "Force update";
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
mySock->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
cprintf(RED, "%s\n", mess);
|
||||
mySock->SendDataOnly(mess,sizeof(mess));
|
||||
}
|
||||
mySock->SendDataOnly(&retval,sizeof(retval));
|
||||
|
||||
//return ok/fail
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::set_multi_detector_size() {
|
||||
ret=OK;
|
||||
int retval=-1;
|
||||
int arg[2];
|
||||
arg[0]=-1;
|
||||
arg[1]=-1;
|
||||
strcpy(mess,"Could not set multi detector size\n");
|
||||
|
||||
|
||||
// receive arguments
|
||||
if(mySock->ReceiveDataOnly(arg,sizeof(arg)) < 0 ){
|
||||
strcpy(mess,"Error reading from socket\n");
|
||||
ret = FAIL;
|
||||
}
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
if (ret==OK) {
|
||||
if (lockStatus==1 && mySock->differentClients==1){
|
||||
sprintf(mess,"Receiver locked by %s\n", mySock->lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
else if (receiverBase == NULL){
|
||||
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
|
||||
ret=FAIL;
|
||||
}
|
||||
else if(receiverBase->getStatus()!= IDLE){
|
||||
strcpy(mess,"Can not set position file id while receiver not idle\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret = FAIL;
|
||||
}
|
||||
else{
|
||||
if((arg[0] > 0) && (arg[1] > 0))
|
||||
receiverBase->setMultiDetectorSize(arg);
|
||||
}
|
||||
}
|
||||
#ifdef VERYVERBOSE
|
||||
if(ret!=FAIL)
|
||||
cout << "Multi Detector Size:" << retval << endl;
|
||||
else
|
||||
cout << mess << endl;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(ret==OK && mySock->differentClients){
|
||||
FILE_LOG(logDEBUG) << "Force update";
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
mySock->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
cprintf(RED, "%s\n", mess);
|
||||
mySock->SendDataOnly(mess,sizeof(mess));
|
||||
}
|
||||
mySock->SendDataOnly(&retval,sizeof(retval));
|
||||
|
||||
//return ok/fail
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user