Skip to content

Form fix ttree write threading#476

Merged
knoepfel merged 4 commits intoFramework-R-D:mainfrom
aolivier23:form_fix_ttree_write_threading
Mar 31, 2026
Merged

Form fix ttree write threading#476
knoepfel merged 4 commits intoFramework-R-D:mainfrom
aolivier23:form_fix_ttree_write_threading

Conversation

@aolivier23
Copy link
Copy Markdown
Contributor

Fixes sporadic failure to write TTree to a file when using multiple threads. I failed to fix this the first time because the problem did not trigger consistently. We think there might be a data race involved.

the right TFile.  Still contains cout statements for instrumentation to
demonstrate that this solves the problem even when weird things happen
to gDirectory.
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Comment thread form/root_storage/root_ttree_write_container.cpp
Comment thread form/root_storage/root_ttree_write_container.cpp Outdated
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##             main     #476      +/-   ##
==========================================
- Coverage   85.51%   85.43%   -0.09%     
==========================================
  Files         144      144              
  Lines        3591     3591              
  Branches      615      615              
==========================================
- Hits         3071     3068       -3     
- Misses        314      315       +1     
- Partials      206      208       +2     
Flag Coverage Δ
unittests 85.43% <100.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
form/root_storage/root_ttree_write_container.cpp 50.00% <100.00%> (ø)

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ff4730...8be135e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aolivier23 aolivier23 requested a review from gemmeren March 31, 2026 14:44
Comment thread form/root_storage/root_ttree_write_container.cpp
Copy link
Copy Markdown
Contributor

@wwuoneway wwuoneway left a comment

Choose a reason for hiding this comment

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

LGTM

@knoepfel knoepfel merged commit b642a4b into Framework-R-D:main Mar 31, 2026
42 checks passed
{
if (m_tree != nullptr) {
m_tree->Write();
m_tree->GetDirectory()->WriteTObject(m_tree);
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.

Suggested change
m_tree->GetDirectory()->WriteTObject(m_tree);
m_tree->Write();

It should already be doing what (and a few more thing) the PR does. (On the other the SetDirectory is probably necessary to ensure that the TTree ends up in the right file).

Comment on lines 45 to +46
m_tree = new TTree(name().c_str(), name().c_str());
m_tree->SetDirectory(m_tfile.get());
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.

The fix is unlikely to solve the underlying problem.

If things are set properly (i.e. Thread Safety is enabled), the 2 codes have the same effective behavior.

TContext set gDirectory to m_tfile. If Thread Safety is enabled gDirectory is thread local and thus can not be influence by other threads.

If the new code is indeed more robust than the older code, it would (most likely) mean that Thread Safety is not enabled ... and if it not enabled all of ROOT/Core/Meta is not thread safe and will fail in many circumstances.

If Thread Safely is already enabled, then we have a deeper mystery to investigate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that must be it. Thread safety is probably not enabled. FORM doesn't do it to my knowledge, and I think we're the only component using ROOT. Thank you!

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.

Note that there is no harm in enabling it multiple time, so indeed FORM must enabled it explicitly.

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.

5 participants