Expose System::getNumOfObsForOutput / getObsForOutput for in-process embedders#72
Merged
Merged
Conversation
Add two one-line public accessors on NFcore::System for index-based read access to the obsToOutput vector: int getNumOfObsForOutput() const Observable * getObsForOutput(int index) const Motivation: in-process / library callers currently cannot enumerate observables programmatically. Public access is limited to getObservableByName(string), which assumes the caller already knows the names — chicken-and-egg for a generic embedder. The CLI output path (outputAllObservableNames + .gdat headers) covers end-users running NFsim as a binary, but does not help anyone linking libnfsim. These accessors are pure read access into the existing private obsToOutput vector via std::vector::size() and std::vector::at(). They do not change simulation behavior, do not add fields, and do not call into anything else. Risk surface is bounded to the two-line diff. Following the precedent of RuleWorld#67 (per-instance RNG), this is a tiny embedding-oriented contribution that keeps the standalone NFsim CLI behavior identical while making libnfsim consumable by in-process hosts (BNGsim, RuleMonkey-style harnesses, future Python/Julia bindings). No new tests ship: existing validate.py coverage exercises the binary path unchanged. Happy to add a small test if reviewers want one — a CLI flag that prints i:name via the accessors, or a dedicated mini-executable, would both work.
# Conflicts: # src/NFcore/NFcore.hh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two one-line accessors on
NFcore::Systemfor index-based read access tothe output observable list:
Both are inline header-only and read directly from the existing
obsToOutputvector.Why
The current public surface for reading observables from a
System*isgetObservableByName(std::string), which assumes the caller alreadyknows the observable names. The CLI output path
(
outputAllObservableNames()plus.gdatheaders) covers end-usersrunning the
NFsimbinary, but doesn't help an in-process consumerthat wants to capture observable counts directly from a
System.These accessors close that gap without changing simulation behavior or
adding any new state.
What it changes
std::vector::size()andstd::vector::at().outputAllObservableNamesand the.gdatoutput path are not touched, and existingvalidate/testscontinue to pass.
Example
Verified
validate/basicModels/v39.xmlsmoke run produces unchanged output.