-
Notifications
You must be signed in to change notification settings - Fork 221
Preserve cout #4115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Preserve cout #4115
Conversation
📝 WalkthroughWalkthroughAdded systematic preservation and restoration of std::cout formatting state around Pythia8 initialization and event processing, and across multiple Fun4AllServer lifecycle points; introduced a member to hold the saved stream state (appears duplicated in header—verify). Changes
Sequence Diagram(s)(omitted — changes are stream-state preservation points and do not introduce a new multi-component control flow requiring a sequence diagram) ✨ Finishing touches
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✏️ Tip: You can disable this entire section by setting Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
generators/PHPythia8/PHPythia8.ccoffline/framework/fun4all/Fun4AllServer.ccoffline/framework/fun4all/Fun4AllServer.h
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{cc,cpp,cxx,c}
⚙️ CodeRabbit configuration file
**/*.{cc,cpp,cxx,c}: Prioritize correctness, memory safety, error handling, and thread-safety.
Flag hidden global state, non-const singletons, and unclear lifetime assumptions.Only raise Critical or Major findings. Do not post minor style, formatting, naming, or “nice-to-have” refactors.
Files:
offline/framework/fun4all/Fun4AllServer.ccgenerators/PHPythia8/PHPythia8.cc
**/*.{h,hpp,hxx,hh}
⚙️ CodeRabbit configuration file
**/*.{h,hpp,hxx,hh}: Focus on API clarity/stability, ownership semantics (RAII), and avoiding raw new/delete.
If interfaces change, ask for compatibility notes and any needed downstream updates.Only raise Critical or Major findings. Do not post minor style, formatting, naming, or “nice-to-have” refactors.
Files:
offline/framework/fun4all/Fun4AllServer.h
🧠 Learnings (2)
📚 Learning: 2026-01-08T18:39:48.023Z
Learnt from: emclaughlin2
Repo: sPHENIX-Collaboration/coresoftware PR: 4098
File: offline/QA/Calorimeters/CaloValid.cc:270-270
Timestamp: 2026-01-08T18:39:48.023Z
Learning: In C++ code that parses or traverses data nodes, implement a dual-key fallback when looking up a GL1Packet-like node: first try the version-specific key (e.g., "14001"), then fall back to the legacy/general key (e.g., "GL1Packet"). This ensures compatibility with multiple data versions where the node naming may have changed over time. Apply this pattern to files under the offline/ Calorimeters area (and similar modules) to maintain data-structure resilience across versions.
Applied to files:
offline/framework/fun4all/Fun4AllServer.cc
📚 Learning: 2026-01-10T07:54:57.021Z
Learnt from: silas-gross
Repo: sPHENIX-Collaboration/coresoftware PR: 4100
File: generators/Herwig/HepMCTrigger/HepMCParticleTrigger.h:93-108
Timestamp: 2026-01-10T07:54:57.021Z
Learning: In HepMCParticleTrigger (generators/Herwig/HepMCTrigger/HepMCParticleTrigger.h), the SetEta* and SetAbsEta* methods intentionally share the same storage variables (_theEtaHigh and _theEtaLow) to emulate the Pythia trigger behavior. This design pattern should be maintained for consistency with existing trigger implementations.
Applied to files:
generators/PHPythia8/PHPythia8.cc
🔇 Additional comments (7)
offline/framework/fun4all/Fun4AllServer.h (1)
146-147: No concerns with this member addition.generators/PHPythia8/PHPythia8.cc (1)
126-133: No concerns with this change.offline/framework/fun4all/Fun4AllServer.cc (5)
248-248: No concerns with this change.
580-580: No concerns with this change.
904-904: No concerns with this change.
1098-1098: No concerns with this change.
1151-1151: No concerns with this change.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| m_saved_cout_state.copyfmt(std::cout); // save current state | ||
| Fun4AllMonitoring::instance()->Snapshot("StartUp"); | ||
| std::string histomanagername; | ||
| histomanagername = Name() + "HISTOS"; | ||
| std::string histomanagername = Name() + "HISTOS"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
find . -name "Fun4AllServer.cc" -type fRepository: sPHENIX-Collaboration/coresoftware
Length of output: 122
🏁 Script executed:
# Get the file size first
wc -l ./offline/framework/fun4all/Fun4AllServer.ccRepository: sPHENIX-Collaboration/coresoftware
Length of output: 127
🏁 Script executed:
# Read the relevant section around lines 131-133
sed -n '125,145p' ./offline/framework/fun4all/Fun4AllServer.ccRepository: sPHENIX-Collaboration/coresoftware
Length of output: 945
🏁 Script executed:
# Search for m_saved_cout_state usage throughout the file
rg "m_saved_cout_state" ./offline/framework/fun4all/Fun4AllServer.cc -n -A 2 -B 2Repository: sPHENIX-Collaboration/coresoftware
Length of output: 1273
🏁 Script executed:
# Look for the class definition to understand the member variable
rg "class Fun4AllServer" ./offline/framework/fun4all/ -A 30Repository: sPHENIX-Collaboration/coresoftware
Length of output: 2821
🏁 Script executed:
# Search for subsystem call sites and lifecycle methods
rg "subsystem->Init|subsystem->InitRun|subsystem->End" ./offline/framework/fun4all/Fun4AllServer.cc -n -B 2 -A 2Repository: sPHENIX-Collaboration/coresoftware
Length of output: 313
Save cout formatting state immediately before each subsystem call, not just at startup.
m_saved_cout_state is captured once during InitAll() but restored at multiple lifecycle points (after subsystem Init(), process_event(), and BeginRunSubsystem() calls). If user code or loaded macros adjust std::cout formatting after server construction, the restore operations will reset those changes back to the startup state. Capture the current state immediately before each restore point to preserve user-applied formatting while still isolating subsystem-induced changes.
Refresh m_saved_cout_state before each major lifecycle entry where a restore will later occur.
Build & test reportReport for commit bd1ae49728ee04de2524280630f1e9956fd76d7d:
Automatically generated by sPHENIX Jenkins continuous integration |
Build & test reportReport for commit 04d53767137b4b03b84e5aeef28e911b6f304b1b:
Automatically generated by sPHENIX Jenkins continuous integration |



Types of changes
What kind of change does this PR introduce? (Bug fix, feature, ...)
pythia8 was messing with our cout state which then modifies all subsequent printouts. In order to prevent subsystem code to be able to do this - fun4all now restores the saved cout state after every call to subsystem code
TODOs (if applicable)
Links to other PRs in macros and calibration repositories (if applicable)
Pull Request Summary: Preserve cout State
Motivation / Context
Pythia8 and other subsystem code can modify the global std::cout formatting state (flags, precision, width), which can unexpectedly change subsequent printed output across subsystems. This PR ensures Fun4All saves and restores std::cout formatting around subsystem calls so transient changes inside subsystems do not leak into the rest of the application.
Key Changes
Potential Risk Areas
Possible Future Improvements
Note: AI-generated summaries can be incorrect or incomplete—please review the diff and tests carefully and use best judgment when accepting changes.