Viewer: a processed CBF / marCCD / SMV sweep shows its run from the _process.h5
A run of an HDF5 file is shown as a snapshot - its metadata read back over the file's own images. A raw sweep has no HDF5 to hang one on, so registering a run was refused and nothing of a finished job reached the image: no beam-stop shadow, spots, reflections or per-image results. The run's _process.h5 carries the images too (Rugnux writes them in when the input is not HDF5), so a raw sweep's run is now read as a file of its own: activating it opens the _process.h5 with the HDF5 reader, activating "Original" goes back to the sweep's reader. Runs can be removed, renamed and switched between as for an HDF5 file, and the run list carries both, so the plots overlay them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
51f3e5dd43
commit
76c11ed179
2 files changed
+88
-26
No files matched your search
@@ -284,6 +284,11 @@ void JFJochImageReadingWorker::LoadFile_i(const QString &filename, qint64 image_
|
||||
// name - ".img" is used by all of miniCBF, marCCD and SMV depending on the writer.
|
||||
// Release the previously open file first, so switching format leaves nothing behind.
|
||||
file_reader->Close();
|
||||
if (raw_reader_)
|
||||
raw_reader_->Close(); // a raw sweep showing one of its runs has both open
|
||||
raw_reader_ = nullptr;
|
||||
raw_runs_.clear();
|
||||
raw_active_ = "Original";
|
||||
const std::string path = filename.toStdString();
|
||||
cbf_mode = true;
|
||||
if (JFJochCBFReader::CanRead(path)) {
|
||||
@@ -300,6 +305,8 @@ void JFJochImageReadingWorker::LoadFile_i(const QString &filename, qint64 image_
|
||||
file_reader = &hdf5_reader;
|
||||
hdf5_reader.ReadFile(path);
|
||||
}
|
||||
if (cbf_mode)
|
||||
raw_reader_ = file_reader;
|
||||
total_images = file_reader->GetNumberOfImages();
|
||||
dataset = file_reader->GetDataset();
|
||||
setAutoLoadMode_i(AutoloadMode::None);
|
||||
@@ -1132,8 +1139,21 @@ void JFJochImageReadingWorker::SetModelPath(QString path) {
|
||||
|
||||
void JFJochImageReadingWorker::ActivateSnapshot_i(const QString &name) {
|
||||
// Assumes m locked! Switch the reader's active metadata snapshot and refresh the view.
|
||||
hdf5_reader.SetActiveSnapshot(name.toStdString());
|
||||
auto dataset = hdf5_reader.GetDataset();
|
||||
const std::string id = name.toStdString();
|
||||
if (cbf_mode) {
|
||||
if (id == "Original") {
|
||||
file_reader = raw_reader_;
|
||||
} else {
|
||||
hdf5_reader.ReadFile(raw_runs_.at(id).path);
|
||||
raw_runs_.at(id).dataset = hdf5_reader.GetDataset();
|
||||
file_reader = &hdf5_reader;
|
||||
}
|
||||
raw_active_ = id;
|
||||
total_images = file_reader->GetNumberOfImages();
|
||||
} else {
|
||||
hdf5_reader.SetActiveSnapshot(id);
|
||||
}
|
||||
auto dataset = file_reader->GetDataset();
|
||||
if (!dataset)
|
||||
return;
|
||||
|
||||
@@ -1143,33 +1163,54 @@ void JFJochImageReadingWorker::ActivateSnapshot_i(const QString &name) {
|
||||
UpdateAzint_i(dataset.get());
|
||||
EmitDatasetLoaded_i(dataset);
|
||||
|
||||
QStringList names;
|
||||
for (const auto &n: hdf5_reader.SnapshotNames())
|
||||
names << QString::fromStdString(n);
|
||||
emit snapshotsChanged(names, QString::fromStdString(hdf5_reader.ActiveSnapshot()));
|
||||
emit snapshotsChanged(RunNames_i(), QString::fromStdString(ActiveRun_i()));
|
||||
EmitRuns_i();
|
||||
|
||||
if (current_image.has_value()) {
|
||||
// A snapshot carries its own per-image results; just re-read the image against the new
|
||||
// metadata source, never re-run analysis (that would re-index on every snapshot switch).
|
||||
// A raw sweep's run is a file of its own, which may hold fewer images than the sweep.
|
||||
const bool prev_reanalyze = auto_reanalyze;
|
||||
auto_reanalyze = false;
|
||||
LoadImage_i(current_image.value(), current_summation);
|
||||
LoadImage_i(std::min<int64_t>(current_image.value(), total_images - 1), current_summation);
|
||||
auto_reanalyze = prev_reanalyze;
|
||||
}
|
||||
}
|
||||
|
||||
std::string JFJochImageReadingWorker::ActiveRun_i() const {
|
||||
return cbf_mode ? raw_active_ : hdf5_reader.ActiveSnapshot();
|
||||
}
|
||||
|
||||
QStringList JFJochImageReadingWorker::RunNames_i() const {
|
||||
QStringList names;
|
||||
if (cbf_mode) {
|
||||
names << "Original";
|
||||
for (const auto &[id, run]: raw_runs_)
|
||||
names << QString::fromStdString(id);
|
||||
} else {
|
||||
for (const auto &n: hdf5_reader.SnapshotNames())
|
||||
names << QString::fromStdString(n);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
void JFJochImageReadingWorker::EmitRuns_i() {
|
||||
// Assumes m locked! Build the run list (every snapshot dataset + its display label).
|
||||
QVector<RunData> runs;
|
||||
if (!http_mode) {
|
||||
for (const auto &[id, dataset]: hdf5_reader.AllSnapshotDatasets()) {
|
||||
const auto it = run_labels_.find(id);
|
||||
const QString label = (it != run_labels_.end()) ? it->second : QString::fromStdString(id);
|
||||
runs.push_back(RunData{QString::fromStdString(id), label, dataset});
|
||||
}
|
||||
std::vector<std::pair<std::string, std::shared_ptr<const JFJochReaderDataset>>> datasets;
|
||||
if (cbf_mode) {
|
||||
datasets.emplace_back("Original", raw_reader_->GetDataset());
|
||||
for (const auto &[id, run]: raw_runs_)
|
||||
datasets.emplace_back(id, run.dataset);
|
||||
} else if (!http_mode) {
|
||||
datasets = hdf5_reader.AllSnapshotDatasets();
|
||||
}
|
||||
emit runsChanged(runs, http_mode ? QString() : QString::fromStdString(hdf5_reader.ActiveSnapshot()));
|
||||
QVector<RunData> runs;
|
||||
for (const auto &[id, dataset]: datasets) {
|
||||
const auto it = run_labels_.find(id);
|
||||
const QString label = (it != run_labels_.end()) ? it->second : QString::fromStdString(id);
|
||||
runs.push_back(RunData{QString::fromStdString(id), label, dataset});
|
||||
}
|
||||
emit runsChanged(runs, http_mode ? QString() : QString::fromStdString(ActiveRun_i()));
|
||||
}
|
||||
|
||||
void JFJochImageReadingWorker::RenameRun(QString id, QString label) {
|
||||
@@ -1182,27 +1223,34 @@ void JFJochImageReadingWorker::RemoveRun(QString id) {
|
||||
QMutexLocker ul(&m);
|
||||
if (http_mode || id == "Original")
|
||||
return;
|
||||
hdf5_reader.RemoveSnapshot(id.toStdString());
|
||||
if (cbf_mode) {
|
||||
raw_runs_.erase(id.toStdString());
|
||||
if (raw_active_ == id.toStdString())
|
||||
raw_active_ = "Original";
|
||||
} else {
|
||||
hdf5_reader.RemoveSnapshot(id.toStdString());
|
||||
}
|
||||
run_labels_.erase(id.toStdString());
|
||||
// Refresh the (possibly now-Original) active view; ActivateSnapshot_i also re-emits runsChanged.
|
||||
ActivateSnapshot_i(QString::fromStdString(hdf5_reader.ActiveSnapshot()));
|
||||
ActivateSnapshot_i(QString::fromStdString(ActiveRun_i()));
|
||||
}
|
||||
|
||||
void JFJochImageReadingWorker::RegisterProcessingSnapshot(QString id, QString label, QString master_path) {
|
||||
QMutexLocker ul(&m);
|
||||
if (http_mode || cbf_mode) {
|
||||
// A snapshot is metadata read back over the SAME images the reader is serving, which only the
|
||||
// HDF5 reader can do; a CBF sweep's job output is a stand-alone file, opened like any other.
|
||||
logger.Error("Processing snapshots are only available for HDF5 files");
|
||||
if (http_mode)
|
||||
return;
|
||||
}
|
||||
try {
|
||||
hdf5_reader.RegisterSnapshot(id.toStdString(), master_path.toStdString());
|
||||
if (cbf_mode)
|
||||
raw_runs_[id.toStdString()] = RawRun{master_path.toStdString(), nullptr}; // read on activation
|
||||
else
|
||||
hdf5_reader.RegisterSnapshot(id.toStdString(), master_path.toStdString());
|
||||
run_labels_[id.toStdString()] = label;
|
||||
ActivateSnapshot_i(id); // activates + emits datasetLoaded / snapshotsChanged / runsChanged
|
||||
} catch (const std::exception &e) {
|
||||
logger.Error("Failed to register snapshot {}: {}", id.toStdString(), e.what());
|
||||
emit fileLoadError("Snapshot error", QString::fromStdString(e.what()));
|
||||
if (cbf_mode && raw_runs_.erase(id.toStdString()) > 0)
|
||||
ActivateSnapshot_i("Original"); // the run's file did not read; back to the sweep
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,8 +83,8 @@ private:
|
||||
|
||||
// A stored file is read by one of these, whichever its format needs; file_reader points at the
|
||||
// one in use. The HDF5-only extras - calibration images and reprocessing snapshots - always go
|
||||
// through hdf5_reader, and a raw image sweep simply has none of them, so raw_mode covers all
|
||||
// three of the raw formats rather than CBF alone.
|
||||
// through hdf5_reader. A raw image sweep has no calibration images and its runs are files of their
|
||||
// own (raw_runs_ below), so cbf_mode covers all three of the raw formats rather than CBF alone.
|
||||
JFJochHDF5Reader hdf5_reader;
|
||||
JFJochCBFReader cbf_reader;
|
||||
JFJochMarCCDReader marccd_reader;
|
||||
@@ -92,6 +92,18 @@ private:
|
||||
JFJochReader *file_reader = &hdf5_reader;
|
||||
bool cbf_mode = false; // "a raw sweep is open", whichever of the three formats it is
|
||||
|
||||
// The runs of a raw sweep. A run of an HDF5 file is a snapshot - its metadata read back over the
|
||||
// file's own images - but a raw sweep has no HDF5 to hang one on. Its run's _process.h5 carries
|
||||
// the images as well, so showing that run means reading that file (with hdf5_reader), and showing
|
||||
// "Original" means reading the sweep again (raw_reader_).
|
||||
struct RawRun {
|
||||
std::string path;
|
||||
std::shared_ptr<const JFJochReaderDataset> dataset;
|
||||
};
|
||||
JFJochReader *raw_reader_ = nullptr;
|
||||
std::map<std::string, RawRun> raw_runs_;
|
||||
std::string raw_active_ = "Original";
|
||||
|
||||
JFJochHttpReader http_reader;
|
||||
|
||||
QString current_file;
|
||||
@@ -197,7 +209,9 @@ private:
|
||||
void ApplyROIOverrideToImage_i(); // rewrite current_image_ptr's dataset with roi_override_
|
||||
void setAutoLoadMode_i(AutoloadMode mode);
|
||||
void ActivateSnapshot_i(const QString &name);
|
||||
void EmitRuns_i(); // emit runsChanged with every snapshot dataset + its label
|
||||
void EmitRuns_i();
|
||||
std::string ActiveRun_i() const;
|
||||
QStringList RunNames_i() const; // emit runsChanged with every snapshot dataset + its label
|
||||
void EmitReferenceInfo_i(); // emit referenceMtzChanged from reference_ + current data
|
||||
|
||||
signals:
|
||||
|
||||
Reference in new issue
Block a user