Skip to content

Writing plt file must consider ordering of PVs vs formulas#3816

Open
georgweiss wants to merge 3 commits into
masterfrom
CSSTUDIO-3722
Open

Writing plt file must consider ordering of PVs vs formulas#3816
georgweiss wants to merge 3 commits into
masterfrom
CSSTUDIO-3722

Conversation

@georgweiss
Copy link
Copy Markdown
Collaborator

@georgweiss georgweiss commented Jun 2, 2026

Fixes the following issue:

User adds PV to a data browser plot and then a formula referencing those PVs. Additional PVs are added and the formula is updated to reference the added items. The saved plot would write the added PVs last, which breaks parsing of the formula tag.

Note: junit test class generated by Claude. Some tweaks were necessary. Also added a test case not spotted by Claude.

  • Testing:

    • The feature has automated tests
    • Tests were run
    • If not, explain how you tested your changes
  • Documentation:

    • The feature is documented
    • The documentation is up to date
    • Release notes:
      • Added an entry if the change is breaking or significant
      • Added an entry when adding a new feature

item.write(writer);

List<PVItem> pvItems =
model.getItems().stream().filter(i -> i instanceof PVItem).map(PVItem.class::cast).toList();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do this as a forEach rather than a map then you don't need the lower for loop. Same for the formulaItems.

Copy link
Copy Markdown
Collaborator Author

@georgweiss georgweiss Jun 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then you would need a try/catch block inside the forEach, which impairs readability.

@georgweiss georgweiss changed the title Csstudio 3722 Writing plt file must consider ordering of PVs vs formulas Jun 2, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 2, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@kasemir
Copy link
Copy Markdown
Collaborator

kasemir commented Jun 2, 2026

This is indeed a problem; a plt file will fail to load if it lists formulas before all their inputs are defined.
As for the implementation of this fix, it hard to see the actual change because it modified almost every line in the source code. Still, sorting plain channels vs. formulas with the latter placed last on save does fix it.
There is the side effect that it changes the order of items, and since traces are rendered in the order in which they are listed in the model, a trace that used to be "on top" of another one might now appear "behind". I think it's fine to simply accept that.

@georgweiss
Copy link
Copy Markdown
Collaborator Author

Yes, sorry about the auto-formatting @kasemir.

@georgweiss
Copy link
Copy Markdown
Collaborator Author

In a sense the issue reported may be a corner case... Guess one would "normally" add all PVs before creating a formula where all are referenced.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants