diff --git a/reader/SweepLayout.cpp b/reader/SweepLayout.cpp index 67cda450f..6feae1122 100644 --- a/reader/SweepLayout.cpp +++ b/reader/SweepLayout.cpp @@ -142,7 +142,7 @@ Layout Place(const std::vector &frames, const std::string &logger_name) { double guess = 0; for (size_t i = 1; i < frames.size(); i++) { const double d = Fold(angle[i] - angle[i - 1]); - if (std::abs(d) > std::max(too_fine, 1e-6) && (guess == 0 || std::abs(d) < std::abs(guess))) + if (std::abs(d) > too_fine && (guess == 0 || std::abs(d) < std::abs(guess))) guess = d; } diff --git a/tests/JFJochReaderTest.cpp b/tests/JFJochReaderTest.cpp index d6a61c86f..6b0c0cc19 100644 --- a/tests/JFJochReaderTest.cpp +++ b/tests/JFJochReaderTest.cpp @@ -4147,6 +4147,9 @@ namespace { int32_t wavelength_e5A = 97872; int32_t saturated = 65535; int32_t depth = 2; + int32_t rotation_axis = 4; // the circle that turned, as the header's own index (phi) + bool zero_end_block = false; // a writer that fills the start angles and nothing else + uint32_t header_offset_tag = MARCCD_HEADER_OFF; // what tag 34710 claims, true or not bool write_instrument_header = true; }; @@ -4169,7 +4172,7 @@ namespace { {277, 3, 1, 1}, // SamplesPerPixel {278, 4, 1, static_cast(ny)}, // RowsPerStrip: one strip {279, 4, 1, static_cast(npixel * 2)}, // StripByteCounts - {34710, 4, 1, MARCCD_HEADER_OFF}, // where the instrument header begins + {34710, 4, 1, f.header_offset_tag}, // where the instrument header begins }; PutU16(file, 8, static_cast(ifd.size())); size_t e = 10; @@ -4195,8 +4198,11 @@ namespace { PutI32(file, h + 656, 1000); // exposure, ms PutI32(file, h + 668, f.two_theta_mdeg); // start_twotheta PutI32(file, h + 684, f.start_phi_mdeg); // start_phi - PutI32(file, h + 700, f.two_theta_mdeg); // end_twotheta - PutI32(file, h + 716, f.end_phi_mdeg); // end_phi + if (!f.zero_end_block) { + PutI32(file, h + 700, f.two_theta_mdeg); // end_twotheta + PutI32(file, h + 716, f.end_phi_mdeg); // end_phi + } + PutI32(file, h + 732, f.rotation_axis); PutI32(file, h + 736, f.rotation_range_mdeg); PutI32(file, h + 772, f.pixel_nm); PutI32(file, h + 776, f.pixel_nm); @@ -4280,6 +4286,37 @@ TEST_CASE("JFJochMarCCDReader_Geometry", "[HDF5][Full]") { RemoveMarCCDSweep("marccdpix_", ".mccd"); } + SECTION("a swung-out 2-theta arm is not the circle the sweep turned") { + // Some writers fill the start angles and leave the whole end block at zero. Reading the + // scanned circle as the first start/end pair that differs then picks two_theta, which is the + // first pair in the block, and a detector on a 2-theta arm was named as the spindle - with a + // start angle that does not move from frame to frame. + MarCCDFields f; + f.two_theta_mdeg = 20000; // the detector swung out by 20 deg + f.zero_end_block = true; + f.rotation_axis = 0; // ... and the index never filled in either + WriteMarCCDSweep("marccd2t_", ".mccd", nx, ny, f); + JFJochMarCCDReader reader; + REQUIRE_NOTHROW(reader.ReadFiles("marccd2t_001.mccd")); + const auto x = reader.GetDataset()->experiment; + REQUIRE(x.GetGoniometer().has_value()); + CHECK(x.GetGoniometer()->GetName() == "phi"); + CHECK(x.GetGoniometer()->GetStart_deg() == Catch::Approx(0.0)); + CHECK(x.GetGoniometer()->GetIncrement_deg() == Catch::Approx(0.2)); + reader.Close(); + RemoveMarCCDSweep("marccd2t_", ".mccd"); + } + + SECTION("a header offset the file cannot hold is refused, not allocated") { + // The offset comes from TIFF tag 34710 and is read on every input the program is given, so a + // foreign or corrupt TIFF can name gigabytes on a file nobody has said is marCCD. + MarCCDFields f; + f.header_offset_tag = 4000000000u; + WriteMarCCDFrame("marccdfaroff_001.mccd", nx, ny, f); + CHECK_FALSE(JFJochMarCCDReader::CanRead("marccdfaroff_001.mccd")); + remove("marccdfaroff_001.mccd"); + } + SECTION("a TIFF that is not marCCD is refused, not misread") { // The name rule alone matches any numbered TIFF in the directory, so a file with no // instrument header must not be opened with a pixel size and a distance of zero.