in between stage

This commit is contained in:
Dhanya Maliakal 2017-04-04 11:20:38 +02:00
parent fb0b0b96ec
commit b401a6c33b
11 changed files with 142 additions and 129 deletions

View File

@ -26,7 +26,7 @@ LIBZMQ = -L$(LIBZMQDIR) -Wl,-rpath=$(LIBZMQDIR) -lzmq
SRC_CLNT = MySocketTCP.cpp ThreadObject.cpp Listener.cpp DataProcessor.cpp DataStreamer.cpp Fifo.cpp File.cpp BinaryFile.cpp UDPInterface.cpp UDPBaseImplementation.cpp UDPStandardImplementation.cpp slsReceiverTCPIPInterface.cpp slsReceiver.cpp slsReceiverUsers.cpp utilities.cpp SRC_CLNT = MySocketTCP.cpp ThreadObject.cpp Listener.cpp DataProcessor.cpp DataStreamer.cpp Fifo.cpp File.cpp BinaryFile.cpp UDPInterface.cpp UDPBaseImplementation.cpp UDPStandardImplementation.cpp slsReceiverTCPIPInterface.cpp slsReceiver.cpp slsReceiverUsers.cpp utilities.cpp
ifeq ($(HDF5),yes) ifeq ($(HDF5),yes)
SRC_CLNT += HDF5File.cpp SRC_CLNT += HDF5File.cpp HDF5FileStatic.cpp
endif endif
ifeq ($(REST), yes) ifeq ($(REST), yes)

View File

@ -162,14 +162,11 @@ class HDF5File : private virtual slsReceiverDefs, public File, public HDF5FileSt
/** Number of files in an acquisition - to verify need of virtual file */ /** Number of files in an acquisition - to verify need of virtual file */
int numFilesinAcquisition; int numFilesinAcquisition;
//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];
/** Dataset array for parameters */
DataSet* dataset_para[HDF5FileStatic::NumberofParameters];
}; };
#endif #endif

View File

@ -13,7 +13,7 @@
#ifndef H5_NO_NAMESPACE #ifndef H5_NO_NAMESPACE
using namespace H5; using namespace H5;
#endif #endif
#include "ansi.h" #include "sls_receiver_defs.h"
#include <string> #include <string>
@ -22,8 +22,7 @@ using namespace H5;
#include <sstream> #include <sstream>
using namespace std; using namespace std;
class HDF5FileStatic: public virtual slsReceiverDefs {
class HDF5FileStatic {
public: public:
@ -32,6 +31,7 @@ public:
/** Destructor */ /** Destructor */
virtual ~HDF5FileStatic(){}; virtual ~HDF5FileStatic(){};
/** /**
* Create File Name in format fpath/fnameprefix_fx_dy_z.raw, * Create File Name in format fpath/fnameprefix_fx_dy_z.raw,
* where x is fnum, y is (dindex * numunits + unitindex) and z is findex * where x is fnum, y is (dindex * numunits + unitindex) and z is findex
@ -98,21 +98,19 @@ public:
* @param fd file pointer * @param fd file pointer
* @param dp dataspace pointer * @param dp dataspace pointer
* @param ds dataset pointer * @param ds dataset pointer
* @param ds_para pointer to array of parameter datasets
*/ */
static void CloseDataFile(int ind, H5File*& fd, DataSpace*& dp, DataSet*& ds, static void CloseDataFile(int ind, H5File*& fd)
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 (fd) {
if(ds) {delete ds; ds = 0;} delete fd;
for (int i = 0; i < numparameters; ++i) { fd = 0;
delete ds_p1[i]; ds_p1[i] = 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 of index %d\n", ind);
error.printError(); error.printError();
} }
} }
@ -125,7 +123,10 @@ public:
{ {
try { try {
Exception::dontPrint(); //to handle errors Exception::dontPrint(); //to handle errors
if(fd) {delete fd; fd = 0;} if (fd) {
delete fd;
fd = 0;
}
} catch(Exception error) { } catch(Exception error) {
cprintf(RED,"Error in closing master HDF5 handles\n"); cprintf(RED,"Error in closing master HDF5 handles\n");
error.printError(); error.printError();
@ -186,20 +187,28 @@ public:
/** /**
* Write Parameter Arrays as datasets (to virtual file) * Write Parameter Arrays as datasets (to virtual file)
*/ */
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_para[], const DataType* const dtype_para[], DataSet* dset_para[],sls_detector_header* header)
P1* para1, P2* para2)
{ {
hsize_t count[1] = {1}; hsize_t count[1] = {1};
hsize_t start[1] = {fnum}; hsize_t start[1] = {fnum};
hsize_t dims2[2] = {1};
try{ try{
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_para[0]->write(para1, *dtype_para[0], memspace, *dspace_para); dset_para[0]->write(&header->frameNumber, ParameterDataTypes[0], memspace, *dspace_para);
dset_para[1]->write(para2, *dtype_para[1], memspace, *dspace_para); dset_para[1]->write(&header->expLength, ParameterDataTypes[1], memspace, *dspace_para);
dset_para[2]->write(&header->packetNumber, ParameterDataTypes[2], memspace, *dspace_para);
dset_para[3]->write(&header->bunchId, ParameterDataTypes[3], memspace, *dspace_para);
dset_para[4]->write(&header->timestamp, ParameterDataTypes[4], memspace, *dspace_para);
dset_para[5]->write(&header->modId, ParameterDataTypes[5], memspace, *dspace_para);
dset_para[6]->write(&header->xCoord, ParameterDataTypes[6], memspace, *dspace_para);
dset_para[7]->write(&header->yCoord, ParameterDataTypes[7], memspace, *dspace_para);
dset_para[8]->write(&header->zCoord, ParameterDataTypes[8], memspace, *dspace_para);
dset_para[9]->write(&header->debug, ParameterDataTypes[9], memspace, *dspace_para);
dset_para[10]->write(&header->roundRNumber, ParameterDataTypes[10], memspace, *dspace_para);
dset_para[11]->write(&header->detType, ParameterDataTypes[11], memspace, *dspace_para);
dset_para[12]->write(&header->version, ParameterDataTypes[12], 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);
@ -346,10 +355,9 @@ public:
*/ */
static int CreateDataFile(int ind, bool owenable, string fname, bool frindexenable, static int CreateDataFile(int ind, bool owenable, string fname, bool frindexenable,
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,
const int numparameters, const char * const parameters[], const DataType* const dtype_para[], DataSpace* dspace_para, DataSet* dset_para[])
DataSpace*& dspace_para, DataSet*& dset_para[])
{ {
try { try {
Exception::dontPrint(); //to handle errors Exception::dontPrint(); //to handle errors
@ -391,8 +399,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);
for (int i = 0; i < numparameters; ++i) for (int i = 0; i < NumberofParameters; ++i)
dset_para[i] = new DataSet(fd->createDataSet(parameters[i], *dtype_para[i], *dspace_para)); dset_para[i] = new DataSet(fd->createDataSet(ParameterNames[i], ParameterDataTypes[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);
@ -435,8 +443,7 @@ public:
char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable, char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable,
int dindex, int numunits, int dindex, int numunits,
uint32_t maxFramesPerFile, uint64_t numf, uint32_t maxFramesPerFile, uint64_t numf,
string srcDataseName, string srcP1DatasetName, string srcP2DatasetName, string srcDataseName, DataType dataType,
DataType dataType, DataType p1DataType, DataType p2DataType,
int numDety, int numDetz, uint32_t nDimy, uint32_t nDimz, int numDety, int numDetz, uint32_t nDimy, uint32_t nDimz,
double version) double version)
{ {
@ -486,15 +493,14 @@ public:
int fill_value = -1; int fill_value = -1;
if (H5Pset_fill_value (dcpl, GetDataTypeinC(dataType), &fill_value) < 0) if (H5Pset_fill_value (dcpl, GetDataTypeinC(dataType), &fill_value) < 0)
return CloseFileOnError(fd, string("Error in creating fill value in virtual file ") + virtualFileName + string("\n")); return CloseFileOnError(fd, string("Error in creating fill value in virtual file ") + virtualFileName + string("\n"));
hid_t dcpl1 = H5Pcreate (H5P_DATASET_CREATE); hid_t dcpl_para[NumberofParameters];
hid_t dcpl2 = H5Pcreate (H5P_DATASET_CREATE); for (int i = 0; i < NumberofParameters; ++i) {
if ((dcpl1 < 0) || (dcpl2 < 0)) dcpl_para[i] = H5Pcreate (H5P_DATASET_CREATE);
if (dcpl_para[i] < 0)
return CloseFileOnError(fd, string("Error in creating file creation properties (parameters) in virtual file ") + virtualFileName + string("\n")); return CloseFileOnError(fd, string("Error in creating file creation properties (parameters) in virtual file ") + virtualFileName + string("\n"));
fill_value = -1; if (H5Pset_fill_value (dcpl_para[i], GetDataTypeinC(ParameterDataTypes[i]), &fill_value) < 0)
if ((H5Pset_fill_value (dcpl1, GetDataTypeinC(p1DataType), &fill_value) < 0) ||
(H5Pset_fill_value (dcpl2, GetDataTypeinC(p2DataType), &fill_value) < 0))
return CloseFileOnError(fd, string("Error in creating fill value (parameters) in virtual file ") + virtualFileName + string("\n")); return CloseFileOnError(fd, string("Error in creating fill value (parameters) in virtual file ") + virtualFileName + string("\n"));
}
//hyperslab //hyperslab
int numMajorHyperslab = numf/maxFramesPerFile; int numMajorHyperslab = numf/maxFramesPerFile;
@ -550,16 +556,14 @@ public:
break; break;
} }
if (H5Pset_virtual(dcpl1, vdsDataspace_para, srcFileName.c_str(), srcP1DatasetName.c_str(), srcDataspace_para) < 0) { for (int k = 0; k < NumberofParameters; ++k) {
cprintf(RED,"could not set mapping for paramter 1\n"); if (H5Pset_virtual(dcpl_para[k], vdsDataspace_para, srcFileName.c_str(), ParameterNames[k], srcDataspace_para) < 0) {
cprintf(RED,"could not set mapping for paramter %d\n", k);
error = true; error = true;
break; break;
} }
if (H5Pset_virtual(dcpl2, vdsDataspace_para, srcFileName.c_str(), srcP2DatasetName.c_str(), srcDataspace_para) < 0) {
cprintf(RED,"could not set mapping for paramter 2\n");
error = true;
break;
} }
//H5Sclose(srcDataspace); //H5Sclose(srcDataspace);
//H5Sclose(srcDataspace_para); //H5Sclose(srcDataspace_para);
offset[2] += nDimz; offset[2] += nDimz;
@ -576,26 +580,25 @@ public:
//dataset //dataset
string virtualDatasetName = string("/virtual_") + srcDataseName; string virtualDatasetName = string("/virtual_") + srcDataseName;
string virutalP1DatasetName = string("/virtual_") + srcP1DatasetName;
string virutalP2DatasetName = string("/virtual_") + srcP2DatasetName;
hid_t vdsdataset = H5Dcreate2 (fd, virtualDatasetName.c_str(), GetDataTypeinC(dataType), vdsDataspace, H5P_DEFAULT, dcpl, H5P_DEFAULT); hid_t vdsdataset = H5Dcreate2 (fd, virtualDatasetName.c_str(), GetDataTypeinC(dataType), vdsDataspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
if (vdsdataset < 0) if (vdsdataset < 0)
return CloseFileOnError(fd, string("Error in creating virutal dataset in virtual file ") + virtualFileName + string("\n")); return CloseFileOnError(fd, string("Error in creating virutal dataset in virtual file ") + virtualFileName + string("\n"));
hid_t vdsdataset1 = H5Dcreate2 (fd, virutalP1DatasetName.c_str(), GetDataTypeinC(p1DataType), vdsDataspace_para, H5P_DEFAULT, dcpl1, H5P_DEFAULT);
hid_t vdsdataset2 = H5Dcreate2 (fd, virutalP2DatasetName.c_str(), GetDataTypeinC(p2DataType), vdsDataspace_para, H5P_DEFAULT, dcpl2, H5P_DEFAULT);
if ((vdsdataset1 < 0) || (vdsdataset2 < 0)) //virtual parameter dataset
for (int i = 0; i < NumberofParameters; ++i) {
hid_t vdsdataset_para = H5Dcreate2 (fd,
(string("/virtual_") + string (ParameterNames[i])).c_str(),
GetDataTypeinC(ParameterDataTypes[i]), vdsDataspace_para, H5P_DEFAULT, dcpl_para[i], H5P_DEFAULT);
if (vdsdataset_para < 0)
return CloseFileOnError(fd, string("Error in creating virutal dataset (parameters) in virtual file ") + virtualFileName + string("\n")); return CloseFileOnError(fd, string("Error in creating virutal dataset (parameters) in virtual file ") + virtualFileName + string("\n"));
}
//close //close
H5Sclose(vdsDataspace);
H5Sclose(vdsDataspace_para);
H5Dclose(vdsdataset);
H5Dclose(vdsdataset1);
H5Dclose(vdsdataset2);
H5Fclose(fd); fd = 0; H5Fclose(fd); fd = 0;
//link //link
return LinkVirtualInMaster(masterFileName, virtualFileName, virtualDatasetName, virutalP1DatasetName, virutalP2DatasetName); return LinkVirtualInMaster(masterFileName, virtualFileName, virtualDatasetName);
} }
@ -691,10 +694,7 @@ public:
DataSet* newDataset = new DataSet( newfd->createDataSet(newDatasetName.c_str(), datatype, *newDataspace)); DataSet* newDataset = new DataSet( newfd->createDataSet(newDatasetName.c_str(), datatype, *newDataspace));
//write and close //write and close
newDataset->write(data_out,datatype); newDataset->write(data_out,datatype);
newDataspace->close();
newDataset->close();
newfd->close(); newfd->close();
oldDataset.close();
oldfd->close(); oldfd->close();
} catch(Exception error){ } catch(Exception error){
cprintf(RED,"Error in copying virtual files\n"); cprintf(RED,"Error in copying virtual files\n");
@ -716,12 +716,9 @@ public:
* @param masterFileName master file name * @param masterFileName master file name
* @param virtualfname virtual file name * @param virtualfname virtual file name
* @param virtualDatasetname virtual dataset name * @param virtualDatasetname virtual dataset name
* @param virtualpara1DatasetName virtual dataset name of parameter 1
* @param virtualpara2DatasetName virtual dataset name of parameter 1
* @returns 0 for success and 1 for fail * @returns 0 for success and 1 for fail
*/ */
static int LinkVirtualInMaster(string masterFileName, string virtualfname, string virtualDatasetname, static int LinkVirtualInMaster(string masterFileName, string virtualfname, string virtualDatasetname) {
string virtualpara1DatasetName, string virtualpara2DatasetName) {
char linkname[100]; char linkname[100];
hid_t vfd = 0; hid_t vfd = 0;
@ -758,34 +755,20 @@ public:
H5Dclose(vdset); H5Dclose(vdset);
//**paramter datasets** //**paramter datasets**
hid_t vdset1 = H5Dopen2( vfd, virtualpara1DatasetName.c_str(), H5P_DEFAULT); for (int i = 0; i < NumberofParameters; ++i){
if (vdset1 < 0) { hid_t vdset_para = H5Dopen2( vfd, (string("/virtual_") + string (ParameterNames[i])).c_str(), H5P_DEFAULT);
if (vdset_para < 0) {
H5Fclose(mfd); mfd = 0; H5Fclose(mfd); mfd = 0;
return CloseFileOnError( vfd, string("Error in opening virtual parameter 1 dataet to create link\n")); return CloseFileOnError( vfd, string("Error in opening virtual parameter dataset to create link\n"));
} }
hid_t vdset2 = H5Dopen2( vfd, virtualpara2DatasetName.c_str(), H5P_DEFAULT); sprintf(linkname, "/entry/data/%s",(string("/virtual_") + string (ParameterNames[i])).c_str());
if (vdset2 < 0) { if(H5Lcreate_external( virtualfname.c_str(), (string("/virtual_") + string (ParameterNames[i])).c_str(),
H5Fclose(mfd); mfd = 0;
return CloseFileOnError( vfd, string("Error in opening virtual parameter 2 dataet to create link\n"));
}
if ((vdset1 < 0) || (vdset2 < 0)) {
H5Fclose(mfd); mfd = 0;
return CloseFileOnError( vfd, string("Error in opening either virtual parameter dataet to create link\n"));
}
sprintf(linkname, "/entry/data/%s",virtualpara1DatasetName.c_str());
if(H5Lcreate_external( virtualfname.c_str(), virtualpara1DatasetName.c_str(),
mfd, linkname, H5P_DEFAULT, H5P_DEFAULT) < 0) { mfd, linkname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
H5Fclose(mfd); mfd = 0; H5Fclose(mfd); mfd = 0;
return CloseFileOnError( vfd, string("Error in creating link to virtual parameter 1 dataset\n")); return CloseFileOnError( vfd, string("Error in creating link to virtual parameter dataset\n"));
} }
sprintf(linkname, "/entry/data/%s",virtualpara2DatasetName.c_str());
if(H5Lcreate_external( virtualfname.c_str(), virtualpara2DatasetName.c_str(),
mfd, linkname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
H5Fclose(mfd); mfd = 0;
return CloseFileOnError( vfd, string("Error in creating link to virtual parameter 2 dataset\n"));
} }
H5Dclose(vdset1);
H5Dclose(vdset2);
H5Fclose(mfd); mfd = 0; H5Fclose(mfd); mfd = 0;
H5Fclose(vfd); vfd = 0; H5Fclose(vfd); vfd = 0;
return 0; return 0;
@ -799,7 +782,9 @@ public:
*/ */
static int CloseFileOnError(hid_t& fd, const string msg) { static int CloseFileOnError(hid_t& fd, const string msg) {
cprintf(RED, "%s", msg.c_str()); cprintf(RED, "%s", msg.c_str());
if(fd > 0) H5Fclose(fd); fd = 0; if(fd > 0)
H5Fclose(fd);
fd = 0;
return 1; return 1;
} }
@ -824,9 +809,15 @@ public:
} }
} }
static const int NumberofParameters = 13;
private:
static const char * const ParameterNames[];
static const DataType ParameterDataTypes[];
}; };
#endif #endif

View File

@ -1,5 +1,5 @@
/************************************************ /************************************************
* @file BinaryFile.h * @file BinaryFile.cpp
* @short sets/gets properties for the binary file, * @short sets/gets properties for the binary file,
* creates/closes the file and writes data to it * creates/closes the file and writes data to it
***********************************************/ ***********************************************/

View File

@ -1,5 +1,5 @@
/************************************************ /************************************************
* @file DataProcessor.h * @file DataProcessor.cpp
* @short creates data processor thread that * @short creates data processor thread that
* pulls pointers to memory addresses from fifos * pulls pointers to memory addresses from fifos
* and processes data stored in them & writes them to file * and processes data stored in them & writes them to file

View File

@ -1,5 +1,5 @@
/************************************************ /************************************************
* @file DataStreamer.h * @file DataStreamer.cpp
* @short streams data from receiver via ZMQ * @short streams data from receiver via ZMQ
***********************************************/ ***********************************************/

View File

@ -1,5 +1,5 @@
/************************************************ /************************************************
* @file Fifo.h * @file Fifo.cpp
* @short constructs the fifo structure * @short constructs the fifo structure
* which is a circular buffer with pointers to * which is a circular buffer with pointers to
* parts of allocated memory * parts of allocated memory

View File

@ -1,5 +1,5 @@
/************************************************ /************************************************
* @file File.h * @file File.cpp
* @short sets/gets properties for the file, * @short sets/gets properties for the file,
* creates/closes the file and writes data to it * creates/closes the file and writes data to it
***********************************************/ ***********************************************/

View File

@ -1,10 +1,8 @@
/************************************************ /************************************************
* @file HDF5File.h * @file HDF5File.cpp
* @short sets/gets properties for the HDF5 file, * @short sets/gets properties for the HDF5 file,
* creates/closes the file and writes data to it * creates/closes the file and writes data to it
***********************************************/ ***********************************************/
#pragma once
#include "HDF5File.h" #include "HDF5File.h"
#include "receiver_defs.h" #include "receiver_defs.h"
@ -13,16 +11,11 @@
using namespace std; 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,
@ -38,12 +31,13 @@ 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)
{ {
#ifdef VERBOSE #ifdef VERBOSE
PrintMembers(); PrintMembers();
#endif #endif
for (int i = 0; i < HDF5FileStatic::NumberofParameters; ++i)
dataset_para[i] = 0;
} }
@ -101,7 +95,6 @@ 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,
NUM_PARAMETERS, PARAMETERS, PARAMETER_DATATYPES,
dataspace_para, dataset_para) == FAIL) { dataspace_para, dataset_para) == FAIL) {
pthread_mutex_unlock(&Mutex); pthread_mutex_unlock(&Mutex);
return FAIL; return FAIL;
@ -114,7 +107,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, NUM_PARAMETERS, dataset_para); HDF5FileStatic::CloseDataFile(index, filefd);
pthread_mutex_unlock(&Mutex); pthread_mutex_unlock(&Mutex);
} }
@ -122,7 +115,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, NUM_PARAMETERS, dataset_para); HDF5FileStatic::CloseDataFile(index, filefd);
if (master && (*detIndex==0)) { if (master && (*detIndex==0)) {
HDF5FileStatic::CloseMasterDataFile(masterfd); HDF5FileStatic::CloseMasterDataFile(masterfd);
HDF5FileStatic::CloseVirtualDataFile(virtualfd); HDF5FileStatic::CloseVirtualDataFile(virtualfd);
@ -138,17 +131,14 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum) {
} }
numFramesInFile++; numFramesInFile++;
sls_detector_header* header = (sls_detector_header*) (buffer);
uint32_t snum = 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) {
sls_detector_header* header = (sls_detector_header*) (buffer);
if (HDF5FileStatic::WriteParameterDatasets(index, dataspace_para, if (HDF5FileStatic::WriteParameterDatasets(index, dataspace_para,
fnum%maxFramesPerFile, fnum%maxFramesPerFile,
dataset_para, PARAMETER_DATATYPES, dataset_para, header) == OK) {
&snum, &bid) == OK) {
pthread_mutex_unlock(&Mutex); pthread_mutex_unlock(&Mutex);
return OK; return OK;
} }
@ -188,7 +178,7 @@ void HDF5File::EndofAcquisition(uint64_t numf) {
osfn << "/data"; osfn << "/data";
if (*frameIndexEnable) osfn << "_f" << setfill('0') << setw(12) << 0; if (*frameIndexEnable) osfn << "_f" << setfill('0') << setw(12) << 0;
string dsetname = osfn.str(); string dsetname = osfn.str();
HDF5FileStatic::LinkVirtualInMaster(masterFileName, currentFileName, dsetname, para1, para2); HDF5FileStatic::LinkVirtualInMaster(masterFileName, currentFileName, dsetname);
} }
} }
numFilesinAcquisition = 0; numFilesinAcquisition = 0;
@ -204,8 +194,7 @@ int HDF5File::CreateVirtualFile(uint64_t numf) {
filePath, fileNamePrefix, *fileIndex, *frameIndexEnable, filePath, fileNamePrefix, *fileIndex, *frameIndexEnable,
*detIndex, *numUnitsPerDetector, *detIndex, *numUnitsPerDetector,
maxFramesPerFile, numf, maxFramesPerFile, numf,
"data", para1, para2, "data", datatype,
datatype, datatype_para1, datatype_para2,
numDetY, numDetX, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX), numDetY, numDetX, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
HDF5_WRITER_VERSION); HDF5_WRITER_VERSION);
pthread_mutex_unlock(&Mutex); pthread_mutex_unlock(&Mutex);
@ -213,4 +202,3 @@ int HDF5File::CreateVirtualFile(uint64_t numf) {
} }
return OK; return OK;
} }

View File

@ -0,0 +1,37 @@
/************************************************
* @file HDF5File.cpp
* @short sets/gets properties for the HDF5 file,
* creates/closes the file and writes data to it
***********************************************/
#include "HDF5FileStatic.h"
const char * const HDF5FileStatic::ParameterNames[] = {
"frameNumber",
"expLength",
"packetNumber",
"bunchId",
"timestamp",
"modId",
"xCoord",
"yCoord",
"zCoord",
"debug",
"roundRNumber",
"detType",
"version"};
const DataType HDF5FileStatic::ParameterDataTypes[] = {
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};

View File

@ -1,5 +1,5 @@
/************************************************ /************************************************
* @file ThreadObject.h * @file ThreadObject.cpp
* @short creates/destroys a thread * @short creates/destroys a thread
***********************************************/ ***********************************************/