Skip to content

[tmva] Check for existence of xml node before reading it#20735

Merged
guitargeek merged 1 commit intoroot-project:masterfrom
tmadlener:tmva-read-fix
Dec 18, 2025
Merged

[tmva] Check for existence of xml node before reading it#20735
guitargeek merged 1 commit intoroot-project:masterfrom
tmadlener:tmva-read-fix

Conversation

@tmadlener
Copy link
Copy Markdown
Contributor

@tmadlener tmadlener commented Dec 16, 2025

This Pull request:

Adds a check for the existence of UseOffsetOrNot fields in TMVA files before trying to read from it.

Changes or fixes:

This avoids breaking the reading of pre-existing TMVA weight files that have been written without this tag. See also #4141 (comment)

Checklist:

  • tested changes locally
  • updated the docs (not necessary)

I have a small-ish (13K) TMVA weight file that triggered the issue for me originally. Should I add that to some test to ensure that it remains readable? If yes, could you point me to where it should go?

@tmadlener tmadlener requested a review from lmoneta as a code owner December 16, 2025 13:54
@guitargeek guitargeek changed the title Check for existence of xml node before reading it [tmva] Check for existence of xml node before reading it Dec 16, 2025
@guitargeek
Copy link
Copy Markdown
Contributor

Thanks for the PR!

I have a small-ish (13K) TMVA weight file that triggered the issue for me originally. Should I add that to some test to ensure that it remains readable? If yes, could you point me to where it should go?

Absolutely welcome! The tests go to tmva/tmva/test, and are implemented using googletest and declared in CMake with the ROOT_ADD_GTEST macro. An example are the unit tests in TestRandomGenerator.cxx:
https://github.com/root-project/root/blob/master/tmva/tmva/test/CMakeLists.txt#L13

Maybe you can implement a new regression test, like TestRegression.cxx that collects the tests for the cases that regressed at some point, like yours?

@guitargeek
Copy link
Copy Markdown
Contributor

There are some failures on the CI:

 /github/home/ROOT-CI/src/tmva/tmva/src/VariableNormalizeTransform.cxx: In member function ‘virtual void TMVA::VariableNormalizeTransform::ReadFromXML(void*)’:
 ##[error]/github/home/ROOT-CI/src/tmva/tmva/src/VariableNormalizeTransform.cxx:381:15: error: request for member ‘HasAttr’ in ‘TMVA::gTools’, which is of non-class type ‘TMVA::Tools&()’
     if (gTools.HasAttr(trfnode, "UseOffsetOrNot")) {
   

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 16, 2025

Test Results

    21 files      21 suites   3d 14h 1m 35s ⏱️
 3 791 tests  3 791 ✅ 0 💤 0 ❌
77 770 runs  77 770 ✅ 0 💤 0 ❌

Results for commit 950956f.

♻️ This comment has been updated with latest results.

@tmadlener
Copy link
Copy Markdown
Contributor Author

Fixed the small typo I introduced via the web editor and things should compile now. I have added a very minimal regression test that I confirmed to fail without the fixes. Let me know if you think this is enough, or if the tests should be adapted somehow.

@dpiparo dpiparo self-requested a review December 18, 2025 15:26
@guitargeek
Copy link
Copy Markdown
Contributor

Thanks a lot! Squash and merge maybe, with the commit message of the second original commit?

This avoids breaking the reading of pre-existing TMVA weight files that
have been written without this tag.

Add a regression test with a weights file that does not yet contain this
tag.
@andresailer
Copy link
Copy Markdown
Contributor

I think this needs to be backported to 6.38?

@guitargeek
Copy link
Copy Markdown
Contributor

You're right. Thanks!

@guitargeek
Copy link
Copy Markdown
Contributor

Here is the backport, which will make it into 6.38.02:

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants