mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-08 19:10:42 +02:00
need to automize parameter passing
This commit is contained in:
parent
a11313fe96
commit
fb0b0b96ec
@ -163,27 +163,13 @@ class HDF5File : private virtual slsReceiverDefs, public File, public HDF5FileSt
|
|||||||
int numFilesinAcquisition;
|
int numFilesinAcquisition;
|
||||||
|
|
||||||
//parameters
|
//parameters
|
||||||
|
static const int const NUM_PARAMETERS;
|
||||||
|
static const char* const PARAMETERS[];
|
||||||
|
static const DataType* const PARAMETER_DATATYPES[];
|
||||||
|
|
||||||
/** Dataspace of parameters */
|
/** Dataspace of parameters */
|
||||||
DataSpace* dataspace_para;
|
DataSpace* dataspace_para;
|
||||||
|
DataSet* dataset_para[NUM_PARAMETERS];
|
||||||
/** 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;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -101,14 +101,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static void CloseDataFile(int ind, H5File*& fd, DataSpace*& dp, DataSet*& ds,
|
static void CloseDataFile(int ind, H5File*& fd, DataSpace*& dp, DataSet*& ds,
|
||||||
DataSet*& ds_p1, DataSet*& ds_p2)
|
const int numparameters, DataSet*& ds_p1[])
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Exception::dontPrint(); //to handle errors
|
Exception::dontPrint(); //to handle errors
|
||||||
if(dp) {delete dp; dp = 0;}
|
if(dp) {delete dp; dp = 0;}
|
||||||
if(ds) {delete ds; ds = 0;}
|
if(ds) {delete ds; ds = 0;}
|
||||||
if(ds_p1) {delete ds_p1; ds_p1 = 0;}
|
for (int i = 0; i < numparameters; ++i) {
|
||||||
if(ds_p2) {delete ds_p2; ds_p2 = 0;}
|
delete ds_p1[i]; ds_p1[i] = 0;
|
||||||
|
}
|
||||||
if(fd) {delete fd; fd = 0;}
|
if(fd) {delete fd; fd = 0;}
|
||||||
} catch(Exception error) {
|
} catch(Exception error) {
|
||||||
cprintf(RED,"Error in closing HDF5 handles\n");
|
cprintf(RED,"Error in closing HDF5 handles\n");
|
||||||
@ -187,8 +188,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
template <typename P1, typename P2>
|
template <typename P1, typename P2>
|
||||||
static int WriteParameterDatasets(int ind, DataSpace* dspace_para, uint64_t fnum,
|
static int WriteParameterDatasets(int ind, DataSpace* dspace_para, uint64_t fnum,
|
||||||
DataSet*& dset_para1, DataType dtype_para1, P1* para1,
|
DataSet*& dset_para[], const DataType* const dtype_para[],
|
||||||
DataSet*& dset_para2, DataType dtype_para2, P2* para2)
|
P1* para1, P2* para2)
|
||||||
{
|
{
|
||||||
hsize_t count[1] = {1};
|
hsize_t count[1] = {1};
|
||||||
hsize_t start[1] = {fnum};
|
hsize_t start[1] = {fnum};
|
||||||
@ -197,8 +198,8 @@ public:
|
|||||||
Exception::dontPrint(); //to handle errors
|
Exception::dontPrint(); //to handle errors
|
||||||
dspace_para->selectHyperslab( H5S_SELECT_SET, count, start);
|
dspace_para->selectHyperslab( H5S_SELECT_SET, count, start);
|
||||||
DataSpace memspace(H5S_SCALAR);
|
DataSpace memspace(H5S_SCALAR);
|
||||||
dset_para1->write(para1, dtype_para1, memspace, *dspace_para);
|
dset_para[0]->write(para1, *dtype_para[0], memspace, *dspace_para);
|
||||||
dset_para2->write(para2, dtype_para2, memspace, *dspace_para);
|
dset_para[1]->write(para2, *dtype_para[1], memspace, *dspace_para);
|
||||||
}
|
}
|
||||||
catch(Exception error){
|
catch(Exception error){
|
||||||
cprintf(RED,"Error in writing parameters to file in object %d\n",ind);
|
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,
|
uint64_t fnum, uint64_t nDimx, uint32_t nDimy, uint32_t nDimz,
|
||||||
DataType dtype, H5File*& fd, DataSpace*& dspace, DataSet*& dset,
|
DataType dtype, H5File*& fd, DataSpace*& dspace, DataSet*& dset,
|
||||||
double version, uint64_t maxchunkedimages,
|
double version, uint64_t maxchunkedimages,
|
||||||
DataSpace*& dspace_para,
|
const int numparameters, const char * const parameters[], const DataType* const dtype_para[],
|
||||||
string para1, DataSet*& dset_para1, DataType dtype_para1,
|
DataSpace*& dspace_para, DataSet*& dset_para[])
|
||||||
string para2, DataSet*& dset_para2, DataType dtype_para2)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Exception::dontPrint(); //to handle errors
|
Exception::dontPrint(); //to handle errors
|
||||||
@ -391,8 +391,8 @@ public:
|
|||||||
//create parameter datasets
|
//create parameter datasets
|
||||||
hsize_t dims[1] = {nDimx};
|
hsize_t dims[1] = {nDimx};
|
||||||
dspace_para = new DataSpace (1,dims);
|
dspace_para = new DataSpace (1,dims);
|
||||||
dset_para1 = new DataSet(fd->createDataSet(para1.c_str(), dtype_para1, *dspace_para));
|
for (int i = 0; i < numparameters; ++i)
|
||||||
dset_para2 = new DataSet(fd->createDataSet(para2.c_str(), dtype_para2, *dspace_para));
|
dset_para[i] = new DataSet(fd->createDataSet(parameters[i], *dtype_para[i], *dspace_para));
|
||||||
}
|
}
|
||||||
catch(Exception error){
|
catch(Exception error){
|
||||||
cprintf(RED,"Error in creating HDF5 handles in object %d\n",ind);
|
cprintf(RED,"Error in creating HDF5 handles in object %d\n",ind);
|
||||||
|
@ -16,6 +16,14 @@ using namespace std;
|
|||||||
pthread_mutex_t HDF5File::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t HDF5File::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
H5File* HDF5File::masterfd = 0;
|
H5File* HDF5File::masterfd = 0;
|
||||||
hid_t HDF5File::virtualfd = 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,
|
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,
|
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),
|
nPixelsY(ny),
|
||||||
numFramesInFile(0),
|
numFramesInFile(0),
|
||||||
numFilesinAcquisition(0),
|
numFilesinAcquisition(0),
|
||||||
|
|
||||||
dataspace_para(0),
|
dataspace_para(0),
|
||||||
|
dataset_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)
|
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
PrintMembers();
|
PrintMembers();
|
||||||
@ -101,9 +101,8 @@ int HDF5File::CreateFile(uint64_t fnum) {
|
|||||||
fnum, framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
fnum, framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
||||||
datatype, filefd, dataspace, dataset,
|
datatype, filefd, dataspace, dataset,
|
||||||
HDF5_WRITER_VERSION, MAX_CHUNKED_IMAGES,
|
HDF5_WRITER_VERSION, MAX_CHUNKED_IMAGES,
|
||||||
dataspace_para,
|
NUM_PARAMETERS, PARAMETERS, PARAMETER_DATATYPES,
|
||||||
para1, dataset_para1, datatype_para1,
|
dataspace_para, dataset_para) == FAIL) {
|
||||||
para2, dataset_para2, datatype_para2) == FAIL) {
|
|
||||||
pthread_mutex_unlock(&Mutex);
|
pthread_mutex_unlock(&Mutex);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -115,7 +114,7 @@ int HDF5File::CreateFile(uint64_t fnum) {
|
|||||||
|
|
||||||
void HDF5File::CloseCurrentFile() {
|
void HDF5File::CloseCurrentFile() {
|
||||||
pthread_mutex_lock(&Mutex);
|
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);
|
pthread_mutex_unlock(&Mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +122,7 @@ void HDF5File::CloseCurrentFile() {
|
|||||||
void HDF5File::CloseAllFiles() {
|
void HDF5File::CloseAllFiles() {
|
||||||
numFilesinAcquisition = 0;
|
numFilesinAcquisition = 0;
|
||||||
pthread_mutex_lock(&Mutex);
|
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)) {
|
if (master && (*detIndex==0)) {
|
||||||
HDF5FileStatic::CloseMasterDataFile(masterfd);
|
HDF5FileStatic::CloseMasterDataFile(masterfd);
|
||||||
HDF5FileStatic::CloseVirtualDataFile(virtualfd);
|
HDF5FileStatic::CloseVirtualDataFile(virtualfd);
|
||||||
@ -140,19 +139,19 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum) {
|
|||||||
numFramesInFile++;
|
numFramesInFile++;
|
||||||
|
|
||||||
sls_detector_header* header = (sls_detector_header*) (buffer);
|
sls_detector_header* header = (sls_detector_header*) (buffer);
|
||||||
//uint32_t snum = header->expLength;
|
uint32_t snum = header->expLength;
|
||||||
// uint64_t bid = header->expLength
|
uint64_t bid = header->expLength;
|
||||||
pthread_mutex_lock(&Mutex);
|
pthread_mutex_lock(&Mutex);
|
||||||
if (HDF5FileStatic::WriteDataFile(index, buffer + sizeof(sls_detector_header),
|
if (HDF5FileStatic::WriteDataFile(index, buffer + sizeof(sls_detector_header),
|
||||||
fnum%maxFramesPerFile, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
fnum%maxFramesPerFile, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
||||||
dataspace, dataset, datatype) == OK) {
|
dataspace, dataset, datatype) == OK) {
|
||||||
/*if (HDF5FileStatic::WriteParameterDatasets(index, dataspace_para,
|
if (HDF5FileStatic::WriteParameterDatasets(index, dataspace_para,
|
||||||
fnum%maxFramesPerFile,
|
fnum%maxFramesPerFile,
|
||||||
dataset_para1, datatype_para1, &snum,
|
dataset_para, PARAMETER_DATATYPES,
|
||||||
dataset_para2, datatype_para2, &bid) == OK) {
|
&snum, &bid) == OK) {
|
||||||
pthread_mutex_unlock(&Mutex);
|
pthread_mutex_unlock(&Mutex);
|
||||||
return OK;
|
return OK;
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&Mutex);
|
pthread_mutex_unlock(&Mutex);
|
||||||
cprintf(RED,"%d Error: Write to file failed\n", index);
|
cprintf(RED,"%d Error: Write to file failed\n", index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user