mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 07:20:01 +02:00
wip
This commit is contained in:
parent
5b4cc53f8c
commit
f2cca765be
@ -28,7 +28,7 @@ void HDF5VirtualFile::CloseFile() {
|
|||||||
error.printErrorStack();
|
error.printErrorStack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void HDF5VirtualFile::CreateVirtualFile(
|
void HDF5VirtualFile::CreateVirtualFile(
|
||||||
const std::string filePath, const std::string fileNamePrefix,
|
const std::string filePath, const std::string fileNamePrefix,
|
||||||
const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode,
|
const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode,
|
||||||
@ -213,3 +213,171 @@ void HDF5VirtualFile::CreateVirtualFile(
|
|||||||
LOG(logINFO) << "Virtual File: " << fileName_;
|
LOG(logINFO) << "Virtual File: " << fileName_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
void HDF5VirtualFile::CreateVirtualFile(
|
||||||
|
const std::string filePath, const std::string fileNamePrefix,
|
||||||
|
const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode,
|
||||||
|
const int modulePos, const int numUnitsPerReadout,
|
||||||
|
const uint32_t maxFramesPerFile, const uint64_t numImages,
|
||||||
|
const uint32_t nPixelsX, const uint32_t nPixelsY,
|
||||||
|
const uint32_t dynamicRange, const uint64_t numImagesCaught,
|
||||||
|
const int numModX, const int numModY, const DataType dataType,
|
||||||
|
const std::vector<std::string> parameterNames,
|
||||||
|
const std::vector<DataType> parameterDataTypes) {
|
||||||
|
// virtual file name
|
||||||
|
std::ostringstream osfn;
|
||||||
|
osfn << filePath << "/" << fileNamePrefix << "_virtual"
|
||||||
|
<< "_" << fileIndex << ".h5";
|
||||||
|
fileName_ = osfn.str();
|
||||||
|
|
||||||
|
uint64_t numModZ = numModX;
|
||||||
|
uint32_t nDimy = nPixelsY;
|
||||||
|
uint32_t nDimz = ((dynamicRange == 4) ? (nPixelsX / 2) : nPixelsX);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(*hdf5Lib_);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Exception::dontPrint(); // to handle errors
|
||||||
|
|
||||||
|
// file
|
||||||
|
FileAccPropList fapl;
|
||||||
|
fapl.setFcloseDegree(H5F_CLOSE_STRONG);
|
||||||
|
fd_ = nullptr;
|
||||||
|
if (!overWriteEnable)
|
||||||
|
fd_ = new H5File(fileName_.c_str(), H5F_ACC_EXCL,
|
||||||
|
FileCreatPropList::DEFAULT, fapl);
|
||||||
|
else
|
||||||
|
fd_ = new H5File(fileName_.c_str(), H5F_ACC_TRUNC,
|
||||||
|
FileCreatPropList::DEFAULT, fapl);
|
||||||
|
|
||||||
|
// attributes - version
|
||||||
|
double dValue = HDF5_WRITER_VERSION;
|
||||||
|
DataSpace dataspace_attr = DataSpace(H5S_SCALAR);
|
||||||
|
Attribute attribute = fd_->createAttribute(
|
||||||
|
"version", PredType::NATIVE_DOUBLE, dataspace_attr);
|
||||||
|
attribute.write(PredType::NATIVE_DOUBLE, &dValue);
|
||||||
|
|
||||||
|
// virtual data dataspace
|
||||||
|
hsize_t vdsDims[3] = {numImagesCaught, numModY * nDimy,
|
||||||
|
numModZ * nDimz};
|
||||||
|
DataSpace vdsDataSpace(3, vdsDims, nullptr);
|
||||||
|
|
||||||
|
// property list (fill value and datatype)
|
||||||
|
int fill_value = -1;
|
||||||
|
DSetCreatPropList plist;
|
||||||
|
plist.setFillValue(dataType, &fill_value);
|
||||||
|
|
||||||
|
// hyperslab
|
||||||
|
int numFiles = numImagesCaught / maxFramesPerFile;
|
||||||
|
if (numImagesCaught % maxFramesPerFile)
|
||||||
|
++numFiles;
|
||||||
|
uint64_t framesSaved = 0;
|
||||||
|
// loop through files
|
||||||
|
for (int file = 0; file < numFiles; ++file) {
|
||||||
|
|
||||||
|
uint64_t nDimx =
|
||||||
|
((numImagesCaught - framesSaved) > maxFramesPerFile)
|
||||||
|
? maxFramesPerFile
|
||||||
|
: (numImagesCaught - framesSaved);
|
||||||
|
|
||||||
|
// static const int nImages = 1280 * nDimx;
|
||||||
|
// hsize_t coord[nImages][3];
|
||||||
|
|
||||||
|
// loop through readouts (image)
|
||||||
|
for (unsigned int iReadout = 0; iReadout < numModY * numModZ;
|
||||||
|
++iReadout) {
|
||||||
|
|
||||||
|
// memset(&coord, 0, sizeof(coord));
|
||||||
|
/*for (int x = 0; x != (int)nDimx; ++x) {
|
||||||
|
for (int z = 0; z != 1280; ++z) {
|
||||||
|
coord[1280 * x + z][0] = x + iReadout * nDimx;
|
||||||
|
coord[1280 * x + z][2] = z;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
hsize_t coord[1280][3];
|
||||||
|
memset(coord, 0, sizeof(coord));
|
||||||
|
for (int z = 0; z != 1280; ++z) {
|
||||||
|
coord[z][0] = iReadout;
|
||||||
|
coord[z][2] = z;
|
||||||
|
}
|
||||||
|
/*for (int x = 0; x != nImages; ++x) {
|
||||||
|
for (int y = 0; y != 3; ++y) {
|
||||||
|
LOG(logDEBUG) << "coord[" << x << "][" << y << "]:\t"
|
||||||
|
<< coord[x][y] << '\n';
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
LOG(logINFO) << iReadout << " before selecting";
|
||||||
|
vdsDataSpace.selectElements(H5S_SELECT_SET, 1280,
|
||||||
|
(const hsize_t *)coord);
|
||||||
|
LOG(logINFO) << iReadout << " after selecting";
|
||||||
|
|
||||||
|
LOG(logINFO) << "vds valid:" << vdsDataSpace.selectValid();
|
||||||
|
|
||||||
|
// source file name
|
||||||
|
std::ostringstream os;
|
||||||
|
os << filePath << "/" << fileNamePrefix << "_d"
|
||||||
|
<< (modulePos * numUnitsPerReadout + iReadout) << "_f"
|
||||||
|
<< file << '_' << fileIndex << ".h5";
|
||||||
|
std::string srcFileName = os.str();
|
||||||
|
LOG(logDEBUG1) << srcFileName;
|
||||||
|
|
||||||
|
// find relative path
|
||||||
|
std::string relative_srcFileName = srcFileName;
|
||||||
|
{
|
||||||
|
size_t p = srcFileName.rfind('/', srcFileName.length());
|
||||||
|
if (p != std::string::npos)
|
||||||
|
relative_srcFileName = (srcFileName.substr(
|
||||||
|
p + 1, srcFileName.length() - p));
|
||||||
|
}
|
||||||
|
|
||||||
|
// source dataset name
|
||||||
|
std::ostringstream osfn;
|
||||||
|
osfn << "/data";
|
||||||
|
if (numImages > 1)
|
||||||
|
osfn << "_f" << std::setfill('0') << std::setw(12) << file;
|
||||||
|
std::string srcDatasetName = osfn.str();
|
||||||
|
|
||||||
|
// source data dataspace
|
||||||
|
hsize_t srcDims[3] = {nDimx, nDimy, nDimz};
|
||||||
|
// hsize_t srcDimsMax[3] = {H5S_UNLIMITED, nDimy, nDimz};
|
||||||
|
DataSpace srcDataSpace(3, srcDims); //, srcDimsMax);
|
||||||
|
/*
|
||||||
|
LOG(logINFO) << iReadout << " before selecting
|
||||||
|
src"; srcDataSpace.selectElements(H5S_SELECT_SET, 1280,
|
||||||
|
(const hsize_t
|
||||||
|
*)coord); LOG(logINFO) << iReadout << " after selecting src";
|
||||||
|
LOG(logINFO) << "src valid:" <<
|
||||||
|
srcDataSpace.selectValid();
|
||||||
|
*/
|
||||||
|
// mapping of data property list
|
||||||
|
// int values[] = {53, 59, 61, 67}; /* New values to be written
|
||||||
|
// */ vdsDataSet->write(values, dataType, srcDataSpace,
|
||||||
|
// vdsDataSpace);
|
||||||
|
|
||||||
|
LOG(logINFORED) << iReadout << " before vritual";
|
||||||
|
plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(),
|
||||||
|
srcDatasetName.c_str(), srcDataSpace);
|
||||||
|
LOG(logINFORED) << iReadout << " before virtual";
|
||||||
|
|
||||||
|
// H5Sclose(srcDataspace);
|
||||||
|
}
|
||||||
|
framesSaved += nDimx;
|
||||||
|
}
|
||||||
|
// data dataset
|
||||||
|
dataSetName_ = "data";
|
||||||
|
DataSet vdsDataSet(fd_->createDataSet(dataSetName_.c_str(), dataType,
|
||||||
|
vdsDataSpace, plist));
|
||||||
|
|
||||||
|
fd_->close();
|
||||||
|
} catch (const Exception &error) {
|
||||||
|
error.printErrorStack();
|
||||||
|
CloseFile();
|
||||||
|
throw sls::RuntimeError(
|
||||||
|
"Could not create/overwrite virtual HDF5 handles");
|
||||||
|
}
|
||||||
|
if (!silentMode) {
|
||||||
|
LOG(logINFO) << "Virtual File: " << fileName_;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user