Build Packages / Unit tests (push) Successful in 1h22m15s
Build Packages / build:windows:nocuda (push) Successful in 18m0s
Build Packages / build:windows:cuda (push) Successful in 20m30s
Build Packages / build:viewer-tgz:cpu (push) Successful in 10m32s
Build Packages / build:viewer-tgz:cuda (push) Successful in 11m39s
Build Packages / build:rugnux-tgz (x86_64) (push) Successful in 8m55s
Build Packages / build:rugnux:windows (push) Successful in 11m25s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 20m6s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 16m27s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 20m19s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 15m34s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 20m25s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 19m36s
Build Packages / build:rpm (rocky8) (push) Successful in 17m43s
Build Packages / build:rpm (rocky9) (push) Successful in 13m34s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 21m28s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 18m19s
Build Packages / DIALS test (push) Successful in 12m36s
Build Packages / XDS test (durin plugin) (push) Successful in 6m56s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 6m48s
Build Packages / XDS test (neggia plugin) (push) Successful in 6m7s
Build Packages / Generate python client (push) Successful in 11s
Build Packages / Build documentation (push) Successful in 36s
Build Packages / Create release (push) Skipped
Build Packages / build:rugnux:aarch64 (cross) (push) Successful in 5m11s
* `rugnux --mode calibration` writes `<prefix>.json` beside the `.poni`, whose `dataset_settings` member is a `jfjoch_broker` `dataset_settings` body as it stands. * `rugnux` and `jfjoch_viewer` read PILATUS miniCBF sweeps natively, without conversion. * Masters written by other facilities open, including Eiger 1.x and third-party NXmx variants. * `rugnux` measures the beam centre on every run, and indexes with it when the file's value indexes nothing. * A detector swung out on a 2theta arm is placed where the file says it stands, and the calibration can hold the tilt fixed. * `rugnux` writes the unmerged MTZ by default, and a P1 merge beside it, so a wrong space group can be re-merged without reprocessing. * Significant improvements to symmetry handling in `rugnux`: the lattice, the point group, the setting and the systematic absences. * The `rugnux` report gives the resolution the CC1/2 fit reached, beside the range the reflections were written to. * The `rugnux` report gives the twinning statistics measured before the space group was decided, beside the ones measured after. * The `rugnux` report gives the strong-direction diffraction limit, and warns when CC1/2 is not monotone with resolution. * `rugnux` ranks screw axes on the evidence their absences carry, rather than on how many control reflections a candidate happens to have. * Twinning is no longer reported when the L-test contradicts it. * The `rugnux` report gives the detector tilt, the measured tilt and the direct beam beside the beam centre, and a post-refined beam centre is judged against the run's own measurement rather than the file's. * `--no-refine-tilt` holds the detector tilt at the value in the file, instead of zeroing it, when the calibration starts from the spots. * The `jfjoch_viewer` grid scan view draws the cells in the proportion of the scan steps, so the map has the shape of the scanned area. Reviewed-on: #76 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
134 lines
5.5 KiB
C++
134 lines
5.5 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "JFJochReader.h"
|
|
#include <future>
|
|
|
|
JFJochReader &JFJochReader::Experiment(const DiffractionExperiment &experiment) {
|
|
std::unique_lock ul(m);
|
|
default_experiment = experiment;
|
|
return *this;
|
|
}
|
|
|
|
void JFJochReader::SummationThread(int64_t image0, int64_t n_image, int64_t image_jump, JFJochReaderImage &image) {
|
|
std::vector<uint8_t> buffer;
|
|
DataMessage msg;
|
|
for (int64_t i = image0; i < n_image; i += image_jump) {
|
|
bool ret = LoadImage_i(dataset, msg, buffer, i, false);
|
|
if (ret) {
|
|
auto image_sum = std::make_shared<JFJochReaderImage>(msg, dataset);
|
|
{
|
|
std::unique_lock ul(summation_mutex);
|
|
image.AddImage(*image_sum);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
std::shared_ptr<JFJochReaderImage> JFJochReader::LoadImage(int64_t image_number, int64_t summation_factor) {
|
|
// It would be a mess to load two images at the same time
|
|
// so loading is protected via mutex
|
|
// yet copying share_ptr pointer is atomic and needs no mutex protection
|
|
std::unique_lock ul(m);
|
|
|
|
std::vector<uint8_t> buffer;
|
|
DataMessage msg;
|
|
|
|
if (LoadImage_i(dataset, msg, buffer, image_number, true)) {
|
|
auto image = std::make_shared<JFJochReaderImage>(msg, dataset);
|
|
if (summation_factor > 4) {
|
|
int64_t nthread = std::min<int64_t>(summation_factor - 1, 8);
|
|
|
|
std::vector<std::future<void>> futures;
|
|
for (int i = 0; i < nthread; i++)
|
|
futures.emplace_back(std::async(std::launch::async,
|
|
&JFJochReader::SummationThread, this,
|
|
image_number + 1 + i,
|
|
image_number + summation_factor,
|
|
nthread,
|
|
std::ref(*image)));
|
|
for (auto &f: futures)
|
|
f.get();
|
|
} else if (summation_factor > 1) {
|
|
SummationThread(image_number + 1, image_number + summation_factor, 1, *image);
|
|
}
|
|
return image;
|
|
}
|
|
return {};
|
|
}
|
|
|
|
void JFJochReader::SetStartMessage(const std::shared_ptr<JFJochReaderDataset> &val) {
|
|
std::unique_lock ul(m);
|
|
dataset = val;
|
|
}
|
|
|
|
std::shared_ptr<const JFJochReaderDataset> JFJochReader::GetDataset() const {
|
|
std::unique_lock ul(m);
|
|
return dataset;
|
|
}
|
|
|
|
void JFJochReader::UpdateGeomMetadata(const DiffractionExperiment &experiment) {
|
|
std::unique_lock ul(m);
|
|
if (!dataset)
|
|
return;
|
|
|
|
auto new_dataset = std::make_shared<JFJochReaderDataset>(*dataset);
|
|
// At the moment subset of options is limited to safe ones...need to change it in the future
|
|
|
|
new_dataset->experiment.BeamX_pxl(experiment.GetBeamX_pxl());
|
|
new_dataset->experiment.BeamY_pxl(experiment.GetBeamY_pxl());
|
|
new_dataset->experiment.DetectorDistance_mm(experiment.GetDetectorDistance_mm());
|
|
new_dataset->experiment.IncidentEnergy_keV(experiment.GetIncidentEnergy_keV());
|
|
new_dataset->experiment.PoniRot1_rad(experiment.GetDatasetSettings().GetPoniRot1_rad());
|
|
new_dataset->experiment.PoniRot2_rad(experiment.GetDatasetSettings().GetPoniRot2_rad());
|
|
new_dataset->experiment.PoniRot3_rad(experiment.GetDatasetSettings().GetPoniRot3_rad());
|
|
new_dataset->experiment.SetUnitCell(experiment.GetUnitCell());
|
|
new_dataset->experiment.SetSpaceGroup(experiment.GetGemmiSpaceGroup());
|
|
new_dataset->experiment.PolarizationFactor(experiment.GetPolarizationFactor());
|
|
new_dataset->experiment.Goniometer(experiment.GetGoniometer());
|
|
new_dataset->experiment.GridScan(experiment.GetGridScan());
|
|
new_dataset->experiment.ImportIndexingSettings(experiment.GetIndexingSettings());
|
|
new_dataset->experiment.ImportBraggIntegrationSettings(experiment.GetBraggIntegrationSettings());
|
|
new_dataset->experiment.DetectIceRings(experiment.IsDetectIceRings());
|
|
dataset = new_dataset;
|
|
}
|
|
|
|
void JFJochReader::UpdateUserMask(const std::vector<uint32_t> &mask) {
|
|
std::unique_lock ul(m);
|
|
if (!dataset)
|
|
return;
|
|
auto new_dataset = std::make_shared<JFJochReaderDataset>(*dataset);
|
|
// Copy-on-write: the mask is shared with the old snapshot, so edit a fresh copy, not in place.
|
|
auto new_mask = std::make_shared<PixelMask>(*dataset->pixel_mask);
|
|
new_mask->LoadUserMask(dataset->experiment, mask);
|
|
new_dataset->pixel_mask = new_mask;
|
|
dataset = new_dataset;
|
|
}
|
|
|
|
std::shared_ptr<JFJochReaderSpots> JFJochReader::ReadAllSpots(int64_t start_image, int64_t end_image,
|
|
int64_t stride) const {
|
|
|
|
if (start_image < 0)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
|
"Start image must be non-negative");
|
|
|
|
if (start_image > end_image)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
|
"Start image number is greater than end image number");
|
|
|
|
if (stride == 0)
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
|
"Stride cannot be zero");
|
|
|
|
size_t nelems = (end_image - start_image) / stride + 1;
|
|
|
|
auto ret = std::make_shared<JFJochReaderSpots>();
|
|
ret->start_image = static_cast<int64_t>(start_image);
|
|
ret->stride = static_cast<int64_t>(stride);
|
|
ret->spots.reserve(nelems);
|
|
|
|
for (int i = 0; i < nelems; i++)
|
|
ret->spots.emplace_back(ReadSpots(start_image + i * stride));
|
|
return ret;
|
|
}
|