mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 23:30:03 +02:00
Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer
This commit is contained in:
commit
9bc60518d8
Binary file not shown.
@ -462,7 +462,6 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
||||
bool jointhread{false};
|
||||
|
||||
/** the data processing thread */
|
||||
// pthread_t dataProcessingThread;
|
||||
std::thread dataProcessingThread;
|
||||
|
||||
/** detector data packed for the gui */
|
||||
|
@ -51,17 +51,15 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
|
||||
|
||||
/**
|
||||
* Create file
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int CreateFile() override;
|
||||
void CreateFile() override;
|
||||
|
||||
/**
|
||||
* Create master file
|
||||
* @param mfwenable master file write enable
|
||||
* @param attr master file attributes
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int CreateMasterFile(bool mfwenable, masterAttributes& attr) override;
|
||||
void CreateMasterFile(bool mfwenable, masterAttributes& attr) override;
|
||||
|
||||
/**
|
||||
* Close Current File
|
||||
@ -79,9 +77,8 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
|
||||
* @param buffersize size of buffer
|
||||
* @param fnum current image number
|
||||
* @param nump number of packets caught
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) override;
|
||||
void WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) override;
|
||||
|
||||
|
||||
|
||||
|
@ -98,23 +98,20 @@ class BinaryFileStatic {
|
||||
* @param fname master file name
|
||||
* @param owenable overwrite enable
|
||||
* @param attr master file attributes
|
||||
* @returns 0 for success and 1 for fail
|
||||
*/
|
||||
static int CreateMasterDataFile(FILE*& fd, std::string fname, bool owenable,
|
||||
static void CreateMasterDataFile(FILE*& fd, std::string fname, bool owenable,
|
||||
masterAttributes& attr)
|
||||
{
|
||||
if(!owenable){
|
||||
if (NULL == (fd = fopen((const char *) fname.c_str(), "wx"))){
|
||||
FILE_LOG(logERROR) << "Could not create binary master file "
|
||||
"(without overwrite enable) " << fname;
|
||||
fd = 0;
|
||||
return 1;
|
||||
throw sls::RuntimeError("Could not create binary master file "
|
||||
"(without overwrite enable) " + fname);
|
||||
}
|
||||
}else if (NULL == (fd = fopen((const char *) fname.c_str(), "w"))){
|
||||
FILE_LOG(logERROR) << "Could not create binary master file "
|
||||
"(with overwrite enable) " << fname;
|
||||
fd = 0;
|
||||
return 1;
|
||||
throw sls::RuntimeError("Could not create binary master file "
|
||||
"(with overwrite enable) " + fname);
|
||||
}
|
||||
time_t t = time(0);
|
||||
char message[MAX_MASTER_FILE_LENGTH];
|
||||
@ -182,16 +179,15 @@ class BinaryFileStatic {
|
||||
attr.roiXmax,
|
||||
ctime(&t));
|
||||
if (strlen(message) > MAX_MASTER_FILE_LENGTH) {
|
||||
FILE_LOG(logERROR) << "Master File Size " << strlen(message) <<
|
||||
" is greater than max str size " << MAX_MASTER_FILE_LENGTH;
|
||||
return 1;
|
||||
throw sls::RuntimeError("Master File Size " + std::to_string(strlen(message)) +
|
||||
" is greater than max str size " + std::to_string(MAX_MASTER_FILE_LENGTH));
|
||||
}
|
||||
|
||||
if (fwrite((void*)message, 1, strlen(message), fd) != strlen(message))
|
||||
return 1;
|
||||
if (fwrite((void*)message, 1, strlen(message), fd) != strlen(message)) {
|
||||
throw sls::RuntimeError("Master binary file incorrect number of bytes written to file");
|
||||
}
|
||||
|
||||
BinaryFileStatic::CloseDataFile(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -203,22 +199,19 @@ class BinaryFileStatic {
|
||||
* @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)
|
||||
static void 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;
|
||||
throw sls::RuntimeError("Could not create/overwrite file " + fname);
|
||||
}
|
||||
}else if (NULL == (fd = fopen((const char *) fname.c_str(), "w"))){
|
||||
FILE_LOG(logERROR) << "Could not create file" << fname;
|
||||
} else if (NULL == (fd = fopen((const char *) fname.c_str(), "w"))){
|
||||
fd = 0;
|
||||
return 1;
|
||||
throw sls::RuntimeError("Could not create file " + fname);
|
||||
}
|
||||
//setting file buffer size to 16mb
|
||||
setvbuf(fd,NULL,_IOFBF,filebuffersize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -6,7 +6,8 @@
|
||||
class MySocketTCP;
|
||||
class ServerInterface;
|
||||
|
||||
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
|
||||
class ClientInterface : private virtual slsDetectorDefs {
|
||||
private:
|
||||
@ -38,17 +39,16 @@ class ClientInterface : private virtual slsDetectorDefs {
|
||||
void *arg);
|
||||
|
||||
private:
|
||||
void startTCPSocket();
|
||||
void stopTCPSocket();
|
||||
static void *startTCPServerThread(void *this_pointer);
|
||||
void startTCPServer();
|
||||
|
||||
int function_table();
|
||||
int decode_function(sls::ServerInterface2 &socket);
|
||||
int functionTable();
|
||||
int decodeFunction(sls::ServerInterface2 &socket);
|
||||
void functionNotImplemented();
|
||||
void modeNotImplemented(const std::string& modename, int mode);
|
||||
template <typename T>
|
||||
void validate(T arg, T retval, std::string modename, numberMode hex);
|
||||
void verifyLock();
|
||||
void verifyIdle(sls::ServerInterface2 &socket);
|
||||
|
||||
|
||||
int exec_command(sls::ServerInterface2 &socket);
|
||||
int exit_server(sls::ServerInterface2 &socket);
|
||||
@ -120,20 +120,27 @@ class ClientInterface : private virtual slsDetectorDefs {
|
||||
int set_num_interfaces(sls::ServerInterface2 &socket);
|
||||
int set_adc_mask_10g(sls::ServerInterface2 &socket);
|
||||
|
||||
Implementation *impl() {
|
||||
if (receiver != nullptr) {
|
||||
return receiver.get();
|
||||
} else {
|
||||
throw sls::SocketError(
|
||||
"Receiver not set up. Please use rx_hostname first.\n");
|
||||
}
|
||||
}
|
||||
|
||||
detectorType myDetectorType;
|
||||
std::unique_ptr<Implementation> receiver{nullptr};
|
||||
int (ClientInterface::*flist[NUM_REC_FUNCTIONS])(
|
||||
sls::ServerInterface2 &socket);
|
||||
int ret{OK};
|
||||
int fnum{-1};
|
||||
/** Lock Status if server locked to a client */
|
||||
int lockStatus{0};
|
||||
int lockedByClient{0};
|
||||
int portNumber{0};
|
||||
std::atomic<bool> killTcpThread{false};
|
||||
std::unique_ptr<std::thread> tcpThread;
|
||||
|
||||
int killTCPServerThread{0};
|
||||
pthread_t TCPServer_thread;
|
||||
bool tcpThreadCreated{false};
|
||||
|
||||
int portNumber;
|
||||
|
||||
//***callback parameters***
|
||||
|
||||
@ -149,17 +156,4 @@ class ClientInterface : private virtual slsDetectorDefs {
|
||||
|
||||
protected:
|
||||
std::unique_ptr<sls::ServerSocket> server{nullptr};
|
||||
|
||||
private:
|
||||
void VerifyLock();
|
||||
void VerifyIdle(sls::ServerInterface2 &socket);
|
||||
|
||||
Implementation *impl() {
|
||||
if (receiver != nullptr) {
|
||||
return receiver.get();
|
||||
} else {
|
||||
throw sls::SocketError(
|
||||
"Receiver not set up. Please use rx_hostname first.\n");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -118,13 +118,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
||||
*/
|
||||
void SetGeneralData(GeneralData* g);
|
||||
|
||||
/**
|
||||
* Set thread priority
|
||||
* @priority priority
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int SetThreadPriority(int priority);
|
||||
|
||||
/**
|
||||
* Set File Format
|
||||
* @param f file format
|
||||
@ -155,9 +148,8 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
||||
/**
|
||||
* Create New File
|
||||
* @param attr master file attributes
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int CreateNewFile(masterAttributes& attr);
|
||||
void CreateNewFile(masterAttributes& attr);
|
||||
|
||||
/**
|
||||
* Closes files
|
||||
@ -201,24 +193,12 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
* @return type
|
||||
*/
|
||||
std::string GetType() override;
|
||||
|
||||
/**
|
||||
* Record First Index
|
||||
* @param fnum frame index to record
|
||||
*/
|
||||
void RecordFirstIndex(uint64_t fnum);
|
||||
|
||||
/**
|
||||
* Destroy file writer object
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
void DestroyFileWriter();
|
||||
|
||||
/**
|
||||
* Thread Exeution for DataProcessor Class
|
||||
* Pop bound addresses, process them,
|
||||
|
@ -79,13 +79,6 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
|
||||
*/
|
||||
void SetGeneralData(GeneralData* g);
|
||||
|
||||
/**
|
||||
* Set thread priority
|
||||
* @priority priority
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int SetThreadPriority(int priority);
|
||||
|
||||
/**
|
||||
* Set number of detectors
|
||||
* @param number of detectors in both dimensions
|
||||
@ -114,19 +107,12 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
|
||||
|
||||
/**
|
||||
* Restream stop dummy packet
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
int RestreamStop();
|
||||
void RestreamStop();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
* @return type
|
||||
*/
|
||||
std::string GetType();
|
||||
|
||||
/**
|
||||
* Record First Index
|
||||
* @param fnum frame index to record
|
||||
|
@ -78,9 +78,8 @@ class Fifo : private virtual slsDetectorDefs {
|
||||
/**
|
||||
* Create Fifos, allocate memory & push addresses into fifo
|
||||
* @param fifoItemSize size of each fifo item
|
||||
* @return OK if successful, else FAIL
|
||||
*/
|
||||
int CreateFifos(uint32_t fifoItemSize);
|
||||
void CreateFifos(uint32_t fifoItemSize);
|
||||
|
||||
/**
|
||||
* Destroy Fifos and deallocate memory
|
||||
|
@ -84,9 +84,8 @@ class File : private virtual slsDetectorDefs {
|
||||
|
||||
/**
|
||||
* Create file
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
virtual int CreateFile() = 0;
|
||||
virtual void CreateFile() = 0;
|
||||
|
||||
/**
|
||||
* Close Current File
|
||||
@ -103,17 +102,15 @@ class File : private virtual slsDetectorDefs {
|
||||
* @param buffer buffer to write from
|
||||
* @param fnum current image number
|
||||
* @param nump number of packets caught
|
||||
* @param OK or FAIL
|
||||
*/
|
||||
virtual int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) = 0;
|
||||
virtual void WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) = 0;
|
||||
|
||||
/**
|
||||
* Create master file
|
||||
* @param mfwenable master file write enable
|
||||
* @param attr master file attributes
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
virtual int CreateMasterFile(bool mfwenable, masterAttributes& attr) = 0;
|
||||
virtual void CreateMasterFile(bool mfwenable, masterAttributes& attr) = 0;
|
||||
|
||||
// HDf5 specific
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@
|
||||
#ifndef H5_NO_NAMESPACE
|
||||
using namespace H5;
|
||||
#endif
|
||||
#include <mutex>
|
||||
|
||||
|
||||
class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileStatic {
|
||||
@ -67,9 +68,8 @@ class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileSt
|
||||
/**
|
||||
* Create file
|
||||
* @param fnum current frame index to include in file name
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int CreateFile();
|
||||
void CreateFile();
|
||||
|
||||
/**
|
||||
* Close Current File
|
||||
@ -87,17 +87,15 @@ class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileSt
|
||||
* @param bsize size of buffer (not used)
|
||||
* @param fnum current image number
|
||||
* @param nump number of packets caught
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int WriteToFile(char* buffer, int bsize, uint64_t fnum, uint32_t nump);
|
||||
void WriteToFile(char* buffer, int bsize, uint64_t fnum, uint32_t nump);
|
||||
|
||||
/**
|
||||
* Create master file
|
||||
* @param mfwenable master file write enable
|
||||
* @param attr master file attributes
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int CreateMasterFile(bool mfwenable, masterAttributes& attr);
|
||||
void CreateMasterFile(bool mfwenable, masterAttributes& attr);
|
||||
|
||||
/**
|
||||
* End of Acquisition
|
||||
@ -112,16 +110,14 @@ class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileSt
|
||||
/**
|
||||
* Create Virtual File
|
||||
* @param numf number of images caught
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int CreateVirtualFile(uint64_t numf);
|
||||
void CreateVirtualFile(uint64_t numf);
|
||||
|
||||
/**
|
||||
* Link virtual file in master file
|
||||
* Only for Jungfrau at the moment for 1 module and 1 data file
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int LinkVirtualFileinMasterFile();
|
||||
void LinkVirtualFileinMasterFile();
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
@ -135,9 +131,8 @@ class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileSt
|
||||
void UpdateDataType();
|
||||
|
||||
|
||||
|
||||
/** mutex to update static items among objects (threads)*/
|
||||
static pthread_mutex_t Mutex;
|
||||
static mutable std::mutex mutex;
|
||||
|
||||
/** Master File handle */
|
||||
static H5File* masterfd;
|
||||
|
@ -156,9 +156,8 @@ public:
|
||||
* @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,
|
||||
static void WriteDataFile(int ind, char* buf,
|
||||
uint64_t nDimx, uint32_t nDimy, uint32_t nDimz,
|
||||
DataSpace* dspace, DataSet* dset, DataType dtype)
|
||||
{
|
||||
@ -176,9 +175,8 @@ public:
|
||||
catch(const Exception& error){
|
||||
FILE_LOG(logERROR) << "Could not write to file in object " << ind;
|
||||
error.printErrorStack();
|
||||
return 1;
|
||||
throw RuntimeError("Could not write to file in object " + std::to_string(ind));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -192,7 +190,7 @@ public:
|
||||
* @param rheader sls_receiver_header pointer
|
||||
* @param parameterDataTypes parameter datatypes
|
||||
*/
|
||||
static int WriteParameterDatasets(int ind, DataSpace* dspace_para, uint64_t fnum,
|
||||
static void WriteParameterDatasets(int ind, DataSpace* dspace_para, uint64_t fnum,
|
||||
std::vector <DataSet*> dset_para,sls_receiver_header* rheader,
|
||||
std::vector <DataType> parameterDataTypes)
|
||||
{
|
||||
@ -236,11 +234,9 @@ public:
|
||||
}i=14;
|
||||
}
|
||||
catch(const Exception& error){
|
||||
FILE_LOG(logERROR) << "Could not write parameters (index:" << i << ") to file in object " << ind;
|
||||
error.printErrorStack();
|
||||
return 1;
|
||||
throw RuntimeError("Could not write parameters (index:" + std::to_string(i) + ") to file in object " + std::to_string(ind));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -253,9 +249,8 @@ public:
|
||||
* @param dspace_para parameter dataspace address pointer
|
||||
* @param dset dataset parameter pointer
|
||||
* @param initialNumImages initial number of images
|
||||
* @returns 0 for success and 1 for fail
|
||||
*/
|
||||
static int ExtendDataset(int ind, DataSpace*& dspace, DataSet* dset,
|
||||
static void ExtendDataset(int ind, DataSpace*& dspace, DataSet* dset,
|
||||
DataSpace*& dspace_para, std::vector <DataSet*> dset_para,
|
||||
uint64_t initialNumImages) {
|
||||
try{
|
||||
@ -279,11 +274,9 @@ public:
|
||||
|
||||
}
|
||||
catch(const Exception& error){
|
||||
FILE_LOG(logERROR) << "Could not extend dataset in object " << ind;
|
||||
error.printErrorStack();
|
||||
return 1;
|
||||
throw RuntimeError("Could not extend dataset in object " + std::to_string(ind));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -292,9 +285,8 @@ public:
|
||||
* @param fname master file name
|
||||
* @param owenable overwrite enable
|
||||
* @param attr master file attributes
|
||||
* @returns 0 for success and 1 for fail
|
||||
*/
|
||||
static int CreateMasterDataFile(H5File*& fd, std::string fname, bool owenable,
|
||||
static void CreateMasterDataFile(H5File*& fd, std::string fname, bool owenable,
|
||||
masterAttributes& attr)
|
||||
{
|
||||
try {
|
||||
@ -443,12 +435,10 @@ public:
|
||||
fd->close();
|
||||
|
||||
} catch(const Exception& error) {
|
||||
FILE_LOG(logERROR) << "Could not create master HDF5 handles";
|
||||
error.printErrorStack();
|
||||
if (fd) fd->close();
|
||||
return 1;
|
||||
throw RuntimeError("Could not create master HDF5 handles");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -473,9 +463,8 @@ public:
|
||||
* @param dset_para vector of datasets of parameters
|
||||
* @param parameterNames parameter names
|
||||
* @param parameterDataTypes parameter datatypes
|
||||
* @returns 0 for success and 1 for fail
|
||||
*/
|
||||
static int CreateDataFile(int ind, bool owenable, std::string fname, bool frindexenable,
|
||||
static void CreateDataFile(int ind, bool owenable, std::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,
|
||||
@ -547,12 +536,10 @@ public:
|
||||
}
|
||||
}
|
||||
catch(const Exception& error){
|
||||
FILE_LOG(logERROR) << "Could not create HDF5 handles in object " << ind;
|
||||
error.printErrorStack();
|
||||
if (fd) fd->close();
|
||||
return 1;
|
||||
throw RuntimeError("Could not create HDF5 handles in object " + ind);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -579,9 +566,8 @@ public:
|
||||
* @param version version of software for hdf5 writing
|
||||
* @param parameterNames parameter names
|
||||
* @param parameterDataTypes parameter datatypes
|
||||
* @returns 0 for success and 1 for fail
|
||||
*/
|
||||
static int CreateVirtualDataFile(
|
||||
static void CreateVirtualDataFile(
|
||||
std::string virtualFileName,
|
||||
hid_t& fd, std::string masterFileName,
|
||||
std::string fpath, std::string fnameprefix, uint64_t findex, bool frindexenable,
|
||||
@ -593,206 +579,167 @@ public:
|
||||
std::vector <const char*> parameterNames,
|
||||
std::vector <DataType> parameterDataTypes)
|
||||
{
|
||||
//file
|
||||
hid_t dfal = H5Pcreate (H5P_FILE_ACCESS);
|
||||
if (dfal < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create file access property for virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
if (H5Pset_fclose_degree (dfal, H5F_CLOSE_STRONG) < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not set strong file close degree for virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
fd = H5Fcreate( virtualFileName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, dfal);
|
||||
if (fd < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create virtual file ") + virtualFileName + std::string("\n"));
|
||||
try {
|
||||
//file
|
||||
hid_t dfal = H5Pcreate (H5P_FILE_ACCESS);
|
||||
if (dfal < 0)
|
||||
throw RuntimeError("Could not create file access property for virtual file " + virtualFileName);
|
||||
if (H5Pset_fclose_degree (dfal, H5F_CLOSE_STRONG) < 0)
|
||||
throw RuntimeError("Could not set strong file close degree for virtual file " + virtualFileName);
|
||||
fd = H5Fcreate( virtualFileName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, dfal);
|
||||
if (fd < 0)
|
||||
throw RuntimeError("Could not create virtual file " + virtualFileName);
|
||||
|
||||
//attributes - version
|
||||
hid_t dataspace_attr = H5Screate (H5S_SCALAR);
|
||||
if (dataspace_attr < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create dataspace for attribute in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
hid_t attrid = H5Acreate2 (fd, "version", H5T_NATIVE_DOUBLE, dataspace_attr, H5P_DEFAULT, H5P_DEFAULT);
|
||||
if (attrid < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create attribute in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
double attr_data = version;
|
||||
if (H5Awrite (attrid, H5T_NATIVE_DOUBLE, &attr_data) < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not write attribute in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
if (H5Aclose (attrid) < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not close attribute in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
//attributes - version
|
||||
hid_t dataspace_attr = H5Screate (H5S_SCALAR);
|
||||
if (dataspace_attr < 0)
|
||||
throw RuntimeError("Could not create dataspace for attribute in virtual file " + virtualFileName);
|
||||
hid_t attrid = H5Acreate2 (fd, "version", H5T_NATIVE_DOUBLE, dataspace_attr, H5P_DEFAULT, H5P_DEFAULT);
|
||||
if (attrid < 0)
|
||||
throw RuntimeError("Could not create attribute in virtual file " + virtualFileName);
|
||||
double attr_data = version;
|
||||
if (H5Awrite (attrid, H5T_NATIVE_DOUBLE, &attr_data) < 0)
|
||||
throw RuntimeError("Could not write attribute in virtual file " + virtualFileName);
|
||||
if (H5Aclose (attrid) < 0)
|
||||
throw RuntimeError("Could not close attribute in virtual file " + virtualFileName);
|
||||
|
||||
|
||||
//virtual dataspace
|
||||
hsize_t vdsdims[3] = {numf, numDety * nDimy, numDetz * nDimz};
|
||||
hid_t vdsDataspace = H5Screate_simple(3, vdsdims ,NULL);
|
||||
if (vdsDataspace < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create virtual dataspace in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
hsize_t vdsdims_para[2] = {numf, (unsigned int) numDety * numDetz};
|
||||
hid_t vdsDataspace_para = H5Screate_simple(2, vdsdims_para, NULL);
|
||||
if (vdsDataspace_para < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create virtual dataspace (parameters) in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
//virtual dataspace
|
||||
hsize_t vdsdims[3] = {numf, numDety * nDimy, numDetz * nDimz};
|
||||
hid_t vdsDataspace = H5Screate_simple(3, vdsdims ,NULL);
|
||||
if (vdsDataspace < 0)
|
||||
throw RuntimeError("Could not create virtual dataspace in virtual file " + virtualFileName);
|
||||
hsize_t vdsdims_para[2] = {numf, (unsigned int) numDety * numDetz};
|
||||
hid_t vdsDataspace_para = H5Screate_simple(2, vdsdims_para, NULL);
|
||||
if (vdsDataspace_para < 0)
|
||||
throw RuntimeError("Could not create virtual dataspace (parameters) in virtual file " + virtualFileName);
|
||||
|
||||
|
||||
//fill values
|
||||
hid_t dcpl = H5Pcreate (H5P_DATASET_CREATE);
|
||||
if (dcpl < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create file creation properties in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
int fill_value = -1;
|
||||
if (H5Pset_fill_value (dcpl, GetDataTypeinC(dataType), &fill_value) < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create fill value in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
hid_t dcpl_para[parameterNames.size()];
|
||||
for (unsigned int i = 0; i < parameterNames.size(); ++i) {
|
||||
dcpl_para[i] = H5Pcreate (H5P_DATASET_CREATE);
|
||||
if (dcpl_para[i] < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create file creation properties (parameters) in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
if (H5Pset_fill_value (dcpl_para[i], GetDataTypeinC(parameterDataTypes[i]), &fill_value) < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create fill value (parameters) in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
}
|
||||
|
||||
//hyperslab
|
||||
int numMajorHyperslab = numf/maxFramesPerFile;
|
||||
if (numf%maxFramesPerFile) numMajorHyperslab++;
|
||||
bool error = false;
|
||||
uint64_t framesSaved = 0;
|
||||
for (int j = 0; j < numMajorHyperslab; j++) {
|
||||
|
||||
uint64_t nDimx = ((numf - framesSaved) > maxFramesPerFile)
|
||||
? maxFramesPerFile : (numf-framesSaved);
|
||||
hsize_t offset[3] = {framesSaved, 0, 0};
|
||||
hsize_t count[3] = {nDimx, nDimy, nDimz};
|
||||
hsize_t offset_para[2] = {framesSaved, 0};
|
||||
hsize_t count_para[2] = {nDimx, 1};
|
||||
|
||||
for (int i = 0; i < numDety * numDetz; ++i) {
|
||||
|
||||
//setect hyperslabs
|
||||
if (H5Sselect_hyperslab (vdsDataspace, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) {
|
||||
FILE_LOG(logERROR) << "Could not select hyperslab";
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
if (H5Sselect_hyperslab (vdsDataspace_para, H5S_SELECT_SET,
|
||||
offset_para, NULL, count_para, NULL) < 0) {
|
||||
FILE_LOG(logERROR) << "Could not select hyperslab for parameters";
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
//source file name
|
||||
std::string srcFileName = HDF5FileStatic::CreateFileName(fpath, fnameprefix, findex,
|
||||
j, dindex, numunits, i);
|
||||
|
||||
FILE_LOG(logERROR) << srcFileName;
|
||||
// find relative path
|
||||
std::string relative_srcFileName = srcFileName;
|
||||
{
|
||||
size_t i = srcFileName.rfind('/', srcFileName.length());
|
||||
if (i != std::string::npos)
|
||||
relative_srcFileName = (srcFileName.substr(i+1, srcFileName.length() - i));
|
||||
}
|
||||
|
||||
//source dataset name
|
||||
std::ostringstream osfn;
|
||||
osfn << "/data";
|
||||
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << j;
|
||||
std::string srcDatasetName = osfn.str();
|
||||
|
||||
//source dataspace
|
||||
hsize_t srcdims[3] = {nDimx, nDimy, nDimz};
|
||||
hsize_t srcdimsmax[3] = {H5S_UNLIMITED, nDimy, nDimz};
|
||||
hid_t srcDataspace = H5Screate_simple(3, srcdims, srcdimsmax);
|
||||
if (srcDataspace < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create source dataspace in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
hsize_t srcdims_para[1] = {nDimx};
|
||||
hsize_t srcdimsmax_para[1] = {H5S_UNLIMITED};
|
||||
hid_t srcDataspace_para = H5Screate_simple(1, srcdims_para, srcdimsmax_para);
|
||||
if (srcDataspace_para < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create source dataspace (parameters) in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
|
||||
//mapping
|
||||
if (H5Pset_virtual(dcpl, vdsDataspace, relative_srcFileName.c_str(),
|
||||
srcDatasetName.c_str(), srcDataspace) < 0) {
|
||||
FILE_LOG(logERROR) << "Could not set mapping for paramter 1";
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
for (unsigned int k = 0; k < parameterNames.size(); ++k) {
|
||||
if (H5Pset_virtual(dcpl_para[k], vdsDataspace_para, relative_srcFileName.c_str(),
|
||||
parameterNames[k], srcDataspace_para) < 0) {
|
||||
FILE_LOG(logERROR) << "Could not set mapping for paramter " << k;
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//H5Sclose(srcDataspace);
|
||||
//H5Sclose(srcDataspace_para);
|
||||
offset[2] += nDimz;
|
||||
if (offset[2] >= (numDetz * nDimz)) {
|
||||
offset[2] = 0;
|
||||
offset[1] += nDimy;
|
||||
}
|
||||
offset_para[1]++;
|
||||
//fill values
|
||||
hid_t dcpl = H5Pcreate (H5P_DATASET_CREATE);
|
||||
if (dcpl < 0)
|
||||
throw RuntimeError("Could not create file creation properties in virtual file " + virtualFileName);
|
||||
int fill_value = -1;
|
||||
if (H5Pset_fill_value (dcpl, GetDataTypeinC(dataType), &fill_value) < 0)
|
||||
throw RuntimeError("Could not create fill value in virtual file " + virtualFileName);
|
||||
hid_t dcpl_para[parameterNames.size()];
|
||||
for (unsigned int i = 0; i < parameterNames.size(); ++i) {
|
||||
dcpl_para[i] = H5Pcreate (H5P_DATASET_CREATE);
|
||||
if (dcpl_para[i] < 0)
|
||||
throw RuntimeError("Could not create file creation properties (parameters) in virtual file " + virtualFileName);
|
||||
if (H5Pset_fill_value (dcpl_para[i], GetDataTypeinC(parameterDataTypes[i]), &fill_value) < 0)
|
||||
throw RuntimeError("Could not create fill value (parameters) in virtual file " + virtualFileName);
|
||||
}
|
||||
framesSaved += nDimx;
|
||||
|
||||
//hyperslab
|
||||
int numMajorHyperslab = numf/maxFramesPerFile;
|
||||
if (numf%maxFramesPerFile) numMajorHyperslab++;
|
||||
uint64_t framesSaved = 0;
|
||||
for (int j = 0; j < numMajorHyperslab; j++) {
|
||||
|
||||
uint64_t nDimx = ((numf - framesSaved) > maxFramesPerFile)
|
||||
? maxFramesPerFile : (numf-framesSaved);
|
||||
hsize_t offset[3] = {framesSaved, 0, 0};
|
||||
hsize_t count[3] = {nDimx, nDimy, nDimz};
|
||||
hsize_t offset_para[2] = {framesSaved, 0};
|
||||
hsize_t count_para[2] = {nDimx, 1};
|
||||
|
||||
for (int i = 0; i < numDety * numDetz; ++i) {
|
||||
|
||||
//setect hyperslabs
|
||||
if (H5Sselect_hyperslab (vdsDataspace, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) {
|
||||
throw RuntimeError("Could not select hyperslab");
|
||||
}
|
||||
if (H5Sselect_hyperslab (vdsDataspace_para, H5S_SELECT_SET,
|
||||
offset_para, NULL, count_para, NULL) < 0) {
|
||||
throw RuntimeError("Could not select hyperslab for parameters");
|
||||
}
|
||||
|
||||
//source file name
|
||||
std::string srcFileName = HDF5FileStatic::CreateFileName(fpath, fnameprefix, findex,
|
||||
j, dindex, numunits, i);
|
||||
|
||||
FILE_LOG(logERROR) << srcFileName;
|
||||
// find relative path
|
||||
std::string relative_srcFileName = srcFileName;
|
||||
{
|
||||
size_t i = srcFileName.rfind('/', srcFileName.length());
|
||||
if (i != std::string::npos)
|
||||
relative_srcFileName = (srcFileName.substr(i+1, srcFileName.length() - i));
|
||||
}
|
||||
|
||||
//source dataset name
|
||||
std::ostringstream osfn;
|
||||
osfn << "/data";
|
||||
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << j;
|
||||
std::string srcDatasetName = osfn.str();
|
||||
|
||||
//source dataspace
|
||||
hsize_t srcdims[3] = {nDimx, nDimy, nDimz};
|
||||
hsize_t srcdimsmax[3] = {H5S_UNLIMITED, nDimy, nDimz};
|
||||
hid_t srcDataspace = H5Screate_simple(3, srcdims, srcdimsmax);
|
||||
if (srcDataspace < 0)
|
||||
throw RuntimeError("Could not create source dataspace in virtual file " + virtualFileName);
|
||||
hsize_t srcdims_para[1] = {nDimx};
|
||||
hsize_t srcdimsmax_para[1] = {H5S_UNLIMITED};
|
||||
hid_t srcDataspace_para = H5Screate_simple(1, srcdims_para, srcdimsmax_para);
|
||||
if (srcDataspace_para < 0)
|
||||
throw RuntimeError("Could not create source dataspace (parameters) in virtual file " + virtualFileName);
|
||||
|
||||
//mapping
|
||||
if (H5Pset_virtual(dcpl, vdsDataspace, relative_srcFileName.c_str(),
|
||||
srcDatasetName.c_str(), srcDataspace) < 0) {
|
||||
throw RuntimeError("Could not set mapping for paramter 1");
|
||||
}
|
||||
|
||||
for (unsigned int k = 0; k < parameterNames.size(); ++k) {
|
||||
if (H5Pset_virtual(dcpl_para[k], vdsDataspace_para, relative_srcFileName.c_str(),
|
||||
parameterNames[k], srcDataspace_para) < 0) {
|
||||
throw RuntimeError("Could not set mapping for paramter " + std::to_string(k));
|
||||
}
|
||||
}
|
||||
|
||||
//H5Sclose(srcDataspace);
|
||||
//H5Sclose(srcDataspace_para);
|
||||
offset[2] += nDimz;
|
||||
if (offset[2] >= (numDetz * nDimz)) {
|
||||
offset[2] = 0;
|
||||
offset[1] += nDimy;
|
||||
}
|
||||
offset_para[1]++;
|
||||
}
|
||||
framesSaved += nDimx;
|
||||
}
|
||||
|
||||
//dataset
|
||||
std::string virtualDatasetName = srcDataseName;
|
||||
hid_t vdsdataset = H5Dcreate2 (fd, virtualDatasetName.c_str(),
|
||||
GetDataTypeinC(dataType), vdsDataspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
|
||||
if (vdsdataset < 0)
|
||||
throw RuntimeError("Could not create virutal dataset in virtual file " + virtualFileName);
|
||||
|
||||
|
||||
//virtual parameter dataset
|
||||
for (unsigned int i = 0; i < parameterNames.size(); ++i) {
|
||||
hid_t vdsdataset_para = H5Dcreate2 (fd,
|
||||
parameterNames[i],
|
||||
GetDataTypeinC(parameterDataTypes[i]), vdsDataspace_para,
|
||||
H5P_DEFAULT, dcpl_para[i], H5P_DEFAULT);
|
||||
if (vdsdataset_para < 0)
|
||||
throw RuntimeError("Could not create virutal dataset (parameters) in virtual file " + virtualFileName);
|
||||
}
|
||||
|
||||
//close
|
||||
H5Fclose(fd);
|
||||
fd = 0;
|
||||
|
||||
//link
|
||||
LinkVirtualInMaster(masterFileName, virtualFileName, virtualDatasetName, parameterNames);
|
||||
} catch (const RuntimeError &e) {
|
||||
if (fd > 0)
|
||||
H5Fclose(fd);
|
||||
fd = 0;
|
||||
}
|
||||
if (error)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not map files in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
|
||||
//dataset
|
||||
std::string virtualDatasetName = srcDataseName;
|
||||
hid_t vdsdataset = H5Dcreate2 (fd, virtualDatasetName.c_str(),
|
||||
GetDataTypeinC(dataType), vdsDataspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
|
||||
if (vdsdataset < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create virutal dataset in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
|
||||
|
||||
//virtual parameter dataset
|
||||
for (unsigned int i = 0; i < parameterNames.size(); ++i) {
|
||||
hid_t vdsdataset_para = H5Dcreate2 (fd,
|
||||
parameterNames[i],
|
||||
GetDataTypeinC(parameterDataTypes[i]), vdsDataspace_para,
|
||||
H5P_DEFAULT, dcpl_para[i], H5P_DEFAULT);
|
||||
if (vdsdataset_para < 0)
|
||||
return CloseFileOnError(fd,
|
||||
std::string("Could not create virutal dataset (parameters) in virtual file ")
|
||||
+ virtualFileName + std::string("\n"));
|
||||
}
|
||||
|
||||
//close
|
||||
H5Fclose(fd); fd = 0;
|
||||
|
||||
//link
|
||||
return LinkVirtualInMaster(masterFileName, virtualFileName, virtualDatasetName, parameterNames);
|
||||
}
|
||||
|
||||
|
||||
@ -809,10 +756,9 @@ public:
|
||||
* @param nDimx Number of objects in x dimension
|
||||
* @param nDimy Number of objects in y dimension
|
||||
* @param nDimz Number of objects in z dimension
|
||||
* @returns 0 for success and 1 for fail
|
||||
*/
|
||||
template <typename T>
|
||||
static int CopyVirtualFile(T datatype, bool owenable, std::string oldFileName, std::string oldDatasetName,
|
||||
static void CopyVirtualFile(T datatype, bool owenable, std::string oldFileName, std::string oldDatasetName,
|
||||
std::string newFileName, std::string newDatasetName, int rank,
|
||||
uint64_t nDimx, uint32_t nDimy, uint32_t nDimz=0)
|
||||
{
|
||||
@ -825,8 +771,7 @@ public:
|
||||
data_out = (T*)malloc(sizeof(T)*(nDimx*nDimy*nDimz));
|
||||
break;
|
||||
default:
|
||||
FILE_LOG(logERROR) << "Invalid rank. Options: 2 or 3";
|
||||
return 0;
|
||||
throw RuntimeError("Invalid rank. Options: 2 or 3");
|
||||
}
|
||||
if (datatype == PredType::STD_U16LE) {
|
||||
FILE_LOG(logINFO) << "datatype:16";
|
||||
@ -837,8 +782,7 @@ public:
|
||||
} else if (datatype == PredType::STD_U8LE) {
|
||||
FILE_LOG(logINFO) << "datatype:8";
|
||||
} else {
|
||||
FILE_LOG(logERROR) << "Unknown datatype: " << datatype;
|
||||
return 1;
|
||||
throw RuntimeError("Unknown datatype:" + std::to_string(datatype));
|
||||
}
|
||||
FILE_LOG(logINFO) << "owenable:" << (owenable?1:0) << std::endl
|
||||
<< "oldFileName:" << oldFileName << std::endl
|
||||
@ -888,15 +832,13 @@ public:
|
||||
newfd->close();
|
||||
oldfd->close();
|
||||
} catch(const Exception& error){
|
||||
FILE_LOG(logERROR) << "Could not copy virtual files";
|
||||
error.printErrorStack();
|
||||
free(data_out);
|
||||
oldfd->close();
|
||||
newfd->close();
|
||||
return 1;
|
||||
throw RuntimeError("Could not copy virtual files");
|
||||
}
|
||||
free(data_out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -908,89 +850,80 @@ public:
|
||||
* @param virtualfname virtual file name
|
||||
* @param virtualDatasetname virtual dataset name
|
||||
* @param parameterNames parameter names
|
||||
* @returns 0 for success and 1 for fail
|
||||
*/
|
||||
static int LinkVirtualInMaster(std::string masterFileName, std::string virtualfname,
|
||||
static void LinkVirtualInMaster(std::string masterFileName, std::string virtualfname,
|
||||
std::string virtualDatasetname, std::vector <const char*> parameterNames) {
|
||||
char linkname[100];
|
||||
hid_t vfd = 0;
|
||||
|
||||
hid_t dfal = H5Pcreate (H5P_FILE_ACCESS);
|
||||
if (dfal < 0)
|
||||
return CloseFileOnError( vfd, std::string("Could not create file access property for link\n"));
|
||||
if (H5Pset_fclose_degree (dfal, H5F_CLOSE_STRONG) < 0)
|
||||
return CloseFileOnError( vfd, std::string("Could not set strong file close degree for link\n"));
|
||||
try {
|
||||
hid_t dfal = H5Pcreate (H5P_FILE_ACCESS);
|
||||
if (dfal < 0)
|
||||
throw RuntimeError("Could not create file access property for link");
|
||||
if (H5Pset_fclose_degree (dfal, H5F_CLOSE_STRONG) < 0)
|
||||
throw RuntimeError("Could not set strong file close degree for link");
|
||||
|
||||
//open master file
|
||||
hid_t mfd = H5Fopen( masterFileName.c_str(), H5F_ACC_RDWR, dfal);
|
||||
if (mfd < 0)
|
||||
return CloseFileOnError( vfd, std::string("Could not open master file\n"));
|
||||
//open master file
|
||||
hid_t mfd = H5Fopen( masterFileName.c_str(), H5F_ACC_RDWR, dfal);
|
||||
if (mfd < 0)
|
||||
throw RuntimeError("Could not open master file");
|
||||
|
||||
//open virtual file
|
||||
vfd = H5Fopen( virtualfname.c_str(), H5F_ACC_RDWR, dfal);
|
||||
if (vfd < 0) {
|
||||
H5Fclose(mfd); mfd = 0;
|
||||
return CloseFileOnError( vfd, std::string("Could not open virtual file\n"));
|
||||
}
|
||||
|
||||
// find relative path
|
||||
std::string relative_virtualfname = virtualfname;
|
||||
{
|
||||
size_t i = virtualfname.rfind('/', virtualfname.length());
|
||||
if (i != std::string::npos)
|
||||
relative_virtualfname = (virtualfname.substr(i+1, virtualfname.length() - i));
|
||||
}
|
||||
|
||||
//**data dataset**
|
||||
hid_t vdset = H5Dopen2( vfd, virtualDatasetname.c_str(), H5P_DEFAULT);
|
||||
if (vdset < 0) {
|
||||
H5Fclose(mfd);
|
||||
return CloseFileOnError( vfd, std::string("Could not open virtual data dataset\n"));
|
||||
}
|
||||
sprintf(linkname, "/entry/data/%s",virtualDatasetname.c_str());
|
||||
if(H5Lcreate_external( relative_virtualfname.c_str(), virtualDatasetname.c_str(),
|
||||
mfd, linkname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
|
||||
H5Fclose(mfd); mfd = 0;
|
||||
return CloseFileOnError( vfd, std::string("Could not create link to data dataset\n"));
|
||||
}
|
||||
H5Dclose(vdset);
|
||||
|
||||
//**paramter datasets**
|
||||
for (unsigned int i = 0; i < parameterNames.size(); ++i){
|
||||
hid_t vdset_para = H5Dopen2( vfd, (std::string (parameterNames[i])).c_str(), H5P_DEFAULT);
|
||||
if (vdset_para < 0) {
|
||||
//open virtual file
|
||||
vfd = H5Fopen( virtualfname.c_str(), H5F_ACC_RDWR, dfal);
|
||||
if (vfd < 0) {
|
||||
H5Fclose(mfd); mfd = 0;
|
||||
return CloseFileOnError( vfd, std::string("Could not open virtual parameter dataset to create link\n"));
|
||||
throw RuntimeError("Could not open virtual file");
|
||||
}
|
||||
sprintf(linkname, "/entry/data/%s",(std::string (parameterNames[i])).c_str());
|
||||
|
||||
if(H5Lcreate_external( relative_virtualfname.c_str(), (std::string (parameterNames[i])).c_str(),
|
||||
mfd, linkname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
|
||||
// find relative path
|
||||
std::string relative_virtualfname = virtualfname;
|
||||
{
|
||||
size_t i = virtualfname.rfind('/', virtualfname.length());
|
||||
if (i != std::string::npos)
|
||||
relative_virtualfname = (virtualfname.substr(i+1, virtualfname.length() - i));
|
||||
}
|
||||
|
||||
//**data dataset**
|
||||
hid_t vdset = H5Dopen2( vfd, virtualDatasetname.c_str(), H5P_DEFAULT);
|
||||
if (vdset < 0) {
|
||||
H5Fclose(mfd);
|
||||
throw RuntimeError("Could not open virtual data dataset");
|
||||
}
|
||||
sprintf(linkname, "/entry/data/%s",virtualDatasetname.c_str());
|
||||
if(H5Lcreate_external( relative_virtualfname.c_str(), virtualDatasetname.c_str(),
|
||||
mfd, linkname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
|
||||
H5Fclose(mfd); mfd = 0;
|
||||
return CloseFileOnError( vfd, std::string("Could not create link to virtual parameter dataset\n"));
|
||||
throw RuntimeError("Could not create link to data dataset");
|
||||
}
|
||||
}
|
||||
H5Dclose(vdset);
|
||||
|
||||
H5Fclose(mfd); mfd = 0;
|
||||
H5Fclose(vfd); vfd = 0;
|
||||
return 0;
|
||||
//**paramter datasets**
|
||||
for (unsigned int i = 0; i < parameterNames.size(); ++i){
|
||||
hid_t vdset_para = H5Dopen2( vfd, (std::string (parameterNames[i])).c_str(), H5P_DEFAULT);
|
||||
if (vdset_para < 0) {
|
||||
H5Fclose(mfd); mfd = 0;
|
||||
throw RuntimeError("Could not open virtual parameter dataset to create link");
|
||||
}
|
||||
sprintf(linkname, "/entry/data/%s",(std::string (parameterNames[i])).c_str());
|
||||
|
||||
if(H5Lcreate_external( relative_virtualfname.c_str(), (std::string (parameterNames[i])).c_str(),
|
||||
mfd, linkname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
|
||||
H5Fclose(mfd); mfd = 0;
|
||||
throw RuntimeError("Could not create link to virtual parameter dataset");
|
||||
}
|
||||
}
|
||||
|
||||
H5Fclose(mfd); mfd = 0;
|
||||
H5Fclose(vfd); vfd = 0;
|
||||
} catch () {
|
||||
if(vfd > 0)
|
||||
H5Fclose(vfd);
|
||||
vfd = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Print Error msg and Close File and called on error
|
||||
* @returns 1 for fail
|
||||
*/
|
||||
static int CloseFileOnError(hid_t& fd, const std::string msg) {
|
||||
FILE_LOG(logERROR) << msg;
|
||||
if(fd > 0)
|
||||
H5Fclose(fd);
|
||||
fd = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Data type in C
|
||||
* @param dtype datatype in C++
|
||||
|
@ -17,22 +17,16 @@ class slsDetectorDefs;
|
||||
|
||||
class Implementation : private virtual slsDetectorDefs {
|
||||
public:
|
||||
Implementation();
|
||||
Implementation(const detectorType d);
|
||||
virtual ~Implementation();
|
||||
|
||||
|
||||
/**************************************************
|
||||
* *
|
||||
* Configuration Parameters *
|
||||
* *
|
||||
* ************************************************/
|
||||
/**
|
||||
* Set receiver type. It is the first function called by the client when
|
||||
* connecting to receiver
|
||||
* @param d detector type
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
int setDetectorType(const detectorType d);
|
||||
|
||||
void setDetectorType(const detectorType d);
|
||||
int *getMultiDetectorSize() const;
|
||||
void setMultiDetectorSize(const int *size);
|
||||
int getDetectorPositionId() const;
|
||||
@ -42,7 +36,7 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
bool getSilentMode() const;
|
||||
void setSilentMode(const bool i);
|
||||
uint32_t getFifoDepth() const;
|
||||
int setFifoDepth(const uint32_t i);
|
||||
void setFifoDepth(const uint32_t i);
|
||||
frameDiscardPolicy getFrameDiscardPolicy() const;
|
||||
void setFrameDiscardPolicy(const frameDiscardPolicy i);
|
||||
bool getFramePaddingEnable() const;
|
||||
@ -81,13 +75,13 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
uint64_t getFramesCaught() const;
|
||||
uint64_t getAcquisitionIndex() const;
|
||||
std::vector<uint64_t> getNumMissingPackets() const;
|
||||
int startReceiver(std::string& err);
|
||||
void startReceiver();
|
||||
void setStoppedFlag(bool stopped);
|
||||
void stopReceiver();
|
||||
void startReadout();
|
||||
void shutDownUDPSockets();
|
||||
void closeFiles();
|
||||
int restreamStop();
|
||||
void restreamStop();
|
||||
|
||||
|
||||
/**************************************************
|
||||
@ -97,7 +91,7 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
* ************************************************/
|
||||
int getNumberofUDPInterfaces() const;
|
||||
/* [Jungfrau] */
|
||||
int setNumberofUDPInterfaces(const int n);
|
||||
void setNumberofUDPInterfaces(const int n);
|
||||
std::string getEthernetInterface() const;
|
||||
void setEthernetInterface(const std::string &c);
|
||||
std::string getEthernetInterface2() const;
|
||||
@ -109,7 +103,7 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
/* [Eiger][Jungfrau] */
|
||||
void setUDPPortNumber2(const uint32_t i);
|
||||
int64_t getUDPSocketBufferSize() const;
|
||||
int setUDPSocketBufferSize(const int64_t s);
|
||||
void setUDPSocketBufferSize(const int64_t s);
|
||||
int64_t getActualUDPSocketBufferSize() const;
|
||||
|
||||
|
||||
@ -119,10 +113,10 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
* *
|
||||
* ************************************************/
|
||||
bool getDataStreamEnable() const;
|
||||
int setDataStreamEnable(const bool enable);
|
||||
void setDataStreamEnable(const bool enable);
|
||||
uint32_t getStreamingFrequency() const;
|
||||
/* 0 for timer */
|
||||
int setStreamingFrequency(const uint32_t freq);
|
||||
void setStreamingFrequency(const uint32_t freq);
|
||||
uint32_t getStreamingTimer() const;
|
||||
void setStreamingTimer(const uint32_t time_in_ms);
|
||||
uint32_t getStreamingPort() const;
|
||||
@ -151,26 +145,26 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
void setSubPeriod(const uint64_t i);
|
||||
uint32_t getNumberofAnalogSamples() const;
|
||||
/**[Ctb][Moench] */
|
||||
int setNumberofAnalogSamples(const uint32_t i);
|
||||
void setNumberofAnalogSamples(const uint32_t i);
|
||||
uint32_t getNumberofDigitalSamples() const;
|
||||
/**[Ctb] */
|
||||
int setNumberofDigitalSamples(const uint32_t i);
|
||||
void setNumberofDigitalSamples(const uint32_t i);
|
||||
uint32_t getDynamicRange() const;
|
||||
int setDynamicRange(const uint32_t i);
|
||||
void setDynamicRange(const uint32_t i);
|
||||
ROI getROI() const;
|
||||
/* [Gotthard] */
|
||||
int setROI(ROI arg);
|
||||
void setROI(ROI arg);
|
||||
bool getTenGigaEnable() const;
|
||||
/* [Eiger][Ctb] */
|
||||
int setTenGigaEnable(const bool b);
|
||||
void setTenGigaEnable(const bool b);
|
||||
int getFlippedDataX() const;
|
||||
void setFlippedDataX(int enable = -1);
|
||||
bool getGapPixelsEnable() const;
|
||||
/* [Eiger] */
|
||||
int setGapPixelsEnable(const bool b);
|
||||
void setGapPixelsEnable(const bool b);
|
||||
bool getQuad() const;
|
||||
/* [Eiger] */
|
||||
int setQuad(const bool b);
|
||||
void setQuad(const bool b);
|
||||
bool getActivate() const;
|
||||
/** [Eiger] If deactivated, receiver will create dummy data if deactivated padding is enabled (as it will receive nothing from detector) */
|
||||
bool setActivate(const bool enable);
|
||||
@ -182,13 +176,13 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
void setReadNLines(const int value);
|
||||
readoutMode getReadoutMode() const;
|
||||
/* [Ctb] */
|
||||
int setReadoutMode(const readoutMode f);
|
||||
void setReadoutMode(const readoutMode f);
|
||||
uint32_t getADCEnableMask() const;
|
||||
/* [Ctb][Moench] */
|
||||
int setADCEnableMask(const uint32_t mask);
|
||||
void setADCEnableMask(const uint32_t mask);
|
||||
uint32_t getTenGigaADCEnableMask() const;
|
||||
/* [Ctb][Moench] */
|
||||
int setTenGigaADCEnableMask(const uint32_t mask);
|
||||
void setTenGigaADCEnableMask(const uint32_t mask);
|
||||
std::vector<int> getDbitList() const;
|
||||
/* [Ctb] */
|
||||
void setDbitList(const std::vector<int> v);
|
||||
@ -215,11 +209,11 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
void InitializeMembers();
|
||||
void SetLocalNetworkParameters();
|
||||
void SetThreadPriorities();
|
||||
int SetupFifoStructure();
|
||||
void SetupFifoStructure();
|
||||
|
||||
void ResetParametersforNewAcquisition();
|
||||
int CreateUDPSockets();
|
||||
int SetupWriter();
|
||||
void CreateUDPSockets();
|
||||
void SetupWriter();
|
||||
void StartRunning();
|
||||
|
||||
|
||||
|
@ -102,18 +102,10 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
|
||||
*/
|
||||
void SetGeneralData(GeneralData* g);
|
||||
|
||||
/**
|
||||
* Set thread priority
|
||||
* @priority priority
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int SetThreadPriority(int priority);
|
||||
|
||||
/**
|
||||
* Creates UDP Sockets
|
||||
* @return OK or FAIL
|
||||
*/
|
||||
int CreateUDPSockets();
|
||||
void CreateUDPSockets();
|
||||
|
||||
/**
|
||||
* Shuts down and deletes UDP Sockets
|
||||
@ -124,9 +116,8 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
|
||||
* Create & closes a dummy UDP socket
|
||||
* to set & get actual buffer size
|
||||
* @param s UDP socket buffer size to be set
|
||||
* @return OK or FAIL of dummy socket creation
|
||||
*/
|
||||
int CreateDummySocketForUDPSocketBufferSize(int64_t s);
|
||||
void CreateDummySocketForUDPSocketBufferSize(int64_t s);
|
||||
|
||||
/**
|
||||
* Set hard coded (calculated but not from detector) row and column
|
||||
@ -139,12 +130,6 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
* @return type
|
||||
*/
|
||||
std::string GetType() override;
|
||||
|
||||
/**
|
||||
* Record First Acquisition Index
|
||||
* @param fnum frame index to record
|
||||
|
@ -10,77 +10,27 @@
|
||||
#include "sls_detector_defs.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <semaphore.h>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
|
||||
class ThreadObject : private virtual slsDetectorDefs {
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param ind self index
|
||||
*/
|
||||
ThreadObject(int ind);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* if alive, destroys thread
|
||||
*/
|
||||
ThreadObject(int threadIndex, std::string threadType);
|
||||
virtual ~ThreadObject();
|
||||
|
||||
/**
|
||||
* Print all member values
|
||||
*/
|
||||
void PrintMembers();
|
||||
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
* @return type
|
||||
*/
|
||||
virtual std::string GetType() = 0;
|
||||
|
||||
/**
|
||||
* Returns if the thread is currently running
|
||||
* @returns true if thread is running, else false
|
||||
*/
|
||||
virtual bool IsRunning() = 0;
|
||||
|
||||
/**
|
||||
* What is really being executed in the thread
|
||||
*/
|
||||
virtual void ThreadExecution() = 0;
|
||||
|
||||
/**
|
||||
* Post semaphore so thread can continue & start an acquisition
|
||||
*/
|
||||
void Continue();
|
||||
void SetThreadPriority(int priority);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Destroy thread, semaphore and resets alive and killThread
|
||||
*/
|
||||
void DestroyThread();
|
||||
|
||||
/**
|
||||
* Create Thread, sets semaphore, alive and killThread
|
||||
* @return OK if successful, else FAIL
|
||||
*/
|
||||
int CreateThread();
|
||||
|
||||
virtual void ThreadExecution() = 0;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Static function using pointer from argument to call RunningThread()
|
||||
* @param thisPointer pointer to an object of ThreadObject
|
||||
*/
|
||||
static void* StartThread(void *thisPointer);
|
||||
|
||||
/**
|
||||
* Actual Thread called: An infinite while loop in which,
|
||||
* Thread called: An infinite while loop in which,
|
||||
* semaphore starts executing its contents as long RunningMask is satisfied
|
||||
* Then it exits the thread on its own if killThread is true
|
||||
*/
|
||||
@ -88,22 +38,10 @@ class ThreadObject : private virtual slsDetectorDefs {
|
||||
|
||||
|
||||
protected:
|
||||
/** Self Index */
|
||||
int index;
|
||||
|
||||
/** Thread is alive/dead */
|
||||
volatile bool alive;
|
||||
|
||||
/** Variable monitored by thread to kills itself */
|
||||
volatile bool killThread;
|
||||
|
||||
/** Thread variable */
|
||||
pthread_t thread;
|
||||
|
||||
/** Semaphore to synchonize starting of each run */
|
||||
int index{0};
|
||||
std::string type;
|
||||
std::atomic<bool> killThread{false};
|
||||
std::unique_ptr<std::thread> threadObject;
|
||||
sem_t semaphore;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -42,20 +42,18 @@ slsDetectorDefs::fileFormat BinaryFile::GetFileType() {
|
||||
}
|
||||
|
||||
|
||||
int BinaryFile::CreateFile() {
|
||||
void BinaryFile::CreateFile() {
|
||||
numFramesInFile = 0;
|
||||
numActualPacketsInFile = 0;
|
||||
|
||||
currentFileName = BinaryFileStatic::CreateFileName(*filePath, *fileNamePrefix, *fileIndex,
|
||||
subFileIndex, *detIndex, *numUnitsPerDetector, index);
|
||||
|
||||
if (BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE) == FAIL)
|
||||
return FAIL;
|
||||
BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE);
|
||||
|
||||
if(!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << "[" << *udpPortNumber << "]: Binary File created: " << currentFileName;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
void BinaryFile::CloseCurrentFile() {
|
||||
@ -68,7 +66,7 @@ void BinaryFile::CloseAllFiles() {
|
||||
BinaryFileStatic::CloseDataFile(masterfd);
|
||||
}
|
||||
|
||||
int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
||||
void BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
||||
// check if maxframesperfile = 0 for infinite
|
||||
if ((*maxFramesPerFile) && (numFramesInFile >= (*maxFramesPerFile))) {
|
||||
CloseCurrentFile();
|
||||
@ -107,14 +105,12 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_
|
||||
|
||||
// if write error
|
||||
if (ret != buffersize) {
|
||||
FILE_LOG(logERROR) << index << " Error: Write to file failed for image number " << fnum;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError(std::to_string(index) + " : Write to file failed for image number " + std::to_string(fnum));
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
void BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
//beginning of every acquisition
|
||||
numFramesInFile = 0;
|
||||
numActualPacketsInFile = 0;
|
||||
@ -126,10 +122,9 @@ int BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
FILE_LOG(logINFO) << "Master File: " << masterFileName;
|
||||
}
|
||||
attr.version = BINARY_WRITER_VERSION;
|
||||
return BinaryFileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
BinaryFileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
*overWriteEnable, attr);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,38 +20,24 @@ using sls::RuntimeError;
|
||||
using sls::SocketError;
|
||||
using Interface = sls::ServerInterface2;
|
||||
|
||||
ClientInterface::~ClientInterface() { stopTCPSocket(); }
|
||||
ClientInterface::~ClientInterface() {
|
||||
killTcpThread = true;
|
||||
// shut down tcp sockets
|
||||
if (server.get() != nullptr) {
|
||||
FILE_LOG(logINFO) << "Shutting down TCP Socket on port " << portNumber;
|
||||
server->shutDownSocket();
|
||||
FILE_LOG(logDEBUG) << "TCP Socket closed on port " << portNumber;
|
||||
}
|
||||
// shut down tcp thread
|
||||
tcpThread->join();
|
||||
}
|
||||
|
||||
ClientInterface::ClientInterface(int portNumber)
|
||||
: myDetectorType(GOTTHARD), portNumber(portNumber > 0 ? portNumber : DEFAULT_PORTNO + 2) {
|
||||
function_table();
|
||||
startTCPSocket();
|
||||
}
|
||||
|
||||
void ClientInterface::startTCPSocket() {
|
||||
FILE_LOG(logDEBUG) << "Creating TCP Server Thread";
|
||||
killTCPServerThread = 0;
|
||||
if (pthread_create(&TCPServer_thread, nullptr, startTCPServerThread,
|
||||
(void *)this)) {
|
||||
throw RuntimeError("Could not create TCP Server thread");
|
||||
}
|
||||
tcpThreadCreated = true;
|
||||
FILE_LOG(logDEBUG) << "TCP Server thread created successfully.";
|
||||
}
|
||||
|
||||
void ClientInterface::stopTCPSocket() {
|
||||
if (tcpThreadCreated) {
|
||||
FILE_LOG(logINFO) << "Shutting down TCP Socket on port " << portNumber;
|
||||
killTCPServerThread = 1;
|
||||
if (server)
|
||||
server->shutDownSocket();
|
||||
FILE_LOG(logDEBUG) << "TCP Socket closed on port " << portNumber;
|
||||
pthread_join(TCPServer_thread, nullptr);
|
||||
tcpThreadCreated = false;
|
||||
killTCPServerThread = 0;
|
||||
FILE_LOG(logDEBUG) << "Exiting TCP Server Thread on port "
|
||||
<< portNumber;
|
||||
}
|
||||
: myDetectorType(GOTTHARD),
|
||||
portNumber(portNumber > 0 ? portNumber : DEFAULT_PORTNO + 2) {
|
||||
functionTable();
|
||||
// start up tcp thread
|
||||
tcpThread = sls::make_unique<std::thread>(&ClientInterface::startTCPServer, this);
|
||||
}
|
||||
|
||||
int64_t ClientInterface::getReceiverVersion() { return APIRECEIVER; }
|
||||
@ -81,14 +67,8 @@ void ClientInterface::registerCallBackRawDataModifyReady(
|
||||
pRawDataReady = arg;
|
||||
}
|
||||
|
||||
void *ClientInterface::startTCPServerThread(void *this_pointer) {
|
||||
((ClientInterface *)this_pointer)->startTCPServer();
|
||||
return this_pointer;
|
||||
}
|
||||
|
||||
void ClientInterface::startTCPServer() {
|
||||
FILE_LOG(logINFOBLUE) << "Created [ TCP server Tid: " << syscall(SYS_gettid)
|
||||
<< "]";
|
||||
FILE_LOG(logINFOBLUE) << "Created [ TCP server Tid: " << syscall(SYS_gettid) << "]";
|
||||
FILE_LOG(logINFO) << "SLS Receiver starting TCP Server on port "
|
||||
<< portNumber << '\n';
|
||||
server = sls::make_unique<sls::ServerSocket>(portNumber);
|
||||
@ -97,8 +77,8 @@ void ClientInterface::startTCPServer() {
|
||||
try {
|
||||
auto socket = server->accept();
|
||||
try {
|
||||
VerifyLock();
|
||||
ret = decode_function(socket);
|
||||
verifyLock();
|
||||
ret = decodeFunction(socket);
|
||||
} catch (const RuntimeError &e) {
|
||||
// We had an error needs to be sent to client
|
||||
char mess[MAX_STR_LENGTH]{};
|
||||
@ -106,37 +86,27 @@ void ClientInterface::startTCPServer() {
|
||||
socket.Send(FAIL);
|
||||
socket.Send(mess);
|
||||
}
|
||||
|
||||
// if tcp command was to exit server
|
||||
if (ret == GOODBYE) {
|
||||
FILE_LOG(logINFO) << "Shutting down UDP Socket";
|
||||
if (receiver) {
|
||||
receiver->shutDownUDPSockets();
|
||||
}
|
||||
FILE_LOG(logINFOBLUE)
|
||||
<< "Exiting [ TCP server Tid: " << syscall(SYS_gettid)
|
||||
<< "]";
|
||||
pthread_exit(nullptr);
|
||||
break;
|
||||
}
|
||||
} catch (const RuntimeError &e) {
|
||||
FILE_LOG(logERROR) << "Accept failed";
|
||||
}
|
||||
|
||||
// if user entered exit
|
||||
if (killTCPServerThread) {
|
||||
if (ret != GOODBYE) {
|
||||
if (receiver) {
|
||||
receiver->shutDownUDPSockets();
|
||||
}
|
||||
}
|
||||
FILE_LOG(logINFOBLUE)
|
||||
<< "Exiting [ TCP server Tid: " << syscall(SYS_gettid) << "]";
|
||||
pthread_exit(nullptr);
|
||||
// destructor to kill this thread
|
||||
if (killTcpThread) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (receiver) {
|
||||
receiver->shutDownUDPSockets();
|
||||
}
|
||||
FILE_LOG(logINFOBLUE) << "Exiting [ TCP server Tid: " << syscall(SYS_gettid) << "]";
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
int ClientInterface::function_table(){
|
||||
int ClientInterface::functionTable(){
|
||||
flist[F_EXEC_RECEIVER_COMMAND] = &ClientInterface::exec_command;
|
||||
flist[F_EXIT_RECEIVER] = &ClientInterface::exit_server;
|
||||
flist[F_LOCK_RECEIVER] = &ClientInterface::lock_receiver;
|
||||
@ -207,35 +177,35 @@ int ClientInterface::function_table(){
|
||||
|
||||
|
||||
for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) {
|
||||
// FILE_LOG(logDEBUG1) << "function fnum: " << i << " (" <<
|
||||
// getFunctionNameFromEnum((enum detFuncs)i) << ") located at " << flist[i];
|
||||
FILE_LOG(logDEBUG1) << "function fnum: " << i << " (" <<
|
||||
getFunctionNameFromEnum((enum detFuncs)i) << ") located at " << flist[i];
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
// clang-format on
|
||||
int ClientInterface::decode_function(Interface &socket) {
|
||||
int ClientInterface::decodeFunction(Interface &socket) {
|
||||
ret = FAIL;
|
||||
socket.Receive(fnum);
|
||||
if (fnum <= NUM_DET_FUNCTIONS || fnum >= NUM_REC_FUNCTIONS) {
|
||||
throw RuntimeError("Unrecognized Function enum " +
|
||||
std::to_string(fnum) + "\n");
|
||||
} else {
|
||||
// FILE_LOG(logDEBUG1) << "calling function fnum: " << fnum << " ("
|
||||
// << getFunctionNameFromEnum((enum detFuncs)fnum)
|
||||
// << ")";
|
||||
FILE_LOG(logDEBUG1) << "calling function fnum: " << fnum << " ("
|
||||
<< getFunctionNameFromEnum((enum detFuncs)fnum)
|
||||
<< ")";
|
||||
ret = (this->*flist[fnum])(socket);
|
||||
// FILE_LOG(logDEBUG1)
|
||||
// << "Function " << getFunctionNameFromEnum((enum detFuncs)fnum)
|
||||
// << " finished";
|
||||
FILE_LOG(logDEBUG1)
|
||||
<< "Function " << getFunctionNameFromEnum((enum detFuncs)fnum)
|
||||
<< " finished";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ClientInterface::functionNotImplemented() {
|
||||
std::ostringstream os;
|
||||
// os << "Function: " << getFunctionNameFromEnum((enum detFuncs)fnum)
|
||||
// << ", is is not implemented for this detector";
|
||||
os << "Function: " << getFunctionNameFromEnum((enum detFuncs)fnum)
|
||||
<< ", is is not implemented for this detector";
|
||||
throw RuntimeError(os.str());
|
||||
}
|
||||
|
||||
@ -259,13 +229,13 @@ void ClientInterface::validate(T arg, T retval, std::string modename,
|
||||
}
|
||||
}
|
||||
|
||||
void ClientInterface::VerifyLock() {
|
||||
if (lockStatus && server->getThisClient() != server->getLockedBy()) {
|
||||
void ClientInterface::verifyLock() {
|
||||
if (lockedByClient && server->getThisClient() != server->getLockedBy()) {
|
||||
throw sls::SocketError("Receiver locked\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ClientInterface::VerifyIdle(Interface &socket) {
|
||||
void ClientInterface::verifyIdle(Interface &socket) {
|
||||
if (impl()->getStatus() != IDLE) {
|
||||
std::ostringstream oss;
|
||||
oss << "Can not execute " << getFunctionNameFromEnum((enum detFuncs)fnum)
|
||||
@ -306,15 +276,15 @@ int ClientInterface::lock_receiver(Interface &socket) {
|
||||
auto lock = socket.Receive<int>();
|
||||
FILE_LOG(logDEBUG1) << "Locking Server to " << lock;
|
||||
if (lock >= 0) {
|
||||
if (!lockStatus || (server->getLockedBy() == server->getThisClient())) {
|
||||
lockStatus = lock;
|
||||
if (!lockedByClient || (server->getLockedBy() == server->getThisClient())) {
|
||||
lockedByClient = lock;
|
||||
lock ? server->setLockedBy(server->getThisClient())
|
||||
: server->setLockedBy(sls::IpAddr{});
|
||||
} else {
|
||||
throw RuntimeError("Receiver locked\n");
|
||||
}
|
||||
}
|
||||
return socket.sendResult(lockStatus);
|
||||
return socket.sendResult(lockedByClient);
|
||||
}
|
||||
|
||||
int ClientInterface::get_last_client_ip(Interface &socket) {
|
||||
@ -458,7 +428,7 @@ int ClientInterface::set_detector_type(Interface &socket) {
|
||||
// if object exists, verify unlocked and idle, else only verify lock
|
||||
// (connecting first time)
|
||||
if (receiver != nullptr) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
}
|
||||
switch (arg) {
|
||||
case GOTTHARD:
|
||||
@ -473,11 +443,11 @@ int ClientInterface::set_detector_type(Interface &socket) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (receiver == nullptr) {
|
||||
receiver = sls::make_unique<Implementation>();
|
||||
}
|
||||
myDetectorType = arg;
|
||||
if (impl()->setDetectorType(myDetectorType) == FAIL) {
|
||||
try {
|
||||
myDetectorType = GENERIC;
|
||||
receiver = sls::make_unique<Implementation>(arg);
|
||||
myDetectorType = arg;
|
||||
} catch (...) {
|
||||
throw RuntimeError("Could not set detector type");
|
||||
}
|
||||
|
||||
@ -504,7 +474,7 @@ int ClientInterface::set_detector_hostname(Interface &socket) {
|
||||
socket.Receive(hostname);
|
||||
|
||||
if (strlen(hostname) != 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
impl()->setDetectorHostname(hostname);
|
||||
}
|
||||
auto s = impl()->getDetectorHostname();
|
||||
@ -524,9 +494,12 @@ int ClientInterface::set_roi(Interface &socket) {
|
||||
if (myDetectorType != GOTTHARD)
|
||||
functionNotImplemented();
|
||||
|
||||
VerifyIdle(socket);
|
||||
if (impl()->setROI(arg) == FAIL)
|
||||
verifyIdle(socket);
|
||||
try {
|
||||
impl()->setROI(arg);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set ROI");
|
||||
}
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
@ -543,7 +516,11 @@ int ClientInterface::set_num_analog_samples(Interface &socket) {
|
||||
if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) {
|
||||
functionNotImplemented();
|
||||
}
|
||||
ret = impl()->setNumberofAnalogSamples(value);
|
||||
try {
|
||||
impl()->setNumberofAnalogSamples(value);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set num analog samples to " + std::to_string(value) + " due to fifo structure memory allocation.");
|
||||
}
|
||||
|
||||
return socket.Send(OK);
|
||||
}
|
||||
@ -554,7 +531,11 @@ int ClientInterface::set_num_digital_samples(Interface &socket) {
|
||||
if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) {
|
||||
functionNotImplemented();
|
||||
}
|
||||
ret = impl()->setNumberofDigitalSamples(value);
|
||||
try {
|
||||
impl()->setNumberofDigitalSamples(value);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set num digital samples to " + std::to_string(value) + " due to fifo structure memory allocation.");
|
||||
}
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
@ -590,7 +571,7 @@ int ClientInterface::set_subdeadtime(Interface &socket) {
|
||||
int ClientInterface::set_dynamic_range(Interface &socket) {
|
||||
auto dr = socket.Receive<int>();
|
||||
if (dr >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting dynamic range: " << dr;
|
||||
bool exists = false;
|
||||
switch(myDetectorType) {
|
||||
@ -613,8 +594,9 @@ int ClientInterface::set_dynamic_range(Interface &socket) {
|
||||
if (!exists) {
|
||||
modeNotImplemented("Dynamic range", dr);
|
||||
} else {
|
||||
ret = impl()->setDynamicRange(dr);
|
||||
if (ret == FAIL) {
|
||||
try {
|
||||
impl()->setDynamicRange(dr);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not allocate memory for fifo or "
|
||||
"could not start listening/writing threads");
|
||||
}
|
||||
@ -629,12 +611,9 @@ int ClientInterface::set_dynamic_range(Interface &socket) {
|
||||
int ClientInterface::set_streaming_frequency(Interface &socket) {
|
||||
auto index = socket.Receive<int>();
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting streaming frequency: " << index;
|
||||
ret = impl()->setStreamingFrequency(index);
|
||||
if (ret == FAIL) {
|
||||
throw RuntimeError("Could not allocate memory for listening fifo");
|
||||
}
|
||||
impl()->setStreamingFrequency(index);
|
||||
}
|
||||
int retval = impl()->getStreamingFrequency();
|
||||
validate(index, retval, "set streaming frequency", DEC);
|
||||
@ -650,11 +629,7 @@ int ClientInterface::get_status(Interface &socket) {
|
||||
int ClientInterface::start_receiver(Interface &socket) {
|
||||
if (impl()->getStatus() == IDLE) {
|
||||
FILE_LOG(logDEBUG1) << "Starting Receiver";
|
||||
std::string err;
|
||||
ret = impl()->startReceiver(err);
|
||||
if (ret == FAIL) {
|
||||
throw RuntimeError(err);
|
||||
}
|
||||
impl()->startReceiver();
|
||||
}
|
||||
return socket.Send(OK);
|
||||
}
|
||||
@ -715,7 +690,7 @@ int ClientInterface::set_file_name(Interface &socket) {
|
||||
int ClientInterface::set_file_index(Interface &socket) {
|
||||
auto index = socket.Receive<int64_t>();
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting file index: " << index;
|
||||
impl()->setFileIndex(index);
|
||||
}
|
||||
@ -752,7 +727,7 @@ int ClientInterface::get_frames_caught(Interface &socket) {
|
||||
int ClientInterface::enable_file_write(Interface &socket) {
|
||||
auto enable = socket.Receive<int>();
|
||||
if (enable >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting File write enable:" << enable;
|
||||
impl()->setFileWriteEnable(enable);
|
||||
}
|
||||
@ -765,7 +740,7 @@ int ClientInterface::enable_file_write(Interface &socket) {
|
||||
int ClientInterface::enable_master_file_write(Interface &socket) {
|
||||
auto enable = socket.Receive<int>();
|
||||
if (enable >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting Master File write enable:" << enable;
|
||||
impl()->setMasterFileWriteEnable(enable);
|
||||
}
|
||||
@ -778,7 +753,7 @@ int ClientInterface::enable_master_file_write(Interface &socket) {
|
||||
int ClientInterface::enable_overwrite(Interface &socket) {
|
||||
auto index = socket.Receive<int>();
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting File overwrite enable:" << index;
|
||||
impl()->setOverwriteEnable(index);
|
||||
}
|
||||
@ -795,9 +770,13 @@ int ClientInterface::enable_tengiga(Interface &socket) {
|
||||
functionNotImplemented();
|
||||
|
||||
if (val >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting 10GbE:" << val;
|
||||
ret = impl()->setTenGigaEnable(val);
|
||||
try {
|
||||
impl()->setTenGigaEnable(val);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set 10GbE.");
|
||||
}
|
||||
}
|
||||
int retval = impl()->getTenGigaEnable();
|
||||
validate(val, retval, "set 10GbE", DEC);
|
||||
@ -808,9 +787,13 @@ int ClientInterface::enable_tengiga(Interface &socket) {
|
||||
int ClientInterface::set_fifo_depth(Interface &socket) {
|
||||
auto value = socket.Receive<int>();
|
||||
if (value >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting fifo depth:" << value;
|
||||
impl()->setFifoDepth(value);
|
||||
try {
|
||||
impl()->setFifoDepth(value);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set fifo depth due to fifo structure memory allocation.");
|
||||
}
|
||||
}
|
||||
int retval = impl()->getFifoDepth();
|
||||
validate(value, retval, std::string("set fifo depth"), DEC);
|
||||
@ -824,7 +807,7 @@ int ClientInterface::set_activate(Interface &socket) {
|
||||
functionNotImplemented();
|
||||
|
||||
if (enable >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting activate:" << enable;
|
||||
impl()->setActivate(static_cast<bool>(enable));
|
||||
}
|
||||
@ -837,9 +820,13 @@ int ClientInterface::set_activate(Interface &socket) {
|
||||
int ClientInterface::set_data_stream_enable(Interface &socket) {
|
||||
auto index = socket.Receive<int>();
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting data stream enable:" << index;
|
||||
impl()->setDataStreamEnable(index);
|
||||
try {
|
||||
impl()->setDataStreamEnable(index);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set data stream enable to " + std::to_string(index));
|
||||
}
|
||||
}
|
||||
auto retval = static_cast<int>(impl()->getDataStreamEnable());
|
||||
validate(index, retval, "set data stream enable", DEC);
|
||||
@ -850,7 +837,7 @@ int ClientInterface::set_data_stream_enable(Interface &socket) {
|
||||
int ClientInterface::set_streaming_timer(Interface &socket) {
|
||||
auto index = socket.Receive<int>();
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting streaming timer:" << index;
|
||||
impl()->setStreamingTimer(index);
|
||||
}
|
||||
@ -867,7 +854,7 @@ int ClientInterface::set_flipped_data(Interface &socket) {
|
||||
functionNotImplemented();
|
||||
|
||||
if (arg >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting flipped data:" << arg;
|
||||
impl()->setFlippedDataX(arg);
|
||||
}
|
||||
@ -881,7 +868,7 @@ int ClientInterface::set_file_format(Interface &socket) {
|
||||
fileFormat f = GET_FILE_FORMAT;
|
||||
socket.Receive(f);
|
||||
if (f >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting file format:" << f;
|
||||
impl()->setFileFormat(f);
|
||||
}
|
||||
@ -894,7 +881,7 @@ int ClientInterface::set_file_format(Interface &socket) {
|
||||
int ClientInterface::set_detector_posid(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
if (arg >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting detector position id:" << arg;
|
||||
impl()->setDetectorPositionId(arg);
|
||||
}
|
||||
@ -908,7 +895,7 @@ int ClientInterface::set_multi_detector_size(Interface &socket) {
|
||||
int arg[]{-1, -1};
|
||||
socket.Receive(arg);
|
||||
if ((arg[0] > 0) && (arg[1] > 0)) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1)
|
||||
<< "Setting multi detector size:" << arg[0] << "," << arg[1];
|
||||
impl()->setMultiDetectorSize(arg);
|
||||
@ -922,7 +909,7 @@ int ClientInterface::set_multi_detector_size(Interface &socket) {
|
||||
int ClientInterface::set_streaming_port(Interface &socket) {
|
||||
auto port = socket.Receive<int>();
|
||||
if (port >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting streaming port:" << port;
|
||||
impl()->setStreamingPort(port);
|
||||
}
|
||||
@ -935,7 +922,7 @@ int ClientInterface::set_streaming_port(Interface &socket) {
|
||||
int ClientInterface::set_streaming_source_ip(Interface &socket) {
|
||||
sls::IpAddr arg = 0u;
|
||||
socket.Receive(arg);
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting streaming source ip:" << arg;
|
||||
impl()->setStreamingSourceIP(arg);
|
||||
sls::IpAddr retval = impl()->getStreamingSourceIP();
|
||||
@ -951,7 +938,7 @@ int ClientInterface::set_streaming_source_ip(Interface &socket) {
|
||||
int ClientInterface::set_silent_mode(Interface &socket) {
|
||||
auto value = socket.Receive<int>();
|
||||
if (value >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting silent mode:" << value;
|
||||
impl()->setSilentMode(value);
|
||||
}
|
||||
@ -967,9 +954,13 @@ int ClientInterface::enable_gap_pixels(Interface &socket) {
|
||||
functionNotImplemented();
|
||||
|
||||
if (enable >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting gap pixels enable:" << enable;
|
||||
impl()->setGapPixelsEnable(static_cast<bool>(enable));
|
||||
try {
|
||||
impl()->setGapPixelsEnable(static_cast<bool>(enable));
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set gap pixels enable to " + std::to_string(enable));
|
||||
}
|
||||
}
|
||||
auto retval = static_cast<int>(impl()->getGapPixelsEnable());
|
||||
validate(enable, retval, "set gap pixels enable", DEC);
|
||||
@ -978,7 +969,7 @@ int ClientInterface::enable_gap_pixels(Interface &socket) {
|
||||
}
|
||||
|
||||
int ClientInterface::restream_stop(Interface &socket) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
if (!impl()->getDataStreamEnable()) {
|
||||
throw RuntimeError(
|
||||
"Could not restream stop packet as data Streaming is disabled");
|
||||
@ -993,7 +984,7 @@ int ClientInterface::set_additional_json_header(Interface &socket) {
|
||||
char arg[MAX_STR_LENGTH]{};
|
||||
char retval[MAX_STR_LENGTH]{};
|
||||
socket.Receive(arg);
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting additional json header: " << arg;
|
||||
impl()->setAdditionalJsonHeader(arg);
|
||||
sls::strcpy_safe(retval, impl()->getAdditionalJsonHeader().c_str());
|
||||
@ -1011,12 +1002,9 @@ int ClientInterface::get_additional_json_header(Interface &socket) {
|
||||
int ClientInterface::set_udp_socket_buffer_size(Interface &socket) {
|
||||
auto index = socket.Receive<int64_t>();
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting UDP Socket Buffer size: " << index;
|
||||
if (impl()->setUDPSocketBufferSize(index) == FAIL) {
|
||||
throw RuntimeError(
|
||||
"Could not create dummy UDP Socket to test buffer size");
|
||||
}
|
||||
impl()->setUDPSocketBufferSize(index);
|
||||
}
|
||||
int64_t retval = impl()->getUDPSocketBufferSize();
|
||||
if (index != 0)
|
||||
@ -1037,7 +1025,7 @@ int ClientInterface::get_real_udp_socket_buffer_size(
|
||||
int ClientInterface::set_frames_per_file(Interface &socket) {
|
||||
auto index = socket.Receive<int>();
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting frames per file: " << index;
|
||||
impl()->setFramesPerFile(index);
|
||||
}
|
||||
@ -1078,7 +1066,7 @@ int ClientInterface::check_version_compatibility(Interface &socket) {
|
||||
int ClientInterface::set_discard_policy(Interface &socket) {
|
||||
auto index = socket.Receive<int>();
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting frames discard policy: " << index;
|
||||
impl()->setFrameDiscardPolicy(static_cast<frameDiscardPolicy>(index));
|
||||
}
|
||||
@ -1091,7 +1079,7 @@ int ClientInterface::set_discard_policy(Interface &socket) {
|
||||
int ClientInterface::set_padding_enable(Interface &socket) {
|
||||
auto index = socket.Receive<int>();
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting frames padding enable: " << index;
|
||||
impl()->setFramePaddingEnable(static_cast<bool>(index));
|
||||
}
|
||||
@ -1108,7 +1096,7 @@ int ClientInterface::set_deactivated_padding_enable(
|
||||
functionNotImplemented();
|
||||
|
||||
if (enable >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting deactivated padding enable: " << enable;
|
||||
impl()->setDeactivatedPadding(enable > 0);
|
||||
}
|
||||
@ -1125,9 +1113,13 @@ int ClientInterface::set_readout_mode(Interface &socket) {
|
||||
functionNotImplemented();
|
||||
|
||||
if (arg >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting readout mode: " << arg;
|
||||
impl()->setReadoutMode(arg);
|
||||
try {
|
||||
impl()->setReadoutMode(arg);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set read out mode due to fifo memory allocation.");
|
||||
}
|
||||
}
|
||||
auto retval = impl()->getReadoutMode();
|
||||
validate(static_cast<int>(arg), static_cast<int>(retval),
|
||||
@ -1138,9 +1130,13 @@ int ClientInterface::set_readout_mode(Interface &socket) {
|
||||
|
||||
int ClientInterface::set_adc_mask(Interface &socket) {
|
||||
auto arg = socket.Receive<uint32_t>();
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting 1Gb ADC enable mask: " << arg;
|
||||
impl()->setADCEnableMask(arg);
|
||||
try {
|
||||
impl()->setADCEnableMask(arg);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set adc enable mask due to fifo memory allcoation");
|
||||
}
|
||||
auto retval = impl()->getADCEnableMask();
|
||||
if (retval != arg) {
|
||||
std::ostringstream os;
|
||||
@ -1160,7 +1156,7 @@ int ClientInterface::set_dbit_list(Interface &socket) {
|
||||
FILE_LOG(logDEBUG1) << it << " ";
|
||||
}
|
||||
FILE_LOG(logDEBUG1) << "\n";
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
impl()->setDbitList(args);
|
||||
return socket.Send(OK);
|
||||
}
|
||||
@ -1175,7 +1171,7 @@ int ClientInterface::get_dbit_list(Interface &socket) {
|
||||
int ClientInterface::set_dbit_offset(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
if (arg >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting Dbit offset: " << arg;
|
||||
impl()->setDbitOffset(arg);
|
||||
}
|
||||
@ -1188,12 +1184,13 @@ int ClientInterface::set_dbit_offset(Interface &socket) {
|
||||
int ClientInterface::set_quad_type(Interface &socket) {
|
||||
auto quadEnable = socket.Receive<int>();
|
||||
if (quadEnable >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting quad:" << quadEnable;
|
||||
ret = impl()->setQuad(quadEnable == 0 ? false : true);
|
||||
if (ret == FAIL) {
|
||||
throw RuntimeError("Could not set Quad due to fifo structure");
|
||||
}
|
||||
try {
|
||||
impl()->setQuad(quadEnable == 0 ? false : true);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set quad to " + std::to_string(quadEnable) + " due to fifo strucutre memory allocation");
|
||||
}
|
||||
}
|
||||
int retval = impl()->getQuad() ? 1 : 0;
|
||||
validate(quadEnable, retval, "set quad", DEC);
|
||||
@ -1204,7 +1201,7 @@ int ClientInterface::set_quad_type(Interface &socket) {
|
||||
int ClientInterface::set_read_n_lines(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
if (arg >= 0) {
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting Read N Lines:" << arg;
|
||||
impl()->setReadNLines(arg);
|
||||
}
|
||||
@ -1217,7 +1214,7 @@ int ClientInterface::set_read_n_lines(Interface &socket) {
|
||||
|
||||
int ClientInterface::set_udp_ip(Interface &socket) {
|
||||
auto arg = socket.Receive<sls::IpAddr>();
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logINFO) << "Received UDP IP: " << arg;
|
||||
// getting eth
|
||||
std::string eth = sls::IpToInterfaceName(arg.str());
|
||||
@ -1244,7 +1241,7 @@ int ClientInterface::set_udp_ip(Interface &socket) {
|
||||
|
||||
int ClientInterface::set_udp_ip2(Interface &socket) {
|
||||
auto arg = socket.Receive<sls::IpAddr>();
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
if (myDetectorType != JUNGFRAU) {
|
||||
throw RuntimeError("UDP Destination IP2 not implemented for this detector");
|
||||
}
|
||||
@ -1271,7 +1268,7 @@ int ClientInterface::set_udp_ip2(Interface &socket) {
|
||||
|
||||
int ClientInterface::set_udp_port(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting UDP Port:" << arg;
|
||||
impl()->setUDPPortNumber(arg);
|
||||
return socket.Send(OK);
|
||||
@ -1279,7 +1276,7 @@ int ClientInterface::set_udp_port(Interface &socket) {
|
||||
|
||||
int ClientInterface::set_udp_port2(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
if (myDetectorType != JUNGFRAU && myDetectorType != EIGER) {
|
||||
throw RuntimeError("UDP Destination Port2 not implemented for this detector");
|
||||
}
|
||||
@ -1291,22 +1288,28 @@ int ClientInterface::set_udp_port2(Interface &socket) {
|
||||
int ClientInterface::set_num_interfaces(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
arg = (arg > 1 ? 2 : 1);
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
if (myDetectorType != JUNGFRAU) {
|
||||
throw RuntimeError("Number of interfaces not implemented for this detector");
|
||||
}
|
||||
FILE_LOG(logDEBUG1) << "Setting Number of UDP Interfaces:" << arg;
|
||||
if (impl()->setNumberofUDPInterfaces(arg) == FAIL) {
|
||||
throw RuntimeError("Failed to set number of interfaces");
|
||||
try {
|
||||
impl()->setNumberofUDPInterfaces(arg);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Failed to set number of interfaces to " + std::to_string(arg));
|
||||
}
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
int ClientInterface::set_adc_mask_10g(Interface &socket) {
|
||||
auto arg = socket.Receive<uint32_t>();
|
||||
VerifyIdle(socket);
|
||||
verifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting 10Gb ADC enable mask: " << arg;
|
||||
impl()->setTenGigaADCEnableMask(arg);
|
||||
try {
|
||||
impl()->setTenGigaADCEnableMask(arg);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set 10Gb adc enable mask due to fifo memory allcoation");
|
||||
}
|
||||
auto retval = impl()->getTenGigaADCEnableMask();
|
||||
if (retval != arg) {
|
||||
std::ostringstream os;
|
||||
|
@ -30,7 +30,7 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f,
|
||||
bool* fp, bool* act, bool* depaden, bool* sm, bool* qe,
|
||||
std::vector <int> * cdl, int* cdo, int* cad) :
|
||||
|
||||
ThreadObject(ind),
|
||||
ThreadObject(ind, TypeName),
|
||||
runningFlag(false),
|
||||
generalData(nullptr),
|
||||
fifo(f),
|
||||
@ -62,11 +62,7 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f,
|
||||
rawDataModifyReadyCallBack(nullptr),
|
||||
pRawDataReady(nullptr)
|
||||
{
|
||||
if(ThreadObject::CreateThread() == FAIL)
|
||||
throw sls::RuntimeError("Could not create processing thread");
|
||||
|
||||
FILE_LOG(logDEBUG) << "DataProcessor " << ind << " created";
|
||||
|
||||
memset((void*)&timerBegin, 0, sizeof(timespec));
|
||||
}
|
||||
|
||||
@ -74,13 +70,9 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f,
|
||||
DataProcessor::~DataProcessor() {
|
||||
delete file;
|
||||
delete [] tempBuffer;
|
||||
ThreadObject::DestroyThread();
|
||||
}
|
||||
|
||||
/** getters */
|
||||
std::string DataProcessor::GetType(){
|
||||
return TypeName;
|
||||
}
|
||||
|
||||
bool DataProcessor::IsRunning() {
|
||||
return runningFlag;
|
||||
@ -158,16 +150,6 @@ void DataProcessor::SetGeneralData(GeneralData* g) {
|
||||
}
|
||||
|
||||
|
||||
int DataProcessor::SetThreadPriority(int priority) {
|
||||
struct sched_param param;
|
||||
param.sched_priority = priority;
|
||||
if (pthread_setschedparam(thread, SCHED_FIFO, ¶m) == EPERM)
|
||||
return FAIL;
|
||||
FILE_LOG(logINFO) << "Processor Thread Priority set to " << priority;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void DataProcessor::SetFileFormat(const fileFormat f) {
|
||||
if ((file != nullptr) && file->GetFileType() != f) {
|
||||
//remember the pointer values before they are destroyed
|
||||
@ -220,16 +202,14 @@ void DataProcessor::SetupFileWriter(bool fwe, int* nd, uint32_t* maxf,
|
||||
}
|
||||
|
||||
// only the first file
|
||||
int DataProcessor::CreateNewFile(masterAttributes& attr) {
|
||||
if (file == nullptr)
|
||||
return FAIL;
|
||||
void DataProcessor::CreateNewFile(masterAttributes& attr) {
|
||||
if (file == nullptr) {
|
||||
throw sls::RuntimeError("file object not contstructed");
|
||||
}
|
||||
file->CloseAllFiles();
|
||||
file->resetSubFileIndex();
|
||||
if (file->CreateMasterFile(*masterFileWriteEnable, attr) == FAIL)
|
||||
return FAIL;
|
||||
if (file->CreateFile() == FAIL)
|
||||
return FAIL;
|
||||
return OK;
|
||||
file->CreateMasterFile(*masterFileWriteEnable, attr);
|
||||
file->CreateFile();
|
||||
}
|
||||
|
||||
|
||||
@ -240,7 +220,11 @@ void DataProcessor::CloseFiles() {
|
||||
|
||||
void DataProcessor::EndofAcquisition(bool anyPacketsCaught, uint64_t numf) {
|
||||
if ((file != nullptr) && file->GetFileType() == HDF5) {
|
||||
file->EndofAcquisition(anyPacketsCaught, numf);
|
||||
try {
|
||||
file->EndofAcquisition(anyPacketsCaught, numf);
|
||||
} catch (const sls::RuntimeError &e) {
|
||||
;// ignore for now //TODO: send error to client via stop receiver
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,10 +336,15 @@ void DataProcessor::ProcessAnImage(char* buf) {
|
||||
|
||||
|
||||
// write to file
|
||||
if (file != nullptr)
|
||||
file->WriteToFile(buf + FIFO_HEADER_NUMBYTES,
|
||||
sizeof(sls_receiver_header) + (uint32_t)(*((uint32_t*)buf)), //+ size of data (resizable from previous call back
|
||||
fnum-firstIndex, nump);
|
||||
if (file != nullptr) {
|
||||
try {
|
||||
file->WriteToFile(buf + FIFO_HEADER_NUMBYTES,
|
||||
sizeof(sls_receiver_header) + (uint32_t)(*((uint32_t*)buf)), //+ size of data (resizable from previous call back
|
||||
fnum-firstIndex, nump);
|
||||
} catch(const sls::RuntimeError &e) {
|
||||
; //ignore write exception for now (TODO: send error message via stopReceiver tcp)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ const std::string DataStreamer::TypeName = "DataStreamer";
|
||||
|
||||
DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, ROI* r,
|
||||
uint64_t* fi, int fd, std::string* ajh, int* nd, bool* gpEnable, bool* qe) :
|
||||
ThreadObject(ind),
|
||||
ThreadObject(ind, TypeName),
|
||||
runningFlag(0),
|
||||
generalData(nullptr),
|
||||
fifo(f),
|
||||
@ -38,25 +38,16 @@ DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, ROI* r,
|
||||
numDet[0] = nd[0];
|
||||
numDet[1] = nd[1];
|
||||
|
||||
if(ThreadObject::CreateThread() == FAIL)
|
||||
throw sls::RuntimeError("Could not create streaming thread");
|
||||
|
||||
FILE_LOG(logDEBUG) << "DataStreamer " << ind << " created";
|
||||
|
||||
// memset(fileNametoStream, 0, MAX_STR_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
DataStreamer::~DataStreamer() {
|
||||
CloseZmqSocket();
|
||||
delete [] completeBuffer;
|
||||
ThreadObject::DestroyThread();
|
||||
}
|
||||
|
||||
/** getters */
|
||||
std::string DataStreamer::GetType(){
|
||||
return TypeName;
|
||||
}
|
||||
|
||||
bool DataStreamer::IsRunning() {
|
||||
return runningFlag;
|
||||
@ -82,7 +73,6 @@ void DataStreamer::ResetParametersforNewAcquisition(const std::string& fname){
|
||||
startedFlag = false;
|
||||
firstIndex = 0;
|
||||
|
||||
// strcpy(fileNametoStream, fname);
|
||||
fileNametoStream = fname;
|
||||
if (completeBuffer) {
|
||||
delete[] completeBuffer;
|
||||
@ -109,15 +99,6 @@ void DataStreamer::SetGeneralData(GeneralData* g) {
|
||||
generalData->Print();
|
||||
}
|
||||
|
||||
int DataStreamer::SetThreadPriority(int priority) {
|
||||
struct sched_param param;
|
||||
param.sched_priority = priority;
|
||||
if (pthread_setschedparam(thread, SCHED_FIFO, ¶m) == EPERM)
|
||||
return FAIL;
|
||||
FILE_LOG(logINFO) << "Streamer Thread Priority set to " << priority;
|
||||
return OK;
|
||||
}
|
||||
|
||||
void DataStreamer::SetNumberofDetectors(int* nd) {
|
||||
numDet[0] = nd[0];
|
||||
numDet[1] = nd[1];
|
||||
@ -258,14 +239,12 @@ int DataStreamer::SendHeader(sls_receiver_header* rheader, uint32_t size, uint32
|
||||
|
||||
|
||||
|
||||
int DataStreamer::RestreamStop() {
|
||||
void DataStreamer::RestreamStop() {
|
||||
//send dummy header
|
||||
int ret = zmqSocket->SendHeaderData(index, true, SLS_DETECTOR_JSON_HEADER_VERSION);
|
||||
if (!ret) {
|
||||
FILE_LOG(logERROR) << "Could not Restream Dummy Header via ZMQ for port " << zmqSocket->GetPortNumber();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not restream Dummy Header via ZMQ for port " + std::to_string(zmqSocket->GetPortNumber()));
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,8 +23,7 @@ Fifo::Fifo(int ind, uint32_t fifoItemSize, uint32_t depth):
|
||||
status_fifoBound(0),
|
||||
status_fifoFree(depth){
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
if(CreateFifos(fifoItemSize) == FAIL)
|
||||
throw sls::RuntimeError("Could not create FIFO");
|
||||
CreateFifos(fifoItemSize);
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +34,7 @@ Fifo::~Fifo() {
|
||||
|
||||
|
||||
|
||||
int Fifo::CreateFifos(uint32_t fifoItemSize) {
|
||||
void Fifo::CreateFifos(uint32_t fifoItemSize) {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
|
||||
//destroy if not already
|
||||
@ -49,8 +48,7 @@ int Fifo::CreateFifos(uint32_t fifoItemSize) {
|
||||
size_t mem_len = fifoItemSize * fifoDepth * sizeof(char);
|
||||
memory = (char*) malloc (mem_len);
|
||||
if (memory == nullptr){
|
||||
FILE_LOG(logERROR) << "Could not allocate memory for fifos";
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not allocate memory for fifos");
|
||||
}
|
||||
memset(memory, 0, mem_len);
|
||||
FILE_LOG(logDEBUG) << "Memory Allocated " << index << ": " << mem_len << " bytes";
|
||||
@ -64,7 +62,6 @@ int Fifo::CreateFifos(uint32_t fifoItemSize) {
|
||||
}
|
||||
}
|
||||
FILE_LOG(logINFO) << "Fifo " << index << " reconstructed Depth (rx_fifodepth): " << fifoFree->getDataValue();
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
pthread_mutex_t HDF5File::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
H5File* HDF5File::masterfd = 0;
|
||||
hid_t HDF5File::virtualfd = 0;
|
||||
|
||||
@ -128,7 +127,7 @@ void HDF5File::UpdateDataType() {
|
||||
}
|
||||
|
||||
|
||||
int HDF5File::CreateFile() {
|
||||
void HDF5File::CreateFile() {
|
||||
numFilesinAcquisition++;
|
||||
numFramesInFile = 0;
|
||||
numActualPacketsInFile = 0;
|
||||
@ -142,29 +141,26 @@ int HDF5File::CreateFile() {
|
||||
uint64_t framestosave = ((*maxFramesPerFile == 0) ? *numImages : // infinite images
|
||||
(((extNumImages - subFileIndex) > (*maxFramesPerFile)) ? // save up to maximum at a time
|
||||
(*maxFramesPerFile) : (extNumImages-subFileIndex)));
|
||||
pthread_mutex_lock(&Mutex);
|
||||
if (HDF5FileStatic::CreateDataFile(index, *overWriteEnable, currentFileName, (*numImages > 1),
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
HDF5FileStatic::CreateDataFile(index, *overWriteEnable, currentFileName, (*numImages > 1),
|
||||
subFileIndex, framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
||||
datatype, filefd, dataspace, dataset,
|
||||
HDF5_WRITER_VERSION, MAX_CHUNKED_IMAGES,
|
||||
dataspace_para, dataset_para,
|
||||
parameterNames, parameterDataTypes) == FAIL) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return FAIL;
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
parameterNames, parameterDataTypes);
|
||||
|
||||
if(!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << *udpPortNumber << ": HDF5 File created: " << currentFileName;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void HDF5File::CloseCurrentFile() {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
HDF5FileStatic::CloseDataFile(index, filefd);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
HDF5FileStatic::CloseDataFile(index, filefd);
|
||||
}
|
||||
for (unsigned int i = 0; i < dataset_para.size(); ++i)
|
||||
delete dataset_para[i];
|
||||
dataset_para.clear();
|
||||
@ -177,14 +173,14 @@ void HDF5File::CloseCurrentFile() {
|
||||
|
||||
void HDF5File::CloseAllFiles() {
|
||||
numFilesinAcquisition = 0;
|
||||
pthread_mutex_lock(&Mutex);
|
||||
HDF5FileStatic::CloseDataFile(index, filefd);
|
||||
if (master && (*detIndex==0)) {
|
||||
HDF5FileStatic::CloseMasterDataFile(masterfd);
|
||||
HDF5FileStatic::CloseVirtualDataFile(virtualfd);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
HDF5FileStatic::CloseDataFile(index, filefd);
|
||||
if (master && (*detIndex==0)) {
|
||||
HDF5FileStatic::CloseMasterDataFile(masterfd);
|
||||
HDF5FileStatic::CloseVirtualDataFile(virtualfd);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
|
||||
for (unsigned int i = 0; i < dataset_para.size(); ++i)
|
||||
delete dataset_para[i];
|
||||
dataset_para.clear();
|
||||
@ -195,7 +191,7 @@ void HDF5File::CloseAllFiles() {
|
||||
}
|
||||
|
||||
|
||||
int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
||||
void HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
||||
|
||||
// check if maxframesperfile = 0 for infinite
|
||||
if ((*maxFramesPerFile) && (numFramesInFile >= (*maxFramesPerFile))) {
|
||||
@ -205,42 +201,35 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t
|
||||
}
|
||||
numFramesInFile++;
|
||||
numActualPacketsInFile += nump;
|
||||
pthread_mutex_lock(&Mutex);
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
// extend dataset (when receiver start followed by many status starts (jungfrau)))
|
||||
if (fnum >= extNumImages) {
|
||||
if (HDF5FileStatic::ExtendDataset(index, dataspace, dataset,
|
||||
dataspace_para, dataset_para, *numImages) == OK) {
|
||||
if (!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << index << " Extending HDF5 dataset by " <<
|
||||
extNumImages << ", Total x Dimension: " << (extNumImages + *numImages);
|
||||
}
|
||||
extNumImages += *numImages;
|
||||
HDF5FileStatic::ExtendDataset(index, dataspace, dataset,
|
||||
dataspace_para, dataset_para, *numImages);
|
||||
if (!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << index << " Extending HDF5 dataset by " <<
|
||||
extNumImages << ", Total x Dimension: " << (extNumImages + *numImages);
|
||||
}
|
||||
extNumImages += *numImages;
|
||||
}
|
||||
|
||||
if (HDF5FileStatic::WriteDataFile(index, buffer + sizeof(sls_receiver_header),
|
||||
HDF5FileStatic::WriteDataFile(index, buffer + sizeof(sls_receiver_header),
|
||||
// infinite then no need for %maxframesperfile
|
||||
((*maxFramesPerFile == 0) ? fnum : fnum%(*maxFramesPerFile)),
|
||||
nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
||||
dataspace, dataset, datatype) == OK) {
|
||||
dataspace, dataset, datatype);
|
||||
|
||||
if (HDF5FileStatic::WriteParameterDatasets(index, dataspace_para,
|
||||
HDF5FileStatic::WriteParameterDatasets(index, dataspace_para,
|
||||
// infinite then no need for %maxframesperfile
|
||||
((*maxFramesPerFile == 0) ? fnum : fnum%(*maxFramesPerFile)),
|
||||
dataset_para, (sls_receiver_header*) (buffer),
|
||||
parameterDataTypes) == OK) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
FILE_LOG(logERROR) << index << "Write to file failed";
|
||||
return FAIL;
|
||||
parameterDataTypes);
|
||||
}
|
||||
|
||||
|
||||
int HDF5File::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
void HDF5File::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
|
||||
//beginning of every acquisition
|
||||
numFramesInFile = 0;
|
||||
@ -254,14 +243,11 @@ int HDF5File::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
if(!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << "Master File: " << masterFileName;
|
||||
}
|
||||
pthread_mutex_lock(&Mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
attr.version = HDF5_WRITER_VERSION;
|
||||
int ret = HDF5FileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
HDF5FileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
*overWriteEnable, attr);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return ret;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@ -286,15 +272,14 @@ void HDF5File::EndofAcquisition(bool anyPacketsCaught, uint64_t numf) {
|
||||
|
||||
|
||||
// called only by the one maser receiver
|
||||
int HDF5File::CreateVirtualFile(uint64_t numf) {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
void HDF5File::CreateVirtualFile(uint64_t numf) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
std::string vname = HDF5FileStatic::CreateVirtualFileName(*filePath, *fileNamePrefix, *fileIndex);
|
||||
if(!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << "Virtual File: " << vname;
|
||||
}
|
||||
|
||||
int ret = HDF5FileStatic::CreateVirtualDataFile(vname,
|
||||
HDF5FileStatic::CreateVirtualDataFile(vname,
|
||||
virtualfd, masterFileName,
|
||||
*filePath, *fileNamePrefix, *fileIndex, (*numImages > 1),
|
||||
*detIndex, *numUnitsPerDetector,
|
||||
@ -305,21 +290,17 @@ int HDF5File::CreateVirtualFile(uint64_t numf) {
|
||||
numDetY, numDetX, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
||||
HDF5_WRITER_VERSION,
|
||||
parameterNames, parameterDataTypes);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// called only by the one maser receiver
|
||||
int HDF5File::LinkVirtualFileinMasterFile() {
|
||||
void HDF5File::LinkVirtualFileinMasterFile() {
|
||||
//dataset name
|
||||
std::ostringstream osfn;
|
||||
osfn << "/data";
|
||||
if ((*numImages > 1)) osfn << "_f" << std::setfill('0') << std::setw(12) << 0;
|
||||
std::string dsetname = osfn.str();
|
||||
|
||||
pthread_mutex_lock(&Mutex);
|
||||
int ret = HDF5FileStatic::LinkVirtualInMaster(masterFileName, currentFileName,
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
HDF5FileStatic::LinkVirtualInMaster(masterFileName, currentFileName,
|
||||
dsetname, parameterNames);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return ret;
|
||||
}
|
||||
|
@ -18,9 +18,10 @@
|
||||
|
||||
/** cosntructor & destructor */
|
||||
|
||||
Implementation::Implementation() {
|
||||
Implementation::Implementation(const detectorType d) {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
InitializeMembers();
|
||||
setDetectorType(d);
|
||||
}
|
||||
|
||||
Implementation::~Implementation() {
|
||||
@ -160,23 +161,12 @@ void Implementation::SetLocalNetworkParameters() {
|
||||
|
||||
void Implementation::SetThreadPriorities() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
|
||||
for (const auto &it : listener) {
|
||||
if (it->SetThreadPriority(LISTENER_PRIORITY) == FAIL) {
|
||||
FILE_LOG(logWARNING) << "Could not prioritize listener threads. "
|
||||
"(No Root Privileges?)";
|
||||
return;
|
||||
}
|
||||
it->SetThreadPriority(LISTENER_PRIORITY);
|
||||
}
|
||||
std::ostringstream osfn;
|
||||
osfn << "Priorities set - "
|
||||
"Listener:"
|
||||
<< LISTENER_PRIORITY;
|
||||
|
||||
FILE_LOG(logINFO) << osfn.str();
|
||||
}
|
||||
|
||||
int Implementation::SetupFifoStructure() {
|
||||
void Implementation::SetupFifoStructure() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
|
||||
fifo.clear();
|
||||
@ -189,11 +179,8 @@ int Implementation::SetupFifoStructure() {
|
||||
(generalData->imageSize) + (generalData->fifoBufferHeaderSize),
|
||||
fifoDepth));
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR)
|
||||
<< "Could not allocate memory for fifo structure of index "
|
||||
<< i;
|
||||
fifo.clear();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not allocate memory for fifo structure " + std::to_string(i));
|
||||
}
|
||||
// set the listener & dataprocessor threads to point to the right fifo
|
||||
if (listener.size())
|
||||
@ -210,7 +197,6 @@ int Implementation::SetupFifoStructure() {
|
||||
fifoDepth)
|
||||
<< " bytes";
|
||||
FILE_LOG(logINFO) << numThreads << " Fifo structure(s) reconstructed";
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@ -221,10 +207,8 @@ int Implementation::SetupFifoStructure() {
|
||||
* *
|
||||
* ************************************************/
|
||||
|
||||
int Implementation::setDetectorType(const detectorType d) {
|
||||
void Implementation::setDetectorType(const detectorType d) {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
DeleteMembers();
|
||||
InitializeMembers();
|
||||
myDetectorType = d;
|
||||
switch (myDetectorType) {
|
||||
case GOTTHARD:
|
||||
@ -237,8 +221,7 @@ int Implementation::setDetectorType(const detectorType d) {
|
||||
<< " Receiver *****";
|
||||
break;
|
||||
default:
|
||||
FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("This is an unknown receiver type " + std::to_string(static_cast<int>(d)));
|
||||
}
|
||||
|
||||
// set detector specific variables
|
||||
@ -270,10 +253,7 @@ int Implementation::setDetectorType(const detectorType d) {
|
||||
framesPerFile = generalData->maxFramesPerFile;
|
||||
|
||||
SetLocalNetworkParameters();
|
||||
if (SetupFifoStructure() == FAIL) {
|
||||
FILE_LOG(logERROR) << "Could not allocate memory for fifo structure";
|
||||
return FAIL;
|
||||
}
|
||||
SetupFifoStructure();
|
||||
|
||||
// create threads
|
||||
for (int i = 0; i < numThreads; ++i) {
|
||||
@ -293,12 +273,9 @@ int Implementation::setDetectorType(const detectorType d) {
|
||||
&silentMode, &quadEnable, &ctbDbitList, &ctbDbitOffset,
|
||||
&ctbAnalogDataBytes));
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR)
|
||||
<< "Could not create listener/dataprocessor threads (index:"
|
||||
<< i << ")";
|
||||
listener.clear();
|
||||
dataProcessor.clear();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create listener/dataprocessor threads (index:" + std::to_string(i) + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,7 +288,6 @@ int Implementation::setDetectorType(const detectorType d) {
|
||||
SetThreadPriorities();
|
||||
|
||||
FILE_LOG(logDEBUG) << " Detector type set to " << sls::ToString(d);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int *Implementation::getMultiDetectorSize() const {
|
||||
@ -404,14 +380,12 @@ uint32_t Implementation::getFifoDepth() const {
|
||||
return fifoDepth;
|
||||
}
|
||||
|
||||
int Implementation::setFifoDepth(const uint32_t i) {
|
||||
void Implementation::setFifoDepth(const uint32_t i) {
|
||||
if (fifoDepth != i) {
|
||||
fifoDepth = i;
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
throw sls::RuntimeError("Failed to setup fifo structure");
|
||||
SetupFifoStructure();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Fifo Depth: " << i;
|
||||
return OK;
|
||||
}
|
||||
|
||||
slsDetectorDefs::frameDiscardPolicy
|
||||
@ -625,18 +599,14 @@ std::vector<uint64_t> Implementation::getNumMissingPackets() const {
|
||||
return mp;
|
||||
}
|
||||
|
||||
int Implementation::startReceiver(std::string& err) {
|
||||
void Implementation::startReceiver() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
FILE_LOG(logINFO) << "Starting Receiver";
|
||||
stoppedFlag = false;
|
||||
ResetParametersforNewAcquisition();
|
||||
|
||||
// listener
|
||||
if (CreateUDPSockets() == FAIL) {
|
||||
err.assign("Could not create UDP Socket(s).");
|
||||
FILE_LOG(logERROR) << err;
|
||||
return FAIL;
|
||||
}
|
||||
CreateUDPSockets();
|
||||
|
||||
// callbacks
|
||||
if (startAcquisitionCallBack) {
|
||||
@ -651,11 +621,7 @@ int Implementation::startReceiver(std::string& err) {
|
||||
|
||||
// processor->writer
|
||||
if (fileWriteEnable) {
|
||||
if (SetupWriter() == FAIL) {
|
||||
err.assign("Could not create file.\n");
|
||||
FILE_LOG(logERROR) << err;
|
||||
return FAIL;
|
||||
}
|
||||
SetupWriter();
|
||||
} else
|
||||
FILE_LOG(logINFO) << "File Write Disabled";
|
||||
|
||||
@ -669,7 +635,6 @@ int Implementation::startReceiver(std::string& err) {
|
||||
|
||||
FILE_LOG(logINFO) << "Receiver Started";
|
||||
FILE_LOG(logINFO) << "Status: " << sls::ToString(status);
|
||||
return OK;
|
||||
}
|
||||
|
||||
void Implementation::setStoppedFlag(bool stopped) {
|
||||
@ -817,14 +782,12 @@ void Implementation::closeFiles() {
|
||||
dataProcessor[0]->EndofAcquisition(anycaught, maxIndexCaught);
|
||||
}
|
||||
|
||||
int Implementation::restreamStop() {
|
||||
void Implementation::restreamStop() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
for (const auto &it : dataStreamer) {
|
||||
if (it->RestreamStop() == FAIL)
|
||||
throw sls::RuntimeError("Could not restream stop packet");
|
||||
it->RestreamStop();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Restreaming Dummy Header via ZMQ successful";
|
||||
return OK;
|
||||
}
|
||||
|
||||
void Implementation::ResetParametersforNewAcquisition() {
|
||||
@ -844,29 +807,23 @@ void Implementation::ResetParametersforNewAcquisition() {
|
||||
}
|
||||
}
|
||||
|
||||
int Implementation::CreateUDPSockets() {
|
||||
void Implementation::CreateUDPSockets() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
bool error = false;
|
||||
|
||||
for (unsigned int i = 0; i < listener.size(); ++i) {
|
||||
if (listener[i]->CreateUDPSockets() == FAIL) {
|
||||
error = true;
|
||||
break;
|
||||
try{
|
||||
for (unsigned int i = 0; i < listener.size(); ++i) {
|
||||
listener[i]->CreateUDPSockets();
|
||||
}
|
||||
}
|
||||
|
||||
if (error) {
|
||||
} catch(const sls::RuntimeError &e) {
|
||||
shutDownUDPSockets();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create UDP Socket(s).");
|
||||
}
|
||||
|
||||
FILE_LOG(logDEBUG) << "UDP socket(s) created successfully.";
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Implementation::SetupWriter() {
|
||||
void Implementation::SetupWriter() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
bool error = false;
|
||||
masterAttributes attr;
|
||||
attr.detectorType = myDetectorType;
|
||||
attr.dynamicRange = dynamicRange;
|
||||
@ -892,18 +849,16 @@ int Implementation::SetupWriter() {
|
||||
for (auto &i : ctbDbitList) {
|
||||
attr.dbitlist |= (1 << i);
|
||||
}
|
||||
for (unsigned int i = 0; i < dataProcessor.size(); ++i)
|
||||
if (dataProcessor[i]->CreateNewFile(attr) == FAIL) {
|
||||
error = true;
|
||||
break;
|
||||
|
||||
try {
|
||||
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
|
||||
dataProcessor[i]->CreateNewFile(attr);
|
||||
}
|
||||
if (error) {
|
||||
} catch(const sls::RuntimeError &e) {
|
||||
shutDownUDPSockets();
|
||||
closeFiles();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create file.");
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void Implementation::StartRunning() {
|
||||
@ -935,7 +890,7 @@ int Implementation::getNumberofUDPInterfaces() const {
|
||||
return numUDPInterfaces;
|
||||
}
|
||||
|
||||
int Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
void Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
|
||||
if (numUDPInterfaces != n) {
|
||||
@ -959,8 +914,7 @@ int Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
udpSocketBufferSize = generalData->defaultUdpSocketBufferSize;
|
||||
|
||||
// fifo
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
|
||||
// create threads
|
||||
for (int i = 0; i < numThreads; ++i) {
|
||||
@ -984,12 +938,9 @@ int Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
&ctbDbitOffset, &ctbAnalogDataBytes));
|
||||
dataProcessor[i]->SetGeneralData(generalData);
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR)
|
||||
<< "Could not create listener/dataprocessor threads (index:"
|
||||
<< i << ")";
|
||||
listener.clear();
|
||||
dataProcessor.clear();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create listener/dataprocessor threads (index:" + std::to_string(i) + ")");
|
||||
}
|
||||
// streamer threads
|
||||
if (dataStreamEnable) {
|
||||
@ -1009,14 +960,11 @@ int Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
&numThreads, streamingPort, streamingSrcIP);
|
||||
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR)
|
||||
<< "Could not create datastreamer threads (index:" << i
|
||||
<< ")";
|
||||
if (dataStreamEnable) {
|
||||
dataStreamer.clear();
|
||||
dataStreamEnable = false;
|
||||
}
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create datastreamer threads (index:" + std::to_string(i) + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1041,13 +989,10 @@ int Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
}
|
||||
|
||||
// test socket buffer size with current set up
|
||||
if (setUDPSocketBufferSize(0) == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
setUDPSocketBufferSize(0);
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO) << "Number of Interfaces: " << numUDPInterfaces;
|
||||
return OK;
|
||||
}
|
||||
|
||||
std::string Implementation::getEthernetInterface() const {
|
||||
@ -1103,22 +1048,17 @@ int64_t Implementation::getUDPSocketBufferSize() const {
|
||||
return udpSocketBufferSize;
|
||||
}
|
||||
|
||||
int Implementation::setUDPSocketBufferSize(const int64_t s) {
|
||||
void Implementation::setUDPSocketBufferSize(const int64_t s) {
|
||||
int64_t size = (s == 0) ? udpSocketBufferSize : s;
|
||||
size_t listSize = listener.size();
|
||||
|
||||
if (myDetectorType == JUNGFRAU && (int)listSize != numUDPInterfaces) {
|
||||
FILE_LOG(logERROR) << "Number of Interfaces " << numUDPInterfaces
|
||||
<< " do not match listener size " << listSize;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Number of Interfaces " + std::to_string(numUDPInterfaces) + " do not match listener size " + std::to_string(listSize));
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < listSize; ++i) {
|
||||
if (listener[i]->CreateDummySocketForUDPSocketBufferSize(size) == FAIL)
|
||||
return FAIL;
|
||||
listener[i]->CreateDummySocketForUDPSocketBufferSize(size);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int64_t Implementation::getActualUDPSocketBufferSize() const {
|
||||
@ -1137,7 +1077,7 @@ bool Implementation::getDataStreamEnable() const {
|
||||
return dataStreamEnable;
|
||||
}
|
||||
|
||||
int Implementation::setDataStreamEnable(const bool enable) {
|
||||
void Implementation::setDataStreamEnable(const bool enable) {
|
||||
|
||||
if (dataStreamEnable != enable) {
|
||||
dataStreamEnable = enable;
|
||||
@ -1164,14 +1104,13 @@ int Implementation::setDataStreamEnable(const bool enable) {
|
||||
} catch (...) {
|
||||
dataStreamer.clear();
|
||||
dataStreamEnable = false;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not set data stream enable.");
|
||||
}
|
||||
}
|
||||
SetThreadPriorities();
|
||||
}
|
||||
}
|
||||
FILE_LOG(logINFO) << "Data Send to Gui: " << dataStreamEnable;
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getStreamingFrequency() const {
|
||||
@ -1179,12 +1118,11 @@ uint32_t Implementation::getStreamingFrequency() const {
|
||||
return streamingFrequency;
|
||||
}
|
||||
|
||||
int Implementation::setStreamingFrequency(const uint32_t freq) {
|
||||
void Implementation::setStreamingFrequency(const uint32_t freq) {
|
||||
if (streamingFrequency != freq) {
|
||||
streamingFrequency = freq;
|
||||
}
|
||||
FILE_LOG(logINFO) << "Streaming Frequency: " << streamingFrequency;
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getStreamingTimer() const {
|
||||
@ -1307,7 +1245,7 @@ uint32_t Implementation::getNumberofAnalogSamples() const {
|
||||
return numberOfAnalogSamples;
|
||||
}
|
||||
|
||||
int Implementation::setNumberofAnalogSamples(const uint32_t i) {
|
||||
void Implementation::setNumberofAnalogSamples(const uint32_t i) {
|
||||
if (numberOfAnalogSamples != i) {
|
||||
numberOfAnalogSamples = i;
|
||||
|
||||
@ -1318,13 +1256,11 @@ int Implementation::setNumberofAnalogSamples(const uint32_t i) {
|
||||
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Number of Analog Samples: " << numberOfAnalogSamples;
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getNumberofDigitalSamples() const {
|
||||
@ -1332,7 +1268,7 @@ uint32_t Implementation::getNumberofDigitalSamples() const {
|
||||
return numberOfDigitalSamples;
|
||||
}
|
||||
|
||||
int Implementation::setNumberofDigitalSamples(const uint32_t i) {
|
||||
void Implementation::setNumberofDigitalSamples(const uint32_t i) {
|
||||
if (numberOfDigitalSamples != i) {
|
||||
numberOfDigitalSamples = i;
|
||||
|
||||
@ -1343,14 +1279,12 @@ int Implementation::setNumberofDigitalSamples(const uint32_t i) {
|
||||
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Number of Digital Samples: "
|
||||
<< numberOfDigitalSamples;
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getDynamicRange() const {
|
||||
@ -1358,7 +1292,7 @@ uint32_t Implementation::getDynamicRange() const {
|
||||
return dynamicRange;
|
||||
}
|
||||
|
||||
int Implementation::setDynamicRange(const uint32_t i) {
|
||||
void Implementation::setDynamicRange(const uint32_t i) {
|
||||
|
||||
if (dynamicRange != i) {
|
||||
dynamicRange = i;
|
||||
@ -1369,12 +1303,10 @@ int Implementation::setDynamicRange(const uint32_t i) {
|
||||
// to update npixelsx, npixelsy in file writer
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
}
|
||||
FILE_LOG(logINFO) << "Dynamic Range: " << dynamicRange;
|
||||
return OK;
|
||||
}
|
||||
|
||||
slsDetectorDefs::ROI Implementation::getROI() const {
|
||||
@ -1382,7 +1314,7 @@ slsDetectorDefs::ROI Implementation::getROI() const {
|
||||
return roi;
|
||||
}
|
||||
|
||||
int Implementation::setROI(slsDetectorDefs::ROI arg) {
|
||||
void Implementation::setROI(slsDetectorDefs::ROI arg) {
|
||||
if (roi.xmin != arg.xmin || roi.xmax != arg.xmax) {
|
||||
roi.xmin = arg.xmin;
|
||||
roi.xmax = arg.xmax;
|
||||
@ -1392,14 +1324,12 @@ int Implementation::setROI(slsDetectorDefs::ROI arg) {
|
||||
framesPerFile = generalData->maxFramesPerFile;
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO) << "ROI: [" << roi.xmin << ", " << roi.xmax << "]";;
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool Implementation::getTenGigaEnable() const {
|
||||
@ -1407,7 +1337,7 @@ bool Implementation::getTenGigaEnable() const {
|
||||
return tengigaEnable;
|
||||
}
|
||||
|
||||
int Implementation::setTenGigaEnable(const bool b) {
|
||||
void Implementation::setTenGigaEnable(const bool b) {
|
||||
if (tengigaEnable != b) {
|
||||
tengigaEnable = b;
|
||||
// side effects
|
||||
@ -1427,13 +1357,11 @@ int Implementation::setTenGigaEnable(const bool b) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Ten Giga: " << (tengigaEnable ? "enabled" : "disabled");
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Implementation::getFlippedDataX() const {
|
||||
@ -1465,7 +1393,7 @@ bool Implementation::getGapPixelsEnable() const {
|
||||
return gapPixelsEnable;
|
||||
}
|
||||
|
||||
int Implementation::setGapPixelsEnable(const bool b) {
|
||||
void Implementation::setGapPixelsEnable(const bool b) {
|
||||
if (gapPixelsEnable != b) {
|
||||
gapPixelsEnable = b;
|
||||
|
||||
@ -1473,11 +1401,9 @@ int Implementation::setGapPixelsEnable(const bool b) {
|
||||
generalData->SetGapPixelsEnable(b, dynamicRange, quadEnable);
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Gap Pixels Enable: " << gapPixelsEnable;
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool Implementation::getQuad() const {
|
||||
@ -1485,7 +1411,7 @@ bool Implementation::getQuad() const {
|
||||
return quadEnable;
|
||||
}
|
||||
|
||||
int Implementation::setQuad(const bool b) {
|
||||
void Implementation::setQuad(const bool b) {
|
||||
if (quadEnable != b) {
|
||||
quadEnable = b;
|
||||
|
||||
@ -1493,8 +1419,7 @@ int Implementation::setQuad(const bool b) {
|
||||
// to update npixelsx, npixelsy in file writer
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
|
||||
if (!quadEnable) {
|
||||
for (const auto &it : dataStreamer) {
|
||||
@ -1513,7 +1438,6 @@ int Implementation::setQuad(const bool b) {
|
||||
}
|
||||
}
|
||||
FILE_LOG(logINFO) << "Quad Enable: " << quadEnable;
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool Implementation::getActivate() const {
|
||||
@ -1557,7 +1481,7 @@ Implementation::getReadoutMode() const {
|
||||
return readoutType;
|
||||
}
|
||||
|
||||
int Implementation::setReadoutMode(const readoutMode f) {
|
||||
void Implementation::setReadoutMode(const readoutMode f) {
|
||||
if (readoutType != f) {
|
||||
readoutType = f;
|
||||
|
||||
@ -1568,14 +1492,12 @@ int Implementation::setReadoutMode(const readoutMode f) {
|
||||
tengigaEnable, readoutType);
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO) << "Readout Mode: " << sls::ToString(f);
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getADCEnableMask() const {
|
||||
@ -1583,7 +1505,7 @@ uint32_t Implementation::getADCEnableMask() const {
|
||||
return adcEnableMaskOneGiga;
|
||||
}
|
||||
|
||||
int Implementation::setADCEnableMask(uint32_t mask) {
|
||||
void Implementation::setADCEnableMask(uint32_t mask) {
|
||||
if (adcEnableMaskOneGiga != mask) {
|
||||
adcEnableMaskOneGiga = mask;
|
||||
|
||||
@ -1594,15 +1516,13 @@ int Implementation::setADCEnableMask(uint32_t mask) {
|
||||
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO) << "ADC Enable Mask for 1Gb mode: 0x" << std::hex << adcEnableMaskOneGiga
|
||||
<< std::dec;
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getTenGigaADCEnableMask() const {
|
||||
@ -1610,7 +1530,7 @@ uint32_t Implementation::getTenGigaADCEnableMask() const {
|
||||
return adcEnableMaskTenGiga;
|
||||
}
|
||||
|
||||
int Implementation::setTenGigaADCEnableMask(uint32_t mask) {
|
||||
void Implementation::setTenGigaADCEnableMask(uint32_t mask) {
|
||||
if (adcEnableMaskTenGiga != mask) {
|
||||
adcEnableMaskTenGiga = mask;
|
||||
|
||||
@ -1621,15 +1541,13 @@ int Implementation::setTenGigaADCEnableMask(uint32_t mask) {
|
||||
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO) << "ADC Enable Mask for 10Gb mode: 0x" << std::hex << adcEnableMaskTenGiga
|
||||
<< std::dec;
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
std::vector<int> Implementation::getDbitList() const {
|
||||
|
@ -24,7 +24,7 @@ Listener::Listener(int ind, detectorType dtype, Fifo* f, std::atomic<runStatus>*
|
||||
uint32_t* portno, std::string* e, uint64_t* nf, uint32_t* dr,
|
||||
int64_t* us, int64_t* as, uint32_t* fpf,
|
||||
frameDiscardPolicy* fdp, bool* act, bool* depaden, bool* sm) :
|
||||
ThreadObject(ind),
|
||||
ThreadObject(ind, TypeName),
|
||||
runningFlag(0),
|
||||
generalData(nullptr),
|
||||
fifo(f),
|
||||
@ -55,9 +55,6 @@ Listener::Listener(int ind, detectorType dtype, Fifo* f, std::atomic<runStatus>*
|
||||
numFramesStatistic(0),
|
||||
oddStartingPacket(true)
|
||||
{
|
||||
if(ThreadObject::CreateThread() == FAIL)
|
||||
throw sls::RuntimeError("Could not create listener thread");
|
||||
|
||||
FILE_LOG(logDEBUG) << "Listener " << ind << " created";
|
||||
}
|
||||
|
||||
@ -67,15 +64,9 @@ Listener::~Listener() {
|
||||
sem_post(&semaphore_socket);
|
||||
sem_destroy(&semaphore_socket);
|
||||
}
|
||||
|
||||
ThreadObject::DestroyThread();
|
||||
}
|
||||
|
||||
/** getters */
|
||||
std::string Listener::GetType(){
|
||||
return TypeName;
|
||||
}
|
||||
|
||||
bool Listener::IsRunning() {
|
||||
return runningFlag;
|
||||
}
|
||||
@ -155,19 +146,10 @@ void Listener::SetGeneralData(GeneralData* g) {
|
||||
}
|
||||
|
||||
|
||||
int Listener::SetThreadPriority(int priority) {
|
||||
struct sched_param param;
|
||||
param.sched_priority = priority;
|
||||
if (pthread_setschedparam(thread, SCHED_FIFO, ¶m) == EPERM)
|
||||
return FAIL;
|
||||
FILE_LOG(logINFO) << "Listener Thread Priority set to " << priority;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Listener::CreateUDPSockets() {
|
||||
void Listener::CreateUDPSockets() {
|
||||
|
||||
if (!(*activated)) {
|
||||
return OK;
|
||||
return;
|
||||
}
|
||||
|
||||
//if eth is mistaken with ip address
|
||||
@ -186,8 +168,7 @@ int Listener::CreateUDPSockets() {
|
||||
*udpSocketBufferSize);
|
||||
FILE_LOG(logINFO) << index << ": UDP port opened at port " << *udpPortNumber;
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR) << "Could not create UDP socket on port " << *udpPortNumber;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create UDP socket on port "+ std::to_string(*udpPortNumber));
|
||||
}
|
||||
|
||||
udpSocketAlive = true;
|
||||
@ -195,8 +176,6 @@ int Listener::CreateUDPSockets() {
|
||||
|
||||
// doubled due to kernel bookkeeping (could also be less due to permissions)
|
||||
*actualUDPSocketBufferSize = udpSocket->getActualUDPSocketBufferSize();
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@ -216,12 +195,12 @@ void Listener::ShutDownUDPSocket() {
|
||||
}
|
||||
|
||||
|
||||
int Listener::CreateDummySocketForUDPSocketBufferSize(int64_t s) {
|
||||
void Listener::CreateDummySocketForUDPSocketBufferSize(int64_t s) {
|
||||
FILE_LOG(logINFO) << "Testing UDP Socket Buffer size " << s << " with test port " << *udpPortNumber;
|
||||
|
||||
if (!(*activated)) {
|
||||
*actualUDPSocketBufferSize = (s*2);
|
||||
return OK;
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t temp = *udpSocketBufferSize;
|
||||
@ -247,12 +226,8 @@ int Listener::CreateDummySocketForUDPSocketBufferSize(int64_t s) {
|
||||
}
|
||||
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR) << "Could not create a test UDP socket on port " << *udpPortNumber;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create a test UDP socket on port " + std::to_string(*udpPortNumber));
|
||||
}
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void Listener::SetHardCodedPosition(uint16_t r, uint16_t c) {
|
||||
|
@ -6,103 +6,71 @@
|
||||
|
||||
|
||||
#include "ThreadObject.h"
|
||||
#include "container_utils.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <syscall.h>
|
||||
|
||||
|
||||
|
||||
ThreadObject::ThreadObject(int ind):
|
||||
index(ind),
|
||||
alive(false),
|
||||
killThread(false),
|
||||
thread(0)
|
||||
{
|
||||
PrintMembers();
|
||||
ThreadObject::ThreadObject(int threadIndex, std::string threadType)
|
||||
: index(threadIndex), type(threadType) {
|
||||
FILE_LOG(logDEBUG) << type << " thread created: " << index;
|
||||
|
||||
sem_init(&semaphore,1,0);
|
||||
|
||||
try {
|
||||
threadObject = sls::make_unique<std::thread>(&ThreadObject::RunningThread, this);
|
||||
} catch (...) {
|
||||
throw sls::RuntimeError("Could not create " + type + " thread with index " + std::to_string(index));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ThreadObject::~ThreadObject() {
|
||||
DestroyThread();
|
||||
}
|
||||
killThread = true;
|
||||
sem_post(&semaphore);
|
||||
|
||||
threadObject->join();
|
||||
|
||||
void ThreadObject::PrintMembers() {
|
||||
FILE_LOG(logDEBUG) << "Index : " << index
|
||||
<< "\nalive: " << alive
|
||||
<< "\nkillThread: " << killThread
|
||||
<< "\npthread: " << thread;
|
||||
}
|
||||
|
||||
|
||||
void ThreadObject::DestroyThread() {
|
||||
if(alive){
|
||||
killThread = true;
|
||||
sem_post(&semaphore);
|
||||
pthread_join(thread,nullptr);
|
||||
sem_destroy(&semaphore);
|
||||
killThread = false;
|
||||
alive = false;
|
||||
FILE_LOG(logDEBUG) << GetType() << " thread with index " << index << " destroyed successfully.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ThreadObject::CreateThread() {
|
||||
if(alive){
|
||||
FILE_LOG(logERROR) << "Cannot create thread " << index << ". Already alive";
|
||||
return FAIL;
|
||||
}
|
||||
sem_init(&semaphore,1,0);
|
||||
killThread = false;
|
||||
|
||||
if(pthread_create(&thread, nullptr,StartThread, (void*) this)){
|
||||
FILE_LOG(logERROR) << "Could not create " << GetType() << " thread with index " << index;
|
||||
return FAIL;
|
||||
}
|
||||
alive = true;
|
||||
FILE_LOG(logDEBUG) << GetType() << " thread " << index << " created successfully.";
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void* ThreadObject::StartThread(void* thisPointer) {
|
||||
((ThreadObject*)thisPointer)->RunningThread();
|
||||
return thisPointer;
|
||||
sem_destroy(&semaphore);
|
||||
}
|
||||
|
||||
|
||||
void ThreadObject::RunningThread() {
|
||||
FILE_LOG(logINFOBLUE) << "Created [ " << GetType() << "Thread " << index << ", "
|
||||
"Tid: " << syscall(SYS_gettid) << "]";
|
||||
FILE_LOG(logINFOBLUE) << "Created [ " << type << "Thread " << index << ", Tid: " << syscall(SYS_gettid) << "]";
|
||||
FILE_LOG(logDEBUG) << type << " thread " << index << " created successfully.";
|
||||
|
||||
while(true) {
|
||||
|
||||
while(IsRunning()) {
|
||||
|
||||
ThreadExecution();
|
||||
|
||||
}//end of inner loop
|
||||
|
||||
|
||||
}
|
||||
//wait till the next acquisition
|
||||
sem_wait(&semaphore);
|
||||
|
||||
if(killThread) {
|
||||
FILE_LOG(logINFOBLUE) << "Exiting [ " << GetType() <<
|
||||
" Thread " << index << ", Tid: " << syscall(SYS_gettid) << "]";
|
||||
pthread_exit(nullptr);
|
||||
break;
|
||||
}
|
||||
|
||||
}//end of outer loop
|
||||
}
|
||||
|
||||
FILE_LOG(logDEBUG) << type << " thread with index " << index << " destroyed successfully.";
|
||||
FILE_LOG(logINFOBLUE) << "Exiting [ " << type << " Thread " << index << ", Tid: " << syscall(SYS_gettid) << "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ThreadObject::Continue() {
|
||||
sem_post(&semaphore);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ThreadObject::SetThreadPriority(int priority) {
|
||||
struct sched_param param;
|
||||
param.sched_priority = priority;
|
||||
if (pthread_setschedparam(threadObject->native_handle(), SCHED_FIFO, ¶m) == EPERM) {
|
||||
if (!index) {
|
||||
FILE_LOG(logWARNING) << "Could not prioritize " << type << " thread. "
|
||||
"(No Root Privileges?)";
|
||||
}
|
||||
} else {
|
||||
FILE_LOG(logINFO) << "Priorities set - " << type << ": " << priority;
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
#define APIRECEIVER 0x190722
|
||||
#define APIGUI 0x190723
|
||||
#define APIMOENCH 0x190820
|
||||
#define APIEIGER 0x191111
|
||||
#define APIGOTTHARD2 0x191127
|
||||
#define APIMYTHEN3 0x191127
|
||||
#define APICTB 0x191127
|
||||
#define APIGOTTHARD 0x191127
|
||||
#define APIJUNGFRAU 0x191127
|
||||
#define APIEIGER 0x191129
|
||||
|
Loading…
x
Reference in New Issue
Block a user