|
10 | 10 | #include "MantidBeamline/DetectorInfo.h" |
11 | 11 | #include "MantidFrameworkTestHelpers/ComponentCreationHelper.h" |
12 | 12 | #include "MantidGeometry/Instrument/Detector.h" |
| 13 | +#include "MantidGeometry/Instrument/FitParameter.h" |
13 | 14 | #include "MantidGeometry/Instrument/Parameter.h" |
14 | 15 | #include "MantidGeometry/Instrument/ParameterFactory.h" |
15 | 16 | #include "MantidGeometry/Instrument/ParameterMap.h" |
@@ -609,6 +610,80 @@ class ParameterMapTest : public CxxTest::TestSuite { |
609 | 610 | TS_ASSERT_EQUALS(pmap.get(comp, "v")->asString(), "[0.123456789012345,0.123456789012345,0.123456789012345]"); |
610 | 611 | } |
611 | 612 |
|
| 613 | + void test_addFittingParameter_keeps_entries_for_different_functions() { |
| 614 | + // Two functions on the same component declare a parameter with the same short name |
| 615 | + // (e.g. Bk2BkExpConvPV:Gamma and IkedaCarpenterPV:Gamma). addFittingParameter must |
| 616 | + // dedupe by (name, function), so both entries should coexist. |
| 617 | + ParameterMap pmap; |
| 618 | + IComponent_sptr comp = m_testInstrument->getChild(0); |
| 619 | + pmap.addFittingParameter(comp.get(), "Gamma", "Bk2BkExpConvPV", "1.5 , Bk2BkExpConvPV , Gamma"); |
| 620 | + pmap.addFittingParameter(comp.get(), "Gamma", "IkedaCarpenterPV", "2.5 , IkedaCarpenterPV , Gamma"); |
| 621 | + |
| 622 | + TS_ASSERT_EQUALS(pmap.size(), 2); |
| 623 | + |
| 624 | + auto bk2bk = pmap.getRecursiveFittingParameter(comp.get(), "Gamma", "Bk2BkExpConvPV"); |
| 625 | + TS_ASSERT(bk2bk); |
| 626 | + TS_ASSERT_EQUALS(bk2bk->value<Mantid::Geometry::FitParameter>().getFunction(), "Bk2BkExpConvPV"); |
| 627 | + TS_ASSERT_DELTA(bk2bk->value<Mantid::Geometry::FitParameter>().getValue(), 1.5, 1e-12); |
| 628 | + |
| 629 | + auto ikedaPV = pmap.getRecursiveFittingParameter(comp.get(), "Gamma", "IkedaCarpenterPV"); |
| 630 | + TS_ASSERT(ikedaPV); |
| 631 | + TS_ASSERT_EQUALS(ikedaPV->value<Mantid::Geometry::FitParameter>().getFunction(), "IkedaCarpenterPV"); |
| 632 | + TS_ASSERT_DELTA(ikedaPV->value<Mantid::Geometry::FitParameter>().getValue(), 2.5, 1e-12); |
| 633 | + |
| 634 | + // Lookup for a function that was never registered yields nothing. |
| 635 | + TS_ASSERT(!pmap.getRecursiveFittingParameter(comp.get(), "Gamma", "IkedaCarpenterMD")); |
| 636 | + } |
| 637 | + |
| 638 | + void test_addFittingParameter_replaces_only_same_function_entry() { |
| 639 | + // A second add for the SAME (name, function) must replace, not duplicate. |
| 640 | + ParameterMap pmap; |
| 641 | + IComponent_sptr comp = m_testInstrument->getChild(0); |
| 642 | + pmap.addFittingParameter(comp.get(), "Gamma", "Bk2BkExpConvPV", "1.5 , Bk2BkExpConvPV , Gamma"); |
| 643 | + pmap.addFittingParameter(comp.get(), "Gamma", "IkedaCarpenterPV", "2.5 , IkedaCarpenterPV , Gamma"); |
| 644 | + |
| 645 | + pmap.addFittingParameter(comp.get(), "Gamma", "Bk2BkExpConvPV", "9.9 , Bk2BkExpConvPV , Gamma"); |
| 646 | + |
| 647 | + // Still two entries — the IkedaCarpenterPV one is untouched, Bk2BkExpConvPV one is overwritten. |
| 648 | + TS_ASSERT_EQUALS(pmap.size(), 2); |
| 649 | + |
| 650 | + auto bk2bk = pmap.getRecursiveFittingParameter(comp.get(), "Gamma", "Bk2BkExpConvPV"); |
| 651 | + TS_ASSERT(bk2bk); |
| 652 | + TS_ASSERT_DELTA(bk2bk->value<Mantid::Geometry::FitParameter>().getValue(), 9.9, 1e-12); |
| 653 | + |
| 654 | + auto ikedaPV = pmap.getRecursiveFittingParameter(comp.get(), "Gamma", "IkedaCarpenterPV"); |
| 655 | + TS_ASSERT(ikedaPV); |
| 656 | + TS_ASSERT_DELTA(ikedaPV->value<Mantid::Geometry::FitParameter>().getValue(), 2.5, 1e-12); |
| 657 | + } |
| 658 | + |
| 659 | + void test_getRecursiveFittingParameter_walks_up_component_tree() { |
| 660 | + // Parameter declared on the parent should be visible from a child component. |
| 661 | + ParameterMap pmap; |
| 662 | + IComponent_sptr parent = m_testInstrument; // the instrument itself |
| 663 | + IComponent_sptr child = m_testInstrument->getChild(0); |
| 664 | + pmap.addFittingParameter(parent.get(), "Gamma", "IkedaCarpenterPV", "3.3 , IkedaCarpenterPV , Gamma"); |
| 665 | + |
| 666 | + auto found = pmap.getRecursiveFittingParameter(child.get(), "Gamma", "IkedaCarpenterPV"); |
| 667 | + TS_ASSERT(found); |
| 668 | + TS_ASSERT_DELTA(found->value<Mantid::Geometry::FitParameter>().getValue(), 3.3, 1e-12); |
| 669 | + } |
| 670 | + |
| 671 | + void test_getRecursive_still_finds_one_entry_after_addFittingParameter() { |
| 672 | + // Backwards-compat: callers that don't care which function the param belongs to should |
| 673 | + // still get a hit from the plain getRecursive("Gamma", "fitting") path. |
| 674 | + ParameterMap pmap; |
| 675 | + IComponent_sptr comp = m_testInstrument->getChild(0); |
| 676 | + pmap.addFittingParameter(comp.get(), "Gamma", "Bk2BkExpConvPV", "1.5 , Bk2BkExpConvPV , Gamma"); |
| 677 | + pmap.addFittingParameter(comp.get(), "Gamma", "IkedaCarpenterPV", "2.5 , IkedaCarpenterPV , Gamma"); |
| 678 | + |
| 679 | + auto found = pmap.getRecursive(comp.get(), "Gamma", "fitting"); |
| 680 | + TS_ASSERT(found); |
| 681 | + // Both entries have type "fitting" with name "Gamma", so getRecursive returns whichever the |
| 682 | + // multimap iterates first — we don't assert which, but we assert the FitParameter is valid. |
| 683 | + const auto &fp = found->value<Mantid::Geometry::FitParameter>(); |
| 684 | + TS_ASSERT(fp.getFunction() == "Bk2BkExpConvPV" || fp.getFunction() == "IkedaCarpenterPV"); |
| 685 | + } |
| 686 | + |
612 | 687 | private: |
613 | 688 | template <typename ValueType> |
614 | 689 | void doCopyAndUpdateTestUsingGenericAdd(const std::string &type, const ValueType &origValue, |
|
0 commit comments