Files
Jungfraujoch/reader/DetectorLayout.h
T
leonarski_fandClaude Opus 5.5 95e51f868d XFEL reader: integer frames stay integer, one gain, placement by panel
DecodeInto no longer turns every stored pixel into a float and back:
- the gain is one value (adu_per_photon_), not a float per stored pixel
  - it always was one value; only --gain or a measured gain set it;
- a 16-bit signed frame (Cheetah CXI, SACLA) without a gain is handed
  up as Int16, in its own type; other integer frames are widened to
  int32 without a float; only a float frame or a gain other than one
  goes through lround(v / gain), exactly as before;
- placement is per panel (start, size, destination steps) instead of a
  64-bit destination per stored pixel; a panel square with the image
  is copied row by row (PAL: 1440x1440 into 1444x1444 - the two-pixel
  margin is Place()'s, kept so the geometry does not move);
- the decode buffers (chunk, inflated, unshuffled) are reused per
  thread, the bitshuffle decode is not copied again;
- a chunk whose HDF5 filter_mask is not zero (a filter skipped) is
  read by HDF5 instead of being decoded as if it were not;
- the never-set value flags (flag_lessthan/morethan/equal) are gone
  from the layout and from the per-pixel loop.

MeasureGain in the CLI now reads Int16 frames as well, so a SACLA run
still has its gain measured.

Tests: JFJochXFELReader_SACLA/_CXI updated for the mode, new
JFJochXFELReader_CXI_Int16 (deflate without shuffle, a chunk with its
filter skipped) and JFJochXTCReader_StoredPixels (synthetic XTC,
stored hand-up and the offset path).

Measured on two PAL-XFEL Rayonix sets (int16, deflate; RTX 5080,
5950X, page cache warm; reports and .hkl identical to the baseline):
  main pass, 2000 frames:  296 -> 799 frames/s (pal86),
                           302 -> 755 frames/s (pal90)
  wall, 2000 frames:       26.4 -> 13.6 s, 32.1 -> 19.4 s
  (the geometry-refinement steps, which read frames too, halve)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
2026-10-21 10:50:34 +02:00

76 lines
3.0 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
// Where the panels of a stills detector lie and what their pixels are worth, as the XFEL readers
// gather it from a file's own metadata (or, while it is still read, a CrystFEL geometry file): the
// panels with their pixel ranges in the stored frame, fast/slow-scan directions and corners, the camera
// length, the pixel size, the gain and the regions to leave out. The conventions are CrystFEL's - a
// corner is the very corner of the panel's first pixel, x and y in pixels in the detector plane.
//
// Lengths are in pixels, except the camera length, which is held in metres. A value taken from the
// image files (a camera length or photon energy stated per shot) is kept as its path, with the factor
// that turns the stored number into the unit held here.
namespace xfel {
// A number stated in the layout, or a path to it in the image file, times scale.
struct Value {
std::string path; // empty: value holds the number
double value = 0;
double scale = 1; // what one stored unit at path is worth
};
struct Panel {
std::string name;
int64_t min_fs = 0, max_fs = 0, min_ss = 0, max_ss = 0; // inclusive, in the stored frame
double fs_x = 1, fs_y = 0, ss_x = 0, ss_y = 1;
double corner_x = 0, corner_y = 0;
double res = 0; // pixels per metre
std::optional<Value> clen; // metres
double coffset = 0; // metres
std::optional<double> adu_per_eV;
std::optional<double> adu_per_photon;
std::optional<double> max_adu;
int64_t mask_edge_pixels = 0;
bool no_index = false;
};
// A region to leave out: either a pixel range on one panel (or, in the old syntax, on the whole
// frame), or a box in the laboratory plane, in pixels.
struct BadRegion {
std::string panel; // empty: fs/ss are whole-frame coordinates
bool in_lab = false;
double min_x = 0, max_x = 0, min_y = 0, max_y = 0;
int64_t min_fs = 0, max_fs = 0, min_ss = 0, max_ss = 0;
};
// A mask array: a pixel is bad where it has any of bad's bits set, or lacks any of good's - or, with
// nonzero_good, where the array is zero.
struct Mask {
std::string data; // HDF5 path
std::string file; // file holding it, or empty for the image file itself
uint32_t good = 0, bad = 0;
bool nonzero_good = false;
[[nodiscard]] bool Bad(uint32_t v) const {
return (bad != 0 && (v & bad) != 0) || (good != 0 && (v & good) != good) || (nonzero_good && v == 0);
}
};
struct Layout {
std::vector<Panel> panels;
std::vector<BadRegion> bad;
std::vector<Mask> masks;
std::string data = "/data/data";
std::optional<Value> photon_energy; // eV
std::optional<Value> wavelength; // Angstrom; used where no photon_energy is stated
};
} // namespace xfel