Skip to content

Commit

Permalink
Merge pull request micro-manager#1956 from nicost/metaDataWriter
Browse files Browse the repository at this point in the history
MultipageTiff writer: warn against killing MM while filesets are being closed.
  • Loading branch information
nicost authored May 29, 2024
2 parents db17f0a + 72fb2b4 commit e8c7e7c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.micromanager.data.internal.multipagetiff;

import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
Expand All @@ -38,6 +39,7 @@
import org.micromanager.data.internal.DefaultMetadata;
import org.micromanager.data.internal.DefaultSummaryMetadata;
import org.micromanager.internal.propertymap.NonPropertyMapJSONFormats;
import org.micromanager.internal.utils.ProgressBar;
import org.micromanager.internal.utils.ReportingUtils;


Expand Down Expand Up @@ -112,9 +114,20 @@ public void finished(String omeXML, String ijDescription) throws IOException {
// only need to finish last one here because previous ones in set are finished
// as they fill up with images
tiffWriters_.getLast().finish();
// close all
// close all, this can be time-consuming ,so use a ProgressBar
ProgressBar pb = null;
if (!GraphicsEnvironment.isHeadless() && tiffWriters_.size() > 4) {
pb = new ProgressBar(null, "Closing files", 0, tiffWriters_.size());
}
int count = 0;
for (MultipageTiffWriter w : tiffWriters_) {
w.close(omeXML, ijDescription);
if (pb != null) {
pb.setProgress(count++);
}
}
if (pb != null) {
pb.setVisible(false);
}
omeMetadata_ = null;
masterStorage_ = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ private void openExistingDataSet() {
MultipageTiffReader reader = null;
File dir = new File(directory_);

ProgressBar tmpProgressBar = null;
// Allow operation in headless mode.
File[] listFiles = dir.listFiles();
ProgressBar progressBar = null;
Expand All @@ -254,7 +253,7 @@ private void openExistingDataSet() {
if (listFiles != null) {
for (File f : listFiles) {
// Heuristics to only read tiff files, and not files created by the
// OS (starting with ".")
// OS (starting with "._")
String fileName = f.getName();
if (fileName.endsWith(".tif") || fileName.endsWith(".TIF")) {
if (!fileName.startsWith("._")) {
Expand Down Expand Up @@ -484,14 +483,14 @@ public synchronized void finished() {
}
ProgressBar progressBar = null;
if (!GraphicsEnvironment.isHeadless()) {
// progressBar = new ProgressBar(parent_, "Finishing Files", 0,
// positionToFileSet_.size());
progressBar = new ProgressBar(parent_,
"Important: do not close Micro-Manager until files are finished writing.",
0, positionToFileSet_.size());
}
try {
int count = 0;
if (progressBar != null) {
progressBar.setProgress(count);
progressBar.setVisible(true);
}
for (FileSet p : positionToFileSet_.values()) {
p.finishAbortedAcqIfNeeded();
Expand Down Expand Up @@ -525,10 +524,6 @@ public synchronized void finished() {
filename = p.getCurrentFilename();
p.finished(fullOMEXMLMetadata, ijDescription);
master = p;
count++;
if (progressBar != null) {
progressBar.setProgress(count);
}
break;
}
}
Expand Down Expand Up @@ -557,10 +552,10 @@ public synchronized void finished() {
progressBar.setProgress(count);
}
}
//shut down writing executor--pause here until all tasks have finished
//writing so that no attempt is made to close the dataset (and thus
//the FileChannel) before everything has finished writing mkae sure
//all images have finished writing if they are on seperate thread
// shut down writing executor--pause here until all tasks have finished
// writing so that no attempt is made to close the dataset (and thus
// the FileChannel) before everything has finished writing make sure
// all images have finished writing if they are on separate thread
if (writingExecutor_ != null && !writingExecutor_.isShutdown()) {
writingExecutor_.shutdown();
try {
Expand All @@ -580,7 +575,8 @@ public synchronized void finished() {
ReportingUtils.logError(ex);
} finally {
if (progressBar != null) {
progressBar.setVisible(false);
final ProgressBar pb = progressBar;
SwingUtilities.invokeLater(() -> pb.setVisible(false));
}
// release resources
omeMetadata_ = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
/**
* Utility class to show a ProgressBar.
* Construction of the ProgressBar is done on the EDT, on the first call of
* SetProgress. Thus, it is safe to call this class from any thread, with the
* possible exception of a call to setVisible(false) from a non-EDT thread.
* SetProgress. Thus, it is safe to call this class from any thread.
*/
public final class ProgressBar extends JPanel {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -122,7 +121,12 @@ public void setVisible(boolean visible) {
});
return;
}
frame_.setVisible(visible);
if (visible && frame_ == null) {
initialize();
}
if (frame_ != null) {
frame_.setVisible(visible);
}
}

public void setRange(int min, int max) {
Expand Down

0 comments on commit e8c7e7c

Please sign in to comment.