* hdf5 fix for string reference

* fix hdf5 compilation after namespace change
This commit is contained in:
Dhanya Thattil
2022-06-09 11:42:32 +02:00
committed by GitHub
parent 3cee36a3db
commit 89aa0760c6
8 changed files with 376 additions and 381 deletions

View File

@ -211,14 +211,14 @@ void DataProcessor::LinkFileInMaster(const std::string &masterFileName,
if (receiverRoiEnabled_) { if (receiverRoiEnabled_) {
throw std::runtime_error("Should not be here, roi with hdf5 virtual should throw."); throw std::runtime_error("Should not be here, roi with hdf5 virtual should throw.");
} }
std::string fname{virtualFileName}, datasetName{virtualDatasetName}; std::string fname{virtualFileName}, datasetName{virtualDatasetName}, masterfname{masterFileName};
// if no virtual file, link data file // if no virtual file, link data file
if (virtualFileName.empty()) { if (virtualFileName.empty()) {
auto res = dataFile_->GetFileAndDatasetName(); auto res = dataFile_->GetFileAndDatasetName();
fname = res[0]; fname = res[0];
datasetName = res[1]; datasetName = res[1];
} }
masterFileUtility::LinkHDF5FileInMaster(masterFileName, fname, datasetName, masterFileUtility::LinkHDF5FileInMaster(masterfname, fname, datasetName,
dataFile_->GetParameterNames(), dataFile_->GetParameterNames(),
silentMode, hdf5LibMutex); silentMode, hdf5LibMutex);
} }

View File

@ -7,15 +7,12 @@
#include <array> #include <array>
namespace sls {
#ifdef HDF5C #ifdef HDF5C
#include "H5Cpp.h" #include "H5Cpp.h"
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif
#endif #endif
namespace sls {
struct MasterAttributes; struct MasterAttributes;
class File : private virtual slsDetectorDefs { class File : private virtual slsDetectorDefs {
@ -42,10 +39,10 @@ class File : private virtual slsDetectorDefs {
return 0; return 0;
}; };
virtual DataType GetPDataType() const { virtual H5::DataType GetPDataType() const {
LOG(logERROR) << "This is a generic function GetPDataType that " LOG(logERROR) << "This is a generic function GetPDataType that "
"should be overloaded by a derived class"; "should be overloaded by a derived class";
return PredType::STD_U16LE; return H5::PredType::STD_U16LE;
} }
virtual std::vector<std::string> GetParameterNames() const { virtual std::vector<std::string> GetParameterNames() const {
@ -55,11 +52,11 @@ class File : private virtual slsDetectorDefs {
return std::vector<std::string>{}; return std::vector<std::string>{};
}; };
virtual std::vector<DataType> GetParameterDataTypes() const { virtual std::vector<H5::DataType> GetParameterDataTypes() const {
LOG(logERROR) LOG(logERROR)
<< "This is a generic function GetFilesInAcquisition that " << "This is a generic function GetFilesInAcquisition that "
"should be overloaded by a derived class"; "should be overloaded by a derived class";
return std::vector<DataType>{}; return std::vector<H5::DataType>{};
}; };
virtual void CreateFirstHDF5DataFile( virtual void CreateFirstHDF5DataFile(

View File

@ -26,13 +26,13 @@ HDF5DataFile::HDF5DataFile(int index, std::mutex *hdf5Lib)
"detector header version", "detector header version",
"packets caught bit mask", "packets caught bit mask",
}; };
StrType strdatatype(PredType::C_S1, sizeof(bitset_storage)); ::H5::StrType strdatatype(::H5::PredType::C_S1, sizeof(bitset_storage));
parameterDataTypes_ = std::vector<DataType>{ parameterDataTypes_ = std::vector<::H5::DataType>{
PredType::STD_U64LE, PredType::STD_U32LE, PredType::STD_U32LE, ::H5::PredType::STD_U64LE, ::H5::PredType::STD_U32LE, ::H5::PredType::STD_U32LE,
PredType::STD_U64LE, PredType::STD_U64LE, PredType::STD_U16LE, ::H5::PredType::STD_U64LE, ::H5::PredType::STD_U64LE, ::H5::PredType::STD_U16LE,
PredType::STD_U16LE, PredType::STD_U16LE, PredType::STD_U16LE, ::H5::PredType::STD_U16LE, ::H5::PredType::STD_U16LE, ::H5::PredType::STD_U16LE,
PredType::STD_U32LE, PredType::STD_U16LE, PredType::STD_U8LE, ::H5::PredType::STD_U32LE, ::H5::PredType::STD_U16LE, ::H5::PredType::STD_U8LE,
PredType::STD_U8LE, strdatatype}; ::H5::PredType::STD_U8LE, strdatatype};
} }
HDF5DataFile::~HDF5DataFile() { CloseFile(); } HDF5DataFile::~HDF5DataFile() { CloseFile(); }
@ -45,25 +45,25 @@ uint32_t HDF5DataFile::GetFilesInAcquisition() const {
return numFilesInAcquisition_; return numFilesInAcquisition_;
} }
DataType HDF5DataFile::GetPDataType() const { return dataType_; } ::H5::DataType HDF5DataFile::GetPDataType() const { return dataType_; }
std::vector<std::string> HDF5DataFile::GetParameterNames() const { std::vector<std::string> HDF5DataFile::GetParameterNames() const {
return parameterNames_; return parameterNames_;
} }
std::vector<DataType> HDF5DataFile::GetParameterDataTypes() const { std::vector<::H5::DataType> HDF5DataFile::GetParameterDataTypes() const {
return parameterDataTypes_; return parameterDataTypes_;
} }
void HDF5DataFile::CloseFile() { void HDF5DataFile::CloseFile() {
std::lock_guard<std::mutex> lock(*hdf5Lib_); std::lock_guard<std::mutex> lock(*hdf5Lib_);
try { try {
Exception::dontPrint(); // to handle errors ::H5::Exception::dontPrint(); // to handle errors
if (fd_) { if (fd_) {
fd_->close(); fd_->close();
delete fd_; delete fd_;
fd_ = nullptr; fd_ = nullptr;
} }
} catch (const Exception &error) { } catch (const ::H5::Exception &error) {
LOG(logERROR) << "Could not close data HDF5 handles of index " LOG(logERROR) << "Could not close data HDF5 handles of index "
<< index_; << index_;
error.printErrorStack(); error.printErrorStack();
@ -116,13 +116,13 @@ void HDF5DataFile::CreateFirstHDF5DataFile(
switch (dynamicRange_) { switch (dynamicRange_) {
case 12: case 12:
case 16: case 16:
dataType_ = PredType::STD_U16LE; dataType_ = ::H5::PredType::STD_U16LE;
break; break;
case 32: case 32:
dataType_ = PredType::STD_U32LE; dataType_ = ::H5::PredType::STD_U32LE;
break; break;
default: default:
dataType_ = PredType::STD_U8LE; dataType_ = ::H5::PredType::STD_U8LE;
break; break;
} }
@ -153,31 +153,31 @@ void HDF5DataFile::CreateFile() {
uint32_t nDimz = ((dynamicRange_ == 4) ? (nPixelsX_ / 2) : nPixelsX_); uint32_t nDimz = ((dynamicRange_ == 4) ? (nPixelsX_ / 2) : nPixelsX_);
try { try {
Exception::dontPrint(); // to handle errors ::H5::Exception::dontPrint(); // to handle errors
// file // file
FileAccPropList fapl; ::H5::FileAccPropList fapl;
fapl.setFcloseDegree(H5F_CLOSE_STRONG); fapl.setFcloseDegree(H5F_CLOSE_STRONG);
fd_ = nullptr; fd_ = nullptr;
if (!overWriteEnable_) if (!overWriteEnable_)
fd_ = new H5File(fileName_.c_str(), H5F_ACC_EXCL, fd_ = new ::H5::H5File(fileName_.c_str(), H5F_ACC_EXCL,
FileCreatPropList::DEFAULT, fapl); ::H5::FileCreatPropList::DEFAULT, fapl);
else else
fd_ = new H5File(fileName_.c_str(), H5F_ACC_TRUNC, fd_ = new ::H5::H5File(fileName_.c_str(), H5F_ACC_TRUNC,
FileCreatPropList::DEFAULT, fapl); ::H5::FileCreatPropList::DEFAULT, fapl);
// attributes - version // attributes - version
double dValue = HDF5_WRITER_VERSION; double dValue = HDF5_WRITER_VERSION;
DataSpace dataspace_attr = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace_attr = ::H5::DataSpace(H5S_SCALAR);
Attribute attribute = fd_->createAttribute( ::H5::Attribute attribute = fd_->createAttribute(
"version", PredType::NATIVE_DOUBLE, dataspace_attr); "version", ::H5::PredType::NATIVE_DOUBLE, dataspace_attr);
attribute.write(PredType::NATIVE_DOUBLE, &dValue); attribute.write(::H5::PredType::NATIVE_DOUBLE, &dValue);
// dataspace // dataspace
hsize_t srcdims[3] = {nDimx, nDimy, nDimz}; hsize_t srcdims[3] = {nDimx, nDimy, nDimz};
hsize_t srcdimsmax[3] = {H5S_UNLIMITED, nDimy, nDimz}; hsize_t srcdimsmax[3] = {H5S_UNLIMITED, nDimy, nDimz};
dataSpace_ = nullptr; dataSpace_ = nullptr;
dataSpace_ = new DataSpace(3, srcdims, srcdimsmax); dataSpace_ = new ::H5::DataSpace(3, srcdims, srcdimsmax);
// dataset name // dataset name
std::ostringstream osfn; std::ostringstream osfn;
@ -188,7 +188,7 @@ void HDF5DataFile::CreateFile() {
// dataset // dataset
// fill value // fill value
DSetCreatPropList plist; ::H5::DSetCreatPropList plist;
int fill_value = -1; int fill_value = -1;
plist.setFillValue(dataType_, &fill_value); plist.setFillValue(dataType_, &fill_value);
// always create chunked dataset as unlimited is only // always create chunked dataset as unlimited is only
@ -196,28 +196,28 @@ void HDF5DataFile::CreateFile() {
hsize_t chunk_dims[3] = {MAX_CHUNKED_IMAGES, nDimy, nDimz}; hsize_t chunk_dims[3] = {MAX_CHUNKED_IMAGES, nDimy, nDimz};
plist.setChunk(3, chunk_dims); plist.setChunk(3, chunk_dims);
dataSet_ = nullptr; dataSet_ = nullptr;
dataSet_ = new DataSet(fd_->createDataSet( dataSet_ = new ::H5::DataSet(fd_->createDataSet(
dataSetName_.c_str(), dataType_, *dataSpace_, plist)); dataSetName_.c_str(), dataType_, *dataSpace_, plist));
// create parameter datasets // create parameter datasets
hsize_t dims[1] = {nDimx}; hsize_t dims[1] = {nDimx};
hsize_t dimsmax[1] = {H5S_UNLIMITED}; hsize_t dimsmax[1] = {H5S_UNLIMITED};
dataSpacePara_ = nullptr; dataSpacePara_ = nullptr;
dataSpacePara_ = new DataSpace(1, dims, dimsmax); dataSpacePara_ = new ::H5::DataSpace(1, dims, dimsmax);
// always create chunked dataset as unlimited is only // always create chunked dataset as unlimited is only
// supported with chunked layout // supported with chunked layout
DSetCreatPropList paralist; ::H5::DSetCreatPropList paralist;
hsize_t chunkpara_dims[3] = {MAX_CHUNKED_IMAGES}; hsize_t chunkpara_dims[3] = {MAX_CHUNKED_IMAGES};
paralist.setChunk(1, chunkpara_dims); paralist.setChunk(1, chunkpara_dims);
for (unsigned int i = 0; i < parameterNames_.size(); ++i) { for (unsigned int i = 0; i < parameterNames_.size(); ++i) {
DataSet *ds = new DataSet(fd_->createDataSet( ::H5::DataSet *ds = new ::H5::DataSet(fd_->createDataSet(
parameterNames_[i].c_str(), parameterDataTypes_[i], parameterNames_[i].c_str(), parameterDataTypes_[i],
*dataSpacePara_, paralist)); *dataSpacePara_, paralist));
dataSetPara_.push_back(ds); dataSetPara_.push_back(ds);
} }
} catch (const Exception &error) { } catch (const ::H5::Exception &error) {
error.printErrorStack(); error.printErrorStack();
CloseFile(); CloseFile();
throw RuntimeError("Could not create HDF5 handles in object " + throw RuntimeError("Could not create HDF5 handles in object " +
@ -287,16 +287,16 @@ void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber,
hsize_t start[3] = {nDimx, 0, 0}; hsize_t start[3] = {nDimx, 0, 0};
hsize_t dims2[2] = {nDimy, nDimz}; hsize_t dims2[2] = {nDimy, nDimz};
try { try {
Exception::dontPrint(); // to handle errors ::H5::Exception::dontPrint(); // to handle errors
dataSpace_->selectHyperslab(H5S_SELECT_SET, count, start); dataSpace_->selectHyperslab(H5S_SELECT_SET, count, start);
DataSpace memspace(2, dims2); ::H5::DataSpace memspace(2, dims2);
dataSet_->write(revBuffer, dataType_, memspace, *dataSpace_); dataSet_->write(revBuffer, dataType_, memspace, *dataSpace_);
memspace.close(); memspace.close();
if (dynamicRange_ == 12) { if (dynamicRange_ == 12) {
free(revBuffer); free(revBuffer);
} }
} catch (const Exception &error) { } catch (const ::H5::Exception &error) {
if (dynamicRange_ == 12) { if (dynamicRange_ == 12) {
free(revBuffer); free(revBuffer);
} }
@ -320,9 +320,9 @@ void HDF5DataFile::WriteParameterDatasets(const uint64_t currentFrameNumber,
hsize_t start[1] = {fnum}; hsize_t start[1] = {fnum};
int i = 0; int i = 0;
try { try {
Exception::dontPrint(); // to handle errors ::H5::Exception::dontPrint(); // to handle errors
dataSpacePara_->selectHyperslab(H5S_SELECT_SET, count, start); dataSpacePara_->selectHyperslab(H5S_SELECT_SET, count, start);
DataSpace memspace(H5S_SCALAR); ::H5::DataSpace memspace(H5S_SCALAR);
dataSetPara_[0]->write(&header.frameNumber, parameterDataTypes_[0], dataSetPara_[0]->write(&header.frameNumber, parameterDataTypes_[0],
memspace, *dataSpacePara_); memspace, *dataSpacePara_);
i = 1; i = 1;
@ -383,7 +383,7 @@ void HDF5DataFile::WriteParameterDatasets(const uint64_t currentFrameNumber,
memspace, *dataSpacePara_); memspace, *dataSpacePara_);
} }
i = 14; i = 14;
} catch (const Exception &error) { } catch (const ::H5::Exception &error) {
error.printErrorStack(); error.printErrorStack();
throw RuntimeError( throw RuntimeError(
"Could not write parameters (index:" + std::to_string(i) + "Could not write parameters (index:" + std::to_string(i) +
@ -395,7 +395,7 @@ void HDF5DataFile::ExtendDataset() {
std::lock_guard<std::mutex> lock(*hdf5Lib_); std::lock_guard<std::mutex> lock(*hdf5Lib_);
try { try {
Exception::dontPrint(); // to handle errors ::H5::Exception::dontPrint(); // to handle errors
hsize_t dims[3]; hsize_t dims[3];
dataSpace_->getSimpleExtentDims(dims); dataSpace_->getSimpleExtentDims(dims);
@ -404,16 +404,16 @@ void HDF5DataFile::ExtendDataset() {
dataSet_->extend(dims); dataSet_->extend(dims);
delete dataSpace_; delete dataSpace_;
dataSpace_ = nullptr; dataSpace_ = nullptr;
dataSpace_ = new DataSpace(dataSet_->getSpace()); dataSpace_ = new ::H5::DataSpace(dataSet_->getSpace());
hsize_t dims_para[1] = {dims[0]}; hsize_t dims_para[1] = {dims[0]};
for (unsigned int i = 0; i < dataSetPara_.size(); ++i) for (unsigned int i = 0; i < dataSetPara_.size(); ++i)
dataSetPara_[i]->extend(dims_para); dataSetPara_[i]->extend(dims_para);
delete dataSpacePara_; delete dataSpacePara_;
dataSpacePara_ = nullptr; dataSpacePara_ = nullptr;
dataSpacePara_ = new DataSpace(dataSetPara_[0]->getSpace()); dataSpacePara_ = new ::H5::DataSpace(dataSetPara_[0]->getSpace());
} catch (const Exception &error) { } catch (const ::H5::Exception &error) {
error.printErrorStack(); error.printErrorStack();
throw RuntimeError("Could not extend dataset in object " + throw RuntimeError("Could not extend dataset in object " +
std::to_string(index_)); std::to_string(index_));

View File

@ -16,9 +16,9 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
std::array<std::string, 2> GetFileAndDatasetName() const override; std::array<std::string, 2> GetFileAndDatasetName() const override;
uint32_t GetFilesInAcquisition() const override; uint32_t GetFilesInAcquisition() const override;
DataType GetPDataType() const override; ::H5::DataType GetPDataType() const override;
std::vector<std::string> GetParameterNames() const override; std::vector<std::string> GetParameterNames() const override;
std::vector<DataType> GetParameterDataTypes() const override; std::vector<::H5::DataType> GetParameterDataTypes() const override;
void CloseFile() override; void CloseFile() override;
@ -45,17 +45,17 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
int index_; int index_;
std::mutex *hdf5Lib_; std::mutex *hdf5Lib_;
H5File *fd_{nullptr}; ::H5::H5File *fd_{nullptr};
std::string fileName_; std::string fileName_;
std::string dataSetName_; std::string dataSetName_;
DataSpace *dataSpace_{nullptr}; ::H5::DataSpace *dataSpace_{nullptr};
DataSet *dataSet_{nullptr}; ::H5::DataSet *dataSet_{nullptr};
DataType dataType_{PredType::STD_U16LE}; ::H5::DataType dataType_{::H5::PredType::STD_U16LE};
DataSpace *dataSpacePara_{nullptr}; ::H5::DataSpace *dataSpacePara_{nullptr};
std::vector<DataSet *> dataSetPara_{nullptr}; std::vector<::H5::DataSet *> dataSetPara_{nullptr};
std::vector<std::string> parameterNames_; std::vector<std::string> parameterNames_;
std::vector<DataType> parameterDataTypes_; std::vector<::H5::DataType> parameterDataTypes_;
uint32_t subFileIndex_{0}; uint32_t subFileIndex_{0};
uint32_t numFramesInFile_{0}; uint32_t numFramesInFile_{0};

View File

@ -1,6 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-or-other // SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package // Copyright (C) 2021 Contributors to the SLS Detector Package
#include "MasterAttributes.h" #include "MasterAttributes.h"
#include <time.h>
namespace sls { namespace sls {
@ -39,7 +41,7 @@ void MasterAttributes::GetBinaryAttributes(
} }
#ifdef HDF5C #ifdef HDF5C
void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5Attributes(::H5::H5File *fd, ::H5::Group *group) {
WriteCommonHDF5Attributes(fd, group); WriteCommonHDF5Attributes(fd, group);
switch (detType) { switch (detType) {
case slsDetectorDefs::GOTTHARD: case slsDetectorDefs::GOTTHARD:
@ -167,40 +169,40 @@ void MasterAttributes::GetFinalBinaryAttributes(
} }
#ifdef HDF5C #ifdef HDF5C
void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteCommonHDF5Attributes(::H5::H5File *fd, ::H5::Group *group) {
char c[1024]{}; char c[1024]{};
// version // version
{ {
double version = BINARY_WRITER_VERSION; double version = BINARY_WRITER_VERSION;
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
Attribute attribute = ::H5::Attribute attribute =
fd->createAttribute("Version", PredType::NATIVE_DOUBLE, dataspace); fd->createAttribute("Version", ::H5::PredType::NATIVE_DOUBLE, dataspace);
attribute.write(PredType::NATIVE_DOUBLE, &version); attribute.write(::H5::PredType::NATIVE_DOUBLE, &version);
} }
// timestamp // timestamp
{ {
time_t t = time(nullptr); time_t t = std::time(nullptr);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Timestamp", strdatatype, dataspace); group->createDataSet("Timestamp", strdatatype, dataspace);
strcpy_safe(c, std::string(ctime(&t))); strcpy_safe(c, std::string(ctime(&t)));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
// detector type // detector type
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Detector Type", strdatatype, dataspace); group->createDataSet("Detector Type", strdatatype, dataspace);
strcpy_safe(c, ToString(detType)); strcpy_safe(c, ToString(detType));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
// timing mode // timing mode
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Timing Mode", strdatatype, dataspace); group->createDataSet("Timing Mode", strdatatype, dataspace);
strcpy_safe(c, ToString(timingMode)); strcpy_safe(c, ToString(timingMode));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
@ -208,27 +210,27 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) {
// TODO: make this into an array? // TODO: make this into an array?
// geometry x // geometry x
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Geometry in x axis", ::H5::DataSet dataset = group->createDataSet("Geometry in x axis",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&geometry.x, PredType::NATIVE_INT); dataset.write(&geometry.x, ::H5::PredType::NATIVE_INT);
} }
// geometry y // geometry y
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Geometry in y axis", ::H5::DataSet dataset = group->createDataSet("Geometry in y axis",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&geometry.y, PredType::NATIVE_INT); dataset.write(&geometry.y, ::H5::PredType::NATIVE_INT);
} }
// Image Size // Image Size
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Image Size", PredType::NATIVE_INT, dataspace); group->createDataSet("Image Size", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&imageSize, PredType::NATIVE_INT); dataset.write(&imageSize, ::H5::PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspaceAttr = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
Attribute attribute = ::H5::Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr); dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
strcpy_safe(c, "bytes"); strcpy_safe(c, "bytes");
attribute.write(strdatatype, c); attribute.write(strdatatype, c);
@ -236,335 +238,335 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) {
// TODO: make this into an array? // TODO: make this into an array?
// npixels x // npixels x
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Number of pixels in x axis", ::H5::DataSet dataset = group->createDataSet("Number of pixels in x axis",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&nPixels.x, PredType::NATIVE_INT); dataset.write(&nPixels.x, ::H5::PredType::NATIVE_INT);
} }
// npixels y // npixels y
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Number of pixels in y axis", ::H5::DataSet dataset = group->createDataSet("Number of pixels in y axis",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&nPixels.y, PredType::NATIVE_INT); dataset.write(&nPixels.y, ::H5::PredType::NATIVE_INT);
} }
// Maximum frames per file // Maximum frames per file
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Maximum frames per file", ::H5::DataSet dataset = group->createDataSet("Maximum frames per file",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&maxFramesPerFile, PredType::NATIVE_INT); dataset.write(&maxFramesPerFile, ::H5::PredType::NATIVE_INT);
} }
// Frame Discard Policy // Frame Discard Policy
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = group->createDataSet("Frame Discard Policy", ::H5::DataSet dataset = group->createDataSet("Frame Discard Policy",
strdatatype, dataspace); strdatatype, dataspace);
strcpy_safe(c, ToString(frameDiscardMode)); strcpy_safe(c, ToString(frameDiscardMode));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
// Frame Padding // Frame Padding
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Frame Padding", ::H5::DataSet dataset = group->createDataSet("Frame Padding",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&framePadding, PredType::NATIVE_INT); dataset.write(&framePadding, ::H5::PredType::NATIVE_INT);
} }
// Scan Parameters // Scan Parameters
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Scan Parameters", strdatatype, dataspace); group->createDataSet("Scan Parameters", strdatatype, dataspace);
strcpy_safe(c, ToString(scanParams)); strcpy_safe(c, ToString(scanParams));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
// Total Frames // Total Frames
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Total Frames", ::H5::DataSet dataset = group->createDataSet("Total Frames",
PredType::STD_U64LE, dataspace); ::H5::PredType::STD_U64LE, dataspace);
dataset.write(&totalFrames, PredType::STD_U64LE); dataset.write(&totalFrames, ::H5::PredType::STD_U64LE);
} }
// Receiver Roi xmin // Receiver Roi xmin
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("receiver roi xmin", ::H5::DataSet dataset = group->createDataSet("receiver roi xmin",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&receiverRoi.xmin, PredType::NATIVE_INT); dataset.write(&receiverRoi.xmin, ::H5::PredType::NATIVE_INT);
} }
// Receiver Roi xmax // Receiver Roi xmax
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("receiver roi xmax", ::H5::DataSet dataset = group->createDataSet("receiver roi xmax",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&receiverRoi.xmax, PredType::NATIVE_INT); dataset.write(&receiverRoi.xmax, ::H5::PredType::NATIVE_INT);
} }
// Receiver Roi ymin // Receiver Roi ymin
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("receiver roi ymin", ::H5::DataSet dataset = group->createDataSet("receiver roi ymin",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&receiverRoi.ymin, PredType::NATIVE_INT); dataset.write(&receiverRoi.ymin, ::H5::PredType::NATIVE_INT);
} }
// Receiver Roi ymax // Receiver Roi ymax
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("receiver roi ymax", ::H5::DataSet dataset = group->createDataSet("receiver roi ymax",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&receiverRoi.ymax, PredType::NATIVE_INT); dataset.write(&receiverRoi.ymax, ::H5::PredType::NATIVE_INT);
} }
} }
void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteFinalHDF5Attributes(::H5::H5File *fd, ::H5::Group *group) {
char c[1024]{}; char c[1024]{};
// Total Frames in file // Total Frames in file
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Frames in File", ::H5::DataSet dataset = group->createDataSet("Frames in File",
PredType::STD_U64LE, dataspace); ::H5::PredType::STD_U64LE, dataspace);
dataset.write(&framesInFile, PredType::STD_U64LE); dataset.write(&framesInFile, ::H5::PredType::STD_U64LE);
} }
// additional json header // additional json header
if (!additionalJsonHeader.empty()) { if (!additionalJsonHeader.empty()) {
std::string json = ToString(additionalJsonHeader); std::string json = ToString(additionalJsonHeader);
StrType strdatatype(PredType::C_S1, json.length()); ::H5::StrType strdatatype(::H5::PredType::C_S1, json.length());
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Additional JSON Header", ::H5::DataSet dataset = group->createDataSet("Additional JSON Header",
strdatatype, dataspace); strdatatype, dataspace);
strcpy_safe(c, ToString(additionalJsonHeader)); strcpy_safe(c, ToString(additionalJsonHeader));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
} }
void MasterAttributes::WriteHDF5Exptime(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5Exptime(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Exposure Time", strdatatype, dataspace); group->createDataSet("Exposure Time", strdatatype, dataspace);
char c[1024]{}; char c[1024]{};
strcpy_safe(c, ToString(exptime)); strcpy_safe(c, ToString(exptime));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
void MasterAttributes::WriteHDF5Period(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5Period(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Acquisition Period", strdatatype, dataspace); group->createDataSet("Acquisition Period", strdatatype, dataspace);
char c[1024]{}; char c[1024]{};
strcpy_safe(c, ToString(period)); strcpy_safe(c, ToString(period));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
void MasterAttributes::WriteHDF5DynamicRange(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5DynamicRange(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Dynamic Range", PredType::NATIVE_INT, dataspace); group->createDataSet("Dynamic Range", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&dynamicRange, PredType::NATIVE_INT); dataset.write(&dynamicRange, ::H5::PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspaceAttr = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
Attribute attribute = ::H5::Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr); dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
char c[1024] = "bits"; char c[1024] = "bits";
attribute.write(strdatatype, c); attribute.write(strdatatype, c);
} }
void MasterAttributes::WriteHDF5TenGiga(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5TenGiga(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Ten Giga Enable", ::H5::DataSet dataset = group->createDataSet("Ten Giga Enable",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&tenGiga, PredType::NATIVE_INT); dataset.write(&tenGiga, ::H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5ROI(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5ROI(::H5::H5File *fd, ::H5::Group *group) {
// Roi xmin // Roi xmin
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("roi xmin", PredType::NATIVE_INT, dataspace); group->createDataSet("roi xmin", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&detectorRoi.xmin, PredType::NATIVE_INT); dataset.write(&detectorRoi.xmin, ::H5::PredType::NATIVE_INT);
} }
// Roi xmax // Roi xmax
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("roi xmax", PredType::NATIVE_INT, dataspace); group->createDataSet("roi xmax", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&detectorRoi.xmax, PredType::NATIVE_INT); dataset.write(&detectorRoi.xmax, ::H5::PredType::NATIVE_INT);
} }
} }
void MasterAttributes::WriteHDF5NumUDPInterfaces(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5NumUDPInterfaces(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Number of UDP Interfaces", ::H5::DataSet dataset = group->createDataSet("Number of UDP Interfaces",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&numUDPInterfaces, PredType::NATIVE_INT); dataset.write(&numUDPInterfaces, ::H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5ReadNRows(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5ReadNRows(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Number of rows", PredType::NATIVE_INT, dataspace); group->createDataSet("Number of rows", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&readNRows, PredType::NATIVE_INT); dataset.write(&readNRows, ::H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5ThresholdEnergy(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5ThresholdEnergy(::H5::H5File *fd, ::H5::Group *group) {
char c[1024]{}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Threshold Energy", ::H5::DataSet dataset = group->createDataSet("Threshold Energy",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&thresholdEnergyeV, PredType::NATIVE_INT); dataset.write(&thresholdEnergyeV, ::H5::PredType::NATIVE_INT);
DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspaceAttr = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
Attribute attribute = ::H5::Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr); dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
strcpy_safe(c, "eV"); strcpy_safe(c, "eV");
attribute.write(strdatatype, c); attribute.write(strdatatype, c);
} }
void MasterAttributes::WriteHDF5ThresholdEnergies(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5ThresholdEnergies(::H5::H5File *fd, ::H5::Group *group) {
char c[1024]{}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024); ::H5::StrType strdatatype(::H5::PredType::C_S1, 1024);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Threshold Energies", strdatatype, dataspace); group->createDataSet("Threshold Energies", strdatatype, dataspace);
strcpy_safe(c, ToString(thresholdAllEnergyeV)); strcpy_safe(c, ToString(thresholdAllEnergyeV));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
void MasterAttributes::WriteHDF5SubExpTime(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5SubExpTime(::H5::H5File *fd, ::H5::Group *group) {
char c[1024]{}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Sub Exposure Time", strdatatype, dataspace); group->createDataSet("Sub Exposure Time", strdatatype, dataspace);
strcpy_safe(c, ToString(subExptime)); strcpy_safe(c, ToString(subExptime));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
void MasterAttributes::WriteHDF5SubPeriod(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5SubPeriod(::H5::H5File *fd, ::H5::Group *group) {
char c[1024]{}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Sub Period", strdatatype, dataspace); group->createDataSet("Sub Period", strdatatype, dataspace);
strcpy_safe(c, ToString(subPeriod)); strcpy_safe(c, ToString(subPeriod));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
void MasterAttributes::WriteHDF5SubQuad(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5SubQuad(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Quad", PredType::NATIVE_INT, dataspace); group->createDataSet("Quad", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&quad, PredType::NATIVE_INT); dataset.write(&quad, ::H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5RateCorrections(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5RateCorrections(::H5::H5File *fd, ::H5::Group *group) {
char c[1024]{}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024); ::H5::StrType strdatatype(::H5::PredType::C_S1, 1024);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Rate Corrections", strdatatype, dataspace); group->createDataSet("Rate Corrections", strdatatype, dataspace);
strcpy_safe(c, ToString(ratecorr)); strcpy_safe(c, ToString(ratecorr));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
void MasterAttributes::WriteHDF5CounterMask(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5CounterMask(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Counter Mask", PredType::STD_U32LE, dataspace); group->createDataSet("Counter Mask", ::H5::PredType::STD_U32LE, dataspace);
dataset.write(&counterMask, PredType::STD_U32LE); dataset.write(&counterMask, ::H5::PredType::STD_U32LE);
} }
void MasterAttributes::WriteHDF5ExptimeArray(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5ExptimeArray(::H5::H5File *fd, ::H5::Group *group) {
for (int i = 0; i != 3; ++i) { for (int i = 0; i != 3; ++i) {
char c[1024]{}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Exposure Time1", strdatatype, dataspace); group->createDataSet("Exposure Time1", strdatatype, dataspace);
strcpy_safe(c, ToString(exptimeArray[i])); strcpy_safe(c, ToString(exptimeArray[i]));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
} }
void MasterAttributes::WriteHDF5GateDelayArray(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5GateDelayArray(::H5::H5File *fd, ::H5::Group *group) {
for (int i = 0; i != 3; ++i) { for (int i = 0; i != 3; ++i) {
char c[1024]{}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Gate Delay1", strdatatype, dataspace); group->createDataSet("Gate Delay1", strdatatype, dataspace);
strcpy_safe(c, ToString(gateDelayArray[i])); strcpy_safe(c, ToString(gateDelayArray[i]));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
} }
void MasterAttributes::WriteHDF5Gates(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5Gates(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Gates", PredType::STD_U32LE, dataspace); group->createDataSet("Gates", ::H5::PredType::STD_U32LE, dataspace);
dataset.write(&gates, PredType::STD_U32LE); dataset.write(&gates, ::H5::PredType::STD_U32LE);
} }
void MasterAttributes::WriteHDF5BurstMode(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5BurstMode(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); ::H5::StrType strdatatype(::H5::PredType::C_S1, 256);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Burst Mode", strdatatype, dataspace); group->createDataSet("Burst Mode", strdatatype, dataspace);
char c[1024]{}; char c[1024]{};
strcpy_safe(c, ToString(burstMode)); strcpy_safe(c, ToString(burstMode));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
void MasterAttributes::WriteHDF5AdcMask(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5AdcMask(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("ADC Mask", PredType::NATIVE_INT, dataspace); group->createDataSet("ADC Mask", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&adcmask, PredType::NATIVE_INT); dataset.write(&adcmask, ::H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5AnalogFlag(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5AnalogFlag(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Analog Flag", PredType::NATIVE_INT, dataspace); group->createDataSet("Analog Flag", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&analog, PredType::NATIVE_INT); dataset.write(&analog, ::H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5AnalogSamples(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5AnalogSamples(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Analog Samples", PredType::NATIVE_INT, dataspace); group->createDataSet("Analog Samples", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&analogSamples, PredType::NATIVE_INT); dataset.write(&analogSamples, ::H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5DigitalFlag(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5DigitalFlag(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Digital Flag", PredType::NATIVE_INT, dataspace); group->createDataSet("Digital Flag", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&digital, PredType::NATIVE_INT); dataset.write(&digital, ::H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5DigitalSamples(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5DigitalSamples(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Digital Samples", ::H5::DataSet dataset = group->createDataSet("Digital Samples",
PredType::NATIVE_INT, dataspace); ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&digitalSamples, PredType::NATIVE_INT); dataset.write(&digitalSamples, ::H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5DbitOffset(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5DbitOffset(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = ::H5::DataSet dataset =
group->createDataSet("Dbit Offset", PredType::NATIVE_INT, dataspace); group->createDataSet("Dbit Offset", ::H5::PredType::NATIVE_INT, dataspace);
dataset.write(&dbitoffset, PredType::NATIVE_INT); dataset.write(&dbitoffset, ::H5::PredType::NATIVE_INT);
} }
void MasterAttributes::WriteHDF5DbitList(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5DbitList(::H5::H5File *fd, ::H5::Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace = ::H5::DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Dbit Bitset List", ::H5::DataSet dataset = group->createDataSet("Dbit Bitset List",
PredType::STD_U64LE, dataspace); ::H5::PredType::STD_U64LE, dataspace);
dataset.write(&dbitlist, PredType::STD_U64LE); dataset.write(&dbitlist, ::H5::PredType::STD_U64LE);
} }
#endif #endif
@ -584,7 +586,7 @@ void MasterAttributes::GetGotthardBinaryAttributes(
}; };
#ifdef HDF5C #ifdef HDF5C
void MasterAttributes::WriteGotthardHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteGotthardHDF5Attributes(::H5::H5File *fd, ::H5::Group *group) {
MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5ROI(fd, group); MasterAttributes::WriteHDF5ROI(fd, group);
@ -604,7 +606,7 @@ void MasterAttributes::GetJungfrauBinaryAttributes(
} }
#ifdef HDF5C #ifdef HDF5C
void MasterAttributes::WriteJungfrauHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteJungfrauHDF5Attributes(::H5::H5File *fd, ::H5::Group *group) {
MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5NumUDPInterfaces(fd, group); MasterAttributes::WriteHDF5NumUDPInterfaces(fd, group);
@ -637,7 +639,7 @@ void MasterAttributes::GetEigerBinaryAttributes(
} }
#ifdef HDF5C #ifdef HDF5C
void MasterAttributes::WriteEigerHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteEigerHDF5Attributes(::H5::H5File *fd, ::H5::Group *group) {
MasterAttributes::WriteHDF5DynamicRange(fd, group); MasterAttributes::WriteHDF5DynamicRange(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group); MasterAttributes::WriteHDF5TenGiga(fd, group);
MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Exptime(fd, group);
@ -676,7 +678,7 @@ void MasterAttributes::GetMythen3BinaryAttributes(
} }
#ifdef HDF5C #ifdef HDF5C
void MasterAttributes::WriteMythen3HDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteMythen3HDF5Attributes(::H5::H5File *fd, ::H5::Group *group) {
MasterAttributes::WriteHDF5DynamicRange(fd, group); MasterAttributes::WriteHDF5DynamicRange(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group); MasterAttributes::WriteHDF5TenGiga(fd, group);
MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5Period(fd, group);
@ -699,7 +701,7 @@ void MasterAttributes::GetGotthard2BinaryAttributes(
} }
#ifdef HDF5C #ifdef HDF5C
void MasterAttributes::WriteGotthard2HDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteGotthard2HDF5Attributes(::H5::H5File *fd, ::H5::Group *group) {
MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5BurstMode(fd, group); MasterAttributes::WriteHDF5BurstMode(fd, group);
@ -721,7 +723,7 @@ void MasterAttributes::GetMoenchBinaryAttributes(
} }
#ifdef HDF5C #ifdef HDF5C
void MasterAttributes::WriteMoenchHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteMoenchHDF5Attributes(::H5::H5File *fd, ::H5::Group *group) {
MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group); MasterAttributes::WriteHDF5TenGiga(fd, group);
@ -755,7 +757,7 @@ void MasterAttributes::GetCtbBinaryAttributes(
} }
#ifdef HDF5C #ifdef HDF5C
void MasterAttributes::WriteCtbHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteCtbHDF5Attributes(::H5::H5File *fd, ::H5::Group *group) {
MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Exptime(fd, group);
MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5Period(fd, group);
MasterAttributes::WriteHDF5TenGiga(fd, group); MasterAttributes::WriteHDF5TenGiga(fd, group);

View File

@ -11,16 +11,16 @@
#include <rapidjson/stringbuffer.h> #include <rapidjson/stringbuffer.h>
#include <chrono> #include <chrono>
#ifdef HDF5C
#include "H5Cpp.h"
#endif
namespace sls { namespace sls {
using ns = std::chrono::nanoseconds; using ns = std::chrono::nanoseconds;
#ifdef HDF5C
#include "H5Cpp.h"
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif
#endif
class MasterAttributes { class MasterAttributes {
public: public:
@ -71,7 +71,7 @@ class MasterAttributes {
void void
GetBinaryAttributes(rapidjson::PrettyWriter<rapidjson::StringBuffer> *w); GetBinaryAttributes(rapidjson::PrettyWriter<rapidjson::StringBuffer> *w);
#ifdef HDF5C #ifdef HDF5C
void WriteHDF5Attributes(H5File *fd, Group *group); void WriteHDF5Attributes(::H5::H5File *fd, ::H5::Group *group);
#endif #endif
void GetCommonBinaryAttributes( void GetCommonBinaryAttributes(
@ -79,75 +79,75 @@ class MasterAttributes {
void GetFinalBinaryAttributes( void GetFinalBinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w); rapidjson::PrettyWriter<rapidjson::StringBuffer> *w);
#ifdef HDF5C #ifdef HDF5C
void WriteCommonHDF5Attributes(H5File *fd, Group *group); void WriteCommonHDF5Attributes(::H5::H5File *fd, ::H5::Group *group);
void WriteFinalHDF5Attributes(H5File *fd, Group *group); void WriteFinalHDF5Attributes(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5Exptime(H5File *fd, Group *group); void WriteHDF5Exptime(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5Period(H5File *fd, Group *group); void WriteHDF5Period(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5DynamicRange(H5File *fd, Group *group); void WriteHDF5DynamicRange(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5TenGiga(H5File *fd, Group *group); void WriteHDF5TenGiga(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5ROI(H5File *fd, Group *group); void WriteHDF5ROI(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5NumUDPInterfaces(H5File *fd, Group *group); void WriteHDF5NumUDPInterfaces(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5ReadNRows(H5File *fd, Group *group); void WriteHDF5ReadNRows(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5ThresholdEnergy(H5File *fd, Group *group); void WriteHDF5ThresholdEnergy(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5ThresholdEnergies(H5File *fd, Group *group); void WriteHDF5ThresholdEnergies(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5SubExpTime(H5File *fd, Group *group); void WriteHDF5SubExpTime(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5SubPeriod(H5File *fd, Group *group); void WriteHDF5SubPeriod(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5SubQuad(H5File *fd, Group *group); void WriteHDF5SubQuad(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5RateCorrections(H5File *fd, Group *group); void WriteHDF5RateCorrections(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5CounterMask(H5File *fd, Group *group); void WriteHDF5CounterMask(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5ExptimeArray(H5File *fd, Group *group); void WriteHDF5ExptimeArray(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5GateDelayArray(H5File *fd, Group *group); void WriteHDF5GateDelayArray(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5Gates(H5File *fd, Group *group); void WriteHDF5Gates(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5BurstMode(H5File *fd, Group *group); void WriteHDF5BurstMode(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5AdcMask(H5File *fd, Group *group); void WriteHDF5AdcMask(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5AnalogFlag(H5File *fd, Group *group); void WriteHDF5AnalogFlag(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5AnalogSamples(H5File *fd, Group *group); void WriteHDF5AnalogSamples(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5DigitalFlag(H5File *fd, Group *group); void WriteHDF5DigitalFlag(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5DigitalSamples(H5File *fd, Group *group); void WriteHDF5DigitalSamples(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5DbitOffset(H5File *fd, Group *group); void WriteHDF5DbitOffset(::H5::H5File *fd, ::H5::Group *group);
void WriteHDF5DbitList(H5File *fd, Group *group); void WriteHDF5DbitList(::H5::H5File *fd, ::H5::Group *group);
#endif #endif
void GetGotthardBinaryAttributes( void GetGotthardBinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w); rapidjson::PrettyWriter<rapidjson::StringBuffer> *w);
#ifdef HDF5C #ifdef HDF5C
void WriteGotthardHDF5Attributes(H5File *fd, Group *group); void WriteGotthardHDF5Attributes(::H5::H5File *fd, ::H5::Group *group);
#endif #endif
void GetJungfrauBinaryAttributes( void GetJungfrauBinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w); rapidjson::PrettyWriter<rapidjson::StringBuffer> *w);
#ifdef HDF5C #ifdef HDF5C
void WriteJungfrauHDF5Attributes(H5File *fd, Group *group); void WriteJungfrauHDF5Attributes(::H5::H5File *fd, ::H5::Group *group);
#endif #endif
void GetEigerBinaryAttributes( void GetEigerBinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w); rapidjson::PrettyWriter<rapidjson::StringBuffer> *w);
#ifdef HDF5C #ifdef HDF5C
void WriteEigerHDF5Attributes(H5File *fd, Group *group); void WriteEigerHDF5Attributes(::H5::H5File *fd, ::H5::Group *group);
#endif #endif
void GetMythen3BinaryAttributes( void GetMythen3BinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w); rapidjson::PrettyWriter<rapidjson::StringBuffer> *w);
#ifdef HDF5C #ifdef HDF5C
void WriteMythen3HDF5Attributes(H5File *fd, Group *group); void WriteMythen3HDF5Attributes(::H5::H5File *fd, ::H5::Group *group);
#endif #endif
void GetGotthard2BinaryAttributes( void GetGotthard2BinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w); rapidjson::PrettyWriter<rapidjson::StringBuffer> *w);
#ifdef HDF5C #ifdef HDF5C
void WriteGotthard2HDF5Attributes(H5File *fd, Group *group); void WriteGotthard2HDF5Attributes(::H5::H5File *fd, ::H5::Group *group);
#endif #endif
void GetMoenchBinaryAttributes( void GetMoenchBinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w); rapidjson::PrettyWriter<rapidjson::StringBuffer> *w);
#ifdef HDF5C #ifdef HDF5C
void WriteMoenchHDF5Attributes(H5File *fd, Group *group); void WriteMoenchHDF5Attributes(::H5::H5File *fd, ::H5::Group *group);
#endif #endif
void void
GetCtbBinaryAttributes(rapidjson::PrettyWriter<rapidjson::StringBuffer> *w); GetCtbBinaryAttributes(rapidjson::PrettyWriter<rapidjson::StringBuffer> *w);
#ifdef HDF5C #ifdef HDF5C
void WriteCtbHDF5Attributes(H5File *fd, Group *group); void WriteCtbHDF5Attributes(::H5::H5File *fd, ::H5::Group *group);
#endif #endif
}; };

View File

@ -47,30 +47,30 @@ std::string CreateMasterBinaryFile(const std::string &filePath,
} }
#ifdef HDF5C #ifdef HDF5C
void LinkHDF5FileInMaster(const std::string &masterFileName, void LinkHDF5FileInMaster(std::string &masterFileName,
const std::string &dataFilename, std::string &dataFilename,
const std::string &dataSetname, std::string &dataSetname,
const std::vector<std::string> parameterNames, std::vector<std::string> parameterNames,
const bool silentMode, std::mutex *hdf5LibMutex) { const bool silentMode, std::mutex *hdf5LibMutex) {
std::lock_guard<std::mutex> lock(*hdf5LibMutex); std::lock_guard<std::mutex> lock(*hdf5LibMutex);
std::unique_ptr<H5File> fd{nullptr}; std::unique_ptr<::H5::H5File> fd{nullptr};
try { try {
Exception::dontPrint(); // to handle errors ::H5::Exception::dontPrint(); // to handle errors
FileAccPropList flist; ::H5::FileAccPropList flist;
flist.setFcloseDegree(H5F_CLOSE_STRONG); flist.setFcloseDegree(H5F_CLOSE_STRONG);
// open master file // open master file
H5File masterfd(masterFileName.c_str(), H5F_ACC_RDWR, ::H5::H5File masterfd(masterFileName.c_str(), H5F_ACC_RDWR,
FileCreatPropList::DEFAULT, flist); ::H5::FileCreatPropList::DEFAULT, flist);
// open data file // open data file
fd = make_unique<H5File>(dataFilename.c_str(), H5F_ACC_RDONLY, fd = make_unique<::H5::H5File>(dataFilename.c_str(), H5F_ACC_RDONLY,
FileCreatPropList::DEFAULT, flist); ::H5::FileCreatPropList::DEFAULT, flist);
// create link for data dataset // create link for data dataset
DataSet dset = fd->openDataSet(dataSetname.c_str()); ::H5::DataSet dset = fd->openDataSet(dataSetname.c_str());
std::string linkname = std::string("/entry/data/") + dataSetname; std::string linkname = std::string("/entry/data/") + dataSetname;
if (H5Lcreate_external(dataFilename.c_str(), dataSetname.c_str(), if (H5Lcreate_external(dataFilename.c_str(), dataSetname.c_str(),
masterfd.getLocId(), linkname.c_str(), masterfd.getLocId(), linkname.c_str(),
@ -81,7 +81,7 @@ void LinkHDF5FileInMaster(const 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) {
DataSet pDset = fd->openDataSet(parameterNames[i].c_str()); ::H5::DataSet pDset = fd->openDataSet(parameterNames[i].c_str());
linkname = std::string("/entry/data/") + parameterNames[i]; linkname = std::string("/entry/data/") + parameterNames[i];
if (H5Lcreate_external(dataFilename.c_str(), if (H5Lcreate_external(dataFilename.c_str(),
parameterNames[i].c_str(), parameterNames[i].c_str(),
@ -93,7 +93,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName,
} }
fd->close(); fd->close();
masterfd.close(); masterfd.close();
} catch (const Exception &error) { } catch (const ::H5::Exception &error) {
error.printErrorStack(); error.printErrorStack();
if (fd != nullptr) if (fd != nullptr)
fd->close(); fd->close();
@ -118,38 +118,38 @@ std::string CreateMasterHDF5File(const std::string &filePath,
std::lock_guard<std::mutex> lock(*hdf5LibMutex); std::lock_guard<std::mutex> lock(*hdf5LibMutex);
std::unique_ptr<H5File> fd{nullptr}; std::unique_ptr<::H5::H5File> fd{nullptr};
try { try {
Exception::dontPrint(); // to handle errors ::H5::Exception::dontPrint(); // to handle errors
FileAccPropList flist; ::H5::FileAccPropList flist;
flist.setFcloseDegree(H5F_CLOSE_STRONG); flist.setFcloseDegree(H5F_CLOSE_STRONG);
unsigned int createFlags = H5F_ACC_EXCL; unsigned int createFlags = H5F_ACC_EXCL;
if (overWriteEnable) { if (overWriteEnable) {
createFlags = H5F_ACC_TRUNC; createFlags = H5F_ACC_TRUNC;
} }
fd = make_unique<H5File>(fileName.c_str(), createFlags, fd = make_unique<::H5::H5File>(fileName.c_str(), createFlags,
FileCreatPropList::DEFAULT, flist); ::H5::FileCreatPropList::DEFAULT, flist);
// attributes - version // attributes - version
double dValue = HDF5_WRITER_VERSION; double dValue = HDF5_WRITER_VERSION;
DataSpace dataspace_attr = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace_attr = ::H5::DataSpace(H5S_SCALAR);
Attribute attribute = fd->createAttribute( ::H5::Attribute attribute = fd->createAttribute(
"version", PredType::NATIVE_DOUBLE, dataspace_attr); "version", ::H5::PredType::NATIVE_DOUBLE, dataspace_attr);
attribute.write(PredType::NATIVE_DOUBLE, &dValue); attribute.write(::H5::PredType::NATIVE_DOUBLE, &dValue);
// Create a group in the file // Create a group in the file
Group group1(fd->createGroup("entry")); ::H5::Group group1(fd->createGroup("entry"));
Group group2(group1.createGroup("data")); ::H5::Group group2(group1.createGroup("data"));
Group group3(group1.createGroup("instrument")); ::H5::Group group3(group1.createGroup("instrument"));
Group group4(group3.createGroup("beam")); ::H5::Group group4(group3.createGroup("beam"));
Group group5(group3.createGroup("detector")); ::H5::Group group5(group3.createGroup("detector"));
Group group6(group1.createGroup("sample")); ::H5::Group group6(group1.createGroup("sample"));
attr->WriteHDF5Attributes(fd.get(), &group5); attr->WriteHDF5Attributes(fd.get(), &group5);
fd->close(); fd->close();
} catch (const Exception &error) { } catch (const ::H5::Exception &error) {
error.printErrorStack(); error.printErrorStack();
if (fd != nullptr) if (fd != nullptr)
fd->close(); fd->close();
@ -169,9 +169,9 @@ std::array<std::string, 2> CreateVirtualHDF5File(
const uint32_t maxFramesPerFile, const uint64_t numImages, const uint32_t maxFramesPerFile, const uint64_t numImages,
const uint32_t nPixelsX, const uint32_t nPixelsY, const uint32_t nPixelsX, const uint32_t nPixelsY,
const uint32_t dynamicRange, const uint64_t numImagesCaught, const uint32_t dynamicRange, const uint64_t numImagesCaught,
const int numModX, const int numModY, const DataType dataType, const int numModX, const int numModY, const ::H5::DataType dataType,
const std::vector<std::string> parameterNames, const std::vector<std::string> parameterNames,
const std::vector<DataType> parameterDataTypes, std::mutex *hdf5LibMutex, const std::vector<::H5::DataType> parameterDataTypes, std::mutex *hdf5LibMutex,
bool gotthard25um) { bool gotthard25um) {
// virtual file name // virtual file name
@ -189,42 +189,42 @@ std::array<std::string, 2> CreateVirtualHDF5File(
std::lock_guard<std::mutex> lock(*hdf5LibMutex); std::lock_guard<std::mutex> lock(*hdf5LibMutex);
std::unique_ptr<H5File> fd{nullptr}; std::unique_ptr<::H5::H5File> fd{nullptr};
try { try {
Exception::dontPrint(); // to handle errors ::H5::Exception::dontPrint(); // to handle errors
// file // file
FileAccPropList fapl; ::H5::FileAccPropList fapl;
fapl.setFcloseDegree(H5F_CLOSE_STRONG); fapl.setFcloseDegree(H5F_CLOSE_STRONG);
if (!overWriteEnable) if (!overWriteEnable)
fd = make_unique<H5File>(fileName.c_str(), H5F_ACC_EXCL, fd = make_unique<::H5::H5File>(fileName.c_str(), H5F_ACC_EXCL,
FileCreatPropList::DEFAULT, fapl); ::H5::FileCreatPropList::DEFAULT, fapl);
else else
fd = make_unique<H5File>(fileName.c_str(), H5F_ACC_TRUNC, fd = make_unique<::H5::H5File>(fileName.c_str(), H5F_ACC_TRUNC,
FileCreatPropList::DEFAULT, fapl); ::H5::FileCreatPropList::DEFAULT, fapl);
// attributes - version // attributes - version
double dValue = HDF5_WRITER_VERSION; double dValue = HDF5_WRITER_VERSION;
DataSpace dataspace_attr = DataSpace(H5S_SCALAR); ::H5::DataSpace dataspace_attr = ::H5::DataSpace(H5S_SCALAR);
Attribute attribute = fd->createAttribute( ::H5::Attribute attribute = fd->createAttribute(
"version", PredType::NATIVE_DOUBLE, dataspace_attr); "version", ::H5::PredType::NATIVE_DOUBLE, dataspace_attr);
attribute.write(PredType::NATIVE_DOUBLE, &dValue); attribute.write(::H5::PredType::NATIVE_DOUBLE, &dValue);
// virtual dataspace // virtual dataspace
hsize_t vdsDims[3] = {numImagesCaught, numModY * nDimy, hsize_t vdsDims[3] = {numImagesCaught, numModY * nDimy,
numModZ * nDimz}; numModZ * nDimz};
DataSpace vdsDataSpace(3, vdsDims, nullptr); ::H5::DataSpace vdsDataSpace(3, vdsDims, nullptr);
hsize_t vdsDimsPara[2] = {numImagesCaught, hsize_t vdsDimsPara[2] = {numImagesCaught,
(unsigned int)numModY * numModZ}; (unsigned int)numModY * numModZ};
DataSpace vdsDataSpacePara(2, vdsDimsPara, nullptr); ::H5::DataSpace vdsDataSpacePara(2, vdsDimsPara, nullptr);
// property list (fill value and datatype) // property list (fill value and datatype)
int fill_value = -1; int fill_value = -1;
DSetCreatPropList plist; ::H5::DSetCreatPropList plist;
plist.setFillValue(dataType, &fill_value); plist.setFillValue(dataType, &fill_value);
// property list for parameters (datatype) // property list for parameters (datatype)
std::vector<DSetCreatPropList> plistPara(paraSize); std::vector<::H5::DSetCreatPropList> plistPara(paraSize);
// hyperslab (files) // hyperslab (files)
int numFiles = numImagesCaught / maxFramesPerFile; int numFiles = numImagesCaught / maxFramesPerFile;
@ -296,10 +296,10 @@ std::array<std::string, 2> CreateVirtualHDF5File(
// source dataspace // source dataspace
hsize_t srcDims[3] = {nDimx, nDimy, nDimz}; hsize_t srcDims[3] = {nDimx, nDimy, nDimz};
hsize_t srcDimsMax[3] = {H5S_UNLIMITED, nDimy, nDimz}; hsize_t srcDimsMax[3] = {H5S_UNLIMITED, nDimy, nDimz};
DataSpace srcDataSpace(3, srcDims, srcDimsMax); ::H5::DataSpace srcDataSpace(3, srcDims, srcDimsMax);
hsize_t srcDimsPara[1] = {nDimx}; hsize_t srcDimsPara[1] = {nDimx};
hsize_t srcDimsMaxPara[1] = {H5S_UNLIMITED}; hsize_t srcDimsMaxPara[1] = {H5S_UNLIMITED};
DataSpace srcDataSpacePara(1, srcDimsPara, srcDimsMaxPara); ::H5::DataSpace srcDataSpacePara(1, srcDimsPara, srcDimsMaxPara);
// mapping of property list // mapping of property list
plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(), plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(),
@ -325,17 +325,17 @@ std::array<std::string, 2> CreateVirtualHDF5File(
framesSaved += nDimx; framesSaved += nDimx;
} }
// datasets // datasets
DataSet vdsDataSet(fd->createDataSet(dataSetName.c_str(), dataType, ::H5::DataSet vdsDataSet(fd->createDataSet(dataSetName.c_str(), dataType,
vdsDataSpace, plist)); vdsDataSpace, plist));
for (unsigned int p = 0; p < paraSize; ++p) { for (unsigned int p = 0; p < paraSize; ++p) {
DataSet vdsDataSetPara(fd->createDataSet( ::H5::DataSet vdsDataSetPara(fd->createDataSet(
parameterNames[p].c_str(), parameterDataTypes[p], parameterNames[p].c_str(), parameterDataTypes[p],
vdsDataSpacePara, plistPara[p])); vdsDataSpacePara, plistPara[p]));
} }
fd->close(); fd->close();
} catch (const Exception &error) { } catch (const ::H5::Exception &error) {
error.printErrorStack(); error.printErrorStack();
if (fd) { if (fd) {
fd->close(); fd->close();

View File

@ -4,17 +4,13 @@
#include "MasterAttributes.h" #include "MasterAttributes.h"
#include <mutex>
namespace sls { namespace sls {
namespace masterFileUtility { namespace masterFileUtility {
#ifdef HDF5C
#include "H5Cpp.h"
#include <mutex>
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif
#endif
std::string CreateMasterBinaryFile(const std::string &filePath, std::string CreateMasterBinaryFile(const std::string &filePath,
@ -25,10 +21,10 @@ std::string CreateMasterBinaryFile(const std::string &filePath,
MasterAttributes *attr); MasterAttributes *attr);
#ifdef HDF5C #ifdef HDF5C
void LinkHDF5FileInMaster(const std::string &masterFileName, void LinkHDF5FileInMaster(std::string &masterFileName,
const std::string &dataFilename, std::string &dataFilename,
const std::string &dataSetname, std::string &dataSetname,
const std::vector<std::string> parameterNames, std::vector<std::string> parameterNames,
const bool silentMode, std::mutex *hdf5LibMutex); const bool silentMode, std::mutex *hdf5LibMutex);
std::string CreateMasterHDF5File(const std::string &filePath, std::string CreateMasterHDF5File(const std::string &filePath,
@ -45,9 +41,9 @@ std::array<std::string, 2> CreateVirtualHDF5File(
const uint32_t maxFramesPerFile, const uint64_t numImages, const uint32_t maxFramesPerFile, const uint64_t numImages,
const uint32_t nPixelsX, const uint32_t nPixelsY, const uint32_t nPixelsX, const uint32_t nPixelsY,
const uint32_t dynamicRange, const uint64_t numImagesCaught, const uint32_t dynamicRange, const uint64_t numImagesCaught,
const int numModX, const int numModY, const DataType dataType, const int numModX, const int numModY, const ::H5::DataType dataType,
const std::vector<std::string> parameterNames, const std::vector<std::string> parameterNames,
const std::vector<DataType> parameterDataTypes, std::mutex *hdf5LibMutex, const std::vector<::H5::DataType> parameterDataTypes, std::mutex *hdf5LibMutex,
bool gotthard25um); bool gotthard25um);
#endif #endif
} // namespace masterFileUtility } // namespace masterFileUtility