5 #include "lzf_filter.h"
8 #if QT_VERSION >= 0x050000
13 #include "qcepmutexlocker.h"
25 m_Application(application),
27 m_DimensionsCache(dim),
28 m_ChunkSizeCache(chunkSize),
30 m_DataFileName(application->
saver(),
this,
"dataFileName",
"input.h5",
"HDF5 Data File Name"),
31 m_DataSetName(application->
saver(),
this,
"dataSetName",
"data",
"HDF5 Dataset name"),
32 m_MaskDataFileName(application->
saver(),
this,
"maskDataFileName",
"",
"Mask Data File Name"),
33 m_MaskDataSetName(application->
saver(),
this,
"maskDataSetName",
"",
"Mask Dataset Name"),
34 m_Mask(QcepSettingsSaverWPtr(),
this,
"mask", QcepIntVector(),
"Mask Image"),
35 m_AnglesDataFileName(application->
saver(),
this,
"anglesDataFileName",
"",
"Angles Data File Name"),
36 m_AnglesDataSetName(application->
saver(),
this,
"anglesDataSetName",
"",
"Angles Dataset Name"),
37 m_Angles(QcepSettingsSaverWPtr(),
this,
"angles", QcepDoubleVector(),
"Angles"),
38 m_WeightsDataFileName(application->
saver(),
this,
"weightsDataFileName",
"",
"Weights Data File Name"),
39 m_WeightsDataSetName(application->
saver(),
this,
"weightsDataSetName",
"",
"Weights Dataset Name"),
40 m_Weights(QcepSettingsSaverWPtr(),
this,
"weights", QcepDoubleVector(),
"Weights"),
41 m_Dimensions(application->
saver(),
this,
"dimensions", m_DimensionsCache,
"Dataset Dimensions"),
42 m_ChunkSize(application->
saver(),
this,
"chunkSize", m_ChunkSizeCache,
"Chunk Size"),
43 m_ChunkCount(QcepSettingsSaverWPtr(),
this,
"chunkCount", m_ChunkCountCache,
"Chunk Count"),
44 m_Compression(application->
saver(),
this,
"compression", 0,
"Compression Level"),
45 m_Normalization(QcepSettingsSaverWPtr(),
this,
"normalization", 1,
"Normalization"),
46 m_HDFChunkSize(application->
saver(),
this,
"hdfChunkSize",
CctwIntVector3D(0,0,0),
"HDF File Chunk Size"),
47 m_ChunksRead(QcepSettingsSaverWPtr(),
this,
"chunksRead", 0,
"Chunks read from input"),
48 m_ChunksWritten(QcepSettingsSaverWPtr(),
this,
"chunksWritten", 0,
"Chunks written to output"),
49 m_ChunksHeld(QcepSettingsSaverWPtr(),
this,
"chunksHeld", 0,
"Chunks held on output"),
50 m_ChunksHeldMax(QcepSettingsSaverWPtr(),
this,
"chunksHeldMax", 0,
"Max Chunks held on output"),
52 m_TransformOptions(0),
58 m_MaskSameFile(
false),
61 m_MaskDataspaceId(-1),
62 m_AnglesSameFile(
false),
64 m_AnglesDatasetId(-1),
65 m_AnglesDataspaceId(-1),
66 m_WeightsSameFile(
false),
68 m_WeightsDatasetId(-1),
69 m_WeightsDataspaceId(-1)
79 prop_Dimensions(), SLOT(setValue(
CctwIntVector3D)), Qt::DirectConnection);
81 prop_ChunkSize(), SLOT(setValue(
CctwIntVector3D)), Qt::DirectConnection);
83 prop_ChunkCount(), SLOT(setValue(
CctwIntVector3D)), Qt::DirectConnection);
86 this, SLOT(sizingChanged()), Qt::DirectConnection);
88 this, SLOT(sizingChanged()), Qt::DirectConnection);
94 QcepMutexLocker lock(__FILE__, __LINE__, &
m_ChunkLock);
117 if (qcepDebug(DEBUG_PROPERTIES)) {
135 if (qcepDebug(DEBUG_PROPERTIES)) {
153 QcepIntVector m = get_Mask();
162 QcepDoubleVector a = get_Angles();
171 QcepDoubleVector a = get_Weights();
180 QcepDoubleVector a = get_Angles();
182 if (n >= 0 && n < a.size()) {
191 return get_Angles().value(n);
196 return get_Weights().value(n);
202 QcepDoubleVector a = get_Weights();
204 if (n >= 0 && n < a.size()) {
213 if (qcepDebug(DEBUG_PROPERTIES)) {
232 if (qcepDebug(DEBUG_APP)) {
239 #if QT_VERSION >= 0x050000
245 set_DataFileName(url.path());
246 set_DataSetName(url.fragment());
248 #if QT_VERSION >= 0x050000
249 if (url.hasQuery()) {
252 QList <QPair <QString, QString> > l = qry.queryItems();
254 QPair<QString, QString> v;
256 if (qcepDebug(DEBUG_APP)) {
262 if (qry.hasQueryItem(
"size")) {
263 QString chunkSize = qry.queryItemValue(
"size");
267 if (qry.hasQueryItem(
"dim")) {
268 QString dims = qry.queryItemValue(
"dim");
272 if (qry.hasQueryItem(
"dataset")) {
273 QString dset = qry.queryItemValue(
"dataset");
303 QRegExp r(
"(\\d+)[Xx,](\\d+)[Xx,](\\d+)", Qt::CaseInsensitive);
305 if (r.exactMatch(desc)) {
306 CctwIntVector3D d(r.cap(1).toInt(), r.cap(2).toInt(), r.cap(3).toInt());
310 printMessage(tr(
"Dataset dimensions set to [%1,%2,%3]").arg(d.x()).arg(d.y()).arg(d.z()));
313 int n = desc.toInt(&ok);
320 printMessage(tr(
"Dataset dimensions set to [%1,%2,%3]").arg(d.
x()).arg(d.
y()).arg(d.
z()));
327 QRegExp r(
"(\\d+)[Xx,](\\d+)[Xx,](\\d+)", Qt::CaseInsensitive);
329 if (r.exactMatch(desc)) {
330 CctwIntVector3D cksz(r.cap(1).toInt(), r.cap(2).toInt(), r.cap(3).toInt());
334 printMessage(tr(
"Chunk size set to [%1,%2,%3]").arg(cksz.x()).arg(cksz.y()).arg(cksz.z()));
337 int n = desc.toInt(&ok);
344 printMessage(tr(
"Chunk size set to [%1,%2,%3]").arg(cksz.
x()).arg(cksz.
y()).arg(cksz.
z()));
351 set_DataSetName(desc);
358 if (qcepDebug(DEBUG_APP)) {
365 #if QT_VERSION >= 0x050000
371 set_MaskDataFileName(url.path());
372 set_MaskDataSetName(url.fragment());
374 #if QT_VERSION >= 0x050000
375 if (url.hasQuery()) {
378 QList <QPair <QString, QString> > l = qry.queryItems();
380 QPair<QString, QString> v;
382 if (qcepDebug(DEBUG_APP)) {
398 if (qry.hasQueryItem(
"dataset")) {
399 QString dset = qry.queryItemValue(
"dataset");
408 set_MaskDataSetName(desc);
415 if (qcepDebug(DEBUG_APP)) {
422 #if QT_VERSION >= 0x050000
428 set_AnglesDataFileName(url.path());
429 set_AnglesDataSetName(url.fragment());
431 #if QT_VERSION >= 0x050000
432 if (url.hasQuery()) {
435 QList <QPair <QString, QString> > l = qry.queryItems();
437 QPair<QString, QString> v;
439 if (qcepDebug(DEBUG_APP)) {
455 if (qry.hasQueryItem(
"dataset")) {
456 QString dset = qry.queryItemValue(
"dataset");
465 set_AnglesDataSetName(desc);
472 if (qcepDebug(DEBUG_APP)) {
479 #if QT_VERSION >= 0x050000
485 set_WeightsDataFileName(url.path());
486 set_WeightsDataSetName(url.fragment());
488 #if QT_VERSION >= 0x050000
489 if (url.hasQuery()) {
492 QList <QPair <QString, QString> > l = qry.queryItems();
494 QPair<QString, QString> v;
496 if (qcepDebug(DEBUG_APP)) {
512 if (qry.hasQueryItem(
"dataset")) {
513 QString dset = qry.queryItemValue(
"dataset");
522 set_WeightsDataSetName(desc);
527 return pixelCoord.
x() >= 0 &&
528 pixelCoord.
y() >= 0 &&
529 pixelCoord.
z() >= 0 &&
579 return chunkIdx.
x()*xstride + chunkIdx.
y()*ystride + chunkIdx.
z()*zstride;
627 QcepMutexLocker lock(__FILE__, __LINE__, &
m_ChunkLock);
632 chunk =
new CctwDataChunk(
this, n, tr(
"Chunk-%1").arg(n), NULL);
635 chunk->moveToThread(parent()->thread());
636 chunk->setParent(parent());
642 if (chunk && chunk->
index() != n) {
654 QcepMutexLocker lock(__FILE__, __LINE__, &
m_ChunkLock);
683 int idx = chunk->
index();
702 set_ChunksWritten(0);
704 set_ChunksHeldMax(0);
719 herr_t (*old_func)(hid_t,
void*);
720 void *old_client_data;
721 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
724 H5Eset_auto(H5E_DEFAULT, NULL, NULL);
730 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
737 set_Normalization(1);
745 QString fileName = get_DataFileName();
748 if (fileName.length() == 0) {
753 if (dataSetName.length() == 0) {
759 printMessage(tr(
"About to open input file: %1 dataset: %2")
760 .arg(fileName).arg(dataSetName));
763 QFileInfo f(fileName);
776 throw tr(
"File %1 does not exist").arg(fileName);
777 if (H5Fis_hdf5(qPrintable(fileName)) <= 0)
778 throw tr(
"File %1 exists but is not an hdf file").arg(fileName);
780 fileId = H5Fopen(qPrintable(fileName), H5F_ACC_RDONLY, H5P_DEFAULT);
782 throw tr(
"File %1 could not be opened").arg(fileName);
784 objId = H5Oopen(fileId, qPrintable(dataSetName), H5P_DEFAULT);
786 throw tr(
"Could not open data object!");
789 if (H5Oget_info(objId, &info) < 0) {
790 throw tr(
"Could not get object info");
796 if (info.type == H5O_TYPE_DATASET) {
799 dsetId = H5Dopen(fileId, qPrintable(dataSetName), H5P_DEFAULT);
801 throw tr(
"Could not open dataset!");
803 dspcId = H5Dget_space(dsetId);
805 throw tr(
"Could not get dataspace of existing dataset");
808 int ndims = H5Sget_simple_extent_ndims(dspcId);
810 throw tr(
"Dataspace is not 3-dimensional");
812 int ndims2 = H5Sget_simple_extent_dims(dspcId, dims, NULL);
814 throw tr(
"Could not get dataspace dimensions");
817 plist = H5Dget_create_plist(dsetId);
820 throw tr(
"Could not get dataset create plist");
823 if (H5Pget_chunk(plist, 3, cksz) < 0) {
832 H5Pclose(plist); plist = -1;
833 }
else if (info.type == H5O_TYPE_GROUP) {
836 dsetId = H5Dopen(fileId, qPrintable(dataSetName+
"/v"), H5P_DEFAULT);
838 throw tr(
"Could not open 'V' dataset!");
840 dspcId = H5Dget_space(dsetId);
842 throw tr(
"Could not get dataspace of existing dataset");
845 int ndims = H5Sget_simple_extent_ndims(dspcId);
847 throw tr(
"Dataspace is not 3-dimensional");
849 int ndims2 = H5Sget_simple_extent_dims(dspcId, dims, NULL);
851 throw tr(
"Could not get dataspace dimensions");
854 plist = H5Dget_create_plist(dsetId);
857 throw tr(
"Could not get dataset create plist");
860 if (H5Pget_chunk(plist, 3, cksz) < 0) {
869 H5Pclose(plist); plist = -1;
871 dset2Id = H5Dopen(fileId, qPrintable(dataSetName+
"/n"), H5P_DEFAULT);
873 printMessage(tr(
"Could not open 'N' dataset, assuming normalized"));
875 dspc2Id = H5Dget_space(dsetId);
877 throw tr(
"Could not get dataspace of existing 'N' dataset");
880 int ndims = H5Sget_simple_extent_ndims(dspc2Id);
882 throw tr(
"Dataspace is not 3-dimensional");
884 int ndims2 = H5Sget_simple_extent_dims(dspc2Id, dims, NULL);
886 throw tr(
"Could not get dataspace dimensions");
889 throw tr(
"Dimension mismatch between 'V' and 'N' datasets");
892 set_Normalization(0);
903 printMessage(tr(
"Opened input file \"%1\" OK, DS \"%2\", Norm %3, DSID %4, DS2ID %5, CMPRS %6")
904 .arg(get_DataFileName()).arg(get_DataSetName())
906 .arg(get_Compression()));
910 printMessage(tr(
"Input dimensions %1, HDF Chunk size %2, Input chunk size %3, Chunk counts %4")
911 .arg(get_Dimensions().toString())
913 .arg(get_ChunkSize().toString())
914 .arg(get_ChunkCount().toString()));
917 catch (QString &msg )
920 printMessage(tr(
"Anomaly in CctwChunkedData::openInputFile fileId=%1, dsetId=%2, dspcId=%3")
921 .arg(fileId).arg(dsetId).arg(dspcId));
925 if (dspcId >= 0) H5Sclose(dspcId);
926 if (dspc2Id >= 0) H5Sclose(dspc2Id);
927 if (dsetId >= 0) H5Dclose(dsetId);
928 if (dset2Id >= 0) H5Dclose(dset2Id);
929 if (objId >= 0) H5Oclose(objId);
930 if (fileId >= 0) H5Fclose(fileId);
931 if (plist >= 0) H5Pclose(plist);
973 #if NEXUS_ENABLED == 1
981 QString fileName = get_DataFileName();
982 QFileInfo f(fileName);
985 printMessage(tr(
"File %1 does not exist").arg(fileName));
987 }
else if (H5Fis_hdf5(qPrintable(fileName)) <= 0) {
988 printMessage(tr(
"File %1 exists but is not an hdf file").arg(fileName));
992 m_NeXusFile =
new NeXus::File(qPrintable(fileName));
993 printMessage(tr(
"NeXus file opened successfully: %1").arg(fileName));
1000 m_NeXusFile->close();
1006 printMessage(tr(
"NeXus was not enabled at build time!"));
1011 printMessage(tr(
"NeXus was not enabled at build time!"));
1023 QString fileName = get_DataFileName();
1026 if (fileName.length() == 0) {
1031 if (dataSetName.length() == 0) {
1036 printMessage(tr(
"About to open output file: %1 dataset: %2")
1037 .arg(fileName).arg(dataSetName));
1041 QFileInfo f(fileName);
1054 fileId = H5Fcreate(qPrintable(fileName), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
1057 printMessage(tr(
"File %1 could not be created").arg(fileName));
1060 }
else if (H5Fis_hdf5(qPrintable(fileName)) <= 0) {
1061 printMessage(tr(
"File %1 exists but is not an hdf file").arg(fileName));
1064 fileId = H5Fopen(qPrintable(fileName), H5F_ACC_RDWR, H5P_DEFAULT);
1067 printMessage(tr(
"File %1 could not be opened").arg(fileName));
1073 herr_t (*old_func)(hid_t,
void*);
1074 void *old_client_data;
1075 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
1078 H5Eset_auto(H5E_DEFAULT, NULL, NULL);
1080 if (get_Normalization()) {
1081 dsetId = H5Dopen(fileId, qPrintable(get_DataSetName()), H5P_DEFAULT);
1083 dsetId = H5Dopen(fileId, qPrintable(get_DataSetName()+
"/v"), H5P_DEFAULT);
1084 dset2Id = H5Dopen(fileId, qPrintable(get_DataSetName()+
"/n"), H5P_DEFAULT);
1088 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
1091 dspcId = H5Dget_space(dsetId);
1094 printMessage(
"Couldn't get dataspace of existing dataset");
1098 int ndims = H5Sget_simple_extent_ndims(dspcId);
1104 int ndims2 = H5Sget_simple_extent_dims(dspcId, dims, NULL);
1113 printMessage(
"Dataspace dimensions do not match output data");
1125 dspcId = H5Screate_simple(3, dims, NULL);
1128 int cmprs = get_Compression();
1130 plist = H5Pcreate(H5P_DATASET_CREATE);
1141 if (H5Pset_chunk(plist, 3, c) < 0) {
1144 }
else if (H5Pset_fill_value(plist, H5T_NATIVE_FLOAT, &zero)) {
1147 }
else if (cmprs > 0) {
1148 if (H5Pset_deflate(plist, cmprs) < 0) {
1153 if (H5Pset_filter(plist, H5PY_FILTER_LZF, H5Z_FLAG_OPTIONAL, 0, NULL) < 0) {
1160 gplist = H5Pcreate(H5P_LINK_CREATE);
1162 if (H5Pset_create_intermediate_group(gplist, 1) < 0) {
1163 printMessage(tr(
"Failed to set create intermediate groups"));
1166 if (get_Normalization()) {
1167 dsetId = H5Dcreate(fileId,
1168 qPrintable(get_DataSetName()),
1175 dsetId = H5Dcreate(fileId,
1176 qPrintable(get_DataSetName()+
"/v"),
1187 printMessage(tr(
"Could not create or find dataset %1").arg(get_DataSetName()));
1189 }
else if (!get_Normalization()) {
1191 dspc2Id = H5Dget_space(dset2Id);
1194 printMessage(
"Couldn't get dataspace of existing 'N' dataset");
1198 int ndims = H5Sget_simple_extent_ndims(dspc2Id);
1204 int ndims2 = H5Sget_simple_extent_dims(dspc2Id, dims, NULL);
1213 printMessage(
"'N' Dataspace dimensions do not match output data");
1225 dspc2Id = H5Screate_simple(3, dims, NULL);
1228 int cmprs = get_Compression();
1230 plist2 = H5Pcreate(H5P_DATASET_CREATE);
1241 if (H5Pset_chunk(plist2, 3, c) < 0) {
1244 }
else if (H5Pset_fill_value(plist2, H5T_NATIVE_FLOAT, &zero)) {
1247 }
else if (cmprs > 0) {
1248 if (H5Pset_deflate(plist2, cmprs) < 0) {
1253 if (H5Pset_filter(plist2, H5PY_FILTER_LZF, H5Z_FLAG_OPTIONAL, 0, NULL) < 0) {
1260 gplist2 = H5Pcreate(H5P_LINK_CREATE);
1262 if (H5Pset_create_intermediate_group(gplist2, 1) < 0) {
1263 printMessage(tr(
"Failed to set create intermediate groups"));
1266 dset2Id = H5Dcreate(fileId,
1267 qPrintable(get_DataSetName()+
"/n"),
1278 if (plist >= 0) H5Pclose(plist);
1279 if (gplist >= 0) H5Pclose(gplist);
1280 if (plist2 >= 0) H5Pclose(plist2);
1281 if (gplist2 >= 0) H5Pclose(gplist2);
1284 if (dspcId >= 0) H5Sclose(dspcId);
1285 if (dsetId >= 0) H5Dclose(dsetId);
1286 if (dspc2Id >= 0) H5Sclose(dspc2Id);
1287 if (dset2Id >= 0) H5Dclose(dset2Id);
1288 if (fileId >= 0) H5Fclose(fileId);
1290 if (fileId < 0 || dsetId < 0 || dspcId < 0) {
1291 printMessage(tr(
"Error in CctwChunkedData::openOutputFile fileId=%1, dsetId=%2, dspcId=%3")
1292 .arg(fileId).arg(dsetId).arg(dspcId));
1295 if (!get_Normalization() && (dset2Id < 0 || dspc2Id < 0)) {
1296 printMessage(tr(
"Error in CctwChunkedData::openOutputFile fileId=%1, dset2Id=%2, dspc2Id=%3")
1297 .arg(fileId).arg(dset2Id).arg(dspc2Id));
1306 printMessage(tr(
"Opened output file \"%1\" OK, DS \"%2\", Norm %3, DSID %4, DS2ID %5, CMPRS %6")
1307 .arg(get_DataFileName()).arg(get_DataSetName())
1309 .arg(get_Compression()));
1313 printMessage(tr(
"Output dimensions %1, HDF Chunk size %2, Output chunk size %3, Output chunk count %4")
1314 .arg(get_Dimensions().toString())
1316 .arg(get_ChunkSize().toString())
1317 .arg(get_ChunkCount().toString()));
1371 herr_t (*old_func)(hid_t,
void*);
1372 void *old_client_data;
1373 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
1376 H5Eset_auto(H5E_DEFAULT, NULL, NULL);
1382 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
1389 bool sameFile =
false;
1397 QString fileName = get_MaskDataFileName();
1399 QString inputFile = get_DataFileName();
1401 if (dataSetName.length()==0) {
1402 printMessage(tr(
"No dataset name given for mask file, skipping"));
1407 printMessage(tr(
"About to open mask input file: %1 dataset: %2")
1408 .arg(fileName).arg(dataSetName));
1411 QFileInfo f(fileName);
1419 if (fileName.length() > 0) {
1421 throw tr(
"Mask file %1 does not exist").arg(fileName);
1422 if (H5Fis_hdf5(qPrintable(fileName)) <= 0)
1423 throw tr(
"Mask file %1 exists but is not an hdf file").arg(fileName);
1426 if (fileName.length() == 0) {
1430 }
else if (fileName == inputFile) {
1435 fileId = H5Fopen(qPrintable(fileName), H5F_ACC_RDWR, H5P_DEFAULT);
1439 throw tr(
"Mask file %1 could not be opened").arg(fileName);
1441 dsetId = H5Dopen(fileId, qPrintable(dataSetName), H5P_DEFAULT);
1443 throw tr(
"Could not open mask dataset!");
1445 dspcId = H5Dget_space(dsetId);
1447 throw tr(
"Could not get dataspace of existing mask dataset");
1450 int ndims = H5Sget_simple_extent_ndims(dspcId);
1452 throw tr(
"Mask dataspace is not 2-dimensional");
1454 int ndims2 = H5Sget_simple_extent_dims(dspcId, dims, NULL);
1456 throw tr(
"Could not get mask dataspace dimensions");
1469 catch (QString &msg )
1472 printMessage(tr(
"Error in CctwChunkedData::openMaskFile fileId=%1, dsetId=%2, dspcId=%3")
1473 .arg(fileId).arg(dsetId).arg(dspcId));
1477 if (dspcId >= 0) H5Sclose(dspcId);
1478 if (dsetId >= 0) H5Dclose(dsetId);
1479 if ((fileId >= 0) && (sameFile ==
false)) H5Fclose(fileId);
1505 if (qcepDebug(DEBUG_APP)) {
1521 hid_t memspace_id = -1;
1522 hsize_t offset[2], count[2], stride[2], block[2];
1524 QcepIntVector a= get_Mask();
1529 count[0] = get_Dimensions().y();
1530 count[1] = get_Dimensions().x();
1538 int *msk = a.data();
1540 memspace_id = H5Screate_simple(2, count, NULL);
1541 herr_t selerr = H5Sselect_hyperslab(
m_MaskDataspaceId, H5S_SELECT_SET, offset, stride, count, block);
1549 if (selerr || rderr) {
1550 printMessage(tr(
"Error reading mask, selerr = %1, rderr = %2").arg(selerr).arg(rderr));
1556 for (
int i=0; i<a.size(); i++) {
1562 printMessage(tr(
"Mask has %1 of %2 bits set").arg(sum).arg(a.size()));
1568 H5Sclose(memspace_id);
1576 if (qcepDebug(DEBUG_APP)) {
1577 printMessage(tr(
"CctwChunkedData::readMaskFile returns %1").arg(res));
1586 herr_t (*old_func)(hid_t,
void*);
1587 void *old_client_data;
1588 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
1591 H5Eset_auto(H5E_DEFAULT, NULL, NULL);
1597 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
1604 bool sameFile =
false;
1612 QString fileName = get_AnglesDataFileName();
1614 QString inputFile = get_DataFileName();
1616 if (dataSetName.length()==0) {
1617 printMessage(tr(
"No dataset name given for angles file, skipping"));
1622 printMessage(tr(
"About to open angles input file: %1 dataset: %2")
1623 .arg(fileName).arg(dataSetName));
1626 QFileInfo f(fileName);
1634 if (fileName.length() > 0) {
1636 throw tr(
"Angles file %1 does not exist").arg(fileName);
1637 if (H5Fis_hdf5(qPrintable(fileName)) <= 0)
1638 throw tr(
"Angles file %1 exists but is not an hdf file").arg(fileName);
1641 if (fileName.length() == 0) {
1644 }
else if (fileName == inputFile) {
1648 fileId = H5Fopen(qPrintable(fileName), H5F_ACC_RDWR, H5P_DEFAULT);
1652 throw tr(
"Angles file %1 could not be opened").arg(fileName);
1654 dsetId = H5Dopen(fileId, qPrintable(dataSetName), H5P_DEFAULT);
1656 throw tr(
"Could not open angles dataset!");
1658 dspcId = H5Dget_space(dsetId);
1660 throw tr(
"Could not get dataspace of existing angles dataset");
1663 int ndims = H5Sget_simple_extent_ndims(dspcId);
1665 throw tr(
"Angles Dataspace is not 1-dimensional");
1667 int ndims2 = H5Sget_simple_extent_dims(dspcId, dims, NULL);
1669 throw tr(
"Could not get angles dataspace dimensions");
1682 catch (QString &msg )
1685 printMessage(tr(
"Error in CctwChunkedData::openAnglesFile fileId=%1, dsetId=%2, dspcId=%3")
1686 .arg(fileId).arg(dsetId).arg(dspcId));
1690 if (dspcId >= 0) H5Sclose(dspcId);
1691 if (dsetId >= 0) H5Dclose(dsetId);
1692 if ((fileId >= 0) && (sameFile ==
false)) H5Fclose(fileId);
1718 if (qcepDebug(DEBUG_APP)) {
1734 hid_t memspace_id = -1;
1735 hsize_t offset[1], count[1], stride[1], block[1];
1737 QcepDoubleVector a= get_Angles();
1740 count[0] = a.size();
1744 double *
angles = a.data();
1746 memspace_id = H5Screate_simple(1, count, NULL);
1747 herr_t selerr = H5Sselect_hyperslab(
m_AnglesDataspaceId, H5S_SELECT_SET, offset, stride, count, block);
1755 if (selerr || rderr) {
1756 printMessage(tr(
"Error reading angles, selerr = %1, rderr = %2").arg(selerr).arg(rderr));
1763 H5Sclose(memspace_id);
1771 if (qcepDebug(DEBUG_APP)) {
1772 printMessage(tr(
"CctwChunkedData::readAnglesFile returns %1").arg(res));
1781 herr_t (*old_func)(hid_t,
void*);
1782 void *old_client_data;
1783 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
1786 H5Eset_auto(H5E_DEFAULT, NULL, NULL);
1792 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
1799 bool sameFile =
false;
1807 QString fileName = get_WeightsDataFileName();
1809 QString inputFile = get_DataFileName();
1811 if (dataSetName.length()==0) {
1812 printMessage(tr(
"No dataset name given for weights file, skipping"));
1817 printMessage(tr(
"About to open Weights input file: %1 dataset: %2")
1818 .arg(fileName).arg(dataSetName));
1821 QFileInfo f(fileName);
1829 if (fileName.length() > 0) {
1831 throw tr(
"Weights File %1 does not exist").arg(fileName);
1832 if (H5Fis_hdf5(qPrintable(fileName)) <= 0)
1833 throw tr(
"Weights File %1 exists but is not an hdf file").arg(fileName);
1836 if (fileName.length() == 0) {
1839 }
else if (fileName == inputFile) {
1843 fileId = H5Fopen(qPrintable(fileName), H5F_ACC_RDWR, H5P_DEFAULT);
1847 throw tr(
"Weights File %1 could not be opened").arg(fileName);
1849 dsetId = H5Dopen(fileId, qPrintable(dataSetName), H5P_DEFAULT);
1851 throw tr(
"Could not open weights dataset!");
1853 dspcId = H5Dget_space(dsetId);
1855 throw tr(
"Could not get dataspace of existing weights dataset");
1858 int ndims = H5Sget_simple_extent_ndims(dspcId);
1860 throw tr(
"Weights Dataspace is not 1-dimensional");
1862 int ndims2 = H5Sget_simple_extent_dims(dspcId, dims, NULL);
1864 throw tr(
"Could not get weights dataspace dimensions");
1877 catch (QString &msg )
1880 printMessage(tr(
"Error in CctwChunkedData::openWeightsFile fileId=%1, dsetId=%2, dspcId=%3")
1881 .arg(fileId).arg(dsetId).arg(dspcId));
1885 if (dspcId >= 0) H5Sclose(dspcId);
1886 if (dsetId >= 0) H5Dclose(dsetId);
1887 if ((fileId >= 0) && (sameFile ==
false)) H5Fclose(fileId);
1913 if (qcepDebug(DEBUG_APP)) {
1929 hid_t memspace_id = -1;
1930 hsize_t offset[1], count[1], stride[1], block[1];
1932 QcepDoubleVector a= get_Weights();
1935 count[0] = a.size();
1939 double *Weights = a.data();
1941 memspace_id = H5Screate_simple(1, count, NULL);
1942 herr_t selerr = H5Sselect_hyperslab(
m_WeightsDataspaceId, H5S_SELECT_SET, offset, stride, count, block);
1950 if (selerr || rderr) {
1951 printMessage(tr(
"Error reading Weights, selerr = %1, rderr = %2").arg(selerr).arg(rderr));
1958 H5Sclose(memspace_id);
1966 if (qcepDebug(DEBUG_APP)) {
1967 printMessage(tr(
"CctwChunkedData::readWeightsFile returns %1").arg(res));
2013 prop_ChunksRead()->incValue(1);
2021 hid_t memspace_id = -1;
2022 hsize_t offset[3], count[3], stride[3], block[3];
2055 if (chunkData == NULL) {
2056 printMessage(tr(
"Anomaly reading chunk %1, data == NULL").arg(n));
2058 memspace_id = H5Screate_simple(3, count, NULL);
2059 herr_t selerr = H5Sselect_hyperslab(
m_DataspaceId, H5S_SELECT_SET, offset, stride, count, block);
2065 if (selerr || rderr) {
2066 printMessage(tr(
"Error reading chunk %1, selerr = %2, rderr = %3")
2073 herr_t selerr = H5Sselect_hyperslab(
m_Dataspace2Id, H5S_SELECT_SET, offset, stride, count, block);
2080 if (selerr || rderr) {
2081 printMessage(tr(
"Error reading weight chunk %1, selerr = %2, rderr = %3")
2088 H5Sclose(memspace_id);
2092 if (weightData && chunkData) {
2095 for (
int i=0; i<s; i++) {
2096 if (chunkData[i] == chunkData[i]) {
2125 if (get_Normalization()) {
2131 hsize_t offset[3], count[3], stride[3], block[3];
2165 if (chunkData == NULL) {
2168 hid_t memspace_id = -1;
2169 memspace_id = H5Screate_simple(3, count, NULL);
2170 herr_t selerr = H5Sselect_hyperslab(
m_DataspaceId, H5S_SELECT_SET, offset, stride, count, block);
2173 if (selerr || wrterr) {
2174 printMessage(tr(
"Error writing chunk %1, selerr = %2, wrterr = %3")
2182 herr_t selerr = H5Sselect_hyperslab(
m_Dataspace2Id, H5S_SELECT_SET, offset, stride, count, block);
2185 if (selerr || wrterr) {
2186 printMessage(tr(
"Error writing chunk %1, selerr = %2, wrterr = %3")
2192 H5Sclose(memspace_id);
2246 prop_ChunksRead()->incValue(n);
2251 prop_ChunksWritten()->incValue(n);
2256 prop_ChunksHeld()->incValue(n);
2258 if (get_ChunksHeld() > get_ChunksHeldMax()) {
2259 set_ChunksHeldMax(get_ChunksHeld());
void incChunksHeld(int n)
bool beginTransform(bool isInput, int transformOptions)
void onMaskFileNameChanged()
virtual void setMaskDataset(QString desc)
virtual void setWeightsSource(QString desc)
void onDataFileNameChanged()
bool openInputNeXusFile()
CctwIntVector3D chunkIndexFromNumber(int n)
static QString addSlashes(QString str)
virtual void setAnglesSource(QString desc)
CctwIntVector3D chunkStart(int n)
void releaseChunkData(int n)
virtual void setWeightsDataset(QString desc)
CctwDataChunk * chunk(int n)
bool containsChunk(int ix, int iy, int iz)
void setMaskDimensions(int mx, int my)
void addDependency(int f, int t)
CctwIntVector3D m_DimensionsCache
void setDimensions(CctwIntVector3D dim)
virtual void setChunks(QString desc)
bool openInputFile(bool quietly=false)
CctwIntVector3D chunkSize() const
virtual void setDataset(QString desc)
void setWeightsDimensions(int n)
bool openMaskFile(bool quietly=false)
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
void mergeChunk(CctwDataChunk *chunk)
void setAnglesDimensions(int n)
#define CCTW_H5T_INTERNAL_TYPE
virtual void setDataSource(QString desc)
CctwIntVector3D m_ChunkCountCache
virtual void setDims(QString desc)
void normalizeChunk(int n)
CctwIntVector3D dimensions() const
static int allocatedChunkCount()
int chunkContaining(CctwIntVector3D pixelCoord)
CctwChunkedData(CctwApplication *application, CctwIntVector3D dim, CctwIntVector3D chunkSize, bool isInput, QString name, QObject *parent)
int allocatedChunkCount()
void setChunkSize(CctwIntVector3D cksz)
CctwChunkedData::MergeDataType * weightsPointer()
CctwIntVector3D chunkCount() const
void closeInputNeXusFile()
void incChunksRead(int n)
bool openWeightsFile(bool quietly=false)
QVector< CctwDataChunk * > m_DataChunks
bool containsPixel(CctwIntVector3D pixelCoord)
CctwVector3D< int > CctwIntVector3D
hid_t m_WeightsDataspaceId
bool openAnglesFile(bool quietly=false)
hid_t m_AnglesDataspaceId
void clearMergeCounters()
CctwIntVector3D hdfChunkSize
CctwChunkedData::MergeDataType * dataPointer()
CctwIntVector3D m_ChunkSizeCache
void incChunksWritten(int n)
void setWeight(int n, double v)
static QMutex m_FileAccessMutex
QcepSettingsSaverWPtr saver() const
void setAngle(int n, double v)
CctwApplication * m_Application
virtual void setMaskSource(QString desc)
int chunkNumberFromIndex(CctwIntVector3D chunkIdx)
virtual void setAnglesDataset(QString desc)
CctwVector3D< double > CctwDoubleVector3D
CctwDataChunk * readChunk(int n)