...
 
Commits (5)
......@@ -858,18 +858,6 @@ class HDF5BaseReader
DataSpaceParameters getBlockSpaceParameters(final long dataSetId, final int[] memoryOffset,
final int[] memoryDimensions, final long[] offset, final int[] blockDimensions,
ICleanUpRegistry registry)
{
return tryGetBlockSpaceParameters(dataSetId, memoryOffset, memoryDimensions, offset,
blockDimensions, false, registry);
}
/**
* Returns the {@link DataSpaceParameters} for a block of the given <var>dataSetId</var> when
* they are mapped to a block in memory.
*/
DataSpaceParameters tryGetBlockSpaceParameters(final long dataSetId, final int[] memoryOffset,
final int[] memoryDimensions, final long[] offset, final int[] blockDimensions,
final boolean nullWhenOutside, ICleanUpRegistry registry)
{
assert memoryOffset != null;
assert memoryDimensions != null;
......@@ -896,19 +884,11 @@ class HDF5BaseReader
final long maxFileBlockSize = dimensions[i] - offset[i];
if (maxFileBlockSize <= 0)
{
if (nullWhenOutside)
{
return null;
}
throw new HDF5JavaException("Offset " + offset[i] + " >= Size " + dimensions[i]);
}
final long maxMemoryBlockSize = memoryDimensions[i] - memoryOffset[i];
if (maxMemoryBlockSize <= 0)
{
if (nullWhenOutside)
{
return null;
}
throw new HDF5JavaException("Memory offset " + memoryOffset[i] + " >= Size "
+ memoryDimensions[i]);
}
......@@ -930,18 +910,6 @@ class HDF5BaseReader
*/
DataSpaceParameters getBlockSpaceParameters(final HDF5DataSet dataSet, final int[] memoryOffset,
final int[] memoryDimensions, final long[] offset, final int[] blockDimensions)
{
return tryGetBlockSpaceParameters(dataSet, memoryOffset, memoryDimensions, offset,
blockDimensions, false);
}
/**
* Returns the {@link DataSpaceParameters} for a block of the given <var>dataSet</var> when
* they are mapped to a block in memory.
*/
DataSpaceParameters tryGetBlockSpaceParameters(final HDF5DataSet dataSet, final int[] memoryOffset,
final int[] memoryDimensions, final long[] offset, final int[] blockDimensions,
final boolean nullWhenOutside)
{
assert dataSet != null;
assert memoryOffset != null;
......@@ -957,7 +925,7 @@ class HDF5BaseReader
final long[] effectiveBlockDimensions;
dataSpaceId = dataSet.getDataSpaceId();
final long[] dimensions = h5.getDataSpaceDimensions(dataSpaceId);
final long[] dimensions = dataSet.getDimensions();
if (dimensions.length != blockDimensions.length)
{
throw new HDF5JavaException("Data Set is expected to be of rank "
......@@ -969,19 +937,11 @@ class HDF5BaseReader
final long maxFileBlockSize = dimensions[i] - offset[i];
if (maxFileBlockSize <= 0)
{
if (nullWhenOutside)
{
return null;
}
throw new HDF5JavaException("Offset " + offset[i] + " >= Size " + dimensions[i]);
}
final long maxMemoryBlockSize = memoryDimensions[i] - memoryOffset[i];
if (maxMemoryBlockSize <= 0)
{
if (nullWhenOutside)
{
return null;
}
throw new HDF5JavaException("Memory offset " + memoryOffset[i] + " >= Size "
+ memoryDimensions[i]);
}
......
......@@ -211,7 +211,7 @@ final class HDF5BaseWriter extends HDF5BaseReader
{
throw new HDF5FileNotFoundException(hdf5File, "File is not writable.");
}
if (mdcGenerateImage == MDCImageGeneration.KEEP_MDC_IMAGE)
if (hdf5File.length() > 0 && mdcGenerateImage == MDCImageGeneration.KEEP_MDC_IMAGE)
{
generateMDCImage = HDF5Factory.hasMDCImage(hdf5File);
}
......
......@@ -622,34 +622,11 @@ class HDF5ByteReader implements IHDF5ByteReader
@Override
public MDByteArray readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
/*
* Copyright 2015 ETH Zuerich, SIS
* Copyright 2007 - 2018 ETH Zuerich, SIS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
......@@ -622,34 +622,11 @@ class HDF5DoubleReader implements IHDF5DoubleReader
@Override
public MDDoubleArray readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
......@@ -622,34 +622,11 @@ class HDF5FloatReader implements IHDF5FloatReader
@Override
public MDFloatArray readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
......@@ -622,34 +622,11 @@ class HDF5IntReader implements IHDF5IntReader
@Override
public MDIntArray readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
......@@ -622,34 +622,11 @@ class HDF5LongReader implements IHDF5LongReader
@Override
public MDLongArray readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
......@@ -622,34 +622,11 @@ class HDF5ShortReader implements IHDF5ShortReader
@Override
public MDShortArray readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
......@@ -622,34 +622,11 @@ class HDF5UnsignedByteReader implements IHDF5ByteReader
@Override
public MDByteArray readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
......@@ -622,34 +622,11 @@ class HDF5UnsignedIntReader implements IHDF5IntReader
@Override
public MDIntArray readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
......@@ -622,34 +622,11 @@ class HDF5UnsignedLongReader implements IHDF5LongReader
@Override
public MDLongArray readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
......@@ -622,34 +622,11 @@ class HDF5UnsignedShortReader implements IHDF5ShortReader
@Override
public MDShortArray readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
......@@ -16,9 +16,10 @@
package ch.systemsx.cisd.hdf5;
import static ch.systemsx.cisd.hdf5.HDF5ArrayBlockParamsBuilder.*;
import static ch.systemsx.cisd.hdf5.MatrixUtils.dims;
import static ch.systemsx.cisd.hdf5.MatrixUtils.ldims;
import static ch.systemsx.cisd.hdf5.HDF5ArrayBlockParamsBuilder.array;
import static ch.systemsx.cisd.hdf5.HDF5ArrayBlockParamsBuilder.block;
import static ch.systemsx.cisd.hdf5.HDF5ArrayBlockParamsBuilder.blockIndex;
import static ch.systemsx.cisd.hdf5.HDF5ArrayBlockParamsBuilder.slice;
import static ch.systemsx.cisd.hdf5.HDF5CompoundMemberMapping.mapping;
import static ch.systemsx.cisd.hdf5.HDF5FloatStorageFeatures.FLOAT_CHUNKED;
import static ch.systemsx.cisd.hdf5.HDF5FloatStorageFeatures.FLOAT_DEFLATE;
......@@ -30,6 +31,8 @@ import static ch.systemsx.cisd.hdf5.HDF5IntStorageFeatures.INT_AUTO_SCALING_DEFL
import static ch.systemsx.cisd.hdf5.HDF5IntStorageFeatures.INT_CHUNKED;
import static ch.systemsx.cisd.hdf5.HDF5IntStorageFeatures.INT_DEFLATE;
import static ch.systemsx.cisd.hdf5.HDF5IntStorageFeatures.INT_SHUFFLE_DEFLATE;
import static ch.systemsx.cisd.hdf5.MatrixUtils.dims;
import static ch.systemsx.cisd.hdf5.MatrixUtils.ldims;
import static ch.systemsx.cisd.hdf5.UnsignedIntUtils.toInt32;
import static ch.systemsx.cisd.hdf5.UnsignedIntUtils.toInt8;
import static hdf.hdf5lib.HDF5Constants.H5T_ENUM;
......@@ -44,6 +47,7 @@ import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;
......@@ -147,6 +151,7 @@ public class HDF5RoundtripTest
+ libversion[2]);
// Tests
test.testWriteToEmptyFile();
test.testStrangeDataSetName();
test.testCreateSomeDeepGroup();
test.testGetGroupMembersIteratively();
......@@ -488,6 +493,26 @@ public class HDF5RoundtripTest
test.finalizeTest();
}
@Test
public void testWriteToEmptyFile()
{
final File file = new File(workingDirectory, "testStrangeDataSetName.h5");
file.delete();
assertFalse(file.exists());
try
{
new FileOutputStream(file).close();
} catch (IOException e)
{
fail("Cannot touch file" + file.getAbsolutePath());
}
file.deleteOnExit();
final IHDF5Writer writer = HDF5Factory.configure(file).writer();
writer.writeString("a", "b");
assertEquals("b", writer.readString("a"));
writer.close();
}
@Test
public void testStrangeDataSetName()
{
......@@ -754,6 +779,12 @@ public class HDF5RoundtripTest
final MDFloatArray slice2 = new MDFloatArray(new float[]
{ 12f, 16f }, new int[]
{ 2 });
final IndexMap boundIndex3 = new IndexMap().bind(2, 3).bind(0, 1).bind(1, 0);
final long[] boundIndex3Arr = new long[]
{ 1, 0, 3 };
final MDFloatArray slice3 = new MDFloatArray(new float[]
{ 12f }, new int[]
{ 1 });
assertEquals(slice1, reader.float32().readMDArraySlice(floatDatasetName, boundIndex1));
assertEquals(slice1, reader.float32().readMDArray(floatDatasetName, slice(boundIndex1)));
assertEquals(slice1, reader.float32().readMDArraySlice(floatDatasetName, boundIndex1Arr));
......@@ -816,6 +847,10 @@ public class HDF5RoundtripTest
assertEquals(slice2, reader.float32().readMDArray(floatDatasetName, slice(boundIndex2)));
assertEquals(slice2, reader.float32().readMDArraySlice(floatDatasetName, boundIndex2Arr));
assertEquals(slice2, reader.float32().readMDArray(floatDatasetName, slice(boundIndex2Arr)));
assertEquals(slice3, reader.float32().readMDArraySlice(floatDatasetName, boundIndex3));
assertEquals(slice3, reader.float32().readMDArray(floatDatasetName, slice(boundIndex3)));
assertEquals(slice3, reader.float32().readMDArraySlice(floatDatasetName, boundIndex3Arr));
assertEquals(slice3, reader.float32().readMDArray(floatDatasetName, slice(boundIndex3Arr)));
reader.close();
}
......
......@@ -622,34 +622,11 @@ class HDF5__Name__Reader implements IHDF5__Name__Reader
@Override
public MD__Name__Array readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......
......@@ -622,34 +622,11 @@ class HDF5Unsigned__Name__Reader implements IHDF5__Name__Reader
@Override
public MD__Name__Array readMDArray(String objectPath, HDF5ArrayBlockParams params)
{
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexArray());
} else
{
return readSlicedMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset(), params.getBoundIndexMap());
}
}
return readMDArrayBlockWithOffset(objectPath, params.getBlockDimensions(), params.getOffset());
}
if (params.hasSlice())
baseReader.checkOpen();
try (final HDF5DataSet dataSet = baseReader.openDataSet(objectPath))
{
if (params.getBoundIndexArray() != null)
{
return readMDArraySlice(objectPath, params.getBoundIndexArray());
} else
{
return readMDArraySlice(objectPath, params.getBoundIndexMap());
}
return readMDArray(dataSet, params);
}
return readMDArray(objectPath);
}
@Override
......