rugnux: the library returns its outputs in memory; the callers write the files

The rugnux library wrote its results itself: _process.h5 through a
FileWriter, the merged/twin/_mr reflection files, the unmerged MTZs, the
maps and their MTZ, the placed models, _detector.jpg and _plot.txt, and
on a doubled cell it renamed files on disk. It now writes none of them.

- MtzTable (common/MtzTable.h): an MTZ file's header, columns and batch
  headers with no file behind it. It replaces MergedReflectionsMessage
  and MapCoefficientsMessage in the END message, with one CBOR encoding.
  WriteMtz (writer/WriteRugnuxFiles.h) is the one serialiser, used by
  rugnux and jfjoch_writer alike; it refuses a table whose columns differ
  in length, name a missing dataset, carry a malformed batch header or
  name a space group gemmi does not know. MergedMtzTable and
  UnmergedMtzTable build the tables the old writers built.
- ProcessResult::outputs (RugnuxOutputs) holds, for the output pass only:
  the answer's merge (MTZ table plus what the .cif/.hkl are written from),
  the twin hypothesis' and the model's choice's merges, the unmerged and
  unmerged-partials tables, the maps (coefficients always; the grids only
  with ProcessConfig::keep_map_grids), the placed models, the detector
  JPEG and the per-image plot table, and the start message of the
  no-lattice _process.h5. Map RMS is taken from the grid in memory, as the
  CCP4 header stated it, whether or not the map is kept.
- The per-image analysis goes to a caller-supplied RugnuxImageSink;
  rugnux and the viewer give a FileWriter-based ProcessFileSink. The
  geometry pre-pass no longer makes a _01_process.h5.
- The doubled cell keeps both output sets: the answer's in outputs, the
  other's in DoubledCell::other_outputs with its suffix; the report names
  files by suffix after the caller's prefix.
- The output prefix, write_process_h5 and the observation dump path are
  gone from ProcessConfig; --dump-observations is a callback.
- What used to be gated on having files to write (model validation and
  MR, the twin-hypothesis merges, the finalist ledger, the scaled fulls,
  the unmerged tables) is gated on the output pass instead, so a caller
  with no prefix gets the same results.
- RugnuxOutputFiles (new library JFJochRugnuxOutput, linked by rugnux,
  the viewer and the tests) writes every file from the result with the
  names and formats rugnux has always used. The viewer writes its job's
  files the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-10-17 16:51:20 +02:00
1 parent 6efc42360a
commit 5f731db81d
50 files changed
+1163 -965

No files matched your search

+43 -44
View File
@@ -521,53 +521,52 @@ inline void CBOR_ENC(CborEncoder &encoder, const char* key, const std::vector<do
cborErr(cbor_encode_byte_string(&encoder, reinterpret_cast<const uint8_t *>(v.data()), v.size() * sizeof(double)));
}
inline void CBOR_ENC(CborEncoder &encoder, const char* key, const MergedReflectionsMessage &m) {
CborEncoder mapEncoder;
inline void CBOR_ENC(CborEncoder &encoder, const char* key, const MtzTable &t) {
CborEncoder mapEncoder, arrayEncoder, elementEncoder;
cborErr(cbor_encode_text_stringz(&encoder, key));
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, CborIndefiniteLength));
CBOR_ENC(mapEncoder, "unit_cell", m.unit_cell);
CBOR_ENC(mapEncoder, "space_group_name", m.space_group_name);
CBOR_ENC(mapEncoder, "wavelength", m.wavelength_A);
CBOR_ENC(mapEncoder, "crystal_name", m.crystal_name);
CBOR_ENC(mapEncoder, "history", m.history);
CBOR_ENC(mapEncoder, "h", m.h);
CBOR_ENC(mapEncoder, "k", m.k);
CBOR_ENC(mapEncoder, "l", m.l);
CBOR_ENC(mapEncoder, "i_mean", m.i_mean);
CBOR_ENC(mapEncoder, "sigma_i_mean", m.sigma_i_mean);
CBOR_ENC(mapEncoder, "i_plus", m.i_plus);
CBOR_ENC(mapEncoder, "sigma_i_plus", m.sigma_i_plus);
CBOR_ENC(mapEncoder, "i_minus", m.i_minus);
CBOR_ENC(mapEncoder, "sigma_i_minus", m.sigma_i_minus);
CBOR_ENC(mapEncoder, "f", m.f);
CBOR_ENC(mapEncoder, "sigma_f", m.sigma_f);
CBOR_ENC(mapEncoder, "f_plus", m.f_plus);
CBOR_ENC(mapEncoder, "sigma_f_plus", m.sigma_f_plus);
CBOR_ENC(mapEncoder, "f_minus", m.f_minus);
CBOR_ENC(mapEncoder, "sigma_f_minus", m.sigma_f_minus);
CBOR_ENC(mapEncoder, "free_flag", m.free_flag);
cborErr(cbor_encoder_close_container(&encoder, &mapEncoder));
}
CBOR_ENC(mapEncoder, "title", t.title);
CBOR_ENC(mapEncoder, "unit_cell", t.unit_cell);
CBOR_ENC(mapEncoder, "space_group_name", t.space_group_name);
CBOR_ENC(mapEncoder, "history", t.history);
CBOR_ENC(mapEncoder, "sort_order", std::vector<int32_t>(t.sort_order.begin(), t.sort_order.end()));
inline void CBOR_ENC(CborEncoder &encoder, const char* key, const MapCoefficientsMessage &m) {
CborEncoder mapEncoder;
cborErr(cbor_encode_text_stringz(&encoder, key));
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, CborIndefiniteLength));
CBOR_ENC(mapEncoder, "unit_cell", m.unit_cell);
CBOR_ENC(mapEncoder, "space_group_name", m.space_group_name);
CBOR_ENC(mapEncoder, "wavelength", m.wavelength_A);
CBOR_ENC(mapEncoder, "h", m.h);
CBOR_ENC(mapEncoder, "k", m.k);
CBOR_ENC(mapEncoder, "l", m.l);
CBOR_ENC(mapEncoder, "fp", m.fp);
CBOR_ENC(mapEncoder, "fc", m.fc);
CBOR_ENC(mapEncoder, "phic", m.phic);
CBOR_ENC(mapEncoder, "fwt", m.fwt);
CBOR_ENC(mapEncoder, "phwt", m.phwt);
CBOR_ENC(mapEncoder, "delfwt", m.delfwt);
CBOR_ENC(mapEncoder, "phdelwt", m.phdelwt);
CBOR_ENC(mapEncoder, "fom", m.fom);
CBOR_ENC(mapEncoder, "free_flag", m.free_flag);
cborErr(cbor_encode_text_stringz(&mapEncoder, "datasets"));
cborErr(cbor_encoder_create_array(&mapEncoder, &arrayEncoder, t.datasets.size()));
for (const auto &d : t.datasets) {
cborErr(cbor_encoder_create_map(&arrayEncoder, &elementEncoder, 4));
CBOR_ENC(elementEncoder, "project_name", d.project_name);
CBOR_ENC(elementEncoder, "crystal_name", d.crystal_name);
CBOR_ENC(elementEncoder, "dataset_name", d.dataset_name);
CBOR_ENC(elementEncoder, "wavelength", d.wavelength_A);
cborErr(cbor_encoder_close_container(&arrayEncoder, &elementEncoder));
}
cborErr(cbor_encoder_close_container(&mapEncoder, &arrayEncoder));
cborErr(cbor_encode_text_stringz(&mapEncoder, "columns"));
cborErr(cbor_encoder_create_array(&mapEncoder, &arrayEncoder, t.columns.size()));
for (const auto &c : t.columns) {
cborErr(cbor_encoder_create_map(&arrayEncoder, &elementEncoder, 4));
CBOR_ENC(elementEncoder, "label", c.label);
CBOR_ENC(elementEncoder, "type", std::string(1, c.type));
CBOR_ENC(elementEncoder, "dataset_id", static_cast<int64_t>(c.dataset_id));
CBOR_ENC(elementEncoder, "values", c.values);
cborErr(cbor_encoder_close_container(&arrayEncoder, &elementEncoder));
}
cborErr(cbor_encoder_close_container(&mapEncoder, &arrayEncoder));
cborErr(cbor_encode_text_stringz(&mapEncoder, "batches"));
cborErr(cbor_encoder_create_array(&mapEncoder, &arrayEncoder, t.batches.size()));
for (const auto &b : t.batches) {
cborErr(cbor_encoder_create_map(&arrayEncoder, &elementEncoder, 5));
CBOR_ENC(elementEncoder, "number", static_cast<int64_t>(b.number));
CBOR_ENC(elementEncoder, "title", b.title);
CBOR_ENC(elementEncoder, "ints", b.ints);
CBOR_ENC(elementEncoder, "floats", b.floats);
CBOR_ENC(elementEncoder, "axes", b.axes);
cborErr(cbor_encoder_close_container(&arrayEncoder, &elementEncoder));
}
cborErr(cbor_encoder_close_container(&mapEncoder, &arrayEncoder));
cborErr(cbor_encoder_close_container(&encoder, &mapEncoder));
}