Skip to content

Improve DefaultParamHandler [532] #532

Closed as not planned
Closed as not planned

Description

@timosachsenberg

Submitted by aiche on 2013-05-22 16:36:54

Currently the DefaultParamHandler allows a very inconsistent access to the managed parameters. We should consider enforcing a certain access pattern which that defines exactly when the parameters should be transferred from the defaultparamhandler to members.

A solution would be

  • make param_ and getParamters() private
  • define updateMembers_(const Param& param) = 0 in DefaultParamHandler

With this every class that inherits from DefaultParamHandler would need to implement the method and it also would be the only possibility to access the parameters. A similar solution could be used for setDefaults.

Activity

  1. timosachsenberg commented on Sep 5, 2026

    @timosachsenberg
    ContributorAuthor

    Triage of this 2013 issue against current develop.

    The diagnosis still holds, the proposed remedy does not

    Access to the managed parameters is still as inconsistent as described:

    classes deriving directly from DefaultParamHandler 113
    classes implementing updateMembers_() 108 (85 non-empty)
    direct reads of the protected param_ ~1500, in 163 files
    direct writes to param_, bypassing setParameters()/checkDefaults() ~71

    But the specific fix proposed here is not workable at that scale, which is what #8278 ran into:

    • getParameters() cannot be made private. It is public API used by TOPP tools, the GUI and pyOpenMS (exposed on the DefaultParamHandler base in the nanobind bindings).
    • Making param_ private means touching those 163 files.
    • updateMembers_() = 0 makes DefaultParamHandler abstract and forces ~100 empty overrides — churn with no semantic gain, and it breaks DefaultParamHandler_test and any direct instantiation.

    What the design flaw actually costs today

    The part that causes real bugs is not the visibility of param_, it is this line of DefaultParamHandler.h:

    Call updateMembers_() at the end of the derived classes' copy constructor and assignment operator.

    Nothing enforces that. Six classes get it wrong right now — their copy constructor and operator= forward to the base (so param_ is copied) but never re-sync the members updateMembers_() caches, none of which have in-class initializers:

    class cached members left indeterminate on copy
    TheoreticalSpectrumGenerator 30
    TheoreticalSpectrumGeneratorXLMS 25
    NucleicAcidSpectrumGenerator 23
    SimpleTSGXLMS 13
    SpectrumAnnotator 8
    Normalizer 1 — method_ stays empty, so a copy throws InvalidValue("Method not known", "")

    The two XLMS generators additionally left loss_db_ empty, so a copy threw std::out_of_range from loss_db_.at() whenever losses were requested. All six expose their copy constructor to Python (nb::init<const T&>(), __copy__, __deepcopy__ in bind_misc.cpp), so copy.deepcopy() of a configured object was affected too.

    The existing copy tests did not catch any of it because they only compared getParameters() — which the base class copies correctly in every case.

    Fix

    Branch claude/openms-issue-532-vxjlrw (commit da4f498). All six copy operations become = default: the compiler-generated versions copy param_ and the cached members together, which is exactly the state updateMembers_() would have produced, since none of these six do anything but assign scalars from param_. The hand-written contract disappears rather than being restated. Also resets TheoreticalSpectrumGenerator::isotope_model_ for isotope_model=none, which updateMembers_() previously left unassigned on the default path. The copy tests now configure an object, copy it, and compare what the copy actually produces.

    Closing: the redesign proposed here is not being pursued, and the concrete defect behind it is addressed on that branch. Worth opening a fresh, narrower issue if someone wants to revisit the API itself.


    Generated by Claude Code

  2. timosachsenberg commented on Sep 5, 2026

    @timosachsenberg
    ContributorAuthor

    Correction: the branch head is 5f8978d, not da4f498 (the commit was amended).

    Since then it has been built and tested: the six class tests pass with the fix, all six fail with the source change reverted and the new tests kept, and 25 dependent class tests (OPXL, DIA scoring, PScore/HyperScore/MorpheusScore, Deisotoper, FragmentIndex, Tagger, SpectrumAlignment, …) pass.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

OpenMS - libraryenhancementmajor

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions