Combines the stills reader and module work (stills-readers, stills-modgeom, stills-euxfel) onto rc178 with the owner's decisions for this release: - Inputs are files, never a directory; several files of one format are one dataset (the multi-input CLI of the previous commit), so every reader takes an explicit list: JFJochXFELReader::ReadFiles, ReadCXI, ReadPanelTable and JFJochXTCReader::ReadFiles take std::vector<std::string>; ListFiles and xtc::CollectStreams are gone, CanRead* accept a regular file only. - One HDF5 frame reader (JFJochCrystFELReader -> JFJochXFELReader) parameterised by what the file holds: per-shot groups or a 3D stack, a /metadata panel table (posx/posy/angle, pixel size, nominal camera length, pixel mask: as SACLA writes), a Cheetah CXI single panel (square frame; a tiled slab is refused with a message). At most 8 files open; every file checked against the first. Signed 32-bit decode, per-frame 3D masks, panels at their own coffset (from the EuXFEL work). - Frames stored one chunk each are read the way the NXmx reader reads its images: only the chunk's place is asked of HDF5 under its lock (H5Dget_chunk_info_by_coord), the bytes are read through HDF5ImageSource::RawFile (positional, no lock) and decoded outside it - deflate(+shuffle) by zlib, bitshuffle/LZ4 (and zstd, plain LZ4) by CompressedImage's decoders. Bitshuffle/LZ4 used to go through HDF5's filter under the global lock, one frame at a time. - LCLS-I XTC (Rayonix): wavelength from the beam record, pixel size from the Rayonix model and binning, only --detector-distance needed; damaged/compressed frames skipped, a truncated last event dropped; std::ifstream, no POSIX calls: builds with MSVC. No DIALS .expt support at all. - CrystFEL .geom: module geometry only (panel ranges, fs/ss, corners, pixel size, coffset, data path) and optionally the camera length; everything else is ignored with a note in the log. - --mask-good / --mask-bad <file>:<dataset>: a mask array in another HDF5 file, in the frames' stored layout (what a .geom's mask_file used to give). - Gain measured on the background for panel-table and CXI input that states none (--gain overrides). - Detector modules from explicit geometry only (DetectorModules: the reader's panels, an NXmx file with one NXdetector_module per module, or --module-geometry); never from the image. Spots and predictions are mapped through the modules, the image is not re-assembled. - Module refinement in the stills bundle adjustment (Ceres; per-module shift and in-plane turn, gauge on mean shift/turn/scale and on the two tilt-like patterns when the tilt is refined; adopted only where it predicts held-out frames better). Applied for a foreign multi-panel detector (panel table, .geom panels); for a JUNGFRAU measured and reported only. Written to <prefix>_modules.h5 (NXmx NXdetector_module groups), read back with --module-geometry. - A panel-table file's camera length is nominal: with a reference cell it is refined from the cell. - Broker and writer output unchanged: masters keep the single NXdetector_module group, the start message carries no module list. Tests: [CrystFELGeometry], JFJochXFELReader_*, JFJochXTCReader, [JFJochMultiReader], [CellPopulation], SaturationCeiling_*, [DetectorModules], RefineGlobalGeometry_ModulePlacement, [reindex], Sublattice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
65 lines
2.8 KiB
C++
65 lines
2.8 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "JFJochReader.h"
|
|
#include "XTC.h"
|
|
|
|
// Reads serial-crystallography stills straight from LCLS-I XTC files: one camera image per event,
|
|
// from a single-panel detector such as the Rayonix CCDs at MFX and XPP. A multi-panel detector
|
|
// (CSPAD, ePix, JUNGFRAU at LCLS) is stored as raw per-module data with its own calibration, and is
|
|
// not read here.
|
|
//
|
|
// What the XTC states is used: the photon energy of every event's electron-beam record (the run is
|
|
// read at their mean) and, for a Rayonix, the pixel size from its model and binning. The distance is
|
|
// not recorded, and the beam centre is not either: the panel is placed square-on with its middle on
|
|
// the beam, the run measures the centre, and the distance (and whatever the XTC did not state) is
|
|
// given on the command line.
|
|
//
|
|
// The images are stills: no goniometer. Each is decoded on demand, the camera's stated pixel offset
|
|
// taken off. A damaged or compressed image is left out, and so is an event the file ends inside.
|
|
class JFJochXTCReader : public JFJochReader {
|
|
std::vector<xtc::Frame> frames_;
|
|
std::shared_ptr<JFJochReaderDataset> dataset_;
|
|
std::optional<double> photon_energy_eV_;
|
|
std::optional<double> pixel_um_;
|
|
float adu_per_photon_ = 1.0f;
|
|
bool counts_in_photons_ = false;
|
|
|
|
bool LoadImage_i(std::shared_ptr<JFJochReaderDataset> &dataset,
|
|
DataMessage &message,
|
|
std::vector<uint8_t> &buffer,
|
|
int64_t image_number,
|
|
bool update_dataset) override;
|
|
|
|
template <class Buffer>
|
|
CompressedImage DecodeInto(int64_t image_number, Buffer &buffer, std::vector<uint8_t> &scratch) const;
|
|
|
|
public:
|
|
~JFJochXTCReader() override = default;
|
|
|
|
static bool CanRead(const std::string &path);
|
|
|
|
// The event streams, read in the order given, their frames one after another.
|
|
void ReadFiles(const std::vector<std::string> &streams);
|
|
|
|
// What the XTC stated; anything it did not is the caller's to give.
|
|
[[nodiscard]] bool HasWavelength() const { return photon_energy_eV_.has_value(); }
|
|
[[nodiscard]] bool HasPixelSize() const { return pixel_um_.has_value(); }
|
|
|
|
// Converts to photons with this gain from here on (detector units per photon).
|
|
void ApplyGain(float adu_per_photon);
|
|
[[nodiscard]] bool CountsInPhotons() const { return counts_in_photons_; }
|
|
|
|
[[nodiscard]] uint64_t GetNumberOfImages() const override;
|
|
void Close() override;
|
|
|
|
bool ReadRawImage(int64_t image_number, JFJochReaderRawImage &image) override;
|
|
[[nodiscard]] std::vector<SpotToSave> ReadSpots(int64_t image) const override;
|
|
};
|