Skip to content

Validate optical-property vector sizes once, after parsing, not per token#158

Merged
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/112-optical-validation-once
Jun 13, 2026
Merged

Validate optical-property vector sizes once, after parsing, not per token#158
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/112-optical-validation-once

Conversation

@zhaozhiwen

Copy link
Copy Markdown
Collaborator

getMaterialPropertyFromString appends one value per token in a while(!eof()) loop, and the cross-vector size-validation block sat inside that loop, guarded by if (propertyName == "rayleigh"). On the first rayleigh token only one value has been pushed, so rayleigh.size() == 1; for any real multi-point optical material (photonEnergy size > 1) the very first check fired ERR_GMATERIALOPTICALPROPERTYMISMATCH and aborted loading of valid, consistent data.

Move the validation block out of the token loop so it runs once, after the full property vector has been parsed. propertyName is constant for the call and rayleigh is parsed last, so all other optical vectors are fully populated when the check runs. The check bodies are unchanged (a pure code-motion; the diff is large only because the block de-indents one level).

Validation: the cherenkov optical example (which exercises the same getMaterialPropertyFromString parser for photonEnergy/indexOfRefraction/absorptionLength) still parses its material and runs to completion in the Geant4 11.4.1 dev container. Note: no in-tree example uses rayleigh, so the specific abort path can't be reproduced without authoring new material data.

Fixes #112

…oken

getMaterialPropertyFromString appends one value per token in a
while(!eof()) loop, and the cross-vector size validation block sat inside
that loop, guarded by `if (propertyName == "rayleigh")`. On the first
rayleigh token only one value has been pushed, so rayleigh.size()==1; for
any real multi-point optical material (photonEnergy size > 1) the very
first check fired ERR_GMATERIALOPTICALPROPERTYMISMATCH and aborted loading
of valid, consistent data.

Move the validation block out of the token loop so it runs once, after
the full property vector has been parsed. propertyName is constant for
the call and rayleigh is parsed last, so all other optical vectors are
fully populated when the check runs. The check bodies are unchanged.

Verified: the cherenkov optical example (photonEnergy/indexOfRefraction/
absorptionLength) still parses its material and runs to completion
(Geant4 11.4.1 dev container).

Fixes gemc#112

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@maureeungaro maureeungaro merged commit 4bc0191 into gemc:main Jun 13, 2026
30 checks passed
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.

[High] Run optical-property size validation once after parsing, not on every rayleigh token

2 participants