mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-07 22:38:42 +01:00
works for complete roi
This commit is contained in:
@@ -70,7 +70,9 @@ void LinkHDF5FileInMaster(std::string &masterFileName,
|
|||||||
for (size_t iRoi = 0; iRoi != multiRoiSize; ++iRoi) {
|
for (size_t iRoi = 0; iRoi != multiRoiSize; ++iRoi) {
|
||||||
|
|
||||||
// create link for data dataset
|
// create link for data dataset
|
||||||
std::string datasetname = DATASET_NAME + '_' + std::to_string(iRoi);
|
std::string datasetname = std::string(DATASET_NAME);
|
||||||
|
if (multiRoiSize > 1)
|
||||||
|
datasetname += ('_' + std::to_string(iRoi));
|
||||||
H5::DataSet dset = fd->openDataSet(datasetname);
|
H5::DataSet dset = fd->openDataSet(datasetname);
|
||||||
std::string linkname =
|
std::string linkname =
|
||||||
std::string("/entry/data/") + datasetname;
|
std::string("/entry/data/") + datasetname;
|
||||||
@@ -83,7 +85,9 @@ void LinkHDF5FileInMaster(std::string &masterFileName,
|
|||||||
|
|
||||||
// create link for parameter datasets
|
// create link for parameter datasets
|
||||||
for (unsigned int i = 0; i < parameterNames.size(); ++i) {
|
for (unsigned int i = 0; i < parameterNames.size(); ++i) {
|
||||||
std::string parameterDsetName = parameterNames[i] + '_' + std::to_string(iRoi);
|
std::string parameterDsetName = parameterNames[i];
|
||||||
|
if (multiRoiSize > 1)
|
||||||
|
parameterDsetName += ('_' + std::to_string(iRoi));
|
||||||
H5::DataSet pDset = fd->openDataSet(parameterDsetName.c_str());
|
H5::DataSet pDset = fd->openDataSet(parameterDsetName.c_str());
|
||||||
linkname = std::string("/entry/data/") + parameterDsetName;
|
linkname = std::string("/entry/data/") + parameterDsetName;
|
||||||
if (H5Lcreate_external(dataFilename.c_str(),
|
if (H5Lcreate_external(dataFilename.c_str(),
|
||||||
@@ -198,8 +202,13 @@ std::string CreateVirtualHDF5File(
|
|||||||
std::mutex *hdf5LibMutex, bool gotthard25um,
|
std::mutex *hdf5LibMutex, bool gotthard25um,
|
||||||
std::vector<defs::ROI> multiRoi) {
|
std::vector<defs::ROI> multiRoi) {
|
||||||
|
|
||||||
// cannot create
|
bool completeRoi = false;
|
||||||
if (!multiRoi.empty()) {
|
if (multiRoi.size() == 1 && multiRoi[0].completeRoi()) {
|
||||||
|
completeRoi = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// roi not allowed in 4 bit mode and with gotthard 2 mods
|
||||||
|
if (!completeRoi) {
|
||||||
if (dynamicRange == 4) {
|
if (dynamicRange == 4) {
|
||||||
throw std::runtime_error("Skipping virtual hdf5 file since rx_roi is "
|
throw std::runtime_error("Skipping virtual hdf5 file since rx_roi is "
|
||||||
"enabled and it is in 4 bit mode.");
|
"enabled and it is in 4 bit mode.");
|
||||||
@@ -216,11 +225,8 @@ std::string CreateVirtualHDF5File(
|
|||||||
osfn << filePath << "/" << fileNamePrefix << "_virtual"
|
osfn << filePath << "/" << fileNamePrefix << "_virtual"
|
||||||
<< "_" << fileIndex << ".h5";
|
<< "_" << fileIndex << ".h5";
|
||||||
std::string fileName = osfn.str();
|
std::string fileName = osfn.str();
|
||||||
|
|
||||||
unsigned int paraSize = parameterNames.size();
|
unsigned int paraSize = parameterNames.size();
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(*hdf5LibMutex);
|
std::lock_guard<std::mutex> lock(*hdf5LibMutex);
|
||||||
|
|
||||||
std::unique_ptr<H5::H5File> fd{nullptr};
|
std::unique_ptr<H5::H5File> fd{nullptr};
|
||||||
try {
|
try {
|
||||||
H5::Exception::dontPrint(); // to handle errors
|
H5::Exception::dontPrint(); // to handle errors
|
||||||
@@ -242,32 +248,37 @@ std::string CreateVirtualHDF5File(
|
|||||||
"version", H5::PredType::NATIVE_DOUBLE, dataspace_attr);
|
"version", H5::PredType::NATIVE_DOUBLE, dataspace_attr);
|
||||||
attribute.write(H5::PredType::NATIVE_DOUBLE, &dValue);
|
attribute.write(H5::PredType::NATIVE_DOUBLE, &dValue);
|
||||||
|
|
||||||
// complete detector in roi
|
|
||||||
if (multiRoi.size() == 1 && multiRoi[0].completeRoi()) {
|
|
||||||
int ny = nPixelsY * numModY;
|
|
||||||
int nx = nPixelsX * numModX;
|
|
||||||
if (nPixelsY == 1) {
|
|
||||||
multiRoi.push_back(defs::ROI{0, nx - 1});
|
|
||||||
} else {
|
|
||||||
multiRoi.push_back(defs::ROI{0, nx - 1, 0, ny - 1});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t depth = numImagesCaught;
|
|
||||||
uint64_t nports = numModX * numModY;
|
|
||||||
int numFiles = numImagesCaught / maxFramesPerFile;
|
|
||||||
if (numImagesCaught % maxFramesPerFile)
|
|
||||||
++numFiles;
|
|
||||||
defs::xy portSize{nPixelsX, nPixelsY};
|
|
||||||
|
|
||||||
for (size_t iRoi = 0; iRoi != multiRoi.size(); ++iRoi) {
|
for (size_t iRoi = 0; iRoi != multiRoi.size(); ++iRoi) {
|
||||||
uint64_t width = multiRoi[iRoi].width();
|
|
||||||
uint64_t height = multiRoi[iRoi].height();
|
auto currentRoi = multiRoi[iRoi];
|
||||||
uint64_t nportsInRoi = GetNumPortsInRoi(multiRoi[iRoi], portSize);
|
defs::xy detectorSize = {nPixelsX * numModX, nPixelsY * numModY};
|
||||||
|
if (completeRoi) {
|
||||||
|
currentRoi = defs::ROI{0, detectorSize.x - 1,
|
||||||
|
0, detectorSize.y - 1};
|
||||||
|
}
|
||||||
|
if (multiRoi[iRoi].completeRoi()&& iRoi != 0)
|
||||||
|
throw RuntimeError("Cannot have complete roi and multiple rois");
|
||||||
|
|
||||||
|
// get detector shape and number of ports in roi
|
||||||
|
defs::xy portSize{nPixelsX, nPixelsY};
|
||||||
|
uint32_t nTotalPorts = numModX * numModY;
|
||||||
|
hsize_t roiWidth = detectorSize.x;
|
||||||
|
hsize_t roiHeight = detectorSize.y;
|
||||||
|
hsize_t nPortsInRoi = nTotalPorts;
|
||||||
|
if (!completeRoi) {
|
||||||
|
roiWidth = multiRoi[iRoi].width();
|
||||||
|
roiHeight = multiRoi[iRoi].height();
|
||||||
|
nPortsInRoi = GetNumPortsInRoi(multiRoi[iRoi], portSize);
|
||||||
|
}
|
||||||
|
|
||||||
// dataspace
|
// dataspace
|
||||||
hsize_t vdsDims[DATA_RANK] = {depth, height, width};
|
uint64_t nImages = numImagesCaught;
|
||||||
hsize_t vdsDimsPara[VDS_PARA_RANK] = {depth, nportsInRoi};
|
int numFiles = numImagesCaught / maxFramesPerFile;
|
||||||
|
if (numImagesCaught % maxFramesPerFile)
|
||||||
|
++numFiles;
|
||||||
|
hsize_t vdsDims[DATA_RANK] = {nImages, roiHeight, roiWidth};
|
||||||
|
hsize_t vdsDimsPara[VDS_PARA_RANK] = {nImages, nPortsInRoi};
|
||||||
H5::DataSpace vdsDataSpace(DATA_RANK, vdsDims, nullptr);
|
H5::DataSpace vdsDataSpace(DATA_RANK, vdsDims, nullptr);
|
||||||
H5::DataSpace vdsDataSpacePara(VDS_PARA_RANK, vdsDimsPara, nullptr);
|
H5::DataSpace vdsDataSpacePara(VDS_PARA_RANK, vdsDimsPara, nullptr);
|
||||||
|
|
||||||
@@ -285,58 +296,52 @@ std::string CreateVirtualHDF5File(
|
|||||||
uint64_t framesSaved = 0;
|
uint64_t framesSaved = 0;
|
||||||
for (int iFile = 0; iFile != numFiles; ++iFile) {
|
for (int iFile = 0; iFile != numFiles; ++iFile) {
|
||||||
|
|
||||||
uint64_t nImagesInFile = numImagesCaught - framesSaved;
|
// images in src file
|
||||||
|
uint64_t nSrcFileImages = numImagesCaught - framesSaved;
|
||||||
if ((numImagesCaught - framesSaved) > maxFramesPerFile)
|
if ((numImagesCaught - framesSaved) > maxFramesPerFile)
|
||||||
nImagesInFile = maxFramesPerFile;
|
nSrcFileImages = maxFramesPerFile;
|
||||||
|
|
||||||
// start location and blocksize recalculated later for each readout (because of irregular roi)
|
|
||||||
hsize_t startLocation[DATA_RANK] = {framesSaved, 0, 0};
|
|
||||||
hsize_t nx = static_cast<hsize_t>(nPixelsX);
|
|
||||||
hsize_t ny = static_cast<hsize_t>(nPixelsY);
|
|
||||||
hsize_t blockSize[DATA_RANK] = {nImagesInFile, nx, ny};
|
|
||||||
hsize_t strideBetweenBlocks[DATA_RANK] = {1, 1, 1};
|
hsize_t strideBetweenBlocks[DATA_RANK] = {1, 1, 1};
|
||||||
hsize_t numBlocks[DATA_RANK] = {1, 1, 1};
|
hsize_t numBlocks[DATA_RANK] = {1, 1, 1};
|
||||||
|
|
||||||
|
|
||||||
// start location of parameter datasets is recalcualted later
|
|
||||||
hsize_t startLocationPara[VDS_PARA_RANK] = {framesSaved, 0};
|
|
||||||
hsize_t strideBetweenBlocksPara[VDS_PARA_RANK] = {1, 1};
|
hsize_t strideBetweenBlocksPara[VDS_PARA_RANK] = {1, 1};
|
||||||
hsize_t numBlocksPara[VDS_PARA_RANK] = {1, 1};
|
hsize_t numBlocksPara[VDS_PARA_RANK] = {1, 1};
|
||||||
hsize_t blockSizePara[VDS_PARA_RANK] = {nImagesInFile, 1};
|
hsize_t blockSizePara[VDS_PARA_RANK] = {nSrcFileImages, 1};
|
||||||
|
|
||||||
|
// following recalculated for every readout
|
||||||
|
hsize_t blockSize[DATA_RANK] = {nSrcFileImages, static_cast<hsize_t>(nPixelsY), static_cast<hsize_t>(nPixelsX)};
|
||||||
|
hsize_t startLocation[DATA_RANK] = {framesSaved, 0, 0};
|
||||||
|
hsize_t startLocationPara[VDS_PARA_RANK] = {framesSaved, 0};
|
||||||
|
|
||||||
// interleaving for g2
|
// interleaving for g2
|
||||||
if (gotthard25um) {
|
if (gotthard25um) {
|
||||||
strideBetweenBlocks[2] = 2;
|
strideBetweenBlocks[2] = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int iReadout = 0; iReadout < nports; ++iReadout) {
|
for (unsigned int iReadout = 0; iReadout < nTotalPorts; ++iReadout) {
|
||||||
|
|
||||||
// skip if roi does not overlap
|
|
||||||
auto globalPortRoi = GetGlobalPortRoi(iReadout, portSize, numModY);
|
auto globalPortRoi = GetGlobalPortRoi(iReadout, portSize, numModY);
|
||||||
if (!globalPortRoi.overlap(multiRoi[iRoi]))
|
if (!globalPortRoi.overlap(currentRoi))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// calculate start location (with roi)
|
// calculate start location (special for roi)
|
||||||
int xmin = std::max(multiRoi[iRoi].xmin, globalPortRoi.xmin);
|
int xmin = std::max(currentRoi.xmin, globalPortRoi.xmin);
|
||||||
int xmax = std::min(multiRoi[iRoi].xmax, globalPortRoi.xmax);
|
int xmax = std::min(currentRoi.xmax, globalPortRoi.xmax);
|
||||||
int ymin = std::max(multiRoi[iRoi].ymin, globalPortRoi.ymin);
|
int ymin = std::max(currentRoi.ymin, globalPortRoi.ymin);
|
||||||
int ymax = std::min(multiRoi[iRoi].ymax, globalPortRoi.ymax);
|
int ymax = std::min(currentRoi.ymax, globalPortRoi.ymax);
|
||||||
uint32_t portRoiHeight = ymax - ymin + 1;
|
hsize_t portRoiHeight = ymax - ymin + 1;
|
||||||
uint32_t portRoiWidth = xmax - xmin + 1;
|
hsize_t portRoiWidth = xmax - xmin + 1;
|
||||||
|
|
||||||
// recalculating start location and block size
|
// recalculating start location and block size
|
||||||
++startLocationPara[1];
|
|
||||||
if (!gotthard25um) {
|
if (!gotthard25um) {
|
||||||
startLocation[1] = ymin;
|
startLocation[1] = ymin;
|
||||||
startLocation[2] = xmin;
|
startLocation[2] = xmin;
|
||||||
blockSize[1] = portRoiHeight;
|
blockSize[1] = portRoiHeight;
|
||||||
blockSize[2] = portRoiWidth;
|
blockSize[2] = portRoiWidth;
|
||||||
}
|
}
|
||||||
// interleaving for g2 (startLocation is 0 and 1)
|
// interleaving for g2 (startLocation is 0 and 1) (g2 had no roi)
|
||||||
else {
|
else {
|
||||||
++startLocation[2];
|
++startLocation[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
vdsDataSpace.selectHyperslab(
|
vdsDataSpace.selectHyperslab(
|
||||||
H5S_SELECT_SET, numBlocks, startLocation,
|
H5S_SELECT_SET, numBlocks, startLocation,
|
||||||
strideBetweenBlocks, blockSize);
|
strideBetweenBlocks, blockSize);
|
||||||
@@ -363,14 +368,13 @@ std::string CreateVirtualHDF5File(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// source dataspace
|
// source dataspace
|
||||||
hsize_t srcDims[DATA_RANK] = {nImagesInFile, portRoiHeight, portRoiWidth};
|
hsize_t srcDims[DATA_RANK] = {nSrcFileImages, portRoiHeight, portRoiWidth};
|
||||||
hsize_t srcDimsMax[DATA_RANK] = {H5S_UNLIMITED, portRoiHeight,
|
hsize_t srcDimsMax[DATA_RANK] = {H5S_UNLIMITED, portRoiHeight,
|
||||||
portRoiWidth};
|
portRoiWidth};
|
||||||
H5::DataSpace srcDataSpace(DATA_RANK, srcDims, srcDimsMax);
|
H5::DataSpace srcDataSpace(DATA_RANK, srcDims, srcDimsMax);
|
||||||
hsize_t srcDimsPara[PARA_RANK] = {nImagesInFile};
|
hsize_t srcDimsPara[PARA_RANK] = {nSrcFileImages};
|
||||||
hsize_t srcDimsMaxPara[PARA_RANK] = {H5S_UNLIMITED};
|
hsize_t srcDimsMaxPara[PARA_RANK] = {H5S_UNLIMITED};
|
||||||
H5::DataSpace srcDataSpacePara(PARA_RANK, srcDimsPara,
|
H5::DataSpace srcDataSpacePara(PARA_RANK, srcDimsPara, srcDimsMaxPara);
|
||||||
srcDimsMaxPara);
|
|
||||||
// temporary fixfor corner case bug:
|
// temporary fixfor corner case bug:
|
||||||
// (framescaught not multiple of framesperfile,
|
// (framescaught not multiple of framesperfile,
|
||||||
// virtual parameter datasets error loading (bad scalar
|
// virtual parameter datasets error loading (bad scalar
|
||||||
@@ -385,30 +389,33 @@ std::string CreateVirtualHDF5File(
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
// mapping of property list
|
// mapping of property list
|
||||||
std::string datasetname = DATASET_NAME + '_' + std::to_string(iRoi);
|
|
||||||
plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(),
|
plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(),
|
||||||
datasetname.c_str(), srcDataSpace);
|
DATASET_NAME, srcDataSpace);
|
||||||
for (unsigned int p = 0; p < paraSize; ++p) {
|
for (unsigned int p = 0; p < paraSize; ++p) {
|
||||||
std::string parameterDsetName = parameterNames[p] + '_' + std::to_string(iRoi);
|
|
||||||
plistPara[p].setVirtual(
|
plistPara[p].setVirtual(
|
||||||
vdsDataSpacePara, relative_srcFileName.c_str(),
|
vdsDataSpacePara, relative_srcFileName.c_str(),
|
||||||
parameterDsetName.c_str(), srcDataSpacePara);
|
parameterNames[p].c_str(), srcDataSpacePara);
|
||||||
}
|
}
|
||||||
|
|
||||||
// H5Sclose(srcDataspace);
|
// map next readout
|
||||||
// H5Sclose(srcDataspace_para);
|
|
||||||
|
|
||||||
++startLocationPara[1];
|
++startLocationPara[1];
|
||||||
}
|
}
|
||||||
framesSaved += nImagesInFile;
|
framesSaved += nSrcFileImages;
|
||||||
}
|
}
|
||||||
// datasets
|
// datasets
|
||||||
|
std::string datasetname = std::string(DATASET_NAME);
|
||||||
|
// suffix '_[iRoi]' for multiple rois
|
||||||
|
if (multiRoi.size() > 1)
|
||||||
|
datasetname += ('_' + std::to_string(iRoi));
|
||||||
H5::DataSet vdsDataSet(
|
H5::DataSet vdsDataSet(
|
||||||
fd->createDataSet(DATASET_NAME, dataType, vdsDataSpace, plist));
|
fd->createDataSet(datasetname, dataType, vdsDataSpace, plist));
|
||||||
|
|
||||||
for (unsigned int p = 0; p < paraSize; ++p) {
|
for (unsigned int p = 0; p < paraSize; ++p) {
|
||||||
|
std::string parameterDsetName = parameterNames[p];
|
||||||
|
// suffix '_[iRoi]' for multiple rois
|
||||||
|
if (multiRoi.size() > 1)
|
||||||
|
parameterDsetName += ('_' + std::to_string(iRoi));
|
||||||
H5::DataSet vdsDataSetPara(fd->createDataSet(
|
H5::DataSet vdsDataSetPara(fd->createDataSet(
|
||||||
parameterNames[p].c_str(), parameterDataTypes[p],
|
parameterDsetName.c_str(), parameterDataTypes[p],
|
||||||
vdsDataSpacePara, plistPara[p]));
|
vdsDataSpacePara, plistPara[p]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user