Skip to content
Snippets Groups Projects
Commit 83a482ef authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

The choice of allowing unsafe reading is not done in prepareForReading, but later.

parent 1372ef88
No related branches found
No related tags found
No related merge requests found
......@@ -212,18 +212,21 @@ public abstract class StackedData extends ReferencedData {
/**
* Prepares everything necessary before data reading and returns the number of data that can be
* read in a block. The reading process can be done on a single thread only or on a multiple threads
* read in a block. The reading process can be done on a single thread only or on a multiple threads.
* <p>
* Don't forget to call {@link #setUnsafeReadingEnabled(boolean)}, in order to say whether reading will be done in a
* single or in multiple thread(s).
* </p>
*
* @return The number of data that can be read in a block.
*/
public int prepareForReading(boolean isSingleReadThreadOnly) {
public int prepareForReading() {
int dataPerBlock = 1;
ICDMAReader reader = getReader();
if (reader != null) {
IDataItem item = reader.getDataItem(contextDataItem);
if (item != null) {
try {
dataPerBlock = item.prepareForReading(getDataRank(), isSingleReadThreadOnly);
dataPerBlock = item.prepareForReading(getDataRank());
} catch (DataAccessException e) {
Factory.getLogger().error("Failed to prepare " + getDataName() + " for multiple reading", e);
}
......@@ -232,4 +235,42 @@ public abstract class StackedData extends ReferencedData {
return dataPerBlock;
}
/**
* Returns whether unsafe reading is enabled.
*
* @return Whether unsafe reading is enabled.
*/
public boolean isUnsafeReadingEnabled() {
boolean unsafeReadingEnabled = false;
ICDMAReader reader = getReader();
if (reader != null) {
IDataItem item = reader.getDataItem(contextDataItem);
if (item != null) {
unsafeReadingEnabled = item.isUnsafeReadingEnabled();
}
}
return unsafeReadingEnabled;
}
/**
* Sets whether the reading process can be unsafe (i.e. no thread safe).
* <p>
* Unsafe reading might be more efficient than safe reading, at the cost of thread safety.
* </p>
* <p>
* Typically, if you read data in a single thread, you can use unsafe reading.
* </p>
*
* @param unsafeReadingEnabled Whether the reading process can be unsafe.
*/
public void setUnsafeReadingEnabled(boolean unsafeReadingEnabled) {
ICDMAReader reader = getReader();
if (reader != null) {
IDataItem item = reader.getDataItem(contextDataItem);
if (item != null) {
item.setUnsafeReadingEnabled(unsafeReadingEnabled);
}
}
}
}
......@@ -442,51 +442,80 @@ public class ScanData {
// }
/**
* Prepares everything necessary before threaded multiple images reading and returns the number of images that can
* Prepares everything necessary before multiple images reading and returns the number of images that can
* be read in a block.
*
* @return The number of images that can be read in a block.
*/
public int prepareImageStackForMultipleReading() {
return images == null ? 0 : images.prepareForReading(false);
public int prepareImageStackForReading() {
return images == null ? 0 : images.prepareForReading();
}
/**
* Prepares everything necessary before reading images on a single thread and returns the number of images
* that can be read in a block.
* Prepares everything necessary before threaded spectra reading and returns the number of spectra that
* can be read in a block.
*
* @return The number of images that can be read in a block.
* @return The number of spectrums that can be read in a block.
*/
public int prepareImageStackForSingleThreadReading() {
return images == null ? 0 : images.prepareForReading(true);
public int prepareSpectrumStackForReading() {
return spectrumStack == null ? 0 : spectrumStack.prepareForReading();
}
/**
* Prepares everything necessary before threaded multiple spectrums reading and returns the number of spectrums that
* can be read in a block.
* Finalizes what has to be finalized after multiple images reading.
*/
public void finalizeImageStackAfterReading() {
if (images != null) {
images.finalizeReading();
}
}
/**
* Finalizes what has to be finalized after multiple spectra reading.
*/
public void finalizeSpectrumStackAfterReading() {
if (spectrumStack != null) {
spectrumStack.finalizeReading();
}
}
/**
* Returns whether unsafe (i.e. not thread safe) image reading is enabled.
*
* @return The number of spectrums that can be read in a block.
* @return A <code>boolean</code>.
*/
public int prepareSpectrumStackFoMultipleReading() {
return spectrumStack == null ? 0 : spectrumStack.prepareForReading(false);
public boolean isUnsafeImageReadingEnabled() {
return images == null ? false : images.isUnsafeReadingEnabled();
}
/**
* Prepares everything necessary before reading spectrums on a single thread and returns the number of spectrums
* that can be read in a block.
* Returns whether unsafe (i.e. not thread safe) spectrum reading is enabled.
*
* @return The number of spectrums that can be read in a block.
* @return A <code>boolean</code>.
*/
public int prepareSpectrumStackForSingleThreadReading() {
return spectrumStack == null ? 0 : spectrumStack.prepareForReading(true);
public boolean isUnsafeSpectrumReadingEnabled() {
return spectrumStack == null ? false : spectrumStack.isUnsafeReadingEnabled();
}
/**
* Finalizes what has to be finalized after threaded multiple images reading
* Sets whether unsafe (i.e. not thread safe) image reading should be enabled.
*
* @param unsafeReadingEnabled Whether unsafe image reading should be enabled.
*/
public void finalizeImageStackAfterMultipleReading() {
public void setUnsafeImageReadingEnabled(boolean unsafeReadingEnabled) {
if (images != null) {
images.finalizeReading();
images.setUnsafeReadingEnabled(unsafeReadingEnabled);
}
}
/**
* Sets whether unsafe (i.e. not thread safe) spectrum reading should be enabled.
*
* @param unsafeReadingEnabled Whether unsafe spectrum reading should be enabled.
*/
public void setUnsafeSpectrumReadingEnabled(boolean unsafeReadingEnabled) {
if (spectrumStack != null) {
spectrumStack.setUnsafeReadingEnabled(unsafeReadingEnabled);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment