From fb0b0b96ecb932bdeabeea78995accbde172fda5 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 24 Mar 2017 16:58:17 +0100 Subject: [PATCH] need to automize parameter passing --- slsReceiverSoftware/include/HDF5File.h | 24 +++--------- slsReceiverSoftware/include/HDF5FileStatic.h | 24 ++++++------ slsReceiverSoftware/src/HDF5File.cpp | 39 ++++++++++---------- 3 files changed, 36 insertions(+), 51 deletions(-) diff --git a/slsReceiverSoftware/include/HDF5File.h b/slsReceiverSoftware/include/HDF5File.h index cc28d6474..c4b75d2cc 100644 --- a/slsReceiverSoftware/include/HDF5File.h +++ b/slsReceiverSoftware/include/HDF5File.h @@ -163,27 +163,13 @@ class HDF5File : private virtual slsReceiverDefs, public File, public HDF5FileSt int numFilesinAcquisition; //parameters + static const int const NUM_PARAMETERS; + static const char* const PARAMETERS[]; + static const DataType* const PARAMETER_DATATYPES[]; + /** Dataspace of parameters */ DataSpace* dataspace_para; - - /** parameter1 */ - std::string para1; - - /** Dataset of parameter1 */ - DataSet* dataset_para1; - - /** Datatype of parameter1 */ - DataType datatype_para1; - - /** parameter2 */ - std::string para2; - - /** Dataset of parameter2 */ - DataSet* dataset_para2; - - /** Datatype of parameter2 */ - DataType datatype_para2; - + DataSet* dataset_para[NUM_PARAMETERS]; }; #endif diff --git a/slsReceiverSoftware/include/HDF5FileStatic.h b/slsReceiverSoftware/include/HDF5FileStatic.h index 3fe47fb0c..86859f948 100644 --- a/slsReceiverSoftware/include/HDF5FileStatic.h +++ b/slsReceiverSoftware/include/HDF5FileStatic.h @@ -101,14 +101,15 @@ public: */ static void CloseDataFile(int ind, H5File*& fd, DataSpace*& dp, DataSet*& ds, - DataSet*& ds_p1, DataSet*& ds_p2) + const int numparameters, DataSet*& ds_p1[]) { try { Exception::dontPrint(); //to handle errors if(dp) {delete dp; dp = 0;} if(ds) {delete ds; ds = 0;} - if(ds_p1) {delete ds_p1; ds_p1 = 0;} - if(ds_p2) {delete ds_p2; ds_p2 = 0;} + for (int i = 0; i < numparameters; ++i) { + delete ds_p1[i]; ds_p1[i] = 0; + } if(fd) {delete fd; fd = 0;} } catch(Exception error) { cprintf(RED,"Error in closing HDF5 handles\n"); @@ -187,8 +188,8 @@ public: */ template static int WriteParameterDatasets(int ind, DataSpace* dspace_para, uint64_t fnum, - DataSet*& dset_para1, DataType dtype_para1, P1* para1, - DataSet*& dset_para2, DataType dtype_para2, P2* para2) + DataSet*& dset_para[], const DataType* const dtype_para[], + P1* para1, P2* para2) { hsize_t count[1] = {1}; hsize_t start[1] = {fnum}; @@ -197,8 +198,8 @@ public: Exception::dontPrint(); //to handle errors dspace_para->selectHyperslab( H5S_SELECT_SET, count, start); DataSpace memspace(H5S_SCALAR); - dset_para1->write(para1, dtype_para1, memspace, *dspace_para); - dset_para2->write(para2, dtype_para2, memspace, *dspace_para); + dset_para[0]->write(para1, *dtype_para[0], memspace, *dspace_para); + dset_para[1]->write(para2, *dtype_para[1], memspace, *dspace_para); } catch(Exception error){ cprintf(RED,"Error in writing parameters to file in object %d\n",ind); @@ -347,9 +348,8 @@ public: 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, - DataSpace*& dspace_para, - string para1, DataSet*& dset_para1, DataType dtype_para1, - string para2, DataSet*& dset_para2, DataType dtype_para2) + const int numparameters, const char * const parameters[], const DataType* const dtype_para[], + DataSpace*& dspace_para, DataSet*& dset_para[]) { try { Exception::dontPrint(); //to handle errors @@ -391,8 +391,8 @@ public: //create parameter datasets hsize_t dims[1] = {nDimx}; dspace_para = new DataSpace (1,dims); - dset_para1 = new DataSet(fd->createDataSet(para1.c_str(), dtype_para1, *dspace_para)); - dset_para2 = new DataSet(fd->createDataSet(para2.c_str(), dtype_para2, *dspace_para)); + for (int i = 0; i < numparameters; ++i) + dset_para[i] = new DataSet(fd->createDataSet(parameters[i], *dtype_para[i], *dspace_para)); } catch(Exception error){ cprintf(RED,"Error in creating HDF5 handles in object %d\n",ind); diff --git a/slsReceiverSoftware/src/HDF5File.cpp b/slsReceiverSoftware/src/HDF5File.cpp index 03f35840a..c2b16b053 100644 --- a/slsReceiverSoftware/src/HDF5File.cpp +++ b/slsReceiverSoftware/src/HDF5File.cpp @@ -16,6 +16,14 @@ using namespace std; pthread_mutex_t HDF5File::Mutex = PTHREAD_MUTEX_INITIALIZER; H5File* HDF5File::masterfd = 0; hid_t HDF5File::virtualfd = 0; +const int const HDF5File::NUM_PARAMETERS = 13; +const char * const HDF5File::PARAMETERS[] = { + "frameNumber", "expLength", "packetNumber", "bunchId", "timestamp", "modId", + "xCoord", "yCoord", "zCoord", "debug", "roundRNumber", "detType", "version"}; +const DataType * const HDF5File::PARAMETER_DATATYPES[] = { + PredType::STD_U64LE, PredType::STD_U32LE, PredType::STD_U32LE, PredType::STD_U64LE, PredType::STD_U64LE, PredType::STD_U16LE, + PredType::STD_U16LE, PredType::STD_U16LE, PredType::STD_U16LE, PredType::STD_U32LE, PredType::STD_U16LE, PredType::STD_U8LE, PredType::STD_U8LE}; + HDF5File::HDF5File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, @@ -30,16 +38,8 @@ HDF5File::HDF5File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, nPixelsY(ny), numFramesInFile(0), numFilesinAcquisition(0), - dataspace_para(0), - - para1("sub_frame_number"), - dataset_para1(0), - datatype_para1(PredType::STD_U32LE), - - para2("bunch_id"), - dataset_para2(0), - datatype_para2(PredType::STD_U64LE) + dataset_para(0) { #ifdef VERBOSE PrintMembers(); @@ -101,9 +101,8 @@ int HDF5File::CreateFile(uint64_t fnum) { fnum, framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), datatype, filefd, dataspace, dataset, HDF5_WRITER_VERSION, MAX_CHUNKED_IMAGES, - dataspace_para, - para1, dataset_para1, datatype_para1, - para2, dataset_para2, datatype_para2) == FAIL) { + NUM_PARAMETERS, PARAMETERS, PARAMETER_DATATYPES, + dataspace_para, dataset_para) == FAIL) { pthread_mutex_unlock(&Mutex); return FAIL; } @@ -115,7 +114,7 @@ int HDF5File::CreateFile(uint64_t fnum) { void HDF5File::CloseCurrentFile() { pthread_mutex_lock(&Mutex); - HDF5FileStatic::CloseDataFile(index, filefd, dataspace, dataset, dataset_para1, dataset_para2); + HDF5FileStatic::CloseDataFile(index, filefd, dataspace, dataset, NUM_PARAMETERS, dataset_para); pthread_mutex_unlock(&Mutex); } @@ -123,7 +122,7 @@ void HDF5File::CloseCurrentFile() { void HDF5File::CloseAllFiles() { numFilesinAcquisition = 0; pthread_mutex_lock(&Mutex); - HDF5FileStatic::CloseDataFile(index, filefd, dataspace, dataset, dataset_para1, dataset_para2); + HDF5FileStatic::CloseDataFile(index, filefd, dataspace, dataset, NUM_PARAMETERS, dataset_para); if (master && (*detIndex==0)) { HDF5FileStatic::CloseMasterDataFile(masterfd); HDF5FileStatic::CloseVirtualDataFile(virtualfd); @@ -140,19 +139,19 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum) { numFramesInFile++; sls_detector_header* header = (sls_detector_header*) (buffer); - //uint32_t snum = header->expLength; -// uint64_t bid = header->expLength + uint32_t snum = header->expLength; + uint64_t bid = header->expLength; pthread_mutex_lock(&Mutex); if (HDF5FileStatic::WriteDataFile(index, buffer + sizeof(sls_detector_header), fnum%maxFramesPerFile, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), dataspace, dataset, datatype) == OK) { - /*if (HDF5FileStatic::WriteParameterDatasets(index, dataspace_para, + if (HDF5FileStatic::WriteParameterDatasets(index, dataspace_para, fnum%maxFramesPerFile, - dataset_para1, datatype_para1, &snum, - dataset_para2, datatype_para2, &bid) == OK) { + dataset_para, PARAMETER_DATATYPES, + &snum, &bid) == OK) { pthread_mutex_unlock(&Mutex); return OK; - }*/ + } } pthread_mutex_unlock(&Mutex); cprintf(RED,"%d Error: Write to file failed\n", index);