|
|
|
@ -47,13 +47,13 @@ public:
|
|
|
|
|
* @param unitindex unit index
|
|
|
|
|
* @returns complete file name created
|
|
|
|
|
*/
|
|
|
|
|
static string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable,
|
|
|
|
|
static std::string CreateFileName(char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable,
|
|
|
|
|
uint64_t fnum = 0, int dindex = -1, int numunits = 1, int unitindex = 0)
|
|
|
|
|
{
|
|
|
|
|
ostringstream osfn;
|
|
|
|
|
std::ostringstream osfn;
|
|
|
|
|
osfn << fpath << "/" << fnameprefix;
|
|
|
|
|
if (dindex >= 0) osfn << "_d" << (dindex * numunits + unitindex);
|
|
|
|
|
if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum;
|
|
|
|
|
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << fnum;
|
|
|
|
|
osfn << "_" << findex;
|
|
|
|
|
osfn << ".h5";
|
|
|
|
|
return osfn.str();
|
|
|
|
@ -66,9 +66,9 @@ public:
|
|
|
|
|
* @param findex file index
|
|
|
|
|
* @returns master file name
|
|
|
|
|
*/
|
|
|
|
|
static string CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex)
|
|
|
|
|
static std::string CreateMasterFileName(char* fpath, char* fnameprefix, uint64_t findex)
|
|
|
|
|
{
|
|
|
|
|
ostringstream osfn;
|
|
|
|
|
std::ostringstream osfn;
|
|
|
|
|
osfn << fpath << "/" << fnameprefix;
|
|
|
|
|
osfn << "_master";
|
|
|
|
|
osfn << "_" << findex;
|
|
|
|
@ -84,9 +84,9 @@ public:
|
|
|
|
|
* @param findex file index
|
|
|
|
|
* @returns virtual file name
|
|
|
|
|
*/
|
|
|
|
|
static string CreateVirtualFileName(char* fpath, char* fnameprefix, uint64_t findex)
|
|
|
|
|
static std::string CreateVirtualFileName(char* fpath, char* fnameprefix, uint64_t findex)
|
|
|
|
|
{
|
|
|
|
|
ostringstream osfn;
|
|
|
|
|
std::ostringstream osfn;
|
|
|
|
|
osfn << fpath << "/" << fnameprefix;
|
|
|
|
|
osfn << "_virtual";
|
|
|
|
|
osfn << "_" << findex;
|
|
|
|
@ -196,8 +196,8 @@ public:
|
|
|
|
|
* @param parameterDataTypes parameter datatypes
|
|
|
|
|
*/
|
|
|
|
|
static int WriteParameterDatasets(int ind, DataSpace* dspace_para, uint64_t fnum,
|
|
|
|
|
vector <DataSet*> dset_para,sls_receiver_header* rheader,
|
|
|
|
|
vector <DataType> parameterDataTypes)
|
|
|
|
|
std::vector <DataSet*> dset_para,sls_receiver_header* rheader,
|
|
|
|
|
std::vector <DataType> parameterDataTypes)
|
|
|
|
|
{
|
|
|
|
|
sls_detector_header header = rheader->detHeader;
|
|
|
|
|
hsize_t count[1] = {1};
|
|
|
|
@ -259,7 +259,7 @@ public:
|
|
|
|
|
* @returns 0 for success and 1 for fail
|
|
|
|
|
*/
|
|
|
|
|
static int ExtendDataset(int ind, DataSpace*& dspace, DataSet* dset,
|
|
|
|
|
DataSpace*& dspace_para, vector <DataSet*> dset_para,
|
|
|
|
|
DataSpace*& dspace_para, std::vector <DataSet*> dset_para,
|
|
|
|
|
uint64_t initialNumImages) {
|
|
|
|
|
try{
|
|
|
|
|
Exception::dontPrint(); //to handle errors
|
|
|
|
@ -308,7 +308,7 @@ public:
|
|
|
|
|
* @param version version of software for hdf5 writing
|
|
|
|
|
* @returns 0 for success and 1 for fail
|
|
|
|
|
*/
|
|
|
|
|
static int CreateMasterDataFile(H5File*& fd, string fname, bool owenable,
|
|
|
|
|
static int CreateMasterDataFile(H5File*& fd, std::string fname, bool owenable,
|
|
|
|
|
uint32_t dr, bool tenE, uint32_t size,
|
|
|
|
|
uint32_t nPixelsx, uint32_t nPixelsy, uint64_t nf,
|
|
|
|
|
uint32_t maxf,
|
|
|
|
@ -356,7 +356,7 @@ public:
|
|
|
|
|
dataset = group5.createDataSet ( "dynamic range", PredType::NATIVE_INT, dataspace );
|
|
|
|
|
dataset.write ( &dr, PredType::NATIVE_INT);
|
|
|
|
|
attribute = dataset.createAttribute("unit",strdatatype, dataspace);
|
|
|
|
|
attribute.write(strdatatype, string("bits"));
|
|
|
|
|
attribute.write(strdatatype, std::string("bits"));
|
|
|
|
|
|
|
|
|
|
//Ten Giga
|
|
|
|
|
iValue = tenE;
|
|
|
|
@ -367,7 +367,7 @@ public:
|
|
|
|
|
dataset = group5.createDataSet ( "image size", PredType::NATIVE_INT, dataspace );
|
|
|
|
|
dataset.write ( &size, PredType::NATIVE_INT);
|
|
|
|
|
attribute = dataset.createAttribute("unit",strdatatype, dataspace);
|
|
|
|
|
attribute.write(strdatatype, string("bytes"));
|
|
|
|
|
attribute.write(strdatatype, std::string("bytes"));
|
|
|
|
|
|
|
|
|
|
//x
|
|
|
|
|
dataset = group5.createDataSet ( "number of pixels in x axis", PredType::NATIVE_INT, dataspace );
|
|
|
|
@ -389,30 +389,30 @@ public:
|
|
|
|
|
dataset = group5.createDataSet ( "exposure time", PredType::STD_U64LE, dataspace );
|
|
|
|
|
dataset.write ( &acquisitionTime, PredType::STD_U64LE);
|
|
|
|
|
attribute = dataset.createAttribute("unit",strdatatype, dataspace);
|
|
|
|
|
attribute.write(strdatatype, string("ns"));
|
|
|
|
|
attribute.write(strdatatype, std::string("ns"));
|
|
|
|
|
|
|
|
|
|
//SubExptime
|
|
|
|
|
dataset = group5.createDataSet ( "sub exposure time", PredType::STD_U64LE, dataspace );
|
|
|
|
|
dataset.write ( &subexposuretime, PredType::STD_U64LE);
|
|
|
|
|
attribute = dataset.createAttribute("unit",strdatatype, dataspace);
|
|
|
|
|
attribute.write(strdatatype, string("ns"));
|
|
|
|
|
attribute.write(strdatatype, std::string("ns"));
|
|
|
|
|
|
|
|
|
|
//SubPeriod
|
|
|
|
|
dataset = group5.createDataSet ( "sub period", PredType::STD_U64LE, dataspace );
|
|
|
|
|
dataset.write ( &subperiod, PredType::STD_U64LE);
|
|
|
|
|
attribute = dataset.createAttribute("unit",strdatatype, dataspace);
|
|
|
|
|
attribute.write(strdatatype, string("ns"));
|
|
|
|
|
attribute.write(strdatatype, std::string("ns"));
|
|
|
|
|
|
|
|
|
|
//Period
|
|
|
|
|
dataset = group5.createDataSet ( "acquisition period", PredType::STD_U64LE, dataspace );
|
|
|
|
|
dataset.write ( &acquisitionPeriod, PredType::STD_U64LE);
|
|
|
|
|
attribute = dataset.createAttribute("unit",strdatatype, dataspace);
|
|
|
|
|
attribute.write(strdatatype, string("ns"));
|
|
|
|
|
attribute.write(strdatatype, std::string("ns"));
|
|
|
|
|
|
|
|
|
|
//Timestamp
|
|
|
|
|
time_t t = time(0);
|
|
|
|
|
dataset = group5.createDataSet ( "timestamp", strdatatype, dataspace );
|
|
|
|
|
dataset.write ( string(ctime(&t)), strdatatype );
|
|
|
|
|
dataset.write ( std::string(ctime(&t)), strdatatype );
|
|
|
|
|
|
|
|
|
|
fd->close();
|
|
|
|
|
|
|
|
|
@ -449,13 +449,13 @@ public:
|
|
|
|
|
* @param parameterDataTypes parameter datatypes
|
|
|
|
|
* @returns 0 for success and 1 for fail
|
|
|
|
|
*/
|
|
|
|
|
static int CreateDataFile(int ind, bool owenable, string fname, bool frindexenable,
|
|
|
|
|
static int 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,
|
|
|
|
|
DataSpace*& dspace_para, vector<DataSet*>& dset_para,
|
|
|
|
|
vector <const char*> parameterNames,
|
|
|
|
|
vector <DataType> parameterDataTypes)
|
|
|
|
|
DataSpace*& dspace_para, std::vector<DataSet*>& dset_para,
|
|
|
|
|
std::vector <const char*> parameterNames,
|
|
|
|
|
std::vector <DataType> parameterDataTypes)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
Exception::dontPrint(); //to handle errors
|
|
|
|
@ -487,10 +487,10 @@ public:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//dataset name
|
|
|
|
|
ostringstream osfn;
|
|
|
|
|
std::ostringstream osfn;
|
|
|
|
|
osfn << "/data";
|
|
|
|
|
if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << fnum;
|
|
|
|
|
string dsetname = osfn.str();
|
|
|
|
|
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << fnum;
|
|
|
|
|
std::string dsetname = osfn.str();
|
|
|
|
|
|
|
|
|
|
//dataset
|
|
|
|
|
//fill value
|
|
|
|
@ -556,52 +556,52 @@ public:
|
|
|
|
|
* @returns 0 for success and 1 for fail
|
|
|
|
|
*/
|
|
|
|
|
static int CreateVirtualDataFile(
|
|
|
|
|
string virtualFileName,
|
|
|
|
|
hid_t& fd, string masterFileName,
|
|
|
|
|
std::string virtualFileName,
|
|
|
|
|
hid_t& fd, std::string masterFileName,
|
|
|
|
|
char* fpath, char* fnameprefix, uint64_t findex, bool frindexenable,
|
|
|
|
|
int dindex, int numunits,
|
|
|
|
|
uint32_t maxFramesPerFile, uint64_t numf,
|
|
|
|
|
string srcDataseName, DataType dataType,
|
|
|
|
|
std::string srcDataseName, DataType dataType,
|
|
|
|
|
int numDety, int numDetz, uint32_t nDimy, uint32_t nDimz,
|
|
|
|
|
double version,
|
|
|
|
|
vector <const char*> parameterNames,
|
|
|
|
|
vector <DataType> parameterDataTypes)
|
|
|
|
|
std::vector <const char*> parameterNames,
|
|
|
|
|
std::vector <DataType> parameterDataTypes)
|
|
|
|
|
{
|
|
|
|
|
//file
|
|
|
|
|
hid_t dfal = H5Pcreate (H5P_FILE_ACCESS);
|
|
|
|
|
if (dfal < 0)
|
|
|
|
|
return CloseFileOnError(fd,
|
|
|
|
|
string("Error in creating file access property for virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating file access property for virtual file ")
|
|
|
|
|
+ virtualFileName + std::string("\n"));
|
|
|
|
|
if (H5Pset_fclose_degree (dfal, H5F_CLOSE_STRONG) < 0)
|
|
|
|
|
return CloseFileOnError(fd,
|
|
|
|
|
string("Error in setting strong file close degree for virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in setting 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,
|
|
|
|
|
string("Error in creating virtual file ") + virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating virtual file ") + virtualFileName + std::string("\n"));
|
|
|
|
|
|
|
|
|
|
//attributes - version
|
|
|
|
|
hid_t dataspace_attr = H5Screate (H5S_SCALAR);
|
|
|
|
|
if (dataspace_attr < 0)
|
|
|
|
|
return CloseFileOnError(fd,
|
|
|
|
|
string("Error in creating dataspace for attribute in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating 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,
|
|
|
|
|
string("Error in creating attribute in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating attribute in virtual file ")
|
|
|
|
|
+ virtualFileName + std::string("\n"));
|
|
|
|
|
double attr_data = version;
|
|
|
|
|
if (H5Awrite (attrid, H5T_NATIVE_DOUBLE, &attr_data) < 0)
|
|
|
|
|
return CloseFileOnError(fd,
|
|
|
|
|
string("Error in writing attribute in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in writing attribute in virtual file ")
|
|
|
|
|
+ virtualFileName + std::string("\n"));
|
|
|
|
|
if (H5Aclose (attrid) < 0)
|
|
|
|
|
return CloseFileOnError(fd,
|
|
|
|
|
string("Error in closing attribute in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in closing attribute in virtual file ")
|
|
|
|
|
+ virtualFileName + std::string("\n"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//virtual dataspace
|
|
|
|
@ -609,38 +609,38 @@ public:
|
|
|
|
|
hid_t vdsDataspace = H5Screate_simple(3, vdsdims ,NULL);
|
|
|
|
|
if (vdsDataspace < 0)
|
|
|
|
|
return CloseFileOnError(fd,
|
|
|
|
|
string("Error in creating virtual dataspace in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating 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,
|
|
|
|
|
string("Error in creating virtual dataspace (parameters) in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating virtual dataspace (parameters) in virtual file ")
|
|
|
|
|
+ virtualFileName + std::string("\n"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//fill values
|
|
|
|
|
hid_t dcpl = H5Pcreate (H5P_DATASET_CREATE);
|
|
|
|
|
if (dcpl < 0)
|
|
|
|
|
return CloseFileOnError(fd,
|
|
|
|
|
string("Error in creating file creation properties in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating 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,
|
|
|
|
|
string("Error in creating fill value in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating 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,
|
|
|
|
|
string("Error in creating file creation properties (parameters) in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating 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,
|
|
|
|
|
string("Error in creating fill value (parameters) in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating fill value (parameters) in virtual file ")
|
|
|
|
|
+ virtualFileName + std::string("\n"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//hyperslab
|
|
|
|
@ -673,22 +673,22 @@ public:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//source file name
|
|
|
|
|
string srcFileName = HDF5FileStatic::CreateFileName(fpath, fnameprefix, findex,
|
|
|
|
|
std::string srcFileName = HDF5FileStatic::CreateFileName(fpath, fnameprefix, findex,
|
|
|
|
|
frindexenable, framesSaved, dindex, numunits, i);
|
|
|
|
|
|
|
|
|
|
// find relative path
|
|
|
|
|
string relative_srcFileName = srcFileName;
|
|
|
|
|
std::string relative_srcFileName = srcFileName;
|
|
|
|
|
{
|
|
|
|
|
size_t i = srcFileName.rfind('/', srcFileName.length());
|
|
|
|
|
if (i != string::npos)
|
|
|
|
|
if (i != std::string::npos)
|
|
|
|
|
relative_srcFileName = (srcFileName.substr(i+1, srcFileName.length() - i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//source dataset name
|
|
|
|
|
ostringstream osfn;
|
|
|
|
|
std::ostringstream osfn;
|
|
|
|
|
osfn << "/data";
|
|
|
|
|
if (frindexenable) osfn << "_f" << setfill('0') << setw(12) << framesSaved;
|
|
|
|
|
string srcDatasetName = osfn.str();
|
|
|
|
|
if (frindexenable) osfn << "_f" << std::setfill('0') << std::setw(12) << framesSaved;
|
|
|
|
|
std::string srcDatasetName = osfn.str();
|
|
|
|
|
|
|
|
|
|
//source dataspace
|
|
|
|
|
hsize_t srcdims[3] = {nDimx, nDimy, nDimz};
|
|
|
|
@ -696,15 +696,15 @@ public:
|
|
|
|
|
hid_t srcDataspace = H5Screate_simple(3, srcdims, srcdimsmax);
|
|
|
|
|
if (srcDataspace < 0)
|
|
|
|
|
return CloseFileOnError(fd,
|
|
|
|
|
string("Error in creating source dataspace in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating 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,
|
|
|
|
|
string("Error in creating source dataspace (parameters) in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating source dataspace (parameters) in virtual file ")
|
|
|
|
|
+ virtualFileName + std::string("\n"));
|
|
|
|
|
|
|
|
|
|
//mapping
|
|
|
|
|
if (H5Pset_virtual(dcpl, vdsDataspace, relative_srcFileName.c_str(),
|
|
|
|
@ -736,17 +736,17 @@ public:
|
|
|
|
|
}
|
|
|
|
|
if (error)
|
|
|
|
|
return CloseFileOnError(fd,
|
|
|
|
|
string("Error in mapping files in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in mapping files in virtual file ")
|
|
|
|
|
+ virtualFileName + std::string("\n"));
|
|
|
|
|
|
|
|
|
|
//dataset
|
|
|
|
|
string virtualDatasetName = srcDataseName;
|
|
|
|
|
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,
|
|
|
|
|
string("Error in creating virutal dataset in virtual file ")
|
|
|
|
|
+ virtualFileName + string("\n"));
|
|
|
|
|
std::string("Error in creating virutal dataset in virtual file ")
|
|
|
|
|
+ virtualFileName + std::string("\n"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//virtual parameter dataset
|
|
|
|
@ -757,8 +757,8 @@ public:
|
|
|
|
|
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"));
|
|
|
|
|
std::string("Error in creating virutal dataset (parameters) in virtual file ")
|
|
|
|
|
+ virtualFileName + std::string("\n"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//close
|
|
|
|
@ -785,8 +785,8 @@ public:
|
|
|
|
|
* @returns 0 for success and 1 for fail
|
|
|
|
|
*/
|
|
|
|
|
template <typename T>
|
|
|
|
|
static int CopyVirtualFile(T datatype, bool owenable, string oldFileName, string oldDatasetName,
|
|
|
|
|
string newFileName, string newDatasetName, int rank,
|
|
|
|
|
static int 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)
|
|
|
|
|
{
|
|
|
|
|
T *data_out;
|
|
|
|
@ -813,14 +813,14 @@ public:
|
|
|
|
|
FILE_LOG(logERROR) << "unknown datatype";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
FILE_LOG(logINFO) << "owenable:" << (owenable?1:0) << endl
|
|
|
|
|
<< "oldFileName:" << oldFileName << endl
|
|
|
|
|
<< "oldDatasetName:" << oldDatasetName << endl
|
|
|
|
|
<< "newFileName:" << newFileName << endl
|
|
|
|
|
<< "newDatasetName:" << newDatasetName << endl
|
|
|
|
|
<< "rank:" << rank << endl
|
|
|
|
|
<< "nDimx:" << nDimx << endl
|
|
|
|
|
<< "nDimy:" << nDimy << endl
|
|
|
|
|
FILE_LOG(logINFO) << "owenable:" << (owenable?1:0) << std::endl
|
|
|
|
|
<< "oldFileName:" << oldFileName << std::endl
|
|
|
|
|
<< "oldDatasetName:" << oldDatasetName << std::endl
|
|
|
|
|
<< "newFileName:" << newFileName << std::endl
|
|
|
|
|
<< "newDatasetName:" << newDatasetName << std::endl
|
|
|
|
|
<< "rank:" << rank << std::endl
|
|
|
|
|
<< "nDimx:" << nDimx << std::endl
|
|
|
|
|
<< "nDimy:" << nDimy << std::endl
|
|
|
|
|
<< "nDimz:" << nDimz;
|
|
|
|
|
|
|
|
|
|
H5File* oldfd;
|
|
|
|
@ -883,34 +883,34 @@ public:
|
|
|
|
|
* @param parameterNames parameter names
|
|
|
|
|
* @returns 0 for success and 1 for fail
|
|
|
|
|
*/
|
|
|
|
|
static int LinkVirtualInMaster(string masterFileName, string virtualfname,
|
|
|
|
|
string virtualDatasetname, vector <const char*> parameterNames) {
|
|
|
|
|
static int 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, string("Error in creating file access property for link\n"));
|
|
|
|
|
return CloseFileOnError( vfd, std::string("Error in creating file access property for link\n"));
|
|
|
|
|
if (H5Pset_fclose_degree (dfal, H5F_CLOSE_STRONG) < 0)
|
|
|
|
|
return CloseFileOnError( vfd, string("Error in setting strong file close degree for link\n"));
|
|
|
|
|
return CloseFileOnError( vfd, std::string("Error in setting strong file close degree for link\n"));
|
|
|
|
|
|
|
|
|
|
//open master file
|
|
|
|
|
hid_t mfd = H5Fopen( masterFileName.c_str(), H5F_ACC_RDWR, dfal);
|
|
|
|
|
if (mfd < 0)
|
|
|
|
|
return CloseFileOnError( vfd, string("Error in opening master file\n"));
|
|
|
|
|
return CloseFileOnError( vfd, std::string("Error in opening master file\n"));
|
|
|
|
|
|
|
|
|
|
//open virtual file
|
|
|
|
|
vfd = H5Fopen( virtualfname.c_str(), H5F_ACC_RDWR, dfal);
|
|
|
|
|
if (vfd < 0) {
|
|
|
|
|
H5Fclose(mfd); mfd = 0;
|
|
|
|
|
return CloseFileOnError( vfd, string("Error in opening virtual file\n"));
|
|
|
|
|
return CloseFileOnError( vfd, std::string("Error in opening virtual file\n"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// find relative path
|
|
|
|
|
string relative_virtualfname = virtualfname;
|
|
|
|
|
std::string relative_virtualfname = virtualfname;
|
|
|
|
|
{
|
|
|
|
|
size_t i = virtualfname.rfind('/', virtualfname.length());
|
|
|
|
|
if (i != string::npos)
|
|
|
|
|
if (i != std::string::npos)
|
|
|
|
|
relative_virtualfname = (virtualfname.substr(i+1, virtualfname.length() - i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -918,29 +918,29 @@ public:
|
|
|
|
|
hid_t vdset = H5Dopen2( vfd, virtualDatasetname.c_str(), H5P_DEFAULT);
|
|
|
|
|
if (vdset < 0) {
|
|
|
|
|
H5Fclose(mfd);
|
|
|
|
|
return CloseFileOnError( vfd, string("Error in opening virtual data dataset\n"));
|
|
|
|
|
return CloseFileOnError( vfd, std::string("Error in opening 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, string("Error in creating link to data dataset\n"));
|
|
|
|
|
return CloseFileOnError( vfd, std::string("Error in creating link to data dataset\n"));
|
|
|
|
|
}
|
|
|
|
|
H5Dclose(vdset);
|
|
|
|
|
|
|
|
|
|
//**paramter datasets**
|
|
|
|
|
for (unsigned int i = 0; i < parameterNames.size(); ++i){
|
|
|
|
|
hid_t vdset_para = H5Dopen2( vfd, (string (parameterNames[i])).c_str(), H5P_DEFAULT);
|
|
|
|
|
hid_t vdset_para = H5Dopen2( vfd, (std::string (parameterNames[i])).c_str(), H5P_DEFAULT);
|
|
|
|
|
if (vdset_para < 0) {
|
|
|
|
|
H5Fclose(mfd); mfd = 0;
|
|
|
|
|
return CloseFileOnError( vfd, string("Error in opening virtual parameter dataset to create link\n"));
|
|
|
|
|
return CloseFileOnError( vfd, std::string("Error in opening virtual parameter dataset to create link\n"));
|
|
|
|
|
}
|
|
|
|
|
sprintf(linkname, "/entry/data/%s",(string (parameterNames[i])).c_str());
|
|
|
|
|
sprintf(linkname, "/entry/data/%s",(std::string (parameterNames[i])).c_str());
|
|
|
|
|
|
|
|
|
|
if(H5Lcreate_external( relative_virtualfname.c_str(), (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;
|
|
|
|
|
return CloseFileOnError( vfd, string("Error in creating link to virtual parameter dataset\n"));
|
|
|
|
|
return CloseFileOnError( vfd, std::string("Error in creating link to virtual parameter dataset\n"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -955,7 +955,7 @@ public:
|
|
|
|
|
* Print Error msg and Close File and called on error
|
|
|
|
|
* @returns 1 for fail
|
|
|
|
|
*/
|
|
|
|
|
static int CloseFileOnError(hid_t& fd, const string msg) {
|
|
|
|
|
static int CloseFileOnError(hid_t& fd, const std::string msg) {
|
|
|
|
|
cprintf(RED, "%s", msg.c_str());
|
|
|
|
|
if(fd > 0)
|
|
|
|
|
H5Fclose(fd);
|
|
|
|
|